@matterlabs/zksync-js 0.0.24 → 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,10 +1,10 @@
1
1
  import { createErrorHandlers, toZKsyncError, classifyReadinessFromRevert } from './chunk-RZH7HBH3.js';
2
- import { createNTVCodec, createAttributesResource, resolveCreateDepositL1GasLimit, isInteropFinalizationInfo, DEFAULT_POLL_MS, DEFAULT_TIMEOUT_MS, resolveIdsFromWaitable, parseBundleReceiptInfo, buildFinalizationInfo, parseBundleSentFromReceipt, pickInteropRoute, ZERO_HASH, toGasOverrides, clampPriorityL2GasLimit, applyPriorityL2GasLimitBuffer, buildFeeBreakdown, buildIndirectBundle, preflightIndirect, buildDirectBundle, preflightDirect, derivePriorityTxGasBreakdown, quoteL2Gas, quoteL2BaseCost, quoteL1Gas, applyL1ToL2Alias, derivePriorityBodyGasEstimateCap, assertProtocolVersion, resolveRegisteredTokenPriorityL2GasLimit, quoteL2Gas2 } from './chunk-5S63J6DW.js';
2
+ import { createNTVCodec, createAttributesResource, resolveCreateDepositL1GasLimit, isInteropFinalizationInfo, DEFAULT_POLL_MS, DEFAULT_TIMEOUT_MS, resolveIdsFromWaitable, parseBundleReceiptInfo, buildFinalizationInfo, parseBundleSentFromReceipt, pickInteropRoute, ZERO_HASH, toGasOverrides, clampPriorityL2GasLimit, applyPriorityL2GasLimitBuffer, buildFeeBreakdown, buildIndirectBundle, preflightIndirect, buildDirectBundle, preflightDirect, derivePriorityTxGasBreakdown, resolveBaseTokenPriorityL2GasLimit, quoteL2Gas, quoteL1Fees, quoteL2BaseCost, quoteL1Gas, applyL1ToL2Alias, derivePriorityBodyGasEstimateCap, assertProtocolVersion, ZK_CHAIN_PRICING_GETTERS_ABI, PUBDATA_PRICING_MODE_ROLLUP, resolveRegisteredTokenPriorityL2GasLimit, quoteL2Gas2 } from './chunk-FMBQ7PVA.js';
3
3
  import { detectWithdrawalProtocol, buildWithdrawalFinalization, parseBundleHashFromLogs, classifyWithdrawalOutcome, phaseFromReadiness, buildWithdrawalBundle } from './chunk-BQ2YCWV2.js';
4
4
  import { findL1MessageSentLog, messengerLogIndex, l1MessageSentSender, pickWithdrawRoute } from './chunk-OEUDZFXH.js';
5
- import { IERC7786Attributes_default, isHash66, IL1Nullifier_default, IInteropHandler_default, createError, OP_WITHDRAWALS, normalizeL1Token, isAddressEq, hexEq, OP_DEPOSITS, IERC20_default, isZKsyncError, isReceiptNotFound, IL1NullifierV32_default, OP_INTEROP, IInteropRootStorage_default, IInteropCenter_default, sleep, isETH, normalizeAddrEq, IL2AssetRouter_default, L2NativeTokenVault_default, assertNever } from './chunk-JNS4XZE2.js';
5
+ import { IERC7786Attributes_default, isHash66, IL1Nullifier_default, IInteropHandler_default, createError, OP_WITHDRAWALS, normalizeL1Token, isAddressEq, hexEq, OP_DEPOSITS, IERC20_default, isZKsyncError, isReceiptNotFound, IL1NullifierV32_default, OP_INTEROP, IInteropRootStorage_default, IInteropCenter_default, sleep, isETH, normalizeAddrEq, IL2AssetRouter_default, L2NativeTokenVault_default, assertNever, IBridgehub_default } from './chunk-JNS4XZE2.js';
6
6
  import { ETH_ADDRESS, TOPIC_CANONICAL_ASSIGNED, TOPIC_CANONICAL_SUCCESS, L2_BASE_TOKEN_ADDRESS, L2_NATIVE_TOKEN_VAULT_ADDRESS, L1_MESSENGER_ADDRESS, L2_INTEROP_ROOT_STORAGE_ADDRESS, BUFFER, SAFE_L1_BRIDGE_GAS, L2_ASSET_ROUTER_ADDRESS, FORMAL_ETH_ADDRESS, ZKSYNC_OS_PRIORITY_TX_TYPE } from './chunk-3IPSDGHO.js';
7
- import { Interface, keccak256, AbiCoder, ethers, getBytes, Contract, NonceManager, JsonRpcProvider, getAddress, concat, hexlify, toBeArray, toBeHex, isError } from 'ethers';
7
+ import { Interface, keccak256, AbiCoder, ethers, getBytes, Contract, NonceManager, JsonRpcProvider, getAddress, concat, hexlify, toBeArray, toBeHex, toQuantity, isError } from 'ethers';
8
8
 
