# Liquidations (/docs/risex/trading/liquidations)

RISEx constantly computes a health factor for all accounts on the exchange to ensure accounts are not at risk for liquidation. To do this, the risk engine is calculating the Cross Health Factor defined below:

```
Cross Health Factor = Cross Margin Balance / Total Cross MM
```

As the Cross Health Factor approaches 1, the risk of liquidation increases. Traders should constantly be monitoring their Health Factor and top-up margin as their Cross Health Factor approaches 1.

***

## Liquidation Waterfall

RISEx follows a four-step liquidation waterfall to protect both the trader and the exchange's solvency. Below is the liquidation flow:

### Stage 1: Pre-liquidation mode

**Cross initial margin requirement > Account equity ≥ Cross maintenance margin requirement**

In this stage, the user can only perform actions that do not increase the maintenance margin or decrease the account equity. The user should reduce leverage or increase collateral to improve equity. Reduce-only orders are the only orders a user can place to reduce leverage.

### Stage 2: Partial liquidation

**Account equity ≤ Maintenance margin**

Once the account equity of a trader's account drops below their cross maintenance margin, the account enters into the partial liquidation mode. During partial liquidation, the following takes place in order:

1. Cancel all open orders for the user
2. Start liquidating the users' positions directly onto the book
   1. These liquidations are done via IoC orders at the zero price
3. Continue liquidating the positions fully until the trader's account goes above the maintenance margin

RISEx takes a 1% fee if the liquidations are executed at a price better than the 0 price. This 1% fee is sent to the XLP vault to help build the insurance fund over time.

Orders are sent as IoC orders at the zero price to ensure that the positions account equity to maintenance margin ratio stays the same or improves. The formula for Zero Price is as follows:

```
M_i = 1 / maintenanceMarginFactor_i
MMR = Σ(|size_j| × markPrice_j × M_j)    (positions only, excluding orders)
adjustment = |Cross Margin Balance| / (maintenanceMarginFactor_i × MMR)

If long:  Cross Zero Price = markPrice × (1 - adjustment)
If short: Cross Zero Price = markPrice × (1 + adjustment)

If account is bankrupt (Cross Margin Balance < 0):
  Cross Zero Price = 2 × markPrice - Cross Zero Price
  (flips the adjustment so RLP receives a favorable price)
```

### Stage 3: Full liquidation

**Account equity ≤ Close out maintenance requirement**

Once the account equity drops below the CMR (2/3 × Maintenance Margin), the account enters full liquidation mode, in which XLP takes over the positions. The XLP determines how to offload positions based on the threading strategies it is running. The XLP insurance fund follows a specific set of risk rules to ensure that the insurance fund does not take on too much risk within a certain time period and to ensure 1 pair can't compromise the total pool:

| Tier          | Max Position | Max Loss         |
| ------------- | ------------ | ---------------- |
| **BTC**       | 4.0x         | 0.30x (i.e. 30%) |
| **ETH**       | 3.0x         | 0.25x            |
| **Major**     | 1.0x         | 0.20x            |
| **Mid-Cap**   | 0.3x         | 0.15x            |
| **Small-Cap** | 0.1x         | 0.05x            |

```
loss_ratio = trailing_24hr_loss / current_equity
max_loss_saturation = min(loss_ratio / max_loss, 1.0)
effective_max_position = max_position × (1.0 - max_loss_saturation)
```

* `trailing_24hr_loss`: realized losses absorbed by the LV on this market over the last 24 hours, computed as an EMA.
* `current_equity`: current LV TVL, total value locked in the vault.
* `max_loss`: per-market daily loss cap as a **fraction of equity** (e.g., 0.3 = 30% of LV TVL).
* `max_position`: maximum gross notional the LV may hold on a market at any moment, as a **multiple of equity**.
* `effective_max_position`: the live, continuously-updated position ceiling for the market.

The effective max position formula creates a smooth, continuous throttle to bring down the total amount the liquidation vault can take based on the trailing 24h loss.

### Stage 4: ADL

**XLP free collateral \< Notional liquidated**

If the insurance fund cannot take on the position, the ADL process is initiated for the bankrupt position. ADL finds the most leveraged and profitable trade on the other side to make the bankrupt position whole.

```
PnL Percent      = (mark_price / entry_price)
Effective Leverage = (notional_position / account_value)
ADL Score        = PnL Percent × Effective Leverage
ADL Ranking      = rank(user.ADLScore) / TotalUserCount
```
