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

101 lines
3.5 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,
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,
loadPoolConfig,
} from '../../helpers/configuration';
2020-11-19 16:46:23 +00:00
import { tEthereumAddress, AavePools, eContractid } from '../../helpers/types';
2021-05-10 08:47:24 +00:00
import { waitForTx, filterMapBy, notFalsyOrZeroAddress } 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,
2021-05-10 08:47:24 +00:00
getWETHGateway,
2020-11-19 16:46:23 +00:00
} 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,
ReservesConfig,
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
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(
ReservesConfig,
2020-11-19 16:46:23 +00:00
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,
pool,
2020-11-19 16:46:23 +00:00
verify
);
await configureReservesByHelper(ReservesConfig, 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();
2021-05-10 08:47:24 +00:00
let gateway = getParamPerNetwork(WethGateway, network);
if (!notFalsyOrZeroAddress(gateway)) {
gateway = (await getWETHGateway()).address;
}
await authorizeWETHGateway(gateway, lendingPoolAddress);
2020-08-21 11:07:32 +00:00
});