Health factor and liquidation

Health factor

For liquidation, the health factor is calculated instead of collateralization ratio.

Health factor=(LTV ratioi×Collateral Value in USDi)Borrowing Value in USDi\text{Health factor} = \frac{\sum (\text{LTV ratio}_i \times \text{Collateral Value in USD}_i)}{\sum \text{Borrowing Value in USD}_i}

The health factor is always bigger than or equal to the collateralization ratio because we take the liquidation threshold out, which always deflates the result of the equation. When they are equal, they will always be at the positive infinity.

Using the information from the table above, the health factor would be:

Health factor=(0.9×5)+(0.9×1)2+0.3=(4.5)+(0.9)2.3=5.42.3=2.347\text{Health factor} = \frac{(0.9 \times 5) + (0.9 \times 1)}{2 + 0.3} = \frac{(4.5) + (0.9)}{2.3} = \frac{5.4}{2.3} = 2.347

As shown, the health factor is greater than the collateralization ratio. The difference between the health factor and the collateralization ratio is a buffer for the borrowers. When the health factor goes below 1, a portion of debt may be liquidated to bring the user's health ratio back to 1.

Amount to liquidate

The liquidation must happen before the health factor drops 'too much' below 1. What would be 'too much'?: When the value of the collateral is so little that the health factor cannot be recovered back to 1 even after being liquidated. How do we derive the equation? We can use the same health factor equation we have above.

Let's give an example using the variables below, and let's say we are repaying USDC debt and taking away XRP collateral during liquidation:

Parameter
XRP
USDC

LTV ratio

80%

85%

Deposited amount in USD

5.4 USD

0.1 USD

Borrowed amount in USD

0.1 USD

5 USD

Liquidation bonus

6%

7%

Let's expand:

Health factor=(LTV ratioi×Collateral Value in USDi)Borrowing Value in USDi\text{Health factor} = \frac{\sum (\text{LTV ratio}_i \times \text{Collateral Value in USD}_i)}{\sum \text{Borrowing Value in USD}_i}

into

HFafter liquidation=LTVXRP×(CVXRPRVUSDC(1+LFXRP))+LTVUSDC×CVUSDCDVXRP+DVUSDCRVUSDC\text{HF}_{\text{after liquidation}} = \frac{LTV_{XRP} \times (CV_{XRP} - RV_{USDC}(1 + LF_{XRP})) + LTV_{USDC} \times CV_{USDC}}{DV_{XRP} + DV_{USDC} - RV_{USDC}}

where

  • HFafter liquidation\text{HF}_{\text{after liquidation}} is the health factor after liquidation takes place.

  • LTVasset\text{LTV}_{asset} is the LTV ratio of an asset.

  • CVasset\text{CV}_{asset} is the value of an asset deposited as a collateral in USD.

  • RVasset\text{RV}_{asset} is the value of repayment on the debt of an asset in USD.

  • DVasset\text{DV}_{asset} is the value of the debt of an asset in USD.

  • LFasset\text{LF}_{asset} is the liquidation bonus factor of an asset.

Notice that the equation is just an equation for the health factor in the post-liquidation state. LTVXRP×(CVXRPRVUSDC(1+LFXRP))LTV_{XRP} \times (CV_{XRP} - RV_{USDC}(1 + LF_{XRP})) represents the discounted collateral left after a part of XRP collateral including the liquidation bonus is captured in exchange for the USDC debt repayment by the liquidator. LTVUSDC×CVUSDCLTV_{USDC} \times CV_{USDC} represents the discounted USDC collateral. DVXRP+DVUSDCRVUSDCDV_{XRP} + DV_{USDC} - RV_{USDC} represents total debt after the USDC debt repayment.

Let's rearrange the equation so we can solve for RVUSDC\text{RV}_{USDC}:

