From 588a0c8da0d34d791d69254fa307c7e4bec9a8c4 Mon Sep 17 00:00:00 2001
From: David Racero <canillas.mail@gmail.com>
Date: Thu, 12 Nov 2020 14:41:08 +0100
Subject: [PATCH] Add provider. Add transaction link to task.

---
 deployed-contracts.json               | 29 ++++++++++-
 hardhat.config.ts                     |  4 +-
 tasks/full/2_lending_pool.ts          | 74 +++++++++++++++------------
 tasks/full/5_initialize.ts            | 14 -----
 tasks/migrations/aave.mainnet.fork.ts |  3 --
 tasks/misc/set-bre.ts                 |  5 ++
 6 files changed, 77 insertions(+), 52 deletions(-)

diff --git a/deployed-contracts.json b/deployed-contracts.json
index 67361d8c..89cdaacb 100644
--- a/deployed-contracts.json
+++ b/deployed-contracts.json
@@ -257,6 +257,10 @@
     "hardhat": {
       "address": "0xFAe0fd738dAbc8a0426F47437322b6d026A9FD95",
       "deployer": "0xc783df8a850f42e7F7e57013759C285caa701eB6"
+    },
+    "tenderlyMain": {
+      "address": "0x011BA4E28C3448513D853599131AcB9A24Cb8E11",
+      "deployer": "0xb2E51BBCB2453701e5aB9bf95Ea9A4eb2D329090"
     }
   },
   "LendingPoolAddressesProviderRegistry": {
@@ -271,6 +275,10 @@
     "hardhat": {
       "address": "0x12080583C4F0211eC382d33a273E6D0f9fAb0F75",
       "deployer": "0xc783df8a850f42e7F7e57013759C285caa701eB6"
+    },
+    "tenderlyMain": {
+      "address": "0x239acf3cD92161Db147389A57cbFaeb0985d5e3A",
+      "deployer": "0xf2F8D0753A4E35B097c871D1ED488B7926D3097a"
     }
   },
   "ReserveLogic": {
@@ -285,6 +293,10 @@
     "hardhat": {
       "address": "0x2cBbbBE1B75Ad7848F0844215816F551f429c64f",
       "deployer": "0xc783df8a850f42e7F7e57013759C285caa701eB6"
+    },
+    "tenderlyMain": {
+      "address": "0xB7Ea702FC07e976b19ED67060099FdF8A34950e2",
+      "deployer": "0x859cFCC3ae5f43221eC254E70D13239046A170f3"
     }
   },
   "GenericLogic": {
@@ -299,6 +311,10 @@
     "hardhat": {
       "address": "0xbAc762e2000b6815268587b081Fd17aC25519aD5",
       "deployer": "0xc783df8a850f42e7F7e57013759C285caa701eB6"
+    },
+    "tenderlyMain": {
+      "address": "0xBECF925e9EB6C026635A2D9216d964D4E12070f7",
+      "deployer": "0x859cFCC3ae5f43221eC254E70D13239046A170f3"
     }
   },
   "ValidationLogic": {
@@ -313,6 +329,10 @@
     "hardhat": {
       "address": "0xa43Ba00FCA75B805D17f67F9433b971E9a398690",
       "deployer": "0xc783df8a850f42e7F7e57013759C285caa701eB6"
+    },
+    "tenderlyMain": {
+      "address": "0x997502540DcB6F2fa31B79cda650bf7810AA53ce",
+      "deployer": "0x802750DB4D80361475353FC88F72F5ed8a86c71F"
     }
   },
   "LendingPool": {
@@ -326,6 +346,10 @@
     "hardhat": {
       "address": "0xAa7BC1924711B77A0F3Aaebdd550BfeDDDbaf3cd",
       "deployer": "0xc783df8a850f42e7F7e57013759C285caa701eB6"
+    },
+    "tenderlyMain": {
+      "address": "0x433Ce38A0154061684db57853f232beDfEC44ac2",
+      "deployer": "0xb2E51BBCB2453701e5aB9bf95Ea9A4eb2D329090"
     }
   },
   "LendingPoolConfigurator": {
@@ -595,6 +619,9 @@
     },
     "hardhat": {
       "address": "0xAa7BC1924711B77A0F3Aaebdd550BfeDDDbaf3cd"
+    },
+    "tenderlyMain": {
+      "address": "0x433Ce38A0154061684db57853f232beDfEC44ac2"
     }
   },
   "LendingPoolConfiguratorImpl": {
@@ -1285,4 +1312,4 @@
       "address": "0xaDF23b1cAa6a7B3b077c432794FfF80A4b935cdF"
     }
   }
