Liquidations and Deleveraging

This page describes mechanics behind Marginly's liquidations and deleveraging

As we described in the Trading section the maximum leverage available both for longs and shorts in Marginly is 20x. So what happens when the user's position exceeds this threshold? There are two possible outcomes which we describe below.

Liquidations

Liquidation flow is straightforward: sell liquidating position's collateral on Uniswap, use proceeds to repay liquidating position's debt, put excess (if any) back to the pool. With such an approach the entire pool enjoys an additional stream of revenues in a form of 5% penalty ( 1 / max leverage) on every position liquidation that occurs in the system. To better understand the mechanics, let's consider a simple example we've seen before when we discussed trading mechanics:

UserETH+ETH-USDC+USDC-NetPosLeverage

1

1

0

0

0

1000

1

2

0

1

1100

0

100

11

User 2 sold short 1 ETH at a price of 1000 USDC. If the price of ETH starts to rise, the user's leverage will grow and at some critical price the user's position will become eligible for liquidation. It's easy to calculate the liquidation price given the maximum allowable leverage, collateral value and quantity of ETH being short:

Pliqshort=usdc_collateral_valueQethshortLmax1LmaxP_{liq}^{short} = \frac{usdc\_collateral\_value}{Q_{eth}^{short}}\cdot \frac{L_{max} - 1}{L_{max}}

Liquidation price for a long position is calculated symmetrically as follows:

Pliqlong=usdc_debt_valueQethlongLmaxLmax1P_{liq}^{long} = \frac{usdc\_debt\_value}{Q_{eth}^{long}}\cdot \frac{L_{max} }{L_{max}-1}

Going back to the example above and using the first formula above, we can calculate that if the price of ETH rises to 1045 USDC, user's position will have leverage of 20x and will get liquidated. Assuming there is no slippage and swap fees are absent, the system will automatically (see reinit() method description for details) sell user's collateral and buy 1100 worth of ETH at current price of 1045 USDC netting ~ 1.0526 ETH in return. The new pool state will now look like this:

UserETH+ETH-USDC+USDC-NetPosLeverage

1

1.0526

0

0

0

1100

1

2

0

0

0

0

0

N/A

Of-course, in real life we can't neglect slippage, swap fees, and balance price vs. swap price discrepancies. So the penalty pool earns will be less than 5% almost surely. To control the slippage on liquidations, Marginly will revert transactions if the swap will result in price movement of more than 5% (margin call slippage parameter).

Deleveraging

Liquidity may be absent in the pool when it all gets borrowed. Following situation may occur: the protocol needs to liquidate the borrower but there is not enough collateral in the pool to sell. To address such situations Marginly introduces no-liquidation approach called Deleveraging. Deleveraging is a process of reduction of the total leverage of the pool (collateral and debt) when there is a liquidity shortage.

A slightly more sophisticated example is required to provide a clear explanation, let's assume the pool composition looks the following way:

UserETH+ETH-USDC+USDC-NetPosLeverage

1

4

0

0

3000

1000

4

2

2

0

0

0

2000

1

3

0

5

6000

0

1000

6

4

0

1

6000

0

5000

1.2

Note, that all of the ETH brought by users 1 and 2 was sold by users 3 and 4. Now let's say the ETH price drops up until the point where the system needs to liquidate user 1. the protocol will need to sell user's 4 ETH, but it won't be able to do so as there is no ETH in the pool! This is exactly where deleveraging comes into play.

Instead of selling something that the pool doesn't have, the protocol will close user's position against the opposing side: short sellers 3 and 4 will have their debts and collaterals reduced by 4 ETH and 3000 USDC proportional to their debt values: let's take user 3 as an example and calculate his new debt and collateral values after deleveraging:

new_debt=old_debteth_liquidatedtotal_eth_debtold_debt=54651.667ETHnew\_debt = old\_debt - \frac{eth\_liquidated}{total\_eth\_debt}\cdot old\_debt=5-\frac{4}{6}\cdot5 \approx 1.667 \quad \text{ETH}
new_collateral=old_collateralusdc_liquidatedtotal_eth_debtold_debt=3500USDCnew\_collateral = old\_collateral - \frac{usdc\_liquidated}{total\_eth\_debt}\cdot old\_debt= 3500 \quad \text{USDC}

The entire pool will look the following way after deleveraging:

UserETH+ETH-USDC+USDC-NetPosLeverage

1

0

0

0

0

0

N/A

2

2

0

0

0

2000

1

3

0

1.667

3500

0

1833.33

1.0909

4

0

0.333

5500

0

5166.67

1.0645

Note the following:

  • There is still no ETH liquidity inside the pool after deleveraging.

  • Total net position of short sellers increased by the net position of the liquidated user.

  • Leverage of short sellers decreased.

  • Lender (user 2) didn't see his net position increase (unlike after regular liquidation).

The implementation of deleveraging mechanics will use deleverage coefficients to modify total collateral and total debt inside the pools. This is similar to how collateral and debt aggregates are modified by collateral coefficients and accrued rates (see pool variables section for details).

Bottom line: Marginly introduces a novel deleveraging mechanics in relation to pool's liquidity management. This mechanics complements traditional liquidations and allows to close out users' positions even when there is liquidity shortage inside the pool. In next versions of Marginly protocol we might consider ditching liquidations altogether and resorting only to deleveraging when liquidating user positions.

Last updated