diff --git a/helpers/types.ts b/helpers/types.ts index 3a3f9a99..4f7c739b 100644 --- a/helpers/types.ts +++ b/helpers/types.ts @@ -428,6 +428,8 @@ export interface ICommonConfiguration { ProviderRegistry: iParamsPerNetwork; ProviderRegistryOwner: iParamsPerNetwork; LendingPoolCollateralManager: iParamsPerNetwork; + LendingPoolConfigurator: iParamsPerNetwork; + LendingPool: iParamsPerNetwork; LendingRateOracleRatesCommon: iMultiPoolsAssets; LendingRateOracle: iParamsPerNetwork; TokenDistributor: iParamsPerNetwork; diff --git a/markets/aave/commons.ts b/markets/aave/commons.ts index 642535d1..115f9372 100644 --- a/markets/aave/commons.ts +++ b/markets/aave/commons.ts @@ -190,6 +190,24 @@ export const CommonsConfig: ICommonConfiguration = { [eEthereumNetwork.main]: '0xbd4765210d4167CE2A5b87280D9E8Ee316D5EC7C', [eEthereumNetwork.tenderlyMain]: '0xbd4765210d4167CE2A5b87280D9E8Ee316D5EC7C', }, + LendingPoolConfigurator: { + [eEthereumNetwork.coverage]: '', + [eEthereumNetwork.hardhat]: '', + [eEthereumNetwork.buidlerevm]: '', + [eEthereumNetwork.kovan]: '', + [eEthereumNetwork.ropsten]: '', + [eEthereumNetwork.main]: '', + [eEthereumNetwork.tenderlyMain]: '', + }, + LendingPool: { + [eEthereumNetwork.coverage]: '', + [eEthereumNetwork.hardhat]: '', + [eEthereumNetwork.buidlerevm]: '', + [eEthereumNetwork.kovan]: '', + [eEthereumNetwork.ropsten]: '', + [eEthereumNetwork.main]: '', + [eEthereumNetwork.tenderlyMain]: '', + }, WethGateway: { [eEthereumNetwork.coverage]: '', [eEthereumNetwork.hardhat]: '', diff --git a/markets/amm/commons.ts b/markets/amm/commons.ts index e02676ae..caacf04a 100644 --- a/markets/amm/commons.ts +++ b/markets/amm/commons.ts @@ -199,6 +199,24 @@ export const CommonsConfig: ICommonConfiguration = { [eEthereumNetwork.main]: '0xbd4765210d4167CE2A5b87280D9E8Ee316D5EC7C', [eEthereumNetwork.tenderlyMain]: '0xbd4765210d4167CE2A5b87280D9E8Ee316D5EC7C', }, + LendingPoolConfigurator: { + [eEthereumNetwork.coverage]: '', + [eEthereumNetwork.hardhat]: '', + [eEthereumNetwork.buidlerevm]: '', + [eEthereumNetwork.kovan]: '0x36eB31800aa67a9c50df1d56EE01981A6E14Cce5', + [eEthereumNetwork.ropsten]: '', + [eEthereumNetwork.main]: '', + [eEthereumNetwork.tenderlyMain]: '', + }, + LendingPool: { + [eEthereumNetwork.coverage]: '', + [eEthereumNetwork.hardhat]: '', + [eEthereumNetwork.buidlerevm]: '', + [eEthereumNetwork.kovan]: '0x78142De7a1930412E9e50dEB3b80dB284c2dFa3A', + [eEthereumNetwork.ropsten]: '', + [eEthereumNetwork.main]: '', + [eEthereumNetwork.tenderlyMain]: '', + }, WethGateway: { [eEthereumNetwork.coverage]: '', [eEthereumNetwork.hardhat]: '', diff --git a/tasks/full/2_lending_pool.ts b/tasks/full/2_lending_pool.ts index db0daabb..fd6e1352 100644 --- a/tasks/full/2_lending_pool.ts +++ b/tasks/full/2_lending_pool.ts @@ -1,45 +1,60 @@ import { task } from 'hardhat/config'; -import { insertContractAddressInDb } from '../../helpers/contracts-helpers'; +import { getParamPerNetwork, insertContractAddressInDb } from '../../helpers/contracts-helpers'; import { deployATokensAndRatesHelper, deployLendingPool, deployLendingPoolConfigurator, deployStableAndVariableTokensHelper, } from '../../helpers/contracts-deployments'; -import { eContractid } from '../../helpers/types'; -import { waitForTx } from '../../helpers/misc-utils'; +import { eContractid, eEthereumNetwork } from '../../helpers/types'; +import { notFalsyOrZeroAddress, waitForTx } from '../../helpers/misc-utils'; import { getLendingPoolAddressesProvider, getLendingPool, getLendingPoolConfiguratorProxy, } from '../../helpers/contracts-getters'; import { HardhatRuntimeEnvironment } from 'hardhat/types'; +import { loadPoolConfig, ConfigNames } from '../../helpers/configuration'; task('full:deploy-lending-pool', 'Deploy lending pool for dev enviroment') .addFlag('verify', 'Verify contracts at Etherscan') - .setAction(async ({ verify }, DRE: HardhatRuntimeEnvironment) => { + .addParam('pool', `Pool name to retrieve configuration, supported: ${Object.values(ConfigNames)}`) + .setAction(async ({ verify, pool }, DRE: HardhatRuntimeEnvironment) => { try { await DRE.run('set-DRE'); - + const network = DRE.network.name; + const poolConfig = loadPoolConfig(pool) const addressesProvider = await getLendingPoolAddressesProvider(); + + const { LendingPool, LendingPoolConfigurator } = poolConfig; - // Deploy lending pool - const lendingPoolImpl = await deployLendingPool(verify); - - // Set lending pool impl to address provider - await waitForTx(await addressesProvider.setLendingPoolImpl(lendingPoolImpl.address)); + // Reuse/deploy lending pool implementation + let lendingPoolImplAddress = getParamPerNetwork(LendingPool, network) + if (!notFalsyOrZeroAddress(lendingPoolImplAddress)) { + console.log("\tDeploying new lending pool implementation & libraries..."); + const lendingPoolImpl = await deployLendingPool(verify); + lendingPoolImplAddress = lendingPoolImpl.address; + } + console.log("\tSetting lending pool implementation with address:" , lendingPoolImplAddress); + // Set lending pool impl to Address provider + await waitForTx(await addressesProvider.setLendingPoolImpl(lendingPoolImplAddress)); const address = await addressesProvider.getLendingPool(); const lendingPoolProxy = await getLendingPool(address); await insertContractAddressInDb(eContractid.LendingPool, lendingPoolProxy.address); - // Deploy lending pool configurator - const lendingPoolConfiguratorImpl = await deployLendingPoolConfigurator(verify); - + // Reuse/deploy lending pool configurator + let lendingPoolConfiguratorImplAddress = getParamPerNetwork(LendingPoolConfigurator, network); //await deployLendingPoolConfigurator(verify); + if (!notFalsyOrZeroAddress(lendingPoolConfiguratorImplAddress)) { + console.log("\tDeploying new configurator implementation..."); + const lendingPoolConfiguratorImpl = await deployLendingPoolConfigurator(verify); + lendingPoolConfiguratorImplAddress = lendingPoolConfiguratorImpl.address; + } + console.log("\tSetting lending pool configurator implementation with address:" , lendingPoolConfiguratorImplAddress); // Set lending pool conf impl to Address Provider await waitForTx( - await addressesProvider.setLendingPoolConfiguratorImpl(lendingPoolConfiguratorImpl.address) + await addressesProvider.setLendingPoolConfiguratorImpl(lendingPoolConfiguratorImplAddress) ); const lendingPoolConfiguratorProxy = await getLendingPoolConfiguratorProxy( diff --git a/tasks/full/6-initialize.ts b/tasks/full/6-initialize.ts index 1b949241..b5ee3aea 100644 --- a/tasks/full/6-initialize.ts +++ b/tasks/full/6-initialize.ts @@ -14,7 +14,7 @@ import { } from '../../helpers/configuration'; import { getWETHGateway } from '../../helpers/contracts-getters'; import { eEthereumNetwork, ICommonConfiguration } from '../../helpers/types'; -import { waitForTx } from '../../helpers/misc-utils'; +import { notFalsyOrZeroAddress, waitForTx } from '../../helpers/misc-utils'; import { initReservesByHelper, configureReservesByHelper } from '../../helpers/init-helpers'; import { exit } from 'process'; import { @@ -73,12 +73,13 @@ task('full:initialize-lending-pool', 'Initialize lending pool configuration.') LendingPoolCollateralManager, network ); - if (!collateralManagerAddress) { + if (!notFalsyOrZeroAddress(collateralManagerAddress)) { const collateralManager = await deployLendingPoolCollateralManager(verify); collateralManagerAddress = collateralManager.address; } // Seems unnecessary to register the collateral manager in the JSON db + console.log("\tSetting lending pool collateral manager implementation with address", collateralManagerAddress); await waitForTx( await addressesProvider.setLendingPoolCollateralManager(collateralManagerAddress) ); @@ -88,7 +89,7 @@ task('full:initialize-lending-pool', 'Initialize lending pool configuration.') const lendingPoolAddress = await addressesProvider.getLendingPool(); let gateWay = getParamPerNetwork(WethGateway, network); - if (gateWay == '') { + if (!notFalsyOrZeroAddress(gateWay)) { gateWay = (await getWETHGateway()).address; } await authorizeWETHGateway(gateWay, lendingPoolAddress); diff --git a/tasks/migrations/aave.mainnet.ts b/tasks/migrations/aave.mainnet.ts index fe05938d..19649262 100644 --- a/tasks/migrations/aave.mainnet.ts +++ b/tasks/migrations/aave.mainnet.ts @@ -21,7 +21,7 @@ task('aave:mainnet', 'Deploy development enviroment') await DRE.run('full:deploy-address-provider', { pool: POOL_NAME }); console.log('2. Deploy lending pool'); - await DRE.run('full:deploy-lending-pool'); + await DRE.run('full:deploy-lending-pool', { pool: POOL_NAME }); console.log('3. Deploy oracles'); await DRE.run('full:deploy-oracles', { pool: POOL_NAME }); diff --git a/tasks/migrations/amm.mainnet.ts b/tasks/migrations/amm.mainnet.ts index 73efeebe..3d0e6c8b 100644 --- a/tasks/migrations/amm.mainnet.ts +++ b/tasks/migrations/amm.mainnet.ts @@ -21,7 +21,7 @@ task('amm:mainnet', 'Deploy development enviroment') await DRE.run('full:deploy-address-provider', { pool: POOL_NAME }); console.log('2. Deploy lending pool'); - await DRE.run('full:deploy-lending-pool'); + await DRE.run('full:deploy-lending-pool', { pool: POOL_NAME }); console.log('3. Deploy oracles'); await DRE.run('full:deploy-oracles', { pool: POOL_NAME });