@matterlabs/zksync-js 0.0.25 → 0.0.26

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-PNTR5FTL.js';
2
- export { buildDirectRequestStruct, createDepositsResource, createEthersSdk, createFinalizationServices, createInteropFinalizationServices, createInteropResource, createTokensResource, createWithdrawalProtocolService, createWithdrawalsResource, encodeNativeTokenVaultTransferData, encodeSecondBridgeArgs, encodeSecondBridgeDataV1, encodeSecondBridgeErc20Args, encodeSecondBridgeEthArgs, getL2TransactionHashFromLogs } from '../../chunk-N5E4FLBF.js';
2
+ export { buildDirectRequestStruct, createDepositsResource, createEthersSdk, createFinalizationServices, createInteropFinalizationServices, createInteropResource, createTokensResource, createWithdrawalProtocolService, createWithdrawalsResource, encodeNativeTokenVaultTransferData, encodeSecondBridgeArgs, encodeSecondBridgeDataV1, encodeSecondBridgeErc20Args, encodeSecondBridgeEthArgs, getL2TransactionHashFromLogs } from '../../chunk-YWUBX7YE.js';
3
3
  export { classifyReadinessFromRevert, createErrorHandlers, decodeRevert, registerErrorAbi, toZKsyncError } from '../../chunk-RZH7HBH3.js';
4
- import '../../chunk-JWN26CQ6.js';
4
+ import '../../chunk-FMBQ7PVA.js';
5
5
  import '../../chunk-BQ2YCWV2.js';
6
6
  import '../../chunk-OEUDZFXH.js';
7
7
  import '../../chunk-UMPAKZCQ.js';
@@ -1,4 +1,4 @@
1
- import type { TransactionRequest } from 'ethers';
1
+ import { type TransactionRequest } from 'ethers';
2
2
  import type { BuildCtx } from '../context';
3
3
  import type { DepositRoute } from '../../../../../core/types/flows/deposits';
4
4
  import type { TxGasOverrides } from '../../../../../core/types/fees';
@@ -38,6 +38,19 @@ export declare function quoteL1Gas(input: QuoteL1GasInput): Promise<GasQuote | u
38
38
  * Quote L2 gas for an L2 transaction.
39
39
  */
40
40
  export declare function quoteL2Gas(input: QuoteL2GasInput): Promise<GasQuote | undefined>;
41
+ /**
42
+ * `l2GasLimit` for a base-token deposit (`requestL2TransactionDirect`). An explicit
43
+ * `ctx.l2GasLimit` wins. EraVM chains use the protocol floor. ZKsync OS chains use the node's
44
+ * estimate of the real L2 call, floored by the protocol minimum. When L1 cannot be read, the chain
45
+ * is treated as a ZKsync OS rollup, which only errs toward a higher limit.
46
+ */
47
+ export declare function determineBaseL2GasLimit(input: {
48
+ ctx: BuildCtx;
49
+ l2Contract: Address;
50
+ l2Value: bigint;
51
+ l2Calldata: `0x${string}`;
52
+ priorityFloorGasLimit: bigint;
53
+ }): Promise<bigint>;
41
54
  export declare function determineErc20L2Gas(input: {
42
55
  ctx: BuildCtx;
43
56
  l1Token: Address;
@@ -6390,8 +6390,6 @@ async function quoteL2BaseCost(input) {
6390
6390
  });
6391
6391
  return BigInt(raw);
6392
6392
  }
