# Liquidation Engine

## Introduction&#x20;

Liquidations are extremely important for Ratio, they help us keep the protocol healthy and they will allow us to expand into accepting LP tokens with volatile underlying assets.

Ratio's liquidation engine involves real-time monitoring of the health of each user's vault, and relies on external information of the liquidity pool. Since LP tokens form the collateral for minting USDr, it is necessary to constantly check the value of the collateral based on the LP token price, which is a function of total value locked (TVL), volume, individual prices, and price slippage.

In general the market value of LP tokens is calculated by dividing the total liquidity in the pool by the number of LP tokens issued, i.e.,

$$
PX\_{LP} = \frac{\text{Total Value Locked}}{\text{Total LP Supply}}
$$

In liquidity pools, the starting or ideal balance of assets is in equal proportions. When a transaction takes place, the proportion of assets in the pool changes, as one asset is exchanged for another. This imbalance is short-lived as the constant product of liquidity pools incentivizes arbitrageurs to rebalance the pool. However, the Market Price of the LP token does not account for the risk of pool imbalance, which could occur from high volume transactions. For example, the Market Price of USDC-USDT might still be $1.04, while the pool is highly imbalanced to the proportion of 5 USDC : 1 USDT. To remedy this situation, we introduce the Fair Price of an LP token.

The calculation of Market Price and Fair Price is [pretty straightforward](https://cmichel.io/pricing-lp-tokens/), it just depends on the underlying prices $$P\_i$$, composition $$X\_i$$ and total supply of the LP token $$L$$. For a 2-Pool, the functional forms are:

$$
PX^{Market}*{LP} = \frac{P\_A X\_A + P\_B X\_B}{L} \quad \text{and} \quad PX^{Fair}*{LP} = 2 \frac{\sqrt{P\_A X\_A P\_B X\_B}}{L}
$$

In the following plot we show the almost fixed Market price of the LP token as the blue line while the amount of  USDC reserves in the pool ranges from 0.2 million to 23 million, causing the[ Fair Price](https://blog.alphaventuredao.io/fair-lp-token-pricing/) to take the shape of an inverted parabola.

<figure><img src="https://lh5.googleusercontent.com/dSS2sa_fzUjCE0XhQBEKkzQmHtL1p85AOu555kOmm17azuN_e9zWgQ2s81LgKFiGUMBKhIE7wEAvcwH01HrIuGxtXhpMSj1IdvnfomZNZ6lDd-j3mSsVVA_GTjlAaqc0IXdBcx3PXwrTede0Td-GiXt6Jf4oJ_b9zNa-RVDipEx_Ej8GxoE2LSBP" alt=""><figcaption></figcaption></figure>

With reference to the plot above, this imbalance can be very costly to the LP provider in a case where there is a large amount of USDC and it goes off its $1 peg.

To protect borrowers from the risk of imbalance, Ratio Finance has a dynamic risk management parameter to account for real-time risk of assets using fair pricing called **Delta**.


---

# Agent Instructions: 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:

```
GET https://docs.ratio.finance/liquidation-engine.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
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.
