@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,7 +1,7 @@
1
- export { createEthersSdk } from '../../chunk-HGB3DOV2.js';
2
- import '../../chunk-65HAYKVL.js';
3
- import '../../chunk-K2UVKMLN.js';
1
+ export { createEthersSdk } from '../../chunk-J2RPWU2R.js';
2
+ import '../../chunk-NJK325XV.js';
3
+ import '../../chunk-6LYAENO6.js';
4
4
  import '../../chunk-3HHUZXSV.js';
5
- import '../../chunk-MDPX5LNW.js';
6
- import '../../chunk-JXR5V5YK.js';
5
+ import '../../chunk-JSBMIT4S.js';
6
+ import '../../chunk-UEKFQAOS.js';
7
7
  import '../../chunk-MT4X5FEO.js';
@@ -1,6 +1,6 @@
1
- export { createViemClient } from '../../chunk-JHRYNLZG.js';
2
- import '../../chunk-YIWXIP2M.js';
1
+ export { createViemClient } from '../../chunk-CK5UFAZK.js';
2
+ import '../../chunk-SBGBYZJM.js';
3
3
  import '../../chunk-BWKWWLY4.js';
4
- import '../../chunk-MDPX5LNW.js';
5
- import '../../chunk-JXR5V5YK.js';
4
+ import '../../chunk-JSBMIT4S.js';
5
+ import '../../chunk-UEKFQAOS.js';
6
6
  import '../../chunk-MT4X5FEO.js';
