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

102 lines
3.8 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';
import { eNetwork } from '../../helpers/types';
import {
getFirstSigner,
getLendingPoolAddressesProviderRegistry,
} from '../../helpers/contracts-getters';
import { formatEther, isAddress, parseEther } from 'ethers/lib/utils';
import { isZeroAddress } from 'ethereumjs-util';
2021-01-12 02:15:47 +00:00
import { Signer, BigNumber } from 'ethers';
import { parse } from 'path';
2021-01-12 02:15:47 +00:00
//import BigNumber from 'bignumber.js';
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');
let signer: Signer;
const network = <eNetwork>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);
const providerRegistryOwner = getParamPerNetwork(poolConfig.ProviderRegistryOwner, network);
if (
!providerRegistryAddress ||
!isAddress(providerRegistryAddress) ||
isZeroAddress(providerRegistryAddress)
) {
throw Error('config.ProviderRegistry is missing or is not an address.');
}
2020-11-05 11:35:50 +00:00
if (
!providerRegistryOwner ||
!isAddress(providerRegistryOwner) ||
isZeroAddress(providerRegistryOwner)
) {
throw Error('config.ProviderRegistryOwner is missing or is not an address.');
}
// Checks if deployer address is registry owner
if (process.env.MAINNET_FORK === 'true') {
await DRE.network.provider.request({
method: 'hardhat_impersonateAccount',
params: [providerRegistryOwner],
});
signer = DRE.ethers.provider.getSigner(providerRegistryOwner);
const firstAccount = await getFirstSigner();
await firstAccount.sendTransaction({ value: parseEther('10'), to: providerRegistryOwner });
} else {
signer = await getFirstSigner();
const deployerAddress = await signer.getAddress();
if (providerRegistryOwner !== (await signer.getAddress())) {
throw Error(
`Current signer is not provider registry owner. \nCurrent deployer address: ${deployerAddress} \nExpected address: ${poolConfig.ProviderRegistryOwner}`
);
}
}
// 1. Address Provider Registry instance
const addressesProviderRegistry = (
await getLendingPoolAddressesProviderRegistry(providerRegistryAddress)
).connect(signer);
2020-08-26 10:38:52 +00:00
console.log('Registry Address', addressesProviderRegistry.address);
2020-08-26 10:38:52 +00:00
// 2. Deploy address provider and set genesis manager
const addressesProvider = await deployLendingPoolAddressesProvider(MarketId, verify);
2021-02-18 21:49:29 +00:00
// DISABLE SEC. 3 FOR GOVERNANCE USE!
// 3. Set the provider at the Registry
2021-02-18 21:49:29 +00:00
await waitForTx(
await addressesProviderRegistry.registerAddressesProvider(
addressesProvider.address,
ProviderId
)
);
// 4. 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());
2020-08-26 10:38:52 +00:00
});