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

92 lines
3.2 KiB
TypeScript
Raw Normal View History

import {task} from '@nomiclabs/buidler/config';
import {
2020-09-24 15:48:29 +00:00
deployLendingPoolCollateralManager,
2020-08-21 11:07:32 +00:00
deployMockFlashLoanReceiver,
deployWalletBalancerProvider,
deployAaveProtocolTestHelpers,
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,
getLendingPool,
getLendingPoolConfiguratorProxy,
getLendingPoolAddressesProvider,
} from '../../helpers/contracts-getters';
import {insertContractAddressInDb} from '../../helpers/contracts-helpers';
task('dev:initialize-lending-pool', 'Initialize lending pool configuration.')
2020-08-21 11:07:32 +00:00
.addOptionalParam('verify', 'Verify contracts at Etherscan')
.addParam('pool', `Pool name to retrieve configuration, supported: ${Object.values(ConfigNames)}`)
.setAction(async ({verify, pool}, localBRE) => {
2020-08-21 11:07:32 +00:00
await localBRE.run('set-bre');
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 lendingPoolProxy = await getLendingPool();
const lendingPoolConfiguratorProxy = await getLendingPoolConfiguratorProxy();
const allTokenAddresses = getAllTokenAddresses(mockTokens);
const addressesProvider = await getLendingPoolAddressesProvider();
2020-08-21 11:07:32 +00:00
const protoPoolReservesAddresses = <{[symbol: string]: tEthereumAddress}>(
filterMapBy(allTokenAddresses, (key: string) => !key.includes('UNI'))
);
2020-10-13 11:41:57 +00:00
const testHelpers = await deployAaveProtocolTestHelpers(addressesProvider.address, verify);
const reservesParams = getReservesConfigByPool(AavePools.proto);
const admin = await addressesProvider.getAaveAdmin();
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.AaveProtocolTestHelpers, testHelpers.address);
const wethAddress = await getWethAddress(poolConfig);
await deployWETHGateway([wethAddress, addressesProvider.address]);
2020-08-21 11:07:32 +00:00
});