aave-protocol-v2/tasks/full/2_lending_pool.ts

87 lines
4.0 KiB
TypeScript
Raw Normal View History

import { task } from 'hardhat/config';
import { getParamPerNetwork, insertContractAddressInDb } from '../../helpers/contracts-helpers';
import {
deployATokensAndRatesHelper,
deployLendingPool,
deployLendingPoolConfigurator,
deployStableAndVariableTokensHelper,
} from '../../helpers/contracts-deployments';
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')
2020-09-24 15:48:29 +00:00
.addFlag('verify', 'Verify contracts at Etherscan')
.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 = <eEthereumNetwork>DRE.network.name;
const poolConfig = loadPoolConfig(pool)
const addressesProvider = await getLendingPoolAddressesProvider();
const { LendingPool, LendingPoolConfigurator } = poolConfig;
// 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);
// 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(lendingPoolConfiguratorImplAddress)
);
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) {
if (DRE.network.name.includes('tenderly')) {
const transactionLink = `https://dashboard.tenderly.co/${DRE.config.tenderly.username}/${
DRE.config.tenderly.project
}/fork/${DRE.tenderlyRPC.getFork()}/simulation/${DRE.tenderlyRPC.getHead()}`;
console.error('Check tx error:', transactionLink);
}
throw error;
}
});