@matterlabs/zksync-js 0.0.1 → 0.0.2

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 (80) hide show
  1. package/README.md +12 -12
  2. package/dist/adapters/ethers/client.cjs +642 -1
  3. package/dist/adapters/ethers/client.cjs.map +1 -1
  4. package/dist/adapters/ethers/client.js +6 -5
  5. package/dist/adapters/ethers/estimator.d.ts +4 -0
  6. package/dist/adapters/ethers/index.cjs +934 -801
  7. package/dist/adapters/ethers/index.cjs.map +1 -1
  8. package/dist/adapters/ethers/index.js +9 -8
  9. package/dist/adapters/ethers/resources/deposits/context.d.ts +5 -5
  10. package/dist/adapters/ethers/resources/deposits/routes/types.d.ts +2 -6
  11. package/dist/adapters/ethers/resources/deposits/services/fee.d.ts +6 -0
  12. package/dist/adapters/ethers/resources/deposits/services/gas.d.ts +40 -0
  13. package/dist/adapters/ethers/resources/utils.d.ts +4 -15
  14. package/dist/adapters/ethers/resources/withdrawals/context.d.ts +4 -4
  15. package/dist/adapters/ethers/resources/withdrawals/routes/types.d.ts +2 -2
  16. package/dist/adapters/ethers/resources/withdrawals/services/fees.d.ts +14 -0
  17. package/dist/adapters/ethers/resources/withdrawals/services/gas.d.ts +12 -0
  18. package/dist/adapters/ethers/sdk.cjs +947 -1292
  19. package/dist/adapters/ethers/sdk.cjs.map +1 -1
  20. package/dist/adapters/ethers/sdk.js +7 -6
  21. package/dist/adapters/viem/client.cjs.map +1 -1
  22. package/dist/adapters/viem/client.d.ts +1 -1
  23. package/dist/adapters/viem/client.js +4 -5
  24. package/dist/adapters/viem/estimator.d.ts +4 -0
  25. package/dist/adapters/viem/index.cjs +944 -662
  26. package/dist/adapters/viem/index.cjs.map +1 -1
  27. package/dist/adapters/viem/index.js +8 -8
  28. package/dist/adapters/viem/resources/deposits/context.d.ts +5 -5
  29. package/dist/adapters/viem/resources/deposits/routes/types.d.ts +2 -6
  30. package/dist/adapters/viem/resources/deposits/services/fee.d.ts +6 -0
  31. package/dist/adapters/viem/resources/deposits/services/gas.d.ts +36 -0
  32. package/dist/adapters/viem/resources/utils.d.ts +3 -16
  33. package/dist/adapters/viem/resources/withdrawals/context.d.ts +3 -6
  34. package/dist/adapters/viem/resources/withdrawals/routes/types.d.ts +12 -2
  35. package/dist/adapters/viem/resources/withdrawals/services/fee.d.ts +17 -0
  36. package/dist/adapters/viem/resources/withdrawals/services/gas.d.ts +12 -0
  37. package/dist/adapters/viem/sdk.cjs +877 -563
  38. package/dist/adapters/viem/sdk.cjs.map +1 -1
  39. package/dist/adapters/viem/sdk.d.ts +1 -1
  40. package/dist/adapters/viem/sdk.js +6 -6
  41. package/dist/{chunk-3LALBFFE.js → chunk-3MRGU4HV.js} +9 -5
  42. package/dist/{chunk-4HLJJKIY.js → chunk-6K6VJQAL.js} +2 -2
  43. package/dist/{chunk-CGO27P7F.js → chunk-BCCKWWOX.js} +540 -741
  44. package/dist/{chunk-6GCT6TLS.js → chunk-F2ENUV3A.js} +13 -1
  45. package/dist/{chunk-DI2CJDPZ.js → chunk-HLUANWGN.js} +2 -2
  46. package/dist/{chunk-Y75OMFK6.js → chunk-M5J2MM2U.js} +351 -1
  47. package/dist/{chunk-263G6636.js → chunk-NCAIVYBR.js} +1 -14
  48. package/dist/{chunk-7M4V3FMT.js → chunk-OC6ZVLSP.js} +669 -559
  49. package/dist/chunk-QJS6ETEE.js +217 -0
  50. package/dist/chunk-XRE7H466.js +157 -0
  51. package/dist/{chunk-BD2LUO5T.js → chunk-YUK547UF.js} +3 -3
  52. package/dist/core/abi.d.ts +9 -0
  53. package/dist/core/adapters/interfaces.d.ts +25 -0
  54. package/dist/core/constants.cjs +12 -0
  55. package/dist/core/constants.cjs.map +1 -1
  56. package/dist/core/constants.d.ts +6 -0
  57. package/dist/core/constants.js +1 -1
  58. package/dist/core/index.cjs +4504 -1
  59. package/dist/core/index.cjs.map +1 -1
  60. package/dist/core/index.d.ts +1 -0
  61. package/dist/core/index.js +4 -4
  62. package/dist/core/resources/deposits/fee.d.ts +15 -0
  63. package/dist/core/resources/deposits/gas.d.ts +38 -0
  64. package/dist/core/resources/withdrawals/gas.d.ts +14 -0
  65. package/dist/core/types/errors.d.ts +1 -1
  66. package/dist/core/types/fees.d.ts +40 -0
  67. package/dist/core/types/flows/base.d.ts +0 -10
  68. package/dist/core/types/flows/deposits.d.ts +20 -6
  69. package/dist/core/types/flows/route.d.ts +2 -3
  70. package/dist/core/types/flows/withdrawals.d.ts +12 -6
  71. package/dist/index.cjs +4516 -1
  72. package/dist/index.cjs.map +1 -1
  73. package/dist/index.d.ts +1 -0
  74. package/dist/index.js +4 -4
  75. package/package.json +5 -1
  76. package/dist/adapters/ethers/resources/withdrawals/routes/eth-nonbase.d.ts +0 -2
  77. package/dist/adapters/viem/resources/withdrawals/routes/eth-nonbase.d.ts +0 -2
  78. package/dist/chunk-B77GWPO5.js +0 -339
  79. package/dist/core/internal/abi-registry.d.ts +0 -9
  80. package/dist/core/utils/gas.d.ts +0 -13
