@matterlabs/zksync-js 0.0.13 → 0.0.15

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 (96) hide show
  1. package/dist/adapters/ethers/client.cjs +13 -4
  2. package/dist/adapters/ethers/client.cjs.map +1 -1
  3. package/dist/adapters/ethers/client.d.ts +1 -2
  4. package/dist/adapters/ethers/client.js +6 -6
  5. package/dist/adapters/ethers/index.cjs +607 -259
  6. package/dist/adapters/ethers/index.cjs.map +1 -1
  7. package/dist/adapters/ethers/index.js +9 -9
  8. package/dist/adapters/ethers/resources/deposits/routes/priority.d.ts +12 -0
  9. package/dist/adapters/ethers/resources/deposits/services/gas.d.ts +4 -0
  10. package/dist/adapters/ethers/resources/interop/index.d.ts +14 -14
  11. package/dist/adapters/ethers/resources/interop/resolvers.d.ts +3 -8
  12. package/dist/adapters/ethers/resources/interop/routes/types.d.ts +2 -1
  13. package/dist/adapters/ethers/resources/interop/services/erc20.d.ts +10 -0
  14. package/dist/adapters/ethers/resources/interop/services/fee.d.ts +12 -0
  15. package/dist/adapters/ethers/resources/interop/services/finalization/index.d.ts +1 -1
  16. package/dist/adapters/ethers/resources/interop/services/finalization/polling.d.ts +1 -1
  17. package/dist/adapters/ethers/resources/interop/services/gas.d.ts +12 -0
  18. package/dist/adapters/ethers/resources/interop/types.d.ts +6 -14
  19. package/dist/adapters/ethers/sdk.cjs +1008 -259
  20. package/dist/adapters/ethers/sdk.cjs.map +1 -1
  21. package/dist/adapters/ethers/sdk.d.ts +6 -1
  22. package/dist/adapters/ethers/sdk.js +7 -7
  23. package/dist/adapters/viem/client.cjs +795 -7
  24. package/dist/adapters/viem/client.cjs.map +1 -1
  25. package/dist/adapters/viem/client.d.ts +6 -1
  26. package/dist/adapters/viem/client.js +6 -6
  27. package/dist/adapters/viem/index.cjs +6490 -2799
  28. package/dist/adapters/viem/index.cjs.map +1 -1
  29. package/dist/adapters/viem/index.d.ts +5 -0
  30. package/dist/adapters/viem/index.js +9 -9
  31. package/dist/adapters/viem/resources/deposits/routes/priority.d.ts +13 -0
  32. package/dist/adapters/viem/resources/deposits/services/gas.d.ts +4 -0
  33. package/dist/adapters/viem/resources/interop/address.d.ts +18 -0
  34. package/dist/adapters/viem/resources/interop/attributes/resource.d.ts +6 -0
  35. package/dist/adapters/viem/resources/interop/context.d.ts +31 -0
  36. package/dist/adapters/viem/resources/interop/index.d.ts +62 -0
  37. package/dist/adapters/viem/resources/interop/resolvers.d.ts +4 -0
  38. package/dist/adapters/viem/resources/interop/routes/direct.d.ts +2 -0
  39. package/dist/adapters/viem/resources/interop/routes/indirect.d.ts +2 -0
  40. package/dist/adapters/viem/resources/interop/routes/types.d.ts +23 -0
  41. package/dist/adapters/viem/resources/interop/services/erc20.d.ts +25 -0
  42. package/dist/adapters/viem/resources/interop/services/fee.d.ts +12 -0
  43. package/dist/adapters/viem/resources/interop/services/finalization/bundle.d.ts +15 -0
  44. package/dist/adapters/viem/resources/interop/services/finalization/data-fetchers.d.ts +17 -0
  45. package/dist/adapters/viem/resources/interop/services/finalization/decoders.d.ts +11 -0
  46. package/dist/adapters/viem/resources/interop/services/finalization/index.d.ts +13 -0
  47. package/dist/adapters/viem/resources/interop/services/finalization/polling.d.ts +7 -0
  48. package/dist/adapters/viem/resources/interop/services/finalization/status.d.ts +5 -0
  49. package/dist/adapters/viem/resources/interop/services/finalization/topics.d.ts +4 -0
  50. package/dist/adapters/viem/resources/interop/services/gas.d.ts +12 -0
  51. package/dist/adapters/viem/resources/interop/services/starter-data.d.ts +6 -0
  52. package/dist/adapters/viem/resources/interop/types.d.ts +8 -0
  53. package/dist/adapters/viem/sdk.cjs +6401 -2758
  54. package/dist/adapters/viem/sdk.cjs.map +1 -1
  55. package/dist/adapters/viem/sdk.d.ts +8 -1
  56. package/dist/adapters/viem/sdk.js +7 -7
  57. package/dist/{chunk-E3KP7XCG.js → chunk-3HHUZXSV.js} +1 -1
  58. package/dist/{chunk-EDWBCPO3.js → chunk-4PZCNTQ3.js} +1387 -71
  59. package/dist/{chunk-UDBRUBEK.js → chunk-65HAYKVL.js} +2 -2
  60. package/dist/chunk-BWKWWLY4.js +9 -0
  61. package/dist/{chunk-JHO2UQ5F.js → chunk-HGB3DOV2.js} +445 -554
  62. package/dist/{chunk-HI64OOAR.js → chunk-HVHMLAYH.js} +1 -1
  63. package/dist/{chunk-2RIARDXZ.js → chunk-JHRYNLZG.js} +65 -7
  64. package/dist/{chunk-RI73VJSH.js → chunk-JXR5V5YK.js} +463 -27
  65. package/dist/chunk-K2UVKMLN.js +658 -0
  66. package/dist/{chunk-53MC5BR2.js → chunk-MDPX5LNW.js} +1 -1
  67. package/dist/{chunk-QQ2OR434.js → chunk-MT4X5FEO.js} +18 -2
  68. package/dist/{chunk-R5WRFPK2.js → chunk-MZBKM3GH.js} +4 -4
  69. package/dist/{chunk-5R7L5NM5.js → chunk-YIWXIP2M.js} +10 -2
  70. package/dist/core/constants.cjs +17 -1
  71. package/dist/core/constants.cjs.map +1 -1
  72. package/dist/core/constants.d.ts +9 -1
  73. package/dist/core/constants.js +1 -1
  74. package/dist/core/index.cjs +52 -24
  75. package/dist/core/index.cjs.map +1 -1
  76. package/dist/core/index.js +5 -5
  77. package/dist/core/internal/abis/IERC7786Attributes.d.ts +21 -11
  78. package/dist/core/internal/abis/IInteropCenter.d.ts +4 -0
  79. package/dist/core/resources/deposits/chains.d.ts +1 -0
  80. package/dist/core/resources/deposits/gas.d.ts +7 -0
  81. package/dist/core/resources/deposits/priority.d.ts +41 -0
  82. package/dist/core/resources/interop/attributes/bundle.d.ts +1 -0
  83. package/dist/core/resources/interop/attributes/resource.d.ts +1 -0
  84. package/dist/core/resources/interop/plan.d.ts +11 -3
  85. package/dist/core/resources/interop/protocol.d.ts +3 -0
  86. package/dist/core/rpc/types.d.ts +1 -0
  87. package/dist/core/rpc/zks.d.ts +5 -1
  88. package/dist/core/types/errors.d.ts +5 -0
  89. package/dist/core/types/flows/interop.d.ts +11 -20
  90. package/dist/core/types/primitives.d.ts +2 -0
  91. package/dist/index.cjs +69 -25
  92. package/dist/index.cjs.map +1 -1
  93. package/dist/index.js +5 -5
  94. package/package.json +1 -1
  95. package/dist/chunk-4S4XDA4N.js +0 -415
  96. package/dist/chunk-5L6EYUJB.js +0 -237