HFafter liquidation=LTVXRP×(CVXRPRVUSDC(1+LFXRP))+LTVUSDC×CVUSDCDVXRP+DVUSDCRVUSDC\text{HF}_{\text{after liquidation}} = \frac{LTV_{XRP} \times (CV_{XRP} - RV_{USDC}(1 + LF_{XRP})) + LTV_{USDC} \times CV_{USDC}}{DV_{XRP} + DV_{USDC} - RV_{USDC}}
    HFafter liquidation(DVXRP)+HFafter liquidation(DVUSDC)HFafter liquidation(RVUSDC)\implies \text{HF}_{\text{after liquidation}}(DV_{XRP}) + \text{HF}_{\text{after liquidation}}(DV_{USDC}) - \text{HF}_{\text{after liquidation}}(RV_{USDC})
=(LTVXRP)(CVXRP)(RVUSDC)(LTVXRP)(1+LFXRP))+(LTVUSDC)(CVUSDC)= (LTV_{XRP})(CV_{XRP}) - (RV_{USDC})(LTV_{XRP})(1 + LF_{XRP})) + (LTV_{USDC})(CV_{USDC})
    (RVUSDC)(LTVXRP)(1+LFXRP))HFafter liquidation(RVUSDC\implies (RV_{USDC})(LTV_{XRP})(1 + LF_{XRP})) - \text{HF}_{\text{after liquidation}}(RV_{USDC}
=HFafter liquidation(DVXRP)HFafter liquidation(DVUSDC)+(LTVXRP)(CVXRP)+(LTVUSDC)(CVUSDC)= -\text{HF}_{\text{after liquidation}}(DV_{XRP}) -\text{HF}_{\text{after liquidation}}(DV_{USDC}) + (LTV_{XRP})(CV_{XRP}) + (LTV_{USDC})(CV_{USDC})
    (RVUSDC)((LTVXRP)(1+LFXRP))HFafter liquidation)\implies (RV_{USDC})((LTV_{XRP})(1 + LF_{XRP})) - \text{HF}_{\text{after liquidation}})
=HFafter liquidation(DVXRP+DVUSDC)+i(LTVi×CVi)= -\text{HF}_{\text{after liquidation}}(DV_{XRP} + DV_{USDC}) + \sum\limits_{i}{(LTV_i \times CV_i)}
    (RVUSDC)((LTVXRP)(1+LFXRP))HFafter liquidation)\implies (RV_{USDC})((LTV_{XRP})(1 + LF_{XRP})) - \text{HF}_{\text{after liquidation}})
=HFafter liquidation(iDVi)+i(LTVi×CVi)= -\text{HF}_{\text{after liquidation}}(\sum\limits_{i}{DV_i}) + \sum\limits_{i}{(LTV_i \times CV_i)}
    RVUSDC=HFafter liquidation(iDVi)+i(LTVi×CVi)((LTVXRP)(1+LFXRP))HFafter liquidation\implies RV_{USDC} = \frac{-\text{HF}_{\text{after liquidation}}(\sum\limits_{i}{DV_i}) + \sum\limits_{i}{(LTV_i \times CV_i)}}{((LTV_{XRP})(1 + LF_{XRP})) - \text{HF}_{\text{after liquidation}}}

Now that we have the equation ready, substitute the variables. We know that:

HFafter liquidation1\text{HF}_{\text{after liquidation}} \le 1

so let's substitute:

HFafter liquidation=1\text{HF}_{\text{after liquidation}} = 1

in this equation below:

RVUSDC=(1)(5+0.1)+(0.8×5.4+0.85×0.1)((0.8)(1+0.06))1RV_{USDC} = \frac{-(1)(5 + 0.1) + (0.8 \times 5.4 + 0.85 \times 0.1)}{((0.8)(1 + 0.06)) - 1}

We can run this Python script to confirm the result:

