@matterlabs/zksync-js 0.0.15 → 0.0.17

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 (35) hide show
  1. package/dist/adapters/ethers/client.js +4 -4
  2. package/dist/adapters/ethers/index.cjs +112 -19
  3. package/dist/adapters/ethers/index.cjs.map +1 -1
  4. package/dist/adapters/ethers/index.js +6 -6
  5. package/dist/adapters/ethers/resources/interop/index.d.ts +7 -3
  6. package/dist/adapters/ethers/resources/interop/services/finalization/bundle.d.ts +6 -1
  7. package/dist/adapters/ethers/resources/interop/services/finalization/index.d.ts +2 -1
  8. package/dist/adapters/ethers/sdk.cjs +112 -19
  9. package/dist/adapters/ethers/sdk.cjs.map +1 -1
  10. package/dist/adapters/ethers/sdk.js +5 -5
  11. package/dist/adapters/viem/client.js +4 -4
  12. package/dist/adapters/viem/index.cjs +121 -21
  13. package/dist/adapters/viem/index.cjs.map +1 -1
  14. package/dist/adapters/viem/index.js +6 -6
  15. package/dist/adapters/viem/resources/interop/index.d.ts +7 -3
  16. package/dist/adapters/viem/resources/interop/services/finalization/bundle.d.ts +6 -1
  17. package/dist/adapters/viem/resources/interop/services/finalization/index.d.ts +2 -1
  18. package/dist/adapters/viem/sdk.cjs +121 -21
  19. package/dist/adapters/viem/sdk.cjs.map +1 -1
  20. package/dist/adapters/viem/sdk.js +5 -5
  21. package/dist/{chunk-MZBKM3GH.js → chunk-24TE2NNJ.js} +2 -2
  22. package/dist/{chunk-K2UVKMLN.js → chunk-6LYAENO6.js} +4 -7
  23. package/dist/{chunk-JHRYNLZG.js → chunk-CK5UFAZK.js} +2 -2
  24. package/dist/{chunk-HGB3DOV2.js → chunk-J2RPWU2R.js} +112 -17
  25. package/dist/{chunk-MDPX5LNW.js → chunk-JSBMIT4S.js} +1 -1
  26. package/dist/{chunk-65HAYKVL.js → chunk-NJK325XV.js} +2 -2
  27. package/dist/{chunk-4PZCNTQ3.js → chunk-ONCNOWNC.js} +121 -19
  28. package/dist/{chunk-YIWXIP2M.js → chunk-SBGBYZJM.js} +2 -2
  29. package/dist/{chunk-HVHMLAYH.js → chunk-TYYUG5GA.js} +1 -1
  30. package/dist/{chunk-JXR5V5YK.js → chunk-UEKFQAOS.js} +1 -0
  31. package/dist/core/index.js +2 -2
  32. package/dist/core/resources/deposits/priority.d.ts +1 -1
  33. package/dist/core/types/errors.d.ts +1 -0
  34. package/dist/index.js +2 -2
  35. package/package.json +1 -1
@@ -1,9 +1,9 @@
1
- export { buildDirectRequestStruct, createContractsResource, createDepositsResource, createFinalizationServices, createInteropFinalizationServices, createInteropResource, createTokensResource, createViemSdk, createWithdrawalsResource, encodeNativeTokenVaultTransferData, encodeSecondBridgeArgs, encodeSecondBridgeDataV1, encodeSecondBridgeErc20Args, encodeSecondBridgeEthArgs, getL2TransactionHashFromLogs } from '../../chunk-4PZCNTQ3.js';
2
- import '../../chunk-K2UVKMLN.js';
1
+ export { buildDirectRequestStruct, createContractsResource, createDepositsResource, createFinalizationServices, createInteropFinalizationServices, createInteropResource, createTokensResource, createViemSdk, createWithdrawalsResource, encodeNativeTokenVaultTransferData, encodeSecondBridgeArgs, encodeSecondBridgeDataV1, encodeSecondBridgeErc20Args, encodeSecondBridgeEthArgs, getL2TransactionHashFromLogs } from '../../chunk-ONCNOWNC.js';
2
+ import '../../chunk-6LYAENO6.js';
3
3
  import '../../chunk-3HHUZXSV.js';
