@matterlabs/zksync-js 0.0.6 → 0.0.7

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.
Files changed (46) hide show
  1. package/dist/adapters/ethers/client.cjs +170 -48
  2. package/dist/adapters/ethers/client.cjs.map +1 -1
  3. package/dist/adapters/ethers/client.js +6 -6
  4. package/dist/adapters/ethers/errors/error-ops.d.ts +26 -19
  5. package/dist/adapters/ethers/index.cjs +171 -49
  6. package/dist/adapters/ethers/index.cjs.map +1 -1
  7. package/dist/adapters/ethers/index.js +9 -9
  8. package/dist/adapters/ethers/sdk.cjs +52 -46
  9. package/dist/adapters/ethers/sdk.cjs.map +1 -1
  10. package/dist/adapters/ethers/sdk.js +7 -7
  11. package/dist/adapters/viem/client.cjs +119 -3
  12. package/dist/adapters/viem/client.cjs.map +1 -1
  13. package/dist/adapters/viem/client.js +4 -4
  14. package/dist/adapters/viem/errors/error-ops.d.ts +26 -19
  15. package/dist/adapters/viem/index.cjs +171 -49
  16. package/dist/adapters/viem/index.cjs.map +1 -1
  17. package/dist/adapters/viem/index.js +8 -8
  18. package/dist/adapters/viem/sdk.cjs +52 -46
  19. package/dist/adapters/viem/sdk.cjs.map +1 -1
  20. package/dist/adapters/viem/sdk.js +6 -6
  21. package/dist/{chunk-YUK547UF.js → chunk-7VP6742W.js} +3 -3
  22. package/dist/{chunk-WU2LOG2A.js → chunk-EWLA4NUE.js} +5 -5
  23. package/dist/{chunk-M5J2MM2U.js → chunk-GIXLOHLK.js} +1 -1
  24. package/dist/{chunk-XRE7H466.js → chunk-GNERKUWO.js} +3 -47
  25. package/dist/chunk-KAMEGD6I.js +75 -0
  26. package/dist/{chunk-2MDK3GLO.js → chunk-KRIRXY74.js} +7 -51
  27. package/dist/{chunk-F2ENUV3A.js → chunk-NCR42O6O.js} +1 -1
  28. package/dist/{chunk-3MRGU4HV.js → chunk-NGXRO2ZX.js} +4 -4
  29. package/dist/{chunk-LL3WKCFJ.js → chunk-NNFWIAVG.js} +2 -2
  30. package/dist/{chunk-NEC2ZKHI.js → chunk-P5PIWVEO.js} +1 -1
  31. package/dist/{chunk-NTEIA5KA.js → chunk-VRL6Y4YJ.js} +1 -1
  32. package/dist/{chunk-6K6VJQAL.js → chunk-WY36Z6YB.js} +122 -5
  33. package/dist/core/constants.cjs +1 -1
  34. package/dist/core/constants.d.ts +1 -1
  35. package/dist/core/constants.js +1 -1
  36. package/dist/core/errors/error-ops.d.ts +18 -0
  37. package/dist/core/index.cjs +120 -3
  38. package/dist/core/index.cjs.map +1 -1
  39. package/dist/core/index.js +5 -5
  40. package/dist/core/rpc/types.d.ts +5 -0
  41. package/dist/core/rpc/zks.d.ts +4 -1
  42. package/dist/index.cjs +121 -4
  43. package/dist/index.cjs.map +1 -1
  44. package/dist/index.js +5 -5
  45. package/package.json +1 -1
  46. package/dist/chunk-NCAIVYBR.js +0 -23
