Merge branch '191-fix-readme-steps-fork' into 'master'

Resolve "Fix README.md: steps for mainnet fork"

Closes #191

See merge request aave-tech/protocol-v2!213
This commit is contained in:
Ernesto Boado 2021-01-07 15:25:44 +00:00
commit e2072c708d
3 changed files with 86 additions and 40 deletions

View File

@ -106,41 +106,87 @@ npm run aave:kovan:full:migration
### Mainnet fork deployment ### 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 docker-compose run contracts-env npm run aave:fork:main
MAINNET_FORK=true npx hardhat node ```
# In another terminal, run docker-compose ### Deploy Aave into a Mainnet Fork via console
docker-compose up
# Open another tab or terminal You can deploy Aave into the Hardhat console in fork mode, to interact with the protocol inside the fork or for testing purposes.
docker-compose exec contracts-env bash
# A new Bash terminal is prompted, connected to the container Run the console in Mainnet fork mode:
npm run aave:fork:main
# 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 At the Hardhat console, interact with the Aave protocol in Mainnet fork mode:
MAINNET_FORK=true npx hardhat console
# Or your custom Hardhat task ```
MAINNET_FORK=true npx hardhat your-custom-task // 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');
``` ```
### Mainnet fork - Run the check list ## Interact with Aave in Mainnet via console
For testing the deployment scripts for Mainnet release, you can run the check-list tests in a Mainnet fork using Hardhat built-in feature: 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:
``` ```
# In another terminal, run docker-compose docker-compose run contracts-env npx hardhat --network main console
docker-compose up ```
# Open another tab or terminal At the Hardhat console, you can interact with the protocol:
docker-compose exec contracts-env bash
```
# A new Bash terminal is prompted, connected to the container // Load the HRE into helpers to access signers
npm run test:main:check-list 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');
``` ```

View File

@ -40,12 +40,11 @@ if (!SKIP_LOAD) {
require(`${path.join(__dirname, 'tasks/misc')}/set-bre.ts`); require(`${path.join(__dirname, 'tasks/misc')}/set-bre.ts`);
const getCommonNetworkConfig = (networkName: eEthereumNetwork, networkId: number) => { const getCommonNetworkConfig = (networkName: eEthereumNetwork, networkId: number) => {
const net = networkName === 'main' ? 'mainnet' : networkName;
return { return {
url: ALCHEMY_KEY url: ALCHEMY_KEY
? `https://eth-${ ? `https://eth-${net}.alchemyapi.io/v2/${ALCHEMY_KEY}`
networkName === 'main' ? 'mainnet' : networkName : `https://${net}.infura.io/v3/${INFURA_KEY}`,
}.alchemyapi.io/v2/${ALCHEMY_KEY}`
: `https://${networkName}.infura.io/v3/${INFURA_KEY}`,
hardfork: HARDFORK, hardfork: HARDFORK,
blockGasLimit: DEFAULT_BLOCK_GAS_LIMIT, blockGasLimit: DEFAULT_BLOCK_GAS_LIMIT,
gasMultiplier: DEFAULT_GAS_MUL, gasMultiplier: DEFAULT_GAS_MUL,
@ -62,10 +61,10 @@ const getCommonNetworkConfig = (networkName: eEthereumNetwork, networkId: number
const mainnetFork = MAINNET_FORK const mainnetFork = MAINNET_FORK
? { ? {
blockNumber: 11366117, blockNumber: 11608298,
url: ALCHEMY_KEY url: ALCHEMY_KEY
? `https://eth-mainnet.alchemyapi.io/v2/${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; : undefined;

View File

@ -11,6 +11,7 @@
"hardhat:main": "hardhat --network main", "hardhat:main": "hardhat --network main",
"hardhat:docker": "hardhat --network hardhatevm_docker", "hardhat:docker": "hardhat --network hardhatevm_docker",
"compile": "SKIP_LOAD=true hardhat compile", "compile": "SKIP_LOAD=true hardhat compile",
"console:fork": "MAINNET_FORK=true hardhat console",
"test": "TS_NODE_TRANSPILE_ONLY=1 hardhat test ./test/*.spec.ts", "test": "TS_NODE_TRANSPILE_ONLY=1 hardhat test ./test/*.spec.ts",
"test-scenarios": "npm run test -- test/__setup.spec.ts test/scenario.spec.ts", "test-scenarios": "npm run test -- test/__setup.spec.ts test/scenario.spec.ts",
"test-repay-with-collateral": "hardhat test test/__setup.spec.ts test/repay-with-collateral.spec.ts", "test-repay-with-collateral": "hardhat test test/__setup.spec.ts test/repay-with-collateral.spec.ts",