@matterlabs/zksync-js 0.0.16 → 0.0.18

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.
@@ -1,7 +1,7 @@
1
1
  export { createEthersClient as createClient, createEthersClient } from '../../chunk-24TE2NNJ.js';
2
- export { buildDirectRequestStruct, createDepositsResource, createEthersSdk, createFinalizationServices, createInteropFinalizationServices, createInteropResource, createTokensResource, createWithdrawalsResource, encodeNativeTokenVaultTransferData, encodeSecondBridgeArgs, encodeSecondBridgeDataV1, encodeSecondBridgeErc20Args, encodeSecondBridgeEthArgs, getL2TransactionHashFromLogs } from '../../chunk-5HG2DUYW.js';
2
+ export { buildDirectRequestStruct, createDepositsResource, createEthersSdk, createFinalizationServices, createInteropFinalizationServices, createInteropResource, createTokensResource, createWithdrawalsResource, encodeNativeTokenVaultTransferData, encodeSecondBridgeArgs, encodeSecondBridgeDataV1, encodeSecondBridgeErc20Args, encodeSecondBridgeEthArgs, getL2TransactionHashFromLogs } from '../../chunk-U72MNQIY.js';
3
3
  export { classifyReadinessFromRevert, createErrorHandlers, decodeRevert, registerErrorAbi, toZKsyncError } from '../../chunk-NJK325XV.js';
4
- import '../../chunk-NLUCYVMX.js';
4
+ import '../../chunk-6LYAENO6.js';
5
5
  import '../../chunk-3HHUZXSV.js';
6
6
  import '../../chunk-BWKWWLY4.js';
7
7
  import '../../chunk-JSBMIT4S.js';
@@ -6,6 +6,7 @@ import type { ContractsResource } from '../contracts';
6
6
  import type { TokensResource } from '../../../../core/types/flows/token';
7
7
  import type { InteropRouteStrategy } from './routes/types';
8
8
  import type { TransactionRequest } from 'ethers';
9
+ import type { TxGasOverrides } from '../../../../core/types/fees';
9
10
  import { createInteropFinalizationServices, type InteropFinalizationServices } from './services/finalization';
10
11
  import { type LogsQueryOptions } from './services/finalization/data-fetchers';
11
12
  import type { ChainRef, InteropConfig } from './types';
@@ -50,8 +51,8 @@ export interface InteropResource {
50
51
  ok: false;
51
52
  error: unknown;
52
53
  }>;