@@ -1,6 +1,6 @@
1
- export { createEthersClient } from '../../chunk-3MRGU4HV.js';
2
- import '../../chunk-XRE7H466.js';
3
- import '../../chunk-NCAIVYBR.js';
4
- import '../../chunk-6K6VJQAL.js';
5
- import '../../chunk-M5J2MM2U.js';
6
- import '../../chunk-F2ENUV3A.js';
1
+ export { createEthersClient } from '../../chunk-NGXRO2ZX.js';
2
+ import '../../chunk-GNERKUWO.js';
3
+ import '../../chunk-KAMEGD6I.js';
4
+ import '../../chunk-WY36Z6YB.js';
5
+ import '../../chunk-GIXLOHLK.js';
6
+ import '../../chunk-NCR42O6O.js';
@@ -1,20 +1,27 @@
1
- import { type TryResult, type ErrorEnvelope, type ErrorType, type Resource } from '../../../core/types/errors';
2
- type Ctx = Record<string, unknown>;
3
- export declare function toZKsyncError(type: ErrorType, base: Omit<ErrorEnvelope, 'type' | 'revert' | 'cause'>, err: unknown): import("../../..").ZKsyncError;
4
- type WrapOptions<TCtx extends Ctx = Ctx> = {
5
- /** Optional contextual data for debugging */
6
- ctx?: TCtx;
7
- /** Optional error message */
8
- message?: string | (() => string);
1
+ declare const toZKsyncError: (type: import("../../..").ErrorType, base: Omit<import("../../..").ErrorEnvelope, "type" | "revert" | "cause">, err: unknown) => import("../../..").ZKsyncError, createErrorHandlers: (resource: import("../../..").Resource) => {
2
+ wrap: <T, TCtx extends {
3
+ [x: string]: unknown;
4
+ } = {
5
+ [x: string]: unknown;
6
+ }>(operation: string, fn: () => T | Promise<T>, opts?: {
7
+ ctx?: TCtx | undefined;
8
+ message?: string | (() => string);
9
+ }) => Promise<T>;
10
+ wrapAs: <T, TCtx extends {
11
+ [x: string]: unknown;
12
+ } = {
13
+ [x: string]: unknown;
14
+ }>(kind: import("../../..").ErrorType, operation: string, fn: () => T | Promise<T>, opts?: {
15
+ ctx?: TCtx | undefined;
16
+ message?: string | (() => string);
17
+ }) => Promise<T>;
18
+ toResult: <T, TCtx extends {
19
+ [x: string]: unknown;
20
+ } = {
21
+ [x: string]: unknown;
22
+ }>(operation: string, fn: () => T | Promise<T>, opts?: {
23
+ ctx?: TCtx | undefined;
24
+ message?: string | (() => string);
25
+ }) => Promise<import("../../..").TryResult<T>>;
9
26
  };
10
- /**
11
- * Factory for resource-scoped error handlers.
12
- * Example:
13
- * const { wrap, wrapAs, toResult } = createErrorHandlers('deposits');
14
- */
15
- export declare function createErrorHandlers(resource: Resource): {
16
- wrap: <T, TCtx extends Ctx = Ctx>(operation: string, fn: () => T | Promise<T>, opts?: WrapOptions<TCtx>) => Promise<T>;
17
- wrapAs: <T, TCtx extends Ctx = Ctx>(kind: ErrorType, operation: string, fn: () => T | Promise<T>, opts?: WrapOptions<TCtx>) => Promise<T>;
18
- toResult: <T, TCtx extends Ctx = Ctx>(operation: string, fn: () => T | Promise<T>, opts?: WrapOptions<TCtx>) => Promise<TryResult<T>>;
19
- };
20
- export {};
27
+ export { toZKsyncError, createErrorHandlers };
@@ -343,6 +343,8 @@ var METHODS = {
343
343
  getBridgehub: "zks_getBridgehubContract",
344
344
  getL2ToL1LogProof: "zks_getL2ToL1LogProof",
345
345
  getReceipt: "eth_getTransactionReceipt",
346
+ getBytecodeSupplier: "zks_getBytecodeSupplierContract",
347
+ getBlockMetadataByNumber: "zks_getBlockMetadataByNumber",
346
348
  getGenesis: "zks_getGenesis"
347
349
  };
348
350
  function toHexArray(arr) {
@@ -395,7 +397,9 @@ function ensureHex(value, field, context) {
395
397
  context: { field, valueType: typeof value, ...context }
396
398
  });
397
399
  }
