βœ…Liquidation

Intro

Liquidation

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 liquidation

  • Step 4: liquidate

Code:

TestCompoundLiquidate.sol

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 protocolSeizeShareMantissa constant. 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

test-compound-liquidate.js

We supply WBTC and borrow DAI.

Test case:

Last updated

Was this helpful?