@matterlabs/zksync-js 0.0.15 → 0.0.16

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 (32) hide show
  1. package/dist/adapters/ethers/client.js +4 -4
  2. package/dist/adapters/ethers/index.cjs +83 -4
  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 +4 -1
  6. package/dist/adapters/ethers/resources/interop/services/finalization/bundle.d.ts +4 -0
  7. package/dist/adapters/ethers/sdk.cjs +83 -4
  8. package/dist/adapters/ethers/sdk.cjs.map +1 -1
  9. package/dist/adapters/ethers/sdk.js +5 -5
  10. package/dist/adapters/viem/client.js +4 -4
  11. package/dist/adapters/viem/index.cjs +93 -6
  12. package/dist/adapters/viem/index.cjs.map +1 -1
  13. package/dist/adapters/viem/index.js +6 -6
  14. package/dist/adapters/viem/resources/interop/index.d.ts +4 -1
  15. package/dist/adapters/viem/resources/interop/services/finalization/bundle.d.ts +4 -0
  16. package/dist/adapters/viem/sdk.cjs +93 -6
  17. package/dist/adapters/viem/sdk.cjs.map +1 -1
  18. package/dist/adapters/viem/sdk.js +5 -5
  19. package/dist/{chunk-MZBKM3GH.js → chunk-24TE2NNJ.js} +2 -2
  20. package/dist/{chunk-4PZCNTQ3.js → chunk-3KH5PCD6.js} +96 -10
  21. package/dist/{chunk-HGB3DOV2.js → chunk-5HG2DUYW.js} +86 -8
  22. package/dist/{chunk-JHRYNLZG.js → chunk-CK5UFAZK.js} +2 -2
  23. package/dist/{chunk-MDPX5LNW.js → chunk-JSBMIT4S.js} +1 -1
  24. package/dist/{chunk-65HAYKVL.js → chunk-NJK325XV.js} +2 -2
  25. package/dist/{chunk-K2UVKMLN.js → chunk-NLUCYVMX.js} +1 -1
  26. package/dist/{chunk-YIWXIP2M.js → chunk-SBGBYZJM.js} +2 -2
  27. package/dist/{chunk-HVHMLAYH.js → chunk-TYYUG5GA.js} +1 -1
  28. package/dist/{chunk-JXR5V5YK.js → chunk-UEKFQAOS.js} +1 -0
  29. package/dist/core/index.js +2 -2
  30. package/dist/core/types/errors.d.ts +1 -0
  31. package/dist/index.js +2 -2
  32. 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-3KH5PCD6.js';
2
+ import '../../chunk-NLUCYVMX.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,11 +1,12 @@
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';
10
11
  export declare const ROUTES: Record<InteropRoute, InteropRouteStrategy>;
11
12
  export interface InteropResource {
@@ -56,6 +57,8 @@ export interface InteropResource {
56
57
  ok: false;
57
58
  error: unknown;
58
59
  }>;
60
+ getInteropRoot(dstChain: ChainRef, rootChainId: bigint, batchNumber: bigint): Promise<Hex>;
61
+ verifyBundle(dstChain: ChainRef, h: InteropWaitable | InteropFinalizationInfo): Promise<InteropFinalizationResult>;
59
62
  }
60
63
  export declare function createInteropResource(client: ViemClient, config?: InteropConfig, tokens?: TokensResource, contracts?: ContractsResource, attributes?: AttributesResource): InteropResource;
61
64
  export { createInteropFinalizationServices };
@@ -13,3 +13,7 @@ export declare function executeBundle(client: ViemClient, dstProvider: PublicCli
13
13
  hash: Hex;
14
14
  wait: () => Promise<TransactionReceipt>;
15
15
  }>;
