aave-protocol-v2/tasks/full/1_address_provider.ts

52 lines
2.2 KiB
TypeScript
Raw Normal View History

2020-11-26 15:11:40 +00:00
import { task } from 'hardhat/config';
import { getParamPerNetwork } from '../../helpers/contracts-helpers';
2020-08-26 10:38:52 +00:00
import {
deployLendingPoolAddressesProvider,
deployLendingPoolAddressesProviderRegistry,
} from '../../helpers/contracts-deployments';
2020-11-26 15:11:40 +00:00
import { notFalsyOrZeroAddress, waitForTx } from '../../helpers/misc-utils';
2020-11-05 11:35:50 +00:00
import {
ConfigNames,
loadPoolConfig,
getGenesisPoolAdmin,
getEmergencyAdmin,
} from '../../helpers/configuration';
2020-11-26 15:11:40 +00:00
import { eEthereumNetwork } from '../../helpers/types';
import { getLendingPoolAddressesProviderRegistry } from '../../helpers/contracts-getters';
2020-08-26 10:38:52 +00:00
task(
'full:deploy-address-provider',
'Deploy address provider, registry and fee provider for dev enviroment'
)
2020-09-24 15:48:29 +00:00
.addFlag('verify', 'Verify contracts at Etherscan')
2020-08-26 10:38:52 +00:00
.addParam('pool', `Pool name to retrieve configuration, supported: ${Object.values(ConfigNames)}`)
2020-11-26 15:11:40 +00:00
.setAction(async ({ verify, pool }, DRE) => {
await DRE.run('set-DRE');
const network = <eEthereumNetwork>DRE.network.name;
2020-08-26 10:38:52 +00:00
const poolConfig = loadPoolConfig(pool);
2020-11-26 15:11:40 +00:00
const { ProviderId, MarketId } = poolConfig;
2020-08-26 10:38:52 +00:00
const providerRegistryAddress = getParamPerNetwork(poolConfig.ProviderRegistry, network);
// Deploy address provider and set genesis manager
2020-11-26 15:11:40 +00:00
const addressesProvider = await deployLendingPoolAddressesProvider(MarketId, verify);
2020-11-05 11:35:50 +00:00
await waitForTx(await addressesProvider.setPoolAdmin(await getGenesisPoolAdmin(poolConfig)));
await waitForTx(await addressesProvider.setEmergencyAdmin(await getEmergencyAdmin(poolConfig)));
2020-11-05 11:35:50 +00:00
console.log('Pool Admin', await addressesProvider.getPoolAdmin());
console.log('Emergency Admin', await addressesProvider.getEmergencyAdmin());
2020-08-26 10:38:52 +00:00
// If no provider registry is set, deploy lending pool address provider registry and register the address provider
const addressesProviderRegistry = notFalsyOrZeroAddress(providerRegistryAddress)
? await getLendingPoolAddressesProviderRegistry(providerRegistryAddress)
: await deployLendingPoolAddressesProviderRegistry(verify);
2020-08-26 10:38:52 +00:00
await waitForTx(
await addressesProviderRegistry.registerAddressesProvider(
addressesProvider.address,
ProviderId
)
);
});