From d0ea8d2e32dd94b65669babd96eaf9b755992b96 Mon Sep 17 00:00:00 2001 From: David Racero Date: Mon, 16 Nov 2020 11:09:23 +0100 Subject: [PATCH] Added buidler mainnent fork --- hardhat.config.ts | 22 ++++++++++++++++++---- package.json | 3 ++- tasks/migrations/aave.mainnet.fork.ts | 13 ++++++------- 3 files changed, 26 insertions(+), 12 deletions(-) diff --git a/hardhat.config.ts b/hardhat.config.ts index 4ce68bf9..e6ddb0c1 100644 --- a/hardhat.config.ts +++ b/hardhat.config.ts @@ -1,5 +1,6 @@ import path from 'path'; import fs from 'fs'; +import {HardhatUserConfig} from 'hardhat/types'; // @ts-ignore import {accounts} from './test-wallets.js'; import {eEthereumNetwork} from './helpers/types'; @@ -22,6 +23,7 @@ const ALCHEMY_KEY = process.env.ALCHEMY_KEY || ''; const ETHERSCAN_KEY = process.env.ETHERSCAN_KEY || ''; const MNEMONIC_PATH = "m/44'/60'/0'/0"; const MNEMONIC = process.env.MNEMONIC || ''; +const MAINNET_FORK = process.env.MAINNET_FORK === 'true'; // Prevent to load scripts before compilation and typechain if (!SKIP_LOAD) { @@ -40,7 +42,9 @@ require(`${path.join(__dirname, 'tasks/misc')}/set-bre.ts`); const getCommonNetworkConfig = (networkName: eEthereumNetwork, networkId: number) => { return { url: ALCHEMY_KEY - ? `https://eth-${networkName}.alchemyapi.io/v2/${ALCHEMY_KEY}` + ? `https://eth-${ + networkName === 'main' ? 'mainnet' : networkName + }.alchemyapi.io/v2/${ALCHEMY_KEY}` : `https://${networkName}.infura.io/v3/${INFURA_KEY}`, hardfork: HARDFORK, blockGasLimit: DEFAULT_BLOCK_GAS_LIMIT, @@ -56,7 +60,16 @@ const getCommonNetworkConfig = (networkName: eEthereumNetwork, networkId: number }; }; -const buidlerConfig = { +const mainnetFork = MAINNET_FORK + ? { + blockNumber: 11268220, + url: ALCHEMY_KEY + ? `https://eth-mainnet.alchemyapi.io/v2/${ALCHEMY_KEY}` + : `https://main.infura.io/v3/${INFURA_KEY}`, + } + : undefined; + +const buidlerConfig: HardhatUserConfig = { solidity: { version: '0.6.8', settings: { @@ -75,8 +88,8 @@ const buidlerConfig = { timeout: 0, }, tenderly: { - project: process.env.TENDERLY_PROJECT, - username: process.env.TENDERLY_USERNAME, + project: process.env.TENDERLY_PROJECT || '', + username: process.env.TENDERLY_USERNAME || '', forkNetwork: '1', //Network id of the network we want to fork }, networks: { @@ -100,6 +113,7 @@ const buidlerConfig = { privateKey: secretKey, balance, })), + forking: mainnetFork, }, buidlerevm_docker: { hardfork: 'istanbul', diff --git a/package.json b/package.json index a8086c28..4be80848 100644 --- a/package.json +++ b/package.json @@ -22,7 +22,8 @@ "aave:kovan:full:initialize": "npm run hardhat:kovan -- full:initialize-lending-pool --verify --pool Aave", "aave:ropsten:dev:migration": "npm run hardhat:ropsten -- aave:dev --verify", "aave:ropsten:full:migration": "npm run hardhat:ropsten -- aave:full --verify", - "aave:fork:main:migration": "npm run hardhat:tenderly-main -- aave:full:fork", + "aave:fork:main:tendery": "npm run hardhat:tenderly-main -- aave:full:fork", + "aave:fork:main": "MAINNET_FORK=true npm run aave:full:fork", "aave:main:dev:migration": "npm run hardhat:main -- aave:dev --verify", "aave:main:full:migration": "npm run hardhat:main -- aave:full --verify", "uniswap:evm:dev:migration": "hardhat uniswap:dev", diff --git a/tasks/migrations/aave.mainnet.fork.ts b/tasks/migrations/aave.mainnet.fork.ts index 94ef557a..dffe8508 100644 --- a/tasks/migrations/aave.mainnet.fork.ts +++ b/tasks/migrations/aave.mainnet.fork.ts @@ -10,9 +10,6 @@ task('aave:full:fork', 'Deploy development enviroment') .setAction(async ({verify}, DRE) => { const POOL_NAME = ConfigNames.Aave; const network = DRE.network.name; - if (!network.includes('tenderly')) { - throw 'This task only supports tenderly networks: tenderlyMain, tenderlyKovan'; - } await DRE.run('set-DRE'); // Prevent loss of gas verifying all the needed ENVs for Etherscan verification @@ -21,10 +18,12 @@ task('aave:full:fork', 'Deploy development enviroment') } // Set the ethers provider to the one we initialized so it targets the correct backend - console.log('- Setting up Tenderly provider'); - await DRE.tenderlyRPC.initializeFork(); - const provider = new DRE.ethers.providers.Web3Provider(DRE.tenderlyRPC as any); - DRE.ethers.provider = provider; + if (network.includes('tenderly')) { + console.log('- Setting up Tenderly provider'); + await DRE.tenderlyRPC.initializeFork(); + const provider = new DRE.ethers.providers.Web3Provider(DRE.tenderlyRPC as any); + DRE.ethers.provider = provider; + } console.log('Migration started\n');