398
- function ensureNumber(value, field) {
400
+ function ensureNumber(value, field, opts) {
401
+ const operation = opts?.operation ?? "zksrpc.normalizeGenesis";
402
+ const messagePrefix = opts?.messagePrefix ?? "Malformed genesis response";
399
403
  if (typeof value === "number" && Number.isFinite(value)) return value;
400
404
  if (typeof value === "bigint") return Number(value);
401
405
  if (typeof value === "string" && value.trim() !== "") {
@@ -404,8 +408,36 @@ function ensureNumber(value, field) {
404
408
  }
405
409
  throw createError("RPC", {
406
410
  resource: "zksrpc",
407
- operation: "zksrpc.normalizeGenesis",
408
- message: "Malformed genesis response: expected numeric value.",
411
+ operation,
412
+ message: `${messagePrefix}: expected numeric value.`,
413
+ context: { field, valueType: typeof value }
414
+ });
415
+ }
416
+ function ensureBigInt(value, field, opts) {
417
+ const operation = opts?.operation ?? "zksrpc.normalizeBlockMetadata";
418
+ const messagePrefix = opts?.messagePrefix ?? "Malformed block metadata response";
419
+ if (typeof value === "bigint") return value;
420
+ if (typeof value === "number" && Number.isFinite(value)) {
421
+ if (!Number.isInteger(value)) {
422
+ throw createError("RPC", {
423
+ resource: "zksrpc",
424
+ operation,
425
+ message: `${messagePrefix}: expected integer value.`,
426
+ context: { field, valueType: typeof value }
427
+ });
428
+ }
429
+ return BigInt(value);
430
+ }
431
+ if (typeof value === "string" && value.trim() !== "") {
432
+ try {
433
+ return BigInt(value);
434
+ } catch {
435
+ }
436
+ }
437
+ throw createError("RPC", {
438
+ resource: "zksrpc",
439
+ operation,
440
+ message: `${messagePrefix}: expected bigint-compatible value.`,
409
441
  context: { field, valueType: typeof value }
410
442
  });
411
443
  }
@@ -491,6 +523,57 @@ function normalizeGenesis(raw) {
491
523
  });
492
524
  }
493
525
  }
526
+ function normalizeBlockMetadata(raw) {
527
+ try {
528
+ if (!raw || typeof raw !== "object") {
529
+ throw createError("RPC", {
530
+ resource: "zksrpc",
531
+ operation: "zksrpc.normalizeBlockMetadata",
532
+ message: "Malformed block metadata response: expected object.",
533
+ context: { receivedType: typeof raw }
534
+ });
535
+ }
536
+ const record = raw;
537
+ const pubdataPricePerByte = ensureBigInt(
538
+ record["pubdata_price_per_byte"] ?? record["pubdataPricePerByte"],
539
+ "pubdata_price_per_byte",
540
+ {
541
+ operation: "zksrpc.normalizeBlockMetadata",
542
+ messagePrefix: "Malformed block metadata response"
543
+ }
544
+ );
545
+ const nativePrice = ensureBigInt(
546
+ record["native_price"] ?? record["nativePrice"],
547
+ "native_price",
548
+ {
549
+ operation: "zksrpc.normalizeBlockMetadata",
550
+ messagePrefix: "Malformed block metadata response"
551
+ }
552
+ );
553
+ const executionVersion = ensureNumber(
554
+ record["execution_version"] ?? record["executionVersion"],
555
+ "execution_version",
556
+ {
557
+ operation: "zksrpc.normalizeBlockMetadata",
558
+ messagePrefix: "Malformed block metadata response"
559
+ }
560
+ );
561
+ return {
562
+ pubdataPricePerByte,
563
+ nativePrice,
564
+ executionVersion
565
+ };
566
+ } catch (e) {
567
+ if (isZKsyncError(e)) throw e;
568
+ throw createError("RPC", {
569
+ resource: "zksrpc",
570
+ operation: "zksrpc.normalizeBlockMetadata",
571
+ message: "Failed to normalize block metadata response.",
572
+ context: { receivedType: typeof raw },
573
+ cause: shapeCause(e)
574
+ });
575
+ }
576
+ }
494
577
  function createZksRpc(transport) {
495
578
  return {
496
579
  // Fetches the Bridgehub contract address.
@@ -513,6 +596,26 @@ function createZksRpc(transport) {
513
596
  }
514
597
  );
515
598
  },
