Section 16 of 18

Build
+20 Lynx

Liquidation: CToken Side

Key takeaway: Compound V2's liquidateBorrow() and seize() functions execute the atomic liquidation flow: the liquidator repays a portion of the debt (capped at the 50% close factor), the protocol seizes equivalent collateral plus the 8% bonus, and ownership transfers all in one transaction. The state-update ordering matters intensely; swap the seize and the repay updates and the liquidator can drain more than they paid. Forks routinely break this ordering during refactors and ship vulnerable code.

What You Are Building

You are building the CToken execution side of liquidation. The previous section built the policy (when liquidation is allowed, how many tokens to seize). This section builds the mechanism: accrue interest on both markets, repay the borrower's debt, calculate the seize amount, and transfer collateral from the borrower to the liquidator with a protocol cut.

This is the most complex CToken operation because it involves TWO markets simultaneously. The liquidator repays debt in the borrowed market (say cUSDC) and receives collateral from a different market (say cETH). The Comptroller's cross-market view is what makes this possible.

Your Code

Solution.sol
Solidity
Loading editor...

Requirements

Write your implementation, then click Run Tests. Tests execute on the server.

Sign up free — keep reading + earn 20 Lynx

Zealynx Academy is free. Track your progress, earn Lynx, and climb the leaderboard.

Sign up free to continue

Already have an account? Log in