@matterlabs/zksync-js 0.0.22 → 0.0.24
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 +202 -93
- 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 +202 -105
- 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 +194 -92
- 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 +194 -108
- package/dist/adapters/viem/sdk.cjs.map +1 -1
- package/dist/adapters/viem/sdk.js +8 -8
- package/dist/{chunk-NQRYXL3K.js → chunk-3IPSDGHO.js} +17 -1
- package/dist/{chunk-KL6ZCPWJ.js → chunk-4ZANKNIK.js} +1 -1
- package/dist/{chunk-3SPDWWRD.js → chunk-5S63J6DW.js} +60 -32
- package/dist/{chunk-CP4SQ5PM.js → chunk-B6P24GL5.js} +137 -57
- package/dist/{chunk-QUAPG3ZR.js → chunk-BQ2YCWV2.js} +2 -2
- package/dist/{chunk-2D3FBCZC.js → chunk-H5A6GU3D.js} +2 -2
- package/dist/{chunk-AMRHBZIY.js → chunk-JNS4XZE2.js} +2 -9
- package/dist/{chunk-32N6TI6K.js → chunk-OEUDZFXH.js} +1 -1
- package/dist/{chunk-PI4PF6WT.js → chunk-PNTR5FTL.js} +3 -3
- package/dist/{chunk-4K4LOCQJ.js → chunk-QMMFUWRV.js} +129 -56
- package/dist/{chunk-CPNHKNI4.js → chunk-RZH7HBH3.js} +2 -2
- package/dist/{chunk-JXBLQQEN.js → chunk-YEA74D2L.js} +3 -3
- package/dist/{chunk-CUBUD4J4.js → chunk-YGXEIOK6.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/core/types/errors.d.ts +1 -1
- 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-QMMFUWRV.js';
|
|
2
|
+
import '../../chunk-5S63J6DW.js';
|
|
3
|
+
import '../../chunk-BQ2YCWV2.js';
|
|
4
|
+
import '../../chunk-OEUDZFXH.js';
|
|
5
|
+
export { createViemClient as createClient, createViemClient } from '../../chunk-YEA74D2L.js';
|
|
6
|
+
export { classifyReadinessFromRevert, createErrorHandlers, decodeRevert, registerErrorAbi, toZKsyncError } from '../../chunk-H5A6GU3D.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-4ZANKNIK.js';
|
|
10
|
+
import '../../chunk-JNS4XZE2.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) {
|
|
@@ -5836,22 +5838,6 @@ function encodeSecondBridgeDataV1(assetId, transferData) {
|
|
|
5836
5838
|
);
|
|
5837
5839
|
return viem.concat(["0x01", data]);
|
|
5838
5840
|
}
|
|
5839
|
-
function encodeSecondBridgeArgs(token, amount, l2Receiver) {
|
|
5840
|
-
return viem.encodeAbiParameters(
|
|
5841
|
-
[
|
|
5842
|
-
{ type: "address", name: "token" },
|
|
5843
|
-
{ type: "uint256", name: "amount" },
|
|
5844
|
-
{ type: "address", name: "l2Receiver" }
|
|
5845
|
-
],
|
|
5846
|
-
[token, amount, l2Receiver]
|
|
5847
|
-
);
|
|
5848
|
-
}
|
|
5849
|
-
function encodeSecondBridgeErc20Args(token, amount, l2Receiver) {
|
|
5850
|
-
return encodeSecondBridgeArgs(token, amount, l2Receiver);
|
|
5851
|
-
}
|
|
5852
|
-
function encodeSecondBridgeEthArgs(amount, l2Receiver, ethToken = ETH_ADDRESS) {
|
|
5853
|
-
return encodeSecondBridgeArgs(ethToken, amount, l2Receiver);
|
|
5854
|
-
}
|
|
5855
5841
|
function buildDirectRequestStruct(args) {
|
|
5856
5842
|
return {
|
|
5857
5843
|
chainId: args.chainId,
|
|
@@ -6147,7 +6133,7 @@ var OP_DEPOSITS = {
|
|
|
6147
6133
|
ethNonBase: {
|
|
6148
6134
|
allowanceBase: "deposits.eth-nonbase:allowanceBaseToken",
|
|
6149
6135
|
ethBalance: "deposits.eth-nonbase:getEthBalance",
|
|
6150
|
-
encodeCalldata: "deposits.eth-nonbase:
|
|
6136
|
+
encodeCalldata: "deposits.eth-nonbase:encodeSecondBridgeEthDepositCalldata",
|
|
6151
6137
|
estGas: "deposits.eth-nonbase:estimateGas",
|
|
6152
6138
|
assertEthAsset: "deposits.eth-nonbase:assertEthAsset",
|
|
6153
6139
|
assertNonEthBase: "deposits.eth-nonbase:assertNonEthBase",
|
|
@@ -6604,6 +6590,68 @@ async function quoteL2Gas(input) {
|
|
|
6604
6590
|
}
|
|
6605
6591
|
}
|
|
6606
6592
|
|
|
6593
|
+
// src/core/resources/deposits/priority.ts
|
|
6594
|
+
var PRIORITY_TX_ENCODING_STEP_BYTES = 544n;
|
|
6595
|
+
var L1_TO_L2_ALIAS_OFFSET = 0x1111000000000000000000000000000000001111n;
|
|
6596
|
+
var DEFAULT_PRIORITY_BODY_GAS_ESTIMATE_MULTIPLIER = 7n;
|
|
6597
|
+
var PRIORITY_L2_GAS_BUFFER = 40n;
|
|
6598
|
+
var maxBigInt2 = (a, b) => a > b ? a : b;
|
|
6599
|
+
var ceilDiv = (a, b) => (a + b - 1n) / b;
|
|
6600
|
+
function applyL1ToL2Alias(address) {
|
|
6601
|
+
return `0x${(BigInt(address) + L1_TO_L2_ALIAS_OFFSET & (1n << 160n) - 1n).toString(16).padStart(40, "0")}`;
|
|
6602
|
+
}
|
|
6603
|
+
function derivePriorityTxGasBreakdown(input) {
|
|
6604
|
+
const factoryDepsCount = input.factoryDepsCount ?? 0n;
|
|
6605
|
+
const minBodyGas = maxBigInt2(
|
|
6606
|
+
L1_TX_INTRINSIC_L2_GAS + ceilDiv(
|
|
6607
|
+
input.encodedLength * L1_TX_DELTA_544_ENCODING_BYTES,
|
|
6608
|
+
PRIORITY_TX_ENCODING_STEP_BYTES
|
|
6609
|
+
) + factoryDepsCount * L1_TX_DELTA_FACTORY_DEPS_L2_GAS,
|
|
6610
|
+
L1_TX_MIN_L2_GAS_BASE
|
|
6611
|
+
) + L1_TX_INTRINSIC_PUBDATA * input.gasPerPubdata + factoryDepsCount * L1_TX_DELTA_FACTORY_DEPS_PUBDATA * input.gasPerPubdata;
|
|
6612
|
+
const overhead = maxBigInt2(TX_SLOT_OVERHEAD_L2_GAS, TX_MEMORY_OVERHEAD_GAS * input.encodedLength);
|
|
6613
|
+
const derivedBodyGas = minBodyGas;
|
|
6614
|
+
return {
|
|
6615
|
+
encodedLength: input.encodedLength,
|
|
6616
|
+
minBodyGas,
|
|
6617
|
+
overhead,
|
|
6618
|
+
derivedBodyGas,
|
|
6619
|
+
derivedL2GasLimit: derivedBodyGas + overhead,
|
|
6620
|
+
priorityTxMaxGasLimit: PRIORITY_TX_MAX_GAS_LIMIT,
|
|
6621
|
+
priorityTxMaxGasLimitExceeded: derivedBodyGas > PRIORITY_TX_MAX_GAS_LIMIT
|
|
6622
|
+
};
|
|
6623
|
+
}
|
|
6624
|
+
function derivePriorityBodyGasEstimateCap(input) {
|
|
6625
|
+
return input.minBodyGas * (input.multiplier ?? DEFAULT_PRIORITY_BODY_GAS_ESTIMATE_MULTIPLIER);
|
|
6626
|
+
}
|
|
6627
|
+
function applyPriorityL2GasLimitBuffer(input) {
|
|
6628
|
+
return input.gasLimit * (100n + PRIORITY_L2_GAS_BUFFER) / 100n;
|
|
6629
|
+
}
|
|
6630
|
+
function minimalPriorityTxL2Gas(input) {
|
|
6631
|
+
const intrinsic = L1_TX_INTRINSIC_L2_GAS_ZKSYNC_OS + L1_TX_CALLDATA_FLOOR_PRICE_L2_GAS_ZKSYNC_OS * input.calldataLength;
|
|
6632
|
+
const pubdata = L1_TX_INTRINSIC_PUBDATA_ZKSYNC_OS * input.gasPerPubdata + ceilDiv(MAX_NATIVE_COMPUTATIONAL_ZKSYNC_OS, L1_TX_NATIVE_PER_GAS);
|
|
6633
|
+
return maxBigInt2(intrinsic, pubdata);
|
|
6634
|
+
}
|
|
6635
|
+
function clampPriorityL2GasLimit(input) {
|
|
6636
|
+
return maxBigInt2(
|
|
6637
|
+
input.gasLimit,
|
|
6638
|
+
minimalPriorityTxL2Gas({
|
|
6639
|
+
calldataLength: BigInt(Math.max(input.l2Calldata.length - 2, 0) / 2),
|
|
6640
|
+
gasPerPubdata: input.gasPerPubdata
|
|
6641
|
+
})
|
|
6642
|
+
);
|
|
6643
|
+
}
|
|
6644
|
+
function resolveRegisteredTokenPriorityL2GasLimit(input) {
|
|
6645
|
+
if (input.nodeEstimate != null && input.nodeEstimate > 0n) {
|
|
6646
|
+
return maxBigInt2(input.priorityFloorGasLimit, applyGasBuffer(input.nodeEstimate));
|
|
6647
|
+
}
|
|
6648
|
+
const modeledGas = REGISTERED_TOKEN_BRIDGE_MINT_EXECUTION_GAS + REGISTERED_TOKEN_BRIDGE_MINT_PUBDATA_BYTES * input.gasPerPubdata;
|
|
6649
|
+
return maxBigInt2(
|
|
6650
|
+
input.priorityFloorGasLimit,
|
|
6651
|
+
applyPriorityL2GasLimitBuffer({ gasLimit: modeledGas })
|
|
6652
|
+
);
|
|
6653
|
+
}
|
|
6654
|
+
|
|
6607
6655
|
// src/adapters/viem/estimator.ts
|
|
6608
6656
|
function toCoreTx(tx) {
|
|
6609
6657
|
return {
|
|
@@ -6655,6 +6703,20 @@ function viemToGasEstimator(client) {
|
|
|
6655
6703
|
maxPriorityFeePerGas: tx.maxPriorityFeePerGas
|
|
6656
6704
|
});
|
|
6657
6705
|
},
|
|
6706
|
+
async estimatePriorityTxGas(tx) {
|
|
6707
|
+
const result = await client.request({
|
|
6708
|
+
method: "eth_estimateGas",
|
|
6709
|
+
params: [
|
|
6710
|
+
{
|
|
6711
|
+
from: tx.from,
|
|
6712
|
+
to: tx.to,
|
|
6713
|
+
data: tx.data,
|
|
6714
|
+
type: ZKSYNC_OS_PRIORITY_TX_TYPE
|
|
6715
|
+
}
|
|
6716
|
+
]
|
|
6717
|
+
});
|
|
6718
|
+
return BigInt(result);
|
|
6719
|
+
},
|
|
6658
6720
|
async estimateFeesPerGas() {
|
|
6659
6721
|
try {
|
|
6660
6722
|
const fees = await client.estimateFeesPerGas();
|
|
@@ -6688,6 +6750,14 @@ function viemToGasEstimator(client) {
|
|
|
6688
6750
|
|
|
6689
6751
|
// src/adapters/viem/resources/deposits/services/gas.ts
|
|
6690
6752
|
var DEFAULT_SAFE_NONBASE_L2_GAS_LIMIT = 3000000n;
|
|
6753
|
+
async function estimatePriorityTxL2Gas(ctx, leg) {
|
|
6754
|
+
if (!leg) return void 0;
|
|
6755
|
+
try {
|
|
6756
|
+
return await viemToGasEstimator(ctx.client.l2).estimatePriorityTxGas?.(leg);
|
|
6757
|
+
} catch {
|
|
6758
|
+
return void 0;
|
|
6759
|
+
}
|
|
6760
|
+
}
|
|
6691
6761
|
async function quoteL1Gas2(input) {
|
|
6692
6762
|
const { ctx, tx, overrides, fallbackGasLimit } = input;
|
|
6693
6763
|
const estimator = viemToGasEstimator(ctx.client.l1);
|
|
@@ -6742,7 +6812,12 @@ async function determineNonBaseL2Gas(input) {
|
|
|
6742
6812
|
return quoteL2Gas2({
|
|
6743
6813
|
ctx,
|
|
6744
6814
|
route,
|
|
6745
|
-
overrideGasLimit:
|
|
6815
|
+
overrideGasLimit: resolveRegisteredTokenPriorityL2GasLimit({
|
|
6816
|
+
chainIdL2: ctx.chainIdL2,
|
|
6817
|
+
priorityFloorGasLimit: input.priorityFloorGasLimit,
|
|
6818
|
+
gasPerPubdata: ctx.gasPerPubdata,
|
|
6819
|
+
nodeEstimate: await estimatePriorityTxL2Gas(ctx, input.priorityTxL2Leg)
|
|
6820
|
+
})
|
|
6746
6821
|
});
|
|
6747
6822
|
}
|
|
6748
6823
|
const modelTx = {
|
|
@@ -6779,6 +6854,7 @@ async function determineEthNonBaseL2Gas(input) {
|
|
|
6779
6854
|
knownL2Token: input.ctx.resolvedToken?.l2,
|
|
6780
6855
|
modelTx: input.modelTx,
|
|
6781
6856
|
priorityFloorGasLimit: input.priorityFloorGasLimit,
|
|
6857
|
+
priorityTxL2Leg: input.priorityTxL2Leg,
|
|
6782
6858
|
undeployedGasLimit: input.undeployedGasLimit
|
|
6783
6859
|
});
|
|
6784
6860
|
}
|
|
@@ -6832,40 +6908,6 @@ function buildFeeBreakdown(p) {
|
|
|
6832
6908
|
l2
|
|
6833
6909
|
};
|
|
6834
6910
|
}
|
|
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
6911
|
var EMPTY_BYTES = "0x";
|
|
6870
6912
|
var ZERO_RESERVED_WORDS = [0n, 0n, 0n, 0n];
|
|
6871
6913
|
var L2_CANONICAL_TRANSACTION_PARAMETER = {
|
|
@@ -6942,9 +6984,13 @@ function routeEthDirect() {
|
|
|
6942
6984
|
l2Calldata,
|
|
6943
6985
|
gasPerPubdata: ctx.gasPerPubdata
|
|
6944
6986
|
});
|
|
6945
|
-
const quotedL2GasLimit = ctx.l2GasLimit ??
|
|
6946
|
-
|
|
6947
|
-
|
|
6987
|
+
const quotedL2GasLimit = ctx.l2GasLimit ?? clampPriorityL2GasLimit({
|
|
6988
|
+
gasLimit: applyPriorityL2GasLimitBuffer({
|
|
6989
|
+
chainIdL2: ctx.chainIdL2,
|
|
6990
|
+
gasLimit: priorityFloorBreakdown.derivedL2GasLimit
|
|
6991
|
+
}),
|
|
6992
|
+
l2Calldata,
|
|
6993
|
+
gasPerPubdata: ctx.gasPerPubdata
|
|
6948
6994
|
});
|
|
6949
6995
|
const l2GasParams = await quoteL2Gas2({
|
|
6950
6996
|
ctx,
|
|
@@ -7104,26 +7150,18 @@ var ntvCodec = createNTVCodec({
|
|
|
7104
7150
|
keccak256: viem.keccak256
|
|
7105
7151
|
});
|
|
7106
7152
|
async function encodeSecondBridgeErc20DepositCalldata(input) {
|
|
7107
|
-
|
|
7108
|
-
|
|
7109
|
-
|
|
7110
|
-
const l1ChainId = BigInt(await input.ctx.client.l1.getChainId());
|
|
7111
|
-
const expectedL1AssetId = ntvCodec.encodeAssetId(
|
|
7112
|
-
l1ChainId,
|
|
7153
|
+
const registeredAssetId = input.ctx.resolvedToken?.assetId;
|
|
7154
|
+
const assetId = registeredAssetId && registeredAssetId.toLowerCase() !== ZERO_ASSET_ID ? registeredAssetId : ntvCodec.encodeAssetId(
|
|
7155
|
+
BigInt(await input.ctx.client.l1.getChainId()),
|
|
7113
7156
|
L2_NATIVE_TOKEN_VAULT_ADDRESS,
|
|
7114
7157
|
input.token
|
|
7115
7158
|
);
|
|
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
7159
|
const transferData = encodeNativeTokenVaultTransferData(
|
|
7122
7160
|
input.amount,
|
|
7123
7161
|
input.receiver,
|
|
7124
7162
|
input.token
|
|
7125
7163
|
);
|
|
7126
|
-
return encodeSecondBridgeDataV1(
|
|
7164
|
+
return encodeSecondBridgeDataV1(assetId, transferData);
|
|
7127
7165
|
}
|
|
7128
7166
|
async function getPriorityGasModel(input) {
|
|
7129
7167
|
try {
|
|
@@ -7165,9 +7203,18 @@ async function getPriorityGasModel(input) {
|
|
|
7165
7203
|
gasPerPubdata: input.ctx.gasPerPubdata
|
|
7166
7204
|
});
|
|
7167
7205
|
const model = {
|
|
7168
|
-
|
|
7169
|
-
|
|
7170
|
-
|
|
7206
|
+
priorityTxL2Leg: {
|
|
7207
|
+
from: applyL1ToL2Alias(input.ctx.l1AssetRouter),
|
|
7208
|
+
to: L2_ASSET_ROUTER_ADDRESS,
|
|
7209
|
+
data: l2Calldata
|
|
7210
|
+
},
|
|
7211
|
+
priorityFloorGasLimit: clampPriorityL2GasLimit({
|
|
7212
|
+
gasLimit: applyPriorityL2GasLimitBuffer({
|
|
7213
|
+
chainIdL2: input.ctx.chainIdL2,
|
|
7214
|
+
gasLimit: priorityFloorBreakdown.derivedL2GasLimit
|
|
7215
|
+
}),
|
|
7216
|
+
l2Calldata,
|
|
7217
|
+
gasPerPubdata: input.ctx.gasPerPubdata
|
|
7171
7218
|
})
|
|
7172
7219
|
};
|
|
7173
7220
|
if (isFirstBridge || input.ctx.resolvedToken.l2.toLowerCase() === viem.zeroAddress) {
|
|
@@ -7210,6 +7257,7 @@ function routeErc20NonBase() {
|
|
|
7210
7257
|
const baseToken = ctx.baseTokenL1 ?? await ctx.client.baseToken(ctx.chainIdL2);
|
|
7211
7258
|
const baseIsEth = ctx.baseIsEth ?? isETH(baseToken);
|
|
7212
7259
|
const assetRouter = ctx.l1AssetRouter;
|
|
7260
|
+
const nativeTokenVault = ctx.l1NativeTokenVault;
|
|
7213
7261
|
const receiver = p.to ?? ctx.sender;
|
|
7214
7262
|
const secondBridgeCalldata = await wrapAs3(
|
|
7215
7263
|
"INTERNAL",
|
|
@@ -7239,6 +7287,7 @@ function routeErc20NonBase() {
|
|
|
7239
7287
|
ctx,
|
|
7240
7288
|
l1Token: p.token,
|
|
7241
7289
|
priorityFloorGasLimit: priorityGasModel.priorityFloorGasLimit,
|
|
7290
|
+
priorityTxL2Leg: priorityGasModel.priorityTxL2Leg,
|
|
7242
7291
|
undeployedGasLimit: priorityGasModel.undeployedGasLimit,
|
|
7243
7292
|
modelTx: {
|
|
7244
7293
|
to: receiver,
|
|
@@ -7259,10 +7308,10 @@ function routeErc20NonBase() {
|
|
|
7259
7308
|
address: p.token,
|
|
7260
7309
|
abi: IERC20_default,
|
|
7261
7310
|
functionName: "allowance",
|
|
7262
|
-
args: [ctx.sender,
|
|
7311
|
+
args: [ctx.sender, nativeTokenVault]
|
|
7263
7312
|
}),
|
|
7264
7313
|
{
|
|
7265
|
-
ctx: { where: "erc20.allowance", token: p.token, spender:
|
|
7314
|
+
ctx: { where: "erc20.allowance", token: p.token, spender: nativeTokenVault },
|
|
7266
7315
|
message: "Failed to read deposit-token allowance."
|
|
7267
7316
|
}
|
|
7268
7317
|
);
|
|
@@ -7273,7 +7322,7 @@ function routeErc20NonBase() {
|
|
|
7273
7322
|
() => buildApprovalRequest({
|
|
7274
7323
|
ctx,
|
|
7275
7324
|
token: p.token,
|
|
7276
|
-
spender:
|
|
7325
|
+
spender: nativeTokenVault,
|
|
7277
7326
|
amount: p.amount
|
|
7278
7327
|
}),
|
|
7279
7328
|
{
|
|
@@ -7281,9 +7330,9 @@ function routeErc20NonBase() {
|
|
|
7281
7330
|
message: "Failed to simulate deposit token approve."
|
|
7282
7331
|
}
|
|
7283
7332
|
);
|
|
7284
|
-
approvals.push({ token: p.token, spender:
|
|
7333
|
+
approvals.push({ token: p.token, spender: nativeTokenVault, amount: p.amount });
|
|
7285
7334
|
steps.push({
|
|
7286
|
-
key: `approve:${p.token}:${
|
|
7335
|
+
key: `approve:${p.token}:${nativeTokenVault}`,
|
|
7287
7336
|
kind: "approve",
|
|
7288
7337
|
description: `Approve deposit token for amount`,
|
|
7289
7338
|
tx: approveTx
|
|
@@ -7297,10 +7346,10 @@ function routeErc20NonBase() {
|
|
|
7297
7346
|
address: baseToken,
|
|
7298
7347
|
abi: IERC20_default,
|
|
7299
7348
|
functionName: "allowance",
|
|
7300
|
-
args: [ctx.sender,
|
|
7349
|
+
args: [ctx.sender, nativeTokenVault]
|
|
7301
7350
|
}),
|
|
7302
7351
|
{
|
|
7303
|
-
ctx: { where: "erc20.allowance", token: baseToken, spender:
|
|
7352
|
+
ctx: { where: "erc20.allowance", token: baseToken, spender: nativeTokenVault },
|
|
7304
7353
|
message: "Failed to read base-token allowance."
|
|
7305
7354
|
}
|
|
7306
7355
|
);
|
|
@@ -7311,7 +7360,7 @@ function routeErc20NonBase() {
|
|
|
7311
7360
|
() => buildApprovalRequest({
|
|
7312
7361
|
ctx,
|
|
7313
7362
|
token: baseToken,
|
|
7314
|
-
spender:
|
|
7363
|
+
spender: nativeTokenVault,
|
|
7315
7364
|
amount: mintValue
|
|
7316
7365
|
}),
|
|
7317
7366
|
{
|
|
@@ -7319,9 +7368,9 @@ function routeErc20NonBase() {
|
|
|
7319
7368
|
message: "Failed to simulate base token approve."
|
|
7320
7369
|
}
|
|
7321
7370
|
);
|
|
7322
|
-
approvals.push({ token: baseToken, spender:
|
|
7371
|
+
approvals.push({ token: baseToken, spender: nativeTokenVault, amount: mintValue });
|
|
7323
7372
|
steps.push({
|
|
7324
|
-
key: `approve:${baseToken}:${
|
|
7373
|
+
key: `approve:${baseToken}:${nativeTokenVault}`,
|
|
7325
7374
|
kind: "approve",
|
|
7326
7375
|
description: `Approve base token for mintValue`,
|
|
7327
7376
|
tx: approveBaseTx
|
|
@@ -7427,6 +7476,20 @@ var ntvCodec2 = createNTVCodec({
|
|
|
7427
7476
|
),
|
|
7428
7477
|
keccak256: viem.keccak256
|
|
7429
7478
|
});
|
|
7479
|
+
async function encodeSecondBridgeEthDepositCalldata(input) {
|
|
7480
|
+
const registeredAssetId = input.ctx.resolvedToken?.assetId;
|
|
7481
|
+
const assetId = registeredAssetId && registeredAssetId.toLowerCase() !== ZERO_ASSET_ID2 ? registeredAssetId : ntvCodec2.encodeAssetId(
|
|
7482
|
+
BigInt(await input.ctx.client.l1.getChainId()),
|
|
7483
|
+
L2_NATIVE_TOKEN_VAULT_ADDRESS,
|
|
7484
|
+
ETH_ADDRESS
|
|
7485
|
+
);
|
|
7486
|
+
const transferData = encodeNativeTokenVaultTransferData(
|
|
7487
|
+
input.amount,
|
|
7488
|
+
input.receiver,
|
|
7489
|
+
ETH_ADDRESS
|
|
7490
|
+
);
|
|
7491
|
+
return encodeSecondBridgeDataV1(assetId, transferData);
|
|
7492
|
+
}
|
|
7430
7493
|
async function getPriorityGasModel2(input) {
|
|
7431
7494
|
try {
|
|
7432
7495
|
const l1AssetRouter = await input.ctx.contracts.l1AssetRouter();
|
|
@@ -7460,9 +7523,18 @@ async function getPriorityGasModel2(input) {
|
|
|
7460
7523
|
gasPerPubdata: input.ctx.gasPerPubdata
|
|
7461
7524
|
});
|
|
7462
7525
|
const model = {
|
|
7463
|
-
|
|
7464
|
-
|
|
7465
|
-
|
|
7526
|
+
priorityTxL2Leg: {
|
|
7527
|
+
from: applyL1ToL2Alias(input.ctx.l1AssetRouter),
|
|
7528
|
+
to: L2_ASSET_ROUTER_ADDRESS,
|
|
7529
|
+
data: l2Calldata
|
|
7530
|
+
},
|
|
7531
|
+
priorityFloorGasLimit: clampPriorityL2GasLimit({
|
|
7532
|
+
gasLimit: applyPriorityL2GasLimitBuffer({
|
|
7533
|
+
chainIdL2: input.ctx.chainIdL2,
|
|
7534
|
+
gasLimit: priorityFloorBreakdown.derivedL2GasLimit
|
|
7535
|
+
}),
|
|
7536
|
+
l2Calldata,
|
|
7537
|
+
gasPerPubdata: input.ctx.gasPerPubdata
|
|
7466
7538
|
})
|
|
7467
7539
|
};
|
|
7468
7540
|
if (input.ctx.resolvedToken.l2.toLowerCase() === viem.zeroAddress) {
|
|
@@ -7537,6 +7609,7 @@ function routeEthNonBase() {
|
|
|
7537
7609
|
ctx,
|
|
7538
7610
|
modelTx: l2TxModel,
|
|
7539
7611
|
priorityFloorGasLimit: priorityGasModel.priorityFloorGasLimit,
|
|
7612
|
+
priorityTxL2Leg: priorityGasModel.priorityTxL2Leg,
|
|
7540
7613
|
undeployedGasLimit: priorityGasModel.undeployedGasLimit
|
|
7541
7614
|
});
|
|
7542
7615
|
if (!l2Gas) throw new Error("Failed to estimate L2 gas parameters.");
|
|
@@ -7551,10 +7624,10 @@ function routeEthNonBase() {
|
|
|
7551
7624
|
address: baseToken,
|
|
7552
7625
|
abi: IERC20_default,
|
|
7553
7626
|
functionName: "allowance",
|
|
7554
|
-
args: [ctx.sender, ctx.
|
|
7627
|
+
args: [ctx.sender, ctx.l1NativeTokenVault]
|
|
7555
7628
|
}),
|
|
7556
7629
|
{
|
|
7557
|
-
ctx: { where: "erc20.allowance", token: baseToken, spender: ctx.
|
|
7630
|
+
ctx: { where: "erc20.allowance", token: baseToken, spender: ctx.l1NativeTokenVault },
|
|
7558
7631
|
message: "Failed to read base-token allowance."
|
|
7559
7632
|
}
|
|
7560
7633
|
);
|
|
@@ -7566,7 +7639,7 @@ function routeEthNonBase() {
|
|
|
7566
7639
|
() => buildApprovalRequest({
|
|
7567
7640
|
ctx,
|
|
7568
7641
|
token: baseToken,
|
|
7569
|
-
spender: ctx.
|
|
7642
|
+
spender: ctx.l1NativeTokenVault,
|
|
7570
7643
|
amount: mintValue
|
|
7571
7644
|
}),
|
|
7572
7645
|
{
|
|
@@ -7574,9 +7647,9 @@ function routeEthNonBase() {
|
|
|
7574
7647
|
message: "Failed to simulate base-token approve."
|
|
7575
7648
|
}
|
|
7576
7649
|
);
|
|
7577
|
-
approvals.push({ token: baseToken, spender: ctx.
|
|
7650
|
+
approvals.push({ token: baseToken, spender: ctx.l1NativeTokenVault, amount: mintValue });
|
|
7578
7651
|
steps.push({
|
|
7579
|
-
key: `approve:${baseToken}:${ctx.
|
|
7652
|
+
key: `approve:${baseToken}:${ctx.l1NativeTokenVault}`,
|
|
7580
7653
|
kind: "approve",
|
|
7581
7654
|
description: `Approve base token for fees (mintValue)`,
|
|
7582
7655
|
tx: approveTx
|
|
@@ -7585,10 +7658,10 @@ function routeEthNonBase() {
|
|
|
7585
7658
|
const secondBridgeCalldata = await wrapAs4(
|
|
7586
7659
|
"INTERNAL",
|
|
7587
7660
|
OP_DEPOSITS.ethNonBase.encodeCalldata,
|
|
7588
|
-
() =>
|
|
7661
|
+
() => encodeSecondBridgeEthDepositCalldata({ ctx, amount: p.amount, receiver }),
|
|
7589
7662
|
{
|
|
7590
7663
|
ctx: {
|
|
7591
|
-
where: "
|
|
7664
|
+
where: "encodeSecondBridgeEthDepositCalldata",
|
|
7592
7665
|
amount: p.amount.toString(),
|
|
7593
7666
|
to: receiver
|
|
7594
7667
|
},
|
|
@@ -7729,9 +7802,13 @@ function routeErc20Base() {
|
|
|
7729
7802
|
l2Calldata,
|
|
7730
7803
|
gasPerPubdata: ctx.gasPerPubdata
|
|
7731
7804
|
});
|
|
7732
|
-
const quotedL2GasLimit = ctx.l2GasLimit ??
|
|
7733
|
-
|
|
7734
|
-
|
|
7805
|
+
const quotedL2GasLimit = ctx.l2GasLimit ?? clampPriorityL2GasLimit({
|
|
7806
|
+
gasLimit: applyPriorityL2GasLimitBuffer({
|
|
7807
|
+
chainIdL2: ctx.chainIdL2,
|
|
7808
|
+
gasLimit: priorityFloorBreakdown.derivedL2GasLimit
|
|
7809
|
+
}),
|
|
7810
|
+
l2Calldata,
|
|
7811
|
+
gasPerPubdata: ctx.gasPerPubdata
|
|
7735
7812
|
});
|
|
7736
7813
|
const l2Gas = await quoteL2Gas2({
|
|
7737
7814
|
ctx,
|
|
@@ -7750,10 +7827,10 @@ function routeErc20Base() {
|
|
|
7750
7827
|
address: baseToken,
|
|
7751
7828
|
abi: IERC20_default,
|
|
7752
7829
|
functionName: "allowance",
|
|
7753
|
-
args: [ctx.sender, ctx.
|
|
7830
|
+
args: [ctx.sender, ctx.l1NativeTokenVault]
|
|
7754
7831
|
}),
|
|
7755
7832
|
{
|
|
7756
|
-
ctx: { where: "erc20.allowance", token: baseToken, spender: ctx.
|
|
7833
|
+
ctx: { where: "erc20.allowance", token: baseToken, spender: ctx.l1NativeTokenVault },
|
|
7757
7834
|
message: "Failed to read base-token allowance."
|
|
7758
7835
|
}
|
|
7759
7836
|
);
|
|
@@ -7765,7 +7842,7 @@ function routeErc20Base() {
|
|
|
7765
7842
|
() => buildApprovalRequest({
|
|
7766
7843
|
ctx,
|
|
7767
7844
|
token: baseToken,
|
|
7768
|
-
spender: ctx.
|
|
7845
|
+
spender: ctx.l1NativeTokenVault,
|
|
7769
7846
|
amount: mintValue
|
|
7770
7847
|
}),
|
|
7771
7848
|
{
|
|
@@ -7773,9 +7850,9 @@ function routeErc20Base() {
|
|
|
7773
7850
|
message: "Failed to simulate ERC-20 approve."
|
|
7774
7851
|
}
|
|
7775
7852
|
);
|
|
7776
|
-
approvals.push({ token: baseToken, spender: ctx.
|
|
7853
|
+
approvals.push({ token: baseToken, spender: ctx.l1NativeTokenVault, amount: mintValue });
|
|
7777
7854
|
steps.push({
|
|
7778
|
-
key: `approve:${baseToken}:${ctx.
|
|
7855
|
+
key: `approve:${baseToken}:${ctx.l1NativeTokenVault}`,
|
|
7779
7856
|
kind: "approve",
|
|
7780
7857
|
description: "Approve base token for mintValue",
|
|
7781
7858
|
tx: approveTx
|
|
@@ -8021,8 +8098,17 @@ function createTokensResource(client) {
|
|
|
8021
8098
|
const chainId = BigInt(await client.l2.getChainId());
|
|
8022
8099
|
return await client.baseToken(chainId);
|
|
8023
8100
|
}
|
|
8024
|
-
const {
|
|
8025
|
-
const
|
|
8101
|
+
const { l2NativeTokenVault, l1NativeTokenVault } = await client.contracts();
|
|
8102
|
+
const assetId = await l2NativeTokenVault.read.assetId([l2Token]);
|
|
8103
|
+
if (BigInt(assetId) === 0n) {
|
|
8104
|
+
throw new Error(`Token ${l2Token} is not registered in the L2 NativeTokenVault.`);
|
|
8105
|
+
}
|
|
8106
|
+
const l1Token = await l1NativeTokenVault.read.tokenAddress([assetId]);
|
|
8107
|
+
if (BigInt(l1Token) === 0n) {
|
|
8108
|
+
throw new Error(
|
|
8109
|
+
`Token ${l2Token} has no L1 counterpart registered in the L1 NativeTokenVault.`
|
|
8110
|
+
);
|
|
8111
|
+
}
|
|
8026
8112
|
return l1Token;
|
|
8027
8113
|
});
|
|
8028
8114
|
}
|