β Liquidation
Intro
In this section, we simulate a borrow->liquidation scenario:
Step 1: supply
Step 2: borrow max
Step 3: wait few blocks and let
borrowed_balance > supplied_balance * collateral_factor-> leads to liquidationStep 4: liquidate
Code:
Setup
Set Comptroller, borrowed token and borrowed cToken:
Close Factor
What is "close factor"? Quote from doc:
The percent, ranging from 0% to 100%, of a liquidatable accountβs borrow that can be repaid in a single liquidate transaction. If a user has multiple borrowed assets, the closeFactor applies to any single borrowed asset, not the aggregated value of a userβs outstanding borrowing.
Close factor can be queried via comptroller.closeFactorMantissa():
Liquidation Incentive
What is "liquidation incentive"? Quote from doc:
The additional collateral given to liquidators as an incentive to perform liquidation of underwater accounts. A portion of this is given to the collateral cToken reserves as determined by the seize share. The seize share is assumed to be 0 if the cToken does not have a
protocolSeizeShareMantissaconstant. For example, if the liquidation incentive is 1.08, and the collateralβs seize share is 1.028, liquidators receive an extra 5.2% of the borrowerβs collateral for every unit they close, and the remaining 2.8% is added to the cTokenβs reserves.
Liquidation incentive can be queried via comptroller.liquidationIncentiveMantissa():
Liquidate
To compute the amount of the collateral that we can liquidate, call comptroller .liquidateCalculateSeizeTokens():
Finally let's implement the high-level liquidate() function:
Test
We supply WBTC and borrow DAI.
Test case:
Last updated
Was this helpful?