4
- export { createViemClient as createClient, createViemClient } from '../../chunk-JHRYNLZG.js';
5
- export { classifyReadinessFromRevert, createErrorHandlers, decodeRevert, registerErrorAbi, toZKsyncError } from '../../chunk-YIWXIP2M.js';
4
+ export { createViemClient as createClient, createViemClient } from '../../chunk-CK5UFAZK.js';
5
+ export { classifyReadinessFromRevert, createErrorHandlers, decodeRevert, registerErrorAbi, toZKsyncError } from '../../chunk-SBGBYZJM.js';
6
6
  import '../../chunk-BWKWWLY4.js';
7
- import '../../chunk-MDPX5LNW.js';
8
- import '../../chunk-JXR5V5YK.js';
7
+ import '../../chunk-JSBMIT4S.js';
8
+ import '../../chunk-UEKFQAOS.js';
9
9
  import '../../chunk-MT4X5FEO.js';
@@ -1,12 +1,14 @@
1
1
  import type { ViemClient } from '../../client';
2
+ import type { Hex } from '../../../../core/types/primitives';
2
3
  import type { AttributesResource } from '../../../../core/resources/interop/attributes/resource';
3
4
  import type { InteropRoute, InteropPlan, InteropQuote, InteropStatus, InteropFinalizationResult, InteropParams, InteropHandle, InteropWaitable, InteropFinalizationInfo } from '../../../../core/types/flows/interop';
4
5
  import type { ContractsResource } from '../contracts';
5
6
  import type { TokensResource } from '../../../../core/types/flows/token';
6
7
  import type { InteropRouteStrategy, ViemTransactionRequest } from './routes/types';
7
8
  import { createInteropFinalizationServices, type InteropFinalizationServices } from './services/finalization';
8
- import type { LogsQueryOptions } from './services/finalization/data-fetchers';
9
+ import { type LogsQueryOptions } from './services/finalization/data-fetchers';
9
10
  import type { ChainRef, InteropConfig } from './types';
11
+ import type { TxGasOverrides } from '../../../../core/types/fees';
10
12
  export declare const ROUTES: Record<InteropRoute, InteropRouteStrategy>;
