dYdX v3 processed $10 billion daily volume on a centralized order book with on-chain settlement. GMX v2 takes a different path: liquidity providers bear risk through GM pools, traders trade against the pool, and Chainlink Low Latency oracle prices determine PnL. Both approaches work—but break differently, and architecture choice determines everything. We specialize in perpetual contract development for perpetual futures DeFi, including perpetuals protocol design, GMX development, and dYdX development. Our team has 7+ years in DeFi and over 30 implemented projects, including 5 perpetuals protocols.
Perpetuals protocol is the most technically complex type of DeFi. Funding rate, mark price, index price, open interest limits, liquidation engine, insurance fund—each of these components can fail under unusual market conditions. Our team has delivered 30+ projects with 99.9% uptime and gas optimization that reduces costs by up to 30%.
Perpetual Contract Protocol Development: Where to Start?
The first step is defining the architecture. It determines oracle requirements, gas cost (up to 3x difference), and risks for LPs and traders. Below we break down the two main patterns.
Virtual AMM (vAMM) — Perpetual Protocol Model
vAMM uses the xy=k formula to determine price without a real liquidity pool. A trader opens a long on 10 ETH—virtual ETH reserve decreases, USDC increases, price rises. Problem: under severe open interest imbalance, the mark price diverges from the index price. Funding rate should correct this, but if the divergence is too large, funding rate becomes economically unbearable. Perpetual Protocol v1 faced this historically: during extreme volatility periods, funding rate reached 1000% APR, causing the market to seize.
Liquidity Pool as Counterparty — GMX Model
The GLP/GM pool holds a basket of assets (ETH, BTC, USDC, USDT). A trader going long on ETH profits from the pool; losses are absorbed by the pool. Liquidity providers bear directional risk: if traders are net profitable, LPs lose. Vulnerability: oracle arbitrage. The v2 solution transitioned to Chainlink Low Latency Feeds updating every few seconds, with a keeper architecture for order execution.
What Is Cumulative Funding Index and Why It Matters
Funding rate is calculated as: fundingRate = (markPrice - indexPrice) / indexPrice * fundingFactor. Critical details: how often funding is accrued (per block or per time?), whether caps exist, and how accrued funding is handled on partial closes. Cumulative funding index (as in Aave) uses one global variable globalFundingIndex updated at each interaction; positions store a snapshot entryFundingIndex. The difference is the accrued funding debt or credit. This is O(1) gas regardless of open position count. An error in this logic leads to direct losses for traders or a hole in the insurance fund. Proper handling of liquidation and funding rate is essential for protocol solvency.
Implementation Details: Solidity Example
// pseudocode for funding index update
function _updateFundingIndex() internal {
uint256 timeDelta = block.timestamp - lastFundingTimestamp;
uint256 fundingAccrued = (indexPrice - markPrice) * timeDelta / 1e18;
globalFundingIndex += fundingAccrued;
lastFundingTimestamp = block.timestamp;
}
Liquidation Engine
A common mistake is permissioned liquidation (only on request). During sharp market moves, liquidators cannot liquidate all underwater positions in one block—the protocol accumulates bad debt. The correct architecture: ADL (Auto-Deleveraging) as the last line. If the insurance fund is exhausted (typical size 2–3% of TVL), the most profitable positions are forcibly closed at mark price. This is a negative user experience but the only way to prevent pool bankruptcy. dYdX v4 implements ADL via a keeper network—bots monitor unsafe positions and call liquidation, receiving a reward. Learn more about Auto-Deleveraging.
Open Interest Limits
Without limits, a single large player can take a position exceeding the entire liquid pool. On liquidation, the market cannot fill it without catastrophic slippage. Per-market and per-side limits (separately for longs and shorts) are mandatory.
Architecture Comparison
| Parameter | vAMM (Perpetual Protocol) | Pool-model (GMX) |
|---|---|---|
| Counterparty | Virtual pool | Real LP pool |
| Oracle dependency | Low (price by formula) | High (Chainlink) |
| Gas cost per open | ~80k | ~120k |
| Liquidity fragmentation | No | Yes (each pool separate) |
| Risk for LP | No | Yes (directional) |
vAMM is 3x cheaper in gas but does not scale under high open interest concentration (e.g., >$500M). Pool-model requires more complex oracle infrastructure but offers better capabilities for combining positions.
Development Stack
For EVM chains (Arbitrum, Base)—Solidity + Foundry (5x faster than Hardhat for test runs). Keeper infrastructure: TypeScript bots using viem/ethers.js, monitoring via Tenderly webhooks. We recommend a combination of oracles: Chainlink Low Latency (push model) and Pyth Network (pull model—trader provides price update, reducing oracle front-running vector). Average block time on Arbitrum is 0.25 seconds, allowing liquidations within 2–3 blocks.
| Component | Solution | Rationale |
|---|---|---|
| Chain | Arbitrum One / Base | Low gas, high liquidity |
| Oracle | Chainlink + Pyth | Different update models |
| Keeper | OpenZeppelin Defender | Managed execution |
| Subgraph | The Graph | Position history, PnL |
| Tests | Foundry + Echidna | Fuzz + property tests |
Development Process
- Mathematical specification (~1 week). Formalize formulas for funding rate, margin requirements, liquidation price, mark price. An error in specification costs an hour; in production, millions.
- Core contract development (~4–8 weeks). Position manager, funding engine, liquidation engine, oracle module. Fork tests on mainnet with real Chainlink feeds. We use Solidity development and Foundry testing for all contracts.
- Keeper infrastructure (~2–3 weeks). TypeScript bots, monitoring, alerting, fallback on downtime.
- Parameterization and simulation (~1–2 weeks). Agent-based simulation: virtual traders with different strategies, stress tests of ±50% volatility. 90% of liquidations occur within 5 seconds of a price move—this is a critical parameter for tuning.
- Audit. Code audit (reentrancy, overflow) + economic audit (incentives). We recommend Trail of Bits or Code4rena. Audit covers 100% of code paths.
To discuss your project details, get a consultation from our engineers—we will evaluate the architecture and propose the optimal stack. We guarantee thorough testing and a dedicated project manager. Typical project budget ranges from $50,000 for a minimal product to $300,000+ for a full platform.
Common Mistakes in Perpetual Development
- Using permissioned liquidation instead of ADL—bad debt grows during sharp moves.
- Missing caps on funding rate—market seizes under imbalance.
- Insurance fund too small (<2% of TVL)—consecutive liquidations can bankrupt the pool.
- Oracle front-running without pull model (Pyth)—traders can front-run price updates.
What Is Included in the Work
- Architectural documentation with flow diagrams
- Complete set of smart contracts with tests (Foundry, Echidna)
- Keeper services and deployment scripts
- Agent-based simulation for parameter calibration
- Subgraph integration for position history
- Mainnet/testnet deployment with multisig
- Monitoring and alerting (Tenderly, Datadog)
- Documentation for DAO governance
- Training for your team (2 sessions)
- 1 month post-launch support and maintenance
Timeline Estimates
MVP with one market and basic orders: 2–3 months. Full platform with multiple markets, DAO governance, cross-margin: 4–6 months. External audit: additional 4–6 weeks. Cost is determined after technical specification, typically ranging from $50k for MVP to $300k+ for full platform.
Contact us to discuss your protocol. Request an architecture consultation—we will evaluate the project and propose the optimal pattern.







