@matterlabs/zksync-js 0.0.24 → 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/index.cjs +138 -79
- package/dist/adapters/ethers/index.cjs.map +1 -1
- package/dist/adapters/ethers/index.js +2 -2
- 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 +138 -79
- package/dist/adapters/ethers/sdk.cjs.map +1 -1
- package/dist/adapters/ethers/sdk.js +2 -2
- package/dist/adapters/viem/index.cjs +165 -119
- package/dist/adapters/viem/index.cjs.map +1 -1
- package/dist/adapters/viem/index.js +2 -2
- 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 +165 -119
- package/dist/adapters/viem/sdk.cjs.map +1 -1
- package/dist/adapters/viem/sdk.js +2 -2
- package/dist/{chunk-5S63J6DW.js → chunk-JWN26CQ6.js} +30 -10
- package/dist/{chunk-B6P24GL5.js → chunk-N5E4FLBF.js} +108 -69
- package/dist/{chunk-QMMFUWRV.js → chunk-NFRRRT5X.js} +136 -115
- package/dist/core/resources/deposits/gas.d.ts +11 -1
- package/package.json +1 -1
|
@@ -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;
|
|
8029
8030
|
}
|
|
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.");
|
|
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;
|
|
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(
|
|
@@ -9057,7 +9097,7 @@ function routeEthNonBase() {
|
|
|
9057
9097
|
return {
|
|
9058
9098
|
// TODO: do we even need these validations?
|
|
9059
9099
|
async preflight(p, ctx) {
|
|
9060
|
-
await
|
|
9100
|
+
await wrapAs5(
|
|
9061
9101
|
"VALIDATION",
|
|
9062
9102
|
OP_DEPOSITS.ethNonBase.assertEthAsset,
|
|
9063
9103
|
() => {
|
|
@@ -9067,7 +9107,7 @@ function routeEthNonBase() {
|
|
|
9067
9107
|
},
|
|
9068
9108
|
{ ctx: { token: p.token } }
|
|
9069
9109
|
);
|
|
9070
|
-
await
|
|
9110
|
+
await wrapAs5(
|
|
9071
9111
|
"VALIDATION",
|
|
9072
9112
|
OP_DEPOSITS.ethNonBase.assertNonEthBase,
|
|
9073
9113
|
() => {
|
|
@@ -9077,7 +9117,7 @@ function routeEthNonBase() {
|
|
|
9077
9117
|
},
|
|
9078
9118
|
{ ctx: { baseIsEth: ctx.baseIsEth, chainIdL2: ctx.chainIdL2 } }
|
|
9079
9119
|
);
|
|
9080
|
-
const ethBal = await
|
|
9120
|
+
const ethBal = await wrapAs5(
|
|
9081
9121
|
"RPC",
|
|
9082
9122
|
OP_DEPOSITS.ethNonBase.ethBalance,
|
|
9083
9123
|
() => ctx.client.l1.getBalance({ address: ctx.sender }),
|
|
@@ -9086,7 +9126,7 @@ function routeEthNonBase() {
|
|
|
9086
9126
|
message: "Failed to read L1 ETH balance."
|
|
9087
9127
|
}
|
|
9088
9128
|
);
|
|
9089
|
-
await
|
|
9129
|
+
await wrapAs5(
|
|
9090
9130
|
"VALIDATION",
|
|
9091
9131
|
OP_DEPOSITS.ethNonBase.assertEthBalance,
|
|
9092
9132
|
() => {
|
|
@@ -9119,11 +9159,16 @@ function routeEthNonBase() {
|
|
|
9119
9159
|
undeployedGasLimit: priorityGasModel.undeployedGasLimit
|
|
9120
9160
|
});
|
|
9121
9161
|
if (!l2Gas) throw new Error("Failed to estimate L2 gas parameters.");
|
|
9122
|
-
const
|
|
9162
|
+
const l1Fees = await quoteL1Fees2({ ctx });
|
|
9163
|
+
const l2BaseCost = await quoteL2BaseCost({
|
|
9164
|
+
ctx,
|
|
9165
|
+
l2GasLimit: l2Gas.gasLimit,
|
|
9166
|
+
l1GasPrice: l1Fees.maxFeePerGas
|
|
9167
|
+
});
|
|
9123
9168
|
const mintValue = l2BaseCost + ctx.operatorTip;
|
|
9124
9169
|
const approvals = [];
|
|
9125
9170
|
const steps = [];
|
|
9126
|
-
const allowance = await
|
|
9171
|
+
const allowance = await wrapAs5(
|
|
9127
9172
|
"CONTRACT",
|
|
9128
9173
|
OP_DEPOSITS.ethNonBase.allowanceBase,
|
|
9129
9174
|
() => ctx.client.l1.readContract({
|
|
@@ -9139,7 +9184,7 @@ function routeEthNonBase() {
|
|
|
9139
9184
|
);
|
|
9140
9185
|
const needsApprove = allowance < mintValue;
|
|
9141
9186
|
if (needsApprove) {
|
|
9142
|
-
const approveTx = await
|
|
9187
|
+
const approveTx = await wrapAs5(
|
|
9143
9188
|
"CONTRACT",
|
|
9144
9189
|
OP_DEPOSITS.ethNonBase.estGas,
|
|
9145
9190
|
() => buildApprovalRequest({
|
|
@@ -9161,7 +9206,7 @@ function routeEthNonBase() {
|
|
|
9161
9206
|
tx: approveTx
|
|
9162
9207
|
});
|
|
9163
9208
|
}
|
|
9164
|
-
const secondBridgeCalldata = await
|
|
9209
|
+
const secondBridgeCalldata = await wrapAs5(
|
|
9165
9210
|
"INTERNAL",
|
|
9166
9211
|
OP_DEPOSITS.ethNonBase.encodeCalldata,
|
|
9167
9212
|
() => encodeSecondBridgeEthDepositCalldata({ ctx, amount: p.amount, receiver }),
|
|
@@ -9203,7 +9248,7 @@ function routeEthNonBase() {
|
|
|
9203
9248
|
args: [requestStruct]
|
|
9204
9249
|
});
|
|
9205
9250
|
} else {
|
|
9206
|
-
const sim = await
|
|
9251
|
+
const sim = await wrapAs5(
|
|
9207
9252
|
"CONTRACT",
|
|
9208
9253
|
OP_DEPOSITS.ethNonBase.estGas,
|
|
9209
9254
|
() => ctx.client.l1.simulateContract({
|
|
@@ -9231,7 +9276,8 @@ function routeEthNonBase() {
|
|
|
9231
9276
|
data: calldata,
|
|
9232
9277
|
value: bridgehubValue,
|
|
9233
9278
|
from: ctx.sender,
|
|
9234
|
-
...ctx.gasOverrides
|
|
9279
|
+
...ctx.gasOverrides,
|
|
9280
|
+
...l1Fees
|
|
9235
9281
|
};
|
|
9236
9282
|
const l1Gas = await quoteL1Gas2({
|
|
9237
9283
|
ctx,
|
|
@@ -9239,14 +9285,11 @@ function routeEthNonBase() {
|
|
|
9239
9285
|
overrides: ctx.gasOverrides,
|
|
9240
9286
|
fallbackGasLimit: SAFE_L1_BRIDGE_GAS
|
|
9241
9287
|
});
|
|
9242
|
-
|
|
9243
|
-
bridgeTx
|
|
9244
|
-
|
|
9245
|
-
|
|
9246
|
-
|
|
9247
|
-
maxPriorityFeePerGas: l1Gas.maxPriorityFeePerGas
|
|
9248
|
-
};
|
|
9249
|
-
}
|
|
9288
|
+
bridgeTx = {
|
|
9289
|
+
...bridgeTx,
|
|
9290
|
+
...l1Fees,
|
|
9291
|
+
...l1Gas ? { gas: l1Gas.gasLimit } : {}
|
|
9292
|
+
};
|
|
9250
9293
|
steps.push({
|
|
9251
9294
|
key: "bridgehub:two-bridges:eth-nonbase",
|
|
9252
9295
|
kind: "bridgehub:two-bridges",
|
|
@@ -9269,12 +9312,12 @@ function routeEthNonBase() {
|
|
|
9269
9312
|
}
|
|
9270
9313
|
};
|
|
9271
9314
|
}
|
|
9272
|
-
var { wrapAs:
|
|
9315
|
+
var { wrapAs: wrapAs6 } = createErrorHandlers("deposits");
|
|
9273
9316
|
var EMPTY_BYTES3 = "0x";
|
|
9274
9317
|
function routeErc20Base() {
|
|
9275
9318
|
return {
|
|
9276
9319
|
async preflight(p, ctx) {
|
|
9277
|
-
await
|
|
9320
|
+
await wrapAs6(
|
|
9278
9321
|
"VALIDATION",
|
|
9279
9322
|
OP_DEPOSITS.base.assertErc20Asset,
|
|
9280
9323
|
() => {
|
|
@@ -9285,7 +9328,7 @@ function routeErc20Base() {
|
|
|
9285
9328
|
{ ctx: { token: p.token } }
|
|
9286
9329
|
);
|
|
9287
9330
|
const baseToken = ctx.baseTokenL1 ?? await ctx.client.baseToken(ctx.chainIdL2);
|
|
9288
|
-
await
|
|
9331
|
+
await wrapAs6(
|
|
9289
9332
|
"VALIDATION",
|
|
9290
9333
|
OP_DEPOSITS.base.assertMatchesBase,
|
|
9291
9334
|
() => {
|
|
@@ -9322,11 +9365,16 @@ function routeErc20Base() {
|
|
|
9322
9365
|
overrideGasLimit: quotedL2GasLimit
|
|
9323
9366
|
});
|
|
9324
9367
|
if (!l2Gas) throw new Error("Failed to estimate L2 gas parameters.");
|
|
9325
|
-
const
|
|
9368
|
+
const l1Fees = await quoteL1Fees2({ ctx });
|
|
9369
|
+
const l2BaseCost = await quoteL2BaseCost({
|
|
9370
|
+
ctx,
|
|
9371
|
+
l2GasLimit: l2Gas.gasLimit,
|
|
9372
|
+
l1GasPrice: l1Fees.maxFeePerGas
|
|
9373
|
+
});
|
|
9326
9374
|
const mintValue = l2BaseCost + ctx.operatorTip + p.amount;
|
|
9327
9375
|
const approvals = [];
|
|
9328
9376
|
const steps = [];
|
|
9329
|
-
const allowance = await
|
|
9377
|
+
const allowance = await wrapAs6(
|
|
9330
9378
|
"CONTRACT",
|
|
9331
9379
|
OP_DEPOSITS.base.allowance,
|
|
9332
9380
|
() => ctx.client.l1.readContract({
|
|
@@ -9342,7 +9390,7 @@ function routeErc20Base() {
|
|
|
9342
9390
|
);
|
|
9343
9391
|
const needsApprove = allowance < mintValue;
|
|
9344
9392
|
if (needsApprove) {
|
|
9345
|
-
const approveTx = await
|
|
9393
|
+
const approveTx = await wrapAs6(
|
|
9346
9394
|
"CONTRACT",
|
|
9347
9395
|
OP_DEPOSITS.base.estGas,
|
|
9348
9396
|
() => buildApprovalRequest({
|
|
@@ -9391,7 +9439,7 @@ function routeErc20Base() {
|
|
|
9391
9439
|
args: [req]
|
|
9392
9440
|
});
|
|
9393
9441
|
} else {
|
|
9394
|
-
const sim = await
|
|
9442
|
+
const sim = await wrapAs6(
|
|
9395
9443
|
"RPC",
|
|
9396
9444
|
OP_DEPOSITS.base.estGas,
|
|
9397
9445
|
() => ctx.client.l1.simulateContract({
|
|
@@ -9419,7 +9467,8 @@ function routeErc20Base() {
|
|
|
9419
9467
|
data: calldata,
|
|
9420
9468
|
value: 0n,
|
|
9421
9469
|
from: ctx.sender,
|
|
9422
|
-
...ctx.gasOverrides
|
|
9470
|
+
...ctx.gasOverrides,
|
|
9471
|
+
...l1Fees
|
|
9423
9472
|
};
|
|
9424
9473
|
const l1Gas = await quoteL1Gas2({
|
|
9425
9474
|
ctx,
|
|
@@ -9427,14 +9476,11 @@ function routeErc20Base() {
|
|
|
9427
9476
|
overrides: ctx.gasOverrides,
|
|
9428
9477
|
fallbackGasLimit: SAFE_L1_BRIDGE_GAS
|
|
9429
9478
|
});
|
|
9430
|
-
|
|
9431
|
-
bridgeTx
|
|
9432
|
-
|
|
9433
|
-
|
|
9434
|
-
|
|
9435
|
-
maxPriorityFeePerGas: l1Gas.maxPriorityFeePerGas
|
|
9436
|
-
};
|
|
9437
|
-
}
|
|
9479
|
+
bridgeTx = {
|
|
9480
|
+
...bridgeTx,
|
|
9481
|
+
...l1Fees,
|
|
9482
|
+
...l1Gas ? { gas: l1Gas.gasLimit } : {}
|
|
9483
|
+
};
|
|
9438
9484
|
steps.push({
|
|
9439
9485
|
key: "bridgehub:direct:erc20-base",
|
|
9440
9486
|
kind: "bridgehub:direct",
|
|
@@ -9532,7 +9578,7 @@ async function waitForL2ExecutionFromL1Tx(l1, l2, l1TxHash) {
|
|
|
9532
9578
|
}
|
|
9533
9579
|
return { l2Receipt, l2TxHash };
|
|
9534
9580
|
}
|
|
9535
|
-
var { wrapAs:
|
|
9581
|
+
var { wrapAs: wrapAs7 } = createErrorHandlers("tokens");
|
|
9536
9582
|
var ntvCodec3 = createNTVCodec({
|
|
9537
9583
|
encode: (types, values) => viem.encodeAbiParameters(
|
|
9538
9584
|
types.map((t, i) => ({ type: t, name: `arg${i}` })),
|
|
@@ -9547,7 +9593,7 @@ function createTokensResource(client) {
|
|
|
9547
9593
|
let wethL2Promise = null;
|
|
9548
9594
|
async function getL1ChainId() {
|
|
9549
9595
|
if (!l2NtvL1ChainIdPromise) {
|
|
9550
|
-
l2NtvL1ChainIdPromise =
|
|
9596
|
+
l2NtvL1ChainIdPromise = wrapAs7("INTERNAL", "getL1ChainId", async () => {
|
|
9551
9597
|
const { l2NativeTokenVault } = await client.contracts();
|
|
9552
9598
|
return await l2NativeTokenVault.read.L1_CHAIN_ID();
|
|
9553
9599
|
});
|
|
@@ -9556,7 +9602,7 @@ function createTokensResource(client) {
|
|
|
9556
9602
|
}
|
|
9557
9603
|
async function getBaseTokenAssetId() {
|
|
9558
9604
|
if (!baseTokenAssetIdPromise) {
|
|
9559
|
-
baseTokenAssetIdPromise =
|
|
9605
|
+
baseTokenAssetIdPromise = wrapAs7("INTERNAL", "baseTokenAssetId", async () => {
|
|
9560
9606
|
const { l2NativeTokenVault } = await client.contracts();
|
|
9561
9607
|
const assetId = await l2NativeTokenVault.read.BASE_TOKEN_ASSET_ID();
|
|
9562
9608
|
return assetId;
|
|
@@ -9566,7 +9612,7 @@ function createTokensResource(client) {
|
|
|
9566
9612
|
}
|
|
9567
9613
|
async function getWethL1() {
|
|
9568
9614
|
if (!wethL1Promise) {
|
|
9569
|
-
wethL1Promise =
|
|
9615
|
+
wethL1Promise = wrapAs7("INTERNAL", "wethL1", async () => {
|
|
9570
9616
|
const { l1NativeTokenVault } = await client.contracts();
|
|
9571
9617
|
const weth = await l1NativeTokenVault.read.WETH_TOKEN();
|
|
9572
9618
|
return weth;
|
|
@@ -9576,7 +9622,7 @@ function createTokensResource(client) {
|
|
|
9576
9622
|
}
|
|
9577
9623
|
async function getWethL2() {
|
|
9578
9624
|
if (!wethL2Promise) {
|
|
9579
|
-
wethL2Promise =
|
|
9625
|
+
wethL2Promise = wrapAs7("INTERNAL", "wethL2", async () => {
|
|
9580
9626
|
const { l2NativeTokenVault } = await client.contracts();
|
|
9581
9627
|
const weth = await l2NativeTokenVault.read.WETH_TOKEN();
|
|
9582
9628
|
return weth;
|
|
@@ -9585,7 +9631,7 @@ function createTokensResource(client) {
|
|
|
9585
9631
|
return wethL2Promise;
|
|
9586
9632
|
}
|
|
9587
9633
|
async function toL2Address(l1Token) {
|
|
9588
|
-
return
|
|
9634
|
+
return wrapAs7("CONTRACT", "tokens.toL2Address", async () => {
|
|
9589
9635
|
const normalized = normalizeL1Token(l1Token);
|
|
9590
9636
|
const chainId = BigInt(await client.l2.getChainId());
|
|
9591
9637
|
const baseToken = await client.baseToken(chainId);
|
|
@@ -9598,7 +9644,7 @@ function createTokensResource(client) {
|
|
|
9598
9644
|
});
|
|
9599
9645
|
}
|
|
9600
9646
|
async function toL1Address(l2Token) {
|
|
9601
|
-
return
|
|
9647
|
+
return wrapAs7("CONTRACT", "tokens.toL1Address", async () => {
|
|
9602
9648
|
if (isAddressEq(l2Token, ETH_ADDRESS)) return ETH_ADDRESS;
|
|
9603
9649
|
if (isAddressEq(l2Token, L2_BASE_TOKEN_ADDRESS)) {
|
|
9604
9650
|
const chainId = BigInt(await client.l2.getChainId());
|
|
@@ -9619,32 +9665,32 @@ function createTokensResource(client) {
|
|
|
9619
9665
|
});
|
|
9620
9666
|
}
|
|
9621
9667
|
async function assetIdOfL1(l1Token) {
|
|
9622
|
-
return
|
|
9668
|
+
return wrapAs7("CONTRACT", "tokens.assetIdOfL1", async () => {
|
|
9623
9669
|
const normalized = normalizeL1Token(l1Token);
|
|
9624
9670
|
const { l1NativeTokenVault } = await client.contracts();
|
|
9625
9671
|
return await l1NativeTokenVault.read.assetId([normalized]);
|
|
9626
9672
|
});
|
|
9627
9673
|
}
|
|
9628
9674
|
async function assetIdOfL2(l2Token) {
|
|
9629
|
-
return
|
|
9675
|
+
return wrapAs7("CONTRACT", "tokens.assetIdOfL2", async () => {
|
|
9630
9676
|
const { l2NativeTokenVault } = await client.contracts();
|
|
9631
9677
|
return await l2NativeTokenVault.read.assetId([l2Token]);
|
|
9632
9678
|
});
|
|
9633
9679
|
}
|
|
9634
9680
|
async function l2TokenFromAssetId(assetId) {
|
|
9635
|
-
return
|
|
9681
|
+
return wrapAs7("CONTRACT", "tokens.l2TokenFromAssetId", async () => {
|
|
9636
9682
|
const { l2NativeTokenVault } = await client.contracts();
|
|
9637
9683
|
return await l2NativeTokenVault.read.tokenAddress([assetId]);
|
|
9638
9684
|
});
|
|
9639
9685
|
}
|
|
9640
9686
|
async function l1TokenFromAssetId(assetId) {
|
|
9641
|
-
return
|
|
9687
|
+
return wrapAs7("CONTRACT", "tokens.l1TokenFromAssetId", async () => {
|
|
9642
9688
|
const { l1NativeTokenVault } = await client.contracts();
|
|
9643
9689
|
return await l1NativeTokenVault.read.tokenAddress([assetId]);
|
|
9644
9690
|
});
|
|
9645
9691
|
}
|
|
9646
9692
|
async function originChainId(assetId) {
|
|
9647
|
-
return
|
|
9693
|
+
return wrapAs7("CONTRACT", "tokens.originChainId", async () => {
|
|
9648
9694
|
const { l2NativeTokenVault } = await client.contracts();
|
|
9649
9695
|
return await l2NativeTokenVault.read.originChainId([assetId]);
|
|
9650
9696
|
});
|
|
@@ -9653,7 +9699,7 @@ function createTokensResource(client) {
|
|
|
9653
9699
|
return getBaseTokenAssetId();
|
|
9654
9700
|
}
|
|
9655
9701
|
async function isChainEthBased() {
|
|
9656
|
-
return
|
|
9702
|
+
return wrapAs7("CONTRACT", "tokens.isChainEthBased", async () => {
|
|
9657
9703
|
const baseAssetId = await getBaseTokenAssetId();
|
|
9658
9704
|
const l1ChainId = await getL1ChainId();
|
|
9659
9705
|
const ethAssetId = ntvCodec3.encodeAssetId(
|
|
@@ -9671,7 +9717,7 @@ function createTokensResource(client) {
|
|
|
9671
9717
|
return getWethL2();
|
|
9672
9718
|
}
|
|
9673
9719
|
async function computeL2BridgedAddress(args) {
|
|
9674
|
-
return
|
|
9720
|
+
return wrapAs7("CONTRACT", "tokens.computeL2BridgedAddress", async () => {
|
|
9675
9721
|
const normalized = normalizeL1Token(args.l1Token);
|
|
9676
9722
|
const { l2NativeTokenVault } = await client.contracts();
|
|
9677
9723
|
const predicted = await l2NativeTokenVault.read.calculateCreate2TokenAddress([
|
|
@@ -9682,7 +9728,7 @@ function createTokensResource(client) {
|
|
|
9682
9728
|
});
|
|
9683
9729
|
}
|
|
9684
9730
|
async function resolve(ref, opts) {
|
|
9685
|
-
return
|
|
9731
|
+
return wrapAs7("CONTRACT", "tokens.resolve", async () => {
|
|
9686
9732
|
let chain;
|
|
9687
9733
|
let address;
|
|
9688
9734
|
if (typeof ref === "string") {
|
|
@@ -10270,12 +10316,12 @@ function buildFeeBreakdown2(p) {
|
|
|
10270
10316
|
}
|
|
10271
10317
|
|
|
10272
10318
|
// src/adapters/viem/resources/withdrawals/routes/eth.ts
|
|
10273
|
-
var { wrapAs:
|
|
10319
|
+
var { wrapAs: wrapAs8 } = createErrorHandlers("withdrawals");
|
|
10274
10320
|
function routeEthBase() {
|
|
10275
10321
|
return {
|
|
10276
10322
|
async build(p, ctx) {
|
|
10277
10323
|
const steps = [];
|
|
10278
|
-
const data = await
|
|
10324
|
+
const data = await wrapAs8(
|
|
10279
10325
|
"INTERNAL",
|
|
10280
10326
|
OP_WITHDRAWALS.eth.encodeWithdraw,
|
|
10281
10327
|
() => Promise.resolve(
|
|
@@ -10325,14 +10371,14 @@ function routeEthBase() {
|
|
|
10325
10371
|
}
|
|
10326
10372
|
};
|
|
10327
10373
|
}
|
|
10328
|
-
var { wrapAs:
|
|
10374
|
+
var { wrapAs: wrapAs9 } = createErrorHandlers("withdrawals");
|
|
10329
10375
|
function routeErc20NonBase2() {
|
|
10330
10376
|
return {
|
|
10331
10377
|
// TODO: add preflight validations here
|
|
10332
10378
|
async build(p, ctx) {
|
|
10333
10379
|
const steps = [];
|
|
10334
10380
|
const approvals = [];
|
|
10335
|
-
const current = await
|
|
10381
|
+
const current = await wrapAs9(
|
|
10336
10382
|
"CONTRACT",
|
|
10337
10383
|
OP_WITHDRAWALS.erc20.allowance,
|
|
10338
10384
|
() => ctx.client.l2.readContract({
|
|
@@ -10371,7 +10417,7 @@ function routeErc20NonBase2() {
|
|
|
10371
10417
|
approveTxCandidate.maxFeePerGas = approveGas.maxFeePerGas;
|
|
10372
10418
|
approveTxCandidate.maxPriorityFeePerGas = approveGas.maxPriorityFeePerGas;
|
|
10373
10419
|
}
|
|
10374
|
-
const approveSim = await
|
|
10420
|
+
const approveSim = await wrapAs9(
|
|
10375
10421
|
"CONTRACT",
|
|
10376
10422
|
OP_WITHDRAWALS.erc20.estGas,
|
|
10377
10423
|
() => ctx.client.l2.simulateContract({
|
|
@@ -10398,7 +10444,7 @@ function routeErc20NonBase2() {
|
|
|
10398
10444
|
tx: approveTx
|
|
10399
10445
|
});
|
|
10400
10446
|
}
|
|
10401
|
-
const assetId = (await
|
|
10447
|
+
const assetId = (await wrapAs9(
|
|
10402
10448
|
"CONTRACT",
|
|
10403
10449
|
OP_WITHDRAWALS.erc20.ensureRegistered,
|
|
10404
10450
|
() => ctx.client.l2.simulateContract({
|
|
@@ -10449,7 +10495,7 @@ function routeErc20NonBase2() {
|
|
|
10449
10495
|
...withdrawGas
|
|
10450
10496
|
};
|
|
10451
10497
|
} else {
|
|
10452
|
-
const sim = await
|
|
10498
|
+
const sim = await wrapAs9(
|
|
10453
10499
|
"CONTRACT",
|
|
10454
10500
|
OP_WITHDRAWALS.erc20.estGas,
|
|
10455
10501
|
() => ctx.client.l2.simulateContract({
|
|
@@ -10611,7 +10657,7 @@ function buildWithdrawalBundle(input) {
|
|
|
10611
10657
|
}
|
|
10612
10658
|
|
|
10613
10659
|
// src/adapters/viem/resources/withdrawals/routes/interop-bundle.ts
|
|
10614
|
-
var { wrapAs:
|
|
10660
|
+
var { wrapAs: wrapAs10 } = createErrorHandlers("withdrawals");
|
|
10615
10661
|
var attributes = createViemAttributesResource();
|
|
10616
10662
|
function saltFor(sender, nonce) {
|
|
10617
10663
|
return viem.keccak256(
|
|
@@ -10636,7 +10682,7 @@ function routeInteropBundle() {
|
|
|
10636
10682
|
if (isBaseToken) {
|
|
10637
10683
|
assetId = ctx.baseTokenAssetId;
|
|
10638
10684
|
} else {
|
|
10639
|
-
assetId = (await
|
|
10685
|
+
assetId = (await wrapAs10(
|
|
10640
10686
|
"CONTRACT",
|
|
10641
10687
|
OP_WITHDRAWALS.erc20.ensureRegistered,
|
|
10642
10688
|
() => ctx.client.l2.simulateContract({
|
|
@@ -10651,7 +10697,7 @@ function routeInteropBundle() {
|
|
|
10651
10697
|
message: "Failed to ensure token is registered in L2NativeTokenVault."
|
|
10652
10698
|
}
|
|
10653
10699
|
)).result;
|
|
10654
|
-
const current = await
|
|
10700
|
+
const current = await wrapAs10(
|
|
10655
10701
|
"CONTRACT",
|
|
10656
10702
|
OP_WITHDRAWALS.erc20.allowance,
|
|
10657
10703
|
() => ctx.client.l2.readContract({
|
|
@@ -10700,7 +10746,7 @@ function routeInteropBundle() {
|
|
|
10700
10746
|
});
|
|
10701
10747
|
}
|
|
10702
10748
|
}
|
|
10703
|
-
const nonce = await
|
|
10749
|
+
const nonce = await wrapAs10(
|
|
10704
10750
|
"RPC",
|
|
10705
10751
|
OP_WITHDRAWALS.prepare,
|
|
10706
10752
|
() => ctx.client.l2.getTransactionCount({ address: ctx.sender, blockTag: "pending" }),
|
|
@@ -10936,7 +10982,7 @@ function createWithdrawalProtocolService(client, override) {
|
|
|
10936
10982
|
}
|
|
10937
10983
|
};
|
|
10938
10984
|
}
|
|
10939
|
-
var { wrapAs:
|
|
10985
|
+
var { wrapAs: wrapAs11 } = createErrorHandlers("withdrawals");
|
|
10940
10986
|
var IL1NullifierMini = [
|
|
10941
10987
|
{
|
|
10942
10988
|
type: "function",
|
|
@@ -10954,7 +11000,7 @@ function createFinalizationServices(client, protocolService = createWithdrawalPr
|
|
|
10954
11000
|
async function finalizationTarget(protocol) {
|
|
10955
11001
|
const { l1Nullifier } = await client.ensureAddresses();
|
|
10956
11002
|
if (protocol === "legacy-withdrawal") return l1Nullifier;
|
|
10957
|
-
return await
|
|
11003
|
+
return await wrapAs11(
|
|
10958
11004
|
"CONTRACT",
|
|
10959
11005
|
OP_WITHDRAWALS.finalize.fetchParams.receipt,
|
|
10960
11006
|
() => client.l1.readContract({
|
|
@@ -10969,7 +11015,7 @@ function createFinalizationServices(client, protocolService = createWithdrawalPr
|
|
|
10969
11015
|
);
|
|
10970
11016
|
}
|
|
10971
11017
|
async function fetchMessageAndProof(l2TxHash) {
|
|
10972
|
-
const raw = await
|
|
11018
|
+
const raw = await wrapAs11(
|
|
10973
11019
|
"RPC",
|
|
10974
11020
|
OP_WITHDRAWALS.finalize.fetchParams.receipt,
|
|
10975
11021
|
() => client.zks.getReceiptWithL2ToL1(l2TxHash),
|
|
@@ -10986,7 +11032,7 @@ function createFinalizationServices(client, protocolService = createWithdrawalPr
|
|
|
10986
11032
|
context: { l2TxHash }
|
|
10987
11033
|
});
|
|
10988
11034
|
}
|
|
10989
|
-
const ev = await
|
|
11035
|
+
const ev = await wrapAs11(
|
|
10990
11036
|
"INTERNAL",
|
|
10991
11037
|
OP_WITHDRAWALS.finalize.fetchParams.findMessage,
|
|
10992
11038
|
// eslint-disable-next-line @typescript-eslint/no-unsafe-argument, @typescript-eslint/no-explicit-any
|
|
@@ -10996,7 +11042,7 @@ function createFinalizationServices(client, protocolService = createWithdrawalPr
|
|
|
10996
11042
|
message: "Failed to locate L1MessageSent event in L2 receipt."
|
|
10997
11043
|
}
|
|
10998
11044
|
);
|
|
10999
|
-
const message = await
|
|
11045
|
+
const message = await wrapAs11(
|
|
11000
11046
|
"INTERNAL",
|
|
11001
11047
|
OP_WITHDRAWALS.finalize.fetchParams.decodeMessage,
|
|
11002
11048
|
() => {
|
|
@@ -11008,7 +11054,7 @@ function createFinalizationServices(client, protocolService = createWithdrawalPr
|
|
|
11008
11054
|
message: "Failed to decode withdrawal message."
|
|
11009
11055
|
}
|
|
11010
11056
|
);
|
|
11011
|
-
const idx = await
|
|
11057
|
+
const idx = await wrapAs11(
|
|
11012
11058
|
"INTERNAL",
|
|
11013
11059
|
OP_WITHDRAWALS.finalize.fetchParams.messengerIndex,
|
|
11014
11060
|
() => Promise.resolve(messengerLogIndex(raw, { index: 0, messenger: L1_MESSENGER_ADDRESS })),
|
|
@@ -11017,7 +11063,7 @@ function createFinalizationServices(client, protocolService = createWithdrawalPr
|
|
|
11017
11063
|
message: "Failed to derive messenger log index."
|
|
11018
11064
|
}
|
|
11019
11065
|
);
|
|
11020
|
-
const proof = await
|
|
11066
|
+
const proof = await wrapAs11(
|
|
11021
11067
|
"RPC",
|
|
11022
11068
|
OP_WITHDRAWALS.finalize.fetchParams.proof,
|
|
11023
11069
|
() => client.zks.getL2ToL1LogProof(l2TxHash, idx),
|
|
@@ -11026,7 +11072,7 @@ function createFinalizationServices(client, protocolService = createWithdrawalPr
|
|
|
11026
11072
|
message: "Failed to fetch L2\u2192L1 log proof."
|
|
11027
11073
|
}
|
|
11028
11074
|
);
|
|
11029
|
-
const chainId = await
|
|
11075
|
+
const chainId = await wrapAs11(
|
|
11030
11076
|
"RPC",
|
|
11031
11077
|
OP_WITHDRAWALS.finalize.fetchParams.network,
|
|
11032
11078
|
() => client.l2.getChainId(),
|
|
@@ -11084,7 +11130,7 @@ function createFinalizationServices(client, protocolService = createWithdrawalPr
|
|
|
11084
11130
|
async function withdrawalOutcome(finalization) {
|
|
11085
11131
|
const target = await finalizationTarget(finalization.protocol);
|
|
11086
11132
|
if (finalization.protocol === "legacy-withdrawal") {
|
|
11087
|
-
const done = await
|
|
11133
|
+
const done = await wrapAs11(
|
|
11088
11134
|
"RPC",
|
|
11089
11135
|
OP_WITHDRAWALS.finalize.isFinalized,
|
|
11090
11136
|
() => client.l1.readContract({
|
|
@@ -11106,7 +11152,7 @@ function createFinalizationServices(client, protocolService = createWithdrawalPr
|
|
|
11106
11152
|
}
|
|
11107
11153
|
const { bundleHash } = finalization.params;
|
|
11108
11154
|
const status = Number(
|
|
11109
|
-
await
|
|
11155
|
+
await wrapAs11(
|
|
11110
11156
|
"RPC",
|
|
11111
11157
|
OP_WITHDRAWALS.finalize.isFinalized,
|
|
11112
11158
|
() => client.l1.readContract({
|
|
@@ -11123,7 +11169,7 @@ function createFinalizationServices(client, protocolService = createWithdrawalPr
|
|
|
11123
11169
|
);
|
|
11124
11170
|
if (status !== 3 /* Unbundled */) return classifyWithdrawalOutcome(status);
|
|
11125
11171
|
const callStatus = Number(
|
|
11126
|
-
await
|
|
11172
|
+
await wrapAs11(
|
|
11127
11173
|
"RPC",
|
|
11128
11174
|
OP_WITHDRAWALS.finalize.isFinalized,
|
|
11129
11175
|
() => client.l1.readContract({
|
|
@@ -11194,7 +11240,7 @@ function createFinalizationServices(client, protocolService = createWithdrawalPr
|
|
|
11194
11240
|
},
|
|
11195
11241
|
async estimateFinalization(finalization) {
|
|
11196
11242
|
const target = await finalizationTarget(finalization.protocol);
|
|
11197
|
-
const gasLimit = await
|
|
11243
|
+
const gasLimit = await wrapAs11(
|
|
11198
11244
|
"RPC",
|
|
11199
11245
|
OP_WITHDRAWALS.finalize.estimate,
|
|
11200
11246
|
() => finalization.protocol === "legacy-withdrawal" ? client.l1.estimateContractGas({
|
|
@@ -11222,7 +11268,7 @@ function createFinalizationServices(client, protocolService = createWithdrawalPr
|
|
|
11222
11268
|
let maxFeePerGas;
|
|
11223
11269
|
let maxPriorityFeePerGas;
|
|
11224
11270
|
try {
|
|
11225
|
-
const fee = await
|
|
11271
|
+
const fee = await wrapAs11(
|
|
11226
11272
|
"RPC",
|
|
11227
11273
|
OP_WITHDRAWALS.finalize.estimate,
|
|
11228
11274
|
() => client.l1.estimateFeesPerGas(),
|
|
@@ -11241,7 +11287,7 @@ function createFinalizationServices(client, protocolService = createWithdrawalPr
|
|
|
11241
11287
|
})();
|
|
11242
11288
|
maxPriorityFeePerGas = fee.maxPriorityFeePerGas ?? 0n;
|
|
11243
11289
|
} catch {
|
|
11244
|
-
const gasPrice = await
|
|
11290
|
+
const gasPrice = await wrapAs11(
|
|
11245
11291
|
"RPC",
|
|
11246
11292
|
OP_WITHDRAWALS.finalize.estimate,
|
|
11247
11293
|
() => client.l1.getGasPrice(),
|