@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
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import { createNTVCodec, createAttributesResource, resolveCreateDepositL1GasLimit, isInteropFinalizationInfo, DEFAULT_POLL_MS, DEFAULT_TIMEOUT_MS, resolveIdsFromWaitable, parseBundleReceiptInfo, buildFinalizationInfo, parseBundleSentFromReceipt, pickInteropRoute, ZERO_HASH, toGasOverrides, clampPriorityL2GasLimit, applyPriorityL2GasLimitBuffer, buildFeeBreakdown, buildIndirectBundle, preflightIndirect, buildDirectBundle, preflightDirect, derivePriorityTxGasBreakdown, quoteL2Gas, quoteL1Gas, applyL1ToL2Alias, derivePriorityBodyGasEstimateCap, assertProtocolVersion, resolveRegisteredTokenPriorityL2GasLimit, quoteL2Gas2 } from './chunk-
|
|
2
|
-
import { detectWithdrawalProtocol, buildWithdrawalFinalization, parseBundleHashFromLogs, classifyWithdrawalOutcome, phaseFromReadiness, buildWithdrawalBundle } from './chunk-
|
|
1
|
+
import { createNTVCodec, createAttributesResource, resolveCreateDepositL1GasLimit, isInteropFinalizationInfo, DEFAULT_POLL_MS, DEFAULT_TIMEOUT_MS, resolveIdsFromWaitable, parseBundleReceiptInfo, buildFinalizationInfo, parseBundleSentFromReceipt, pickInteropRoute, ZERO_HASH, toGasOverrides, clampPriorityL2GasLimit, applyPriorityL2GasLimitBuffer, buildFeeBreakdown, buildIndirectBundle, preflightIndirect, buildDirectBundle, preflightDirect, derivePriorityTxGasBreakdown, quoteL2Gas, quoteL1Fees, quoteL1Gas, applyL1ToL2Alias, derivePriorityBodyGasEstimateCap, assertProtocolVersion, resolveRegisteredTokenPriorityL2GasLimit, quoteL2Gas2 } from './chunk-JWN26CQ6.js';
|
|
2
|
+
import { detectWithdrawalProtocol, buildWithdrawalFinalization, parseBundleHashFromLogs, classifyWithdrawalOutcome, phaseFromReadiness, buildWithdrawalBundle } from './chunk-BQ2YCWV2.js';
|
|
3
3
|
import { findL1MessageSentLog, messengerLogIndex, l1MessageSentSender, pickWithdrawRoute } from './chunk-OEUDZFXH.js';
|
|
4
|
-
import { createErrorHandlers, toZKsyncError, classifyReadinessFromRevert } from './chunk-
|
|
5
|
-
import { IERC7786Attributes_default, isHash66, IL1Nullifier_default, IInteropHandler_default, OP_WITHDRAWALS, createError, normalizeL1Token, isAddressEq, hexEq, OP_DEPOSITS, IERC20_default, isZKsyncError, isReceiptNotFound, IL1NullifierV32_default, OP_INTEROP, IInteropRootStorage_default, IInteropCenter_default, sleep, IBridgehub_default, isETH, normalizeAddrEq, IL2AssetRouter_default, L2NativeTokenVault_default, IBaseToken_default, assertNever } from './chunk-
|
|
4
|
+
import { createErrorHandlers, toZKsyncError, classifyReadinessFromRevert } from './chunk-H5A6GU3D.js';
|
|
5
|
+
import { IERC7786Attributes_default, isHash66, IL1Nullifier_default, IInteropHandler_default, OP_WITHDRAWALS, createError, normalizeL1Token, isAddressEq, hexEq, OP_DEPOSITS, IERC20_default, isZKsyncError, isReceiptNotFound, IL1NullifierV32_default, OP_INTEROP, IInteropRootStorage_default, IInteropCenter_default, sleep, IBridgehub_default, isETH, normalizeAddrEq, IL2AssetRouter_default, L2NativeTokenVault_default, IBaseToken_default, assertNever } from './chunk-JNS4XZE2.js';
|
|
6
6
|
import { ETH_ADDRESS, TOPIC_CANONICAL_ASSIGNED, TOPIC_CANONICAL_SUCCESS, L2_BASE_TOKEN_ADDRESS, L2_NATIVE_TOKEN_VAULT_ADDRESS, L1_MESSENGER_ADDRESS, L2_INTEROP_ROOT_STORAGE_ADDRESS, BUFFER, SAFE_L1_BRIDGE_GAS, L2_ASSET_ROUTER_ADDRESS, FORMAL_ETH_ADDRESS, ZKSYNC_OS_PRIORITY_TX_TYPE } from './chunk-3IPSDGHO.js';
|
|
7
7
|
import { keccak256, encodeAbiParameters, toBytes, encodeFunctionData, concat, decodeEventLog, createWalletClient, custom, decodeAbiParameters, createPublicClient, http, encodeEventTopics, numberToHex, zeroAddress, getAddress, toHex } from 'viem';
|
|
8
8
|
|
|
@@ -195,6 +195,7 @@ function viemToGasEstimator(client) {
|
|
|
195
195
|
}
|
|
196
196
|
|
|
197
197
|
// src/adapters/viem/resources/deposits/services/gas.ts
|
|
198
|
+
var { wrapAs } = createErrorHandlers("deposits");
|
|
198
199
|
var DEFAULT_SAFE_NONBASE_L2_GAS_LIMIT = 3000000n;
|
|
199
200
|
async function estimatePriorityTxL2Gas(ctx, leg) {
|
|
200
201
|
if (!leg) return void 0;
|
|
@@ -204,6 +205,18 @@ async function estimatePriorityTxL2Gas(ctx, leg) {
|
|
|
204
205
|
return void 0;
|
|
205
206
|
}
|
|
206
207
|
}
|
|
208
|
+
async function quoteL1Fees2(input) {
|
|
209
|
+
const { ctx } = input;
|
|
210
|
+
return wrapAs(
|
|
211
|
+
"RPC",
|
|
212
|
+
"deposits.fees.l1",
|
|
213
|
+
() => quoteL1Fees({
|
|
214
|
+
estimator: viemToGasEstimator(ctx.client.l1),
|
|
215
|
+
overrides: ctx.gasOverrides
|
|
216
|
+
}),
|
|
217
|
+
{ ctx: { chainIdL2: ctx.chainIdL2 } }
|
|
218
|
+
);
|
|
219
|
+
}
|
|
207
220
|
async function quoteL1Gas2(input) {
|
|
208
221
|
const { ctx, tx, overrides, fallbackGasLimit } = input;
|
|
209
222
|
const estimator = viemToGasEstimator(ctx.client.l1);
|
|
@@ -306,13 +319,10 @@ async function determineEthNonBaseL2Gas(input) {
|
|
|
306
319
|
}
|
|
307
320
|
|
|
308
321
|
// src/adapters/viem/resources/deposits/services/fee.ts
|
|
309
|
-
var { wrapAs } = createErrorHandlers("deposits");
|
|
322
|
+
var { wrapAs: wrapAs2 } = createErrorHandlers("deposits");
|
|
310
323
|
async function quoteL2BaseCost(input) {
|
|
311
|
-
const { ctx, l2GasLimit } = input;
|
|
312
|
-
|
|
313
|
-
const fees = await estimator.estimateFeesPerGas();
|
|
314
|
-
const gasPrice = fees.maxFeePerGas ?? fees.gasPrice ?? await estimator.getGasPrice();
|
|
315
|
-
return wrapAs(
|
|
324
|
+
const { ctx, l2GasLimit, l1GasPrice } = input;
|
|
325
|
+
return wrapAs2(
|
|
316
326
|
"RPC",
|
|
317
327
|
"deposits.fees.l2BaseCost",
|
|
318
328
|
async () => {
|
|
@@ -320,7 +330,7 @@ async function quoteL2BaseCost(input) {
|
|
|
320
330
|
address: ctx.bridgehub,
|
|
321
331
|
abi: IBridgehub_default,
|
|
322
332
|
functionName: "l2TransactionBaseCost",
|
|
323
|
-
args: [ctx.chainIdL2,
|
|
333
|
+
args: [ctx.chainIdL2, l1GasPrice, l2GasLimit, ctx.gasPerPubdata]
|
|
324
334
|
});
|
|
325
335
|
},
|
|
326
336
|
{ ctx: { chainIdL2: ctx.chainIdL2 } }
|
|
@@ -387,7 +397,7 @@ function getPriorityTxGasBreakdown(input) {
|
|
|
387
397
|
}
|
|
388
398
|
|
|
389
399
|
// src/adapters/viem/resources/deposits/routes/eth.ts
|
|
390
|
-
var { wrapAs:
|
|
400
|
+
var { wrapAs: wrapAs3 } = createErrorHandlers("deposits");
|
|
391
401
|
var EMPTY_BYTES2 = "0x";
|
|
392
402
|
function routeEthDirect() {
|
|
393
403
|
return {
|
|
@@ -418,7 +428,12 @@ function routeEthDirect() {
|
|
|
418
428
|
if (!l2GasParams) {
|
|
419
429
|
throw new Error("Failed to estimate L2 gas for deposit.");
|
|
420
430
|
}
|
|
421
|
-
const
|
|
431
|
+
const l1Fees = await quoteL1Fees2({ ctx });
|
|
432
|
+
const baseCost = await quoteL2BaseCost({
|
|
433
|
+
ctx,
|
|
434
|
+
l2GasLimit: l2GasParams.gasLimit,
|
|
435
|
+
l1GasPrice: l1Fees.maxFeePerGas
|
|
436
|
+
});
|
|
422
437
|
const mintValue = baseCost + ctx.operatorTip + l2Value;
|
|
423
438
|
const req = buildDirectRequestStruct({
|
|
424
439
|
chainId: ctx.chainIdL2,
|
|
@@ -429,7 +444,7 @@ function routeEthDirect() {
|
|
|
429
444
|
l2Contract,
|
|
430
445
|
l2Value
|
|
431
446
|
});
|
|
432
|
-
const sim = await
|
|
447
|
+
const sim = await wrapAs3(
|
|
433
448
|
"RPC",
|
|
434
449
|
OP_DEPOSITS.eth.estGas,
|
|
435
450
|
() => ctx.client.l1.simulateContract({
|
|
@@ -455,22 +470,19 @@ function routeEthDirect() {
|
|
|
455
470
|
data,
|
|
456
471
|
value: mintValue,
|
|
457
472
|
from: ctx.sender,
|
|
458
|
-
...ctx.gasOverrides
|
|
473
|
+
...ctx.gasOverrides,
|
|
474
|
+
...l1Fees
|
|
459
475
|
};
|
|
460
476
|
const l1Gas = await quoteL1Gas2({
|
|
461
477
|
ctx,
|
|
462
478
|
tx: l1TxCandidate,
|
|
463
479
|
overrides: ctx.gasOverrides
|
|
464
480
|
});
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
maxFeePerGas: l1Gas.maxFeePerGas,
|
|
471
|
-
maxPriorityFeePerGas: l1Gas.maxPriorityFeePerGas
|
|
472
|
-
};
|
|
473
|
-
}
|
|
481
|
+
const bridgeTx = {
|
|
482
|
+
...sim.request,
|
|
483
|
+
...l1Fees,
|
|
484
|
+
...l1Gas ? { gas: l1Gas.gasLimit } : {}
|
|
485
|
+
};
|
|
474
486
|
const steps = [
|
|
475
487
|
{
|
|
476
488
|
key: "bridgehub:direct",
|
|
@@ -544,7 +556,7 @@ async function buildApprovalRequest({
|
|
|
544
556
|
}
|
|
545
557
|
|
|
546
558
|
// src/adapters/viem/resources/deposits/routes/erc20-nonbase.ts
|
|
547
|
-
var { wrapAs:
|
|
559
|
+
var { wrapAs: wrapAs4 } = createErrorHandlers("deposits");
|
|
548
560
|
var ZERO_ASSET_ID = "0x0000000000000000000000000000000000000000000000000000000000000000";
|
|
549
561
|
var ntvCodec = createNTVCodec({
|
|
550
562
|
encode: (types, values) => encodeAbiParameters(
|
|
@@ -635,7 +647,7 @@ function routeErc20NonBase() {
|
|
|
635
647
|
return {
|
|
636
648
|
// TODO: do we even need these validations?
|
|
637
649
|
async preflight(p, ctx) {
|
|
638
|
-
await
|
|
650
|
+
await wrapAs4(
|
|
639
651
|
"VALIDATION",
|
|
640
652
|
OP_DEPOSITS.nonbase.assertNotEthAsset,
|
|
641
653
|
() => {
|
|
@@ -646,7 +658,7 @@ function routeErc20NonBase() {
|
|
|
646
658
|
{ ctx: { token: p.token } }
|
|
647
659
|
);
|
|
648
660
|
const baseToken = ctx.baseTokenL1 ?? await ctx.client.baseToken(ctx.chainIdL2);
|
|
649
|
-
await
|
|
661
|
+
await wrapAs4(
|
|
650
662
|
"VALIDATION",
|
|
651
663
|
OP_DEPOSITS.nonbase.assertNonBaseToken,
|
|
652
664
|
() => {
|
|
@@ -663,7 +675,7 @@ function routeErc20NonBase() {
|
|
|
663
675
|
const assetRouter = ctx.l1AssetRouter;
|
|
664
676
|
const nativeTokenVault = ctx.l1NativeTokenVault;
|
|
665
677
|
const receiver = p.to ?? ctx.sender;
|
|
666
|
-
const secondBridgeCalldata = await
|
|
678
|
+
const secondBridgeCalldata = await wrapAs4(
|
|
667
679
|
"INTERNAL",
|
|
668
680
|
OP_DEPOSITS.nonbase.encodeCalldata,
|
|
669
681
|
() => encodeSecondBridgeErc20DepositCalldata({
|
|
@@ -701,11 +713,16 @@ function routeErc20NonBase() {
|
|
|
701
713
|
}
|
|
702
714
|
});
|
|
703
715
|
if (!l2Gas) throw new Error("Failed to establish L2 gas parameters.");
|
|
704
|
-
const
|
|
716
|
+
const l1Fees = await quoteL1Fees2({ ctx });
|
|
717
|
+
const l2BaseCost = await quoteL2BaseCost({
|
|
718
|
+
ctx,
|
|
719
|
+
l2GasLimit: l2Gas.gasLimit,
|
|
720
|
+
l1GasPrice: l1Fees.maxFeePerGas
|
|
721
|
+
});
|
|
705
722
|
const mintValue = l2BaseCost + ctx.operatorTip;
|
|
706
723
|
const approvals = [];
|
|
707
724
|
const steps = [];
|
|
708
|
-
const depositAllowance = await
|
|
725
|
+
const depositAllowance = await wrapAs4(
|
|
709
726
|
"CONTRACT",
|
|
710
727
|
OP_DEPOSITS.nonbase.allowanceToken,
|
|
711
728
|
() => ctx.client.l1.readContract({
|
|
@@ -720,7 +737,7 @@ function routeErc20NonBase() {
|
|
|
720
737
|
}
|
|
721
738
|
);
|
|
722
739
|
if (depositAllowance < p.amount) {
|
|
723
|
-
const approveTx = await
|
|
740
|
+
const approveTx = await wrapAs4(
|
|
724
741
|
"CONTRACT",
|
|
725
742
|
OP_DEPOSITS.nonbase.estGas,
|
|
726
743
|
() => buildApprovalRequest({
|
|
@@ -743,7 +760,7 @@ function routeErc20NonBase() {
|
|
|
743
760
|
});
|
|
744
761
|
}
|
|
745
762
|
if (!baseIsEth) {
|
|
746
|
-
const baseAllowance = await
|
|
763
|
+
const baseAllowance = await wrapAs4(
|
|
747
764
|
"CONTRACT",
|
|
748
765
|
OP_DEPOSITS.nonbase.allowanceBase,
|
|
749
766
|
() => ctx.client.l1.readContract({
|
|
@@ -758,7 +775,7 @@ function routeErc20NonBase() {
|
|
|
758
775
|
}
|
|
759
776
|
);
|
|
760
777
|
if (baseAllowance < mintValue) {
|
|
761
|
-
const approveBaseTx = await
|
|
778
|
+
const approveBaseTx = await wrapAs4(
|
|
762
779
|
"CONTRACT",
|
|
763
780
|
OP_DEPOSITS.nonbase.estGas,
|
|
764
781
|
() => buildApprovalRequest({
|
|
@@ -803,7 +820,8 @@ function routeErc20NonBase() {
|
|
|
803
820
|
data: calldata,
|
|
804
821
|
value: msgValue,
|
|
805
822
|
from: ctx.sender,
|
|
806
|
-
...ctx.gasOverrides
|
|
823
|
+
...ctx.gasOverrides,
|
|
824
|
+
...l1Fees
|
|
807
825
|
};
|
|
808
826
|
const l1Gas = await quoteL1Gas2({
|
|
809
827
|
ctx,
|
|
@@ -823,7 +841,7 @@ function routeErc20NonBase() {
|
|
|
823
841
|
account: ctx.client.account
|
|
824
842
|
};
|
|
825
843
|
} else {
|
|
826
|
-
const sim = await
|
|
844
|
+
const sim = await wrapAs4(
|
|
827
845
|
"CONTRACT",
|
|
828
846
|
OP_DEPOSITS.nonbase.estGas,
|
|
829
847
|
() => ctx.client.l1.simulateContract({
|
|
@@ -841,14 +859,11 @@ function routeErc20NonBase() {
|
|
|
841
859
|
);
|
|
842
860
|
bridgeTx = { ...sim.request };
|
|
843
861
|
}
|
|
844
|
-
|
|
845
|
-
bridgeTx
|
|
846
|
-
|
|
847
|
-
|
|
848
|
-
|
|
849
|
-
maxPriorityFeePerGas: l1Gas.maxPriorityFeePerGas
|
|
850
|
-
};
|
|
851
|
-
}
|
|
862
|
+
bridgeTx = {
|
|
863
|
+
...bridgeTx,
|
|
864
|
+
...l1Fees,
|
|
865
|
+
...l1Gas ? { gas: l1Gas.gasLimit } : {}
|
|
866
|
+
};
|
|
852
867
|
steps.push({
|
|
853
868
|
key: "bridgehub:two-bridges:erc20-nonbase",
|
|
854
869
|
kind: "bridgehub:two-bridges",
|
|
@@ -871,7 +886,7 @@ function routeErc20NonBase() {
|
|
|
871
886
|
}
|
|
872
887
|
};
|
|
873
888
|
}
|
|
874
|
-
var { wrapAs:
|
|
889
|
+
var { wrapAs: wrapAs5 } = createErrorHandlers("deposits");
|
|
875
890
|
var ZERO_ASSET_ID2 = "0x0000000000000000000000000000000000000000000000000000000000000000";
|
|
876
891
|
var ntvCodec2 = createNTVCodec({
|
|
877
892
|
encode: (types, values) => encodeAbiParameters(
|
|
@@ -880,6 +895,20 @@ var ntvCodec2 = createNTVCodec({
|
|
|
880
895
|
),
|
|
881
896
|
keccak256: keccak256
|
|
882
897
|
});
|
|
898
|
+
async function encodeSecondBridgeEthDepositCalldata(input) {
|
|
899
|
+
const registeredAssetId = input.ctx.resolvedToken?.assetId;
|
|
900
|
+
const assetId = registeredAssetId && registeredAssetId.toLowerCase() !== ZERO_ASSET_ID2 ? registeredAssetId : ntvCodec2.encodeAssetId(
|
|
901
|
+
BigInt(await input.ctx.client.l1.getChainId()),
|
|
902
|
+
L2_NATIVE_TOKEN_VAULT_ADDRESS,
|
|
903
|
+
ETH_ADDRESS
|
|
904
|
+
);
|
|
905
|
+
const transferData = encodeNativeTokenVaultTransferData(
|
|
906
|
+
input.amount,
|
|
907
|
+
input.receiver,
|
|
908
|
+
ETH_ADDRESS
|
|
909
|
+
);
|
|
910
|
+
return encodeSecondBridgeDataV1(assetId, transferData);
|
|
911
|
+
}
|
|
883
912
|
async function getPriorityGasModel2(input) {
|
|
884
913
|
try {
|
|
885
914
|
const l1AssetRouter = await input.ctx.contracts.l1AssetRouter();
|
|
@@ -941,7 +970,7 @@ function routeEthNonBase() {
|
|
|
941
970
|
return {
|
|
942
971
|
// TODO: do we even need these validations?
|
|
943
972
|
async preflight(p, ctx) {
|
|
944
|
-
await
|
|
973
|
+
await wrapAs5(
|
|
945
974
|
"VALIDATION",
|
|
946
975
|
OP_DEPOSITS.ethNonBase.assertEthAsset,
|
|
947
976
|
() => {
|
|
@@ -951,7 +980,7 @@ function routeEthNonBase() {
|
|
|
951
980
|
},
|
|
952
981
|
{ ctx: { token: p.token } }
|
|
953
982
|
);
|
|
954
|
-
await
|
|
983
|
+
await wrapAs5(
|
|
955
984
|
"VALIDATION",
|
|
956
985
|
OP_DEPOSITS.ethNonBase.assertNonEthBase,
|
|
957
986
|
() => {
|
|
@@ -961,7 +990,7 @@ function routeEthNonBase() {
|
|
|
961
990
|
},
|
|
962
991
|
{ ctx: { baseIsEth: ctx.baseIsEth, chainIdL2: ctx.chainIdL2 } }
|
|
963
992
|
);
|
|
964
|
-
const ethBal = await
|
|
993
|
+
const ethBal = await wrapAs5(
|
|
965
994
|
"RPC",
|
|
966
995
|
OP_DEPOSITS.ethNonBase.ethBalance,
|
|
967
996
|
() => ctx.client.l1.getBalance({ address: ctx.sender }),
|
|
@@ -970,7 +999,7 @@ function routeEthNonBase() {
|
|
|
970
999
|
message: "Failed to read L1 ETH balance."
|
|
971
1000
|
}
|
|
972
1001
|
);
|
|
973
|
-
await
|
|
1002
|
+
await wrapAs5(
|
|
974
1003
|
"VALIDATION",
|
|
975
1004
|
OP_DEPOSITS.ethNonBase.assertEthBalance,
|
|
976
1005
|
() => {
|
|
@@ -1003,11 +1032,16 @@ function routeEthNonBase() {
|
|
|
1003
1032
|
undeployedGasLimit: priorityGasModel.undeployedGasLimit
|
|
1004
1033
|
});
|
|
1005
1034
|
if (!l2Gas) throw new Error("Failed to estimate L2 gas parameters.");
|
|
1006
|
-
const
|
|
1035
|
+
const l1Fees = await quoteL1Fees2({ ctx });
|
|
1036
|
+
const l2BaseCost = await quoteL2BaseCost({
|
|
1037
|
+
ctx,
|
|
1038
|
+
l2GasLimit: l2Gas.gasLimit,
|
|
1039
|
+
l1GasPrice: l1Fees.maxFeePerGas
|
|
1040
|
+
});
|
|
1007
1041
|
const mintValue = l2BaseCost + ctx.operatorTip;
|
|
1008
1042
|
const approvals = [];
|
|
1009
1043
|
const steps = [];
|
|
1010
|
-
const allowance = await
|
|
1044
|
+
const allowance = await wrapAs5(
|
|
1011
1045
|
"CONTRACT",
|
|
1012
1046
|
OP_DEPOSITS.ethNonBase.allowanceBase,
|
|
1013
1047
|
() => ctx.client.l1.readContract({
|
|
@@ -1023,7 +1057,7 @@ function routeEthNonBase() {
|
|
|
1023
1057
|
);
|
|
1024
1058
|
const needsApprove = allowance < mintValue;
|
|
1025
1059
|
if (needsApprove) {
|
|
1026
|
-
const approveTx = await
|
|
1060
|
+
const approveTx = await wrapAs5(
|
|
1027
1061
|
"CONTRACT",
|
|
1028
1062
|
OP_DEPOSITS.ethNonBase.estGas,
|
|
1029
1063
|
() => buildApprovalRequest({
|
|
@@ -1045,13 +1079,13 @@ function routeEthNonBase() {
|
|
|
1045
1079
|
tx: approveTx
|
|
1046
1080
|
});
|
|
1047
1081
|
}
|
|
1048
|
-
const secondBridgeCalldata = await
|
|
1082
|
+
const secondBridgeCalldata = await wrapAs5(
|
|
1049
1083
|
"INTERNAL",
|
|
1050
1084
|
OP_DEPOSITS.ethNonBase.encodeCalldata,
|
|
1051
|
-
() =>
|
|
1085
|
+
() => encodeSecondBridgeEthDepositCalldata({ ctx, amount: p.amount, receiver }),
|
|
1052
1086
|
{
|
|
1053
1087
|
ctx: {
|
|
1054
|
-
where: "
|
|
1088
|
+
where: "encodeSecondBridgeEthDepositCalldata",
|
|
1055
1089
|
amount: p.amount.toString(),
|
|
1056
1090
|
to: receiver
|
|
1057
1091
|
},
|
|
@@ -1087,7 +1121,7 @@ function routeEthNonBase() {
|
|
|
1087
1121
|
args: [requestStruct]
|
|
1088
1122
|
});
|
|
1089
1123
|
} else {
|
|
1090
|
-
const sim = await
|
|
1124
|
+
const sim = await wrapAs5(
|
|
1091
1125
|
"CONTRACT",
|
|
1092
1126
|
OP_DEPOSITS.ethNonBase.estGas,
|
|
1093
1127
|
() => ctx.client.l1.simulateContract({
|
|
@@ -1115,7 +1149,8 @@ function routeEthNonBase() {
|
|
|
1115
1149
|
data: calldata,
|
|
1116
1150
|
value: bridgehubValue,
|
|
1117
1151
|
from: ctx.sender,
|
|
1118
|
-
...ctx.gasOverrides
|
|
1152
|
+
...ctx.gasOverrides,
|
|
1153
|
+
...l1Fees
|
|
1119
1154
|
};
|
|
1120
1155
|
const l1Gas = await quoteL1Gas2({
|
|
1121
1156
|
ctx,
|
|
@@ -1123,14 +1158,11 @@ function routeEthNonBase() {
|
|
|
1123
1158
|
overrides: ctx.gasOverrides,
|
|
1124
1159
|
fallbackGasLimit: SAFE_L1_BRIDGE_GAS
|
|
1125
1160
|
});
|
|
1126
|
-
|
|
1127
|
-
bridgeTx
|
|
1128
|
-
|
|
1129
|
-
|
|
1130
|
-
|
|
1131
|
-
maxPriorityFeePerGas: l1Gas.maxPriorityFeePerGas
|
|
1132
|
-
};
|
|
1133
|
-
}
|
|
1161
|
+
bridgeTx = {
|
|
1162
|
+
...bridgeTx,
|
|
1163
|
+
...l1Fees,
|
|
1164
|
+
...l1Gas ? { gas: l1Gas.gasLimit } : {}
|
|
1165
|
+
};
|
|
1134
1166
|
steps.push({
|
|
1135
1167
|
key: "bridgehub:two-bridges:eth-nonbase",
|
|
1136
1168
|
kind: "bridgehub:two-bridges",
|
|
@@ -1153,12 +1185,12 @@ function routeEthNonBase() {
|
|
|
1153
1185
|
}
|
|
1154
1186
|
};
|
|
1155
1187
|
}
|
|
1156
|
-
var { wrapAs:
|
|
1188
|
+
var { wrapAs: wrapAs6 } = createErrorHandlers("deposits");
|
|
1157
1189
|
var EMPTY_BYTES3 = "0x";
|
|
1158
1190
|
function routeErc20Base() {
|
|
1159
1191
|
return {
|
|
1160
1192
|
async preflight(p, ctx) {
|
|
1161
|
-
await
|
|
1193
|
+
await wrapAs6(
|
|
1162
1194
|
"VALIDATION",
|
|
1163
1195
|
OP_DEPOSITS.base.assertErc20Asset,
|
|
1164
1196
|
() => {
|
|
@@ -1169,7 +1201,7 @@ function routeErc20Base() {
|
|
|
1169
1201
|
{ ctx: { token: p.token } }
|
|
1170
1202
|
);
|
|
1171
1203
|
const baseToken = ctx.baseTokenL1 ?? await ctx.client.baseToken(ctx.chainIdL2);
|
|
1172
|
-
await
|
|
1204
|
+
await wrapAs6(
|
|
1173
1205
|
"VALIDATION",
|
|
1174
1206
|
OP_DEPOSITS.base.assertMatchesBase,
|
|
1175
1207
|
() => {
|
|
@@ -1206,11 +1238,16 @@ function routeErc20Base() {
|
|
|
1206
1238
|
overrideGasLimit: quotedL2GasLimit
|
|
1207
1239
|
});
|
|
1208
1240
|
if (!l2Gas) throw new Error("Failed to estimate L2 gas parameters.");
|
|
1209
|
-
const
|
|
1241
|
+
const l1Fees = await quoteL1Fees2({ ctx });
|
|
1242
|
+
const l2BaseCost = await quoteL2BaseCost({
|
|
1243
|
+
ctx,
|
|
1244
|
+
l2GasLimit: l2Gas.gasLimit,
|
|
1245
|
+
l1GasPrice: l1Fees.maxFeePerGas
|
|
1246
|
+
});
|
|
1210
1247
|
const mintValue = l2BaseCost + ctx.operatorTip + p.amount;
|
|
1211
1248
|
const approvals = [];
|
|
1212
1249
|
const steps = [];
|
|
1213
|
-
const allowance = await
|
|
1250
|
+
const allowance = await wrapAs6(
|
|
1214
1251
|
"CONTRACT",
|
|
1215
1252
|
OP_DEPOSITS.base.allowance,
|
|
1216
1253
|
() => ctx.client.l1.readContract({
|
|
@@ -1226,7 +1263,7 @@ function routeErc20Base() {
|
|
|
1226
1263
|
);
|
|
1227
1264
|
const needsApprove = allowance < mintValue;
|
|
1228
1265
|
if (needsApprove) {
|
|
1229
|
-
const approveTx = await
|
|
1266
|
+
const approveTx = await wrapAs6(
|
|
1230
1267
|
"CONTRACT",
|
|
1231
1268
|
OP_DEPOSITS.base.estGas,
|
|
1232
1269
|
() => buildApprovalRequest({
|
|
@@ -1275,7 +1312,7 @@ function routeErc20Base() {
|
|
|
1275
1312
|
args: [req]
|
|
1276
1313
|
});
|
|
1277
1314
|
} else {
|
|
1278
|
-
const sim = await
|
|
1315
|
+
const sim = await wrapAs6(
|
|
1279
1316
|
"RPC",
|
|
1280
1317
|
OP_DEPOSITS.base.estGas,
|
|
1281
1318
|
() => ctx.client.l1.simulateContract({
|
|
@@ -1303,7 +1340,8 @@ function routeErc20Base() {
|
|
|
1303
1340
|
data: calldata,
|
|
1304
1341
|
value: 0n,
|
|
1305
1342
|
from: ctx.sender,
|
|
1306
|
-
...ctx.gasOverrides
|
|
1343
|
+
...ctx.gasOverrides,
|
|
1344
|
+
...l1Fees
|
|
1307
1345
|
};
|
|
1308
1346
|
const l1Gas = await quoteL1Gas2({
|
|
1309
1347
|
ctx,
|
|
@@ -1311,14 +1349,11 @@ function routeErc20Base() {
|
|
|
1311
1349
|
overrides: ctx.gasOverrides,
|
|
1312
1350
|
fallbackGasLimit: SAFE_L1_BRIDGE_GAS
|
|
1313
1351
|
});
|
|
1314
|
-
|
|
1315
|
-
bridgeTx
|
|
1316
|
-
|
|
1317
|
-
|
|
1318
|
-
|
|
1319
|
-
maxPriorityFeePerGas: l1Gas.maxPriorityFeePerGas
|
|
1320
|
-
};
|
|
1321
|
-
}
|
|
1352
|
+
bridgeTx = {
|
|
1353
|
+
...bridgeTx,
|
|
1354
|
+
...l1Fees,
|
|
1355
|
+
...l1Gas ? { gas: l1Gas.gasLimit } : {}
|
|
1356
|
+
};
|
|
1322
1357
|
steps.push({
|
|
1323
1358
|
key: "bridgehub:direct:erc20-base",
|
|
1324
1359
|
kind: "bridgehub:direct",
|
|
@@ -1416,7 +1451,7 @@ async function waitForL2ExecutionFromL1Tx(l1, l2, l1TxHash) {
|
|
|
1416
1451
|
}
|
|
1417
1452
|
return { l2Receipt, l2TxHash };
|
|
1418
1453
|
}
|
|
1419
|
-
var { wrapAs:
|
|
1454
|
+
var { wrapAs: wrapAs7 } = createErrorHandlers("tokens");
|
|
1420
1455
|
var ntvCodec3 = createNTVCodec({
|
|
1421
1456
|
encode: (types, values) => encodeAbiParameters(
|
|
1422
1457
|
types.map((t, i) => ({ type: t, name: `arg${i}` })),
|
|
@@ -1431,7 +1466,7 @@ function createTokensResource(client) {
|
|
|
1431
1466
|
let wethL2Promise = null;
|
|
1432
1467
|
async function getL1ChainId() {
|
|
1433
1468
|
if (!l2NtvL1ChainIdPromise) {
|
|
1434
|
-
l2NtvL1ChainIdPromise =
|
|
1469
|
+
l2NtvL1ChainIdPromise = wrapAs7("INTERNAL", "getL1ChainId", async () => {
|
|
1435
1470
|
const { l2NativeTokenVault } = await client.contracts();
|
|
1436
1471
|
return await l2NativeTokenVault.read.L1_CHAIN_ID();
|
|
1437
1472
|
});
|
|
@@ -1440,7 +1475,7 @@ function createTokensResource(client) {
|
|
|
1440
1475
|
}
|
|
1441
1476
|
async function getBaseTokenAssetId() {
|
|
1442
1477
|
if (!baseTokenAssetIdPromise) {
|
|
1443
|
-
baseTokenAssetIdPromise =
|
|
1478
|
+
baseTokenAssetIdPromise = wrapAs7("INTERNAL", "baseTokenAssetId", async () => {
|
|
1444
1479
|
const { l2NativeTokenVault } = await client.contracts();
|
|
1445
1480
|
const assetId = await l2NativeTokenVault.read.BASE_TOKEN_ASSET_ID();
|
|
1446
1481
|
return assetId;
|
|
@@ -1450,7 +1485,7 @@ function createTokensResource(client) {
|
|
|
1450
1485
|
}
|
|
1451
1486
|
async function getWethL1() {
|
|
1452
1487
|
if (!wethL1Promise) {
|
|
1453
|
-
wethL1Promise =
|
|
1488
|
+
wethL1Promise = wrapAs7("INTERNAL", "wethL1", async () => {
|
|
1454
1489
|
const { l1NativeTokenVault } = await client.contracts();
|
|
1455
1490
|
const weth = await l1NativeTokenVault.read.WETH_TOKEN();
|
|
1456
1491
|
return weth;
|
|
@@ -1460,7 +1495,7 @@ function createTokensResource(client) {
|
|
|
1460
1495
|
}
|
|
1461
1496
|
async function getWethL2() {
|
|
1462
1497
|
if (!wethL2Promise) {
|
|
1463
|
-
wethL2Promise =
|
|
1498
|
+
wethL2Promise = wrapAs7("INTERNAL", "wethL2", async () => {
|
|
1464
1499
|
const { l2NativeTokenVault } = await client.contracts();
|
|
1465
1500
|
const weth = await l2NativeTokenVault.read.WETH_TOKEN();
|
|
1466
1501
|
return weth;
|
|
@@ -1469,7 +1504,7 @@ function createTokensResource(client) {
|
|
|
1469
1504
|
return wethL2Promise;
|
|
1470
1505
|
}
|
|
1471
1506
|
async function toL2Address(l1Token) {
|
|
1472
|
-
return
|
|
1507
|
+
return wrapAs7("CONTRACT", "tokens.toL2Address", async () => {
|
|
1473
1508
|
const normalized = normalizeL1Token(l1Token);
|
|
1474
1509
|
const chainId = BigInt(await client.l2.getChainId());
|
|
1475
1510
|
const baseToken = await client.baseToken(chainId);
|
|
@@ -1482,7 +1517,7 @@ function createTokensResource(client) {
|
|
|
1482
1517
|
});
|
|
1483
1518
|
}
|
|
1484
1519
|
async function toL1Address(l2Token) {
|
|
1485
|
-
return
|
|
1520
|
+
return wrapAs7("CONTRACT", "tokens.toL1Address", async () => {
|
|
1486
1521
|
if (isAddressEq(l2Token, ETH_ADDRESS)) return ETH_ADDRESS;
|
|
1487
1522
|
if (isAddressEq(l2Token, L2_BASE_TOKEN_ADDRESS)) {
|
|
1488
1523
|
const chainId = BigInt(await client.l2.getChainId());
|
|
@@ -1503,32 +1538,32 @@ function createTokensResource(client) {
|
|
|
1503
1538
|
});
|
|
1504
1539
|
}
|
|
1505
1540
|
async function assetIdOfL1(l1Token) {
|
|
1506
|
-
return
|
|
1541
|
+
return wrapAs7("CONTRACT", "tokens.assetIdOfL1", async () => {
|
|
1507
1542
|
const normalized = normalizeL1Token(l1Token);
|
|
1508
1543
|
const { l1NativeTokenVault } = await client.contracts();
|
|
1509
1544
|
return await l1NativeTokenVault.read.assetId([normalized]);
|
|
1510
1545
|
});
|
|
1511
1546
|
}
|
|
1512
1547
|
async function assetIdOfL2(l2Token) {
|
|
1513
|
-
return
|
|
1548
|
+
return wrapAs7("CONTRACT", "tokens.assetIdOfL2", async () => {
|
|
1514
1549
|
const { l2NativeTokenVault } = await client.contracts();
|
|
1515
1550
|
return await l2NativeTokenVault.read.assetId([l2Token]);
|
|
1516
1551
|
});
|
|
1517
1552
|
}
|
|
1518
1553
|
async function l2TokenFromAssetId(assetId) {
|
|
1519
|
-
return
|
|
1554
|
+
return wrapAs7("CONTRACT", "tokens.l2TokenFromAssetId", async () => {
|
|
1520
1555
|
const { l2NativeTokenVault } = await client.contracts();
|
|
1521
1556
|
return await l2NativeTokenVault.read.tokenAddress([assetId]);
|
|
1522
1557
|
});
|
|
1523
1558
|
}
|
|
1524
1559
|
async function l1TokenFromAssetId(assetId) {
|
|
1525
|
-
return
|
|
1560
|
+
return wrapAs7("CONTRACT", "tokens.l1TokenFromAssetId", async () => {
|
|
1526
1561
|
const { l1NativeTokenVault } = await client.contracts();
|
|
1527
1562
|
return await l1NativeTokenVault.read.tokenAddress([assetId]);
|
|
1528
1563
|
});
|
|
1529
1564
|
}
|
|
1530
1565
|
async function originChainId(assetId) {
|
|
1531
|
-
return
|
|
1566
|
+
return wrapAs7("CONTRACT", "tokens.originChainId", async () => {
|
|
1532
1567
|
const { l2NativeTokenVault } = await client.contracts();
|
|
1533
1568
|
return await l2NativeTokenVault.read.originChainId([assetId]);
|
|
1534
1569
|
});
|
|
@@ -1537,7 +1572,7 @@ function createTokensResource(client) {
|
|
|
1537
1572
|
return getBaseTokenAssetId();
|
|
1538
1573
|
}
|
|
1539
1574
|
async function isChainEthBased() {
|
|
1540
|
-
return
|
|
1575
|
+
return wrapAs7("CONTRACT", "tokens.isChainEthBased", async () => {
|
|
1541
1576
|
const baseAssetId = await getBaseTokenAssetId();
|
|
1542
1577
|
const l1ChainId = await getL1ChainId();
|
|
1543
1578
|
const ethAssetId = ntvCodec3.encodeAssetId(
|
|
@@ -1555,7 +1590,7 @@ function createTokensResource(client) {
|
|
|
1555
1590
|
return getWethL2();
|
|
1556
1591
|
}
|
|
1557
1592
|
async function computeL2BridgedAddress(args) {
|
|
1558
|
-
return
|
|
1593
|
+
return wrapAs7("CONTRACT", "tokens.computeL2BridgedAddress", async () => {
|
|
1559
1594
|
const normalized = normalizeL1Token(args.l1Token);
|
|
1560
1595
|
const { l2NativeTokenVault } = await client.contracts();
|
|
1561
1596
|
const predicted = await l2NativeTokenVault.read.calculateCreate2TokenAddress([
|
|
@@ -1566,7 +1601,7 @@ function createTokensResource(client) {
|
|
|
1566
1601
|
});
|
|
1567
1602
|
}
|
|
1568
1603
|
async function resolve(ref, opts) {
|
|
1569
|
-
return
|
|
1604
|
+
return wrapAs7("CONTRACT", "tokens.resolve", async () => {
|
|
1570
1605
|
let chain;
|
|
1571
1606
|
let address;
|
|
1572
1607
|
if (typeof ref === "string") {
|
|
@@ -2080,12 +2115,12 @@ function buildFeeBreakdown2(p) {
|
|
|
2080
2115
|
}
|
|
2081
2116
|
|
|
2082
2117
|
// src/adapters/viem/resources/withdrawals/routes/eth.ts
|
|
2083
|
-
var { wrapAs:
|
|
2118
|
+
var { wrapAs: wrapAs8 } = createErrorHandlers("withdrawals");
|
|
2084
2119
|
function routeEthBase() {
|
|
2085
2120
|
return {
|
|
2086
2121
|
async build(p, ctx) {
|
|
2087
2122
|
const steps = [];
|
|
2088
|
-
const data = await
|
|
2123
|
+
const data = await wrapAs8(
|
|
2089
2124
|
"INTERNAL",
|
|
2090
2125
|
OP_WITHDRAWALS.eth.encodeWithdraw,
|
|
2091
2126
|
() => Promise.resolve(
|
|
@@ -2135,14 +2170,14 @@ function routeEthBase() {
|
|
|
2135
2170
|
}
|
|
2136
2171
|
};
|
|
2137
2172
|
}
|
|
2138
|
-
var { wrapAs:
|
|
2173
|
+
var { wrapAs: wrapAs9 } = createErrorHandlers("withdrawals");
|
|
2139
2174
|
function routeErc20NonBase2() {
|
|
2140
2175
|
return {
|
|
2141
2176
|
// TODO: add preflight validations here
|
|
2142
2177
|
async build(p, ctx) {
|
|
2143
2178
|
const steps = [];
|
|
2144
2179
|
const approvals = [];
|
|
2145
|
-
const current = await
|
|
2180
|
+
const current = await wrapAs9(
|
|
2146
2181
|
"CONTRACT",
|
|
2147
2182
|
OP_WITHDRAWALS.erc20.allowance,
|
|
2148
2183
|
() => ctx.client.l2.readContract({
|
|
@@ -2181,7 +2216,7 @@ function routeErc20NonBase2() {
|
|
|
2181
2216
|
approveTxCandidate.maxFeePerGas = approveGas.maxFeePerGas;
|
|
2182
2217
|
approveTxCandidate.maxPriorityFeePerGas = approveGas.maxPriorityFeePerGas;
|
|
2183
2218
|
}
|
|
2184
|
-
const approveSim = await
|
|
2219
|
+
const approveSim = await wrapAs9(
|
|
2185
2220
|
"CONTRACT",
|
|
2186
2221
|
OP_WITHDRAWALS.erc20.estGas,
|
|
2187
2222
|
() => ctx.client.l2.simulateContract({
|
|
@@ -2208,7 +2243,7 @@ function routeErc20NonBase2() {
|
|
|
2208
2243
|
tx: approveTx
|
|
2209
2244
|
});
|
|
2210
2245
|
}
|
|
2211
|
-
const assetId = (await
|
|
2246
|
+
const assetId = (await wrapAs9(
|
|
2212
2247
|
"CONTRACT",
|
|
2213
2248
|
OP_WITHDRAWALS.erc20.ensureRegistered,
|
|
2214
2249
|
() => ctx.client.l2.simulateContract({
|
|
@@ -2259,7 +2294,7 @@ function routeErc20NonBase2() {
|
|
|
2259
2294
|
...withdrawGas
|
|
2260
2295
|
};
|
|
2261
2296
|
} else {
|
|
2262
|
-
const sim = await
|
|
2297
|
+
const sim = await wrapAs9(
|
|
2263
2298
|
"CONTRACT",
|
|
2264
2299
|
OP_WITHDRAWALS.erc20.estGas,
|
|
2265
2300
|
() => ctx.client.l2.simulateContract({
|
|
@@ -2354,7 +2389,7 @@ function createViemAttributesResource() {
|
|
|
2354
2389
|
}
|
|
2355
2390
|
|
|
2356
2391
|
// src/adapters/viem/resources/withdrawals/routes/interop-bundle.ts
|
|
2357
|
-
var { wrapAs:
|
|
2392
|
+
var { wrapAs: wrapAs10 } = createErrorHandlers("withdrawals");
|
|
2358
2393
|
var attributes = createViemAttributesResource();
|
|
2359
2394
|
function saltFor(sender, nonce) {
|
|
2360
2395
|
return keccak256(
|
|
@@ -2379,7 +2414,7 @@ function routeInteropBundle() {
|
|
|
2379
2414
|
if (isBaseToken) {
|
|
2380
2415
|
assetId = ctx.baseTokenAssetId;
|
|
2381
2416
|
} else {
|
|
2382
|
-
assetId = (await
|
|
2417
|
+
assetId = (await wrapAs10(
|
|
2383
2418
|
"CONTRACT",
|
|
2384
2419
|
OP_WITHDRAWALS.erc20.ensureRegistered,
|
|
2385
2420
|
() => ctx.client.l2.simulateContract({
|
|
@@ -2394,7 +2429,7 @@ function routeInteropBundle() {
|
|
|
2394
2429
|
message: "Failed to ensure token is registered in L2NativeTokenVault."
|
|
2395
2430
|
}
|
|
2396
2431
|
)).result;
|
|
2397
|
-
const current = await
|
|
2432
|
+
const current = await wrapAs10(
|
|
2398
2433
|
"CONTRACT",
|
|
2399
2434
|
OP_WITHDRAWALS.erc20.allowance,
|
|
2400
2435
|
() => ctx.client.l2.readContract({
|
|
@@ -2443,7 +2478,7 @@ function routeInteropBundle() {
|
|
|
2443
2478
|
});
|
|
2444
2479
|
}
|
|
2445
2480
|
}
|
|
2446
|
-
const nonce = await
|
|
2481
|
+
const nonce = await wrapAs10(
|
|
2447
2482
|
"RPC",
|
|
2448
2483
|
OP_WITHDRAWALS.prepare,
|
|
2449
2484
|
() => ctx.client.l2.getTransactionCount({ address: ctx.sender, blockTag: "pending" }),
|
|
@@ -2549,7 +2584,7 @@ function createWithdrawalProtocolService(client, override) {
|
|
|
2549
2584
|
}
|
|
2550
2585
|
};
|
|
2551
2586
|
}
|
|
2552
|
-
var { wrapAs:
|
|
2587
|
+
var { wrapAs: wrapAs11 } = createErrorHandlers("withdrawals");
|
|
2553
2588
|
var IL1NullifierMini = [
|
|
2554
2589
|
{
|
|
2555
2590
|
type: "function",
|
|
@@ -2567,7 +2602,7 @@ function createFinalizationServices(client, protocolService = createWithdrawalPr
|
|
|
2567
2602
|
async function finalizationTarget(protocol) {
|
|
2568
2603
|
const { l1Nullifier } = await client.ensureAddresses();
|
|
2569
2604
|
if (protocol === "legacy-withdrawal") return l1Nullifier;
|
|
2570
|
-
return await
|
|
2605
|
+
return await wrapAs11(
|
|
2571
2606
|
"CONTRACT",
|
|
2572
2607
|
OP_WITHDRAWALS.finalize.fetchParams.receipt,
|
|
2573
2608
|
() => client.l1.readContract({
|
|
@@ -2582,7 +2617,7 @@ function createFinalizationServices(client, protocolService = createWithdrawalPr
|
|
|
2582
2617
|
);
|
|
2583
2618
|
}
|
|
2584
2619
|
async function fetchMessageAndProof(l2TxHash) {
|
|
2585
|
-
const raw = await
|
|
2620
|
+
const raw = await wrapAs11(
|
|
2586
2621
|
"RPC",
|
|
2587
2622
|
OP_WITHDRAWALS.finalize.fetchParams.receipt,
|
|
2588
2623
|
() => client.zks.getReceiptWithL2ToL1(l2TxHash),
|
|
@@ -2599,7 +2634,7 @@ function createFinalizationServices(client, protocolService = createWithdrawalPr
|
|
|
2599
2634
|
context: { l2TxHash }
|
|
2600
2635
|
});
|
|
2601
2636
|
}
|
|
2602
|
-
const ev = await
|
|
2637
|
+
const ev = await wrapAs11(
|
|
2603
2638
|
"INTERNAL",
|
|
2604
2639
|
OP_WITHDRAWALS.finalize.fetchParams.findMessage,
|
|
2605
2640
|
// eslint-disable-next-line @typescript-eslint/no-unsafe-argument, @typescript-eslint/no-explicit-any
|
|
@@ -2609,7 +2644,7 @@ function createFinalizationServices(client, protocolService = createWithdrawalPr
|
|
|
2609
2644
|
message: "Failed to locate L1MessageSent event in L2 receipt."
|
|
2610
2645
|
}
|
|
2611
2646
|
);
|
|
2612
|
-
const message = await
|
|
2647
|
+
const message = await wrapAs11(
|
|
2613
2648
|
"INTERNAL",
|
|
2614
2649
|
OP_WITHDRAWALS.finalize.fetchParams.decodeMessage,
|
|
2615
2650
|
() => {
|
|
@@ -2621,7 +2656,7 @@ function createFinalizationServices(client, protocolService = createWithdrawalPr
|
|
|
2621
2656
|
message: "Failed to decode withdrawal message."
|
|
2622
2657
|
}
|
|
2623
2658
|
);
|
|
2624
|
-
const idx = await
|
|
2659
|
+
const idx = await wrapAs11(
|
|
2625
2660
|
"INTERNAL",
|
|
2626
2661
|
OP_WITHDRAWALS.finalize.fetchParams.messengerIndex,
|
|
2627
2662
|
() => Promise.resolve(messengerLogIndex(raw, { index: 0, messenger: L1_MESSENGER_ADDRESS })),
|
|
@@ -2630,7 +2665,7 @@ function createFinalizationServices(client, protocolService = createWithdrawalPr
|
|
|
2630
2665
|
message: "Failed to derive messenger log index."
|
|
2631
2666
|
}
|
|
2632
2667
|
);
|
|
2633
|
-
const proof = await
|
|
2668
|
+
const proof = await wrapAs11(
|
|
2634
2669
|
"RPC",
|
|
2635
2670
|
OP_WITHDRAWALS.finalize.fetchParams.proof,
|
|
2636
2671
|
() => client.zks.getL2ToL1LogProof(l2TxHash, idx),
|
|
@@ -2639,7 +2674,7 @@ function createFinalizationServices(client, protocolService = createWithdrawalPr
|
|
|
2639
2674
|
message: "Failed to fetch L2\u2192L1 log proof."
|
|
2640
2675
|
}
|
|
2641
2676
|
);
|
|
2642
|
-
const chainId = await
|
|
2677
|
+
const chainId = await wrapAs11(
|
|
2643
2678
|
"RPC",
|
|
2644
2679
|
OP_WITHDRAWALS.finalize.fetchParams.network,
|
|
2645
2680
|
() => client.l2.getChainId(),
|
|
@@ -2697,7 +2732,7 @@ function createFinalizationServices(client, protocolService = createWithdrawalPr
|
|
|
2697
2732
|
async function withdrawalOutcome(finalization) {
|
|
2698
2733
|
const target = await finalizationTarget(finalization.protocol);
|
|
2699
2734
|
if (finalization.protocol === "legacy-withdrawal") {
|
|
2700
|
-
const done = await
|
|
2735
|
+
const done = await wrapAs11(
|
|
2701
2736
|
"RPC",
|
|
2702
2737
|
OP_WITHDRAWALS.finalize.isFinalized,
|
|
2703
2738
|
() => client.l1.readContract({
|
|
@@ -2719,7 +2754,7 @@ function createFinalizationServices(client, protocolService = createWithdrawalPr
|
|
|
2719
2754
|
}
|
|
2720
2755
|
const { bundleHash } = finalization.params;
|
|
2721
2756
|
const status = Number(
|
|
2722
|
-
await
|
|
2757
|
+
await wrapAs11(
|
|
2723
2758
|
"RPC",
|
|
2724
2759
|
OP_WITHDRAWALS.finalize.isFinalized,
|
|
2725
2760
|
() => client.l1.readContract({
|
|
@@ -2736,7 +2771,7 @@ function createFinalizationServices(client, protocolService = createWithdrawalPr
|
|
|
2736
2771
|
);
|
|
2737
2772
|
if (status !== 3 /* Unbundled */) return classifyWithdrawalOutcome(status);
|
|
2738
2773
|
const callStatus = Number(
|
|
2739
|
-
await
|
|
2774
|
+
await wrapAs11(
|
|
2740
2775
|
"RPC",
|
|
2741
2776
|
OP_WITHDRAWALS.finalize.isFinalized,
|
|
2742
2777
|
() => client.l1.readContract({
|
|
@@ -2807,7 +2842,7 @@ function createFinalizationServices(client, protocolService = createWithdrawalPr
|
|
|
2807
2842
|
},
|
|
2808
2843
|
async estimateFinalization(finalization) {
|
|
2809
2844
|
const target = await finalizationTarget(finalization.protocol);
|
|
2810
|
-
const gasLimit = await
|
|
2845
|
+
const gasLimit = await wrapAs11(
|
|
2811
2846
|
"RPC",
|
|
2812
2847
|
OP_WITHDRAWALS.finalize.estimate,
|
|
2813
2848
|
() => finalization.protocol === "legacy-withdrawal" ? client.l1.estimateContractGas({
|
|
@@ -2835,7 +2870,7 @@ function createFinalizationServices(client, protocolService = createWithdrawalPr
|
|
|
2835
2870
|
let maxFeePerGas;
|
|
2836
2871
|
let maxPriorityFeePerGas;
|
|
2837
2872
|
try {
|
|
2838
|
-
const fee = await
|
|
2873
|
+
const fee = await wrapAs11(
|
|
2839
2874
|
"RPC",
|
|
2840
2875
|
OP_WITHDRAWALS.finalize.estimate,
|
|
2841
2876
|
() => client.l1.estimateFeesPerGas(),
|
|
@@ -2854,7 +2889,7 @@ function createFinalizationServices(client, protocolService = createWithdrawalPr
|
|
|
2854
2889
|
})();
|
|
2855
2890
|
maxPriorityFeePerGas = fee.maxPriorityFeePerGas ?? 0n;
|
|
2856
2891
|
} catch {
|
|
2857
|
-
const gasPrice = await
|
|
2892
|
+
const gasPrice = await wrapAs11(
|
|
2858
2893
|
"RPC",
|
|
2859
2894
|
OP_WITHDRAWALS.finalize.estimate,
|
|
2860
2895
|
() => client.l1.getGasPrice(),
|