RV_axlUSDC_NUMERATOR = (-1 * (0.1 + 5) + (0.8 * 5.4 + 0.85 * 0.1))
RV_axlUSDC_DENOMINATOR = ((0.8) * (1 + 0.06) - 1)
RV_axlUSDC = RV_axlUSDC_NUMERATOR / RV_axlUSDC_DENOMINATOR

print(RV_axlUSDC_NUMERATOR)
print(RV_axlUSDC_DENOMINATOR)
print(RV_axlUSDC)

HF_CHECK_NUMERATOR = 0.8 * (5.4 - RV_axlUSDC * (1 + 0.06)) + 0.85 * 0.1
HF_CHECK_DENOMINATOR = 5.1 - RV_axlUSDC
HF = HF_CHECK_NUMERATOR/HF_CHECK_DENOMINATOR

print(HF_CHECK_NUMERATOR)
print(HF_CHECK_DENOMINATOR)
print(HF)

The console will print:

-0.6949999999999994 # RV_axlUSDC_NUMERATOR
-0.1519999999999999 # RV_axlUSDC_DENOMINATOR
4.57236842105263 # RV_axlUSDC
0.5276315789473698 # HF_CHECK_NUMERATOR
0.5276315789473696 # HF_CHECK_DENOMINATOR
1.0000000000000004 # HF

Disregarding the floating point number errors, we can confirm that we deduced the correct RVUSDCRV_{USDC}.

We can now generalize the equation further, from:

RVUSDC=HFafter liquidation(iDVi)+i(LTVi×CVi)((LTVXRP)(1+LFXRP))HFafter liquidationRV_{USDC} = \frac{-\text{HF}_{\text{after liquidation}}(\sum\limits_{i}{DV_i}) + \sum\limits_{i}{(LTV_i \times CV_i)}}{((LTV_{XRP})(1 + LF_{XRP})) - \text{HF}_{\text{after liquidation}}}

to:

RVrepaid asset=HFafter liquidation(iDVi)+i(LTVi×CVi)(LTVliquidated asset)(1+LF_liquidated asset)HFafter liquidationRV_{\text{repaid asset}} = \frac{-\text{HF}_{\text{after liquidation}}(\sum\limits_{i}{DV_i}) + \sum\limits_{i}{(LTV_i \times CV_i)}}{(LTV_{\text{liquidated asset}})(1 + LF\_{\text{liquidated asset}}) - \text{HF}_{\text{after liquidation}}}

However, in some cases where more than two assets are borrowed or deposited as collaterals, RVrepaid assetRV_{\text{repaid asset}} can exceed DVrepaid assetDV_{\text{repaid asset}} or CVliquidated assetCV_{\text{liquidated asset}}. In either case, repayment is not valid because repayment amount must be smaller than the debt and must be smaller than the captured collateral amount plus liquidation bonus in order for the liquidation to work.

In such cases, Final Repaid Amountrepaid asset\text{Final Repaid Amount}_{\text{repaid asset}} needs to be reduced down to min(RVrepaid asset,min(DVrepaid asset,CVliquidated asset1+LFliquidated asset))min(RV_{\text{repaid asset}}, min(DV_{\text{repaid asset}}, \frac{CV_{\text{liquidated asset}}}{1 + LF_{\text{liquidated asset}}})).

Below, we review all of the different possibilities for liquidation. We use USDC=repaid asset\text{USDC} = \text{repaid asset}, and XRP=liquidated asset\text{XRP} = \text{liquidated asset}.

  1. HF1\text{HF} \ge 1

Parameter
XRP
USDC

LTV ratio

80%

85%

Deposited amount in USD

5.4 USD

0.1 USD

Borrowed amount in USD

0.1 USD

0 USD

Liquidation bonus

6%

7%

In this case, there can't be a liquidation on this account, because the user's position is healthy:

