@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
@@ -345,6 +345,8 @@ var METHODS = {
345
345
  getBridgehub: "zks_getBridgehubContract",
346
346
  getL2ToL1LogProof: "zks_getL2ToL1LogProof",
347
347
  getReceipt: "eth_getTransactionReceipt",
348
+ getBytecodeSupplier: "zks_getBytecodeSupplierContract",
349
+ getBlockMetadataByNumber: "zks_getBlockMetadataByNumber",
348
350
  getGenesis: "zks_getGenesis"
349
351
  };
350
352
  function toHexArray(arr) {
@@ -397,7 +399,9 @@ function ensureHex(value, field, context) {
397
399
  context: { field, valueType: typeof value, ...context }
398
400
  });
399
401
  }
400
- function ensureNumber(value, field) {
402
+ function ensureNumber(value, field, opts) {
403
+ const operation = opts?.operation ?? "zksrpc.normalizeGenesis";
404
+ const messagePrefix = opts?.messagePrefix ?? "Malformed genesis response";
401
405
  if (typeof value === "number" && Number.isFinite(value)) return value;
402
406
  if (typeof value === "bigint") return Number(value);
403
407
  if (typeof value === "string" && value.trim() !== "") {
@@ -406,8 +410,36 @@ function ensureNumber(value, field) {
406
410
  }
407
411
  throw createError("RPC", {
408
412
  resource: "zksrpc",
409
- operation: "zksrpc.normalizeGenesis",
410
- message: "Malformed genesis response: expected numeric value.",
413
+ operation,
414
+ message: `${messagePrefix}: expected numeric value.`,
415
+ context: { field, valueType: typeof value }
416
+ });
417
+ }
418
+ function ensureBigInt(value, field, opts) {
419
+ const operation = opts?.operation ?? "zksrpc.normalizeBlockMetadata";
420
+ const messagePrefix = opts?.messagePrefix ?? "Malformed block metadata response";
421
+ if (typeof value === "bigint") return value;
422
+ if (typeof value === "number" && Number.isFinite(value)) {
423
+ if (!Number.isInteger(value)) {
424
+ throw createError("RPC", {
425
+ resource: "zksrpc",
426
+ operation,
427
+ message: `${messagePrefix}: expected integer value.`,
428
+ context: { field, valueType: typeof value }
429
+ });
430
+ }
431
+ return BigInt(value);
432
+ }
433
+ if (typeof value === "string" && value.trim() !== "") {
434
+ try {
435
+ return BigInt(value);
436
+ } catch {
437
+ }
438
+ }
439
+ throw createError("RPC", {
440
+ resource: "zksrpc",
441
+ operation,
442
+ message: `${messagePrefix}: expected bigint-compatible value.`,
411
443
  context: { field, valueType: typeof value }
412
444
  });
413
445
  }
@@ -493,6 +525,57 @@ function normalizeGenesis(raw) {
493
525
  });
494
526
  }
495
527
  }
528
+ function normalizeBlockMetadata(raw) {
529
+ try {
530
+ if (!raw || typeof raw !== "object") {
531
+ throw createError("RPC", {
532
+ resource: "zksrpc",
533
+ operation: "zksrpc.normalizeBlockMetadata",
534
+ message: "Malformed block metadata response: expected object.",
535
+ context: { receivedType: typeof raw }
536
+ });
537
+ }
538
+ const record = raw;
539
+ const pubdataPricePerByte = ensureBigInt(
540
+ record["pubdata_price_per_byte"] ?? record["pubdataPricePerByte"],
541
+ "pubdata_price_per_byte",
542
+ {
543
+ operation: "zksrpc.normalizeBlockMetadata",
544
+ messagePrefix: "Malformed block metadata response"
545
+ }
546
+ );
547
+ const nativePrice = ensureBigInt(
548
+ record["native_price"] ?? record["nativePrice"],
549
+ "native_price",
550
+ {
551
+ operation: "zksrpc.normalizeBlockMetadata",
552
+ messagePrefix: "Malformed block metadata response"
553
+ }
554
+ );
555
+ const executionVersion = ensureNumber(
556
+ record["execution_version"] ?? record["executionVersion"],
557
+ "execution_version",
558
+ {
559
+ operation: "zksrpc.normalizeBlockMetadata",
560
+ messagePrefix: "Malformed block metadata response"
561
+ }
562
+ );
563
+ return {
564
+ pubdataPricePerByte,
565
+ nativePrice,
566
+ executionVersion
567
+ };
568
+ } catch (e) {
569
+ if (isZKsyncError(e)) throw e;
570
+ throw createError("RPC", {
571
+ resource: "zksrpc",
572
+ operation: "zksrpc.normalizeBlockMetadata",
573
+ message: "Failed to normalize block metadata response.",
574
+ context: { receivedType: typeof raw },
575
+ cause: shapeCause(e)
576
+ });
577
+ }
578
+ }
496
579
  function createZksRpc(transport) {
497
580
  return {
498
581
  // Fetches the Bridgehub contract address.
@@ -515,6 +598,26 @@ function createZksRpc(transport) {
515
598
  }
516
599
  );
517
600
  },
