-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhardhat.config.ts
More file actions
209 lines (192 loc) · 7.69 KB
/
hardhat.config.ts
File metadata and controls
209 lines (192 loc) · 7.69 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
/* eslint @typescript-eslint/no-non-null-assertion: ["off"] */
import { HardhatUserConfig, subtask } from "hardhat/config";
import type { MultiSolcUserConfig } from "hardhat/src/types/config";
import { TASK_COMPILE_SOLIDITY_GET_SOURCE_PATHS } from "hardhat/builtin-tasks/task-names";
/* Uncomment if support of TypeScript `paths` mappings is needed.
* Make sure to run `pnpm add -D "tsconfig-paths@4.2.0"` in this case.
*/
// import "tsconfig-paths/register";
import "@nomicfoundation/hardhat-toolbox";
import "@nomicfoundation/hardhat-foundry";
/* `hardhat-tracer` traces events, calls and storage operations as tests progress.
* However, it slows down test execution even when not in use. It can be commented out if it is not needed.
*/
import "hardhat-tracer";
import "solidity-docgen"; // The tool by OpenZeppelin to generate documentation for contracts in Markdown.
import "hardhat-contract-sizer";
import "hardhat-abi-exporter";
import "hardhat-exposed";
import "@openzeppelin/hardhat-upgrades";
import dotenv from "dotenv";
dotenv.config();
import "./scripts/tasks/generate-account";
/* Sets the action for the `TASK_COMPILE_SOLIDITY_GET_SOURCE_PATHS` task.
*
* The approach to ignore Solidity files in `test` directories for Hardhat speeds up its compilation process
* significantly. This is especially true in large projects with a lot of Foundry tests.
* It can be also extended for deployment scripts as well.
* See for more details:
* `https://kennysliding.medium.com/how-to-ignore-solidity-files-in-hardhat-compilation-6162963f8c84`
*/
subtask(TASK_COMPILE_SOLIDITY_GET_SOURCE_PATHS).setAction(async (_, __, runSuper) => {
/* Get the list of source paths that would normally be passed to the Solidity compiler, then
* apply a filter function to exclude paths that contain the string "test".
*/
// eslint-disable-next-line @typescript-eslint/no-unsafe-return, @typescript-eslint/no-unsafe-call, @typescript-eslint/no-unsafe-member-access, @typescript-eslint/no-explicit-any
return (await runSuper()).filter((p: any) => !p.includes("test"));
});
const envs = process.env;
// Private keys can be set in `.env` file.
const ethereumMainnetKeys = envs.ETHEREUM_MAINNET_KEYS?.split(",") ?? [];
const ethereumTestnetKeys = envs.ETHEREUM_TESTNET_KEYS?.split(",") ?? [];
const isOptionTrue = (option: string | undefined) => ["true", "1"].includes(option ?? "");
/* The solc compiler optimizer is disabled by default to keep the Hardhat stack traces' line numbers the same.
* To enable, set `RUN_OPTIMIZER` to `true` in the `.env` file.
*/
const optimizerRuns = isOptionTrue(envs.RUN_OPTIMIZER) || isOptionTrue(envs.REPORT_GAS);
const optimizerRunNum = envs.OPTIMIZER_RUN_NUM ? +envs.OPTIMIZER_RUN_NUM : 200;
const viaIR = envs.VIA_IR ? isOptionTrue(envs.VIA_IR) : true;
const enableForking = isOptionTrue(envs.FORKING);
const mochaSerial = isOptionTrue(envs.SERIAL);
const mochaBail = isOptionTrue(envs.BAIL);
const enableSourcify = envs.SOURCIFY ? true : envs.ETHERSCAN_API_KEY ? false : true;
const abiExporterExceptions = ["interfaces/", "mocks/", "vendor/", "contracts-exposed/"];
const config: HardhatUserConfig = {
solidity: {
compilers: [
{
version: "0.8.30",
settings: {
viaIR: viaIR,
optimizer: {
enabled: optimizerRuns,
runs: optimizerRunNum,
details: {
yulDetails: {
optimizerSteps: optimizerRuns ? "u" : undefined
}
}
}
}
}
// { version: "0.7.6" }
]
// overrides: { "contracts/Deployed.sol": { version: "0.8.21" } }
},
// defaultNetwork: "hardhat",
networks: {
hardhat: {
allowUnlimitedContractSize: !optimizerRuns,
accounts: {
accountsBalance: envs.ACCOUNT_BALANCE ?? "10000000000000000000000", // 10000 ETH.
count: envs.NUMBER_OF_ACCOUNTS ? +envs.NUMBER_OF_ACCOUNTS : 20
},
forking: {
url: envs.FORKING_URL ?? "",
enabled: enableForking
}
// Uncomment if "Error: cannot estimate gas; transaction may fail or may require manual gas limit...".
// gas: 3E7,
// gasPrice: 8E9
},
// Ethereum:
ethereum: {
chainId: 1,
url: envs.ETHEREUM_URL ?? "",
accounts: [...ethereumMainnetKeys]
},
sepolia: {
chainId: 11155111,
url: envs.SEPOLIA_URL ?? "",
accounts: [...ethereumTestnetKeys]
},
holesky: {
chainId: 17000,
url: envs.HOLESKY_URL ?? "",
accounts: [...ethereumTestnetKeys]
},
hoodi: {
chainId: 560048,
url: envs.HOODI_URL ?? "",
accounts: [...ethereumTestnetKeys]
}
},
etherscan: {
// To see supported networks and their identifiers for `apiKey`, run `pnpm hardhat verify --list-networks`.
apiKey: {
mainnet: envs.ETHERSCAN_API_KEY ?? "",
sepolia: envs.ETHERSCAN_API_KEY ?? "",
holesky: envs.ETHERSCAN_API_KEY ?? ""
// hoodi: envs.ETHERSCAN_API_KEY ?? ""
}
},
sourcify: {
enabled: enableSourcify
},
gasReporter: {
enabled: envs.REPORT_GAS !== undefined,
excludeContracts: ["vendor/"],
// currency: "USD", // "CHF", "EUR", etc.
darkMode: true,
showMethodSig: true,
L1Etherscan: envs.ETHERSCAN_API_KEY
// trackGasDeltas: true // Track and report changes in gas usage between test runs.
},
mocha: {
timeout: 100000,
parallel: !mochaSerial,
bail: mochaBail
},
docgen: {
pages: "files",
exclude: ["mocks/", "vendor/", "contracts-exposed/", "test/"]
},
contractSizer: {
except: ["mocks/", "vendor/", "contracts-exposed/", "test/"]
},
abiExporter: [
{
path: "./abi/json",
format: "json",
except: abiExporterExceptions,
spacing: 4
},
{
path: "./abi/minimal",
format: "minimal",
except: abiExporterExceptions,
spacing: 4
},
{
path: "./abi/full",
format: "fullName",
except: abiExporterExceptions,
spacing: 4
}
],
exposed: {
imports: true,
initializers: true,
exclude: ["vendor/**/*"]
}
};
if (envs.EVM_VERSION !== "default")
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
(config.solidity! as MultiSolcUserConfig).compilers[0].settings!.evmVersion = envs.EVM_VERSION ?? "prague";
// By default fork from the latest block.
if (envs.FORKING_BLOCK_NUMBER) config.networks!.hardhat!.forking!.blockNumber = +envs.FORKING_BLOCK_NUMBER;
if (envs.HARDFORK !== "default") config.networks!.hardhat!.hardfork = envs.HARDFORK ?? "prague";
// Extra settings for `hardhat-gas-reporter`.
if (envs.COINMARKETCAP_API_KEY) config.gasReporter!.coinmarketcap = envs.COINMARKETCAP_API_KEY;
if (envs.REPORT_GAS_FILE_TYPE === "md") {
config.gasReporter!.outputFile = "gas-report.md";
config.gasReporter!.reportFormat = "markdown";
config.gasReporter!.forceTerminalOutput = true;
config.gasReporter!.forceTerminalOutputFormat = "terminal";
}
if (envs.REPORT_GAS_FILE_TYPE === "json") {
config.gasReporter!.outputJSON = true;
config.gasReporter!.outputJSONFile = "gas-report.json";
config.gasReporter!.includeBytecodeInJSON = true;
}
export default config;