GEB Docs
  • Introduction to GEB
  • Community Resources
  • FLX Mechanics
  • FAQ
  • RAI
    • RAI Use-Cases
    • Multi-chain RAI
    • RAI Integrations
  • The Money God League
    • Intro to The League
  • Ungovernance
    • Governance Minimization Guide
  • Risk
    • GEB Risks
    • PID Failure Modes & Responses
  • Incentives
    • RAI Uniswap V2 Mint + LP Incentives Program
    • RAI Uniswap V3 Mint + LP Incentives Program (Inactive)
    • FLX Staking
    • RAI / ETH Uniswap V3 Oracle LP Incentives Program
  • Contract Variables Translation
    • Core Contracts Naming Transition
    • Governance Contracts Naming Transition
    • SAFE Management Contract Naming Transition
  • System Contracts
    • Core Module
      • SAFE Engine
      • Liquidation Engine
      • Accounting Engine
    • Auction Module
      • English Collateral Auction House
      • Fixed Discount Collateral Auction House
      • Increasing Discount Collateral Auction House
      • Debt Auction House
      • Surplus Auction House
    • Oracle Module
      • Oracle Relayer
      • Medianizer
        • DSValue
        • Governance Led Median
        • Chainlink Median
        • Uniswap V2 Median
      • FSM
        • Oracle Security Module
        • Dampened Security Module
        • FSM Governance Interface
    • Token Module
      • Token Adapters
      • System Coin
      • Protocol Token
      • Protocol Token Authority
      • Protocol Token Printing Permissions
    • Money Market Module
      • Tax Collector
    • Sustainability Module
      • Stability Fee Treasury
      • FSM Wrapper
      • Increasing Treasury Reimbursement
      • Mandatory Fixed Treasury Reimbursement
      • Increasing Reward Relayer
    • Automation Module
      • Collateral Auction Throttler
      • Single Spot Debt Ceiling Setter
      • ESM Threshold Setter
    • Governance Module
      • DSPause
    • Shutdown Module
      • Global Settlement
      • ESM
  • Proxy Infrastructure
    • DSProxy
    • Proxy Registry
  • Helper Contracts
    • SAFE Manager
  • GEB.js
    • Getting Started
    • Global Settlement Guide
    • API Reference
      • Geb
      • Safe
      • Proxy Actions
      • Geb Admin
  • APIs
    • API Endpoints
  • Pyflex
    • Getting Started
      • Configuration
      • GEB Basics
    • SAFE Management
      • Opening a SAFE
      • Closing a SAFE
    • Numerics
  • Keepers
    • Keeper Overview
    • Collateral Auction Keeper
      • Running in Docker
      • Running on a Host
      • Liquidations & Collateral Auctions
      • Collateral Auction Flash Swaps
    • Debt Auction Keeper
      • Running in Docker
      • Running on a Host
    • Staked Token Auction Keeper
      • Running in Docker
      • Running on a Host
    • Surplus Auction Keeper
      • Running in Docker
      • Running on a Host
    • Bidding Models
  • Liquidation Protection
    • SAFE Protection
    • Liquidation Protection Guide
    • Uni-V2 RAI/ETH Savior Details
    • Curve V1 Savior Details
Powered by GitBook
On this page

Was this helpful?

  1. Liquidation Protection

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}Pliq​

Redemption price: PRPP_{RP}PRP​

Asset price: PRAIP_{RAI}PRAI​ , PETHP_{ETH}PETH​

Debt: DDD

Collateral: CCC

Accumulated rate: AccA_{cc}Acc​

CRatio: RliqR_{liq}Rliq​ , RtargR_{targ}Rtarg​

Uniswap reserves: SRAIS_{RAI}SRAI​ , SETHS_{ETH}SETH​

We first need to use the liquidation price formula:

Pliq=DAccRliqPrpCP_{liq} = \frac{DA_{cc}R_{liq}P_{rp}}{C}Pliq​=CDAcc​Rliq​Prp​​

​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}Rtar​ 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}} Dsave​Csav​​=Pliq​Acc​Rtar​Prp​​

The savior will be withdrawing an amount of LP tokens to get DlpD_{lp}Dlp​ RAI and CLPC_{LP}CLP​ 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}Csave​=C+Clp​

Dsave=C−DlpD_{save} = C - D_{lp}Dsave​=C−Dlp​

Which then gives us:

C+ClpD−Dlp=AccRtarPrpPliq\frac{C + C_{lp}}{D - D_{lp}} = \frac{A_{cc}R_{tar}P_{rp}}{P_{liq}} D−Dlp​C+Clp​​=Pliq​Acc​Rtar​Prp​​

We will reuse this formula later. We now need to model the Uniswap pool dynamics to calculate the amount DlpD_{lp}Dlp​ and CLPC_{LP}CLP​ 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}{Klp​=SETH​SRAI​SETH​PETH​=SRAI​PRAI​​
  ⟺  KLPPETH=SRAI2PRAI\iff K_{LP} P_{ETH} = {S_{RAI}}^2 P_{RAI}⟺KLP​PETH​=SRAI​2PRAI​
  ⟺  SRAI=KLPPETHPRAI\iff S_{RAI} = \sqrt{K_{LP} \frac{P_{ETH}}{P_{RAI}}} ⟺SRAI​=KLP​PRAI​PETH​​​

And similarly:

  ⟺  SETH=KLPPRAIPETH\iff S_{ETH} = \sqrt{K_{LP} \frac{P_{RAI}}{P_{ETH}}} ⟺SETH​=KLP​PETH​PRAI​​​

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

C+KLPPRAIPETHD−KLPPETHPRAI=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}} D−KLP​PRAI​PETH​​​C+KLP​PETH​PRAI​​​​=Pliq​Acc​Rtar​Prp​​

We simplify the equation using p=PRAIPETH p = \frac{P_{RAI}}{P_{ETH}}p=PETH​PRAI​​ and j=AccRtarPrpPliqj=\frac{A_{cc}R_{tar}P_{rp}}{P_{liq}}j=Pliq​Acc​Rtar​Prp​​

C+KLPpD−KLP1p=j\frac{C + \sqrt{K_{LP}p } }{D - \sqrt{K_{LP} \frac{1}{p}} } = jD−KLP​p1​​C+KLP​p​​=j

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

Using Wolfram Alpha:

​We get 2 solutions:

{KLP1=p(C−Dj)2(j−p)2KLP2=p(C−Dj)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}{KLP1​=(j−p)2p(C−Dj)2​KLP2​=(j+p)2p(C−Dj)2​​

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}KLP​ ​to get the actual LP token balance:

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

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

PreviousLiquidation Protection GuideNextCurve V1 Savior Details

Last updated 3 years ago

Was this helpful?

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
solve(Divide[c+Sqrt[k*p],d-Sqrt[k*(Divide[1,p])]]=j,k) - Wolfram|AlphaWolfram_Alpha
Logo