@matterlabs/zksync-js 0.0.22 → 0.0.23

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.
Files changed (49) hide show
  1. package/dist/adapters/ethers/client.cjs +0 -7
  2. package/dist/adapters/ethers/client.cjs.map +1 -1
  3. package/dist/adapters/ethers/client.js +5 -5
  4. package/dist/adapters/ethers/index.cjs +185 -90
  5. package/dist/adapters/ethers/index.cjs.map +1 -1
  6. package/dist/adapters/ethers/index.js +9 -9
  7. package/dist/adapters/ethers/resources/deposits/context.d.ts +2 -0
  8. package/dist/adapters/ethers/resources/deposits/services/gas.d.ts +3 -0
  9. package/dist/adapters/ethers/sdk.cjs +185 -93
  10. package/dist/adapters/ethers/sdk.cjs.map +1 -1
  11. package/dist/adapters/ethers/sdk.js +8 -8
  12. package/dist/adapters/viem/client.cjs +0 -7
  13. package/dist/adapters/viem/client.cjs.map +1 -1
  14. package/dist/adapters/viem/client.js +5 -5
  15. package/dist/adapters/viem/index.cjs +177 -89
  16. package/dist/adapters/viem/index.cjs.map +1 -1
  17. package/dist/adapters/viem/index.js +9 -9
  18. package/dist/adapters/viem/resources/deposits/context.d.ts +2 -0
  19. package/dist/adapters/viem/resources/deposits/services/gas.d.ts +3 -0
  20. package/dist/adapters/viem/sdk.cjs +177 -92
  21. package/dist/adapters/viem/sdk.cjs.map +1 -1
  22. package/dist/adapters/viem/sdk.js +8 -8
  23. package/dist/{chunk-AMRHBZIY.js → chunk-2DDJFHHD.js} +1 -8
  24. package/dist/{chunk-NQRYXL3K.js → chunk-3IPSDGHO.js} +17 -1
  25. package/dist/{chunk-KL6ZCPWJ.js → chunk-4GPIHYVF.js} +1 -1
  26. package/dist/{chunk-2D3FBCZC.js → chunk-4M7VNYGC.js} +2 -2
  27. package/dist/{chunk-JXBLQQEN.js → chunk-6WIAMFIW.js} +3 -3
  28. package/dist/{chunk-QUAPG3ZR.js → chunk-JJ523MOL.js} +2 -2
  29. package/dist/{chunk-4K4LOCQJ.js → chunk-NVOFHV3A.js} +113 -54
  30. package/dist/{chunk-32N6TI6K.js → chunk-OEUDZFXH.js} +1 -1
  31. package/dist/{chunk-CPNHKNI4.js → chunk-TUN6NH5D.js} +2 -2
  32. package/dist/{chunk-PI4PF6WT.js → chunk-URHDNDFN.js} +3 -3
  33. package/dist/{chunk-CP4SQ5PM.js → chunk-V2TDNGI5.js} +121 -55
  34. package/dist/{chunk-3SPDWWRD.js → chunk-WPCZNITC.js} +60 -32
  35. package/dist/{chunk-CUBUD4J4.js → chunk-X2JJDQ4O.js} +1 -1
  36. package/dist/core/adapters/interfaces.d.ts +2 -0
  37. package/dist/core/constants.cjs +16 -0
  38. package/dist/core/constants.cjs.map +1 -1
  39. package/dist/core/constants.d.ts +8 -0
  40. package/dist/core/constants.js +1 -1
  41. package/dist/core/index.cjs +0 -7
  42. package/dist/core/index.cjs.map +1 -1
  43. package/dist/core/index.js +5 -5
  44. package/dist/core/internal/abis/IL2AssetRouter.d.ts +0 -14
  45. package/dist/core/resources/deposits/priority.d.ts +30 -0
  46. package/dist/index.cjs +16 -7
  47. package/dist/index.cjs.map +1 -1
  48. package/dist/index.js +4 -4
  49. package/package.json +1 -1
@@ -1,7 +1,7 @@
1
- export { createEthersClient } from '../../chunk-PI4PF6WT.js';
2
- import '../../chunk-CPNHKNI4.js';
1
+ export { createEthersClient } from '../../chunk-URHDNDFN.js';
2
+ import '../../chunk-TUN6NH5D.js';
3
3
  import '../../chunk-UMPAKZCQ.js';
4
4
  import '../../chunk-BWKWWLY4.js';
5
- import '../../chunk-KL6ZCPWJ.js';
6
- import '../../chunk-AMRHBZIY.js';
7
- import '../../chunk-NQRYXL3K.js';
5
+ import '../../chunk-4GPIHYVF.js';
6
+ import '../../chunk-2DDJFHHD.js';
7
+ import '../../chunk-3IPSDGHO.js';
@@ -58,6 +58,14 @@ var L1_TX_DELTA_FACTORY_DEPS_L2_GAS = 2473n;
58
58
  var L1_TX_DELTA_FACTORY_DEPS_PUBDATA = 64n;
59
59
  var TX_SLOT_OVERHEAD_L2_GAS = 10000n;
60
60
  var PRIORITY_TX_MAX_GAS_LIMIT = 72000000n;
61
+ var L1_TX_INTRINSIC_L2_GAS_ZKSYNC_OS = 21000n;
62
+ var L1_TX_CALLDATA_FLOOR_PRICE_L2_GAS_ZKSYNC_OS = 40n;
63
+ var L1_TX_INTRINSIC_PUBDATA_ZKSYNC_OS = 351n;
64
+ var MAX_NATIVE_COMPUTATIONAL_ZKSYNC_OS = 1n << 35n;
65
+ var L1_TX_NATIVE_PER_GAS = 100000000n;
66
+ var ZKSYNC_OS_PRIORITY_TX_TYPE = "0x7f";
67
+ var REGISTERED_TOKEN_BRIDGE_MINT_EXECUTION_GAS = 140000n;
68
+ var REGISTERED_TOKEN_BRIDGE_MINT_PUBDATA_BYTES = 300n;
61
69
 
62
70
  // src/core/utils/addr.ts
