@matterlabs/zksync-js 0.0.7 → 0.0.8

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 (71) hide show
  1. package/dist/adapters/ethers/client.cjs +75 -33
  2. package/dist/adapters/ethers/client.cjs.map +1 -1
  3. package/dist/adapters/ethers/client.js +6 -6
  4. package/dist/adapters/ethers/index.cjs +122 -73
  5. package/dist/adapters/ethers/index.cjs.map +1 -1
  6. package/dist/adapters/ethers/index.js +9 -9
  7. package/dist/adapters/ethers/sdk.cjs +26 -13
  8. package/dist/adapters/ethers/sdk.cjs.map +1 -1
  9. package/dist/adapters/ethers/sdk.js +7 -7
  10. package/dist/adapters/viem/client.cjs +75 -33
  11. package/dist/adapters/viem/client.cjs.map +1 -1
  12. package/dist/adapters/viem/client.js +4 -4
  13. package/dist/adapters/viem/index.cjs +122 -73
  14. package/dist/adapters/viem/index.cjs.map +1 -1
  15. package/dist/adapters/viem/index.js +8 -8
  16. package/dist/adapters/viem/sdk.cjs +45 -34
  17. package/dist/adapters/viem/sdk.cjs.map +1 -1
  18. package/dist/adapters/viem/sdk.js +6 -6
  19. package/dist/{chunk-GIXLOHLK.js → chunk-3GFCAGGI.js} +1430 -7
  20. package/dist/{chunk-KAMEGD6I.js → chunk-5V2JRM5J.js} +1 -1
  21. package/dist/{chunk-EWLA4NUE.js → chunk-63DNJXS3.js} +7 -8
  22. package/dist/{chunk-NCR42O6O.js → chunk-C3AGOEHR.js} +11 -1
  23. package/dist/{chunk-NGXRO2ZX.js → chunk-FGXRG2JS.js} +4 -4
  24. package/dist/{chunk-VRL6Y4YJ.js → chunk-L343N56B.js} +1 -1
  25. package/dist/{chunk-KRIRXY74.js → chunk-LNIEQ7AN.js} +7 -8
  26. package/dist/{chunk-NNFWIAVG.js → chunk-NODVRI3E.js} +2 -2
  27. package/dist/{chunk-GNERKUWO.js → chunk-NVULC4JB.js} +2 -2
  28. package/dist/{chunk-7VP6742W.js → chunk-ODMBZ2VX.js} +3 -3
  29. package/dist/{chunk-P5PIWVEO.js → chunk-QZVYN3YA.js} +30 -7
  30. package/dist/{chunk-WY36Z6YB.js → chunk-SHQQI3UD.js} +57 -19
  31. package/dist/core/abi.d.ts +5 -0
  32. package/dist/core/constants.cjs +10 -0
  33. package/dist/core/constants.cjs.map +1 -1
  34. package/dist/core/constants.d.ts +10 -0
  35. package/dist/core/constants.js +1 -1
  36. package/dist/core/index.cjs +1673 -184
  37. package/dist/core/index.cjs.map +1 -1
  38. package/dist/core/index.d.ts +2 -1
  39. package/dist/core/index.js +5 -5
  40. package/dist/core/internal/abis/IERC7786Attributes.d.ts +42 -0
  41. package/dist/core/internal/abis/IInteropCenter.d.ts +211 -0
  42. package/dist/core/internal/abis/IInteropHandler.d.ts +166 -0
  43. package/dist/core/internal/abis/InteropCenter.d.ts +578 -0
  44. package/dist/core/internal/abis/InteropRootStorage.d.ts +20 -0
  45. package/dist/core/internal/abis/L2MessageVerification.d.ts +277 -0
  46. package/dist/core/resources/interop/attributes/bundle.d.ts +6 -0
  47. package/dist/core/resources/interop/attributes/call.d.ts +6 -0
  48. package/dist/core/resources/interop/attributes/index.d.ts +4 -0
  49. package/dist/core/resources/interop/attributes/resource.d.ts +12 -0
  50. package/dist/core/resources/interop/attributes/types.d.ts +6 -0
  51. package/dist/core/resources/interop/events.d.ts +7 -0
  52. package/dist/core/resources/interop/finalization.d.ts +61 -0
  53. package/dist/core/resources/interop/plan.d.ts +39 -0
  54. package/dist/core/resources/interop/route.d.ts +15 -0
  55. package/dist/core/rpc/types.d.ts +9 -0
  56. package/dist/core/types/errors.d.ts +43 -2
  57. package/dist/core/types/flows/base.d.ts +1 -1
  58. package/dist/core/types/flows/interop.d.ts +231 -0
  59. package/dist/core/types/flows/withdrawals.d.ts +0 -8
  60. package/dist/core/types/transactions.d.ts +10 -0
  61. package/dist/core/utils/addr.d.ts +2 -2
  62. package/dist/core/utils/events.d.ts +12 -0
  63. package/dist/core/utils/hash.d.ts +5 -0
  64. package/dist/core/utils/index.d.ts +5 -0
  65. package/dist/core/utils/number.d.ts +2 -0
  66. package/dist/index.cjs +1683 -184
  67. package/dist/index.cjs.map +1 -1
  68. package/dist/index.d.ts +2 -1
  69. package/dist/index.js +5 -5
  70. package/package.json +6 -2
  71. package/dist/core/resources/withdrawals/events.d.ts +0 -9
