Are you an LLM? Read llms.txt for a summary of the docs, or llms-full.txt for the full context.
Skip to content

Risk Engine

The risk engine monitors accounts during block-tail processing and handles liquidation, auto-deleveraging, and funding settlement. On the ordinary path this is incremental — limited to accounts touched by the block — but an oracle update triggers a full margin recalculation so every position is marked to the new prices.

Liquidation

When a cross account's or isolated position's margin ratio falls below 1.0, liquidation runs in a fixed sequence:

  1. Decision — using the tiered-margin config, compute how much of the position must be taken over, classify the liquidation as full or partial, and select the liquidator account. Partial liquidation is only considered from tier 3 upward; below that the position is closed in full. A partial liquidation reduces the position to the size cap of the tier below.
  2. Cancel — cancel the orders that conflict with the liquidation. In cross mode this covers all of the user's perpetual orders (spot and outcome orders are left alone); in isolated mode only orders on the liquidated instrument are cancelled.
  3. Takeover — the liquidator account takes over the position at the bankruptcy price.
  4. Market disposal — the liquidator places a single reduce-only IOC order, priced past the bankruptcy price by a per-instrument slippage rate (lower for a sell, higher for a buy) so resting liquidity can absorb it. Instruments without an override use the protocol default.
  5. ADL (auto-deleveraging) — whatever market disposal could not clear is force-closed against counterparties on the opposite side, highest leverage-PnL ratio first.
  6. Settlement — a fill better than the bankruptcy price is recorded as a liquidation surplus; a fill worse than it is recorded as a shortfall.

Every stage emits on-chain events, so a liquidation can be fully reconstructed from the block stream.

ADL ranking and price

Counterparties on the opposite side are ranked by leverage-PnL ratio and exposed as a 1–5 ADL indicator (adlQuantile); 5 is deleveraged first. ADL does not execute at the mark price — the fill price is the bankruptcy price adjusted by the taker fee rate, raised for a long being deleveraged and lowered for a short.

See Auto-deleveraging (ADL) for the trader-facing view of the queue and the fill price.

Liquidation surplus and shortfall

Settlement classifies every liquidation result: a surplus above the bankruptcy price is recorded as a liquidation fee, and a shortfall as a bankruptcy loss. Both are emitted as auditable on-chain events.

Funding rate

  • Perpetual contracts settle funding on a fixed cycle (default every hour) so the contract price tracks the oracle price.
  • The oracle publishes the funding rate in percent. Divide by 100 to get the decimal rate used in settlement: a published 0.01 means 0.01%, i.e. a rate of 0.0001. See Oracle.
  • Payment for a position is −size × mark price × (published rate / 100), so longs pay and shorts receive when the rate is positive.
  • Funding is accrued per position (segmented since open / since last change) and booked when the settlement cycle is reached.
  • For isolated positions, funding adjusts the position margin; for cross positions, it adjusts account equity.