2021-01-15 15:48:54 +00:00
|
|
|
import { task } from 'hardhat/config';
|
2021-02-23 03:25:48 +00:00
|
|
|
import { getParamPerNetwork, insertContractAddressInDb } from '../../helpers/contracts-helpers';
|
2020-08-20 15:35:05 +00:00
|
|
|
import {
|
2020-10-27 09:58:51 +00:00
|
|
|
deployATokensAndRatesHelper,
|
2020-08-20 15:35:05 +00:00
|
|
|
deployLendingPool,
|
|
|
|
deployLendingPoolConfigurator,
|
2020-10-27 09:58:51 +00:00
|
|
|
deployStableAndVariableTokensHelper,
|
2020-10-16 09:27:09 +00:00
|
|
|
} from '../../helpers/contracts-deployments';
|
2021-02-23 14:42:47 +00:00
|
|
|
import { eContractid, eNetwork } from '../../helpers/types';
|
2021-02-23 03:25:48 +00:00
|
|
|
import { notFalsyOrZeroAddress, waitForTx } from '../../helpers/misc-utils';
|
2020-10-15 11:57:03 +00:00
|
|
|
import {
|
|
|
|
getLendingPoolAddressesProvider,
|
|
|
|
getLendingPool,
|
|
|
|
getLendingPoolConfiguratorProxy,
|
|
|
|
} from '../../helpers/contracts-getters';
|
2021-01-15 15:48:54 +00:00
|
|
|
import { HardhatRuntimeEnvironment } from 'hardhat/types';
|
2021-02-23 03:25:48 +00:00
|
|
|
import { loadPoolConfig, ConfigNames } from '../../helpers/configuration';
|
2020-08-20 15:35:05 +00:00
|
|
|
|
2020-08-31 10:10:40 +00:00
|
|
|
task('full:deploy-lending-pool', 'Deploy lending pool for dev enviroment')
|
2020-09-24 15:48:29 +00:00
|
|
|
.addFlag('verify', 'Verify contracts at Etherscan')
|
2021-02-23 03:25:48 +00:00
|
|
|
.addParam('pool', `Pool name to retrieve configuration, supported: ${Object.values(ConfigNames)}`)
|
|
|
|
.setAction(async ({ verify, pool }, DRE: HardhatRuntimeEnvironment) => {
|
2020-11-12 13:41:08 +00:00
|
|
|
try {
|
|
|
|
await DRE.run('set-DRE');
|
2021-02-23 14:42:47 +00:00
|
|
|
const network = <eNetwork>DRE.network.name;
|
|
|
|
const poolConfig = loadPoolConfig(pool);
|
2020-11-12 13:41:08 +00:00
|
|
|
const addressesProvider = await getLendingPoolAddressesProvider();
|
2021-02-23 14:42:47 +00:00
|
|
|
|
2021-02-23 03:25:48 +00:00
|
|
|
const { LendingPool, LendingPoolConfigurator } = poolConfig;
|
|
|
|
|
|
|
|
// Reuse/deploy lending pool implementation
|
2021-02-23 14:42:47 +00:00
|
|
|
let lendingPoolImplAddress = getParamPerNetwork(LendingPool, network);
|
2021-02-23 03:25:48 +00:00
|
|
|
if (!notFalsyOrZeroAddress(lendingPoolImplAddress)) {
|
2021-02-23 14:42:47 +00:00
|
|
|
console.log('\tDeploying new lending pool implementation & libraries...');
|
2021-02-23 03:25:48 +00:00
|
|
|
const lendingPoolImpl = await deployLendingPool(verify);
|
|
|
|
lendingPoolImplAddress = lendingPoolImpl.address;
|
2021-03-31 08:41:05 +00:00
|
|
|
await lendingPoolImpl.initialize(addressesProvider.address);
|
2021-02-23 03:25:48 +00:00
|
|
|
}
|
2021-02-23 14:42:47 +00:00
|
|
|
console.log('\tSetting lending pool implementation with address:', lendingPoolImplAddress);
|
2021-02-23 03:25:48 +00:00
|
|
|
// Set lending pool impl to Address provider
|
|
|
|
await waitForTx(await addressesProvider.setLendingPoolImpl(lendingPoolImplAddress));
|
2020-11-12 13:41:08 +00:00
|
|
|
|
|
|
|
const address = await addressesProvider.getLendingPool();
|
|
|
|
const lendingPoolProxy = await getLendingPool(address);
|
|
|
|
|
|
|
|
await insertContractAddressInDb(eContractid.LendingPool, lendingPoolProxy.address);
|
|
|
|
|
2021-02-23 03:25:48 +00:00
|
|
|
// Reuse/deploy lending pool configurator
|
|
|
|
let lendingPoolConfiguratorImplAddress = getParamPerNetwork(LendingPoolConfigurator, network); //await deployLendingPoolConfigurator(verify);
|
|
|
|
if (!notFalsyOrZeroAddress(lendingPoolConfiguratorImplAddress)) {
|
2021-02-23 14:42:47 +00:00
|
|
|
console.log('\tDeploying new configurator implementation...');
|
2021-02-23 03:25:48 +00:00
|
|
|
const lendingPoolConfiguratorImpl = await deployLendingPoolConfigurator(verify);
|
|
|
|
lendingPoolConfiguratorImplAddress = lendingPoolConfiguratorImpl.address;
|
|
|
|
}
|
2021-02-23 14:42:47 +00:00
|
|
|
console.log(
|
|
|
|
'\tSetting lending pool configurator implementation with address:',
|
|
|
|
lendingPoolConfiguratorImplAddress
|
|
|
|
);
|
2020-11-12 13:41:08 +00:00
|
|
|
// Set lending pool conf impl to Address Provider
|
|
|
|
await waitForTx(
|
2021-02-23 03:25:48 +00:00
|
|
|
await addressesProvider.setLendingPoolConfiguratorImpl(lendingPoolConfiguratorImplAddress)
|
2020-11-12 13:41:08 +00:00
|
|
|
);
|
|
|
|
|
|
|
|
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
|
|
|
|
);
|
|
|
|
} catch (error) {
|
2020-11-16 15:08:07 +00:00
|
|
|
if (DRE.network.name.includes('tenderly')) {
|
|
|
|
const transactionLink = `https://dashboard.tenderly.co/${DRE.config.tenderly.username}/${
|
|
|
|
DRE.config.tenderly.project
|
2021-05-18 08:40:22 +00:00
|
|
|
}/fork/${DRE.tenderlyNetwork.getFork()}/simulation/${DRE.tenderlyNetwork.getHead()}`;
|
2020-11-16 15:08:07 +00:00
|
|
|
console.error('Check tx error:', transactionLink);
|
|
|
|
}
|
|
|
|
throw error;
|
2020-11-12 13:41:08 +00:00
|
|
|
}
|
2020-08-20 15:35:05 +00:00
|
|
|
});
|