@@ -1,9 +1,9 @@
1
- export { createEthersClient as createClient, createEthersClient } from '../../chunk-NGXRO2ZX.js';
2
- export { buildDirectRequestStruct, createDepositsResource, createEthersSdk, createFinalizationServices, createTokensResource, createWithdrawalsResource, encodeNativeTokenVaultTransferData, encodeSecondBridgeArgs, encodeSecondBridgeDataV1, encodeSecondBridgeErc20Args, encodeSecondBridgeEthArgs } from '../../chunk-EWLA4NUE.js';
3
- export { classifyReadinessFromRevert, createErrorHandlers, decodeRevert, registerErrorAbi, toZKsyncError } from '../../chunk-GNERKUWO.js';
4
- import '../../chunk-NNFWIAVG.js';
5
- import '../../chunk-P5PIWVEO.js';
6
- import '../../chunk-KAMEGD6I.js';
7
- import '../../chunk-WY36Z6YB.js';
8
- import '../../chunk-GIXLOHLK.js';
9
- import '../../chunk-NCR42O6O.js';
1
+ export { createEthersClient as createClient, createEthersClient } from '../../chunk-FGXRG2JS.js';
2
+ export { buildDirectRequestStruct, createDepositsResource, createEthersSdk, createFinalizationServices, createTokensResource, createWithdrawalsResource, encodeNativeTokenVaultTransferData, encodeSecondBridgeArgs, encodeSecondBridgeDataV1, encodeSecondBridgeErc20Args, encodeSecondBridgeEthArgs } from '../../chunk-63DNJXS3.js';
3
+ export { classifyReadinessFromRevert, createErrorHandlers, decodeRevert, registerErrorAbi, toZKsyncError } from '../../chunk-NVULC4JB.js';
4
+ import '../../chunk-NODVRI3E.js';
5
+ import '../../chunk-QZVYN3YA.js';
6
+ import '../../chunk-5V2JRM5J.js';
7
+ import '../../chunk-SHQQI3UD.js';
8
+ import '../../chunk-3GFCAGGI.js';
9
+ import '../../chunk-C3AGOEHR.js';
@@ -5,6 +5,14 @@ var sha3 = require('@noble/hashes/sha3');
5
5
  var utils = require('@noble/hashes/utils');
6
6
 
7
7
  // src/adapters/ethers/resources/deposits/services/verification.ts
