-
Notifications
You must be signed in to change notification settings - Fork 73
Expand file tree
/
Copy pathcommon.ts
More file actions
123 lines (106 loc) · 3.68 KB
/
common.ts
File metadata and controls
123 lines (106 loc) · 3.68 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
import { z } from 'zod';
export const hexSchema = z
.string()
.regex(/^0x[0-9a-fA-F]*$/, 'Invalid hex string')
.transform((val) => val as `0x${string}`);
export const addressSchema = z
.string()
.regex(/^0x[0-9a-fA-F]{40}$/, 'Invalid Ethereum address')
.transform((val) => val as `0x${string}`);
export const privateKeySchema = z
.string()
.regex(/^0x[0-9a-fA-F]{64}$/, 'Invalid private key')
.transform((val) => val as `0x${string}`);
// z.coerce.bigint() calls BigInt() which throws a raw SyntaxError on invalid
// input, bypassing zod's error pipeline -- safeParse can throw, and the error
// has no field path context. Regex guard makes the BigInt() call provably safe.
export const bigintSchema = z
.string()
.regex(/^-?\d+$/, 'Expected a numeric string')
.transform(BigInt);
export const rollupCreatorVersionSchema = z.enum(['v3.2', 'v2.1']);
export const sequencerInboxMaxTimeVariationSchema = z.object({
delayBlocks: bigintSchema,
futureBlocks: bigintSchema,
delaySeconds: bigintSchema,
futureSeconds: bigintSchema,
});
export const gasOptionsSchema = z.object({
base: bigintSchema.optional(),
percentIncrease: bigintSchema.optional(),
});
export const gasLimitSchema = z.object({
gasLimit: gasOptionsSchema.optional(),
});
export const tokenBridgeRetryableGasOverridesSchema = z.object({
maxSubmissionCostForFactory: gasOptionsSchema.optional(),
maxGasForFactory: gasOptionsSchema.optional(),
maxSubmissionCostForContracts: gasOptionsSchema.optional(),
maxGasForContracts: gasOptionsSchema.optional(),
maxGasPrice: bigintSchema.optional(),
});
export const setWethGatewayGasOverridesSchema = z.object({
gasLimit: gasOptionsSchema.optional(),
maxFeePerGas: gasOptionsSchema.optional(),
maxSubmissionCost: gasOptionsSchema.optional(),
});
export const coreContractsSchema = z.object({
rollup: addressSchema,
nativeToken: addressSchema,
inbox: addressSchema,
outbox: addressSchema,
rollupEventInbox: addressSchema,
challengeManager: addressSchema,
adminProxy: addressSchema,
sequencerInbox: addressSchema,
bridge: addressSchema,
upgradeExecutor: addressSchema,
validatorUtils: addressSchema.optional(),
validatorWalletCreator: addressSchema,
deployedAtBlockNumber: z.number(),
});
export const bufferConfigSchema = z.object({
threshold: bigintSchema,
max: bigintSchema,
replenishRateInBasis: bigintSchema,
});
const globalStateSchema = z.object({
bytes32Vals: z.tuple([hexSchema, hexSchema]),
u64Vals: z.tuple([bigintSchema, bigintSchema]),
});
export const assertionStateSchema = z.object({
globalState: globalStateSchema,
machineStatus: z.number(),
endHistoryRoot: hexSchema,
});
export const prepareChainConfigArbitrumParamsSchema = z.object({
InitialChainOwner: addressSchema,
DataAvailabilityCommittee: z.boolean().optional(),
InitialArbOSVersion: z.number().optional(),
MaxCodeSize: z.number().optional(),
MaxInitCodeSize: z.number().optional(),
});
const chainConfigArbitrumParamsSchema = prepareChainConfigArbitrumParamsSchema.required().extend({
EnableArbOS: z.boolean(),
AllowDebugPrecompiles: z.boolean(),
GenesisBlockNum: z.number(),
});
export const chainConfigSchema = z.object({
chainId: z.number(),
homesteadBlock: z.number(),
daoForkBlock: z.null(),
daoForkSupport: z.boolean(),
eip150Block: z.number(),
eip150Hash: z.string(),
eip155Block: z.number(),
eip158Block: z.number(),
byzantiumBlock: z.number(),
constantinopleBlock: z.number(),
petersburgBlock: z.number(),
istanbulBlock: z.number(),
muirGlacierBlock: z.number(),
berlinBlock: z.number(),
londonBlock: z.number(),
clique: z.object({ period: z.number(), epoch: z.number() }),
arbitrum: chainConfigArbitrumParamsSchema,
});