# ADL

Auto-deleveraging (ADL) is the last line of defense employed by the risk engine to protect the solvency of markets. It kicks in when a position cannot be closed above the bankruptcy price and the insurance fund is insufficient to cover the capital shortfall. On Bluefin, a permissioned ADL worker automatically deleverages bankrupt positions against top-of-queue positions from the opposite side. The ADL queue prioritizes closing the most profitable and high-leverage traders to reduce counterparty risk.

## ADL Queue

The objective of the ADL queue is to pick out accounts with the highest PnL percentage and leverage. For each market, $$i$$ be the individual position for which the ADL Score is calculated.&#x20;

$$\text{PNL Score}*i = \begin{cases} \frac{ P*{index/oracle}-P\_{pos} }{P\_{pos}} \quad &\text{if Long}, \\\ \frac{-( P\_{index/oracle}-P\_{pos}) }{P\_{pos}} \quad &\text{if Short}.\end{cases}$$

$$\text{PNL Score}\_i = \max (0, \text{PNL Score}\_i)$$

$$\text{Leverage Score}\_i = 1/\text{max}(\text{MMR},\text{MR})$$

$$\text{ADL Score}\_i = \text{PNL Score}\_i \times \text{Leverage Score}\_i$$

$$\text{ADL Quantile} = rank(user.\text{ADL Score}\_i)/\text{Total User Count}$$