8
+
9
+ // src/core/utils/hash.ts
10
+ var RegExpHex = /^0x[0-9a-fA-F]*$/;
11
+ var isHash = (x, length) => {
12
+ if (!x || typeof x !== "string") return false;
13
+ return (x.length === length) && RegExpHex.test(x);
14
+ };
15
+ var isHash66 = (x) => isHash(x, 66);
8
16
  var k256hex = (s) => `0x${utils.bytesToHex(sha3.keccak_256(utils.utf8ToBytes(s)))}`.toLowerCase();
9
17
  var FORMAL_ETH_ADDRESS = "0x0000000000000000000000000000000000000000";
10
18
  var ETH_ADDRESS = "0x0000000000000000000000000000000000000001";
@@ -23,8 +31,11 @@ var DEFAULT_PUBDATA_BYTES = 155n;
23
31
  var DEFAULT_ABI_BYTES = 400n;
24
32
  var SAFE_L1_BRIDGE_GAS = 700000n;
25
33
 
34
+ // src/core/utils/number.ts
35
+ var isNumber = (x) => typeof x === "number" && Number.isFinite(x);
36
+ var isBigint = (x) => typeof x === "bigint";
37
+
26
38
  // src/core/utils/addr.ts
27
- var isHash66 = (x) => !!x && x.startsWith("0x") && x.length === 66;
28
39
  function isAddressEq(a, b) {
29
40
  return a.toLowerCase() === b.toLowerCase();
30
41
  }
