From e0627ce66bbc1af5ea714d30752ce6bf935138c0 Mon Sep 17 00:00:00 2001 From: David Racero Date: Fri, 16 Oct 2020 11:27:09 +0200 Subject: [PATCH] Added correct library placheholder hashes. Fix imports. --- helpers/contracts-deployments.ts | 29 ++++++++++++-------- helpers/contracts-getters.ts | 14 ++-------- helpers/init-helpers.ts | 11 ++++---- helpers/oracles-helpers.ts | 4 +-- tasks/dev/1_mock_tokens.ts | 2 +- tasks/dev/2_address_provider_registry.ts | 2 +- tasks/dev/3_lending_pool.ts | 4 +-- tasks/dev/4_oracles.ts | 2 +- tasks/dev/5_initialize.ts | 11 +++++--- tasks/full/1_address_provider_registry.ts | 4 +-- tasks/full/2_lending_pool.ts | 4 +-- tasks/full/3_oracles.ts | 5 ++-- tasks/full/5_initialize.ts | 14 ++++++---- test/__setup.spec.ts | 27 ++++++++---------- test/helpers/actions.ts | 1 - test/helpers/make-suite.ts | 1 - test/helpers/utils/calculations.ts | 1 - test/lending-pool-addresses-provider.spec.ts | 2 +- 18 files changed, 66 insertions(+), 72 deletions(-) diff --git a/helpers/contracts-deployments.ts b/helpers/contracts-deployments.ts index 4d2a8f62..717bd1ca 100644 --- a/helpers/contracts-deployments.ts +++ b/helpers/contracts-deployments.ts @@ -15,7 +15,7 @@ import {MintableErc20 as MintableERC20} from '../types/MintableErc20'; import {readArtifact} from '@nomiclabs/buidler/plugins'; import {MockContract} from 'ethereum-waffle'; import {getReservesConfigByPool} from './configuration'; -import {getFirstSigner, getGenericLogic} from './contracts-getters'; +import {getFirstSigner, getReserveLogic} from './contracts-getters'; import {ZERO_ADDRESS} from './constants'; import { AaveProtocolTestHelpersFactory, @@ -115,17 +115,22 @@ export const deployAaveLibraries = async ( const genericLogic = await deployGenericLogic(verify); const validationLogic = await deployValidationLogic(reserveLogic, genericLogic, verify); + console.log('generic logic address LEND POOL', genericLogic.address); // Hardcoded solidity placeholders, if any library changes path this will fail. - // Placeholder can be calculated via solidity keccak, but the LendingPoolLibraryAddresses Type seems to + // The '__$PLACEHOLDER$__ can be calculated via solidity keccak, but the LendingPoolLibraryAddresses Type seems to // require a hardcoded string. // - // how-to: PLACEHOLDER = solidityKeccak256(['string'], `${libPath}:${libName}`).slice(2, 36) - // '__$PLACEHOLDER$__' + // how-to: + // 1. PLACEHOLDER = solidityKeccak256(['string'], `${libPath}:${libName}`).slice(2, 36) + // 2. LIB_PLACEHOLDER = `__$${PLACEHOLDER}$__` // or grab placeholdes from LendingPoolLibraryAddresses at Typechain generation. + // + // libPath example: contracts/libraries/logic/GenericLogic.sol + // libName example: GenericLogic return { - ['__$5201a97c05ba6aa659e2f36a933dd51801$__']: reserveLogic.address, - ['__$d3b4366daeb9cadc7528af6145b50b2183$__']: genericLogic.address, - ['__$4c26be947d349222af871a3168b3fe584b$__']: validationLogic.address, + ['__$5201a97c05ba6aa659e2f36a933dd51801$__']: validationLogic.address, + ['__$d3b4366daeb9cadc7528af6145b50b2183$__']: reserveLogic.address, + ['__$4c26be947d349222af871a3168b3fe584b$__']: genericLogic.address, }; }; @@ -175,10 +180,10 @@ export const deployChainlinkProxyPriceProvider = async ( ); export const deployLendingPoolCollateralManager = async (verify?: boolean) => { - const genericLogic = await getGenericLogic(); + const reservesLogic = await getReserveLogic(); const libraries = { // See deployAaveLibraries() function - ['__$d3b4366daeb9cadc7528af6145b50b2183$__']: genericLogic.address, + ['__$d3b4366daeb9cadc7528af6145b50b2183$__']: reservesLogic.address, }; return withSaveAndVerify( @@ -256,7 +261,7 @@ export const deployDefaultReserveInterestRateStrategy = async ( ); export const deployStableDebtToken = async ( - args: [string, string, tEthereumAddress, tEthereumAddress, tEthereumAddress], + args: [tEthereumAddress, tEthereumAddress, string, string, tEthereumAddress], verify: boolean ) => withSaveAndVerify( @@ -267,7 +272,7 @@ export const deployStableDebtToken = async ( ); export const deployVariableDebtToken = async ( - args: [string, string, tEthereumAddress, tEthereumAddress, tEthereumAddress], + args: [tEthereumAddress, tEthereumAddress, string, string, tEthereumAddress], verify: boolean ) => withSaveAndVerify( @@ -295,7 +300,7 @@ export const deployGenericAToken = async ( string, tEthereumAddress ] = [poolAddress, underlyingAssetAddress, ZERO_ADDRESS, name, symbol, incentivesController]; - withSaveAndVerify( + return withSaveAndVerify( await new ATokenFactory(await getFirstSigner()).deploy(...args), eContractid.VariableDebtToken, args, diff --git a/helpers/contracts-getters.ts b/helpers/contracts-getters.ts index 5ab75f07..880c878d 100644 --- a/helpers/contracts-getters.ts +++ b/helpers/contracts-getters.ts @@ -196,24 +196,16 @@ export const getLendingPoolAddressesProviderRegistry = async (address?: tEthereu await getFirstSigner() ); -export const getReserveLogicLibrary = async (address?: tEthereumAddress) => +export const getReserveLogic = async (address?: tEthereumAddress) => await ReserveLogicFactory.connect( address || - ( - await getDb() - .get(`${eContractid.LendingPoolAddressesProviderRegistry}.${BRE.network.name}`) - .value() - ).address, + (await getDb().get(`${eContractid.ReserveLogic}.${BRE.network.name}`).value()).address, await getFirstSigner() ); export const getGenericLogic = async (address?: tEthereumAddress) => await GenericLogicFactory.connect( address || - ( - await getDb() - .get(`${eContractid.LendingPoolAddressesProviderRegistry}.${BRE.network.name}`) - .value() - ).address, + (await getDb().get(`${eContractid.GenericLogic}.${BRE.network.name}`).value()).address, await getFirstSigner() ); diff --git a/helpers/init-helpers.ts b/helpers/init-helpers.ts index a2fc3099..d254fc43 100644 --- a/helpers/init-helpers.ts +++ b/helpers/init-helpers.ts @@ -8,7 +8,8 @@ import { deployStableDebtToken, deployVariableDebtToken, deployGenericAToken, -} from './contracts-helpers'; +} from './contracts-deployments'; +import {getEthersSigners} from './contracts-helpers'; export const enableReservesToBorrow = async ( reservesParams: iMultiPoolsAssets, @@ -151,10 +152,10 @@ export const initReserves = async ( console.log('- Deploy stable deb totken ', assetSymbol); const stableDebtToken = await deployStableDebtToken( [ + lendingPool.address, + tokenAddress, `Aave stable debt bearing ${assetSymbol === 'WETH' ? 'ETH' : assetSymbol}`, `stableDebt${assetSymbol === 'WETH' ? 'ETH' : assetSymbol}`, - tokenAddress, - lendingPool.address, incentivesController, ], verify @@ -163,10 +164,10 @@ export const initReserves = async ( console.log('- Deploy var deb totken ', assetSymbol); const variableDebtToken = await deployVariableDebtToken( [ + lendingPool.address, + tokenAddress, `Aave variable debt bearing ${assetSymbol === 'WETH' ? 'ETH' : assetSymbol}`, `variableDebt${assetSymbol === 'WETH' ? 'ETH' : assetSymbol}`, - tokenAddress, - lendingPool.address, incentivesController, ], verify diff --git a/helpers/oracles-helpers.ts b/helpers/oracles-helpers.ts index f87f54b3..f6997f8a 100644 --- a/helpers/oracles-helpers.ts +++ b/helpers/oracles-helpers.ts @@ -11,7 +11,7 @@ import { import {LendingRateOracle} from '../types/LendingRateOracle'; import {PriceOracle} from '../types/PriceOracle'; import {MockAggregator} from '../types/MockAggregator'; -import {deployMockAggregator, getContract, MockTokenMap} from './contracts-helpers'; +import {deployMockAggregator} from './contracts-deployments'; import {waitForTx} from './misc-utils'; import {verifyContract} from './etherscan-verification'; @@ -47,9 +47,7 @@ export const setInitialAssetPricesInOracle = async ( const [, assetAddress] = (Object.entries(assetsAddresses) as [string, string][])[ assetAddressIndex ]; - console.log('PRIOR'); await waitForTx(await priceOracleInstance.setAssetPrice(assetAddress, price)); - console.log('AFTA'); } }; diff --git a/tasks/dev/1_mock_tokens.ts b/tasks/dev/1_mock_tokens.ts index 617071ce..efa3ca04 100644 --- a/tasks/dev/1_mock_tokens.ts +++ b/tasks/dev/1_mock_tokens.ts @@ -1,5 +1,5 @@ import {task} from '@nomiclabs/buidler/config'; -import {deployAllMockTokens} from '../../helpers/contracts-helpers'; +import {deployAllMockTokens} from '../../helpers/contracts-deployments'; task('dev:deploy-mock-tokens', 'Deploy mock tokens for dev enviroment') .addOptionalParam('verify', 'Verify contracts at Etherscan') .setAction(async ({verify}, localBRE) => { diff --git a/tasks/dev/2_address_provider_registry.ts b/tasks/dev/2_address_provider_registry.ts index 078b56c5..5886774b 100644 --- a/tasks/dev/2_address_provider_registry.ts +++ b/tasks/dev/2_address_provider_registry.ts @@ -2,7 +2,7 @@ import {task} from '@nomiclabs/buidler/config'; import { deployLendingPoolAddressesProvider, deployLendingPoolAddressesProviderRegistry, -} from '../../helpers/contracts-helpers'; +} from '../../helpers/contracts-deployments'; import {waitForTx} from '../../helpers/misc-utils'; task( diff --git a/tasks/dev/3_lending_pool.ts b/tasks/dev/3_lending_pool.ts index 82459557..cc4bce81 100644 --- a/tasks/dev/3_lending_pool.ts +++ b/tasks/dev/3_lending_pool.ts @@ -1,9 +1,8 @@ import {task} from '@nomiclabs/buidler/config'; import { deployLendingPool, - insertContractAddressInDb, deployLendingPoolConfigurator, -} from '../../helpers/contracts-helpers'; +} from '../../helpers/contracts-deployments'; import {eContractid} from '../../helpers/types'; import {waitForTx} from '../../helpers/misc-utils'; import { @@ -11,6 +10,7 @@ import { getLendingPool, getLendingPoolConfiguratorProxy, } from '../../helpers/contracts-getters'; +import {insertContractAddressInDb} from '../../helpers/contracts-helpers'; task('dev:deploy-lending-pool', 'Deploy lending pool for dev enviroment') .addOptionalParam('verify', 'Verify contracts at Etherscan') diff --git a/tasks/dev/4_oracles.ts b/tasks/dev/4_oracles.ts index 5ab756d9..415f6884 100644 --- a/tasks/dev/4_oracles.ts +++ b/tasks/dev/4_oracles.ts @@ -3,7 +3,7 @@ import { deployPriceOracle, deployChainlinkProxyPriceProvider, deployLendingRateOracle, -} from '../../helpers/contracts-helpers'; +} from '../../helpers/contracts-deployments'; import { setInitialAssetPricesInOracle, diff --git a/tasks/dev/5_initialize.ts b/tasks/dev/5_initialize.ts index e504decd..28c59bbf 100644 --- a/tasks/dev/5_initialize.ts +++ b/tasks/dev/5_initialize.ts @@ -1,17 +1,19 @@ import {task} from '@nomiclabs/buidler/config'; import { - initReserves, deployLendingPoolCollateralManager, - insertContractAddressInDb, deployMockFlashLoanReceiver, deployWalletBalancerProvider, deployAaveProtocolTestHelpers, -} from '../../helpers/contracts-helpers'; +} from '../../helpers/contracts-deployments'; import {getReservesConfigByPool} from '../../helpers/configuration'; import {tEthereumAddress, AavePools, eContractid} from '../../helpers/types'; import {waitForTx, filterMapBy} from '../../helpers/misc-utils'; -import {enableReservesToBorrow, enableReservesAsCollateral} from '../../helpers/init-helpers'; +import { + enableReservesToBorrow, + enableReservesAsCollateral, + initReserves, +} from '../../helpers/init-helpers'; import {getAllTokenAddresses} from '../../helpers/mock-helpers'; import {ZERO_ADDRESS} from '../../helpers/constants'; import { @@ -20,6 +22,7 @@ import { getLendingPoolConfiguratorProxy, getLendingPoolAddressesProvider, } from '../../helpers/contracts-getters'; +import {insertContractAddressInDb} from '../../helpers/contracts-helpers'; task('dev:initialize-lending-pool', 'Initialize lending pool configuration.') .addOptionalParam('verify', 'Verify contracts at Etherscan') diff --git a/tasks/full/1_address_provider_registry.ts b/tasks/full/1_address_provider_registry.ts index 11195e66..24534901 100644 --- a/tasks/full/1_address_provider_registry.ts +++ b/tasks/full/1_address_provider_registry.ts @@ -1,9 +1,9 @@ import {task} from '@nomiclabs/buidler/config'; +import {getParamPerNetwork} from '../../helpers/contracts-helpers'; import { deployLendingPoolAddressesProvider, deployLendingPoolAddressesProviderRegistry, - getParamPerNetwork, -} from '../../helpers/contracts-helpers'; +} from '../../helpers/contracts-deployments'; import {waitForTx} from '../../helpers/misc-utils'; import {ConfigNames, loadPoolConfig, getGenesisAaveAdmin} from '../../helpers/configuration'; import {eEthereumNetwork} from '../../helpers/types'; diff --git a/tasks/full/2_lending_pool.ts b/tasks/full/2_lending_pool.ts index 5c3fb7f9..cd498a0b 100644 --- a/tasks/full/2_lending_pool.ts +++ b/tasks/full/2_lending_pool.ts @@ -1,9 +1,9 @@ import {task} from '@nomiclabs/buidler/config'; +import {insertContractAddressInDb} from '../../helpers/contracts-helpers'; import { deployLendingPool, - insertContractAddressInDb, deployLendingPoolConfigurator, -} from '../../helpers/contracts-helpers'; +} from '../../helpers/contracts-deployments'; import {eContractid} from '../../helpers/types'; import {waitForTx} from '../../helpers/misc-utils'; import { diff --git a/tasks/full/3_oracles.ts b/tasks/full/3_oracles.ts index 9d640448..853330f2 100644 --- a/tasks/full/3_oracles.ts +++ b/tasks/full/3_oracles.ts @@ -1,10 +1,9 @@ import {task} from '@nomiclabs/buidler/config'; +import {getParamPerNetwork} from '../../helpers/contracts-helpers'; import { deployChainlinkProxyPriceProvider, deployLendingRateOracle, - getParamPerNetwork, -} from '../../helpers/contracts-helpers'; - +} from '../../helpers/contracts-deployments'; import {setInitialMarketRatesInRatesOracle} from '../../helpers/oracles-helpers'; import {ICommonConfiguration, eEthereumNetwork, SymbolMap} from '../../helpers/types'; import {waitForTx, filterMapBy} from '../../helpers/misc-utils'; diff --git a/tasks/full/5_initialize.ts b/tasks/full/5_initialize.ts index 1c54fd69..fe2c5c42 100644 --- a/tasks/full/5_initialize.ts +++ b/tasks/full/5_initialize.ts @@ -1,16 +1,18 @@ import {task} from '@nomiclabs/buidler/config'; +import {getParamPerNetwork} from '../../helpers/contracts-helpers'; import { - initReserves, deployLendingPoolCollateralManager, deployWalletBalancerProvider, deployAaveProtocolTestHelpers, - getParamPerNetwork, -} from '../../helpers/contracts-helpers'; +} from '../../helpers/contracts-deployments'; import {loadPoolConfig, ConfigNames} from '../../helpers/configuration'; - -import {AavePools, eContractid, eEthereumNetwork, ICommonConfiguration} from '../../helpers/types'; +import {AavePools, eEthereumNetwork, ICommonConfiguration} from '../../helpers/types'; import {waitForTx} from '../../helpers/misc-utils'; -import {enableReservesToBorrow, enableReservesAsCollateral} from '../../helpers/init-helpers'; +import { + enableReservesToBorrow, + enableReservesAsCollateral, + initReserves, +} from '../../helpers/init-helpers'; import {ZERO_ADDRESS} from '../../helpers/constants'; import {exit} from 'process'; import { diff --git a/test/__setup.spec.ts b/test/__setup.spec.ts index 6a02b940..a6c20849 100644 --- a/test/__setup.spec.ts +++ b/test/__setup.spec.ts @@ -1,5 +1,10 @@ import rawBRE from '@nomiclabs/buidler'; import {MockContract} from 'ethereum-waffle'; +import { + insertContractAddressInDb, + getEthersSigners, + registerContractInJsonDb, +} from '../helpers/contracts-helpers'; import { deployLendingPoolAddressesProvider, deployMintableERC20, @@ -11,20 +16,15 @@ import { deployLendingPoolCollateralManager, deployMockFlashLoanReceiver, deployWalletBalancerProvider, - insertContractAddressInDb, deployAaveProtocolTestHelpers, - getEthersSigners, - registerContractInJsonDb, - initReserves, deployMockSwapAdapter, deployLendingRateOracle, -} from '../helpers/contracts-helpers'; +} from '../helpers/contracts-deployments'; import {Signer} from 'ethers'; import {TokenContractId, eContractid, tEthereumAddress, AavePools} from '../helpers/types'; import {MintableErc20 as MintableERC20} from '../types/MintableErc20'; import {getReservesConfigByPool} from '../helpers/configuration'; import {initializeMakeSuite} from './helpers/make-suite'; -import {AaveProtocolTestHelpers} from '../types/AaveProtocolTestHelpers'; import { setInitialAssetPricesInOracle, @@ -32,7 +32,11 @@ import { deployAllMockAggregators, } from '../helpers/oracles-helpers'; import {waitForTx} from '../helpers/misc-utils'; -import {enableReservesToBorrow, enableReservesAsCollateral} from '../helpers/init-helpers'; +import { + enableReservesToBorrow, + enableReservesAsCollateral, + initReserves, +} from '../helpers/init-helpers'; import {AaveConfig} from '../config/aave'; import {ZERO_ADDRESS} from '../helpers/constants'; import { @@ -95,14 +99,9 @@ const buildTestEnv = async (deployer: Signer, secondaryWallet: Signer) => { await waitForTx(await addressesProvider.setLendingPoolImpl(lendingPoolImpl.address)); - console.log('Added pool to addresses provider'); - const address = await addressesProvider.getLendingPool(); - console.log('Address is ', address); const lendingPoolProxy = await getLendingPool(address); - console.log('implementation set, address:', lendingPoolProxy.address); - await insertContractAddressInDb(eContractid.LendingPool, lendingPoolProxy.address); const lendingPoolConfiguratorImpl = await deployLendingPoolConfigurator(); @@ -112,6 +111,7 @@ const buildTestEnv = async (deployer: Signer, secondaryWallet: Signer) => { const lendingPoolConfiguratorProxy = await getLendingPoolConfiguratorProxy( await addressesProvider.getLendingPoolConfigurator() ); + console.log('proxy address', lendingPoolConfiguratorProxy.address); await insertContractAddressInDb( eContractid.LendingPoolConfigurator, lendingPoolConfiguratorProxy.address @@ -152,10 +152,7 @@ const buildTestEnv = async (deployer: Signer, secondaryWallet: Signer) => { fallbackOracle ); - console.log('setted prices'); - console.log('prior mocks'); const mockAggregators = await deployAllMockAggregators(MOCK_CHAINLINK_AGGREGATORS_PRICES); - console.log('aftahlocks'); const allTokenAddresses = Object.entries(mockTokens).reduce( (accum: {[tokenSymbol: string]: tEthereumAddress}, [tokenSymbol, tokenContract]) => ({ diff --git a/test/helpers/actions.ts b/test/helpers/actions.ts index 0ab80a21..422b0455 100644 --- a/test/helpers/actions.ts +++ b/test/helpers/actions.ts @@ -28,7 +28,6 @@ import {ReserveData, UserReserveData} from './utils/interfaces'; import {ContractReceipt} from 'ethers'; import {AToken} from '../../types/AToken'; import {RateMode, tEthereumAddress} from '../../helpers/types'; -import {time} from 'console'; const {expect} = chai; diff --git a/test/helpers/make-suite.ts b/test/helpers/make-suite.ts index 29b1f546..d11278ea 100644 --- a/test/helpers/make-suite.ts +++ b/test/helpers/make-suite.ts @@ -27,7 +27,6 @@ import {LendingPoolAddressesProvider} from '../../types/LendingPoolAddressesProv import {MockSwapAdapter} from '../../types/MockSwapAdapter'; import {LendingPoolAddressesProviderRegistry} from '../../types/LendingPoolAddressesProviderRegistry'; import {getEthersSigners} from '../../helpers/contracts-helpers'; -import {AaveProtocolTestHelpersFactory} from '../../types'; chai.use(bignumberChai()); chai.use(almostEqual()); diff --git a/test/helpers/utils/calculations.ts b/test/helpers/utils/calculations.ts index 46623a62..894f3373 100644 --- a/test/helpers/utils/calculations.ts +++ b/test/helpers/utils/calculations.ts @@ -5,7 +5,6 @@ import { MAX_UINT_AMOUNT, OPTIMAL_UTILIZATION_RATE, EXCESS_UTILIZATION_RATE, - ZERO_ADDRESS, } from '../../../helpers/constants'; import {IReserveParams, iAavePoolAssets, RateMode, tEthereumAddress} from '../../../helpers/types'; import './math'; diff --git a/test/lending-pool-addresses-provider.spec.ts b/test/lending-pool-addresses-provider.spec.ts index ed283c46..4858531a 100644 --- a/test/lending-pool-addresses-provider.spec.ts +++ b/test/lending-pool-addresses-provider.spec.ts @@ -5,7 +5,7 @@ import {ProtocolErrors} from '../helpers/types'; import {ethers} from 'ethers'; import {ZERO_ADDRESS} from '../helpers/constants'; import {waitForTx} from '../helpers/misc-utils'; -import {deployLendingPool} from '../helpers/contracts-helpers'; +import {deployLendingPool} from '../helpers/contracts-deployments'; const {utils} = ethers;