@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.
@@ -8538,8 +8538,6 @@ async function quoteL2BaseCost(input) {
8538
8538
  });
8539
8539
  return BigInt(raw);
8540
8540
  }
8541
-
8542
- // src/adapters/ethers/estimator.ts
8543
8541
  function toCoreTx(tx) {
8544
8542
  return {
8545
8543
  to: tx.to,
@@ -8589,7 +8587,13 @@ function ethersToGasEstimator(provider) {
8589
8587
  throw new Error('Provider does not support "send"; cannot estimate priority tx gas.');
8590
8588
  }
8591
8589
  const result = await provider.send("eth_estimateGas", [
8592
- { from: tx.from, to: tx.to, data: tx.data, type: ZKSYNC_OS_PRIORITY_TX_TYPE }
8590
+ {
8591
+ from: tx.from,
8592
+ to: tx.to,
8593
+ data: tx.data,
8594
+ ...tx.value != null ? { value: ethers.toQuantity(tx.value) } : {},
8595
+ type: ZKSYNC_OS_PRIORITY_TX_TYPE
8596
+ }
8593
8597
  ]);
8594
8598
  return BigInt(result);
8595
8599
  },
@@ -8643,10 +8647,28 @@ async function quoteL2BaseCost2(input) {
8643
8647
  }
8644
8648
 
8645
8649
  // src/core/resources/deposits/priority.ts
8650
+ var ZK_CHAIN_PRICING_GETTERS_ABI = [
8651
+ {
8652
+ type: "function",
8653
+ name: "getZKsyncOS",
8654
+ stateMutability: "view",
8655
+ inputs: [],
8656
+ outputs: [{ name: "", type: "bool" }]
8657
+ },
8658
+ {
8659
+ type: "function",
8660
+ name: "getPubdataPricingMode",
8661
+ stateMutability: "view",
8662
+ inputs: [],
8663
+ outputs: [{ name: "", type: "uint8" }]
8664
+ }
8665
+ ];
8666
+ var PUBDATA_PRICING_MODE_ROLLUP = 0;
8646
8667
  var PRIORITY_TX_ENCODING_STEP_BYTES = 544n;
8647
8668
  var L1_TO_L2_ALIAS_OFFSET = 0x1111000000000000000000000000000000001111n;
8648
8669
  var DEFAULT_PRIORITY_BODY_GAS_ESTIMATE_MULTIPLIER = 7n;
8649
8670
  var PRIORITY_L2_GAS_BUFFER = 40n;
8671
+ var BASE_TOKEN_DEPOSIT_NEW_ACCOUNTS_PUBDATA_BYTES = 590n;
8650
8672
  var maxBigInt2 = (a, b) => a > b ? a : b;
8651
8673
  var ceilDiv = (a, b) => (a + b - 1n) / b;
8652
8674
  function applyL1ToL2Alias(address) {
@@ -8693,6 +8715,16 @@ function clampPriorityL2GasLimit(input) {
8693
8715
  })
8694
8716
  );
8695
8717
  }
