@matterlabs/zksync-js 0.0.24 → 0.0.25

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,5 +1,5 @@
1
- export { createViemSdk } from '../../chunk-QMMFUWRV.js';
2
- import '../../chunk-5S63J6DW.js';
1
+ export { createViemSdk } from '../../chunk-NFRRRT5X.js';
2
+ import '../../chunk-JWN26CQ6.js';
3
3
  import '../../chunk-BQ2YCWV2.js';
4
4
  import '../../chunk-OEUDZFXH.js';
5
5
  import '../../chunk-H5A6GU3D.js';
@@ -10,6 +10,7 @@ function isEraVmChain(chainIdL2) {
10
10
 
11
11
  // src/core/resources/deposits/gas.ts
12
12
  var CREATE_REESTIMATE_BUFFER = 15n;
13
+ var ZERO_FEES = { maxFeePerGas: 0n, maxPriorityFeePerGas: 0n };
13
14
  var maxBigInt = (a, b) => a > b ? a : b;
14
15
  function applyGasBuffer(gasLimit, bufferPct = BUFFER) {
15
16
  return gasLimit * (100n + bufferPct) / 100n;
@@ -60,15 +61,39 @@ async function fetchFees(estimator) {
60
61
  const gp = await estimator.getGasPrice();
61
62
  return { maxFeePerGas: gp, maxPriorityFeePerGas: 0n };
62
63
  } catch {
63
- return { maxFeePerGas: 0n, maxPriorityFeePerGas: 0n };
64
+ return void 0;
65
+ }
66
+ }
67
+ async function quoteL1Fees(input) {
68
+ const { estimator, overrides } = input;
69
+ const maxFeeOverride = overrides?.maxFeePerGas;
70
+ const tipOverride = overrides?.maxPriorityFeePerGas;
71
+ if (maxFeeOverride != null && tipOverride != null) {
72
+ return { maxFeePerGas: maxFeeOverride, maxPriorityFeePerGas: tipOverride };
73
+ }
74
+ const market = await fetchFees(estimator);
75
+ if (maxFeeOverride != null) {
76
+ const tip = market?.maxPriorityFeePerGas ?? 0n;
77
+ return {
78
+ maxFeePerGas: maxFeeOverride,
79
+ maxPriorityFeePerGas: tip < maxFeeOverride ? tip : maxFeeOverride
80
+ };
64
81
  }
82
+ if (market == null) {
83
+ throw new Error("Could not fetch L1 gas price for Bridgehub base cost calculation.");
84
+ }
85
+ if (tipOverride != null) {
86
+ const headroom = market.maxFeePerGas > market.maxPriorityFeePerGas ? market.maxFeePerGas - market.maxPriorityFeePerGas : 0n;
87
+ return { maxFeePerGas: headroom + tipOverride, maxPriorityFeePerGas: tipOverride };
88
+ }
89
+ return market;
65
90
  }
66
91
  async function quoteL1Gas(input) {
67
92
  const { estimator, tx, overrides, fallbackGasLimit } = input;
68
93
  let market;
69
94
  const getMarket = async () => {
70
95
  if (market) return market;
71
- market = await fetchFees(estimator);
96
+ market = await fetchFees(estimator) ?? ZERO_FEES;
72
97
  return market;
73
98
  };
74
99
  const maxFeePerGas = overrides?.maxFeePerGas ?? (tx.maxFeePerGas != null ? BigInt(tx.maxFeePerGas) : (await getMarket()).maxFeePerGas);
@@ -90,7 +115,7 @@ async function quoteL1Gas(input) {
90
115
  }
91
116
  async function quoteL2Gas(input) {
92
117
  const { estimator, route, tx, gasPerPubdata, l2GasLimit, overrideGasLimit, stateOverrides } = input;
93
- const market = await fetchFees(estimator);
118
+ const market = await fetchFees(estimator) ?? ZERO_FEES;
94
119
  const maxFeePerGas = market.maxFeePerGas || market.maxPriorityFeePerGas || 0n;
95
120
  const txGasLimit = tx?.gasLimit != null ? BigInt(tx.gasLimit) : void 0;
96
121
  const explicit = overrideGasLimit ?? txGasLimit;
@@ -131,12 +156,7 @@ async function quoteL2Gas(input) {
131
156
  }
132
157
  }
133
158
  async function quoteL2BaseCost(input) {
134
- const { estimator, encode, bridgehub, chainIdL2, l2GasLimit, gasPerPubdata } = input;
135
- const market = await fetchFees(estimator);
136
- const l1GasPrice = market.maxFeePerGas || market.maxPriorityFeePerGas || 0n;
137
- if (l1GasPrice === 0n) {
138
- throw new Error("Could not fetch L1 gas price for Bridgehub base cost calculation.");
139
- }
159
+ const { estimator, encode, bridgehub, chainIdL2, l2GasLimit, gasPerPubdata, l1GasPrice } = input;
140
160
  const data = encode(IBridgehub_default, "l2TransactionBaseCost", [
141
161
  chainIdL2,
142
162
  l1GasPrice,
@@ -682,4 +702,4 @@ async function quoteL2Gas2(input) {
682
702
  }
683
703
  }
684
704
 
685
- export { DEFAULT_POLL_MS, DEFAULT_TIMEOUT_MS, ZERO_HASH, applyL1ToL2Alias, applyPriorityL2GasLimitBuffer, assertProtocolVersion, buildDirectBundle, buildFeeBreakdown, buildFinalizationInfo, buildIndirectBundle, clampPriorityL2GasLimit, createAttributesResource, createNTVCodec, derivePriorityBodyGasEstimateCap, derivePriorityTxGasBreakdown, isInteropFinalizationInfo, parseBundleReceiptInfo, parseBundleSentFromReceipt, pickInteropRoute, preflightDirect, preflightIndirect, quoteL1Gas, quoteL2BaseCost, quoteL2Gas, quoteL2Gas2, resolveCreateDepositL1GasLimit, resolveIdsFromWaitable, resolveRegisteredTokenPriorityL2GasLimit, toGasOverrides };
705
+ export { DEFAULT_POLL_MS, DEFAULT_TIMEOUT_MS, ZERO_HASH, applyL1ToL2Alias, applyPriorityL2GasLimitBuffer, assertProtocolVersion, buildDirectBundle, buildFeeBreakdown, buildFinalizationInfo, buildIndirectBundle, clampPriorityL2GasLimit, createAttributesResource, createNTVCodec, derivePriorityBodyGasEstimateCap, derivePriorityTxGasBreakdown, isInteropFinalizationInfo, parseBundleReceiptInfo, parseBundleSentFromReceipt, pickInteropRoute, preflightDirect, preflightIndirect, quoteL1Fees, quoteL1Gas, quoteL2BaseCost, quoteL2Gas, quoteL2Gas2, resolveCreateDepositL1GasLimit, resolveIdsFromWaitable, resolveRegisteredTokenPriorityL2GasLimit, toGasOverrides };