perpX is a decentralized leveraged trading protocol that reimagines perpetual futures by introducing forced expiry and outcome-based settlement.
perpX - Decentralized Perpetual Futures & Prediction Markets
Overview
perpX is a next-generation decentralized trading platform built on Arbitrum Stylus that combines perpetual futures trading with prediction markets. By leveraging Rust-based WASM smart contracts, perpX delivers institutional-grade performance with the transparency and security of blockchain technology.
Problem Statement
The current DeFi trading landscape is broken.
High latency and gas costs: Traditional Solidity-based DEXs suffer from slow execution and expensive transactions, making them unsuitable for active traders.
Limited market access: Most DeFi platforms only offer spot trading or basic perpetuals, lacking sophisticated financial instruments.
Centralization risks: Users are forced to choose between fast centralized exchanges with custody risks or slow decentralized alternatives.
Poor capital efficiency: Existing platforms require excessive collateral and offer limited leverage options.
No unified platform: Traders must use multiple platforms for perpetuals, predictions, and other derivatives, fragmenting liquidity and user experience.
Solution
perpX solves these problems by building a unified trading platform on Arbitrum Stylus that offers the following.
Lightning-fast execution: Rust and WASM smart contracts execute 10 to 100 times faster than Solidity equivalents, enabling near centralized-exchange performance with full decentralization.
Unified trading experience: One platform for perpetual futures and prediction markets, allowing users to trade price movements or bet on real-world outcomes.
Capital efficient design:
Up to 40x leverage on perpetuals
Cross-margin support
Efficient collateral management using USDC
Trustless and transparent:
All trades are settled on-chain
Pyth Network oracle integration for reliable price feeds
Open-source smart contracts
Features
Perpetual futures trading includes multi-asset support for BTC, ETH, and ARB perpetuals. Markets are available in 24-hour, 7-day, and 30-day timeframes. Traders can use up to 40x leverage with liquidation protection and can take both long and short positions.
Prediction markets allow outcome-based trading on future events. Markets are time-bound with defined expiry for clear settlement. Binary outcomes provide simple yes or no predictions with transparent payouts.
Risk management features include a secure USDC collateral vault, an automated liquidation engine to protect the protocol, a protocol-owned insurance fund to cover shortfalls, and a position manager to track and manage all open positions.
User experience features include real-time prices via CoinGecko, a portfolio dashboard to track balances, positions, and profit and loss, one-click trading for streamlined execution, and a mobile-responsive interface.
How It Works
Opening a position involves the user depositing USDC into the CollateralVault, selecting a market such as BTC, ETH, or ARB and a timeframe of 24 hours, 7 days, or 30 days. The user chooses a long or short position and leverage between 1x and 40x. The frontend fetches the latest price from CoinGecko and updates the price adapter. The OutcomeMarket validates parameters and locks collateral, the PositionManager creates a position record, and the user can monitor profit and loss in real time.
Closing a position occurs when the user clicks close. The current price is fetched and submitted, profit and loss is calculated based on the difference between entry and current price, collateral is released with profit added or loss deducted, and the position is marked as closed.
Liquidation works by the LiquidationEngine continuously monitoring all positions. When a position’s health drops below the threshold, liquidation is triggered. The position is closed at market price, remaining collateral is sent to the InsuranceFund, and the liquidator receives a reward.
Smart Contracts (Rust/Stylus) - Built 8 production-ready contracts from scratch in Rust targeting Arbitrum Stylus: - OutcomeMarket - Core trading engine with long/short positions, leverage, and P&L calculations - CollateralVault - Secure deposit/withdrawal system with multi-token support - PositionManager - Position tracking and management - PythPriceAdapter - Oracle integration with staleness checks - LiquidationEngine - Automated liquidation system - InsuranceFund - Protocol reserve management - OrderBook - Limit order infrastructure - CrossMargin - Cross-margining capabilities - Deployed 9 market contracts on Arbitrum Sepolia: - BTC/USD (24h, 7d, 30d markets) - ETH/USD (24h, 7d, 30d markets) - ARB/USD (24h, 7d, 30d markets) Frontend Development - Built complete trading interface with Next.js 14 & TypeScript - Real-time price feeds via CoinGecko API - Wallet integration using Reown (WalletConnect) - Portfolio dashboard with P&L tracking - Position management UI - Responsive design for all devices Key Technical Achievements - Successfully compiled and deployed Rust WASM contracts to Stylus - Integrated Pyth Network oracle for decentralized price feeds - Implemented 2-step trading flow (price update → position open) - Built secure collateral locking/releasing mechanism - Created market authorization system for contract interactions Challenges Overcome - Debugged cross-contract calls between Stylus contracts - Resolved price staleness issues with configurable thresholds - Fixed decimal conversion between USDC (6 decimals) and USD values (18 decimals) - Optimized gas usage for Stylus contract deployment
N/A