Skip to content

Latest commit

 

History

History
40 lines (28 loc) · 1.36 KB

File metadata and controls

40 lines (28 loc) · 1.36 KB

Repay Exercise

In this exercise, you'll learn how to repay DAI debt by interacting with Vat and DaiJoin contracts directly.

The starter code for this exercise is provided in foundry/src/exercises/Repay.sol

Solution is in foundry/src/solutions/Repay.sol

Hint: notes/code/DssProxyActions.sol

Task 1 - Repay partial debt

function repay(uint256 amt) external auth {
    // Write your code here
}
  • Transfer DAI from the caller, approve, and join it into the Vat via DaiJoin.
  • Calculate the debt to repay using Math.calcDebtToRepay.
  • Call vat.frob to wipe debt (zero dink, negative dart).
  • Refund any excess DAI remaining in the Vat back to the caller.

Task 2 - Repay all debt

function repayAll() external auth {
    // Write your code here
}
  • Calculate the exact DAI amount needed using Math.calcDaiToRepayAll.
  • Transfer DAI from the caller, approve, and join it into the Vat via DaiJoin.
  • Get the urn's art (total debt units) and call vat.frob with negative dart equal to -art.

Test

forge test --fork-url $FORK_URL --match-path test/Repay.t.sol -vvv