HF=0.8×5.4+0.85×0.10.11\text{HF} = \frac{0.8 \times 5.4 + 0.85 \times 0.1}{0.1} \ge 1
  1. HF1\text{HF} \le 1 and RVrepaid asset=min(RVrepaid asset,min(DVrepaid asset,CVliquidated asset1+LFliquidated asset))RV_{\text{repaid asset}} = min(RV_{\text{repaid asset}}, min(DV_{\text{repaid asset}}, \frac{CV_{\text{liquidated asset}}}{1 + LF_{\text{liquidated asset}}}))

Parameter
XRP
USDC

LTV ratio

80%

85%

Deposited amount in USD

5.4 USD

0.1 USD

Borrowed amount in USD

0.1 USD

5 USD

Liquidation bonus

6%

7%

This is the example we used previously. HF is smaller than 1:

HF=0.8×5.4+0.85×0.10.1+5=4.4055.11\text{HF} = \frac{0.8 \times 5.4 + 0.85 \times 0.1}{0.1 + 5} = \frac{4.405}{5.1} \le 1

and RVrepaid asset=min(RVrepaid asset,min(DVrepaid asset,CVliquidated asset1+LFliquidated asset)RV_{\text{repaid asset}} = min(RV_{\text{repaid asset}}, min(DV_{\text{repaid asset}}, \frac{CV_{\text{liquidated asset}}}{1 + LF_{\text{liquidated asset}}}):

RVrepaid asset=HFafter liquidation(iDVi)+i(LTVi×CVi)((LTVliquidated asset)(1+LFliquidated asset))HFafter liquidationRV_{\text{repaid asset}} = \frac{-\text{HF}_{\text{after liquidation}}(\sum\limits_{i}{DV_i}) + \sum\limits_{i}{(LTV_i \times CV_i)}}{((LTV_{\text{liquidated asset}})(1 + LF_{\text{liquidated asset}})) - \text{HF}_{\text{after liquidation}}}
    RVUSDC=(1)(5+0.1)+(0.8×5.4+0.85×0.1)((0.8)(1+0.06))1\implies RV_{\text{USDC}} = \frac{-(1)(5 + 0.1) + (0.8 \times 5.4 + 0.85 \times 0.1)}{((0.8)(1 + 0.06)) - 1}
    RVUSDC=4.57236842105263...\implies RV_{\text{USDC}} = 4.57236842105263...
  1. HF1\text{HF} \le 1 and Final Repaid Amountrepaid asset=CVliquidated asset1+LFliquidated asset=min(RVrepaid asset,min(DVrepaid asset,CVliquidated asset1+LFliquidated asset)\text{Final Repaid Amount}_{\text{repaid asset}} = \frac{CV_{\text{liquidated asset}}}{1 + LF_{\text{liquidated asset}}} = min(RV_{\text{repaid asset}}, min(DV_{\text{repaid asset}}, \frac{CV_{\text{liquidated asset}}}{1 + LF_{\text{liquidated asset}}})

Put simply, this is when the amount of collateral to be liquidated isn't enough to bring HF back to 1, because the user has multiple collaterals.

Parameter
XRP
USDC

LTV ratio

80%

85%

Deposited amount in USD

3 USD

2.5 USD

Borrowed amount in USD

0.1 USD

5 USD

Liquidation bonus

6%

7%

Calculate HF first:

HF=0.8×3+0.85×2.50.1+5=4.5255.11\text{HF} = \frac{0.8 \times 3 + 0.85 \times 2.5}{0.1 + 5} = \frac{4.525}{5.1} \le 1
RVUSDC=(1)(5+0.1)+(0.8×3+0.85×2.5)((0.8)(1+0.06))1=3.7828947368421026...RV_{\text{USDC}} = \frac{-(1)(5 + 0.1) + (0.8 \times 3 + 0.85 \times 2.5)}{((0.8)(1 + 0.06)) - 1} = 3.7828947368421026...
3.7828947368421026...CVXRPCVXRP=33.7828947368421026... \ge CV_{XRP} \because CV_{XRP} = 3
3.7828947368421026...DVUSDCDVUSDC=53.7828947368421026... \le DV_{USDC} \because DV_{USDC} = 5
    Final Repaid AmountUSDC=CVXRP1+LFXRP=min(RVrepaid asset,min(DVrepaid asset,CVXRP1+LFXRP)\implies \text{Final Repaid Amount}_{USDC} = \frac{CV_{\text{XRP}}}{1 + LF_{\text{XRP}}} = min(RV_{\text{repaid asset}}, min(DV_{\text{repaid asset}}, \frac{CV_{\text{XRP}}}{1 + LF_{\text{XRP}}})

Therefore, we can only repay 31+LFXRP=31.06=2.830188679....\frac{3}{1 + LF_{\text{XRP}}} = \frac{3}{1.06} = 2.830188679.... in this scenario. HF will not be fully restored back to 1. The denominator exists to account for the liquidation bonus, so that we can get 3 USD as the value of captured collateral plus liquidation bonus, which is the maximum we can get from the deposited USDC collateral. But liquidation should still run regardless.

Here's HFafter liquidation\text{HF}_{\text{after liquidation}}:

HFafter liquidation=LTVXRP×(CVXRP(Final Repaid AmountUSDC)(1+LFXRP))+LTVUSDC×CVUSDCDVXRP+DVUSDCFinal Repaid AmountUSDC\text{HF}_{\text{after liquidation}} = \frac{LTV_{XRP} \times (CV_{XRP} - (\text{Final Repaid Amount}_{USDC})(1 + LF_{\text{XRP}})) + LTV_{USDC} \times CV_{USDC}}{DV_{XRP} + DV_{USDC} - \text{Final Repaid Amount}_{USDC}}
=0+LTVUSDC×CVUSDCDVXRP+DVUSDCFinal Repaid AmountUSDC= \frac{0 + LTV_{USDC} \times CV_{USDC}}{DV_{XRP} + DV_{USDC} - \text{Final Repaid Amount}_{USDC}}
=0+2.5×0.855.12.5=2.1252.6=0.81730769....= \frac{0 + 2.5 \times 0.85}{5.1 - 2.5} = \frac{2.125}{2.6} = 0.81730769....

Notice that we will need to liquidate the other collateral to fully recover the health factor back to 1.

  1. DVrepaid asset=min(RVrepaid asset,min(DVrepaid asset,CVliquidated asset1+LFliquidated asset)DV_{\text{repaid asset}} = min(RV_{\text{repaid asset}}, min(DV_{\text{repaid asset}}, \frac{CV_{\text{liquidated asset}}}{1 + LF_{\text{liquidated asset}}})

This is when the amount of debt to be repaid isn't enough to bring HF back to 1 because the user has multiple assets in debt, and this amount is smaller than the collateral that can be captured.

Parameter
XRP
USDC

LTV ratio

80%

85%

Deposited amount in USD

5.4 USD

0.1 USD

Borrowed amount in USD

2.5 USD

2.6 USD

Liquidation bonus

6%

7%

Again, we are repaying USDC and liquidating XRP:

RVUSDC=(1)(2.5+2.6)+(0.8×5.4+0.85×0.1)((0.8)(1+0.06))1RV_{\text{USDC}} = \frac{-(1)(2.5 + 2.6) + (0.8 \times 5.4 + 0.85 \times 0.1)}{((0.8)(1 + 0.06)) - 1}
=4.57236842105263...= 4.57236842105263...

This means we want to liquidate 4.57236842105263 USD equivalent of USDC, but we cannot because the user only has 2.6 USD worth of USDC in debt, thus:

Final repaid amountUSDC=min(4.57236842105263,min(2.6,5.41.06))\text{Final repaid amount}_{USDC} = min(4.57236842105263, min(2.6, \frac{5.4}{1.06}))
=2.6= 2.6

This won't recover HF back to 1. It will require another liquidation to be run to repay USDC and liquidate XRP.

Last updated