2021-05-07 14:59:24 +00:00
|
|
|
import { task } from 'hardhat/config';
|
|
|
|
import { getParamPerNetwork } from '../../helpers/contracts-helpers';
|
|
|
|
import { waitForTx } from '../../helpers/misc-utils';
|
|
|
|
import { ConfigNames, loadPoolConfig } from '../../helpers/configuration';
|
|
|
|
import { eNetwork } from '../../helpers/types';
|
|
|
|
import {
|
|
|
|
getFirstSigner,
|
|
|
|
getLendingPoolAddressesProvider,
|
|
|
|
getLendingPoolAddressesProviderRegistry,
|
|
|
|
} from '../../helpers/contracts-getters';
|
|
|
|
import { isAddress, parseEther } from 'ethers/lib/utils';
|
|
|
|
import { isZeroAddress } from 'ethereumjs-util';
|
|
|
|
import { Signer } from 'ethers';
|
2021-05-10 08:16:13 +00:00
|
|
|
import { exit } from 'process';
|
2021-05-07 14:59:24 +00:00
|
|
|
|
|
|
|
task('add-market-to-registry', 'Adds address provider to registry')
|
|
|
|
.addParam('pool', `Pool name to retrieve configuration, supported: ${Object.values(ConfigNames)}`)
|
|
|
|
.addOptionalParam('addressesProvider', `Address of LendingPoolAddressProvider`)
|
|
|
|
.addFlag('verify', 'Verify contracts at Etherscan')
|
|
|
|
.addFlag('deployRegistry', 'Deploy a new address provider registry')
|
|
|
|
.setAction(async ({ verify, addressesProvider, pool, deployRegistry }, DRE) => {
|
|
|
|
await DRE.run('set-DRE');
|
|
|
|
let signer: Signer;
|
|
|
|
const network = <eNetwork>DRE.network.name;
|
|
|
|
const poolConfig = loadPoolConfig(pool);
|
|
|
|
const { ProviderId } = poolConfig;
|
|
|
|
|
|
|
|
let providerRegistryAddress = getParamPerNetwork(poolConfig.ProviderRegistry, network);
|
|
|
|
let providerRegistryOwner = getParamPerNetwork(poolConfig.ProviderRegistryOwner, network);
|
2021-05-10 08:16:13 +00:00
|
|
|
const currentSignerAddress = await (
|
|
|
|
await (await getFirstSigner()).getAddress()
|
|
|
|
).toLocaleLowerCase();
|
|
|
|
let deployed = false;
|
2021-05-07 14:59:24 +00:00
|
|
|
|
|
|
|
if (
|
|
|
|
deployRegistry ||
|
|
|
|
!providerRegistryAddress ||
|
|
|
|
!isAddress(providerRegistryAddress) ||
|
|
|
|
isZeroAddress(providerRegistryAddress)
|
|
|
|
) {
|
|
|
|
console.log('- Deploying a new Address Providers Registry:');
|
|
|
|
|
2021-07-21 09:38:55 +00:00
|
|
|
await DRE.run('full:deploy-address-provider-registry', { verify, pool });
|
2021-05-07 14:59:24 +00:00
|
|
|
|
|
|
|
providerRegistryAddress = (await getLendingPoolAddressesProviderRegistry()).address;
|
|
|
|
providerRegistryOwner = await (await getFirstSigner()).getAddress();
|
2021-05-10 08:16:13 +00:00
|
|
|
deployed = true;
|
2021-05-07 14:59:24 +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
|
2021-05-10 13:34:31 +00:00
|
|
|
if (process.env.FORK) {
|
2021-05-07 14:59:24 +00:00
|
|
|
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 });
|
2021-05-10 13:34:31 +00:00
|
|
|
} else if (
|
2021-05-10 08:16:13 +00:00
|
|
|
!deployed &&
|
|
|
|
providerRegistryOwner.toLocaleLowerCase() !== currentSignerAddress.toLocaleLowerCase()
|
|
|
|
) {
|
|
|
|
console.error('ProviderRegistryOwner config does not match current signer:');
|
|
|
|
console.error('Expected:', providerRegistryOwner);
|
|
|
|
console.error('Current:', currentSignerAddress);
|
|
|
|
exit(2);
|
2021-05-07 14:59:24 +00:00
|
|
|
} else {
|
|
|
|
signer = DRE.ethers.provider.getSigner(providerRegistryOwner);
|
|
|
|
}
|
|
|
|
|
|
|
|
// 1. Address Provider Registry instance
|
|
|
|
const addressesProviderRegistry = (
|
|
|
|
await getLendingPoolAddressesProviderRegistry(providerRegistryAddress)
|
|
|
|
).connect(signer);
|
|
|
|
|
|
|
|
const addressesProviderInstance = await getLendingPoolAddressesProvider(addressesProvider);
|
|
|
|
|
|
|
|
// 2. Set the provider at the Registry
|
|
|
|
await waitForTx(
|
|
|
|
await addressesProviderRegistry.registerAddressesProvider(
|
|
|
|
addressesProviderInstance.address,
|
|
|
|
ProviderId
|
|
|
|
)
|
|
|
|
);
|
|
|
|
console.log(
|
|
|
|
`Added LendingPoolAddressesProvider with address "${addressesProviderInstance.address}" to registry located at ${addressesProviderRegistry.address}`
|
|
|
|
);
|
|
|
|
});
|