GX CoreClearinghouse

Clearinghouse

The GX Core clearinghouse is the settlement layer for all trading activity on GX Exchange. It manages margin accounting, position tracking, funding rate payments, and liquidation execution for perpetual futures, as well as settlement for spot markets.


Perpetual Futures Clearinghouse

Margin System

GX Exchange uses a margin-based system where traders post USDC collateral to open leveraged positions. The clearinghouse continuously monitors all positions against margin requirements.

ParameterValue
Collateral assetUSDC
Initial margin5% of position notional (20x leverage)
Maintenance margin3% of position notional
Maximum leverageUp to 50x (market-dependent)
Margin modeCross-margin (default), isolated-margin (optional)

Cross-Margin vs. Isolated Margin

ModeBehavior
Cross-marginAll positions share a single collateral pool. Unrealized profits from one position can offset losses in another. More capital-efficient but a single large loss can liquidate all positions.
Isolated marginEach position has its own dedicated collateral. A liquidation in one position does not affect others. Less capital-efficient but limits downside risk per position.

Position Lifecycle

1. OPEN
   - User places a buy or sell order
   - Order matches against the order book
   - Clearinghouse creates a position record:
     - Entry price (fill price)
     - Size (in base asset units)
     - Side (long or short)
     - Margin allocated (collateral locked)

2. MAINTAIN
   - Mark price updated continuously via oracle
   - Unrealized PnL = (mark_price - entry_price) * size * direction
   - Margin ratio = equity / position_notional
   - Funding payments applied periodically

3. CLOSE
   - User places an opposing order (or Reduce Only)
   - Order matches, position size decreases
   - Realized PnL settled: collateral returned or deducted
   - Trading fees deducted from equity

4. LIQUIDATION (if margin ratio < maintenance)
   - Position is forcibly closed at the mark price
   - Remaining equity after close goes to the insurance fund
   - If equity is negative, the insurance fund covers the deficit

Funding Rate

Perpetual futures use a funding rate mechanism to anchor the perpetual price to the spot oracle price. Funding payments transfer between long and short holders.

ParameterDescription
Calculationfunding_rate = (mark_price - oracle_price) / oracle_price
Payment frequencyEvery 8 hours (configurable)
DirectionLongs pay shorts when mark > oracle; shorts pay longs when mark < oracle
ClampingFunding rate is clamped to a maximum of 0.05% per period

Funding payments are applied atomically during block processing. The payment amount for a position is:

funding_payment = position_size * oracle_price * funding_rate

Liquidation Engine

When an account’s margin ratio falls below the maintenance margin threshold, the liquidation engine takes over:

  1. Detection — Every block, the clearinghouse checks all positions against the current mark price
  2. Ordering — Positions closest to bankruptcy are liquidated first (semantic mempool priority)
  3. Execution — The position is closed at the oracle mark price
  4. Settlement — Remaining equity is transferred to the insurance fund
  5. Backstop — If the insurance fund is insufficient, auto-deleveraging (ADL) reduces profitable counter-positions

Auto-Deleveraging (ADL)

If a liquidation results in a negative equity shortfall that exceeds the insurance fund, ADL is triggered:

  • The most profitable opposing positions are identified
  • These positions are partially closed to offset the shortfall
  • ADL is a last resort and has never been triggered during testing

Spot Clearinghouse

The spot clearinghouse handles atomic settlement of spot token trades:

FeatureDescription
SettlementAtomic swap: base token and quote token transferred simultaneously
FeesMaker/taker fees deducted from the quote asset at settlement
Token supportAny token registered on GX Core (native) or GX EVM (ERC-20)
MarginNo margin for spot — fully collateralized trades only

Accounting

All clearinghouse operations use integer arithmetic to prevent floating-point rounding errors. Prices and sizes are represented as fixed-point integers with configurable decimal precision per market.

PrecisionRepresentation
PriceInteger with 6 decimal places (1 USDC = 1,000,000 units)
SizeInteger with market-specific decimal places
PnLComputed in integer arithmetic, settled in USDC

This ensures that all validators produce identical settlement results for the same inputs, which is critical for deterministic consensus.