@matterlabs/zksync-js 0.0.7 → 0.0.9

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 (105) hide show
  1. package/dist/adapters/ethers/client.cjs +1705 -259
  2. package/dist/adapters/ethers/client.cjs.map +1 -1
  3. package/dist/adapters/ethers/client.d.ts +11 -0
  4. package/dist/adapters/ethers/client.js +6 -6
  5. package/dist/adapters/ethers/index.cjs +5254 -2335
  6. package/dist/adapters/ethers/index.cjs.map +1 -1
  7. package/dist/adapters/ethers/index.d.ts +4 -0
  8. package/dist/adapters/ethers/index.js +9 -9
  9. package/dist/adapters/ethers/resources/contracts/types.d.ts +15 -0
  10. package/dist/adapters/ethers/resources/deposits/context.d.ts +3 -3
  11. package/dist/adapters/ethers/resources/deposits/services/gas.d.ts +2 -2
  12. package/dist/adapters/ethers/resources/deposits/services/verification.d.ts +1 -1
  13. package/dist/adapters/ethers/resources/interop/address.d.ts +18 -0
  14. package/dist/adapters/ethers/resources/interop/attributes/resource.d.ts +9 -0
  15. package/dist/adapters/ethers/resources/interop/context.d.ts +36 -0
  16. package/dist/adapters/ethers/resources/interop/index.d.ts +63 -0
  17. package/dist/adapters/ethers/resources/interop/resolvers.d.ts +9 -0
  18. package/dist/adapters/ethers/resources/interop/routes/direct.d.ts +2 -0
  19. package/dist/adapters/ethers/resources/interop/routes/indirect.d.ts +2 -0
  20. package/dist/adapters/ethers/resources/interop/routes/types.d.ts +13 -0
  21. package/dist/adapters/ethers/resources/interop/services/erc20.d.ts +15 -0
  22. package/dist/adapters/ethers/resources/interop/services/finalization/bundle.d.ts +15 -0
  23. package/dist/adapters/ethers/resources/interop/services/finalization/data-fetchers.d.ts +17 -0
  24. package/dist/adapters/ethers/resources/interop/services/finalization/decoders.d.ts +12 -0
  25. package/dist/adapters/ethers/resources/interop/services/finalization/index.d.ts +13 -0
  26. package/dist/adapters/ethers/resources/interop/services/finalization/polling.d.ts +7 -0
  27. package/dist/adapters/ethers/resources/interop/services/finalization/status.d.ts +5 -0
  28. package/dist/adapters/ethers/resources/interop/services/finalization/topics.d.ts +6 -0
  29. package/dist/adapters/ethers/resources/interop/services/starter-data.d.ts +6 -0
  30. package/dist/adapters/ethers/resources/interop/types.d.ts +16 -0
  31. package/dist/adapters/ethers/resources/withdrawals/context.d.ts +2 -2
  32. package/dist/adapters/ethers/sdk.cjs +3384 -931
  33. package/dist/adapters/ethers/sdk.cjs.map +1 -1
  34. package/dist/adapters/ethers/sdk.d.ts +10 -8
  35. package/dist/adapters/ethers/sdk.js +7 -7
  36. package/dist/adapters/viem/client.cjs +760 -64
  37. package/dist/adapters/viem/client.cjs.map +1 -1
  38. package/dist/adapters/viem/client.js +6 -4
  39. package/dist/adapters/viem/index.cjs +404 -276
  40. package/dist/adapters/viem/index.cjs.map +1 -1
  41. package/dist/adapters/viem/index.d.ts +1 -0
  42. package/dist/adapters/viem/index.js +9 -8
  43. package/dist/adapters/viem/resources/deposits/context.d.ts +3 -3
  44. package/dist/adapters/viem/resources/deposits/services/gas.d.ts +2 -2
  45. package/dist/adapters/viem/resources/deposits/services/verification.d.ts +1 -1
  46. package/dist/adapters/viem/resources/withdrawals/context.d.ts +2 -2
  47. package/dist/adapters/viem/sdk.cjs +84 -92
  48. package/dist/adapters/viem/sdk.cjs.map +1 -1
  49. package/dist/adapters/viem/sdk.js +6 -6
  50. package/dist/{chunk-KRIRXY74.js → chunk-5AG6B7UX.js} +38 -63
  51. package/dist/{chunk-NNFWIAVG.js → chunk-AIFHAPJC.js} +9 -3
  52. package/dist/{chunk-NCR42O6O.js → chunk-C3AGOEHR.js} +11 -1
  53. package/dist/{chunk-GIXLOHLK.js → chunk-FBKBF7YM.js} +1534 -12
  54. package/dist/{chunk-VRL6Y4YJ.js → chunk-IYEDEUXG.js} +1 -1
  55. package/dist/chunk-JNWHQJU3.js +209 -0
  56. package/dist/{chunk-7VP6742W.js → chunk-KLNFDFLA.js} +43 -32
  57. package/dist/{chunk-GNERKUWO.js → chunk-QDJOEVGJ.js} +2 -2
  58. package/dist/{chunk-EWLA4NUE.js → chunk-RRKVUW3G.js} +1377 -78
  59. package/dist/{chunk-KAMEGD6I.js → chunk-SRPKTXIF.js} +1 -1
  60. package/dist/{chunk-WY36Z6YB.js → chunk-UIXU35ZU.js} +57 -19
  61. package/dist/{chunk-P5PIWVEO.js → chunk-ZVHFVUDE.js} +14 -26
  62. package/dist/core/abi.d.ts +5 -0
  63. package/dist/core/constants.cjs +10 -0
  64. package/dist/core/constants.cjs.map +1 -1
  65. package/dist/core/constants.d.ts +10 -0
  66. package/dist/core/constants.js +1 -1
  67. package/dist/core/index.cjs +1676 -186
  68. package/dist/core/index.cjs.map +1 -1
  69. package/dist/core/index.d.ts +2 -1
  70. package/dist/core/index.js +5 -5
  71. package/dist/core/internal/abis/IERC7786Attributes.d.ts +42 -0
  72. package/dist/core/internal/abis/IInteropCenter.d.ts +211 -0
  73. package/dist/core/internal/abis/IInteropHandler.d.ts +166 -0
  74. package/dist/core/internal/abis/InteropCenter.d.ts +578 -0
  75. package/dist/core/internal/abis/InteropRootStorage.d.ts +20 -0
  76. package/dist/core/internal/abis/L2MessageVerification.d.ts +277 -0
  77. package/dist/core/resources/interop/attributes/bundle.d.ts +6 -0
  78. package/dist/core/resources/interop/attributes/call.d.ts +6 -0
  79. package/dist/core/resources/interop/attributes/index.d.ts +4 -0
  80. package/dist/core/resources/interop/attributes/resource.d.ts +12 -0
  81. package/dist/core/resources/interop/attributes/types.d.ts +4 -0
  82. package/dist/core/resources/interop/events.d.ts +7 -0
  83. package/dist/core/resources/interop/finalization.d.ts +60 -0
  84. package/dist/core/resources/interop/plan.d.ts +39 -0
  85. package/dist/core/resources/interop/route.d.ts +15 -0
  86. package/dist/core/rpc/types.d.ts +9 -0
  87. package/dist/core/types/errors.d.ts +56 -5
  88. package/dist/core/types/fees.d.ts +9 -0
  89. package/dist/core/types/flows/base.d.ts +1 -1
  90. package/dist/core/types/flows/interop.d.ts +207 -0
  91. package/dist/core/types/flows/withdrawals.d.ts +0 -8
  92. package/dist/core/types/primitives.d.ts +1 -0
  93. package/dist/core/types/transactions.d.ts +10 -0
  94. package/dist/core/utils/addr.d.ts +2 -2
  95. package/dist/core/utils/events.d.ts +12 -0
  96. package/dist/core/utils/hash.d.ts +5 -0
  97. package/dist/core/utils/index.d.ts +5 -0
  98. package/dist/core/utils/number.d.ts +2 -0
  99. package/dist/index.cjs +1686 -186
  100. package/dist/index.cjs.map +1 -1
  101. package/dist/index.d.ts +2 -1
  102. package/dist/index.js +5 -5
  103. package/package.json +6 -2
  104. package/dist/chunk-NGXRO2ZX.js +0 -142
  105. package/dist/core/resources/withdrawals/events.d.ts +0 -9
