Aave Protocol V2
Go to file
2021-03-29 17:10:35 +02:00
audits Fixed slight merge errors 2021-02-04 14:12:08 -05:00
contracts Added incentives information to UI data provider contract 2021-03-29 17:10:35 +02:00
helpers Merge branch 'master' into feat/light-deployments 2021-03-05 13:46:11 +01:00
markets Update LP oracles with latest oracle interface 2021-03-10 18:17:52 +01:00
modules/tenderly Added permit domain check test. Update typechain and typescript to support new ethers 5 generated typings. Updated ethers to support _TypedDataEncoder for domain hash. 2020-11-18 19:18:02 +01:00
specs Solve conflicts 2021-01-12 12:11:03 +01:00
tasks Support fork connection. 2021-03-03 12:25:10 +01:00
test-suites Merge branch 'master' into feat/light-deployments 2021-03-05 13:46:11 +01:00
.editorconfig - Added mocha __setup script with snapshotting 2020-06-08 14:03:40 +02:00
.giatattributes Added gitattributes 2020-11-11 11:19:59 +01:00
.gitignore - Unexcluded types/ on contracts libraries 2020-11-24 15:11:02 +01:00
.gitlab-ci.yml Merge branch '201-add-protocol-contracts-to-the-npm' into 'master' 2021-01-29 09:13:42 +00:00
.prettierignore pretty print 2020-07-13 11:54:08 +03:00
.prettierrc Updated require message errors with constant string numbers to reduce gas 2020-08-25 15:51:52 +02:00
.solcover.js Fixed coverage random failing tests. Added coverage network and minimal config. 2020-09-09 21:24:20 +02:00
aave-v2-whitepaper.pdf - Added v2 whitepaper 2020-12-03 14:27:12 +01:00
buidler.config.ts Updated solidity version 2020-11-20 11:41:58 +01:00
coverage.json Renamed ChainlinkProxyPriceProvider to AaveOracle 2020-11-17 10:24:24 +01:00
docker-compose.test.yml Support fork connection. 2021-03-03 12:25:10 +01:00
docker-compose.yml Support fork connection. 2021-03-03 12:25:10 +01:00
Dockerfile Updated solidity version 2020-11-20 11:41:58 +01:00
Dockerfile_test add test step to CI 2020-08-21 15:11:01 +03:00
hardhat.config.ts Update LP oracles with latest oracle interface 2021-03-10 18:17:52 +01:00
helper-hardhat-config.ts Added configs to support tenderly fork rpcs. Added new price feeds addresses. Fix owner signer issues. 2021-03-02 17:21:04 +01:00
LICENSE.md pretty print 2020-07-13 11:54:08 +03:00
package-lock.json Merge branch 'master' into feat/light-deployments 2021-03-05 13:46:11 +01:00
package.json Support fork connection. 2021-03-03 12:25:10 +01:00
README.md Fixed slight merge errors 2021-02-04 14:12:08 -05:00
runStableTokenCLI.sh Updated runners 2020-12-03 18:17:31 +02:00
runUserConfigCLI.sh Updated runners 2020-12-03 18:13:22 +02:00
runVariableTokenCLI.sh Updated runners 2020-12-03 18:17:31 +02:00
test-wallets.js Initial fix 2020-08-19 16:10:08 +02:00
test.log Rolled back PVE002, added further optimization 2020-10-22 18:59:15 +02:00
tsconfig.json Separated tests by market. Replace WETH9 symbol with 'UniWETH' to run test-lp. WIP. 2021-02-06 22:10:29 -05:00
tslint.json pretty print 2020-07-13 11:54:08 +03:00

        .///.                .///.     //.            .//  `/////////////-
       `++:++`              .++:++`    :++`          `++:  `++:......---.`
      `/+: -+/`            `++- :+/`    /+/         `/+/   `++.
      /+/   :+/            /+:   /+/    `/+/        /+/`   `++.
  -::/++::`  /+:       -::/++::` `/+:    `++:      :++`    `++/:::::::::.
  -:+++::-`  `/+:      --++/---`  `++-    .++-    -++.     `++/:::::::::.
   -++.       .++-      -++`       .++.    .++.  .++-      `++.
  .++-         -++.    .++.         -++.    -++``++-       `++.
 `++:           :++`  .++-           :++`    :+//+:        `++:----------`
 -/:             :/-  -/:             :/.     ://:         `/////////////-

Aave Protocol v2

This repository contains the smart contracts source code and markets configuration for Aave Protocol V2. The repository uses Docker Compose and Hardhat as development enviroment for compilation, testing and deployment tasks.

What is Aave?

Aave is a decentralized non-custodial liquidity markets protocol where users can participate as depositors or borrowers. Depositors provide liquidity to the market to earn a passive income, while borrowers are able to borrow in an overcollateralized (perpetually) or undercollateralized (one-block liquidity) fashion.

Documentation

The documentation of Aave V2 is in the following Aave V2 documentation link. At the documentation you can learn more about the protocol, see the contract interfaces, integration guides and audits.

For getting the latest contracts addresses, please check the Deployed contracts page at the documentation to stay up to date.

A more detailed and technical description of the protocol can be found in this repository, here

Audits

  • MixBytes (16/09/2020 - 03/12/2020): report
  • PeckShield (29/09/2020 - 03/12/2020) : report (Also available in Chinese in the same folder)
  • CertiK (28/09/2020 - 02/12/2020): report
  • Consensys Diligence (09/09/2020 - 09/10/2020): report
  • Certora, formal verification (02/08/2020 - 29/10/2020): report
  • SigmaPrime (January 2021): report

Connect with the community

