Skip to content

Commit

Permalink
Solve conflicts
Browse files Browse the repository at this point in the history
  • Loading branch information
kartojal committed Jan 12, 2021
2 parents 3d2a877 + 3782bfd commit 46c753c
Show file tree
Hide file tree
Showing 27 changed files with 833 additions and 343 deletions.
16 changes: 16 additions & 0 deletions .gitlab-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,19 @@ deploy-mainnet-fork:
after_script:
- docker-compose -p ${CI_JOB_ID} -f docker-compose.test.yml run contracts-env npm run ci:clean
- docker-compose -p ${CI_JOB_ID} -f docker-compose.test.yml down

certora-test:
stage: checks
image: python:latest
before_script:
- apt-get update || apt-get update
- apt-get install -y software-properties-common
- pip3 install certora-cli
- wget https://github.com/ethereum/solidity/releases/download/v0.6.12/solc-static-linux
- chmod +x solc-static-linux
- mv solc-static-linux /usr/bin/solc
- export PATH=$PATH:/usr/bin/solc/solc-static-linux
script:
- certoraRun specs/harness/StableDebtTokenHarness.sol:StableDebtTokenHarness --solc_args '--optimize' --verify StableDebtTokenHarness:specs/StableDebtToken.spec --settings -assumeUnwindCond,-b=4 --cache StableDebtToken --cloud
- certoraRun specs/harness/UserConfigurationHarness.sol --verify UserConfigurationHarness:specs/UserConfiguration.spec --solc_args '--optimize' --settings -useBitVectorTheory --cache UserConfiguration --cloud
- certoraRun contracts/protocol/tokenization/VariableDebtToken.sol:VariableDebtToken specs/harness/LendingPoolHarnessForVariableDebtToken.sol --solc_args '--optimize' --link VariableDebtToken:POOL=LendingPoolHarnessForVariableDebtToken --verify VariableDebtToken:specs/VariableDebtToken.spec --settings -assumeUnwindCond,-useNonLinearArithmetic,-b=4 --cache VariableDebtToken --cloud
119 changes: 94 additions & 25 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,16 @@
```
.///. .///. //. .// `/////////////-
`++:++` .++:++` :++` `++: `++:......---.`
`/+: -+/` `++- :+/` /+/ `/+/ `++.
/+/ :+/ /+: /+/ `/+/ /+/` `++.
-::/++::` /+: -::/++::` `/+: `++: :++` `++/:::::::::.
-:+++::-` `/+: --++/---` `++- .++- -++. `++/:::::::::.
-++. .++- -++` .++. .++. .++- `++.
.++- -++. .++. -++. -++``++- `++.
`++: :++` .++- :++` :+//+: `++:----------`
-/: :/- -/: :/. ://: `/////////////-
```

# 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.
Expand All @@ -8,13 +21,23 @@ Aave is a decentralized non-custodial liquidity markets protocol where users can

## Documentation

The documentation of Aave V2 is in the following [Aave V2 documentation](https://docs.aave.com/v2/-MJXUluJ2u1DiL-VU6MM) link. At the documentation you can learn more about the protocol, see the contract interfaces, integration guides and audits.
The documentation of Aave V2 is in the following [Aave V2 documentation](https://docs.aave.com/developers/v/2.0/) 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](https://docs.aave.com/developers/v/2.0/deployed-contracts/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](./aave-v2-whitepaper.pdf)

For getting the latest contracts addresses, please check the [Deployed contracts](https://docs.aave.com/v2/-MJXUluJ2u1DiL-VU6MM/deployed-contracts) page at the documentation to stay up to date.
## Audits

- MixBytes (16/09/2020 - 03/12/2020): [report](./audits/Mixbytes-aave-v2-03-12-2020.pdf)
- PeckShield (29/09/2020 - 03/12/2020) : [report](./audits/Peckshield-aave-v2-03-12-2020-EN.pdf) (Also available in Chinese in the same folder)
- CertiK (28/09/2020 - 02/12/2020): [report](./audits/Certik-aave-v2-03-12-2020.pdf)
- Consensys Diligence (09/09/2020 - 09/10/2020): [report](https://consensys.net/diligence/audits/2020/09/aave-protocol-v2/)
- Certora, formal verification (02/08/2020 - 29/10/2020): [report](./audits/Certora-FV-aave-v2-03-12-2020.pdf)

## Connect with the community

You can join at the [Discord](https://discord.com/invite/CJm5Jt3) channel or at the [Governance Forum](https://governance.aave.com/) for asking questions about the protocol or talk about Aave with other peers.
You can join at the [Discord](http://aave.com/discord) channel or at the [Governance Forum](https://governance.aave.com/) for asking questions about the protocol or talk about Aave with other peers.

## Setup

Expand Down Expand Up @@ -83,41 +106,87 @@ npm run aave:kovan:full:migration

### Mainnet fork deployment

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

```
# In one terminal, run a hardhat note with mainnet fork enabled
MAINNET_FORK=true npx hardhat node
docker-compose run contracts-env npm run aave:fork:main
```

# In another terminal, run docker-compose
docker-compose up
### Deploy Aave into a Mainnet Fork via console

# Open another tab or terminal
docker-compose exec contracts-env bash
You can deploy Aave into the Hardhat console in fork mode, to interact with the protocol inside the fork or for testing purposes.

# A new Bash terminal is prompted, connected to the container
npm run aave:fork:main
Run the console in Mainnet fork mode:

# Contracts are now deployed at Hardhat node with Mainnet fork.
```
docker-compose run contracts-env npm run console:fork
```

# You can interact with them via Hardhat console
MAINNET_FORK=true npx hardhat console
# Or your custom Hardhat task
MAINNET_FORK=true npx hardhat your-custom-task
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")
### Mainnet fork - Run the check list
// ERC20 token DAI Mainnet instance
const DAI = await contractGetters.getIErc20Detailed("0x6B175474E89094C44Da98b954EedeAC495271d0F");
For testing the deployment scripts for Mainnet release, you can run the check-list tests in a Mainnet fork using Hardhat built-in feature:
// 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');
```
# In another terminal, run docker-compose
docker-compose up