16
+ export declare function verifyBundle(client: ViemClient, dstProvider: PublicClient, info: InteropFinalizationInfo): Promise<{
17
+ hash: Hex;
18
+ wait: () => Promise<TransactionReceipt>;
19
+ }>;
@@ -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"
@@ -7220,7 +7221,7 @@ function routeEthNonBase() {
7220
7221
  const requestStruct = {
7221
7222
  chainId: ctx.chainIdL2,
7222
7223
  mintValue,
7223
- l2Value: p.amount,
7224
+ l2Value: 0n,
7224
7225
  l2GasLimit: l2Gas.gasLimit,
7225
7226
  l2GasPerPubdataByteLimit: ctx.gasPerPubdata,
7226
7227
  refundRecipient: ctx.refundRecipient,
@@ -7228,6 +7229,7 @@ function routeEthNonBase() {
7228
7229
  secondBridgeValue: p.amount,
7229
7230
  secondBridgeCalldata
7230
7231
  };
7232
+ const bridgehubValue = p.amount;
7231
7233
  let bridgeTx;
7232
7234
  let calldata;
7233
7235
  if (needsApprove) {
@@ -7236,8 +7238,7 @@ function routeEthNonBase() {
7236
7238
  abi: IBridgehub_default,
7237
7239
  functionName: "requestL2TransactionTwoBridges",
7238
7240
  args: [requestStruct],
7239
- value: p.amount,
7240
- // base ≠ ETH ⇒ msg.value == secondBridgeValue
7241
+ value: bridgehubValue,
7241
7242
  account: ctx.client.account
7242
7243
  };
7243
7244
  calldata = viem.encodeFunctionData({
@@ -7254,7 +7255,7 @@ function routeEthNonBase() {
7254
7255
  abi: IBridgehub_default,
7255
7256
  functionName: "requestL2TransactionTwoBridges",
7256
7257
  args: [requestStruct],
7257
- value: p.amount,
7258
+ value: bridgehubValue,
7258
7259
  account: ctx.client.account
7259
7260
  }),
7260
7261
  {
@@ -7272,7 +7273,7 @@ function routeEthNonBase() {
7272
7273
  const l1TxCandidate = {
7273
7274
  to: ctx.bridgehub,
7274
7275
  data: calldata,
7275
- value: p.amount,
7276
+ value: bridgehubValue,
7276
7277
  from: ctx.sender,
7277
7278
  ...ctx.gasOverrides
7278
7279
  };
@@ -10046,6 +10047,68 @@ async function executeBundle(client, dstProvider, info, opts) {
10046
10047
  );
10047
10048
  }
10048
10049
  }
10050
+ async function verifyBundle(client, dstProvider, info) {
10051
+ const { interopHandler } = await client.ensureAddresses();
10052
+ const dstWallet = await wrap4(
10053
+ OP_INTEROP.verify,
10054
+ () => viem.createWalletClient({
10055
+ account: client.account,
10056
+ transport: viem.custom(dstProvider.transport),
10057
+ chain: dstProvider.chain
10058
+ }),
10059
+ { message: "Failed to create destination wallet client for verifyBundle." }
10060
+ );
10061
+ try {
10062
+ const hash = await dstWallet.writeContract({
10063
+ address: interopHandler,
10064
+ abi: IInteropHandler_default,
10065
+ functionName: "verifyBundle",
10066
+ args: [info.encodedData, info.proof],
10067
+ account: client.account,
10068
+ chain: dstProvider.chain ?? null
10069
+ });
10070
+ return {
10071
+ hash,
10072
+ wait: async () => {
10073
+ try {
10074
+ const receipt = await dstProvider.waitForTransactionReceipt({ hash });
10075
+ if (receipt.status === "reverted") {
10076
+ throw createError("EXECUTION", {
10077
+ resource: "interop",
10078
+ operation: OP_INTEROP.verify,
10079
+ message: "Interop bundle verification reverted on destination.",
10080
+ context: { txHash: hash }
10081
+ });
10082
+ }
10083
+ return receipt;
10084
+ } catch (e) {
10085
+ if (isZKsyncError(e)) throw e;
10086
+ throw toZKsyncError(
10087
+ "EXECUTION",
10088
+ {
10089
+ resource: "interop",
10090
+ operation: OP_INTEROP.verify,
10091
+ message: "Failed while waiting for verifyBundle transaction on destination.",
10092
+ context: { txHash: hash }
10093
+ },
10094
+ e
10095
+ );
10096
+ }
10097
+ }
10098
+ };
10099
+ } catch (e) {
10100
+ if (isZKsyncError(e)) throw e;
10101
+ throw toZKsyncError(
10102
+ "EXECUTION",
10103
+ {
10104
+ resource: "interop",
10105
+ operation: OP_INTEROP.verify,
10106
+ message: "Failed to send verifyBundle transaction on destination chain."
10107
+ },
10108
+ e
10109
+ );
10110
+ }
10111
+ }
10049
10112
 
10050
10113
  // src/core/resources/interop/finalization.ts
10051
10114
  var DEFAULT_POLL_MS = 1e3;
@@ -10643,6 +10706,28 @@ function createInteropResource(client, config, tokens, contracts, attributes) {
10643
10706
  }
10644
10707
  );
10645
10708
  const tryFinalize = (dstChain, h, opts) => toResult2(OP_INTEROP.tryFinalize, () => finalize(dstChain, h, opts));
10709
+ const interopGetRoot = (dstChain, rootChainId, batchNumber) => wrap6(
10710
+ OP_INTEROP.svc.status.getRoot,
10711
+ () => getInteropRoot(resolveChainRef(dstChain), rootChainId, batchNumber),
10712
+ {
10713
+ message: "Failed to get interop root from the destination chain.",
10714
+ ctx: { where: "interop.getInteropRoot" }
10715
+ }
10716
+ );
10717
+ const verifyBundle2 = (dstChain, h) => wrap6(
10718
+ OP_INTEROP.verify,
10719
+ async () => {
10720
+ const dstProvider = resolveChainRef(dstChain);
10721
+ const info = isInteropFinalizationInfo(h) ? h : await svc.wait(dstProvider, getGwProvider(), h);
10722
+ const result = await verifyBundle(client, dstProvider, info);
10723
+ await result.wait();
10724
+ return { bundleHash: info.bundleHash, dstExecTxHash: result.hash };
10725
+ },
10726
+ {
10727
+ message: "Failed to verify interop bundle on destination.",
10728
+ ctx: { where: "interop.verifyBundle" }
10729
+ }
10730
+ );
10646
10731
  return {
10647
10732
  quote,
10648
10733
  tryQuote,
@@ -10654,7 +10739,9 @@ function createInteropResource(client, config, tokens, contracts, attributes) {
10654
10739
  wait,
10655
10740
  tryWait,
10656
10741
  finalize,
10657
- tryFinalize
10742
+ tryFinalize,
10743
+ getInteropRoot: interopGetRoot,
10744
+ verifyBundle: verifyBundle2
10658
10745
  };
10659
10746
  }
10660
10747