You can join at the Discord channel or at the Governance Forum for asking questions about the protocol or talk about Aave with other peers.

Getting Started

You can install @aave/protocol-v2 as an NPM package in your Hardhat, Buidler or Truffle project to import the contracts and interfaces:

npm install @aave/protocol-v2

Import at Solidity files:

import {ILendingPool} from "@aave/protocol-v2/contracts/interfaces/ILendingPool.sol";

contract Misc {

  function deposit(address pool, address token, address user, uint256 amount) {
    ILendingPool(pool).deposit(token, amount, user, '0');
    {...}
  }
}

The JSON artifacts with the ABI and Bytecode are also included into the bundled NPM package at artifacts/ directory.

Import JSON file via Node JS require:

const LendingPoolV2Artifact = require('@aave/protocol-v2/artifacts/contracts/protocol/lendingpool/LendingPool.sol/LendingPool.json');

// Log the ABI into console
console.log(LendingPoolV2Artifact.abi)

Setup

The repository uses Docker Compose to manage sensitive keys and load the configuration. Prior any action like test or deploy, you must run docker-compose up to start the contracts-env container, and then connect to the container console via docker-compose exec contracts-env bash.

Follow the next steps to setup the repository:

  • Install docker and docker-compose
  • Create an enviroment file named .env and fill the next enviroment variables
# Mnemonic, only first address will be used
MNEMONIC=""

# Add Alchemy or Infura provider keys, alchemy takes preference at the config level
ALCHEMY_KEY=""
INFURA_KEY=""


# Optional Etherscan key, for automatize the verification of the contracts at Etherscan
ETHERSCAN_KEY=""

# Optional, if you plan to use Tenderly scripts
TENDERLY_PROJECT=""
TENDERLY_USERNAME=""

Markets configuration

The configurations related with the Aave Markets are located at markets directory. You can follow the IAaveConfiguration interface to create new Markets configuration or extend the current Aave configuration.

Each market should have his own Market configuration file, and their own set of deployment tasks, using the Aave market config and tasks as a reference.

Test

You can run the full test suite with the following commands:

# In one terminal
docker-compose up

# Open another tab or terminal
docker-compose exec contracts-env bash

# A new Bash terminal is prompted, connected to the container
npm run test

Deployments

For deploying Aave Protocol V2, you can use the available scripts located at package.json. For a complete list, run npm run to see all the tasks.

Kovan deployment

# In one terminal
docker-compose up

# Open another tab or terminal
docker-compose exec contracts-env bash

# A new Bash terminal is prompted, connected to the container
npm run aave:kovan:full:migration

Mainnet fork deployment

You can deploy Aave Protocol v2 in a forked Mainnet chain using Hardhat built-in fork feature:

docker-compose run contracts-env npm run aave:fork:main

Deploy Aave into a Mainnet Fork via console

You can deploy Aave into the Hardhat console in fork mode, to interact with the protocol inside the fork or for testing purposes.

Run the console in Mainnet fork mode:

docker-compose run contracts-env npm run console:fork

At the Hardhat console, interact with the Aave protocol in Mainnet fork mode:

// Deploy the Aave protocol in fork mode
await run('aave:mainnet')

// Or your custom Hardhat task
await run('your-custom-task');

// After you initialize the HRE via 'set-DRE' task, you can import any TS/JS file
run('set-DRE');

// Import contract getters to retrieve an Ethers.js Contract instance
const contractGetters = require('./helpers/contracts-getters'); // Import a TS/JS file

// Lending pool instance
const lendingPool = await contractGetters.getLendingPool("LendingPool address from 'aave:mainnet' task");

// You can impersonate any Ethereum address
await network.provider.request({ method: "hardhat_impersonateAccount",  params: ["0xb1adceddb2941033a090dd166a462fe1c2029484"]});

const signer = await ethers.provider.getSigner("0xb1adceddb2941033a090dd166a462fe1c2029484")

// ERC20 token DAI Mainnet instance
const DAI = await contractGetters.getIErc20Detailed("0x6B175474E89094C44Da98b954EedeAC495271d0F");

// Approve 100 DAI to LendingPool address
await DAI.connect(signer).approve(lendingPool.address, ethers.utils.parseUnits('100'));

// Deposit 100 DAI
await lendingPool.connect(signer).deposit(DAI.address, ethers.utils.parseUnits('100'), await signer.getAddress(), '0');

Interact with Aave in Mainnet via console

You can interact with Aave at Mainnet network using the Hardhat console, in the scenario where the frontend is down or you want to interact directly. You can check the deployed addresses at https://docs.aave.com/developers/deployed-contracts.

Run the Hardhat console pointing to the Mainnet network:

docker-compose run contracts-env npx hardhat --network main console

At the Hardhat console, you can interact with the protocol:

// Load the HRE into helpers to access signers
run("set-DRE")

// Import getters to instance any Aave contract
const contractGetters = require('./helpers/contracts-getters');

// Load the first signer
const signer = await contractGetters.getFirstSigner();

// Lending pool instance
const lendingPool = await contractGetters.getLendingPool("0x7d2768dE32b0b80b7a3454c06BdAc94A69DDc7A9");

// ERC20 token DAI Mainnet instance
const DAI = await contractGetters.getIErc20Detailed("0x6B175474E89094C44Da98b954EedeAC495271d0F");

// Approve 100 DAI to LendingPool address
await DAI.connect(signer).approve(lendingPool.address, ethers.utils.parseUnits('100'));

// Deposit 100 DAI
await lendingPool.connect(signer).deposit(DAI.address, ethers.utils.parseUnits('100'), await signer.getAddress(), '0');