2020-11-19 16:46:23 +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,
|
2020-11-10 14:19:47 +00:00
|
|
|
deployAaveProtocolDataProvider,
|
2021-02-22 12:23:52 +00:00
|
|
|
authorizeWETHGateway,
|
2020-10-16 09:27:09 +00:00
|
|
|
} from '../../helpers/contracts-deployments';
|
2021-02-22 12:23:52 +00:00
|
|
|
import { getParamPerNetwork } from '../../helpers/contracts-helpers';
|
2021-02-23 14:42:47 +00:00
|
|
|
import { eNetwork } from '../../helpers/types';
|
2020-10-28 17:06:24 +00:00
|
|
|
import {
|
|
|
|
ConfigNames,
|
|
|
|
getReservesConfigByPool,
|
2020-11-27 15:40:00 +00:00
|
|
|
getTreasuryAddress,
|
2020-10-28 17:06:24 +00:00
|
|
|
loadPoolConfig,
|
|
|
|
} from '../../helpers/configuration';
|
2020-08-20 15:35:05 +00:00
|
|
|
|
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';
|
2021-01-27 14:43:34 +00:00
|
|
|
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';
|
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)}`)
|
2020-11-19 16:46:23 +00:00
|
|
|
.setAction(async ({ verify, pool }, localBRE) => {
|
2020-11-05 12:44:20 +00:00
|
|
|
await localBRE.run('set-DRE');
|
2021-02-23 14:42:47 +00:00
|
|
|
const network = <eNetwork>localBRE.network.name;
|
2020-10-28 17:06:24 +00:00
|
|
|
const poolConfig = loadPoolConfig(pool);
|
2021-02-19 20:50:06 +00:00
|
|
|
const {
|
|
|
|
ATokenNamePrefix,
|
|
|
|
StableDebtTokenNamePrefix,
|
|
|
|
VariableDebtTokenNamePrefix,
|
|
|
|
SymbolPrefix,
|
2021-02-22 12:23:52 +00:00
|
|
|
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);
|
|
|
|
|
2020-08-20 15:35:05 +00:00
|
|
|
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
|
|
|
);
|
2020-08-20 15:35:05 +00:00
|
|
|
|
2020-11-10 14:19:47 +00:00
|
|
|
const testHelpers = await deployAaveProtocolDataProvider(addressesProvider.address, verify);
|
2020-10-13 11:41:57 +00:00
|
|
|
|
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-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
|
|
|
|
);
|
2021-01-27 14:43:34 +00:00
|
|
|
await configureReservesByHelper(reservesParams, protoPoolReservesAddresses, testHelpers, 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-11-20 10:32:17 +00:00
|
|
|
await deployWalletBalancerProvider(verify);
|
2020-08-20 15:35:05 +00:00
|
|
|
|
2020-11-10 14:19:47 +00:00
|
|
|
await insertContractAddressInDb(eContractid.AaveProtocolDataProvider, testHelpers.address);
|
2020-10-28 17:06:24 +00:00
|
|
|
|
2020-11-02 17:43:50 +00:00
|
|
|
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
|
|
|
});
|