@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,7 +1,7 @@
|
|
|
1
|
-
export { createViemClient } from '../../chunk-
|
|
2
|
-
import '../../chunk-
|
|
1
|
+
export { createViemClient } from '../../chunk-6WIAMFIW.js';
|
|
2
|
+
import '../../chunk-4M7VNYGC.js';
|
|
3
3
|
import '../../chunk-UMPAKZCQ.js';
|
|
4
4
|
import '../../chunk-BWKWWLY4.js';
|
|
5
|
-
import '../../chunk-
|
|
6
|
-
import '../../chunk-
|
|
7
|
-
import '../../chunk-
|
|
5
|
+
import '../../chunk-4GPIHYVF.js';
|
|
6
|
+
import '../../chunk-2DDJFHHD.js';
|
|
7
|
+
import '../../chunk-3IPSDGHO.js';
|
|
@@ -53,6 +53,14 @@ var L1_TX_DELTA_FACTORY_DEPS_L2_GAS = 2473n;
|
|
|
53
53
|
var L1_TX_DELTA_FACTORY_DEPS_PUBDATA = 64n;
|
|
54
54
|
var TX_SLOT_OVERHEAD_L2_GAS = 10000n;
|
|
55
55
|
var PRIORITY_TX_MAX_GAS_LIMIT = 72000000n;
|
|
56
|
+
var L1_TX_INTRINSIC_L2_GAS_ZKSYNC_OS = 21000n;
|
|
57
|
+
var L1_TX_CALLDATA_FLOOR_PRICE_L2_GAS_ZKSYNC_OS = 40n;
|
|
58
|
+
var L1_TX_INTRINSIC_PUBDATA_ZKSYNC_OS = 351n;
|
|
59
|
+
var MAX_NATIVE_COMPUTATIONAL_ZKSYNC_OS = 1n << 35n;
|
|
60
|
+
var L1_TX_NATIVE_PER_GAS = 100000000n;
|
|
61
|
+
var ZKSYNC_OS_PRIORITY_TX_TYPE = "0x7f";
|
|
62
|
+
var REGISTERED_TOKEN_BRIDGE_MINT_EXECUTION_GAS = 140000n;
|
|
63
|
+
var REGISTERED_TOKEN_BRIDGE_MINT_PUBDATA_BYTES = 300n;
|
|
56
64
|
|
|
57
65
|
// src/core/utils/addr.ts
|
|
58
66
|
function isAddress(x) {
|
|
@@ -3909,13 +3917,6 @@ var IL2AssetRouterABI = [
|
|
|
3909
3917
|
outputs: [{ name: "", type: "address", internalType: "address" }],
|
|
3910
3918
|
stateMutability: "view"
|
|
3911
3919
|
},
|
|
3912
|
-
{
|
|
3913
|
-
type: "function",
|
|
3914
|
-
name: "l1TokenAddress",
|
|
3915
|
-
inputs: [{ name: "_l2Token", type: "address", internalType: "address" }],
|
|
3916
|
-
outputs: [{ name: "", type: "address", internalType: "address" }],
|
|
3917
|
-
stateMutability: "view"
|
|
3918
|
-
},
|
|
3919
3920
|
{
|
|
3920
3921
|
type: "function",
|
|
3921
3922
|
name: "l2TokenAddress",
|
|
@@ -7876,7 +7877,7 @@ function toGasOverrides(overrides) {
|
|
|
7876
7877
|
|
|
7877
7878
|
// src/adapters/viem/resources/deposits/context.ts
|
|
7878
7879
|
async function commonCtx(p, client, tokens, contracts) {
|
|
7879
|
-
const { bridgehub, l1AssetRouter } = await contracts.addresses();
|
|
7880
|
+
const { bridgehub, l1AssetRouter, l1NativeTokenVault } = await contracts.addresses();
|
|
7880
7881
|
const chainId = await client.l2.getChainId();
|
|
7881
7882
|
const sender = client.account.address;
|
|
7882
7883
|
const gasPerPubdata = p.gasPerPubdata ?? 800n;
|
|
@@ -7904,6 +7905,7 @@ async function commonCtx(p, client, tokens, contracts) {
|
|
|
7904
7905
|
baseTokenL1,
|
|
7905
7906
|
baseIsEth,
|
|
7906
7907
|
l1AssetRouter,
|
|
7908
|
+
l1NativeTokenVault,
|
|
7907
7909
|
route,
|
|
7908
7910
|
bridgehub,
|
|
7909
7911
|
chainIdL2: BigInt(chainId),
|
|
@@ -8094,6 +8096,68 @@ async function quoteL2Gas(input) {
|
|
|
8094
8096
|
}
|
|
8095
8097
|
}
|
|
8096
8098
|
|
|
8099
|
+
// src/core/resources/deposits/priority.ts
|
|
8100
|
+
var PRIORITY_TX_ENCODING_STEP_BYTES = 544n;
|
|
8101
|
+
var L1_TO_L2_ALIAS_OFFSET = 0x1111000000000000000000000000000000001111n;
|
|
8102
|
+
var DEFAULT_PRIORITY_BODY_GAS_ESTIMATE_MULTIPLIER = 7n;
|
|
8103
|
+
var PRIORITY_L2_GAS_BUFFER = 40n;
|
|
8104
|
+
var maxBigInt2 = (a, b) => a > b ? a : b;
|
|
8105
|
+
var ceilDiv = (a, b) => (a + b - 1n) / b;
|
|
8106
|
+
function applyL1ToL2Alias(address) {
|
|
8107
|
+
return `0x${(BigInt(address) + L1_TO_L2_ALIAS_OFFSET & (1n << 160n) - 1n).toString(16).padStart(40, "0")}`;
|
|
8108
|
+
}
|
|
8109
|
+
function derivePriorityTxGasBreakdown(input) {
|
|
8110
|
+
const factoryDepsCount = input.factoryDepsCount ?? 0n;
|
|
8111
|
+
const minBodyGas = maxBigInt2(
|
|
8112
|
+
L1_TX_INTRINSIC_L2_GAS + ceilDiv(
|
|
8113
|
+
input.encodedLength * L1_TX_DELTA_544_ENCODING_BYTES,
|
|
8114
|
+
PRIORITY_TX_ENCODING_STEP_BYTES
|
|
8115
|
+
) + factoryDepsCount * L1_TX_DELTA_FACTORY_DEPS_L2_GAS,
|
|
8116
|
+
L1_TX_MIN_L2_GAS_BASE
|
|
8117
|
+
) + L1_TX_INTRINSIC_PUBDATA * input.gasPerPubdata + factoryDepsCount * L1_TX_DELTA_FACTORY_DEPS_PUBDATA * input.gasPerPubdata;
|
|
8118
|
+
const overhead = maxBigInt2(TX_SLOT_OVERHEAD_L2_GAS, TX_MEMORY_OVERHEAD_GAS * input.encodedLength);
|
|
8119
|
+
const derivedBodyGas = minBodyGas;
|
|
8120
|
+
return {
|
|
8121
|
+
encodedLength: input.encodedLength,
|
|
8122
|
+
minBodyGas,
|
|
8123
|
+
overhead,
|
|
8124
|
+
derivedBodyGas,
|
|
8125
|
+
derivedL2GasLimit: derivedBodyGas + overhead,
|
|
8126
|
+
priorityTxMaxGasLimit: PRIORITY_TX_MAX_GAS_LIMIT,
|
|
8127
|
+
priorityTxMaxGasLimitExceeded: derivedBodyGas > PRIORITY_TX_MAX_GAS_LIMIT
|
|
8128
|
+
};
|
|
8129
|
+
}
|
|
8130
|
+
function derivePriorityBodyGasEstimateCap(input) {
|
|
8131
|
+
return input.minBodyGas * (input.multiplier ?? DEFAULT_PRIORITY_BODY_GAS_ESTIMATE_MULTIPLIER);
|
|
8132
|
+
}
|
|
8133
|
+
function applyPriorityL2GasLimitBuffer(input) {
|
|
8134
|
+
return input.gasLimit * (100n + PRIORITY_L2_GAS_BUFFER) / 100n;
|
|
8135
|
+
}
|
|
8136
|
+
function minimalPriorityTxL2Gas(input) {
|
|
8137
|
+
const intrinsic = L1_TX_INTRINSIC_L2_GAS_ZKSYNC_OS + L1_TX_CALLDATA_FLOOR_PRICE_L2_GAS_ZKSYNC_OS * input.calldataLength;
|
|
8138
|
+
const pubdata = L1_TX_INTRINSIC_PUBDATA_ZKSYNC_OS * input.gasPerPubdata + ceilDiv(MAX_NATIVE_COMPUTATIONAL_ZKSYNC_OS, L1_TX_NATIVE_PER_GAS);
|
|
8139
|
+
return maxBigInt2(intrinsic, pubdata);
|
|
8140
|
+
}
|
|
8141
|
+
function clampPriorityL2GasLimit(input) {
|
|
8142
|
+
return maxBigInt2(
|
|
8143
|
+
input.gasLimit,
|
|
8144
|
+
minimalPriorityTxL2Gas({
|
|
8145
|
+
calldataLength: BigInt(Math.max(input.l2Calldata.length - 2, 0) / 2),
|
|
8146
|
+
gasPerPubdata: input.gasPerPubdata
|
|
8147
|
+
})
|
|
8148
|
+
);
|
|
8149
|
+
}
|
|
8150
|
+
function resolveRegisteredTokenPriorityL2GasLimit(input) {
|
|
8151
|
+
if (input.nodeEstimate != null && input.nodeEstimate > 0n) {
|
|
8152
|
+
return maxBigInt2(input.priorityFloorGasLimit, applyGasBuffer(input.nodeEstimate));
|
|
8153
|
+
}
|
|
8154
|
+
const modeledGas = REGISTERED_TOKEN_BRIDGE_MINT_EXECUTION_GAS + REGISTERED_TOKEN_BRIDGE_MINT_PUBDATA_BYTES * input.gasPerPubdata;
|
|
8155
|
+
return maxBigInt2(
|
|
8156
|
+
input.priorityFloorGasLimit,
|
|
8157
|
+
applyPriorityL2GasLimitBuffer({ gasLimit: modeledGas })
|
|
8158
|
+
);
|
|
8159
|
+
}
|
|
8160
|
+
|
|
8097
8161
|
// src/adapters/viem/estimator.ts
|
|
8098
8162
|
function toCoreTx(tx) {
|
|
8099
8163
|
return {
|
|
@@ -8145,6 +8209,20 @@ function viemToGasEstimator(client) {
|
|
|
8145
8209
|
maxPriorityFeePerGas: tx.maxPriorityFeePerGas
|
|
8146
8210
|
});
|
|
8147
8211
|
},
|
|
8212
|
+
async estimatePriorityTxGas(tx) {
|
|
8213
|
+
const result = await client.request({
|
|
8214
|
+
method: "eth_estimateGas",
|
|
8215
|
+
params: [
|
|
8216
|
+
{
|
|
8217
|
+
from: tx.from,
|
|
8218
|
+
to: tx.to,
|
|
8219
|
+
data: tx.data,
|
|
8220
|
+
type: ZKSYNC_OS_PRIORITY_TX_TYPE
|
|
8221
|
+
}
|
|
8222
|
+
]
|
|
8223
|
+
});
|
|
8224
|
+
return BigInt(result);
|
|
8225
|
+
},
|
|
8148
8226
|
async estimateFeesPerGas() {
|
|
8149
8227
|
try {
|
|
8150
8228
|
const fees = await client.estimateFeesPerGas();
|
|
@@ -8178,6 +8256,14 @@ function viemToGasEstimator(client) {
|
|
|
8178
8256
|
|
|
8179
8257
|
// src/adapters/viem/resources/deposits/services/gas.ts
|
|
8180
8258
|
var DEFAULT_SAFE_NONBASE_L2_GAS_LIMIT = 3000000n;
|
|
8259
|
+
async function estimatePriorityTxL2Gas(ctx, leg) {
|
|
8260
|
+
if (!leg) return void 0;
|
|
8261
|
+
try {
|
|
8262
|
+
return await viemToGasEstimator(ctx.client.l2).estimatePriorityTxGas?.(leg);
|
|
8263
|
+
} catch {
|
|
8264
|
+
return void 0;
|
|
8265
|
+
}
|
|
8266
|
+
}
|
|
8181
8267
|
async function quoteL1Gas2(input) {
|
|
8182
8268
|
const { ctx, tx, overrides, fallbackGasLimit } = input;
|
|
8183
8269
|
const estimator = viemToGasEstimator(ctx.client.l1);
|
|
@@ -8232,7 +8318,12 @@ async function determineNonBaseL2Gas(input) {
|
|
|
8232
8318
|
return quoteL2Gas2({
|
|
8233
8319
|
ctx,
|
|
8234
8320
|
route,
|
|
8235
|
-
overrideGasLimit:
|
|
8321
|
+
overrideGasLimit: resolveRegisteredTokenPriorityL2GasLimit({
|
|
8322
|
+
chainIdL2: ctx.chainIdL2,
|
|
8323
|
+
priorityFloorGasLimit: input.priorityFloorGasLimit,
|
|
8324
|
+
gasPerPubdata: ctx.gasPerPubdata,
|
|
8325
|
+
nodeEstimate: await estimatePriorityTxL2Gas(ctx, input.priorityTxL2Leg)
|
|
8326
|
+
})
|
|
8236
8327
|
});
|
|
8237
8328
|
}
|
|
8238
8329
|
const modelTx = {
|
|
@@ -8269,6 +8360,7 @@ async function determineEthNonBaseL2Gas(input) {
|
|
|
8269
8360
|
knownL2Token: input.ctx.resolvedToken?.l2,
|
|
8270
8361
|
modelTx: input.modelTx,
|
|
8271
8362
|
priorityFloorGasLimit: input.priorityFloorGasLimit,
|
|
8363
|
+
priorityTxL2Leg: input.priorityTxL2Leg,
|
|
8272
8364
|
undeployedGasLimit: input.undeployedGasLimit
|
|
8273
8365
|
});
|
|
8274
8366
|
}
|
|
@@ -8322,40 +8414,6 @@ function buildFeeBreakdown(p) {
|
|
|
8322
8414
|
l2
|
|
8323
8415
|
};
|
|
8324
8416
|
}
|
|
8325
|
-
|
|
8326
|
-
// src/core/resources/deposits/priority.ts
|
|
8327
|
-
var PRIORITY_TX_ENCODING_STEP_BYTES = 544n;
|
|
8328
|
-
var DEFAULT_PRIORITY_BODY_GAS_ESTIMATE_MULTIPLIER = 7n;
|
|
8329
|
-
var PRIORITY_L2_GAS_BUFFER = 40n;
|
|
8330
|
-
var maxBigInt2 = (a, b) => a > b ? a : b;
|
|
8331
|
-
var ceilDiv = (a, b) => (a + b - 1n) / b;
|
|
8332
|
-
function derivePriorityTxGasBreakdown(input) {
|
|
8333
|
-
const factoryDepsCount = input.factoryDepsCount ?? 0n;
|
|
8334
|
-
const minBodyGas = maxBigInt2(
|
|
8335
|
-
L1_TX_INTRINSIC_L2_GAS + ceilDiv(
|
|
8336
|
-
input.encodedLength * L1_TX_DELTA_544_ENCODING_BYTES,
|
|
8337
|
-
PRIORITY_TX_ENCODING_STEP_BYTES
|
|
8338
|
-
) + factoryDepsCount * L1_TX_DELTA_FACTORY_DEPS_L2_GAS,
|
|
8339
|
-
L1_TX_MIN_L2_GAS_BASE
|
|
8340
|
-
) + L1_TX_INTRINSIC_PUBDATA * input.gasPerPubdata + factoryDepsCount * L1_TX_DELTA_FACTORY_DEPS_PUBDATA * input.gasPerPubdata;
|
|
8341
|
-
const overhead = maxBigInt2(TX_SLOT_OVERHEAD_L2_GAS, TX_MEMORY_OVERHEAD_GAS * input.encodedLength);
|
|
8342
|
-
const derivedBodyGas = minBodyGas;
|
|
8343
|
-
return {
|
|
8344
|
-
encodedLength: input.encodedLength,
|
|
8345
|
-
minBodyGas,
|
|
8346
|
-
overhead,
|
|
8347
|
-
derivedBodyGas,
|
|
8348
|
-
derivedL2GasLimit: derivedBodyGas + overhead,
|
|
8349
|
-
priorityTxMaxGasLimit: PRIORITY_TX_MAX_GAS_LIMIT,
|
|
8350
|
-
priorityTxMaxGasLimitExceeded: derivedBodyGas > PRIORITY_TX_MAX_GAS_LIMIT
|
|
8351
|
-
};
|
|
8352
|
-
}
|
|
8353
|
-
function derivePriorityBodyGasEstimateCap(input) {
|
|
8354
|
-
return input.minBodyGas * (input.multiplier ?? DEFAULT_PRIORITY_BODY_GAS_ESTIMATE_MULTIPLIER);
|
|
8355
|
-
}
|
|
8356
|
-
function applyPriorityL2GasLimitBuffer(input) {
|
|
8357
|
-
return input.gasLimit * (100n + PRIORITY_L2_GAS_BUFFER) / 100n;
|
|
8358
|
-
}
|
|
8359
8417
|
var EMPTY_BYTES = "0x";
|
|
8360
8418
|
var ZERO_RESERVED_WORDS = [0n, 0n, 0n, 0n];
|
|
8361
8419
|
var L2_CANONICAL_TRANSACTION_PARAMETER = {
|
|
@@ -8432,9 +8490,13 @@ function routeEthDirect() {
|
|
|
8432
8490
|
l2Calldata,
|
|
8433
8491
|
gasPerPubdata: ctx.gasPerPubdata
|
|
8434
8492
|
});
|
|
8435
|
-
const quotedL2GasLimit = ctx.l2GasLimit ??
|
|
8436
|
-
|
|
8437
|
-
|
|
8493
|
+
const quotedL2GasLimit = ctx.l2GasLimit ?? clampPriorityL2GasLimit({
|
|
8494
|
+
gasLimit: applyPriorityL2GasLimitBuffer({
|
|
8495
|
+
chainIdL2: ctx.chainIdL2,
|
|
8496
|
+
gasLimit: priorityFloorBreakdown.derivedL2GasLimit
|
|
8497
|
+
}),
|
|
8498
|
+
l2Calldata,
|
|
8499
|
+
gasPerPubdata: ctx.gasPerPubdata
|
|
8438
8500
|
});
|
|
8439
8501
|
const l2GasParams = await quoteL2Gas2({
|
|
8440
8502
|
ctx,
|
|
@@ -8594,26 +8656,18 @@ var ntvCodec = createNTVCodec({
|
|
|
8594
8656
|
keccak256: viem.keccak256
|
|
8595
8657
|
});
|
|
8596
8658
|
async function encodeSecondBridgeErc20DepositCalldata(input) {
|
|
8597
|
-
|
|
8598
|
-
|
|
8599
|
-
|
|
8600
|
-
const l1ChainId = BigInt(await input.ctx.client.l1.getChainId());
|
|
8601
|
-
const expectedL1AssetId = ntvCodec.encodeAssetId(
|
|
8602
|
-
l1ChainId,
|
|
8659
|
+
const registeredAssetId = input.ctx.resolvedToken?.assetId;
|
|
8660
|
+
const assetId = registeredAssetId && registeredAssetId.toLowerCase() !== ZERO_ASSET_ID ? registeredAssetId : ntvCodec.encodeAssetId(
|
|
8661
|
+
BigInt(await input.ctx.client.l1.getChainId()),
|
|
8603
8662
|
L2_NATIVE_TOKEN_VAULT_ADDRESS,
|
|
8604
8663
|
input.token
|
|
8605
8664
|
);
|
|
8606
|
-
const assetId = input.ctx.resolvedToken.assetId.toLowerCase();
|
|
8607
|
-
const isL1Origin = assetId === ZERO_ASSET_ID || assetId === expectedL1AssetId.toLowerCase();
|
|
8608
|
-
if (isL1Origin) {
|
|
8609
|
-
return encodeSecondBridgeErc20Args(input.token, input.amount, input.receiver);
|
|
8610
|
-
}
|
|
8611
8665
|
const transferData = encodeNativeTokenVaultTransferData(
|
|
8612
8666
|
input.amount,
|
|
8613
8667
|
input.receiver,
|
|
8614
8668
|
input.token
|
|
8615
8669
|
);
|
|
8616
|
-
return encodeSecondBridgeDataV1(
|
|
8670
|
+
return encodeSecondBridgeDataV1(assetId, transferData);
|
|
8617
8671
|
}
|
|
8618
8672
|
async function getPriorityGasModel(input) {
|
|
8619
8673
|
try {
|
|
@@ -8655,9 +8709,18 @@ async function getPriorityGasModel(input) {
|
|
|
8655
8709
|
gasPerPubdata: input.ctx.gasPerPubdata
|
|
8656
8710
|
});
|
|
8657
8711
|
const model = {
|
|
8658
|
-
|
|
8659
|
-
|
|
8660
|
-
|
|
8712
|
+
priorityTxL2Leg: {
|
|
8713
|
+
from: applyL1ToL2Alias(input.ctx.l1AssetRouter),
|
|
8714
|
+
to: L2_ASSET_ROUTER_ADDRESS,
|
|
8715
|
+
data: l2Calldata
|
|
8716
|
+
},
|
|
8717
|
+
priorityFloorGasLimit: clampPriorityL2GasLimit({
|
|
8718
|
+
gasLimit: applyPriorityL2GasLimitBuffer({
|
|
8719
|
+
chainIdL2: input.ctx.chainIdL2,
|
|
8720
|
+
gasLimit: priorityFloorBreakdown.derivedL2GasLimit
|
|
8721
|
+
}),
|
|
8722
|
+
l2Calldata,
|
|
8723
|
+
gasPerPubdata: input.ctx.gasPerPubdata
|
|
8661
8724
|
})
|
|
8662
8725
|
};
|
|
8663
8726
|
if (isFirstBridge || input.ctx.resolvedToken.l2.toLowerCase() === viem.zeroAddress) {
|
|
@@ -8700,6 +8763,7 @@ function routeErc20NonBase() {
|
|
|
8700
8763
|
const baseToken = ctx.baseTokenL1 ?? await ctx.client.baseToken(ctx.chainIdL2);
|
|
8701
8764
|
const baseIsEth = ctx.baseIsEth ?? isETH(baseToken);
|
|
8702
8765
|
const assetRouter = ctx.l1AssetRouter;
|
|
8766
|
+
const nativeTokenVault = ctx.l1NativeTokenVault;
|
|
8703
8767
|
const receiver = p.to ?? ctx.sender;
|
|
8704
8768
|
const secondBridgeCalldata = await wrapAs3(
|
|
8705
8769
|
"INTERNAL",
|
|
@@ -8729,6 +8793,7 @@ function routeErc20NonBase() {
|
|
|
8729
8793
|
ctx,
|
|
8730
8794
|
l1Token: p.token,
|
|
8731
8795
|
priorityFloorGasLimit: priorityGasModel.priorityFloorGasLimit,
|
|
8796
|
+
priorityTxL2Leg: priorityGasModel.priorityTxL2Leg,
|
|
8732
8797
|
undeployedGasLimit: priorityGasModel.undeployedGasLimit,
|
|
8733
8798
|
modelTx: {
|
|
8734
8799
|
to: receiver,
|
|
@@ -8749,10 +8814,10 @@ function routeErc20NonBase() {
|
|
|
8749
8814
|
address: p.token,
|
|
8750
8815
|
abi: IERC20_default,
|
|
8751
8816
|
functionName: "allowance",
|
|
8752
|
-
args: [ctx.sender,
|
|
8817
|
+
args: [ctx.sender, nativeTokenVault]
|
|
8753
8818
|
}),
|
|
8754
8819
|
{
|
|
8755
|
-
ctx: { where: "erc20.allowance", token: p.token, spender:
|
|
8820
|
+
ctx: { where: "erc20.allowance", token: p.token, spender: nativeTokenVault },
|
|
8756
8821
|
message: "Failed to read deposit-token allowance."
|
|
8757
8822
|
}
|
|
8758
8823
|
);
|
|
@@ -8763,7 +8828,7 @@ function routeErc20NonBase() {
|
|
|
8763
8828
|
() => buildApprovalRequest({
|
|
8764
8829
|
ctx,
|
|
8765
8830
|
token: p.token,
|
|
8766
|
-
spender:
|
|
8831
|
+
spender: nativeTokenVault,
|
|
8767
8832
|
amount: p.amount
|
|
8768
8833
|
}),
|
|
8769
8834
|
{
|
|
@@ -8771,9 +8836,9 @@ function routeErc20NonBase() {
|
|
|
8771
8836
|
message: "Failed to simulate deposit token approve."
|
|
8772
8837
|
}
|
|
8773
8838
|
);
|
|
8774
|
-
approvals.push({ token: p.token, spender:
|
|
8839
|
+
approvals.push({ token: p.token, spender: nativeTokenVault, amount: p.amount });
|
|
8775
8840
|
steps.push({
|
|
8776
|
-
key: `approve:${p.token}:${
|
|
8841
|
+
key: `approve:${p.token}:${nativeTokenVault}`,
|
|
8777
8842
|
kind: "approve",
|
|
8778
8843
|
description: `Approve deposit token for amount`,
|
|
8779
8844
|
tx: approveTx
|
|
@@ -8787,10 +8852,10 @@ function routeErc20NonBase() {
|
|
|
8787
8852
|
address: baseToken,
|
|
8788
8853
|
abi: IERC20_default,
|
|
8789
8854
|
functionName: "allowance",
|
|
8790
|
-
args: [ctx.sender,
|
|
8855
|
+
args: [ctx.sender, nativeTokenVault]
|
|
8791
8856
|
}),
|
|
8792
8857
|
{
|
|
8793
|
-
ctx: { where: "erc20.allowance", token: baseToken, spender:
|
|
8858
|
+
ctx: { where: "erc20.allowance", token: baseToken, spender: nativeTokenVault },
|
|
8794
8859
|
message: "Failed to read base-token allowance."
|
|
8795
8860
|
}
|
|
8796
8861
|
);
|
|
@@ -8801,7 +8866,7 @@ function routeErc20NonBase() {
|
|
|
8801
8866
|
() => buildApprovalRequest({
|
|
8802
8867
|
ctx,
|
|
8803
8868
|
token: baseToken,
|
|
8804
|
-
spender:
|
|
8869
|
+
spender: nativeTokenVault,
|
|
8805
8870
|
amount: mintValue
|
|
8806
8871
|
}),
|
|
8807
8872
|
{
|
|
@@ -8809,9 +8874,9 @@ function routeErc20NonBase() {
|
|
|
8809
8874
|
message: "Failed to simulate base token approve."
|
|
8810
8875
|
}
|
|
8811
8876
|
);
|
|
8812
|
-
approvals.push({ token: baseToken, spender:
|
|
8877
|
+
approvals.push({ token: baseToken, spender: nativeTokenVault, amount: mintValue });
|
|
8813
8878
|
steps.push({
|
|
8814
|
-
key: `approve:${baseToken}:${
|
|
8879
|
+
key: `approve:${baseToken}:${nativeTokenVault}`,
|
|
8815
8880
|
kind: "approve",
|
|
8816
8881
|
description: `Approve base token for mintValue`,
|
|
8817
8882
|
tx: approveBaseTx
|
|
@@ -8950,9 +9015,18 @@ async function getPriorityGasModel2(input) {
|
|
|
8950
9015
|
gasPerPubdata: input.ctx.gasPerPubdata
|
|
8951
9016
|
});
|
|
8952
9017
|
const model = {
|
|
8953
|
-
|
|
8954
|
-
|
|
8955
|
-
|
|
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
|
|
8956
9030
|
})
|
|
8957
9031
|
};
|
|
8958
9032
|
if (input.ctx.resolvedToken.l2.toLowerCase() === viem.zeroAddress) {
|
|
@@ -9027,6 +9101,7 @@ function routeEthNonBase() {
|
|
|
9027
9101
|
ctx,
|
|
9028
9102
|
modelTx: l2TxModel,
|
|
9029
9103
|
priorityFloorGasLimit: priorityGasModel.priorityFloorGasLimit,
|
|
9104
|
+
priorityTxL2Leg: priorityGasModel.priorityTxL2Leg,
|
|
9030
9105
|
undeployedGasLimit: priorityGasModel.undeployedGasLimit
|
|
9031
9106
|
});
|
|
9032
9107
|
if (!l2Gas) throw new Error("Failed to estimate L2 gas parameters.");
|
|
@@ -9041,10 +9116,10 @@ function routeEthNonBase() {
|
|
|
9041
9116
|
address: baseToken,
|
|
9042
9117
|
abi: IERC20_default,
|
|
9043
9118
|
functionName: "allowance",
|
|
9044
|
-
args: [ctx.sender, ctx.
|
|
9119
|
+
args: [ctx.sender, ctx.l1NativeTokenVault]
|
|
9045
9120
|
}),
|
|
9046
9121
|
{
|
|
9047
|
-
ctx: { where: "erc20.allowance", token: baseToken, spender: ctx.
|
|
9122
|
+
ctx: { where: "erc20.allowance", token: baseToken, spender: ctx.l1NativeTokenVault },
|
|
9048
9123
|
message: "Failed to read base-token allowance."
|
|
9049
9124
|
}
|
|
9050
9125
|
);
|
|
@@ -9056,7 +9131,7 @@ function routeEthNonBase() {
|
|
|
9056
9131
|
() => buildApprovalRequest({
|
|
9057
9132
|
ctx,
|
|
9058
9133
|
token: baseToken,
|
|
9059
|
-
spender: ctx.
|
|
9134
|
+
spender: ctx.l1NativeTokenVault,
|
|
9060
9135
|
amount: mintValue
|
|
9061
9136
|
}),
|
|
9062
9137
|
{
|
|
@@ -9064,9 +9139,9 @@ function routeEthNonBase() {
|
|
|
9064
9139
|
message: "Failed to simulate base-token approve."
|
|
9065
9140
|
}
|
|
9066
9141
|
);
|
|
9067
|
-
approvals.push({ token: baseToken, spender: ctx.
|
|
9142
|
+
approvals.push({ token: baseToken, spender: ctx.l1NativeTokenVault, amount: mintValue });
|
|
9068
9143
|
steps.push({
|
|
9069
|
-
key: `approve:${baseToken}:${ctx.
|
|
9144
|
+
key: `approve:${baseToken}:${ctx.l1NativeTokenVault}`,
|
|
9070
9145
|
kind: "approve",
|
|
9071
9146
|
description: `Approve base token for fees (mintValue)`,
|
|
9072
9147
|
tx: approveTx
|
|
@@ -9219,9 +9294,13 @@ function routeErc20Base() {
|
|
|
9219
9294
|
l2Calldata,
|
|
9220
9295
|
gasPerPubdata: ctx.gasPerPubdata
|
|
9221
9296
|
});
|
|
9222
|
-
const quotedL2GasLimit = ctx.l2GasLimit ??
|
|
9223
|
-
|
|
9224
|
-
|
|
9297
|
+
const quotedL2GasLimit = ctx.l2GasLimit ?? clampPriorityL2GasLimit({
|
|
9298
|
+
gasLimit: applyPriorityL2GasLimitBuffer({
|
|
9299
|
+
chainIdL2: ctx.chainIdL2,
|
|
9300
|
+
gasLimit: priorityFloorBreakdown.derivedL2GasLimit
|
|
9301
|
+
}),
|
|
9302
|
+
l2Calldata,
|
|
9303
|
+
gasPerPubdata: ctx.gasPerPubdata
|
|
9225
9304
|
});
|
|
9226
9305
|
const l2Gas = await quoteL2Gas2({
|
|
9227
9306
|
ctx,
|
|
@@ -9240,10 +9319,10 @@ function routeErc20Base() {
|
|
|
9240
9319
|
address: baseToken,
|
|
9241
9320
|
abi: IERC20_default,
|
|
9242
9321
|
functionName: "allowance",
|
|
9243
|
-
args: [ctx.sender, ctx.
|
|
9322
|
+
args: [ctx.sender, ctx.l1NativeTokenVault]
|
|
9244
9323
|
}),
|
|
9245
9324
|
{
|
|
9246
|
-
ctx: { where: "erc20.allowance", token: baseToken, spender: ctx.
|
|
9325
|
+
ctx: { where: "erc20.allowance", token: baseToken, spender: ctx.l1NativeTokenVault },
|
|
9247
9326
|
message: "Failed to read base-token allowance."
|
|
9248
9327
|
}
|
|
9249
9328
|
);
|
|
@@ -9255,7 +9334,7 @@ function routeErc20Base() {
|
|
|
9255
9334
|
() => buildApprovalRequest({
|
|
9256
9335
|
ctx,
|
|
9257
9336
|
token: baseToken,
|
|
9258
|
-
spender: ctx.
|
|
9337
|
+
spender: ctx.l1NativeTokenVault,
|
|
9259
9338
|
amount: mintValue
|
|
9260
9339
|
}),
|
|
9261
9340
|
{
|
|
@@ -9263,9 +9342,9 @@ function routeErc20Base() {
|
|
|
9263
9342
|
message: "Failed to simulate ERC-20 approve."
|
|
9264
9343
|
}
|
|
9265
9344
|
);
|
|
9266
|
-
approvals.push({ token: baseToken, spender: ctx.
|
|
9345
|
+
approvals.push({ token: baseToken, spender: ctx.l1NativeTokenVault, amount: mintValue });
|
|
9267
9346
|
steps.push({
|
|
9268
|
-
key: `approve:${baseToken}:${ctx.
|
|
9347
|
+
key: `approve:${baseToken}:${ctx.l1NativeTokenVault}`,
|
|
9269
9348
|
kind: "approve",
|
|
9270
9349
|
description: "Approve base token for mintValue",
|
|
9271
9350
|
tx: approveTx
|
|
@@ -9511,8 +9590,17 @@ function createTokensResource(client) {
|
|
|
9511
9590
|
const chainId = BigInt(await client.l2.getChainId());
|
|
9512
9591
|
return await client.baseToken(chainId);
|
|
9513
9592
|
}
|
|
9514
|
-
const {
|
|
9515
|
-
const
|
|
9593
|
+
const { l2NativeTokenVault, l1NativeTokenVault } = await client.contracts();
|
|
9594
|
+
const assetId = await l2NativeTokenVault.read.assetId([l2Token]);
|
|
9595
|
+
if (BigInt(assetId) === 0n) {
|
|
9596
|
+
throw new Error(`Token ${l2Token} is not registered in the L2 NativeTokenVault.`);
|
|
9597
|
+
}
|
|
9598
|
+
const l1Token = await l1NativeTokenVault.read.tokenAddress([assetId]);
|
|
9599
|
+
if (BigInt(l1Token) === 0n) {
|
|
9600
|
+
throw new Error(
|
|
9601
|
+
`Token ${l2Token} has no L1 counterpart registered in the L1 NativeTokenVault.`
|
|
9602
|
+
);
|
|
9603
|
+
}
|
|
9516
9604
|
return l1Token;
|
|
9517
9605
|
});
|
|
9518
9606
|
}
|