@@ -4,6 +4,7 @@ export * from './sdk';
4
4
  export * from './resources/utils';
5
5
  export { createDepositsResource } from './resources/deposits';
6
6
  export type { DepositsResource } from './resources/deposits';
7
+ export { getL2TransactionHashFromLogs } from './resources/deposits/services/verification';
7
8
  export { createWithdrawalsResource } from './resources/withdrawals';
8
9
  export { createFinalizationServices } from './resources/withdrawals';
9
10
  export type { WithdrawalsResource, FinalizationServices } from './resources/withdrawals';
@@ -1,8 +1,9 @@
1
- export { buildDirectRequestStruct, classifyReadinessFromRevert, createContractsResource, createDepositsResource, createErrorHandlers, createFinalizationServices, createTokensResource, createViemSdk, createWithdrawalsResource, decodeRevert, encodeNativeTokenVaultTransferData, encodeSecondBridgeArgs, encodeSecondBridgeDataV1, encodeSecondBridgeErc20Args, encodeSecondBridgeEthArgs, registerErrorAbi, toZKsyncError } from '../../chunk-KRIRXY74.js';
2
- import '../../chunk-NNFWIAVG.js';
3
- import '../../chunk-P5PIWVEO.js';
4
- import '../../chunk-KAMEGD6I.js';
5
- export { createViemClient as createClient, createViemClient } from '../../chunk-7VP6742W.js';
6
- import '../../chunk-WY36Z6YB.js';
7
- import '../../chunk-GIXLOHLK.js';
8
- import '../../chunk-NCR42O6O.js';
1
+ export { buildDirectRequestStruct, classifyReadinessFromRevert, createContractsResource, createDepositsResource, createErrorHandlers, createFinalizationServices, createTokensResource, createViemSdk, createWithdrawalsResource, decodeRevert, encodeNativeTokenVaultTransferData, encodeSecondBridgeArgs, encodeSecondBridgeDataV1, encodeSecondBridgeErc20Args, encodeSecondBridgeEthArgs, getL2TransactionHashFromLogs, registerErrorAbi, toZKsyncError } from '../../chunk-5AG6B7UX.js';
2
+ import '../../chunk-AIFHAPJC.js';
3
+ import '../../chunk-ZVHFVUDE.js';
4
+ export { createViemClient as createClient, createViemClient } from '../../chunk-KLNFDFLA.js';
5
+ import '../../chunk-UIXU35ZU.js';
6
+ import '../../chunk-QDJOEVGJ.js';
7
+ import '../../chunk-SRPKTXIF.js';
8
+ import '../../chunk-FBKBF7YM.js';
9
+ import '../../chunk-C3AGOEHR.js';
@@ -2,7 +2,7 @@ import type { ViemClient } from '../../client';
2
2
  import type { Address, Hex } from '../../../../core/types/primitives';