8718
+ function resolveBaseTokenPriorityL2GasLimit(input) {
8719
+ if (input.nodeEstimate != null && input.nodeEstimate > 0n) {
8720
+ return maxBigInt2(input.priorityFloorGasLimit, applyGasBuffer(input.nodeEstimate));
8721
+ }
8722
+ if (!input.chargesPubdata) return input.priorityFloorGasLimit;
8723
+ return maxBigInt2(
8724
+ input.priorityFloorGasLimit,
8725
+ applyGasBuffer(BASE_TOKEN_DEPOSIT_NEW_ACCOUNTS_PUBDATA_BYTES * input.gasPerPubdata)
8726
+ );
8727
+ }
8696
8728
  function resolveRegisteredTokenPriorityL2GasLimit(input) {
8697
8729
  if (input.nodeEstimate != null && input.nodeEstimate > 0n) {
8698
8730
  return maxBigInt2(input.priorityFloorGasLimit, applyGasBuffer(input.nodeEstimate));
@@ -8716,6 +8748,39 @@ async function estimatePriorityTxL2Gas(ctx, leg) {
8716
8748
  return void 0;
8717
8749
  }
8718
8750
  }
8751
+ async function resolvePriorityTxL2Sender(ctx) {
8752
+ try {
8753
+ const code = await ctx.client.l1.getCode(ctx.sender);
8754
+ if (!code || code === "0x") return ctx.sender;
8755
+ } catch {
8756
+ }
8757
+ return applyL1ToL2Alias(ctx.sender);
8758
+ }
8759
+ var chainPricingCache = /* @__PURE__ */ new WeakMap();
8760
+ async function readChainPricing(ctx) {
8761
+ const cached = chainPricingCache.get(ctx.client)?.get(ctx.chainIdL2);
8762
+ if (cached) return cached;
8763
+ try {
8764
+ const bridgehub = new ethers.Contract(ctx.bridgehub, IBridgehub_default, ctx.client.l1);
8765
+ const zkChainAddress = await bridgehub.getZKChain(ctx.chainIdL2);
8766
+ const zkChain = new ethers.Contract(zkChainAddress, ZK_CHAIN_PRICING_GETTERS_ABI, ctx.client.l1);
8767
+ let zksyncOS;
8768
+ try {
8769
+ zksyncOS = await zkChain.getZKsyncOS();
8770
+ } catch (err) {
8771
+ if (!ethers.isError(err, "CALL_EXCEPTION")) throw err;
8772
+ zksyncOS = false;
8773
+ }
8774
+ const chargesPubdata = zksyncOS && Number(await zkChain.getPubdataPricingMode()) === PUBDATA_PRICING_MODE_ROLLUP;
8775
+ const pricing = { zksyncOS, chargesPubdata };
8776
+ const perClient = chainPricingCache.get(ctx.client) ?? /* @__PURE__ */ new Map();
8777
+ perClient.set(ctx.chainIdL2, pricing);
8778
+ chainPricingCache.set(ctx.client, perClient);
8779
+ return pricing;
8780
+ } catch {
8781
+ return void 0;
8782
+ }
8783
+ }
8719
8784
  async function quoteL1Fees2(input) {
8720
8785
  const { ctx } = input;
8721
8786
  return wrapAs3(
@@ -8751,6 +8816,26 @@ async function quoteL2Gas2(input) {
8751
8816
  stateOverrides: input.stateOverrides
8752
8817
  });
8753
8818
  }
8819
+ async function determineBaseL2GasLimit(input) {
8820
+ const { ctx } = input;
8821
+ if (ctx.l2GasLimit != null) return ctx.l2GasLimit;
8822
+ const [pricing, from] = await Promise.all([
8823
+ readChainPricing(ctx),
8824
+ resolvePriorityTxL2Sender(ctx)
8825
+ ]);
8826
+ if (pricing && !pricing.zksyncOS) return input.priorityFloorGasLimit;
8827
+ return resolveBaseTokenPriorityL2GasLimit({
8828
+ priorityFloorGasLimit: input.priorityFloorGasLimit,
8829
+ gasPerPubdata: ctx.gasPerPubdata,
8830
+ chargesPubdata: pricing?.chargesPubdata ?? true,
8831
+ nodeEstimate: await estimatePriorityTxL2Gas(ctx, {
8832
+ from,
8833
+ to: input.l2Contract,
8834
+ data: input.l2Calldata,
8835
+ value: input.l2Value
8836
+ })
8837
+ });
8838
+ }
8754
8839
  async function determineNonBaseL2Gas(input) {
8755
8840
  const { ctx, l1Token, route } = input;
8756
8841
  const fallbackQuote = () => quoteL2Gas2({
@@ -8911,13 +8996,19 @@ function routeEthDirect() {
8911
8996
  l2Calldata,
8912
8997
  gasPerPubdata: ctx.gasPerPubdata
8913
8998
  });
8914
- const quotedL2GasLimit = ctx.l2GasLimit ?? clampPriorityL2GasLimit({
8915
- gasLimit: applyPriorityL2GasLimitBuffer({
8916
- chainIdL2: ctx.chainIdL2,
8917
- gasLimit: priorityFloorBreakdown.derivedL2GasLimit
8918
- }),
8999
+ const quotedL2GasLimit = await determineBaseL2GasLimit({
9000
+ ctx,
9001
+ l2Contract,
9002
+ l2Value,
8919
9003
  l2Calldata,
8920
- gasPerPubdata: ctx.gasPerPubdata
9004
+ priorityFloorGasLimit: clampPriorityL2GasLimit({
9005
+ gasLimit: applyPriorityL2GasLimitBuffer({
9006
+ chainIdL2: ctx.chainIdL2,
9007
+ gasLimit: priorityFloorBreakdown.derivedL2GasLimit
9008
+ }),
9009
+ l2Calldata,
9010
+ gasPerPubdata: ctx.gasPerPubdata
9011
+ })
8921
9012
  });
8922
9013
  const l2GasParams = await quoteL2Gas2({
8923
9014
  ctx,
@@ -9546,13 +9637,19 @@ function routeErc20Base() {
9546
9637
  l2Calldata,
9547
9638
  gasPerPubdata: ctx.gasPerPubdata
9548
9639
  });
9549
- const quotedL2GasLimit = ctx.l2GasLimit ?? clampPriorityL2GasLimit({
9550
- gasLimit: applyPriorityL2GasLimitBuffer({
9551
- chainIdL2: ctx.chainIdL2,
9552
- gasLimit: priorityFloorBreakdown.derivedL2GasLimit
9553
- }),
9640
+ const quotedL2GasLimit = await determineBaseL2GasLimit({
9641
+ ctx,
9642
+ l2Contract,
9643
+ l2Value,
9554
9644
  l2Calldata,
9555
- gasPerPubdata: ctx.gasPerPubdata
9645
+ priorityFloorGasLimit: clampPriorityL2GasLimit({
9646
+ gasLimit: applyPriorityL2GasLimitBuffer({
9647
+ chainIdL2: ctx.chainIdL2,
9648
+ gasLimit: priorityFloorBreakdown.derivedL2GasLimit
9649
+ }),
9650
+ l2Calldata,
9651
+ gasPerPubdata: ctx.gasPerPubdata
9652
+ })
9556
9653
  });
9557
9654
  const l2GasParams = await quoteL2Gas2({
9558
9655
  ctx,