63
71
  function isAddress(x) {
@@ -3902,13 +3910,6 @@ var IL2AssetRouterABI = [
3902
3910
  outputs: [{ name: "", type: "address", internalType: "address" }],
3903
3911
  stateMutability: "view"
3904
3912
  },
3905
- {
3906
- type: "function",
3907
- name: "l1TokenAddress",
3908
- inputs: [{ name: "_l2Token", type: "address", internalType: "address" }],
3909
- outputs: [{ name: "", type: "address", internalType: "address" }],
3910
- stateMutability: "view"
3911
- },
3912
3913
  {
3913
3914
  type: "function",
3914
3915
  name: "l2TokenAddress",
@@ -8296,7 +8297,7 @@ function toGasOverrides(overrides) {
8296
8297
 
8297
8298
  // src/adapters/ethers/resources/deposits/context.ts
8298
8299
  async function commonCtx(p, client, tokens, contracts) {
8299
- const { bridgehub, l1AssetRouter } = await contracts.addresses();
8300
+ const { bridgehub, l1AssetRouter, l1NativeTokenVault } = await contracts.addresses();
8300
8301
  const { chainId } = await client.l2.getNetwork();
8301
8302
  const sender = await client.signer.getAddress();
8302
8303
  const gasPerPubdata = p.gasPerPubdata ?? 800n;
@@ -8324,6 +8325,7 @@ async function commonCtx(p, client, tokens, contracts) {
8324
8325
  baseTokenL1,
8325
8326
  baseIsEth,
8326
8327
  l1AssetRouter,
8328
+ l1NativeTokenVault,
8327
8329
  route,
8328
8330
  bridgehub,
8329
8331
  chainIdL2: BigInt(chainId),
@@ -8561,6 +8563,15 @@ function ethersToGasEstimator(provider) {
8561
8563
  }
8562
8564
  return await provider.estimateGas(ethTx);
8563
8565
  },
8566
+ async estimatePriorityTxGas(tx) {
8567
+ if (!("send" in provider)) {
8568
+ throw new Error('Provider does not support "send"; cannot estimate priority tx gas.');
8569
+ }
8570
+ const result = await provider.send("eth_estimateGas", [
8571
+ { from: tx.from, to: tx.to, data: tx.data, type: ZKSYNC_OS_PRIORITY_TX_TYPE }
8572
+ ]);
8573
+ return BigInt(result);
8574
+ },
8564
8575
  async estimateFeesPerGas() {
8565
8576
  const fd = await provider.getFeeData();
8566
8577
  return {
@@ -8609,9 +8620,79 @@ async function quoteL2BaseCost2(input) {
8609
8620
  );
8610
8621
  }
8611
8622
 
8623
+ // src/core/resources/deposits/priority.ts
8624
+ var PRIORITY_TX_ENCODING_STEP_BYTES = 544n;
8625
+ var L1_TO_L2_ALIAS_OFFSET = 0x1111000000000000000000000000000000001111n;
8626
+ var DEFAULT_PRIORITY_BODY_GAS_ESTIMATE_MULTIPLIER = 7n;
8627
+ var PRIORITY_L2_GAS_BUFFER = 40n;
8628
+ var maxBigInt2 = (a, b) => a > b ? a : b;
8629
+ var ceilDiv = (a, b) => (a + b - 1n) / b;
8630
+ function applyL1ToL2Alias(address) {
8631
+ return `0x${(BigInt(address) + L1_TO_L2_ALIAS_OFFSET & (1n << 160n) - 1n).toString(16).padStart(40, "0")}`;
8632
+ }
8633
+ function derivePriorityTxGasBreakdown(input) {
8634
+ const factoryDepsCount = input.factoryDepsCount ?? 0n;
8635
+ const minBodyGas = maxBigInt2(
8636
+ L1_TX_INTRINSIC_L2_GAS + ceilDiv(
8637
+ input.encodedLength * L1_TX_DELTA_544_ENCODING_BYTES,
8638
+ PRIORITY_TX_ENCODING_STEP_BYTES
8639
+ ) + factoryDepsCount * L1_TX_DELTA_FACTORY_DEPS_L2_GAS,
8640
+ L1_TX_MIN_L2_GAS_BASE
8641
+ ) + L1_TX_INTRINSIC_PUBDATA * input.gasPerPubdata + factoryDepsCount * L1_TX_DELTA_FACTORY_DEPS_PUBDATA * input.gasPerPubdata;
8642
+ const overhead = maxBigInt2(TX_SLOT_OVERHEAD_L2_GAS, TX_MEMORY_OVERHEAD_GAS * input.encodedLength);
8643
+ const derivedBodyGas = minBodyGas;
8644
+ return {
8645
+ encodedLength: input.encodedLength,
8646
+ minBodyGas,
8647
+ overhead,
8648
+ derivedBodyGas,
8649
+ derivedL2GasLimit: derivedBodyGas + overhead,
8650
+ priorityTxMaxGasLimit: PRIORITY_TX_MAX_GAS_LIMIT,
8651
+ priorityTxMaxGasLimitExceeded: derivedBodyGas > PRIORITY_TX_MAX_GAS_LIMIT
8652
+ };
8653
+ }
8654
+ function derivePriorityBodyGasEstimateCap(input) {
8655
+ return input.minBodyGas * (input.multiplier ?? DEFAULT_PRIORITY_BODY_GAS_ESTIMATE_MULTIPLIER);
8656
+ }
8657
+ function applyPriorityL2GasLimitBuffer(input) {
8658
+ return input.gasLimit * (100n + PRIORITY_L2_GAS_BUFFER) / 100n;
8659
+ }
8660
+ function minimalPriorityTxL2Gas(input) {
8661
+ const intrinsic = L1_TX_INTRINSIC_L2_GAS_ZKSYNC_OS + L1_TX_CALLDATA_FLOOR_PRICE_L2_GAS_ZKSYNC_OS * input.calldataLength;
8662
+ const pubdata = L1_TX_INTRINSIC_PUBDATA_ZKSYNC_OS * input.gasPerPubdata + ceilDiv(MAX_NATIVE_COMPUTATIONAL_ZKSYNC_OS, L1_TX_NATIVE_PER_GAS);
8663
+ return maxBigInt2(intrinsic, pubdata);
8664
+ }
8665
+ function clampPriorityL2GasLimit(input) {
8666
+ return maxBigInt2(
8667
+ input.gasLimit,
8668
+ minimalPriorityTxL2Gas({
8669
+ calldataLength: BigInt(Math.max(input.l2Calldata.length - 2, 0) / 2),
8670
+ gasPerPubdata: input.gasPerPubdata
8671
+ })
8672
+ );
8673
+ }
8674
+ function resolveRegisteredTokenPriorityL2GasLimit(input) {
8675
+ if (input.nodeEstimate != null && input.nodeEstimate > 0n) {
8676
+ return maxBigInt2(input.priorityFloorGasLimit, applyGasBuffer(input.nodeEstimate));
8677
+ }
8678
+ const modeledGas = REGISTERED_TOKEN_BRIDGE_MINT_EXECUTION_GAS + REGISTERED_TOKEN_BRIDGE_MINT_PUBDATA_BYTES * input.gasPerPubdata;
8679
+ return maxBigInt2(
8680
+ input.priorityFloorGasLimit,
8681
+ applyPriorityL2GasLimitBuffer({ gasLimit: modeledGas })
8682
+ );
8683
+ }
8684
+
8612
8685
  // src/adapters/ethers/resources/deposits/services/gas.ts
8613
8686
  var DEFAULT_SAFE_NONBASE_L2_GAS_LIMIT = 3000000n;
8614
8687
  var ZERO_L2_TOKEN_ADDRESS = "0x0000000000000000000000000000000000000000";
8688
+ async function estimatePriorityTxL2Gas(ctx, leg) {
8689
+ if (!leg) return void 0;
8690
+ try {
8691
+ return await ethersToGasEstimator(ctx.client.l2).estimatePriorityTxGas?.(leg);
8692
+ } catch {
8693
+ return void 0;
8694
+ }
8695
+ }
8615
8696
  async function quoteL1Gas2(input) {
8616
8697
  const { ctx, tx, overrides, fallbackGasLimit } = input;
8617
8698
  const estimator = ethersToGasEstimator(ctx.client.l1);
@@ -8665,7 +8746,12 @@ async function determineNonBaseL2Gas(input) {
8665
8746
  return quoteL2Gas2({
8666
8747
  ctx,
8667
8748
  route,
8668
- overrideGasLimit: input.priorityFloorGasLimit
8749
+ overrideGasLimit: resolveRegisteredTokenPriorityL2GasLimit({
8750
+ chainIdL2: ctx.chainIdL2,
8751
+ priorityFloorGasLimit: input.priorityFloorGasLimit,
8752
+ gasPerPubdata: ctx.gasPerPubdata,
8753
+ nodeEstimate: await estimatePriorityTxL2Gas(ctx, input.priorityTxL2Leg)
8754
+ })
8669
8755
  });
8670
8756
  }
8671
8757
  const modelTx = {
@@ -8702,6 +8788,7 @@ async function determineEthNonBaseL2Gas(input) {
8702
8788
  knownL2Token: input.ctx.resolvedToken?.l2,
8703
8789
  modelTx: input.modelTx,
8704
8790
  priorityFloorGasLimit: input.priorityFloorGasLimit,
8791
+ priorityTxL2Leg: input.priorityTxL2Leg,
8705
8792
  undeployedGasLimit: input.undeployedGasLimit
8706
8793
  });
8707
8794
  }
@@ -8733,40 +8820,6 @@ function buildFeeBreakdown(p) {
8733
8820
  l2
8734
8821
  };
8735
8822
  }
8736
-
8737
- // src/core/resources/deposits/priority.ts
8738
- var PRIORITY_TX_ENCODING_STEP_BYTES = 544n;
8739
- var DEFAULT_PRIORITY_BODY_GAS_ESTIMATE_MULTIPLIER = 7n;
8740
- var PRIORITY_L2_GAS_BUFFER = 40n;
8741
- var maxBigInt2 = (a, b) => a > b ? a : b;
8742
- var ceilDiv = (a, b) => (a + b - 1n) / b;
8743
- function derivePriorityTxGasBreakdown(input) {
8744
- const factoryDepsCount = input.factoryDepsCount ?? 0n;
8745
- const minBodyGas = maxBigInt2(
8746
- L1_TX_INTRINSIC_L2_GAS + ceilDiv(
8747
- input.encodedLength * L1_TX_DELTA_544_ENCODING_BYTES,
8748
- PRIORITY_TX_ENCODING_STEP_BYTES
8749
- ) + factoryDepsCount * L1_TX_DELTA_FACTORY_DEPS_L2_GAS,
8750
- L1_TX_MIN_L2_GAS_BASE
8751
- ) + L1_TX_INTRINSIC_PUBDATA * input.gasPerPubdata + factoryDepsCount * L1_TX_DELTA_FACTORY_DEPS_PUBDATA * input.gasPerPubdata;
8752
- const overhead = maxBigInt2(TX_SLOT_OVERHEAD_L2_GAS, TX_MEMORY_OVERHEAD_GAS * input.encodedLength);
8753
- const derivedBodyGas = minBodyGas;
8754
- return {
8755
- encodedLength: input.encodedLength,
8756
- minBodyGas,
8757
- overhead,
8758
- derivedBodyGas,
8759
- derivedL2GasLimit: derivedBodyGas + overhead,
8760
- priorityTxMaxGasLimit: PRIORITY_TX_MAX_GAS_LIMIT,
8761
- priorityTxMaxGasLimitExceeded: derivedBodyGas > PRIORITY_TX_MAX_GAS_LIMIT
8762
- };
8763
- }
8764
- function derivePriorityBodyGasEstimateCap(input) {
8765
- return input.minBodyGas * (input.multiplier ?? DEFAULT_PRIORITY_BODY_GAS_ESTIMATE_MULTIPLIER);
8766
- }
8767
- function applyPriorityL2GasLimitBuffer(input) {
8768
- return input.gasLimit * (100n + PRIORITY_L2_GAS_BUFFER) / 100n;
8769
- }
8770
8823
  var EMPTY_BYTES = "0x";
8771
8824
  var ZERO_RESERVED_WORDS = [0n, 0n, 0n, 0n];
8772
8825
  var L2_CANONICAL_TRANSACTION_TUPLE = "tuple(uint256 txType,uint256 from,uint256 to,uint256 gasLimit,uint256 gasPerPubdataByteLimit,uint256 maxFeePerGas,uint256 maxPriorityFeePerGas,uint256 paymaster,uint256 nonce,uint256 value,uint256[4] reserved,bytes data,bytes signature,uint256[] factoryDeps,bytes paymasterInput,bytes reservedDynamic)";
@@ -8823,9 +8876,13 @@ function routeEthDirect() {
8823
8876
  l2Calldata,
8824
8877
  gasPerPubdata: ctx.gasPerPubdata
8825
8878
  });
8826
- const quotedL2GasLimit = ctx.l2GasLimit ?? applyPriorityL2GasLimitBuffer({
8827
- chainIdL2: ctx.chainIdL2,
8828
- gasLimit: priorityFloorBreakdown.derivedL2GasLimit
8879
+ const quotedL2GasLimit = ctx.l2GasLimit ?? clampPriorityL2GasLimit({
8880
+ gasLimit: applyPriorityL2GasLimitBuffer({
8881
+ chainIdL2: ctx.chainIdL2,
8882
+ gasLimit: priorityFloorBreakdown.derivedL2GasLimit
8883
+ }),
8884
+ l2Calldata,
8885
+ gasPerPubdata: ctx.gasPerPubdata
8829
8886
  });
8830
8887
  const l2GasParams = await quoteL2Gas2({
8831
8888
  ctx,
@@ -8912,26 +8969,18 @@ var ntvCodec = createNTVCodec({
8912
8969
  keccak256: (data) => ethers.keccak256(data)
8913
8970
  });
8914
8971
  async function encodeSecondBridgeErc20DepositCalldata(input) {
8915
- if (!input.ctx.resolvedToken) {
8916
- return encodeSecondBridgeErc20Args(input.token, input.amount, input.receiver);
8917
- }
8918
- const { chainId } = await input.ctx.client.l1.getNetwork();
8919
- const expectedL1AssetId = ntvCodec.encodeAssetId(
8920
- BigInt(chainId),
8972
+ const registeredAssetId = input.ctx.resolvedToken?.assetId;
8973
+ const assetId = registeredAssetId && registeredAssetId.toLowerCase() !== ZERO_ASSET_ID ? registeredAssetId : ntvCodec.encodeAssetId(
8974
+ BigInt((await input.ctx.client.l1.getNetwork()).chainId),
8921
8975
  L2_NATIVE_TOKEN_VAULT_ADDRESS,
8922
8976
  input.token
8923
8977
  );
8924
- const assetId = input.ctx.resolvedToken.assetId.toLowerCase();
8925
- const isL1Origin = assetId === ZERO_ASSET_ID || assetId === expectedL1AssetId.toLowerCase();
8926
- if (isL1Origin) {
8927
- return encodeSecondBridgeErc20Args(input.token, input.amount, input.receiver);
8928
- }
8929
8978
  const transferData = encodeNativeTokenVaultTransferData(
8930
8979
  input.amount,
8931
8980
  input.receiver,
8932
8981
  input.token
8933
8982
  );
8934
- return encodeSecondBridgeDataV1(input.ctx.resolvedToken.assetId, transferData);
8983
+ return encodeSecondBridgeDataV1(assetId, transferData);
8935
8984
  }
8936
8985
  async function getPriorityGasModel(input) {
8937
8986
  try {
@@ -8966,9 +9015,18 @@ async function getPriorityGasModel(input) {
8966
9015
  gasPerPubdata: input.ctx.gasPerPubdata
8967
9016
  });
8968
9017
  const model = {
8969
- priorityFloorGasLimit: applyPriorityL2GasLimitBuffer({
8970
- chainIdL2: input.ctx.chainIdL2,
8971
- gasLimit: priorityFloorBreakdown.derivedL2GasLimit
9018
+ priorityTxL2Leg: {
9019
+ from: applyL1ToL2Alias(input.ctx.l1AssetRouter),
9020
+ to: L2_ASSET_ROUTER_ADDRESS,
9021
+ data: l2Calldata
9022
+ },
9023
+ priorityFloorGasLimit: clampPriorityL2GasLimit({
9024
+ gasLimit: applyPriorityL2GasLimitBuffer({
9025
+ chainIdL2: input.ctx.chainIdL2,
9026
+ gasLimit: priorityFloorBreakdown.derivedL2GasLimit
9027
+ }),
9028
+ l2Calldata,
9029
+ gasPerPubdata: input.ctx.gasPerPubdata
8972
9030
  })
8973
9031
  };
8974
9032
  if (isFirstBridge || input.ctx.resolvedToken.l2.toLowerCase() === ZERO_L2_TOKEN_ADDRESS2) {
@@ -9026,6 +9084,7 @@ function routeErc20NonBase() {
9026
9084
  ctx,
9027
9085
  l1Token: p.token,
9028
9086
  priorityFloorGasLimit: priorityGasModel.priorityFloorGasLimit,
9087
+ priorityTxL2Leg: priorityGasModel.priorityTxL2Leg,
9029
9088
  undeployedGasLimit: priorityGasModel.undeployedGasLimit,
9030
9089
  modelTx: {
9031
9090
  to: receiver,
@@ -9040,25 +9099,29 @@ function routeErc20NonBase() {
9040
9099
  const approvals = [];
9041
9100
  const steps = [];
9042
9101
  const assetRouter = ctx.l1AssetRouter;
9102
+ const nativeTokenVault = ctx.l1NativeTokenVault;
9043
9103
  const erc20Deposit = new ethers.Contract(p.token, IERC20_default, l1Signer);
9044
9104
  const allowanceToken = await wrapAs3(
9045
9105
  "RPC",
9046
9106
  OP_DEPOSITS.nonbase.allowanceToken,
9047
- () => erc20Deposit.allowance(ctx.sender, assetRouter),
9107
+ () => erc20Deposit.allowance(ctx.sender, nativeTokenVault),
9048
9108
  {
9049
- ctx: { where: "erc20.allowance", token: p.token, spender: assetRouter },
9109
+ ctx: { where: "erc20.allowance", token: p.token, spender: nativeTokenVault },
9050
9110
  message: "Failed to read deposit-token allowance."
9051
9111
  }
9052
9112
  );
9053
9113
  if (allowanceToken < p.amount) {
9054
- approvals.push({ token: p.token, spender: assetRouter, amount: p.amount });
9114
+ approvals.push({ token: p.token, spender: nativeTokenVault, amount: p.amount });
9055
9115
  steps.push({
9056
- key: `approve:${p.token}:${assetRouter}`,
9116
+ key: `approve:${p.token}:${nativeTokenVault}`,
9057
9117
  kind: "approve",
9058
- description: `Approve ${p.amount} for router (deposit token)`,
9118
+ description: `Approve ${p.amount} for the native token vault (deposit token)`,
9059
9119
  tx: {
9060
9120
  to: p.token,
9061
- data: erc20Deposit.interface.encodeFunctionData("approve", [assetRouter, p.amount]),
9121
+ data: erc20Deposit.interface.encodeFunctionData("approve", [
9122
+ nativeTokenVault,
9123
+ p.amount
9124
+ ]),
9062
9125
  from: ctx.sender,
9063
9126
  ...ctx.gasOverrides
9064
9127
  }
@@ -9069,21 +9132,24 @@ function routeErc20NonBase() {
9069
9132
  const allowanceBase = await wrapAs3(
9070
9133
  "RPC",
9071
9134
  OP_DEPOSITS.nonbase.allowanceBase,
9072
- () => erc20Base.allowance(ctx.sender, assetRouter),
9135
+ () => erc20Base.allowance(ctx.sender, nativeTokenVault),
9073
9136
  {
9074
- ctx: { where: "erc20.allowance", token: baseToken, spender: assetRouter },
9137
+ ctx: { where: "erc20.allowance", token: baseToken, spender: nativeTokenVault },
9075
9138
  message: "Failed to read base-token allowance."
9076
9139
  }
9077
9140
  );
9078
9141
  if (allowanceBase < mintValue) {
9079
- approvals.push({ token: baseToken, spender: assetRouter, amount: mintValue });
9142
+ approvals.push({ token: baseToken, spender: nativeTokenVault, amount: mintValue });
9080
9143
  steps.push({
9081
- key: `approve:${baseToken}:${assetRouter}`,
9144
+ key: `approve:${baseToken}:${nativeTokenVault}`,
9082
9145
  kind: "approve",
9083
9146
  description: `Approve base token for mintValue`,
9084
9147
  tx: {
9085
9148
  to: baseToken,
9086
- data: erc20Base.interface.encodeFunctionData("approve", [assetRouter, mintValue]),
9149
+ data: erc20Base.interface.encodeFunctionData("approve", [
9150
+ nativeTokenVault,
9151
+ mintValue
9152
+ ]),
9087
9153
  from: ctx.sender,
9088
9154
  ...ctx.gasOverrides
9089
9155
  }
@@ -9180,9 +9246,18 @@ async function getPriorityGasModel2(input) {
9180
9246
  gasPerPubdata: input.ctx.gasPerPubdata
9181
9247
  });
9182
9248
  const model = {
9183
- priorityFloorGasLimit: applyPriorityL2GasLimitBuffer({
9184
- chainIdL2: input.ctx.chainIdL2,
9185
- gasLimit: priorityFloorBreakdown.derivedL2GasLimit
9249
+ priorityTxL2Leg: {
9250
+ from: applyL1ToL2Alias(input.ctx.l1AssetRouter),
9251
+ to: L2_ASSET_ROUTER_ADDRESS,
9252
+ data: l2Calldata
9253
+ },
9254
+ priorityFloorGasLimit: clampPriorityL2GasLimit({
9255
+ gasLimit: applyPriorityL2GasLimitBuffer({
9256
+ chainIdL2: input.ctx.chainIdL2,
9257
+ gasLimit: priorityFloorBreakdown.derivedL2GasLimit
9258
+ }),
9259
+ l2Calldata,
9260
+ gasPerPubdata: input.ctx.gasPerPubdata
9186
9261
  })
9187
9262
  };
9188
9263
  if (input.ctx.resolvedToken.l2.toLowerCase() === ZERO_L2_TOKEN_ADDRESS3) {
@@ -9259,6 +9334,7 @@ function routeEthNonBase() {
9259
9334
  ctx,
9260
9335
  modelTx: l2TxModel,
9261
9336
  priorityFloorGasLimit: priorityGasModel.priorityFloorGasLimit,
9337
+ priorityTxL2Leg: priorityGasModel.priorityTxL2Leg,
9262
9338
  undeployedGasLimit: priorityGasModel.undeployedGasLimit
9263
9339
  });
9264
9340
  if (!l2GasParams) throw new Error("Failed to estimate L2 gas parameters.");
@@ -9270,21 +9346,24 @@ function routeEthNonBase() {
9270
9346
  const allowance = await wrapAs4(
9271
9347
  "RPC",
9272
9348
  OP_DEPOSITS.ethNonBase.allowanceBase,
9273
- () => erc20Base.allowance(ctx.sender, ctx.l1AssetRouter),
9349
+ () => erc20Base.allowance(ctx.sender, ctx.l1NativeTokenVault),
9274
9350
  {
9275
- ctx: { where: "erc20.allowance", token: baseToken, spender: ctx.l1AssetRouter },
9351
+ ctx: { where: "erc20.allowance", token: baseToken, spender: ctx.l1NativeTokenVault },
9276
9352
  message: "Failed to read base-token allowance."
9277
9353
  }
9278
9354
  );
9279
9355
  if (allowance < mintValue) {
9280
- approvals.push({ token: baseToken, spender: ctx.l1AssetRouter, amount: mintValue });
9356
+ approvals.push({ token: baseToken, spender: ctx.l1NativeTokenVault, amount: mintValue });
9281
9357
  steps.push({
9282
- key: `approve:${baseToken}:${ctx.l1AssetRouter}`,
9358
+ key: `approve:${baseToken}:${ctx.l1NativeTokenVault}`,
9283
9359
  kind: "approve",
9284
9360
  description: `Approve base token for fees (mintValue)`,
9285
9361
  tx: {
9286
9362
  to: baseToken,
9287
- data: erc20Base.interface.encodeFunctionData("approve", [ctx.l1AssetRouter, mintValue]),
9363
+ data: erc20Base.interface.encodeFunctionData("approve", [
9364
+ ctx.l1NativeTokenVault,
9365
+ mintValue
9366
+ ]),
9288
9367
  from: ctx.sender,
9289
9368
  ...ctx.gasOverrides
9290
9369
  }
@@ -9400,9 +9479,13 @@ function routeErc20Base() {
9400
9479
  l2Calldata,
9401
9480
  gasPerPubdata: ctx.gasPerPubdata
9402
9481
  });
9403
- const quotedL2GasLimit = ctx.l2GasLimit ?? applyPriorityL2GasLimitBuffer({
9404
- chainIdL2: ctx.chainIdL2,
9405
- gasLimit: priorityFloorBreakdown.derivedL2GasLimit
9482
+ const quotedL2GasLimit = ctx.l2GasLimit ?? clampPriorityL2GasLimit({
9483
+ gasLimit: applyPriorityL2GasLimitBuffer({
9484
+ chainIdL2: ctx.chainIdL2,
9485
+ gasLimit: priorityFloorBreakdown.derivedL2GasLimit
9486
+ }),
9487
+ l2Calldata,
9488
+ gasPerPubdata: ctx.gasPerPubdata
9406
9489
  });
9407
9490
  const l2GasParams = await quoteL2Gas2({
9408
9491
  ctx,
@@ -9419,21 +9502,24 @@ function routeErc20Base() {
9419
9502
  const allowance = await wrapAs5(
9420
9503
  "RPC",
9421
9504
  OP_DEPOSITS.base.allowance,
9422
- () => erc20.allowance(ctx.sender, ctx.l1AssetRouter),
9505
+ () => erc20.allowance(ctx.sender, ctx.l1NativeTokenVault),
9423
9506
  {
9424
- ctx: { where: "erc20.allowance", token: baseToken, spender: ctx.l1AssetRouter },
9507
+ ctx: { where: "erc20.allowance", token: baseToken, spender: ctx.l1NativeTokenVault },
9425
9508
  message: "Failed to read base-token allowance."
9426
9509
  }
9427
9510
  );
9428
9511
  if (allowance < mintValue) {
9429
- approvals.push({ token: baseToken, spender: ctx.l1AssetRouter, amount: mintValue });
9512
+ approvals.push({ token: baseToken, spender: ctx.l1NativeTokenVault, amount: mintValue });
9430
9513
  steps.push({
9431
- key: `approve:${baseToken}:${ctx.l1AssetRouter}`,
9514
+ key: `approve:${baseToken}:${ctx.l1NativeTokenVault}`,
9432
9515
  kind: "approve",
9433
9516
  description: "Approve base token for mintValue",
9434
9517
  tx: {
9435
9518
  to: baseToken,
9436
- data: erc20.interface.encodeFunctionData("approve", [ctx.l1AssetRouter, mintValue]),
9519
+ data: erc20.interface.encodeFunctionData("approve", [
9520
+ ctx.l1NativeTokenVault,
9521
+ mintValue
9522
+ ]),
9437
9523
  from: ctx.sender,
9438
9524
  ...ctx.gasOverrides
9439
9525
  }
@@ -9567,8 +9653,17 @@ function createTokensResource(client) {
9567
9653
  const { chainId } = await client.l2.getNetwork();
9568
9654
  return await client.baseToken(BigInt(chainId));
9569
9655
  }
9570
- const { l2AssetRouter } = await client.contracts();
9571
- const l1Token = await l2AssetRouter.l1TokenAddress(l2Token);
9656
+ const { l2NativeTokenVault, l1NativeTokenVault } = await client.contracts();
9657
+ const assetId = await l2NativeTokenVault.assetId(l2Token);
9658
+ if (BigInt(assetId) === 0n) {
9659
+ throw new Error(`Token ${l2Token} is not registered in the L2 NativeTokenVault.`);
9660
+ }
9661
+ const l1Token = await l1NativeTokenVault.tokenAddress(assetId);
9662
+ if (BigInt(l1Token) === 0n) {
9663
+ throw new Error(
9664
+ `Token ${l2Token} has no L1 counterpart registered in the L1 NativeTokenVault.`
9665
+ );
9666
+ }
9572
9667
  return l1Token;
9573
9668
  });
9574
9669
  }