Aave Protocol V2
Go to file
2021-06-25 14:06:10 +02:00
.github/workflows ci: add env var usage 2021-05-10 18:02:05 +02:00
audits Fixed slight merge errors 2021-02-04 14:12:08 -05:00
contracts docs: fixed comments for isUserPermissionAdminValid 2021-06-25 14:06:10 +02:00
helpers add permissioned wethgateway getter 2021-06-07 13:26:55 +05:30
markets fix: finalized configuration of AAVE in Aave pro 2021-05-18 12:38:17 +02: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 Merge pull request #142 from shivgupt/feat/permissioned-market 2021-06-25 12:04:58 +02:00
test-suites feat:store permissionAdmin per user 2021-06-25 11:10:01 +02: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 Merged master 2020-09-04 10:27:32 +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 - Fix typo on whitepaper 2021-04-20 19:04:40 +02: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 Test envs 2020-11-20 16:01:00 +01:00
docker-compose.yml feat: Add DEFENDER env variables to docker yml 2021-05-17 14:36:39 +02: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 feat: updated deployment scripts for the permissioned market 2021-05-24 10:46:11 +02:00
helper-hardhat-config.ts feat: Improve readability of fork configuration. Support FORK_BLOCK_NUMBER enviroment variable. 2021-05-14 14:47:19 +02:00
LICENSE.md pretty print 2020-07-13 11:54:08 +03:00
package-lock.json feat:store permissionAdmin per user 2021-06-25 11:10:01 +02:00
package.json add pro kovan fork deploy 2021-06-07 11:26:57 +05:30
README.md update readme 2021-06-07 16:31:21 +05:30
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 feat: Add defender utils and use of signer 2021-05-17 14:35:21 +02:00
tslint.json pretty print 2020-07-13 11:54:08 +03:00

License: AGPL v3 Build pass

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

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) public {
    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

Kovan Aave Pro Deployment

You can deploy aave-pro with default configuration on kovan.

In markets/aave-pro/commons.ts make following changes:

  • Configure ProviderRegistryOwner and ReserveFactorTreasuryAddress

    Set owner to your deployer address with kovan funds.

    Set ReserveFactorTreasuryAddress to your team's wallet

    Notet: Script uses first address generated, from MNEMONIC provided in .env file, as the deployer.

    ProviderRegistryOwner: {
      [eEthereumNetwork.kovan]: '0xYourDeployerAddress',
      // Other network settings. You can leave them empty or same
    },
    
    ReserveFactorTreasuryAddress: {
      [eEthereumNetwork.kovan]: '0xYourDeployerAddress,
      // Other network settings. You can leave them empty or same
    },
    
  • Configure to deploy new ProviderRegistry and LendingPoolCollateralManager

    Set registry and collateral manager address to empty string to deploy new registry.

    ProviderRegistry: {
      [eEthereumNetwork.kovan]: '',
      // Other network settings. You can leave them empty or same
    },
    LendingPoolCollateralManager: {
      [eEthereumNetwork.kovan]: '',
    }
    
  • Configure to deploy/initialize PermissionedWethGateWay

    Set gateway address to empty string to deploy new.

    WethGateway: {
      [eEthereumNetwork.kovan]: '',
      // Other network settings. You can leave them empty or same
    },
    

Note: To configure aave pro market you can update markets/aave-pro/

Deploy Market

Using Docker

# 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 pro:kovan:full:migration

Without Docker

npm run pro: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');