hardhat 2.6.6 → 2.8.0-dev.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +39 -0
- package/builtin-tasks/compile.js +9 -0
- package/builtin-tasks/compile.js.map +1 -1
- package/builtin-tasks/node.js +26 -9
- package/builtin-tasks/node.js.map +1 -1
- package/internal/artifacts.d.ts +49 -0
- package/internal/artifacts.d.ts.map +1 -1
- package/internal/artifacts.js +191 -55
- package/internal/artifacts.js.map +1 -1
- package/internal/cli/analytics.js +2 -2
- package/internal/cli/analytics.js.map +1 -1
- package/internal/cli/cli.js +1 -1
- package/internal/cli/cli.js.map +1 -1
- package/internal/constants.d.ts +2 -0
- package/internal/constants.d.ts.map +1 -1
- package/internal/constants.js +3 -1
- package/internal/constants.js.map +1 -1
- package/internal/core/config/config-loading.d.ts.map +1 -1
- package/internal/core/config/config-loading.js +16 -2
- package/internal/core/config/config-loading.js.map +1 -1
- package/internal/core/config/config-resolution.d.ts.map +1 -1
- package/internal/core/config/config-resolution.js +42 -4
- package/internal/core/config/config-resolution.js.map +1 -1
- package/internal/core/config/config-validation.d.ts +1 -0
- package/internal/core/config/config-validation.d.ts.map +1 -1
- package/internal/core/config/config-validation.js +126 -13
- package/internal/core/config/config-validation.js.map +1 -1
- package/internal/core/config/default-config.d.ts +1 -0
- package/internal/core/config/default-config.d.ts.map +1 -1
- package/internal/core/config/default-config.js +69 -4
- package/internal/core/config/default-config.js.map +1 -1
- package/internal/core/errors-list.d.ts +14 -0
- package/internal/core/errors-list.d.ts.map +1 -1
- package/internal/core/errors-list.js +21 -2
- package/internal/core/errors-list.js.map +1 -1
- package/internal/core/jsonrpc/types/output/log.d.ts +1 -0
- package/internal/core/jsonrpc/types/output/log.d.ts.map +1 -1
- package/internal/core/jsonrpc/types/output/log.js +1 -0
- package/internal/core/jsonrpc/types/output/log.js.map +1 -1
- package/internal/core/jsonrpc/types/output/receipt.d.ts +1 -0
- package/internal/core/jsonrpc/types/output/receipt.d.ts.map +1 -1
- package/internal/core/params/hardhat-params.js +2 -2
- package/internal/core/params/hardhat-params.js.map +1 -1
- package/internal/core/providers/accounts.d.ts.map +1 -1
- package/internal/core/providers/accounts.js +14 -0
- package/internal/core/providers/accounts.js.map +1 -1
- package/internal/core/providers/construction.d.ts.map +1 -1
- package/internal/core/providers/construction.js +4 -2
- package/internal/core/providers/construction.js.map +1 -1
- package/internal/core/providers/gas-providers.d.ts.map +1 -1
- package/internal/core/providers/gas-providers.js +1 -1
- package/internal/core/providers/gas-providers.js.map +1 -1
- package/internal/core/typescript-support.d.ts +1 -1
- package/internal/core/typescript-support.d.ts.map +1 -1
- package/internal/core/typescript-support.js +4 -1
- package/internal/core/typescript-support.js.map +1 -1
- package/internal/hardhat-network/jsonrpc/client.d.ts +2 -0
- package/internal/hardhat-network/jsonrpc/client.d.ts.map +1 -1
- package/internal/hardhat-network/provider/BlockchainData.d.ts +1 -1
- package/internal/hardhat-network/provider/TransactionQueue.d.ts +2 -1
- package/internal/hardhat-network/provider/TransactionQueue.d.ts.map +1 -1
- package/internal/hardhat-network/provider/TransactionQueue.js +16 -2
- package/internal/hardhat-network/provider/TransactionQueue.js.map +1 -1
- package/internal/hardhat-network/provider/fork/ForkBlockchain.d.ts.map +1 -1
- package/internal/hardhat-network/provider/fork/ForkBlockchain.js +1 -3
- package/internal/hardhat-network/provider/fork/ForkBlockchain.js.map +1 -1
- package/internal/hardhat-network/provider/modules/hardhat.d.ts +3 -0
- package/internal/hardhat-network/provider/modules/hardhat.d.ts.map +1 -1
- package/internal/hardhat-network/provider/modules/hardhat.js +16 -0
- package/internal/hardhat-network/provider/modules/hardhat.js.map +1 -1
- package/internal/hardhat-network/provider/modules/personal.d.ts +9 -0
- package/internal/hardhat-network/provider/modules/personal.d.ts.map +1 -0
- package/internal/hardhat-network/provider/modules/personal.js +31 -0
- package/internal/hardhat-network/provider/modules/personal.js.map +1 -0
- package/internal/hardhat-network/provider/node-types.d.ts +7 -1
- package/internal/hardhat-network/provider/node-types.d.ts.map +1 -1
- package/internal/hardhat-network/provider/node-types.js.map +1 -1
- package/internal/hardhat-network/provider/node.d.ts +11 -2
- package/internal/hardhat-network/provider/node.d.ts.map +1 -1
- package/internal/hardhat-network/provider/node.js +108 -31
- package/internal/hardhat-network/provider/node.js.map +1 -1
- package/internal/hardhat-network/provider/output.d.ts +1 -1
- package/internal/hardhat-network/provider/output.d.ts.map +1 -1
- package/internal/hardhat-network/provider/output.js +9 -6
- package/internal/hardhat-network/provider/output.js.map +1 -1
- package/internal/hardhat-network/provider/provider.d.ts +8 -3
- package/internal/hardhat-network/provider/provider.d.ts.map +1 -1
- package/internal/hardhat-network/provider/provider.js +14 -2
- package/internal/hardhat-network/provider/provider.js.map +1 -1
- package/internal/hardhat-network/stack-traces/error-inferrer.d.ts.map +1 -1
- package/internal/hardhat-network/stack-traces/error-inferrer.js +14 -0
- package/internal/hardhat-network/stack-traces/error-inferrer.js.map +1 -1
- package/internal/hardhat-network/stack-traces/solidityTracer.d.ts +1 -1
- package/internal/hardhat-network/stack-traces/solidityTracer.js +1 -1
- package/package.json +5 -5
- package/register.js +1 -1
- package/register.js.map +1 -1
- package/src/builtin-tasks/compile.ts +14 -0
- package/src/builtin-tasks/node.ts +41 -9
- package/src/internal/artifacts.ts +268 -71
- package/src/internal/cli/analytics.ts +1 -1
- package/src/internal/cli/cli.ts +1 -1
- package/src/internal/constants.ts +3 -0
- package/src/internal/core/config/config-loading.ts +24 -2
- package/src/internal/core/config/config-resolution.ts +61 -3
- package/src/internal/core/config/config-validation.ts +217 -15
- package/src/internal/core/config/default-config.ts +67 -2
- package/src/internal/core/errors-list.ts +21 -2
- package/src/internal/core/jsonrpc/types/output/log.ts +1 -0
- package/src/internal/core/params/hardhat-params.ts +2 -2
- package/src/internal/core/providers/accounts.ts +19 -0
- package/src/internal/core/providers/construction.ts +9 -2
- package/src/internal/core/providers/gas-providers.ts +1 -1
- package/src/internal/core/typescript-support.ts +5 -1
- package/src/internal/hardhat-network/provider/TransactionQueue.ts +31 -4
- package/src/internal/hardhat-network/provider/fork/ForkBlockchain.ts +1 -3
- package/src/internal/hardhat-network/provider/modules/hardhat.ts +23 -0
- package/src/internal/hardhat-network/provider/modules/personal.ts +39 -0
- package/src/internal/hardhat-network/provider/node-types.ts +8 -1
- package/src/internal/hardhat-network/provider/node.ts +164 -29
- package/src/internal/hardhat-network/provider/output.ts +9 -9
- package/src/internal/hardhat-network/provider/provider.ts +18 -1
- package/src/internal/hardhat-network/stack-traces/error-inferrer.ts +19 -0
- package/src/internal/hardhat-network/stack-traces/solidityTracer.ts +1 -1
- package/src/register.ts +1 -1
- package/src/types/config.ts +42 -0
- package/src/utils/contract-names.ts +112 -0
- package/src/utils/source-names.ts +1 -1
- package/types/config.d.ts +26 -0
- package/types/config.d.ts.map +1 -1
- package/utils/contract-names.d.ts +10 -0
- package/utils/contract-names.d.ts.map +1 -1
- package/utils/contract-names.js +92 -1
- package/utils/contract-names.js.map +1 -1
- package/utils/source-names.d.ts +1 -1
- package/utils/source-names.js +1 -1
|
@@ -6,10 +6,14 @@ import path from "path";
|
|
|
6
6
|
import {
|
|
7
7
|
HardhatConfig,
|
|
8
8
|
HardhatNetworkAccountsConfig,
|
|
9
|
+
HardhatNetworkChainConfig,
|
|
10
|
+
HardhatNetworkChainsConfig,
|
|
9
11
|
HardhatNetworkConfig,
|
|
10
12
|
HardhatNetworkForkingConfig,
|
|
11
13
|
HardhatNetworkMiningConfig,
|
|
12
14
|
HardhatNetworkMiningUserConfig,
|
|
15
|
+
HardhatNetworkMempoolConfig,
|
|
16
|
+
HardhatNetworkMempoolUserConfig,
|
|
13
17
|
HardhatNetworkUserConfig,
|
|
14
18
|
HardhatUserConfig,
|
|
15
19
|
HDAccountsUserConfig,
|
|
@@ -29,6 +33,7 @@ import {
|
|
|
29
33
|
SolidityUserConfig,
|
|
30
34
|
} from "../../../types";
|
|
31
35
|
import { HARDHAT_NETWORK_NAME } from "../../constants";
|
|
36
|
+
import { HardforkName } from "../../util/hardforks";
|
|
32
37
|
import { fromEntries } from "../../util/lang";
|
|
33
38
|
import { assertHardhatInvariant } from "../errors";
|
|
34
39
|
|
|
@@ -148,9 +153,11 @@ function resolveHardhatNetworkConfig(
|
|
|
148
153
|
}
|
|
149
154
|
: undefined;
|
|
150
155
|
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
156
|
+
if (forking !== undefined) {
|
|
157
|
+
const blockNumber = hardhatNetworkConfig?.forking?.blockNumber;
|
|
158
|
+
if (blockNumber !== undefined) {
|
|
159
|
+
forking.blockNumber = hardhatNetworkConfig?.forking?.blockNumber;
|
|
160
|
+
}
|
|
154
161
|
}
|
|
155
162
|
|
|
156
163
|
const mining = resolveMiningConfig(hardhatNetworkConfig.mining);
|
|
@@ -169,6 +176,30 @@ function resolveHardhatNetworkConfig(
|
|
|
169
176
|
const initialDate =
|
|
170
177
|
hardhatNetworkConfig.initialDate ?? new Date().toISOString();
|
|
171
178
|
|
|
179
|
+
const chains: HardhatNetworkChainsConfig = new Map(
|
|
180
|
+
defaultHardhatNetworkParams.chains
|
|
181
|
+
);
|
|
182
|
+
if (hardhatNetworkConfig.chains !== undefined) {
|
|
183
|
+
for (const [chainId, userChainConfig] of Object.entries(
|
|
184
|
+
hardhatNetworkConfig.chains
|
|
185
|
+
)) {
|
|
186
|
+
const chainConfig: HardhatNetworkChainConfig = {
|
|
187
|
+
hardforkHistory: new Map(),
|
|
188
|
+
};
|
|
189
|
+
if (userChainConfig.hardforkHistory !== undefined) {
|
|
190
|
+
for (const [name, block] of Object.entries(
|
|
191
|
+
userChainConfig.hardforkHistory
|
|
192
|
+
)) {
|
|
193
|
+
chainConfig.hardforkHistory.set(
|
|
194
|
+
name as HardforkName,
|
|
195
|
+
block as number
|
|
196
|
+
);
|
|
197
|
+
}
|
|
198
|
+
}
|
|
199
|
+
chains.set(parseInt(chainId, 10), chainConfig);
|
|
200
|
+
}
|
|
201
|
+
}
|
|
202
|
+
|
|
172
203
|
const config = {
|
|
173
204
|
...clonedDefaultHardhatNetworkParams,
|
|
174
205
|
...hardhatNetworkConfig,
|
|
@@ -179,6 +210,7 @@ function resolveHardhatNetworkConfig(
|
|
|
179
210
|
gas,
|
|
180
211
|
initialDate,
|
|
181
212
|
minGasPrice,
|
|
213
|
+
chains,
|
|
182
214
|
};
|
|
183
215
|
|
|
184
216
|
// We do it this way because ts gets lost otherwise
|
|
@@ -228,10 +260,12 @@ function resolveHttpNetworkConfig(
|
|
|
228
260
|
function resolveMiningConfig(
|
|
229
261
|
userConfig: HardhatNetworkMiningUserConfig | undefined
|
|
230
262
|
): HardhatNetworkMiningConfig {
|
|
263
|
+
const mempool = resolveMempoolConfig(userConfig?.mempool);
|
|
231
264
|
if (userConfig === undefined) {
|
|
232
265
|
return {
|
|
233
266
|
auto: true,
|
|
234
267
|
interval: 0,
|
|
268
|
+
mempool,
|
|
235
269
|
};
|
|
236
270
|
}
|
|
237
271
|
|
|
@@ -241,6 +275,7 @@ function resolveMiningConfig(
|
|
|
241
275
|
return {
|
|
242
276
|
auto: true,
|
|
243
277
|
interval: 0,
|
|
278
|
+
mempool,
|
|
244
279
|
};
|
|
245
280
|
}
|
|
246
281
|
|
|
@@ -248,6 +283,7 @@ function resolveMiningConfig(
|
|
|
248
283
|
return {
|
|
249
284
|
auto: false,
|
|
250
285
|
interval,
|
|
286
|
+
mempool,
|
|
251
287
|
};
|
|
252
288
|
}
|
|
253
289
|
|
|
@@ -255,6 +291,7 @@ function resolveMiningConfig(
|
|
|
255
291
|
return {
|
|
256
292
|
auto,
|
|
257
293
|
interval: 0,
|
|
294
|
+
mempool,
|
|
258
295
|
};
|
|
259
296
|
}
|
|
260
297
|
|
|
@@ -262,9 +299,30 @@ function resolveMiningConfig(
|
|
|
262
299
|
return {
|
|
263
300
|
auto: auto!,
|
|
264
301
|
interval: interval!,
|
|
302
|
+
mempool,
|
|
265
303
|
};
|
|
266
304
|
}
|
|
267
305
|
|
|
306
|
+
function resolveMempoolConfig(
|
|
307
|
+
userConfig: HardhatNetworkMempoolUserConfig | undefined
|
|
308
|
+
): HardhatNetworkMempoolConfig {
|
|
309
|
+
if (userConfig === undefined) {
|
|
310
|
+
return {
|
|
311
|
+
order: "priority",
|
|
312
|
+
};
|
|
313
|
+
}
|
|
314
|
+
|
|
315
|
+
if (userConfig.order === undefined) {
|
|
316
|
+
return {
|
|
317
|
+
order: "priority",
|
|
318
|
+
};
|
|
319
|
+
}
|
|
320
|
+
|
|
321
|
+
return {
|
|
322
|
+
order: userConfig.order,
|
|
323
|
+
} as HardhatNetworkMempoolConfig;
|
|
324
|
+
}
|
|
325
|
+
|
|
268
326
|
function resolveSolidityConfig(userConfig: HardhatUserConfig): SolidityConfig {
|
|
269
327
|
const userSolidityConfig = userConfig.solidity ?? DEFAULT_SOLC_VERSION;
|
|
270
328
|
|
|
@@ -3,6 +3,7 @@ import { Context, getFunctionName, ValidationError } from "io-ts/lib";
|
|
|
3
3
|
import { Reporter } from "io-ts/lib/Reporter";
|
|
4
4
|
|
|
5
5
|
import {
|
|
6
|
+
HARDHAT_MEMPOOL_SUPPORTED_ORDERS,
|
|
6
7
|
HARDHAT_NETWORK_NAME,
|
|
7
8
|
HARDHAT_NETWORK_SUPPORTED_HARDFORKS,
|
|
8
9
|
} from "../../constants";
|
|
@@ -11,6 +12,7 @@ import { fromEntries } from "../../util/lang";
|
|
|
11
12
|
import { HardhatError } from "../errors";
|
|
12
13
|
import { ERRORS } from "../errors-list";
|
|
13
14
|
import { hardforkGte, HardforkName } from "../../util/hardforks";
|
|
15
|
+
import { HardhatNetworkChainUserConfig } from "../../../types/config";
|
|
14
16
|
import { defaultHardhatNetworkParams } from "./default-config";
|
|
15
17
|
|
|
16
18
|
function stringify(v: any): string {
|
|
@@ -53,6 +55,59 @@ function getErrorMessage(path: string, value: any, expectedType: string) {
|
|
|
53
55
|
)} for ${path} - Expected a value of type ${expectedType}.`;
|
|
54
56
|
}
|
|
55
57
|
|
|
58
|
+
function getPrivateKeyError(index: number, network: string, message: string) {
|
|
59
|
+
return `Invalid account: #${index} for network: ${network} - ${message}`;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
function validatePrivateKey(
|
|
63
|
+
privateKey: unknown,
|
|
64
|
+
index: number,
|
|
65
|
+
network: string,
|
|
66
|
+
errors: string[]
|
|
67
|
+
) {
|
|
68
|
+
if (typeof privateKey !== "string") {
|
|
69
|
+
errors.push(
|
|
70
|
+
getPrivateKeyError(
|
|
71
|
+
index,
|
|
72
|
+
network,
|
|
73
|
+
`Expected string, received ${typeof privateKey}`
|
|
74
|
+
)
|
|
75
|
+
);
|
|
76
|
+
} else {
|
|
77
|
+
// private key validation
|
|
78
|
+
const pkWithPrefix = /^0x/.test(privateKey)
|
|
79
|
+
? privateKey
|
|
80
|
+
: `0x${privateKey}`;
|
|
81
|
+
|
|
82
|
+
// 32 bytes = 64 characters + 2 char prefix = 66
|
|
83
|
+
if (pkWithPrefix.length < 66) {
|
|
84
|
+
errors.push(
|
|
85
|
+
getPrivateKeyError(
|
|
86
|
+
index,
|
|
87
|
+
network,
|
|
88
|
+
"private key too short, expected 32 bytes"
|
|
89
|
+
)
|
|
90
|
+
);
|
|
91
|
+
} else if (pkWithPrefix.length > 66) {
|
|
92
|
+
errors.push(
|
|
93
|
+
getPrivateKeyError(
|
|
94
|
+
index,
|
|
95
|
+
network,
|
|
96
|
+
"private key too long, expected 32 bytes"
|
|
97
|
+
)
|
|
98
|
+
);
|
|
99
|
+
} else if (hexString.decode(pkWithPrefix).isLeft()) {
|
|
100
|
+
errors.push(
|
|
101
|
+
getPrivateKeyError(
|
|
102
|
+
index,
|
|
103
|
+
network,
|
|
104
|
+
"invalid hex character(s) found in string"
|
|
105
|
+
)
|
|
106
|
+
);
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
|
|
56
111
|
export function failure(es: ValidationError[]): string[] {
|
|
57
112
|
return es.map(getMessage);
|
|
58
113
|
}
|
|
@@ -91,6 +146,27 @@ export const hexString = new t.Type<string>(
|
|
|
91
146
|
t.identity
|
|
92
147
|
);
|
|
93
148
|
|
|
149
|
+
function isAddress(v: unknown): v is string {
|
|
150
|
+
if (typeof v !== "string") {
|
|
151
|
+
return false;
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
const trimmed = v.trim();
|
|
155
|
+
|
|
156
|
+
return (
|
|
157
|
+
trimmed.match(HEX_STRING_REGEX) !== null &&
|
|
158
|
+
trimmed.startsWith("0x") &&
|
|
159
|
+
trimmed.length === 42
|
|
160
|
+
);
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
export const address = new t.Type<string>(
|
|
164
|
+
"address",
|
|
165
|
+
isAddress,
|
|
166
|
+
(u, c) => (isAddress(u) ? t.success(u) : t.failure(u, c)),
|
|
167
|
+
t.identity
|
|
168
|
+
);
|
|
169
|
+
|
|
94
170
|
export const decimalString = new t.Type<string>(
|
|
95
171
|
"decimal string",
|
|
96
172
|
isDecimalString,
|
|
@@ -117,12 +193,73 @@ const HardhatNetworkHDAccountsConfig = t.type({
|
|
|
117
193
|
...commonHDAccountsFields,
|
|
118
194
|
});
|
|
119
195
|
|
|
196
|
+
const Integer = new t.Type<number>(
|
|
197
|
+
"Integer",
|
|
198
|
+
(num: unknown): num is number => typeof num === "number",
|
|
199
|
+
(u, c) => {
|
|
200
|
+
try {
|
|
201
|
+
return typeof u === "string"
|
|
202
|
+
? t.success(parseInt(u, 10))
|
|
203
|
+
: t.failure(u, c);
|
|
204
|
+
} catch {
|
|
205
|
+
return t.failure(u, c);
|
|
206
|
+
}
|
|
207
|
+
},
|
|
208
|
+
t.identity
|
|
209
|
+
);
|
|
210
|
+
|
|
120
211
|
const HardhatNetworkForkingConfig = t.type({
|
|
121
212
|
enabled: optional(t.boolean),
|
|
122
213
|
url: t.string,
|
|
123
214
|
blockNumber: optional(t.number),
|
|
124
215
|
});
|
|
125
216
|
|
|
217
|
+
const HardhatNetworkMempoolConfig = t.type({
|
|
218
|
+
order: optional(
|
|
219
|
+
t.keyof(
|
|
220
|
+
fromEntries(
|
|
221
|
+
HARDHAT_MEMPOOL_SUPPORTED_ORDERS.map((order) => [order, null])
|
|
222
|
+
)
|
|
223
|
+
)
|
|
224
|
+
),
|
|
225
|
+
});
|
|
226
|
+
|
|
227
|
+
const HardhatNetworkMiningConfig = t.type({
|
|
228
|
+
auto: optional(t.boolean),
|
|
229
|
+
interval: optional(t.union([t.number, t.tuple([t.number, t.number])])),
|
|
230
|
+
mempool: optional(HardhatNetworkMempoolConfig),
|
|
231
|
+
});
|
|
232
|
+
|
|
233
|
+
function isValidHardforkName(name: string) {
|
|
234
|
+
return Object.values(HardforkName).includes(name as HardforkName);
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
const HardforkNameType = new t.Type<HardforkName>(
|
|
238
|
+
Object.values(HardforkName)
|
|
239
|
+
.map((v) => `"${v}"`)
|
|
240
|
+
.join(" | "),
|
|
241
|
+
(name: unknown): name is HardforkName =>
|
|
242
|
+
typeof name === "string" && isValidHardforkName(name),
|
|
243
|
+
(u, c) => {
|
|
244
|
+
return typeof u === "string" && isValidHardforkName(u)
|
|
245
|
+
? t.success(u as HardforkName)
|
|
246
|
+
: t.failure(u, c);
|
|
247
|
+
},
|
|
248
|
+
t.identity
|
|
249
|
+
);
|
|
250
|
+
|
|
251
|
+
const HardhatNetworkHardforkHistory = t.record(
|
|
252
|
+
HardforkNameType,
|
|
253
|
+
t.number,
|
|
254
|
+
"HardhatNetworkHardforkHistory"
|
|
255
|
+
);
|
|
256
|
+
|
|
257
|
+
const HardhatNetworkChainConfig = t.type({
|
|
258
|
+
hardforkHistory: HardhatNetworkHardforkHistory,
|
|
259
|
+
});
|
|
260
|
+
|
|
261
|
+
const HardhatNetworkChainsConfig = t.record(Integer, HardhatNetworkChainConfig);
|
|
262
|
+
|
|
126
263
|
const commonNetworkConfigFields = {
|
|
127
264
|
chainId: optional(t.number),
|
|
128
265
|
from: optional(t.string),
|
|
@@ -149,6 +286,9 @@ const HardhatNetworkConfig = t.type({
|
|
|
149
286
|
initialDate: optional(t.string),
|
|
150
287
|
loggingEnabled: optional(t.boolean),
|
|
151
288
|
forking: optional(HardhatNetworkForkingConfig),
|
|
289
|
+
mining: optional(HardhatNetworkMiningConfig),
|
|
290
|
+
coinbase: optional(address),
|
|
291
|
+
chains: optional(HardhatNetworkChainsConfig),
|
|
152
292
|
});
|
|
153
293
|
|
|
154
294
|
const HDAccountsConfig = t.type({
|
|
@@ -224,7 +364,7 @@ export function validateConfig(config: any) {
|
|
|
224
364
|
}
|
|
225
365
|
|
|
226
366
|
export function getValidationErrors(config: any): string[] {
|
|
227
|
-
const errors = [];
|
|
367
|
+
const errors: string[] = [];
|
|
228
368
|
|
|
229
369
|
// These can't be validated with io-ts
|
|
230
370
|
if (config !== undefined && typeof config.networks === "object") {
|
|
@@ -237,8 +377,7 @@ export function getValidationErrors(config: any): string[] {
|
|
|
237
377
|
}
|
|
238
378
|
|
|
239
379
|
// Validating the accounts with io-ts leads to very confusing errors messages
|
|
240
|
-
const configExceptAccounts =
|
|
241
|
-
delete configExceptAccounts.accounts;
|
|
380
|
+
const { accounts, ...configExceptAccounts } = hardhatNetwork;
|
|
242
381
|
|
|
243
382
|
const netConfigResult = HardhatNetworkConfig.decode(configExceptAccounts);
|
|
244
383
|
if (netConfigResult.isLeft()) {
|
|
@@ -251,31 +390,37 @@ export function getValidationErrors(config: any): string[] {
|
|
|
251
390
|
);
|
|
252
391
|
}
|
|
253
392
|
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
393
|
+
// manual validation of accounts
|
|
394
|
+
if (Array.isArray(accounts)) {
|
|
395
|
+
for (const [index, account] of accounts.entries()) {
|
|
396
|
+
if (typeof account !== "object") {
|
|
257
397
|
errors.push(
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
398
|
+
getPrivateKeyError(
|
|
399
|
+
index,
|
|
400
|
+
HARDHAT_NETWORK_NAME,
|
|
401
|
+
`Expected object, received ${typeof account}`
|
|
262
402
|
)
|
|
263
403
|
);
|
|
404
|
+
continue;
|
|
264
405
|
}
|
|
265
406
|
|
|
266
|
-
|
|
407
|
+
const { privateKey, balance } = account;
|
|
408
|
+
|
|
409
|
+
validatePrivateKey(privateKey, index, HARDHAT_NETWORK_NAME, errors);
|
|
410
|
+
|
|
411
|
+
if (typeof balance !== "string") {
|
|
267
412
|
errors.push(
|
|
268
413
|
getErrorMessage(
|
|
269
414
|
`HardhatConfig.networks.${HARDHAT_NETWORK_NAME}.accounts[].balance`,
|
|
270
|
-
|
|
415
|
+
balance,
|
|
271
416
|
"string"
|
|
272
417
|
)
|
|
273
418
|
);
|
|
274
|
-
} else if (decimalString.decode(
|
|
419
|
+
} else if (decimalString.decode(balance).isLeft()) {
|
|
275
420
|
errors.push(
|
|
276
421
|
getErrorMessage(
|
|
277
422
|
`HardhatConfig.networks.${HARDHAT_NETWORK_NAME}.accounts[].balance`,
|
|
278
|
-
|
|
423
|
+
balance,
|
|
279
424
|
"decimal(wei)"
|
|
280
425
|
)
|
|
281
426
|
);
|
|
@@ -319,6 +464,29 @@ export function getValidationErrors(config: any): string[] {
|
|
|
319
464
|
);
|
|
320
465
|
}
|
|
321
466
|
}
|
|
467
|
+
|
|
468
|
+
if (hardhatNetwork.chains !== undefined) {
|
|
469
|
+
Object.entries(hardhatNetwork.chains).forEach((chainEntry) => {
|
|
470
|
+
const [chainId, chainConfig] = chainEntry as [
|
|
471
|
+
string,
|
|
472
|
+
HardhatNetworkChainUserConfig
|
|
473
|
+
];
|
|
474
|
+
const { hardforkHistory } = chainConfig;
|
|
475
|
+
if (hardforkHistory !== undefined) {
|
|
476
|
+
Object.keys(hardforkHistory).forEach((hardforkName) => {
|
|
477
|
+
if (!HARDHAT_NETWORK_SUPPORTED_HARDFORKS.includes(hardforkName)) {
|
|
478
|
+
errors.push(
|
|
479
|
+
getErrorMessage(
|
|
480
|
+
`HardhatConfig.networks.${HARDHAT_NETWORK_NAME}.chains[${chainId}].hardforkHistory`,
|
|
481
|
+
hardforkName,
|
|
482
|
+
`"${HARDHAT_NETWORK_SUPPORTED_HARDFORKS.join('" | "')}"`
|
|
483
|
+
)
|
|
484
|
+
);
|
|
485
|
+
}
|
|
486
|
+
});
|
|
487
|
+
}
|
|
488
|
+
});
|
|
489
|
+
}
|
|
322
490
|
}
|
|
323
491
|
|
|
324
492
|
for (const [networkName, netConfig] of Object.entries<any>(
|
|
@@ -340,7 +508,9 @@ export function getValidationErrors(config: any): string[] {
|
|
|
340
508
|
}
|
|
341
509
|
}
|
|
342
510
|
|
|
343
|
-
const
|
|
511
|
+
const { accounts, ...configExceptAccounts } = netConfig;
|
|
512
|
+
|
|
513
|
+
const netConfigResult = HttpNetworkConfig.decode(configExceptAccounts);
|
|
344
514
|
if (netConfigResult.isLeft()) {
|
|
345
515
|
errors.push(
|
|
346
516
|
getErrorMessage(
|
|
@@ -350,6 +520,38 @@ export function getValidationErrors(config: any): string[] {
|
|
|
350
520
|
)
|
|
351
521
|
);
|
|
352
522
|
}
|
|
523
|
+
|
|
524
|
+
// manual validation of accounts
|
|
525
|
+
if (Array.isArray(accounts)) {
|
|
526
|
+
accounts.forEach((privateKey, index) =>
|
|
527
|
+
validatePrivateKey(privateKey, index, networkName, errors)
|
|
528
|
+
);
|
|
529
|
+
} else if (typeof accounts === "object") {
|
|
530
|
+
const hdConfigResult = HDAccountsConfig.decode(accounts);
|
|
531
|
+
if (hdConfigResult.isLeft()) {
|
|
532
|
+
errors.push(
|
|
533
|
+
getErrorMessage(
|
|
534
|
+
`HardhatConfig.networks.${networkName}`,
|
|
535
|
+
accounts,
|
|
536
|
+
"HttpNetworkHDAccountsConfig"
|
|
537
|
+
)
|
|
538
|
+
);
|
|
539
|
+
}
|
|
540
|
+
} else if (typeof accounts === "string") {
|
|
541
|
+
if (accounts !== "remote") {
|
|
542
|
+
errors.push(
|
|
543
|
+
`Invalid 'accounts' entry for network '${networkName}': expected an array of accounts or the string 'remote', but got the string '${accounts}'`
|
|
544
|
+
);
|
|
545
|
+
}
|
|
546
|
+
} else if (accounts !== undefined) {
|
|
547
|
+
errors.push(
|
|
548
|
+
getErrorMessage(
|
|
549
|
+
`HardhatConfig.networks.${networkName}.accounts`,
|
|
550
|
+
accounts,
|
|
551
|
+
'"remote" | string[] | HttpNetworkHDAccountsConfig | undefined'
|
|
552
|
+
)
|
|
553
|
+
);
|
|
554
|
+
}
|
|
353
555
|
}
|
|
354
556
|
}
|
|
355
557
|
|
|
@@ -1,13 +1,14 @@
|
|
|
1
1
|
import { BN } from "ethereumjs-util";
|
|
2
2
|
|
|
3
3
|
import { HardhatNetworkConfig } from "../../../types";
|
|
4
|
+
import { HardforkName } from "../../util/hardforks";
|
|
4
5
|
import { HARDHAT_NETWORK_NAME } from "../../constants";
|
|
5
6
|
|
|
6
7
|
export const DEFAULT_SOLC_VERSION = "0.7.3";
|
|
7
8
|
export const HARDHAT_NETWORK_DEFAULT_GAS_PRICE = "auto";
|
|
8
9
|
export const HARDHAT_NETWORK_DEFAULT_MAX_PRIORITY_FEE_PER_GAS = 1e9;
|
|
9
10
|
export const HARDHAT_NETWORK_DEFAULT_INITIAL_BASE_FEE_PER_GAS = 1e9;
|
|
10
|
-
const HARDHAT_NETWORK_MNEMONIC =
|
|
11
|
+
export const HARDHAT_NETWORK_MNEMONIC =
|
|
11
12
|
"test test test test test test test test test test test junk";
|
|
12
13
|
export const DEFAULT_HARDHAT_NETWORK_BALANCE = "10000000000000000000000";
|
|
13
14
|
|
|
@@ -42,11 +43,74 @@ export const defaultHardhatNetworkParams: Omit<
|
|
|
42
43
|
throwOnTransactionFailures: true,
|
|
43
44
|
throwOnCallFailures: true,
|
|
44
45
|
allowUnlimitedContractSize: false,
|
|
45
|
-
mining: {
|
|
46
|
+
mining: {
|
|
47
|
+
auto: true,
|
|
48
|
+
interval: 0,
|
|
49
|
+
mempool: {
|
|
50
|
+
order: "priority",
|
|
51
|
+
},
|
|
52
|
+
},
|
|
46
53
|
accounts: defaultHardhatNetworkHdAccountsConfigParams,
|
|
47
54
|
loggingEnabled: false,
|
|
48
55
|
gasMultiplier: DEFAULT_GAS_MULTIPLIER,
|
|
49
56
|
minGasPrice: new BN(0),
|
|
57
|
+
chains: new Map([
|
|
58
|
+
[
|
|
59
|
+
// block numbers below were taken from https://github.com/ethereumjs/ethereumjs-monorepo/tree/master/packages/common/src/chains
|
|
60
|
+
1, // mainnet
|
|
61
|
+
{
|
|
62
|
+
hardforkHistory: new Map([
|
|
63
|
+
[HardforkName.BYZANTIUM, 4370000],
|
|
64
|
+
[HardforkName.CONSTANTINOPLE, 7280000],
|
|
65
|
+
[HardforkName.PETERSBURG, 7280000],
|
|
66
|
+
[HardforkName.ISTANBUL, 9069000],
|
|
67
|
+
[HardforkName.MUIR_GLACIER, 9200000],
|
|
68
|
+
[HardforkName.BERLIN, 12244000],
|
|
69
|
+
[HardforkName.LONDON, 12965000],
|
|
70
|
+
]),
|
|
71
|
+
},
|
|
72
|
+
],
|
|
73
|
+
[
|
|
74
|
+
3, // ropsten
|
|
75
|
+
{
|
|
76
|
+
hardforkHistory: new Map([
|
|
77
|
+
[HardforkName.BYZANTIUM, 1700000],
|
|
78
|
+
[HardforkName.CONSTANTINOPLE, 4230000],
|
|
79
|
+
[HardforkName.PETERSBURG, 4939394],
|
|
80
|
+
[HardforkName.ISTANBUL, 6485846],
|
|
81
|
+
[HardforkName.MUIR_GLACIER, 7117117],
|
|
82
|
+
[HardforkName.BERLIN, 9812189],
|
|
83
|
+
[HardforkName.LONDON, 10499401],
|
|
84
|
+
]),
|
|
85
|
+
},
|
|
86
|
+
],
|
|
87
|
+
[
|
|
88
|
+
4, // rinkeby
|
|
89
|
+
{
|
|
90
|
+
hardforkHistory: new Map([
|
|
91
|
+
[HardforkName.BYZANTIUM, 1035301],
|
|
92
|
+
[HardforkName.CONSTANTINOPLE, 3660663],
|
|
93
|
+
[HardforkName.PETERSBURG, 4321234],
|
|
94
|
+
[HardforkName.ISTANBUL, 5435345],
|
|
95
|
+
[HardforkName.BERLIN, 8290928],
|
|
96
|
+
[HardforkName.LONDON, 8897988],
|
|
97
|
+
]),
|
|
98
|
+
},
|
|
99
|
+
],
|
|
100
|
+
[
|
|
101
|
+
42, // kovan
|
|
102
|
+
{
|
|
103
|
+
hardforkHistory: new Map([
|
|
104
|
+
[HardforkName.BYZANTIUM, 5067000],
|
|
105
|
+
[HardforkName.CONSTANTINOPLE, 9200000],
|
|
106
|
+
[HardforkName.PETERSBURG, 10255201],
|
|
107
|
+
[HardforkName.ISTANBUL, 14111141],
|
|
108
|
+
[HardforkName.BERLIN, 24770900],
|
|
109
|
+
[HardforkName.LONDON, 26741100],
|
|
110
|
+
]),
|
|
111
|
+
},
|
|
112
|
+
],
|
|
113
|
+
]),
|
|
50
114
|
};
|
|
51
115
|
|
|
52
116
|
export const defaultHttpNetworkParams = {
|
|
@@ -69,6 +133,7 @@ export const defaultSolcOutputSelection = {
|
|
|
69
133
|
"evm.bytecode",
|
|
70
134
|
"evm.deployedBytecode",
|
|
71
135
|
"evm.methodIdentifiers",
|
|
136
|
+
"metadata",
|
|
72
137
|
],
|
|
73
138
|
"": ["ast"],
|
|
74
139
|
},
|
|
@@ -360,6 +360,15 @@ Please double check your transactions' parameters.`,
|
|
|
360
360
|
Please double check your transactions' parameters.`,
|
|
361
361
|
shouldBeReported: false,
|
|
362
362
|
},
|
|
363
|
+
PERSONALSIGN_MISSING_ADDRESS_PARAM: {
|
|
364
|
+
number: 116,
|
|
365
|
+
message: 'Missing "address" param when calling personal_sign.',
|
|
366
|
+
title: "Missing `address` param when calling personal_sign.",
|
|
367
|
+
description: `You called \`personal_sign\` with incorrect parameters.
|
|
368
|
+
|
|
369
|
+
Please check that you are sending an \`address\` parameter.`,
|
|
370
|
+
shouldBeReported: false,
|
|
371
|
+
},
|
|
363
372
|
},
|
|
364
373
|
TASK_DEFINITIONS: {
|
|
365
374
|
PARAM_AFTER_VARIADIC: {
|
|
@@ -562,7 +571,7 @@ Please double check how you invoked Hardhat or ran your task.`,
|
|
|
562
571
|
},
|
|
563
572
|
MISSING_TASK_ARGUMENT: {
|
|
564
573
|
number: 306,
|
|
565
|
-
message: "
|
|
574
|
+
message: "The '%param%' parameter expects a value, but none was passed.",
|
|
566
575
|
title: "Missing task argument",
|
|
567
576
|
description: `You tried to run a task, but one of its required arguments was missing.
|
|
568
577
|
|
|
@@ -861,11 +870,21 @@ To start the JSON-RPC server, retry the command without the --network parameter.
|
|
|
861
870
|
if the URL of the JSON-RPC wasn't set.`,
|
|
862
871
|
shouldBeReported: false,
|
|
863
872
|
},
|
|
873
|
+
COMPILE_TASK_UNSUPPORTED_SOLC_VERSION: {
|
|
874
|
+
number: 608,
|
|
875
|
+
message: `Version %version% is not supported by Hardhat.
|
|
876
|
+
|
|
877
|
+
The first supported version is %firstSupportedVersion%`,
|
|
878
|
+
title: "Unsupported solc version",
|
|
879
|
+
description: `This version of solidity is not supported by Hardhtat.
|
|
880
|
+
Please use a newer, supported version.`,
|
|
881
|
+
shouldBeReported: true,
|
|
882
|
+
},
|
|
864
883
|
},
|
|
865
884
|
ARTIFACTS: {
|
|
866
885
|
NOT_FOUND: {
|
|
867
886
|
number: 700,
|
|
868
|
-
message: 'Artifact for contract "%contractName%" not found.',
|
|
887
|
+
message: 'Artifact for contract "%contractName%" not found. %suggestion%',
|
|
869
888
|
title: "Artifact not found",
|
|
870
889
|
description: `Tried to import a nonexistent artifact.
|
|
871
890
|
|
|
@@ -6,6 +6,7 @@ import { rpcAddress, rpcData, rpcHash, rpcQuantity } from "../base-types";
|
|
|
6
6
|
export type RpcLog = t.TypeOf<typeof rpcLog>;
|
|
7
7
|
export const rpcLog = t.type(
|
|
8
8
|
{
|
|
9
|
+
logIndex: nullable(rpcQuantity),
|
|
9
10
|
transactionIndex: nullable(rpcQuantity),
|
|
10
11
|
transactionHash: nullable(rpcHash),
|
|
11
12
|
blockHash: nullable(rpcHash),
|
|
@@ -78,8 +78,8 @@ export const HARDHAT_PARAM_DEFINITIONS: HardhatParamDefinitions = {
|
|
|
78
78
|
tsconfig: {
|
|
79
79
|
name: "tsconfig",
|
|
80
80
|
defaultValue: undefined,
|
|
81
|
-
description: "
|
|
82
|
-
type: types.
|
|
81
|
+
description: "A TypeScript config file.",
|
|
82
|
+
type: types.inputFile,
|
|
83
83
|
isOptional: true,
|
|
84
84
|
isFlag: false,
|
|
85
85
|
isVariadic: false,
|
|
@@ -74,6 +74,25 @@ export class LocalAccountsProvider extends ProviderWrapperWithChainId {
|
|
|
74
74
|
}
|
|
75
75
|
}
|
|
76
76
|
|
|
77
|
+
if (args.method === "personal_sign") {
|
|
78
|
+
if (params.length > 0) {
|
|
79
|
+
const [data, address] = validateParams(params, rpcData, rpcAddress);
|
|
80
|
+
|
|
81
|
+
if (data !== undefined) {
|
|
82
|
+
if (address === undefined) {
|
|
83
|
+
throw new HardhatError(
|
|
84
|
+
ERRORS.NETWORK.PERSONALSIGN_MISSING_ADDRESS_PARAM
|
|
85
|
+
);
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
const privateKey = this._getPrivateKeyForAddress(address);
|
|
89
|
+
const messageHash = hashPersonalMessage(toBuffer(data));
|
|
90
|
+
const signature = ecsign(messageHash, privateKey);
|
|
91
|
+
return toRpcSig(signature.v, signature.r, signature.s);
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
|
|
77
96
|
if (args.method === "eth_signTypedData_v4") {
|
|
78
97
|
const [address, data] = validateParams(params, rpcAddress, t.any);
|
|
79
98
|
|
|
@@ -13,7 +13,10 @@ import type {
|
|
|
13
13
|
} from "../../../types";
|
|
14
14
|
import { HARDHAT_NETWORK_NAME } from "../../constants";
|
|
15
15
|
import { ModulesLogger } from "../../hardhat-network/provider/modules/logger";
|
|
16
|
-
import {
|
|
16
|
+
import {
|
|
17
|
+
ForkConfig,
|
|
18
|
+
MempoolOrder,
|
|
19
|
+
} from "../../hardhat-network/provider/node-types";
|
|
17
20
|
import { getForkCacheDirPath } from "../../hardhat-network/provider/utils/disk-cache";
|
|
18
21
|
import { parseDateString } from "../../util/date";
|
|
19
22
|
|
|
@@ -88,6 +91,9 @@ export function createProvider(
|
|
|
88
91
|
hardhatNetConfig.throwOnCallFailures,
|
|
89
92
|
hardhatNetConfig.mining.auto,
|
|
90
93
|
hardhatNetConfig.mining.interval,
|
|
94
|
+
// This cast is valid because of the config validation and resolution
|
|
95
|
+
hardhatNetConfig.mining.mempool.order as MempoolOrder,
|
|
96
|
+
hardhatNetConfig.chains,
|
|
91
97
|
new ModulesLogger(hardhatNetConfig.loggingEnabled),
|
|
92
98
|
accounts,
|
|
93
99
|
artifacts,
|
|
@@ -97,7 +103,8 @@ export function createProvider(
|
|
|
97
103
|
: undefined,
|
|
98
104
|
experimentalHardhatNetworkMessageTraceHooks,
|
|
99
105
|
forkConfig,
|
|
100
|
-
paths !== undefined ? getForkCacheDirPath(paths) : undefined
|
|
106
|
+
paths !== undefined ? getForkCacheDirPath(paths) : undefined,
|
|
107
|
+
hardhatNetConfig.coinbase
|
|
101
108
|
);
|
|
102
109
|
} else {
|
|
103
110
|
const HttpProvider = importProvider<
|