# Liquidations

## Overview

Our perpetual futures exchange implements a robust multi-tier liquidation and loss mitigation system. This system is designed to handle underwater positions effectively while minimizing the impact on healthy traders. A liquidator is free to sell on the book or keep the liquidated size. There is a natural incentive to sell the liquidated size on the book if the book price is better than liquidation price.

The mitigation strategy consists of a progressive cascade of three layers:<br>

* Insurance Fund Coverage
* Socialized Losses
* Auto-Deleveraging (ADL)

A position enters liquidation when its margin falls below the **maintenance margin requirement**. This can occur due to:

* **Price Movement:** Index prices move against the user, causing unrealized PnL to erode the margin.
* **Funding Payments:** Continuous funding payments reduce the collateral balance if the account is on the paying side of the funding rate.

{% hint style="info" %}
Withdrawing collateral and placing orders are prevented by the system if they would breach initial margin requirements, so these actions cannot trigger a liquidation themselves.
{% endhint %}

***

## Mark Price

To prevent market manipulation (such as "wicking" on a single exchange), we use Mark Price rather than the spot Index Price to determine liquidation triggers.\
Where:

$$
{\small
\begin{align\*}
\small
& MarkPrice = median(BookPrice, FundingPrice, TwapPrice)
\\
\&FundingPrice = IndexPrice + \text{TWA}*{1m,1h}(BookPrice - IndexPrice) \cdot \frac{\text{Time to next Funding}}{ \text{Funding Period}}
\\
\&TwapPrice = IndexPrice + \text{TWA}*{5s,5m}(BookPrice - IndexPrice)
\end{align\*}
}%
$$

*(See the* [*Funding*](https://docs.aftermath.finance/perpetuals/architecture/funding) *chapter for the detailed definition of TWAs.)*

***

## Liquidation Process

Our system is **permissionless**, allowing any participant to liquidate underwater positions. The process prioritizes position health over total closure.&#x20;

### Partial Liquidations

Unlike full position closures, we only liquidate the minimum amount necessary to restore the position to a healthy state.

* **Target:** The position is reduced until it returns to the market's **maximum initial leverage** (e.g., restoring a 50x position back to 10x).
* **Liquidator Role:** Liquidators acquire the liquidated portion immediately at Mark Price. They can choose to close it immediately or hold it based on their strategy.

### Liquidation Fees

Three fees are charged during a liquidation event to incentivize keepers and protect the protocol. These are configurable by the market admin:

| Fee Type               | Recipient      | Description                                                                                                                                              |
| ---------------------- | -------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------- |
| **Liquidation Fee**    | Liquidator     | Incentive for performing the liquidation.                                                                                                                |
| **Force Cancel Fee**   | Liquidator     | Charged if the liquidated position had pending orders. It is a % of the canceled size, typically an order of magnitude smaller than the Liquidation Fee. |
| **Insurance Fund Fee** | Insurance Fund | A smaller fee that flows directly into the market's isolated insurance fund.                                                                             |

***

## System Safety & Bad Debt

If liquidations cannot occur fast enough and a position falls below its bankruptcy price (generating bad debt), the system resolves this through a progressive cascade of **three safety layers**.

{% stepper %}
{% step %}

### Layer 1: Insurance Fund

This is the first line of defense.

* **Structure:** Each market maintains its own **isolated** insurance fund.
* **Source:** Funded by the Insurance Fund Fee collected during healthy liquidations.
* **Impact:** If the bad debt can be covered by this fund, **no other traders are affected**.
  {% endstep %}

{% step %}

### Layer 2: Socialized Losses

If the insurance fund is depleted but bad debt is within defined thresholds, losses are **socialized**.

* **Mechanism:** Losses are distributed proportionally among all positions on the opposite side of the market.
* **Settlement:** The bad debt amount is added to the **funding rates** of opposing positions and settled when those positions trigger a funding update.
* **Safety:** Thresholds ensure that a healthy position cannot take on so much socialized debt that it becomes liquidatable itself.
  {% endstep %}

{% step %}

### Layer 3: Auto-Deleveraging (ADL)

As a final measure for extreme scenarios (e.g., suspected manipulation or massive insolvency), the system triggers **Auto-Deleveraging (ADL)**.

* **Mechanism:** Highly profitable positions on the opposing side are automatically closed against the underwater position at the bankruptcy price.
* **Why ADL?** It is considered more equitable to close specific, highly profitable positions rather than socializing massive losses across the entire market.
* **Permissioned Model:** ADL is executed by the market admin to allow for judgment in complex edge cases, though the results are verifiable on-chain.

{% hint style="info" %}
Note: The market admin can trigger ADL at any moment, even if socialized losses are an option, to ensure market health.
{% endhint %}

For full details, see the [ADL](https://docs.aftermath.finance/perpetuals/architecture/liquidations/adl) documentation.

{% endstep %}
{% endstepper %}
