Skip to content

Latest commit

 

History

History
42 lines (31 loc) · 1.22 KB

File metadata and controls

42 lines (31 loc) · 1.22 KB

Flash Loan Exercise

In this exercise, you'll learn how to execute a DAI flash loan using the DssFlash contract (ERC3156).

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

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

Task 1 - Initiate flash loan

function start(uint256 amt) external {
    // Write your code here
}
  • Call flash.flashLoan with this contract as the borrower, DAI as the token, the amount, and encode msg.sender as data.

Task 2 - Flash loan callback

function onFlashLoan(
    address initiator,
    address token,
    uint256 amt,
    uint256 fee,
    bytes calldata data
) external returns (bytes32) {
    // Write your code here
}
  • Verify msg.sender is the flash loan contract and initiator is this contract.
  • Decode data to get the original caller and transfer the fee from them.
  • Approve the flash loan contract to pull back amt + fee.
  • Return FLASH_CALLBACK_SUCCESS.

Test

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