mirror of
https://github.com/Instadapp/aave-protocol-v2.git
synced 2024-07-29 21:47:30 +00:00
103 lines
3.8 KiB
TypeScript
103 lines
3.8 KiB
TypeScript
import { task } from 'hardhat/config';
|
|
import { getParamPerNetwork } from '../../helpers/contracts-helpers';
|
|
import {
|
|
deployLendingPoolAddressesProvider,
|
|
deployLendingPoolAddressesProviderRegistry,
|
|
} from '../../helpers/contracts-deployments';
|
|
import { notFalsyOrZeroAddress, waitForTx } from '../../helpers/misc-utils';
|
|
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';
|
|
import { Signer, BigNumber } from 'ethers';
|
|
import { parse } from 'path';
|
|
//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('deployRegistry', 'Deploy a new address provider registry')
|
|
.setAction(async ({ verify, pool, deployRegistry }, DRE) => {
|
|
await DRE.run('set-DRE');
|
|
let signer: Signer;
|
|
const network = <eNetwork>DRE.network.name;
|
|
const poolConfig = loadPoolConfig(pool);
|
|
const { ProviderId, MarketId } = poolConfig;
|
|
|
|
let providerRegistryAddress = getParamPerNetwork(poolConfig.ProviderRegistry, network);
|
|
let providerRegistryOwner = getParamPerNetwork(poolConfig.ProviderRegistryOwner, network);
|
|
|
|
if (
|
|
deployRegistry ||
|
|
!providerRegistryAddress ||
|
|
!isAddress(providerRegistryAddress) ||
|
|
isZeroAddress(providerRegistryAddress)
|
|
) {
|
|
console.log('- Deploying a new Address Providers Registry:');
|
|
|
|
await DRE.run('full:deploy-address-provider-registry');
|
|
|
|
providerRegistryAddress = (await getLendingPoolAddressesProviderRegistry()).address;
|
|
providerRegistryOwner = await (await getFirstSigner()).getAddress();
|
|
}
|
|
|
|
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 = DRE.ethers.provider.getSigner(providerRegistryOwner);
|
|
}
|
|
// 1. Address Provider Registry instance
|
|
const addressesProviderRegistry = (
|
|
await getLendingPoolAddressesProviderRegistry(providerRegistryAddress)
|
|
).connect(signer);
|
|
|
|
console.log('Registry Address', addressesProviderRegistry.address);
|
|
|
|
// 2. Deploy address provider and set genesis manager
|
|
const addressesProvider = await deployLendingPoolAddressesProvider(MarketId, verify);
|
|
|
|
// DISABLE SEC. 3 FOR GOVERNANCE USE!
|
|
// 3. Set the provider at the Registry
|
|
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());
|
|
});
|