feat: merge fix/101-support-registry-config

This commit is contained in:
David Racero 2021-05-14 12:44:57 +02:00
commit 6f03bb9cf9
26 changed files with 279 additions and 142 deletions

View File

@ -30,6 +30,20 @@ jobs:
run: npm ci
- name: Test
run: npm run ci:test
- name: Dev deployment
run: npm run aave:evm:dev:migration
- name: Mainnet deployment at Mainnet fork
run: npm run aave:fork:main
env:
ALCHEMY_KEY: ${{ secrets.ALCHEMY_KEY }}
- name: Amm deployment at Mainnet fork
run: npm run amm:fork:main
env:
ALCHEMY_KEY: ${{ secrets.ALCHEMY_KEY }}
- name: Aave deployment at Kovan fork
run: npm run aave:fork:kovan
env:
ALCHEMY_KEY: ${{ secrets.ALCHEMY_KEY }}
# - name: Coverage
# run: npm run coverage
# - uses: codecov/codecov-action@v1

View File

@ -5,7 +5,7 @@ import { HardhatUserConfig } from 'hardhat/types';
import { accounts } from './test-wallets.js';
import { eEthereumNetwork, eNetwork, ePolygonNetwork, eXDaiNetwork } from './helpers/types';
import { BUIDLEREVM_CHAINID, COVERAGE_CHAINID } from './helpers/buidler-constants';
import { NETWORKS_RPC_URL, NETWORKS_DEFAULT_GAS } from './helper-hardhat-config';
import { NETWORKS_RPC_URL, NETWORKS_DEFAULT_GAS, BLOCK_TO_FORK } from './helper-hardhat-config';
require('dotenv').config();
@ -24,7 +24,7 @@ const HARDFORK = 'istanbul';
const ETHERSCAN_KEY = process.env.ETHERSCAN_KEY || '';
const MNEMONIC_PATH = "m/44'/60'/0'/0";
const MNEMONIC = process.env.MNEMONIC || '';
const MAINNET_FORK = process.env.MAINNET_FORK === 'true';
const FORK = process.env.FORK || '';
// Prevent to load scripts before compilation and typechain
if (!SKIP_LOAD) {
@ -57,10 +57,13 @@ const getCommonNetworkConfig = (networkName: eNetwork, networkId: number) => ({
},
});
const mainnetFork = MAINNET_FORK
const forkMode = FORK
? {
blockNumber: 12012081,
url: NETWORKS_RPC_URL['main'],
url: NETWORKS_RPC_URL[FORK],
...(FORK &&
BLOCK_TO_FORK[FORK] && {
blockNumber: BLOCK_TO_FORK[FORK],
}),
}
: undefined;
@ -111,7 +114,7 @@ const buidlerConfig: HardhatUserConfig = {
privateKey: secretKey,
balance,
})),
forking: mainnetFork,
forking: forkMode,
},
buidlerevm_docker: {
hardfork: 'berlin',

View File

@ -34,7 +34,7 @@ export const NETWORKS_RPC_URL: iParamsPerNetwork<string> = {
};
export const NETWORKS_DEFAULT_GAS: iParamsPerNetwork<number> = {
[eEthereumNetwork.kovan]: 65 * GWEI,
[eEthereumNetwork.kovan]: 1 * GWEI,
[eEthereumNetwork.ropsten]: 65 * GWEI,
[eEthereumNetwork.main]: 65 * GWEI,
[eEthereumNetwork.coverage]: 65 * GWEI,
@ -45,3 +45,16 @@ export const NETWORKS_DEFAULT_GAS: iParamsPerNetwork<number> = {
[ePolygonNetwork.matic]: 1 * GWEI,
[eXDaiNetwork.xdai]: 1 * GWEI,
};
export const BLOCK_TO_FORK: iParamsPerNetwork<number | undefined> = {
[eEthereumNetwork.main]: 12406069,
[eEthereumNetwork.kovan]: undefined,
[eEthereumNetwork.ropsten]: undefined,
[eEthereumNetwork.coverage]: undefined,
[eEthereumNetwork.hardhat]: undefined,
[eEthereumNetwork.buidlerevm]: undefined,
[eEthereumNetwork.tenderlyMain]: 12406069,
[ePolygonNetwork.mumbai]: undefined,
[ePolygonNetwork.matic]: undefined,
[eXDaiNetwork.xdai]: undefined,
};

View File

@ -61,7 +61,7 @@ export const getReservesConfigByPool = (pool: AavePools): iMultiPoolsAssets<IRes
export const getGenesisPoolAdmin = async (
config: ICommonConfiguration
): Promise<tEthereumAddress> => {
const currentNetwork = process.env.MAINNET_FORK === 'true' ? 'main' : DRE.network.name;
const currentNetwork = process.env.FORK ? process.env.FORK : DRE.network.name;
const targetAddress = getParamPerNetwork(config.PoolAdmin, <eNetwork>currentNetwork);
if (targetAddress) {
return targetAddress;
@ -76,7 +76,7 @@ export const getGenesisPoolAdmin = async (
export const getEmergencyAdmin = async (
config: ICommonConfiguration
): Promise<tEthereumAddress> => {
const currentNetwork = process.env.MAINNET_FORK === 'true' ? 'main' : DRE.network.name;
const currentNetwork = process.env.FORK ? process.env.FORK : DRE.network.name;
const targetAddress = getParamPerNetwork(config.EmergencyAdmin, <eNetwork>currentNetwork);
if (targetAddress) {
return targetAddress;
@ -91,7 +91,7 @@ export const getEmergencyAdmin = async (
export const getTreasuryAddress = async (
config: ICommonConfiguration
): Promise<tEthereumAddress> => {
const currentNetwork = process.env.MAINNET_FORK === 'true' ? 'main' : DRE.network.name;
const currentNetwork = process.env.FORK ? process.env.FORK : DRE.network.name;
return getParamPerNetwork(config.ReserveFactorTreasuryAddress, <eNetwork>currentNetwork);
};
@ -101,7 +101,7 @@ export const getATokenDomainSeparatorPerNetwork = (
): tEthereumAddress => getParamPerNetwork<tEthereumAddress>(config.ATokenDomainSeparator, network);
export const getWethAddress = async (config: ICommonConfiguration) => {
const currentNetwork = process.env.MAINNET_FORK === 'true' ? 'main' : DRE.network.name;
const currentNetwork = process.env.FORK ? process.env.FORK : DRE.network.name;
const wethAddress = getParamPerNetwork(config.WETH, <eNetwork>currentNetwork);
if (wethAddress) {
return wethAddress;
@ -133,8 +133,7 @@ export const getLendingRateOracles = (poolConfig: ICommonConfiguration) => {
ReserveAssets,
} = poolConfig;
const MAINNET_FORK = process.env.MAINNET_FORK === 'true';
const network = MAINNET_FORK ? 'main' : DRE.network.name;
const network = process.env.FORK ? process.env.FORK : DRE.network.name;
return filterMapBy(LendingRateOracleRatesCommon, (key) =>
Object.keys(ReserveAssets[network]).includes(key)
);

View File

@ -34,8 +34,8 @@ export type MockTokenMap = { [symbol: string]: MintableERC20 };
export const registerContractInJsonDb = async (contractId: string, contractInstance: Contract) => {
const currentNetwork = DRE.network.name;
const MAINNET_FORK = process.env.MAINNET_FORK === 'true';
if (MAINNET_FORK || (currentNetwork !== 'hardhat' && !currentNetwork.includes('coverage'))) {
const FORK = process.env.FORK;
if (FORK || (currentNetwork !== 'hardhat' && !currentNetwork.includes('coverage'))) {
console.log(`*** ${contractId} ***\n`);
console.log(`Network: ${currentNetwork}`);
console.log(`tx: ${contractInstance.deployTransaction.hash}`);
@ -147,9 +147,8 @@ export const getParamPerNetwork = <T>(param: iParamsPerNetwork<T>, network: eNet
} = param as iEthereumParamsPerNetwork<T>;
const { matic, mumbai } = param as iPolygonParamsPerNetwork<T>;
const { xdai } = param as iXDaiParamsPerNetwork<T>;
const MAINNET_FORK = process.env.MAINNET_FORK === 'true';
if (MAINNET_FORK) {
return main;
if (process.env.FORK) {
return param[process.env.FORK as eNetwork] as T;
}
switch (network) {

View File

@ -17,7 +17,7 @@ import {
getContractAddressWithJsonFallback,
rawInsertContractAddressInDb,
} from './contracts-helpers';
import { BigNumber, BigNumberish, Signer } from 'ethers';
import { BigNumberish } from 'ethers';
import { deployDefaultReserveInterestRateStrategy } from './contracts-deployments';
import { ConfigNames } from './configuration';
@ -76,6 +76,10 @@ export const initReservesByHelper = async (
const reserves = Object.entries(reservesParams);
for (let [symbol, params] of reserves) {
if (!tokenAddresses[symbol]) {
console.log(`- Skipping init of ${symbol} due token address is not set at markets config`);
continue;
}
const { strategy, aTokenImpl, reserveDecimals } = params;
const {
optimalUtilizationRate,
@ -207,6 +211,12 @@ export const configureReservesByHelper = async (
borrowingEnabled,
},
] of Object.entries(reservesParams) as [string, IReserveParams][]) {
if (!tokenAddresses[assetSymbol]) {
console.log(
`- Skipping init of ${assetSymbol} due token address is not set at markets config`
);
continue;
}
if (baseLTVAsCollateral === '-1') continue;
const assetAddressIndex = Object.keys(tokenAddresses).findIndex(

View File

@ -72,9 +72,6 @@ export const setInitialAssetPricesInOracle = async (
priceOracleInstance: PriceOracle
) => {
for (const [assetSymbol, price] of Object.entries(prices) as [string, string][]) {
console.log("Trying for ", assetsAddresses, assetSymbol);
const assetAddressIndex = Object.keys(assetsAddresses).findIndex(
(value) => value === assetSymbol
);

View File

@ -93,6 +93,9 @@ export const CommonsConfig: ICommonConfiguration = {
UNI: {
borrowRate: oneRay.multipliedBy(0.03).toFixed(),
},
ENJ: {
borrowRate: oneRay.multipliedBy(0.03).toFixed(),
},
BUSD: {
borrowRate: oneRay.multipliedBy(0.05).toFixed(),
},
@ -135,11 +138,11 @@ export const CommonsConfig: ICommonConfiguration = {
ProviderRegistryOwner: {
[eEthereumNetwork.kovan]: '0x85e4A467343c0dc4aDAB74Af84448D9c45D8ae6F',
[eEthereumNetwork.ropsten]: '',
[eEthereumNetwork.main]: '0xbd723fc4f1d737dcfc48a07fe7336766d34cad5f',
[eEthereumNetwork.main]: '0xB9062896ec3A615a4e4444DF183F0531a77218AE',
[eEthereumNetwork.coverage]: '',
[eEthereumNetwork.hardhat]: '',
[eEthereumNetwork.buidlerevm]: '',
[eEthereumNetwork.tenderlyMain]: '0xbd723fc4f1d737dcfc48a07fe7336766d34cad5f',
[eEthereumNetwork.tenderlyMain]: '0xB9062896ec3A615a4e4444DF183F0531a77218AE',
},
LendingRateOracle: {
[eEthereumNetwork.coverage]: '',
@ -181,7 +184,7 @@ export const CommonsConfig: ICommonConfiguration = {
[eEthereumNetwork.coverage]: '',
[eEthereumNetwork.hardhat]: '',
[eEthereumNetwork.buidlerevm]: '',
[eEthereumNetwork.kovan]: '0xf99b8E67a0E044734B01EC4586D1c88C9a869718',
[eEthereumNetwork.kovan]: '',
[eEthereumNetwork.ropsten]: '',
[eEthereumNetwork.main]: '',
[eEthereumNetwork.tenderlyMain]: '',
@ -282,6 +285,7 @@ export const CommonsConfig: ICommonConfiguration = {
YFI: '0x7c5d4F8345e66f68099581Db340cd65B078C41f4',
ZRX: '0x2Da4983a622a8498bb1a21FaE9D8F6C664939962',
USD: '0x5f4eC3Df9cbd43714FE2740f5E3616155c5b8419',
xSUSHI: '0x9b26214bEC078E68a394AaEbfbffF406Ce14893F',
},
[eEthereumNetwork.tenderlyMain]: {
AAVE: '0x6Df09E975c830ECae5bd4eD9d90f3A95a4f88012',
@ -304,6 +308,7 @@ export const CommonsConfig: ICommonConfiguration = {
YFI: '0x7c5d4F8345e66f68099581Db340cd65B078C41f4',
ZRX: '0x2Da4983a622a8498bb1a21FaE9D8F6C664939962',
USD: '0x5f4eC3Df9cbd43714FE2740f5E3616155c5b8419',
xSUSHI: '0x9b26214bEC078E68a394AaEbfbffF406Ce14893F',
},
},
ReserveAssets: {

View File

@ -23,6 +23,7 @@ import {
strategyWETH,
strategyYFI,
strategyXSUSHI,
strategyENJ,
} from './reservesConfigs';
// ----------------
@ -38,7 +39,7 @@ export const AaveConfig: IAaveConfiguration = {
BAT: strategyBAT,
BUSD: strategyBUSD,
DAI: strategyDAI,
ENJ: strategyREN,
ENJ: strategyENJ,
KNC: strategyKNC,
LINK: strategyLINK,
MANA: strategyMANA,

View File

@ -139,14 +139,13 @@ export const CommonsConfig: ICommonConfiguration = {
[eEthereumNetwork.tenderlyMain]: '0x52D306e36E3B6B02c153d0266ff0f85d18BCD413',
},
ProviderRegistryOwner: {
// DEPLOYED WITH CORRECT ADDRESS
[eEthereumNetwork.kovan]: '0x85e4A467343c0dc4aDAB74Af84448D9c45D8ae6F',
[eEthereumNetwork.ropsten]: '',
[eEthereumNetwork.main]: '0xbd723fc4f1d737dcfc48a07fe7336766d34cad5f',
[eEthereumNetwork.main]: '0xB9062896ec3A615a4e4444DF183F0531a77218AE',
[eEthereumNetwork.coverage]: '',
[eEthereumNetwork.hardhat]: '',
[eEthereumNetwork.buidlerevm]: '',
[eEthereumNetwork.tenderlyMain]: '0xbd723fc4f1d737dcfc48a07fe7336766d34cad5f',
[eEthereumNetwork.tenderlyMain]: '0xB9062896ec3A615a4e4444DF183F0531a77218AE',
},
LendingRateOracle: {
[eEthereumNetwork.coverage]: '',

24
package-lock.json generated
View File

@ -12918,19 +12918,17 @@
"string.prototype.trimend": "^1.0.4",
"string.prototype.trimstart": "^1.0.4",
"unbox-primitive": "^1.0.0"
},
"dependencies": {
"get-intrinsic": {
"version": "1.1.1",
"resolved": "https://registry.npmjs.org/get-intrinsic/-/get-intrinsic-1.1.1.tgz",
"integrity": "sha512-kWZrnVM42QCiEA2Ig1bG8zjoIMOgxWwYCEeNdwY6Tv/cOSeGpcoX4pXHfKUxNKVoArnrEr2e9srnAxxGIraS9Q==",
"dev": true,
"requires": {
"function-bind": "^1.1.1",
"has": "^1.0.3",
"has-symbols": "^1.0.1"
}
}
}
},
"get-intrinsic": {
"version": "1.1.1",
"resolved": "https://registry.npmjs.org/get-intrinsic/-/get-intrinsic-1.1.1.tgz",
"integrity": "sha512-kWZrnVM42QCiEA2Ig1bG8zjoIMOgxWwYCEeNdwY6Tv/cOSeGpcoX4pXHfKUxNKVoArnrEr2e9srnAxxGIraS9Q==",
"dev": true,
"requires": {
"function-bind": "^1.1.1",
"has": "^1.0.3",
"has-symbols": "^1.0.1"
}
}
}

View File

@ -17,28 +17,47 @@
"hardhat:mumbai": "hardhat --network mumbai",
"hardhat:matic": "hardhat --network matic",
"compile": "SKIP_LOAD=true hardhat compile",
"console:fork": "MAINNET_FORK=true hardhat console",
"console:fork": "FORK=main hardhat console",
"test": "npm run compile && TS_NODE_TRANSPILE_ONLY=1 hardhat test ./test-suites/test-aave/*.spec.ts",
"test-amm": "npm run compile && TS_NODE_TRANSPILE_ONLY=1 hardhat test ./test-suites/test-amm/*.spec.ts",
"test-amm-scenarios": "npm run compile && TS_NODE_TRANSPILE_ONLY=1 hardhat test ./test-suites/test-amm/__setup.spec.ts test-suites/test-amm/scenario.spec.ts",
"test-scenarios": "npm run compile && npx hardhat test test-suites/test-aave/__setup.spec.ts test-suites/test-aave/scenario.spec.ts",
"test-subgraph:scenarios": "npm run compile && hardhat --network hardhatevm_docker test test-suites/test-aave/__setup.spec.ts test-suites/test-aave/subgraph-scenarios.spec.ts",
"test:main:check-list": "npm run compile && MAINNET_FORK=true TS_NODE_TRANSPILE_ONLY=1 hardhat test test-suites/test-aave/__setup.spec.ts test-suites/test-aave/mainnet/check-list.spec.ts",
"test:main:check-list": "npm run compile && FORK=true TS_NODE_TRANSPILE_ONLY=1 hardhat test test-suites/test-aave/__setup.spec.ts test-suites/test-aave/mainnet/check-list.spec.ts",
"dev:coverage": "buidler compile --force && buidler coverage --network coverage",
"aave:evm:dev:migration": "npm run compile && hardhat aave:dev",
"aave:docker:full:migration": "npm run compile && npm run hardhat:docker -- aave:mainnet",
"aave:kovan:full:migration": "npm run compile && npm run hardhat:kovan -- aave:mainnet --verify",
"matic:mumbai:full:migration": "npm run compile && npm run hardhat:mumbai sidechain:mainnet -- --pool Matic",
"matic:matic:full:migration": "npm run compile && npm run hardhat:matic sidechain:mainnet -- --pool Matic",
"amm:kovan:full:migration": "npm run compile && npm run hardhat:kovan -- amm:mainnet --verify",
"aave:docker:full:migration": "npm run compile && npm run hardhat:docker -- aave:mainnet --skip-registry",
"aave:kovan:full:migration": "npm run compile && npm run hardhat:kovan -- aave:mainnet --skip-registry",
"matic:mumbai:full:migration": "npm run compile && npm run hardhat:mumbai sidechain:mainnet -- --pool Matic --skip-registry",
"matic:matic:full:migration": "npm run compile && npm run hardhat:matic sidechain:mainnet -- --pool Matic --skip-registry",
"amm:kovan:full:migration": "npm run compile && npm run hardhat:kovan -- amm:mainnet --skip-registry",
"aave:docker:full:migration:add-registry": "npm run compile && npm run hardhat:docker -- aave:mainnet",
"aave:kovan:full:migration:add-registry": "npm run compile && npm run hardhat:kovan -- aave:mainnet",
"matic:mumbai:full:migration:add-registry": "npm run compile && npm run hardhat:mumbai sidechain:mainnet -- --pool Matic",
"matic:matic:full:migration:add-registry": "npm run compile && npm run hardhat:matic sidechain:mainnet -- --pool Matic",
"amm:kovan:full:migration:add-registry": "npm run compile && npm run hardhat:kovan -- amm:mainnet",
"aave:docker:add-market-to-registry-from-config": "npm run compile && npm run hardhat:docker -- add-market-to-registry --pool Aave",
"aave:kovan:add-market-to-registry-from-config": "npm run compile && npm run hardhat:kovan -- add-market-to-registry --pool Aave",
"matic:mumbai:add-market-to-registry-from-config": "npm run compile && npm run hardhat:mumbai add-market-to-registry --pool Matic",
"amm:kovan:add-market-to-registry-from-config": "npm run compile && npm run hardhat:kovan -- add-market-to-registry --pool Amm",
"matic:matic:add-market-to-registry-from-config": "npm run compile && npm run hardhat:matic add-market-to-registry --pool Matic",
"aave:main:add-market-to-registry-from-config": "npm run compile && npm run hardhat:main -- add-market-to-registry --pool Aave",
"aave:docker:add-market-to-new-registry": "npm run compile && npm run hardhat:docker -- add-market-to-registry --pool Aave --deploy-registry",
"aave:kovan:add-market-to-new-registry": "npm run compile && npm run hardhat:kovan -- add-market-to-registry --pool Aave --verify --deploy-registry",
"matic:mumbai:add-market-to-new-registry": "npm run compile && npm run hardhat:mumbai add-market-to-registry --pool Matic --verify --deploy-registry",
"amm:kovan:add-market-to-new-registry": "npm run compile && npm run hardhat:kovan -- add-market-to-registry --pool Amm --verify --deploy-registry",
"matic:matic:add-market-to-new-registry": "npm run compile && npm run hardhat:matic -- add-market-to-registry --pool Matic --verify --deploy-registry",
"aave:main:add-market-to-new-registry": "npm run compile && npm run hardhat:matic -- add-market-to-registry --pool Matic --verify --deploy-registry",
"aave:kovan:full:initialize": "npm run hardhat:kovan -- full:initialize-lending-pool --verify --pool Aave",
"aave:ropsten:full:migration": "npm run compile && npm run hardhat:ropsten -- aave:mainnet --verify",
"aave:fork:main:tenderly": "npm run compile && npm run hardhat:tenderly-main -- aave:mainnet",
"aave:fork:main": "npm run compile && MAINNET_FORK=true hardhat aave:mainnet",
"amm:fork:main": "npm run compile && MAINNET_FORK=true hardhat amm:mainnet",
"aave:fork:main": "npm run compile && FORK=main hardhat aave:mainnet",
"aave:fork:kovan": "npm run compile && FORK=kovan hardhat aave:mainnet",
"amm:fork:main": "npm run compile && FORK=main hardhat amm:mainnet",
"amm:fork:kovan": "npm run compile && FORK=kovan hardhat amm:mainnet",
"amm:fork:main:tenderly": "npm run compile && npm run hardhat:tenderly-main -- amm:mainnet",
"aave:main:full:migration": "npm run compile && npm run hardhat:main -- aave:mainnet --verify",
"aave:main:full:initialize": "npm run compile && MAINNET_FORK=true full:initialize-tokens --pool Aave",
"aave:main:full:initialize": "npm run compile && FORK=main full:initialize-tokens --pool Aave",
"amm:main:full:migration": "npm run compile && npm run hardhat:main -- amm:mainnet --verify",
"prettier:check": "npx prettier -c 'tasks/**/*.ts' 'contracts/**/*.sol' 'helpers/**/*.ts' 'test-suites/test-aave/**/*.ts'",
"prettier:write": "prettier --write 'tasks/**/*.ts' 'contracts/**/*.sol' 'helpers/**/*.ts' 'test-suites/test-aave/**/*.ts'",
@ -65,7 +84,7 @@
"kovan:verify:tokens": "npm run hardhat:kovan verify:tokens -- --pool Aave",
"ropsten:verify:tokens": "npm run hardhat:ropsten verify:tokens -- --pool Aave",
"mainnet:verify:tokens": "npm run hardhat:main verify:tokens -- --pool Aave",
"print-config:fork:mainnet": "MAINNET_FORK=true hardhat print-config:fork",
"print-config:fork:mainnet": "FORK=main hardhat print-config:fork",
"print-config:kovan": "hardhat --network kovan print-config --pool Aave --data-provider 0xA1901785c29cBd48bfA74e46b67C736b26054fa4",
"external:deploy-assets-kovan": "npm run compile && hardhat --network kovan external:deploy-new-asset --symbol ${SYMBOL} --verify",
"external:deploy-assets-main": "npm run compile && hardhat --network main external:deploy-new-asset --symbol ${SYMBOL} --verify",

View File

@ -0,0 +1,96 @@
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';
import { exit } from 'process';
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);
const currentSignerAddress = await (
await (await getFirstSigner()).getAddress()
).toLocaleLowerCase();
let deployed = false;
if (
deployRegistry ||
!providerRegistryAddress ||
!isAddress(providerRegistryAddress) ||
isZeroAddress(providerRegistryAddress)
) {
console.log('- Deploying a new Address Providers Registry:');
await DRE.run('full:deploy-address-provider-registry', { verify });
providerRegistryAddress = (await getLendingPoolAddressesProviderRegistry()).address;
providerRegistryOwner = await (await getFirstSigner()).getAddress();
deployed = true;
}
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.FORK) {
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 if (
!deployed &&
providerRegistryOwner.toLocaleLowerCase() !== currentSignerAddress.toLocaleLowerCase()
) {
console.error('ProviderRegistryOwner config does not match current signer:');
console.error('Expected:', providerRegistryOwner);
console.error('Current:', currentSignerAddress);
exit(2);
} 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}`
);
});

View File

@ -18,6 +18,7 @@ task(
const addressesProvider = await deployLendingPoolAddressesProvider(AaveConfig.MarketId, verify);
await waitForTx(await addressesProvider.setPoolAdmin(admin));
await waitForTx(await addressesProvider.setEmergencyAdmin(admin));
const addressesProviderRegistry = await deployLendingPoolAddressesProviderRegistry(verify);
await waitForTx(

View File

@ -4,7 +4,6 @@ import {
deployMockFlashLoanReceiver,
deployWalletBalancerProvider,
deployAaveProtocolDataProvider,
deployWETHGateway,
authorizeWETHGateway,
} from '../../helpers/contracts-deployments';
import { getParamPerNetwork } from '../../helpers/contracts-helpers';
@ -13,18 +12,18 @@ import {
ConfigNames,
getReservesConfigByPool,
getTreasuryAddress,
getWethAddress,
loadPoolConfig,
} from '../../helpers/configuration';
import { tEthereumAddress, AavePools, eContractid } from '../../helpers/types';
import { waitForTx, filterMapBy } from '../../helpers/misc-utils';
import { waitForTx, filterMapBy, notFalsyOrZeroAddress } from '../../helpers/misc-utils';
import { configureReservesByHelper, initReservesByHelper } from '../../helpers/init-helpers';
import { getAllTokenAddresses } from '../../helpers/mock-helpers';
import { ZERO_ADDRESS } from '../../helpers/constants';
import {
getAllMockedTokens,
getLendingPoolAddressesProvider,
getWETHGateway,
} from '../../helpers/contracts-getters';
import { insertContractAddressInDb } from '../../helpers/contracts-helpers';
@ -92,6 +91,10 @@ task('dev:initialize-lending-pool', 'Initialize lending pool configuration.')
await insertContractAddressInDb(eContractid.AaveProtocolDataProvider, testHelpers.address);
const lendingPoolAddress = await addressesProvider.getLendingPool();
const gateWay = await getParamPerNetwork(WethGateway, network);
await authorizeWETHGateway(gateWay, lendingPoolAddress);
let gateway = getParamPerNetwork(WethGateway, network);
if (!notFalsyOrZeroAddress(gateway)) {
gateway = (await getWETHGateway()).address;
}
await authorizeWETHGateway(gateway, lendingPoolAddress);
});

View File

@ -1,9 +1,5 @@
import { task } from 'hardhat/config';
import { getParamPerNetwork } from '../../helpers/contracts-helpers';
import {
deployLendingPoolAddressesProvider,
deployLendingPoolAddressesProviderRegistry,
} from '../../helpers/contracts-deployments';
import { deployLendingPoolAddressesProvider } from '../../helpers/contracts-deployments';
import { notFalsyOrZeroAddress, waitForTx } from '../../helpers/misc-utils';
import {
ConfigNames,
@ -11,16 +7,8 @@ import {
getGenesisPoolAdmin,
getEmergencyAdmin,
} from '../../helpers/configuration';
import { getParamPerNetwork } from '../../helpers/contracts-helpers';
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',
@ -28,57 +16,29 @@ task(
)
.addFlag('verify', 'Verify contracts at Etherscan')
.addParam('pool', `Pool name to retrieve configuration, supported: ${Object.values(ConfigNames)}`)
.setAction(async ({ verify, pool }, DRE) => {
.addFlag('skipRegistry')
.setAction(async ({ verify, pool, skipRegistry }, DRE) => {
await DRE.run('set-DRE');
let signer: Signer;
const network = <eNetwork>DRE.network.name;
const poolConfig = loadPoolConfig(pool);
const { ProviderId, MarketId } = poolConfig;
const { MarketId } = poolConfig;
const providerRegistryAddress = getParamPerNetwork(poolConfig.ProviderRegistry, network);
const providerRegistryOwner = getParamPerNetwork(poolConfig.ProviderRegistryOwner, network);
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
// 1. 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
// 2. Add to registry or setup a new one
if (!skipRegistry) {
const providerRegistryAddress = getParamPerNetwork(
poolConfig.ProviderRegistry,
<eNetwork>DRE.network.name
);
await DRE.run('add-market-to-registry', {
pool,
addressesProvider: addressesProvider.address,
deployRegistry: !notFalsyOrZeroAddress(providerRegistryAddress),
});
}
// 3. Set pool admins
await waitForTx(await addressesProvider.setPoolAdmin(await getGenesisPoolAdmin(poolConfig)));
await waitForTx(await addressesProvider.setEmergencyAdmin(await getEmergencyAdmin(poolConfig)));

View File

@ -29,7 +29,10 @@ task('aave:dev', 'Deploy development enviroment')
console.log('4. Deploy oracles');
await localBRE.run('dev:deploy-oracles', { verify, pool: POOL_NAME });
console.log('5. Initialize lending pool');
console.log('5. Deploy WETH Gateway');
await localBRE.run('full-deploy-weth-gateway', { verify, pool: POOL_NAME });
console.log('6. Initialize lending pool');
await localBRE.run('dev:initialize-lending-pool', { verify, pool: POOL_NAME });
console.log('\nFinished migration');

View File

@ -6,7 +6,8 @@ import { usingTenderly } from '../../helpers/tenderly-utils';
task('aave:mainnet', 'Deploy development enviroment')
.addFlag('verify', 'Verify contracts at Etherscan')
.setAction(async ({ verify }, DRE) => {
.addFlag('skipRegistry', 'Skip addresses provider registration at Addresses Provider Registry')
.setAction(async ({ verify, skipRegistry }, DRE) => {
const POOL_NAME = ConfigNames.Aave;
await DRE.run('set-DRE');
@ -18,7 +19,7 @@ task('aave:mainnet', 'Deploy development enviroment')
console.log('Migration started\n');
console.log('1. Deploy address provider');
await DRE.run('full:deploy-address-provider', { pool: POOL_NAME });
await DRE.run('full:deploy-address-provider', { pool: POOL_NAME, skipRegistry });
console.log('2. Deploy lending pool');
await DRE.run('full:deploy-lending-pool', { pool: POOL_NAME });

View File

@ -6,7 +6,8 @@ import { usingTenderly } from '../../helpers/tenderly-utils';
task('amm:mainnet', 'Deploy development enviroment')
.addFlag('verify', 'Verify contracts at Etherscan')
.setAction(async ({ verify }, DRE) => {
.addFlag('skipRegistry', 'Skip addresses provider registration at Addresses Provider Registry')
.setAction(async ({ verify, skipRegistry }, DRE) => {
const POOL_NAME = ConfigNames.Amm;
await DRE.run('set-DRE');
@ -18,7 +19,7 @@ task('amm:mainnet', 'Deploy development enviroment')
console.log('Migration started\n');
console.log('1. Deploy address provider');
await DRE.run('full:deploy-address-provider', { pool: POOL_NAME });
await DRE.run('full:deploy-address-provider', { pool: POOL_NAME, skipRegistry });
console.log('2. Deploy lending pool');
await DRE.run('full:deploy-lending-pool', { pool: POOL_NAME });

View File

@ -5,9 +5,10 @@ import { printContracts } from '../../helpers/misc-utils';
import { usingTenderly } from '../../helpers/tenderly-utils';
task('sidechain:mainnet', 'Deploy market at sidechain')
.addFlag('verify', 'Verify contracts at Etherscan')
.addParam('pool', `Market pool configuration, one of ${Object.keys(ConfigNames)}`)
.setAction(async ({ verify, pool }, DRE) => {
.addFlag('verify', 'Verify contracts at Etherscan')
.addFlag('skipRegistry', 'Skip addresses provider registration at Addresses Provider Registry')
.setAction(async ({ verify, pool, skipRegistry }, DRE) => {
const POOL_NAME = pool;
await DRE.run('set-DRE');
@ -22,7 +23,7 @@ task('sidechain:mainnet', 'Deploy market at sidechain')
await DRE.run('full:deploy-address-provider-registry', { pool: POOL_NAME });
console.log('1. Deploy address provider');
await DRE.run('full:deploy-address-provider', { pool: POOL_NAME });
await DRE.run('full:deploy-address-provider', { pool: POOL_NAME, skipRegistry });
console.log('2. Deploy lending pool');
await DRE.run('full:deploy-lending-pool', { pool: POOL_NAME });

View File

@ -14,10 +14,10 @@ task('print-config', 'Inits the DRE, to have access to all the plugins')
.addParam('pool', `Pool name to retrieve configuration, supported: ${Object.values(ConfigNames)}`)
.setAction(async ({ pool, dataProvider }, localBRE) => {
await localBRE.run('set-DRE');
const network =
process.env.MAINNET_FORK === 'true'
? eEthereumNetwork.main
: (localBRE.network.name as eNetwork);
const network = process.env.FORK
? (process.env.FORK as eNetwork)
: (localBRE.network.name as eNetwork);
console.log(network);
const poolConfig = loadPoolConfig(pool);
const providerRegistryAddress = getParamPerNetwork(poolConfig.ProviderRegistry, network);
@ -60,7 +60,7 @@ task('print-config', 'Inits the DRE, to have access to all the plugins')
];
const tokensFields = ['aToken', 'stableDebtToken', 'variableDebtToken'];
for (const [symbol, address] of Object.entries(
getParamPerNetwork(poolConfig.ReserveAssets, network)
getParamPerNetwork(poolConfig.ReserveAssets, network as eNetwork)
)) {
console.log(`- ${symbol} asset config`);
console.log(` - reserve address: ${address}`);

View File

@ -5,6 +5,8 @@ import { usingTenderly } from '../../helpers/tenderly-utils';
import { HardhatRuntimeEnvironment } from 'hardhat/types';
import { getFirstSigner } from '../../helpers/contracts-getters';
import { formatEther } from 'ethers/lib/utils';
import { fork } from 'child_process';
import { env } from 'process';
task(`set-DRE`, `Inits the DRE, to have access to all the plugins' objects`).setAction(
async (_, _DRE) => {
@ -36,6 +38,18 @@ task(`set-DRE`, `Inits the DRE, to have access to all the plugins' objects`).set
);
}
console.log('- Enviroment');
if (process.env.FORK) {
console.log(' - Fork Mode activated at network: ', process.env.FORK);
if (_DRE?.config?.networks?.hardhat?.forking?.url) {
console.log(' - Provider URL:', _DRE.config.networks.hardhat.forking?.url?.split('/')[2]);
} else {
console.error(
`[FORK][Error], missing Provider URL for "${_DRE.network.name}" network. Fill the URL at './helper-hardhat-config.ts' file`
);
}
}
console.log(' - Network :', _DRE.network.name);
setDRE(_DRE);
return _DRE;
}

View File

@ -304,10 +304,10 @@ const buildTestEnv = async (deployer: Signer, secondaryWallet: Signer) => {
before(async () => {
await rawBRE.run('set-DRE');
const [deployer, secondaryWallet] = await getEthersSigners();
const MAINNET_FORK = process.env.MAINNET_FORK === 'true';
const FORK = process.env.FORK;
if (MAINNET_FORK) {
await rawBRE.run('aave:mainnet');
if (FORK) {
await rawBRE.run('aave:mainnet', { skipRegistry: true });
} else {
console.log('-> Deploying test environment...');
await buildTestEnv(deployer, secondaryWallet);

View File

@ -17,7 +17,7 @@ import {
getRewardsToken,
getRewardsATokenMock,
} from '../../../helpers/contracts-getters';
import { eEthereumNetwork, tEthereumAddress } from '../../../helpers/types';
import { eEthereumNetwork, eNetwork, tEthereumAddress } from '../../../helpers/types';
import { LendingPool } from '../../../types/LendingPool';
import { AaveProtocolDataProvider } from '../../../types/AaveProtocolDataProvider';
import { MintableERC20 } from '../../../types/MintableERC20';
@ -122,9 +122,9 @@ export async function initializeMakeSuite() {
testEnv.addressesProvider = await getLendingPoolAddressesProvider();
if (process.env.MAINNET_FORK === 'true') {
if (process.env.FORK) {
testEnv.registry = await getLendingPoolAddressesProviderRegistry(
getParamPerNetwork(AaveConfig.ProviderRegistry, eEthereumNetwork.main)
getParamPerNetwork(AaveConfig.ProviderRegistry, process.env.FORK as eNetwork)
);
} else {
testEnv.registry = await getLendingPoolAddressesProviderRegistry();

View File

@ -293,10 +293,10 @@ const buildTestEnv = async (deployer: Signer, secondaryWallet: Signer) => {
before(async () => {
await rawBRE.run('set-DRE');
const [deployer, secondaryWallet] = await getEthersSigners();
const MAINNET_FORK = process.env.MAINNET_FORK === 'true';
const FORK = process.env.FORK;
if (MAINNET_FORK) {
await rawBRE.run('amm:mainnet');
if (FORK) {
await rawBRE.run('amm:mainnet', { skipRegistry: true });
} else {
console.log('-> Deploying test environment...');
await buildTestEnv(deployer, secondaryWallet);

View File

@ -15,7 +15,7 @@ import {
getUniswapRepayAdapter,
getFlashLiquidationAdapter,
} from '../../../helpers/contracts-getters';
import { eEthereumNetwork, tEthereumAddress } from '../../../helpers/types';
import { eEthereumNetwork, eNetwork, tEthereumAddress } from '../../../helpers/types';
import { LendingPool } from '../../../types/LendingPool';
import { AaveProtocolDataProvider } from '../../../types/AaveProtocolDataProvider';
import { MintableERC20 } from '../../../types/MintableERC20';
@ -116,9 +116,9 @@ export async function initializeMakeSuite() {
testEnv.addressesProvider = await getLendingPoolAddressesProvider();
if (process.env.MAINNET_FORK === 'true') {
if (process.env.FORK) {
testEnv.registry = await getLendingPoolAddressesProviderRegistry(
getParamPerNetwork(AmmConfig.ProviderRegistry, eEthereumNetwork.main)
getParamPerNetwork(AmmConfig.ProviderRegistry, process.env.FORK as eNetwork)
);
} else {
testEnv.registry = await getLendingPoolAddressesProviderRegistry();