aave-protocol-v2/tasks/full/6-initialize.ts

101 lines
3.5 KiB
TypeScript

import { task } from 'hardhat/config';
import { getParamPerNetwork } from '../../helpers/contracts-helpers';
import {
deployLendingPoolCollateralManager,
deployWalletBalancerProvider,
deployWETHGateway,
authorizeWETHGateway,
} from '../../helpers/contracts-deployments';
import {
loadPoolConfig,
ConfigNames,
getWethAddress,
getTreasuryAddress,
} from '../../helpers/configuration';
import { getWETHGateway } from '../../helpers/contracts-getters';
import { eEthereumNetwork, ICommonConfiguration } from '../../helpers/types';
import { notFalsyOrZeroAddress, waitForTx } from '../../helpers/misc-utils';
import { initReservesByHelper, configureReservesByHelper } from '../../helpers/init-helpers';
import { exit } from 'process';
import {
getAaveProtocolDataProvider,
getLendingPoolAddressesProvider,
} from '../../helpers/contracts-getters';
import { ZERO_ADDRESS } from '../../helpers/constants';
task('full:initialize-lending-pool', 'Initialize lending pool configuration.')
.addFlag('verify', 'Verify contracts at Etherscan')
.addParam('pool', `Pool name to retrieve configuration, supported: ${Object.values(ConfigNames)}`)
.setAction(async ({ verify, pool }, localBRE) => {
try {
await localBRE.run('set-DRE');
const network = <eEthereumNetwork>localBRE.network.name;
const poolConfig = loadPoolConfig(pool);
const {
ATokenNamePrefix,
StableDebtTokenNamePrefix,
VariableDebtTokenNamePrefix,
SymbolPrefix,
ReserveAssets,
ReservesConfig,
LendingPoolCollateralManager,
WethGateway,
} = poolConfig as ICommonConfiguration;
const reserveAssets = await getParamPerNetwork(ReserveAssets, network);
const addressesProvider = await getLendingPoolAddressesProvider();
const testHelpers = await getAaveProtocolDataProvider();
const admin = await addressesProvider.getPoolAdmin();
if (!reserveAssets) {
throw 'Reserve assets is undefined. Check ReserveAssets configuration at config directory';
}
const treasuryAddress = await getTreasuryAddress(poolConfig);
await initReservesByHelper(
ReservesConfig,
reserveAssets,
ATokenNamePrefix,
StableDebtTokenNamePrefix,
VariableDebtTokenNamePrefix,
SymbolPrefix,
admin,
treasuryAddress,
ZERO_ADDRESS,
verify
);
await configureReservesByHelper(ReservesConfig, reserveAssets, testHelpers, admin);
let collateralManagerAddress = await getParamPerNetwork(
LendingPoolCollateralManager,
network
);
if (!notFalsyOrZeroAddress(collateralManagerAddress)) {
const collateralManager = await deployLendingPoolCollateralManager(verify);
collateralManagerAddress = collateralManager.address;
}
// Seems unnecessary to register the collateral manager in the JSON db
console.log("\tSetting lending pool collateral manager implementation with address", collateralManagerAddress);
await waitForTx(
await addressesProvider.setLendingPoolCollateralManager(collateralManagerAddress)
);
await deployWalletBalancerProvider(verify);
const lendingPoolAddress = await addressesProvider.getLendingPool();
let gateWay = getParamPerNetwork(WethGateway, network);
if (!notFalsyOrZeroAddress(gateWay)) {
gateWay = (await getWETHGateway()).address;
}
await authorizeWETHGateway(gateWay, lendingPoolAddress);
} catch (err) {
console.error(err);
exit(1);
}
});