Section 7 of 18

Build
+15 Lynx

CToken: Withdraw (redeem)

Key takeaway: Compound V2's redeem() and redeemUnderlying() functions burn cTokens to withdraw the underlying token. They route through the Comptroller's redeemAllowed hook to verify that withdrawing won't push the user underwater on any outstanding borrows. The exchange-rate-driven math is symmetric with mint(), so the same accrueInterest-first pattern keeps the rate fresh. If the user has no borrows the check passes trivially; otherwise it depends entirely on accountLiquidity.

What You Are Building

You are adding the withdrawal mechanism to the CToken. Users burn cTokens to get their underlying tokens back. This is the reverse of mintFresh() from the previous section, but with a critical difference: the Comptroller can block the withdrawal if those cTokens are backing a borrow.

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 15 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