• Stars
    star
    582
  • Rank 76,801 (Top 2 %)
  • Language
    Solidity
  • License
    GNU Affero Genera...
  • Created over 4 years ago
  • Updated almost 2 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

A box containing all you need to get started with developing Aave v1 flash loans

Aave Flash Loan Truffle Box

This Truffle box comes with everything you need to start developing on flash loans

Installation and Setup

  1. Install Truffle globally, if not already installed.
    npm install -g truffle@latest
    
    Note: there is an issue with some older Truffle versions, e.g. v.5.1.25. This truffle box is confirmed working with the latest version (Truffle v5.1.32)
  2. Download the box.
    truffle unbox aave/flashloan-box
    
  3. Rename the env file to .env and edit the following values in the file:
    • Sign up for Infura (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).
    • 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.
  4. Ensure your ethereum account has some ETH to deploy the contract.
  5. In your terminal, navigate to your repo directory and install the dependencies (if not already done):
    npm install
    
  6. In the same terminal, replace NAME_OF_YOUR_NETWORK with either kovan, ropsten, or mainnet (depending on where you want to deploy the contract):
    truffle console --network NAME_OF_YOUR_NETWORK
    
  7. You are now connected to the network you chose. In the same terminal window:
    migrate --reset
    
  8. After a few minutes, your contract will be deployed on your chosen network.
    • 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.
    • See our documentation for token address and faucets.
  9. Call your contract's flashloan function within the truffle console, replacing RESERVE_ADDRESS with the reserve address found in our documentation:
    let f = await Flashloan.deployed()
    await f.flashloan(RESERVE_ADDRESS)
    
    • 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.
  10. If you've successfully followed the above steps, then congratulations, you've just made a flash loan.
    • For reference, here is an example transaction that followed the above steps on Ropsten using Dai.
    • For reference, here is an example transaction that followed the above steps on Ropsten using ETH.

Setup for cross protocol flash lending

If 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.

  1. Follow the steps 0 --> step 4 from above.

  2. (Install and) Run Ganache, preferably the CLI version

  3. In truffle-config.js, ensure the details for the development network match up with your running Ganache instance.

  4. To minimise set up steps with Aave's lending pools, use Ganache's fork feature. This will 'fork' mainnet into your Ganache instance. Open terminal, replace YOUR_INFURA_KEY (this is called Project ID in the Infra dashboard) in the following and run:

    ganache-cli --fork https://mainnet.infura.io/v3/YOUR_INFURA_KEY -i 1
    
  5. In a new terminal window in your repo directory, run:

    truffle console
    
  6. Migrate your Flashloan contract to your instance of Ganache with:

    migrate --reset
    
  7. After a few minutes, your contract will be deployed.

    • 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.
    • See our documentation for token address and faucets.
  8. 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 found in our documentation:

    let f = await Flashloan.deployed()
    await f.flashloan(RESERVE_ADDRESS)
    

    Be patient as your ganache instance works its magic.

  9. If your implementation is correct, then the transaction will succeed. If it fails/reverts, a reason will be given.

Known issues

No access to archive state errors

If 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.

Unable to debug executeOperation() with mainnet ganache fork

The Truffle debugger does not work too well with proxy / complex calls. You may find that the Truffle debugger returns an error such as:

TypeError: Cannot read property 'version' of undefined
at ...
  • 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).
  • Alternatively, see the 'Troubleshooting' link.

Troubleshooting

See our Troubleshooting Errors documentation.

Resources

More Repositories

1

aave-protocol

Aave Protocol Version 1.0 - Decentralized Lending Pools
HTML
1,384
star
2

aave-v3-core

This repository contains the core smart contracts of the Aave V3 protocol.
TypeScript
866
star
3

protocol-v2

Aave Protocol V2
TypeScript
660
star
4

interface

An open source interface for the decentralized liquidity protocol Aave
TypeScript
407
star
5

gho-core

Solidity
252
star
6

governance-crosschain-bridges

This repo contains the crosschain governance bridges used for the aave markets deployed across different networks
TypeScript
165
star
7

aave-js

TypeScript
142
star
8

