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

86 lines
3.0 KiB
TypeScript
Raw Normal View History

2020-11-05 11:18:20 +00:00
import {task} from 'hardhat/config';
import {
2020-09-24 15:48:29 +00:00
deployLendingPoolCollateralManager,
2020-08-21 11:07:32 +00:00
deployMockFlashLoanReceiver,
deployWalletBalancerProvider,
deployAaveProtocolDataProvider,
deployWETHGateway,
} from '../../helpers/contracts-deployments';
import {
ConfigNames,
getReservesConfigByPool,
getWethAddress,
loadPoolConfig,
} from '../../helpers/configuration';
2020-08-21 11:07:32 +00:00
import {tEthereumAddress, AavePools, eContractid} from '../../helpers/types';
import {waitForTx, filterMapBy} from '../../helpers/misc-utils';
import {
enableReservesToBorrowByHelper,
enableReservesAsCollateralByHelper,
initReservesByHelper,
} from '../../helpers/init-helpers';
import {getAllTokenAddresses} from '../../helpers/mock-helpers';
2020-09-24 15:48:29 +00:00
import {ZERO_ADDRESS} from '../../helpers/constants';
import {getAllMockedTokens, getLendingPoolAddressesProvider} from '../../helpers/contracts-getters';
import {insertContractAddressInDb} from '../../helpers/contracts-helpers';
task('dev:initialize-lending-pool', 'Initialize lending pool configuration.')
.addFlag('verify', 'Verify contracts at Etherscan')
.addParam('pool', `Pool name to retrieve configuration, supported: ${Object.values(ConfigNames)}`)
.setAction(async ({verify, pool}, localBRE) => {
await localBRE.run('set-DRE');
const poolConfig = loadPoolConfig(pool);
2020-08-25 12:15:35 +00:00
const mockTokens = await getAllMockedTokens();
2020-08-21 11:07:32 +00:00
const allTokenAddresses = getAllTokenAddresses(mockTokens);
const addressesProvider = await getLendingPoolAddressesProvider();
2020-08-21 11:07:32 +00:00
const protoPoolReservesAddresses = <{[symbol: string]: tEthereumAddress}>(
2020-11-04 10:47:06 +00:00
filterMapBy(allTokenAddresses, (key: string) => !key.includes('UNI_'))
2020-08-21 11:07:32 +00:00
);
const testHelpers = await deployAaveProtocolDataProvider(addressesProvider.address, verify);
2020-10-13 11:41:57 +00:00
const reservesParams = getReservesConfigByPool(AavePools.proto);
2020-11-05 15:15:52 +00:00
const admin = await addressesProvider.getPoolAdmin();
await initReservesByHelper(reservesParams, protoPoolReservesAddresses, admin, ZERO_ADDRESS);
await enableReservesToBorrowByHelper(
reservesParams,
protoPoolReservesAddresses,
2020-10-13 11:41:57 +00:00
testHelpers,
admin
);
await enableReservesAsCollateralByHelper(
reservesParams,
protoPoolReservesAddresses,
2020-10-13 11:41:57 +00:00
testHelpers,
admin
);
2020-09-24 15:48:29 +00:00
const collateralManager = await deployLendingPoolCollateralManager(verify);
await waitForTx(
2020-09-24 15:48:29 +00:00
await addressesProvider.setLendingPoolCollateralManager(collateralManager.address)
);
2020-08-21 11:07:32 +00:00
const mockFlashLoanReceiver = await deployMockFlashLoanReceiver(
addressesProvider.address,
verify
);
await insertContractAddressInDb(
eContractid.MockFlashLoanReceiver,
mockFlashLoanReceiver.address
);
2020-08-21 11:07:32 +00:00
await deployWalletBalancerProvider(addressesProvider.address, verify);
await insertContractAddressInDb(eContractid.AaveProtocolDataProvider, testHelpers.address);
const lendingPoolAddress = await addressesProvider.getLendingPool();
const wethAddress = await getWethAddress(poolConfig);
await deployWETHGateway([wethAddress, lendingPoolAddress]);
2020-08-21 11:07:32 +00:00
});