# Open another tab or terminal
docker-compose exec contracts-env bash
## Interact with Aave in Mainnet via console

# A new Bash terminal is prompted, connected to the container
npm run test:main:check-list
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');
```
Binary file added aave-v2-whitepaper.pdf
Binary file not shown.
Binary file added audits/Certik-aave-v2-03-12-2020.pdf
Binary file not shown.
Binary file added audits/Certora-FV-aave-v2-03-12-2020.pdf
Binary file not shown.
Binary file added audits/Mixbytes-aave-v2-03-12-2020.pdf
Binary file not shown.
Binary file added audits/PeckShield-aave-v2-03-12-2020-CN.pdf
Binary file not shown.
Binary file added audits/Peckshield-aave-v2-03-12-2020-EN.pdf
Binary file not shown.
29 changes: 15 additions & 14 deletions hardhat.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,25 +29,26 @@ const MAINNET_FORK = process.env.MAINNET_FORK === 'true';

// Prevent to load scripts before compilation and typechain
if (!SKIP_LOAD) {
['misc', 'migrations', 'dev', 'full', 'verifications', 'deployments'].forEach((folder) => {
const tasksPath = path.join(__dirname, 'tasks', folder);
fs.readdirSync(tasksPath)
.filter((pth) => pth.includes('.ts'))
.forEach((task) => {
require(`${tasksPath}/${task}`);
});
});
['misc', 'migrations', 'dev', 'full', 'verifications', 'deployments', 'helpers'].forEach(
(folder) => {
const tasksPath = path.join(__dirname, 'tasks', folder);
fs.readdirSync(tasksPath)
.filter((pth) => pth.includes('.ts'))
.forEach((task) => {
require(`${tasksPath}/${task}`);
});
}
);
}

require(`${path.join(__dirname, 'tasks/misc')}/set-bre.ts`);

const getCommonNetworkConfig = (networkName: eEthereumNetwork, networkId: number) => {
const net = networkName === 'main' ? 'mainnet' : networkName;
return {
url: ALCHEMY_KEY
? `https://eth-${
networkName === 'main' ? 'mainnet' : networkName
}.alchemyapi.io/v2/${ALCHEMY_KEY}`
: `https://${networkName === 'main' ? 'mainnet' : networkName}.infura.io/v3/${INFURA_KEY}`,
? `https://eth-${net}.alchemyapi.io/v2/${ALCHEMY_KEY}`
: `https://${net}.infura.io/v3/${INFURA_KEY}`,
hardfork: HARDFORK,
blockGasLimit: DEFAULT_BLOCK_GAS_LIMIT,
gasMultiplier: DEFAULT_GAS_MUL,
Expand All @@ -64,10 +65,10 @@ const getCommonNetworkConfig = (networkName: eEthereumNetwork, networkId: number

const mainnetFork = MAINNET_FORK
? {
blockNumber: 11361132,
blockNumber: 11608298,
url: ALCHEMY_KEY
? `https://eth-mainnet.alchemyapi.io/v2/${ALCHEMY_KEY}`
: `https://main.infura.io/v3/${INFURA_KEY}`,
: `https://mainnet.infura.io/v3/${INFURA_KEY}`,
}
: undefined;

Expand Down
4 changes: 2 additions & 2 deletions helpers/contracts-getters.ts
Original file line number Diff line number Diff line change
Expand Up @@ -323,8 +323,8 @@ export const getLendingPoolCollateralManager = async (address?: tEthereumAddress
await getFirstSigner()
);

export const getAddressById = async (id: string) =>
(await getDb().get(`${id}.${DRE.network.name}`).value()).address;
export const getAddressById = async (id: string): Promise<tEthereumAddress | undefined> =>
(await getDb().get(`${id}.${DRE.network.name}`).value())?.address || undefined;

export const getAaveOracle = async (address?: tEthereumAddress) =>
await AaveOracleFactory.connect(
Expand Down
Loading

0 comments on commit 46c753c

Please sign in to comment.