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

98 lines
3.4 KiB
TypeScript
Raw Normal View History

2020-11-19 16:46:23 +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,
authorizeWETHGateway,
} from '../../helpers/contracts-deployments';
import { getParamPerNetwork } from '../../helpers/contracts-helpers';
import { eNetwork } from '../../helpers/types';
import {
ConfigNames,
getReservesConfigByPool,
2020-11-27 15:40:00 +00:00
getTreasuryAddress,
getWethAddress,
loadPoolConfig,
} from '../../helpers/configuration';
2020-11-19 16:46:23 +00:00
import { tEthereumAddress, AavePools, eContractid } from '../../helpers/types';
import { waitForTx, filterMapBy } from '../../helpers/misc-utils';
import { configureReservesByHelper, initReservesByHelper } from '../../helpers/init-helpers';
2020-11-19 16:46:23 +00:00
import { getAllTokenAddresses } from '../../helpers/mock-helpers';
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)}`)
2020-11-19 16:46:23 +00:00
.setAction(async ({ verify, pool }, localBRE) => {
await localBRE.run('set-DRE');
const network = <eNetwork>localBRE.network.name;
const poolConfig = loadPoolConfig(pool);
2021-02-19 20:50:06 +00:00
const {
ATokenNamePrefix,
StableDebtTokenNamePrefix,
VariableDebtTokenNamePrefix,
SymbolPrefix,
WethGateway,
2021-02-19 20:50:06 +00:00
} = poolConfig;
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-11-19 16:46:23 +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();
2020-11-27 15:40:00 +00:00
const treasuryAddress = await getTreasuryAddress(poolConfig);
2020-11-19 16:46:23 +00:00
await initReservesByHelper(
reservesParams,
protoPoolReservesAddresses,
2021-02-19 20:50:06 +00:00
ATokenNamePrefix,
StableDebtTokenNamePrefix,
VariableDebtTokenNamePrefix,
SymbolPrefix,
2020-11-19 16:46:23 +00:00
admin,
2020-11-27 15:40:00 +00:00
treasuryAddress,
2020-11-19 16:46:23 +00:00
ZERO_ADDRESS,
verify
);
await configureReservesByHelper(reservesParams, protoPoolReservesAddresses, 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
);
await deployWalletBalancerProvider(verify);
await insertContractAddressInDb(eContractid.AaveProtocolDataProvider, testHelpers.address);
const lendingPoolAddress = await addressesProvider.getLendingPool();
const gateWay = await getParamPerNetwork(WethGateway, network);
await authorizeWETHGateway(gateWay, lendingPoolAddress);
2020-08-21 11:07:32 +00:00
});