> For the complete documentation index, see [llms.txt](https://docs.aftermath.finance/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.aftermath.finance/perpetuals/architecture/liquidations/adl.md).

# ADL

### Execution Process

The execution follows a hybrid off-chain calculation and on-chain execution model:

1. Ranking (Off-Chain): Profitable positions are ranked based on factors such as profitability, leverage, and position size.
2. Selection: The top-ranked positions are selected to cover the specific amount of bad debt (e.g., 2, 3, or 4 positions).
3. Execution (On-Chain): The bad debt position is closed against the selected counterparties.
   * Zero PnL Impact: The closure occurs at the counterparty's average entry price, ensuring the counterparty realizes 0 PnL on the trade.
   * Collateral: The bad debt position's collateral is distributed to the counterparties.

### Verifiability

While ADL execution is permissioned and depends on decided offchain factors, being fully onchain allows for the ADL result to remain fully verifiable.

#### Post-Execution Verification:

* All position data exists on-chain at the time of ADL.
* Anyone can reconstruct the position rankings as they existed at the moment of ADL.
* The community can verify that the admin selected the appropriate positions according to the published ranking criteria.
* Transparency: Index prices, position states, and all relevant data are immutably recorded on-chain.
* Accountability: While users cannot prevent ADL in real-time, any deviation from the published ranking algorithm is provably detectable after the fact. The community can reconstruct rankings and challenge improper executions.<br>

### Technical Implementation

The ADL ranking algorithm considers multiple factors:

* Profitability: Higher unrealized PnL increases ranking.
* Leverage: Higher effective leverage increases ranking.
* Position Size: Larger positions may be weighted in ranking.

For Profitable Positions: $$\text{ADL Ranking} = \text{PNL%} \times \text{Effective Leverage}$$

For Losing Positions: $$\text{ADL Ranking} = \frac{\text{PNL%}}{\text{Effective Leverage}}$$

Where: $$\text{PNL%} = \frac{\text{Unrealized PnL}}{|\text{Position Size} \times \text{Mark Price}|}$$

$$\text{Effective Leverage} = \frac{1}{\text{Position Margin Ratio}}$$

#### Socialized Losses Threshold Configuration

The bad debt thresholds that determine when to use socialized losses vs. ADL are configurable.

```
If bad_debt > max(M, open_interest × mark_price x α):
    Trigger ADL
Else:
    Use Socialized Losses
```

#### Verification Process

To verify ADL execution was proper:

* Query on-chain state at the block height of ADL execution.
* Reconstruct all position states (size, entry price, unrealized PnL, leverage).
* Apply the documented ranking algorithm.
* Compare the positions selected for ADL against the reconstructed ranking.
* Confirm the selected positions match the top-ranked positions for the required bad debt coverage.


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://docs.aftermath.finance/perpetuals/architecture/liquidations/adl.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
