2020-11-19 16:46:23 +00:00
|
|
|
import { task } from 'hardhat/config';
|
|
|
|
import { getParamPerNetwork } from '../../helpers/contracts-helpers';
|
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
|
|
|
deployWalletBalancerProvider,
|
2020-10-28 17:06:24 +00:00
|
|
|
deployWETHGateway,
|
2021-02-22 12:23:52 +00:00
|
|
|
authorizeWETHGateway,
|
2020-10-16 09:27:09 +00:00
|
|
|
} from '../../helpers/contracts-deployments';
|
2021-01-27 14:43:34 +00:00
|
|
|
import {
|
|
|
|
loadPoolConfig,
|
|
|
|
ConfigNames,
|
|
|
|
getWethAddress,
|
|
|
|
getTreasuryAddress,
|
|
|
|
} from '../../helpers/configuration';
|
2021-02-22 13:58:16 +00:00
|
|
|
import { getWETHGateway } from '../../helpers/contracts-getters';
|
2021-02-23 14:42:47 +00:00
|
|
|
import { eNetwork, ICommonConfiguration } from '../../helpers/types';
|
2021-02-23 03:25:48 +00:00
|
|
|
import { notFalsyOrZeroAddress, waitForTx } from '../../helpers/misc-utils';
|
2021-01-27 14:43:34 +00:00
|
|
|
import { initReservesByHelper, configureReservesByHelper } from '../../helpers/init-helpers';
|
2020-11-19 16:46:23 +00:00
|
|
|
import { exit } from 'process';
|
2020-11-20 10:32:17 +00:00
|
|
|
import {
|
|
|
|
getAaveProtocolDataProvider,
|
|
|
|
getLendingPoolAddressesProvider,
|
|
|
|
} from '../../helpers/contracts-getters';
|
2020-11-19 16:46:23 +00:00
|
|
|
import { ZERO_ADDRESS } from '../../helpers/constants';
|
2020-08-20 15:35:05 +00:00
|
|
|
|
2020-08-31 10:10:40 +00:00
|
|
|
task('full:initialize-lending-pool', 'Initialize lending pool configuration.')
|
2020-09-24 15:48:29 +00:00
|
|
|
.addFlag('verify', 'Verify contracts at Etherscan')
|
2020-08-31 10:10:40 +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-09-24 15:48:29 +00:00
|
|
|
try {
|
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-09-24 15:48:29 +00:00
|
|
|
const poolConfig = loadPoolConfig(pool);
|
2021-02-22 12:23:52 +00:00
|
|
|
const {
|
2021-02-19 20:50:06 +00:00
|
|
|
ATokenNamePrefix,
|
|
|
|
StableDebtTokenNamePrefix,
|
|
|
|
VariableDebtTokenNamePrefix,
|
|
|
|
SymbolPrefix,
|
|
|
|
ReserveAssets,
|
|
|
|
ReservesConfig,
|
2021-02-22 12:23:52 +00:00
|
|
|
LendingPoolCollateralManager,
|
|
|
|
WethGateway,
|
2021-03-26 14:20:24 +00:00
|
|
|
IncentivesController,
|
2021-02-19 20:50:06 +00:00
|
|
|
} = poolConfig as ICommonConfiguration;
|
2020-08-20 15:35:05 +00:00
|
|
|
|
2020-09-24 15:48:29 +00:00
|
|
|
const reserveAssets = await getParamPerNetwork(ReserveAssets, network);
|
2021-03-26 14:20:24 +00:00
|
|
|
const incentivesController = await getParamPerNetwork(IncentivesController, network);
|
2020-09-24 15:48:29 +00:00
|
|
|
const addressesProvider = await getLendingPoolAddressesProvider();
|
2020-08-20 15:35:05 +00:00
|
|
|
|
2020-11-20 10:32:17 +00:00
|
|
|
const testHelpers = await getAaveProtocolDataProvider();
|
2020-10-13 11:41:57 +00:00
|
|
|
|
2020-11-05 15:15:52 +00:00
|
|
|
const admin = await addressesProvider.getPoolAdmin();
|
2020-10-23 16:38:27 +00:00
|
|
|
if (!reserveAssets) {
|
|
|
|
throw 'Reserve assets is undefined. Check ReserveAssets configuration at config directory';
|
|
|
|
}
|
|
|
|
|
2020-11-27 15:40:00 +00:00
|
|
|
const treasuryAddress = await getTreasuryAddress(poolConfig);
|
2021-02-10 23:36:51 +00:00
|
|
|
|
2021-01-27 14:43:34 +00:00
|
|
|
await initReservesByHelper(
|
|
|
|
ReservesConfig,
|
|
|
|
reserveAssets,
|
2021-02-19 20:50:06 +00:00
|
|
|
ATokenNamePrefix,
|
|
|
|
StableDebtTokenNamePrefix,
|
|
|
|
VariableDebtTokenNamePrefix,
|
|
|
|
SymbolPrefix,
|
2021-01-27 14:43:34 +00:00
|
|
|
admin,
|
|
|
|
treasuryAddress,
|
2021-03-26 14:20:24 +00:00
|
|
|
incentivesController,
|
2021-01-27 14:43:34 +00:00
|
|
|
verify
|
|
|
|
);
|
2020-11-28 11:54:54 +00:00
|
|
|
await configureReservesByHelper(ReservesConfig, reserveAssets, testHelpers, admin);
|
2020-08-20 15:35:05 +00:00
|
|
|
|
2021-02-22 12:23:52 +00:00
|
|
|
let collateralManagerAddress = await getParamPerNetwork(
|
|
|
|
LendingPoolCollateralManager,
|
|
|
|
network
|
|
|
|
);
|
2021-02-23 03:25:48 +00:00
|
|
|
if (!notFalsyOrZeroAddress(collateralManagerAddress)) {
|
2021-02-12 03:54:04 +00:00
|
|
|
const collateralManager = await deployLendingPoolCollateralManager(verify);
|
|
|
|
collateralManagerAddress = collateralManager.address;
|
|
|
|
}
|
|
|
|
// Seems unnecessary to register the collateral manager in the JSON db
|
2021-01-12 02:15:47 +00:00
|
|
|
|
2021-02-23 14:42:47 +00:00
|
|
|
console.log(
|
|
|
|
'\tSetting lending pool collateral manager implementation with address',
|
|
|
|
collateralManagerAddress
|
|
|
|
);
|
2020-09-24 15:48:29 +00:00
|
|
|
await waitForTx(
|
2021-02-12 03:54:04 +00:00
|
|
|
await addressesProvider.setLendingPoolCollateralManager(collateralManagerAddress)
|
2020-09-24 15:48:29 +00:00
|
|
|
);
|
2020-08-20 15:35:05 +00:00
|
|
|
|
2021-03-31 12:13:44 +00:00
|
|
|
console.log(
|
|
|
|
'\tSetting AaveProtocolDataProvider at AddressesProvider at id: 0x01',
|
|
|
|
collateralManagerAddress
|
|
|
|
);
|
|
|
|
const aaveProtocolDataProvider = await getAaveProtocolDataProvider();
|
|
|
|
await waitForTx(
|
|
|
|
await addressesProvider.setAddress(
|
|
|
|
'0x0100000000000000000000000000000000000000000000000000000000000000',
|
|
|
|
aaveProtocolDataProvider.address
|
|
|
|
)
|
|
|
|
);
|
|
|
|
|
2020-11-20 10:32:17 +00:00
|
|
|
await deployWalletBalancerProvider(verify);
|
2020-10-28 17:06:24 +00:00
|
|
|
|
2020-11-02 17:43:50 +00:00
|
|
|
const lendingPoolAddress = await addressesProvider.getLendingPool();
|
2021-02-22 13:58:16 +00:00
|
|
|
|
|
|
|
let gateWay = getParamPerNetwork(WethGateway, network);
|
2021-02-23 03:25:48 +00:00
|
|
|
if (!notFalsyOrZeroAddress(gateWay)) {
|
2021-02-22 13:58:16 +00:00
|
|
|
gateWay = (await getWETHGateway()).address;
|
|
|
|
}
|
2021-03-11 15:55:04 +00:00
|
|
|
console.log('GATEWAY', gateWay);
|
2021-02-22 12:23:52 +00:00
|
|
|
await authorizeWETHGateway(gateWay, lendingPoolAddress);
|
2020-09-24 15:48:29 +00:00
|
|
|
} catch (err) {
|
|
|
|
console.error(err);
|
|
|
|
exit(1);
|
|
|
|
}
|
2020-08-21 11:07:32 +00:00
|
|
|
});
|