@@ -5,7 +5,8 @@ import type {
5
5
import type { HardhatUserConfigValidationError } from "../../../types/hooks.js" ;
6
6
7
7
import {
8
- sensitiveUrlType ,
8
+ conditionalUnionType ,
9
+ sensitiveUrlSchema ,
9
10
unionType ,
10
11
validateUserConfigZodType ,
11
12
} from "@ignored/hardhat-vnext-zod-utils" ;
@@ -16,27 +17,26 @@ const chainTypeSchema = unionType(
16
17
"Expected 'l1', 'optimism', or 'unknown'" ,
17
18
) ;
18
19
20
+ const userGasSchema = conditionalUnionType (
21
+ [
22
+ [ ( data ) => typeof data === "string" , z . literal ( "auto" ) ] ,
23
+ [ ( data ) => typeof data === "number" , z . number ( ) . int ( ) . positive ( ) . safe ( ) ] ,
24
+ [ ( data ) => typeof data === "bigint" , z . bigint ( ) . positive ( ) ] ,
25
+ ] ,
26
+ "Expected 'auto', a safe int, or bigint" ,
27
+ ) ;
28
+
19
29
const httpNetworkUserConfigSchema = z . object ( {
20
30
type : z . literal ( "http" ) ,
21
31
chainId : z . optional ( z . number ( ) . int ( ) ) ,
22
32
chainType : z . optional ( chainTypeSchema ) ,
23
33
from : z . optional ( z . string ( ) ) ,
24
- gas : z . optional (
25
- unionType (
26
- [ z . literal ( "auto" ) , z . number ( ) . int ( ) . safe ( ) , z . bigint ( ) ] ,
27
- "Expected 'auto', a safe int, or bigint" ,
28
- ) ,
29
- ) ,
34
+ gas : z . optional ( userGasSchema ) ,
30
35
gasMultiplier : z . optional ( z . number ( ) ) ,
31
- gasPrice : z . optional (
32
- unionType (
33
- [ z . literal ( "auto" ) , z . number ( ) . int ( ) . safe ( ) , z . bigint ( ) ] ,
34
- "Expected 'auto', a safe int, or bigint" ,
35
- ) ,
36
- ) ,
36
+ gasPrice : z . optional ( userGasSchema ) ,
37
37
38
38
// HTTP network specific
39
- url : sensitiveUrlType ,
39
+ url : sensitiveUrlSchema ,
40
40
timeout : z . optional ( z . number ( ) ) ,
41
41
httpHeaders : z . optional ( z . record ( z . string ( ) ) ) ,
42
42
} ) ;
@@ -46,15 +46,9 @@ const edrNetworkUserConfigSchema = z.object({
46
46
chainId : z . number ( ) . int ( ) ,
47
47
chainType : z . optional ( chainTypeSchema ) ,
48
48
from : z . optional ( z . string ( ) ) ,
49
- gas : unionType (
50
- [ z . literal ( "auto" ) , z . number ( ) . int ( ) . safe ( ) , z . bigint ( ) ] ,
51
- "Expected 'auto', a safe int, or bigint" ,
52
- ) ,
49
+ gas : userGasSchema ,
53
50
gasMultiplier : z . number ( ) ,
54
- gasPrice : unionType (
55
- [ z . literal ( "auto" ) , z . number ( ) . int ( ) . safe ( ) , z . bigint ( ) ] ,
56
- "Expected 'auto', a safe int, or bigint" ,
57
- ) ,
51
+ gasPrice : userGasSchema ,
58
52
} ) ;
59
53
60
54
const networkUserConfigSchema = z . discriminatedUnion ( "type" , [
@@ -68,20 +62,25 @@ const userConfigSchema = z.object({
68
62
networks : z . optional ( z . record ( networkUserConfigSchema ) ) ,
69
63
} ) ;
70
64
65
+ const gasSchema = conditionalUnionType (
66
+ [
67
+ [ ( data ) => typeof data === "string" , z . literal ( "auto" ) ] ,
68
+ [ ( data ) => typeof data === "bigint" , z . bigint ( ) . positive ( ) ] ,
69
+ ] ,
70
+ "Expected 'auto' or bigint" ,
71
+ ) ;
72
+
71
73
const httpNetworkConfigSchema = z . object ( {
72
74
type : z . literal ( "http" ) ,
73
75
chainId : z . optional ( z . number ( ) . int ( ) ) ,
74
76
chainType : z . optional ( chainTypeSchema ) ,
75
77
from : z . optional ( z . string ( ) ) ,
76
- gas : unionType ( [ z . literal ( "auto" ) , z . bigint ( ) ] , "Expected 'auto' or bigint" ) ,
78
+ gas : gasSchema ,
77
79
gasMultiplier : z . number ( ) ,
78
- gasPrice : unionType (
79
- [ z . literal ( "auto" ) , z . bigint ( ) ] ,
80
- "Expected 'auto' or bigint" ,
81
- ) ,
80
+ gasPrice : gasSchema ,
82
81
83
82
// HTTP network specific
84
- url : sensitiveUrlType ,
83
+ url : sensitiveUrlSchema ,
85
84
timeout : z . number ( ) ,
86
85
httpHeaders : z . record ( z . string ( ) ) ,
87
86
} ) ;
@@ -91,12 +90,9 @@ const edrNetworkConfigSchema = z.object({
91
90
chainId : z . number ( ) . int ( ) ,
92
91
chainType : z . optional ( chainTypeSchema ) ,
93
92
from : z . string ( ) ,
94
- gas : unionType ( [ z . literal ( "auto" ) , z . bigint ( ) ] , "Expected 'auto' or bigint" ) ,
93
+ gas : gasSchema ,
95
94
gasMultiplier : z . number ( ) ,
96
- gasPrice : unionType (
97
- [ z . literal ( "auto" ) , z . bigint ( ) ] ,
98
- "Expected 'auto' or bigint" ,
99
- ) ,
95
+ gasPrice : gasSchema ,
100
96
} ) ;
101
97
102
98
const networkConfigSchema = z . discriminatedUnion ( "type" , [
0 commit comments