53
- finalize(dstChain: ChainRef, h: InteropWaitable | InteropFinalizationInfo, opts?: LogsQueryOptions): Promise<InteropFinalizationResult>;
54
- tryFinalize(dstChain: ChainRef, h: InteropWaitable | InteropFinalizationInfo, opts?: LogsQueryOptions): Promise<{
54
+ finalize(dstChain: ChainRef, h: InteropWaitable | InteropFinalizationInfo, opts?: LogsQueryOptions, txOverrides?: TxGasOverrides): Promise<InteropFinalizationResult>;
55
+ tryFinalize(dstChain: ChainRef, h: InteropWaitable | InteropFinalizationInfo, opts?: LogsQueryOptions, txOverrides?: TxGasOverrides): Promise<{
55
56
  ok: true;
56
57
  value: InteropFinalizationResult;
57
58
  } | {
@@ -1,6 +1,7 @@
1
1
  import { type AbstractProvider, type TransactionReceipt } from 'ethers';
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 { EthersClient } 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,7 @@ export declare function getBundleStatus(client: EthersClient, dstProvider: Abstr
9
10
  phase: InteropPhase;
10
11
  dstExecTxHash?: Hex;
11
12
  }>;
12
- export declare function executeBundle(client: EthersClient, dstProvider: AbstractProvider, info: InteropFinalizationInfo, opts?: LogsQueryOptions): Promise<{
13
+ export declare function executeBundle(client: EthersClient, dstProvider: AbstractProvider, info: InteropFinalizationInfo, opts?: LogsQueryOptions, txOverrides?: TxGasOverrides): Promise<{
13
14
  hash: Hex;
14
15
  wait: () => Promise<TransactionReceipt>;
15
16
  }>;
@@ -2,12 +2,13 @@ import type { AbstractProvider } from 'ethers';
2
2
  import type { InteropStatus, InteropWaitable, InteropFinalizationInfo, InteropFinalizationResult } from '../../../../../../core/types/flows/interop';
3
3
  import type { EthersClient } 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: AbstractProvider, input: InteropWaitable, opts?: LogsQueryOptions): Promise<InteropStatus>;
7
8
  wait(dstProvider: AbstractProvider, gwProvider: AbstractProvider, input: InteropWaitable, opts?: {
8
9
  pollMs?: number;
9
10
  timeoutMs?: number;
10
11
  }): Promise<InteropFinalizationInfo>;
11
- finalize(dstProvider: AbstractProvider, info: InteropFinalizationInfo, opts?: LogsQueryOptions): Promise<InteropFinalizationResult>;
12
+ finalize(dstProvider: AbstractProvider, info: InteropFinalizationInfo, opts?: LogsQueryOptions, txOverrides?: TxGasOverrides): Promise<InteropFinalizationResult>;
12
13
  }
13
14
  export declare function createInteropFinalizationServices(client: EthersClient): InteropFinalizationServices;
@@ -6481,8 +6481,8 @@ function buildFeeBreakdown(p) {
6481
6481
 
6482
6482
  // src/core/resources/deposits/priority.ts
6483
6483
  var PRIORITY_TX_ENCODING_STEP_BYTES = 544n;
6484
- var DEFAULT_PRIORITY_BODY_GAS_ESTIMATE_MULTIPLIER = 6n;
6485
- var ERAVM_PRIORITY_L2_GAS_BUFFER = 30n;
6484
+ var DEFAULT_PRIORITY_BODY_GAS_ESTIMATE_MULTIPLIER = 7n;
6485
+ var PRIORITY_L2_GAS_BUFFER = 40n;
6486
6486
  var maxBigInt2 = (a, b) => a > b ? a : b;
6487
6487
  var ceilDiv = (a, b) => (a + b - 1n) / b;
6488
6488
  function derivePriorityTxGasBreakdown(input) {
@@ -6510,10 +6510,7 @@ function derivePriorityBodyGasEstimateCap(input) {
6510
6510
  return input.minBodyGas * (input.multiplier ?? DEFAULT_PRIORITY_BODY_GAS_ESTIMATE_MULTIPLIER);
6511
6511
  }
6512
6512
  function applyPriorityL2GasLimitBuffer(input) {
6513
- if (!isEraVmChain(input.chainIdL2)) {
6514
- return input.gasLimit;
6515
- }
6516
- return input.gasLimit * (100n + ERAVM_PRIORITY_L2_GAS_BUFFER) / 100n;
6513
+ return input.gasLimit * (100n + PRIORITY_L2_GAS_BUFFER) / 100n;
6517
6514
  }
6518
6515
  var EMPTY_BYTES = "0x";
6519
6516
  var ZERO_RESERVED_WORDS = [0n, 0n, 0n, 0n];
@@ -6644,6 +6641,22 @@ var ZERO_HASH = "0x0000000000000000000000000000000000000000000000000000000000000
6644
6641
  var { wrapAs: wrapAs2 } = createErrorHandlers("deposits");
6645
6642
  var ZERO_L2_TOKEN_ADDRESS2 = "0x0000000000000000000000000000000000000000";
6646
6643
  var ZERO_ASSET_ID = "0x0000000000000000000000000000000000000000000000000000000000000000";
6644
+ async function encodeSecondBridgeErc20DepositCalldata(input) {
6645
+ if (!input.ctx.resolvedToken) {
6646
+ return encodeSecondBridgeErc20Args(input.token, input.amount, input.receiver);
6647
+ }
6648
+ const { chainId: l1ChainId } = await input.ctx.client.l1.getNetwork();
6649
+ const isL1Origin = input.ctx.resolvedToken.assetId.toLowerCase() === ZERO_ASSET_ID || input.ctx.resolvedToken.originChainId === 0n || input.ctx.resolvedToken.originChainId === BigInt(l1ChainId);
6650
+ if (isL1Origin) {
6651
+ return encodeSecondBridgeErc20Args(input.token, input.amount, input.receiver);
6652
+ }
6653
+ const transferData = encodeNativeTokenVaultTransferData(
6654
+ input.amount,
6655
+ input.receiver,
6656
+ input.token
6657
+ );
6658
+ return encodeSecondBridgeDataV1(input.ctx.resolvedToken.assetId, transferData);
6659
+ }
6647
6660
  async function getPriorityGasModel(input) {
6648
6661
  try {
6649
6662
  const l1NativeTokenVault = await input.ctx.contracts.l1NativeTokenVault();
@@ -6716,9 +6729,14 @@ function routeErc20NonBase() {
6716
6729
  const secondBridgeCalldata = await wrapAs2(
6717
6730
  "INTERNAL",
6718
6731
  OP_DEPOSITS.nonbase.encodeCalldata,
6719
- () => Promise.resolve(encodeSecondBridgeErc20Args(p.token, p.amount, receiver)),
6732
+ () => encodeSecondBridgeErc20DepositCalldata({
6733
+ ctx,
6734
+ token: p.token,
6735
+ amount: p.amount,
6736
+ receiver
6737
+ }),
6720
6738
  {
6721
- ctx: { where: "encodeSecondBridgeErc20Args" },
6739
+ ctx: { where: "encodeSecondBridgeErc20DepositCalldata" },
6722
6740
  message: "Failed to encode bridging calldata."
6723
6741
  }
6724
6742
  );
@@ -9173,13 +9191,23 @@ function routeIndirect() {
9173
9191
  // src/adapters/ethers/resources/interop/routes/direct.ts
9174
9192
  function routeDirect() {
9175
9193
  return {
9176
- // eslint-disable-next-line @typescript-eslint/require-await
9177
9194
  async preflight(params, ctx) {
9178
9195
  preflightDirect(params, {
9179
9196
  dstChainId: ctx.dstChainId,
9180
9197
  baseTokens: ctx.baseTokens,
9181
9198
  l2AssetRouter: ctx.l2AssetRouter,
9182
9199
  l2NativeTokenVault: ctx.l2NativeTokenVault});
9200
+ for (const action of params.actions) {
9201
+ const code = await ctx.dstProvider.getCode(action.to);
9202
+ if (!code || code === "0x") {
9203
+ throw createError("VALIDATION", {
9204
+ resource: "interop",
9205
+ operation: OP_INTEROP.routes.direct.preflight,
9206
+ 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).`,
9207
+ context: { to: action.to, action: action.type }
9208
+ });
9209
+ }
9210
+ }
9183
9211
  },
9184
9212
  async build(params, ctx) {
9185
9213
  const steps = [];
@@ -9429,7 +9457,7 @@ async function getBundleStatus(client, dstProvider, topics, bundleHash, opts) {
9429
9457
  }
9430
9458
  return { phase: "SENT" };
9431
9459
  }
9432
- async function executeBundle(client, dstProvider, info, opts) {
9460
+ async function executeBundle(client, dstProvider, info, opts, txOverrides) {
9433
9461
  const { topics } = getTopics();
9434
9462
  const { bundleHash, encodedData, proof } = info;
9435
9463
  const dstStatus = await getBundleStatus(client, dstProvider, topics, bundleHash, opts);
@@ -9447,7 +9475,11 @@ async function executeBundle(client, dstProvider, info, opts) {
9447
9475
  const { interopHandler } = await client.ensureAddresses();
9448
9476
  const handler = new ethers.Contract(interopHandler, IInteropHandler_default, signer);
9449
9477
  try {
9450
- const txResponse = await handler.executeBundle(encodedData, proof);
9478
+ const txResponse = await handler.executeBundle(
9479
+ encodedData,
9480
+ proof,
9481
+ txOverrides ?? {}
9482
+ );
9451
9483
  const hash = txResponse.hash;
9452
9484
  return {
9453
9485
  hash,
@@ -9895,8 +9927,8 @@ function createInteropFinalizationServices(client) {
9895
9927
  wait(dstProvider, gwProvider, input, opts) {
9896
9928
  return waitForFinalization(client, dstProvider, gwProvider, input, opts);
9897
9929
  },
9898
- async finalize(dstProvider, info, opts) {
9899
- const execResult = await executeBundle(client, dstProvider, info, opts);
9930
+ async finalize(dstProvider, info, opts, txOverrides) {
9931
+ const execResult = await executeBundle(client, dstProvider, info, opts, txOverrides);
9900
9932
  await execResult.wait();
9901
9933
  return {
9902
9934
  bundleHash: info.bundleHash,
@@ -10106,22 +10138,25 @@ function createInteropResource(client, config, tokens, contracts, attributes) {
10106
10138
  ctx: { where: "interop.wait" }
10107
10139
  });
10108
10140
  const tryWait = (dstChain, h, opts) => toResult2(OP_INTEROP.tryWait, () => wait(dstChain, h, opts));
10109
- const finalize = (dstChain, h, opts) => wrap6(
10141
+ const finalize = (dstChain, h, opts, txOverrides) => wrap6(
10110
10142
  OP_INTEROP.finalize,
10111
10143
  async () => {
10112
10144
  const dstProvider = resolveChainRef(dstChain);
10113
10145
  if (isInteropFinalizationInfo(h)) {
10114
- return svc.finalize(dstProvider, h, opts);
10146
+ return svc.finalize(dstProvider, h, opts, txOverrides);
10115
10147
  }
10116
10148
  const info = await svc.wait(dstProvider, getGwProvider(), h);
10117
- return svc.finalize(dstProvider, info, opts);
10149
+ return svc.finalize(dstProvider, info, opts, txOverrides);
10118
10150
  },
10119
10151
  {
10120
10152
  message: "Failed to finalize/execute interop bundle on destination.",
10121
10153
  ctx: { where: "interop.finalize" }
10122
10154
  }
10123
10155
  );
10124
- const tryFinalize = (dstChain, h, opts) => toResult2(OP_INTEROP.tryFinalize, () => finalize(dstChain, h, opts));
10156
+ const tryFinalize = (dstChain, h, opts, txOverrides) => toResult2(
10157
+ OP_INTEROP.tryFinalize,
10158
+ () => finalize(dstChain, h, opts, txOverrides)
10159
+ );
10125
10160
  const interopGetRoot = (dstChain, rootChainId, batchNumber) => wrap6(
10126
10161
  OP_INTEROP.svc.status.getRoot,
10127
10162
  () => getInteropRoot(resolveChainRef(dstChain), rootChainId, batchNumber),