6393
-
6394
- // src/adapters/ethers/estimator.ts
6395
6393
  function toCoreTx(tx) {
6396
6394
  return {
6397
6395
  to: tx.to,
@@ -6441,7 +6439,13 @@ function ethersToGasEstimator(provider) {
6441
6439
  throw new Error('Provider does not support "send"; cannot estimate priority tx gas.');
6442
6440
  }
6443
6441
  const result = await provider.send("eth_estimateGas", [
6444
- { from: tx.from, to: tx.to, data: tx.data, type: ZKSYNC_OS_PRIORITY_TX_TYPE }
6442
+ {
6443
+ from: tx.from,
6444
+ to: tx.to,
6445
+ data: tx.data,
6446
+ ...tx.value != null ? { value: ethers.toQuantity(tx.value) } : {},
6447
+ type: ZKSYNC_OS_PRIORITY_TX_TYPE
6448
+ }
6445
6449
  ]);
6446
6450
  return BigInt(result);
6447
6451
  },
@@ -6678,10 +6682,28 @@ async function quoteL2BaseCost2(input) {
6678
6682
  }
6679
6683
 
6680
6684
  // src/core/resources/deposits/priority.ts
6685
+ var ZK_CHAIN_PRICING_GETTERS_ABI = [
6686
+ {
6687
+ type: "function",
6688
+ name: "getZKsyncOS",
6689
+ stateMutability: "view",
6690
+ inputs: [],
6691
+ outputs: [{ name: "", type: "bool" }]
6692
+ },
6693
+ {
6694
+ type: "function",
6695
+ name: "getPubdataPricingMode",
6696
+ stateMutability: "view",
6697
+ inputs: [],
6698
+ outputs: [{ name: "", type: "uint8" }]
6699
+ }
6700
+ ];
6701
+ var PUBDATA_PRICING_MODE_ROLLUP = 0;
6681
6702
  var PRIORITY_TX_ENCODING_STEP_BYTES = 544n;
6682
6703
  var L1_TO_L2_ALIAS_OFFSET = 0x1111000000000000000000000000000000001111n;
6683
6704
  var DEFAULT_PRIORITY_BODY_GAS_ESTIMATE_MULTIPLIER = 7n;
6684
6705
  var PRIORITY_L2_GAS_BUFFER = 40n;
6706
+ var BASE_TOKEN_DEPOSIT_NEW_ACCOUNTS_PUBDATA_BYTES = 590n;
6685
6707
  var maxBigInt2 = (a, b) => a > b ? a : b;
6686
6708
  var ceilDiv = (a, b) => (a + b - 1n) / b;
6687
6709
  function applyL1ToL2Alias(address) {
@@ -6728,6 +6750,16 @@ function clampPriorityL2GasLimit(input) {
6728
6750
  })
6729
6751
  );
6730
6752
  }
