-
Notifications
You must be signed in to change notification settings - Fork 62
Expand file tree
/
Copy pathhardhat.config.js
More file actions
614 lines (608 loc) · 20.5 KB
/
Copy pathhardhat.config.js
File metadata and controls
614 lines (608 loc) · 20.5 KB
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
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
/** @type import('hardhat/config').HardhatUserConfig */
// Env loading (runs before `networks` — independent of `--network`):
// - If process.env.ENV_FILE is set (shell), only that file is loaded into process.env.
// - Else if root `.env` exists and defines ENV_FILE=..., only that target file is loaded
// (`.env` is parsed for ENV_FILE only — other keys in `.env` are NOT applied).
// - Else load default `.env` as usual.
// `--network abstract_testnet` does NOT switch ENV_FILE; root `.env` may still point at e.g. bsc_testnet.
// Override per command: ENV_FILE=.env.launchpadv5_dev_abstract_testnet npx hardhat verify ... --network abstract_testnet
// Usage: put `ENV_FILE=.env.launchpadv5_local` in `.env`, or `ENV_FILE=.env.launchpadv5_local npx hardhat ...`
const fs = require("fs");
const path = require("path");
const dotenv = require("dotenv");
const projectRoot = __dirname;
const rootDotEnv = path.join(projectRoot, ".env");
function resolveEnvPath(p) {
const s = (p || "").trim();
if (!s) return null;
return path.isAbsolute(s) ? s : path.join(projectRoot, s);
}
let target = process.env.ENV_FILE?.trim() || null;
if (!target && fs.existsSync(rootDotEnv)) {
const parsed = dotenv.parse(fs.readFileSync(rootDotEnv, "utf8"));
target = (parsed.ENV_FILE || "").trim() || null;
}
if (target) {
const resolved = resolveEnvPath(target);
if (!resolved || !fs.existsSync(resolved)) {
throw new Error(
`ENV_FILE "${target}" resolved to missing path: ${resolved || "(empty)"}`
);
}
dotenv.config({ path: resolved });
console.log(`Loaded env file: ${resolved}`);
} else if (fs.existsSync(rootDotEnv)) {
dotenv.config({ path: rootDotEnv });
console.log(`Loaded env file: ${rootDotEnv}`);
} else {
dotenv.config(); // cwd `.env`, same as dotenv default
console.log("Loaded env via dotenv default (cwd .env if present)");
}
require("@nomicfoundation/hardhat-toolbox");
require("@okxweb3/hardhat-explorer-verify"); // OKLink `okverify` for X Layer (chainId 1952 / 196). See okxweb3explorer below.
require("hardhat-deploy");
require("@openzeppelin/hardhat-upgrades");
require("@fireblocks/hardhat-fireblocks");
require("hardhat-contract-sizer");
const { ApiBaseUrl } = require("@fireblocks/fireblocks-web3-provider");
module.exports = {
// Multiple compilers: verify (okverify / etherscan) must include every solc version present in on-chain bytecode metadata.
// Deploys may use 0.8.29 while day-to-day sources target 0.8.26 — list both with the same optimizer/viaIR so verification matches.
// Hardhat picks the highest pragma-compatible compiler per file; use `overrides` below to pin 0.8.26 where bytecode must stay fixed.
// Uni V2 npm artifacts: @uniswap/v2-core 0.5.16; @uniswap/v2-periphery 0.6.6.
solidity: {
compilers: [
{
version: "0.5.16",
settings: {
optimizer: {
enabled: true,
runs: 999999,
},
evmVersion: "istanbul",
},
},
{
version: "0.6.6",
settings: {
optimizer: {
enabled: true,
runs: 999999,
},
evmVersion: "istanbul",
},
},
{
version: "0.8.26",
settings: {
viaIR: true,
optimizer: {
enabled: true,
runs: 200,
},
},
},
// {
// version: "0.8.29",
// settings: {
// viaIR: true,
// optimizer: {
// enabled: true,
// runs: 200,
// },
// },
// },
],
},
overrides: {
"contracts/genesis/FGenesis.sol": {
version: "0.8.26",
settings: {
optimizer: {
enabled: true,
runs: 200,
},
viaIR: false,
},
},
"contracts/genesis/Genesis.sol": {
version: "0.8.26",
settings: {
optimizer: {
enabled: true,
runs: 200,
},
viaIR: false,
},
},
"contracts/launchpadv2/BondingV2.sol": {
version: "0.8.26",
settings: {
optimizer: {
enabled: true,
runs: 200,
},
viaIR: false,
},
},
"contracts/launchpadv2/BondingV4.sol": {
version: "0.8.26",
settings: {
optimizer: {
enabled: true,
runs: 200,
},
viaIR: false,
},
},
"contracts/launchpadv2/BondingV5.sol": {
version: "0.8.26",
settings: {
optimizer: {
enabled: true,
runs: 200,
},
viaIR: false,
},
},
},
namedAccounts: {
deployer: `privatekey://${process.env.PRIVATE_KEY}`,
},
etherscan: {
// Etherscan API V2 (single key, multichain via chainid): https://docs.etherscan.io/v2-migration
// Do not use legacy api.basescan.org/api — Hardhat-verify reports deprecated V1 / log fetch failures.
//
// X Layer (OKLink): uses `okverify` task from @okxweb3/hardhat-explorer-verify (Method 1).
// Method 2 (customChains + verify:verify/verify:etherscan) does NOT work — OKLink's plugin
// endpoint rejects standard Etherscan POST format ("Missing or unsupported chainid parameter").
// The xlayer_* entries below are kept for reference but verification goes through okxweb3explorer below.
// Set OKLINK_API_KEY (or ETHERSCAN_API_KEY) to your OKLink API key when verifying on xlayer_*.
// https://www.oklink.com/docs/zh/#explorer-api-tools-contract-verification-verify-source-code-using-hardhat
// Object format required so hardhat-verify uses customChains.urls.apiURL per network.
// String format routes ALL chains to Etherscan V2 (api.etherscan.io/v2/api?chainid=...) and
// ignores customChains apiURLs — breaking chains not in Etherscan V2's supported list (e.g. robinhood_testnet).
apiKey: {
// Etherscan V2 chains (all share the same key via api.etherscan.io/v2/api?chainid=)
eth_mainnet: process.env.ETHERSCAN_API_KEY || "",
sepolia: process.env.ETHERSCAN_API_KEY || "",
eth_sepolia: process.env.ETHERSCAN_API_KEY || "",
bsc_mainnet: process.env.ETHERSCAN_API_KEY || "",
bsc_testnet: process.env.ETHERSCAN_API_KEY || "",
base: process.env.ETHERSCAN_API_KEY || "",
base_sepolia: process.env.ETHERSCAN_API_KEY || "",
abstract_testnet: process.env.ETHERSCAN_API_KEY || "",
abstract_mainnet: process.env.ETHERSCAN_API_KEY || "",
monad_testnet: process.env.ETHERSCAN_API_KEY || "",
monad_mainnet: process.env.ETHERSCAN_API_KEY || "",
arbitrum_sepolia: process.env.ETHERSCAN_API_KEY || "",
// X Layer — OKLink key used by okverify task; kept here for completeness
xlayer_testnet: process.env.OKLINK_API_KEY || process.env.ETHERSCAN_API_KEY || "",
xlayer_mainnet: process.env.OKLINK_API_KEY || process.env.ETHERSCAN_API_KEY || "",
// Robinhood testnet/mainnet — Blockscout explorer (not in Etherscan V2).
// Blockscout does not validate API keys; any non-empty string works.
robinhood_testnet: process.env.ETHERSCAN_API_KEY || "blockscout",
robinhood_mainnet: process.env.ETHERSCAN_API_KEY || "blockscout",
},
customChains: [
{
network: "base",
chainId: 8453,
urls: {
apiURL: "https://api.etherscan.io/v2/api",
browserURL: "https://basescan.org/",
},
},
{
network: "base_sepolia",
chainId: 84532,
urls: {
apiURL: "https://api.etherscan.io/v2/api",
browserURL: "https://sepolia.basescan.org/",
},
},
// Abstract L2 — https://docs.abs.xyz/build-on-abstract/smart-contracts/hardhat/verifying-contracts
{
network: "abstract_testnet",
chainId: 11124,
urls: {
apiURL: "https://api.etherscan.io/v2/api",
browserURL: "https://sepolia.abscan.org/",
},
},
{
network: "abstract_mainnet",
chainId: 2741,
urls: {
apiURL: "https://api.etherscan.io/v2/api",
browserURL: "https://abscan.org/",
},
},
// Monad — https://docs.monad.xyz/guides/verify-smart-contract/hardhat
// MonadScan uses Etherscan v2 (api.etherscan.io; Hardhat passes chainid). Monad Vision uses Sourcify
// (see scripts/launchpadv5/utils.ts verifyContract for monad_* networks).
{
network: "monad_testnet",
chainId: 10143,
urls: {
apiURL: "https://api.etherscan.io/v2/api",
browserURL: "https://testnet.monadscan.com/",
},
},
{
network: "monad_mainnet",
chainId: 143,
urls: {
apiURL: "https://api.etherscan.io/v2/api",
browserURL: "https://monadscan.com/",
},
},
{
network: "arbitrum_sepolia",
chainId: 421614,
urls: {
apiURL: "https://api.etherscan.io/v2/api",
browserURL: "https://sepolia.arbiscan.io/",
},
},
// Arc Network — uses Blockscout (Etherscan-compatible API).
// Explorer: https://testnet.arcscan.app
{
network: "arc_testnet",
chainId: 5042002,
urls: {
apiURL: "https://testnet.arcscan.app/api",
browserURL: "https://testnet.arcscan.app",
},
},
{
network: "arc_mainnet",
chainId: 5042,
urls: {
apiURL: "https://arcscan.app/api",
browserURL: "https://arcscan.app",
// Robinhood testnet (chainId 46630) is NOT in Etherscan V2's chainlist.
// apiKey is an object (see above), so hardhat-verify uses this Blockscout apiURL directly
// instead of routing to Etherscan V2. Blockscout is Etherscan-compatible and does not
// validate API key values. The robinhood_testnet entry in apiKey holds any non-empty string.
},
},
{
network: "robinhood_testnet",
chainId: 46630,
urls: {
apiURL: "https://robinhoodchain-testnet.blockscout.com/api",
browserURL: "https://robinhoodchain-testnet.blockscout.com",
},
},
// X Layer (OKLink) — kept for reference only. Verification uses okxweb3explorer (okverify) below.
// Standard Etherscan format (verify:verify / verify:etherscan) fails with "Missing or unsupported chainid parameter".
{
network: "xlayer_testnet",
chainId: 1952,
urls: {
apiURL:
"https://www.oklink.com/api/v5/explorer/contract/verify-source-code-plugin/XLAYER_TESTNET",
browserURL: "https://www.oklink.com/xlayer-test",
},
},
{
network: "xlayer_mainnet",
chainId: 196,
urls: {
apiURL:
"https://www.oklink.com/api/v5/explorer/contract/verify-source-code-plugin/XLAYER",
browserURL: "https://www.oklink.com/xlayer",
},
},
{
network: "robinhood_mainnet",
chainId: 4663,
urls: {
apiURL: "https://robinhoodchain.blockscout.com/api",
browserURL: "https://robinhoodchain.blockscout.com",
},
},
],
},
// @okxweb3/hardhat-explorer-verify: primary verification for X Layer (okverify task, Method 1).
// Uses OKLink-specific request format — the only format OKLink's plugin endpoint accepts.
okxweb3explorer: {
apiKey:
process.env.OKLINK_API_KEY ||
process.env.ETHERSCAN_API_KEY ||
"OKLINK",
customChains: [
{
network: "xlayer_testnet",
chainId: 1952,
urls: {
apiURL:
"https://www.oklink.com/api/v5/explorer/contract/verify-source-code-plugin/XLAYER_TESTNET",
browserURL: "https://www.oklink.com/zh-hans/xlayer-test/explorer",
},
},
{
network: "xlayer_mainnet",
chainId: 196,
urls: {
apiURL:
"https://www.oklink.com/api/v5/explorer/contract/verify-source-code-plugin/XLAYER",
browserURL: "https://www.oklink.com/zh-hans/xlayer/explorer",
},
},
],
},
// Do not set a global Monad Sourcify URL here: `verify` would send every chain’s chainId to that server.
// Monad Sourcify is applied only in `scripts/launchpadv5/utils.ts` when network is monad_*.
sourcify: {
enabled: false,
},
networks: {
eth_mainnet: {
url: process.env.ETH_MAINNET_RPC_URL || "https://eth.drpc.org",
accounts: [process.env.PRIVATE_KEY],
},
sepolia: {
url: process.env.SEPOLIA_RPC_URL || "https://sepolia.drpc.org",
accounts: [process.env.PRIVATE_KEY],
},
eth_sepolia: {
url: process.env.ETH_SEPOLIA_RPC_URL || "https://sepolia.drpc.org",
accounts: [process.env.PRIVATE_KEY],
},
bsc_mainnet: {
url:
process.env.BSC_RPC_URL ||
process.env.RPC_URL ||
"https://bsc.drpc.org",
accounts: [process.env.PRIVATE_KEY],
chainId: 56,
},
bsc_testnet: {
url:
process.env.BSC_TESTNET_RPC_URL ||
process.env.RPC_URL ||
"https://bsc-testnet.drpc.org",
accounts: [process.env.PRIVATE_KEY],
chainId: 97,
},
// Abstract L2 testnet (see https://docs.abs.xyz/connect-to-abstract)
abstract_testnet: {
url:
process.env.ABSTRACT_TESTNET_RPC_URL ||
process.env.RPC_URL ||
"https://api.testnet.abs.xyz",
accounts: [process.env.PRIVATE_KEY],
chainId: 11124,
},
// Abstract L2 mainnet (see https://docs.abs.xyz/connect-to-abstract)
abstract_mainnet: {
url:
process.env.ABSTRACT_MAINNET_RPC_URL ||
process.env.RPC_URL ||
"https://api.mainnet.abs.xyz",
accounts: [process.env.PRIVATE_KEY],
chainId: 2741,
},
monad_testnet: {
url:
process.env.MONAD_TESTNET_RPC_URL ||
process.env.RPC_URL ||
"https://testnet-rpc.monad.xyz",
accounts: [process.env.PRIVATE_KEY],
chainId: 10143,
},
monad_mainnet: {
url:
process.env.MONAD_MAINNET_RPC_URL ||
process.env.RPC_URL ||
"https://mainnet.monad.xyz",
accounts: [process.env.PRIVATE_KEY],
chainId: 143,
},
base: {
url:
process.env.BASE_RPC_URL ||
process.env.RPC_URL ||
"https://mainnet.base.org",
accounts: [process.env.PRIVATE_KEY],
},
base_fire: {
url: "https://mainnet.base.org",
accounts: [process.env.PRIVATE_KEY],
fireblocks: {
privateKey: process.env.FIREBLOCKS_API_PRIVATE_KEY_PATH,
apiKey: process.env.FIREBLOCKS_API_KEY,
vaultAccountIds: process.env.FIREBLOCKS_VAULT_ACCOUNT_IDS,
},
},
base_sepolia: {
url:
process.env.BASE_SEPOLIA_RPC_URL ||
process.env.RPC_URL ||
"https://base-sepolia.drpc.org",
accounts: [process.env.PRIVATE_KEY],
},
// Do not fall back to RPC_URL — it often points at another chain (e.g. mainnet) in shared .env files.
arbitrum_sepolia: {
url:
process.env.ARBITRUM_SEPOLIA_RPC_URL ||
"https://sepolia-rollup.arbitrum.io/rpc",
accounts: [process.env.PRIVATE_KEY],
chainId: 421614,
},
robinhood_testnet: {
url:
process.env.ROBINHOOD_TESTNET_RPC_URL ||
"https://testnet.rpc.robinhood.com",
accounts: [process.env.PRIVATE_KEY],
chainId: 46630,
},
robinhood_mainnet: {
url: process.env.ROBINHOOD_MAINNET_RPC_URL || "",
accounts: [process.env.PRIVATE_KEY],
chainId: 4663,
},
robinhood_fire: {
url: process.env.ROBINHOOD_MAINNET_RPC_URL || "",
accounts: [process.env.PRIVATE_KEY],
chainId: 4663,
fireblocks: {
privateKey: process.env.FIREBLOCKS_API_PRIVATE_KEY_PATH,
apiKey: process.env.FIREBLOCKS_API_KEY,
vaultAccountIds: process.env.FIREBLOCKS_VAULT_ACCOUNT_IDS,
chainId: 4663,
assetId:"ROBINHOOD",
},
},
// X Layer (OKX)
// Do not fall back to RPC_URL to avoid accidental cross-chain deploys.
xlayer_testnet: {
url:
process.env.XLAYER_TESTNET_RPC_URL ||
// `/terigon` has been flaky (ECONNRESET); public endpoint without path is more stable.
"https://xlayertestrpc.okx.com",
accounts: [process.env.PRIVATE_KEY],
chainId: 1952,
timeout: 120_000,
},
xlayer_mainnet: {
url:
process.env.XLAYER_RPC_URL ||
"https://xlayerrpc.okx.com",
accounts: [process.env.PRIVATE_KEY],
chainId: 196,
},
// Arc Network — https://www.arc.network/
// Do not fall back to RPC_URL to avoid accidental cross-chain deploys.
arc_testnet: {
url:
process.env.ARC_TESTNET_RPC_URL ||
"https://rpc.arc-testnet.network",
accounts: [process.env.PRIVATE_KEY],
chainId: 5042002,
timeout: 120_000,
},
arc_mainnet: {
url:
process.env.ARC_MAINNET_RPC_URL ||
"https://rpc.arc.network",
accounts: [process.env.PRIVATE_KEY],
chainId: 5042,
},
robinhood_testnet: {
url: process.env.ROBINHOOD_TESTNET_RPC_URL || "",
accounts: [process.env.PRIVATE_KEY],
chainId: 46630,
},
robinhood_mainnet: {
url: process.env.ROBINHOOD_MAINNET_RPC_URL || "",
accounts: [process.env.PRIVATE_KEY],
chainId: 4663,
},
base_sepolia_fire: {
url: "https://sepolia.base.org",
accounts: [process.env.PRIVATE_KEY],
fireblocks: {
apiBaseUrl: ApiBaseUrl.Sandbox,
privateKey: process.env.FIREBLOCKS_API_PRIVATE_KEY_PATH,
apiKey: process.env.FIREBLOCKS_API_KEY,
vaultAccountIds: process.env.FIREBLOCKS_VAULT_ACCOUNT_IDS,
},
},
local: {
url: "http://127.0.0.1:8545",
// Forked `hardhat node`: use PRIVATE_KEY so deployer matches the address that holds
// tokens on the forked chain (default Hardhat account #0 is usually empty on real forks).
...(process.env.PRIVATE_KEY
? { accounts: [process.env.PRIVATE_KEY] }
: {}),
// For forked node: npx hardhat node --fork <rpc_url> [--fork-block-number <n>]
},
// Fork RPC:
// - `npx hardhat node --fork <url>`: Hardhat uses that URL. Nothing below overrides it.
// - `npx hardhat test --network hardhat` with FORK_ENABLED=true: uses `forking.url` here
// (no separate node; no --fork on the CLI).
hardhat: {
// // Test-only: BondingV5 implementation currently exceeds EIP-170 size limit.
// // Keep production networks constrained; only relax in local hardhat runtime.
// allowUnlimitedContractSize: true,
forking: {
// Prefer FORK_RPC_URL when set. `run_local_deploy.sh --network local` requires FORK_RPC_URL in the env file.
url:
process.env.FORK_RPC_URL ||
process.env.BASE_SEPOLIA_RPC_URL ||
"https://base-sepolia.drpc.org",
enabled: process.env.FORK_ENABLED === "true",
// Omit blockNumber → Hardhat uses latest block from the fork RPC.
// Set FORK_BLOCK_NUMBER only when you need a pinned height (reproducible state).
...(process.env.FORK_BLOCK_NUMBER
? { blockNumber: parseInt(process.env.FORK_BLOCK_NUMBER, 10) }
: {}),
},
// Don't restrict accounts for hardhat network - use default 20 test accounts
// This ensures tests have enough signers available
// `chains` is the local EVM hardfork schedule, not “which RPC”. Hardhat reads chainId
// from the fork, but execution still needs a known activation history for some networks;
// add an entry here only if you hit that error (see Hardhat “chains” docs).
chains: {
84532: {
hardforkHistory: {
cancun: 0,
},
},
97: {
hardforkHistory: {
cancun: 0,
},
},
11124: {
hardforkHistory: {
cancun: 0,
},
},
2741: {
hardforkHistory: {
cancun: 0,
},
},
10143: {
hardforkHistory: {
cancun: 0,
},
},
421614: {
hardforkHistory: {
cancun: 0,
},
},
1952: {
hardforkHistory: {
cancun: 0,
},
},
196: {
hardforkHistory: {
cancun: 0,
},
},
},
},
polygon: {
url: "https://rpc-mainnet.maticvigil.com/",
accounts: [process.env.PRIVATE_KEY],
},
mumbai: {
url: "https://rpc.ankr.com/polygon_mumbai",
accounts: [process.env.PRIVATE_KEY],
},
goerli: {
url: "https://rpc.ankr.com/eth_goerli",
accounts: [process.env.PRIVATE_KEY],
},
},
mocha: {
timeout: 100000000,
},
};