9
9
  var I_BRIDGEHUB = new Interface([
10
10
  "event NewPriorityRequest(uint256 indexed chainId, address indexed sender, bytes32 txHash, uint256 txId, bytes data)"
@@ -145,8 +145,6 @@ function buildDirectRequestStruct(args) {
145
145
  refundRecipient: args.refundRecipient
146
146
  };
147
147
  }
148
-
149
- // src/adapters/ethers/estimator.ts
150
148
  function toCoreTx(tx) {
151
149
  return {
152
150
  to: tx.to,
@@ -154,8 +152,9 @@ function toCoreTx(tx) {
154
152
  data: tx.data,
155
153
  value: tx.value ? BigInt(tx.value) : void 0,
156
154
  gasLimit: tx.gasLimit ? BigInt(tx.gasLimit) : void 0,
157
- maxFeePerGas: tx.maxFeePerGas ? BigInt(tx.maxFeePerGas) : void 0,
158
- maxPriorityFeePerGas: tx.maxPriorityFeePerGas ? BigInt(tx.maxPriorityFeePerGas) : void 0
155
+ // zero fees are explicit on zero-base-fee chains; dropping them would re-fetch the market tip
156
+ maxFeePerGas: tx.maxFeePerGas != null ? BigInt(tx.maxFeePerGas) : void 0,
157
+ maxPriorityFeePerGas: tx.maxPriorityFeePerGas != null ? BigInt(tx.maxPriorityFeePerGas) : void 0
159
158
  };
160
159
  }
161
160
  function ethersToGasEstimator(provider) {
@@ -195,7 +194,13 @@ function ethersToGasEstimator(provider) {
195
194
  throw new Error('Provider does not support "send"; cannot estimate priority tx gas.');
196
195
  }
197
196
  const result = await provider.send("eth_estimateGas", [
198
- { from: tx.from, to: tx.to, data: tx.data, type: ZKSYNC_OS_PRIORITY_TX_TYPE }
197
+ {
198
+ from: tx.from,
199
+ to: tx.to,
200
+ data: tx.data,
201
+ ...tx.value != null ? { value: toQuantity(tx.value) } : {},
202
+ type: ZKSYNC_OS_PRIORITY_TX_TYPE
203
+ }
199
204
  ]);
200
205
  return BigInt(result);
201
206
  },
@@ -230,7 +235,7 @@ var encode = (abi2, fn, args) => {
230
235
  return new Interface(abi2).encodeFunctionData(fn, args);
231
236
  };
232
237
  async function quoteL2BaseCost2(input) {
233
- const { ctx, l2GasLimit } = input;
238
+ const { ctx, l2GasLimit, l1GasPrice } = input;
234
239
  const estimator = ethersToGasEstimator(ctx.client.l1);
235
240
  return wrapAs(
236
241
  "RPC",
@@ -241,13 +246,13 @@ async function quoteL2BaseCost2(input) {
241
246
  bridgehub: ctx.bridgehub,
242
247
  chainIdL2: ctx.chainIdL2,
243
248
  l2GasLimit,
244
- gasPerPubdata: ctx.gasPerPubdata
249
+ gasPerPubdata: ctx.gasPerPubdata,
250
+ l1GasPrice
245
251
  }),
246
252
  { ctx: { chainIdL2: ctx.chainIdL2 } }
247
253
  );
248
254
  }
249
-
250
- // src/adapters/ethers/resources/deposits/services/gas.ts
255
+ var { wrapAs: wrapAs2 } = createErrorHandlers("deposits");
251
256
  var DEFAULT_SAFE_NONBASE_L2_GAS_LIMIT = 3000000n;
252
257
  var ZERO_L2_TOKEN_ADDRESS = "0x0000000000000000000000000000000000000000";
253
258
  async function estimatePriorityTxL2Gas(ctx, leg) {
@@ -258,6 +263,51 @@ async function estimatePriorityTxL2Gas(ctx, leg) {
258
263
  return void 0;
259
264
  }
260
265
  }
266
+ async function resolvePriorityTxL2Sender(ctx) {
267
+ try {
268
+ const code = await ctx.client.l1.getCode(ctx.sender);
269
+ if (!code || code === "0x") return ctx.sender;
270
+ } catch {
271
+ }
272
+ return applyL1ToL2Alias(ctx.sender);
273
+ }
274
+ var chainPricingCache = /* @__PURE__ */ new WeakMap();
275
+ async function readChainPricing(ctx) {
276
+ const cached = chainPricingCache.get(ctx.client)?.get(ctx.chainIdL2);
277
+ if (cached) return cached;
278
+ try {
279
+ const bridgehub = new Contract(ctx.bridgehub, IBridgehub_default, ctx.client.l1);
280
+ const zkChainAddress = await bridgehub.getZKChain(ctx.chainIdL2);
281
+ const zkChain = new Contract(zkChainAddress, ZK_CHAIN_PRICING_GETTERS_ABI, ctx.client.l1);
282
+ let zksyncOS;
283
+ try {
284
+ zksyncOS = await zkChain.getZKsyncOS();
285
+ } catch (err) {
286
+ if (!isError(err, "CALL_EXCEPTION")) throw err;
287
+ zksyncOS = false;
288
+ }
289
+ const chargesPubdata = zksyncOS && Number(await zkChain.getPubdataPricingMode()) === PUBDATA_PRICING_MODE_ROLLUP;
290
+ const pricing = { zksyncOS, chargesPubdata };
291
+ const perClient = chainPricingCache.get(ctx.client) ?? /* @__PURE__ */ new Map();
292
+ perClient.set(ctx.chainIdL2, pricing);
293
+ chainPricingCache.set(ctx.client, perClient);
294
+ return pricing;
295
+ } catch {
296
+ return void 0;
297
+ }
298
+ }
299
+ async function quoteL1Fees2(input) {
300
+ const { ctx } = input;
301
+ return wrapAs2(
302
+ "RPC",
303
+ "deposits.fees.l1",
304
+ () => quoteL1Fees({
305
+ estimator: ethersToGasEstimator(ctx.client.l1),
306
+ overrides: ctx.gasOverrides
307
+ }),
308
+ { ctx: { chainIdL2: ctx.chainIdL2 } }
309
+ );
310
+ }
261
311
  async function quoteL1Gas2(input) {
262
312
  const { ctx, tx, overrides, fallbackGasLimit } = input;
263
313
  const estimator = ethersToGasEstimator(ctx.client.l1);
@@ -281,6 +331,26 @@ async function quoteL2Gas3(input) {
281
331
  stateOverrides: input.stateOverrides
282
332
  });
283
333
  }
