-
Notifications
You must be signed in to change notification settings - Fork 0
/
hardhat.config.ts
454 lines (400 loc) · 15 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
445
446
447
448
449
450
451
452
453
454
import '@nomiclabs/hardhat-waffle';
import '@nomiclabs/hardhat-etherscan';
import '@typechain/hardhat';
import "dotenv/config"
import * as fs from 'fs';
import "hardhat-contract-sizer"
import "hardhat-gas-reporter"
import { HardhatUserConfig } from 'hardhat/config';
import 'solidity-coverage';
const mnemonic = fs.existsSync('.secret')
? fs
.readFileSync('.secret')
.toString()
.trim()
: 'test test test test test test test test test test test junk';
const infuraKey = process.env.INFURA_KEY;
const etherscanKey = process.env.ETHERSCAN_KEY;
// You need to export an object to set up your config
// Go to https://hardhat.org/config/ to learn more
export default {
networks: {
hardhat: {
forking: {
enabled: process.env.FORK === 'true',
url: `https://eth-mainnet.alchemyapi.io/v2/SR-wBhpxMirgFtp4OGeJoWKO1ObmVeFg`,
},
initialBaseFeePerGas: 0 // workaround for eip-1559 (solidity-coverage)
},
ropsten: {
url: `https://ropsten.infura.io/v3/${infuraKey}`,
accounts: {
mnemonic
}
},
kovan: {
url: `https://kovan.infura.io/v3/${infuraKey}`,
accounts: {
mnemonic
}
}
},
solidity: {
settings: {
optimizer: {
enabled: true,
runs: 200
},
},
version: '0.7.6',
},
typechain: {
outDir: 'typechain',
target: 'ethers-v5'
},
contractSizer: {
alphaSort: true,
runOnCompile: process.env.COVERAGE ? false: true,
disambiguatePaths: false,
},
gasReporter: {
currency: 'USD',
gasPrice: 43,
enabled: true,
},
etherscan: {
apiKey: etherscanKey
},
mocha: {
timeout: 40000
}
} as HardhatUserConfig;
// const { utils } = require("ethers");
// const fs = require("fs");
// const chalk = require("chalk");
// require("@nomiclabs/hardhat-waffle");
// require("@tenderly/hardhat-tenderly")
// require("@nomiclabs/hardhat-etherscan");
// require("@typechain/hardhat")
// const { isAddress, getAddress, formatUnits, parseUnits } = utils;
// /*
// 📡 This is where you configure your deploy configuration for 🏗 scaffold-eth
// check out `packages/scripts/deploy.js` to customize your deployment
// out of the box it will auto deploy anything in the `contracts` folder and named *.sol
// plus it will use *.args for constructor args
// */
// //
// // Select the network you want to deploy to here:
// //
// const defaultNetwork = "localhost";
// 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 = {
// typechain: {
// outDir: 'typechain',
// target: 'ethers-v5',
// },
// defaultNetwork,
// networks: {
// localhost: {
// url: "http://localhost:8545",
// /*
// notice no mnemonic here? it will just use account 0 of the hardhat node to deploy
// (you can put in a mnemonic here to set the deployer locally)
// */
// },
// rinkeby: {
// url: "https://rinkeby.infura.io/v3/460f40a260564ac4a4f4b3fffb032dad", //<---- YOUR INFURA ID! (or it won't work)
// accounts: {
// mnemonic: mnemonic(),
// },
// },
// kovan: {
// url: "https://kovan.infura.io/v3/460f40a260564ac4a4f4b3fffb032dad", //<---- YOUR INFURA ID! (or it won't work)
// accounts: {
// mnemonic: mnemonic(),
// },
// },
// mainnet: {
// url: "https://mainnet.infura.io/v3/460f40a260564ac4a4f4b3fffb032dad", //<---- YOUR INFURA ID! (or it won't work)
// accounts: {
// mnemonic: mnemonic(),
// },
// },
// ropsten: {
// url: "https://ropsten.infura.io/v3/460f40a260564ac4a4f4b3fffb032dad", //<---- YOUR INFURA ID! (or it won't work)
// accounts: {
// mnemonic: mnemonic(),
// },
// },
// goerli: {
// url: "https://goerli.infura.io/v3/460f40a260564ac4a4f4b3fffb032dad", //<---- YOUR INFURA ID! (or it won't work)
// accounts: {
// mnemonic: mnemonic(),
// },
// },
// xdai: {
// url: 'https://rpc.xdaichain.com/',
// gasPrice: 1000000000,
// accounts: {
// mnemonic: mnemonic(),
// },
// },
// matic: {
// url: 'https://rpc-mainnet.maticvigil.com/',
// gasPrice: 1000000000,
// accounts: {
// mnemonic: mnemonic(),
// },
// },
// },
// solidity: {
// compilers: [
// {
// version: "0.7.6",
// settings: {
// optimizer: {
// enabled: true,
// runs: 200
// }
// }
// },
// {
// version: "0.6.7",
// settings: {
// optimizer: {
// enabled: true,
// runs: 200
// }
// }
// }
// ],
// },
// etherscan: {
// apiKey: "PSW8C433Q667DVEX5BCRMGNAH9FSGFZ7Q8"
// }
// };
// const DEBUG = false;
// function debug(text) {
// if (DEBUG) {
// console.log(text);
// }
// }
// task("wallet", "Create a wallet (pk) link", async (_, { ethers }) => {
// const randomWallet = ethers.Wallet.createRandom()
// const privateKey = randomWallet._signingKey().privateKey
// console.log("🔐 WALLET Generated as " + randomWallet.address + "")
// console.log("🔗 http://localhost:3000/pk#"+privateKey)
// });
// task("fundedwallet", "Create a wallet (pk) link and fund it with deployer?")
// .addOptionalParam("amount", "Amount of ETH to send to wallet after generating")
// .addOptionalParam("url", "URL to add pk to")
// .setAction(async (taskArgs, { network, ethers }) => {
// const randomWallet = ethers.Wallet.createRandom()
// const privateKey = randomWallet._signingKey().privateKey
// console.log("🔐 WALLET Generated as " + randomWallet.address + "")
// let url = taskArgs.url?taskArgs.url:"http://localhost:3000"
// let localDeployerMnemonic
// try{
// localDeployerMnemonic = fs.readFileSync("./mnemonic.txt")
// localDeployerMnemonic = localDeployerMnemonic.toString().trim()
// } catch (e) {
// /* do nothing - this file isn't always there */
// }
// let amount = taskArgs.amount?taskArgs.amount:"0.01"
// const tx = {
// to: randomWallet.address,
// value: ethers.utils.parseEther(amount)
// };
// //SEND USING LOCAL DEPLOYER MNEMONIC IF THERE IS ONE
// // IF NOT SEND USING LOCAL HARDHAT NODE:
// if(localDeployerMnemonic){
// let deployerWallet = new ethers.Wallet.fromMnemonic(localDeployerMnemonic)
// deployerWallet = deployerWallet.connect(ethers.provider)
// console.log("💵 Sending "+amount+" ETH to "+randomWallet.address+" using deployer account");
// let sendresult = await deployerWallet.sendTransaction(tx)
// console.log("\n"+url+"/pk#"+privateKey+"\n")
// return
// }else{
// console.log("💵 Sending "+amount+" ETH to "+randomWallet.address+" using local node");
// console.log("\n"+url+"/pk#"+privateKey+"\n")
// return send(ethers.provider.getSigner(), tx);
// }
// });
// task("generate", "Create a mnemonic for builder deploys", async (_, { ethers }) => {
// const bip39 = require("bip39")
// const hdkey = require('ethereumjs-wallet/hdkey');
// const mnemonic = bip39.generateMnemonic()
// if (DEBUG) console.log("mnemonic", mnemonic)
// const seed = await bip39.mnemonicToSeed(mnemonic)
// if (DEBUG) console.log("seed", seed)
// const hdwallet = hdkey.fromMasterSeed(seed);
// const wallet_hdpath = "m/44'/60'/0'/0/";
// const account_index = 0
// let fullPath = wallet_hdpath + account_index
// if (DEBUG) console.log("fullPath", fullPath)
// const wallet = hdwallet.derivePath(fullPath).getWallet();
// const privateKey = "0x" + wallet._privKey.toString('hex');
// if (DEBUG) console.log("privateKey", privateKey)
// var EthUtil = require('ethereumjs-util');
// const address = "0x" + EthUtil.privateToAddress(wallet._privKey).toString('hex')
// console.log("🔐 Account Generated as " + address + " and set as mnemonic in packages/hardhat")
// console.log("💬 Use 'yarn run account' to get more information about the deployment account.")
// fs.writeFileSync("./" + address + ".txt", mnemonic.toString())
// fs.writeFileSync("./mnemonic.txt", mnemonic.toString())
// });
// task("mineContractAddress", "Looks for a deployer account that will give leading zeros")
// .addParam("searchFor", "String to search for")
// .setAction(async (taskArgs, { network, ethers }) => {
// let contract_address = ""
// let address;
// const bip39 = require("bip39")
// const hdkey = require('ethereumjs-wallet/hdkey');
// let mnemonic = ""
// while(contract_address.indexOf(taskArgs.searchFor)!=0){
// mnemonic = bip39.generateMnemonic()
// if (DEBUG) console.log("mnemonic", mnemonic)
// const seed = await bip39.mnemonicToSeed(mnemonic)
// if (DEBUG) console.log("seed", seed)
// const hdwallet = hdkey.fromMasterSeed(seed);
// const wallet_hdpath = "m/44'/60'/0'/0/";
// const account_index = 0
// let fullPath = wallet_hdpath + account_index
// if (DEBUG) console.log("fullPath", fullPath)
// const wallet = hdwallet.derivePath(fullPath).getWallet();
// const privateKey = "0x" + wallet._privKey.toString('hex');
// if (DEBUG) console.log("privateKey", privateKey)
// var EthUtil = require('ethereumjs-util');
// address = "0x" + EthUtil.privateToAddress(wallet._privKey).toString('hex')
// const rlp = require('rlp');
// const keccak = require('keccak');
// let nonce = 0x00; //The nonce must be a hex literal!
// let sender = address;
// let input_arr = [ sender, nonce ];
// let rlp_encoded = rlp.encode(input_arr);
// let contract_address_long = keccak('keccak256').update(rlp_encoded).digest('hex');
// contract_address = contract_address_long.substring(24); //Trim the first 24 characters.
// }
// console.log("⛏ Account Mined as " + address + " and set as mnemonic in packages/hardhat")
// console.log("📜 This will create the first contract: "+chalk.magenta("0x"+contract_address));
// console.log("💬 Use 'yarn run account' to get more information about the deployment account.")
// fs.writeFileSync("./" + address + "_produces"+contract_address+".txt", mnemonic.toString())
// fs.writeFileSync("./mnemonic.txt", mnemonic.toString())
// });
// task("account", "Get balance informations for the deployment account.", async (_, { ethers }) => {
// const hdkey = require('ethereumjs-wallet/hdkey');
// const bip39 = require("bip39")
// let mnemonic = fs.readFileSync("./mnemonic.txt").toString().trim()
// if (DEBUG) console.log("mnemonic", mnemonic)
// const seed = await bip39.mnemonicToSeed(mnemonic)
// if (DEBUG) console.log("seed", seed)
// const hdwallet = hdkey.fromMasterSeed(seed);
// const wallet_hdpath = "m/44'/60'/0'/0/";
// const account_index = 0
// let fullPath = wallet_hdpath + account_index
// if (DEBUG) console.log("fullPath", fullPath)
// const wallet = hdwallet.derivePath(fullPath).getWallet();
// const privateKey = "0x" + wallet._privKey.toString('hex');
// if (DEBUG) console.log("privateKey", privateKey)
// var EthUtil = require('ethereumjs-util');
// const address = "0x" + EthUtil.privateToAddress(wallet._privKey).toString('hex')
// var qrcode = require('qrcode-terminal');
// qrcode.generate(address);
// console.log("📬 Deployer Account is " + address)
// for (let n in config.networks) {
// //console.log(config.networks[n],n)
// try {
// let provider = new ethers.providers.JsonRpcProvider(config.networks[n].url)
// let balance = (await provider.getBalance(address))
// console.log(" -- " + n + " -- -- -- 📡 ")
// console.log(" balance: " + ethers.utils.formatEther(balance))
// console.log(" nonce: " + (await provider.getTransactionCount(address)))
// } catch (e) {
// if (DEBUG) {
// console.log(e)
// }
// }
// }
// });
// 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);
// });