Trade dominance with perpetuals. Zero-sum P&L, Pyth oracles, live on Arbitrum. Built at ETH Prague.
How We Built RMSP
Core Innovation: We store market share ratios (e.g., ETH = 2.37% of ETH+BTC) instead of USD prices. This creates perfectly symmetric P&L - when longs win $100, shorts lose exactly $100. Zero external funding needed.
Tech Stack:
Notable Hacks:
Why Pyth: Sub-second price feeds from 40+ exchanges. Same data used by Binance/OKX. Perfect for DeFi.
Result: (almost) Fully functional mainnet perpetual Proof of concept DEX for ETH/BTC dominance trading. Self-balancing, no LPs needed. Built with Claude AI assistance.
NOTE: the USDC used in the contracts is a mock! Don't try to send real money to it.
How We Built RMSP: The Nitty-Gritty Technical Details
The Architecture Journey
We started with a simple question: "How can traders bet on ETH vs BTC dominance without complex multi-leg trades?" This led us down a fascinating technical rabbit hole.
Smart Contract Layer (Foundry + Solidity)
The Core Innovation: We built SimplePerpV2.sol which tracks positions using a novel "entry share" mechanism. Instead of storing USD prices, we store the market share ratio at entry (e.g., 2.37%). This enables perfect P&L symmetry - longs and shorts are exact opposites.
Key Technical Decisions:
The Oracle Challenge: RatioOracle.sol was the trickiest part. We needed real-time ETH/BTC ratios, so we:
Pyth Network Integration (The Game Changer)
Why Pyth: We needed sub-second price updates from reliable sources. Pyth aggregates data from 40+ exchanges and trading firms, giving us the same data used by Binance, OKX, and other major platforms.
The Integration: // Fetch prices with cryptographic proofs IPyth.Price memory ethPrice = pyth.getPriceUnsafe(ETH_PRICE_ID); IPyth.Price memory btcPrice = pyth.getPriceUnsafe(BTC_PRICE_ID);
// Calculate ratio with 18 decimal precision uint256 ratio = (ethPrice * 1e18) / (ethPrice + btcPrice);
The Hack: Pyth prices need periodic updates. Instead of running a keeper, we added an "Update Oracle Prices" button that lets users update prices themselves before trading. This saved us from running infrastructure while keeping the UX smooth.
Frontend (Next.js + wagmi + TradingView)
Real-time Position Tracking: We used wagmi's useContractRead with 5-second polling to show live P&L updates. The trick was calculating everything client-side to reduce RPC calls:
const entryRatioPercent = (Number(position.entryShare) / 1e18) * 100; const pnlPercent = ((currentRatio - entryRatio) / entryRatio) * 100;
TradingView Integration: We embedded TradingView's lightweight charts and overlaid position data. The hacky part: we draw position entry lines by injecting custom series data into their chart instance.
The 0.02% Bug: Initially showed entry share as 0.02% instead of 2.37%. The issue? We were dividing by 1e18 twice - once in the contract and once in the UI. Classic decimal precision bug that made profits look 100x bigger!
GraphQL Indexer (Ponder)
Why Ponder: We needed historical position data and couldn't query logs efficiently. Ponder let us index events into a PostgreSQL database with GraphQL API in under 100 lines of code.
The Schema: type Position { id: ID! user: String! openedAt: BigInt! closedAt: BigInt entryShare: BigInt! pnl: BigInt }
The Hack: Instead of indexing price updates (too many), we only index position events and fetch current prices client-side. This kept our indexer lightweight and query times under 50ms.
Deployment Strategy
Arbitrum Mainnet: We deployed directly to mainnet (not testnet) because:
Contract Verification: Used Foundry's --verify flag with Arbiscan API. Had to flatten contracts first because Arbiscan couldn't handle our import structure.
Notable Hacks & Workarounds
Technology Stack
Smart Contracts:
Frontend:
Backend:
Developer Tools:
The Result
A fully functional perpetual DEX for relative value trading, built in 3 days, with real money on mainnet, integrated with institutional-grade oracles, and a professional trading interface. The zero-sum architecture means it's self-sustaining - no LP incentives needed, no external funding required. Just pure relative value speculation.