599
+ // Fetches the Bytecode Supplier contract address.
600
+ async getBytecodeSupplierAddress() {
601
+ return withRpcOp(
602
+ "zksrpc.getBytecodeSupplierAddress",
603
+ "Failed to fetch Bytecode Supplier address.",
604
+ {},
605
+ async () => {
606
+ const addrRaw = await transport(METHODS.getBytecodeSupplier, []);
607
+ if (typeof addrRaw !== "string" || !addrRaw.startsWith("0x")) {
608
+ throw createError("RPC", {
609
+ resource: "zksrpc",
610
+ operation: "zksrpc.getBytecodeSupplierAddress",
611
+ message: "Unexpected Bytecode Supplier address response.",
612
+ context: { valueType: typeof addrRaw }
613
+ });
614
+ }
615
+ return addrRaw;
616
+ }
617
+ );
618
+ },
516
619
  // Fetches a proof for an L2→L1 log emitted in the given transaction.
517
620
  async getL2ToL1LogProof(txHash, index) {
518
621
  return withRpcOp(
@@ -549,6 +652,19 @@ function createZksRpc(transport) {
549
652
  }
550
653
  );
551
654
  },
655
+ // Fetches block metadata for the given block number.
656
+ async getBlockMetadataByNumber(blockNumber) {
657
+ return withRpcOp(
658
+ "zksrpc.getBlockMetadataByNumber",
659
+ "Failed to fetch block metadata.",
660
+ { blockNumber },
661
+ async () => {
662
+ const raw = await transport(METHODS.getBlockMetadataByNumber, [blockNumber]);
663
+ if (raw == null) return null;
664
+ return normalizeBlockMetadata(raw);
665
+ }
666
+ );
667
+ },
552
668
  // Fetches the genesis configuration returned by `zks_getGenesis`.
