Skip to content

Commit 0829f97

Browse files
authored
Merge pull request #306 from aave/feat/deploy-improvement
feat: improve deploy scripts
2 parents b172dbe + 228c0bb commit 0829f97

22 files changed

+171
-59
lines changed

.github/workflows/node.js.yml

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,6 @@ jobs:
2020
uses: actions/setup-node@v2
2121
with:
2222
node-version: ${{ matrix.node-version }}
23-
- uses: actions/cache@v2
24-
with:
25-
path: ~/.npm
26-
key: ${{ runner.os }}-node-${{ hashFiles('**/package-lock.json') }}
27-
restore-keys: |
28-
${{ runner.os }}-node-
2923
- name: Install dependencies
3024
run: npm ci
3125
- name: Test

hardhat.config.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,7 @@ const buidlerConfig: HardhatUserConfig = {
108108
xdai: getCommonNetworkConfig(eXDaiNetwork.xdai, 100),
109109
avalanche: getCommonNetworkConfig(eAvalancheNetwork.avalanche, 43114),
110110
fuji: getCommonNetworkConfig(eAvalancheNetwork.fuji, 43113),
111+
goerli: getCommonNetworkConfig(eEthereumNetwork.goerli, 5),
111112
hardhat: {
112113
hardfork: 'berlin',
113114
blockGasLimit: DEFAULT_BLOCK_GAS_LIMIT,

helper-hardhat-config.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ export const NETWORKS_RPC_URL: iParamsPerNetwork<string> = {
5555
[eXDaiNetwork.xdai]: 'https://rpc.xdaichain.com/',
5656
[eAvalancheNetwork.avalanche]: 'https://api.avax.network/ext/bc/C/rpc',
5757
[eAvalancheNetwork.fuji]: 'https://api.avax-test.network/ext/bc/C/rpc',
58+
[eEthereumNetwork.goerli]: `https://eth-goerli.g.alchemy.com/v2/${ALCHEMY_KEY}`,
5859
};
5960

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

7577
export const BLOCK_TO_FORK: iParamsPerNetwork<number | undefined> = {
@@ -85,4 +87,5 @@ export const BLOCK_TO_FORK: iParamsPerNetwork<number | undefined> = {
8587
[eXDaiNetwork.xdai]: undefined,
8688
[eAvalancheNetwork.avalanche]: undefined,
8789
[eAvalancheNetwork.fuji]: undefined,
90+
[eEthereumNetwork.goerli]: undefined,
8891
};

helpers/constants.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import BigNumber from 'bignumber.js';
2-
import { eEthereumNetwork } from './types';
32

43
// ----------------
54
// MATH
@@ -87,6 +86,7 @@ export const chainlinkAggregatorProxy = {
8786
'arbitrum-rinkeby': '0x5f0423B1a6935dc5596e7A24d98532b67A0AeFd8',
8887
arbitrum: '0x639Fe6ab55C921f74e7fac1ee960C0B6293ba612',
8988
rinkeby: '0x8A753747A1Fa494EC906cE90E9f37563A8AF630e',
89+
goerli: '0x9F54B624fb17d07816C5552f8AB133c21b0322cD',
9090
};
9191

9292
export const chainlinkEthUsdAggregatorProxy = {
@@ -100,4 +100,5 @@ export const chainlinkEthUsdAggregatorProxy = {
100100
'arbitrum-rinkeby': '0x5f0423B1a6935dc5596e7A24d98532b67A0AeFd8',
101101
arbitrum: '0x639Fe6ab55C921f74e7fac1ee960C0B6293ba612',
102102
rinkeby: '0x8A753747A1Fa494EC906cE90E9f37563A8AF630e',
103+
goerli: '0x9F54B624fb17d07816C5552f8AB133c21b0322cD',
103104
};

helpers/contracts-getters.ts

Lines changed: 24 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -210,17 +210,21 @@ export const getPairsTokenAggregator = (
210210
getQuoteCurrencies(oracleQuoteCurrency)
211211
);
212212

213-
const pairs = Object.entries(assetsWithoutQuoteCurrency).map(([tokenSymbol, tokenAddress]) => {
214-
//if (true/*tokenSymbol !== 'WETH' && tokenSymbol !== 'ETH' && tokenSymbol !== 'LpWETH'*/) {
215-
const aggregatorAddressIndex = Object.keys(aggregatorsAddresses).findIndex(
216-
(value) => value === tokenSymbol
217-
);
218-
const [, aggregatorAddress] = (
219-
Object.entries(aggregatorsAddresses) as [string, tEthereumAddress][]
220-
)[aggregatorAddressIndex];
221-
return [tokenAddress, aggregatorAddress];
222-
//}
223-
}) as [string, string][];
213+
const pairs = Object.entries(assetsWithoutQuoteCurrency).reduce<[string, string][]>(
214+
(acc, [tokenSymbol, tokenAddress]) => {
215+
const aggregatorAddressIndex = Object.keys(aggregatorsAddresses).findIndex(
216+
(value) => value === tokenSymbol
217+
);
218+
if (aggregatorAddressIndex >= 0) {
219+
const [, aggregatorAddress] = (
220+
Object.entries(aggregatorsAddresses) as [string, tEthereumAddress][]
221+
)[aggregatorAddressIndex];
222+
return [...acc, [tokenAddress, aggregatorAddress]];
223+
}
224+
return acc;
225+
},
226+
[]
227+
);
224228

225229
const mappedPairs = pairs.map(([asset]) => asset);
226230
const mappedAggregators = pairs.map(([, source]) => source);
@@ -424,23 +428,26 @@ export const getFlashLiquidationAdapter = async (address?: tEthereumAddress) =>
424428
export const getMockParaSwapAugustus = async (address?: tEthereumAddress) =>
425429
await MockParaSwapAugustusFactory.connect(
426430
address ||
427-
(await getDb().get(`${eContractid.MockParaSwapAugustus}.${DRE.network.name}`).value())
428-
.address,
431+
(
432+
await getDb().get(`${eContractid.MockParaSwapAugustus}.${DRE.network.name}`).value()
433+
).address,
429434
await getFirstSigner()
430435
);
431436

432437
export const getMockParaSwapAugustusRegistry = async (address?: tEthereumAddress) =>
433438
await MockParaSwapAugustusRegistryFactory.connect(
434439
address ||
435-
(await getDb().get(`${eContractid.MockParaSwapAugustusRegistry}.${DRE.network.name}`).value())
436-
.address,
440+
(
441+
await getDb().get(`${eContractid.MockParaSwapAugustusRegistry}.${DRE.network.name}`).value()
442+
).address,
437443
await getFirstSigner()
438444
);
439445

440446
export const getParaSwapLiquiditySwapAdapter = async (address?: tEthereumAddress) =>
441447
await ParaSwapLiquiditySwapAdapterFactory.connect(
442448
address ||
443-
(await getDb().get(`${eContractid.ParaSwapLiquiditySwapAdapter}.${DRE.network.name}`).value())
444-
.address,
449+
(
450+
await getDb().get(`${eContractid.ParaSwapLiquiditySwapAdapter}.${DRE.network.name}`).value()
451+
).address,
445452
await getFirstSigner()
446453
);

helpers/contracts-helpers.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ export const linkBytecode = (artifact: BuidlerArtifact | Artifact, libraries: an
145145
};
146146

147147
export const getParamPerNetwork = <T>(param: iParamsPerNetwork<T>, network: eNetwork) => {
148-
const { main, ropsten, kovan, coverage, buidlerevm, tenderly } =
148+
const { main, ropsten, kovan, coverage, buidlerevm, tenderly, goerli } =
149149
param as iEthereumParamsPerNetwork<T>;
150150
const { matic, mumbai } = param as iPolygonParamsPerNetwork<T>;
151151
const { xdai } = param as iXDaiParamsPerNetwork<T>;
@@ -179,6 +179,8 @@ export const getParamPerNetwork = <T>(param: iParamsPerNetwork<T>, network: eNet
179179
return avalanche;
180180
case eAvalancheNetwork.fuji:
181181
return fuji;
182+
case eEthereumNetwork.goerli:
183+
return goerli;
182184
}
183185
};
184186

helpers/etherscan-verification.ts

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,20 @@ const fatalErrors = [
1010
`The constructor for`,
1111
];
1212

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

1515
const unableVerifyError = 'Fail - Unable to verify';
1616

17-
export const SUPPORTED_ETHERSCAN_NETWORKS = ['main', 'ropsten', 'kovan', 'matic', 'mumbai'];
17+
export const SUPPORTED_ETHERSCAN_NETWORKS = [
18+
'main',
19+
'ropsten',
20+
'kovan',
21+
'matic',
22+
'mumbai',
23+
'goerli',
24+
'avalanche',
25+
'fuji',
26+
];
1827

1928
function delay(ms: number) {
2029
return new Promise((resolve) => setTimeout(resolve, ms));

helpers/init-helpers.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import { chunk, getDb, waitForTx } from './misc-utils';
1010
import {
1111
getAToken,
1212
getATokensAndRatesHelper,
13+
getLendingPool,
1314
getLendingPoolAddressesProvider,
1415
getLendingPoolConfiguratorProxy,
1516
} from './contracts-getters';
@@ -20,9 +21,9 @@ import {
2021
import { BigNumberish } from 'ethers';
2122
import { ConfigNames } from './configuration';
2223
import { deployRateStrategy } from './contracts-deployments';
24+
import { ZERO_ADDRESS } from './constants';
2325

2426
export const getATokenExtraParams = async (aTokenName: string, tokenAddress: tEthereumAddress) => {
25-
console.log(aTokenName);
2627
switch (aTokenName) {
2728
default:
2829
return '0x10';
@@ -88,6 +89,12 @@ export const initReservesByHelper = async (
8889
console.log(`- Skipping init of ${symbol} due token address is not set at markets config`);
8990
continue;
9091
}
92+
const pool = await getLendingPool(await addressProvider.getLendingPool());
93+
const poolReserve = await pool.getReserveData(tokenAddresses[symbol]);
94+
if (poolReserve.aTokenAddress !== ZERO_ADDRESS) {
95+
console.log(`- Skipping init of ${symbol} due is already initialized`);
96+
continue;
97+
}
9198
const { strategy, aTokenImpl, reserveDecimals } = params;
9299
const {
93100
optimalUtilizationRate,

helpers/oracles-helpers.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -67,8 +67,8 @@ export const setInitialMarketRatesInRatesOracleByHelper = async (
6767
};
6868

6969
export const setInitialAssetPricesInOracle = async (
70-
prices: iAssetBase<tEthereumAddress>,
71-
assetsAddresses: iAssetBase<tEthereumAddress>,
70+
prices: { [key: string]: string },
71+
assetsAddresses: { [key: string]: string },
7272
priceOracleInstance: PriceOracle
7373
) => {
7474
for (const [assetSymbol, price] of Object.entries(prices) as [string, string][]) {
@@ -113,17 +113,17 @@ export const deployMockAggregators = async (initialPrices: SymbolMap<string>, ve
113113
};
114114

115115
export const deployAllMockAggregators = async (
116-
initialPrices: iAssetAggregatorBase<string>,
116+
initialPrices: SymbolMap<string>,
117117
verify?: boolean
118118
) => {
119-
const aggregators: { [tokenSymbol: string]: MockAggregator } = {};
119+
const aggregators: { [tokenSymbol: string]: tEthereumAddress } = {};
120120
for (const tokenContractName of Object.keys(initialPrices)) {
121121
if (tokenContractName !== 'ETH') {
122122
const priceIndex = Object.keys(initialPrices).findIndex(
123123
(value) => value === tokenContractName
124124
);
125125
const [, price] = (Object.entries(initialPrices) as [string, string][])[priceIndex];
126-
aggregators[tokenContractName] = await deployMockAggregator(price, verify);
126+
aggregators[tokenContractName] = (await deployMockAggregator(price, verify)).address;
127127
}
128128
}
129129
return aggregators;

helpers/types.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,9 @@ export enum eEthereumNetwork {
1313
main = 'main',
1414
coverage = 'coverage',
1515
hardhat = 'hardhat',
16+
1617
tenderly = 'tenderly',
18+
goerli = 'goerli',
1719
}
1820

1921
export enum ePolygonNetwork {
@@ -432,6 +434,7 @@ export interface iEthereumParamsPerNetwork<T> {
432434
[eEthereumNetwork.main]: T;
433435
[eEthereumNetwork.hardhat]: T;
434436
[eEthereumNetwork.tenderly]: T;
437+
[eEthereumNetwork.goerli]: T;
435438
}
436439

437440
export interface iPolygonParamsPerNetwork<T> {
@@ -480,7 +483,7 @@ export interface IProtocolGlobalConfig {
480483
}
481484

482485
export interface IMocksConfig {
483-
AllAssetsInitialPrices: iAssetBase<string>;
486+
AllAssetsInitialPrices: { [key: string]: string };
484487
}
485488

486489
export interface ILendingRateOracleRatesCommon {

0 commit comments

Comments
 (0)