aave-protocol-v2/tasks/full/5_initialize.ts

62 lines
2.6 KiB
TypeScript
Raw Normal View History

2020-11-05 11:18:20 +00:00
import {task} from 'hardhat/config';
import {getParamPerNetwork} from '../../helpers/contracts-helpers';
import {
2020-09-24 15:48:29 +00:00
deployLendingPoolCollateralManager,
2020-08-21 11:07:32 +00:00
deployWalletBalancerProvider,
deployAaveProtocolDataProvider,
deployWETHGateway,
} from '../../helpers/contracts-deployments';
import {loadPoolConfig, ConfigNames, getWethAddress} from '../../helpers/configuration';
import {eEthereumNetwork, ICommonConfiguration} from '../../helpers/types';
import {waitForTx} from '../../helpers/misc-utils';
import {
initReservesByHelper,
enableReservesToBorrowByHelper,
enableReservesAsCollateralByHelper,
} from '../../helpers/init-helpers';
2020-09-24 15:48:29 +00:00
import {exit} from 'process';
import {getLendingPoolAddressesProvider} from '../../helpers/contracts-getters';
import {ZERO_ADDRESS} from '../../helpers/constants';
task('full:initialize-lending-pool', 'Initialize lending pool configuration.')
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}, localBRE) => {
2020-09-24 15:48:29 +00:00
try {
await localBRE.run('set-DRE');
2020-09-24 15:48:29 +00:00
const network = <eEthereumNetwork>localBRE.network.name;
const poolConfig = loadPoolConfig(pool);
const {ReserveAssets, ReservesConfig} = poolConfig as ICommonConfiguration;
2020-09-24 15:48:29 +00:00
const reserveAssets = await getParamPerNetwork(ReserveAssets, network);
2020-08-21 11:07:32 +00:00
2020-09-24 15:48:29 +00:00
const addressesProvider = await getLendingPoolAddressesProvider();
const testHelpers = await deployAaveProtocolDataProvider(addressesProvider.address, verify);
2020-10-13 11:41:57 +00:00
2020-11-05 15:15:52 +00:00
const admin = await addressesProvider.getPoolAdmin();
if (!reserveAssets) {
throw 'Reserve assets is undefined. Check ReserveAssets configuration at config directory';
}
await initReservesByHelper(ReservesConfig, reserveAssets, admin, ZERO_ADDRESS);
await enableReservesToBorrowByHelper(ReservesConfig, reserveAssets, testHelpers, admin);
await enableReservesAsCollateralByHelper(ReservesConfig, reserveAssets, testHelpers, admin);
2020-09-24 15:48:29 +00:00
const collateralManager = await deployLendingPoolCollateralManager(verify);
await waitForTx(
await addressesProvider.setLendingPoolCollateralManager(collateralManager.address)
);
2020-09-24 15:48:29 +00:00
await deployWalletBalancerProvider(addressesProvider.address, verify);
const wethAddress = await getWethAddress(poolConfig);
const lendingPoolAddress = await addressesProvider.getLendingPool();
await deployWETHGateway([wethAddress, lendingPoolAddress]);
2020-09-24 15:48:29 +00:00
} catch (err) {
console.error(err);
exit(1);
}
2020-08-21 11:07:32 +00:00
});