553
669
  async getGenesis() {
554
670
  return withRpcOp(
@@ -590,7 +706,7 @@ var TX_OVERHEAD_GAS = 10000n;
590
706
  var TX_MEMORY_OVERHEAD_GAS = 10n;
591
707
  var DEFAULT_PUBDATA_BYTES = 155n;
592
708
  var DEFAULT_ABI_BYTES = 400n;
593
- var SAFE_L1_BRIDGE_GAS = 600000n;
709
+ var SAFE_L1_BRIDGE_GAS = 700000n;
594
710
 
595
711
  // src/core/internal/abis/IBridgehub.ts
596
712
  var IBridgehubABI = [
@@ -5080,6 +5196,56 @@ var MailboxABI = [
5080
5196
  ];
5081
5197
  var Mailbox_default = MailboxABI;
5082
5198
 
5199
+ // src/core/errors/error-ops.ts
5200
+ function resolveMessage(op, msg) {
5201
+ if (!msg) return `Error during ${op}.`;
5202
+ return typeof msg === "function" ? msg() : msg;
5203
+ }
5204
+ function createErrorOps(decodeRevert2) {
5205
+ function toZKsyncError2(type, base, err) {
5206
+ if (isZKsyncError(err)) return err;
5207
+ const revert = decodeRevert2 ? decodeRevert2(err) : void 0;
5208
+ return createError(type, { ...base, ...revert ? { revert } : {}, cause: shapeCause(err) });
5209
+ }
5210
+ function createErrorHandlers2(resource) {
5211
+ async function run(kind, operation, fn, opts) {
5212
+ try {
5213
+ return await fn();
5214
+ } catch (e) {
5215
+ if (isZKsyncError(e)) throw e;
5216
+ const message = resolveMessage(operation, opts?.message);
5217
+ throw toZKsyncError2(kind, { resource, operation, context: opts?.ctx ?? {}, message }, e);
5218
+ }
5219
+ }
5220
+ function wrap2(operation, fn, opts) {
5221
+ return run("INTERNAL", operation, fn, opts);
5222
+ }
5223
+ function wrapAs10(kind, operation, fn, opts) {
5224
+ return run(kind, operation, fn, opts);
5225
+ }
5226
+ async function toResult2(operation, fn, opts) {
5227
+ try {
5228
+ const value = await wrap2(operation, fn, opts);
5229
+ return { ok: true, value };
5230
+ } catch (e) {
5231
+ const shaped = isZKsyncError(e) ? e : toZKsyncError2(
5232
+ "INTERNAL",
5233
+ {
5234
+ resource,
5235
+ operation,
5236
+ context: opts?.ctx ?? {},
5237
+ message: resolveMessage(operation, opts?.message)
5238
+ },
5239
+ e
5240
+ );
5241
+ return { ok: false, error: shaped };
5242
+ }
5243
+ }
5244
+ return { wrap: wrap2, wrapAs: wrapAs10, toResult: toResult2 };
5245
+ }
5246
+ return { toZKsyncError: toZKsyncError2, createErrorHandlers: createErrorHandlers2 };
5247
+ }
5248
+
5083
5249
  // src/core/errors/withdrawal-revert-map.ts
5084
5250
  var REVERT_TO_READINESS = {
5085
5251
  // Already done
@@ -5209,51 +5375,7 @@ function classifyReadinessFromRevert(e) {
5209
5375
  }
5210
5376
 
5211
5377
  // src/adapters/ethers/errors/error-ops.ts
5212
- function toZKsyncError(type, base, err) {
5213
- if (isZKsyncError(err)) return err;
5214
- const revert = decodeRevert(err);
5215
- return createError(type, { ...base, ...revert ? { revert } : {}, cause: shapeCause(err) });
5216
- }
5217
- function resolveMessage(op, msg) {
5218
- if (!msg) return `Error during ${op}.`;
5219
- return typeof msg === "function" ? msg() : msg;
5220
- }
5221
- function createErrorHandlers(resource) {
5222
- async function run(kind, operation, fn, opts) {
5223
- try {
5224
- return await fn();
5225
- } catch (e) {
5226
- if (isZKsyncError(e)) throw e;
5227
- const message = resolveMessage(operation, opts?.message);
5228
- throw toZKsyncError(kind, { resource, operation, context: opts?.ctx ?? {}, message }, e);
5229
- }
5230
- }
5231
- function wrap2(operation, fn, opts) {
5232
- return run("INTERNAL", operation, fn, opts);
5233
- }
5234
- function wrapAs10(kind, operation, fn, opts) {
5235
- return run(kind, operation, fn, opts);
5236
- }
5237
- async function toResult2(operation, fn, opts) {
5238
- try {
5239
- const value = await wrap2(operation, fn, opts);
5240
- return { ok: true, value };
5241
- } catch (e) {
5242
- const shaped = isZKsyncError(e) ? e : toZKsyncError(
5243
- "INTERNAL",
5244
- {
5245
- resource,
5246
- operation,
5247
- context: opts?.ctx ?? {},
5248
- message: resolveMessage(operation, opts?.message)
5249
- },
5250
- e
5251
- );
5252
- return { ok: false, error: shaped };
5253
- }
5254
- }
5255
- return { wrap: wrap2, wrapAs: wrapAs10, toResult: toResult2 };
5256
- }
5378
+ var { toZKsyncError, createErrorHandlers } = createErrorOps(decodeRevert);
5257
5379
 
5258
5380
  // src/adapters/ethers/client.ts
5259
5381
  var { wrapAs } = createErrorHandlers("client");