diff --git a/docs/guides/arbitrageurs/flash-loans.md b/docs/guides/arbitrageurs/flash-loans.md index a7941dde..c7ce41ec 100644 --- a/docs/guides/arbitrageurs/flash-loans.md +++ b/docs/guides/arbitrageurs/flash-loans.md @@ -9,18 +9,19 @@ Since the Vault holds all tokens for all pools, the consolidated token balances ```solidity pragma solidity ^0.7.0; -import "@balancer-labs/v2-vault/contracts/interfaces/IVault.sol"; -import "@balancer-labs/v2-vault/contracts/interfaces/IFlashLoanRecipient.sol"; +/* +* "@balancer-labs/v2-interfaces/contracts" is refering to "balancer-v2-monorepo/pkg/interfaces/contracts" +*/ +import {IVault} from "@balancer-labs/v2-interfaces/contracts/vault/IVault.sol"; +import {IFlashLoanRecipient} from "@balancer-labs/v2-interfaces/contracts/vault/IFlashLoanRecipient.sol"; +import {IERC20} from "@balancer-labs/v2-interfaces/contracts/solidity-utils/openzeppelin/IERC20.sol"; + contract FlashLoanRecipient is IFlashLoanRecipient { - IVault private constant vault = "0xBA12222222228d8Ba445958a75a0704d566BF2C8"; + IVault private constant vault = IVault(0xBA12222222228d8Ba445958a75a0704d566BF2C8); - function makeFlashLoan( - IERC20[] memory tokens, - uint256[] memory amounts, - bytes memory userData - ) external { - vault.flashLoan(this, tokens, amounts, userData); + function makeFlashLoan(IERC20[] memory tokens, uint256[] memory amounts, bytes memory userData) external { + vault.flashLoan(this, tokens, amounts, userData); } function receiveFlashLoan( @@ -29,8 +30,23 @@ contract FlashLoanRecipient is IFlashLoanRecipient { uint256[] memory feeAmounts, bytes memory userData ) external override { - require(msg.sender == vault); - ... + require(msg.sender == address(vault)); + + // This contract now has the funds requested. + + // Your logic goes here... + + /* + At the end of your logic above, this contract owes + the flashloaned amounts + feeAmounts. + Therefore ensure your contract has enough to repay these amounts. + */ + + // Return loan + for (uint256 i = 0; i < tokens.length; i++) { + tokens[i].transfer(address(vault), amounts[i] + feeAmounts[i]); + } } } + ```