# Liquidations

A liquidation starts when the equity of a quote-token margin pool falls below its maintenance-margin requirement.

Maintenance margin is evaluated against the oracle mark.

## Liquidation Scope

The quote token defines the scope:

* In a cross-margin pool, the liquidation includes all positions that use that quote token.
* In an isolated pool, the liquidation is limited to positions that use the isolated quote token.
* A liquidation does not use a balance from another subaccount or another quote-token pool.

Liquidation transfers the full affected pool. mPerp positions remain exposed to position fees during a scheduled gap and to the next accepted mark at reopen.

## Process

1. The matching system identifies a pool below maintenance margin.
2. Open orders in that pool are canceled.
3. Its positions transfer to the liquidator account and its quote-token balance becomes zero.
4. The contracts validate the liquidation and oracle data.
5. The liquidator reduces the transferred positions.

## First-Bankruptcy-Price Cap

The matching system can cap the mark at the first price where account equity reaches zero.

The takeover uses the system's bankruptcy-price accounting. The displayed liquidation price is only an estimate of the trigger point.

## Maintenance Margin

For one product, the base maintenance-margin fraction is:

```text
base maintenance margin fraction = 1 / (2 * maximum leverage)
```

The pool requirement includes all positions, product taker fees, and precision tolerances. Pool equity includes unrealized PnL, outstanding funding, and outstanding position fees.

## Onchain Validation

The exchange contracts check important parts of a liquidation. These checks include:

* The submitted product IDs and position sizes.
* The quote token shared by the liquidation batch.
* Pyth price data and its configured maximum age.
* Realized PnL within defined precision tolerances.
* The maintenance-margin condition.
* The balance transfer to the liquidator.

## User Result

After liquidation, the affected quote-token balance is zero and the affected positions no longer belong to the user. Balances in other quote-token pools remain separate.

Liquidation records are available through `GET /v1/position/liquidation` and the `SubaccountLiquidation` WebSocket stream.
