@matterlabs/zksync-js 0.0.1

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 (139) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +124 -0
  3. package/dist/adapters/ethers/client.cjs +4548 -0
  4. package/dist/adapters/ethers/client.cjs.map +1 -0
  5. package/dist/adapters/ethers/client.d.ts +61 -0
  6. package/dist/adapters/ethers/client.js +5 -0
  7. package/dist/adapters/ethers/errors/error-ops.d.ts +20 -0
  8. package/dist/adapters/ethers/errors/revert.d.ts +28 -0
  9. package/dist/adapters/ethers/index.cjs +7537 -0
  10. package/dist/adapters/ethers/index.cjs.map +1 -0
  11. package/dist/adapters/ethers/index.d.ts +12 -0
  12. package/dist/adapters/ethers/index.js +8 -0
  13. package/dist/adapters/ethers/resources/deposits/context.d.ts +27 -0
  14. package/dist/adapters/ethers/resources/deposits/index.d.ts +46 -0
  15. package/dist/adapters/ethers/resources/deposits/routes/erc20-base.d.ts +2 -0
  16. package/dist/adapters/ethers/resources/deposits/routes/erc20-nonbase.d.ts +2 -0
  17. package/dist/adapters/ethers/resources/deposits/routes/eth-nonbase.d.ts +2 -0
  18. package/dist/adapters/ethers/resources/deposits/routes/eth.d.ts +2 -0
  19. package/dist/adapters/ethers/resources/deposits/routes/types.d.ts +10 -0
  20. package/dist/adapters/ethers/resources/deposits/services/verification.d.ts +9 -0
  21. package/dist/adapters/ethers/resources/token-info.d.ts +31 -0
  22. package/dist/adapters/ethers/resources/utils.d.ts +39 -0
  23. package/dist/adapters/ethers/resources/withdrawals/context.d.ts +19 -0
  24. package/dist/adapters/ethers/resources/withdrawals/index.d.ts +56 -0
  25. package/dist/adapters/ethers/resources/withdrawals/routes/erc20-nonbase.d.ts +2 -0
  26. package/dist/adapters/ethers/resources/withdrawals/routes/eth-nonbase.d.ts +2 -0
  27. package/dist/adapters/ethers/resources/withdrawals/routes/eth.d.ts +2 -0
  28. package/dist/adapters/ethers/resources/withdrawals/routes/types.d.ts +18 -0
  29. package/dist/adapters/ethers/resources/withdrawals/services/finalization.d.ts +33 -0
  30. package/dist/adapters/ethers/rpc.d.ts +4 -0
  31. package/dist/adapters/ethers/sdk.cjs +6245 -0
  32. package/dist/adapters/ethers/sdk.cjs.map +1 -0
  33. package/dist/adapters/ethers/sdk.d.ts +29 -0
  34. package/dist/adapters/ethers/sdk.js +6 -0
  35. package/dist/adapters/ethers/typechain/IAssetRouterBase.d.ts +198 -0
  36. package/dist/adapters/ethers/typechain/IBridgehub.d.ts +731 -0
  37. package/dist/adapters/ethers/typechain/IERC20.d.ts +108 -0
  38. package/dist/adapters/ethers/typechain/IL1AssetRouter.d.ts +570 -0
  39. package/dist/adapters/ethers/typechain/IL1NativeTokenVault.d.ts +154 -0
  40. package/dist/adapters/ethers/typechain/IL1Nullifier.d.ts +305 -0
  41. package/dist/adapters/ethers/typechain/IL2AssetRouter.d.ts +288 -0
  42. package/dist/adapters/ethers/typechain/IL2NativeTokenVault.d.ts +380 -0
  43. package/dist/adapters/ethers/typechain/common.d.ts +46 -0
  44. package/dist/adapters/ethers/typechain/factories/IAssetRouterBase__factory.d.ts +203 -0
  45. package/dist/adapters/ethers/typechain/factories/IBridgehub__factory.d.ts +998 -0
  46. package/dist/adapters/ethers/typechain/factories/IERC20__factory.d.ts +177 -0
  47. package/dist/adapters/ethers/typechain/factories/IL1AssetRouter__factory.d.ts +666 -0
  48. package/dist/adapters/ethers/typechain/factories/IL1NativeTokenVault__factory.d.ts +234 -0
  49. package/dist/adapters/ethers/typechain/factories/IL1Nullifier__factory.d.ts +382 -0
  50. package/dist/adapters/ethers/typechain/factories/IL2AssetRouter__factory.d.ts +327 -0
  51. package/dist/adapters/ethers/typechain/factories/IL2NativeTokenVault__factory.d.ts +696 -0
  52. package/dist/adapters/ethers/typechain/factories/index.d.ts +8 -0
  53. package/dist/adapters/ethers/typechain/index.d.ts +17 -0
  54. package/dist/adapters/viem/client.cjs +4534 -0
  55. package/dist/adapters/viem/client.cjs.map +1 -0
  56. package/dist/adapters/viem/client.d.ts +44 -0
  57. package/dist/adapters/viem/client.js +5 -0
  58. package/dist/adapters/viem/errors/error-ops.d.ts +20 -0
  59. package/dist/adapters/viem/errors/revert.d.ts +25 -0
  60. package/dist/adapters/viem/index.cjs +7772 -0
  61. package/dist/adapters/viem/index.cjs.map +1 -0
  62. package/dist/adapters/viem/index.d.ts +11 -0
  63. package/dist/adapters/viem/index.js +8 -0
  64. package/dist/adapters/viem/resources/deposits/context.d.ts +27 -0
  65. package/dist/adapters/viem/resources/deposits/index.d.ts +46 -0
  66. package/dist/adapters/viem/resources/deposits/routes/erc20-base.d.ts +2 -0
  67. package/dist/adapters/viem/resources/deposits/routes/erc20-nonbase.d.ts +2 -0
  68. package/dist/adapters/viem/resources/deposits/routes/eth-nonbase.d.ts +2 -0
  69. package/dist/adapters/viem/resources/deposits/routes/eth.d.ts +2 -0
  70. package/dist/adapters/viem/resources/deposits/routes/types.d.ts +20 -0
  71. package/dist/adapters/viem/resources/deposits/services/verification.d.ts +7 -0
  72. package/dist/adapters/viem/resources/token-info.d.ts +34 -0
  73. package/dist/adapters/viem/resources/utils.d.ts +42 -0
  74. package/dist/adapters/viem/resources/withdrawals/context.d.ts +22 -0
  75. package/dist/adapters/viem/resources/withdrawals/index.d.ts +56 -0
  76. package/dist/adapters/viem/resources/withdrawals/routes/erc20-nonbase.d.ts +2 -0
  77. package/dist/adapters/viem/resources/withdrawals/routes/eth-nonbase.d.ts +2 -0
  78. package/dist/adapters/viem/resources/withdrawals/routes/eth.d.ts +2 -0
  79. package/dist/adapters/viem/resources/withdrawals/routes/types.d.ts +19 -0
  80. package/dist/adapters/viem/resources/withdrawals/services/finalization.d.ts +33 -0
  81. package/dist/adapters/viem/rpc.d.ts +2 -0
  82. package/dist/adapters/viem/sdk.cjs +6481 -0
  83. package/dist/adapters/viem/sdk.cjs.map +1 -0
  84. package/dist/adapters/viem/sdk.d.ts +32 -0
  85. package/dist/adapters/viem/sdk.js +6 -0
  86. package/dist/chunk-263G6636.js +36 -0
  87. package/dist/chunk-3LALBFFE.js +138 -0
  88. package/dist/chunk-4HLJJKIY.js +262 -0
  89. package/dist/chunk-6GCT6TLS.js +45 -0
  90. package/dist/chunk-7M4V3FMT.js +2444 -0
  91. package/dist/chunk-B77GWPO5.js +339 -0
  92. package/dist/chunk-BD2LUO5T.js +123 -0
  93. package/dist/chunk-CGO27P7F.js +2187 -0
  94. package/dist/chunk-DI2CJDPZ.js +76 -0
  95. package/dist/chunk-Y75OMFK6.js +4489 -0
  96. package/dist/core/constants.cjs +39 -0
  97. package/dist/core/constants.cjs.map +1 -0
  98. package/dist/core/constants.d.ts +36 -0
  99. package/dist/core/constants.js +1 -0
  100. package/dist/core/errors/factory.d.ts +10 -0
  101. package/dist/core/errors/formatter.d.ts +2 -0
  102. package/dist/core/errors/rpc.d.ts +4 -0
  103. package/dist/core/errors/withdrawal-revert-map.d.ts +3 -0
  104. package/dist/core/index.cjs +552 -0
  105. package/dist/core/index.cjs.map +1 -0
  106. package/dist/core/index.d.ts +18 -0
  107. package/dist/core/index.js +4 -0
  108. package/dist/core/internal/abi-registry.d.ts +9 -0
  109. package/dist/core/internal/abis/IAssetRouterBase.d.ts +198 -0
  110. package/dist/core/internal/abis/IBaseToken.d.ts +162 -0
  111. package/dist/core/internal/abis/IBridgehub.d.ts +994 -0
  112. package/dist/core/internal/abis/IERC20.d.ts +224 -0
  113. package/dist/core/internal/abis/IL1AssetRouter.d.ts +661 -0
  114. package/dist/core/internal/abis/IL1Nullifier.d.ts +377 -0
  115. package/dist/core/internal/abis/IL2AssetRouter.d.ts +690 -0
  116. package/dist/core/internal/abis/L1NativeTokenVault.d.ts +719 -0
  117. package/dist/core/internal/abis/L2NativeTokenVault.d.ts +735 -0
  118. package/dist/core/internal/abis/Mailbox.d.ts +779 -0
  119. package/dist/core/resources/deposits/route.d.ts +6 -0
  120. package/dist/core/resources/withdrawals/events.d.ts +9 -0
  121. package/dist/core/resources/withdrawals/logs.d.ts +5 -0
  122. package/dist/core/resources/withdrawals/route.d.ts +6 -0
  123. package/dist/core/rpc/transport.d.ts +10 -0
  124. package/dist/core/rpc/types.d.ts +40 -0
  125. package/dist/core/rpc/zks.d.ts +12 -0
  126. package/dist/core/types/errors.d.ts +177 -0
  127. package/dist/core/types/flows/base.d.ts +51 -0
  128. package/dist/core/types/flows/deposits.d.ts +43 -0
  129. package/dist/core/types/flows/route.d.ts +12 -0
  130. package/dist/core/types/flows/withdrawals.d.ts +83 -0
  131. package/dist/core/types/index.d.ts +2 -0
  132. package/dist/core/types/primitives.d.ts +3 -0
  133. package/dist/core/utils/addr.d.ts +5 -0
  134. package/dist/core/utils/gas.d.ts +13 -0
  135. package/dist/index.cjs +571 -0
  136. package/dist/index.cjs.map +1 -0
  137. package/dist/index.d.ts +18 -0
  138. package/dist/index.js +4 -0
  139. package/package.json +177 -0
