Skip to content

feat: improve deploy scripts #306

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 7 commits into from
Aug 10, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 0 additions & 6 deletions .github/workflows/node.js.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,6 @@ jobs:
uses: actions/setup-node@v2
with:
node-version: ${{ matrix.node-version }}
- uses: actions/cache@v2
with:
path: ~/.npm
key: ${{ runner.os }}-node-${{ hashFiles('**/package-lock.json') }}
restore-keys: |
${{ runner.os }}-node-
- name: Install dependencies
run: npm ci
- name: Test
Expand Down
1 change: 1 addition & 0 deletions hardhat.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@ const buidlerConfig: HardhatUserConfig = {
xdai: getCommonNetworkConfig(eXDaiNetwork.xdai, 100),
avalanche: getCommonNetworkConfig(eAvalancheNetwork.avalanche, 43114),
fuji: getCommonNetworkConfig(eAvalancheNetwork.fuji, 43113),
goerli: getCommonNetworkConfig(eEthereumNetwork.goerli, 5),
hardhat: {
hardfork: 'berlin',
blockGasLimit: DEFAULT_BLOCK_GAS_LIMIT,
Expand Down
3 changes: 3 additions & 0 deletions helper-hardhat-config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ export const NETWORKS_RPC_URL: iParamsPerNetwork<string> = {
[eXDaiNetwork.xdai]: 'https://rpc.xdaichain.com/',
[eAvalancheNetwork.avalanche]: 'https://api.avax.network/ext/bc/C/rpc',
[eAvalancheNetwork.fuji]: 'https://api.avax-test.network/ext/bc/C/rpc',
[eEthereumNetwork.goerli]: `https://eth-goerli.g.alchemy.com/v2/${ALCHEMY_KEY}`,
};

export const NETWORKS_DEFAULT_GAS: iParamsPerNetwork<number> = {
Expand All @@ -70,6 +71,7 @@ export const NETWORKS_DEFAULT_GAS: iParamsPerNetwork<number> = {
[eXDaiNetwork.xdai]: 1 * GWEI,
[eAvalancheNetwork.avalanche]: 225 * GWEI,
[eAvalancheNetwork.fuji]: 85 * GWEI,
[eEthereumNetwork.goerli]: 2 * GWEI,
};

export const BLOCK_TO_FORK: iParamsPerNetwork<number | undefined> = {
Expand All @@ -85,4 +87,5 @@ export const BLOCK_TO_FORK: iParamsPerNetwork<number | undefined> = {
[eXDaiNetwork.xdai]: undefined,
[eAvalancheNetwork.avalanche]: undefined,
[eAvalancheNetwork.fuji]: undefined,
[eEthereumNetwork.goerli]: undefined,
};
3 changes: 2 additions & 1 deletion helpers/constants.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import BigNumber from 'bignumber.js';
import { eEthereumNetwork } from './types';

// ----------------
// MATH
Expand Down Expand Up @@ -87,6 +86,7 @@ export const chainlinkAggregatorProxy = {
'arbitrum-rinkeby': '0x5f0423B1a6935dc5596e7A24d98532b67A0AeFd8',
arbitrum: '0x639Fe6ab55C921f74e7fac1ee960C0B6293ba612',
rinkeby: '0x8A753747A1Fa494EC906cE90E9f37563A8AF630e',
goerli: '0x9F54B624fb17d07816C5552f8AB133c21b0322cD',
};

export const chainlinkEthUsdAggregatorProxy = {
Expand All @@ -100,4 +100,5 @@ export const chainlinkEthUsdAggregatorProxy = {
'arbitrum-rinkeby': '0x5f0423B1a6935dc5596e7A24d98532b67A0AeFd8',
arbitrum: '0x639Fe6ab55C921f74e7fac1ee960C0B6293ba612',
rinkeby: '0x8A753747A1Fa494EC906cE90E9f37563A8AF630e',
goerli: '0x9F54B624fb17d07816C5552f8AB133c21b0322cD',
};
41 changes: 24 additions & 17 deletions helpers/contracts-getters.ts
Original file line number Diff line number Diff line change
Expand Up @@ -210,17 +210,21 @@ export const getPairsTokenAggregator = (
getQuoteCurrencies(oracleQuoteCurrency)
);

const pairs = Object.entries(assetsWithoutQuoteCurrency).map(([tokenSymbol, tokenAddress]) => {
//if (true/*tokenSymbol !== 'WETH' && tokenSymbol !== 'ETH' && tokenSymbol !== 'LpWETH'*/) {
const aggregatorAddressIndex = Object.keys(aggregatorsAddresses).findIndex(
(value) => value === tokenSymbol
);
const [, aggregatorAddress] = (
Object.entries(aggregatorsAddresses) as [string, tEthereumAddress][]
)[aggregatorAddressIndex];
return [tokenAddress, aggregatorAddress];
//}
}) as [string, string][];
const pairs = Object.entries(assetsWithoutQuoteCurrency).reduce<[string, string][]>(
(acc, [tokenSymbol, tokenAddress]) => {
const aggregatorAddressIndex = Object.keys(aggregatorsAddresses).findIndex(
(value) => value === tokenSymbol
);
if (aggregatorAddressIndex >= 0) {
const [, aggregatorAddress] = (
Object.entries(aggregatorsAddresses) as [string, tEthereumAddress][]
)[aggregatorAddressIndex];
return [...acc, [tokenAddress, aggregatorAddress]];
}
return acc;
},
[]
);

const mappedPairs = pairs.map(([asset]) => asset);
const mappedAggregators = pairs.map(([, source]) => source);
Expand Down Expand Up @@ -424,23 +428,26 @@ export const getFlashLiquidationAdapter = async (address?: tEthereumAddress) =>
export const getMockParaSwapAugustus = async (address?: tEthereumAddress) =>
await MockParaSwapAugustusFactory.connect(
address ||
(await getDb().get(`${eContractid.MockParaSwapAugustus}.${DRE.network.name}`).value())
.address,
(
await getDb().get(`${eContractid.MockParaSwapAugustus}.${DRE.network.name}`).value()
).address,
await getFirstSigner()
);

export const getMockParaSwapAugustusRegistry = async (address?: tEthereumAddress) =>
await MockParaSwapAugustusRegistryFactory.connect(
address ||
(await getDb().get(`${eContractid.MockParaSwapAugustusRegistry}.${DRE.network.name}`).value())
.address,
(
await getDb().get(`${eContractid.MockParaSwapAugustusRegistry}.${DRE.network.name}`).value()
).address,
await getFirstSigner()
);

export const getParaSwapLiquiditySwapAdapter = async (address?: tEthereumAddress) =>
await ParaSwapLiquiditySwapAdapterFactory.connect(
address ||
(await getDb().get(`${eContractid.ParaSwapLiquiditySwapAdapter}.${DRE.network.name}`).value())
.address,
(
await getDb().get(`${eContractid.ParaSwapLiquiditySwapAdapter}.${DRE.network.name}`).value()
).address,
await getFirstSigner()
);
4 changes: 3 additions & 1 deletion helpers/contracts-helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ export const linkBytecode = (artifact: BuidlerArtifact | Artifact, libraries: an
};

export const getParamPerNetwork = <T>(param: iParamsPerNetwork<T>, network: eNetwork) => {
const { main, ropsten, kovan, coverage, buidlerevm, tenderly } =
const { main, ropsten, kovan, coverage, buidlerevm, tenderly, goerli } =
param as iEthereumParamsPerNetwork<T>;
const { matic, mumbai } = param as iPolygonParamsPerNetwork<T>;
const { xdai } = param as iXDaiParamsPerNetwork<T>;
Expand Down Expand Up @@ -179,6 +179,8 @@ export const getParamPerNetwork = <T>(param: iParamsPerNetwork<T>, network: eNet
return avalanche;
case eAvalancheNetwork.fuji:
return fuji;
case eEthereumNetwork.goerli:
return goerli;
}
};

Expand Down
13 changes: 11 additions & 2 deletions helpers/etherscan-verification.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,20 @@ const fatalErrors = [
`The constructor for`,
];

const okErrors = [`Contract source code already verified`];
const okErrors = [`Contract source code already verified`, 'Already Verified'];

const unableVerifyError = 'Fail - Unable to verify';

export const SUPPORTED_ETHERSCAN_NETWORKS = ['main', 'ropsten', 'kovan', 'matic', 'mumbai'];
export const SUPPORTED_ETHERSCAN_NETWORKS = [
'main',
'ropsten',
'kovan',
'matic',
'mumbai',
'goerli',
'avalanche',
'fuji',
];

function delay(ms: number) {
return new Promise((resolve) => setTimeout(resolve, ms));
Expand Down
9 changes: 8 additions & 1 deletion helpers/init-helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import { chunk, getDb, waitForTx } from './misc-utils';
import {
getAToken,
getATokensAndRatesHelper,
getLendingPool,
getLendingPoolAddressesProvider,
getLendingPoolConfiguratorProxy,
} from './contracts-getters';
Expand All @@ -20,9 +21,9 @@ import {
import { BigNumberish } from 'ethers';
import { ConfigNames } from './configuration';
import { deployRateStrategy } from './contracts-deployments';
import { ZERO_ADDRESS } from './constants';

export const getATokenExtraParams = async (aTokenName: string, tokenAddress: tEthereumAddress) => {
console.log(aTokenName);
switch (aTokenName) {
default:
return '0x10';
Expand Down Expand Up @@ -88,6 +89,12 @@ export const initReservesByHelper = async (
console.log(`- Skipping init of ${symbol} due token address is not set at markets config`);
continue;
}
const pool = await getLendingPool(await addressProvider.getLendingPool());
const poolReserve = await pool.getReserveData(tokenAddresses[symbol]);
if (poolReserve.aTokenAddress !== ZERO_ADDRESS) {
console.log(`- Skipping init of ${symbol} due is already initialized`);
continue;
}
const { strategy, aTokenImpl, reserveDecimals } = params;
const {
optimalUtilizationRate,
Expand Down
10 changes: 5 additions & 5 deletions helpers/oracles-helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,8 @@ export const setInitialMarketRatesInRatesOracleByHelper = async (
};

export const setInitialAssetPricesInOracle = async (
prices: iAssetBase<tEthereumAddress>,
assetsAddresses: iAssetBase<tEthereumAddress>,
prices: { [key: string]: string },
assetsAddresses: { [key: string]: string },
priceOracleInstance: PriceOracle
) => {
for (const [assetSymbol, price] of Object.entries(prices) as [string, string][]) {
Expand Down Expand Up @@ -113,17 +113,17 @@ export const deployMockAggregators = async (initialPrices: SymbolMap<string>, ve
};

export const deployAllMockAggregators = async (
initialPrices: iAssetAggregatorBase<string>,
initialPrices: SymbolMap<string>,
verify?: boolean
) => {
const aggregators: { [tokenSymbol: string]: MockAggregator } = {};
const aggregators: { [tokenSymbol: string]: tEthereumAddress } = {};
for (const tokenContractName of Object.keys(initialPrices)) {
if (tokenContractName !== 'ETH') {
const priceIndex = Object.keys(initialPrices).findIndex(
(value) => value === tokenContractName
);
const [, price] = (Object.entries(initialPrices) as [string, string][])[priceIndex];
aggregators[tokenContractName] = await deployMockAggregator(price, verify);
aggregators[tokenContractName] = (await deployMockAggregator(price, verify)).address;
}
}
return aggregators;
Expand Down
5 changes: 4 additions & 1 deletion helpers/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,9 @@ export enum eEthereumNetwork {
main = 'main',
coverage = 'coverage',
hardhat = 'hardhat',

tenderly = 'tenderly',
goerli = 'goerli',
}

export enum ePolygonNetwork {
Expand Down Expand Up @@ -432,6 +434,7 @@ export interface iEthereumParamsPerNetwork<T> {
[eEthereumNetwork.main]: T;
[eEthereumNetwork.hardhat]: T;
[eEthereumNetwork.tenderly]: T;
[eEthereumNetwork.goerli]: T;
}

export interface iPolygonParamsPerNetwork<T> {
Expand Down Expand Up @@ -480,7 +483,7 @@ export interface IProtocolGlobalConfig {
}

export interface IMocksConfig {
AllAssetsInitialPrices: iAssetBase<string>;
AllAssetsInitialPrices: { [key: string]: string };
}

export interface ILendingRateOracleRatesCommon {
Expand Down
Loading