TAGS

flashloan-box

CREATED

UPDATED

STARS

INSTALL

...

REPOSITORY
GitHub Download
Please wait: Fetching readme...

b"# Aave Flash Loan Truffle Box\n\nThis Truffle box comes with everything you need to start [developing on flash loans](https://docs.aave.com/developers/tutorials/performing-a-flash-loan/...-with-truffle)\n\n## Installation and Setup\n\n0. Install Truffle globally, if not already installed.\n ```\n npm install -g truffle@latest\n ```\n Note: there is an issue with some older Truffle versions, e.g. v.5.1.25.\n **This truffle box is confirmed working with the latest version (Truffle v5.1.32)**\n1. Download the box.\n ```\n truffle unbox aave/flashloan-box\n ```\n2. Rename the `env` file to `.env` and edit the following values in the file:\n - Sign up for [Infura](https://infura.io/) (or a similar provider) and replace `YOUR_INFURA_KEY` with an API key for your project (this is called Project ID in the Infra dashboard).\n - Replace `YOUR_ACCOUNT_KEY_FOR_DEPLOYMENT` with the private key of the ethereum account you will be using to deploy the contracts. This account will become the `owner` of the contract.\n3. Ensure your ethereum account has some ETH to deploy the contract.\n4. In your terminal, navigate to your repo directory and install the dependencies (if not already done):\n ```\n npm install\n ```\n5. In the same terminal, replace `NAME_OF_YOUR_NETWORK` with either `kovan`, `ropsten`, or `mainnet` (depending on where you want to deploy the contract):\n ```\n truffle console --network NAME_OF_YOUR_NETWORK\n ```\n6. You are now connected to the network you chose. In the same terminal window:\n ```\n migrate --reset\n ```\n7. After a few minutes, your contract will be deployed on your chosen network.\n - If you have not added any profitable logic to `Flashloan.sol` line 23, then you will need to fund your contract with the desired asset.\n - See our [documentation](https://docs.aave.com/developers/developing-on-aave/deployed-contract-instances#reserves-assets) for token address and faucets.\n8. Call your contract's flashloan function within the truffle console, replacing `RESERVE_ADDRESS` with the [reserve address](https://docs.aave.com/developers/developing-on-aave/deployed-contract-instances#reserves-assets) found in our documentation:\n ```\n let f = await Flashloan.deployed()\n await f.flashloan(RESERVE_ADDRESS)\n ```\n - if the above operation takes an unreasonably long time or timesout, try `CTRL+C` to exit the Truffle console, repeat step 5, then try this step agin. You may need to wait a few blocks before your node can 'see' the deployed contract.\n9. If you've successfully followed the above steps, then congratulations, you've just made a flash loan.\n - For reference, here is an [example transaction](https://ropsten.etherscan.io/tx/0x7877238373ffface4fb2b98ca4db1679c64bc2c84c7754432aaab994a9b51e17) that followed the above steps on `Ropsten` using **Dai**.\n - For reference, here is an [example transaction](https://ropsten.etherscan.io/tx/0x32eb3e03e00803dc19a7d2edd0a0a670756fbe210be81697be312518baeb16cc) that followed the above steps on `Ropsten` using **ETH**.\n\n## Setup for cross protocol flash lending\nIf you are working across protocols, such as using the flash loaned amount on another #DeFi protocol, sometimes it is easier to fork mainnet and use each protocol's production contracts and production ERC20 tokens.\n\n1. Follow the steps 0 --> step 4 from above.\n2. (Install and) Run [Ganache](https://www.trufflesuite.com/ganache), preferably the [CLI version](https://github.com/trufflesuite/ganache-cli)\n3. In `truffle-config.js`, ensure the details for the `development` network match up with your running Ganache instance.\n4. To minimise set up steps with Aave's lending pools, use Ganache's fork feature. This will 'fork' mainnet into your Ganache instance.\n Open terminal, replace `YOUR_INFURA_KEY` (this is called Project ID in the Infra dashboard) in the following and run:\n ```\n ganache-cli --fork https://mainnet.infura.io/v3/YOUR_INFURA_KEY -i 1\n ```\n5. In a new terminal window in your repo directory, run:\n ```\n truffle console\n ```\n6. Migrate your Flashloan contract to your instance of Ganache with:\n ```\n migrate --reset\n ```\n7. After a few minutes, your contract will be deployed.\n - If you have not added any profitable logic to `Flashloan.sol` line 23, then you will need to fund your contract with the desired asset.\n - See our [documentation](https://docs.aave.com/developers/developing-on-aave/deployed-contract-instances#reserves-assets) for token address and faucets.\n8. Your contract is now deployed on your local Ganache, which is mirroring mainnet. Call your contract's flashloan function within the truffle console, replacing `RESERVE_ADDRESS` with the [reserve address](https://docs.aave.com/developers/developing-on-aave/deployed-contract-instances#reserves-assets) found in our documentation:\n ```\n let f = await Flashloan.deployed()\n await f.flashloan(RESERVE_ADDRESS)\n ```\n Be patient as your ganache instance works its magic.\n\n9. If your implementation is correct, then the transaction will succeed. If it fails/reverts, a reason will be given.\n\n## Known issues\n### No access to archive state errors\nIf you are using Ganache to fork a network, then you may have issues with the blockchain archive state every 30 minutes. This is due to your node provider (i.e. Infura) only allowing free users access to 30 minutes of archive state. To solve this, upgrade to a paid plan, or simply restart your ganache instance and redploy your contracts.\n\n### Unable to debug executeOperation() with mainnet ganache fork\nThe Truffle debugger does not work too well with proxy / complex calls. You may find that the Truffle debugger returns an error such as:\n```\nTypeError: Cannot read property 'version' of undefined\nat ...\n```\n- In this case you can try calling your `executeOperation()` function directly, instead of having Aave's `LendingPool` contract invoke the function. This will allow you to debug the function directly, however you will need to supply the relevant parameters (e.g. `_amount`, `_fee`, `_reserve`, etc).\n- Alternatively, see the 'Troubleshooting' link.\n\n\n## Troubleshooting\nSee our [Troubleshooting Errors](https://docs.aave.com/developers/tutorials/troubleshooting-errors) documentation.\n\n# Resources\n - Our [flash loan documentation](https://docs.aave.com/developers/tutorials/performing-a-flash-loan)\n - Our [Developer Discord channel](https://discord.gg/CJm5Jt3)\n"