Uni-V2 RAI/ETH Savior Details
Last updated
Last updated
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.
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:
Redemption price:
Asset price: ,
Debt:
Collateral:
Accumulated rate:
CRatio: ,
Uniswap reserves: ,
We first need to use the liquidation price formula:
Which then gives us:
And similarly:
We can now replace these results in the equation from the liquidation price:
Using Wolfram Alpha:
We get 2 solutions:
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
From here, we can reorganize the formula to isolate the debt and collateral amount in the Safe. We also use the Target Rebalance CRatio instead of the liquidation CRatio to know how much debt and collateral we need to save the Safe:
The savior will be withdrawing an amount of LP tokens to get RAI and ETH. Therefore, the resulting debt and collateral in safe after and adding the proceeds from the LP shares will be:
We will reuse this formula later. We now need to model the Uniswap pool dynamics to calculate the amount and we would get from the savior LP shares at a given liquidation price. We start from the standard xy=k assumptions:
We simplify the equation using and
We need to solve the equation above for .
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 to get the actual LP token balance: