@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
|
@@ -6299,7 +6299,7 @@ function createErrorOps(decodeRevert2) {
|
|
|
6299
6299
|
function wrap7(operation, fn, opts) {
|
|
6300
6300
|
return run("INTERNAL", operation, fn, opts);
|
|
6301
6301
|
}
|
|
6302
|
-
function
|
|
6302
|
+
function wrapAs12(kind, operation, fn, opts) {
|
|
6303
6303
|
return run(kind, operation, fn, opts);
|
|
6304
6304
|
}
|
|
6305
6305
|
async function toResult3(operation, fn, opts) {
|
|
@@ -6320,7 +6320,7 @@ function createErrorOps(decodeRevert2) {
|
|
|
6320
6320
|
return { ok: false, error: shaped };
|
|
6321
6321
|
}
|
|
6322
6322
|
}
|
|
6323
|
-
return { wrap: wrap7, wrapAs:
|
|
6323
|
+
return { wrap: wrap7, wrapAs: wrapAs12, toResult: toResult3 };
|
|
6324
6324
|
}
|
|
6325
6325
|
return { toZKsyncError: toZKsyncError2, createErrorHandlers: createErrorHandlers2 };
|
|
6326
6326
|
}
|
|
@@ -6469,6 +6469,7 @@ function isEraVmChain(chainIdL2) {
|
|
|
6469
6469
|
|
|
6470
6470
|
// src/core/resources/deposits/gas.ts
|
|
6471
6471
|
var CREATE_REESTIMATE_BUFFER = 15n;
|
|
6472
|
+
var ZERO_FEES = { maxFeePerGas: 0n, maxPriorityFeePerGas: 0n };
|
|
6472
6473
|
var maxBigInt = (a, b) => a > b ? a : b;
|
|
6473
6474
|
function applyGasBuffer(gasLimit, bufferPct = BUFFER) {
|
|
6474
6475
|
return gasLimit * (100n + bufferPct) / 100n;
|
|
@@ -6519,15 +6520,39 @@ async function fetchFees(estimator) {
|
|
|
6519
6520
|
const gp = await estimator.getGasPrice();
|
|
6520
6521
|
return { maxFeePerGas: gp, maxPriorityFeePerGas: 0n };
|
|
6521
6522
|
} catch {
|
|
6522
|
-
return
|
|
6523
|
+
return void 0;
|
|
6523
6524
|
}
|
|
6524
6525
|
}
|
|
6526
|
+
async function quoteL1Fees(input) {
|
|
6527
|
+
const { estimator, overrides } = input;
|
|
6528
|
+
const maxFeeOverride = overrides?.maxFeePerGas;
|
|
6529
|
+
const tipOverride = overrides?.maxPriorityFeePerGas;
|
|
6530
|
+
if (maxFeeOverride != null && tipOverride != null) {
|
|
6531
|
+
return { maxFeePerGas: maxFeeOverride, maxPriorityFeePerGas: tipOverride };
|
|
6532
|
+
}
|
|
6533
|
+
const market = await fetchFees(estimator);
|
|
6534
|
+
if (maxFeeOverride != null) {
|
|
6535
|
+
const tip = market?.maxPriorityFeePerGas ?? 0n;
|
|
6536
|
+
return {
|
|
6537
|
+
maxFeePerGas: maxFeeOverride,
|
|
6538
|
+
maxPriorityFeePerGas: tip < maxFeeOverride ? tip : maxFeeOverride
|
|
6539
|
+
};
|
|
6540
|
+
}
|
|
6541
|
+
if (market == null) {
|
|
6542
|
+
throw new Error("Could not fetch L1 gas price for Bridgehub base cost calculation.");
|
|
6543
|
+
}
|
|
6544
|
+
if (tipOverride != null) {
|
|
6545
|
+
const headroom = market.maxFeePerGas > market.maxPriorityFeePerGas ? market.maxFeePerGas - market.maxPriorityFeePerGas : 0n;
|
|
6546
|
+
return { maxFeePerGas: headroom + tipOverride, maxPriorityFeePerGas: tipOverride };
|
|
6547
|
+
}
|
|
6548
|
+
return market;
|
|
6549
|
+
}
|
|
6525
6550
|
async function quoteL1Gas(input) {
|
|
6526
6551
|
const { estimator, tx, overrides, fallbackGasLimit } = input;
|
|
6527
6552
|
let market;
|
|
6528
6553
|
const getMarket = async () => {
|
|
6529
6554
|
if (market) return market;
|
|
6530
|
-
market = await fetchFees(estimator);
|
|
6555
|
+
market = await fetchFees(estimator) ?? ZERO_FEES;
|
|
6531
6556
|
return market;
|
|
6532
6557
|
};
|
|
6533
6558
|
const maxFeePerGas = overrides?.maxFeePerGas ?? (tx.maxFeePerGas != null ? BigInt(tx.maxFeePerGas) : (await getMarket()).maxFeePerGas);
|
|
@@ -6549,7 +6574,7 @@ async function quoteL1Gas(input) {
|
|
|
6549
6574
|
}
|
|
6550
6575
|
async function quoteL2Gas(input) {
|
|
6551
6576
|
const { estimator, route, tx, gasPerPubdata, l2GasLimit, overrideGasLimit, stateOverrides } = input;
|
|
6552
|
-
const market = await fetchFees(estimator);
|
|
6577
|
+
const market = await fetchFees(estimator) ?? ZERO_FEES;
|
|
6553
6578
|
const maxFeePerGas = market.maxFeePerGas || market.maxPriorityFeePerGas || 0n;
|
|
6554
6579
|
const txGasLimit = tx?.gasLimit != null ? BigInt(tx.gasLimit) : void 0;
|
|
6555
6580
|
const explicit = overrideGasLimit ?? txGasLimit;
|
|
@@ -6749,6 +6774,7 @@ function viemToGasEstimator(client) {
|
|
|
6749
6774
|
}
|
|
6750
6775
|
|
|
6751
6776
|
// src/adapters/viem/resources/deposits/services/gas.ts
|
|
6777
|
+
var { wrapAs } = createErrorHandlers("deposits");
|
|
6752
6778
|
var DEFAULT_SAFE_NONBASE_L2_GAS_LIMIT = 3000000n;
|
|
6753
6779
|
async function estimatePriorityTxL2Gas(ctx, leg) {
|
|
6754
6780
|
if (!leg) return void 0;
|
|
@@ -6758,6 +6784,18 @@ async function estimatePriorityTxL2Gas(ctx, leg) {
|
|
|
6758
6784
|
return void 0;
|
|
6759
6785
|
}
|
|
6760
6786
|
}
|
|
6787
|
+
async function quoteL1Fees2(input) {
|
|
6788
|
+
const { ctx } = input;
|
|
6789
|
+
return wrapAs(
|
|
6790
|
+
"RPC",
|
|
6791
|
+
"deposits.fees.l1",
|
|
6792
|
+
() => quoteL1Fees({
|
|
6793
|
+
estimator: viemToGasEstimator(ctx.client.l1),
|
|
6794
|
+
overrides: ctx.gasOverrides
|
|
6795
|
+
}),
|
|
6796
|
+
{ ctx: { chainIdL2: ctx.chainIdL2 } }
|
|
6797
|
+
);
|
|
6798
|
+
}
|
|
6761
6799
|
async function quoteL1Gas2(input) {
|
|
6762
6800
|
const { ctx, tx, overrides, fallbackGasLimit } = input;
|
|
6763
6801
|
const estimator = viemToGasEstimator(ctx.client.l1);
|
|
@@ -6860,13 +6898,10 @@ async function determineEthNonBaseL2Gas(input) {
|
|
|
6860
6898
|
}
|
|
6861
6899
|
|
|
6862
6900
|
// src/adapters/viem/resources/deposits/services/fee.ts
|
|
6863
|
-
var { wrapAs } = createErrorHandlers("deposits");
|
|
6901
|
+
var { wrapAs: wrapAs2 } = createErrorHandlers("deposits");
|
|
6864
6902
|
async function quoteL2BaseCost(input) {
|
|
6865
|
-
const { ctx, l2GasLimit } = input;
|
|
6866
|
-
|
|
6867
|
-
const fees = await estimator.estimateFeesPerGas();
|
|
6868
|
-
const gasPrice = fees.maxFeePerGas ?? fees.gasPrice ?? await estimator.getGasPrice();
|
|
6869
|
-
return wrapAs(
|
|
6903
|
+
const { ctx, l2GasLimit, l1GasPrice } = input;
|
|
6904
|
+
return wrapAs2(
|
|
6870
6905
|
"RPC",
|
|
6871
6906
|
"deposits.fees.l2BaseCost",
|
|
6872
6907
|
async () => {
|
|
@@ -6874,7 +6909,7 @@ async function quoteL2BaseCost(input) {
|
|
|
6874
6909
|
address: ctx.bridgehub,
|
|
6875
6910
|
abi: IBridgehub_default,
|
|
6876
6911
|
functionName: "l2TransactionBaseCost",
|
|
6877
|
-
args: [ctx.chainIdL2,
|
|
6912
|
+
args: [ctx.chainIdL2, l1GasPrice, l2GasLimit, ctx.gasPerPubdata]
|
|
6878
6913
|
});
|
|
6879
6914
|
},
|
|
6880
6915
|
{ ctx: { chainIdL2: ctx.chainIdL2 } }
|
|
@@ -6969,7 +7004,7 @@ function getPriorityTxGasBreakdown(input) {
|
|
|
6969
7004
|
}
|
|
6970
7005
|
|
|
6971
7006
|
// src/adapters/viem/resources/deposits/routes/eth.ts
|
|
6972
|
-
var { wrapAs:
|
|
7007
|
+
var { wrapAs: wrapAs3 } = createErrorHandlers("deposits");
|
|
6973
7008
|
var EMPTY_BYTES2 = "0x";
|
|
6974
7009
|
function routeEthDirect() {
|
|
6975
7010
|
return {
|
|
@@ -7000,7 +7035,12 @@ function routeEthDirect() {
|
|
|
7000
7035
|
if (!l2GasParams) {
|
|
7001
7036
|
throw new Error("Failed to estimate L2 gas for deposit.");
|
|
7002
7037
|
}
|
|
7003
|
-
const
|
|
7038
|
+
const l1Fees = await quoteL1Fees2({ ctx });
|
|
7039
|
+
const baseCost = await quoteL2BaseCost({
|
|
7040
|
+
ctx,
|
|
7041
|
+
l2GasLimit: l2GasParams.gasLimit,
|
|
7042
|
+
l1GasPrice: l1Fees.maxFeePerGas
|
|
7043
|
+
});
|
|
7004
7044
|
const mintValue = baseCost + ctx.operatorTip + l2Value;
|
|
7005
7045
|
const req = buildDirectRequestStruct({
|
|
7006
7046
|
chainId: ctx.chainIdL2,
|
|
@@ -7011,7 +7051,7 @@ function routeEthDirect() {
|
|
|
7011
7051
|
l2Contract,
|
|
7012
7052
|
l2Value
|
|
7013
7053
|
});
|
|
7014
|
-
const sim = await
|
|
7054
|
+
const sim = await wrapAs3(
|
|
7015
7055
|
"RPC",
|
|
7016
7056
|
OP_DEPOSITS.eth.estGas,
|
|
7017
7057
|
() => ctx.client.l1.simulateContract({
|
|
@@ -7037,22 +7077,19 @@ function routeEthDirect() {
|
|
|
7037
7077
|
data,
|
|
7038
7078
|
value: mintValue,
|
|
7039
7079
|
from: ctx.sender,
|
|
7040
|
-
...ctx.gasOverrides
|
|
7080
|
+
...ctx.gasOverrides,
|
|
7081
|
+
...l1Fees
|
|
7041
7082
|
};
|
|
7042
7083
|
const l1Gas = await quoteL1Gas2({
|
|
7043
7084
|
ctx,
|
|
7044
7085
|
tx: l1TxCandidate,
|
|
7045
7086
|
overrides: ctx.gasOverrides
|
|
7046
7087
|
});
|
|
7047
|
-
|
|
7048
|
-
|
|
7049
|
-
|
|
7050
|
-
|
|
7051
|
-
|
|
7052
|
-
maxFeePerGas: l1Gas.maxFeePerGas,
|
|
7053
|
-
maxPriorityFeePerGas: l1Gas.maxPriorityFeePerGas
|
|
7054
|
-
};
|
|
7055
|
-
}
|
|
7088
|
+
const bridgeTx = {
|
|
7089
|
+
...sim.request,
|
|
7090
|
+
...l1Fees,
|
|
7091
|
+
...l1Gas ? { gas: l1Gas.gasLimit } : {}
|
|
7092
|
+
};
|
|
7056
7093
|
const steps = [
|
|
7057
7094
|
{
|
|
7058
7095
|
key: "bridgehub:direct",
|
|
@@ -7140,7 +7177,7 @@ async function buildApprovalRequest({
|
|
|
7140
7177
|
}
|
|
7141
7178
|
|
|
7142
7179
|
// src/adapters/viem/resources/deposits/routes/erc20-nonbase.ts
|
|
7143
|
-
var { wrapAs:
|
|
7180
|
+
var { wrapAs: wrapAs4 } = createErrorHandlers("deposits");
|
|
7144
7181
|
var ZERO_ASSET_ID = "0x0000000000000000000000000000000000000000000000000000000000000000";
|
|
7145
7182
|
var ntvCodec = createNTVCodec({
|
|
7146
7183
|
encode: (types, values) => viem.encodeAbiParameters(
|
|
@@ -7231,7 +7268,7 @@ function routeErc20NonBase() {
|
|
|
7231
7268
|
return {
|
|
7232
7269
|
// TODO: do we even need these validations?
|
|
7233
7270
|
async preflight(p, ctx) {
|
|
7234
|
-
await
|
|
7271
|
+
await wrapAs4(
|
|
7235
7272
|
"VALIDATION",
|
|
7236
7273
|
OP_DEPOSITS.nonbase.assertNotEthAsset,
|
|
7237
7274
|
() => {
|
|
@@ -7242,7 +7279,7 @@ function routeErc20NonBase() {
|
|
|
7242
7279
|
{ ctx: { token: p.token } }
|
|
7243
7280
|
);
|
|
7244
7281
|
const baseToken = ctx.baseTokenL1 ?? await ctx.client.baseToken(ctx.chainIdL2);
|
|
7245
|
-
await
|
|
7282
|
+
await wrapAs4(
|
|
7246
7283
|
"VALIDATION",
|
|
7247
7284
|
OP_DEPOSITS.nonbase.assertNonBaseToken,
|
|
7248
7285
|
() => {
|
|
@@ -7259,7 +7296,7 @@ function routeErc20NonBase() {
|
|
|
7259
7296
|
const assetRouter = ctx.l1AssetRouter;
|
|
7260
7297
|
const nativeTokenVault = ctx.l1NativeTokenVault;
|
|
7261
7298
|
const receiver = p.to ?? ctx.sender;
|
|
7262
|
-
const secondBridgeCalldata = await
|
|
7299
|
+
const secondBridgeCalldata = await wrapAs4(
|
|
7263
7300
|
"INTERNAL",
|
|
7264
7301
|
OP_DEPOSITS.nonbase.encodeCalldata,
|
|
7265
7302
|
() => encodeSecondBridgeErc20DepositCalldata({
|
|
@@ -7297,11 +7334,16 @@ function routeErc20NonBase() {
|
|
|
7297
7334
|
}
|
|
7298
7335
|
});
|
|
7299
7336
|
if (!l2Gas) throw new Error("Failed to establish L2 gas parameters.");
|
|
7300
|
-
const
|
|
7337
|
+
const l1Fees = await quoteL1Fees2({ ctx });
|
|
7338
|
+
const l2BaseCost = await quoteL2BaseCost({
|
|
7339
|
+
ctx,
|
|
7340
|
+
l2GasLimit: l2Gas.gasLimit,
|
|
7341
|
+
l1GasPrice: l1Fees.maxFeePerGas
|
|
7342
|
+
});
|
|
7301
7343
|
const mintValue = l2BaseCost + ctx.operatorTip;
|
|
7302
7344
|
const approvals = [];
|
|
7303
7345
|
const steps = [];
|
|
7304
|
-
const depositAllowance = await
|
|
7346
|
+
const depositAllowance = await wrapAs4(
|
|
7305
7347
|
"CONTRACT",
|
|
7306
7348
|
OP_DEPOSITS.nonbase.allowanceToken,
|
|
7307
7349
|
() => ctx.client.l1.readContract({
|
|
@@ -7316,7 +7358,7 @@ function routeErc20NonBase() {
|
|
|
7316
7358
|
}
|
|
7317
7359
|
);
|
|
7318
7360
|
if (depositAllowance < p.amount) {
|
|
7319
|
-
const approveTx = await
|
|
7361
|
+
const approveTx = await wrapAs4(
|
|
7320
7362
|
"CONTRACT",
|
|
7321
7363
|
OP_DEPOSITS.nonbase.estGas,
|
|
7322
7364
|
() => buildApprovalRequest({
|
|
@@ -7339,7 +7381,7 @@ function routeErc20NonBase() {
|
|
|
7339
7381
|
});
|
|
7340
7382
|
}
|
|
7341
7383
|
if (!baseIsEth) {
|
|
7342
|
-
const baseAllowance = await
|
|
7384
|
+
const baseAllowance = await wrapAs4(
|
|
7343
7385
|
"CONTRACT",
|
|
7344
7386
|
OP_DEPOSITS.nonbase.allowanceBase,
|
|
7345
7387
|
() => ctx.client.l1.readContract({
|
|
@@ -7354,7 +7396,7 @@ function routeErc20NonBase() {
|
|
|
7354
7396
|
}
|
|
7355
7397
|
);
|
|
7356
7398
|
if (baseAllowance < mintValue) {
|
|
7357
|
-
const approveBaseTx = await
|
|
7399
|
+
const approveBaseTx = await wrapAs4(
|
|
7358
7400
|
"CONTRACT",
|
|
7359
7401
|
OP_DEPOSITS.nonbase.estGas,
|
|
7360
7402
|
() => buildApprovalRequest({
|
|
@@ -7399,7 +7441,8 @@ function routeErc20NonBase() {
|
|
|
7399
7441
|
data: calldata,
|
|
7400
7442
|
value: msgValue,
|
|
7401
7443
|
from: ctx.sender,
|
|
7402
|
-
...ctx.gasOverrides
|
|
7444
|
+
...ctx.gasOverrides,
|
|
7445
|
+
...l1Fees
|
|
7403
7446
|
};
|
|
7404
7447
|
const l1Gas = await quoteL1Gas2({
|
|
7405
7448
|
ctx,
|
|
@@ -7419,7 +7462,7 @@ function routeErc20NonBase() {
|
|
|
7419
7462
|
account: ctx.client.account
|
|
7420
7463
|
};
|
|
7421
7464
|
} else {
|
|
7422
|
-
const sim = await
|
|
7465
|
+
const sim = await wrapAs4(
|
|
7423
7466
|
"CONTRACT",
|
|
7424
7467
|
OP_DEPOSITS.nonbase.estGas,
|
|
7425
7468
|
() => ctx.client.l1.simulateContract({
|
|
@@ -7437,14 +7480,11 @@ function routeErc20NonBase() {
|
|
|
7437
7480
|
);
|
|
7438
7481
|
bridgeTx = { ...sim.request };
|
|
7439
7482
|
}
|
|
7440
|
-
|
|
7441
|
-
bridgeTx
|
|
7442
|
-
|
|
7443
|
-
|
|
7444
|
-
|
|
7445
|
-
maxPriorityFeePerGas: l1Gas.maxPriorityFeePerGas
|
|
7446
|
-
};
|
|
7447
|
-
}
|
|
7483
|
+
bridgeTx = {
|
|
7484
|
+
...bridgeTx,
|
|
7485
|
+
...l1Fees,
|
|
7486
|
+
...l1Gas ? { gas: l1Gas.gasLimit } : {}
|
|
7487
|
+
};
|
|
7448
7488
|
steps.push({
|
|
7449
7489
|
key: "bridgehub:two-bridges:erc20-nonbase",
|
|
7450
7490
|
kind: "bridgehub:two-bridges",
|
|
@@ -7467,7 +7507,7 @@ function routeErc20NonBase() {
|
|
|
7467
7507
|
}
|
|
7468
7508
|
};
|
|
7469
7509
|
}
|
|
7470
|
-
var { wrapAs:
|
|
7510
|
+
var { wrapAs: wrapAs5 } = createErrorHandlers("deposits");
|
|
7471
7511
|
var ZERO_ASSET_ID2 = "0x0000000000000000000000000000000000000000000000000000000000000000";
|
|
7472
7512
|
var ntvCodec2 = createNTVCodec({
|
|
7473
7513
|
encode: (types, values) => viem.encodeAbiParameters(
|
|
@@ -7551,7 +7591,7 @@ function routeEthNonBase() {
|
|
|
7551
7591
|
return {
|
|
7552
7592
|
// TODO: do we even need these validations?
|
|
7553
7593
|
async preflight(p, ctx) {
|
|
7554
|
-
await
|
|
7594
|
+
await wrapAs5(
|
|
7555
7595
|
"VALIDATION",
|
|
7556
7596
|
OP_DEPOSITS.ethNonBase.assertEthAsset,
|
|
7557
7597
|
() => {
|
|
@@ -7561,7 +7601,7 @@ function routeEthNonBase() {
|
|
|
7561
7601
|
},
|
|
7562
7602
|
{ ctx: { token: p.token } }
|
|
7563
7603
|
);
|
|
7564
|
-
await
|
|
7604
|
+
await wrapAs5(
|
|
7565
7605
|
"VALIDATION",
|
|
7566
7606
|
OP_DEPOSITS.ethNonBase.assertNonEthBase,
|
|
7567
7607
|
() => {
|
|
@@ -7571,7 +7611,7 @@ function routeEthNonBase() {
|
|
|
7571
7611
|
},
|
|
7572
7612
|
{ ctx: { baseIsEth: ctx.baseIsEth, chainIdL2: ctx.chainIdL2 } }
|
|
7573
7613
|
);
|
|
7574
|
-
const ethBal = await
|
|
7614
|
+
const ethBal = await wrapAs5(
|
|
7575
7615
|
"RPC",
|
|
7576
7616
|
OP_DEPOSITS.ethNonBase.ethBalance,
|
|
7577
7617
|
() => ctx.client.l1.getBalance({ address: ctx.sender }),
|
|
@@ -7580,7 +7620,7 @@ function routeEthNonBase() {
|
|
|
7580
7620
|
message: "Failed to read L1 ETH balance."
|
|
7581
7621
|
}
|
|
7582
7622
|
);
|
|
7583
|
-
await
|
|
7623
|
+
await wrapAs5(
|
|
7584
7624
|
"VALIDATION",
|
|
7585
7625
|
OP_DEPOSITS.ethNonBase.assertEthBalance,
|
|
7586
7626
|
() => {
|
|
@@ -7613,11 +7653,16 @@ function routeEthNonBase() {
|
|
|
7613
7653
|
undeployedGasLimit: priorityGasModel.undeployedGasLimit
|
|
7614
7654
|
});
|
|
7615
7655
|
if (!l2Gas) throw new Error("Failed to estimate L2 gas parameters.");
|
|
7616
|
-
const
|
|
7656
|
+
const l1Fees = await quoteL1Fees2({ ctx });
|
|
7657
|
+
const l2BaseCost = await quoteL2BaseCost({
|
|
7658
|
+
ctx,
|
|
7659
|
+
l2GasLimit: l2Gas.gasLimit,
|
|
7660
|
+
l1GasPrice: l1Fees.maxFeePerGas
|
|
7661
|
+
});
|
|
7617
7662
|
const mintValue = l2BaseCost + ctx.operatorTip;
|
|
7618
7663
|
const approvals = [];
|
|
7619
7664
|
const steps = [];
|
|
7620
|
-
const allowance = await
|
|
7665
|
+
const allowance = await wrapAs5(
|
|
7621
7666
|
"CONTRACT",
|
|
7622
7667
|
OP_DEPOSITS.ethNonBase.allowanceBase,
|
|
7623
7668
|
() => ctx.client.l1.readContract({
|
|
@@ -7633,7 +7678,7 @@ function routeEthNonBase() {
|
|
|
7633
7678
|
);
|
|
7634
7679
|
const needsApprove = allowance < mintValue;
|
|
7635
7680
|
if (needsApprove) {
|
|
7636
|
-
const approveTx = await
|
|
7681
|
+
const approveTx = await wrapAs5(
|
|
7637
7682
|
"CONTRACT",
|
|
7638
7683
|
OP_DEPOSITS.ethNonBase.estGas,
|
|
7639
7684
|
() => buildApprovalRequest({
|
|
@@ -7655,7 +7700,7 @@ function routeEthNonBase() {
|
|
|
7655
7700
|
tx: approveTx
|
|
7656
7701
|
});
|
|
7657
7702
|
}
|
|
7658
|
-
const secondBridgeCalldata = await
|
|
7703
|
+
const secondBridgeCalldata = await wrapAs5(
|
|
7659
7704
|
"INTERNAL",
|
|
7660
7705
|
OP_DEPOSITS.ethNonBase.encodeCalldata,
|
|
7661
7706
|
() => encodeSecondBridgeEthDepositCalldata({ ctx, amount: p.amount, receiver }),
|
|
@@ -7697,7 +7742,7 @@ function routeEthNonBase() {
|
|
|
7697
7742
|
args: [requestStruct]
|
|
7698
7743
|
});
|
|
7699
7744
|
} else {
|
|
7700
|
-
const sim = await
|
|
7745
|
+
const sim = await wrapAs5(
|
|
7701
7746
|
"CONTRACT",
|
|
7702
7747
|
OP_DEPOSITS.ethNonBase.estGas,
|
|
7703
7748
|
() => ctx.client.l1.simulateContract({
|
|
@@ -7725,7 +7770,8 @@ function routeEthNonBase() {
|
|
|
7725
7770
|
data: calldata,
|
|
7726
7771
|
value: bridgehubValue,
|
|
7727
7772
|
from: ctx.sender,
|
|
7728
|
-
...ctx.gasOverrides
|
|
7773
|
+
...ctx.gasOverrides,
|
|
7774
|
+
...l1Fees
|
|
7729
7775
|
};
|
|
7730
7776
|
const l1Gas = await quoteL1Gas2({
|
|
7731
7777
|
ctx,
|
|
@@ -7733,14 +7779,11 @@ function routeEthNonBase() {
|
|
|
7733
7779
|
overrides: ctx.gasOverrides,
|
|
7734
7780
|
fallbackGasLimit: SAFE_L1_BRIDGE_GAS
|
|
7735
7781
|
});
|
|
7736
|
-
|
|
7737
|
-
bridgeTx
|
|
7738
|
-
|
|
7739
|
-
|
|
7740
|
-
|
|
7741
|
-
maxPriorityFeePerGas: l1Gas.maxPriorityFeePerGas
|
|
7742
|
-
};
|
|
7743
|
-
}
|
|
7782
|
+
bridgeTx = {
|
|
7783
|
+
...bridgeTx,
|
|
7784
|
+
...l1Fees,
|
|
7785
|
+
...l1Gas ? { gas: l1Gas.gasLimit } : {}
|
|
7786
|
+
};
|
|
7744
7787
|
steps.push({
|
|
7745
7788
|
key: "bridgehub:two-bridges:eth-nonbase",
|
|
7746
7789
|
kind: "bridgehub:two-bridges",
|
|
@@ -7763,12 +7806,12 @@ function routeEthNonBase() {
|
|
|
7763
7806
|
}
|
|
7764
7807
|
};
|
|
7765
7808
|
}
|
|
7766
|
-
var { wrapAs:
|
|
7809
|
+
var { wrapAs: wrapAs6 } = createErrorHandlers("deposits");
|
|
7767
7810
|
var EMPTY_BYTES3 = "0x";
|
|
7768
7811
|
function routeErc20Base() {
|
|
7769
7812
|
return {
|
|
7770
7813
|
async preflight(p, ctx) {
|
|
7771
|
-
await
|
|
7814
|
+
await wrapAs6(
|
|
7772
7815
|
"VALIDATION",
|
|
7773
7816
|
OP_DEPOSITS.base.assertErc20Asset,
|
|
7774
7817
|
() => {
|
|
@@ -7779,7 +7822,7 @@ function routeErc20Base() {
|
|
|
7779
7822
|
{ ctx: { token: p.token } }
|
|
7780
7823
|
);
|
|
7781
7824
|
const baseToken = ctx.baseTokenL1 ?? await ctx.client.baseToken(ctx.chainIdL2);
|
|
7782
|
-
await
|
|
7825
|
+
await wrapAs6(
|
|
7783
7826
|
"VALIDATION",
|
|
7784
7827
|
OP_DEPOSITS.base.assertMatchesBase,
|
|
7785
7828
|
() => {
|
|
@@ -7816,11 +7859,16 @@ function routeErc20Base() {
|
|
|
7816
7859
|
overrideGasLimit: quotedL2GasLimit
|
|
7817
7860
|
});
|
|
7818
7861
|
if (!l2Gas) throw new Error("Failed to estimate L2 gas parameters.");
|
|
7819
|
-
const
|
|
7862
|
+
const l1Fees = await quoteL1Fees2({ ctx });
|
|
7863
|
+
const l2BaseCost = await quoteL2BaseCost({
|
|
7864
|
+
ctx,
|
|
7865
|
+
l2GasLimit: l2Gas.gasLimit,
|
|
7866
|
+
l1GasPrice: l1Fees.maxFeePerGas
|
|
7867
|
+
});
|
|
7820
7868
|
const mintValue = l2BaseCost + ctx.operatorTip + p.amount;
|
|
7821
7869
|
const approvals = [];
|
|
7822
7870
|
const steps = [];
|
|
7823
|
-
const allowance = await
|
|
7871
|
+
const allowance = await wrapAs6(
|
|
7824
7872
|
"CONTRACT",
|
|
7825
7873
|
OP_DEPOSITS.base.allowance,
|
|
7826
7874
|
() => ctx.client.l1.readContract({
|
|
@@ -7836,7 +7884,7 @@ function routeErc20Base() {
|
|
|
7836
7884
|
);
|
|
7837
7885
|
const needsApprove = allowance < mintValue;
|
|
7838
7886
|
if (needsApprove) {
|
|
7839
|
-
const approveTx = await
|
|
7887
|
+
const approveTx = await wrapAs6(
|
|
7840
7888
|
"CONTRACT",
|
|
7841
7889
|
OP_DEPOSITS.base.estGas,
|
|
7842
7890
|
() => buildApprovalRequest({
|
|
@@ -7885,7 +7933,7 @@ function routeErc20Base() {
|
|
|
7885
7933
|
args: [req]
|
|
7886
7934
|
});
|
|
7887
7935
|
} else {
|
|
7888
|
-
const sim = await
|
|
7936
|
+
const sim = await wrapAs6(
|
|
7889
7937
|
"RPC",
|
|
7890
7938
|
OP_DEPOSITS.base.estGas,
|
|
7891
7939
|
() => ctx.client.l1.simulateContract({
|
|
@@ -7913,7 +7961,8 @@ function routeErc20Base() {
|
|
|
7913
7961
|
data: calldata,
|
|
7914
7962
|
value: 0n,
|
|
7915
7963
|
from: ctx.sender,
|
|
7916
|
-
...ctx.gasOverrides
|
|
7964
|
+
...ctx.gasOverrides,
|
|
7965
|
+
...l1Fees
|
|
7917
7966
|
};
|
|
7918
7967
|
const l1Gas = await quoteL1Gas2({
|
|
7919
7968
|
ctx,
|
|
@@ -7921,14 +7970,11 @@ function routeErc20Base() {
|
|
|
7921
7970
|
overrides: ctx.gasOverrides,
|
|
7922
7971
|
fallbackGasLimit: SAFE_L1_BRIDGE_GAS
|
|
7923
7972
|
});
|
|
7924
|
-
|
|
7925
|
-
bridgeTx
|
|
7926
|
-
|
|
7927
|
-
|
|
7928
|
-
|
|
7929
|
-
maxPriorityFeePerGas: l1Gas.maxPriorityFeePerGas
|
|
7930
|
-
};
|
|
7931
|
-
}
|
|
7973
|
+
bridgeTx = {
|
|
7974
|
+
...bridgeTx,
|
|
7975
|
+
...l1Fees,
|
|
7976
|
+
...l1Gas ? { gas: l1Gas.gasLimit } : {}
|
|
7977
|
+
};
|
|
7932
7978
|
steps.push({
|
|
7933
7979
|
key: "bridgehub:direct:erc20-base",
|
|
7934
7980
|
kind: "bridgehub:direct",
|
|
@@ -8026,7 +8072,7 @@ async function waitForL2ExecutionFromL1Tx(l1, l2, l1TxHash) {
|
|
|
8026
8072
|
}
|
|
8027
8073
|
return { l2Receipt, l2TxHash };
|
|
8028
8074
|
}
|
|
8029
|
-
var { wrapAs:
|
|
8075
|
+
var { wrapAs: wrapAs7 } = createErrorHandlers("tokens");
|
|
8030
8076
|
var ntvCodec3 = createNTVCodec({
|
|
8031
8077
|
encode: (types, values) => viem.encodeAbiParameters(
|
|
8032
8078
|
types.map((t, i) => ({ type: t, name: `arg${i}` })),
|
|
@@ -8041,7 +8087,7 @@ function createTokensResource(client) {
|
|
|
8041
8087
|
let wethL2Promise = null;
|
|
8042
8088
|
async function getL1ChainId() {
|
|
8043
8089
|
if (!l2NtvL1ChainIdPromise) {
|
|
8044
|
-
l2NtvL1ChainIdPromise =
|
|
8090
|
+
l2NtvL1ChainIdPromise = wrapAs7("INTERNAL", "getL1ChainId", async () => {
|
|
8045
8091
|
const { l2NativeTokenVault } = await client.contracts();
|
|
8046
8092
|
return await l2NativeTokenVault.read.L1_CHAIN_ID();
|
|
8047
8093
|
});
|
|
@@ -8050,7 +8096,7 @@ function createTokensResource(client) {
|
|
|
8050
8096
|
}
|
|
8051
8097
|
async function getBaseTokenAssetId() {
|
|
8052
8098
|
if (!baseTokenAssetIdPromise) {
|
|
8053
|
-
baseTokenAssetIdPromise =
|
|
8099
|
+
baseTokenAssetIdPromise = wrapAs7("INTERNAL", "baseTokenAssetId", async () => {
|
|
8054
8100
|
const { l2NativeTokenVault } = await client.contracts();
|
|
8055
8101
|
const assetId = await l2NativeTokenVault.read.BASE_TOKEN_ASSET_ID();
|
|
8056
8102
|
return assetId;
|
|
@@ -8060,7 +8106,7 @@ function createTokensResource(client) {
|
|
|
8060
8106
|
}
|
|
8061
8107
|
async function getWethL1() {
|
|
8062
8108
|
if (!wethL1Promise) {
|
|
8063
|
-
wethL1Promise =
|
|
8109
|
+
wethL1Promise = wrapAs7("INTERNAL", "wethL1", async () => {
|
|
8064
8110
|
const { l1NativeTokenVault } = await client.contracts();
|
|
8065
8111
|
const weth = await l1NativeTokenVault.read.WETH_TOKEN();
|
|
8066
8112
|
return weth;
|
|
@@ -8070,7 +8116,7 @@ function createTokensResource(client) {
|
|
|
8070
8116
|
}
|
|
8071
8117
|
async function getWethL2() {
|
|
8072
8118
|
if (!wethL2Promise) {
|
|
8073
|
-
wethL2Promise =
|
|
8119
|
+
wethL2Promise = wrapAs7("INTERNAL", "wethL2", async () => {
|
|
8074
8120
|
const { l2NativeTokenVault } = await client.contracts();
|
|
8075
8121
|
const weth = await l2NativeTokenVault.read.WETH_TOKEN();
|
|
8076
8122
|
return weth;
|
|
@@ -8079,7 +8125,7 @@ function createTokensResource(client) {
|
|
|
8079
8125
|
return wethL2Promise;
|
|
8080
8126
|
}
|
|
8081
8127
|
async function toL2Address(l1Token) {
|
|
8082
|
-
return
|
|
8128
|
+
return wrapAs7("CONTRACT", "tokens.toL2Address", async () => {
|
|
8083
8129
|
const normalized = normalizeL1Token(l1Token);
|
|
8084
8130
|
const chainId = BigInt(await client.l2.getChainId());
|
|
8085
8131
|
const baseToken = await client.baseToken(chainId);
|
|
@@ -8092,7 +8138,7 @@ function createTokensResource(client) {
|
|
|
8092
8138
|
});
|
|
8093
8139
|
}
|
|
8094
8140
|
async function toL1Address(l2Token) {
|
|
8095
|
-
return
|
|
8141
|
+
return wrapAs7("CONTRACT", "tokens.toL1Address", async () => {
|
|
8096
8142
|
if (isAddressEq(l2Token, ETH_ADDRESS)) return ETH_ADDRESS;
|
|
8097
8143
|
if (isAddressEq(l2Token, L2_BASE_TOKEN_ADDRESS)) {
|
|
8098
8144
|
const chainId = BigInt(await client.l2.getChainId());
|
|
@@ -8113,32 +8159,32 @@ function createTokensResource(client) {
|
|
|
8113
8159
|
});
|
|
8114
8160
|
}
|
|
8115
8161
|
async function assetIdOfL1(l1Token) {
|
|
8116
|
-
return
|
|
8162
|
+
return wrapAs7("CONTRACT", "tokens.assetIdOfL1", async () => {
|
|
8117
8163
|
const normalized = normalizeL1Token(l1Token);
|
|
8118
8164
|
const { l1NativeTokenVault } = await client.contracts();
|
|
8119
8165
|
return await l1NativeTokenVault.read.assetId([normalized]);
|
|
8120
8166
|
});
|
|
8121
8167
|
}
|
|
8122
8168
|
async function assetIdOfL2(l2Token) {
|
|
8123
|
-
return
|
|
8169
|
+
return wrapAs7("CONTRACT", "tokens.assetIdOfL2", async () => {
|
|
8124
8170
|
const { l2NativeTokenVault } = await client.contracts();
|
|
8125
8171
|
return await l2NativeTokenVault.read.assetId([l2Token]);
|
|
8126
8172
|
});
|
|
8127
8173
|
}
|
|
8128
8174
|
async function l2TokenFromAssetId(assetId) {
|
|
8129
|
-
return
|
|
8175
|
+
return wrapAs7("CONTRACT", "tokens.l2TokenFromAssetId", async () => {
|
|
8130
8176
|
const { l2NativeTokenVault } = await client.contracts();
|
|
8131
8177
|
return await l2NativeTokenVault.read.tokenAddress([assetId]);
|
|
8132
8178
|
});
|
|
8133
8179
|
}
|
|
8134
8180
|
async function l1TokenFromAssetId(assetId) {
|
|
8135
|
-
return
|
|
8181
|
+
return wrapAs7("CONTRACT", "tokens.l1TokenFromAssetId", async () => {
|
|
8136
8182
|
const { l1NativeTokenVault } = await client.contracts();
|
|
8137
8183
|
return await l1NativeTokenVault.read.tokenAddress([assetId]);
|
|
8138
8184
|
});
|
|
8139
8185
|
}
|
|
8140
8186
|
async function originChainId(assetId) {
|
|
8141
|
-
return
|
|
8187
|
+
return wrapAs7("CONTRACT", "tokens.originChainId", async () => {
|
|
8142
8188
|
const { l2NativeTokenVault } = await client.contracts();
|
|
8143
8189
|
return await l2NativeTokenVault.read.originChainId([assetId]);
|
|
8144
8190
|
});
|
|
@@ -8147,7 +8193,7 @@ function createTokensResource(client) {
|
|
|
8147
8193
|
return getBaseTokenAssetId();
|
|
8148
8194
|
}
|
|
8149
8195
|
async function isChainEthBased() {
|
|
8150
|
-
return
|
|
8196
|
+
return wrapAs7("CONTRACT", "tokens.isChainEthBased", async () => {
|
|
8151
8197
|
const baseAssetId = await getBaseTokenAssetId();
|
|
8152
8198
|
const l1ChainId = await getL1ChainId();
|
|
8153
8199
|
const ethAssetId = ntvCodec3.encodeAssetId(
|
|
@@ -8165,7 +8211,7 @@ function createTokensResource(client) {
|
|
|
8165
8211
|
return getWethL2();
|
|
8166
8212
|
}
|
|
8167
8213
|
async function computeL2BridgedAddress(args) {
|
|
8168
|
-
return
|
|
8214
|
+
return wrapAs7("CONTRACT", "tokens.computeL2BridgedAddress", async () => {
|
|
8169
8215
|
const normalized = normalizeL1Token(args.l1Token);
|
|
8170
8216
|
const { l2NativeTokenVault } = await client.contracts();
|
|
8171
8217
|
const predicted = await l2NativeTokenVault.read.calculateCreate2TokenAddress([
|
|
@@ -8176,7 +8222,7 @@ function createTokensResource(client) {
|
|
|
8176
8222
|
});
|
|
8177
8223
|
}
|
|
8178
8224
|
async function resolve(ref, opts) {
|
|
8179
|
-
return
|
|
8225
|
+
return wrapAs7("CONTRACT", "tokens.resolve", async () => {
|
|
8180
8226
|
let chain;
|
|
8181
8227
|
let address;
|
|
8182
8228
|
if (typeof ref === "string") {
|
|
@@ -8764,12 +8810,12 @@ function buildFeeBreakdown2(p) {
|
|
|
8764
8810
|
}
|
|
8765
8811
|
|
|
8766
8812
|
// src/adapters/viem/resources/withdrawals/routes/eth.ts
|
|
8767
|
-
var { wrapAs:
|
|
8813
|
+
var { wrapAs: wrapAs8 } = createErrorHandlers("withdrawals");
|
|
8768
8814
|
function routeEthBase() {
|
|
8769
8815
|
return {
|
|
8770
8816
|
async build(p, ctx) {
|
|
8771
8817
|
const steps = [];
|
|
8772
|
-
const data = await
|
|
8818
|
+
const data = await wrapAs8(
|
|
8773
8819
|
"INTERNAL",
|
|
8774
8820
|
OP_WITHDRAWALS.eth.encodeWithdraw,
|
|
8775
8821
|
() => Promise.resolve(
|
|
@@ -8819,14 +8865,14 @@ function routeEthBase() {
|
|
|
8819
8865
|
}
|
|
8820
8866
|
};
|
|
8821
8867
|
}
|
|
8822
|
-
var { wrapAs:
|
|
8868
|
+
var { wrapAs: wrapAs9 } = createErrorHandlers("withdrawals");
|
|
8823
8869
|
function routeErc20NonBase2() {
|
|
8824
8870
|
return {
|
|
8825
8871
|
// TODO: add preflight validations here
|
|
8826
8872
|
async build(p, ctx) {
|
|
8827
8873
|
const steps = [];
|
|
8828
8874
|
const approvals = [];
|
|
8829
|
-
const current = await
|
|
8875
|
+
const current = await wrapAs9(
|
|
8830
8876
|
"CONTRACT",
|
|
8831
8877
|
OP_WITHDRAWALS.erc20.allowance,
|
|
8832
8878
|
() => ctx.client.l2.readContract({
|
|
@@ -8865,7 +8911,7 @@ function routeErc20NonBase2() {
|
|
|
8865
8911
|
approveTxCandidate.maxFeePerGas = approveGas.maxFeePerGas;
|
|
8866
8912
|
approveTxCandidate.maxPriorityFeePerGas = approveGas.maxPriorityFeePerGas;
|
|
8867
8913
|
}
|
|
8868
|
-
const approveSim = await
|
|
8914
|
+
const approveSim = await wrapAs9(
|
|
8869
8915
|
"CONTRACT",
|
|
8870
8916
|
OP_WITHDRAWALS.erc20.estGas,
|
|
8871
8917
|
() => ctx.client.l2.simulateContract({
|
|
@@ -8892,7 +8938,7 @@ function routeErc20NonBase2() {
|
|
|
8892
8938
|
tx: approveTx
|
|
8893
8939
|
});
|
|
8894
8940
|
}
|
|
8895
|
-
const assetId = (await
|
|
8941
|
+
const assetId = (await wrapAs9(
|
|
8896
8942
|
"CONTRACT",
|
|
8897
8943
|
OP_WITHDRAWALS.erc20.ensureRegistered,
|
|
8898
8944
|
() => ctx.client.l2.simulateContract({
|
|
@@ -8943,7 +8989,7 @@ function routeErc20NonBase2() {
|
|
|
8943
8989
|
...withdrawGas
|
|
8944
8990
|
};
|
|
8945
8991
|
} else {
|
|
8946
|
-
const sim = await
|
|
8992
|
+
const sim = await wrapAs9(
|
|
8947
8993
|
"CONTRACT",
|
|
8948
8994
|
OP_WITHDRAWALS.erc20.estGas,
|
|
8949
8995
|
() => ctx.client.l2.simulateContract({
|
|
@@ -9105,7 +9151,7 @@ function buildWithdrawalBundle(input) {
|
|
|
9105
9151
|
}
|
|
9106
9152
|
|
|
9107
9153
|
// src/adapters/viem/resources/withdrawals/routes/interop-bundle.ts
|
|
9108
|
-
var { wrapAs:
|
|
9154
|
+
var { wrapAs: wrapAs10 } = createErrorHandlers("withdrawals");
|
|
9109
9155
|
var attributes = createViemAttributesResource();
|
|
9110
9156
|
function saltFor(sender, nonce) {
|
|
9111
9157
|
return viem.keccak256(
|
|
@@ -9130,7 +9176,7 @@ function routeInteropBundle() {
|
|
|
9130
9176
|
if (isBaseToken) {
|
|
9131
9177
|
assetId = ctx.baseTokenAssetId;
|
|
9132
9178
|
} else {
|
|
9133
|
-
assetId = (await
|
|
9179
|
+
assetId = (await wrapAs10(
|
|
9134
9180
|
"CONTRACT",
|
|
9135
9181
|
OP_WITHDRAWALS.erc20.ensureRegistered,
|
|
9136
9182
|
() => ctx.client.l2.simulateContract({
|
|
@@ -9145,7 +9191,7 @@ function routeInteropBundle() {
|
|
|
9145
9191
|
message: "Failed to ensure token is registered in L2NativeTokenVault."
|
|
9146
9192
|
}
|
|
9147
9193
|
)).result;
|
|
9148
|
-
const current = await
|
|
9194
|
+
const current = await wrapAs10(
|
|
9149
9195
|
"CONTRACT",
|
|
9150
9196
|
OP_WITHDRAWALS.erc20.allowance,
|
|
9151
9197
|
() => ctx.client.l2.readContract({
|
|
@@ -9194,7 +9240,7 @@ function routeInteropBundle() {
|
|
|
9194
9240
|
});
|
|
9195
9241
|
}
|
|
9196
9242
|
}
|
|
9197
|
-
const nonce = await
|
|
9243
|
+
const nonce = await wrapAs10(
|
|
9198
9244
|
"RPC",
|
|
9199
9245
|
OP_WITHDRAWALS.prepare,
|
|
9200
9246
|
() => ctx.client.l2.getTransactionCount({ address: ctx.sender, blockTag: "pending" }),
|
|
@@ -9430,7 +9476,7 @@ function createWithdrawalProtocolService(client, override) {
|
|
|
9430
9476
|
}
|
|
9431
9477
|
};
|
|
9432
9478
|
}
|
|
9433
|
-
var { wrapAs:
|
|
9479
|
+
var { wrapAs: wrapAs11 } = createErrorHandlers("withdrawals");
|
|
9434
9480
|
var IL1NullifierMini = [
|
|
9435
9481
|
{
|
|
9436
9482
|
type: "function",
|
|
@@ -9448,7 +9494,7 @@ function createFinalizationServices(client, protocolService = createWithdrawalPr
|
|
|
9448
9494
|
async function finalizationTarget(protocol) {
|
|
9449
9495
|
const { l1Nullifier } = await client.ensureAddresses();
|
|
9450
9496
|
if (protocol === "legacy-withdrawal") return l1Nullifier;
|
|
9451
|
-
return await
|
|
9497
|
+
return await wrapAs11(
|
|
9452
9498
|
"CONTRACT",
|
|
9453
9499
|
OP_WITHDRAWALS.finalize.fetchParams.receipt,
|
|
9454
9500
|
() => client.l1.readContract({
|
|
@@ -9463,7 +9509,7 @@ function createFinalizationServices(client, protocolService = createWithdrawalPr
|
|
|
9463
9509
|
);
|
|
9464
9510
|
}
|
|
9465
9511
|
async function fetchMessageAndProof(l2TxHash) {
|
|
9466
|
-
const raw = await
|
|
9512
|
+
const raw = await wrapAs11(
|
|
9467
9513
|
"RPC",
|
|
9468
9514
|
OP_WITHDRAWALS.finalize.fetchParams.receipt,
|
|
9469
9515
|
() => client.zks.getReceiptWithL2ToL1(l2TxHash),
|
|
@@ -9480,7 +9526,7 @@ function createFinalizationServices(client, protocolService = createWithdrawalPr
|
|
|
9480
9526
|
context: { l2TxHash }
|
|
9481
9527
|
});
|
|
9482
9528
|
}
|
|
9483
|
-
const ev = await
|
|
9529
|
+
const ev = await wrapAs11(
|
|
9484
9530
|
"INTERNAL",
|
|
9485
9531
|
OP_WITHDRAWALS.finalize.fetchParams.findMessage,
|
|
9486
9532
|
// eslint-disable-next-line @typescript-eslint/no-unsafe-argument, @typescript-eslint/no-explicit-any
|
|
@@ -9490,7 +9536,7 @@ function createFinalizationServices(client, protocolService = createWithdrawalPr
|
|
|
9490
9536
|
message: "Failed to locate L1MessageSent event in L2 receipt."
|
|
9491
9537
|
}
|
|
9492
9538
|
);
|
|
9493
|
-
const message = await
|
|
9539
|
+
const message = await wrapAs11(
|
|
9494
9540
|
"INTERNAL",
|
|
9495
9541
|
OP_WITHDRAWALS.finalize.fetchParams.decodeMessage,
|
|
9496
9542
|
() => {
|
|
@@ -9502,7 +9548,7 @@ function createFinalizationServices(client, protocolService = createWithdrawalPr
|
|
|
9502
9548
|
message: "Failed to decode withdrawal message."
|
|
9503
9549
|
}
|
|
9504
9550
|
);
|
|
9505
|
-
const idx = await
|
|
9551
|
+
const idx = await wrapAs11(
|
|
9506
9552
|
"INTERNAL",
|
|
9507
9553
|
OP_WITHDRAWALS.finalize.fetchParams.messengerIndex,
|
|
9508
9554
|
() => Promise.resolve(messengerLogIndex(raw, { index: 0, messenger: L1_MESSENGER_ADDRESS })),
|
|
@@ -9511,7 +9557,7 @@ function createFinalizationServices(client, protocolService = createWithdrawalPr
|
|
|
9511
9557
|
message: "Failed to derive messenger log index."
|
|
9512
9558
|
}
|
|
9513
9559
|
);
|
|
9514
|
-
const proof = await
|
|
9560
|
+
const proof = await wrapAs11(
|
|
9515
9561
|
"RPC",
|
|
9516
9562
|
OP_WITHDRAWALS.finalize.fetchParams.proof,
|
|
9517
9563
|
() => client.zks.getL2ToL1LogProof(l2TxHash, idx),
|
|
@@ -9520,7 +9566,7 @@ function createFinalizationServices(client, protocolService = createWithdrawalPr
|
|
|
9520
9566
|
message: "Failed to fetch L2\u2192L1 log proof."
|
|
9521
9567
|
}
|
|
9522
9568
|
);
|
|
9523
|
-
const chainId = await
|
|
9569
|
+
const chainId = await wrapAs11(
|
|
9524
9570
|
"RPC",
|
|
9525
9571
|
OP_WITHDRAWALS.finalize.fetchParams.network,
|
|
9526
9572
|
() => client.l2.getChainId(),
|
|
@@ -9578,7 +9624,7 @@ function createFinalizationServices(client, protocolService = createWithdrawalPr
|
|
|
9578
9624
|
async function withdrawalOutcome(finalization) {
|
|
9579
9625
|
const target = await finalizationTarget(finalization.protocol);
|
|
9580
9626
|
if (finalization.protocol === "legacy-withdrawal") {
|
|
9581
|
-
const done = await
|
|
9627
|
+
const done = await wrapAs11(
|
|
9582
9628
|
"RPC",
|
|
9583
9629
|
OP_WITHDRAWALS.finalize.isFinalized,
|
|
9584
9630
|
() => client.l1.readContract({
|
|
@@ -9600,7 +9646,7 @@ function createFinalizationServices(client, protocolService = createWithdrawalPr
|
|
|
9600
9646
|
}
|
|
9601
9647
|
const { bundleHash } = finalization.params;
|
|
9602
9648
|
const status = Number(
|
|
9603
|
-
await
|
|
9649
|
+
await wrapAs11(
|
|
9604
9650
|
"RPC",
|
|
9605
9651
|
OP_WITHDRAWALS.finalize.isFinalized,
|
|
9606
9652
|
() => client.l1.readContract({
|
|
@@ -9617,7 +9663,7 @@ function createFinalizationServices(client, protocolService = createWithdrawalPr
|
|
|
9617
9663
|
);
|
|
9618
9664
|
if (status !== 3 /* Unbundled */) return classifyWithdrawalOutcome(status);
|
|
9619
9665
|
const callStatus = Number(
|
|
9620
|
-
await
|
|
9666
|
+
await wrapAs11(
|
|
9621
9667
|
"RPC",
|
|
9622
9668
|
OP_WITHDRAWALS.finalize.isFinalized,
|
|
9623
9669
|
() => client.l1.readContract({
|
|
@@ -9688,7 +9734,7 @@ function createFinalizationServices(client, protocolService = createWithdrawalPr
|
|
|
9688
9734
|
},
|
|
9689
9735
|
async estimateFinalization(finalization) {
|
|
9690
9736
|
const target = await finalizationTarget(finalization.protocol);
|
|
9691
|
-
const gasLimit = await
|
|
9737
|
+
const gasLimit = await wrapAs11(
|
|
9692
9738
|
"RPC",
|
|
9693
9739
|
OP_WITHDRAWALS.finalize.estimate,
|
|
9694
9740
|
() => finalization.protocol === "legacy-withdrawal" ? client.l1.estimateContractGas({
|
|
@@ -9716,7 +9762,7 @@ function createFinalizationServices(client, protocolService = createWithdrawalPr
|
|
|
9716
9762
|
let maxFeePerGas;
|
|
9717
9763
|
let maxPriorityFeePerGas;
|
|
9718
9764
|
try {
|
|
9719
|
-
const fee = await
|
|
9765
|
+
const fee = await wrapAs11(
|
|
9720
9766
|
"RPC",
|
|
9721
9767
|
OP_WITHDRAWALS.finalize.estimate,
|
|
9722
9768
|
() => client.l1.estimateFeesPerGas(),
|
|
@@ -9735,7 +9781,7 @@ function createFinalizationServices(client, protocolService = createWithdrawalPr
|
|
|
9735
9781
|
})();
|
|
9736
9782
|
maxPriorityFeePerGas = fee.maxPriorityFeePerGas ?? 0n;
|
|
9737
9783
|
} catch {
|
|
9738
|
-
const gasPrice = await
|
|
9784
|
+
const gasPrice = await wrapAs11(
|
|
9739
9785
|
"RPC",
|
|
9740
9786
|
OP_WITHDRAWALS.finalize.estimate,
|
|
9741
9787
|
() => client.l1.getGasPrice(),
|