aave-protocol-v2/tasks/full/1_address_provider.ts
2021-05-10 10:16:13 +02:00

50 lines
1.9 KiB
TypeScript

import { task } from 'hardhat/config';
import { deployLendingPoolAddressesProvider } from '../../helpers/contracts-deployments';
import { notFalsyOrZeroAddress, waitForTx } from '../../helpers/misc-utils';
import {
ConfigNames,
loadPoolConfig,
getGenesisPoolAdmin,
getEmergencyAdmin,
} from '../../helpers/configuration';
import { getParamPerNetwork } from '../../helpers/contracts-helpers';
import { eNetwork } from '../../helpers/types';
import { isZeroAddress } from 'ethereumjs-util';
//import BigNumber from 'bignumber.js';
task(
'full:deploy-address-provider',
'Deploy address provider, registry and fee provider for dev enviroment'
)
.addFlag('verify', 'Verify contracts at Etherscan')
.addParam('pool', `Pool name to retrieve configuration, supported: ${Object.values(ConfigNames)}`)
.addFlag('skipRegistry')
.setAction(async ({ verify, pool, skipRegistry }, DRE) => {
await DRE.run('set-DRE');
const poolConfig = loadPoolConfig(pool);
const { MarketId } = poolConfig;
// 1. Deploy address provider and set genesis manager
const addressesProvider = await deployLendingPoolAddressesProvider(MarketId, verify);
// 2. Add to registry or setup a new one
if (!skipRegistry) {
const providerRegistryAddress = getParamPerNetwork(
poolConfig.ProviderRegistry,
<eNetwork>DRE.network.name
);
await DRE.run('add-market-to-registry', {
pool,
addressesProvider: addressesProvider.address,
deployRegistry: !notFalsyOrZeroAddress(providerRegistryAddress),
});
}
// 3. Set pool admins
await waitForTx(await addressesProvider.setPoolAdmin(await getGenesisPoolAdmin(poolConfig)));
await waitForTx(await addressesProvider.setEmergencyAdmin(await getEmergencyAdmin(poolConfig)));
console.log('Pool Admin', await addressesProvider.getPoolAdmin());
console.log('Emergency Admin', await addressesProvider.getEmergencyAdmin());
});