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
function start(uint256 amt) external {
// Write your code here
}- Call
flash.flashLoanwith this contract as the borrower, DAI as the token, the amount, and encodemsg.senderas data.
function onFlashLoan(
address initiator,
address token,
uint256 amt,
uint256 fee,
bytes calldata data
) external returns (bytes32) {
// Write your code here
}- Verify
msg.senderis the flash loan contract andinitiatoris this contract. - Decode
datato get the original caller and transfer thefeefrom them. - Approve the flash loan contract to pull back
amt + fee. - Return
FLASH_CALLBACK_SUCCESS.
forge test --fork-url $FORK_URL --match-path test/Flash.t.sol -vvv