Oracle-Based Pricing System for Perpetual DEX

We design and develop full-cycle blockchain solutions: from smart contract architecture to launching DeFi protocols, NFT marketplaces and crypto exchanges. Security audits, tokenomics, integration with existing infrastructure.
Showing 1 of 1 servicesAll 1306 services
Oracle-Based Pricing System for Perpetual DEX
Complex
~1-2 weeks
FAQ
Blockchain Development Services
Blockchain Development Stages
Latest works
  • image_website-b2b-advance_0.png
    B2B ADVANCE company website development
    1214
  • image_web-applications_feedme_466_0.webp
    Development of a web application for FEEDME
    1161
  • image_websites_belfingroup_462_0.webp
    Website development for BELFINGROUP
    852
  • image_ecommerce_furnoro_435_0.webp
    Development of an online store for the company FURNORO
    1041
  • image_logo-advance_0.png
    B2B Advance company logo design
    561
  • image_crm_enviok_479_0.webp
    Development of a web application for Enviok
    823

Oracle-Based Pricing System for Perpetuals

Perpetual DEX without correct oracle pricing — minefield. GMX, dYdX, Synthetix — all used oracle price for mark price contracts, fundamentally different from spot order book pricing. Correct oracle mechanism determines if protocol can be manipulated and fairness of liquidations.

Mark Price vs Index Price vs Oracle Price

Index Price: aggregated price from major centralized exchanges (Binance, OKX, Coinbase). Represents "fair" market price.

Mark Price: price used for unrealized PnL calculation and liquidation determination. On perp DEX usually = Oracle Price. Can't deviate significantly from Index Price (if does — funding rate corrects).

Oracle Price: concrete smart contract from which price read.

Consequences of wrong oracle: if mark price deviates from fair price — unfair liquidations (liquidate healthy position on oracle spike) or manipulation attacks possible.

Oracle Choice for Perpetual DEX

GMX v2 Approach: Chainlink Low-Latency

GMX v2 integrated Chainlink Data Streams — off-chain price reports signed by Chainlink nodes, verifiable on-chain. Sub-second freshness with cryptographic reliability.

Protection Against Oracle Manipulation

Spread-Based Protection

On large oracle deviation from previous price — activate protection:

function updateOraclePrice(bytes32 assetId, uint256 newPrice) internal {
    uint256 lastPrice = lastOraclePrice[assetId];
    if (lastPrice > 0) {
        uint256 deviation = newPrice > lastPrice 
            ? (newPrice - lastPrice) * 10000 / lastPrice
            : (lastPrice - newPrice) * 10000 / lastPrice;
            
        // Circuit breaker on too sharp movement
        if (deviation > MAX_PRICE_DEVIATION) {
            newPrice = lastPrice * (10000 + MAX_PRICE_DEVIATION) / 10000;
        }
    }
    lastOraclePrice[assetId] = newPrice;
}

Multi-Source Validation

Read prices from multiple sources (Chainlink + Pyth + on-chain TWAP), take median.

TWAP for Liquidations

For liquidation threshold — use TWAP (Time-Weighted Average Price) over last 15-30 minutes, not spot price. Flash crash doesn't trigger mass liquidations.

Operation Recommended Oracle
Open/close position Spot oracle (Chainlink/Pyth)
Unrealized PnL Mark price (oracle)
Liquidation check TWAP (15-30 min)
Funding rate Index price (CEX aggregate)

Development of oracle system for perp DEX — 4-8 weeks. Critical component: most major perp DEX attacks (GMX, Synthetix) were oracle manipulation attacks.