forked from compound-finance/comet
-
Notifications
You must be signed in to change notification settings - Fork 0
/
hardhat.config.ts
444 lines (419 loc) · 11.8 KB
/
hardhat.config.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
import 'dotenv/config';
import { HardhatUserConfig, task } from 'hardhat/config';
import '@compound-finance/hardhat-import';
import '@nomiclabs/hardhat-ethers';
import '@nomiclabs/hardhat-etherscan';
import '@typechain/hardhat';
import 'hardhat-chai-matchers';
import 'hardhat-change-network';
import 'hardhat-contract-sizer';
import 'hardhat-cover';
import 'hardhat-gas-reporter';
// Hardhat tasks
import './tasks/deployment_manager/task.ts';
import './tasks/spider/task.ts';
import './tasks/scenario/task.ts';
// Relation Config
import relationConfigMap from './deployments/relations';
import goerliRelationConfigMap from './deployments/goerli/usdc/relations';
import goerliWethRelationConfigMap from './deployments/goerli/weth/relations';
import mumbaiRelationConfigMap from './deployments/mumbai/usdc/relations';
import mainnetRelationConfigMap from './deployments/mainnet/usdc/relations';
import mainnetWethRelationConfigMap from './deployments/mainnet/weth/relations';
import polygonRelationConfigMap from './deployments/polygon/usdc/relations';
import arbitrumRelationConfigMap from './deployments/arbitrum/usdc/relations';
import arbitrumBridgedUsdcGoerliRelationConfigMap from './deployments/arbitrum-goerli/usdc.e/relations';
import arbitrumGoerliNativeUsdcRelationConfigMap from './deployments/arbitrum-goerli/usdc/relations';
import baseUsdbcRelationConfigMap from './deployments/base/usdbc/relations';
import baseGoerliRelationConfigMap from './deployments/base-goerli/usdc/relations';
import baseGoerliWethRelationConfigMap from './deployments/base-goerli/weth/relations';
import lineaGoerliRelationConfigMap from './deployments/linea-goerli/usdc/relations';
task('accounts', 'Prints the list of accounts', async (taskArgs, hre) => {
for (const account of await hre.ethers.getSigners()) console.log(account.address);
});
/* note: boolean environment variables are imported as strings */
const {
COINMARKETCAP_API_KEY,
ETH_PK = '',
ETHERSCAN_KEY,
SNOWTRACE_KEY,
POLYGONSCAN_KEY,
ARBISCAN_KEY,
BASESCAN_KEY,
LINEASCAN_KEY,
INFURA_KEY,
QUICKNODE_KEY,
MNEMONIC = 'myth like bonus scare over problem client lizard pioneer submit female collect',
REPORT_GAS = 'false',
NETWORK_PROVIDER = '',
GOV_NETWORK_PROVIDER = '',
GOV_NETWORK = '',
REMOTE_ACCOUNTS = ''
} = process.env;
function *deriveAccounts(pk: string, n: number = 10) {
for (let i = 0; i < n; i++)
yield (BigInt('0x' + pk) + BigInt(i)).toString(16);
}
export function requireEnv(varName, msg?: string): string {
const varVal = process.env[varName];
if (!varVal) {
throw new Error(msg ?? `Missing required environment variable '${varName}'`);
}
return varVal;
}
// required environment variables
[
'ETHERSCAN_KEY',
'SNOWTRACE_KEY',
'INFURA_KEY',
'POLYGONSCAN_KEY',
'ARBISCAN_KEY',
'LINEASCAN_KEY'
].map(v => requireEnv(v));
// Networks
interface NetworkConfig {
network: string;
chainId: number;
url?: string;
gas?: number | 'auto';
gasPrice?: number | 'auto';
}
const networkConfigs: NetworkConfig[] = [
{ network: 'mainnet', chainId: 1 },
{ network: 'ropsten', chainId: 3 },
{ network: 'rinkeby', chainId: 4 },
{ network: 'goerli', chainId: 5 },
{
network: 'polygon',
chainId: 137,
url: `${process.env.ALCHEMY_PROVIDER}`,
},
{
network: 'base',
chainId: 8453,
url: `https://clean-spring-wind.base-mainnet.discover.quiknode.pro/${QUICKNODE_KEY}`,
},
{
network: 'arbitrum',
chainId: 42161,
url: `https://arbitrum-mainnet.infura.io/v3/${INFURA_KEY}`,
},
{
network: 'avalanche',
chainId: 43114,
url: 'https://api.avax.network/ext/bc/C/rpc',
},
{
network: 'fuji',
chainId: 43113,
url: 'https://api.avax-test.network/ext/bc/C/rpc',
},
{
network: 'mumbai',
chainId: 80001,
url: `https://polygon-mumbai.infura.io/v3/${INFURA_KEY}`,
},
{
network: 'arbitrum-goerli',
chainId: 421613,
url: `https://arbitrum-goerli.infura.io/v3/${INFURA_KEY}`,
},
{
network: 'base-goerli',
chainId: 84531,
url: `https://goerli.base.org/`,
},
{
network: 'linea-goerli',
chainId: 59140,
url: `https://linea-goerli.infura.io/v3/${INFURA_KEY}`,
},
];
function getDefaultProviderURL(network: string) {
return `https://${network}.infura.io/v3/${INFURA_KEY}`;
}
function setupDefaultNetworkProviders(hardhatConfig: HardhatUserConfig) {
for (const netConfig of networkConfigs) {
hardhatConfig.networks[netConfig.network] = {
chainId: netConfig.chainId,
url:
(netConfig.network === GOV_NETWORK ? GOV_NETWORK_PROVIDER : undefined) ||
NETWORK_PROVIDER ||
netConfig.url ||
getDefaultProviderURL(netConfig.network),
gas: netConfig.gas || 'auto',
gasPrice: netConfig.gasPrice || 'auto',
accounts: REMOTE_ACCOUNTS ? 'remote' : ( ETH_PK ? [...deriveAccounts(ETH_PK)] : { mnemonic: MNEMONIC } ),
};
}
}
/**
* @type import('hardhat/config').HardhatUserConfig
*/
const config: HardhatUserConfig = {
solidity: {
version: '0.8.15',
settings: {
optimizer: (
process.env['OPTIMIZER_DISABLED'] ? { enabled: false } : {
enabled: true,
runs: 1,
details: {
yulDetails: {
optimizerSteps: 'dhfoDgvulfnTUtnIf [xa[r]scLM cCTUtTOntnfDIul Lcul Vcul [j] Tpeul xa[rul] xa[r]cL gvif CTUca[r]LsTOtfDnca[r]Iulc] jmul[jul] VcTOcul jmul'
},
},
}
),
outputSelection: {
'*': {
'*': ['evm.deployedBytecode.sourceMap']
},
},
viaIR: process.env['OPTIMIZER_DISABLED'] ? false : true,
},
},
networks: {
hardhat: {
chainId: 1337,
loggingEnabled: !!process.env['LOGGING'],
gas: 12000000,
gasPrice: 'auto',
blockGasLimit: 12000000,
accounts: ETH_PK ?
[...deriveAccounts(ETH_PK)].map(privateKey => ({ privateKey, balance: (10n ** 36n).toString() }))
: { mnemonic: MNEMONIC, accountsBalance: (10n ** 36n).toString() },
// this should only be relied upon for test harnesses and coverage (which does not use viaIR flag)
allowUnlimitedContractSize: true,
hardfork: 'shanghai'
},
},
// See https://hardhat.org/plugins/nomiclabs-hardhat-etherscan.html#multiple-api-keys-and-alternative-block-explorers
etherscan: {
apiKey: {
// Ethereum
mainnet: ETHERSCAN_KEY,
ropsten: ETHERSCAN_KEY,
rinkeby: ETHERSCAN_KEY,
goerli: ETHERSCAN_KEY,
// Avalanche
avalanche: SNOWTRACE_KEY,
avalancheFujiTestnet: SNOWTRACE_KEY,
// Polygon
polygon: POLYGONSCAN_KEY,
polygonMumbai: POLYGONSCAN_KEY,
// Arbitrum
arbitrumOne: ARBISCAN_KEY,
arbitrumTestnet: ARBISCAN_KEY,
arbitrum: ARBISCAN_KEY,
'arbitrum-goerli': ARBISCAN_KEY,
// Base
base: BASESCAN_KEY,
'base-goerli': BASESCAN_KEY,
// Linea
'linea-goerli': LINEASCAN_KEY,
},
customChains: [
{
// Hardhat's Etherscan plugin calls the network `arbitrumOne`, so we need to add an entry for our own network name
network: 'arbitrum',
chainId: 42161,
urls: {
apiURL: 'https://api.arbiscan.io/api',
browserURL: 'https://arbiscan.io/'
}
},
{
// Hardhat's Etherscan plugin calls the network `arbitrumGoerli`, so we need to add an entry for our own network name
network: 'arbitrum-goerli',
chainId: 421613,
urls: {
apiURL: 'https://api-goerli.arbiscan.io/api',
browserURL: 'https://goerli.arbiscan.io/'
}
},
{
// Hardhat's Etherscan plugin doesn't have support Base, so we need to add an entry for our own network name
network: 'base',
chainId: 8453,
urls: {
apiURL: 'https://api.basescan.org/api',
browserURL: 'https://basescan.org/'
}
},
{
// Hardhat's Etherscan plugin calls the network `baseGoerli`, so we need to add an entry for our own network name
network: 'base-goerli',
chainId: 84531,
urls: {
apiURL: 'https://api-goerli.basescan.org/api',
browserURL: 'https://goerli.basescan.org/'
}
},
{
network: 'linea-goerli',
chainId: 59140,
urls: {
apiURL: 'https://api-goerli.lineascan.build/api',
browserURL: 'https://goerli.lineascan.build/'
}
}
]
},
typechain: {
outDir: 'build/types',
target: 'ethers-v5',
},
deploymentManager: {
relationConfigMap,
networks: {
goerli: {
usdc: goerliRelationConfigMap,
weth: goerliWethRelationConfigMap
},
mumbai: {
usdc: mumbaiRelationConfigMap
},
mainnet: {
usdc: mainnetRelationConfigMap,
weth: mainnetWethRelationConfigMap
},
polygon: {
usdc: polygonRelationConfigMap
},
arbitrum: {
usdc: arbitrumRelationConfigMap
},
'arbitrum-goerli': {
'usdc.e': arbitrumBridgedUsdcGoerliRelationConfigMap,
usdc: arbitrumGoerliNativeUsdcRelationConfigMap
},
'base': {
usdbc: baseUsdbcRelationConfigMap,
},
'base-goerli': {
usdc: baseGoerliRelationConfigMap,
weth: baseGoerliWethRelationConfigMap
},
'linea-goerli': {
usdc: lineaGoerliRelationConfigMap
}
},
},
scenario: {
bases: [
{
name: 'mainnet',
network: 'mainnet',
deployment: 'usdc',
allocation: 1.0, // eth
},
{
name: 'mainnet-weth',
network: 'mainnet',
deployment: 'weth',
},
{
name: 'development',
network: 'hardhat',
deployment: 'dai'
},
{
name: 'fuji',
network: 'fuji',
deployment: 'usdc'
},
{
name: 'goerli',
network: 'goerli',
deployment: 'usdc'
},
{
name: 'goerli-weth',
network: 'goerli',
deployment: 'weth',
},
{
name: 'mumbai',
network: 'mumbai',
deployment: 'usdc',
auxiliaryBase: 'goerli'
},
{
name: 'polygon',
network: 'polygon',
deployment: 'usdc',
auxiliaryBase: 'mainnet'
},
{
name: 'arbitrum',
network: 'arbitrum',
deployment: 'usdc',
auxiliaryBase: 'mainnet'
},
{
name: 'arbitrum-goerli-usdc.e',
network: 'arbitrum-goerli',
deployment: 'usdc.e',
auxiliaryBase: 'goerli'
},
{
name: 'arbitrum-goerli-usdc',
network: 'arbitrum-goerli',
deployment: 'usdc',
auxiliaryBase: 'goerli'
},
{
name: 'base-usdbc',
network: 'base',
deployment: 'usdbc',
auxiliaryBase: 'mainnet'
},
{
name: 'base-goerli',
network: 'base-goerli',
deployment: 'usdc',
auxiliaryBase: 'goerli'
},
{
name: 'base-goerli-weth',
network: 'base-goerli',
deployment: 'weth',
auxiliaryBase: 'goerli'
},
{
name: 'linea-goerli',
network: 'linea-goerli',
deployment: 'usdc',
auxiliaryBase: 'goerli'
}
],
},
mocha: {
reporter: 'mocha-multi-reporters',
reporterOptions: {
reporterEnabled: ['spec', 'json'],
jsonReporterOptions: {
output: 'test-results.json',
},
},
timeout: 150_000
},
paths: {
tests: './test',
},
contractSizer: {
alphaSort: true,
disambiguatePaths: false,
runOnCompile: true,
strict: false, // allow tests to run anyway
},
gasReporter: {
enabled: REPORT_GAS === 'true' ? true : false,
currency: 'USD',
coinmarketcap: COINMARKETCAP_API_KEY,
gasPrice: 200, // gwei
},
};
setupDefaultNetworkProviders(config);
export default config;