11
13
  export interface InteropResource {
12
14
  quote(dstChain: ChainRef, params: InteropParams): Promise<InteropQuote>;
@@ -48,14 +50,16 @@ export interface InteropResource {
48
50
  ok: false;
49
51
  error: unknown;
50
52
  }>;
51
- finalize(dstChain: ChainRef, h: InteropWaitable | InteropFinalizationInfo, opts?: LogsQueryOptions): Promise<InteropFinalizationResult>;
52
- tryFinalize(dstChain: ChainRef, h: InteropWaitable | InteropFinalizationInfo, opts?: LogsQueryOptions): Promise<{
53
+ finalize(dstChain: ChainRef, h: InteropWaitable | InteropFinalizationInfo, opts?: LogsQueryOptions, txOverrides?: TxGasOverrides): Promise<InteropFinalizationResult>;
54
+ tryFinalize(dstChain: ChainRef, h: InteropWaitable | InteropFinalizationInfo, opts?: LogsQueryOptions, txOverrides?: TxGasOverrides): Promise<{
53
55
  ok: true;
54
56
  value: InteropFinalizationResult;
55
57
  } | {
56
58
  ok: false;
57
59
  error: unknown;
58
60
  }>;
61
+ getInteropRoot(dstChain: ChainRef, rootChainId: bigint, batchNumber: bigint): Promise<Hex>;
62
+ verifyBundle(dstChain: ChainRef, h: InteropWaitable | InteropFinalizationInfo): Promise<InteropFinalizationResult>;
59
63
  }
60
64
  export declare function createInteropResource(client: ViemClient, config?: InteropConfig, tokens?: TokensResource, contracts?: ContractsResource, attributes?: AttributesResource): InteropResource;
61
65
  export { createInteropFinalizationServices };
@@ -1,6 +1,7 @@
1
1
  import { type PublicClient, type TransactionReceipt } from 'viem';
2
2
  import type { Hex } from '../../../../../../core/types/primitives';
3
3
  import type { InteropFinalizationInfo } from '../../../../../../core/types/flows/interop';
4
+ import type { TxGasOverrides } from '../../../../../../core/types/fees';
4
5
  import type { ViemClient } from '../../../../client';
5
6
  import type { InteropPhase } from '../../../../../../core/types/flows/interop';
6
7
  import type { InteropTopics } from '../../../../../../core/resources/interop/events';
@@ -9,7 +10,11 @@ export declare function getBundleStatus(client: ViemClient, dstProvider: PublicC
9
10
  phase: InteropPhase;
10
11
  dstExecTxHash?: Hex;
11
12
  }>;
12
- export declare function executeBundle(client: ViemClient, dstProvider: PublicClient, info: InteropFinalizationInfo, opts?: LogsQueryOptions): Promise<{
13
+ export declare function executeBundle(client: ViemClient, dstProvider: PublicClient, info: InteropFinalizationInfo, opts?: LogsQueryOptions, txOverrides?: TxGasOverrides): Promise<{
14
+ hash: Hex;
15
+ wait: () => Promise<TransactionReceipt>;
16
+ }>;
17
+ export declare function verifyBundle(client: ViemClient, dstProvider: PublicClient, info: InteropFinalizationInfo): Promise<{
13
18
  hash: Hex;
14
19
  wait: () => Promise<TransactionReceipt>;
15
20
  }>;
@@ -2,12 +2,13 @@ import type { PublicClient } from 'viem';
2
2
  import type { InteropStatus, InteropWaitable, InteropFinalizationInfo, InteropFinalizationResult } from '../../../../../../core/types/flows/interop';
3
3
  import type { ViemClient } from '../../../../client';
4
4
  import type { LogsQueryOptions } from './data-fetchers';
5
+ import type { TxGasOverrides } from '../../../../../../core/types/fees';
5
6
  export interface InteropFinalizationServices {
6
7
  status(dstProvider: PublicClient, input: InteropWaitable, opts?: LogsQueryOptions): Promise<InteropStatus>;
7
8
  wait(dstProvider: PublicClient, gwProvider: PublicClient, input: InteropWaitable, opts?: {
8
9
  pollMs?: number;
9
10
  timeoutMs?: number;
10
11
  }): Promise<InteropFinalizationInfo>;
11
- finalize(dstProvider: PublicClient, info: InteropFinalizationInfo, opts?: LogsQueryOptions): Promise<InteropFinalizationResult>;
12
+ finalize(dstProvider: PublicClient, info: InteropFinalizationInfo, opts?: LogsQueryOptions, txOverrides?: TxGasOverrides): Promise<InteropFinalizationResult>;
12
13
  }
13
14
  export declare function createInteropFinalizationServices(client: ViemClient): InteropFinalizationServices;
@@ -5915,6 +5915,7 @@ var OP_INTEROP = {
5915
5915
  tryWait: "interop.tryWait",
5916
5916
  finalize: "interop.finalize",
5917
5917
  tryFinalize: "interop.tryFinalize",
5918
+ verify: "interop.verify",
5918
5919
  context: {
5919
5920
  chainTypeManager: "interop.chainTypeManager",
5920
5921
  protocolVersion: "interop.protocolVersion"
@@ -6532,8 +6533,8 @@ function buildFeeBreakdown(p) {
6532
6533
 
6533
6534
  // src/core/resources/deposits/priority.ts
6534
6535
  var PRIORITY_TX_ENCODING_STEP_BYTES = 544n;
6535
- var DEFAULT_PRIORITY_BODY_GAS_ESTIMATE_MULTIPLIER = 6n;
6536
- var ERAVM_PRIORITY_L2_GAS_BUFFER = 30n;
6536
+ var DEFAULT_PRIORITY_BODY_GAS_ESTIMATE_MULTIPLIER = 7n;
6537
+ var PRIORITY_L2_GAS_BUFFER = 40n;
6537
6538
  var maxBigInt2 = (a, b) => a > b ? a : b;
6538
6539
  var ceilDiv = (a, b) => (a + b - 1n) / b;
6539
6540
  function derivePriorityTxGasBreakdown(input) {
@@ -6561,10 +6562,7 @@ function derivePriorityBodyGasEstimateCap(input) {
6561
6562
  return input.minBodyGas * (input.multiplier ?? DEFAULT_PRIORITY_BODY_GAS_ESTIMATE_MULTIPLIER);
6562
6563
  }
6563
6564
  function applyPriorityL2GasLimitBuffer(input) {
6564
- if (!isEraVmChain(input.chainIdL2)) {
6565
- return input.gasLimit;
6566
- }
6567
- return input.gasLimit * (100n + ERAVM_PRIORITY_L2_GAS_BUFFER) / 100n;
6565
+ return input.gasLimit * (100n + PRIORITY_L2_GAS_BUFFER) / 100n;
6568
6566
  }
6569
6567
  var EMPTY_BYTES = "0x";
6570
6568
  var ZERO_RESERVED_WORDS = [0n, 0n, 0n, 0n];
@@ -7220,7 +7218,7 @@ function routeEthNonBase() {
7220
7218
  const requestStruct = {
7221
7219
  chainId: ctx.chainIdL2,
7222
7220
  mintValue,
7223
- l2Value: p.amount,
7221
+ l2Value: 0n,
7224
7222
  l2GasLimit: l2Gas.gasLimit,
7225
7223
  l2GasPerPubdataByteLimit: ctx.gasPerPubdata,
7226
7224
  refundRecipient: ctx.refundRecipient,
@@ -7228,6 +7226,7 @@ function routeEthNonBase() {
7228
7226
  secondBridgeValue: p.amount,
7229
7227
  secondBridgeCalldata
7230
7228
  };
7229
+ const bridgehubValue = p.amount;
7231
7230
  let bridgeTx;
7232
7231
  let calldata;
7233
7232
  if (needsApprove) {
@@ -7236,8 +7235,7 @@ function routeEthNonBase() {
7236
7235
  abi: IBridgehub_default,
7237
7236
  functionName: "requestL2TransactionTwoBridges",
7238
7237
  args: [requestStruct],
7239
- value: p.amount,
7240
- // base ≠ ETH ⇒ msg.value == secondBridgeValue
7238
+ value: bridgehubValue,
7241
7239
  account: ctx.client.account
7242
7240
  };
7243
7241
  calldata = viem.encodeFunctionData({
@@ -7254,7 +7252,7 @@ function routeEthNonBase() {
7254
7252
  abi: IBridgehub_default,
7255
7253
  functionName: "requestL2TransactionTwoBridges",
7256
7254
  args: [requestStruct],
7257
- value: p.amount,
7255
+ value: bridgehubValue,
7258
7256
  account: ctx.client.account
7259
7257
  }),
7260
7258
  {
@@ -7272,7 +7270,7 @@ function routeEthNonBase() {
7272
7270
  const l1TxCandidate = {
7273
7271
  to: ctx.bridgehub,
7274
7272
  data: calldata,
7275
- value: p.amount,
7273
+ value: bridgehubValue,
7276
7274
  from: ctx.sender,
7277
7275
  ...ctx.gasOverrides
7278
7276
  };
@@ -9708,13 +9706,23 @@ function routeIndirect() {
9708
9706
  }
9709
9707
  function routeDirect() {
9710
9708
  return {
9711
- // eslint-disable-next-line @typescript-eslint/require-await
9712
9709
  async preflight(params, ctx) {
9713
9710
  preflightDirect(params, {
9714
9711
  dstChainId: ctx.dstChainId,
9715
9712
  baseTokens: ctx.baseTokens,
9716
9713
  l2AssetRouter: ctx.l2AssetRouter,
9717
9714
  l2NativeTokenVault: ctx.l2NativeTokenVault});
9715
+ for (const action of params.actions) {
9716
+ const bytecode = await ctx.dstPublicClient.getCode({ address: action.to });
9717
+ if (!bytecode || bytecode === "0x") {
9718
+ throw createError("VALIDATION", {
9719
+ resource: "interop",
9720
+ operation: OP_INTEROP.routes.direct.preflight,
9721
+ message: `Destination address ${action.to} is not a contract on the destination chain. The receiver must be a contract that implements the IERC7786Recipient interface (receiveMessage).`,
9722
+ context: { to: action.to, action: action.type }
9723
+ });
9724
+ }
9725
+ }
9718
9726
  },
9719
9727
  async build(params, ctx) {
9720
9728
  const steps = [];
@@ -9974,7 +9982,7 @@ async function getBundleStatus(client, dstProvider, topics, bundleHash, opts) {
9974
9982
  }
9975
9983
  return { phase: "SENT" };
9976
9984
  }
9977
- async function executeBundle(client, dstProvider, info, opts) {
9985
+ async function executeBundle(client, dstProvider, info, opts, txOverrides) {
9978
9986
  const { topics } = getTopics();
9979
9987
  const { bundleHash, encodedData, proof } = info;
9980
9988
  const dstStatus = await getBundleStatus(client, dstProvider, topics, bundleHash, opts);
@@ -10003,7 +10011,10 @@ async function executeBundle(client, dstProvider, info, opts) {
10003
10011
  functionName: "executeBundle",
10004
10012
  args: [encodedData, proof],
10005
10013
  account: client.account,
10006
- chain: dstProvider.chain ?? null
10014
+ chain: dstProvider.chain ?? null,
10015
+ gas: txOverrides?.gasLimit,
10016
+ maxFeePerGas: txOverrides?.maxFeePerGas,
10017
+ maxPriorityFeePerGas: txOverrides?.maxPriorityFeePerGas
10007
10018
  });
10008
10019
  return {
10009
10020
  hash,
@@ -10046,6 +10057,68 @@ async function executeBundle(client, dstProvider, info, opts) {
10046
10057
  );
10047
10058
  }
10048
10059
  }
10060
+ async function verifyBundle(client, dstProvider, info) {
10061
+ const { interopHandler } = await client.ensureAddresses();
10062
+ const dstWallet = await wrap4(
10063
+ OP_INTEROP.verify,
10064
+ () => viem.createWalletClient({
10065
+ account: client.account,
10066
+ transport: viem.custom(dstProvider.transport),
10067
+ chain: dstProvider.chain
10068
+ }),
10069
+ { message: "Failed to create destination wallet client for verifyBundle." }
10070
+ );
10071
+ try {
10072
+ const hash = await dstWallet.writeContract({
10073
+ address: interopHandler,
10074
+ abi: IInteropHandler_default,
10075
+ functionName: "verifyBundle",
10076
+ args: [info.encodedData, info.proof],
10077
+ account: client.account,
10078
+ chain: dstProvider.chain ?? null
10079
+ });
10080
+ return {
10081
+ hash,
10082
+ wait: async () => {
10083
+ try {
10084
+ const receipt = await dstProvider.waitForTransactionReceipt({ hash });
10085
+ if (receipt.status === "reverted") {
10086
+ throw createError("EXECUTION", {
10087
+ resource: "interop",
10088
+ operation: OP_INTEROP.verify,
10089
+ message: "Interop bundle verification reverted on destination.",
10090
+ context: { txHash: hash }
10091
+ });
10092
+ }
10093
+ return receipt;
10094
+ } catch (e) {
10095
+ if (isZKsyncError(e)) throw e;
10096
+ throw toZKsyncError(
10097
+ "EXECUTION",
10098
+ {
10099
+ resource: "interop",
10100
+ operation: OP_INTEROP.verify,
10101
+ message: "Failed while waiting for verifyBundle transaction on destination.",
10102
+ context: { txHash: hash }
10103
+ },
10104
+ e
10105
+ );
10106
+ }
10107
+ }
10108
+ };
10109
+ } catch (e) {
10110
+ if (isZKsyncError(e)) throw e;
10111
+ throw toZKsyncError(
10112
+ "EXECUTION",
10113
+ {
10114
+ resource: "interop",
10115
+ operation: OP_INTEROP.verify,
10116
+ message: "Failed to send verifyBundle transaction on destination chain."
10117
+ },
10118
+ e
10119
+ );
10120
+ }
10121
+ }
10049
10122
 
10050
10123
  // src/core/resources/interop/finalization.ts
10051
10124
  var DEFAULT_POLL_MS = 1e3;
@@ -10398,8 +10471,8 @@ function createInteropFinalizationServices(client) {
10398
10471
  wait(dstProvider, gwProvider, input, opts) {
10399
10472
  return waitForFinalization(client, dstProvider, gwProvider, input, opts);
10400
10473
  },
10401
- async finalize(dstProvider, info, opts) {
10402
- const execResult = await executeBundle(client, dstProvider, info, opts);
10474
+ async finalize(dstProvider, info, opts, txOverrides) {
10475
+ const execResult = await executeBundle(client, dstProvider, info, opts, txOverrides);
10403
10476
  await execResult.wait();
10404
10477
  return {
10405
10478
  bundleHash: info.bundleHash,
@@ -10627,22 +10700,47 @@ function createInteropResource(client, config, tokens, contracts, attributes) {
10627
10700
  ctx: { where: "interop.wait" }
10628
10701
  });
10629
10702
  const tryWait = (dstChain, h, opts) => toResult2(OP_INTEROP.tryWait, () => wait(dstChain, h, opts));
10630
- const finalize = (dstChain, h, opts) => wrap6(
10703
+ const finalize = (dstChain, h, opts, txOverrides) => wrap6(
10631
10704
  OP_INTEROP.finalize,
10632
10705
  async () => {
10633
10706
  const dstProvider = resolveChainRef(dstChain);
10634
10707
  if (isInteropFinalizationInfo(h)) {
10635
- return svc.finalize(dstProvider, h, opts);
10708
+ return svc.finalize(dstProvider, h, opts, txOverrides);
10636
10709
  }
10637
10710
  const info = await svc.wait(dstProvider, getGwProvider(), h);
10638
- return svc.finalize(dstProvider, info, opts);
10711
+ return svc.finalize(dstProvider, info, opts, txOverrides);
10639
10712
  },
10640
10713
  {
10641
10714
  message: "Failed to finalize/execute interop bundle on destination.",
10642
10715
  ctx: { where: "interop.finalize" }
10643
10716
  }
10644
10717
  );
10645
- const tryFinalize = (dstChain, h, opts) => toResult2(OP_INTEROP.tryFinalize, () => finalize(dstChain, h, opts));
10718
+ const tryFinalize = (dstChain, h, opts, txOverrides) => toResult2(
10719
+ OP_INTEROP.tryFinalize,
10720
+ () => finalize(dstChain, h, opts, txOverrides)
10721
+ );
10722
+ const interopGetRoot = (dstChain, rootChainId, batchNumber) => wrap6(
10723
+ OP_INTEROP.svc.status.getRoot,
10724
+ () => getInteropRoot(resolveChainRef(dstChain), rootChainId, batchNumber),
10725
+ {
10726
+ message: "Failed to get interop root from the destination chain.",
10727
+ ctx: { where: "interop.getInteropRoot" }
10728
+ }
10729
+ );
10730
+ const verifyBundle2 = (dstChain, h) => wrap6(
10731
+ OP_INTEROP.verify,
10732
+ async () => {
10733
+ const dstProvider = resolveChainRef(dstChain);
10734
+ const info = isInteropFinalizationInfo(h) ? h : await svc.wait(dstProvider, getGwProvider(), h);
10735
+ const result = await verifyBundle(client, dstProvider, info);
10736
+ await result.wait();
10737
+ return { bundleHash: info.bundleHash, dstExecTxHash: result.hash };
10738
+ },
10739
+ {
10740
+ message: "Failed to verify interop bundle on destination.",
10741
+ ctx: { where: "interop.verifyBundle" }
10742
+ }
10743
+ );
10646
10744
  return {
10647
10745
  quote,
10648
10746
  tryQuote,
@@ -10654,7 +10752,9 @@ function createInteropResource(client, config, tokens, contracts, attributes) {
10654
10752
  wait,
10655
10753
  tryWait,
10656
10754
  finalize,
10657
- tryFinalize
10755
+ tryFinalize,
10756
+ getInteropRoot: interopGetRoot,
10757
+ verifyBundle: verifyBundle2
10658
10758
  };
10659
10759
  }
10660
10760