@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.
- package/dist/adapters/ethers/client.cjs +0 -7
- package/dist/adapters/ethers/client.cjs.map +1 -1
- package/dist/adapters/ethers/client.js +5 -5
- package/dist/adapters/ethers/index.cjs +185 -90
- package/dist/adapters/ethers/index.cjs.map +1 -1
- package/dist/adapters/ethers/index.js +9 -9
- package/dist/adapters/ethers/resources/deposits/context.d.ts +2 -0
- package/dist/adapters/ethers/resources/deposits/services/gas.d.ts +3 -0
- package/dist/adapters/ethers/sdk.cjs +185 -93
- package/dist/adapters/ethers/sdk.cjs.map +1 -1
- package/dist/adapters/ethers/sdk.js +8 -8
- package/dist/adapters/viem/client.cjs +0 -7
- package/dist/adapters/viem/client.cjs.map +1 -1
- package/dist/adapters/viem/client.js +5 -5
- package/dist/adapters/viem/index.cjs +177 -89
- package/dist/adapters/viem/index.cjs.map +1 -1
- package/dist/adapters/viem/index.js +9 -9
- package/dist/adapters/viem/resources/deposits/context.d.ts +2 -0
- package/dist/adapters/viem/resources/deposits/services/gas.d.ts +3 -0
- package/dist/adapters/viem/sdk.cjs +177 -92
- package/dist/adapters/viem/sdk.cjs.map +1 -1
- package/dist/adapters/viem/sdk.js +8 -8
- package/dist/{chunk-AMRHBZIY.js → chunk-2DDJFHHD.js} +1 -8
- package/dist/{chunk-NQRYXL3K.js → chunk-3IPSDGHO.js} +17 -1
- package/dist/{chunk-KL6ZCPWJ.js → chunk-4GPIHYVF.js} +1 -1
- package/dist/{chunk-2D3FBCZC.js → chunk-4M7VNYGC.js} +2 -2
- package/dist/{chunk-JXBLQQEN.js → chunk-6WIAMFIW.js} +3 -3
- package/dist/{chunk-QUAPG3ZR.js → chunk-JJ523MOL.js} +2 -2
- package/dist/{chunk-4K4LOCQJ.js → chunk-NVOFHV3A.js} +113 -54
- package/dist/{chunk-32N6TI6K.js → chunk-OEUDZFXH.js} +1 -1
- package/dist/{chunk-CPNHKNI4.js → chunk-TUN6NH5D.js} +2 -2
- package/dist/{chunk-PI4PF6WT.js → chunk-URHDNDFN.js} +3 -3
- package/dist/{chunk-CP4SQ5PM.js → chunk-V2TDNGI5.js} +121 -55
- package/dist/{chunk-3SPDWWRD.js → chunk-WPCZNITC.js} +60 -32
- package/dist/{chunk-CUBUD4J4.js → chunk-X2JJDQ4O.js} +1 -1
- package/dist/core/adapters/interfaces.d.ts +2 -0
- package/dist/core/constants.cjs +16 -0
- package/dist/core/constants.cjs.map +1 -1
- package/dist/core/constants.d.ts +8 -0
- package/dist/core/constants.js +1 -1
- package/dist/core/index.cjs +0 -7
- package/dist/core/index.cjs.map +1 -1
- package/dist/core/index.js +5 -5
- package/dist/core/internal/abis/IL2AssetRouter.d.ts +0 -14
- package/dist/core/resources/deposits/priority.d.ts +30 -0
- package/dist/index.cjs +16 -7
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +4 -4
- package/package.json +1 -1
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
export { buildDirectRequestStruct, createContractsResource, createDepositsResource, createFinalizationServices, createInteropFinalizationServices, createInteropResource, createTokensResource, createViemSdk, createWithdrawalProtocolService, createWithdrawalsResource, encodeNativeTokenVaultTransferData, encodeSecondBridgeArgs, encodeSecondBridgeDataV1, encodeSecondBridgeErc20Args, encodeSecondBridgeEthArgs, getL2TransactionHashFromLogs } from '../../chunk-
|
|
2
|
-
import '../../chunk-
|
|
3
|
-
import '../../chunk-
|
|
4
|
-
import '../../chunk-
|
|
5
|
-
export { createViemClient as createClient, createViemClient } from '../../chunk-
|
|
6
|
-
export { classifyReadinessFromRevert, createErrorHandlers, decodeRevert, registerErrorAbi, toZKsyncError } from '../../chunk-
|
|
1
|
+
export { buildDirectRequestStruct, createContractsResource, createDepositsResource, createFinalizationServices, createInteropFinalizationServices, createInteropResource, createTokensResource, createViemSdk, createWithdrawalProtocolService, createWithdrawalsResource, encodeNativeTokenVaultTransferData, encodeSecondBridgeArgs, encodeSecondBridgeDataV1, encodeSecondBridgeErc20Args, encodeSecondBridgeEthArgs, getL2TransactionHashFromLogs } from '../../chunk-NVOFHV3A.js';
|
|
2
|
+
import '../../chunk-WPCZNITC.js';
|
|
3
|
+
import '../../chunk-JJ523MOL.js';
|
|
4
|
+
import '../../chunk-OEUDZFXH.js';
|
|
5
|
+
export { createViemClient as createClient, createViemClient } from '../../chunk-6WIAMFIW.js';
|
|
6
|
+
export { classifyReadinessFromRevert, createErrorHandlers, decodeRevert, registerErrorAbi, toZKsyncError } from '../../chunk-4M7VNYGC.js';
|
|
7
7
|
import '../../chunk-UMPAKZCQ.js';
|
|
8
8
|
import '../../chunk-BWKWWLY4.js';
|
|
9
|
-
import '../../chunk-
|
|
10
|
-
import '../../chunk-
|
|
11
|
-
import '../../chunk-
|
|
9
|
+
import '../../chunk-4GPIHYVF.js';
|
|
10
|
+
import '../../chunk-2DDJFHHD.js';
|
|
11
|
+
import '../../chunk-3IPSDGHO.js';
|
|
@@ -14,6 +14,7 @@ export interface BuildCtx extends CommonCtx {
|
|
|
14
14
|
baseTokenL1: Address;
|
|
15
15
|
baseIsEth: boolean;
|
|
16
16
|
l1AssetRouter: Address;
|
|
17
|
+
l1NativeTokenVault: Address;
|
|
17
18
|
gasOverrides?: TxGasOverrides;
|
|
18
19
|
l2GasLimit?: bigint;
|
|
19
20
|
gasPerPubdata: bigint;
|
|
@@ -29,6 +30,7 @@ export declare function commonCtx(p: DepositParams, client: ViemClient, tokens:
|
|
|
29
30
|
baseTokenL1: `0x${string}`;
|
|
30
31
|
baseIsEth: boolean;
|
|
31
32
|
l1AssetRouter: `0x${string}`;
|
|
33
|
+
l1NativeTokenVault: `0x${string}`;
|
|
32
34
|
route: DepositRoute;
|
|
33
35
|
bridgehub: `0x${string}`;
|
|
34
36
|
chainIdL2: bigint;
|
|
@@ -4,6 +4,7 @@ import type { DepositRoute } from '../../../../../core/types/flows/deposits';
|
|
|
4
4
|
import type { TxGasOverrides } from '../../../../../core/types/fees';
|
|
5
5
|
import type { Address } from '../../../../../core/types/primitives';
|
|
6
6
|
import { type GasQuote } from '../../../../../core/resources/deposits/gas';
|
|
7
|
+
import { type PriorityTxL2Leg } from '../../../../../core/resources/deposits/priority.ts';
|
|
7
8
|
export type { GasQuote };
|
|
8
9
|
export type QuoteL1GasInput = {
|
|
9
10
|
ctx: BuildCtx;
|
|
@@ -31,11 +32,13 @@ export declare function determineErc20L2Gas(input: {
|
|
|
31
32
|
l1Token: Address;
|
|
32
33
|
modelTx?: TransactionRequest;
|
|
33
34
|
priorityFloorGasLimit?: bigint;
|
|
35
|
+
priorityTxL2Leg?: PriorityTxL2Leg;
|
|
34
36
|
undeployedGasLimit?: bigint;
|
|
35
37
|
}): Promise<GasQuote | undefined>;
|
|
36
38
|
export declare function determineEthNonBaseL2Gas(input: {
|
|
37
39
|
ctx: BuildCtx;
|
|
38
40
|
modelTx?: TransactionRequest;
|
|
39
41
|
priorityFloorGasLimit?: bigint;
|
|
42
|
+
priorityTxL2Leg?: PriorityTxL2Leg;
|
|
40
43
|
undeployedGasLimit?: bigint;
|
|
41
44
|
}): Promise<GasQuote | undefined>;
|
|
@@ -2189,13 +2189,6 @@ var IL2AssetRouterABI = [
|
|
|
2189
2189
|
outputs: [{ name: "", type: "address", internalType: "address" }],
|
|
2190
2190
|
stateMutability: "view"
|
|
2191
2191
|
},
|
|
2192
|
-
{
|
|
2193
|
-
type: "function",
|
|
2194
|
-
name: "l1TokenAddress",
|
|
2195
|
-
inputs: [{ name: "_l2Token", type: "address", internalType: "address" }],
|
|
2196
|
-
outputs: [{ name: "", type: "address", internalType: "address" }],
|
|
2197
|
-
stateMutability: "view"
|
|
2198
|
-
},
|
|
2199
2192
|
{
|
|
2200
2193
|
type: "function",
|
|
2201
2194
|
name: "l2TokenAddress",
|
|
@@ -5746,7 +5739,7 @@ function toGasOverrides(overrides) {
|
|
|
5746
5739
|
|
|
5747
5740
|
// src/adapters/viem/resources/deposits/context.ts
|
|
5748
5741
|
async function commonCtx(p, client, tokens, contracts) {
|
|
5749
|
-
const { bridgehub, l1AssetRouter } = await contracts.addresses();
|
|
5742
|
+
const { bridgehub, l1AssetRouter, l1NativeTokenVault } = await contracts.addresses();
|
|
5750
5743
|
const chainId = await client.l2.getChainId();
|
|
5751
5744
|
const sender = client.account.address;
|
|
5752
5745
|
const gasPerPubdata = p.gasPerPubdata ?? 800n;
|
|
@@ -5774,6 +5767,7 @@ async function commonCtx(p, client, tokens, contracts) {
|
|
|
5774
5767
|
baseTokenL1,
|
|
5775
5768
|
baseIsEth,
|
|
5776
5769
|
l1AssetRouter,
|
|
5770
|
+
l1NativeTokenVault,
|
|
5777
5771
|
route,
|
|
5778
5772
|
bridgehub,
|
|
5779
5773
|
chainIdL2: BigInt(chainId),
|
|
@@ -5814,6 +5808,14 @@ var L1_TX_DELTA_FACTORY_DEPS_L2_GAS = 2473n;
|
|
|
5814
5808
|
var L1_TX_DELTA_FACTORY_DEPS_PUBDATA = 64n;
|
|
5815
5809
|
var TX_SLOT_OVERHEAD_L2_GAS = 10000n;
|
|
5816
5810
|
var PRIORITY_TX_MAX_GAS_LIMIT = 72000000n;
|
|
5811
|
+
var L1_TX_INTRINSIC_L2_GAS_ZKSYNC_OS = 21000n;
|
|
5812
|
+
var L1_TX_CALLDATA_FLOOR_PRICE_L2_GAS_ZKSYNC_OS = 40n;
|
|
5813
|
+
var L1_TX_INTRINSIC_PUBDATA_ZKSYNC_OS = 351n;
|
|
5814
|
+
var MAX_NATIVE_COMPUTATIONAL_ZKSYNC_OS = 1n << 35n;
|
|
5815
|
+
var L1_TX_NATIVE_PER_GAS = 100000000n;
|
|
5816
|
+
var ZKSYNC_OS_PRIORITY_TX_TYPE = "0x7f";
|
|
5817
|
+
var REGISTERED_TOKEN_BRIDGE_MINT_EXECUTION_GAS = 140000n;
|
|
5818
|
+
var REGISTERED_TOKEN_BRIDGE_MINT_PUBDATA_BYTES = 300n;
|
|
5817
5819
|
|
|
5818
5820
|
// src/adapters/viem/resources/utils.ts
|
|
5819
5821
|
function encodeNativeTokenVaultTransferData(amount, receiver, token) {
|
|
@@ -5846,9 +5848,6 @@ function encodeSecondBridgeArgs(token, amount, l2Receiver) {
|
|
|
5846
5848
|
[token, amount, l2Receiver]
|
|
5847
5849
|
);
|
|
5848
5850
|
}
|
|
5849
|
-
function encodeSecondBridgeErc20Args(token, amount, l2Receiver) {
|
|
5850
|
-
return encodeSecondBridgeArgs(token, amount, l2Receiver);
|
|
5851
|
-
}
|
|
5852
5851
|
function encodeSecondBridgeEthArgs(amount, l2Receiver, ethToken = ETH_ADDRESS) {
|
|
5853
5852
|
return encodeSecondBridgeArgs(ethToken, amount, l2Receiver);
|
|
5854
5853
|
}
|
|
@@ -6604,6 +6603,68 @@ async function quoteL2Gas(input) {
|
|
|
6604
6603
|
}
|
|
6605
6604
|
}
|
|
6606
6605
|
|
|
6606
|
+
// src/core/resources/deposits/priority.ts
|
|
6607
|
+
var PRIORITY_TX_ENCODING_STEP_BYTES = 544n;
|
|
6608
|
+
var L1_TO_L2_ALIAS_OFFSET = 0x1111000000000000000000000000000000001111n;
|
|
6609
|
+
var DEFAULT_PRIORITY_BODY_GAS_ESTIMATE_MULTIPLIER = 7n;
|
|
6610
|
+
var PRIORITY_L2_GAS_BUFFER = 40n;
|
|
6611
|
+
var maxBigInt2 = (a, b) => a > b ? a : b;
|
|
6612
|
+
var ceilDiv = (a, b) => (a + b - 1n) / b;
|
|
6613
|
+
function applyL1ToL2Alias(address) {
|
|
6614
|
+
return `0x${(BigInt(address) + L1_TO_L2_ALIAS_OFFSET & (1n << 160n) - 1n).toString(16).padStart(40, "0")}`;
|
|
6615
|
+
}
|
|
6616
|
+
function derivePriorityTxGasBreakdown(input) {
|
|
6617
|
+
const factoryDepsCount = input.factoryDepsCount ?? 0n;
|
|
6618
|
+
const minBodyGas = maxBigInt2(
|
|
6619
|
+
L1_TX_INTRINSIC_L2_GAS + ceilDiv(
|
|
6620
|
+
input.encodedLength * L1_TX_DELTA_544_ENCODING_BYTES,
|
|
6621
|
+
PRIORITY_TX_ENCODING_STEP_BYTES
|
|
6622
|
+
) + factoryDepsCount * L1_TX_DELTA_FACTORY_DEPS_L2_GAS,
|
|
6623
|
+
L1_TX_MIN_L2_GAS_BASE
|
|
6624
|
+
) + L1_TX_INTRINSIC_PUBDATA * input.gasPerPubdata + factoryDepsCount * L1_TX_DELTA_FACTORY_DEPS_PUBDATA * input.gasPerPubdata;
|
|
6625
|
+
const overhead = maxBigInt2(TX_SLOT_OVERHEAD_L2_GAS, TX_MEMORY_OVERHEAD_GAS * input.encodedLength);
|
|
6626
|
+
const derivedBodyGas = minBodyGas;
|
|
6627
|
+
return {
|
|
6628
|
+
encodedLength: input.encodedLength,
|
|
6629
|
+
minBodyGas,
|
|
6630
|
+
overhead,
|
|
6631
|
+
derivedBodyGas,
|
|
6632
|
+
derivedL2GasLimit: derivedBodyGas + overhead,
|
|
6633
|
+
priorityTxMaxGasLimit: PRIORITY_TX_MAX_GAS_LIMIT,
|
|
6634
|
+
priorityTxMaxGasLimitExceeded: derivedBodyGas > PRIORITY_TX_MAX_GAS_LIMIT
|
|
6635
|
+
};
|
|
6636
|
+
}
|
|
6637
|
+
function derivePriorityBodyGasEstimateCap(input) {
|
|
6638
|
+
return input.minBodyGas * (input.multiplier ?? DEFAULT_PRIORITY_BODY_GAS_ESTIMATE_MULTIPLIER);
|
|
6639
|
+
}
|
|
6640
|
+
function applyPriorityL2GasLimitBuffer(input) {
|
|
6641
|
+
return input.gasLimit * (100n + PRIORITY_L2_GAS_BUFFER) / 100n;
|
|
6642
|
+
}
|
|
6643
|
+
function minimalPriorityTxL2Gas(input) {
|
|
6644
|
+
const intrinsic = L1_TX_INTRINSIC_L2_GAS_ZKSYNC_OS + L1_TX_CALLDATA_FLOOR_PRICE_L2_GAS_ZKSYNC_OS * input.calldataLength;
|
|
6645
|
+
const pubdata = L1_TX_INTRINSIC_PUBDATA_ZKSYNC_OS * input.gasPerPubdata + ceilDiv(MAX_NATIVE_COMPUTATIONAL_ZKSYNC_OS, L1_TX_NATIVE_PER_GAS);
|
|
6646
|
+
return maxBigInt2(intrinsic, pubdata);
|
|
6647
|
+
}
|
|
6648
|
+
function clampPriorityL2GasLimit(input) {
|
|
6649
|
+
return maxBigInt2(
|
|
6650
|
+
input.gasLimit,
|
|
6651
|
+
minimalPriorityTxL2Gas({
|
|
6652
|
+
calldataLength: BigInt(Math.max(input.l2Calldata.length - 2, 0) / 2),
|
|
6653
|
+
gasPerPubdata: input.gasPerPubdata
|
|
6654
|
+
})
|
|
6655
|
+
);
|
|
6656
|
+
}
|
|
6657
|
+
function resolveRegisteredTokenPriorityL2GasLimit(input) {
|
|
6658
|
+
if (input.nodeEstimate != null && input.nodeEstimate > 0n) {
|
|
6659
|
+
return maxBigInt2(input.priorityFloorGasLimit, applyGasBuffer(input.nodeEstimate));
|
|
6660
|
+
}
|
|
6661
|
+
const modeledGas = REGISTERED_TOKEN_BRIDGE_MINT_EXECUTION_GAS + REGISTERED_TOKEN_BRIDGE_MINT_PUBDATA_BYTES * input.gasPerPubdata;
|
|
6662
|
+
return maxBigInt2(
|
|
6663
|
+
input.priorityFloorGasLimit,
|
|
6664
|
+
applyPriorityL2GasLimitBuffer({ gasLimit: modeledGas })
|
|
6665
|
+
);
|
|
6666
|
+
}
|
|
6667
|
+
|
|
6607
6668
|
// src/adapters/viem/estimator.ts
|
|
6608
6669
|
function toCoreTx(tx) {
|
|
6609
6670
|
return {
|
|
@@ -6655,6 +6716,20 @@ function viemToGasEstimator(client) {
|
|
|
6655
6716
|
maxPriorityFeePerGas: tx.maxPriorityFeePerGas
|
|
6656
6717
|
});
|
|
6657
6718
|
},
|
|
6719
|
+
async estimatePriorityTxGas(tx) {
|
|
6720
|
+
const result = await client.request({
|
|
6721
|
+
method: "eth_estimateGas",
|
|
6722
|
+
params: [
|
|
6723
|
+
{
|
|
6724
|
+
from: tx.from,
|
|
6725
|
+
to: tx.to,
|
|
6726
|
+
data: tx.data,
|
|
6727
|
+
type: ZKSYNC_OS_PRIORITY_TX_TYPE
|
|
6728
|
+
}
|
|
6729
|
+
]
|
|
6730
|
+
});
|
|
6731
|
+
return BigInt(result);
|
|
6732
|
+
},
|
|
6658
6733
|
async estimateFeesPerGas() {
|
|
6659
6734
|
try {
|
|
6660
6735
|
const fees = await client.estimateFeesPerGas();
|
|
@@ -6688,6 +6763,14 @@ function viemToGasEstimator(client) {
|
|
|
6688
6763
|
|
|
6689
6764
|
// src/adapters/viem/resources/deposits/services/gas.ts
|
|
6690
6765
|
var DEFAULT_SAFE_NONBASE_L2_GAS_LIMIT = 3000000n;
|
|
6766
|
+
async function estimatePriorityTxL2Gas(ctx, leg) {
|
|
6767
|
+
if (!leg) return void 0;
|
|
6768
|
+
try {
|
|
6769
|
+
return await viemToGasEstimator(ctx.client.l2).estimatePriorityTxGas?.(leg);
|
|
6770
|
+
} catch {
|
|
6771
|
+
return void 0;
|
|
6772
|
+
}
|
|
6773
|
+
}
|
|
6691
6774
|
async function quoteL1Gas2(input) {
|
|
6692
6775
|
const { ctx, tx, overrides, fallbackGasLimit } = input;
|
|
6693
6776
|
const estimator = viemToGasEstimator(ctx.client.l1);
|
|
@@ -6742,7 +6825,12 @@ async function determineNonBaseL2Gas(input) {
|
|
|
6742
6825
|
return quoteL2Gas2({
|
|
6743
6826
|
ctx,
|
|
6744
6827
|
route,
|
|
6745
|
-
overrideGasLimit:
|
|
6828
|
+
overrideGasLimit: resolveRegisteredTokenPriorityL2GasLimit({
|
|
6829
|
+
chainIdL2: ctx.chainIdL2,
|
|
6830
|
+
priorityFloorGasLimit: input.priorityFloorGasLimit,
|
|
6831
|
+
gasPerPubdata: ctx.gasPerPubdata,
|
|
6832
|
+
nodeEstimate: await estimatePriorityTxL2Gas(ctx, input.priorityTxL2Leg)
|
|
6833
|
+
})
|
|
6746
6834
|
});
|
|
6747
6835
|
}
|
|
6748
6836
|
const modelTx = {
|
|
@@ -6779,6 +6867,7 @@ async function determineEthNonBaseL2Gas(input) {
|
|
|
6779
6867
|
knownL2Token: input.ctx.resolvedToken?.l2,
|
|
6780
6868
|
modelTx: input.modelTx,
|
|
6781
6869
|
priorityFloorGasLimit: input.priorityFloorGasLimit,
|
|
6870
|
+
priorityTxL2Leg: input.priorityTxL2Leg,
|
|
6782
6871
|
undeployedGasLimit: input.undeployedGasLimit
|
|
6783
6872
|
});
|
|
6784
6873
|
}
|
|
@@ -6832,40 +6921,6 @@ function buildFeeBreakdown(p) {
|
|
|
6832
6921
|
l2
|
|
6833
6922
|
};
|
|
6834
6923
|
}
|
|
6835
|
-
|
|
6836
|
-
// src/core/resources/deposits/priority.ts
|
|
6837
|
-
var PRIORITY_TX_ENCODING_STEP_BYTES = 544n;
|
|
6838
|
-
var DEFAULT_PRIORITY_BODY_GAS_ESTIMATE_MULTIPLIER = 7n;
|
|
6839
|
-
var PRIORITY_L2_GAS_BUFFER = 40n;
|
|
6840
|
-
var maxBigInt2 = (a, b) => a > b ? a : b;
|
|
6841
|
-
var ceilDiv = (a, b) => (a + b - 1n) / b;
|
|
6842
|
-
function derivePriorityTxGasBreakdown(input) {
|
|
6843
|
-
const factoryDepsCount = input.factoryDepsCount ?? 0n;
|
|
6844
|
-
const minBodyGas = maxBigInt2(
|
|
6845
|
-
L1_TX_INTRINSIC_L2_GAS + ceilDiv(
|
|
6846
|
-
input.encodedLength * L1_TX_DELTA_544_ENCODING_BYTES,
|
|
6847
|
-
PRIORITY_TX_ENCODING_STEP_BYTES
|
|
6848
|
-
) + factoryDepsCount * L1_TX_DELTA_FACTORY_DEPS_L2_GAS,
|
|
6849
|
-
L1_TX_MIN_L2_GAS_BASE
|
|
6850
|
-
) + L1_TX_INTRINSIC_PUBDATA * input.gasPerPubdata + factoryDepsCount * L1_TX_DELTA_FACTORY_DEPS_PUBDATA * input.gasPerPubdata;
|
|
6851
|
-
const overhead = maxBigInt2(TX_SLOT_OVERHEAD_L2_GAS, TX_MEMORY_OVERHEAD_GAS * input.encodedLength);
|
|
6852
|
-
const derivedBodyGas = minBodyGas;
|
|
6853
|
-
return {
|
|
6854
|
-
encodedLength: input.encodedLength,
|
|
6855
|
-
minBodyGas,
|
|
6856
|
-
overhead,
|
|
6857
|
-
derivedBodyGas,
|
|
6858
|
-
derivedL2GasLimit: derivedBodyGas + overhead,
|
|
6859
|
-
priorityTxMaxGasLimit: PRIORITY_TX_MAX_GAS_LIMIT,
|
|
6860
|
-
priorityTxMaxGasLimitExceeded: derivedBodyGas > PRIORITY_TX_MAX_GAS_LIMIT
|
|
6861
|
-
};
|
|
6862
|
-
}
|
|
6863
|
-
function derivePriorityBodyGasEstimateCap(input) {
|
|
6864
|
-
return input.minBodyGas * (input.multiplier ?? DEFAULT_PRIORITY_BODY_GAS_ESTIMATE_MULTIPLIER);
|
|
6865
|
-
}
|
|
6866
|
-
function applyPriorityL2GasLimitBuffer(input) {
|
|
6867
|
-
return input.gasLimit * (100n + PRIORITY_L2_GAS_BUFFER) / 100n;
|
|
6868
|
-
}
|
|
6869
6924
|
var EMPTY_BYTES = "0x";
|
|
6870
6925
|
var ZERO_RESERVED_WORDS = [0n, 0n, 0n, 0n];
|
|
6871
6926
|
var L2_CANONICAL_TRANSACTION_PARAMETER = {
|
|
@@ -6942,9 +6997,13 @@ function routeEthDirect() {
|
|
|
6942
6997
|
l2Calldata,
|
|
6943
6998
|
gasPerPubdata: ctx.gasPerPubdata
|
|
6944
6999
|
});
|
|
6945
|
-
const quotedL2GasLimit = ctx.l2GasLimit ??
|
|
6946
|
-
|
|
6947
|
-
|
|
7000
|
+
const quotedL2GasLimit = ctx.l2GasLimit ?? clampPriorityL2GasLimit({
|
|
7001
|
+
gasLimit: applyPriorityL2GasLimitBuffer({
|
|
7002
|
+
chainIdL2: ctx.chainIdL2,
|
|
7003
|
+
gasLimit: priorityFloorBreakdown.derivedL2GasLimit
|
|
7004
|
+
}),
|
|
7005
|
+
l2Calldata,
|
|
7006
|
+
gasPerPubdata: ctx.gasPerPubdata
|
|
6948
7007
|
});
|
|
6949
7008
|
const l2GasParams = await quoteL2Gas2({
|
|
6950
7009
|
ctx,
|
|
@@ -7104,26 +7163,18 @@ var ntvCodec = createNTVCodec({
|
|
|
7104
7163
|
keccak256: viem.keccak256
|
|
7105
7164
|
});
|
|
7106
7165
|
async function encodeSecondBridgeErc20DepositCalldata(input) {
|
|
7107
|
-
|
|
7108
|
-
|
|
7109
|
-
|
|
7110
|
-
const l1ChainId = BigInt(await input.ctx.client.l1.getChainId());
|
|
7111
|
-
const expectedL1AssetId = ntvCodec.encodeAssetId(
|
|
7112
|
-
l1ChainId,
|
|
7166
|
+
const registeredAssetId = input.ctx.resolvedToken?.assetId;
|
|
7167
|
+
const assetId = registeredAssetId && registeredAssetId.toLowerCase() !== ZERO_ASSET_ID ? registeredAssetId : ntvCodec.encodeAssetId(
|
|
7168
|
+
BigInt(await input.ctx.client.l1.getChainId()),
|
|
7113
7169
|
L2_NATIVE_TOKEN_VAULT_ADDRESS,
|
|
7114
7170
|
input.token
|
|
7115
7171
|
);
|
|
7116
|
-
const assetId = input.ctx.resolvedToken.assetId.toLowerCase();
|
|
7117
|
-
const isL1Origin = assetId === ZERO_ASSET_ID || assetId === expectedL1AssetId.toLowerCase();
|
|
7118
|
-
if (isL1Origin) {
|
|
7119
|
-
return encodeSecondBridgeErc20Args(input.token, input.amount, input.receiver);
|
|
7120
|
-
}
|
|
7121
7172
|
const transferData = encodeNativeTokenVaultTransferData(
|
|
7122
7173
|
input.amount,
|
|
7123
7174
|
input.receiver,
|
|
7124
7175
|
input.token
|
|
7125
7176
|
);
|
|
7126
|
-
return encodeSecondBridgeDataV1(
|
|
7177
|
+
return encodeSecondBridgeDataV1(assetId, transferData);
|
|
7127
7178
|
}
|
|
7128
7179
|
async function getPriorityGasModel(input) {
|
|
7129
7180
|
try {
|
|
@@ -7165,9 +7216,18 @@ async function getPriorityGasModel(input) {
|
|
|
7165
7216
|
gasPerPubdata: input.ctx.gasPerPubdata
|
|
7166
7217
|
});
|
|
7167
7218
|
const model = {
|
|
7168
|
-
|
|
7169
|
-
|
|
7170
|
-
|
|
7219
|
+
priorityTxL2Leg: {
|
|
7220
|
+
from: applyL1ToL2Alias(input.ctx.l1AssetRouter),
|
|
7221
|
+
to: L2_ASSET_ROUTER_ADDRESS,
|
|
7222
|
+
data: l2Calldata
|
|
7223
|
+
},
|
|
7224
|
+
priorityFloorGasLimit: clampPriorityL2GasLimit({
|
|
7225
|
+
gasLimit: applyPriorityL2GasLimitBuffer({
|
|
7226
|
+
chainIdL2: input.ctx.chainIdL2,
|
|
7227
|
+
gasLimit: priorityFloorBreakdown.derivedL2GasLimit
|
|
7228
|
+
}),
|
|
7229
|
+
l2Calldata,
|
|
7230
|
+
gasPerPubdata: input.ctx.gasPerPubdata
|
|
7171
7231
|
})
|
|
7172
7232
|
};
|
|
7173
7233
|
if (isFirstBridge || input.ctx.resolvedToken.l2.toLowerCase() === viem.zeroAddress) {
|
|
@@ -7210,6 +7270,7 @@ function routeErc20NonBase() {
|
|
|
7210
7270
|
const baseToken = ctx.baseTokenL1 ?? await ctx.client.baseToken(ctx.chainIdL2);
|
|
7211
7271
|
const baseIsEth = ctx.baseIsEth ?? isETH(baseToken);
|
|
7212
7272
|
const assetRouter = ctx.l1AssetRouter;
|
|
7273
|
+
const nativeTokenVault = ctx.l1NativeTokenVault;
|
|
7213
7274
|
const receiver = p.to ?? ctx.sender;
|
|
7214
7275
|
const secondBridgeCalldata = await wrapAs3(
|
|
7215
7276
|
"INTERNAL",
|
|
@@ -7239,6 +7300,7 @@ function routeErc20NonBase() {
|
|
|
7239
7300
|
ctx,
|
|
7240
7301
|
l1Token: p.token,
|
|
7241
7302
|
priorityFloorGasLimit: priorityGasModel.priorityFloorGasLimit,
|
|
7303
|
+
priorityTxL2Leg: priorityGasModel.priorityTxL2Leg,
|
|
7242
7304
|
undeployedGasLimit: priorityGasModel.undeployedGasLimit,
|
|
7243
7305
|
modelTx: {
|
|
7244
7306
|
to: receiver,
|
|
@@ -7259,10 +7321,10 @@ function routeErc20NonBase() {
|
|
|
7259
7321
|
address: p.token,
|
|
7260
7322
|
abi: IERC20_default,
|
|
7261
7323
|
functionName: "allowance",
|
|
7262
|
-
args: [ctx.sender,
|
|
7324
|
+
args: [ctx.sender, nativeTokenVault]
|
|
7263
7325
|
}),
|
|
7264
7326
|
{
|
|
7265
|
-
ctx: { where: "erc20.allowance", token: p.token, spender:
|
|
7327
|
+
ctx: { where: "erc20.allowance", token: p.token, spender: nativeTokenVault },
|
|
7266
7328
|
message: "Failed to read deposit-token allowance."
|
|
7267
7329
|
}
|
|
7268
7330
|
);
|
|
@@ -7273,7 +7335,7 @@ function routeErc20NonBase() {
|
|
|
7273
7335
|
() => buildApprovalRequest({
|
|
7274
7336
|
ctx,
|
|
7275
7337
|
token: p.token,
|
|
7276
|
-
spender:
|
|
7338
|
+
spender: nativeTokenVault,
|
|
7277
7339
|
amount: p.amount
|
|
7278
7340
|
}),
|
|
7279
7341
|
{
|
|
@@ -7281,9 +7343,9 @@ function routeErc20NonBase() {
|
|
|
7281
7343
|
message: "Failed to simulate deposit token approve."
|
|
7282
7344
|
}
|
|
7283
7345
|
);
|
|
7284
|
-
approvals.push({ token: p.token, spender:
|
|
7346
|
+
approvals.push({ token: p.token, spender: nativeTokenVault, amount: p.amount });
|
|
7285
7347
|
steps.push({
|
|
7286
|
-
key: `approve:${p.token}:${
|
|
7348
|
+
key: `approve:${p.token}:${nativeTokenVault}`,
|
|
7287
7349
|
kind: "approve",
|
|
7288
7350
|
description: `Approve deposit token for amount`,
|
|
7289
7351
|
tx: approveTx
|
|
@@ -7297,10 +7359,10 @@ function routeErc20NonBase() {
|
|
|
7297
7359
|
address: baseToken,
|
|
7298
7360
|
abi: IERC20_default,
|
|
7299
7361
|
functionName: "allowance",
|
|
7300
|
-
args: [ctx.sender,
|
|
7362
|
+
args: [ctx.sender, nativeTokenVault]
|
|
7301
7363
|
}),
|
|
7302
7364
|
{
|
|
7303
|
-
ctx: { where: "erc20.allowance", token: baseToken, spender:
|
|
7365
|
+
ctx: { where: "erc20.allowance", token: baseToken, spender: nativeTokenVault },
|
|
7304
7366
|
message: "Failed to read base-token allowance."
|
|
7305
7367
|
}
|
|
7306
7368
|
);
|
|
@@ -7311,7 +7373,7 @@ function routeErc20NonBase() {
|
|
|
7311
7373
|
() => buildApprovalRequest({
|
|
7312
7374
|
ctx,
|
|
7313
7375
|
token: baseToken,
|
|
7314
|
-
spender:
|
|
7376
|
+
spender: nativeTokenVault,
|
|
7315
7377
|
amount: mintValue
|
|
7316
7378
|
}),
|
|
7317
7379
|
{
|
|
@@ -7319,9 +7381,9 @@ function routeErc20NonBase() {
|
|
|
7319
7381
|
message: "Failed to simulate base token approve."
|
|
7320
7382
|
}
|
|
7321
7383
|
);
|
|
7322
|
-
approvals.push({ token: baseToken, spender:
|
|
7384
|
+
approvals.push({ token: baseToken, spender: nativeTokenVault, amount: mintValue });
|
|
7323
7385
|
steps.push({
|
|
7324
|
-
key: `approve:${baseToken}:${
|
|
7386
|
+
key: `approve:${baseToken}:${nativeTokenVault}`,
|
|
7325
7387
|
kind: "approve",
|
|
7326
7388
|
description: `Approve base token for mintValue`,
|
|
7327
7389
|
tx: approveBaseTx
|
|
@@ -7460,9 +7522,18 @@ async function getPriorityGasModel2(input) {
|
|
|
7460
7522
|
gasPerPubdata: input.ctx.gasPerPubdata
|
|
7461
7523
|
});
|
|
7462
7524
|
const model = {
|
|
7463
|
-
|
|
7464
|
-
|
|
7465
|
-
|
|
7525
|
+
priorityTxL2Leg: {
|
|
7526
|
+
from: applyL1ToL2Alias(input.ctx.l1AssetRouter),
|
|
7527
|
+
to: L2_ASSET_ROUTER_ADDRESS,
|
|
7528
|
+
data: l2Calldata
|
|
7529
|
+
},
|
|
7530
|
+
priorityFloorGasLimit: clampPriorityL2GasLimit({
|
|
7531
|
+
gasLimit: applyPriorityL2GasLimitBuffer({
|
|
7532
|
+
chainIdL2: input.ctx.chainIdL2,
|
|
7533
|
+
gasLimit: priorityFloorBreakdown.derivedL2GasLimit
|
|
7534
|
+
}),
|
|
7535
|
+
l2Calldata,
|
|
7536
|
+
gasPerPubdata: input.ctx.gasPerPubdata
|
|
7466
7537
|
})
|
|
7467
7538
|
};
|
|
7468
7539
|
if (input.ctx.resolvedToken.l2.toLowerCase() === viem.zeroAddress) {
|
|
@@ -7537,6 +7608,7 @@ function routeEthNonBase() {
|
|
|
7537
7608
|
ctx,
|
|
7538
7609
|
modelTx: l2TxModel,
|
|
7539
7610
|
priorityFloorGasLimit: priorityGasModel.priorityFloorGasLimit,
|
|
7611
|
+
priorityTxL2Leg: priorityGasModel.priorityTxL2Leg,
|
|
7540
7612
|
undeployedGasLimit: priorityGasModel.undeployedGasLimit
|
|
7541
7613
|
});
|
|
7542
7614
|
if (!l2Gas) throw new Error("Failed to estimate L2 gas parameters.");
|
|
@@ -7551,10 +7623,10 @@ function routeEthNonBase() {
|
|
|
7551
7623
|
address: baseToken,
|
|
7552
7624
|
abi: IERC20_default,
|
|
7553
7625
|
functionName: "allowance",
|
|
7554
|
-
args: [ctx.sender, ctx.
|
|
7626
|
+
args: [ctx.sender, ctx.l1NativeTokenVault]
|
|
7555
7627
|
}),
|
|
7556
7628
|
{
|
|
7557
|
-
ctx: { where: "erc20.allowance", token: baseToken, spender: ctx.
|
|
7629
|
+
ctx: { where: "erc20.allowance", token: baseToken, spender: ctx.l1NativeTokenVault },
|
|
7558
7630
|
message: "Failed to read base-token allowance."
|
|
7559
7631
|
}
|
|
7560
7632
|
);
|
|
@@ -7566,7 +7638,7 @@ function routeEthNonBase() {
|
|
|
7566
7638
|
() => buildApprovalRequest({
|
|
7567
7639
|
ctx,
|
|
7568
7640
|
token: baseToken,
|
|
7569
|
-
spender: ctx.
|
|
7641
|
+
spender: ctx.l1NativeTokenVault,
|
|
7570
7642
|
amount: mintValue
|
|
7571
7643
|
}),
|
|
7572
7644
|
{
|
|
@@ -7574,9 +7646,9 @@ function routeEthNonBase() {
|
|
|
7574
7646
|
message: "Failed to simulate base-token approve."
|
|
7575
7647
|
}
|
|
7576
7648
|
);
|
|
7577
|
-
approvals.push({ token: baseToken, spender: ctx.
|
|
7649
|
+
approvals.push({ token: baseToken, spender: ctx.l1NativeTokenVault, amount: mintValue });
|
|
7578
7650
|
steps.push({
|
|
7579
|
-
key: `approve:${baseToken}:${ctx.
|
|
7651
|
+
key: `approve:${baseToken}:${ctx.l1NativeTokenVault}`,
|
|
7580
7652
|
kind: "approve",
|
|
7581
7653
|
description: `Approve base token for fees (mintValue)`,
|
|
7582
7654
|
tx: approveTx
|
|
@@ -7729,9 +7801,13 @@ function routeErc20Base() {
|
|
|
7729
7801
|
l2Calldata,
|
|
7730
7802
|
gasPerPubdata: ctx.gasPerPubdata
|
|
7731
7803
|
});
|
|
7732
|
-
const quotedL2GasLimit = ctx.l2GasLimit ??
|
|
7733
|
-
|
|
7734
|
-
|
|
7804
|
+
const quotedL2GasLimit = ctx.l2GasLimit ?? clampPriorityL2GasLimit({
|
|
7805
|
+
gasLimit: applyPriorityL2GasLimitBuffer({
|
|
7806
|
+
chainIdL2: ctx.chainIdL2,
|
|
7807
|
+
gasLimit: priorityFloorBreakdown.derivedL2GasLimit
|
|
7808
|
+
}),
|
|
7809
|
+
l2Calldata,
|
|
7810
|
+
gasPerPubdata: ctx.gasPerPubdata
|
|
7735
7811
|
});
|
|
7736
7812
|
const l2Gas = await quoteL2Gas2({
|
|
7737
7813
|
ctx,
|
|
@@ -7750,10 +7826,10 @@ function routeErc20Base() {
|
|
|
7750
7826
|
address: baseToken,
|
|
7751
7827
|
abi: IERC20_default,
|
|
7752
7828
|
functionName: "allowance",
|
|
7753
|
-
args: [ctx.sender, ctx.
|
|
7829
|
+
args: [ctx.sender, ctx.l1NativeTokenVault]
|
|
7754
7830
|
}),
|
|
7755
7831
|
{
|
|
7756
|
-
ctx: { where: "erc20.allowance", token: baseToken, spender: ctx.
|
|
7832
|
+
ctx: { where: "erc20.allowance", token: baseToken, spender: ctx.l1NativeTokenVault },
|
|
7757
7833
|
message: "Failed to read base-token allowance."
|
|
7758
7834
|
}
|
|
7759
7835
|
);
|
|
@@ -7765,7 +7841,7 @@ function routeErc20Base() {
|
|
|
7765
7841
|
() => buildApprovalRequest({
|
|
7766
7842
|
ctx,
|
|
7767
7843
|
token: baseToken,
|
|
7768
|
-
spender: ctx.
|
|
7844
|
+
spender: ctx.l1NativeTokenVault,
|
|
7769
7845
|
amount: mintValue
|
|
7770
7846
|
}),
|
|
7771
7847
|
{
|
|
@@ -7773,9 +7849,9 @@ function routeErc20Base() {
|
|
|
7773
7849
|
message: "Failed to simulate ERC-20 approve."
|
|
7774
7850
|
}
|
|
7775
7851
|
);
|
|
7776
|
-
approvals.push({ token: baseToken, spender: ctx.
|
|
7852
|
+
approvals.push({ token: baseToken, spender: ctx.l1NativeTokenVault, amount: mintValue });
|
|
7777
7853
|
steps.push({
|
|
7778
|
-
key: `approve:${baseToken}:${ctx.
|
|
7854
|
+
key: `approve:${baseToken}:${ctx.l1NativeTokenVault}`,
|
|
7779
7855
|
kind: "approve",
|
|
7780
7856
|
description: "Approve base token for mintValue",
|
|
7781
7857
|
tx: approveTx
|
|
@@ -8021,8 +8097,17 @@ function createTokensResource(client) {
|
|
|
8021
8097
|
const chainId = BigInt(await client.l2.getChainId());
|
|
8022
8098
|
return await client.baseToken(chainId);
|
|
8023
8099
|
}
|
|
8024
|
-
const {
|
|
8025
|
-
const
|
|
8100
|
+
const { l2NativeTokenVault, l1NativeTokenVault } = await client.contracts();
|
|
8101
|
+
const assetId = await l2NativeTokenVault.read.assetId([l2Token]);
|
|
8102
|
+
if (BigInt(assetId) === 0n) {
|
|
8103
|
+
throw new Error(`Token ${l2Token} is not registered in the L2 NativeTokenVault.`);
|
|
8104
|
+
}
|
|
8105
|
+
const l1Token = await l1NativeTokenVault.read.tokenAddress([assetId]);
|
|
8106
|
+
if (BigInt(l1Token) === 0n) {
|
|
8107
|
+
throw new Error(
|
|
8108
|
+
`Token ${l2Token} has no L1 counterpart registered in the L1 NativeTokenVault.`
|
|
8109
|
+
);
|
|
8110
|
+
}
|
|
8026
8111
|
return l1Token;
|
|
8027
8112
|
});
|
|
8028
8113
|
}
|