> 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

ADL is a permissioned function, meaning only the market admin (or delegated parties) can execute it.

### 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.
   * Eligibility: Funding is settled on the bad debt position first. ADL runs only if its equity (collateral value plus unrealized PnL at the mark price, with no haircut) is zero or negative. Otherwise the call does nothing.
   * Closing the bad debt position: Its open orders are cancelled, then it is fully closed at the mark price. The realized PnL is added to its collateral.
   * Distributing the shortfall: The position's remaining collateral (zero or negative) is split among the counterparties using weights set by the ADL admin. The weights must sum to exactly 100%, and any rounding remainder goes to the first counterparty.
   * Closing counterparties: Each counterparty has funding settled, then its assigned size is closed at the mark price. It realizes PnL against its own entry price, then absorbs its share of the bad debt from its collateral as a separate, additional deduction.
   * Closed markets: ADL on a closed market uses the market's closing prices for both the mark price and the collateral price.

### Verifiability

ADL execution is permissioned and depends on offchain factors, but because it runs onchain, anyone can verify the result.

#### 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.