@@ -1,339 +0,0 @@
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 };
@@ -1,9 +0,0 @@
1
- export { default as IBridgehubABI } from './abis/IBridgehub';
2
- export { default as IL1AssetRouterABI } from './abis/IL1AssetRouter';
3
- export { default as IL1NullifierABI } from './abis/IL1Nullifier';
4
- export { default as IL2AssetRouterABI } from './abis/IL2AssetRouter';
5
- export { default as L1NativeTokenVaultABI } from './abis/L1NativeTokenVault';
6
- export { default as L2NativeTokenVaultABI } from './abis/L2NativeTokenVault';
7
- export { default as IBaseTokenABI } from './abis/IBaseToken';
8
- export { default as IERC20ABI } from './abis/IERC20';
9
- export { default as MailboxABI } from './abis/Mailbox';
@@ -1,13 +0,0 @@
1
- import type { Eip1559GasOverrides } from '../types/flows/base';
2
- /**
3
- * Ensures a user-supplied override does not include legacy gas properties.
4
- * Throws if `gasPrice` is present.
5
- */
6
- export declare function assertNoLegacyGas(overrides: Eip1559GasOverrides | (Eip1559GasOverrides & Record<string, unknown>) | undefined): void;
7
- /**
8
- * Validates that maxPriorityFeePerGas does not exceed maxFeePerGas.
9
- */
10
- export declare function assertPriorityFeeBounds(fees: {
11
- maxFeePerGas: bigint;
12
- maxPriorityFeePerGas: bigint;
13
- }): void;