Perpetuals

Overview

Real Exchange includes a non-custodial decentralized perpetual trading market designed for on-chain trading of leveraged markets using stablecoin collateral. The protocol enables users to gain long or short price exposure without holding the underlying asset, while maintaining full control of funds through self-custody.

Perpetuals uses a pooled-liquidity, oracle-driven design with automated funding and liquidation mechanisms, delivering transparent execution, predictable risk management, and on-chain settlement.


Purpose

  • Enable non-custodial perpetual trading on-chain

  • Provide leveraged price exposure without asset custody

  • Settle profits and losses transparently through smart contracts

  • Use stablecoins as primary collateral for margin and settlement

  • Enforce risk management through automated protocol logic

  • Support scalable, capital-efficient perpetual markets


Key Features

  • Perpetual markets

    • Long and short positions with leverage

    • Stablecoin-settled PnL

    • No traditional order book; execution via protocol pricing

  • Pooled liquidity model

    • Liquidity providers supply capital to protocol vaults

    • Traders interact with pooled liquidity rather than direct counterparties

  • Oracle-driven pricing

    • Index prices sourced from trusted oracle providers

    • Mark price logic designed to reduce manipulation and MEV risk

  • Funding rate mechanism

    • Periodic funding aligns perpetual prices with index prices

    • Funding payments are settled on-chain

  • Automated liquidations

    • Maintenance margin enforced at the protocol level

    • Permissionless liquidators incentivized to close unsafe positions

  • Non-custodial design

    • Users retain control of private keys and assets

    • All trades, positions, and settlements are verifiable on-chain


Architecture

Core Protocol

  • Smart contracts managing:

    • Position lifecycle

    • Collateral accounting

    • PnL calculation

    • Funding accrual

  • Vault-based liquidity system

  • Deterministic execution enforced entirely by smart contracts

Pricing and Oracles

  • External index price feeds for reference pricing

  • Mark price computation for funding and liquidation logic

  • Safeguards against stale or manipulated pricing data

Execution and Automation

  • Keeper network responsible for:

    • Order execution

    • Funding updates

    • Liquidation triggers

  • Permissionless execution aligned with protocol incentives

Risk Management

  • Initial and maintenance margin parameters per market

  • Maximum leverage caps

  • Open interest and exposure limits


Example User Flow

  • User connects a wallet to the Real Exchange interface

  • User deposits stablecoins into protocol vaults as collateral

  • User selects a perpetual market

  • User opens a leveraged long or short position

  • Protocol calculates margin requirements and funding exposure

  • Funding accrues periodically while the position is open

  • Margin is continuously monitored on-chain

  • If maintenance margin is breached:

    • Liquidators execute on-chain liquidation

  • User closes the position

  • PnL settles directly to the user’s wallet


Codebase Overview

The Real Exchange perpetuals codebase is structured around modular smart contracts and supporting infrastructure:

  • contracts/

    Core smart contracts for trading, margin, and accounting

  • contracts/core/

    Market state, positions, collateral, and configuration

  • contracts/exchange/

    Trade execution and position lifecycle logic

  • contracts/oracle/

    Price feeds, validation, and safety checks

  • contracts/keeper/

    Automation for funding updates and execution

  • contracts/liquidation/

    Liquidation eligibility and execution logic

  • contracts/reader/

    Read-only helpers for front-end and analytics

  • contracts/peripherals/

    Routing and UX-focused helper contracts

  • scripts/

    Deployment and operational scripts

  • deploy/

    Network-specific deployment configurations

  • test/

    Unit and integration tests

  • frontend/

    Web interface for trading and position management

  • docs/

    Protocol documentation and specifications

Last updated