2020-11-05 11:18:20 +00:00
|
|
|
import {task} from 'hardhat/config';
|
2020-10-16 09:27:09 +00:00
|
|
|
import {getParamPerNetwork} from '../../helpers/contracts-helpers';
|
2020-08-20 15:35:05 +00:00
|
|
|
import {
|
2020-09-24 15:48:29 +00:00
|
|
|
deployLendingPoolCollateralManager,
|
2020-08-21 11:07:32 +00:00
|
|
|
deployWalletBalancerProvider,
|
2020-11-10 14:19:47 +00:00
|
|
|
deployAaveProtocolDataProvider,
|
2020-10-28 17:06:24 +00:00
|
|
|
deployWETHGateway,
|
2020-10-16 09:27:09 +00:00
|
|
|
} from '../../helpers/contracts-deployments';
|
2020-10-28 17:06:24 +00:00
|
|
|
import {loadPoolConfig, ConfigNames, getWethAddress} from '../../helpers/configuration';
|
2020-10-26 16:43:10 +00:00
|
|
|
import {eEthereumNetwork, ICommonConfiguration} from '../../helpers/types';
|
2020-08-31 10:10:40 +00:00
|
|
|
import {waitForTx} from '../../helpers/misc-utils';
|
2020-10-16 09:27:09 +00:00
|
|
|
import {
|
2020-10-23 16:38:27 +00:00
|
|
|
initReservesByHelper,
|
2020-10-26 16:43:10 +00:00
|
|
|
enableReservesToBorrowByHelper,
|
|
|
|
enableReservesAsCollateralByHelper,
|
2020-10-16 09:27:09 +00:00
|
|
|
} from '../../helpers/init-helpers';
|
2020-09-24 15:48:29 +00:00
|
|
|
import {exit} from 'process';
|
2020-11-02 16:51:54 +00:00
|
|
|
import {getLendingPoolAddressesProvider} from '../../helpers/contracts-getters';
|
2020-10-26 16:43:10 +00:00
|
|
|
import {ZERO_ADDRESS} from '../../helpers/constants';
|
2020-08-20 15:35:05 +00:00
|
|
|
|
2020-08-31 10:10:40 +00:00
|
|
|
task('full:initialize-lending-pool', 'Initialize lending pool configuration.')
|
2020-09-24 15:48:29 +00:00
|
|
|
.addFlag('verify', 'Verify contracts at Etherscan')
|
2020-08-31 10:10:40 +00:00
|
|
|
.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 {
|
2020-11-05 12:44:20 +00:00
|
|
|
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-08-20 15:35:05 +00:00
|
|
|
|
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();
|
2020-08-20 15:35:05 +00:00
|
|
|
|
2020-11-10 14:19:47 +00:00
|
|
|
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();
|
2020-10-23 16:38:27 +00:00
|
|
|
if (!reserveAssets) {
|
|
|
|
throw 'Reserve assets is undefined. Check ReserveAssets configuration at config directory';
|
|
|
|
}
|
|
|
|
|
2020-10-27 09:58:51 +00:00
|
|
|
await initReservesByHelper(ReservesConfig, reserveAssets, admin, ZERO_ADDRESS);
|
2020-10-26 16:43:10 +00:00
|
|
|
await enableReservesToBorrowByHelper(ReservesConfig, reserveAssets, testHelpers, admin);
|
|
|
|
await enableReservesAsCollateralByHelper(ReservesConfig, reserveAssets, testHelpers, admin);
|
2020-08-20 15:35:05 +00:00
|
|
|
|
2020-09-24 15:48:29 +00:00
|
|
|
const collateralManager = await deployLendingPoolCollateralManager(verify);
|
|
|
|
await waitForTx(
|
|
|
|
await addressesProvider.setLendingPoolCollateralManager(collateralManager.address)
|
|
|
|
);
|
2020-08-20 15:35:05 +00:00
|
|
|
|
2020-09-24 15:48:29 +00:00
|
|
|
await deployWalletBalancerProvider(addressesProvider.address, verify);
|
2020-10-28 17:06:24 +00:00
|
|
|
|
|
|
|
const wethAddress = await getWethAddress(poolConfig);
|
2020-11-02 17:43:50 +00:00
|
|
|
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
|
|
|
});
|