2020-11-05 11:18:20 +00:00
|
|
|
import {task} from 'hardhat/config';
|
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
|
|
|
deployMockFlashLoanReceiver,
|
|
|
|
deployWalletBalancerProvider,
|
|
|
|
deployAaveProtocolTestHelpers,
|
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 {
|
|
|
|
ConfigNames,
|
|
|
|
getReservesConfigByPool,
|
|
|
|
getWethAddress,
|
|
|
|
loadPoolConfig,
|
|
|
|
} from '../../helpers/configuration';
|
2020-08-20 15:35:05 +00:00
|
|
|
|
2020-08-21 11:07:32 +00:00
|
|
|
import {tEthereumAddress, AavePools, eContractid} from '../../helpers/types';
|
|
|
|
import {waitForTx, filterMapBy} from '../../helpers/misc-utils';
|
2020-10-16 09:27:09 +00:00
|
|
|
import {
|
2020-10-26 16:43:10 +00:00
|
|
|
enableReservesToBorrowByHelper,
|
|
|
|
enableReservesAsCollateralByHelper,
|
2020-10-23 16:38:27 +00:00
|
|
|
initReservesByHelper,
|
2020-10-16 09:27:09 +00:00
|
|
|
} from '../../helpers/init-helpers';
|
2020-08-25 15:15:27 +00:00
|
|
|
import {getAllTokenAddresses} from '../../helpers/mock-helpers';
|
2020-09-24 15:48:29 +00:00
|
|
|
import {ZERO_ADDRESS} from '../../helpers/constants';
|
2020-11-02 16:51:54 +00:00
|
|
|
import {getAllMockedTokens, getLendingPoolAddressesProvider} from '../../helpers/contracts-getters';
|
2020-10-16 09:27:09 +00:00
|
|
|
import {insertContractAddressInDb} from '../../helpers/contracts-helpers';
|
2020-08-20 15:35:05 +00:00
|
|
|
|
2020-08-31 10:10:40 +00:00
|
|
|
task('dev:initialize-lending-pool', 'Initialize lending pool configuration.')
|
2020-11-02 13:45:00 +00:00
|
|
|
.addFlag('verify', 'Verify contracts at Etherscan')
|
2020-10-28 17:06:24 +00:00
|
|
|
.addParam('pool', `Pool name to retrieve configuration, supported: ${Object.values(ConfigNames)}`)
|
|
|
|
.setAction(async ({verify, pool}, localBRE) => {
|
2020-11-05 12:44:20 +00:00
|
|
|
await localBRE.run('set-DRE');
|
2020-10-28 17:06:24 +00:00
|
|
|
const poolConfig = loadPoolConfig(pool);
|
2020-08-20 15:35:05 +00:00
|
|
|
|
2020-08-25 12:15:35 +00:00
|
|
|
const mockTokens = await getAllMockedTokens();
|
2020-08-21 11:07:32 +00:00
|
|
|
const allTokenAddresses = getAllTokenAddresses(mockTokens);
|
|
|
|
|
2020-08-20 15:35:05 +00:00
|
|
|
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
|
|
|
);
|
2020-08-20 15:35:05 +00:00
|
|
|
|
2020-10-13 11:41:57 +00:00
|
|
|
const testHelpers = await deployAaveProtocolTestHelpers(addressesProvider.address, verify);
|
|
|
|
|
2020-08-20 15:35:05 +00:00
|
|
|
const reservesParams = getReservesConfigByPool(AavePools.proto);
|
|
|
|
|
2020-11-05 15:15:52 +00:00
|
|
|
const admin = await addressesProvider.getPoolAdmin();
|
2020-10-23 16:38:27 +00:00
|
|
|
|
2020-10-27 09:58:51 +00:00
|
|
|
await initReservesByHelper(reservesParams, protoPoolReservesAddresses, admin, ZERO_ADDRESS);
|
2020-10-26 16:43:10 +00:00
|
|
|
await enableReservesToBorrowByHelper(
|
2020-08-20 15:35:05 +00:00
|
|
|
reservesParams,
|
|
|
|
protoPoolReservesAddresses,
|
2020-10-13 11:41:57 +00:00
|
|
|
testHelpers,
|
2020-10-26 16:43:10 +00:00
|
|
|
admin
|
2020-08-20 15:35:05 +00:00
|
|
|
);
|
2020-10-26 16:43:10 +00:00
|
|
|
await enableReservesAsCollateralByHelper(
|
2020-08-20 15:35:05 +00:00
|
|
|
reservesParams,
|
|
|
|
protoPoolReservesAddresses,
|
2020-10-13 11:41:57 +00:00
|
|
|
testHelpers,
|
2020-10-26 16:43:10 +00:00
|
|
|
admin
|
2020-08-20 15:35:05 +00:00
|
|
|
);
|
|
|
|
|
2020-09-24 15:48:29 +00:00
|
|
|
const collateralManager = await deployLendingPoolCollateralManager(verify);
|
2020-08-20 15:35:05 +00:00
|
|
|
await waitForTx(
|
2020-09-24 15:48:29 +00:00
|
|
|
await addressesProvider.setLendingPoolCollateralManager(collateralManager.address)
|
2020-08-20 15:35:05 +00:00
|
|
|
);
|
|
|
|
|
2020-08-21 11:07:32 +00:00
|
|
|
const mockFlashLoanReceiver = await deployMockFlashLoanReceiver(
|
|
|
|
addressesProvider.address,
|
|
|
|
verify
|
|
|
|
);
|
2020-08-20 15:35:05 +00:00
|
|
|
await insertContractAddressInDb(
|
|
|
|
eContractid.MockFlashLoanReceiver,
|
|
|
|
mockFlashLoanReceiver.address
|
|
|
|
);
|
|
|
|
|
2020-08-21 11:07:32 +00:00
|
|
|
await deployWalletBalancerProvider(addressesProvider.address, verify);
|
2020-08-20 15:35:05 +00:00
|
|
|
|
|
|
|
await insertContractAddressInDb(eContractid.AaveProtocolTestHelpers, testHelpers.address);
|
2020-10-28 17:06:24 +00:00
|
|
|
|
2020-11-02 17:43:50 +00:00
|
|
|
const lendingPoolAddress = await addressesProvider.getLendingPool();
|
2020-10-28 17:06:24 +00:00
|
|
|
const wethAddress = await getWethAddress(poolConfig);
|
2020-11-02 17:43:50 +00:00
|
|
|
await deployWETHGateway([wethAddress, lendingPoolAddress]);
|
2020-08-21 11:07:32 +00:00
|
|
|
});
|