aave-v3-periphery

TypeScript
132
star
9

aave-ui

[DEPRECATED] An open source interface for the decentralized liquidity protocol Aave
TypeScript
127
star
10

aave-utilities

TypeScript
119
star
11

protocol-subgraphs

The code of Aave protocol subgraphs
TypeScript
116
star
12

aip

Aave Improvement Proposals
JavaScript
103
star
13

code-examples-protocol

Solidity
103
star
14

gho-bug-bounty

81
star
15

aave-stake-v2

V2 implementation of the stkAAVE token
Solidity
57
star
16

aave-v3-deploy

TypeScript
45
star
17

governance-v2

TypeScript
44
star
18

Aave-Vault

ERC4626 vault to hold aToken assets
Solidity
42
star
19

ethlondon-flash

Flashy workshop
JavaScript
34
star
20

aave-sandbox

Sandbox of Aave Markets that replicates a forked production environment. The environment is envisioned for testing liquidations or other integrations.
TypeScript
31
star
21

aptos-aave-v3

Aave's V3 Protocol on Aptos
Move
26
star
22

bug-bounty

25
star
23

aave-token

AAVE token implementation
TypeScript
23
star
24

aave-token-v2

V2 implementation of the AAVE token
TypeScript
21
star
25

safety-module

Safety module implementation for the Aave protocol
TypeScript
20
star
26

aave-ui-caching-server

Thin and simple data caching layer to give better "real time" experience to users of https://github.com/aave/aave-ui
TypeScript
18
star
27

aave-ui-kit

Package containing UI components and helpers used on https://github.com/aave/aave-ui
TypeScript
18
star
28

price-aggregators

Solidity
14
star
29

governance-v2-subgraph

TypeScript
12
star
30

incentives-controller

TypeScript
12
star
31

liquidation-ui

TypeScript
11
star
32

branding-assets

Repository for the Aave protocol branding assets
11
star
33

docs-v3

11
star
34

upgradeable-configurable-rights-pool

Solidity
10
star
35

dlp-docs-abi

Initial documentation of the Decentralized Lending Pool protocol developed by Aave
JavaScript
10
star
36

aave-asset-listing

TypeScript
8
star
37

gho-aip

Solidity
8
star
38

markets-adapters

Adapters smart contracts used on different Aave markets
TypeScript
6
star
39

loanlord-bot

An open source bot that interacts with the ETHLend platform.
JavaScript
5
star
40

aave-api

Misc Aave api
TypeScript
5
star
41

risk-v3

5
star
42

tests-protocol-v2-sigmaprime

Test suite for the Aave Protocol v2 by SigmaPrime during their audit
Solidity
5
star
43

docs-gho

JavaScript
4
star
44

aip-uploader

JavaScript
4
star
45

docs-v2

4
star
46

split-croatia-workshop

https://aave.github.io/split-croatia-workshop/
JavaScript
4
star
47

proto-governance

Aave governance based on LEND token
TypeScript
4
star
48

gho-public

Gho is a collateral backed stablecoin that can be natively integrated into the Aave Protocol
4
star
49

aavenomics

4
star
50

aave-grants-update-and-renewal

TypeScript
4
star
51

arc-timelock

Set of contracts for Timelock Executor of ARC Market
TypeScript
3
star
52

v3-retroactive-funding

V3 Retroactive funding proposal
TypeScript
3
star
53

walletconnect-connector

Fork of @web3-react/walletconnect-connector from deprecated V6 version of uniswap/web3-react, which is still in use on aave/interface
TypeScript
3
star
54

aave-addresses

TypeScript
3
star
55

gho-brand-assets

3
star
56

pinata-action

Github action to upload & pin to pinata
JavaScript
2
star
57

cloudflare-update-action

JavaScript
2
star
58

aave-gitcoin-hackaton-2019

2
star
59

governance-delegation-subgraph

TypeScript
1
star
60

token-wrappers

Foundry-based repository for testing token wrappers for supply/withdrawal from v3 Pools
Solidity
1
star
61

genesis-migration

Misc smart contracts used on the LEND -> AAVE migration
TypeScript
1
star