Uni-V2 RAI/ETH Savior Details

The Uniswap V2 RAI/ETH savior allows users to deposit LP shares to protect their safe. Upon a liquidation attempt from a keeper, the savior will withdraw all RAI and ETH liquidity from Uniswap.

The saviour will then repay as much RAI debt as possible. If the Safe's collateralization ratio is still not at the target ratio that the Safe owner picked, the saviour will also add more ETH in the Safe. The keeper that triggered the saviour will then take a flat fee as reward for saving the Safe.

The savior does not guarantee that the safe will be saved. The user needs to make sure that they deposited enough LP tokens so the saviour can both reward the keeper that saves their position and bring the Safe's collateralization ratio to the target they picked.

Minimum Savior Balance Formula

In order to derive the formula for the minimum LP balance that can bring your Safe to a target CRatio, we use the following variables:

Liquidation price: PliqP_{liq}

Redemption price: PRPP_{RP}

Asset price: PRAIP_{RAI} , PETHP_{ETH}

Debt: DD

Collateral: CC

Accumulated rate: AccA_{cc}

CRatio: RliqR_{liq} , RtargR_{targ}

Uniswap reserves: SRAIS_{RAI} , SETHS_{ETH}

We first need to use the liquidation price formula:

Pliq=DAccRliqPrpCP_{liq} = \frac{DA_{cc}R_{liq}P_{rp}}{C}

​From here, we can reorganize the formula to isolate the debt and collateral amount in the Safe. We also use the Target Rebalance CRatio RtarR_{tar} instead of the liquidation CRatio to know how much debt and collateral we need to save the Safe:

CsavDsave=AccRtarPrpPliq\frac{C_{sav}}{D_{save}} = \frac{A_{cc}R_{tar}P_{rp}}{P_{liq}}

The savior will be withdrawing an amount of LP tokens to get DlpD_{lp} RAI and CLPC_{LP} ETH. Therefore, the resulting debt and collateral in safe after and adding the proceeds from the LP shares will be:

Csave=C+ClpC_{save} = C + C_{lp}

Dsave=CDlpD_{save} = C - D_{lp}

Which then gives us:

C+ClpDDlp=AccRtarPrpPliq\frac{C + C_{lp}}{D - D_{lp}} = \frac{A_{cc}R_{tar}P_{rp}}{P_{liq}}

We will reuse this formula later. We now need to model the Uniswap pool dynamics to calculate the amount DlpD_{lp} and CLPC_{LP} we would get from the savior LP shares at a given liquidation price. We start from the standard xy=k assumptions:

{Klp=SETHSRAISETHPETH=SRAIPRAI\begin{cases}K_{lp} = S_{ETH}S_{RAI}\\ S_{ETH}P_{ETH}= S_{RAI}P_{RAI}\end{cases}
    KLPPETH=SRAI2PRAI\iff K_{LP} P_{ETH} = {S_{RAI}}^2 P_{RAI}
    SRAI=KLPPETHPRAI\iff S_{RAI} = \sqrt{K_{LP} \frac{P_{ETH}}{P_{RAI}}}

And similarly:

    SETH=KLPPRAIPETH\iff S_{ETH} = \sqrt{K_{LP} \frac{P_{RAI}}{P_{ETH}}}

We can now replace these results in the equation from the liquidation price:

C+KLPPRAIPETHDKLPPETHPRAI=AccRtarPrpPliq\frac{C + \sqrt{K_{LP} \frac{P_{RAI}}{P_{ETH}}} }{D - \sqrt{K_{LP} \frac{P_{ETH}}{P_{RAI}}} } = \frac{A_{cc}R_{tar}P_{rp}}{P_{liq}}

We simplify the equation using p=PRAIPETH p = \frac{P_{RAI}}{P_{ETH}} and j=AccRtarPrpPliqj=\frac{A_{cc}R_{tar}P_{rp}}{P_{liq}}

C+KLPpDKLP1p=j\frac{C + \sqrt{K_{LP}p } }{D - \sqrt{K_{LP} \frac{1}{p}} } = j

We need to solve the equation above for KLPK_{LP}.

Using Wolfram Alpha:

​We get 2 solutions:

{KLP1=p(CDj)2(jp)2KLP2=p(CDj)2(j+p)2\begin{cases} K_{LP1}= \frac{p(C-Dj)^2}{(j-p)^2} \\ K_{LP2}= \frac{p(C-Dj)^2}{(j+p)^2} \end{cases}

Since we're interested in the minimum balance of LP tokens, we keep only the second solution that will give the lowest balance possible. Last, we need to take the square root of KLPK_{LP} ​to get the actual LP token balance:

BalLPmin=p(CDj)2(j+p)2=pCDjj+pBal_{LPmin}= \sqrt{\frac{p(C-Dj)^2}{(j+p)^2}}=\sqrt{p} \frac{|C-Dj|}{j+p}

Done! To that we have to add the flat $2000 keeper fee. Below is a calculation example:

The spreadsheet is available here, make a copy to test your own parameters: https://docs.google.com/spreadsheets/d/1flg9LidXvxcAInw4-AtDCEFniMGoZg9fIgm-x36S3CA/edit#gid=0

Last updated