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,
|
2020-10-16 09:27:09 +00:00
|
|
|
} 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';
|
2021-02-23 14:42:47 +00:00
|
|
|
import { eNetwork } from '../../helpers/types';
|
2020-11-30 18:25:06 +00:00
|
|
|
import {
|
|
|
|
getFirstSigner,
|
|
|
|
getLendingPoolAddressesProviderRegistry,
|
|
|
|
} from '../../helpers/contracts-getters';
|
2020-12-02 08:57:47 +00:00
|
|
|
import { formatEther, isAddress, parseEther } from 'ethers/lib/utils';
|
2020-11-30 18:25:06 +00:00
|
|
|
import { isZeroAddress } from 'ethereumjs-util';
|
2021-01-12 02:15:47 +00:00
|
|
|
import { Signer, BigNumber } from 'ethers';
|
2020-12-02 08:57:47 +00:00
|
|
|
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) => {
|
2020-11-16 18:22:22 +00:00
|
|
|
await DRE.run('set-DRE');
|
2020-11-30 18:25:06 +00:00
|
|
|
let signer: Signer;
|
2021-02-23 14:42:47 +00:00
|
|
|
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);
|
2020-11-30 18:25:06 +00:00
|
|
|
const providerRegistryOwner = getParamPerNetwork(poolConfig.ProviderRegistryOwner, network);
|
2020-11-12 13:12:26 +00:00
|
|
|
|
2020-11-30 18:25:06 +00:00
|
|
|
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
|
|
|
|
2020-11-30 18:25:06 +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);
|
2020-12-02 08:57:47 +00:00
|
|
|
const firstAccount = await getFirstSigner();
|
|
|
|
await firstAccount.sendTransaction({ value: parseEther('10'), to: providerRegistryOwner });
|
2020-11-30 18:25:06 +00:00
|
|
|
} else {
|
2021-03-02 16:21:04 +00:00
|
|
|
signer = DRE.ethers.provider.getSigner(providerRegistryOwner);
|
2020-11-30 18:25:06 +00:00
|
|
|
}
|
|
|
|
// 1. Address Provider Registry instance
|
|
|
|
const addressesProviderRegistry = (
|
|
|
|
await getLendingPoolAddressesProviderRegistry(providerRegistryAddress)
|
|
|
|
).connect(signer);
|
2020-08-26 10:38:52 +00:00
|
|
|
|
2020-11-30 18:25:06 +00:00
|
|
|
console.log('Registry Address', addressesProviderRegistry.address);
|
2020-08-26 10:38:52 +00:00
|
|
|
|
2020-11-30 18:25:06 +00:00
|
|
|
// 2. Deploy address provider and set genesis manager
|
|
|
|
const addressesProvider = await deployLendingPoolAddressesProvider(MarketId, verify);
|
2021-02-23 14:42:47 +00:00
|
|
|
|
2021-02-18 21:49:29 +00:00
|
|
|
// DISABLE SEC. 3 FOR GOVERNANCE USE!
|
2020-11-30 18:25:06 +00:00
|
|
|
// 3. Set the provider at the Registry
|
2021-02-18 21:49:29 +00:00
|
|
|
await waitForTx(
|
|
|
|
await addressesProviderRegistry.registerAddressesProvider(
|
|
|
|
addressesProvider.address,
|
|
|
|
ProviderId
|
|
|
|
)
|
|
|
|
);
|
2020-11-30 18:25:06 +00:00
|
|
|
|
|
|
|
// 4. Set pool admins
|
2021-02-23 14:42:47 +00:00
|
|
|
|
2020-11-30 18:25:06 +00:00
|
|
|
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
|
|
|
});
|