@matterlabs/zksync-js 0.0.6 → 0.0.8
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/dist/adapters/ethers/client.cjs +243 -79
- package/dist/adapters/ethers/client.cjs.map +1 -1
- package/dist/adapters/ethers/client.js +6 -6
- package/dist/adapters/ethers/errors/error-ops.d.ts +26 -19
- package/dist/adapters/ethers/index.cjs +290 -119
- package/dist/adapters/ethers/index.cjs.map +1 -1
- package/dist/adapters/ethers/index.js +9 -9
- package/dist/adapters/ethers/sdk.cjs +78 -59
- package/dist/adapters/ethers/sdk.cjs.map +1 -1
- package/dist/adapters/ethers/sdk.js +7 -7
- package/dist/adapters/viem/client.cjs +192 -34
- package/dist/adapters/viem/client.cjs.map +1 -1
- package/dist/adapters/viem/client.js +4 -4
- package/dist/adapters/viem/errors/error-ops.d.ts +26 -19
- package/dist/adapters/viem/index.cjs +290 -119
- package/dist/adapters/viem/index.cjs.map +1 -1
- package/dist/adapters/viem/index.js +8 -8
- package/dist/adapters/viem/sdk.cjs +97 -80
- package/dist/adapters/viem/sdk.cjs.map +1 -1
- package/dist/adapters/viem/sdk.js +6 -6
- package/dist/{chunk-M5J2MM2U.js → chunk-3GFCAGGI.js} +1430 -7
- package/dist/chunk-5V2JRM5J.js +75 -0
- package/dist/{chunk-WU2LOG2A.js → chunk-63DNJXS3.js} +7 -8
- package/dist/{chunk-F2ENUV3A.js → chunk-C3AGOEHR.js} +12 -2
- package/dist/{chunk-3MRGU4HV.js → chunk-FGXRG2JS.js} +4 -4
- package/dist/{chunk-NTEIA5KA.js → chunk-L343N56B.js} +1 -1
- package/dist/{chunk-2MDK3GLO.js → chunk-LNIEQ7AN.js} +9 -54
- package/dist/{chunk-LL3WKCFJ.js → chunk-NODVRI3E.js} +2 -2
- package/dist/{chunk-XRE7H466.js → chunk-NVULC4JB.js} +3 -47
- package/dist/{chunk-YUK547UF.js → chunk-ODMBZ2VX.js} +3 -3
- package/dist/{chunk-NEC2ZKHI.js → chunk-QZVYN3YA.js} +30 -7
- package/dist/{chunk-6K6VJQAL.js → chunk-SHQQI3UD.js} +175 -20
- package/dist/core/abi.d.ts +5 -0
- package/dist/core/constants.cjs +11 -1
- package/dist/core/constants.cjs.map +1 -1
- package/dist/core/constants.d.ts +11 -1
- package/dist/core/constants.js +1 -1
- package/dist/core/errors/error-ops.d.ts +18 -0
- package/dist/core/index.cjs +1737 -131
- package/dist/core/index.cjs.map +1 -1
- package/dist/core/index.d.ts +2 -1
- package/dist/core/index.js +5 -5
- package/dist/core/internal/abis/IERC7786Attributes.d.ts +42 -0
- package/dist/core/internal/abis/IInteropCenter.d.ts +211 -0
- package/dist/core/internal/abis/IInteropHandler.d.ts +166 -0
- package/dist/core/internal/abis/InteropCenter.d.ts +578 -0
- package/dist/core/internal/abis/InteropRootStorage.d.ts +20 -0
- package/dist/core/internal/abis/L2MessageVerification.d.ts +277 -0
- package/dist/core/resources/interop/attributes/bundle.d.ts +6 -0
- package/dist/core/resources/interop/attributes/call.d.ts +6 -0
- package/dist/core/resources/interop/attributes/index.d.ts +4 -0
- package/dist/core/resources/interop/attributes/resource.d.ts +12 -0
- package/dist/core/resources/interop/attributes/types.d.ts +6 -0
- package/dist/core/resources/interop/events.d.ts +7 -0
- package/dist/core/resources/interop/finalization.d.ts +61 -0
- package/dist/core/resources/interop/plan.d.ts +39 -0
- package/dist/core/resources/interop/route.d.ts +15 -0
- package/dist/core/rpc/types.d.ts +14 -0
- package/dist/core/rpc/zks.d.ts +4 -1
- package/dist/core/types/errors.d.ts +43 -2
- package/dist/core/types/flows/base.d.ts +1 -1
- package/dist/core/types/flows/interop.d.ts +231 -0
- package/dist/core/types/flows/withdrawals.d.ts +0 -8
- package/dist/core/types/transactions.d.ts +10 -0
- package/dist/core/utils/addr.d.ts +2 -2
- package/dist/core/utils/events.d.ts +12 -0
- package/dist/core/utils/hash.d.ts +5 -0
- package/dist/core/utils/index.d.ts +5 -0
- package/dist/core/utils/number.d.ts +2 -0
- package/dist/index.cjs +1748 -132
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +2 -1
- package/dist/index.js +5 -5
- package/package.json +6 -2
- package/dist/chunk-NCAIVYBR.js +0 -23
- package/dist/core/resources/withdrawals/events.d.ts +0 -9
|
@@ -11,6 +11,16 @@ function makeTransportFromEthers(provider) {
|
|
|
11
11
|
return (m, p = []) => provider.send(m, p);
|
|
12
12
|
}
|
|
13
13
|
|
|
14
|
+
// src/core/utils/number.ts
|
|
15
|
+
var isNumber = (x) => typeof x === "number" && Number.isFinite(x);
|
|
16
|
+
var isBigint = (x) => typeof x === "bigint";
|
|
17
|
+
var k256hex = (s) => `0x${utils.bytesToHex(sha3.keccak_256(utils.utf8ToBytes(s)))}`.toLowerCase();
|
|
18
|
+
var L2_ASSET_ROUTER_ADDRESS = "0x0000000000000000000000000000000000010003";
|
|
19
|
+
var L2_NATIVE_TOKEN_VAULT_ADDRESS = "0x0000000000000000000000000000000000010004";
|
|
20
|
+
var L2_BASE_TOKEN_ADDRESS = "0x000000000000000000000000000000000000800A";
|
|
21
|
+
k256hex("L1MessageSent(uint256,bytes32,bytes)");
|
|
22
|
+
k256hex("L1MessageSent(address,bytes32,bytes)");
|
|
23
|
+
|
|
14
24
|
// src/core/errors/formatter.ts
|
|
15
25
|
function elideMiddle(s, max = 96) {
|
|
16
26
|
if (s.length <= max) return s;
|
|
@@ -21,7 +31,7 @@ function shortJSON(v, max = 240) {
|
|
|
21
31
|
try {
|
|
22
32
|
const s = JSON.stringify(
|
|
23
33
|
v,
|
|
24
|
-
(_k, val) =>
|
|
34
|
+
(_k, val) => isBigint(val) ? `${val.toString()}n` : val
|
|
25
35
|
);
|
|
26
36
|
return s.length > max ? elideMiddle(s, max) : s;
|
|
27
37
|
} catch {
|
|
@@ -41,7 +51,7 @@ function formatContextLine(ctx) {
|
|
|
41
51
|
if (txHash !== void 0)
|
|
42
52
|
parts.push(`txHash=${typeof txHash === "string" ? txHash : shortJSON(txHash, 96)}`);
|
|
43
53
|
if (nonce !== void 0) {
|
|
44
|
-
const nonceStr = typeof nonce === "string" ||
|
|
54
|
+
const nonceStr = typeof nonce === "string" || isNumber(nonce) || isBigint(nonce) ? String(nonce) : shortJSON(nonce, 48);
|
|
45
55
|
parts.push(`nonce=${nonceStr}`);
|
|
46
56
|
}
|
|
47
57
|
return parts.length ? ` ${kv("Context", parts.join(" \u2022 "))}` : void 0;
|
|
@@ -71,17 +81,17 @@ function formatCause(c) {
|
|
|
71
81
|
const head = [];
|
|
72
82
|
if (obj.name !== void 0) {
|
|
73
83
|
const nameVal = obj.name;
|
|
74
|
-
const nameStr = typeof nameVal === "string" ||
|
|
84
|
+
const nameStr = typeof nameVal === "string" || isNumber(nameVal) || isBigint(nameVal) || typeof nameVal === "boolean" ? String(nameVal) : shortJSON(nameVal, 120);
|
|
75
85
|
head.push(`name=${nameStr}`);
|
|
76
86
|
}
|
|
77
87
|
if (obj.code !== void 0) {
|
|
78
88
|
const codeVal = obj.code;
|
|
79
|
-
const codeStr = typeof codeVal === "string" ||
|
|
89
|
+
const codeStr = typeof codeVal === "string" || isNumber(codeVal) || isBigint(codeVal) || typeof codeVal === "boolean" ? String(codeVal) : shortJSON(codeVal, 120);
|
|
80
90
|
head.push(`code=${codeStr}`);
|
|
81
91
|
}
|
|
82
92
|
if (head.length) out.push(` ${kv("Cause", head.join(" "))}`);
|
|
83
93
|
if (obj.message) {
|
|
84
|
-
const messageStr = typeof obj.message === "string" ||
|
|
94
|
+
const messageStr = typeof obj.message === "string" || isNumber(obj.message) || isBigint(obj.message) || typeof obj.message === "boolean" ? String(obj.message) : shortJSON(obj.message, 600);
|
|
85
95
|
out.push(` message=${elideMiddle(messageStr, 600)}`);
|
|
86
96
|
}
|
|
87
97
|
if (obj.data) {
|
|
@@ -160,20 +170,20 @@ function createError(type, input) {
|
|
|
160
170
|
return new ZKsyncError({ ...input, type });
|
|
161
171
|
}
|
|
162
172
|
function shapeCause(err) {
|
|
163
|
-
const
|
|
173
|
+
const isRecord2 = (x) => x !== null && typeof x === "object";
|
|
164
174
|
let data = void 0;
|
|
165
|
-
if (
|
|
175
|
+
if (isRecord2(err)) {
|
|
166
176
|
const r2 = err;
|
|
167
177
|
const d = r2.data;
|
|
168
|
-
if (
|
|
178
|
+
if (isRecord2(d) && "data" in d) {
|
|
169
179
|
data = d.data;
|
|
170
|
-
} else if ("error" in r2 &&
|
|
180
|
+
} else if ("error" in r2 && isRecord2(r2.error) && "data" in r2.error) {
|
|
171
181
|
data = r2.error.data;
|
|
172
182
|
} else if ("data" in r2) {
|
|
173
183
|
data = r2.data;
|
|
174
184
|
}
|
|
175
185
|
}
|
|
176
|
-
const r =
|
|
186
|
+
const r = isRecord2(err) ? err : void 0;
|
|
177
187
|
const name = r && typeof r.name === "string" ? r.name : void 0;
|
|
178
188
|
const message = r && typeof r.message === "string" ? r.message : r && typeof r.shortMessage === "string" ? r.shortMessage : void 0;
|
|
179
189
|
const code = r && "code" in r ? r.code : void 0;
|
|
@@ -206,6 +216,8 @@ var METHODS = {
|
|
|
206
216
|
getBridgehub: "zks_getBridgehubContract",
|
|
207
217
|
getL2ToL1LogProof: "zks_getL2ToL1LogProof",
|
|
208
218
|
getReceipt: "eth_getTransactionReceipt",
|
|
219
|
+
getBytecodeSupplier: "zks_getBytecodeSupplierContract",
|
|
220
|
+
getBlockMetadataByNumber: "zks_getBlockMetadataByNumber",
|
|
209
221
|
getGenesis: "zks_getGenesis"
|
|
210
222
|
};
|
|
211
223
|
function toHexArray(arr) {
|
|
@@ -225,7 +237,7 @@ function normalizeProof(p) {
|
|
|
225
237
|
context: { keys: Object.keys(raw ?? {}) }
|
|
226
238
|
});
|
|
227
239
|
}
|
|
228
|
-
const toBig = (x) =>
|
|
240
|
+
const toBig = (x) => isBigint(x) ? x : isNumber(x) ? BigInt(x) : typeof x === "string" ? BigInt(x) : (() => {
|
|
229
241
|
throw createError("RPC", {
|
|
230
242
|
resource: "zksrpc",
|
|
231
243
|
operation: "zksrpc.normalizeProof",
|
|
@@ -236,7 +248,8 @@ function normalizeProof(p) {
|
|
|
236
248
|
return {
|
|
237
249
|
id: toBig(idRaw),
|
|
238
250
|
batchNumber: toBig(bnRaw),
|
|
239
|
-
proof: toHexArray(raw?.proof)
|
|
251
|
+
proof: toHexArray(raw?.proof),
|
|
252
|
+
root: raw.root
|
|
240
253
|
};
|
|
241
254
|
} catch (e) {
|
|
242
255
|
if (isZKsyncError(e)) throw e;
|
|
@@ -258,20 +271,53 @@ function ensureHex(value, field, context) {
|
|
|
258
271
|
context: { field, valueType: typeof value, ...context }
|
|
259
272
|
});
|
|
260
273
|
}
|
|
261
|
-
function ensureNumber(value, field) {
|
|
262
|
-
|
|
263
|
-
|
|
274
|
+
function ensureNumber(value, field, opts) {
|
|
275
|
+
const operation = opts?.operation ?? "zksrpc.normalizeGenesis";
|
|
276
|
+
const messagePrefix = opts?.messagePrefix ?? "Malformed genesis response";
|
|
277
|
+
if (isNumber(value)) return value;
|
|
278
|
+
if (isBigint(value)) return Number(value);
|
|
264
279
|
if (typeof value === "string" && value.trim() !== "") {
|
|
265
280
|
const parsed = Number(value);
|
|
266
281
|
if (Number.isFinite(parsed)) return parsed;
|
|
267
282
|
}
|
|
268
283
|
throw createError("RPC", {
|
|
269
284
|
resource: "zksrpc",
|
|
270
|
-
operation
|
|
271
|
-
message:
|
|
285
|
+
operation,
|
|
286
|
+
message: `${messagePrefix}: expected numeric value.`,
|
|
287
|
+
context: { field, valueType: typeof value }
|
|
288
|
+
});
|
|
289
|
+
}
|
|
290
|
+
function ensureBigInt(value, field, opts) {
|
|
291
|
+
const operation = opts?.operation ?? "zksrpc.normalizeBlockMetadata";
|
|
292
|
+
const messagePrefix = opts?.messagePrefix ?? "Malformed block metadata response";
|
|
293
|
+
if (isBigint(value)) return value;
|
|
294
|
+
if (isNumber(value)) {
|
|
295
|
+
if (!Number.isInteger(value)) {
|
|
296
|
+
throw createError("RPC", {
|
|
297
|
+
resource: "zksrpc",
|
|
298
|
+
operation,
|
|
299
|
+
message: `${messagePrefix}: expected integer value.`,
|
|
300
|
+
context: { field, valueType: typeof value }
|
|
301
|
+
});
|
|
302
|
+
}
|
|
303
|
+
return BigInt(value);
|
|
304
|
+
}
|
|
305
|
+
if (typeof value === "string" && value.trim() !== "") {
|
|
306
|
+
try {
|
|
307
|
+
return BigInt(value);
|
|
308
|
+
} catch {
|
|
309
|
+
}
|
|
310
|
+
}
|
|
311
|
+
throw createError("RPC", {
|
|
312
|
+
resource: "zksrpc",
|
|
313
|
+
operation,
|
|
314
|
+
message: `${messagePrefix}: expected bigint-compatible value.`,
|
|
272
315
|
context: { field, valueType: typeof value }
|
|
273
316
|
});
|
|
274
317
|
}
|
|
318
|
+
function isRecord(x) {
|
|
319
|
+
return !!x && typeof x === "object" && !Array.isArray(x);
|
|
320
|
+
}
|
|
275
321
|
function normalizeContractTuple(tuple, index) {
|
|
276
322
|
if (!Array.isArray(tuple) || tuple.length < 2) {
|
|
277
323
|
throw createError("RPC", {
|
|
@@ -287,7 +333,7 @@ function normalizeContractTuple(tuple, index) {
|
|
|
287
333
|
bytecode: ensureHex(bytecodeRaw, "initial_contracts.bytecode", { index })
|
|
288
334
|
};
|
|
289
335
|
}
|
|
290
|
-
function
|
|
336
|
+
function normalizeRawStorageTuple(tuple, index) {
|
|
291
337
|
if (!Array.isArray(tuple) || tuple.length < 2) {
|
|
292
338
|
throw createError("RPC", {
|
|
293
339
|
resource: "zksrpc",
|
|
@@ -298,10 +344,53 @@ function normalizeStorageTuple(tuple, index) {
|
|
|
298
344
|
}
|
|
299
345
|
const [keyRaw, valueRaw] = tuple;
|
|
300
346
|
return {
|
|
347
|
+
format: "raw",
|
|
301
348
|
key: ensureHex(keyRaw, "additional_storage.key", { index }),
|
|
302
349
|
value: ensureHex(valueRaw, "additional_storage.value", { index })
|
|
303
350
|
};
|
|
304
351
|
}
|
|
352
|
+
function normalizeAdditionalStorage(value, record) {
|
|
353
|
+
const effective = value ?? record["additional_storage_raw"];
|
|
354
|
+
if (Array.isArray(effective)) {
|
|
355
|
+
return effective.map((entry, index) => {
|
|
356
|
+
const kv2 = normalizeRawStorageTuple(entry, index);
|
|
357
|
+
return { format: "raw", key: kv2.key, value: kv2.value };
|
|
358
|
+
});
|
|
359
|
+
}
|
|
360
|
+
if (isRecord(effective)) {
|
|
361
|
+
const out = [];
|
|
362
|
+
for (const [addrRaw, slotsRaw] of Object.entries(effective)) {
|
|
363
|
+
const address = ensureHex(addrRaw, "additional_storage.address", {});
|
|
364
|
+
if (!isRecord(slotsRaw)) {
|
|
365
|
+
throw createError("RPC", {
|
|
366
|
+
resource: "zksrpc",
|
|
367
|
+
operation: "zksrpc.normalizeGenesis",
|
|
368
|
+
message: "Malformed genesis response: additional_storage[address] must be an object map.",
|
|
369
|
+
context: { address, valueType: typeof slotsRaw }
|
|
370
|
+
});
|
|
371
|
+
}
|
|
372
|
+
for (const [slotRaw, valRaw] of Object.entries(slotsRaw)) {
|
|
373
|
+
out.push({
|
|
374
|
+
format: "pretty",
|
|
375
|
+
address,
|
|
376
|
+
key: ensureHex(slotRaw, "additional_storage.key", { address }),
|
|
377
|
+
value: ensureHex(valRaw, "additional_storage.value", { address, key: slotRaw })
|
|
378
|
+
});
|
|
379
|
+
}
|
|
380
|
+
}
|
|
381
|
+
return out;
|
|
382
|
+
}
|
|
383
|
+
throw createError("RPC", {
|
|
384
|
+
resource: "zksrpc",
|
|
385
|
+
operation: "zksrpc.normalizeGenesis",
|
|
386
|
+
message: "Malformed genesis response: additional_storage must be an array (raw) or an object map (pretty).",
|
|
387
|
+
context: {
|
|
388
|
+
valueType: typeof effective,
|
|
389
|
+
hasAdditionalStorage: "additional_storage" in record,
|
|
390
|
+
hasAdditionalStorageRaw: "additional_storage_raw" in record
|
|
391
|
+
}
|
|
392
|
+
});
|
|
393
|
+
}
|
|
305
394
|
function normalizeGenesis(raw) {
|
|
306
395
|
try {
|
|
307
396
|
if (!raw || typeof raw !== "object") {
|
|
@@ -322,21 +411,12 @@ function normalizeGenesis(raw) {
|
|
|
322
411
|
context: { valueType: typeof contractsRaw }
|
|
323
412
|
});
|
|
324
413
|
}
|
|
325
|
-
const storageRaw = record["additional_storage"];
|
|
326
|
-
if (!Array.isArray(storageRaw)) {
|
|
327
|
-
throw createError("RPC", {
|
|
328
|
-
resource: "zksrpc",
|
|
329
|
-
operation: "zksrpc.normalizeGenesis",
|
|
330
|
-
message: "Malformed genesis response: additional_storage must be an array.",
|
|
331
|
-
context: { valueType: typeof storageRaw }
|
|
332
|
-
});
|
|
333
|
-
}
|
|
334
414
|
const executionVersion = ensureNumber(record["execution_version"], "execution_version");
|
|
335
415
|
const genesisRoot = ensureHex(record["genesis_root"], "genesis_root", {});
|
|
336
416
|
const initialContracts = contractsRaw.map(
|
|
337
417
|
(entry, index) => normalizeContractTuple(entry, index)
|
|
338
418
|
);
|
|
339
|
-
const additionalStorage =
|
|
419
|
+
const additionalStorage = normalizeAdditionalStorage(record["additional_storage"], record);
|
|
340
420
|
return {
|
|
341
421
|
initialContracts,
|
|
342
422
|
additionalStorage,
|
|
@@ -354,6 +434,57 @@ function normalizeGenesis(raw) {
|
|
|
354
434
|
});
|
|
355
435
|
}
|
|
356
436
|
}
|
|
437
|
+
function normalizeBlockMetadata(raw) {
|
|
438
|
+
try {
|
|
439
|
+
if (!raw || typeof raw !== "object") {
|
|
440
|
+
throw createError("RPC", {
|
|
441
|
+
resource: "zksrpc",
|
|
442
|
+
operation: "zksrpc.normalizeBlockMetadata",
|
|
443
|
+
message: "Malformed block metadata response: expected object.",
|
|
444
|
+
context: { receivedType: typeof raw }
|
|
445
|
+
});
|
|
446
|
+
}
|
|
447
|
+
const record = raw;
|
|
448
|
+
const pubdataPricePerByte = ensureBigInt(
|
|
449
|
+
record["pubdata_price_per_byte"] ?? record["pubdataPricePerByte"],
|
|
450
|
+
"pubdata_price_per_byte",
|
|
451
|
+
{
|
|
452
|
+
operation: "zksrpc.normalizeBlockMetadata",
|
|
453
|
+
messagePrefix: "Malformed block metadata response"
|
|
454
|
+
}
|
|
455
|
+
);
|
|
456
|
+
const nativePrice = ensureBigInt(
|
|
457
|
+
record["native_price"] ?? record["nativePrice"],
|
|
458
|
+
"native_price",
|
|
459
|
+
{
|
|
460
|
+
operation: "zksrpc.normalizeBlockMetadata",
|
|
461
|
+
messagePrefix: "Malformed block metadata response"
|
|
462
|
+
}
|
|
463
|
+
);
|
|
464
|
+
const executionVersion = ensureNumber(
|
|
465
|
+
record["execution_version"] ?? record["executionVersion"],
|
|
466
|
+
"execution_version",
|
|
467
|
+
{
|
|
468
|
+
operation: "zksrpc.normalizeBlockMetadata",
|
|
469
|
+
messagePrefix: "Malformed block metadata response"
|
|
470
|
+
}
|
|
471
|
+
);
|
|
472
|
+
return {
|
|
473
|
+
pubdataPricePerByte,
|
|
474
|
+
nativePrice,
|
|
475
|
+
executionVersion
|
|
476
|
+
};
|
|
477
|
+
} catch (e) {
|
|
478
|
+
if (isZKsyncError(e)) throw e;
|
|
479
|
+
throw createError("RPC", {
|
|
480
|
+
resource: "zksrpc",
|
|
481
|
+
operation: "zksrpc.normalizeBlockMetadata",
|
|
482
|
+
message: "Failed to normalize block metadata response.",
|
|
483
|
+
context: { receivedType: typeof raw },
|
|
484
|
+
cause: shapeCause(e)
|
|
485
|
+
});
|
|
486
|
+
}
|
|
487
|
+
}
|
|
357
488
|
function createZksRpc(transport) {
|
|
358
489
|
return {
|
|
359
490
|
// Fetches the Bridgehub contract address.
|
|
@@ -376,6 +507,26 @@ function createZksRpc(transport) {
|
|
|
376
507
|
}
|
|
377
508
|
);
|
|
378
509
|
},
|
|
510
|
+
// Fetches the Bytecode Supplier contract address.
|
|
511
|
+
async getBytecodeSupplierAddress() {
|
|
512
|
+
return withRpcOp(
|
|
513
|
+
"zksrpc.getBytecodeSupplierAddress",
|
|
514
|
+
"Failed to fetch Bytecode Supplier address.",
|
|
515
|
+
{},
|
|
516
|
+
async () => {
|
|
517
|
+
const addrRaw = await transport(METHODS.getBytecodeSupplier, []);
|
|
518
|
+
if (typeof addrRaw !== "string" || !addrRaw.startsWith("0x")) {
|
|
519
|
+
throw createError("RPC", {
|
|
520
|
+
resource: "zksrpc",
|
|
521
|
+
operation: "zksrpc.getBytecodeSupplierAddress",
|
|
522
|
+
message: "Unexpected Bytecode Supplier address response.",
|
|
523
|
+
context: { valueType: typeof addrRaw }
|
|
524
|
+
});
|
|
525
|
+
}
|
|
526
|
+
return addrRaw;
|
|
527
|
+
}
|
|
528
|
+
);
|
|
529
|
+
},
|
|
379
530
|
// Fetches a proof for an L2→L1 log emitted in the given transaction.
|
|
380
531
|
async getL2ToL1LogProof(txHash, index) {
|
|
381
532
|
return withRpcOp(
|
|
@@ -412,6 +563,19 @@ function createZksRpc(transport) {
|
|
|
412
563
|
}
|
|
413
564
|
);
|
|
414
565
|
},
|
|
566
|
+
// Fetches block metadata for the given block number.
|
|
567
|
+
async getBlockMetadataByNumber(blockNumber) {
|
|
568
|
+
return withRpcOp(
|
|
569
|
+
"zksrpc.getBlockMetadataByNumber",
|
|
570
|
+
"Failed to fetch block metadata.",
|
|
571
|
+
{ blockNumber },
|
|
572
|
+
async () => {
|
|
573
|
+
const raw = await transport(METHODS.getBlockMetadataByNumber, [blockNumber]);
|
|
574
|
+
if (raw == null) return null;
|
|
575
|
+
return normalizeBlockMetadata(raw);
|
|
576
|
+
}
|
|
577
|
+
);
|
|
578
|
+
},
|
|
415
579
|
// Fetches the genesis configuration returned by `zks_getGenesis`.
|
|
416
580
|
async getGenesis() {
|
|
417
581
|
return withRpcOp(
|
|
@@ -437,12 +601,6 @@ function zksRpcFromEthers(l2Provider) {
|
|
|
437
601
|
}
|
|
438
602
|
return createZksRpc(makeTransportFromEthers(maybe));
|
|
439
603
|
}
|
|
440
|
-
var k256hex = (s) => `0x${utils.bytesToHex(sha3.keccak_256(utils.utf8ToBytes(s)))}`.toLowerCase();
|
|
441
|
-
var L2_ASSET_ROUTER_ADDRESS = "0x0000000000000000000000000000000000010003";
|
|
442
|
-
var L2_NATIVE_TOKEN_VAULT_ADDRESS = "0x0000000000000000000000000000000000010004";
|
|
443
|
-
var L2_BASE_TOKEN_ADDRESS = "0x000000000000000000000000000000000000800A";
|
|
444
|
-
k256hex("L1MessageSent(uint256,bytes32,bytes)");
|
|
445
|
-
k256hex("L1MessageSent(address,bytes32,bytes)");
|
|
446
604
|
|
|
447
605
|
// src/core/internal/abis/IBridgehub.ts
|
|
448
606
|
var IBridgehubABI = [
|
|
@@ -4931,6 +5089,56 @@ var MailboxABI = [
|
|
|
4931
5089
|
{ type: "error", name: "ZeroGasPriceL1TxZKSyncOS", inputs: [] }
|
|
4932
5090
|
];
|
|
4933
5091
|
var Mailbox_default = MailboxABI;
|
|
5092
|
+
|
|
5093
|
+
// src/core/errors/error-ops.ts
|
|
5094
|
+
function resolveMessage(op, msg) {
|
|
5095
|
+
if (!msg) return `Error during ${op}.`;
|
|
5096
|
+
return typeof msg === "function" ? msg() : msg;
|
|
5097
|
+
}
|
|
5098
|
+
function createErrorOps(decodeRevert2) {
|
|
5099
|
+
function toZKsyncError2(type, base, err) {
|
|
5100
|
+
if (isZKsyncError(err)) return err;
|
|
5101
|
+
const revert = decodeRevert2 ? decodeRevert2(err) : void 0;
|
|
5102
|
+
return createError(type, { ...base, ...revert ? { revert } : {}, cause: shapeCause(err) });
|
|
5103
|
+
}
|
|
5104
|
+
function createErrorHandlers2(resource) {
|
|
5105
|
+
async function run(kind, operation, fn, opts) {
|
|
5106
|
+
try {
|
|
5107
|
+
return await fn();
|
|
5108
|
+
} catch (e) {
|
|
5109
|
+
if (isZKsyncError(e)) throw e;
|
|
5110
|
+
const message = resolveMessage(operation, opts?.message);
|
|
5111
|
+
throw toZKsyncError2(kind, { resource, operation, context: opts?.ctx ?? {}, message }, e);
|
|
5112
|
+
}
|
|
5113
|
+
}
|
|
5114
|
+
function wrap(operation, fn, opts) {
|
|
5115
|
+
return run("INTERNAL", operation, fn, opts);
|
|
5116
|
+
}
|
|
5117
|
+
function wrapAs2(kind, operation, fn, opts) {
|
|
5118
|
+
return run(kind, operation, fn, opts);
|
|
5119
|
+
}
|
|
5120
|
+
async function toResult(operation, fn, opts) {
|
|
5121
|
+
try {
|
|
5122
|
+
const value = await wrap(operation, fn, opts);
|
|
5123
|
+
return { ok: true, value };
|
|
5124
|
+
} catch (e) {
|
|
5125
|
+
const shaped = isZKsyncError(e) ? e : toZKsyncError2(
|
|
5126
|
+
"INTERNAL",
|
|
5127
|
+
{
|
|
5128
|
+
resource,
|
|
5129
|
+
operation,
|
|
5130
|
+
context: opts?.ctx ?? {},
|
|
5131
|
+
message: resolveMessage(operation, opts?.message)
|
|
5132
|
+
},
|
|
5133
|
+
e
|
|
5134
|
+
);
|
|
5135
|
+
return { ok: false, error: shaped };
|
|
5136
|
+
}
|
|
5137
|
+
}
|
|
5138
|
+
return { wrap, wrapAs: wrapAs2, toResult };
|
|
5139
|
+
}
|
|
5140
|
+
return { toZKsyncError: toZKsyncError2, createErrorHandlers: createErrorHandlers2 };
|
|
5141
|
+
}
|
|
4934
5142
|
var ERROR_IFACES = [];
|
|
4935
5143
|
var IFACE_ERROR_STRING = new ethers.Interface(["error Error(string)"]);
|
|
4936
5144
|
var IFACE_PANIC = new ethers.Interface(["error Panic(uint256)"]);
|
|
@@ -5014,51 +5222,7 @@ function decodeRevert(e) {
|
|
|
5014
5222
|
}
|
|
5015
5223
|
|
|
5016
5224
|
// src/adapters/ethers/errors/error-ops.ts
|
|
5017
|
-
|
|
5018
|
-
if (isZKsyncError(err)) return err;
|
|
5019
|
-
const revert = decodeRevert(err);
|
|
5020
|
-
return createError(type, { ...base, ...revert ? { revert } : {}, cause: shapeCause(err) });
|
|
5021
|
-
}
|
|
5022
|
-
function resolveMessage(op, msg) {
|
|
5023
|
-
if (!msg) return `Error during ${op}.`;
|
|
5024
|
-
return typeof msg === "function" ? msg() : msg;
|
|
5025
|
-
}
|
|
5026
|
-
function createErrorHandlers(resource) {
|
|
5027
|
-
async function run(kind, operation, fn, opts) {
|
|
5028
|
-
try {
|
|
5029
|
-
return await fn();
|
|
5030
|
-
} catch (e) {
|
|
5031
|
-
if (isZKsyncError(e)) throw e;
|
|
5032
|
-
const message = resolveMessage(operation, opts?.message);
|
|
5033
|
-
throw toZKsyncError(kind, { resource, operation, context: opts?.ctx ?? {}, message }, e);
|
|
5034
|
-
}
|
|
5035
|
-
}
|
|
5036
|
-
function wrap(operation, fn, opts) {
|
|
5037
|
-
return run("INTERNAL", operation, fn, opts);
|
|
5038
|
-
}
|
|
5039
|
-
function wrapAs2(kind, operation, fn, opts) {
|
|
5040
|
-
return run(kind, operation, fn, opts);
|
|
5041
|
-
}
|
|
5042
|
-
async function toResult(operation, fn, opts) {
|
|
5043
|
-
try {
|
|
5044
|
-
const value = await wrap(operation, fn, opts);
|
|
5045
|
-
return { ok: true, value };
|
|
5046
|
-
} catch (e) {
|
|
5047
|
-
const shaped = isZKsyncError(e) ? e : toZKsyncError(
|
|
5048
|
-
"INTERNAL",
|
|
5049
|
-
{
|
|
5050
|
-
resource,
|
|
5051
|
-
operation,
|
|
5052
|
-
context: opts?.ctx ?? {},
|
|
5053
|
-
message: resolveMessage(operation, opts?.message)
|
|
5054
|
-
},
|
|
5055
|
-
e
|
|
5056
|
-
);
|
|
5057
|
-
return { ok: false, error: shaped };
|
|
5058
|
-
}
|
|
5059
|
-
}
|
|
5060
|
-
return { wrap, wrapAs: wrapAs2, toResult };
|
|
5061
|
-
}
|
|
5225
|
+
var { createErrorHandlers } = createErrorOps(decodeRevert);
|
|
5062
5226
|
|
|
5063
5227
|
// src/adapters/ethers/client.ts
|
|
5064
5228
|
var { wrapAs } = createErrorHandlers("client");
|