-}
\ No newline at end of file
+}
diff --git a/hardhat.config.ts b/hardhat.config.ts
index 5e366506..4ce68bf9 100644
--- a/hardhat.config.ts
+++ b/hardhat.config.ts
@@ -75,8 +75,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: {
diff --git a/tasks/full/2_lending_pool.ts b/tasks/full/2_lending_pool.ts
index b8b57344..004ab951 100644
--- a/tasks/full/2_lending_pool.ts
+++ b/tasks/full/2_lending_pool.ts
@@ -16,45 +16,55 @@ import {
 
 task('full:deploy-lending-pool', 'Deploy lending pool for dev enviroment')
   .addFlag('verify', 'Verify contracts at Etherscan')
-  .setAction(async ({verify}, localBRE) => {
-    await localBRE.run('set-DRE');
+  .setAction(async ({verify}, DRE) => {
+    try {
+      await DRE.run('set-DRE');
 
-    const addressesProvider = await getLendingPoolAddressesProvider();
+      const addressesProvider = await getLendingPoolAddressesProvider();
 
-    // Deploy lending pool
-    const lendingPoolImpl = await deployLendingPool(verify);
+      // Deploy lending pool
+      const lendingPoolImpl = await deployLendingPool(verify);
 
-    // Set lending pool impl to address provider
-    await waitForTx(await addressesProvider.setLendingPoolImpl(lendingPoolImpl.address));
+      console.log('setting up lending pool', addressesProvider);
+      // Set lending pool impl to address provider
+      await waitForTx(await addressesProvider.setLendingPoolImpl(lendingPoolImpl.address));
+      console.log('lending pool setted');
 
-    const address = await addressesProvider.getLendingPool();
-    const lendingPoolProxy = await getLendingPool(address);
+      const address = await addressesProvider.getLendingPool();
+      const lendingPoolProxy = await getLendingPool(address);
 
-    await insertContractAddressInDb(eContractid.LendingPool, lendingPoolProxy.address);
+      await insertContractAddressInDb(eContractid.LendingPool, lendingPoolProxy.address);
 
-    // Deploy lending pool configurator
-    const lendingPoolConfiguratorImpl = await deployLendingPoolConfigurator(verify);
+      // Deploy lending pool configurator
+      const lendingPoolConfiguratorImpl = await deployLendingPoolConfigurator(verify);
 
-    // Set lending pool conf impl to Address Provider
-    await waitForTx(
-      await addressesProvider.setLendingPoolConfiguratorImpl(lendingPoolConfiguratorImpl.address)
-    );
+      console.log('set up x');
+      // Set lending pool conf impl to Address Provider
+      await waitForTx(
+        await addressesProvider.setLendingPoolConfiguratorImpl(lendingPoolConfiguratorImpl.address)
+      );
 
-    const lendingPoolConfiguratorProxy = await getLendingPoolConfiguratorProxy(
-      await addressesProvider.getLendingPoolConfigurator()
-    );
+      console.log('set up x');
+      const lendingPoolConfiguratorProxy = await getLendingPoolConfiguratorProxy(
+        await addressesProvider.getLendingPoolConfigurator()
+      );
 
-    await insertContractAddressInDb(
-      eContractid.LendingPoolConfigurator,
-      lendingPoolConfiguratorProxy.address
-    );
-    // Deploy deployment helpers
-    await deployStableAndVariableTokensHelper(
-      [lendingPoolProxy.address, addressesProvider.address],
-      verify
-    );
-    await deployATokensAndRatesHelper(
-      [lendingPoolProxy.address, addressesProvider.address, lendingPoolConfiguratorProxy.address],
-      verify
-    );
+      await insertContractAddressInDb(
+        eContractid.LendingPoolConfigurator,
+        lendingPoolConfiguratorProxy.address
+      );
+      // Deploy deployment helpers
+      await deployStableAndVariableTokensHelper(
+        [lendingPoolProxy.address, addressesProvider.address],
+        verify
+      );
+      console.log('set up x');
+      await deployATokensAndRatesHelper(
+        [lendingPoolProxy.address, addressesProvider.address, lendingPoolConfiguratorProxy.address],
+        verify
+      );
+    } catch (error) {
+      const transactionLink = `https://dashboard.tenderly.co/fork/${DRE.tenderlyRPC.getFork()}/simulation/${DRE.tenderlyRPC.getHead()}`;
+      console.log(transactionLink);
+    }
   });
diff --git a/tasks/full/5_initialize.ts b/tasks/full/5_initialize.ts
index 718c2231..99b55f15 100644
--- a/tasks/full/5_initialize.ts
+++ b/tasks/full/5_initialize.ts
@@ -54,20 +54,6 @@ task('full:initialize-lending-pool', 'Initialize lending pool configuration.')
       const lendingPoolAddress = await addressesProvider.getLendingPool();
 
       await deployWETHGateway([wethAddress, lendingPoolAddress]);
-
-      //register the proxy price provider on the addressesProvider
-      const proxyProvider = getParamPerNetwork(poolConfig.ProxyPriceProvider, network);
-
-      if (proxyProvider && proxyProvider !== '') {
-        await waitForTx(await addressesProvider.setPriceOracle(proxyProvider));
-      }
-
-      //register the lending rate oracle
-      const lendingRateOracle = getParamPerNetwork(poolConfig.LendingRateOracle, network);
-
-      if (lendingRateOracle && lendingRateOracle !== '') {
-        await waitForTx(await addressesProvider.setLendingRateOracle(lendingRateOracle));
-      }
     } catch (err) {
       console.error(err);
       exit(1);
diff --git a/tasks/migrations/aave.mainnet.fork.ts b/tasks/migrations/aave.mainnet.fork.ts
index 9f61d042..0ad5de5a 100644
--- a/tasks/migrations/aave.mainnet.fork.ts
+++ b/tasks/migrations/aave.mainnet.fork.ts
@@ -20,9 +20,6 @@ task('aave:full:fork', 'Deploy development enviroment')
       checkVerification();
     }
     console.log('- Setting up Tenderly provider');
-    DRE.ethers.provider = new DRE.ethers.providers.Web3Provider(
-      DRE.tenderlyRPC as ExternalProvider
-    );
 
     //Set the ethers provider to the one we initialized so it targets the correct backend
     console.log('Migration started\n');
diff --git a/tasks/misc/set-bre.ts b/tasks/misc/set-bre.ts
index a1cb29c5..4c9eca6f 100644
--- a/tasks/misc/set-bre.ts
+++ b/tasks/misc/set-bre.ts
@@ -1,9 +1,14 @@
+import {ExternalProvider} from '@ethersproject/providers';
+
 import {task} from 'hardhat/config';
 import {setDRE} from '../../helpers/misc-utils';
 
 task(`set-DRE`, `Inits the DRE, to have access to all the plugins' objects`).setAction(
   async (_, _DRE) => {
     setDRE(_DRE);
+    const provider = new _DRE.ethers.providers.Web3Provider(_DRE.tenderlyRPC as ExternalProvider);
+    //Set the ethers provider to the one we initialized so it targets the correct backend
+    _DRE.ethers.provider = provider;
     return _DRE;
   }
 );