@@ -53,7 +64,7 @@ function shortJSON(v, max = 240) {
53
64
  try {
54
65
  const s = JSON.stringify(
55
66
  v,
56
- (_k, val) => typeof val === "bigint" ? `${val.toString()}n` : val
67
+ (_k, val) => isBigint(val) ? `${val.toString()}n` : val
57
68
  );
58
69
  return s.length > max ? elideMiddle(s, max) : s;
59
70
  } catch {
@@ -73,7 +84,7 @@ function formatContextLine(ctx) {
73
84
  if (txHash !== void 0)
74
85
  parts.push(`txHash=${typeof txHash === "string" ? txHash : shortJSON(txHash, 96)}`);
75
86
  if (nonce !== void 0) {
76
- const nonceStr = typeof nonce === "string" || typeof nonce === "number" || typeof nonce === "bigint" ? String(nonce) : shortJSON(nonce, 48);
87
+ const nonceStr = typeof nonce === "string" || isNumber(nonce) || isBigint(nonce) ? String(nonce) : shortJSON(nonce, 48);
77
88
  parts.push(`nonce=${nonceStr}`);
78
89
  }
79
90
  return parts.length ? ` ${kv("Context", parts.join(" \u2022 "))}` : void 0;
@@ -103,17 +114,17 @@ function formatCause(c) {
103
114
  const head = [];
104
115
  if (obj.name !== void 0) {
105
116
  const nameVal = obj.name;
106
- const nameStr = typeof nameVal === "string" || typeof nameVal === "number" || typeof nameVal === "bigint" || typeof nameVal === "boolean" ? String(nameVal) : shortJSON(nameVal, 120);
117
+ const nameStr = typeof nameVal === "string" || isNumber(nameVal) || isBigint(nameVal) || typeof nameVal === "boolean" ? String(nameVal) : shortJSON(nameVal, 120);
107
118
  head.push(`name=${nameStr}`);
108
119
  }
109
120
  if (obj.code !== void 0) {
110
121
  const codeVal = obj.code;
111
- const codeStr = typeof codeVal === "string" || typeof codeVal === "number" || typeof codeVal === "bigint" || typeof codeVal === "boolean" ? String(codeVal) : shortJSON(codeVal, 120);
122
+ const codeStr = typeof codeVal === "string" || isNumber(codeVal) || isBigint(codeVal) || typeof codeVal === "boolean" ? String(codeVal) : shortJSON(codeVal, 120);
112
123
  head.push(`code=${codeStr}`);
113
124
  }
114
125
  if (head.length) out.push(` ${kv("Cause", head.join(" "))}`);
115
126
  if (obj.message) {
116
- 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);
127
+ const messageStr = typeof obj.message === "string" || isNumber(obj.message) || isBigint(obj.message) || typeof obj.message === "boolean" ? String(obj.message) : shortJSON(obj.message, 600);
117
128
  out.push(` message=${elideMiddle(messageStr, 600)}`);
118
129
  }
119
130
  if (obj.data) {
@@ -5420,8 +5431,7 @@ function routeErc20NonBase2() {
5420
5431
  tx: approveTx
5421
5432
  });
5422
5433
  }
5423
- const resolved = ctx.resolvedToken ?? (ctx.tokens ? await ctx.tokens.resolve(p.token, { chain: "l2" }) : void 0);
5424
- const assetId = resolved?.assetId ?? await wrapAs7(
5434
+ const assetId = await wrapAs7(
5425
5435
  "CONTRACT",
5426
5436
  OP_WITHDRAWALS.erc20.ensureRegistered,
5427
5437
  async () => {
@@ -5460,7 +5470,7 @@ function routeErc20NonBase2() {
5460
5470
  data: dataWithdraw,
5461
5471
  from: ctx.sender
5462
5472
  };
5463
- const withdrawGas = await quoteL2Gas4({ ctx, tx: withdrawTx });
5473
+ const withdrawGas = current >= p.amount ? await quoteL2Gas4({ ctx, tx: withdrawTx }) : void 0;
5464
5474
  if (withdrawGas) {
5465
5475
  withdrawTx.gasLimit = withdrawGas.gasLimit;
5466
5476
  withdrawTx.maxFeePerGas = withdrawGas.maxFeePerGas;
@@ -5481,11 +5491,14 @@ function routeErc20NonBase2() {
5481
5491
  };
5482
5492
  }
5483
5493
 
5484
- // src/core/resources/withdrawals/events.ts
5494
+ // src/core/utils/events.ts
5495
+ function extractPreferAddress(opts) {
5496
+ const preferAddr = typeof opts?.prefer === "object" ? opts.prefer.address : opts?.prefer === "assetRouter" ? L2_ASSET_ROUTER_ADDRESS : L1_MESSENGER_ADDRESS;
5497
+ return (preferAddr || L1_MESSENGER_ADDRESS).toLowerCase();
5498
+ }
5485
5499
  function findL1MessageSentLog(receipt, opts) {
5486
5500
  const index = opts?.index;
5487
- const preferAddr = typeof opts?.prefer === "object" ? opts?.prefer.address : opts?.prefer === "assetRouter" ? L2_ASSET_ROUTER_ADDRESS : L1_MESSENGER_ADDRESS;
5488
- const prefer = (preferAddr ?? L1_MESSENGER_ADDRESS).toLowerCase();
5501
+ const preferAddr = extractPreferAddress(opts);
5489
5502
  const matches = receipt.logs.filter((lg) => {
5490
5503
  const t0 = (lg.topics?.[0] ?? "").toLowerCase();
5491
5504
  return t0 === TOPIC_L1_MESSAGE_SENT_NEW || t0 === TOPIC_L1_MESSAGE_SENT_LEG;
@@ -5493,7 +5506,7 @@ function findL1MessageSentLog(receipt, opts) {
5493
5506
  if (!matches.length) {
5494
5507
  throw new Error("No L1MessageSent event found in L2 receipt logs.");
5495
5508
  }
5496
- const preferred = matches.find((lg) => (lg.address ?? "").toLowerCase() === prefer);
5509
+ const preferred = matches.find((lg) => (lg.address ?? "").toLowerCase() === preferAddr);
5497
5510
  const chosen = preferred ?? matches[index] ?? matches[0];
5498
5511
  if (!chosen) {
5499
5512
  throw new Error("No suitable L1MessageSent event found.");