@@ -0,0 +1,339 @@
1
+ import { __export } from './chunk-6GCT6TLS.js';
2
+
3
+ // src/core/errors/formatter.ts
4
+ function elideMiddle(s, max = 96) {
5
+ if (s.length <= max) return s;
6
+ const keep = Math.max(10, Math.floor((max - 1) / 2));
7
+ return `${s.slice(0, keep)}\u2026${s.slice(-keep)}`;
8
+ }
9
+ function shortJSON(v, max = 240) {
10
+ try {
11
+ const s = JSON.stringify(
12
+ v,
13
+ (_k, val) => typeof val === "bigint" ? `${val.toString()}n` : val
14
+ );
15
+ return s.length > max ? elideMiddle(s, max) : s;
16
+ } catch {
17
+ return String(v);
18
+ }
19
+ }
20
+ function kv(label, value) {
21
+ const width = 10;
22
+ const pad = label.length >= width ? " " : " ".repeat(width - label.length);
23
+ return `${label + pad}: ${value}`;
24
+ }
25
+ function formatContextLine(ctx) {
26
+ if (!ctx) return;
27
+ const txHash = ctx["txHash"] ?? ctx["l1TxHash"] ?? ctx["hash"];
28
+ const nonce = ctx["nonce"];
29
+ const parts = [];
30
+ if (txHash !== void 0)
31
+ parts.push(`txHash=${typeof txHash === "string" ? txHash : shortJSON(txHash, 96)}`);
32
+ if (nonce !== void 0) {
33
+ const nonceStr = typeof nonce === "string" || typeof nonce === "number" || typeof nonce === "bigint" ? String(nonce) : shortJSON(nonce, 48);
34
+ parts.push(`nonce=${nonceStr}`);
35
+ }
36
+ return parts.length ? ` ${kv("Context", parts.join(" \u2022 "))}` : void 0;
37
+ }
38
+ function formatStep(ctx) {
39
+ const step = ctx && typeof ctx["step"] === "string" ? ctx["step"] : void 0;
40
+ return step ? ` ${kv("Step", step)}` : void 0;
41
+ }
42
+ function formatRevert(r) {
43
+ if (!r) return;
44
+ const first = [`selector=${r.selector}`];
45
+ const lines = [];
46
+ lines.push(` ${kv("Revert", first.join(" "))}`);
47
+ if (r.name) lines.push(` name=${r.name}`);
48
+ if (r.contract) lines.push(` contract=${r.contract}`);
49
+ if (r.fn) lines.push(` fn=${r.fn}`);
50
+ if (r.args && r.args.length) {
51
+ lines.push(` args=${shortJSON(r.args, 120)}`);
52
+ }
53
+ return lines.join("\n");
54
+ }
55
+ function formatCause(c) {
56
+ if (!c) return [];
57
+ const out = [];
58
+ if (typeof c === "object" && c !== null) {
59
+ const obj = c;
60
+ const head = [];
61
+ if (obj.name !== void 0) {
62
+ const nameVal = obj.name;
63
+ const nameStr = typeof nameVal === "string" || typeof nameVal === "number" || typeof nameVal === "bigint" || typeof nameVal === "boolean" ? String(nameVal) : shortJSON(nameVal, 120);
64
+ head.push(`name=${nameStr}`);
65
+ }
66
+ if (obj.code !== void 0) {
67
+ const codeVal = obj.code;
68
+ const codeStr = typeof codeVal === "string" || typeof codeVal === "number" || typeof codeVal === "bigint" || typeof codeVal === "boolean" ? String(codeVal) : shortJSON(codeVal, 120);
69
+ head.push(`code=${codeStr}`);
70
+ }
71
+ if (head.length) out.push(` ${kv("Cause", head.join(" "))}`);
72
+ if (obj.message) {
73
+ const messageStr = typeof obj.message === "string" || typeof obj.message === "number" || typeof obj.message === "bigint" || typeof obj.message === "boolean" ? String(obj.message) : shortJSON(obj.message, 600);
74
+ out.push(` message=${elideMiddle(messageStr, 600)}`);
75
+ }
76
+ if (obj.data) {
77
+ const dataStr = shortJSON(obj.data, 200);
78
+ out.push(` data=${elideMiddle(dataStr, 200)}`);
79
+ }
80
+ } else {
81
+ out.push(` ${kv("Cause", shortJSON(c, 200))}`);
82
+ }
83
+ return out;
84
+ }
85
+ function formatEnvelopePretty(e) {
86
+ const lines = [];
87
+ lines.push(`\u2716 ZKsyncError [${e.type}]`);
88
+ lines.push(` ${kv("Message", e.message)}`);
89
+ lines.push("");
90
+ lines.push(` ${kv("Operation", e.operation)}`);
91
+ const ctx = (() => {
92
+ const u = e;
93
+ if (!u || typeof u !== "object") return void 0;
94
+ const obj = u;
95
+ const candidate = obj["ctx"] ?? obj["context"];
96
+ if (candidate && typeof candidate === "object" && candidate !== null) {
97
+ return candidate;
98
+ }
99
+ return void 0;
100
+ })();
101
+ const ctxLine = formatContextLine(ctx);
102
+ if (ctxLine) lines.push(ctxLine);
103
+ const stepLine = formatStep(ctx);
104
+ if (stepLine) lines.push(stepLine);
105
+ const rv = formatRevert(e.revert);
106
+ if (rv) lines.push(rv);
107
+ const causeLines = formatCause(e.cause);
108
+ if (causeLines.length) {
109
+ if (!ctxLine && !rv) lines.push("");
110
+ lines.push(...causeLines);
111
+ }
112
+ return lines.join("\n");
113
+ }
114
+
115
+ // src/core/errors/factory.ts
116
+ var factory_exports = {};
117
+ __export(factory_exports, {
118
+ createError: () => createError,
119
+ shapeCause: () => shapeCause
120
+ });
121
+
122
+ // src/core/types/errors.ts
123
+ var hasSymbolInspect = typeof Symbol === "function" && typeof Symbol.for === "function";
124
+ var kInspect = hasSymbolInspect ? Symbol.for("nodejs.util.inspect.custom") : void 0;
125
+ function safeInspect(val) {
126
+ try {
127
+ if (typeof val === "string") return val;
128
+ return JSON.stringify(val, null, 2);
129
+ } catch {
130
+ try {
131
+ return String(val);
132
+ } catch {
133
+ return Object.prototype.toString.call(val);
134
+ }
135
+ }
136
+ }
137
+ var ZKsyncError = class extends Error {
138
+ constructor(envelope) {
139
+ super(formatEnvelopePretty(envelope), envelope.cause ? { cause: envelope.cause } : void 0);
140
+ this.envelope = envelope;
141
+ this.name = "ZKsyncError";
142
+ }
143
+ toJSON() {
144
+ return { name: this.name, ...this.envelope };
145
+ }
146
+ };
147
+ if (kInspect) {
148
+ Object.defineProperty(ZKsyncError.prototype, kInspect, {
149
+ value() {
150
+ return `${this.name}: ${formatEnvelopePretty(this.envelope)}`;
151
+ },
152
+ enumerable: false
153
+ });
154
+ }
155
+ function isZKsyncError(e) {
156
+ if (!e || typeof e !== "object") return false;
157
+ const maybe = e;
158
+ if (!("envelope" in maybe)) return false;
159
+ const envelope = maybe.envelope;
160
+ return typeof envelope?.type === "string" && typeof envelope?.message === "string";
161
+ }
162
+ function isReceiptNotFound(e) {
163
+ const chain = [];
164
+ let cur = e;
165
+ for (let i = 0; i < 5 && cur; i++) {
166
+ chain.push(cur);
167
+ cur = cur.cause;
168
+ }
169
+ const NAME_HITS = /* @__PURE__ */ new Set([
170
+ "TransactionReceiptNotFoundError",
171
+ // viem
172
+ "TransactionNotFoundError",
173
+ // viem
174
+ "NotFoundError"
175
+ // some RPC wrappers
176
+ ]);
177
+ const CODE_HITS = /* @__PURE__ */ new Set([
178
+ "TRANSACTION_NOT_FOUND",
179
+ // some ethers-ish shapes / providers
180
+ "RECEIPT_NOT_FOUND",
181
+ "NOT_FOUND",
182
+ -32e3
183
+ // JSON-RPC server error
184
+ ]);
185
+ const MSG_RE = /(transaction|receipt)[^]*?(not\s+(?:be\s+)?found|missing)/i;
186
+ for (const node of chain) {
187
+ const name = node?.name;
188
+ const code = node?.code;
189
+ const short = node?.shortMessage;
190
+ const msg = String(short ?? node?.message ?? "");
191
+ if (name && NAME_HITS.has(name)) return true;
192
+ if (code && CODE_HITS.has(code)) return true;
193
+ if (MSG_RE.test(msg)) return true;
194
+ }
195
+ const raw = (() => {
196
+ const node = e;
197
+ const short = node?.shortMessage;
198
+ const msg = node?.message;
199
+ if (typeof short === "string" && short) return short;
200
+ if (typeof msg === "string" && msg) return msg;
201
+ if (e == null) return "";
202
+ if (typeof e === "string") return e;
203
+ return safeInspect(e);
204
+ })();
205
+ return MSG_RE.test(raw);
206
+ }
207
+ var OP_DEPOSITS = {
208
+ // high-level flow ops
209
+ quote: "deposits.quote",
210
+ tryQuote: "deposits.tryQuote",
211
+ prepare: "deposits.prepare",
212
+ tryPrepare: "deposits.tryPrepare",
213
+ create: "deposits.create",
214
+ tryCreate: "deposits.tryCreate",
215
+ status: "deposits.status",
216
+ wait: "deposits.wait",
217
+ tryWait: "deposits.tryWait",
218
+ base: {
219
+ assertErc20Asset: "deposits.erc20-base:assertErc20Asset",
220
+ assertMatchesBase: "deposits.erc20-base:assertMatchesBase",
221
+ baseToken: "deposits.erc20-base:baseToken",
222
+ allowance: "deposits.erc20-base:allowance",
223
+ baseCost: "deposits.erc20-base:l2TransactionBaseCost",
224
+ estGas: "deposits.erc20-base:estimateGas"
225
+ },
226
+ nonbase: {
227
+ baseToken: "deposits.erc20-nonbase:baseToken",
228
+ assertNotEthAsset: "deposits.erc20-nonbase:assertNotEthAsset",
229
+ allowance: "deposits.erc20-nonbase:allowance",
230
+ allowanceFees: "deposits.erc20-nonbase:allowanceFeesBaseToken",
231
+ baseCost: "deposits.erc20-nonbase:l2TransactionBaseCost",
232
+ encodeCalldata: "deposits.erc20-nonbase:encodeSecondBridgeErc20Args",
233
+ estGas: "deposits.erc20-nonbase:estimateGas",
234
+ assertBaseIsEth: "deposits.erc20-nonbase:assertBaseIsEth",
235
+ assertBaseIsErc20: "deposits.erc20-nonbase:assertBaseIsErc20",
236
+ assertNonBaseToken: "deposits.erc20-nonbase:assertNonBaseToken",
237
+ allowanceToken: "deposits.erc20-nonbase:allowanceToken",
238
+ allowanceBase: "deposits.erc20-nonbase:allowanceBase"
239
+ },
240
+ eth: {
241
+ baseCost: "deposits.eth:l2TransactionBaseCost",
242
+ estGas: "deposits.eth:estimateGas"
243
+ },
244
+ ethNonBase: {
245
+ baseToken: "deposits.eth-nonbase:baseToken",
246
+ baseCost: "deposits.eth-nonbase:l2TransactionBaseCost",
247
+ allowanceBase: "deposits.eth-nonbase:allowanceBaseToken",
248
+ ethBalance: "deposits.eth-nonbase:getEthBalance",
249
+ encodeCalldata: "deposits.eth-nonbase:encodeSecondBridgeEthArgs",
250
+ estGas: "deposits.eth-nonbase:estimateGas",
251
+ assertEthAsset: "deposits.eth-nonbase:assertEthAsset",
252
+ assertNonEthBase: "deposits.eth-nonbase:assertNonEthBase",
253
+ assertEthBalance: "deposits.eth-nonbase:assertEthBalance"
254
+ }
255
+ };
256
+ var OP_WITHDRAWALS = {
257
+ quote: "withdrawals.quote",
258
+ tryQuote: "withdrawals.tryQuote",
259
+ prepare: "withdrawals.prepare",
260
+ tryPrepare: "withdrawals.tryPrepare",
261
+ create: "withdrawals.create",
262
+ tryCreate: "withdrawals.tryCreate",
263
+ status: "withdrawals.status",
264
+ wait: "withdrawals.wait",
265
+ tryWait: "withdrawals.tryWait",
266
+ erc20: {
267
+ allowance: "withdrawals.erc20:allowance",
268
+ ensureRegistered: "withdrawals.erc20:ensureTokenIsRegistered",
269
+ encodeAssetData: "withdrawals.erc20:encodeAssetData",
270
+ encodeWithdraw: "withdrawals.erc20:encodeWithdraw",
271
+ estGas: "withdrawals.erc20:estimateGas"
272
+ },
273
+ eth: {
274
+ encodeWithdraw: "withdrawals.eth:encodeWithdraw",
275
+ estGas: "withdrawals.eth:estimateGas"
276
+ },
277
+ ethNonBase: {
278
+ allowance: "withdrawals.eth-nonbase:allowance",
279
+ ensureRegistered: "withdrawals.eth-nonbase:ensureTokenIsRegistered",
280
+ encodeAssetData: "withdrawals.eth-nonbase:encodeAssetData",
281
+ encodeWithdraw: "withdrawals.eth-nonbase:encodeWithdraw",
282
+ estGas: "withdrawals.eth-nonbase:estimateGas",
283
+ baseToken: "withdrawals.eth-nonbase:baseToken",
284
+ assertNonEthBase: "withdrawals.eth-nonbase:assertNonEthBase"
285
+ },
286
+ finalize: {
287
+ fetchParams: {
288
+ receipt: "withdrawals.finalize.fetchParams:receipt",
289
+ findMessage: "withdrawals.finalize.fetchParams:findMessage",
290
+ decodeMessage: "withdrawals.finalize.fetchParams:decodeMessage",
291
+ rawReceipt: "withdrawals.finalize.fetchParams:rawReceipt",
292
+ messengerIndex: "withdrawals.finalize.fetchParams:messengerIndex",
293
+ proof: "withdrawals.finalize.fetchParams:proof",
294
+ network: "withdrawals.finalize.fetchParams:network",
295
+ ensureAddresses: "withdrawals.finalize.fetchParams:ensureAddresses"
296
+ },
297
+ readiness: {
298
+ ensureAddresses: "withdrawals.finalize.readiness:ensureAddresses",
299
+ isFinalized: "withdrawals.finalize.readiness:isWithdrawalFinalized",
300
+ simulate: "withdrawals.finalize.readiness:simulate"
301
+ },
302
+ isFinalized: "withdrawals.finalize.isWithdrawalFinalized",
303
+ send: "withdrawals.finalize.finalizeDeposit:send",
304
+ wait: "withdrawals.finalize.finalizeDeposit:wait",
305
+ estimate: "withdrawals.finalize.estimateFinalizationFees"
306
+ }
307
+ };
308
+
309
+ // src/core/errors/factory.ts
310
+ function createError(type, input) {
311
+ return new ZKsyncError({ ...input, type });
312
+ }
313
+ function shapeCause(err) {
314
+ const isRecord = (x) => x !== null && typeof x === "object";
315
+ let data = void 0;
316
+ if (isRecord(err)) {
317
+ const r2 = err;
318
+ const d = r2.data;
319
+ if (isRecord(d) && "data" in d) {
320
+ data = d.data;
321
+ } else if ("error" in r2 && isRecord(r2.error) && "data" in r2.error) {
322
+ data = r2.error.data;
323
+ } else if ("data" in r2) {
324
+ data = r2.data;
325
+ }
326
+ }
327
+ const r = isRecord(err) ? err : void 0;
328
+ const name = r && typeof r.name === "string" ? r.name : void 0;
329
+ const message = r && typeof r.message === "string" ? r.message : r && typeof r.shortMessage === "string" ? r.shortMessage : void 0;
330
+ const code = r && "code" in r ? r.code : void 0;
331
+ return {
332
+ name,
333
+ message,
334
+ code,
335
+ data: typeof data === "string" && data.startsWith("0x") ? `${data.slice(0, 10)}\u2026` : void 0
336
+ };
337
+ }
338
+
339
+ export { OP_DEPOSITS, OP_WITHDRAWALS, createError, factory_exports, formatEnvelopePretty, isReceiptNotFound, isZKsyncError, shapeCause };
@@ -0,0 +1,123 @@
1
+ import { createZksRpc, makeTransportFromViem } from './chunk-4HLJJKIY.js';
2
+ import { IBridgehub_default, IL1AssetRouter_default, IL1Nullifier_default, IBaseToken_default, L2NativeTokenVault_default, IL2AssetRouter_default, L1NativeTokenVault_default } from './chunk-Y75OMFK6.js';
3
+ import { L2_ASSET_ROUTER_ADDRESS, L2_NATIVE_TOKEN_VAULT_ADDRESS, L2_BASE_TOKEN_ADDRESS } from './chunk-6GCT6TLS.js';
4
+ import { getContract, createWalletClient } from 'viem';
5
+
6
+ // src/adapters/viem/rpc.ts
7
+ function zksRpcFromViem(l2Client) {
8
+ const compatible = {
9
+ request: (args) => l2Client.request(args)
10
+ };
11
+ return createZksRpc(makeTransportFromViem(compatible));
12
+ }
13
+
14
+ // src/adapters/viem/client.ts
15
+ function createViemClient(args) {
16
+ const { l1, l2, l1Wallet, l2Wallet } = args;
17
+ if (!l1Wallet.account) {
18
+ throw new Error("WalletClient must have an account configured.");
19
+ }
20
+ if (l2Wallet && !l2Wallet.account) throw new Error("l2Wallet provided without an account.");
21
+ const zks = zksRpcFromViem(l2);
22
+ let addrCache;
23
+ let cCache;
24
+ async function ensureAddresses() {
25
+ if (addrCache) return addrCache;
26
+ const bridgehub = args.overrides?.bridgehub ?? await zks.getBridgehubAddress();
27
+ const l1AssetRouter = args.overrides?.l1AssetRouter ?? await l1.readContract({
28
+ address: bridgehub,
29
+ abi: IBridgehub_default,
30
+ functionName: "assetRouter"
31
+ });
32
+ const l1Nullifier = args.overrides?.l1Nullifier ?? await l1.readContract({
33
+ address: l1AssetRouter,
34
+ abi: IL1AssetRouter_default,
35
+ functionName: "L1_NULLIFIER"
36
+ });
37
+ const l1NativeTokenVault = args.overrides?.l1NativeTokenVault ?? await l1.readContract({
38
+ address: l1Nullifier,
39
+ abi: IL1Nullifier_default,
40
+ functionName: "l1NativeTokenVault"
41
+ });
42
+ const l2AssetRouter = args.overrides?.l2AssetRouter ?? L2_ASSET_ROUTER_ADDRESS;
43
+ const l2NativeTokenVault = args.overrides?.l2NativeTokenVault ?? L2_NATIVE_TOKEN_VAULT_ADDRESS;
44
+ const l2BaseTokenSystem = args.overrides?.l2BaseTokenSystem ?? L2_BASE_TOKEN_ADDRESS;
45
+ addrCache = {
46
+ bridgehub,
47
+ l1AssetRouter,
48
+ l1Nullifier,
49
+ l1NativeTokenVault,
50
+ l2AssetRouter,
51
+ l2NativeTokenVault,
52
+ l2BaseTokenSystem
53
+ };
54
+ return addrCache;
55
+ }
56
+ async function contracts() {
57
+ if (cCache) return cCache;
58
+ const a = await ensureAddresses();
59
+ cCache = {
60
+ bridgehub: getContract({ address: a.bridgehub, abi: IBridgehub_default, client: l1 }),
61
+ l1AssetRouter: getContract({ address: a.l1AssetRouter, abi: IL1AssetRouter_default, client: l1 }),
62
+ l1Nullifier: getContract({ address: a.l1Nullifier, abi: IL1Nullifier_default, client: l1 }),
63
+ l1NativeTokenVault: getContract({
64
+ address: a.l1NativeTokenVault,
65
+ abi: L1NativeTokenVault_default,
66
+ client: l1
67
+ }),
68
+ l2AssetRouter: getContract({ address: a.l2AssetRouter, abi: IL2AssetRouter_default, client: l2 }),
69
+ l2NativeTokenVault: getContract({
70
+ address: a.l2NativeTokenVault,
71
+ abi: L2NativeTokenVault_default,
72
+ client: l2
73
+ }),
74
+ l2BaseTokenSystem: getContract({
75
+ address: a.l2BaseTokenSystem,
76
+ abi: IBaseToken_default,
77
+ client: l2
78
+ })
79
+ };
80
+ return cCache;
81
+ }
82
+ function refresh() {
83
+ addrCache = void 0;
84
+ cCache = void 0;
85
+ }
86
+ async function baseToken(chainId) {
87
+ const { bridgehub } = await ensureAddresses();
88
+ const token = await l1.readContract({
89
+ address: bridgehub,
90
+ abi: IBridgehub_default,
91
+ functionName: "baseToken",
92
+ args: [chainId]
93
+ });
94
+ return token;
95
+ }
96
+ let lazyL2;
97
+ function getL2Wallet() {
98
+ if (l2Wallet) return l2Wallet;
99
+ if (!lazyL2) {
100
+ lazyL2 = createWalletClient({
101
+ account: l1Wallet.account,
102
+ transport: l2.transport
103
+ });
104
+ }
105
+ return lazyL2;
106
+ }
107
+ return {
108
+ kind: "viem",
109
+ l1,
110
+ l2,
111
+ l1Wallet,
112
+ l2Wallet,
113
+ account: l1Wallet.account,
114
+ zks,
115
+ ensureAddresses,
116
+ contracts,
117
+ refresh,
118
+ baseToken,
119
+ getL2Wallet
120
+ };
121
+ }
122
+
123
+ export { createViemClient };