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.
| Parameter | Value |
|---|---|
| Collateral asset | USDC |
| Initial margin | 5% of position notional (20x leverage) |
| Maintenance margin | 3% of position notional |
| Maximum leverage | Up to 50x (market-dependent) |
| Margin mode | Cross-margin (default), isolated-margin (optional) |
Cross-Margin vs. Isolated Margin
| Mode | Behavior |
|---|---|
| Cross-margin | All 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 margin | Each 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 deficitFunding 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.
| Parameter | Description |
|---|---|
| Calculation | funding_rate = (mark_price - oracle_price) / oracle_price |
| Payment frequency | Every 8 hours (configurable) |
| Direction | Longs pay shorts when mark > oracle; shorts pay longs when mark < oracle |
| Clamping | Funding 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_rateLiquidation Engine
When an account’s margin ratio falls below the maintenance margin threshold, the liquidation engine takes over:
- Detection — Every block, the clearinghouse checks all positions against the current mark price
- Ordering — Positions closest to bankruptcy are liquidated first (semantic mempool priority)
- Execution — The position is closed at the oracle mark price
- Settlement — Remaining equity is transferred to the insurance fund
- 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:
| Feature | Description |
|---|---|
| Settlement | Atomic swap: base token and quote token transferred simultaneously |
| Fees | Maker/taker fees deducted from the quote asset at settlement |
| Token support | Any token registered on GX Core (native) or GX EVM (ERC-20) |
| Margin | No 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.
| Precision | Representation |
|---|---|
| Price | Integer with 6 decimal places (1 USDC = 1,000,000 units) |
| Size | Integer with market-specific decimal places |
| PnL | Computed 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.