From 39f71f961046572529d0706ddae91bb1984ce92f Mon Sep 17 00:00:00 2001 From: David Racero Date: Wed, 2 Dec 2020 10:58:44 +0100 Subject: [PATCH] Prevent to hang if missing address at db json --- helpers/contracts-getters.ts | 4 +- tasks/verifications/1_general.ts | 93 ++++++-------------------------- tasks/verifications/2_tokens.ts | 67 ++++++++++++----------- 3 files changed, 54 insertions(+), 110 deletions(-) diff --git a/helpers/contracts-getters.ts b/helpers/contracts-getters.ts index cd748c9e..65834cc6 100644 --- a/helpers/contracts-getters.ts +++ b/helpers/contracts-getters.ts @@ -320,8 +320,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 => + (await getDb().get(`${id}.${DRE.network.name}`).value())?.address || undefined; export const getAaveOracle = async (address?: tEthereumAddress) => await AaveOracleFactory.connect( diff --git a/tasks/verifications/1_general.ts b/tasks/verifications/1_general.ts index 16e7fb6d..6e42e483 100644 --- a/tasks/verifications/1_general.ts +++ b/tasks/verifications/1_general.ts @@ -1,3 +1,4 @@ +import { error } from 'console'; import { zeroAddress } from 'ethereumjs-util'; import { task } from 'hardhat/config'; import { @@ -105,86 +106,22 @@ task('verify:general', 'Deploy oracles for dev enviroment') console.log('\n- Verifying Lending Pool Collateral Manager Proxy...\n'); await verifyContract(lendingPoolCollateralManager.address, []); - // Tokens verification - const DAI = getParamPerNetwork(ReserveAssets, network).DAI; - const stableDebtDai = await getAddressById('stableDebtDAI'); - const variableDebtDai = await getAddressById('variableDebtDAI'); - const aDAI = await getAddressById('aDAI'); - const { - stableDebtTokenAddress, - variableDebtTokenAddress, - aTokenAddress, - interestRateStrategyAddress, - } = await lendingPoolProxy.getReserveData(DAI); - const { - baseVariableBorrowRate, - variableRateSlope1, - variableRateSlope2, - stableRateSlope1, - stableRateSlope2, - } = ReservesConfig.DAI; - - // Proxy Stable Debt - console.log('\n- Verifying DAI Stable Debt Token proxy...\n'); - await verifyContract(stableDebtTokenAddress, [lendingPoolConfigurator.address]); - - // Proxy Variable Debt - console.log('\n- Verifying DAI Variable Debt Token proxy...\n'); - await verifyContract(variableDebtTokenAddress, [lendingPoolConfigurator.address]); - - // Proxy aToken - console.log('\n- Verifying aDAI Token proxy...\n'); - await verifyContract(aTokenAddress, [lendingPoolConfigurator.address]); - - // Strategy Rate - console.log('\n- Verifying Strategy rate...\n'); - await verifyContract(interestRateStrategyAddress, [ - addressesProvider.address, - baseVariableBorrowRate, - variableRateSlope1, - variableRateSlope2, - stableRateSlope1, - stableRateSlope2, - ]); - - // aToken - console.log('\n- Verifying aToken...\n'); - await verifyContract(aDAI, [ - lendingPoolProxy.address, - DAI, - treasuryAddress, - 'Aave interest bearing DAI', - 'aDAI', - ZERO_ADDRESS, - ]); - // stableDebtToken - console.log('\n- Verifying StableDebtToken...\n'); - await verifyContract(stableDebtDai, [ - lendingPoolProxy.address, - DAI, - 'Aave stable debt bearing DAI', - 'stableDebtDAI', - ZERO_ADDRESS, - ]); - // variableDebtToken - console.log('\n- Verifying VariableDebtToken...\n'); - await verifyContract(variableDebtDai, [ - lendingPoolProxy.address, - DAI, - 'Aave variable debt bearing DAI', - 'variableDebtDAI', - ZERO_ADDRESS, - ]); // DelegatedAwareAToken console.log('\n- Verifying DelegatedAwareAToken...\n'); const UNI = getParamPerNetwork(ReserveAssets, network).UNI; const aUNI = await getAddressById('aUNI'); - await verifyContract(aUNI, [ - lendingPoolProxy.address, - UNI, - treasuryAddress, - 'Aave interest bearing UNI', - 'aUNI', - ZERO_ADDRESS, - ]); + if (aUNI) { + console.log('Verifying aUNI'); + await verifyContract(aUNI, [ + lendingPoolProxy.address, + UNI, + treasuryAddress, + 'Aave interest bearing UNI', + 'aUNI', + ZERO_ADDRESS, + ]); + } else { + console.error('Missing aUNI address at JSON DB. Skipping...'); + } + console.log('Finished verifications.'); }); diff --git a/tasks/verifications/2_tokens.ts b/tasks/verifications/2_tokens.ts index f50c3cee..591aa45a 100644 --- a/tasks/verifications/2_tokens.ts +++ b/tasks/verifications/2_tokens.ts @@ -83,35 +83,42 @@ task('verify:tokens', 'Deploy oracles for dev enviroment') const variableDebt = await getAddressById(`variableDebt${token}`); const aToken = await getAddressById(`a${token}`); - // aToken - console.log('\n- Verifying aToken...\n'); - await verifyContract(aToken, [ - lendingPoolProxy.address, - tokenAddress, - treasuryAddress, - `Aave interest bearing ${token}`, - `a${token}`, - ZERO_ADDRESS, - ]); - - // stableDebtToken - console.log('\n- Verifying StableDebtToken...\n'); - await verifyContract(stableDebt, [ - lendingPoolProxy.address, - tokenAddress, - `Aave stable debt bearing ${token}`, - `stableDebt${token}`, - ZERO_ADDRESS, - ]); - - // variableDebtToken - console.log('\n- Verifying VariableDebtToken...\n'); - await verifyContract(variableDebt, [ - lendingPoolProxy.address, - tokenAddress, - `Aave variable debt bearing ${token}`, - `variableDebt${token}`, - ZERO_ADDRESS, - ]); + if (aToken) { + console.log('\n- Verifying aToken...\n'); + await verifyContract(aToken, [ + lendingPoolProxy.address, + tokenAddress, + treasuryAddress, + `Aave interest bearing ${token}`, + `a${token}`, + ZERO_ADDRESS, + ]); + } else { + console.error(`Skipping aToken verify for ${token}. Missing address at JSON DB.`); + } + if (stableDebt) { + console.log('\n- Verifying StableDebtToken...\n'); + await verifyContract(stableDebt, [ + lendingPoolProxy.address, + tokenAddress, + `Aave stable debt bearing ${token}`, + `stableDebt${token}`, + ZERO_ADDRESS, + ]); + } else { + console.error(`Skipping stable debt verify for ${token}. Missing address at JSON DB.`); + } + if (variableDebt) { + console.log('\n- Verifying VariableDebtToken...\n'); + await verifyContract(variableDebt, [ + lendingPoolProxy.address, + tokenAddress, + `Aave variable debt bearing ${token}`, + `variableDebt${token}`, + ZERO_ADDRESS, + ]); + } else { + console.error(`Skipping variable debt verify for ${token}. Missing address at JSON DB.`); + } } });