Skip to content

Instantly share code, notes, and snippets.

@ajb413
Created March 16, 2022 19:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ajb413/45ba3ac84bab5037e9e9cadba99a052b to your computer and use it in GitHub Desktop.
Save ajb413/45ba3ac84bab5037e9e9cadba99a052b to your computer and use it in GitHub Desktop.
A Compound v2 Liquidation Example

A borrower account has Dai collateral and an open WBTC borrow. It has become under-collateralized. I can seize their cDai by liquidating their WBTC borrow. I have a balance of WBTC. I call approve on cWBTC and pass the amount of WBTC that I want to repay (or greater). I then call liquidateBorrow on cWBTC and pass the borrower address, amount of WBTC to liquidate, and the cDai address. If the liquidation is successful, my WBTC balance goes down and my cDai balance goes up. If I redeem that cDai immediately, the underlying Dai is worth the same amount as the amount of WBTC I gave up plus 8%.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment