Added small guide to how to interact with Aave in Mainnet with console

This commit is contained in:
David Racero 2021-01-07 16:17:33 +01:00
parent e4f5c0defa
commit 037ac78acb
2 changed files with 59 additions and 19 deletions

View File

@ -112,41 +112,81 @@ You can deploy Aave Protocol v2 in a forked Mainnet chain using Hardhat built-in
docker-compose run contracts-env npm run aave:fork:main
```
### Mainnet fork - Interact with Aave via Hardhat console
### Deploy Aave into a Mainnet Fork via console
You can also deploy Aave into the Hardhat console in fork mode, to interact with the protocol inside the fork or for testing purposes.
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:
```
# Run the console in fork mode
docker-compose run contracts-env npm run console:fork
```
# Deploy the Aave protocol in fork mode
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
// Or your custom Hardhat task
await run('your-custom-task');
# After you initialize the Signers via 'set-DRE' task, you can import any TS/JS file
await run('set-DRE'); // Initialize signers
// 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
// Import contract getters to retrieve an Ethers.js Contract instance
const contractGetters = require('./helpers/contracts-getters'); // Import a TS/JS file
# Lending pool instance
// Lending pool instance
const lendingPool = await contractGetters.getLendingPool("LendingPool address from 'aave:mainnet' task");
```
### Mainnet fork - Run the check list
// You can impersonate any Ethereum address
await network.provider.request({ method: "hardhat_impersonateAccount", params: ["0xb1adceddb2941033a090dd166a462fe1c2029484"]});
For testing the deployment scripts for Mainnet release, you can run the check-list tests in a Mainnet fork using Hardhat built-in feature:
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');
```
# 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
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:
# A new Bash terminal is prompted, connected to the container
npm run test:main:check-list
```
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');
```

View File

@ -61,7 +61,7 @@ const getCommonNetworkConfig = (networkName: eEthereumNetwork, networkId: number
const mainnetFork = MAINNET_FORK
? {
blockNumber: 11366117,
blockNumber: 11608298,
url: ALCHEMY_KEY
? `https://eth-mainnet.alchemyapi.io/v2/${ALCHEMY_KEY}`
: `https://mainnet.infura.io/v3/${INFURA_KEY}`,