@matterlabs/zksync-js 0.0.23 → 0.0.25
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.js +4 -4
- package/dist/adapters/ethers/index.cjs +155 -82
- package/dist/adapters/ethers/index.cjs.map +1 -1
- package/dist/adapters/ethers/index.js +7 -7
- package/dist/adapters/ethers/resources/deposits/services/fee.d.ts +1 -0
- package/dist/adapters/ethers/resources/deposits/services/gas.d.ts +9 -2
- package/dist/adapters/ethers/sdk.cjs +155 -91
- package/dist/adapters/ethers/sdk.cjs.map +1 -1
- package/dist/adapters/ethers/sdk.js +6 -6
- package/dist/adapters/viem/client.js +4 -4
- package/dist/adapters/viem/index.cjs +182 -122
- package/dist/adapters/viem/index.cjs.map +1 -1
- package/dist/adapters/viem/index.js +7 -7
- package/dist/adapters/viem/resources/deposits/services/fee.d.ts +1 -0
- package/dist/adapters/viem/resources/deposits/services/gas.d.ts +9 -2
- package/dist/adapters/viem/sdk.cjs +182 -135
- package/dist/adapters/viem/sdk.cjs.map +1 -1
- package/dist/adapters/viem/sdk.js +6 -6
- package/dist/{chunk-4GPIHYVF.js → chunk-4ZANKNIK.js} +1 -1
- package/dist/{chunk-JJ523MOL.js → chunk-BQ2YCWV2.js} +1 -1
- package/dist/{chunk-4M7VNYGC.js → chunk-H5A6GU3D.js} +2 -2
- package/dist/{chunk-2DDJFHHD.js → chunk-JNS4XZE2.js} +1 -1
- package/dist/{chunk-WPCZNITC.js → chunk-JWN26CQ6.js} +31 -11
- package/dist/{chunk-V2TDNGI5.js → chunk-N5E4FLBF.js} +127 -74
- package/dist/{chunk-NVOFHV3A.js → chunk-NFRRRT5X.js} +155 -120
- package/dist/{chunk-URHDNDFN.js → chunk-PNTR5FTL.js} +2 -2
- package/dist/{chunk-TUN6NH5D.js → chunk-RZH7HBH3.js} +2 -2
- package/dist/{chunk-6WIAMFIW.js → chunk-YEA74D2L.js} +2 -2
- package/dist/{chunk-X2JJDQ4O.js → chunk-YGXEIOK6.js} +1 -1
- package/dist/core/index.js +3 -3
- package/dist/core/resources/deposits/gas.d.ts +11 -1
- package/dist/core/types/errors.d.ts +1 -1
- package/dist/index.js +2 -2
- package/package.json +1 -1
|
@@ -330,7 +330,7 @@ var OP_DEPOSITS = {
|
|
|
330
330
|
ethNonBase: {
|
|
331
331
|
allowanceBase: "deposits.eth-nonbase:allowanceBaseToken",
|
|
332
332
|
ethBalance: "deposits.eth-nonbase:getEthBalance",
|
|
333
|
-
encodeCalldata: "deposits.eth-nonbase:
|
|
333
|
+
encodeCalldata: "deposits.eth-nonbase:encodeSecondBridgeEthDepositCalldata",
|
|
334
334
|
estGas: "deposits.eth-nonbase:estimateGas",
|
|
335
335
|
assertEthAsset: "deposits.eth-nonbase:assertEthAsset",
|
|
336
336
|
assertNonEthBase: "deposits.eth-nonbase:assertNonEthBase",
|
|
@@ -7483,7 +7483,7 @@ function createErrorOps(decodeRevert2) {
|
|
|
7483
7483
|
function wrap8(operation, fn, opts) {
|
|
7484
7484
|
return run("INTERNAL", operation, fn, opts);
|
|
7485
7485
|
}
|
|
7486
|
-
function
|
|
7486
|
+
function wrapAs12(kind, operation, fn, opts) {
|
|
7487
7487
|
return run(kind, operation, fn, opts);
|
|
7488
7488
|
}
|
|
7489
7489
|
async function toResult3(operation, fn, opts) {
|
|
@@ -7504,7 +7504,7 @@ function createErrorOps(decodeRevert2) {
|
|
|
7504
7504
|
return { ok: false, error: shaped };
|
|
7505
7505
|
}
|
|
7506
7506
|
}
|
|
7507
|
-
return { wrap: wrap8, wrapAs:
|
|
7507
|
+
return { wrap: wrap8, wrapAs: wrapAs12, toResult: toResult3 };
|
|
7508
7508
|
}
|
|
7509
7509
|
return { toZKsyncError: toZKsyncError2, createErrorHandlers: createErrorHandlers2 };
|
|
7510
7510
|
}
|
|
@@ -7975,6 +7975,7 @@ function isEraVmChain(chainIdL2) {
|
|
|
7975
7975
|
|
|
7976
7976
|
// src/core/resources/deposits/gas.ts
|
|
7977
7977
|
var CREATE_REESTIMATE_BUFFER = 15n;
|
|
7978
|
+
var ZERO_FEES = { maxFeePerGas: 0n, maxPriorityFeePerGas: 0n };
|
|
7978
7979
|
var maxBigInt = (a, b) => a > b ? a : b;
|
|
7979
7980
|
function applyGasBuffer(gasLimit, bufferPct = BUFFER) {
|
|
7980
7981
|
return gasLimit * (100n + bufferPct) / 100n;
|
|
@@ -8025,15 +8026,39 @@ async function fetchFees(estimator) {
|
|
|
8025
8026
|
const gp = await estimator.getGasPrice();
|
|
8026
8027
|
return { maxFeePerGas: gp, maxPriorityFeePerGas: 0n };
|
|
8027
8028
|
} catch {
|
|
8028
|
-
return
|
|
8029
|
+
return void 0;
|
|
8030
|
+
}
|
|
8031
|
+
}
|
|
8032
|
+
async function quoteL1Fees(input) {
|
|
8033
|
+
const { estimator, overrides } = input;
|
|
8034
|
+
const maxFeeOverride = overrides?.maxFeePerGas;
|
|
8035
|
+
const tipOverride = overrides?.maxPriorityFeePerGas;
|
|
8036
|
+
if (maxFeeOverride != null && tipOverride != null) {
|
|
8037
|
+
return { maxFeePerGas: maxFeeOverride, maxPriorityFeePerGas: tipOverride };
|
|
8038
|
+
}
|
|
8039
|
+
const market = await fetchFees(estimator);
|
|
8040
|
+
if (maxFeeOverride != null) {
|
|
8041
|
+
const tip = market?.maxPriorityFeePerGas ?? 0n;
|
|
8042
|
+
return {
|
|
8043
|
+
maxFeePerGas: maxFeeOverride,
|
|
8044
|
+
maxPriorityFeePerGas: tip < maxFeeOverride ? tip : maxFeeOverride
|
|
8045
|
+
};
|
|
8046
|
+
}
|
|
8047
|
+
if (market == null) {
|
|
8048
|
+
throw new Error("Could not fetch L1 gas price for Bridgehub base cost calculation.");
|
|
8029
8049
|
}
|
|
8050
|
+
if (tipOverride != null) {
|
|
8051
|
+
const headroom = market.maxFeePerGas > market.maxPriorityFeePerGas ? market.maxFeePerGas - market.maxPriorityFeePerGas : 0n;
|
|
8052
|
+
return { maxFeePerGas: headroom + tipOverride, maxPriorityFeePerGas: tipOverride };
|
|
8053
|
+
}
|
|
8054
|
+
return market;
|
|
8030
8055
|
}
|
|
8031
8056
|
async function quoteL1Gas(input) {
|
|
8032
8057
|
const { estimator, tx, overrides, fallbackGasLimit } = input;
|
|
8033
8058
|
let market;
|
|
8034
8059
|
const getMarket = async () => {
|
|
8035
8060
|
if (market) return market;
|
|
8036
|
-
market = await fetchFees(estimator);
|
|
8061
|
+
market = await fetchFees(estimator) ?? ZERO_FEES;
|
|
8037
8062
|
return market;
|
|
8038
8063
|
};
|
|
8039
8064
|
const maxFeePerGas = overrides?.maxFeePerGas ?? (tx.maxFeePerGas != null ? BigInt(tx.maxFeePerGas) : (await getMarket()).maxFeePerGas);
|
|
@@ -8055,7 +8080,7 @@ async function quoteL1Gas(input) {
|
|
|
8055
8080
|
}
|
|
8056
8081
|
async function quoteL2Gas(input) {
|
|
8057
8082
|
const { estimator, route, tx, gasPerPubdata, l2GasLimit, overrideGasLimit, stateOverrides } = input;
|
|
8058
|
-
const market = await fetchFees(estimator);
|
|
8083
|
+
const market = await fetchFees(estimator) ?? ZERO_FEES;
|
|
8059
8084
|
const maxFeePerGas = market.maxFeePerGas || market.maxPriorityFeePerGas || 0n;
|
|
8060
8085
|
const txGasLimit = tx?.gasLimit != null ? BigInt(tx.gasLimit) : void 0;
|
|
8061
8086
|
const explicit = overrideGasLimit ?? txGasLimit;
|
|
@@ -8255,6 +8280,7 @@ function viemToGasEstimator(client) {
|
|
|
8255
8280
|
}
|
|
8256
8281
|
|
|
8257
8282
|
// src/adapters/viem/resources/deposits/services/gas.ts
|
|
8283
|
+
var { wrapAs } = createErrorHandlers("deposits");
|
|
8258
8284
|
var DEFAULT_SAFE_NONBASE_L2_GAS_LIMIT = 3000000n;
|
|
8259
8285
|
async function estimatePriorityTxL2Gas(ctx, leg) {
|
|
8260
8286
|
if (!leg) return void 0;
|
|
@@ -8264,6 +8290,18 @@ async function estimatePriorityTxL2Gas(ctx, leg) {
|
|
|
8264
8290
|
return void 0;
|
|
8265
8291
|
}
|
|
8266
8292
|
}
|
|
8293
|
+
async function quoteL1Fees2(input) {
|
|
8294
|
+
const { ctx } = input;
|
|
8295
|
+
return wrapAs(
|
|
8296
|
+
"RPC",
|
|
8297
|
+
"deposits.fees.l1",
|
|
8298
|
+
() => quoteL1Fees({
|
|
8299
|
+
estimator: viemToGasEstimator(ctx.client.l1),
|
|
8300
|
+
overrides: ctx.gasOverrides
|
|
8301
|
+
}),
|
|
8302
|
+
{ ctx: { chainIdL2: ctx.chainIdL2 } }
|
|
8303
|
+
);
|
|
8304
|
+
}
|
|
8267
8305
|
async function quoteL1Gas2(input) {
|
|
8268
8306
|
const { ctx, tx, overrides, fallbackGasLimit } = input;
|
|
8269
8307
|
const estimator = viemToGasEstimator(ctx.client.l1);
|
|
@@ -8366,13 +8404,10 @@ async function determineEthNonBaseL2Gas(input) {
|
|
|
8366
8404
|
}
|
|
8367
8405
|
|
|
8368
8406
|
// src/adapters/viem/resources/deposits/services/fee.ts
|
|
8369
|
-
var { wrapAs } = createErrorHandlers("deposits");
|
|
8407
|
+
var { wrapAs: wrapAs2 } = createErrorHandlers("deposits");
|
|
8370
8408
|
async function quoteL2BaseCost(input) {
|
|
8371
|
-
const { ctx, l2GasLimit } = input;
|
|
8372
|
-
|
|
8373
|
-
const fees = await estimator.estimateFeesPerGas();
|
|
8374
|
-
const gasPrice = fees.maxFeePerGas ?? fees.gasPrice ?? await estimator.getGasPrice();
|
|
8375
|
-
return wrapAs(
|
|
8409
|
+
const { ctx, l2GasLimit, l1GasPrice } = input;
|
|
8410
|
+
return wrapAs2(
|
|
8376
8411
|
"RPC",
|
|
8377
8412
|
"deposits.fees.l2BaseCost",
|
|
8378
8413
|
async () => {
|
|
@@ -8380,7 +8415,7 @@ async function quoteL2BaseCost(input) {
|
|
|
8380
8415
|
address: ctx.bridgehub,
|
|
8381
8416
|
abi: IBridgehub_default,
|
|
8382
8417
|
functionName: "l2TransactionBaseCost",
|
|
8383
|
-
args: [ctx.chainIdL2,
|
|
8418
|
+
args: [ctx.chainIdL2, l1GasPrice, l2GasLimit, ctx.gasPerPubdata]
|
|
8384
8419
|
});
|
|
8385
8420
|
},
|
|
8386
8421
|
{ ctx: { chainIdL2: ctx.chainIdL2 } }
|
|
@@ -8475,7 +8510,7 @@ function getPriorityTxGasBreakdown(input) {
|
|
|
8475
8510
|
}
|
|
8476
8511
|
|
|
8477
8512
|
// src/adapters/viem/resources/deposits/routes/eth.ts
|
|
8478
|
-
var { wrapAs:
|
|
8513
|
+
var { wrapAs: wrapAs3 } = createErrorHandlers("deposits");
|
|
8479
8514
|
var EMPTY_BYTES2 = "0x";
|
|
8480
8515
|
function routeEthDirect() {
|
|
8481
8516
|
return {
|
|
@@ -8506,7 +8541,12 @@ function routeEthDirect() {
|
|
|
8506
8541
|
if (!l2GasParams) {
|
|
8507
8542
|
throw new Error("Failed to estimate L2 gas for deposit.");
|
|
8508
8543
|
}
|
|
8509
|
-
const
|
|
8544
|
+
const l1Fees = await quoteL1Fees2({ ctx });
|
|
8545
|
+
const baseCost = await quoteL2BaseCost({
|
|
8546
|
+
ctx,
|
|
8547
|
+
l2GasLimit: l2GasParams.gasLimit,
|
|
8548
|
+
l1GasPrice: l1Fees.maxFeePerGas
|
|
8549
|
+
});
|
|
8510
8550
|
const mintValue = baseCost + ctx.operatorTip + l2Value;
|
|
8511
8551
|
const req = buildDirectRequestStruct({
|
|
8512
8552
|
chainId: ctx.chainIdL2,
|
|
@@ -8517,7 +8557,7 @@ function routeEthDirect() {
|
|
|
8517
8557
|
l2Contract,
|
|
8518
8558
|
l2Value
|
|
8519
8559
|
});
|
|
8520
|
-
const sim = await
|
|
8560
|
+
const sim = await wrapAs3(
|
|
8521
8561
|
"RPC",
|
|
8522
8562
|
OP_DEPOSITS.eth.estGas,
|
|
8523
8563
|
() => ctx.client.l1.simulateContract({
|
|
@@ -8543,22 +8583,19 @@ function routeEthDirect() {
|
|
|
8543
8583
|
data,
|
|
8544
8584
|
value: mintValue,
|
|
8545
8585
|
from: ctx.sender,
|
|
8546
|
-
...ctx.gasOverrides
|
|
8586
|
+
...ctx.gasOverrides,
|
|
8587
|
+
...l1Fees
|
|
8547
8588
|
};
|
|
8548
8589
|
const l1Gas = await quoteL1Gas2({
|
|
8549
8590
|
ctx,
|
|
8550
8591
|
tx: l1TxCandidate,
|
|
8551
8592
|
overrides: ctx.gasOverrides
|
|
8552
8593
|
});
|
|
8553
|
-
|
|
8554
|
-
|
|
8555
|
-
|
|
8556
|
-
|
|
8557
|
-
|
|
8558
|
-
maxFeePerGas: l1Gas.maxFeePerGas,
|
|
8559
|
-
maxPriorityFeePerGas: l1Gas.maxPriorityFeePerGas
|
|
8560
|
-
};
|
|
8561
|
-
}
|
|
8594
|
+
const bridgeTx = {
|
|
8595
|
+
...sim.request,
|
|
8596
|
+
...l1Fees,
|
|
8597
|
+
...l1Gas ? { gas: l1Gas.gasLimit } : {}
|
|
8598
|
+
};
|
|
8562
8599
|
const steps = [
|
|
8563
8600
|
{
|
|
8564
8601
|
key: "bridgehub:direct",
|
|
@@ -8646,7 +8683,7 @@ async function buildApprovalRequest({
|
|
|
8646
8683
|
}
|
|
8647
8684
|
|
|
8648
8685
|
// src/adapters/viem/resources/deposits/routes/erc20-nonbase.ts
|
|
8649
|
-
var { wrapAs:
|
|
8686
|
+
var { wrapAs: wrapAs4 } = createErrorHandlers("deposits");
|
|
8650
8687
|
var ZERO_ASSET_ID = "0x0000000000000000000000000000000000000000000000000000000000000000";
|
|
8651
8688
|
var ntvCodec = createNTVCodec({
|
|
8652
8689
|
encode: (types, values) => viem.encodeAbiParameters(
|
|
@@ -8737,7 +8774,7 @@ function routeErc20NonBase() {
|
|
|
8737
8774
|
return {
|
|
8738
8775
|
// TODO: do we even need these validations?
|
|
8739
8776
|
async preflight(p, ctx) {
|
|
8740
|
-
await
|
|
8777
|
+
await wrapAs4(
|
|
8741
8778
|
"VALIDATION",
|
|
8742
8779
|
OP_DEPOSITS.nonbase.assertNotEthAsset,
|
|
8743
8780
|
() => {
|
|
@@ -8748,7 +8785,7 @@ function routeErc20NonBase() {
|
|
|
8748
8785
|
{ ctx: { token: p.token } }
|
|
8749
8786
|
);
|
|
8750
8787
|
const baseToken = ctx.baseTokenL1 ?? await ctx.client.baseToken(ctx.chainIdL2);
|
|
8751
|
-
await
|
|
8788
|
+
await wrapAs4(
|
|
8752
8789
|
"VALIDATION",
|
|
8753
8790
|
OP_DEPOSITS.nonbase.assertNonBaseToken,
|
|
8754
8791
|
() => {
|
|
@@ -8765,7 +8802,7 @@ function routeErc20NonBase() {
|
|
|
8765
8802
|
const assetRouter = ctx.l1AssetRouter;
|
|
8766
8803
|
const nativeTokenVault = ctx.l1NativeTokenVault;
|
|
8767
8804
|
const receiver = p.to ?? ctx.sender;
|
|
8768
|
-
const secondBridgeCalldata = await
|
|
8805
|
+
const secondBridgeCalldata = await wrapAs4(
|
|
8769
8806
|
"INTERNAL",
|
|
8770
8807
|
OP_DEPOSITS.nonbase.encodeCalldata,
|
|
8771
8808
|
() => encodeSecondBridgeErc20DepositCalldata({
|
|
@@ -8803,11 +8840,16 @@ function routeErc20NonBase() {
|
|
|
8803
8840
|
}
|
|
8804
8841
|
});
|
|
8805
8842
|
if (!l2Gas) throw new Error("Failed to establish L2 gas parameters.");
|
|
8806
|
-
const
|
|
8843
|
+
const l1Fees = await quoteL1Fees2({ ctx });
|
|
8844
|
+
const l2BaseCost = await quoteL2BaseCost({
|
|
8845
|
+
ctx,
|
|
8846
|
+
l2GasLimit: l2Gas.gasLimit,
|
|
8847
|
+
l1GasPrice: l1Fees.maxFeePerGas
|
|
8848
|
+
});
|
|
8807
8849
|
const mintValue = l2BaseCost + ctx.operatorTip;
|
|
8808
8850
|
const approvals = [];
|
|
8809
8851
|
const steps = [];
|
|
8810
|
-
const depositAllowance = await
|
|
8852
|
+
const depositAllowance = await wrapAs4(
|
|
8811
8853
|
"CONTRACT",
|
|
8812
8854
|
OP_DEPOSITS.nonbase.allowanceToken,
|
|
8813
8855
|
() => ctx.client.l1.readContract({
|
|
@@ -8822,7 +8864,7 @@ function routeErc20NonBase() {
|
|
|
8822
8864
|
}
|
|
8823
8865
|
);
|
|
8824
8866
|
if (depositAllowance < p.amount) {
|
|
8825
|
-
const approveTx = await
|
|
8867
|
+
const approveTx = await wrapAs4(
|
|
8826
8868
|
"CONTRACT",
|
|
8827
8869
|
OP_DEPOSITS.nonbase.estGas,
|
|
8828
8870
|
() => buildApprovalRequest({
|
|
@@ -8845,7 +8887,7 @@ function routeErc20NonBase() {
|
|
|
8845
8887
|
});
|
|
8846
8888
|
}
|
|
8847
8889
|
if (!baseIsEth) {
|
|
8848
|
-
const baseAllowance = await
|
|
8890
|
+
const baseAllowance = await wrapAs4(
|
|
8849
8891
|
"CONTRACT",
|
|
8850
8892
|
OP_DEPOSITS.nonbase.allowanceBase,
|
|
8851
8893
|
() => ctx.client.l1.readContract({
|
|
@@ -8860,7 +8902,7 @@ function routeErc20NonBase() {
|
|
|
8860
8902
|
}
|
|
8861
8903
|
);
|
|
8862
8904
|
if (baseAllowance < mintValue) {
|
|
8863
|
-
const approveBaseTx = await
|
|
8905
|
+
const approveBaseTx = await wrapAs4(
|
|
8864
8906
|
"CONTRACT",
|
|
8865
8907
|
OP_DEPOSITS.nonbase.estGas,
|
|
8866
8908
|
() => buildApprovalRequest({
|
|
@@ -8905,7 +8947,8 @@ function routeErc20NonBase() {
|
|
|
8905
8947
|
data: calldata,
|
|
8906
8948
|
value: msgValue,
|
|
8907
8949
|
from: ctx.sender,
|
|
8908
|
-
...ctx.gasOverrides
|
|
8950
|
+
...ctx.gasOverrides,
|
|
8951
|
+
...l1Fees
|
|
8909
8952
|
};
|
|
8910
8953
|
const l1Gas = await quoteL1Gas2({
|
|
8911
8954
|
ctx,
|
|
@@ -8925,7 +8968,7 @@ function routeErc20NonBase() {
|
|
|
8925
8968
|
account: ctx.client.account
|
|
8926
8969
|
};
|
|
8927
8970
|
} else {
|
|
8928
|
-
const sim = await
|
|
8971
|
+
const sim = await wrapAs4(
|
|
8929
8972
|
"CONTRACT",
|
|
8930
8973
|
OP_DEPOSITS.nonbase.estGas,
|
|
8931
8974
|
() => ctx.client.l1.simulateContract({
|
|
@@ -8943,14 +8986,11 @@ function routeErc20NonBase() {
|
|
|
8943
8986
|
);
|
|
8944
8987
|
bridgeTx = { ...sim.request };
|
|
8945
8988
|
}
|
|
8946
|
-
|
|
8947
|
-
bridgeTx
|
|
8948
|
-
|
|
8949
|
-
|
|
8950
|
-
|
|
8951
|
-
maxPriorityFeePerGas: l1Gas.maxPriorityFeePerGas
|
|
8952
|
-
};
|
|
8953
|
-
}
|
|
8989
|
+
bridgeTx = {
|
|
8990
|
+
...bridgeTx,
|
|
8991
|
+
...l1Fees,
|
|
8992
|
+
...l1Gas ? { gas: l1Gas.gasLimit } : {}
|
|
8993
|
+
};
|
|
8954
8994
|
steps.push({
|
|
8955
8995
|
key: "bridgehub:two-bridges:erc20-nonbase",
|
|
8956
8996
|
kind: "bridgehub:two-bridges",
|
|
@@ -8973,7 +9013,7 @@ function routeErc20NonBase() {
|
|
|
8973
9013
|
}
|
|
8974
9014
|
};
|
|
8975
9015
|
}
|
|
8976
|
-
var { wrapAs:
|
|
9016
|
+
var { wrapAs: wrapAs5 } = createErrorHandlers("deposits");
|
|
8977
9017
|
var ZERO_ASSET_ID2 = "0x0000000000000000000000000000000000000000000000000000000000000000";
|
|
8978
9018
|
var ntvCodec2 = createNTVCodec({
|
|
8979
9019
|
encode: (types, values) => viem.encodeAbiParameters(
|
|
@@ -8982,6 +9022,20 @@ var ntvCodec2 = createNTVCodec({
|
|
|
8982
9022
|
),
|
|
8983
9023
|
keccak256: viem.keccak256
|
|
8984
9024
|
});
|
|
9025
|
+
async function encodeSecondBridgeEthDepositCalldata(input) {
|
|
9026
|
+
const registeredAssetId = input.ctx.resolvedToken?.assetId;
|
|
9027
|
+
const assetId = registeredAssetId && registeredAssetId.toLowerCase() !== ZERO_ASSET_ID2 ? registeredAssetId : ntvCodec2.encodeAssetId(
|
|
9028
|
+
BigInt(await input.ctx.client.l1.getChainId()),
|
|
9029
|
+
L2_NATIVE_TOKEN_VAULT_ADDRESS,
|
|
9030
|
+
ETH_ADDRESS
|
|
9031
|
+
);
|
|
9032
|
+
const transferData = encodeNativeTokenVaultTransferData(
|
|
9033
|
+
input.amount,
|
|
9034
|
+
input.receiver,
|
|
9035
|
+
ETH_ADDRESS
|
|
9036
|
+
);
|
|
9037
|
+
return encodeSecondBridgeDataV1(assetId, transferData);
|
|
9038
|
+
}
|
|
8985
9039
|
async function getPriorityGasModel2(input) {
|
|
8986
9040
|
try {
|
|
8987
9041
|
const l1AssetRouter = await input.ctx.contracts.l1AssetRouter();
|
|
@@ -9043,7 +9097,7 @@ function routeEthNonBase() {
|
|
|
9043
9097
|
return {
|
|
9044
9098
|
// TODO: do we even need these validations?
|
|
9045
9099
|
async preflight(p, ctx) {
|
|
9046
|
-
await
|
|
9100
|
+
await wrapAs5(
|
|
9047
9101
|
"VALIDATION",
|
|
9048
9102
|
OP_DEPOSITS.ethNonBase.assertEthAsset,
|
|
9049
9103
|
() => {
|
|
@@ -9053,7 +9107,7 @@ function routeEthNonBase() {
|
|
|
9053
9107
|
},
|
|
9054
9108
|
{ ctx: { token: p.token } }
|
|
9055
9109
|
);
|
|
9056
|
-
await
|
|
9110
|
+
await wrapAs5(
|
|
9057
9111
|
"VALIDATION",
|
|
9058
9112
|
OP_DEPOSITS.ethNonBase.assertNonEthBase,
|
|
9059
9113
|
() => {
|
|
@@ -9063,7 +9117,7 @@ function routeEthNonBase() {
|
|
|
9063
9117
|
},
|
|
9064
9118
|
{ ctx: { baseIsEth: ctx.baseIsEth, chainIdL2: ctx.chainIdL2 } }
|
|
9065
9119
|
);
|
|
9066
|
-
const ethBal = await
|
|
9120
|
+
const ethBal = await wrapAs5(
|
|
9067
9121
|
"RPC",
|
|
9068
9122
|
OP_DEPOSITS.ethNonBase.ethBalance,
|
|
9069
9123
|
() => ctx.client.l1.getBalance({ address: ctx.sender }),
|
|
@@ -9072,7 +9126,7 @@ function routeEthNonBase() {
|
|
|
9072
9126
|
message: "Failed to read L1 ETH balance."
|
|
9073
9127
|
}
|
|
9074
9128
|
);
|
|
9075
|
-
await
|
|
9129
|
+
await wrapAs5(
|
|
9076
9130
|
"VALIDATION",
|
|
9077
9131
|
OP_DEPOSITS.ethNonBase.assertEthBalance,
|
|
9078
9132
|
() => {
|
|
@@ -9105,11 +9159,16 @@ function routeEthNonBase() {
|
|
|
9105
9159
|
undeployedGasLimit: priorityGasModel.undeployedGasLimit
|
|
9106
9160
|
});
|
|
9107
9161
|
if (!l2Gas) throw new Error("Failed to estimate L2 gas parameters.");
|
|
9108
|
-
const
|
|
9162
|
+
const l1Fees = await quoteL1Fees2({ ctx });
|
|
9163
|
+
const l2BaseCost = await quoteL2BaseCost({
|
|
9164
|
+
ctx,
|
|
9165
|
+
l2GasLimit: l2Gas.gasLimit,
|
|
9166
|
+
l1GasPrice: l1Fees.maxFeePerGas
|
|
9167
|
+
});
|
|
9109
9168
|
const mintValue = l2BaseCost + ctx.operatorTip;
|
|
9110
9169
|
const approvals = [];
|
|
9111
9170
|
const steps = [];
|
|
9112
|
-
const allowance = await
|
|
9171
|
+
const allowance = await wrapAs5(
|
|
9113
9172
|
"CONTRACT",
|
|
9114
9173
|
OP_DEPOSITS.ethNonBase.allowanceBase,
|
|
9115
9174
|
() => ctx.client.l1.readContract({
|
|
@@ -9125,7 +9184,7 @@ function routeEthNonBase() {
|
|
|
9125
9184
|
);
|
|
9126
9185
|
const needsApprove = allowance < mintValue;
|
|
9127
9186
|
if (needsApprove) {
|
|
9128
|
-
const approveTx = await
|
|
9187
|
+
const approveTx = await wrapAs5(
|
|
9129
9188
|
"CONTRACT",
|
|
9130
9189
|
OP_DEPOSITS.ethNonBase.estGas,
|
|
9131
9190
|
() => buildApprovalRequest({
|
|
@@ -9147,13 +9206,13 @@ function routeEthNonBase() {
|
|
|
9147
9206
|
tx: approveTx
|
|
9148
9207
|
});
|
|
9149
9208
|
}
|
|
9150
|
-
const secondBridgeCalldata = await
|
|
9209
|
+
const secondBridgeCalldata = await wrapAs5(
|
|
9151
9210
|
"INTERNAL",
|
|
9152
9211
|
OP_DEPOSITS.ethNonBase.encodeCalldata,
|
|
9153
|
-
() =>
|
|
9212
|
+
() => encodeSecondBridgeEthDepositCalldata({ ctx, amount: p.amount, receiver }),
|
|
9154
9213
|
{
|
|
9155
9214
|
ctx: {
|
|
9156
|
-
where: "
|
|
9215
|
+
where: "encodeSecondBridgeEthDepositCalldata",
|
|
9157
9216
|
amount: p.amount.toString(),
|
|
9158
9217
|
to: receiver
|
|
9159
9218
|
},
|
|
@@ -9189,7 +9248,7 @@ function routeEthNonBase() {
|
|
|
9189
9248
|
args: [requestStruct]
|
|
9190
9249
|
});
|
|
9191
9250
|
} else {
|
|
9192
|
-
const sim = await
|
|
9251
|
+
const sim = await wrapAs5(
|
|
9193
9252
|
"CONTRACT",
|
|
9194
9253
|
OP_DEPOSITS.ethNonBase.estGas,
|
|
9195
9254
|
() => ctx.client.l1.simulateContract({
|
|
@@ -9217,7 +9276,8 @@ function routeEthNonBase() {
|
|
|
9217
9276
|
data: calldata,
|
|
9218
9277
|
value: bridgehubValue,
|
|
9219
9278
|
from: ctx.sender,
|
|
9220
|
-
...ctx.gasOverrides
|
|
9279
|
+
...ctx.gasOverrides,
|
|
9280
|
+
...l1Fees
|
|
9221
9281
|
};
|
|
9222
9282
|
const l1Gas = await quoteL1Gas2({
|
|
9223
9283
|
ctx,
|
|
@@ -9225,14 +9285,11 @@ function routeEthNonBase() {
|
|
|
9225
9285
|
overrides: ctx.gasOverrides,
|
|
9226
9286
|
fallbackGasLimit: SAFE_L1_BRIDGE_GAS
|
|
9227
9287
|
});
|
|
9228
|
-
|
|
9229
|
-
bridgeTx
|
|
9230
|
-
|
|
9231
|
-
|
|
9232
|
-
|
|
9233
|
-
maxPriorityFeePerGas: l1Gas.maxPriorityFeePerGas
|
|
9234
|
-
};
|
|
9235
|
-
}
|
|
9288
|
+
bridgeTx = {
|
|
9289
|
+
...bridgeTx,
|
|
9290
|
+
...l1Fees,
|
|
9291
|
+
...l1Gas ? { gas: l1Gas.gasLimit } : {}
|
|
9292
|
+
};
|
|
9236
9293
|
steps.push({
|
|
9237
9294
|
key: "bridgehub:two-bridges:eth-nonbase",
|
|
9238
9295
|
kind: "bridgehub:two-bridges",
|
|
@@ -9255,12 +9312,12 @@ function routeEthNonBase() {
|
|
|
9255
9312
|
}
|
|
9256
9313
|
};
|
|
9257
9314
|
}
|
|
9258
|
-
var { wrapAs:
|
|
9315
|
+
var { wrapAs: wrapAs6 } = createErrorHandlers("deposits");
|
|
9259
9316
|
var EMPTY_BYTES3 = "0x";
|
|
9260
9317
|
function routeErc20Base() {
|
|
9261
9318
|
return {
|
|
9262
9319
|
async preflight(p, ctx) {
|
|
9263
|
-
await
|
|
9320
|
+
await wrapAs6(
|
|
9264
9321
|
"VALIDATION",
|
|
9265
9322
|
OP_DEPOSITS.base.assertErc20Asset,
|
|
9266
9323
|
() => {
|
|
@@ -9271,7 +9328,7 @@ function routeErc20Base() {
|
|
|
9271
9328
|
{ ctx: { token: p.token } }
|
|
9272
9329
|
);
|
|
9273
9330
|
const baseToken = ctx.baseTokenL1 ?? await ctx.client.baseToken(ctx.chainIdL2);
|
|
9274
|
-
await
|
|
9331
|
+
await wrapAs6(
|
|
9275
9332
|
"VALIDATION",
|
|
9276
9333
|
OP_DEPOSITS.base.assertMatchesBase,
|
|
9277
9334
|
() => {
|
|
@@ -9308,11 +9365,16 @@ function routeErc20Base() {
|
|
|
9308
9365
|
overrideGasLimit: quotedL2GasLimit
|
|
9309
9366
|
});
|
|
9310
9367
|
if (!l2Gas) throw new Error("Failed to estimate L2 gas parameters.");
|
|
9311
|
-
const
|
|
9368
|
+
const l1Fees = await quoteL1Fees2({ ctx });
|
|
9369
|
+
const l2BaseCost = await quoteL2BaseCost({
|
|
9370
|
+
ctx,
|
|
9371
|
+
l2GasLimit: l2Gas.gasLimit,
|
|
9372
|
+
l1GasPrice: l1Fees.maxFeePerGas
|
|
9373
|
+
});
|
|
9312
9374
|
const mintValue = l2BaseCost + ctx.operatorTip + p.amount;
|
|
9313
9375
|
const approvals = [];
|
|
9314
9376
|
const steps = [];
|
|
9315
|
-
const allowance = await
|
|
9377
|
+
const allowance = await wrapAs6(
|
|
9316
9378
|
"CONTRACT",
|
|
9317
9379
|
OP_DEPOSITS.base.allowance,
|
|
9318
9380
|
() => ctx.client.l1.readContract({
|
|
@@ -9328,7 +9390,7 @@ function routeErc20Base() {
|
|
|
9328
9390
|
);
|
|
9329
9391
|
const needsApprove = allowance < mintValue;
|
|
9330
9392
|
if (needsApprove) {
|
|
9331
|
-
const approveTx = await
|
|
9393
|
+
const approveTx = await wrapAs6(
|
|
9332
9394
|
"CONTRACT",
|
|
9333
9395
|
OP_DEPOSITS.base.estGas,
|
|
9334
9396
|
() => buildApprovalRequest({
|
|
@@ -9377,7 +9439,7 @@ function routeErc20Base() {
|
|
|
9377
9439
|
args: [req]
|
|
9378
9440
|
});
|
|
9379
9441
|
} else {
|
|
9380
|
-
const sim = await
|
|
9442
|
+
const sim = await wrapAs6(
|
|
9381
9443
|
"RPC",
|
|
9382
9444
|
OP_DEPOSITS.base.estGas,
|
|
9383
9445
|
() => ctx.client.l1.simulateContract({
|
|
@@ -9405,7 +9467,8 @@ function routeErc20Base() {
|
|
|
9405
9467
|
data: calldata,
|
|
9406
9468
|
value: 0n,
|
|
9407
9469
|
from: ctx.sender,
|
|
9408
|
-
...ctx.gasOverrides
|
|
9470
|
+
...ctx.gasOverrides,
|
|
9471
|
+
...l1Fees
|
|
9409
9472
|
};
|
|
9410
9473
|
const l1Gas = await quoteL1Gas2({
|
|
9411
9474
|
ctx,
|
|
@@ -9413,14 +9476,11 @@ function routeErc20Base() {
|
|
|
9413
9476
|
overrides: ctx.gasOverrides,
|
|
9414
9477
|
fallbackGasLimit: SAFE_L1_BRIDGE_GAS
|
|
9415
9478
|
});
|
|
9416
|
-
|
|
9417
|
-
bridgeTx
|
|
9418
|
-
|
|
9419
|
-
|
|
9420
|
-
|
|
9421
|
-
maxPriorityFeePerGas: l1Gas.maxPriorityFeePerGas
|
|
9422
|
-
};
|
|
9423
|
-
}
|
|
9479
|
+
bridgeTx = {
|
|
9480
|
+
...bridgeTx,
|
|
9481
|
+
...l1Fees,
|
|
9482
|
+
...l1Gas ? { gas: l1Gas.gasLimit } : {}
|
|
9483
|
+
};
|
|
9424
9484
|
steps.push({
|
|
9425
9485
|
key: "bridgehub:direct:erc20-base",
|
|
9426
9486
|
kind: "bridgehub:direct",
|
|
@@ -9518,7 +9578,7 @@ async function waitForL2ExecutionFromL1Tx(l1, l2, l1TxHash) {
|
|
|
9518
9578
|
}
|
|
9519
9579
|
return { l2Receipt, l2TxHash };
|
|
9520
9580
|
}
|
|
9521
|
-
var { wrapAs:
|
|
9581
|
+
var { wrapAs: wrapAs7 } = createErrorHandlers("tokens");
|
|
9522
9582
|
var ntvCodec3 = createNTVCodec({
|
|
9523
9583
|
encode: (types, values) => viem.encodeAbiParameters(
|
|
9524
9584
|
types.map((t, i) => ({ type: t, name: `arg${i}` })),
|
|
@@ -9533,7 +9593,7 @@ function createTokensResource(client) {
|
|
|
9533
9593
|
let wethL2Promise = null;
|
|
9534
9594
|
async function getL1ChainId() {
|
|
9535
9595
|
if (!l2NtvL1ChainIdPromise) {
|
|
9536
|
-
l2NtvL1ChainIdPromise =
|
|
9596
|
+
l2NtvL1ChainIdPromise = wrapAs7("INTERNAL", "getL1ChainId", async () => {
|
|
9537
9597
|
const { l2NativeTokenVault } = await client.contracts();
|
|
9538
9598
|
return await l2NativeTokenVault.read.L1_CHAIN_ID();
|
|
9539
9599
|
});
|
|
@@ -9542,7 +9602,7 @@ function createTokensResource(client) {
|
|
|
9542
9602
|
}
|
|
9543
9603
|
async function getBaseTokenAssetId() {
|
|
9544
9604
|
if (!baseTokenAssetIdPromise) {
|
|
9545
|
-
baseTokenAssetIdPromise =
|
|
9605
|
+
baseTokenAssetIdPromise = wrapAs7("INTERNAL", "baseTokenAssetId", async () => {
|
|
9546
9606
|
const { l2NativeTokenVault } = await client.contracts();
|
|
9547
9607
|
const assetId = await l2NativeTokenVault.read.BASE_TOKEN_ASSET_ID();
|
|
9548
9608
|
return assetId;
|
|
@@ -9552,7 +9612,7 @@ function createTokensResource(client) {
|
|
|
9552
9612
|
}
|
|
9553
9613
|
async function getWethL1() {
|
|
9554
9614
|
if (!wethL1Promise) {
|
|
9555
|
-
wethL1Promise =
|
|
9615
|
+
wethL1Promise = wrapAs7("INTERNAL", "wethL1", async () => {
|
|
9556
9616
|
const { l1NativeTokenVault } = await client.contracts();
|
|
9557
9617
|
const weth = await l1NativeTokenVault.read.WETH_TOKEN();
|
|
9558
9618
|
return weth;
|
|
@@ -9562,7 +9622,7 @@ function createTokensResource(client) {
|
|
|
9562
9622
|
}
|
|
9563
9623
|
async function getWethL2() {
|
|
9564
9624
|
if (!wethL2Promise) {
|
|
9565
|
-
wethL2Promise =
|
|
9625
|
+
wethL2Promise = wrapAs7("INTERNAL", "wethL2", async () => {
|
|
9566
9626
|
const { l2NativeTokenVault } = await client.contracts();
|
|
9567
9627
|
const weth = await l2NativeTokenVault.read.WETH_TOKEN();
|
|
9568
9628
|
return weth;
|
|
@@ -9571,7 +9631,7 @@ function createTokensResource(client) {
|
|
|
9571
9631
|
return wethL2Promise;
|
|
9572
9632
|
}
|
|
9573
9633
|
async function toL2Address(l1Token) {
|
|
9574
|
-
return
|
|
9634
|
+
return wrapAs7("CONTRACT", "tokens.toL2Address", async () => {
|
|
9575
9635
|
const normalized = normalizeL1Token(l1Token);
|
|
9576
9636
|
const chainId = BigInt(await client.l2.getChainId());
|
|
9577
9637
|
const baseToken = await client.baseToken(chainId);
|
|
@@ -9584,7 +9644,7 @@ function createTokensResource(client) {
|
|
|
9584
9644
|
});
|
|
9585
9645
|
}
|
|
9586
9646
|
async function toL1Address(l2Token) {
|
|
9587
|
-
return
|
|
9647
|
+
return wrapAs7("CONTRACT", "tokens.toL1Address", async () => {
|
|
9588
9648
|
if (isAddressEq(l2Token, ETH_ADDRESS)) return ETH_ADDRESS;
|
|
9589
9649
|
if (isAddressEq(l2Token, L2_BASE_TOKEN_ADDRESS)) {
|
|
9590
9650
|
const chainId = BigInt(await client.l2.getChainId());
|
|
@@ -9605,32 +9665,32 @@ function createTokensResource(client) {
|
|
|
9605
9665
|
});
|
|
9606
9666
|
}
|
|
9607
9667
|
async function assetIdOfL1(l1Token) {
|
|
9608
|
-
return
|
|
9668
|
+
return wrapAs7("CONTRACT", "tokens.assetIdOfL1", async () => {
|
|
9609
9669
|
const normalized = normalizeL1Token(l1Token);
|
|
9610
9670
|
const { l1NativeTokenVault } = await client.contracts();
|
|
9611
9671
|
return await l1NativeTokenVault.read.assetId([normalized]);
|
|
9612
9672
|
});
|
|
9613
9673
|
}
|
|
9614
9674
|
async function assetIdOfL2(l2Token) {
|
|
9615
|
-
return
|
|
9675
|
+
return wrapAs7("CONTRACT", "tokens.assetIdOfL2", async () => {
|
|
9616
9676
|
const { l2NativeTokenVault } = await client.contracts();
|
|
9617
9677
|
return await l2NativeTokenVault.read.assetId([l2Token]);
|
|
9618
9678
|
});
|
|
9619
9679
|
}
|
|
9620
9680
|
async function l2TokenFromAssetId(assetId) {
|
|
9621
|
-
return
|
|
9681
|
+
return wrapAs7("CONTRACT", "tokens.l2TokenFromAssetId", async () => {
|
|
9622
9682
|
const { l2NativeTokenVault } = await client.contracts();
|
|
9623
9683
|
return await l2NativeTokenVault.read.tokenAddress([assetId]);
|
|
9624
9684
|
});
|
|
9625
9685
|
}
|
|
9626
9686
|
async function l1TokenFromAssetId(assetId) {
|
|
9627
|
-
return
|
|
9687
|
+
return wrapAs7("CONTRACT", "tokens.l1TokenFromAssetId", async () => {
|
|
9628
9688
|
const { l1NativeTokenVault } = await client.contracts();
|
|
9629
9689
|
return await l1NativeTokenVault.read.tokenAddress([assetId]);
|
|
9630
9690
|
});
|
|
9631
9691
|
}
|
|
9632
9692
|
async function originChainId(assetId) {
|
|
9633
|
-
return
|
|
9693
|
+
return wrapAs7("CONTRACT", "tokens.originChainId", async () => {
|
|
9634
9694
|
const { l2NativeTokenVault } = await client.contracts();
|
|
9635
9695
|
return await l2NativeTokenVault.read.originChainId([assetId]);
|
|
9636
9696
|
});
|
|
@@ -9639,7 +9699,7 @@ function createTokensResource(client) {
|
|
|
9639
9699
|
return getBaseTokenAssetId();
|
|
9640
9700
|
}
|
|
9641
9701
|
async function isChainEthBased() {
|
|
9642
|
-
return
|
|
9702
|
+
return wrapAs7("CONTRACT", "tokens.isChainEthBased", async () => {
|
|
9643
9703
|
const baseAssetId = await getBaseTokenAssetId();
|
|
9644
9704
|
const l1ChainId = await getL1ChainId();
|
|
9645
9705
|
const ethAssetId = ntvCodec3.encodeAssetId(
|
|
@@ -9657,7 +9717,7 @@ function createTokensResource(client) {
|
|
|
9657
9717
|
return getWethL2();
|
|
9658
9718
|
}
|
|
9659
9719
|
async function computeL2BridgedAddress(args) {
|
|
9660
|
-
return
|
|
9720
|
+
return wrapAs7("CONTRACT", "tokens.computeL2BridgedAddress", async () => {
|
|
9661
9721
|
const normalized = normalizeL1Token(args.l1Token);
|
|
9662
9722
|
const { l2NativeTokenVault } = await client.contracts();
|
|
9663
9723
|
const predicted = await l2NativeTokenVault.read.calculateCreate2TokenAddress([
|
|
@@ -9668,7 +9728,7 @@ function createTokensResource(client) {
|
|
|
9668
9728
|
});
|
|
9669
9729
|
}
|
|
9670
9730
|
async function resolve(ref, opts) {
|
|
9671
|
-
return
|
|
9731
|
+
return wrapAs7("CONTRACT", "tokens.resolve", async () => {
|
|
9672
9732
|
let chain;
|
|
9673
9733
|
let address;
|
|
9674
9734
|
if (typeof ref === "string") {
|
|
@@ -10256,12 +10316,12 @@ function buildFeeBreakdown2(p) {
|
|
|
10256
10316
|
}
|
|
10257
10317
|
|
|
10258
10318
|
// src/adapters/viem/resources/withdrawals/routes/eth.ts
|
|
10259
|
-
var { wrapAs:
|
|
10319
|
+
var { wrapAs: wrapAs8 } = createErrorHandlers("withdrawals");
|
|
10260
10320
|
function routeEthBase() {
|
|
10261
10321
|
return {
|
|
10262
10322
|
async build(p, ctx) {
|
|
10263
10323
|
const steps = [];
|
|
10264
|
-
const data = await
|
|
10324
|
+
const data = await wrapAs8(
|
|
10265
10325
|
"INTERNAL",
|
|
10266
10326
|
OP_WITHDRAWALS.eth.encodeWithdraw,
|
|
10267
10327
|
() => Promise.resolve(
|
|
@@ -10311,14 +10371,14 @@ function routeEthBase() {
|
|
|
10311
10371
|
}
|
|
10312
10372
|
};
|
|
10313
10373
|
}
|
|
10314
|
-
var { wrapAs:
|
|
10374
|
+
var { wrapAs: wrapAs9 } = createErrorHandlers("withdrawals");
|
|
10315
10375
|
function routeErc20NonBase2() {
|
|
10316
10376
|
return {
|
|
10317
10377
|
// TODO: add preflight validations here
|
|
10318
10378
|
async build(p, ctx) {
|
|
10319
10379
|
const steps = [];
|
|
10320
10380
|
const approvals = [];
|
|
10321
|
-
const current = await
|
|
10381
|
+
const current = await wrapAs9(
|
|
10322
10382
|
"CONTRACT",
|
|
10323
10383
|
OP_WITHDRAWALS.erc20.allowance,
|
|
10324
10384
|
() => ctx.client.l2.readContract({
|
|
@@ -10357,7 +10417,7 @@ function routeErc20NonBase2() {
|
|
|
10357
10417
|
approveTxCandidate.maxFeePerGas = approveGas.maxFeePerGas;
|
|
10358
10418
|
approveTxCandidate.maxPriorityFeePerGas = approveGas.maxPriorityFeePerGas;
|
|
10359
10419
|
}
|
|
10360
|
-
const approveSim = await
|
|
10420
|
+
const approveSim = await wrapAs9(
|
|
10361
10421
|
"CONTRACT",
|
|
10362
10422
|
OP_WITHDRAWALS.erc20.estGas,
|
|
10363
10423
|
() => ctx.client.l2.simulateContract({
|
|
@@ -10384,7 +10444,7 @@ function routeErc20NonBase2() {
|
|
|
10384
10444
|
tx: approveTx
|
|
10385
10445
|
});
|
|
10386
10446
|
}
|
|
10387
|
-
const assetId = (await
|
|
10447
|
+
const assetId = (await wrapAs9(
|
|
10388
10448
|
"CONTRACT",
|
|
10389
10449
|
OP_WITHDRAWALS.erc20.ensureRegistered,
|
|
10390
10450
|
() => ctx.client.l2.simulateContract({
|
|
@@ -10435,7 +10495,7 @@ function routeErc20NonBase2() {
|
|
|
10435
10495
|
...withdrawGas
|
|
10436
10496
|
};
|
|
10437
10497
|
} else {
|
|
10438
|
-
const sim = await
|
|
10498
|
+
const sim = await wrapAs9(
|
|
10439
10499
|
"CONTRACT",
|
|
10440
10500
|
OP_WITHDRAWALS.erc20.estGas,
|
|
10441
10501
|
() => ctx.client.l2.simulateContract({
|
|
@@ -10597,7 +10657,7 @@ function buildWithdrawalBundle(input) {
|
|
|
10597
10657
|
}
|
|
10598
10658
|
|
|
10599
10659
|
// src/adapters/viem/resources/withdrawals/routes/interop-bundle.ts
|
|
10600
|
-
var { wrapAs:
|
|
10660
|
+
var { wrapAs: wrapAs10 } = createErrorHandlers("withdrawals");
|
|
10601
10661
|
var attributes = createViemAttributesResource();
|
|
10602
10662
|
function saltFor(sender, nonce) {
|
|
10603
10663
|
return viem.keccak256(
|
|
@@ -10622,7 +10682,7 @@ function routeInteropBundle() {
|
|
|
10622
10682
|
if (isBaseToken) {
|
|
10623
10683
|
assetId = ctx.baseTokenAssetId;
|
|
10624
10684
|
} else {
|
|
10625
|
-
assetId = (await
|
|
10685
|
+
assetId = (await wrapAs10(
|
|
10626
10686
|
"CONTRACT",
|
|
10627
10687
|
OP_WITHDRAWALS.erc20.ensureRegistered,
|
|
10628
10688
|
() => ctx.client.l2.simulateContract({
|
|
@@ -10637,7 +10697,7 @@ function routeInteropBundle() {
|
|
|
10637
10697
|
message: "Failed to ensure token is registered in L2NativeTokenVault."
|
|
10638
10698
|
}
|
|
10639
10699
|
)).result;
|
|
10640
|
-
const current = await
|
|
10700
|
+
const current = await wrapAs10(
|
|
10641
10701
|
"CONTRACT",
|
|
10642
10702
|
OP_WITHDRAWALS.erc20.allowance,
|
|
10643
10703
|
() => ctx.client.l2.readContract({
|
|
@@ -10686,7 +10746,7 @@ function routeInteropBundle() {
|
|
|
10686
10746
|
});
|
|
10687
10747
|
}
|
|
10688
10748
|
}
|
|
10689
|
-
const nonce = await
|
|
10749
|
+
const nonce = await wrapAs10(
|
|
10690
10750
|
"RPC",
|
|
10691
10751
|
OP_WITHDRAWALS.prepare,
|
|
10692
10752
|
() => ctx.client.l2.getTransactionCount({ address: ctx.sender, blockTag: "pending" }),
|
|
@@ -10922,7 +10982,7 @@ function createWithdrawalProtocolService(client, override) {
|
|
|
10922
10982
|
}
|
|
10923
10983
|
};
|
|
10924
10984
|
}
|
|
10925
|
-
var { wrapAs:
|
|
10985
|
+
var { wrapAs: wrapAs11 } = createErrorHandlers("withdrawals");
|
|
10926
10986
|
var IL1NullifierMini = [
|
|
10927
10987
|
{
|
|
10928
10988
|
type: "function",
|
|
@@ -10940,7 +11000,7 @@ function createFinalizationServices(client, protocolService = createWithdrawalPr
|
|
|
10940
11000
|
async function finalizationTarget(protocol) {
|
|
10941
11001
|
const { l1Nullifier } = await client.ensureAddresses();
|
|
10942
11002
|
if (protocol === "legacy-withdrawal") return l1Nullifier;
|
|
10943
|
-
return await
|
|
11003
|
+
return await wrapAs11(
|
|
10944
11004
|
"CONTRACT",
|
|
10945
11005
|
OP_WITHDRAWALS.finalize.fetchParams.receipt,
|
|
10946
11006
|
() => client.l1.readContract({
|
|
@@ -10955,7 +11015,7 @@ function createFinalizationServices(client, protocolService = createWithdrawalPr
|
|
|
10955
11015
|
);
|
|
10956
11016
|
}
|
|
10957
11017
|
async function fetchMessageAndProof(l2TxHash) {
|
|
10958
|
-
const raw = await
|
|
11018
|
+
const raw = await wrapAs11(
|
|
10959
11019
|
"RPC",
|
|
10960
11020
|
OP_WITHDRAWALS.finalize.fetchParams.receipt,
|
|
10961
11021
|
() => client.zks.getReceiptWithL2ToL1(l2TxHash),
|
|
@@ -10972,7 +11032,7 @@ function createFinalizationServices(client, protocolService = createWithdrawalPr
|
|
|
10972
11032
|
context: { l2TxHash }
|
|
10973
11033
|
});
|
|
10974
11034
|
}
|
|
10975
|
-
const ev = await
|
|
11035
|
+
const ev = await wrapAs11(
|
|
10976
11036
|
"INTERNAL",
|
|
10977
11037
|
OP_WITHDRAWALS.finalize.fetchParams.findMessage,
|
|
10978
11038
|
// eslint-disable-next-line @typescript-eslint/no-unsafe-argument, @typescript-eslint/no-explicit-any
|
|
@@ -10982,7 +11042,7 @@ function createFinalizationServices(client, protocolService = createWithdrawalPr
|
|
|
10982
11042
|
message: "Failed to locate L1MessageSent event in L2 receipt."
|
|
10983
11043
|
}
|
|
10984
11044
|
);
|
|
10985
|
-
const message = await
|
|
11045
|
+
const message = await wrapAs11(
|
|
10986
11046
|
"INTERNAL",
|
|
10987
11047
|
OP_WITHDRAWALS.finalize.fetchParams.decodeMessage,
|
|
10988
11048
|
() => {
|
|
@@ -10994,7 +11054,7 @@ function createFinalizationServices(client, protocolService = createWithdrawalPr
|
|
|
10994
11054
|
message: "Failed to decode withdrawal message."
|
|
10995
11055
|
}
|
|
10996
11056
|
);
|
|
10997
|
-
const idx = await
|
|
11057
|
+
const idx = await wrapAs11(
|
|
10998
11058
|
"INTERNAL",
|
|
10999
11059
|
OP_WITHDRAWALS.finalize.fetchParams.messengerIndex,
|
|
11000
11060
|
() => Promise.resolve(messengerLogIndex(raw, { index: 0, messenger: L1_MESSENGER_ADDRESS })),
|
|
@@ -11003,7 +11063,7 @@ function createFinalizationServices(client, protocolService = createWithdrawalPr
|
|
|
11003
11063
|
message: "Failed to derive messenger log index."
|
|
11004
11064
|
}
|
|
11005
11065
|
);
|
|
11006
|
-
const proof = await
|
|
11066
|
+
const proof = await wrapAs11(
|
|
11007
11067
|
"RPC",
|
|
11008
11068
|
OP_WITHDRAWALS.finalize.fetchParams.proof,
|
|
11009
11069
|
() => client.zks.getL2ToL1LogProof(l2TxHash, idx),
|
|
@@ -11012,7 +11072,7 @@ function createFinalizationServices(client, protocolService = createWithdrawalPr
|
|
|
11012
11072
|
message: "Failed to fetch L2\u2192L1 log proof."
|
|
11013
11073
|
}
|
|
11014
11074
|
);
|
|
11015
|
-
const chainId = await
|
|
11075
|
+
const chainId = await wrapAs11(
|
|
11016
11076
|
"RPC",
|
|
11017
11077
|
OP_WITHDRAWALS.finalize.fetchParams.network,
|
|
11018
11078
|
() => client.l2.getChainId(),
|
|
@@ -11070,7 +11130,7 @@ function createFinalizationServices(client, protocolService = createWithdrawalPr
|
|
|
11070
11130
|
async function withdrawalOutcome(finalization) {
|
|
11071
11131
|
const target = await finalizationTarget(finalization.protocol);
|
|
11072
11132
|
if (finalization.protocol === "legacy-withdrawal") {
|
|
11073
|
-
const done = await
|
|
11133
|
+
const done = await wrapAs11(
|
|
11074
11134
|
"RPC",
|
|
11075
11135
|
OP_WITHDRAWALS.finalize.isFinalized,
|
|
11076
11136
|
() => client.l1.readContract({
|
|
@@ -11092,7 +11152,7 @@ function createFinalizationServices(client, protocolService = createWithdrawalPr
|
|
|
11092
11152
|
}
|
|
11093
11153
|
const { bundleHash } = finalization.params;
|
|
11094
11154
|
const status = Number(
|
|
11095
|
-
await
|
|
11155
|
+
await wrapAs11(
|
|
11096
11156
|
"RPC",
|
|
11097
11157
|
OP_WITHDRAWALS.finalize.isFinalized,
|
|
11098
11158
|
() => client.l1.readContract({
|
|
@@ -11109,7 +11169,7 @@ function createFinalizationServices(client, protocolService = createWithdrawalPr
|
|
|
11109
11169
|
);
|
|
11110
11170
|
if (status !== 3 /* Unbundled */) return classifyWithdrawalOutcome(status);
|
|
11111
11171
|
const callStatus = Number(
|
|
11112
|
-
await
|
|
11172
|
+
await wrapAs11(
|
|
11113
11173
|
"RPC",
|
|
11114
11174
|
OP_WITHDRAWALS.finalize.isFinalized,
|
|
11115
11175
|
() => client.l1.readContract({
|
|
@@ -11180,7 +11240,7 @@ function createFinalizationServices(client, protocolService = createWithdrawalPr
|
|
|
11180
11240
|
},
|
|
11181
11241
|
async estimateFinalization(finalization) {
|
|
11182
11242
|
const target = await finalizationTarget(finalization.protocol);
|
|
11183
|
-
const gasLimit = await
|
|
11243
|
+
const gasLimit = await wrapAs11(
|
|
11184
11244
|
"RPC",
|
|
11185
11245
|
OP_WITHDRAWALS.finalize.estimate,
|
|
11186
11246
|
() => finalization.protocol === "legacy-withdrawal" ? client.l1.estimateContractGas({
|
|
@@ -11208,7 +11268,7 @@ function createFinalizationServices(client, protocolService = createWithdrawalPr
|
|
|
11208
11268
|
let maxFeePerGas;
|
|
11209
11269
|
let maxPriorityFeePerGas;
|
|
11210
11270
|
try {
|
|
11211
|
-
const fee = await
|
|
11271
|
+
const fee = await wrapAs11(
|
|
11212
11272
|
"RPC",
|
|
11213
11273
|
OP_WITHDRAWALS.finalize.estimate,
|
|
11214
11274
|
() => client.l1.estimateFeesPerGas(),
|
|
@@ -11227,7 +11287,7 @@ function createFinalizationServices(client, protocolService = createWithdrawalPr
|
|
|
11227
11287
|
})();
|
|
11228
11288
|
maxPriorityFeePerGas = fee.maxPriorityFeePerGas ?? 0n;
|
|
11229
11289
|
} catch {
|
|
11230
|
-
const gasPrice = await
|
|
11290
|
+
const gasPrice = await wrapAs11(
|
|
11231
11291
|
"RPC",
|
|
11232
11292
|
OP_WITHDRAWALS.finalize.estimate,
|
|
11233
11293
|
() => client.l1.getGasPrice(),
|