@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
|
@@ -5838,19 +5838,6 @@ function encodeSecondBridgeDataV1(assetId, transferData) {
|
|
|
5838
5838
|
);
|
|
5839
5839
|
return viem.concat(["0x01", data]);
|
|
5840
5840
|
}
|
|
5841
|
-
function encodeSecondBridgeArgs(token, amount, l2Receiver) {
|
|
5842
|
-
return viem.encodeAbiParameters(
|
|
5843
|
-
[
|
|
5844
|
-
{ type: "address", name: "token" },
|
|
5845
|
-
{ type: "uint256", name: "amount" },
|
|
5846
|
-
{ type: "address", name: "l2Receiver" }
|
|
5847
|
-
],
|
|
5848
|
-
[token, amount, l2Receiver]
|
|
5849
|
-
);
|
|
5850
|
-
}
|
|
5851
|
-
function encodeSecondBridgeEthArgs(amount, l2Receiver, ethToken = ETH_ADDRESS) {
|
|
5852
|
-
return encodeSecondBridgeArgs(ethToken, amount, l2Receiver);
|
|
5853
|
-
}
|
|
5854
5841
|
function buildDirectRequestStruct(args) {
|
|
5855
5842
|
return {
|
|
5856
5843
|
chainId: args.chainId,
|
|
@@ -6146,7 +6133,7 @@ var OP_DEPOSITS = {
|
|
|
6146
6133
|
ethNonBase: {
|
|
6147
6134
|
allowanceBase: "deposits.eth-nonbase:allowanceBaseToken",
|
|
6148
6135
|
ethBalance: "deposits.eth-nonbase:getEthBalance",
|
|
6149
|
-
encodeCalldata: "deposits.eth-nonbase:
|
|
6136
|
+
encodeCalldata: "deposits.eth-nonbase:encodeSecondBridgeEthDepositCalldata",
|
|
6150
6137
|
estGas: "deposits.eth-nonbase:estimateGas",
|
|
6151
6138
|
assertEthAsset: "deposits.eth-nonbase:assertEthAsset",
|
|
6152
6139
|
assertNonEthBase: "deposits.eth-nonbase:assertNonEthBase",
|
|
@@ -6312,7 +6299,7 @@ function createErrorOps(decodeRevert2) {
|
|
|
6312
6299
|
function wrap7(operation, fn, opts) {
|
|
6313
6300
|
return run("INTERNAL", operation, fn, opts);
|
|
6314
6301
|
}
|
|
6315
|
-
function
|
|
6302
|
+
function wrapAs12(kind, operation, fn, opts) {
|
|
6316
6303
|
return run(kind, operation, fn, opts);
|
|
6317
6304
|
}
|
|
6318
6305
|
async function toResult3(operation, fn, opts) {
|
|
@@ -6333,7 +6320,7 @@ function createErrorOps(decodeRevert2) {
|
|
|
6333
6320
|
return { ok: false, error: shaped };
|
|
6334
6321
|
}
|
|
6335
6322
|
}
|
|
6336
|
-
return { wrap: wrap7, wrapAs:
|
|
6323
|
+
return { wrap: wrap7, wrapAs: wrapAs12, toResult: toResult3 };
|
|
6337
6324
|
}
|
|
6338
6325
|
return { toZKsyncError: toZKsyncError2, createErrorHandlers: createErrorHandlers2 };
|
|
6339
6326
|
}
|
|
@@ -6482,6 +6469,7 @@ function isEraVmChain(chainIdL2) {
|
|
|
6482
6469
|
|
|
6483
6470
|
// src/core/resources/deposits/gas.ts
|
|
6484
6471
|
var CREATE_REESTIMATE_BUFFER = 15n;
|
|
6472
|
+
var ZERO_FEES = { maxFeePerGas: 0n, maxPriorityFeePerGas: 0n };
|
|
6485
6473
|
var maxBigInt = (a, b) => a > b ? a : b;
|
|
6486
6474
|
function applyGasBuffer(gasLimit, bufferPct = BUFFER) {
|
|
6487
6475
|
return gasLimit * (100n + bufferPct) / 100n;
|
|
@@ -6532,15 +6520,39 @@ async function fetchFees(estimator) {
|
|
|
6532
6520
|
const gp = await estimator.getGasPrice();
|
|
6533
6521
|
return { maxFeePerGas: gp, maxPriorityFeePerGas: 0n };
|
|
6534
6522
|
} catch {
|
|
6535
|
-
return
|
|
6523
|
+
return void 0;
|
|
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 };
|
|
6536
6547
|
}
|
|
6548
|
+
return market;
|
|
6537
6549
|
}
|
|
6538
6550
|
async function quoteL1Gas(input) {
|
|
6539
6551
|
const { estimator, tx, overrides, fallbackGasLimit } = input;
|
|
6540
6552
|
let market;
|
|
6541
6553
|
const getMarket = async () => {
|
|
6542
6554
|
if (market) return market;
|
|
6543
|
-
market = await fetchFees(estimator);
|
|
6555
|
+
market = await fetchFees(estimator) ?? ZERO_FEES;
|
|
6544
6556
|
return market;
|
|
6545
6557
|
};
|
|
6546
6558
|
const maxFeePerGas = overrides?.maxFeePerGas ?? (tx.maxFeePerGas != null ? BigInt(tx.maxFeePerGas) : (await getMarket()).maxFeePerGas);
|
|
@@ -6562,7 +6574,7 @@ async function quoteL1Gas(input) {
|
|
|
6562
6574
|
}
|
|
6563
6575
|
async function quoteL2Gas(input) {
|
|
6564
6576
|
const { estimator, route, tx, gasPerPubdata, l2GasLimit, overrideGasLimit, stateOverrides } = input;
|
|
6565
|
-
const market = await fetchFees(estimator);
|
|
6577
|
+
const market = await fetchFees(estimator) ?? ZERO_FEES;
|
|
6566
6578
|
const maxFeePerGas = market.maxFeePerGas || market.maxPriorityFeePerGas || 0n;
|
|
6567
6579
|
const txGasLimit = tx?.gasLimit != null ? BigInt(tx.gasLimit) : void 0;
|
|
6568
6580
|
const explicit = overrideGasLimit ?? txGasLimit;
|
|
@@ -6762,6 +6774,7 @@ function viemToGasEstimator(client) {
|
|
|
6762
6774
|
}
|
|
6763
6775
|
|
|
6764
6776
|
// src/adapters/viem/resources/deposits/services/gas.ts
|
|
6777
|
+
var { wrapAs } = createErrorHandlers("deposits");
|
|
6765
6778
|
var DEFAULT_SAFE_NONBASE_L2_GAS_LIMIT = 3000000n;
|
|
6766
6779
|
async function estimatePriorityTxL2Gas(ctx, leg) {
|
|
6767
6780
|
if (!leg) return void 0;
|
|
@@ -6771,6 +6784,18 @@ async function estimatePriorityTxL2Gas(ctx, leg) {
|
|
|
6771
6784
|
return void 0;
|
|
6772
6785
|
}
|
|
6773
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
|
+
}
|
|
6774
6799
|
async function quoteL1Gas2(input) {
|
|
6775
6800
|
const { ctx, tx, overrides, fallbackGasLimit } = input;
|
|
6776
6801
|
const estimator = viemToGasEstimator(ctx.client.l1);
|
|
@@ -6873,13 +6898,10 @@ async function determineEthNonBaseL2Gas(input) {
|
|
|
6873
6898
|
}
|
|
6874
6899
|
|
|
6875
6900
|
// src/adapters/viem/resources/deposits/services/fee.ts
|
|
6876
|
-
var { wrapAs } = createErrorHandlers("deposits");
|
|
6901
|
+
var { wrapAs: wrapAs2 } = createErrorHandlers("deposits");
|
|
6877
6902
|
async function quoteL2BaseCost(input) {
|
|
6878
|
-
const { ctx, l2GasLimit } = input;
|
|
6879
|
-
|
|
6880
|
-
const fees = await estimator.estimateFeesPerGas();
|
|
6881
|
-
const gasPrice = fees.maxFeePerGas ?? fees.gasPrice ?? await estimator.getGasPrice();
|
|
6882
|
-
return wrapAs(
|
|
6903
|
+
const { ctx, l2GasLimit, l1GasPrice } = input;
|
|
6904
|
+
return wrapAs2(
|
|
6883
6905
|
"RPC",
|
|
6884
6906
|
"deposits.fees.l2BaseCost",
|
|
6885
6907
|
async () => {
|
|
@@ -6887,7 +6909,7 @@ async function quoteL2BaseCost(input) {
|
|
|
6887
6909
|
address: ctx.bridgehub,
|
|
6888
6910
|
abi: IBridgehub_default,
|
|
6889
6911
|
functionName: "l2TransactionBaseCost",
|
|
6890
|
-
args: [ctx.chainIdL2,
|
|
6912
|
+
args: [ctx.chainIdL2, l1GasPrice, l2GasLimit, ctx.gasPerPubdata]
|
|
6891
6913
|
});
|
|
6892
6914
|
},
|
|
6893
6915
|
{ ctx: { chainIdL2: ctx.chainIdL2 } }
|
|
@@ -6982,7 +7004,7 @@ function getPriorityTxGasBreakdown(input) {
|
|
|
6982
7004
|
}
|
|
6983
7005
|
|
|
6984
7006
|
// src/adapters/viem/resources/deposits/routes/eth.ts
|
|
6985
|
-
var { wrapAs:
|
|
7007
|
+
var { wrapAs: wrapAs3 } = createErrorHandlers("deposits");
|
|
6986
7008
|
var EMPTY_BYTES2 = "0x";
|
|
6987
7009
|
function routeEthDirect() {
|
|
6988
7010
|
return {
|
|
@@ -7013,7 +7035,12 @@ function routeEthDirect() {
|
|
|
7013
7035
|
if (!l2GasParams) {
|
|
7014
7036
|
throw new Error("Failed to estimate L2 gas for deposit.");
|
|
7015
7037
|
}
|
|
7016
|
-
const
|
|
7038
|
+
const l1Fees = await quoteL1Fees2({ ctx });
|
|
7039
|
+
const baseCost = await quoteL2BaseCost({
|
|
7040
|
+
ctx,
|
|
7041
|
+
l2GasLimit: l2GasParams.gasLimit,
|
|
7042
|
+
l1GasPrice: l1Fees.maxFeePerGas
|
|
7043
|
+
});
|
|
7017
7044
|
const mintValue = baseCost + ctx.operatorTip + l2Value;
|
|
7018
7045
|
const req = buildDirectRequestStruct({
|
|
7019
7046
|
chainId: ctx.chainIdL2,
|
|
@@ -7024,7 +7051,7 @@ function routeEthDirect() {
|
|
|
7024
7051
|
l2Contract,
|
|
7025
7052
|
l2Value
|
|
7026
7053
|
});
|
|
7027
|
-
const sim = await
|
|
7054
|
+
const sim = await wrapAs3(
|
|
7028
7055
|
"RPC",
|
|
7029
7056
|
OP_DEPOSITS.eth.estGas,
|
|
7030
7057
|
() => ctx.client.l1.simulateContract({
|
|
@@ -7050,22 +7077,19 @@ function routeEthDirect() {
|
|
|
7050
7077
|
data,
|
|
7051
7078
|
value: mintValue,
|
|
7052
7079
|
from: ctx.sender,
|
|
7053
|
-
...ctx.gasOverrides
|
|
7080
|
+
...ctx.gasOverrides,
|
|
7081
|
+
...l1Fees
|
|
7054
7082
|
};
|
|
7055
7083
|
const l1Gas = await quoteL1Gas2({
|
|
7056
7084
|
ctx,
|
|
7057
7085
|
tx: l1TxCandidate,
|
|
7058
7086
|
overrides: ctx.gasOverrides
|
|
7059
7087
|
});
|
|
7060
|
-
|
|
7061
|
-
|
|
7062
|
-
|
|
7063
|
-
|
|
7064
|
-
|
|
7065
|
-
maxFeePerGas: l1Gas.maxFeePerGas,
|
|
7066
|
-
maxPriorityFeePerGas: l1Gas.maxPriorityFeePerGas
|
|
7067
|
-
};
|
|
7068
|
-
}
|
|
7088
|
+
const bridgeTx = {
|
|
7089
|
+
...sim.request,
|
|
7090
|
+
...l1Fees,
|
|
7091
|
+
...l1Gas ? { gas: l1Gas.gasLimit } : {}
|
|
7092
|
+
};
|
|
7069
7093
|
const steps = [
|
|
7070
7094
|
{
|
|
7071
7095
|
key: "bridgehub:direct",
|
|
@@ -7153,7 +7177,7 @@ async function buildApprovalRequest({
|
|
|
7153
7177
|
}
|
|
7154
7178
|
|
|
7155
7179
|
// src/adapters/viem/resources/deposits/routes/erc20-nonbase.ts
|
|
7156
|
-
var { wrapAs:
|
|
7180
|
+
var { wrapAs: wrapAs4 } = createErrorHandlers("deposits");
|
|
7157
7181
|
var ZERO_ASSET_ID = "0x0000000000000000000000000000000000000000000000000000000000000000";
|
|
7158
7182
|
var ntvCodec = createNTVCodec({
|
|
7159
7183
|
encode: (types, values) => viem.encodeAbiParameters(
|
|
@@ -7244,7 +7268,7 @@ function routeErc20NonBase() {
|
|
|
7244
7268
|
return {
|
|
7245
7269
|
// TODO: do we even need these validations?
|
|
7246
7270
|
async preflight(p, ctx) {
|
|
7247
|
-
await
|
|
7271
|
+
await wrapAs4(
|
|
7248
7272
|
"VALIDATION",
|
|
7249
7273
|
OP_DEPOSITS.nonbase.assertNotEthAsset,
|
|
7250
7274
|
() => {
|
|
@@ -7255,7 +7279,7 @@ function routeErc20NonBase() {
|
|
|
7255
7279
|
{ ctx: { token: p.token } }
|
|
7256
7280
|
);
|
|
7257
7281
|
const baseToken = ctx.baseTokenL1 ?? await ctx.client.baseToken(ctx.chainIdL2);
|
|
7258
|
-
await
|
|
7282
|
+
await wrapAs4(
|
|
7259
7283
|
"VALIDATION",
|
|
7260
7284
|
OP_DEPOSITS.nonbase.assertNonBaseToken,
|
|
7261
7285
|
() => {
|
|
@@ -7272,7 +7296,7 @@ function routeErc20NonBase() {
|
|
|
7272
7296
|
const assetRouter = ctx.l1AssetRouter;
|
|
7273
7297
|
const nativeTokenVault = ctx.l1NativeTokenVault;
|
|
7274
7298
|
const receiver = p.to ?? ctx.sender;
|
|
7275
|
-
const secondBridgeCalldata = await
|
|
7299
|
+
const secondBridgeCalldata = await wrapAs4(
|
|
7276
7300
|
"INTERNAL",
|
|
7277
7301
|
OP_DEPOSITS.nonbase.encodeCalldata,
|
|
7278
7302
|
() => encodeSecondBridgeErc20DepositCalldata({
|
|
@@ -7310,11 +7334,16 @@ function routeErc20NonBase() {
|
|
|
7310
7334
|
}
|
|
7311
7335
|
});
|
|
7312
7336
|
if (!l2Gas) throw new Error("Failed to establish L2 gas parameters.");
|
|
7313
|
-
const
|
|
7337
|
+
const l1Fees = await quoteL1Fees2({ ctx });
|
|
7338
|
+
const l2BaseCost = await quoteL2BaseCost({
|
|
7339
|
+
ctx,
|
|
7340
|
+
l2GasLimit: l2Gas.gasLimit,
|
|
7341
|
+
l1GasPrice: l1Fees.maxFeePerGas
|
|
7342
|
+
});
|
|
7314
7343
|
const mintValue = l2BaseCost + ctx.operatorTip;
|
|
7315
7344
|
const approvals = [];
|
|
7316
7345
|
const steps = [];
|
|
7317
|
-
const depositAllowance = await
|
|
7346
|
+
const depositAllowance = await wrapAs4(
|
|
7318
7347
|
"CONTRACT",
|
|
7319
7348
|
OP_DEPOSITS.nonbase.allowanceToken,
|
|
7320
7349
|
() => ctx.client.l1.readContract({
|
|
@@ -7329,7 +7358,7 @@ function routeErc20NonBase() {
|
|
|
7329
7358
|
}
|
|
7330
7359
|
);
|
|
7331
7360
|
if (depositAllowance < p.amount) {
|
|
7332
|
-
const approveTx = await
|
|
7361
|
+
const approveTx = await wrapAs4(
|
|
7333
7362
|
"CONTRACT",
|
|
7334
7363
|
OP_DEPOSITS.nonbase.estGas,
|
|
7335
7364
|
() => buildApprovalRequest({
|
|
@@ -7352,7 +7381,7 @@ function routeErc20NonBase() {
|
|
|
7352
7381
|
});
|
|
7353
7382
|
}
|
|
7354
7383
|
if (!baseIsEth) {
|
|
7355
|
-
const baseAllowance = await
|
|
7384
|
+
const baseAllowance = await wrapAs4(
|
|
7356
7385
|
"CONTRACT",
|
|
7357
7386
|
OP_DEPOSITS.nonbase.allowanceBase,
|
|
7358
7387
|
() => ctx.client.l1.readContract({
|
|
@@ -7367,7 +7396,7 @@ function routeErc20NonBase() {
|
|
|
7367
7396
|
}
|
|
7368
7397
|
);
|
|
7369
7398
|
if (baseAllowance < mintValue) {
|
|
7370
|
-
const approveBaseTx = await
|
|
7399
|
+
const approveBaseTx = await wrapAs4(
|
|
7371
7400
|
"CONTRACT",
|
|
7372
7401
|
OP_DEPOSITS.nonbase.estGas,
|
|
7373
7402
|
() => buildApprovalRequest({
|
|
@@ -7412,7 +7441,8 @@ function routeErc20NonBase() {
|
|
|
7412
7441
|
data: calldata,
|
|
7413
7442
|
value: msgValue,
|
|
7414
7443
|
from: ctx.sender,
|
|
7415
|
-
...ctx.gasOverrides
|
|
7444
|
+
...ctx.gasOverrides,
|
|
7445
|
+
...l1Fees
|
|
7416
7446
|
};
|
|
7417
7447
|
const l1Gas = await quoteL1Gas2({
|
|
7418
7448
|
ctx,
|
|
@@ -7432,7 +7462,7 @@ function routeErc20NonBase() {
|
|
|
7432
7462
|
account: ctx.client.account
|
|
7433
7463
|
};
|
|
7434
7464
|
} else {
|
|
7435
|
-
const sim = await
|
|
7465
|
+
const sim = await wrapAs4(
|
|
7436
7466
|
"CONTRACT",
|
|
7437
7467
|
OP_DEPOSITS.nonbase.estGas,
|
|
7438
7468
|
() => ctx.client.l1.simulateContract({
|
|
@@ -7450,14 +7480,11 @@ function routeErc20NonBase() {
|
|
|
7450
7480
|
);
|
|
7451
7481
|
bridgeTx = { ...sim.request };
|
|
7452
7482
|
}
|
|
7453
|
-
|
|
7454
|
-
bridgeTx
|
|
7455
|
-
|
|
7456
|
-
|
|
7457
|
-
|
|
7458
|
-
maxPriorityFeePerGas: l1Gas.maxPriorityFeePerGas
|
|
7459
|
-
};
|
|
7460
|
-
}
|
|
7483
|
+
bridgeTx = {
|
|
7484
|
+
...bridgeTx,
|
|
7485
|
+
...l1Fees,
|
|
7486
|
+
...l1Gas ? { gas: l1Gas.gasLimit } : {}
|
|
7487
|
+
};
|
|
7461
7488
|
steps.push({
|
|
7462
7489
|
key: "bridgehub:two-bridges:erc20-nonbase",
|
|
7463
7490
|
kind: "bridgehub:two-bridges",
|
|
@@ -7480,7 +7507,7 @@ function routeErc20NonBase() {
|
|
|
7480
7507
|
}
|
|
7481
7508
|
};
|
|
7482
7509
|
}
|
|
7483
|
-
var { wrapAs:
|
|
7510
|
+
var { wrapAs: wrapAs5 } = createErrorHandlers("deposits");
|
|
7484
7511
|
var ZERO_ASSET_ID2 = "0x0000000000000000000000000000000000000000000000000000000000000000";
|
|
7485
7512
|
var ntvCodec2 = createNTVCodec({
|
|
7486
7513
|
encode: (types, values) => viem.encodeAbiParameters(
|
|
@@ -7489,6 +7516,20 @@ var ntvCodec2 = createNTVCodec({
|
|
|
7489
7516
|
),
|
|
7490
7517
|
keccak256: viem.keccak256
|
|
7491
7518
|
});
|
|
7519
|
+
async function encodeSecondBridgeEthDepositCalldata(input) {
|
|
7520
|
+
const registeredAssetId = input.ctx.resolvedToken?.assetId;
|
|
7521
|
+
const assetId = registeredAssetId && registeredAssetId.toLowerCase() !== ZERO_ASSET_ID2 ? registeredAssetId : ntvCodec2.encodeAssetId(
|
|
7522
|
+
BigInt(await input.ctx.client.l1.getChainId()),
|
|
7523
|
+
L2_NATIVE_TOKEN_VAULT_ADDRESS,
|
|
7524
|
+
ETH_ADDRESS
|
|
7525
|
+
);
|
|
7526
|
+
const transferData = encodeNativeTokenVaultTransferData(
|
|
7527
|
+
input.amount,
|
|
7528
|
+
input.receiver,
|
|
7529
|
+
ETH_ADDRESS
|
|
7530
|
+
);
|
|
7531
|
+
return encodeSecondBridgeDataV1(assetId, transferData);
|
|
7532
|
+
}
|
|
7492
7533
|
async function getPriorityGasModel2(input) {
|
|
7493
7534
|
try {
|
|
7494
7535
|
const l1AssetRouter = await input.ctx.contracts.l1AssetRouter();
|
|
@@ -7550,7 +7591,7 @@ function routeEthNonBase() {
|
|
|
7550
7591
|
return {
|
|
7551
7592
|
// TODO: do we even need these validations?
|
|
7552
7593
|
async preflight(p, ctx) {
|
|
7553
|
-
await
|
|
7594
|
+
await wrapAs5(
|
|
7554
7595
|
"VALIDATION",
|
|
7555
7596
|
OP_DEPOSITS.ethNonBase.assertEthAsset,
|
|
7556
7597
|
() => {
|
|
@@ -7560,7 +7601,7 @@ function routeEthNonBase() {
|
|
|
7560
7601
|
},
|
|
7561
7602
|
{ ctx: { token: p.token } }
|
|
7562
7603
|
);
|
|
7563
|
-
await
|
|
7604
|
+
await wrapAs5(
|
|
7564
7605
|
"VALIDATION",
|
|
7565
7606
|
OP_DEPOSITS.ethNonBase.assertNonEthBase,
|
|
7566
7607
|
() => {
|
|
@@ -7570,7 +7611,7 @@ function routeEthNonBase() {
|
|
|
7570
7611
|
},
|
|
7571
7612
|
{ ctx: { baseIsEth: ctx.baseIsEth, chainIdL2: ctx.chainIdL2 } }
|
|
7572
7613
|
);
|
|
7573
|
-
const ethBal = await
|
|
7614
|
+
const ethBal = await wrapAs5(
|
|
7574
7615
|
"RPC",
|
|
7575
7616
|
OP_DEPOSITS.ethNonBase.ethBalance,
|
|
7576
7617
|
() => ctx.client.l1.getBalance({ address: ctx.sender }),
|
|
@@ -7579,7 +7620,7 @@ function routeEthNonBase() {
|
|
|
7579
7620
|
message: "Failed to read L1 ETH balance."
|
|
7580
7621
|
}
|
|
7581
7622
|
);
|
|
7582
|
-
await
|
|
7623
|
+
await wrapAs5(
|
|
7583
7624
|
"VALIDATION",
|
|
7584
7625
|
OP_DEPOSITS.ethNonBase.assertEthBalance,
|
|
7585
7626
|
() => {
|
|
@@ -7612,11 +7653,16 @@ function routeEthNonBase() {
|
|
|
7612
7653
|
undeployedGasLimit: priorityGasModel.undeployedGasLimit
|
|
7613
7654
|
});
|
|
7614
7655
|
if (!l2Gas) throw new Error("Failed to estimate L2 gas parameters.");
|
|
7615
|
-
const
|
|
7656
|
+
const l1Fees = await quoteL1Fees2({ ctx });
|
|
7657
|
+
const l2BaseCost = await quoteL2BaseCost({
|
|
7658
|
+
ctx,
|
|
7659
|
+
l2GasLimit: l2Gas.gasLimit,
|
|
7660
|
+
l1GasPrice: l1Fees.maxFeePerGas
|
|
7661
|
+
});
|
|
7616
7662
|
const mintValue = l2BaseCost + ctx.operatorTip;
|
|
7617
7663
|
const approvals = [];
|
|
7618
7664
|
const steps = [];
|
|
7619
|
-
const allowance = await
|
|
7665
|
+
const allowance = await wrapAs5(
|
|
7620
7666
|
"CONTRACT",
|
|
7621
7667
|
OP_DEPOSITS.ethNonBase.allowanceBase,
|
|
7622
7668
|
() => ctx.client.l1.readContract({
|
|
@@ -7632,7 +7678,7 @@ function routeEthNonBase() {
|
|
|
7632
7678
|
);
|
|
7633
7679
|
const needsApprove = allowance < mintValue;
|
|
7634
7680
|
if (needsApprove) {
|
|
7635
|
-
const approveTx = await
|
|
7681
|
+
const approveTx = await wrapAs5(
|
|
7636
7682
|
"CONTRACT",
|
|
7637
7683
|
OP_DEPOSITS.ethNonBase.estGas,
|
|
7638
7684
|
() => buildApprovalRequest({
|
|
@@ -7654,13 +7700,13 @@ function routeEthNonBase() {
|
|
|
7654
7700
|
tx: approveTx
|
|
7655
7701
|
});
|
|
7656
7702
|
}
|
|
7657
|
-
const secondBridgeCalldata = await
|
|
7703
|
+
const secondBridgeCalldata = await wrapAs5(
|
|
7658
7704
|
"INTERNAL",
|
|
7659
7705
|
OP_DEPOSITS.ethNonBase.encodeCalldata,
|
|
7660
|
-
() =>
|
|
7706
|
+
() => encodeSecondBridgeEthDepositCalldata({ ctx, amount: p.amount, receiver }),
|
|
7661
7707
|
{
|
|
7662
7708
|
ctx: {
|
|
7663
|
-
where: "
|
|
7709
|
+
where: "encodeSecondBridgeEthDepositCalldata",
|
|
7664
7710
|
amount: p.amount.toString(),
|
|
7665
7711
|
to: receiver
|
|
7666
7712
|
},
|
|
@@ -7696,7 +7742,7 @@ function routeEthNonBase() {
|
|
|
7696
7742
|
args: [requestStruct]
|
|
7697
7743
|
});
|
|
7698
7744
|
} else {
|
|
7699
|
-
const sim = await
|
|
7745
|
+
const sim = await wrapAs5(
|
|
7700
7746
|
"CONTRACT",
|
|
7701
7747
|
OP_DEPOSITS.ethNonBase.estGas,
|
|
7702
7748
|
() => ctx.client.l1.simulateContract({
|
|
@@ -7724,7 +7770,8 @@ function routeEthNonBase() {
|
|
|
7724
7770
|
data: calldata,
|
|
7725
7771
|
value: bridgehubValue,
|
|
7726
7772
|
from: ctx.sender,
|
|
7727
|
-
...ctx.gasOverrides
|
|
7773
|
+
...ctx.gasOverrides,
|
|
7774
|
+
...l1Fees
|
|
7728
7775
|
};
|
|
7729
7776
|
const l1Gas = await quoteL1Gas2({
|
|
7730
7777
|
ctx,
|
|
@@ -7732,14 +7779,11 @@ function routeEthNonBase() {
|
|
|
7732
7779
|
overrides: ctx.gasOverrides,
|
|
7733
7780
|
fallbackGasLimit: SAFE_L1_BRIDGE_GAS
|
|
7734
7781
|
});
|
|
7735
|
-
|
|
7736
|
-
bridgeTx
|
|
7737
|
-
|
|
7738
|
-
|
|
7739
|
-
|
|
7740
|
-
maxPriorityFeePerGas: l1Gas.maxPriorityFeePerGas
|
|
7741
|
-
};
|
|
7742
|
-
}
|
|
7782
|
+
bridgeTx = {
|
|
7783
|
+
...bridgeTx,
|
|
7784
|
+
...l1Fees,
|
|
7785
|
+
...l1Gas ? { gas: l1Gas.gasLimit } : {}
|
|
7786
|
+
};
|
|
7743
7787
|
steps.push({
|
|
7744
7788
|
key: "bridgehub:two-bridges:eth-nonbase",
|
|
7745
7789
|
kind: "bridgehub:two-bridges",
|
|
@@ -7762,12 +7806,12 @@ function routeEthNonBase() {
|
|
|
7762
7806
|
}
|
|
7763
7807
|
};
|
|
7764
7808
|
}
|
|
7765
|
-
var { wrapAs:
|
|
7809
|
+
var { wrapAs: wrapAs6 } = createErrorHandlers("deposits");
|
|
7766
7810
|
var EMPTY_BYTES3 = "0x";
|
|
7767
7811
|
function routeErc20Base() {
|
|
7768
7812
|
return {
|
|
7769
7813
|
async preflight(p, ctx) {
|
|
7770
|
-
await
|
|
7814
|
+
await wrapAs6(
|
|
7771
7815
|
"VALIDATION",
|
|
7772
7816
|
OP_DEPOSITS.base.assertErc20Asset,
|
|
7773
7817
|
() => {
|
|
@@ -7778,7 +7822,7 @@ function routeErc20Base() {
|
|
|
7778
7822
|
{ ctx: { token: p.token } }
|
|
7779
7823
|
);
|
|
7780
7824
|
const baseToken = ctx.baseTokenL1 ?? await ctx.client.baseToken(ctx.chainIdL2);
|
|
7781
|
-
await
|
|
7825
|
+
await wrapAs6(
|
|
7782
7826
|
"VALIDATION",
|
|
7783
7827
|
OP_DEPOSITS.base.assertMatchesBase,
|
|
7784
7828
|
() => {
|
|
@@ -7815,11 +7859,16 @@ function routeErc20Base() {
|
|
|
7815
7859
|
overrideGasLimit: quotedL2GasLimit
|
|
7816
7860
|
});
|
|
7817
7861
|
if (!l2Gas) throw new Error("Failed to estimate L2 gas parameters.");
|
|
7818
|
-
const
|
|
7862
|
+
const l1Fees = await quoteL1Fees2({ ctx });
|
|
7863
|
+
const l2BaseCost = await quoteL2BaseCost({
|
|
7864
|
+
ctx,
|
|
7865
|
+
l2GasLimit: l2Gas.gasLimit,
|
|
7866
|
+
l1GasPrice: l1Fees.maxFeePerGas
|
|
7867
|
+
});
|
|
7819
7868
|
const mintValue = l2BaseCost + ctx.operatorTip + p.amount;
|
|
7820
7869
|
const approvals = [];
|
|
7821
7870
|
const steps = [];
|
|
7822
|
-
const allowance = await
|
|
7871
|
+
const allowance = await wrapAs6(
|
|
7823
7872
|
"CONTRACT",
|
|
7824
7873
|
OP_DEPOSITS.base.allowance,
|
|
7825
7874
|
() => ctx.client.l1.readContract({
|
|
@@ -7835,7 +7884,7 @@ function routeErc20Base() {
|
|
|
7835
7884
|
);
|
|
7836
7885
|
const needsApprove = allowance < mintValue;
|
|
7837
7886
|
if (needsApprove) {
|
|
7838
|
-
const approveTx = await
|
|
7887
|
+
const approveTx = await wrapAs6(
|
|
7839
7888
|
"CONTRACT",
|
|
7840
7889
|
OP_DEPOSITS.base.estGas,
|
|
7841
7890
|
() => buildApprovalRequest({
|
|
@@ -7884,7 +7933,7 @@ function routeErc20Base() {
|
|
|
7884
7933
|
args: [req]
|
|
7885
7934
|
});
|
|
7886
7935
|
} else {
|
|
7887
|
-
const sim = await
|
|
7936
|
+
const sim = await wrapAs6(
|
|
7888
7937
|
"RPC",
|
|
7889
7938
|
OP_DEPOSITS.base.estGas,
|
|
7890
7939
|
() => ctx.client.l1.simulateContract({
|
|
@@ -7912,7 +7961,8 @@ function routeErc20Base() {
|
|
|
7912
7961
|
data: calldata,
|
|
7913
7962
|
value: 0n,
|
|
7914
7963
|
from: ctx.sender,
|
|
7915
|
-
...ctx.gasOverrides
|
|
7964
|
+
...ctx.gasOverrides,
|
|
7965
|
+
...l1Fees
|
|
7916
7966
|
};
|
|
7917
7967
|
const l1Gas = await quoteL1Gas2({
|
|
7918
7968
|
ctx,
|
|
@@ -7920,14 +7970,11 @@ function routeErc20Base() {
|
|
|
7920
7970
|
overrides: ctx.gasOverrides,
|
|
7921
7971
|
fallbackGasLimit: SAFE_L1_BRIDGE_GAS
|
|
7922
7972
|
});
|
|
7923
|
-
|
|
7924
|
-
bridgeTx
|
|
7925
|
-
|
|
7926
|
-
|
|
7927
|
-
|
|
7928
|
-
maxPriorityFeePerGas: l1Gas.maxPriorityFeePerGas
|
|
7929
|
-
};
|
|
7930
|
-
}
|
|
7973
|
+
bridgeTx = {
|
|
7974
|
+
...bridgeTx,
|
|
7975
|
+
...l1Fees,
|
|
7976
|
+
...l1Gas ? { gas: l1Gas.gasLimit } : {}
|
|
7977
|
+
};
|
|
7931
7978
|
steps.push({
|
|
7932
7979
|
key: "bridgehub:direct:erc20-base",
|
|
7933
7980
|
kind: "bridgehub:direct",
|
|
@@ -8025,7 +8072,7 @@ async function waitForL2ExecutionFromL1Tx(l1, l2, l1TxHash) {
|
|
|
8025
8072
|
}
|
|
8026
8073
|
return { l2Receipt, l2TxHash };
|
|
8027
8074
|
}
|
|
8028
|
-
var { wrapAs:
|
|
8075
|
+
var { wrapAs: wrapAs7 } = createErrorHandlers("tokens");
|
|
8029
8076
|
var ntvCodec3 = createNTVCodec({
|
|
8030
8077
|
encode: (types, values) => viem.encodeAbiParameters(
|
|
8031
8078
|
types.map((t, i) => ({ type: t, name: `arg${i}` })),
|
|
@@ -8040,7 +8087,7 @@ function createTokensResource(client) {
|
|
|
8040
8087
|
let wethL2Promise = null;
|
|
8041
8088
|
async function getL1ChainId() {
|
|
8042
8089
|
if (!l2NtvL1ChainIdPromise) {
|
|
8043
|
-
l2NtvL1ChainIdPromise =
|
|
8090
|
+
l2NtvL1ChainIdPromise = wrapAs7("INTERNAL", "getL1ChainId", async () => {
|
|
8044
8091
|
const { l2NativeTokenVault } = await client.contracts();
|
|
8045
8092
|
return await l2NativeTokenVault.read.L1_CHAIN_ID();
|
|
8046
8093
|
});
|
|
@@ -8049,7 +8096,7 @@ function createTokensResource(client) {
|
|
|
8049
8096
|
}
|
|
8050
8097
|
async function getBaseTokenAssetId() {
|
|
8051
8098
|
if (!baseTokenAssetIdPromise) {
|
|
8052
|
-
baseTokenAssetIdPromise =
|
|
8099
|
+
baseTokenAssetIdPromise = wrapAs7("INTERNAL", "baseTokenAssetId", async () => {
|
|
8053
8100
|
const { l2NativeTokenVault } = await client.contracts();
|
|
8054
8101
|
const assetId = await l2NativeTokenVault.read.BASE_TOKEN_ASSET_ID();
|
|
8055
8102
|
return assetId;
|
|
@@ -8059,7 +8106,7 @@ function createTokensResource(client) {
|
|
|
8059
8106
|
}
|
|
8060
8107
|
async function getWethL1() {
|
|
8061
8108
|
if (!wethL1Promise) {
|
|
8062
|
-
wethL1Promise =
|
|
8109
|
+
wethL1Promise = wrapAs7("INTERNAL", "wethL1", async () => {
|
|
8063
8110
|
const { l1NativeTokenVault } = await client.contracts();
|
|
8064
8111
|
const weth = await l1NativeTokenVault.read.WETH_TOKEN();
|
|
8065
8112
|
return weth;
|
|
@@ -8069,7 +8116,7 @@ function createTokensResource(client) {
|
|
|
8069
8116
|
}
|
|
8070
8117
|
async function getWethL2() {
|
|
8071
8118
|
if (!wethL2Promise) {
|
|
8072
|
-
wethL2Promise =
|
|
8119
|
+
wethL2Promise = wrapAs7("INTERNAL", "wethL2", async () => {
|
|
8073
8120
|
const { l2NativeTokenVault } = await client.contracts();
|
|
8074
8121
|
const weth = await l2NativeTokenVault.read.WETH_TOKEN();
|
|
8075
8122
|
return weth;
|
|
@@ -8078,7 +8125,7 @@ function createTokensResource(client) {
|
|
|
8078
8125
|
return wethL2Promise;
|
|
8079
8126
|
}
|
|
8080
8127
|
async function toL2Address(l1Token) {
|
|
8081
|
-
return
|
|
8128
|
+
return wrapAs7("CONTRACT", "tokens.toL2Address", async () => {
|
|
8082
8129
|
const normalized = normalizeL1Token(l1Token);
|
|
8083
8130
|
const chainId = BigInt(await client.l2.getChainId());
|
|
8084
8131
|
const baseToken = await client.baseToken(chainId);
|
|
@@ -8091,7 +8138,7 @@ function createTokensResource(client) {
|
|
|
8091
8138
|
});
|
|
8092
8139
|
}
|
|
8093
8140
|
async function toL1Address(l2Token) {
|
|
8094
|
-
return
|
|
8141
|
+
return wrapAs7("CONTRACT", "tokens.toL1Address", async () => {
|
|
8095
8142
|
if (isAddressEq(l2Token, ETH_ADDRESS)) return ETH_ADDRESS;
|
|
8096
8143
|
if (isAddressEq(l2Token, L2_BASE_TOKEN_ADDRESS)) {
|
|
8097
8144
|
const chainId = BigInt(await client.l2.getChainId());
|
|
@@ -8112,32 +8159,32 @@ function createTokensResource(client) {
|
|
|
8112
8159
|
});
|
|
8113
8160
|
}
|
|
8114
8161
|
async function assetIdOfL1(l1Token) {
|
|
8115
|
-
return
|
|
8162
|
+
return wrapAs7("CONTRACT", "tokens.assetIdOfL1", async () => {
|
|
8116
8163
|
const normalized = normalizeL1Token(l1Token);
|
|
8117
8164
|
const { l1NativeTokenVault } = await client.contracts();
|
|
8118
8165
|
return await l1NativeTokenVault.read.assetId([normalized]);
|
|
8119
8166
|
});
|
|
8120
8167
|
}
|
|
8121
8168
|
async function assetIdOfL2(l2Token) {
|
|
8122
|
-
return
|
|
8169
|
+
return wrapAs7("CONTRACT", "tokens.assetIdOfL2", async () => {
|
|
8123
8170
|
const { l2NativeTokenVault } = await client.contracts();
|
|
8124
8171
|
return await l2NativeTokenVault.read.assetId([l2Token]);
|
|
8125
8172
|
});
|
|
8126
8173
|
}
|
|
8127
8174
|
async function l2TokenFromAssetId(assetId) {
|
|
8128
|
-
return
|
|
8175
|
+
return wrapAs7("CONTRACT", "tokens.l2TokenFromAssetId", async () => {
|
|
8129
8176
|
const { l2NativeTokenVault } = await client.contracts();
|
|
8130
8177
|
return await l2NativeTokenVault.read.tokenAddress([assetId]);
|
|
8131
8178
|
});
|
|
8132
8179
|
}
|
|
8133
8180
|
async function l1TokenFromAssetId(assetId) {
|
|
8134
|
-
return
|
|
8181
|
+
return wrapAs7("CONTRACT", "tokens.l1TokenFromAssetId", async () => {
|
|
8135
8182
|
const { l1NativeTokenVault } = await client.contracts();
|
|
8136
8183
|
return await l1NativeTokenVault.read.tokenAddress([assetId]);
|
|
8137
8184
|
});
|
|
8138
8185
|
}
|
|
8139
8186
|
async function originChainId(assetId) {
|
|
8140
|
-
return
|
|
8187
|
+
return wrapAs7("CONTRACT", "tokens.originChainId", async () => {
|
|
8141
8188
|
const { l2NativeTokenVault } = await client.contracts();
|
|
8142
8189
|
return await l2NativeTokenVault.read.originChainId([assetId]);
|
|
8143
8190
|
});
|
|
@@ -8146,7 +8193,7 @@ function createTokensResource(client) {
|
|
|
8146
8193
|
return getBaseTokenAssetId();
|
|
8147
8194
|
}
|
|
8148
8195
|
async function isChainEthBased() {
|
|
8149
|
-
return
|
|
8196
|
+
return wrapAs7("CONTRACT", "tokens.isChainEthBased", async () => {
|
|
8150
8197
|
const baseAssetId = await getBaseTokenAssetId();
|
|
8151
8198
|
const l1ChainId = await getL1ChainId();
|
|
8152
8199
|
const ethAssetId = ntvCodec3.encodeAssetId(
|
|
@@ -8164,7 +8211,7 @@ function createTokensResource(client) {
|
|
|
8164
8211
|
return getWethL2();
|
|
8165
8212
|
}
|
|
8166
8213
|
async function computeL2BridgedAddress(args) {
|
|
8167
|
-
return
|
|
8214
|
+
return wrapAs7("CONTRACT", "tokens.computeL2BridgedAddress", async () => {
|
|
8168
8215
|
const normalized = normalizeL1Token(args.l1Token);
|
|
8169
8216
|
const { l2NativeTokenVault } = await client.contracts();
|
|
8170
8217
|
const predicted = await l2NativeTokenVault.read.calculateCreate2TokenAddress([
|
|
@@ -8175,7 +8222,7 @@ function createTokensResource(client) {
|
|
|
8175
8222
|
});
|
|
8176
8223
|
}
|
|
8177
8224
|
async function resolve(ref, opts) {
|
|
8178
|
-
return
|
|
8225
|
+
return wrapAs7("CONTRACT", "tokens.resolve", async () => {
|
|
8179
8226
|
let chain;
|
|
8180
8227
|
let address;
|
|
8181
8228
|
if (typeof ref === "string") {
|
|
@@ -8763,12 +8810,12 @@ function buildFeeBreakdown2(p) {
|
|
|
8763
8810
|
}
|
|
8764
8811
|
|
|
8765
8812
|
// src/adapters/viem/resources/withdrawals/routes/eth.ts
|
|
8766
|
-
var { wrapAs:
|
|
8813
|
+
var { wrapAs: wrapAs8 } = createErrorHandlers("withdrawals");
|
|
8767
8814
|
function routeEthBase() {
|
|
8768
8815
|
return {
|
|
8769
8816
|
async build(p, ctx) {
|
|
8770
8817
|
const steps = [];
|
|
8771
|
-
const data = await
|
|
8818
|
+
const data = await wrapAs8(
|
|
8772
8819
|
"INTERNAL",
|
|
8773
8820
|
OP_WITHDRAWALS.eth.encodeWithdraw,
|
|
8774
8821
|
() => Promise.resolve(
|
|
@@ -8818,14 +8865,14 @@ function routeEthBase() {
|
|
|
8818
8865
|
}
|
|
8819
8866
|
};
|
|
8820
8867
|
}
|
|
8821
|
-
var { wrapAs:
|
|
8868
|
+
var { wrapAs: wrapAs9 } = createErrorHandlers("withdrawals");
|
|
8822
8869
|
function routeErc20NonBase2() {
|
|
8823
8870
|
return {
|
|
8824
8871
|
// TODO: add preflight validations here
|
|
8825
8872
|
async build(p, ctx) {
|
|
8826
8873
|
const steps = [];
|
|
8827
8874
|
const approvals = [];
|
|
8828
|
-
const current = await
|
|
8875
|
+
const current = await wrapAs9(
|
|
8829
8876
|
"CONTRACT",
|
|
8830
8877
|
OP_WITHDRAWALS.erc20.allowance,
|
|
8831
8878
|
() => ctx.client.l2.readContract({
|
|
@@ -8864,7 +8911,7 @@ function routeErc20NonBase2() {
|
|
|
8864
8911
|
approveTxCandidate.maxFeePerGas = approveGas.maxFeePerGas;
|
|
8865
8912
|
approveTxCandidate.maxPriorityFeePerGas = approveGas.maxPriorityFeePerGas;
|
|
8866
8913
|
}
|
|
8867
|
-
const approveSim = await
|
|
8914
|
+
const approveSim = await wrapAs9(
|
|
8868
8915
|
"CONTRACT",
|
|
8869
8916
|
OP_WITHDRAWALS.erc20.estGas,
|
|
8870
8917
|
() => ctx.client.l2.simulateContract({
|
|
@@ -8891,7 +8938,7 @@ function routeErc20NonBase2() {
|
|
|
8891
8938
|
tx: approveTx
|
|
8892
8939
|
});
|
|
8893
8940
|
}
|
|
8894
|
-
const assetId = (await
|
|
8941
|
+
const assetId = (await wrapAs9(
|
|
8895
8942
|
"CONTRACT",
|
|
8896
8943
|
OP_WITHDRAWALS.erc20.ensureRegistered,
|
|
8897
8944
|
() => ctx.client.l2.simulateContract({
|
|
@@ -8942,7 +8989,7 @@ function routeErc20NonBase2() {
|
|
|
8942
8989
|
...withdrawGas
|
|
8943
8990
|
};
|
|
8944
8991
|
} else {
|
|
8945
|
-
const sim = await
|
|
8992
|
+
const sim = await wrapAs9(
|
|
8946
8993
|
"CONTRACT",
|
|
8947
8994
|
OP_WITHDRAWALS.erc20.estGas,
|
|
8948
8995
|
() => ctx.client.l2.simulateContract({
|
|
@@ -9104,7 +9151,7 @@ function buildWithdrawalBundle(input) {
|
|
|
9104
9151
|
}
|
|
9105
9152
|
|
|
9106
9153
|
// src/adapters/viem/resources/withdrawals/routes/interop-bundle.ts
|
|
9107
|
-
var { wrapAs:
|
|
9154
|
+
var { wrapAs: wrapAs10 } = createErrorHandlers("withdrawals");
|
|
9108
9155
|
var attributes = createViemAttributesResource();
|
|
9109
9156
|
function saltFor(sender, nonce) {
|
|
9110
9157
|
return viem.keccak256(
|
|
@@ -9129,7 +9176,7 @@ function routeInteropBundle() {
|
|
|
9129
9176
|
if (isBaseToken) {
|
|
9130
9177
|
assetId = ctx.baseTokenAssetId;
|
|
9131
9178
|
} else {
|
|
9132
|
-
assetId = (await
|
|
9179
|
+
assetId = (await wrapAs10(
|
|
9133
9180
|
"CONTRACT",
|
|
9134
9181
|
OP_WITHDRAWALS.erc20.ensureRegistered,
|
|
9135
9182
|
() => ctx.client.l2.simulateContract({
|
|
@@ -9144,7 +9191,7 @@ function routeInteropBundle() {
|
|
|
9144
9191
|
message: "Failed to ensure token is registered in L2NativeTokenVault."
|
|
9145
9192
|
}
|
|
9146
9193
|
)).result;
|
|
9147
|
-
const current = await
|
|
9194
|
+
const current = await wrapAs10(
|
|
9148
9195
|
"CONTRACT",
|
|
9149
9196
|
OP_WITHDRAWALS.erc20.allowance,
|
|
9150
9197
|
() => ctx.client.l2.readContract({
|
|
@@ -9193,7 +9240,7 @@ function routeInteropBundle() {
|
|
|
9193
9240
|
});
|
|
9194
9241
|
}
|
|
9195
9242
|
}
|
|
9196
|
-
const nonce = await
|
|
9243
|
+
const nonce = await wrapAs10(
|
|
9197
9244
|
"RPC",
|
|
9198
9245
|
OP_WITHDRAWALS.prepare,
|
|
9199
9246
|
() => ctx.client.l2.getTransactionCount({ address: ctx.sender, blockTag: "pending" }),
|
|
@@ -9429,7 +9476,7 @@ function createWithdrawalProtocolService(client, override) {
|
|
|
9429
9476
|
}
|
|
9430
9477
|
};
|
|
9431
9478
|
}
|
|
9432
|
-
var { wrapAs:
|
|
9479
|
+
var { wrapAs: wrapAs11 } = createErrorHandlers("withdrawals");
|
|
9433
9480
|
var IL1NullifierMini = [
|
|
9434
9481
|
{
|
|
9435
9482
|
type: "function",
|
|
@@ -9447,7 +9494,7 @@ function createFinalizationServices(client, protocolService = createWithdrawalPr
|
|
|
9447
9494
|
async function finalizationTarget(protocol) {
|
|
9448
9495
|
const { l1Nullifier } = await client.ensureAddresses();
|
|
9449
9496
|
if (protocol === "legacy-withdrawal") return l1Nullifier;
|
|
9450
|
-
return await
|
|
9497
|
+
return await wrapAs11(
|
|
9451
9498
|
"CONTRACT",
|
|
9452
9499
|
OP_WITHDRAWALS.finalize.fetchParams.receipt,
|
|
9453
9500
|
() => client.l1.readContract({
|
|
@@ -9462,7 +9509,7 @@ function createFinalizationServices(client, protocolService = createWithdrawalPr
|
|
|
9462
9509
|
);
|
|
9463
9510
|
}
|
|
9464
9511
|
async function fetchMessageAndProof(l2TxHash) {
|
|
9465
|
-
const raw = await
|
|
9512
|
+
const raw = await wrapAs11(
|
|
9466
9513
|
"RPC",
|
|
9467
9514
|
OP_WITHDRAWALS.finalize.fetchParams.receipt,
|
|
9468
9515
|
() => client.zks.getReceiptWithL2ToL1(l2TxHash),
|
|
@@ -9479,7 +9526,7 @@ function createFinalizationServices(client, protocolService = createWithdrawalPr
|
|
|
9479
9526
|
context: { l2TxHash }
|
|
9480
9527
|
});
|
|
9481
9528
|
}
|
|
9482
|
-
const ev = await
|
|
9529
|
+
const ev = await wrapAs11(
|
|
9483
9530
|
"INTERNAL",
|
|
9484
9531
|
OP_WITHDRAWALS.finalize.fetchParams.findMessage,
|
|
9485
9532
|
// eslint-disable-next-line @typescript-eslint/no-unsafe-argument, @typescript-eslint/no-explicit-any
|
|
@@ -9489,7 +9536,7 @@ function createFinalizationServices(client, protocolService = createWithdrawalPr
|
|
|
9489
9536
|
message: "Failed to locate L1MessageSent event in L2 receipt."
|
|
9490
9537
|
}
|
|
9491
9538
|
);
|
|
9492
|
-
const message = await
|
|
9539
|
+
const message = await wrapAs11(
|
|
9493
9540
|
"INTERNAL",
|
|
9494
9541
|
OP_WITHDRAWALS.finalize.fetchParams.decodeMessage,
|
|
9495
9542
|
() => {
|
|
@@ -9501,7 +9548,7 @@ function createFinalizationServices(client, protocolService = createWithdrawalPr
|
|
|
9501
9548
|
message: "Failed to decode withdrawal message."
|
|
9502
9549
|
}
|
|
9503
9550
|
);
|
|
9504
|
-
const idx = await
|
|
9551
|
+
const idx = await wrapAs11(
|
|
9505
9552
|
"INTERNAL",
|
|
9506
9553
|
OP_WITHDRAWALS.finalize.fetchParams.messengerIndex,
|
|
9507
9554
|
() => Promise.resolve(messengerLogIndex(raw, { index: 0, messenger: L1_MESSENGER_ADDRESS })),
|
|
@@ -9510,7 +9557,7 @@ function createFinalizationServices(client, protocolService = createWithdrawalPr
|
|
|
9510
9557
|
message: "Failed to derive messenger log index."
|
|
9511
9558
|
}
|
|
9512
9559
|
);
|
|
9513
|
-
const proof = await
|
|
9560
|
+
const proof = await wrapAs11(
|
|
9514
9561
|
"RPC",
|
|
9515
9562
|
OP_WITHDRAWALS.finalize.fetchParams.proof,
|
|
9516
9563
|
() => client.zks.getL2ToL1LogProof(l2TxHash, idx),
|
|
@@ -9519,7 +9566,7 @@ function createFinalizationServices(client, protocolService = createWithdrawalPr
|
|
|
9519
9566
|
message: "Failed to fetch L2\u2192L1 log proof."
|
|
9520
9567
|
}
|
|
9521
9568
|
);
|
|
9522
|
-
const chainId = await
|
|
9569
|
+
const chainId = await wrapAs11(
|
|
9523
9570
|
"RPC",
|
|
9524
9571
|
OP_WITHDRAWALS.finalize.fetchParams.network,
|
|
9525
9572
|
() => client.l2.getChainId(),
|
|
@@ -9577,7 +9624,7 @@ function createFinalizationServices(client, protocolService = createWithdrawalPr
|
|
|
9577
9624
|
async function withdrawalOutcome(finalization) {
|
|
9578
9625
|
const target = await finalizationTarget(finalization.protocol);
|
|
9579
9626
|
if (finalization.protocol === "legacy-withdrawal") {
|
|
9580
|
-
const done = await
|
|
9627
|
+
const done = await wrapAs11(
|
|
9581
9628
|
"RPC",
|
|
9582
9629
|
OP_WITHDRAWALS.finalize.isFinalized,
|
|
9583
9630
|
() => client.l1.readContract({
|
|
@@ -9599,7 +9646,7 @@ function createFinalizationServices(client, protocolService = createWithdrawalPr
|
|
|
9599
9646
|
}
|
|
9600
9647
|
const { bundleHash } = finalization.params;
|
|
9601
9648
|
const status = Number(
|
|
9602
|
-
await
|
|
9649
|
+
await wrapAs11(
|
|
9603
9650
|
"RPC",
|
|
9604
9651
|
OP_WITHDRAWALS.finalize.isFinalized,
|
|
9605
9652
|
() => client.l1.readContract({
|
|
@@ -9616,7 +9663,7 @@ function createFinalizationServices(client, protocolService = createWithdrawalPr
|
|
|
9616
9663
|
);
|
|
9617
9664
|
if (status !== 3 /* Unbundled */) return classifyWithdrawalOutcome(status);
|
|
9618
9665
|
const callStatus = Number(
|
|
9619
|
-
await
|
|
9666
|
+
await wrapAs11(
|
|
9620
9667
|
"RPC",
|
|
9621
9668
|
OP_WITHDRAWALS.finalize.isFinalized,
|
|
9622
9669
|
() => client.l1.readContract({
|
|
@@ -9687,7 +9734,7 @@ function createFinalizationServices(client, protocolService = createWithdrawalPr
|
|
|
9687
9734
|
},
|
|
9688
9735
|
async estimateFinalization(finalization) {
|
|
9689
9736
|
const target = await finalizationTarget(finalization.protocol);
|
|
9690
|
-
const gasLimit = await
|
|
9737
|
+
const gasLimit = await wrapAs11(
|
|
9691
9738
|
"RPC",
|
|
9692
9739
|
OP_WITHDRAWALS.finalize.estimate,
|
|
9693
9740
|
() => finalization.protocol === "legacy-withdrawal" ? client.l1.estimateContractGas({
|
|
@@ -9715,7 +9762,7 @@ function createFinalizationServices(client, protocolService = createWithdrawalPr
|
|
|
9715
9762
|
let maxFeePerGas;
|
|
9716
9763
|
let maxPriorityFeePerGas;
|
|
9717
9764
|
try {
|
|
9718
|
-
const fee = await
|
|
9765
|
+
const fee = await wrapAs11(
|
|
9719
9766
|
"RPC",
|
|
9720
9767
|
OP_WITHDRAWALS.finalize.estimate,
|
|
9721
9768
|
() => client.l1.estimateFeesPerGas(),
|
|
@@ -9734,7 +9781,7 @@ function createFinalizationServices(client, protocolService = createWithdrawalPr
|
|
|
9734
9781
|
})();
|
|
9735
9782
|
maxPriorityFeePerGas = fee.maxPriorityFeePerGas ?? 0n;
|
|
9736
9783
|
} catch {
|
|
9737
|
-
const gasPrice = await
|
|
9784
|
+
const gasPrice = await wrapAs11(
|
|
9738
9785
|
"RPC",
|
|
9739
9786
|
OP_WITHDRAWALS.finalize.estimate,
|
|
9740
9787
|
() => client.l1.getGasPrice(),
|