3
3
  import type { DepositParams, DepositRoute } from '../../../../core/types/flows/deposits';
4
4
  import type { CommonCtx } from '../../../../core/types/flows/base';
5
- import type { TxOverrides } from '../../../../core/types/fees';
5
+ import { type TxGasOverrides } from '../../../../core/types/fees';
6
6
  import type { ResolvedToken, TokensResource } from '../../../../core/types/flows/token';
7
7
  import type { ContractsResource } from '../contracts';
8
8
  export interface BuildCtx extends CommonCtx {
@@ -14,7 +14,7 @@ export interface BuildCtx extends CommonCtx {
14
14
  baseTokenL1: Address;
15
15
  baseIsEth: boolean;
16
16
  l1AssetRouter: Address;
17
- gasOverrides?: TxOverrides;
17
+ gasOverrides?: TxGasOverrides;
18
18
  l2GasLimit?: bigint;
19
19
  gasPerPubdata: bigint;
20
20
  operatorTip: bigint;
@@ -33,7 +33,7 @@ export declare function commonCtx(p: DepositParams, client: ViemClient, tokens:
33
33
  bridgehub: `0x${string}`;
34
34
  chainIdL2: bigint;
35
35
  sender: `0x${string}`;
36
- gasOverrides: TxOverrides | undefined;
36
+ gasOverrides: TxGasOverrides | undefined;
37
37
  l2GasLimit: bigint | undefined;
38
38
  gasPerPubdata: bigint;
39
39
  operatorTip: bigint;
@@ -1,14 +1,14 @@
1
1
  import { type TransactionRequest } from 'viem';
2
2
  import type { BuildCtx } from '../context';
3
3
  import type { DepositRoute } from '../../../../../core/types/flows/deposits';
4
- import type { TxOverrides } from '../../../../../core/types/fees';
4
+ import type { TxGasOverrides } from '../../../../../core/types/fees';
5
5
  import type { Address } from '../../../../../core/types/primitives';
6
6
  import { type GasQuote } from '../../../../../core/resources/deposits/gas';
7
7
  export type { GasQuote };
8
8
  export type QuoteL1GasInput = {
9
9
  ctx: BuildCtx;
10
10
  tx: TransactionRequest;
11
- overrides?: TxOverrides;
11
+ overrides?: TxGasOverrides;
12
12
  fallbackGasLimit?: bigint;
13
13
  };
14
14
  export type QuoteL2GasInput = {
@@ -1,6 +1,6 @@
1
1
  import type { PublicClient, TransactionReceipt, Log } from 'viem';
2
2
  import type { Hex } from '../../../../../core/types/primitives';
3
- export declare function extractL2TxHashFromL1Logs(logs: ReadonlyArray<Log>): Hex | null;
3
+ export declare function getL2TransactionHashFromLogs(logs: ReadonlyArray<Log>): Hex | null;
4
4
  export declare function waitForL2ExecutionFromL1Tx(l1: PublicClient, l2: PublicClient, l1TxHash: Hex): Promise<{
5
5
  l2Receipt: TransactionReceipt;
6
6
  l2TxHash: Hex;
@@ -2,7 +2,7 @@ import type { ViemClient } from '../../client';
2
2
  import type { Address } from '../../../../core/types/primitives';
3
3
  import { type WithdrawParams, type WithdrawRoute } from '../../../../core/types/flows/withdrawals';
4
4
  import type { CommonCtx } from '../../../../core/types/flows/base';
5
- import type { TxOverrides } from '../../../../core/types/fees';
5
+ import { type TxGasOverrides } from '../../../../core/types/fees';
6
6
  import type { Hex } from '../../../../core/types/primitives';
7
7
  import type { ResolvedToken, TokensResource } from '../../../../core/types/flows/token';
8
8
  import type { ContractsResource } from '../contracts';
@@ -20,7 +20,7 @@ export interface BuildCtx extends CommonCtx {
20
20
  l2AssetRouter: Address;
21
21
  l2NativeTokenVault: Address;
22
22
  l2BaseTokenSystem: Address;
23
- gasOverrides?: TxOverrides;
23
+ gasOverrides?: TxGasOverrides;
24
24
  }
25
25
  export declare function commonCtx(p: WithdrawParams, client: ViemClient, tokens: TokensResource, contracts: ContractsResource): Promise<BuildCtx & {
26
26
  route: WithdrawRoute;
@@ -3646,6 +3646,12 @@ var MailboxABI = [
3646
3646
  ];
3647
3647
  var Mailbox_default = MailboxABI;
3648
3648
 
3649
+ // src/core/types/fees.ts
3650
+ function toGasOverrides(overrides) {
3651
+ const { nonce: _, ...gas } = overrides;
3652
+ return gas;
3653
+ }
3654
+
3649
3655
  // src/adapters/viem/resources/deposits/context.ts
3650
3656
  async function commonCtx(p, client, tokens, contracts) {
3651
3657
  const { bridgehub, l1AssetRouter } = await contracts.addresses();
@@ -3680,7 +3686,7 @@ async function commonCtx(p, client, tokens, contracts) {
3680
3686
  bridgehub,
3681
3687
  chainIdL2: BigInt(chainId),
3682
3688
  sender,
3683
- gasOverrides: p.l1TxOverrides,
3689
+ gasOverrides: p.l1TxOverrides ? toGasOverrides(p.l1TxOverrides) : void 0,
3684
3690
  l2GasLimit: p.l2GasLimit,
3685
3691
  gasPerPubdata,
3686
3692
  operatorTip,
@@ -3736,6 +3742,37 @@ function buildDirectRequestStruct(args) {
3736
3742
  };
3737
3743
  }
3738
3744
 
3745
+ // src/core/utils/hash.ts
3746
+ var RegExpHex = /^0x[0-9a-fA-F]*$/;
3747
+ var isHash = (x, length) => {
3748
+ if (!x || typeof x !== "string") return false;
3749
+ return (x.length === length) && RegExpHex.test(x);
3750
+ };
3751
+ var isHash66 = (x) => isHash(x, 66);
3752
+
3753
+ // src/core/utils/number.ts
3754
+ var isNumber = (x) => typeof x === "number" && Number.isFinite(x);
3755
+ var isBigint = (x) => typeof x === "bigint";
3756
+
3757
+ // src/core/utils/addr.ts
3758
+ function isAddressEq(a, b) {
3759
+ return a.toLowerCase() === b.toLowerCase();
3760
+ }
3761
+ function isETH(token) {
3762
+ return isAddressEq(token, FORMAL_ETH_ADDRESS) || isAddressEq(token, L2_BASE_TOKEN_ADDRESS) || isAddressEq(token, ETH_ADDRESS);
3763
+ }
3764
+ function normalizeAddrEq(a, b) {
3765
+ if (!a || !b) return false;
3766
+ const normalize = (s) => {
3767
+ const hasPrefix = s.slice(0, 2).toLowerCase() === "0x";
3768
+ const body = hasPrefix ? s.slice(2) : s;
3769
+ return `0x${body.toLowerCase()}`;
3770
+ };
3771
+ return normalize(a) === normalize(b);
3772
+ }
3773
+ var hexEq = (a, b) => a.toLowerCase() === b.toLowerCase();
3774
+ var normalizeL1Token = (token) => isAddressEq(token, FORMAL_ETH_ADDRESS) ? ETH_ADDRESS : token;
3775
+
3739
3776
  // src/core/errors/formatter.ts
3740
3777
  function elideMiddle(s, max = 96) {
3741
3778
  if (s.length <= max) return s;
@@ -3746,7 +3783,7 @@ function shortJSON(v, max = 240) {
3746
3783
  try {
3747
3784
  const s = JSON.stringify(
3748
3785
  v,
3749
- (_k, val) => typeof val === "bigint" ? `${val.toString()}n` : val
3786
+ (_k, val) => isBigint(val) ? `${val.toString()}n` : val
3750
3787
  );
3751
3788
  return s.length > max ? elideMiddle(s, max) : s;
3752
3789
  } catch {
@@ -3766,7 +3803,7 @@ function formatContextLine(ctx) {
3766
3803
  if (txHash !== void 0)
3767
3804
  parts.push(`txHash=${typeof txHash === "string" ? txHash : shortJSON(txHash, 96)}`);
3768
3805
  if (nonce !== void 0) {
3769
- const nonceStr = typeof nonce === "string" || typeof nonce === "number" || typeof nonce === "bigint" ? String(nonce) : shortJSON(nonce, 48);
3806
+ const nonceStr = typeof nonce === "string" || isNumber(nonce) || isBigint(nonce) ? String(nonce) : shortJSON(nonce, 48);
3770
3807
  parts.push(`nonce=${nonceStr}`);
3771
3808
  }
3772
3809
  return parts.length ? ` ${kv("Context", parts.join(" \u2022 "))}` : void 0;
@@ -3796,17 +3833,17 @@ function formatCause(c) {
3796
3833
  const head = [];
3797
3834
  if (obj.name !== void 0) {
3798
3835
  const nameVal = obj.name;
3799
- const nameStr = typeof nameVal === "string" || typeof nameVal === "number" || typeof nameVal === "bigint" || typeof nameVal === "boolean" ? String(nameVal) : shortJSON(nameVal, 120);
3836
+ const nameStr = typeof nameVal === "string" || isNumber(nameVal) || isBigint(nameVal) || typeof nameVal === "boolean" ? String(nameVal) : shortJSON(nameVal, 120);
3800
3837
  head.push(`name=${nameStr}`);
3801
3838
  }
3802
3839
  if (obj.code !== void 0) {
3803
3840
  const codeVal = obj.code;
3804
- const codeStr = typeof codeVal === "string" || typeof codeVal === "number" || typeof codeVal === "bigint" || typeof codeVal === "boolean" ? String(codeVal) : shortJSON(codeVal, 120);
3841
+ const codeStr = typeof codeVal === "string" || isNumber(codeVal) || isBigint(codeVal) || typeof codeVal === "boolean" ? String(codeVal) : shortJSON(codeVal, 120);
3805
3842
  head.push(`code=${codeStr}`);
3806
3843
  }
3807
3844
  if (head.length) out.push(` ${kv("Cause", head.join(" "))}`);
3808
3845
  if (obj.message) {
3809
- 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);
3846
+ const messageStr = typeof obj.message === "string" || isNumber(obj.message) || isBigint(obj.message) || typeof obj.message === "boolean" ? String(obj.message) : shortJSON(obj.message, 600);
3810
3847
  out.push(` message=${elideMiddle(messageStr, 600)}`);
3811
3848
  }
3812
3849
  if (obj.data) {
@@ -3881,12 +3918,13 @@ if (kInspect) {
3881
3918
  enumerable: false
3882
3919
  });
3883
3920
  }
3884
- function isZKsyncError(e) {
3921
+ function isZKsyncError(e, opts) {
3885
3922
  if (!e || typeof e !== "object") return false;
3886
3923
  const maybe = e;
3887
3924
  if (!("envelope" in maybe)) return false;
3888
3925
  const envelope = maybe.envelope;
3889
- return typeof envelope?.type === "string" && typeof envelope?.message === "string";
3926
+ if (typeof envelope?.type !== "string" || typeof envelope?.message !== "string") return false;
3927
+ return true;
3890
3928
  }
3891
3929
  function isReceiptNotFound(e) {
3892
3930
  const chain = [];
@@ -4009,11 +4047,9 @@ var OP_WITHDRAWALS = {
4009
4047
  rawReceipt: "withdrawals.finalize.fetchParams:rawReceipt",
4010
4048
  messengerIndex: "withdrawals.finalize.fetchParams:messengerIndex",
4011
4049
  proof: "withdrawals.finalize.fetchParams:proof",
4012
- network: "withdrawals.finalize.fetchParams:network",
4013
- ensureAddresses: "withdrawals.finalize.fetchParams:ensureAddresses"
4050
+ network: "withdrawals.finalize.fetchParams:network"
4014
4051
  },
4015
4052
  readiness: {
4016
- ensureAddresses: "withdrawals.finalize.readiness:ensureAddresses",
4017
4053
  isFinalized: "withdrawals.finalize.readiness:isWithdrawalFinalized",
4018
4054
  simulate: "withdrawals.finalize.readiness:simulate"
4019
4055
  },
@@ -4634,28 +4670,6 @@ function routeEthDirect() {
4634
4670
  }
4635
4671
  };
4636
4672
  }
4637
-
4638
- // src/core/utils/addr.ts
4639
- var isHash66 = (x) => !!x && x.startsWith("0x") && x.length === 66;
4640
- function isAddressEq(a, b) {
4641
- return a.toLowerCase() === b.toLowerCase();
4642
- }
4643
- function isETH(token) {
4644
- return isAddressEq(token, FORMAL_ETH_ADDRESS) || isAddressEq(token, L2_BASE_TOKEN_ADDRESS) || isAddressEq(token, ETH_ADDRESS);
4645
- }
4646
- function normalizeAddrEq(a, b) {
4647
- if (!a || !b) return false;
4648
- const normalize = (s) => {
4649
- const hasPrefix = s.slice(0, 2).toLowerCase() === "0x";
4650
- const body = hasPrefix ? s.slice(2) : s;
4651
- return `0x${body.toLowerCase()}`;
4652
- };
4653
- return normalize(a) === normalize(b);
4654
- }
4655
- var hexEq = (a, b) => a.toLowerCase() === b.toLowerCase();
4656
- var normalizeL1Token = (token) => isAddressEq(token, FORMAL_ETH_ADDRESS) ? ETH_ADDRESS : token;
4657
-
4658
- // src/adapters/viem/resources/deposits/routes/erc20-nonbase.ts
4659
4673
  var { wrapAs: wrapAs3 } = createErrorHandlers("deposits");
4660
4674
  function routeErc20NonBase() {
4661
4675
  return {
@@ -5282,7 +5296,7 @@ var I_BRIDGEHUB_NEW_PRIORITY_REQUEST = {
5282
5296
  { name: "data", type: "bytes", indexed: false }
5283
5297
  ]
5284
5298
  };
5285
- function extractL2TxHashFromL1Logs(logs) {
5299
+ function getL2TransactionHashFromLogs(logs) {
5286
5300
  for (const lg of logs) {
5287
5301
  try {
5288
5302
  const parsed = viem.decodeEventLog({
@@ -5314,7 +5328,7 @@ function extractL2TxHashFromL1Logs(logs) {
5314
5328
  async function waitForL2ExecutionFromL1Tx(l1, l2, l1TxHash) {
5315
5329
  const l1Receipt = await l1.waitForTransactionReceipt({ hash: l1TxHash });
5316
5330
  if (!l1Receipt) throw new Error("No L1 receipt found");
5317
- const l2TxHash = extractL2TxHashFromL1Logs(l1Receipt.logs);
5331
+ const l2TxHash = getL2TransactionHashFromLogs(l1Receipt.logs);
5318
5332
  if (!l2TxHash) {
5319
5333
  throw createError("VERIFICATION", {
5320
5334
  message: "Failed to extract L2 transaction hash from L1 logs",
@@ -5677,7 +5691,13 @@ function createDepositsResource(client, tokens, contracts) {
5677
5691
  const plan = await prepare(p);
5678
5692
  const stepHashes = {};
5679
5693
  const from = client.account.address;
5680
- let next = await client.l1.getTransactionCount({ address: from, blockTag: "latest" });
5694
+ let next;
5695
+ if (typeof p.l1TxOverrides?.nonce === "number") {
5696
+ next = p.l1TxOverrides.nonce;
5697
+ } else {
5698
+ const blockTag = p.l1TxOverrides?.nonce ?? "latest";
5699
+ next = await client.l1.getTransactionCount({ address: from, blockTag });
5700
+ }
5681
5701
  for (const step of plan.steps) {
5682
5702
  if (step.kind === "approve") {
5683
5703
  try {
@@ -5824,14 +5844,14 @@ function createDepositsResource(client, tokens, contracts) {
5824
5844
  if (!l1Rcpt) return { phase: "L1_PENDING", l1TxHash };
5825
5845
  let l2TxHash;
5826
5846
  try {
5827
- l2TxHash = extractL2TxHashFromL1Logs(l1Rcpt.logs) ?? void 0;
5847
+ l2TxHash = getL2TransactionHashFromLogs(l1Rcpt.logs) ?? void 0;
5828
5848
  } catch (e) {
5829
5849
  throw toZKsyncError(
5830
5850
  "INTERNAL",
5831
5851
  {
5832
5852
  resource: "deposits",
5833
- operation: "deposits.status.extractL2TxHashFromL1Logs",
5834
- context: { where: "extractL2TxHashFromL1Logs", l1TxHash },
5853
+ operation: "deposits.status.getL2TransactionHashFromLogs",
5854
+ context: { where: "getL2TransactionHashFromLogs", l1TxHash },
5835
5855
  message: "Failed to derive L2 transaction hash from L1 logs."
5836
5856
  },
5837
5857
  e
@@ -5980,7 +6000,7 @@ async function commonCtx2(p, client, tokens, contracts) {
5980
6000
  l2NativeTokenVault,
5981
6001
  l2BaseTokenSystem,
5982
6002
  baseIsEth,
5983
- gasOverrides: p.l2TxOverrides
6003
+ gasOverrides: p.l2TxOverrides ? toGasOverrides(p.l2TxOverrides) : void 0
5984
6004
  };
5985
6005
  }
5986
6006
 
@@ -6201,8 +6221,7 @@ function routeErc20NonBase2() {
6201
6221
  tx: approveTx
6202
6222
  });
6203
6223
  }
6204
- const resolved = ctx.resolvedToken ?? (ctx.tokens ? await ctx.tokens.resolve(p.token, { chain: "l2" }) : void 0);
6205
- const assetId = resolved?.assetId ?? (await wrapAs8(
6224
+ const assetId = (await wrapAs8(
6206
6225
  "CONTRACT",
6207
6226
  OP_WITHDRAWALS.erc20.ensureRegistered,
6208
6227
  () => ctx.client.l2.simulateContract({
@@ -6236,7 +6255,7 @@ function routeErc20NonBase2() {
6236
6255
  value: 0n,
6237
6256
  from: ctx.sender
6238
6257
  };
6239
- const withdrawGas = await quoteL2Gas4({ ctx, tx: withdrawTxCandidate });
6258
+ const withdrawGas = current >= p.amount ? await quoteL2Gas4({ ctx, tx: withdrawTxCandidate }) : void 0;
6240
6259
  if (withdrawGas) {
6241
6260
  withdrawTxCandidate.gas = withdrawGas.gasLimit;
6242
6261
  withdrawTxCandidate.maxFeePerGas = withdrawGas.maxFeePerGas;
@@ -6290,11 +6309,14 @@ function routeErc20NonBase2() {
6290
6309
  };
6291
6310
  }
6292
6311
 
6293
- // src/core/resources/withdrawals/events.ts
6312
+ // src/core/utils/events.ts
6313
+ function extractPreferAddress(opts) {
6314
+ const preferAddr = typeof opts?.prefer === "object" ? opts.prefer.address : opts?.prefer === "assetRouter" ? L2_ASSET_ROUTER_ADDRESS : L1_MESSENGER_ADDRESS;
6315
+ return (preferAddr || L1_MESSENGER_ADDRESS).toLowerCase();
6316
+ }
6294
6317
  function findL1MessageSentLog(receipt, opts) {
6295
6318
  const index = opts?.index;
6296
- const preferAddr = typeof opts?.prefer === "object" ? opts?.prefer.address : opts?.prefer === "assetRouter" ? L2_ASSET_ROUTER_ADDRESS : L1_MESSENGER_ADDRESS;
6297
- const prefer = (preferAddr ?? L1_MESSENGER_ADDRESS).toLowerCase();
6319
+ const preferAddr = extractPreferAddress(opts);
6298
6320
  const matches = receipt.logs.filter((lg) => {
6299
6321
  const t0 = (lg.topics?.[0] ?? "").toLowerCase();
6300
6322
  return t0 === TOPIC_L1_MESSAGE_SENT_NEW || t0 === TOPIC_L1_MESSAGE_SENT_LEG;
@@ -6302,7 +6324,7 @@ function findL1MessageSentLog(receipt, opts) {
6302
6324
  if (!matches.length) {
6303
6325
  throw new Error("No L1MessageSent event found in L2 receipt logs.");
6304
6326
  }
6305
- const preferred = matches.find((lg) => (lg.address ?? "").toLowerCase() === prefer);
6327
+ const preferred = matches.find((lg) => (lg.address ?? "").toLowerCase() === preferAddr);
6306
6328
  const chosen = preferred ?? matches[index] ?? matches[0];
6307
6329
  if (!chosen) {
6308
6330
  throw new Error("No suitable L1MessageSent event found.");
@@ -6428,27 +6450,11 @@ function createFinalizationServices(client) {
6428
6450
  message,
6429
6451
  merkleProof: proof.proof
6430
6452
  };
6431
- const { l1Nullifier } = await wrapAs9(
6432
- "INTERNAL",
6433
- OP_WITHDRAWALS.finalize.fetchParams.ensureAddresses,
6434
- () => client.ensureAddresses(),
6435
- {
6436
- ctx: { where: "ensureAddresses" },
6437
- message: "Failed to ensure L1 Nullifier address."
6438
- }
6439
- );
6453
+ const { l1Nullifier } = await client.ensureAddresses();
6440
6454
  return { params, nullifier: l1Nullifier };
6441
6455
  },
6442
6456
  async simulateFinalizeReadiness(params) {
6443
- const { l1Nullifier } = await wrapAs9(
6444
- "INTERNAL",
6445
- OP_WITHDRAWALS.finalize.readiness.ensureAddresses,
6446
- () => client.ensureAddresses(),
6447
- {
6448
- ctx: { where: "ensureAddresses" },
6449
- message: "Failed to ensure L1 Nullifier address."
6450
- }
6451
- );
6457
+ const { l1Nullifier } = await client.ensureAddresses();
6452
6458
  const done = await (async () => {
6453
6459
  try {
6454
6460
  const result = await wrapAs9(
@@ -6485,15 +6491,7 @@ function createFinalizationServices(client) {
6485
6491
  }
6486
6492
  },
6487
6493
  async isWithdrawalFinalized(key) {
6488
- const { l1Nullifier } = await wrapAs9(
6489
- "INTERNAL",
6490
- OP_WITHDRAWALS.finalize.fetchParams.ensureAddresses,
6491
- () => client.ensureAddresses(),
6492
- {
6493
- ctx: { where: "ensureAddresses" },
6494
- message: "Failed to ensure L1 Nullifier address."
6495
- }
6496
- );
6494
+ const { l1Nullifier } = await client.ensureAddresses();
6497
6495
  return await wrapAs9(
6498
6496
  "RPC",
6499
6497
  OP_WITHDRAWALS.finalize.isFinalized,
@@ -6510,15 +6508,7 @@ function createFinalizationServices(client) {
6510
6508
  );
6511
6509
  },
6512
6510
  async estimateFinalization(params) {
6513
- const { l1Nullifier } = await wrapAs9(
6514
- "INTERNAL",
6515
- OP_WITHDRAWALS.finalize.estimate,
6516
- () => client.ensureAddresses(),
6517
- {
6518
- ctx: { where: "ensureAddresses" },
6519
- message: "Failed to ensure L1 Nullifier address."
6520
- }
6521
- );
6511
+ const { l1Nullifier } = await client.ensureAddresses();
6522
6512
  const gasLimit = await wrapAs9(
6523
6513
  "RPC",
6524
6514
  OP_WITHDRAWALS.finalize.estimate,
@@ -6581,15 +6571,7 @@ function createFinalizationServices(client) {
6581
6571
  };
6582
6572
  },
6583
6573
  async finalizeDeposit(params) {
6584
- const { l1Nullifier } = await wrapAs9(
6585
- "INTERNAL",
6586
- OP_WITHDRAWALS.finalize.fetchParams.ensureAddresses,
6587
- () => client.ensureAddresses(),
6588
- {
6589
- ctx: { where: "ensureAddresses" },
6590
- message: "Failed to ensure L1 Nullifier address."
6591
- }
6592
- );
6574
+ const { l1Nullifier } = await client.ensureAddresses();
6593
6575
  try {
6594
6576
  const hash = await client.l1Wallet.writeContract({
6595
6577
  address: l1Nullifier,
@@ -6690,6 +6672,14 @@ function createWithdrawalsResource(client, tokens, contracts) {
6690
6672
  const plan = await prepare(p);
6691
6673
  const stepHashes = {};
6692
6674
  const l2Wallet = client.getL2Wallet();
6675
+ const from = client.account.address;
6676
+ let next;
6677
+ if (typeof p.l2TxOverrides?.nonce === "number") {
6678
+ next = p.l2TxOverrides.nonce;
6679
+ } else {
6680
+ const blockTag = p.l2TxOverrides?.nonce ?? "pending";
6681
+ next = await client.l2.getTransactionCount({ address: from, blockTag });
6682
+ }
6693
6683
  for (const step of plan.steps) {
6694
6684
  if (p.l2TxOverrides) {
6695
6685
  const overrides = p.l2TxOverrides;
@@ -6723,6 +6713,7 @@ function createWithdrawalsResource(client, tokens, contracts) {
6723
6713
  maxFeePerGas: step.tx.maxFeePerGas,
6724
6714
  maxPriorityFeePerGas: step.tx.maxPriorityFeePerGas
6725
6715
  } : {};
6716
+ const nonce = next++;
6726
6717
  const baseReq = {
6727
6718
  address: step.tx.address,
6728
6719
  abi: step.tx.abi,
@@ -6730,6 +6721,7 @@ function createWithdrawalsResource(client, tokens, contracts) {
6730
6721
  args: step.tx.args ?? [],
6731
6722
  account: step.tx.account ?? l2Wallet.account ?? client.account,
6732
6723
  gas: step.tx.gas,
6724
+ nonce,
6733
6725
  ...fee1559,
6734
6726
  ...step.tx.dataSuffix ? { dataSuffix: step.tx.dataSuffix } : {},
6735
6727
  ...step.tx.chain ? { chain: step.tx.chain } : {}