@@ -391,6 +391,7 @@ var OP_INTEROP = {
391
391
  tryWait: "interop.tryWait",
392
392
  finalize: "interop.finalize",
393
393
  tryFinalize: "interop.tryFinalize",
394
+ verify: "interop.verify",
394
395
  context: {
395
396
  chainTypeManager: "interop.chainTypeManager",
396
397
  protocolVersion: "interop.protocolVersion"
@@ -7978,8 +7979,8 @@ function buildFeeBreakdown(p) {
7978
7979
 
7979
7980
  // src/core/resources/deposits/priority.ts
7980
7981
  var PRIORITY_TX_ENCODING_STEP_BYTES = 544n;
7981
- var DEFAULT_PRIORITY_BODY_GAS_ESTIMATE_MULTIPLIER = 6n;
7982
- var ERAVM_PRIORITY_L2_GAS_BUFFER = 30n;
7982
+ var DEFAULT_PRIORITY_BODY_GAS_ESTIMATE_MULTIPLIER = 7n;
7983
+ var PRIORITY_L2_GAS_BUFFER = 40n;
7983
7984
  var maxBigInt2 = (a, b) => a > b ? a : b;
7984
7985
  var ceilDiv = (a, b) => (a + b - 1n) / b;
7985
7986
  function derivePriorityTxGasBreakdown(input) {
@@ -8007,10 +8008,7 @@ function derivePriorityBodyGasEstimateCap(input) {
8007
8008
  return input.minBodyGas * (input.multiplier ?? DEFAULT_PRIORITY_BODY_GAS_ESTIMATE_MULTIPLIER);
8008
8009
  }
8009
8010
  function applyPriorityL2GasLimitBuffer(input) {
8010
- if (!isEraVmChain(input.chainIdL2)) {
8011
- return input.gasLimit;
8012
- }
8013
- return input.gasLimit * (100n + ERAVM_PRIORITY_L2_GAS_BUFFER) / 100n;
8011
+ return input.gasLimit * (100n + PRIORITY_L2_GAS_BUFFER) / 100n;
8014
8012
  }
8015
8013
  var EMPTY_BYTES = "0x";
8016
8014
  var ZERO_RESERVED_WORDS = [0n, 0n, 0n, 0n];
@@ -8666,7 +8664,7 @@ function routeEthNonBase() {
8666
8664
  const requestStruct = {
8667
8665
  chainId: ctx.chainIdL2,
8668
8666
  mintValue,
8669
- l2Value: p.amount,
8667
+ l2Value: 0n,
8670
8668
  l2GasLimit: l2Gas.gasLimit,
8671
8669
  l2GasPerPubdataByteLimit: ctx.gasPerPubdata,
8672
8670
  refundRecipient: ctx.refundRecipient,
@@ -8674,6 +8672,7 @@ function routeEthNonBase() {
8674
8672
  secondBridgeValue: p.amount,
8675
8673
  secondBridgeCalldata
8676
8674
  };
8675
+ const bridgehubValue = p.amount;
8677
8676
  let bridgeTx;
8678
8677
  let calldata;
8679
8678
  if (needsApprove) {
@@ -8682,8 +8681,7 @@ function routeEthNonBase() {
8682
8681
  abi: IBridgehub_default,
8683
8682
  functionName: "requestL2TransactionTwoBridges",
8684
8683
  args: [requestStruct],
8685
- value: p.amount,
8686
- // base ≠ ETH ⇒ msg.value == secondBridgeValue
8684
+ value: bridgehubValue,
8687
8685
  account: ctx.client.account
8688
8686
  };
8689
8687
  calldata = viem.encodeFunctionData({
@@ -8700,7 +8698,7 @@ function routeEthNonBase() {
8700
8698
  abi: IBridgehub_default,
8701
8699
  functionName: "requestL2TransactionTwoBridges",
8702
8700
  args: [requestStruct],
8703
- value: p.amount,
8701
+ value: bridgehubValue,
8704
8702
  account: ctx.client.account
8705
8703
  }),
8706
8704
  {
@@ -8718,7 +8716,7 @@ function routeEthNonBase() {
8718
8716
  const l1TxCandidate = {
8719
8717
  to: ctx.bridgehub,
8720
8718
  data: calldata,
8721
- value: p.amount,
8719
+ value: bridgehubValue,
8722
8720
  from: ctx.sender,
8723
8721
  ...ctx.gasOverrides
8724
8722
  };
@@ -11154,13 +11152,23 @@ function routeIndirect() {
11154
11152
  }
11155
11153
  function routeDirect() {
11156
11154
  return {
11157
- // eslint-disable-next-line @typescript-eslint/require-await
11158
11155
  async preflight(params, ctx) {
11159
11156
  preflightDirect(params, {
11160
11157
  dstChainId: ctx.dstChainId,
11161
11158
  baseTokens: ctx.baseTokens,
11162
11159
  l2AssetRouter: ctx.l2AssetRouter,
11163
11160
  l2NativeTokenVault: ctx.l2NativeTokenVault});
11161
+ for (const action of params.actions) {
11162
+ const bytecode = await ctx.dstPublicClient.getCode({ address: action.to });
11163
+ if (!bytecode || bytecode === "0x") {
11164
+ throw createError("VALIDATION", {
11165
+ resource: "interop",
11166
+ operation: OP_INTEROP.routes.direct.preflight,
11167
+ 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).`,
11168
+ context: { to: action.to, action: action.type }
11169
+ });
11170
+ }
11171
+ }
11164
11172
  },
11165
11173
  async build(params, ctx) {
11166
11174
  const steps = [];
@@ -11420,7 +11428,7 @@ async function getBundleStatus(client, dstProvider, topics, bundleHash, opts) {
11420
11428
  }
11421
11429
  return { phase: "SENT" };
11422
11430
  }
11423
- async function executeBundle(client, dstProvider, info, opts) {
11431
+ async function executeBundle(client, dstProvider, info, opts, txOverrides) {
11424
11432
  const { topics } = getTopics();
11425
11433
  const { bundleHash, encodedData, proof } = info;
11426
11434
  const dstStatus = await getBundleStatus(client, dstProvider, topics, bundleHash, opts);
@@ -11449,7 +11457,10 @@ async function executeBundle(client, dstProvider, info, opts) {
11449
11457
  functionName: "executeBundle",
11450
11458
  args: [encodedData, proof],
11451
11459
  account: client.account,
11452
- chain: dstProvider.chain ?? null
11460
+ chain: dstProvider.chain ?? null,
11461
+ gas: txOverrides?.gasLimit,
11462
+ maxFeePerGas: txOverrides?.maxFeePerGas,
11463
+ maxPriorityFeePerGas: txOverrides?.maxPriorityFeePerGas
11453
11464
  });
11454
11465
  return {
11455
11466
  hash,
@@ -11492,6 +11503,68 @@ async function executeBundle(client, dstProvider, info, opts) {
11492
11503
  );
11493
11504
  }
11494
11505
  }
11506
+ async function verifyBundle(client, dstProvider, info) {
11507
+ const { interopHandler } = await client.ensureAddresses();
11508
+ const dstWallet = await wrap5(
11509
+ OP_INTEROP.verify,
11510
+ () => viem.createWalletClient({
11511
+ account: client.account,
11512
+ transport: viem.custom(dstProvider.transport),
11513
+ chain: dstProvider.chain
11514
+ }),
11515
+ { message: "Failed to create destination wallet client for verifyBundle." }
11516
+ );
11517
+ try {
11518
+ const hash = await dstWallet.writeContract({
11519
+ address: interopHandler,
11520
+ abi: IInteropHandler_default,
11521
+ functionName: "verifyBundle",
11522
+ args: [info.encodedData, info.proof],
11523
+ account: client.account,
11524
+ chain: dstProvider.chain ?? null
11525
+ });
11526
+ return {
11527
+ hash,
11528
+ wait: async () => {
11529
+ try {
11530
+ const receipt = await dstProvider.waitForTransactionReceipt({ hash });
11531
+ if (receipt.status === "reverted") {
11532
+ throw createError("EXECUTION", {
11533
+ resource: "interop",
11534
+ operation: OP_INTEROP.verify,
11535
+ message: "Interop bundle verification reverted on destination.",
11536
+ context: { txHash: hash }
11537
+ });
11538
+ }
11539
+ return receipt;
11540
+ } catch (e) {
11541
+ if (isZKsyncError(e)) throw e;
11542
+ throw toZKsyncError(
11543
+ "EXECUTION",
11544
+ {
11545
+ resource: "interop",
11546
+ operation: OP_INTEROP.verify,
11547
+ message: "Failed while waiting for verifyBundle transaction on destination.",
11548
+ context: { txHash: hash }
11549
+ },
11550
+ e
11551
+ );
11552
+ }
11553
+ }
11554
+ };
11555
+ } catch (e) {
11556
+ if (isZKsyncError(e)) throw e;
11557
+ throw toZKsyncError(
11558
+ "EXECUTION",
11559
+ {
11560
+ resource: "interop",
11561
+ operation: OP_INTEROP.verify,
11562
+ message: "Failed to send verifyBundle transaction on destination chain."
11563
+ },
11564
+ e
11565
+ );
11566
+ }
11567
+ }
11495
11568
 
11496
11569
  // src/core/resources/interop/finalization.ts
11497
11570
  var DEFAULT_POLL_MS = 1e3;
@@ -11844,8 +11917,8 @@ function createInteropFinalizationServices(client) {
11844
11917
  wait(dstProvider, gwProvider, input, opts) {
11845
11918
  return waitForFinalization(client, dstProvider, gwProvider, input, opts);
11846
11919
  },
11847
- async finalize(dstProvider, info, opts) {
11848
- const execResult = await executeBundle(client, dstProvider, info, opts);
11920
+ async finalize(dstProvider, info, opts, txOverrides) {
11921
+ const execResult = await executeBundle(client, dstProvider, info, opts, txOverrides);
11849
11922
  await execResult.wait();
11850
11923
  return {
11851
11924
  bundleHash: info.bundleHash,
@@ -12073,22 +12146,47 @@ function createInteropResource(client, config, tokens, contracts, attributes) {
12073
12146
  ctx: { where: "interop.wait" }
12074
12147
  });
12075
12148
  const tryWait = (dstChain, h, opts) => toResult2(OP_INTEROP.tryWait, () => wait(dstChain, h, opts));
12076
- const finalize = (dstChain, h, opts) => wrap7(
12149
+ const finalize = (dstChain, h, opts, txOverrides) => wrap7(
12077
12150
  OP_INTEROP.finalize,
12078
12151
  async () => {
12079
12152
  const dstProvider = resolveChainRef(dstChain);
12080
12153
  if (isInteropFinalizationInfo(h)) {
12081
- return svc.finalize(dstProvider, h, opts);
12154
+ return svc.finalize(dstProvider, h, opts, txOverrides);
12082
12155
  }
12083
12156
  const info = await svc.wait(dstProvider, getGwProvider(), h);
12084
- return svc.finalize(dstProvider, info, opts);
12157
+ return svc.finalize(dstProvider, info, opts, txOverrides);
12085
12158
  },
12086
12159
  {
12087
12160
  message: "Failed to finalize/execute interop bundle on destination.",
12088
12161
  ctx: { where: "interop.finalize" }
12089
12162
  }
12090
12163
  );
12091
- const tryFinalize = (dstChain, h, opts) => toResult2(OP_INTEROP.tryFinalize, () => finalize(dstChain, h, opts));
12164
+ const tryFinalize = (dstChain, h, opts, txOverrides) => toResult2(
12165
+ OP_INTEROP.tryFinalize,
12166
+ () => finalize(dstChain, h, opts, txOverrides)
12167
+ );
12168
+ const interopGetRoot = (dstChain, rootChainId, batchNumber) => wrap7(
12169
+ OP_INTEROP.svc.status.getRoot,
12170
+ () => getInteropRoot(resolveChainRef(dstChain), rootChainId, batchNumber),
12171
+ {
12172
+ message: "Failed to get interop root from the destination chain.",
12173
+ ctx: { where: "interop.getInteropRoot" }
12174
+ }
12175
+ );
12176
+ const verifyBundle2 = (dstChain, h) => wrap7(
12177
+ OP_INTEROP.verify,
12178
+ async () => {
12179
+ const dstProvider = resolveChainRef(dstChain);
12180
+ const info = isInteropFinalizationInfo(h) ? h : await svc.wait(dstProvider, getGwProvider(), h);
12181
+ const result = await verifyBundle(client, dstProvider, info);
12182
+ await result.wait();
12183
+ return { bundleHash: info.bundleHash, dstExecTxHash: result.hash };
12184
+ },
12185
+ {
12186
+ message: "Failed to verify interop bundle on destination.",
12187
+ ctx: { where: "interop.verifyBundle" }
12188
+ }
12189
+ );
12092
12190
  return {
12093
12191
  quote,
12094
12192
  tryQuote,
@@ -12100,7 +12198,9 @@ function createInteropResource(client, config, tokens, contracts, attributes) {
12100
12198
  wait,
12101
12199
  tryWait,
12102
12200
  finalize,
12103
- tryFinalize
12201
+ tryFinalize,
12202
+ getInteropRoot: interopGetRoot,
12203
+ verifyBundle: verifyBundle2
12104
12204
  };
12105
12205
  }
12106
12206