601
+ // Fetches the Bytecode Supplier contract address.
602
+ async getBytecodeSupplierAddress() {
603
+ return withRpcOp(
604
+ "zksrpc.getBytecodeSupplierAddress",
605
+ "Failed to fetch Bytecode Supplier address.",
606
+ {},
607
+ async () => {
608
+ const addrRaw = await transport(METHODS.getBytecodeSupplier, []);
609
+ if (typeof addrRaw !== "string" || !addrRaw.startsWith("0x")) {
610
+ throw createError("RPC", {
611
+ resource: "zksrpc",
612
+ operation: "zksrpc.getBytecodeSupplierAddress",
613
+ message: "Unexpected Bytecode Supplier address response.",
614
+ context: { valueType: typeof addrRaw }
615
+ });
616
+ }
617
+ return addrRaw;
618
+ }
619
+ );
620
+ },
518
621
  // Fetches a proof for an L2→L1 log emitted in the given transaction.
519
622
  async getL2ToL1LogProof(txHash, index) {
520
623
  return withRpcOp(
@@ -551,6 +654,19 @@ function createZksRpc(transport) {
551
654
  }
552
655
  );
553
656
  },
657
+ // Fetches block metadata for the given block number.
658
+ async getBlockMetadataByNumber(blockNumber) {
659
+ return withRpcOp(
660
+ "zksrpc.getBlockMetadataByNumber",
661
+ "Failed to fetch block metadata.",
662
+ { blockNumber },
663
+ async () => {
664
+ const raw = await transport(METHODS.getBlockMetadataByNumber, [blockNumber]);
665
+ if (raw == null) return null;
666
+ return normalizeBlockMetadata(raw);
667
+ }
668
+ );
669
+ },
554
670
  // Fetches the genesis configuration returned by `zks_getGenesis`.
555
671
  async getGenesis() {
556
672
  return withRpcOp(
@@ -594,7 +710,7 @@ var TX_OVERHEAD_GAS = 10000n;
594
710
  var TX_MEMORY_OVERHEAD_GAS = 10n;
595
711
  var DEFAULT_PUBDATA_BYTES = 155n;
596
712
  var DEFAULT_ABI_BYTES = 400n;
597
- var SAFE_L1_BRIDGE_GAS = 600000n;
713
+ var SAFE_L1_BRIDGE_GAS = 700000n;
598
714
 
599
715
  // src/core/internal/abis/IBridgehub.ts
600
716
  var IBridgehubABI = [
@@ -5284,6 +5400,56 @@ function buildDirectRequestStruct(args) {
5284
5400
  };
5285
5401
  }
5286
5402
 
5403
+ // src/core/errors/error-ops.ts
5404
+ function resolveMessage(op, msg) {
5405
+ if (!msg) return `Error during ${op}.`;
5406
+ return typeof msg === "function" ? msg() : msg;
5407
+ }
5408
+ function createErrorOps(decodeRevert2) {
5409
+ function toZKsyncError2(type, base, err) {
5410
+ if (isZKsyncError(err)) return err;
5411
+ const revert = decodeRevert2 ? decodeRevert2(err) : void 0;
5412
+ return createError(type, { ...base, ...revert ? { revert } : {}, cause: shapeCause(err) });
5413
+ }
5414
+ function createErrorHandlers2(resource) {
5415
+ async function run(kind, operation, fn, opts) {
5416
+ try {
5417
+ return await fn();
5418
+ } catch (e) {
5419
+ if (isZKsyncError(e)) throw e;
5420
+ const message = resolveMessage(operation, opts?.message);
5421
+ throw toZKsyncError2(kind, { resource, operation, context: opts?.ctx ?? {}, message }, e);
5422
+ }
5423
+ }
5424
+ function wrap2(operation, fn, opts) {
5425
+ return run("INTERNAL", operation, fn, opts);
5426
+ }
5427
+ function wrapAs10(kind, operation, fn, opts) {
5428
+ return run(kind, operation, fn, opts);
5429
+ }
5430
+ async function toResult2(operation, fn, opts) {
5431
+ try {
5432
+ const value = await wrap2(operation, fn, opts);
5433
+ return { ok: true, value };
5434
+ } catch (e) {
5435
+ const shaped = isZKsyncError(e) ? e : toZKsyncError2(
5436
+ "INTERNAL",
5437
+ {
5438
+ resource,
5439
+ operation,
5440
+ context: opts?.ctx ?? {},
5441
+ message: resolveMessage(operation, opts?.message)
5442
+ },
5443
+ e
5444
+ );
5445
+ return { ok: false, error: shaped };
5446
+ }
5447
+ }
5448
+ return { wrap: wrap2, wrapAs: wrapAs10, toResult: toResult2 };
5449
+ }
5450
+ return { toZKsyncError: toZKsyncError2, createErrorHandlers: createErrorHandlers2 };
5451
+ }
5452
+
5287
5453
  // src/core/errors/withdrawal-revert-map.ts
5288
5454
  var REVERT_TO_READINESS = {
5289
5455
  // Already done
@@ -5413,51 +5579,7 @@ function classifyReadinessFromRevert(e) {
5413
5579
  }
5414
5580
 
5415
5581
  // src/adapters/viem/errors/error-ops.ts
5416
- function toZKsyncError(type, base, err) {
5417
- if (isZKsyncError(err)) return err;
5418
- const revert = decodeRevert(err);
5419
- return createError(type, { ...base, ...revert ? { revert } : {}, cause: shapeCause(err) });
5420
- }
5421
- function resolveMessage(op, msg) {
5422
- if (!msg) return `Error during ${op}.`;
5423
- return typeof msg === "function" ? msg() : msg;
5424
- }
5425
- function createErrorHandlers(resource) {
5426
- async function run(kind, operation, fn, opts) {
5427
- try {
5428
- return await fn();
5429
- } catch (e) {
5430
- if (isZKsyncError(e)) throw e;
5431
- const message = resolveMessage(operation, opts?.message);
5432
- throw toZKsyncError(kind, { resource, operation, context: opts?.ctx ?? {}, message }, e);
5433
- }
5434
- }
5435
- function wrap2(operation, fn, opts) {
5436
- return run("INTERNAL", operation, fn, opts);
5437
- }
5438
- function wrapAs10(kind, operation, fn, opts) {
5439
- return run(kind, operation, fn, opts);
5440
- }
5441
- async function toResult2(operation, fn, opts) {
5442
- try {
5443
- const value = await wrap2(operation, fn, opts);
5444
- return { ok: true, value };
5445
- } catch (e) {
5446
- const shaped = isZKsyncError(e) ? e : toZKsyncError(
5447
- "INTERNAL",
5448
- {
5449
- resource,
5450
- operation,
5451
- context: opts?.ctx ?? {},
5452
- message: resolveMessage(operation, opts?.message)
5453
- },
5454
- e
5455
- );
5456
- return { ok: false, error: shaped };
5457
- }
5458
- }
5459
- return { wrap: wrap2, wrapAs: wrapAs10, toResult: toResult2 };
5460
- }
5582
+ var { toZKsyncError, createErrorHandlers } = createErrorOps(decodeRevert);
5461
5583
 
5462
5584
  // src/core/resources/deposits/gas.ts
5463
5585
  function makeGasQuote(p) {