-
Notifications
You must be signed in to change notification settings - Fork 33
/
Copy pathhardhat.config.js
598 lines (527 loc) Β· 16.7 KB
/
hardhat.config.js
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
// Load Libraries
const chalk = require('chalk');
const fs = require("fs");
require("@nomiclabs/hardhat-waffle");
require("@nomiclabs/hardhat-ethers");
require("hardhat-gas-reporter");
require('hardhat-contract-sizer');
require("@nomicfoundation/hardhat-verify");
const { ethers } = require("ethers");
const { isAddress, getAddress, formatUnits, parseUnits } = ethers.utils;
// Check ENV File first and load ENV
verifyENV();
async function verifyENV() {
const envVerifierLoader = require('./loaders/envVerifier');
envVerifierLoader(true);
}
require('dotenv').config();
const defaultNetwork = "hardhat";
function mnemonic() {
try {
return fs.readFileSync("./mnemonic.txt").toString().trim();
} catch (e) {
if (defaultNetwork !== "localhost") {
console.log(
"β’οΈ WARNING: No mnemonic file created for a deploy account. Try `yarn run generate` and then `yarn run account`."
);
}
}
return "";
}
module.exports = {
contractSizer: {
alphaSort: false,
disambiguatePaths: false,
runOnCompile: true,
strict: true,
only: [],
},
defaultNetwork,
// don't forget to set your provider like:
// REACT_APP_PROVIDER=https://dai.poa.network in packages/react-app/.env
// (then your frontend will talk to your contracts on the live network!)
// (you will need to restart the `yarn run start` dev server after editing the .env)
networks: {
hardhat: {
allowUnlimitedContractSize: true,
// forking: {
// url:
// `https://eth-mainnet.g.alchemy.com/v2/${process.env.ALCHEMY_API}`,
// blockNumber: 15917401
// },
},
localhost: {
url: "http://localhost:8545",
/*
notice no mnemonic here? it will just use account 0 of the buidler node to deploy
(you can put in a mnemonic here to set the deployer locally)
*/
},
// ETH Network
sepolia: {
url: `https://sepolia.infura.io/v3/${process.env.INFURA_PROJECT_ID}`,
accounts: [process.env.PRIVATE]
},
mainnet: {
url: `https://mainnet.infura.io/v3/${process.env.INFURA_PROJECT_ID}`, // <---- YOUR INFURA ID! (or it won't work)
aaccounts: {
mnemonic: mnemonic(),
},
},
// Polygon Chain
polygonMumbai: {
url: `https://rpc-mumbai.maticvigil.com/`, // <---- YOUR INFURA ID! (or it won't work)
accounts: [process.env.PRIVATE]
},
polygon: {
url: `https://polygon-rpc.com/`, // <---- YOUR INFURA ID! (or it won't work)
accounts: [process.env.PRIVATE]
},
polygonAmoy: {
url: `https://rpc-amoy.polygon.technology/`, // <---- YOUR INFURA ID! (or it won't work)
accounts:[process.env.PRIVATE],
},
// BSC Chain
bscTestnet: {
url: "https://data-seed-prebsc-1-s1.binance.org:8545/",
accounts: {
mnemonic: mnemonic(),
}
},
bscMainnet: {
url: "https://bsc-dataseed1.binance.org/",
accounts: [process.env.PRIVATE]
},
// Polygon zkEVM Chain
polygonZkEVMTestnet: {
url: "https://rpc.cardona.zkevm-rpc.com/",
accounts: [process.env.PRIVATE]
},
zkEVMMainnet: {
url: "https://zkevm-rpc.com ",
accounts: [process.env.PRIVATE]
},
// Optimisim Chain
optimismSepolia: {
url: "https://sepolia.optimism.io",
accounts: [process.env.PRIVATE]
},
optimismMainnet: {
url: "https://mainnet.optimism.io",
accounts: [process.env.PRIVATE]
},
// Arbitrum Chain
arbitrumSepolia: {
url: "https://arbitrum-sepolia.blockpi.network/v1/rpc/public",
accounts: [process.env.PRIVATE]
},
arbitrumMainnet : {
url: 'https://arb1.arbitrum.io/rpc',
accounts: [process.env.PRIVATE]
},
// Linea Chain
lineaSepolia: {
url: `https://rpc.sepolia.linea.build`,
accounts: [process.env.PRIVATE]
},
lineaMainnet: {
url: `https://rpc.linea.build`,
accounts: [process.env.PRIVATE]
},
//Fuse Mainnet
fuse:{
url:"https://rpc.fuse.io",
accounts: [process.env.PRIVATE],
},
//Fuse Testnet
fuseSpark:{
url:"https://rpc.fusespark.io",
accounts: [process.env.PRIVATE],
},
//Shardeum Testnet
sphinx:{
url: "https://sphinx.shardeum.org/",
chainId: 8082,
accounts:[process.env.PRIVATE]
},
//Bera Chain testnet
berachainTestnet: {
url: "https://artio.rpc.berachain.com/",
chainId: 80085,
accounts: [process.env.PRIVATE],
},
//OKX testnet X1
X1: {
url: "https://testrpc.x1.tech",
accounts:[process.env.PRIVATE]
},
// Cyber Chain
cyberTestnet: {
url: "https://cyber-testnet.alt.technology/",
accounts:[process.env.PRIVATE]
},
cyberMainnet: {
url: "https://cyber.alt.technology/",
chainId: 7560,
accounts:[process.env.PRIVATE]
},
//Base Chain
baseMainnet: {
url: 'https://mainnet.base.org',
accounts: [process.env.PRIVATE],
},
baseSepolia: {
url: 'https://sepolia.base.org',
accounts: [process.env.PRIVATE],
}
},
etherscan: {
apiKey: {
lineaSepolia: process.env.ETHERSCAN_API,
mainnet: process.env.ETHERSCAN_API,
polygon: process.env.POLYGONSCAN_API,
sepolia:process.env.ETHERSCAN_API,
bscTestnet: process.env.BNBSCAN_API,
fuse: process.env.FUSE_API,
fuseSpark: process.env.FUSE_API,
arbitrumSepolia:process.env.ARBISCAN_API,
arbitrumOne: process.env.ARBISCAN_API,
optimismSepolia :process.env.OPTIMISM_API,
polygonZkEVMTestnet: process.env.POLYGONzkEVMSCAN_API,
berachainTestnet: "apiNotRequired",
polygonAmoy:"OKLINK",
X1: "Not required",
cyber_testnet: "Not Required",
cyber:"Not Required",
"base-sepolia": "PLACEHOLDER_STRING"
},
customChains: [
{
network: "lineaSepolia",
chainId: 59141,
urls: {
apiURL: "https://explorer.sepolia.linea.build/api",
browserURL: "https://sepolia.lineascan.build/",
},
},
{
network: "lineaMainnet",
chainId: 59144,
urls: {
apiURL: "https://api.lineascan.build/api",
browserURL: "https://lineascan.build/",
},
},
{
network: "fuse",
chainId: 122,
urls:{
apiURL: "https://explorer.fuse.io/api",
browserURL: "https://explorer.fuse.io/",
}
},
{
network: "fuseSpark",
chainId: 123,
urls:{
apiURL: "https://explorer.fusespark.io/api",
browserURL: "https://explorer.fusespark.io/",
},
},
{
network: "berachainTestnet",
chainId: 80085,
urls: {
apiURL:
"https://api.routescan.io/v2/network/testnet/evm/80085/etherscan/api/",
browserURL: "https://artio.beratrail.io/",
},
},
{
network: "arbitrumSepolia",
chainId: 421614,
urls: {
apiURL:
"https://api-sepolia.arbiscan.io/api",
browserURL: "https://sepolia.arbiscan.io//",
},
},
{
network: "optimismSepolia",
chainId: 11155420,
urls: {
apiURL:
"https://api-sepolia-optimistic.etherscan.io/api",
browserURL: "https://sepolia-optimistic.etherscan.io/",
},
},
{
network: "polygonAmoy",
chainId: 80002,
urls: {
apiURL: "https://www.oklink.com/api/explorer/v1/contract/verify/async/api/polygon_amoy",
browserURL: "https://www.oklink.com/amoy"
}
},
{
network: "X1",
chainId: 195,
urls: {
apiURL: "https://www.oklink.com/api/explorer/v1/contract/verify/async/api/x1_test",
browserURL: "https://www.oklink.com/x1-test"
}
},
{
network: "polygonZkEVMTestnet",
chainId: 2442,
urls: {
apiURL: "https://api-zkevm.polygonscan.com/api",
browserURL: "https://cardona-zkevm.polygonscan.com/"
}
},
{
network: "cyber_testnet",
chainId: 111557560,
urls: {
apiURL: "https://testnet.cyberscan.co/api",
browserURL: "https://testnet.cyberscan.co"
}
},
{
network: "base-sepolia",
chainId: 84532,
urls: {
apiURL: "https://api-sepolia.basescan.org/api",
browserURL: "https://sepolia.basescan.org"
}
},
{
network: "cyber",
chainId: 7560,
urls: {
apiURL: "https://cyberscan.co/api",
browserURL: "https://cyberscan.co"
}
}
],
},
solidity: {
version: "0.6.11",
settings: {
optimizer: {
enabled: true,
runs: 99999,
},
},
},
};
// ENABLE / DISABLE DEBUG
const DEBUG = true;
function debug(text) {
if (DEBUG) {
console.log(text);
}
}
// To Generate mnemonic
function mnemonic() {
try {
return fs.readFileSync("./wallets/main_mnemonic.txt").toString().trim();
} catch (e) {
if (defaultNetwork !== "localhost") {
console.log(
"β’οΈ WARNING: No mnemonic file created for a deploy account. Try `npx hardhat generate` and then `npx hardhat account`."
);
}
}
return "";
}
function getPrivateKey() {
try {
const key = fs.readFileSync("./wallets/main_privateKey.txt").toString().trim();
return [key];
} catch (e) {
if (defaultNetwork !== "localhost") {
console.log(
"β’οΈ WARNING: No mnemonic / private key file created for a deploy account. Try `npx hardhat generate` and then `npx hardhat account`."
);
}
}
return "";
}
task(
"generate",
"Create a mnemonic for builder deploys",
async (_, { ethers }) => {
const generate = async (isSecondary) => {
const bip39 = require("bip39");
const { hdkey } = require('ethereumjs-wallet')
const mnemonic = bip39.generateMnemonic();
const seed = await bip39.mnemonicToSeed(mnemonic);
const hdwallet = hdkey.fromMasterSeed(seed);
const wallet_hdpath = "m/44'/60'/0'/0/";
const account_index = 0;
const fullPath = wallet_hdpath + account_index;
const wallet = hdwallet.derivePath(fullPath).getWallet();
const privateKey = "0x" + wallet.privateKey.toString("hex");
if (DEBUG) console.log(chalk.bgGreen.bold.black(`\n\t\t\t`))
if (DEBUG) console.log(chalk.bgBlack.bold.white(` π° Wallet - ${isSecondary ? "alt_wallet" : "main_wallet"} | ${privateKey} `))
if (DEBUG) console.log(chalk.bgGreen.bold.black(`\t\t\t\n`))
if (DEBUG) console.log("mnemonic", mnemonic);
if (DEBUG) console.log("seed", seed);
if (DEBUG) console.log("fullPath", fullPath);
if (DEBUG) console.log("privateKey", privateKey);
const EthUtil = require("ethereumjs-util");
const address = "0x" + EthUtil.privateToAddress(wallet.privateKey).toString("hex");
console.log(
"π Account Generated as " +
address +
".txt and set as mnemonic in packages/buidler"
);
console.log(
"π¬ Use 'npx hardhat account' to get more information about the deployment account."
);
if (isSecondary) {
fs.writeFileSync("./wallets/alt_" + address + ".txt", mnemonic.toString() + "\n" + privateKey);
fs.writeFileSync("./wallets/alt_mnemonic.txt", mnemonic.toString());
fs.writeFileSync("./wallets/alt_private.txt", privateKey.toString());
}
else {
fs.writeFileSync("./wallets/main_" + address + ".txt", mnemonic.toString() + "\n" + privateKey);
fs.writeFileSync("./wallets/main_mnemonic.txt", mnemonic.toString());
fs.writeFileSync("./wallets/main_privatekey.txt", privateKey.toString());
}
if (DEBUG) console.log("\n------\n");
}
await generate()
await generate(true)
}
);
task(
"account",
"Get balance informations for the deployment account.",
async (_, { ethers }) => {
const showAccount = async (walletName) => {
const { hdkey } = require('ethereumjs-wallet')
const bip39 = require("bip39");
const mnemonic = fs.readFileSync(`./wallets/${walletName}_mnemonic.txt`).toString().trim();
const seed = await bip39.mnemonicToSeed(mnemonic);
const hdwallet = hdkey.fromMasterSeed(seed);
const wallet_hdpath = "m/44'/60'/0'/0/";
const account_index = 0;
const fullPath = wallet_hdpath + account_index;
const wallet = hdwallet.derivePath(fullPath).getWallet();
const privateKey = "0x" + wallet.privateKey.toString("hex");
const EthUtil = require("ethereumjs-util");
const address =
"0x" + EthUtil.privateToAddress(wallet.privateKey).toString("hex");
if (DEBUG) console.log(chalk.bgGreen.bold.black(`\n\t\t\t`))
if (DEBUG) console.log(chalk.bgBlack.bold.white(` π° Wallet - ${walletName} | ${privateKey} `))
if (DEBUG) console.log(chalk.bgGreen.bold.black(`\t\t\t\n`))
if (DEBUG) console.log("mnemonic", mnemonic);
if (DEBUG) console.log("seed", seed);
if (DEBUG) console.log("fullPath", fullPath);
if (DEBUG) console.log("privateKey", privateKey);
if (DEBUG) console.log("βπ¬ Deployer Account is " + address);
const qrcode = require("qrcode-terminal");
qrcode.generate(address);
for (const n in config.networks) {
// console.log(config.networks[n],n)
try {
const provider = new ethers.providers.JsonRpcProvider(
config.networks[n].url
);
const balance = await provider.getBalance(address);
console.log(" -- " + n + " -- -- -- π‘ ");
console.log(" balance: " + ethers.utils.formatEther(balance));
console.log(
// eslint-disable-next-line no-await-in-loop
" nonce: " + (await provider.getTransactionCount(address))
);
} catch (e) {
if (DEBUG) {
console.log(e);
}
}
}
if (DEBUG) console.log("\n------\n");
}
await showAccount("main")
await showAccount("alt")
}
);
async function addr(ethers, addr) {
if (isAddress(addr)) {
return getAddress(addr);
}
const accounts = await ethers.provider.listAccounts();
if (accounts[addr] !== undefined) {
return accounts[addr];
}
throw `Could not normalize address: ${addr}`;
}
task("accounts", "Prints the list of accounts", async (_, { ethers }) => {
const accounts = await ethers.provider.listAccounts();
accounts.forEach((account) => console.log(account));
});
task("blockNumber", "Prints the block number", async (_, { ethers }) => {
const blockNumber = await ethers.provider.getBlockNumber();
console.log(blockNumber);
});
task("balance", "Prints an account's balance")
.addPositionalParam("account", "The account's address")
.setAction(async (taskArgs, { ethers }) => {
const balance = await ethers.provider.getBalance(
await addr(ethers, taskArgs.account)
);
console.log(formatUnits(balance, "ether"), "ETH");
}
);
function send(signer, txparams) {
return signer.sendTransaction(txparams, (error, transactionHash) => {
if (error) {
debug(`Error: ${error}`);
}
debug(`transactionHash: ${transactionHash}`);
// checkForReceipt(2, params, transactionHash, resolve)
});
}
task("send", "Send ETH")
.addParam("from", "From address or account index")
.addOptionalParam("to", "To address or account index")
.addOptionalParam("amount", "Amount to send in ether")
.addOptionalParam("data", "Data included in transaction")
.addOptionalParam("gasPrice", "Price you are willing to pay in gwei")
.addOptionalParam("gasLimit", "Limit of how much gas to spend")
.setAction(async (taskArgs, { network, ethers }) => {
const from = await addr(ethers, taskArgs.from);
debug(`Normalized from address: ${from}`);
const fromSigner = await ethers.provider.getSigner(from);
let to;
if (taskArgs.to) {
to = await addr(ethers, taskArgs.to);
debug(`Normalized to address: ${to}`);
}
const txRequest = {
from: await fromSigner.getAddress(),
to,
value: parseUnits(
taskArgs.amount ? taskArgs.amount : "0",
"ether"
).toHexString(),
nonce: await fromSigner.getTransactionCount(),
gasPrice: parseUnits(
taskArgs.gasPrice ? taskArgs.gasPrice : "1.001",
"gwei"
).toHexString(),
gasLimit: taskArgs.gasLimit ? taskArgs.gasLimit : 24000,
chainId: network.config.chainId,
};
if (taskArgs.data !== undefined) {
txRequest.data = taskArgs.data;
debug(`Adding data to payload: ${txRequest.data}`);
}
debug(txRequest.gasPrice / 1000000000 + " gwei");
debug(JSON.stringify(txRequest, null, 2));
return send(fromSigner, txRequest);
}
);