• Stars
    star
    660
  • Rank 68,297 (Top 2 %)
  • Language
    TypeScript
  • License
    Other
  • Created almost 4 years ago
  • Updated 3 months ago

Reviews

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

Repository Details

Aave Protocol V2

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

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');

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

flashloan-box

A box containing all you need to get started with developing Aave v1 flash loans
Solidity
582
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