6753
+ function resolveBaseTokenPriorityL2GasLimit(input) {
6754
+ if (input.nodeEstimate != null && input.nodeEstimate > 0n) {
6755
+ return maxBigInt2(input.priorityFloorGasLimit, applyGasBuffer(input.nodeEstimate));
6756
+ }
6757
+ if (!input.chargesPubdata) return input.priorityFloorGasLimit;
6758
+ return maxBigInt2(
6759
+ input.priorityFloorGasLimit,
6760
+ applyGasBuffer(BASE_TOKEN_DEPOSIT_NEW_ACCOUNTS_PUBDATA_BYTES * input.gasPerPubdata)
6761
+ );
6762
+ }
6731
6763
  function resolveRegisteredTokenPriorityL2GasLimit(input) {
6732
6764
  if (input.nodeEstimate != null && input.nodeEstimate > 0n) {
6733
6765
  return maxBigInt2(input.priorityFloorGasLimit, applyGasBuffer(input.nodeEstimate));
@@ -6751,6 +6783,39 @@ async function estimatePriorityTxL2Gas(ctx, leg) {
6751
6783
  return void 0;
6752
6784
  }
6753
6785
  }
6786
+ async function resolvePriorityTxL2Sender(ctx) {
6787
+ try {
6788
+ const code = await ctx.client.l1.getCode(ctx.sender);
6789
+ if (!code || code === "0x") return ctx.sender;
6790
+ } catch {
6791
+ }
6792
+ return applyL1ToL2Alias(ctx.sender);
6793
+ }
6794
+ var chainPricingCache = /* @__PURE__ */ new WeakMap();
6795
+ async function readChainPricing(ctx) {
6796
+ const cached = chainPricingCache.get(ctx.client)?.get(ctx.chainIdL2);
6797
+ if (cached) return cached;
6798
+ try {
6799
+ const bridgehub = new ethers.Contract(ctx.bridgehub, IBridgehub_default, ctx.client.l1);
6800
+ const zkChainAddress = await bridgehub.getZKChain(ctx.chainIdL2);
6801
+ const zkChain = new ethers.Contract(zkChainAddress, ZK_CHAIN_PRICING_GETTERS_ABI, ctx.client.l1);
6802
+ let zksyncOS;
6803
+ try {
6804
+ zksyncOS = await zkChain.getZKsyncOS();
6805
+ } catch (err) {
6806
+ if (!ethers.isError(err, "CALL_EXCEPTION")) throw err;
6807
+ zksyncOS = false;
6808
+ }
6809
+ const chargesPubdata = zksyncOS && Number(await zkChain.getPubdataPricingMode()) === PUBDATA_PRICING_MODE_ROLLUP;
6810
+ const pricing = { zksyncOS, chargesPubdata };
6811
+ const perClient = chainPricingCache.get(ctx.client) ?? /* @__PURE__ */ new Map();
6812
+ perClient.set(ctx.chainIdL2, pricing);
6813
+ chainPricingCache.set(ctx.client, perClient);
6814
+ return pricing;
6815
+ } catch {
6816
+ return void 0;
6817
+ }
6818
+ }
6754
6819
  async function quoteL1Fees2(input) {
6755
6820
  const { ctx } = input;
6756
6821
  return wrapAs2(
@@ -6786,6 +6851,26 @@ async function quoteL2Gas2(input) {
6786
6851
  stateOverrides: input.stateOverrides
6787
6852
  });
6788
6853
  }
6854
+ async function determineBaseL2GasLimit(input) {
6855
+ const { ctx } = input;
6856
+ if (ctx.l2GasLimit != null) return ctx.l2GasLimit;
6857
+ const [pricing, from] = await Promise.all([
6858
+ readChainPricing(ctx),
6859
+ resolvePriorityTxL2Sender(ctx)
6860
+ ]);
6861
+ if (pricing && !pricing.zksyncOS) return input.priorityFloorGasLimit;
6862
+ return resolveBaseTokenPriorityL2GasLimit({
6863
+ priorityFloorGasLimit: input.priorityFloorGasLimit,
6864
+ gasPerPubdata: ctx.gasPerPubdata,
6865
+ chargesPubdata: pricing?.chargesPubdata ?? true,
6866
+ nodeEstimate: await estimatePriorityTxL2Gas(ctx, {
6867
+ from,
6868
+ to: input.l2Contract,
6869
+ data: input.l2Calldata,
6870
+ value: input.l2Value
6871
+ })
6872
+ });
6873
+ }
6789
6874
  async function determineNonBaseL2Gas(input) {
6790
6875
  const { ctx, l1Token, route } = input;
6791
6876
  const fallbackQuote = () => quoteL2Gas2({
@@ -6946,13 +7031,19 @@ function routeEthDirect() {
6946
7031
  l2Calldata,
6947
7032
  gasPerPubdata: ctx.gasPerPubdata
6948
7033
  });
6949
- const quotedL2GasLimit = ctx.l2GasLimit ?? clampPriorityL2GasLimit({
6950
- gasLimit: applyPriorityL2GasLimitBuffer({
6951
- chainIdL2: ctx.chainIdL2,
6952
- gasLimit: priorityFloorBreakdown.derivedL2GasLimit
6953
- }),
7034
+ const quotedL2GasLimit = await determineBaseL2GasLimit({
7035
+ ctx,
7036
+ l2Contract,
7037
+ l2Value,
6954
7038
  l2Calldata,
6955
- gasPerPubdata: ctx.gasPerPubdata
7039
+ priorityFloorGasLimit: clampPriorityL2GasLimit({
7040
+ gasLimit: applyPriorityL2GasLimitBuffer({
7041
+ chainIdL2: ctx.chainIdL2,
7042
+ gasLimit: priorityFloorBreakdown.derivedL2GasLimit
7043
+ }),
7044
+ l2Calldata,
7045
+ gasPerPubdata: ctx.gasPerPubdata
7046
+ })
6956
7047
  });
6957
7048
  const l2GasParams = await quoteL2Gas2({
6958
7049
  ctx,
@@ -7584,13 +7675,19 @@ function routeErc20Base() {
7584
7675
  l2Calldata,
7585
7676
  gasPerPubdata: ctx.gasPerPubdata
7586
7677
  });
7587
- const quotedL2GasLimit = ctx.l2GasLimit ?? clampPriorityL2GasLimit({
7588
- gasLimit: applyPriorityL2GasLimitBuffer({
7589
- chainIdL2: ctx.chainIdL2,
7590
- gasLimit: priorityFloorBreakdown.derivedL2GasLimit
7591
- }),
7678
+ const quotedL2GasLimit = await determineBaseL2GasLimit({
7679
+ ctx,
7680
+ l2Contract,
7681
+ l2Value,
7592
7682
  l2Calldata,
7593
- gasPerPubdata: ctx.gasPerPubdata
7683
+ priorityFloorGasLimit: clampPriorityL2GasLimit({
7684
+ gasLimit: applyPriorityL2GasLimitBuffer({
7685
+ chainIdL2: ctx.chainIdL2,
7686
+ gasLimit: priorityFloorBreakdown.derivedL2GasLimit
7687
+ }),
7688
+ l2Calldata,
7689
+ gasPerPubdata: ctx.gasPerPubdata
7690
+ })
7594
7691
  });
7595
7692
  const l2GasParams = await quoteL2Gas2({
7596
7693
  ctx,