@@ -1,4 +1,4 @@
1
- import { isETH, normalizeAddrEq } from './chunk-RI73VJSH.js';
1
+ import { isETH, normalizeAddrEq } from './chunk-JXR5V5YK.js';
2
2
 
3
3
  // src/core/resources/deposits/route.ts
4
4
  async function pickDepositRoute(client, chainIdL2, token) {
@@ -1,8 +1,8 @@
1
- import { createErrorHandlers } from './chunk-5R7L5NM5.js';
2
- import { createZksRpc, makeTransportFromViem } from './chunk-4S4XDA4N.js';
3
- import { OP_CLIENT, IBridgehub_default, IL1AssetRouter_default, IL1Nullifier_default, IBaseToken_default, L2NativeTokenVault_default, IL2AssetRouter_default, L1NativeTokenVault_default } from './chunk-RI73VJSH.js';
4
- import { L2_ASSET_ROUTER_ADDRESS, L2_NATIVE_TOKEN_VAULT_ADDRESS, L2_BASE_TOKEN_ADDRESS } from './chunk-QQ2OR434.js';
5
- import { getContract, createWalletClient } from 'viem';
1
+ import { createErrorHandlers } from './chunk-YIWXIP2M.js';
2
+ import { makeTransportFromViem } from './chunk-BWKWWLY4.js';
3
+ import { OP_CLIENT, IBridgehub_default, IL1AssetRouter_default, IL1Nullifier_default, IBaseToken_default, L2NativeTokenVault_default, IL2AssetRouter_default, L1NativeTokenVault_default, createError, createZksRpc } from './chunk-JXR5V5YK.js';
4
+ import { L2_ASSET_ROUTER_ADDRESS, L2_NATIVE_TOKEN_VAULT_ADDRESS, L2_BASE_TOKEN_ADDRESS, L2_INTEROP_CENTER_ADDRESS, L2_INTEROP_HANDLER_ADDRESS, L2_MESSAGE_VERIFICATION_ADDRESS, FORMAL_ETH_ADDRESS } from './chunk-MT4X5FEO.js';
5
+ import { getContract, createWalletClient, custom } from 'viem';
6
6
 
7
7
  // src/adapters/viem/rpc.ts
8
8
  function zksRpcFromViem(l2Client) {
@@ -14,6 +14,15 @@ function zksRpcFromViem(l2Client) {
14
14
 
15
15
  // src/adapters/viem/client.ts
16
16
  var { wrap } = createErrorHandlers("client");
17
+ var ChainTypeManagerABI = [
18
+ {
19
+ type: "function",
20
+ name: "getSemverProtocolVersion",
21
+ inputs: [],
22
+ outputs: [{ type: "uint32" }, { type: "uint32" }, { type: "uint32" }],
23
+ stateMutability: "view"
24
+ }
25
+ ];
17
26
  function createViemClient(args) {
18
27
  const { l1, l2, l1Wallet, l2Wallet } = args;
19
28
  if (!l1Wallet.account) {
@@ -47,6 +56,9 @@ function createViemClient(args) {
47
56
  const l2AssetRouter = args.overrides?.l2AssetRouter ?? L2_ASSET_ROUTER_ADDRESS;
48
57
  const l2NativeTokenVault = args.overrides?.l2NativeTokenVault ?? L2_NATIVE_TOKEN_VAULT_ADDRESS;
49
58
  const l2BaseTokenSystem = args.overrides?.l2BaseTokenSystem ?? L2_BASE_TOKEN_ADDRESS;
59
+ const interopCenter = args.overrides?.interopCenter ?? L2_INTEROP_CENTER_ADDRESS;
60
+ const interopHandler = args.overrides?.interopHandler ?? L2_INTEROP_HANDLER_ADDRESS;
61
+ const l2MessageVerification = args.overrides?.l2MessageVerification ?? L2_MESSAGE_VERIFICATION_ADDRESS;
50
62
  addrCache = {
51
63
  bridgehub,
52
64
  l1AssetRouter,
@@ -54,7 +66,10 @@ function createViemClient(args) {
54
66
  l1NativeTokenVault,
55
67
  l2AssetRouter,
56
68
  l2NativeTokenVault,
57
- l2BaseTokenSystem
69
+ l2BaseTokenSystem,
70
+ interopCenter,
71
+ interopHandler,
72
+ l2MessageVerification
58
73
  };
59
74
  return addrCache;
60
75
  },
@@ -104,13 +119,55 @@ function createViemClient(args) {
104
119
  });
105
120
  return token;
106
121
  }
122
+ async function getProtocolVersion(chainId) {
123
+ const targetChainId = chainId ?? BigInt(await l2.getChainId());
124
+ const { bridgehub } = await ensureAddresses();
125
+ const chainTypeManager = await wrap(
126
+ OP_CLIENT.getSemverProtocolVersion,
127
+ () => l1.readContract({
128
+ address: bridgehub,
129
+ abi: IBridgehub_default,
130
+ functionName: "chainTypeManager",
131
+ args: [targetChainId]
132
+ }),
133
+ {
134
+ ctx: { where: "bridgehub.chainTypeManager", bridgehub, chainId: targetChainId },
135
+ message: "Failed to read chain type manager."
136
+ }
137
+ );
138
+ if (chainTypeManager.toLowerCase() === FORMAL_ETH_ADDRESS.toLowerCase()) {
139
+ throw createError("STATE", {
140
+ resource: "client",
141
+ operation: OP_CLIENT.getSemverProtocolVersion,
142
+ message: "No registered chain type manager for the chain.",
143
+ context: { chainId }
144
+ });
145
+ }
146
+ const semver = await wrap(
147
+ OP_CLIENT.getSemverProtocolVersion,
148
+ () => l1.readContract({
149
+ address: chainTypeManager,
150
+ abi: ChainTypeManagerABI,
151
+ functionName: "getSemverProtocolVersion"
152
+ }),
153
+ {
154
+ ctx: {
155
+ where: "chainTypeManager.getSemverProtocolVersion",
156
+ chainId: targetChainId,
157
+ chainTypeManager
158
+ },
159
+ message: "Failed to read semver protocol version."
160
+ }
161
+ );
162
+ return semver;
163
+ }
107
164
  let lazyL2;
108
165
  function getL2Wallet() {
109
166
  if (l2Wallet) return l2Wallet;
110
167
  if (!lazyL2) {
111
168
  lazyL2 = createWalletClient({
112
169
  account: l1Wallet.account,
113
- transport: l2.transport
170
+ transport: custom(l2.transport)
114
171
  });
115
172
  }
116
173
  return lazyL2;
@@ -127,6 +184,7 @@ function createViemClient(args) {
127
184
  contracts,
128
185
  refresh,
129
186
  baseToken,
187
+ getProtocolVersion,
130
188
  getL2Wallet
131
189
  };
132
190
  }
@@ -1,4 +1,4 @@
1
- import { __export, ETH_ADDRESS, FORMAL_ETH_ADDRESS, L2_BASE_TOKEN_ADDRESS } from './chunk-QQ2OR434.js';
1
+ import { __export, ETH_ADDRESS, FORMAL_ETH_ADDRESS, L2_BASE_TOKEN_ADDRESS } from './chunk-MT4X5FEO.js';
2
2
 
3
3
  // src/core/internal/abis/IBridgehub.ts
4
4
  var IBridgehubABI = [
@@ -4449,6 +4449,11 @@ var IInteropCenterABI = [
4449
4449
  type: "uint256",
4450
4450
  internalType: "uint256"
4451
4451
  },
4452
+ {
4453
+ name: "destinationBaseTokenAssetId",
4454
+ type: "bytes32",
4455
+ internalType: "bytes32"
4456
+ },
4452
4457
  {
4453
4458
  name: "interopBundleSalt",
4454
4459
  type: "bytes32",
@@ -5447,56 +5452,69 @@ var IERC20_default = IERC20ABI;
5447
5452
  // src/core/internal/abis/IERC7786Attributes.ts
5448
5453
  var IERC7786AttributesABI = [
5449
5454
  {
5455
+ type: "function",
5456
+ name: "executionAddress",
5450
5457
  inputs: [
5451
5458
  {
5452
- internalType: "bytes",
5453
5459
  name: "_executionAddress",
5454
- type: "bytes"
5460
+ type: "bytes",
5461
+ internalType: "bytes"
5455
5462
  }
5456
5463
  ],
5457
- name: "executionAddress",
5458
5464
  outputs: [],
5459
- stateMutability: "pure",
5460
- type: "function"
5465
+ stateMutability: "pure"
5461
5466
  },
5462
5467
  {
5468
+ type: "function",
5469
+ name: "indirectCall",
5463
5470
  inputs: [
5464
5471
  {
5465
- internalType: "uint256",
5466
5472
  name: "_indirectCallMessageValue",
5467
- type: "uint256"
5473
+ type: "uint256",
5474
+ internalType: "uint256"
5468
5475
  }
5469
5476
  ],
5470
- name: "indirectCall",
5471
5477
  outputs: [],
5472
- stateMutability: "pure",
5473
- type: "function"
5478
+ stateMutability: "pure"
5474
5479
  },
5475
5480
  {
5481
+ type: "function",
5482
+ name: "interopCallValue",
5476
5483
  inputs: [
5477
5484
  {
5478
- internalType: "uint256",
5479
5485
  name: "_interopCallValue",
5480
- type: "uint256"
5486
+ type: "uint256",
5487
+ internalType: "uint256"
5481
5488
  }
5482
5489
  ],
5483
- name: "interopCallValue",
5484
5490
  outputs: [],
5485
- stateMutability: "pure",
5486
- type: "function"
5491
+ stateMutability: "pure"
5487
5492
  },
5488
5493
  {
5494
+ type: "function",
5495
+ name: "unbundlerAddress",
5489
5496
  inputs: [
5490
5497
  {
5491
- internalType: "bytes",
5492
5498
  name: "_unbundlerAddress",
5493
- type: "bytes"
5499
+ type: "bytes",
5500
+ internalType: "bytes"
5494
5501
  }
5495
5502
  ],
5496
- name: "unbundlerAddress",
5497
5503
  outputs: [],
5498
- stateMutability: "pure",
5499
- type: "function"
5504
+ stateMutability: "pure"
5505
+ },
5506
+ {
5507
+ type: "function",
5508
+ name: "useFixedFee",
5509
+ inputs: [
5510
+ {
5511
+ name: "_useFixed",
5512
+ type: "bool",
5513
+ internalType: "bool"
5514
+ }
5515
+ ],
5516
+ outputs: [],
5517
+ stateMutability: "pure"
5500
5518
  }
5501
5519
  ];
5502
5520
  var IERC7786Attributes_default = IERC7786AttributesABI;
@@ -7041,6 +7059,11 @@ var OP_INTEROP = {
7041
7059
  wait: {
7042
7060
  poll: "interop.svc.wait:poll",
7043
7061
  timeout: "interop.svc.wait:timeout"
7062
+ },
7063
+ fees: {
7064
+ zkInteropFee: "interop.svc.fees:zkInteropFee",
7065
+ zkToken: "interop.svc.fees:zkToken",
7066
+ protocolFee: "interop.svc.fees:protocolFee"
7044
7067
  }
7045
7068
  }
7046
7069
  };
@@ -7055,20 +7078,20 @@ function createError(type, input) {
7055
7078
  return new ZKsyncError({ ...input, type });
7056
7079
  }
7057
7080
  function shapeCause(err) {
7058
- const isRecord = (x) => x !== null && typeof x === "object";
7081
+ const isRecord2 = (x) => x !== null && typeof x === "object";
7059
7082
  let data = void 0;
7060
- if (isRecord(err)) {
7083
+ if (isRecord2(err)) {
7061
7084
  const r2 = err;
7062
7085
  const d = r2.data;
7063
- if (isRecord(d) && "data" in d) {
7086
+ if (isRecord2(d) && "data" in d) {
7064
7087
  data = d.data;
7065
- } else if ("error" in r2 && isRecord(r2.error) && "data" in r2.error) {
7088
+ } else if ("error" in r2 && isRecord2(r2.error) && "data" in r2.error) {
7066
7089
  data = r2.error.data;
7067
7090
  } else if ("data" in r2) {
7068
7091
  data = r2.data;
7069
7092
  }
7070
7093
  }
7071
- const r = isRecord(err) ? err : void 0;
7094
+ const r = isRecord2(err) ? err : void 0;
7072
7095
  const name = r && typeof r.name === "string" ? r.name : void 0;
7073
7096
  const message = r && typeof r.message === "string" ? r.message : r && typeof r.shortMessage === "string" ? r.shortMessage : void 0;
7074
7097
  const code = r && "code" in r ? r.code : void 0;
@@ -7080,4 +7103,417 @@ function shapeCause(err) {
7080
7103
  };
7081
7104
  }
7082
7105
 
7083
- export { IBaseToken_default, IBridgehub_default, IERC20_default, IERC7786Attributes_default, IInteropCenter_default, IInteropErrors_default, IInteropHandler_default, IInteropRootStorage_default, IL1AssetRouter_default, IL1ContractErrors_default, IL1Nullifier_default, IL2AssetRouter_default, L1NativeTokenVault_default, L2MessageVerification_default, L2NativeTokenVault_default, Mailbox_default, OP_CLIENT, OP_DEPOSITS, OP_INTEROP, OP_WITHDRAWALS, abi_exports, assertNever, createError, factory_exports, formatEnvelopePretty, hexEq, isAddress, isAddressEq, isBigint, isETH, isHash, isHash66, isHash66Array, isHashArray, isNumber, isReceiptNotFound, isZKsyncError, normalizeAddrEq, normalizeL1Token, shapeCause, sleep };
7106
+ // src/core/rpc/zks.ts
7107
+ var zks_exports = {};
7108
+ __export(zks_exports, {
7109
+ ProofTarget: () => ProofTarget,
7110
+ createZksRpc: () => createZksRpc,
7111
+ normalizeBlockMetadata: () => normalizeBlockMetadata,
7112
+ normalizeGenesis: () => normalizeGenesis,
7113
+ normalizeProof: () => normalizeProof
7114
+ });
7115
+
7116
+ // src/core/errors/rpc.ts
7117
+ async function withRpcOp(operation, message, ctx, fn) {
7118
+ try {
7119
+ return await fn();
7120
+ } catch (e) {
7121
+ if (isZKsyncError(e)) throw e;
7122
+ throw createError("RPC", {
7123
+ resource: "zksrpc",
7124
+ operation,
7125
+ message,
7126
+ context: ctx,
7127
+ cause: shapeCause(e)
7128
+ });
7129
+ }
7130
+ }
7131
+
7132
+ // src/core/rpc/zks.ts
7133
+ var ProofTarget = /* @__PURE__ */ ((ProofTarget2) => {
7134
+ ProofTarget2["L1BatchRoot"] = "l1BatchRoot";
7135
+ ProofTarget2["MessageRoot"] = "messageRoot";
7136
+ return ProofTarget2;
7137
+ })(ProofTarget || {});
7138
+ var METHODS = {
7139
+ getBridgehub: "zks_getBridgehubContract",
7140
+ getL2ToL1LogProof: "zks_getL2ToL1LogProof",
7141
+ getReceipt: "eth_getTransactionReceipt",
7142
+ getBytecodeSupplier: "zks_getBytecodeSupplierContract",
7143
+ getBlockMetadataByNumber: "zks_getBlockMetadataByNumber",
7144
+ getGenesis: "zks_getGenesis"
7145
+ };
7146
+ function toHexArray(arr) {
7147
+ const list = Array.isArray(arr) ? arr : [];
7148
+ return list.map((x) => x);
7149
+ }
7150
+ function normalizeProof(p) {
7151
+ try {
7152
+ const raw = p ?? {};
7153
+ const idRaw = raw?.id ?? raw?.index;
7154
+ const bnRaw = raw?.batch_number ?? raw?.batchNumber;
7155
+ const gwBlockNumberRaw = raw?.gatewayBlockNumber;
7156
+ if (idRaw == null || bnRaw == null) {
7157
+ throw createError("RPC", {
7158
+ resource: "zksrpc",
7159
+ operation: "zksrpc.normalizeProof",
7160
+ message: "Malformed proof: missing id or batch number.",
7161
+ context: { keys: Object.keys(raw ?? {}) }
7162
+ });
7163
+ }
7164
+ const toBig = (x) => isBigint(x) ? x : isNumber(x) ? BigInt(x) : typeof x === "string" ? BigInt(x) : (() => {
7165
+ throw createError("RPC", {
7166
+ resource: "zksrpc",
7167
+ operation: "zksrpc.normalizeProof",
7168
+ message: "Malformed proof: invalid numeric field.",
7169
+ context: { valueType: typeof x }
7170
+ });
7171
+ })();
7172
+ return {
7173
+ id: toBig(idRaw),
7174
+ batchNumber: toBig(bnRaw),
7175
+ proof: toHexArray(raw?.proof),
7176
+ root: raw.root,
7177
+ gatewayBlockNumber: gwBlockNumberRaw != null ? toBig(gwBlockNumberRaw) : void 0
7178
+ };
7179
+ } catch (e) {
7180
+ if (isZKsyncError(e)) throw e;
7181
+ throw createError("RPC", {
7182
+ resource: "zksrpc",
7183
+ operation: "zksrpc.normalizeProof",
7184
+ message: "Failed to normalize proof.",
7185
+ context: { receivedType: typeof p },
7186
+ cause: shapeCause(e)
7187
+ });
7188
+ }
7189
+ }
7190
+ function ensureHex(value, field, context) {
7191
+ if (typeof value === "string" && value.startsWith("0x")) return value;
7192
+ throw createError("RPC", {
7193
+ resource: "zksrpc",
7194
+ operation: "zksrpc.normalizeGenesis",
7195
+ message: "Malformed genesis response: expected 0x-prefixed hex value.",
7196
+ context: { field, valueType: typeof value, ...context }
7197
+ });
7198
+ }
7199
+ function ensureNumber(value, field, opts) {
7200
+ const operation = opts?.operation;
7201
+ const messagePrefix = opts?.messagePrefix;
7202
+ if (isNumber(value)) return value;
7203
+ if (isBigint(value)) return Number(value);
7204
+ if (typeof value === "string" && value.trim() !== "") {
7205
+ const parsed = Number(value);
7206
+ if (Number.isFinite(parsed)) return parsed;
7207
+ }
7208
+ throw createError("RPC", {
7209
+ resource: "zksrpc",
7210
+ operation,
7211
+ message: `${messagePrefix}: expected numeric value.`,
7212
+ context: { field, valueType: typeof value }
7213
+ });
7214
+ }
7215
+ function ensureBigInt(value, field, opts) {
7216
+ const operation = opts?.operation ?? "zksrpc.normalizeBlockMetadata";
7217
+ const messagePrefix = opts?.messagePrefix ?? "Malformed block metadata response";
7218
+ if (isBigint(value)) return value;
7219
+ if (isNumber(value)) {
7220
+ if (!Number.isInteger(value)) {
7221
+ throw createError("RPC", {
7222
+ resource: "zksrpc",
7223
+ operation,
7224
+ message: `${messagePrefix}: expected integer value.`,
7225
+ context: { field, valueType: typeof value }
7226
+ });
7227
+ }
7228
+ return BigInt(value);
7229
+ }
7230
+ if (typeof value === "string" && value.trim() !== "") {
7231
+ try {
7232
+ return BigInt(value);
7233
+ } catch {
7234
+ }
7235
+ }
7236
+ throw createError("RPC", {
7237
+ resource: "zksrpc",
7238
+ operation,
7239
+ message: `${messagePrefix}: expected bigint-compatible value.`,
7240
+ context: { field, valueType: typeof value }
7241
+ });
7242
+ }
7243
+ function isRecord(x) {
7244
+ return !!x && typeof x === "object" && !Array.isArray(x);
7245
+ }
7246
+ function normalizeContractTuple(tuple, index) {
7247
+ if (!Array.isArray(tuple) || tuple.length < 2) {
7248
+ throw createError("RPC", {
7249
+ resource: "zksrpc",
7250
+ operation: "zksrpc.normalizeGenesis",
7251
+ message: "Malformed genesis response: invalid contract tuple.",
7252
+ context: { index, valueType: typeof tuple }
7253
+ });
7254
+ }
7255
+ const [addrRaw, bytecodeRaw] = tuple;
7256
+ return {
7257
+ address: ensureHex(addrRaw, "initial_contracts.address", { index }),
7258
+ bytecode: ensureHex(bytecodeRaw, "initial_contracts.bytecode", { index })
7259
+ };
7260
+ }
7261
+ function normalizeRawStorageTuple(tuple, index) {
7262
+ if (!Array.isArray(tuple) || tuple.length < 2) {
7263
+ throw createError("RPC", {
7264
+ resource: "zksrpc",
7265
+ operation: "zksrpc.normalizeGenesis",
7266
+ message: "Malformed genesis response: invalid storage tuple.",
7267
+ context: { index, valueType: typeof tuple }
7268
+ });
7269
+ }
7270
+ const [keyRaw, valueRaw] = tuple;
7271
+ return {
7272
+ format: "raw",
7273
+ key: ensureHex(keyRaw, "additional_storage.key", { index }),
7274
+ value: ensureHex(valueRaw, "additional_storage.value", { index })
7275
+ };
7276
+ }
7277
+ function normalizeAdditionalStorage(value, record) {
7278
+ const effective = value ?? record["additional_storage_raw"];
7279
+ if (Array.isArray(effective)) {
7280
+ return effective.map((entry, index) => {
7281
+ const kv2 = normalizeRawStorageTuple(entry, index);
7282
+ return { format: "raw", key: kv2.key, value: kv2.value };
7283
+ });
7284
+ }
7285
+ if (isRecord(effective)) {
7286
+ const out = [];
7287
+ for (const [addrRaw, slotsRaw] of Object.entries(effective)) {
7288
+ const address = ensureHex(addrRaw, "additional_storage.address", {});
7289
+ if (!isRecord(slotsRaw)) {
7290
+ throw createError("RPC", {
7291
+ resource: "zksrpc",
7292
+ operation: "zksrpc.normalizeGenesis",
7293
+ message: "Malformed genesis response: additional_storage[address] must be an object map.",
7294
+ context: { address, valueType: typeof slotsRaw }
7295
+ });
7296
+ }
7297
+ for (const [slotRaw, valRaw] of Object.entries(slotsRaw)) {
7298
+ out.push({
7299
+ format: "pretty",
7300
+ address,
7301
+ key: ensureHex(slotRaw, "additional_storage.key", { address }),
7302
+ value: ensureHex(valRaw, "additional_storage.value", { address, key: slotRaw })
7303
+ });
7304
+ }
7305
+ }
7306
+ return out;
7307
+ }
7308
+ throw createError("RPC", {
7309
+ resource: "zksrpc",
7310
+ operation: "zksrpc.normalizeGenesis",
7311
+ message: "Malformed genesis response: additional_storage must be an array (raw) or an object map (pretty).",
7312
+ context: {
7313
+ valueType: typeof effective,
7314
+ hasAdditionalStorage: "additional_storage" in record,
7315
+ hasAdditionalStorageRaw: "additional_storage_raw" in record
7316
+ }
7317
+ });
7318
+ }
7319
+ function normalizeGenesis(raw) {
7320
+ try {
7321
+ if (!raw || typeof raw !== "object") {
7322
+ throw createError("RPC", {
7323
+ resource: "zksrpc",
7324
+ operation: "zksrpc.normalizeGenesis",
7325
+ message: "Malformed genesis response: expected object.",
7326
+ context: { receivedType: typeof raw }
7327
+ });
7328
+ }
7329
+ const record = raw;
7330
+ const contractsRaw = record["initial_contracts"];
7331
+ if (!Array.isArray(contractsRaw)) {
7332
+ throw createError("RPC", {
7333
+ resource: "zksrpc",
7334
+ operation: "zksrpc.normalizeGenesis",
7335
+ message: "Malformed genesis response: initial_contracts must be an array.",
7336
+ context: { valueType: typeof contractsRaw }
7337
+ });
7338
+ }
7339
+ const genesisRoot = ensureHex(record["genesis_root"], "genesis_root", {});
7340
+ const initialContracts = contractsRaw.map(
7341
+ (entry, index) => normalizeContractTuple(entry, index)
7342
+ );
7343
+ const additionalStorage = normalizeAdditionalStorage(record["additional_storage"], record);
7344
+ return {
7345
+ initialContracts,
7346
+ additionalStorage,
7347
+ genesisRoot
7348
+ };
7349
+ } catch (e) {
7350
+ if (isZKsyncError(e)) throw e;
7351
+ throw createError("RPC", {
7352
+ resource: "zksrpc",
7353
+ operation: "zksrpc.normalizeGenesis",
7354
+ message: "Failed to normalize genesis response.",
7355
+ context: { receivedType: typeof raw },
7356
+ cause: shapeCause(e)
7357
+ });
7358
+ }
7359
+ }
7360
+ function normalizeBlockMetadata(raw) {
7361
+ try {
7362
+ if (!raw || typeof raw !== "object") {
7363
+ throw createError("RPC", {
7364
+ resource: "zksrpc",
7365
+ operation: "zksrpc.normalizeBlockMetadata",
7366
+ message: "Malformed block metadata response: expected object.",
7367
+ context: { receivedType: typeof raw }
7368
+ });
7369
+ }
7370
+ const record = raw;
7371
+ const pubdataPricePerByte = ensureBigInt(
7372
+ record["pubdata_price_per_byte"] ?? record["pubdataPricePerByte"],
7373
+ "pubdata_price_per_byte",
7374
+ {
7375
+ operation: "zksrpc.normalizeBlockMetadata",
7376
+ messagePrefix: "Malformed block metadata response"
7377
+ }
7378
+ );
7379
+ const nativePrice = ensureBigInt(
7380
+ record["native_price"] ?? record["nativePrice"],
7381
+ "native_price",
7382
+ {
7383
+ operation: "zksrpc.normalizeBlockMetadata",
7384
+ messagePrefix: "Malformed block metadata response"
7385
+ }
7386
+ );
7387
+ const executionVersion = ensureNumber(
7388
+ record["execution_version"] ?? record["executionVersion"],
7389
+ "execution_version",
7390
+ {
7391
+ operation: "zksrpc.normalizeBlockMetadata",
7392
+ messagePrefix: "Malformed block metadata response"
7393
+ }
7394
+ );
7395
+ return {
7396
+ pubdataPricePerByte,
7397
+ nativePrice,
7398
+ executionVersion
7399
+ };
7400
+ } catch (e) {
7401
+ if (isZKsyncError(e)) throw e;
7402
+ throw createError("RPC", {
7403
+ resource: "zksrpc",
7404
+ operation: "zksrpc.normalizeBlockMetadata",
7405
+ message: "Failed to normalize block metadata response.",
7406
+ context: { receivedType: typeof raw },
7407
+ cause: shapeCause(e)
7408
+ });
7409
+ }
7410
+ }
7411
+ function createZksRpc(transport) {
7412
+ return {
7413
+ // Fetches the Bridgehub contract address.
7414
+ async getBridgehubAddress() {
7415
+ return withRpcOp(
7416
+ "zksrpc.getBridgehubAddress",
7417
+ "Failed to fetch Bridgehub address.",
7418
+ {},
7419
+ async () => {
7420
+ const addrRaw = await transport(METHODS.getBridgehub, []);
7421
+ if (typeof addrRaw !== "string" || !addrRaw.startsWith("0x")) {
7422
+ throw createError("RPC", {
7423
+ resource: "zksrpc",
7424
+ operation: "zksrpc.getBridgehubAddress",
7425
+ message: "Unexpected Bridgehub address response.",
7426
+ context: { valueType: typeof addrRaw }
7427
+ });
7428
+ }
7429
+ return addrRaw;
7430
+ }
7431
+ );
7432
+ },
7433
+ // Fetches the Bytecode Supplier contract address.
7434
+ async getBytecodeSupplierAddress() {
7435
+ return withRpcOp(
7436
+ "zksrpc.getBytecodeSupplierAddress",
7437
+ "Failed to fetch Bytecode Supplier address.",
7438
+ {},
7439
+ async () => {
7440
+ const addrRaw = await transport(METHODS.getBytecodeSupplier, []);
7441
+ if (typeof addrRaw !== "string" || !addrRaw.startsWith("0x")) {
7442
+ throw createError("RPC", {
7443
+ resource: "zksrpc",
7444
+ operation: "zksrpc.getBytecodeSupplierAddress",
7445
+ message: "Unexpected Bytecode Supplier address response.",
7446
+ context: { valueType: typeof addrRaw }
7447
+ });
7448
+ }
7449
+ return addrRaw;
7450
+ }
7451
+ );
7452
+ },
7453
+ // Fetches a proof for an L2→L1 log emitted in the given transaction.
7454
+ async getL2ToL1LogProof(txHash, index, proofTarget) {
7455
+ return withRpcOp(
7456
+ "zksrpc.getL2ToL1LogProof",
7457
+ "Failed to fetch L2\u2192L1 log proof.",
7458
+ { txHash, index, proofTarget },
7459
+ async () => {
7460
+ const params = [txHash, index];
7461
+ if (proofTarget != void 0) params.push(proofTarget);
7462
+ const proof = await transport(METHODS.getL2ToL1LogProof, params);
7463
+ if (!proof) {
7464
+ throw createError("STATE", {
7465
+ resource: "zksrpc",
7466
+ operation: "zksrpc.getL2ToL1LogProof",
7467
+ message: "Proof not yet available. Please try again later.",
7468
+ context: { txHash, index }
7469
+ });
7470
+ }
7471
+ return normalizeProof(proof);
7472
+ }
7473
+ );
7474
+ },
7475
+ // Fetches the transaction receipt, including the `l2ToL1Logs` field.
7476
+ async getReceiptWithL2ToL1(txHash) {
7477
+ return withRpcOp(
7478
+ "zksrpc.getReceiptWithL2ToL1",
7479
+ "Failed to fetch transaction receipt.",
7480
+ { txHash },
7481
+ async () => {
7482
+ const rcptRaw = await transport(METHODS.getReceipt, [txHash]);
7483
+ if (!rcptRaw) return null;
7484
+ const rcptObj = rcptRaw;
7485
+ const logs = Array.isArray(rcptObj["l2ToL1Logs"]) ? rcptObj["l2ToL1Logs"] : [];
7486
+ rcptObj["l2ToL1Logs"] = logs;
7487
+ return rcptObj;
7488
+ }
7489
+ );
7490
+ },
7491
+ // Fetches block metadata for the given block number.
7492
+ async getBlockMetadataByNumber(blockNumber) {
7493
+ return withRpcOp(
7494
+ "zksrpc.getBlockMetadataByNumber",
7495
+ "Failed to fetch block metadata.",
7496
+ { blockNumber },
7497
+ async () => {
7498
+ const raw = await transport(METHODS.getBlockMetadataByNumber, [blockNumber]);
7499
+ if (raw == null) return null;
7500
+ return normalizeBlockMetadata(raw);
7501
+ }
7502
+ );
7503
+ },
7504
+ // Fetches the genesis configuration returned by `zks_getGenesis`.
7505
+ async getGenesis() {
7506
+ return withRpcOp(
7507
+ "zksrpc.getGenesis",
7508
+ "Failed to fetch genesis configuration.",
7509
+ {},
7510
+ async () => {
7511
+ const genesisRaw = await transport(METHODS.getGenesis, []);
7512
+ return normalizeGenesis(genesisRaw);
7513
+ }
7514
+ );
7515
+ }
7516
+ };
7517
+ }
7518
+
7519
+ export { IBaseToken_default, IBridgehub_default, IERC20_default, IERC7786Attributes_default, IInteropCenter_default, IInteropErrors_default, IInteropHandler_default, IInteropRootStorage_default, IL1AssetRouter_default, IL1ContractErrors_default, IL1Nullifier_default, IL2AssetRouter_default, L1NativeTokenVault_default, L2MessageVerification_default, L2NativeTokenVault_default, Mailbox_default, OP_CLIENT, OP_DEPOSITS, OP_INTEROP, OP_WITHDRAWALS, abi_exports, assertNever, createError, createZksRpc, factory_exports, formatEnvelopePretty, hexEq, isAddress, isAddressEq, isBigint, isETH, isHash, isHash66, isHash66Array, isHashArray, isNumber, isReceiptNotFound, isZKsyncError, normalizeAddrEq, normalizeL1Token, shapeCause, sleep, zks_exports };