334
+ async function determineBaseL2GasLimit(input) {
335
+ const { ctx } = input;
336
+ if (ctx.l2GasLimit != null) return ctx.l2GasLimit;
337
+ const [pricing, from] = await Promise.all([
338
+ readChainPricing(ctx),
339
+ resolvePriorityTxL2Sender(ctx)
340
+ ]);
341
+ if (pricing && !pricing.zksyncOS) return input.priorityFloorGasLimit;
342
+ return resolveBaseTokenPriorityL2GasLimit({
343
+ priorityFloorGasLimit: input.priorityFloorGasLimit,
344
+ gasPerPubdata: ctx.gasPerPubdata,
345
+ chargesPubdata: pricing?.chargesPubdata ?? true,
346
+ nodeEstimate: await estimatePriorityTxL2Gas(ctx, {
347
+ from,
348
+ to: input.l2Contract,
349
+ data: input.l2Calldata,
350
+ value: input.l2Value
351
+ })
352
+ });
353
+ }
284
354
  async function determineNonBaseL2Gas(input) {
285
355
  const { ctx, l1Token, route } = input;
286
356
  const fallbackQuote = () => quoteL2Gas3({
@@ -413,13 +483,19 @@ function routeEthDirect() {
413
483
  l2Calldata,
414
484
  gasPerPubdata: ctx.gasPerPubdata
415
485
  });
416
- const quotedL2GasLimit = ctx.l2GasLimit ?? clampPriorityL2GasLimit({
417
- gasLimit: applyPriorityL2GasLimitBuffer({
418
- chainIdL2: ctx.chainIdL2,
419
- gasLimit: priorityFloorBreakdown.derivedL2GasLimit
420
- }),
486
+ const quotedL2GasLimit = await determineBaseL2GasLimit({
487
+ ctx,
488
+ l2Contract,
489
+ l2Value,
421
490
  l2Calldata,
422
- gasPerPubdata: ctx.gasPerPubdata
491
+ priorityFloorGasLimit: clampPriorityL2GasLimit({
492
+ gasLimit: applyPriorityL2GasLimitBuffer({
493
+ chainIdL2: ctx.chainIdL2,
494
+ gasLimit: priorityFloorBreakdown.derivedL2GasLimit
495
+ }),
496
+ l2Calldata,
497
+ gasPerPubdata: ctx.gasPerPubdata
498
+ })
423
499
  });
424
500
  const l2GasParams = await quoteL2Gas3({
425
501
  ctx,
@@ -429,7 +505,12 @@ function routeEthDirect() {
429
505
  if (!l2GasParams) {
430
506
  throw new Error("Failed to estimate L2 gas for deposit.");
431
507
  }
432
- const baseCost = await quoteL2BaseCost2({ ctx, l2GasLimit: l2GasParams.gasLimit });
508
+ const l1Fees = await quoteL1Fees2({ ctx });
509
+ const baseCost = await quoteL2BaseCost2({
510
+ ctx,
511
+ l2GasLimit: l2GasParams.gasLimit,
512
+ l1GasPrice: l1Fees.maxFeePerGas
513
+ });
433
514
  const mintValue = baseCost + ctx.operatorTip + l2Value;
434
515
  const req = buildDirectRequestStruct({
435
516
  chainId: ctx.chainIdL2,
@@ -446,7 +527,8 @@ function routeEthDirect() {
446
527
  data,
447
528
  value: mintValue,
448
529
  from: ctx.sender,
449
- ...ctx.gasOverrides
530
+ ...ctx.gasOverrides,
531
+ ...l1Fees
450
532
  };
451
533
  const l1GasParams = await quoteL1Gas2({
452
534
  ctx,
@@ -482,7 +564,7 @@ function routeEthDirect() {
482
564
  }
483
565
  };
484
566
  }
485
- var { wrapAs: wrapAs2 } = createErrorHandlers("deposits");
567
+ var { wrapAs: wrapAs3 } = createErrorHandlers("deposits");
486
568
  var ZERO_L2_TOKEN_ADDRESS2 = "0x0000000000000000000000000000000000000000";
487
569
  var ZERO_ASSET_ID = "0x0000000000000000000000000000000000000000000000000000000000000000";
488
570
  var ntvCodec = createNTVCodec({
@@ -565,7 +647,7 @@ function routeErc20NonBase() {
565
647
  async preflight(p, ctx) {
566
648
  const resolved = ctx.resolvedToken ?? (ctx.tokens ? await ctx.tokens.resolve(p.token, { chain: "l1" }) : void 0);
567
649
  const baseToken = ctx.baseTokenL1 ?? await ctx.client.baseToken(ctx.chainIdL2);
568
- await wrapAs2(
650
+ await wrapAs3(
569
651
  "VALIDATION",
570
652
  OP_DEPOSITS.nonbase.assertNonBaseToken,
571
653
  () => {
@@ -581,7 +663,7 @@ function routeErc20NonBase() {
581
663
  const baseToken = ctx.baseTokenL1 ?? await ctx.client.baseToken(ctx.chainIdL2);
582
664
  const baseIsEth = ctx.baseIsEth ?? isETH(baseToken);
583
665
  const receiver = p.to ?? ctx.sender;
584
- const secondBridgeCalldata = await wrapAs2(
666
+ const secondBridgeCalldata = await wrapAs3(
585
667
  "INTERNAL",
586
668
  OP_DEPOSITS.nonbase.encodeCalldata,
587
669
  () => encodeSecondBridgeErc20DepositCalldata({
@@ -615,14 +697,19 @@ function routeErc20NonBase() {
615
697
  }
616
698
  });
617
699
  if (!l2GasParams) throw new Error("Failed to establish L2 gas parameters.");
618
- const baseCost = await quoteL2BaseCost2({ ctx, l2GasLimit: l2GasParams.gasLimit });
700
+ const l1Fees = await quoteL1Fees2({ ctx });
701
+ const baseCost = await quoteL2BaseCost2({
702
+ ctx,
703
+ l2GasLimit: l2GasParams.gasLimit,
704
+ l1GasPrice: l1Fees.maxFeePerGas
705
+ });
619
706
  const mintValue = baseCost + ctx.operatorTip;
620
707
  const approvals = [];
621
708
  const steps = [];
622
709
  const assetRouter = ctx.l1AssetRouter;
623
710
  const nativeTokenVault = ctx.l1NativeTokenVault;
624
711
  const erc20Deposit = new Contract(p.token, IERC20_default, l1Signer);
625
- const allowanceToken = await wrapAs2(
712
+ const allowanceToken = await wrapAs3(
626
713
  "RPC",
627
714
  OP_DEPOSITS.nonbase.allowanceToken,
628
715
  () => erc20Deposit.allowance(ctx.sender, nativeTokenVault),
@@ -650,7 +737,7 @@ function routeErc20NonBase() {
650
737
  }
651
738
  if (!baseIsEth) {
652
739
  const erc20Base = new Contract(baseToken, IERC20_default, l1Signer);
653
- const allowanceBase = await wrapAs2(
740
+ const allowanceBase = await wrapAs3(
654
741
  "RPC",
655
742
  OP_DEPOSITS.nonbase.allowanceBase,
656
743
  () => erc20Base.allowance(ctx.sender, nativeTokenVault),
@@ -698,7 +785,8 @@ function routeErc20NonBase() {
698
785
  data,
699
786
  value: txValue,
700
787
  from: ctx.sender,
701
- ...ctx.gasOverrides
788
+ ...ctx.gasOverrides,
789
+ ...l1Fees
702
790
  };
703
791
  const l1GasParams = await quoteL1Gas2({
704
792
  ctx,
@@ -733,7 +821,7 @@ function routeErc20NonBase() {
733
821
  }
734
822
  };
735
823
  }
736
- var { wrapAs: wrapAs3 } = createErrorHandlers("deposits");
824
+ var { wrapAs: wrapAs4 } = createErrorHandlers("deposits");
737
825
  var ZERO_L2_TOKEN_ADDRESS3 = "0x0000000000000000000000000000000000000000";
738
826
  var ZERO_ASSET_ID2 = "0x0000000000000000000000000000000000000000000000000000000000000000";
739
827
  var ntvCodec2 = createNTVCodec({
@@ -809,7 +897,7 @@ function routeEthNonBase() {
809
897
  return {
810
898
  async preflight(p, ctx) {
811
899
  const resolved = ctx.resolvedToken ?? (ctx.tokens ? await ctx.tokens.resolve(p.token, { chain: "l1" }) : void 0);
812
- await wrapAs3(
900
+ await wrapAs4(
813
901
  "VALIDATION",
814
902
  OP_DEPOSITS.ethNonBase.assertEthAsset,
815
903
  () => {
@@ -819,7 +907,7 @@ function routeEthNonBase() {
819
907
  },
820
908
  { ctx: { token: p.token } }
821
909
  );
822
- await wrapAs3(
910
+ await wrapAs4(
823
911
  "VALIDATION",
824
912
  OP_DEPOSITS.ethNonBase.assertNonEthBase,
825
913
  () => {
@@ -829,7 +917,7 @@ function routeEthNonBase() {
829
917
  },
830
918
  { ctx: { baseIsEth: ctx.baseIsEth, chainIdL2: ctx.chainIdL2 } }
831
919
  );
832
- const ethBal = await wrapAs3(
920
+ const ethBal = await wrapAs4(
833
921
  "RPC",
834
922
  OP_DEPOSITS.ethNonBase.ethBalance,
835
923
  () => ctx.client.l1.getBalance(ctx.sender),
@@ -838,7 +926,7 @@ function routeEthNonBase() {
838
926
  message: "Failed to read L1 ETH balance."
839
927
  }
840
928
  );
841
- await wrapAs3(
929
+ await wrapAs4(
842
930
  "VALIDATION",
843
931
  OP_DEPOSITS.ethNonBase.assertEthBalance,
844
932
  () => {
@@ -873,12 +961,17 @@ function routeEthNonBase() {
873
961
  undeployedGasLimit: priorityGasModel.undeployedGasLimit
874
962
  });
875
963
  if (!l2GasParams) throw new Error("Failed to estimate L2 gas parameters.");
876
- const baseCost = await quoteL2BaseCost2({ ctx, l2GasLimit: l2GasParams.gasLimit });
964
+ const l1Fees = await quoteL1Fees2({ ctx });
965
+ const baseCost = await quoteL2BaseCost2({
966
+ ctx,
967
+ l2GasLimit: l2GasParams.gasLimit,
968
+ l1GasPrice: l1Fees.maxFeePerGas
969
+ });
877
970
  const mintValue = baseCost + ctx.operatorTip;
878
971
  const approvals = [];
879
972
  const steps = [];
880
973
  const erc20Base = new Contract(baseToken, IERC20_default, l1Signer);
881
- const allowance = await wrapAs3(
974
+ const allowance = await wrapAs4(
882
975
  "RPC",
883
976
  OP_DEPOSITS.ethNonBase.allowanceBase,
884
977
  () => erc20Base.allowance(ctx.sender, ctx.l1NativeTokenVault),
@@ -904,7 +997,7 @@ function routeEthNonBase() {
904
997
  }
905
998
  });
906
999
  }
907
- const secondBridgeCalldata = await wrapAs3(
1000
+ const secondBridgeCalldata = await wrapAs4(
908
1001
  "INTERNAL",
909
1002
  OP_DEPOSITS.ethNonBase.encodeCalldata,
910
1003
  () => encodeSecondBridgeEthDepositCalldata({ ctx, amount: p.amount, receiver }),
@@ -937,7 +1030,8 @@ function routeEthNonBase() {
937
1030
  data,
938
1031
  value: bridgehubValue,
939
1032
  from: ctx.sender,
940
- ...ctx.gasOverrides
1033
+ ...ctx.gasOverrides,
1034
+ ...l1Fees
941
1035
  };
942
1036
  const l1GasParams = await quoteL1Gas2({
943
1037
  ctx,
@@ -972,13 +1066,13 @@ function routeEthNonBase() {
972
1066
  }
973
1067
  };
974
1068
  }
975
- var { wrapAs: wrapAs4 } = createErrorHandlers("deposits");
1069
+ var { wrapAs: wrapAs5 } = createErrorHandlers("deposits");
976
1070
  var EMPTY_BYTES3 = "0x";
977
1071
  function routeErc20Base() {
978
1072
  return {
979
1073
  async preflight(p, ctx) {
980
1074
  const resolved = ctx.resolvedToken ?? (ctx.tokens ? await ctx.tokens.resolve(p.token, { chain: "l1" }) : void 0);
981
- await wrapAs4(
1075
+ await wrapAs5(
982
1076
  "VALIDATION",
983
1077
  OP_DEPOSITS.base.assertErc20Asset,
984
1078
  () => {
@@ -989,7 +1083,7 @@ function routeErc20Base() {
989
1083
  { ctx: { token: p.token } }
990
1084
  );
991
1085
  const baseToken = ctx.baseTokenL1 ?? await ctx.client.baseToken(ctx.chainIdL2);
992
- await wrapAs4(
1086
+ await wrapAs5(
993
1087
  "VALIDATION",
994
1088
  OP_DEPOSITS.base.assertMatchesBase,
995
1089
  () => {
@@ -1014,13 +1108,19 @@ function routeErc20Base() {
1014
1108
  l2Calldata,
1015
1109
  gasPerPubdata: ctx.gasPerPubdata
1016
1110
  });
1017
- const quotedL2GasLimit = ctx.l2GasLimit ?? clampPriorityL2GasLimit({
1018
- gasLimit: applyPriorityL2GasLimitBuffer({
1019
- chainIdL2: ctx.chainIdL2,
1020
- gasLimit: priorityFloorBreakdown.derivedL2GasLimit
1021
- }),
1111
+ const quotedL2GasLimit = await determineBaseL2GasLimit({
1112
+ ctx,
1113
+ l2Contract,
1114
+ l2Value,
1022
1115
  l2Calldata,
1023
- gasPerPubdata: ctx.gasPerPubdata
1116
+ priorityFloorGasLimit: clampPriorityL2GasLimit({
1117
+ gasLimit: applyPriorityL2GasLimitBuffer({
1118
+ chainIdL2: ctx.chainIdL2,
1119
+ gasLimit: priorityFloorBreakdown.derivedL2GasLimit
1120
+ }),
1121
+ l2Calldata,
1122
+ gasPerPubdata: ctx.gasPerPubdata
1123
+ })
1024
1124
  });
1025
1125
  const l2GasParams = await quoteL2Gas3({
1026
1126
  ctx,
@@ -1028,13 +1128,18 @@ function routeErc20Base() {
1028
1128
  overrideGasLimit: quotedL2GasLimit
1029
1129
  });
1030
1130
  if (!l2GasParams) throw new Error("Failed to estimate L2 gas parameters.");
1031
- const baseCost = await quoteL2BaseCost2({ ctx, l2GasLimit: l2GasParams.gasLimit });
1131
+ const l1Fees = await quoteL1Fees2({ ctx });
1132
+ const baseCost = await quoteL2BaseCost2({
1133
+ ctx,
1134
+ l2GasLimit: l2GasParams.gasLimit,
1135
+ l1GasPrice: l1Fees.maxFeePerGas
1136
+ });
1032
1137
  const mintValue = baseCost + ctx.operatorTip + p.amount;
1033
1138
  const approvals = [];
1034
1139
  const steps = [];
1035
1140
  {
1036
1141
  const erc20 = new Contract(baseToken, IERC20_default, l1Signer);
1037
- const allowance = await wrapAs4(
1142
+ const allowance = await wrapAs5(
1038
1143
  "RPC",
1039
1144
  OP_DEPOSITS.base.allowance,
1040
1145
  () => erc20.allowance(ctx.sender, ctx.l1NativeTokenVault),
@@ -1080,7 +1185,8 @@ function routeErc20Base() {
1080
1185
  value: 0n,
1081
1186
  // base token is ERC-20 ⇒ msg.value MUST be 0
1082
1187
  from: ctx.sender,
1083
- ...ctx.gasOverrides
1188
+ ...ctx.gasOverrides,
1189
+ ...l1Fees
1084
1190
  };
1085
1191
  const l1GasParams = await quoteL1Gas2({
1086
1192
  ctx,
@@ -1115,7 +1221,7 @@ function routeErc20Base() {
1115
1221
  }
1116
1222
  };
1117
1223
  }
1118
- var { wrapAs: wrapAs5 } = createErrorHandlers("tokens");
1224
+ var { wrapAs: wrapAs6 } = createErrorHandlers("tokens");
1119
1225
  var abi = AbiCoder.defaultAbiCoder();
1120
1226
  var ntvCodec3 = createNTVCodec({
1121
1227
  encode: (types, values) => abi.encode(types, values),
@@ -1128,7 +1234,7 @@ function createTokensResource(client) {
1128
1234
  let wethL2Promise = null;
1129
1235
  async function getL1ChainId() {
1130
1236
  if (!l2NtvL1ChainIdPromise) {
1131
- l2NtvL1ChainIdPromise = wrapAs5("INTERNAL", "getL1ChainId", async () => {
1237
+ l2NtvL1ChainIdPromise = wrapAs6("INTERNAL", "getL1ChainId", async () => {
1132
1238
  const { l2NativeTokenVault } = await client.contracts();
1133
1239
  const chainId = await l2NativeTokenVault.L1_CHAIN_ID();
1134
1240
  return chainId;
@@ -1138,7 +1244,7 @@ function createTokensResource(client) {
1138
1244
  }
1139
1245
  async function getBaseTokenAssetId() {
1140
1246
  if (!baseTokenAssetIdPromise) {
1141
- baseTokenAssetIdPromise = wrapAs5("INTERNAL", "baseTokenAssetId", async () => {
1247
+ baseTokenAssetIdPromise = wrapAs6("INTERNAL", "baseTokenAssetId", async () => {
1142
1248
  const { l2NativeTokenVault } = await client.contracts();
1143
1249
  const assetId = await l2NativeTokenVault.BASE_TOKEN_ASSET_ID();
1144
1250
  return assetId;
@@ -1148,7 +1254,7 @@ function createTokensResource(client) {
1148
1254
  }
1149
1255
  async function getWethL1() {
1150
1256
  if (!wethL1Promise) {
1151
- wethL1Promise = wrapAs5("INTERNAL", "wethL1", async () => {
1257
+ wethL1Promise = wrapAs6("INTERNAL", "wethL1", async () => {
1152
1258
  const { l1NativeTokenVault } = await client.contracts();
1153
1259
  const weth = await l1NativeTokenVault.WETH_TOKEN();
1154
1260
  return weth;
@@ -1158,7 +1264,7 @@ function createTokensResource(client) {
1158
1264
  }
1159
1265
  async function getWethL2() {
1160
1266
  if (!wethL2Promise) {
1161
- wethL2Promise = wrapAs5("INTERNAL", "wethL2", async () => {
1267
+ wethL2Promise = wrapAs6("INTERNAL", "wethL2", async () => {
1162
1268
  const { l2NativeTokenVault } = await client.contracts();
1163
1269
  const weth = await l2NativeTokenVault.WETH_TOKEN();
1164
1270
  return weth;
@@ -1167,7 +1273,7 @@ function createTokensResource(client) {
1167
1273
  return wethL2Promise;
1168
1274
  }
1169
1275
  async function toL2Address(l1Token) {
1170
- return wrapAs5("CONTRACT", "tokens.toL2Address", async () => {
1276
+ return wrapAs6("CONTRACT", "tokens.toL2Address", async () => {
1171
1277
  const normalized = normalizeL1Token(l1Token);
1172
1278
  const { chainId } = await client.l2.getNetwork();
1173
1279
  const baseToken = await client.baseToken(BigInt(chainId));
@@ -1180,7 +1286,7 @@ function createTokensResource(client) {
1180
1286
  });
1181
1287
  }
1182
1288
  async function toL1Address(l2Token) {
1183
- return wrapAs5("CONTRACT", "tokens.toL1Address", async () => {
1289
+ return wrapAs6("CONTRACT", "tokens.toL1Address", async () => {
1184
1290
  if (isAddressEq(l2Token, ETH_ADDRESS)) {
1185
1291
  return ETH_ADDRESS;
1186
1292
  }
@@ -1203,7 +1309,7 @@ function createTokensResource(client) {
1203
1309
  });
1204
1310
  }
1205
1311
  async function assetIdOfL1(l1Token) {
1206
- return wrapAs5("CONTRACT", "tokens.assetIdOfL1", async () => {
1312
+ return wrapAs6("CONTRACT", "tokens.assetIdOfL1", async () => {
1207
1313
  const normalized = normalizeL1Token(l1Token);
1208
1314
  const { l1NativeTokenVault } = await client.contracts();
1209
1315
  const assetId = await l1NativeTokenVault.assetId(normalized);
@@ -1211,28 +1317,28 @@ function createTokensResource(client) {
1211
1317
  });
1212
1318
  }
1213
1319
  async function assetIdOfL2(l2Token) {
1214
- return wrapAs5("CONTRACT", "tokens.assetIdOfL2", async () => {
1320
+ return wrapAs6("CONTRACT", "tokens.assetIdOfL2", async () => {
1215
1321
  const { l2NativeTokenVault } = await client.contracts();
1216
1322
  const assetId = await l2NativeTokenVault.assetId(l2Token);
1217
1323
  return assetId;
1218
1324
  });
1219
1325
  }
1220
1326
  async function l2TokenFromAssetId(assetId) {
1221
- return wrapAs5("CONTRACT", "tokens.l2TokenFromAssetId", async () => {
1327
+ return wrapAs6("CONTRACT", "tokens.l2TokenFromAssetId", async () => {
1222
1328
  const { l2NativeTokenVault } = await client.contracts();
1223
1329
  const tokenAddr = await l2NativeTokenVault.tokenAddress(assetId);
1224
1330
  return tokenAddr;
1225
1331
  });
1226
1332
  }
1227
1333
  async function l1TokenFromAssetId(assetId) {
1228
- return wrapAs5("CONTRACT", "tokens.l1TokenFromAssetId", async () => {
1334
+ return wrapAs6("CONTRACT", "tokens.l1TokenFromAssetId", async () => {
1229
1335
  const { l1NativeTokenVault } = await client.contracts();
1230
1336
  const tokenAddr = await l1NativeTokenVault.tokenAddress(assetId);
1231
1337
  return tokenAddr;
1232
1338
  });
1233
1339
  }
1234
1340
  async function originChainId(assetId) {
1235
- return wrapAs5("CONTRACT", "tokens.originChainId", async () => {
1341
+ return wrapAs6("CONTRACT", "tokens.originChainId", async () => {
1236
1342
  const { l2NativeTokenVault } = await client.contracts();
1237
1343
  const chainId = await l2NativeTokenVault.originChainId(assetId);
1238
1344
  return chainId;
@@ -1242,7 +1348,7 @@ function createTokensResource(client) {
1242
1348
  return getBaseTokenAssetId();
1243
1349
  }
1244
1350
  async function isChainEthBased() {
1245
- return wrapAs5("CONTRACT", "tokens.isChainEthBased", async () => {
1351
+ return wrapAs6("CONTRACT", "tokens.isChainEthBased", async () => {
1246
1352
  const baseAssetId = await getBaseTokenAssetId();
1247
1353
  const l1ChainId = await getL1ChainId();
1248
1354
  const ethAssetId = ntvCodec3.encodeAssetId(
@@ -1260,7 +1366,7 @@ function createTokensResource(client) {
1260
1366
  return getWethL2();
1261
1367
  }
1262
1368
  async function computeL2BridgedAddress(args) {
1263
- return wrapAs5("CONTRACT", "tokens.computeL2BridgedAddress", async () => {
1369
+ return wrapAs6("CONTRACT", "tokens.computeL2BridgedAddress", async () => {
1264
1370
  const normalized = normalizeL1Token(args.l1Token);
1265
1371
  const { l2NativeTokenVault } = await client.contracts();
1266
1372
  const predicted = await l2NativeTokenVault.calculateCreate2TokenAddress(
@@ -1271,7 +1377,7 @@ function createTokensResource(client) {
1271
1377
  });
1272
1378
  }
1273
1379
  async function resolve(ref, opts) {
1274
- return wrapAs5("CONTRACT", "tokens.resolve", async () => {
1380
+ return wrapAs6("CONTRACT", "tokens.resolve", async () => {
1275
1381
  let chain;
1276
1382
  let address;
1277
1383
  if (typeof ref === "string") {
@@ -1764,13 +1870,13 @@ function buildFeeBreakdown2(p) {
1764
1870
  }
1765
1871
 
1766
1872
  // src/adapters/ethers/resources/withdrawals/routes/eth.ts
1767
- var { wrapAs: wrapAs6 } = createErrorHandlers("withdrawals");
1873
+ var { wrapAs: wrapAs7 } = createErrorHandlers("withdrawals");
1768
1874
  function routeEthBase() {
1769
1875
  return {
1770
1876
  async build(p, ctx) {
1771
1877
  const steps = [];
1772
1878
  const base = await ctx.contracts.l2BaseTokenSystem();
1773
- const data = await wrapAs6(
1879
+ const data = await wrapAs7(
1774
1880
  "INTERNAL",
1775
1881
  OP_WITHDRAWALS.eth.encodeWithdraw,
1776
1882
  () => Promise.resolve(base.interface.encodeFunctionData("withdraw", [p.to ?? ctx.sender])),
@@ -1805,7 +1911,7 @@ function routeEthBase() {
1805
1911
  }
1806
1912
  };
1807
1913
  }
1808
- var { wrapAs: wrapAs7 } = createErrorHandlers("withdrawals");
1914
+ var { wrapAs: wrapAs8 } = createErrorHandlers("withdrawals");
1809
1915
  var SIG = {
1810
1916
  withdraw: "withdraw(bytes32,bytes)"
1811
1917
  };
@@ -1815,7 +1921,7 @@ function routeErc20NonBase2() {
1815
1921
  const steps = [];
1816
1922
  const approvals = [];
1817
1923
  const erc20 = new Contract(p.token, IERC20_default, ctx.client.l2);
1818
- const current = await wrapAs7(
1924
+ const current = await wrapAs8(
1819
1925
  "CONTRACT",
1820
1926
  OP_WITHDRAWALS.erc20.allowance,
1821
1927
  () => erc20.allowance(ctx.sender, ctx.l2NativeTokenVault),
@@ -1853,7 +1959,7 @@ function routeErc20NonBase2() {
1853
1959
  tx: approveTx
1854
1960
  });
1855
1961
  }
1856
- const assetId = await wrapAs7(
1962
+ const assetId = await wrapAs8(
1857
1963
  "CONTRACT",
1858
1964
  OP_WITHDRAWALS.erc20.ensureRegistered,
1859
1965
  async () => {
@@ -1866,7 +1972,7 @@ function routeErc20NonBase2() {
1866
1972
  message: "Failed to ensure token is registered in L2NativeTokenVault."
1867
1973
  }
1868
1974
  );
1869
- const assetData = await wrapAs7(
1975
+ const assetData = await wrapAs8(
1870
1976
  "INTERNAL",
1871
1977
  OP_WITHDRAWALS.erc20.encodeAssetData,
1872
1978
  () => Promise.resolve(
@@ -1878,7 +1984,7 @@ function routeErc20NonBase2() {
1878
1984
  }
1879
1985
  );
1880
1986
  const l2ar = await ctx.contracts.l2AssetRouter();
1881
- const dataWithdraw = await wrapAs7(
1987
+ const dataWithdraw = await wrapAs8(
1882
1988
  "INTERNAL",
1883
1989
  OP_WITHDRAWALS.erc20.encodeWithdraw,
1884
1990
  () => Promise.resolve(l2ar.interface.encodeFunctionData(SIG.withdraw, [assetId, assetData])),
@@ -1968,7 +2074,7 @@ function createEthersAttributesResource(opts = {}) {
1968
2074
  }
1969
2075
 
1970
2076
  // src/adapters/ethers/resources/withdrawals/routes/interop-bundle.ts
1971
- var { wrapAs: wrapAs8 } = createErrorHandlers("withdrawals");
2077
+ var { wrapAs: wrapAs9 } = createErrorHandlers("withdrawals");
1972
2078
  var attributes = createEthersAttributesResource();
1973
2079
  function saltFor(sender, nonce) {
1974
2080
  return keccak256(
@@ -1987,7 +2093,7 @@ function routeInteropBundle() {
1987
2093
  if (isBaseToken) {
1988
2094
  assetId = ctx.baseTokenAssetId;
1989
2095
  } else {
1990
- assetId = await wrapAs8(
2096
+ assetId = await wrapAs9(
1991
2097
  "CONTRACT",
1992
2098
  OP_WITHDRAWALS.erc20.ensureRegistered,
1993
2099
  async () => {
@@ -2000,7 +2106,7 @@ function routeInteropBundle() {
2000
2106
  }
2001
2107
  );
2002
2108
  const erc20 = new Contract(p.token, IERC20_default, ctx.client.l2);
2003
- const current = await wrapAs8(
2109
+ const current = await wrapAs9(
2004
2110
  "CONTRACT",
2005
2111
  OP_WITHDRAWALS.erc20.allowance,
2006
2112
  () => erc20.allowance(ctx.sender, ctx.l2NativeTokenVault),
@@ -2036,7 +2142,7 @@ function routeInteropBundle() {
2036
2142
  });
2037
2143
  }
2038
2144
  }
2039
- const nonce = await wrapAs8(
2145
+ const nonce = await wrapAs9(
2040
2146
  "RPC",
2041
2147
  OP_WITHDRAWALS.prepare,
2042
2148
  () => ctx.client.l2.getTransactionCount(ctx.sender, "pending"),
@@ -2066,7 +2172,7 @@ function routeInteropBundle() {
2066
2172
  }
2067
2173
  });
2068
2174
  const interopCenter = await ctx.contracts.interopCenter();
2069
- const data = await wrapAs8(
2175
+ const data = await wrapAs9(
2070
2176
  "INTERNAL",
2071
2177
  OP_WITHDRAWALS.erc20.encodeWithdraw,
2072
2178
  () => Promise.resolve(
@@ -2151,7 +2257,7 @@ function createWithdrawalProtocolService(client, override) {
2151
2257
  }
2152
2258
 
2153
2259
  // src/adapters/ethers/resources/withdrawals/services/finalization.ts
2154
- var { wrapAs: wrapAs9 } = createErrorHandlers("withdrawals");
2260
+ var { wrapAs: wrapAs10 } = createErrorHandlers("withdrawals");
2155
2261
  var IL1NullifierMini = [
2156
2262
  "function isWithdrawalFinalized(uint256,uint256,uint256) view returns (bool)"
2157
2263
  ];
@@ -2161,7 +2267,7 @@ function createFinalizationServices(client, protocolService = createWithdrawalPr
2161
2267
  const { l1Nullifier } = await client.ensureAddresses();
2162
2268
  if (protocol === "legacy-withdrawal") return l1Nullifier;
2163
2269
  const nullifier = new Contract(l1Nullifier, IL1NullifierV32_default, l1);
2164
- const handler = await wrapAs9(
2270
+ const handler = await wrapAs10(
2165
2271
  "CONTRACT",
2166
2272
  OP_WITHDRAWALS.finalize.fetchParams.receipt,
2167
2273
  () => nullifier.l1InteropHandler(),
@@ -2173,7 +2279,7 @@ function createFinalizationServices(client, protocolService = createWithdrawalPr
2173
2279
  return handler;
2174
2280
  }
2175
2281
  async function fetchMessageAndProof(l2TxHash) {
2176
- const raw = await wrapAs9(
2282
+ const raw = await wrapAs10(
2177
2283
  "RPC",
2178
2284
  OP_WITHDRAWALS.finalize.fetchParams.receipt,
2179
2285
  () => client.zks.getReceiptWithL2ToL1(l2TxHash),
@@ -2190,7 +2296,7 @@ function createFinalizationServices(client, protocolService = createWithdrawalPr
2190
2296
  context: { l2TxHash }
2191
2297
  });
2192
2298
  }
2193
- const ev = await wrapAs9(
2299
+ const ev = await wrapAs10(
2194
2300
  "INTERNAL",
2195
2301
  OP_WITHDRAWALS.finalize.fetchParams.findMessage,
2196
2302
  // eslint-disable-next-line @typescript-eslint/no-unsafe-argument, @typescript-eslint/no-explicit-any
@@ -2200,7 +2306,7 @@ function createFinalizationServices(client, protocolService = createWithdrawalPr
2200
2306
  message: "Failed to locate L1MessageSent event in L2 receipt."
2201
2307
  }
2202
2308
  );
2203
- const message = await wrapAs9(
2309
+ const message = await wrapAs10(
2204
2310
  "INTERNAL",
2205
2311
  OP_WITHDRAWALS.finalize.fetchParams.decodeMessage,
2206
2312
  () => Promise.resolve(AbiCoder.defaultAbiCoder().decode(["bytes"], ev.data)[0]),
@@ -2209,7 +2315,7 @@ function createFinalizationServices(client, protocolService = createWithdrawalPr
2209
2315
  message: "Failed to decode withdrawal message."
2210
2316
  }
2211
2317
  );
2212
- const idx = await wrapAs9(
2318
+ const idx = await wrapAs10(
2213
2319
  "INTERNAL",
2214
2320
  OP_WITHDRAWALS.finalize.fetchParams.messengerIndex,
2215
2321
  () => Promise.resolve(messengerLogIndex(raw, { index: 0, messenger: L1_MESSENGER_ADDRESS })),
@@ -2218,7 +2324,7 @@ function createFinalizationServices(client, protocolService = createWithdrawalPr
2218
2324
  message: "Failed to derive messenger log index."
2219
2325
  }
2220
2326
  );
2221
- const proof = await wrapAs9(
2327
+ const proof = await wrapAs10(
2222
2328
  "RPC",
2223
2329
  OP_WITHDRAWALS.finalize.fetchParams.proof,
2224
2330
  () => client.zks.getL2ToL1LogProof(l2TxHash, idx),
@@ -2227,7 +2333,7 @@ function createFinalizationServices(client, protocolService = createWithdrawalPr
2227
2333
  message: "Failed to fetch L2\u2192L1 log proof."
2228
2334
  }
2229
2335
  );
2230
- const { chainId } = await wrapAs9(
2336
+ const { chainId } = await wrapAs10(
2231
2337
  "RPC",
2232
2338
  OP_WITHDRAWALS.finalize.fetchParams.network,
2233
2339
  () => l2.getNetwork(),
@@ -2286,7 +2392,7 @@ function createFinalizationServices(client, protocolService = createWithdrawalPr
2286
2392
  const target = await finalizationTarget(finalization.protocol);
2287
2393
  if (finalization.protocol === "legacy-withdrawal") {
2288
2394
  const c = new Contract(target, IL1NullifierMini, l1);
2289
- const done = await wrapAs9(
2395
+ const done = await wrapAs10(
2290
2396
  "RPC",
2291
2397
  OP_WITHDRAWALS.finalize.isFinalized,
2292
2398
  () => c.isWithdrawalFinalized(
@@ -2304,7 +2410,7 @@ function createFinalizationServices(client, protocolService = createWithdrawalPr
2304
2410
  const { bundleHash } = finalization.params;
2305
2411
  const handler = new Contract(target, IInteropHandler_default, l1);
2306
2412
  const status = Number(
2307
- await wrapAs9(
2413
+ await wrapAs10(
2308
2414
  "RPC",
2309
2415
  OP_WITHDRAWALS.finalize.isFinalized,
2310
2416
  () => handler.bundleStatus(bundleHash),
@@ -2316,7 +2422,7 @@ function createFinalizationServices(client, protocolService = createWithdrawalPr
2316
2422
  );
2317
2423
  if (status !== 3 /* Unbundled */) return classifyWithdrawalOutcome(status);
2318
2424
  const callStatus = Number(
2319
- await wrapAs9(
2425
+ await wrapAs10(
2320
2426
  "RPC",
2321
2427
  OP_WITHDRAWALS.finalize.isFinalized,
2322
2428
  () => handler.callStatus(bundleHash, 0),
@@ -2376,7 +2482,7 @@ function createFinalizationServices(client, protocolService = createWithdrawalPr
2376
2482
  async estimateFinalization(finalization) {
2377
2483
  const target = await finalizationTarget(finalization.protocol);
2378
2484
  const l1Signer = client.getL1Signer();
2379
- const gasLimit = await wrapAs9(
2485
+ const gasLimit = await wrapAs10(
2380
2486
  "RPC",
2381
2487
  OP_WITHDRAWALS.finalize.estimate,
2382
2488
  () => {
@@ -2395,7 +2501,7 @@ function createFinalizationServices(client, protocolService = createWithdrawalPr
2395
2501
  message: "Failed to estimate gas for withdrawal finalization."
2396
2502
  }
2397
2503
  );
2398
- const feeData = await wrapAs9("RPC", OP_WITHDRAWALS.finalize.estimate, () => l1.getFeeData(), {
2504
+ const feeData = await wrapAs10("RPC", OP_WITHDRAWALS.finalize.estimate, () => l1.getFeeData(), {
2399
2505
  ctx: { where: "l1.getFeeData" },
2400
2506
  message: "Failed to estimate fee data for withdrawal finalization."
2401
2507
  });