@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
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { createErrorHandlers, toZKsyncError, classifyReadinessFromRevert } from './chunk-RZH7HBH3.js';
|
|
2
|
-
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, quoteL2BaseCost, quoteL1Gas, applyL1ToL2Alias, derivePriorityBodyGasEstimateCap, assertProtocolVersion, resolveRegisteredTokenPriorityL2GasLimit, quoteL2Gas2 } from './chunk-
|
|
2
|
+
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, quoteL2BaseCost, quoteL1Gas, applyL1ToL2Alias, derivePriorityBodyGasEstimateCap, assertProtocolVersion, resolveRegisteredTokenPriorityL2GasLimit, quoteL2Gas2 } from './chunk-JWN26CQ6.js';
|
|
3
3
|
import { detectWithdrawalProtocol, buildWithdrawalFinalization, parseBundleHashFromLogs, classifyWithdrawalOutcome, phaseFromReadiness, buildWithdrawalBundle } from './chunk-BQ2YCWV2.js';
|
|
4
4
|
import { findL1MessageSentLog, messengerLogIndex, l1MessageSentSender, pickWithdrawRoute } from './chunk-OEUDZFXH.js';
|
|
5
5
|
import { IERC7786Attributes_default, isHash66, IL1Nullifier_default, IInteropHandler_default, createError, OP_WITHDRAWALS, normalizeL1Token, isAddressEq, hexEq, OP_DEPOSITS, IERC20_default, isZKsyncError, isReceiptNotFound, IL1NullifierV32_default, OP_INTEROP, IInteropRootStorage_default, IInteropCenter_default, sleep, isETH, normalizeAddrEq, IL2AssetRouter_default, L2NativeTokenVault_default, assertNever } from './chunk-JNS4XZE2.js';
|
|
@@ -154,8 +154,9 @@ function toCoreTx(tx) {
|
|
|
154
154
|
data: tx.data,
|
|
155
155
|
value: tx.value ? BigInt(tx.value) : void 0,
|
|
156
156
|
gasLimit: tx.gasLimit ? BigInt(tx.gasLimit) : void 0,
|
|
157
|
-
|
|
158
|
-
|
|
157
|
+
// zero fees are explicit on zero-base-fee chains; dropping them would re-fetch the market tip
|
|
158
|
+
maxFeePerGas: tx.maxFeePerGas != null ? BigInt(tx.maxFeePerGas) : void 0,
|
|
159
|
+
maxPriorityFeePerGas: tx.maxPriorityFeePerGas != null ? BigInt(tx.maxPriorityFeePerGas) : void 0
|
|
159
160
|
};
|
|
160
161
|
}
|
|
161
162
|
function ethersToGasEstimator(provider) {
|
|
@@ -230,7 +231,7 @@ var encode = (abi2, fn, args) => {
|
|
|
230
231
|
return new Interface(abi2).encodeFunctionData(fn, args);
|
|
231
232
|
};
|
|
232
233
|
async function quoteL2BaseCost2(input) {
|
|
233
|
-
const { ctx, l2GasLimit } = input;
|
|
234
|
+
const { ctx, l2GasLimit, l1GasPrice } = input;
|
|
234
235
|
const estimator = ethersToGasEstimator(ctx.client.l1);
|
|
235
236
|
return wrapAs(
|
|
236
237
|
"RPC",
|
|
@@ -241,13 +242,15 @@ async function quoteL2BaseCost2(input) {
|
|
|
241
242
|
bridgehub: ctx.bridgehub,
|
|
242
243
|
chainIdL2: ctx.chainIdL2,
|
|
243
244
|
l2GasLimit,
|
|
244
|
-
gasPerPubdata: ctx.gasPerPubdata
|
|
245
|
+
gasPerPubdata: ctx.gasPerPubdata,
|
|
246
|
+
l1GasPrice
|
|
245
247
|
}),
|
|
246
248
|
{ ctx: { chainIdL2: ctx.chainIdL2 } }
|
|
247
249
|
);
|
|
248
250
|
}
|
|
249
251
|
|
|
250
252
|
// src/adapters/ethers/resources/deposits/services/gas.ts
|
|
253
|
+
var { wrapAs: wrapAs2 } = createErrorHandlers("deposits");
|
|
251
254
|
var DEFAULT_SAFE_NONBASE_L2_GAS_LIMIT = 3000000n;
|
|
252
255
|
var ZERO_L2_TOKEN_ADDRESS = "0x0000000000000000000000000000000000000000";
|
|
253
256
|
async function estimatePriorityTxL2Gas(ctx, leg) {
|
|
@@ -258,6 +261,18 @@ async function estimatePriorityTxL2Gas(ctx, leg) {
|
|
|
258
261
|
return void 0;
|
|
259
262
|
}
|
|
260
263
|
}
|
|
264
|
+
async function quoteL1Fees2(input) {
|
|
265
|
+
const { ctx } = input;
|
|
266
|
+
return wrapAs2(
|
|
267
|
+
"RPC",
|
|
268
|
+
"deposits.fees.l1",
|
|
269
|
+
() => quoteL1Fees({
|
|
270
|
+
estimator: ethersToGasEstimator(ctx.client.l1),
|
|
271
|
+
overrides: ctx.gasOverrides
|
|
272
|
+
}),
|
|
273
|
+
{ ctx: { chainIdL2: ctx.chainIdL2 } }
|
|
274
|
+
);
|
|
275
|
+
}
|
|
261
276
|
async function quoteL1Gas2(input) {
|
|
262
277
|
const { ctx, tx, overrides, fallbackGasLimit } = input;
|
|
263
278
|
const estimator = ethersToGasEstimator(ctx.client.l1);
|
|
@@ -429,7 +444,12 @@ function routeEthDirect() {
|
|
|
429
444
|
if (!l2GasParams) {
|
|
430
445
|
throw new Error("Failed to estimate L2 gas for deposit.");
|
|
431
446
|
}
|
|
432
|
-
const
|
|
447
|
+
const l1Fees = await quoteL1Fees2({ ctx });
|
|
448
|
+
const baseCost = await quoteL2BaseCost2({
|
|
449
|
+
ctx,
|
|
450
|
+
l2GasLimit: l2GasParams.gasLimit,
|
|
451
|
+
l1GasPrice: l1Fees.maxFeePerGas
|
|
452
|
+
});
|
|
433
453
|
const mintValue = baseCost + ctx.operatorTip + l2Value;
|
|
434
454
|
const req = buildDirectRequestStruct({
|
|
435
455
|
chainId: ctx.chainIdL2,
|
|
@@ -446,7 +466,8 @@ function routeEthDirect() {
|
|
|
446
466
|
data,
|
|
447
467
|
value: mintValue,
|
|
448
468
|
from: ctx.sender,
|
|
449
|
-
...ctx.gasOverrides
|
|
469
|
+
...ctx.gasOverrides,
|
|
470
|
+
...l1Fees
|
|
450
471
|
};
|
|
451
472
|
const l1GasParams = await quoteL1Gas2({
|
|
452
473
|
ctx,
|
|
@@ -482,7 +503,7 @@ function routeEthDirect() {
|
|
|
482
503
|
}
|
|
483
504
|
};
|
|
484
505
|
}
|
|
485
|
-
var { wrapAs:
|
|
506
|
+
var { wrapAs: wrapAs3 } = createErrorHandlers("deposits");
|
|
486
507
|
var ZERO_L2_TOKEN_ADDRESS2 = "0x0000000000000000000000000000000000000000";
|
|
487
508
|
var ZERO_ASSET_ID = "0x0000000000000000000000000000000000000000000000000000000000000000";
|
|
488
509
|
var ntvCodec = createNTVCodec({
|
|
@@ -565,7 +586,7 @@ function routeErc20NonBase() {
|
|
|
565
586
|
async preflight(p, ctx) {
|
|
566
587
|
const resolved = ctx.resolvedToken ?? (ctx.tokens ? await ctx.tokens.resolve(p.token, { chain: "l1" }) : void 0);
|
|
567
588
|
const baseToken = ctx.baseTokenL1 ?? await ctx.client.baseToken(ctx.chainIdL2);
|
|
568
|
-
await
|
|
589
|
+
await wrapAs3(
|
|
569
590
|
"VALIDATION",
|
|
570
591
|
OP_DEPOSITS.nonbase.assertNonBaseToken,
|
|
571
592
|
() => {
|
|
@@ -581,7 +602,7 @@ function routeErc20NonBase() {
|
|
|
581
602
|
const baseToken = ctx.baseTokenL1 ?? await ctx.client.baseToken(ctx.chainIdL2);
|
|
582
603
|
const baseIsEth = ctx.baseIsEth ?? isETH(baseToken);
|
|
583
604
|
const receiver = p.to ?? ctx.sender;
|
|
584
|
-
const secondBridgeCalldata = await
|
|
605
|
+
const secondBridgeCalldata = await wrapAs3(
|
|
585
606
|
"INTERNAL",
|
|
586
607
|
OP_DEPOSITS.nonbase.encodeCalldata,
|
|
587
608
|
() => encodeSecondBridgeErc20DepositCalldata({
|
|
@@ -615,14 +636,19 @@ function routeErc20NonBase() {
|
|
|
615
636
|
}
|
|
616
637
|
});
|
|
617
638
|
if (!l2GasParams) throw new Error("Failed to establish L2 gas parameters.");
|
|
618
|
-
const
|
|
639
|
+
const l1Fees = await quoteL1Fees2({ ctx });
|
|
640
|
+
const baseCost = await quoteL2BaseCost2({
|
|
641
|
+
ctx,
|
|
642
|
+
l2GasLimit: l2GasParams.gasLimit,
|
|
643
|
+
l1GasPrice: l1Fees.maxFeePerGas
|
|
644
|
+
});
|
|
619
645
|
const mintValue = baseCost + ctx.operatorTip;
|
|
620
646
|
const approvals = [];
|
|
621
647
|
const steps = [];
|
|
622
648
|
const assetRouter = ctx.l1AssetRouter;
|
|
623
649
|
const nativeTokenVault = ctx.l1NativeTokenVault;
|
|
624
650
|
const erc20Deposit = new Contract(p.token, IERC20_default, l1Signer);
|
|
625
|
-
const allowanceToken = await
|
|
651
|
+
const allowanceToken = await wrapAs3(
|
|
626
652
|
"RPC",
|
|
627
653
|
OP_DEPOSITS.nonbase.allowanceToken,
|
|
628
654
|
() => erc20Deposit.allowance(ctx.sender, nativeTokenVault),
|
|
@@ -650,7 +676,7 @@ function routeErc20NonBase() {
|
|
|
650
676
|
}
|
|
651
677
|
if (!baseIsEth) {
|
|
652
678
|
const erc20Base = new Contract(baseToken, IERC20_default, l1Signer);
|
|
653
|
-
const allowanceBase = await
|
|
679
|
+
const allowanceBase = await wrapAs3(
|
|
654
680
|
"RPC",
|
|
655
681
|
OP_DEPOSITS.nonbase.allowanceBase,
|
|
656
682
|
() => erc20Base.allowance(ctx.sender, nativeTokenVault),
|
|
@@ -698,7 +724,8 @@ function routeErc20NonBase() {
|
|
|
698
724
|
data,
|
|
699
725
|
value: txValue,
|
|
700
726
|
from: ctx.sender,
|
|
701
|
-
...ctx.gasOverrides
|
|
727
|
+
...ctx.gasOverrides,
|
|
728
|
+
...l1Fees
|
|
702
729
|
};
|
|
703
730
|
const l1GasParams = await quoteL1Gas2({
|
|
704
731
|
ctx,
|
|
@@ -733,7 +760,7 @@ function routeErc20NonBase() {
|
|
|
733
760
|
}
|
|
734
761
|
};
|
|
735
762
|
}
|
|
736
|
-
var { wrapAs:
|
|
763
|
+
var { wrapAs: wrapAs4 } = createErrorHandlers("deposits");
|
|
737
764
|
var ZERO_L2_TOKEN_ADDRESS3 = "0x0000000000000000000000000000000000000000";
|
|
738
765
|
var ZERO_ASSET_ID2 = "0x0000000000000000000000000000000000000000000000000000000000000000";
|
|
739
766
|
var ntvCodec2 = createNTVCodec({
|
|
@@ -809,7 +836,7 @@ function routeEthNonBase() {
|
|
|
809
836
|
return {
|
|
810
837
|
async preflight(p, ctx) {
|
|
811
838
|
const resolved = ctx.resolvedToken ?? (ctx.tokens ? await ctx.tokens.resolve(p.token, { chain: "l1" }) : void 0);
|
|
812
|
-
await
|
|
839
|
+
await wrapAs4(
|
|
813
840
|
"VALIDATION",
|
|
814
841
|
OP_DEPOSITS.ethNonBase.assertEthAsset,
|
|
815
842
|
() => {
|
|
@@ -819,7 +846,7 @@ function routeEthNonBase() {
|
|
|
819
846
|
},
|
|
820
847
|
{ ctx: { token: p.token } }
|
|
821
848
|
);
|
|
822
|
-
await
|
|
849
|
+
await wrapAs4(
|
|
823
850
|
"VALIDATION",
|
|
824
851
|
OP_DEPOSITS.ethNonBase.assertNonEthBase,
|
|
825
852
|
() => {
|
|
@@ -829,7 +856,7 @@ function routeEthNonBase() {
|
|
|
829
856
|
},
|
|
830
857
|
{ ctx: { baseIsEth: ctx.baseIsEth, chainIdL2: ctx.chainIdL2 } }
|
|
831
858
|
);
|
|
832
|
-
const ethBal = await
|
|
859
|
+
const ethBal = await wrapAs4(
|
|
833
860
|
"RPC",
|
|
834
861
|
OP_DEPOSITS.ethNonBase.ethBalance,
|
|
835
862
|
() => ctx.client.l1.getBalance(ctx.sender),
|
|
@@ -838,7 +865,7 @@ function routeEthNonBase() {
|
|
|
838
865
|
message: "Failed to read L1 ETH balance."
|
|
839
866
|
}
|
|
840
867
|
);
|
|
841
|
-
await
|
|
868
|
+
await wrapAs4(
|
|
842
869
|
"VALIDATION",
|
|
843
870
|
OP_DEPOSITS.ethNonBase.assertEthBalance,
|
|
844
871
|
() => {
|
|
@@ -873,12 +900,17 @@ function routeEthNonBase() {
|
|
|
873
900
|
undeployedGasLimit: priorityGasModel.undeployedGasLimit
|
|
874
901
|
});
|
|
875
902
|
if (!l2GasParams) throw new Error("Failed to estimate L2 gas parameters.");
|
|
876
|
-
const
|
|
903
|
+
const l1Fees = await quoteL1Fees2({ ctx });
|
|
904
|
+
const baseCost = await quoteL2BaseCost2({
|
|
905
|
+
ctx,
|
|
906
|
+
l2GasLimit: l2GasParams.gasLimit,
|
|
907
|
+
l1GasPrice: l1Fees.maxFeePerGas
|
|
908
|
+
});
|
|
877
909
|
const mintValue = baseCost + ctx.operatorTip;
|
|
878
910
|
const approvals = [];
|
|
879
911
|
const steps = [];
|
|
880
912
|
const erc20Base = new Contract(baseToken, IERC20_default, l1Signer);
|
|
881
|
-
const allowance = await
|
|
913
|
+
const allowance = await wrapAs4(
|
|
882
914
|
"RPC",
|
|
883
915
|
OP_DEPOSITS.ethNonBase.allowanceBase,
|
|
884
916
|
() => erc20Base.allowance(ctx.sender, ctx.l1NativeTokenVault),
|
|
@@ -904,7 +936,7 @@ function routeEthNonBase() {
|
|
|
904
936
|
}
|
|
905
937
|
});
|
|
906
938
|
}
|
|
907
|
-
const secondBridgeCalldata = await
|
|
939
|
+
const secondBridgeCalldata = await wrapAs4(
|
|
908
940
|
"INTERNAL",
|
|
909
941
|
OP_DEPOSITS.ethNonBase.encodeCalldata,
|
|
910
942
|
() => encodeSecondBridgeEthDepositCalldata({ ctx, amount: p.amount, receiver }),
|
|
@@ -937,7 +969,8 @@ function routeEthNonBase() {
|
|
|
937
969
|
data,
|
|
938
970
|
value: bridgehubValue,
|
|
939
971
|
from: ctx.sender,
|
|
940
|
-
...ctx.gasOverrides
|
|
972
|
+
...ctx.gasOverrides,
|
|
973
|
+
...l1Fees
|
|
941
974
|
};
|
|
942
975
|
const l1GasParams = await quoteL1Gas2({
|
|
943
976
|
ctx,
|
|
@@ -972,13 +1005,13 @@ function routeEthNonBase() {
|
|
|
972
1005
|
}
|
|
973
1006
|
};
|
|
974
1007
|
}
|
|
975
|
-
var { wrapAs:
|
|
1008
|
+
var { wrapAs: wrapAs5 } = createErrorHandlers("deposits");
|
|
976
1009
|
var EMPTY_BYTES3 = "0x";
|
|
977
1010
|
function routeErc20Base() {
|
|
978
1011
|
return {
|
|
979
1012
|
async preflight(p, ctx) {
|
|
980
1013
|
const resolved = ctx.resolvedToken ?? (ctx.tokens ? await ctx.tokens.resolve(p.token, { chain: "l1" }) : void 0);
|
|
981
|
-
await
|
|
1014
|
+
await wrapAs5(
|
|
982
1015
|
"VALIDATION",
|
|
983
1016
|
OP_DEPOSITS.base.assertErc20Asset,
|
|
984
1017
|
() => {
|
|
@@ -989,7 +1022,7 @@ function routeErc20Base() {
|
|
|
989
1022
|
{ ctx: { token: p.token } }
|
|
990
1023
|
);
|
|
991
1024
|
const baseToken = ctx.baseTokenL1 ?? await ctx.client.baseToken(ctx.chainIdL2);
|
|
992
|
-
await
|
|
1025
|
+
await wrapAs5(
|
|
993
1026
|
"VALIDATION",
|
|
994
1027
|
OP_DEPOSITS.base.assertMatchesBase,
|
|
995
1028
|
() => {
|
|
@@ -1028,13 +1061,18 @@ function routeErc20Base() {
|
|
|
1028
1061
|
overrideGasLimit: quotedL2GasLimit
|
|
1029
1062
|
});
|
|
1030
1063
|
if (!l2GasParams) throw new Error("Failed to estimate L2 gas parameters.");
|
|
1031
|
-
const
|
|
1064
|
+
const l1Fees = await quoteL1Fees2({ ctx });
|
|
1065
|
+
const baseCost = await quoteL2BaseCost2({
|
|
1066
|
+
ctx,
|
|
1067
|
+
l2GasLimit: l2GasParams.gasLimit,
|
|
1068
|
+
l1GasPrice: l1Fees.maxFeePerGas
|
|
1069
|
+
});
|
|
1032
1070
|
const mintValue = baseCost + ctx.operatorTip + p.amount;
|
|
1033
1071
|
const approvals = [];
|
|
1034
1072
|
const steps = [];
|
|
1035
1073
|
{
|
|
1036
1074
|
const erc20 = new Contract(baseToken, IERC20_default, l1Signer);
|
|
1037
|
-
const allowance = await
|
|
1075
|
+
const allowance = await wrapAs5(
|
|
1038
1076
|
"RPC",
|
|
1039
1077
|
OP_DEPOSITS.base.allowance,
|
|
1040
1078
|
() => erc20.allowance(ctx.sender, ctx.l1NativeTokenVault),
|
|
@@ -1080,7 +1118,8 @@ function routeErc20Base() {
|
|
|
1080
1118
|
value: 0n,
|
|
1081
1119
|
// base token is ERC-20 ⇒ msg.value MUST be 0
|
|
1082
1120
|
from: ctx.sender,
|
|
1083
|
-
...ctx.gasOverrides
|
|
1121
|
+
...ctx.gasOverrides,
|
|
1122
|
+
...l1Fees
|
|
1084
1123
|
};
|
|
1085
1124
|
const l1GasParams = await quoteL1Gas2({
|
|
1086
1125
|
ctx,
|
|
@@ -1115,7 +1154,7 @@ function routeErc20Base() {
|
|
|
1115
1154
|
}
|
|
1116
1155
|
};
|
|
1117
1156
|
}
|
|
1118
|
-
var { wrapAs:
|
|
1157
|
+
var { wrapAs: wrapAs6 } = createErrorHandlers("tokens");
|
|
1119
1158
|
var abi = AbiCoder.defaultAbiCoder();
|
|
1120
1159
|
var ntvCodec3 = createNTVCodec({
|
|
1121
1160
|
encode: (types, values) => abi.encode(types, values),
|
|
@@ -1128,7 +1167,7 @@ function createTokensResource(client) {
|
|
|
1128
1167
|
let wethL2Promise = null;
|
|
1129
1168
|
async function getL1ChainId() {
|
|
1130
1169
|
if (!l2NtvL1ChainIdPromise) {
|
|
1131
|
-
l2NtvL1ChainIdPromise =
|
|
1170
|
+
l2NtvL1ChainIdPromise = wrapAs6("INTERNAL", "getL1ChainId", async () => {
|
|
1132
1171
|
const { l2NativeTokenVault } = await client.contracts();
|
|
1133
1172
|
const chainId = await l2NativeTokenVault.L1_CHAIN_ID();
|
|
1134
1173
|
return chainId;
|
|
@@ -1138,7 +1177,7 @@ function createTokensResource(client) {
|
|
|
1138
1177
|
}
|
|
1139
1178
|
async function getBaseTokenAssetId() {
|
|
1140
1179
|
if (!baseTokenAssetIdPromise) {
|
|
1141
|
-
baseTokenAssetIdPromise =
|
|
1180
|
+
baseTokenAssetIdPromise = wrapAs6("INTERNAL", "baseTokenAssetId", async () => {
|
|
1142
1181
|
const { l2NativeTokenVault } = await client.contracts();
|
|
1143
1182
|
const assetId = await l2NativeTokenVault.BASE_TOKEN_ASSET_ID();
|
|
1144
1183
|
return assetId;
|
|
@@ -1148,7 +1187,7 @@ function createTokensResource(client) {
|
|
|
1148
1187
|
}
|
|
1149
1188
|
async function getWethL1() {
|
|
1150
1189
|
if (!wethL1Promise) {
|
|
1151
|
-
wethL1Promise =
|
|
1190
|
+
wethL1Promise = wrapAs6("INTERNAL", "wethL1", async () => {
|
|
1152
1191
|
const { l1NativeTokenVault } = await client.contracts();
|
|
1153
1192
|
const weth = await l1NativeTokenVault.WETH_TOKEN();
|
|
1154
1193
|
return weth;
|
|
@@ -1158,7 +1197,7 @@ function createTokensResource(client) {
|
|
|
1158
1197
|
}
|
|
1159
1198
|
async function getWethL2() {
|
|
1160
1199
|
if (!wethL2Promise) {
|
|
1161
|
-
wethL2Promise =
|
|
1200
|
+
wethL2Promise = wrapAs6("INTERNAL", "wethL2", async () => {
|
|
1162
1201
|
const { l2NativeTokenVault } = await client.contracts();
|
|
1163
1202
|
const weth = await l2NativeTokenVault.WETH_TOKEN();
|
|
1164
1203
|
return weth;
|
|
@@ -1167,7 +1206,7 @@ function createTokensResource(client) {
|
|
|
1167
1206
|
return wethL2Promise;
|
|
1168
1207
|
}
|
|
1169
1208
|
async function toL2Address(l1Token) {
|
|
1170
|
-
return
|
|
1209
|
+
return wrapAs6("CONTRACT", "tokens.toL2Address", async () => {
|
|
1171
1210
|
const normalized = normalizeL1Token(l1Token);
|
|
1172
1211
|
const { chainId } = await client.l2.getNetwork();
|
|
1173
1212
|
const baseToken = await client.baseToken(BigInt(chainId));
|
|
@@ -1180,7 +1219,7 @@ function createTokensResource(client) {
|
|
|
1180
1219
|
});
|
|
1181
1220
|
}
|
|
1182
1221
|
async function toL1Address(l2Token) {
|
|
1183
|
-
return
|
|
1222
|
+
return wrapAs6("CONTRACT", "tokens.toL1Address", async () => {
|
|
1184
1223
|
if (isAddressEq(l2Token, ETH_ADDRESS)) {
|
|
1185
1224
|
return ETH_ADDRESS;
|
|
1186
1225
|
}
|
|
@@ -1203,7 +1242,7 @@ function createTokensResource(client) {
|
|
|
1203
1242
|
});
|
|
1204
1243
|
}
|
|
1205
1244
|
async function assetIdOfL1(l1Token) {
|
|
1206
|
-
return
|
|
1245
|
+
return wrapAs6("CONTRACT", "tokens.assetIdOfL1", async () => {
|
|
1207
1246
|
const normalized = normalizeL1Token(l1Token);
|
|
1208
1247
|
const { l1NativeTokenVault } = await client.contracts();
|
|
1209
1248
|
const assetId = await l1NativeTokenVault.assetId(normalized);
|
|
@@ -1211,28 +1250,28 @@ function createTokensResource(client) {
|
|
|
1211
1250
|
});
|
|
1212
1251
|
}
|
|
1213
1252
|
async function assetIdOfL2(l2Token) {
|
|
1214
|
-
return
|
|
1253
|
+
return wrapAs6("CONTRACT", "tokens.assetIdOfL2", async () => {
|
|
1215
1254
|
const { l2NativeTokenVault } = await client.contracts();
|
|
1216
1255
|
const assetId = await l2NativeTokenVault.assetId(l2Token);
|
|
1217
1256
|
return assetId;
|
|
1218
1257
|
});
|
|
1219
1258
|
}
|
|
1220
1259
|
async function l2TokenFromAssetId(assetId) {
|
|
1221
|
-
return
|
|
1260
|
+
return wrapAs6("CONTRACT", "tokens.l2TokenFromAssetId", async () => {
|
|
1222
1261
|
const { l2NativeTokenVault } = await client.contracts();
|
|
1223
1262
|
const tokenAddr = await l2NativeTokenVault.tokenAddress(assetId);
|
|
1224
1263
|
return tokenAddr;
|
|
1225
1264
|
});
|
|
1226
1265
|
}
|
|
1227
1266
|
async function l1TokenFromAssetId(assetId) {
|
|
1228
|
-
return
|
|
1267
|
+
return wrapAs6("CONTRACT", "tokens.l1TokenFromAssetId", async () => {
|
|
1229
1268
|
const { l1NativeTokenVault } = await client.contracts();
|
|
1230
1269
|
const tokenAddr = await l1NativeTokenVault.tokenAddress(assetId);
|
|
1231
1270
|
return tokenAddr;
|
|
1232
1271
|
});
|
|
1233
1272
|
}
|
|
1234
1273
|
async function originChainId(assetId) {
|
|
1235
|
-
return
|
|
1274
|
+
return wrapAs6("CONTRACT", "tokens.originChainId", async () => {
|
|
1236
1275
|
const { l2NativeTokenVault } = await client.contracts();
|
|
1237
1276
|
const chainId = await l2NativeTokenVault.originChainId(assetId);
|
|
1238
1277
|
return chainId;
|
|
@@ -1242,7 +1281,7 @@ function createTokensResource(client) {
|
|
|
1242
1281
|
return getBaseTokenAssetId();
|
|
1243
1282
|
}
|
|
1244
1283
|
async function isChainEthBased() {
|
|
1245
|
-
return
|
|
1284
|
+
return wrapAs6("CONTRACT", "tokens.isChainEthBased", async () => {
|
|
1246
1285
|
const baseAssetId = await getBaseTokenAssetId();
|
|
1247
1286
|
const l1ChainId = await getL1ChainId();
|
|
1248
1287
|
const ethAssetId = ntvCodec3.encodeAssetId(
|
|
@@ -1260,7 +1299,7 @@ function createTokensResource(client) {
|
|
|
1260
1299
|
return getWethL2();
|
|
1261
1300
|
}
|
|
1262
1301
|
async function computeL2BridgedAddress(args) {
|
|
1263
|
-
return
|
|
1302
|
+
return wrapAs6("CONTRACT", "tokens.computeL2BridgedAddress", async () => {
|
|
1264
1303
|
const normalized = normalizeL1Token(args.l1Token);
|
|
1265
1304
|
const { l2NativeTokenVault } = await client.contracts();
|
|
1266
1305
|
const predicted = await l2NativeTokenVault.calculateCreate2TokenAddress(
|
|
@@ -1271,7 +1310,7 @@ function createTokensResource(client) {
|
|
|
1271
1310
|
});
|
|
1272
1311
|
}
|
|
1273
1312
|
async function resolve(ref, opts) {
|
|
1274
|
-
return
|
|
1313
|
+
return wrapAs6("CONTRACT", "tokens.resolve", async () => {
|
|
1275
1314
|
let chain;
|
|
1276
1315
|
let address;
|
|
1277
1316
|
if (typeof ref === "string") {
|
|
@@ -1764,13 +1803,13 @@ function buildFeeBreakdown2(p) {
|
|
|
1764
1803
|
}
|
|
1765
1804
|
|
|
1766
1805
|
// src/adapters/ethers/resources/withdrawals/routes/eth.ts
|
|
1767
|
-
var { wrapAs:
|
|
1806
|
+
var { wrapAs: wrapAs7 } = createErrorHandlers("withdrawals");
|
|
1768
1807
|
function routeEthBase() {
|
|
1769
1808
|
return {
|
|
1770
1809
|
async build(p, ctx) {
|
|
1771
1810
|
const steps = [];
|
|
1772
1811
|
const base = await ctx.contracts.l2BaseTokenSystem();
|
|
1773
|
-
const data = await
|
|
1812
|
+
const data = await wrapAs7(
|
|
1774
1813
|
"INTERNAL",
|
|
1775
1814
|
OP_WITHDRAWALS.eth.encodeWithdraw,
|
|
1776
1815
|
() => Promise.resolve(base.interface.encodeFunctionData("withdraw", [p.to ?? ctx.sender])),
|
|
@@ -1805,7 +1844,7 @@ function routeEthBase() {
|
|
|
1805
1844
|
}
|
|
1806
1845
|
};
|
|
1807
1846
|
}
|
|
1808
|
-
var { wrapAs:
|
|
1847
|
+
var { wrapAs: wrapAs8 } = createErrorHandlers("withdrawals");
|
|
1809
1848
|
var SIG = {
|
|
1810
1849
|
withdraw: "withdraw(bytes32,bytes)"
|
|
1811
1850
|
};
|
|
@@ -1815,7 +1854,7 @@ function routeErc20NonBase2() {
|
|
|
1815
1854
|
const steps = [];
|
|
1816
1855
|
const approvals = [];
|
|
1817
1856
|
const erc20 = new Contract(p.token, IERC20_default, ctx.client.l2);
|
|
1818
|
-
const current = await
|
|
1857
|
+
const current = await wrapAs8(
|
|
1819
1858
|
"CONTRACT",
|
|
1820
1859
|
OP_WITHDRAWALS.erc20.allowance,
|
|
1821
1860
|
() => erc20.allowance(ctx.sender, ctx.l2NativeTokenVault),
|
|
@@ -1853,7 +1892,7 @@ function routeErc20NonBase2() {
|
|
|
1853
1892
|
tx: approveTx
|
|
1854
1893
|
});
|
|
1855
1894
|
}
|
|
1856
|
-
const assetId = await
|
|
1895
|
+
const assetId = await wrapAs8(
|
|
1857
1896
|
"CONTRACT",
|
|
1858
1897
|
OP_WITHDRAWALS.erc20.ensureRegistered,
|
|
1859
1898
|
async () => {
|
|
@@ -1866,7 +1905,7 @@ function routeErc20NonBase2() {
|
|
|
1866
1905
|
message: "Failed to ensure token is registered in L2NativeTokenVault."
|
|
1867
1906
|
}
|
|
1868
1907
|
);
|
|
1869
|
-
const assetData = await
|
|
1908
|
+
const assetData = await wrapAs8(
|
|
1870
1909
|
"INTERNAL",
|
|
1871
1910
|
OP_WITHDRAWALS.erc20.encodeAssetData,
|
|
1872
1911
|
() => Promise.resolve(
|
|
@@ -1878,7 +1917,7 @@ function routeErc20NonBase2() {
|
|
|
1878
1917
|
}
|
|
1879
1918
|
);
|
|
1880
1919
|
const l2ar = await ctx.contracts.l2AssetRouter();
|
|
1881
|
-
const dataWithdraw = await
|
|
1920
|
+
const dataWithdraw = await wrapAs8(
|
|
1882
1921
|
"INTERNAL",
|
|
1883
1922
|
OP_WITHDRAWALS.erc20.encodeWithdraw,
|
|
1884
1923
|
() => Promise.resolve(l2ar.interface.encodeFunctionData(SIG.withdraw, [assetId, assetData])),
|
|
@@ -1968,7 +2007,7 @@ function createEthersAttributesResource(opts = {}) {
|
|
|
1968
2007
|
}
|
|
1969
2008
|
|
|
1970
2009
|
// src/adapters/ethers/resources/withdrawals/routes/interop-bundle.ts
|
|
1971
|
-
var { wrapAs:
|
|
2010
|
+
var { wrapAs: wrapAs9 } = createErrorHandlers("withdrawals");
|
|
1972
2011
|
var attributes = createEthersAttributesResource();
|
|
1973
2012
|
function saltFor(sender, nonce) {
|
|
1974
2013
|
return keccak256(
|
|
@@ -1987,7 +2026,7 @@ function routeInteropBundle() {
|
|
|
1987
2026
|
if (isBaseToken) {
|
|
1988
2027
|
assetId = ctx.baseTokenAssetId;
|
|
1989
2028
|
} else {
|
|
1990
|
-
assetId = await
|
|
2029
|
+
assetId = await wrapAs9(
|
|
1991
2030
|
"CONTRACT",
|
|
1992
2031
|
OP_WITHDRAWALS.erc20.ensureRegistered,
|
|
1993
2032
|
async () => {
|
|
@@ -2000,7 +2039,7 @@ function routeInteropBundle() {
|
|
|
2000
2039
|
}
|
|
2001
2040
|
);
|
|
2002
2041
|
const erc20 = new Contract(p.token, IERC20_default, ctx.client.l2);
|
|
2003
|
-
const current = await
|
|
2042
|
+
const current = await wrapAs9(
|
|
2004
2043
|
"CONTRACT",
|
|
2005
2044
|
OP_WITHDRAWALS.erc20.allowance,
|
|
2006
2045
|
() => erc20.allowance(ctx.sender, ctx.l2NativeTokenVault),
|
|
@@ -2036,7 +2075,7 @@ function routeInteropBundle() {
|
|
|
2036
2075
|
});
|
|
2037
2076
|
}
|
|
2038
2077
|
}
|
|
2039
|
-
const nonce = await
|
|
2078
|
+
const nonce = await wrapAs9(
|
|
2040
2079
|
"RPC",
|
|
2041
2080
|
OP_WITHDRAWALS.prepare,
|
|
2042
2081
|
() => ctx.client.l2.getTransactionCount(ctx.sender, "pending"),
|
|
@@ -2066,7 +2105,7 @@ function routeInteropBundle() {
|
|
|
2066
2105
|
}
|
|
2067
2106
|
});
|
|
2068
2107
|
const interopCenter = await ctx.contracts.interopCenter();
|
|
2069
|
-
const data = await
|
|
2108
|
+
const data = await wrapAs9(
|
|
2070
2109
|
"INTERNAL",
|
|
2071
2110
|
OP_WITHDRAWALS.erc20.encodeWithdraw,
|
|
2072
2111
|
() => Promise.resolve(
|
|
@@ -2151,7 +2190,7 @@ function createWithdrawalProtocolService(client, override) {
|
|
|
2151
2190
|
}
|
|
2152
2191
|
|
|
2153
2192
|
// src/adapters/ethers/resources/withdrawals/services/finalization.ts
|
|
2154
|
-
var { wrapAs:
|
|
2193
|
+
var { wrapAs: wrapAs10 } = createErrorHandlers("withdrawals");
|
|
2155
2194
|
var IL1NullifierMini = [
|
|
2156
2195
|
"function isWithdrawalFinalized(uint256,uint256,uint256) view returns (bool)"
|
|
2157
2196
|
];
|
|
@@ -2161,7 +2200,7 @@ function createFinalizationServices(client, protocolService = createWithdrawalPr
|
|
|
2161
2200
|
const { l1Nullifier } = await client.ensureAddresses();
|
|
2162
2201
|
if (protocol === "legacy-withdrawal") return l1Nullifier;
|
|
2163
2202
|
const nullifier = new Contract(l1Nullifier, IL1NullifierV32_default, l1);
|
|
2164
|
-
const handler = await
|
|
2203
|
+
const handler = await wrapAs10(
|
|
2165
2204
|
"CONTRACT",
|
|
2166
2205
|
OP_WITHDRAWALS.finalize.fetchParams.receipt,
|
|
2167
2206
|
() => nullifier.l1InteropHandler(),
|
|
@@ -2173,7 +2212,7 @@ function createFinalizationServices(client, protocolService = createWithdrawalPr
|
|
|
2173
2212
|
return handler;
|
|
2174
2213
|
}
|
|
2175
2214
|
async function fetchMessageAndProof(l2TxHash) {
|
|
2176
|
-
const raw = await
|
|
2215
|
+
const raw = await wrapAs10(
|
|
2177
2216
|
"RPC",
|
|
2178
2217
|
OP_WITHDRAWALS.finalize.fetchParams.receipt,
|
|
2179
2218
|
() => client.zks.getReceiptWithL2ToL1(l2TxHash),
|
|
@@ -2190,7 +2229,7 @@ function createFinalizationServices(client, protocolService = createWithdrawalPr
|
|
|
2190
2229
|
context: { l2TxHash }
|
|
2191
2230
|
});
|
|
2192
2231
|
}
|
|
2193
|
-
const ev = await
|
|
2232
|
+
const ev = await wrapAs10(
|
|
2194
2233
|
"INTERNAL",
|
|
2195
2234
|
OP_WITHDRAWALS.finalize.fetchParams.findMessage,
|
|
2196
2235
|
// eslint-disable-next-line @typescript-eslint/no-unsafe-argument, @typescript-eslint/no-explicit-any
|
|
@@ -2200,7 +2239,7 @@ function createFinalizationServices(client, protocolService = createWithdrawalPr
|
|
|
2200
2239
|
message: "Failed to locate L1MessageSent event in L2 receipt."
|
|
2201
2240
|
}
|
|
2202
2241
|
);
|
|
2203
|
-
const message = await
|
|
2242
|
+
const message = await wrapAs10(
|
|
2204
2243
|
"INTERNAL",
|
|
2205
2244
|
OP_WITHDRAWALS.finalize.fetchParams.decodeMessage,
|
|
2206
2245
|
() => Promise.resolve(AbiCoder.defaultAbiCoder().decode(["bytes"], ev.data)[0]),
|
|
@@ -2209,7 +2248,7 @@ function createFinalizationServices(client, protocolService = createWithdrawalPr
|
|
|
2209
2248
|
message: "Failed to decode withdrawal message."
|
|
2210
2249
|
}
|
|
2211
2250
|
);
|
|
2212
|
-
const idx = await
|
|
2251
|
+
const idx = await wrapAs10(
|
|
2213
2252
|
"INTERNAL",
|
|
2214
2253
|
OP_WITHDRAWALS.finalize.fetchParams.messengerIndex,
|
|
2215
2254
|
() => Promise.resolve(messengerLogIndex(raw, { index: 0, messenger: L1_MESSENGER_ADDRESS })),
|
|
@@ -2218,7 +2257,7 @@ function createFinalizationServices(client, protocolService = createWithdrawalPr
|
|
|
2218
2257
|
message: "Failed to derive messenger log index."
|
|
2219
2258
|
}
|
|
2220
2259
|
);
|
|
2221
|
-
const proof = await
|
|
2260
|
+
const proof = await wrapAs10(
|
|
2222
2261
|
"RPC",
|
|
2223
2262
|
OP_WITHDRAWALS.finalize.fetchParams.proof,
|
|
2224
2263
|
() => client.zks.getL2ToL1LogProof(l2TxHash, idx),
|
|
@@ -2227,7 +2266,7 @@ function createFinalizationServices(client, protocolService = createWithdrawalPr
|
|
|
2227
2266
|
message: "Failed to fetch L2\u2192L1 log proof."
|
|
2228
2267
|
}
|
|
2229
2268
|
);
|
|
2230
|
-
const { chainId } = await
|
|
2269
|
+
const { chainId } = await wrapAs10(
|
|
2231
2270
|
"RPC",
|
|
2232
2271
|
OP_WITHDRAWALS.finalize.fetchParams.network,
|
|
2233
2272
|
() => l2.getNetwork(),
|
|
@@ -2286,7 +2325,7 @@ function createFinalizationServices(client, protocolService = createWithdrawalPr
|
|
|
2286
2325
|
const target = await finalizationTarget(finalization.protocol);
|
|
2287
2326
|
if (finalization.protocol === "legacy-withdrawal") {
|
|
2288
2327
|
const c = new Contract(target, IL1NullifierMini, l1);
|
|
2289
|
-
const done = await
|
|
2328
|
+
const done = await wrapAs10(
|
|
2290
2329
|
"RPC",
|
|
2291
2330
|
OP_WITHDRAWALS.finalize.isFinalized,
|
|
2292
2331
|
() => c.isWithdrawalFinalized(
|
|
@@ -2304,7 +2343,7 @@ function createFinalizationServices(client, protocolService = createWithdrawalPr
|
|
|
2304
2343
|
const { bundleHash } = finalization.params;
|
|
2305
2344
|
const handler = new Contract(target, IInteropHandler_default, l1);
|
|
2306
2345
|
const status = Number(
|
|
2307
|
-
await
|
|
2346
|
+
await wrapAs10(
|
|
2308
2347
|
"RPC",
|
|
2309
2348
|
OP_WITHDRAWALS.finalize.isFinalized,
|
|
2310
2349
|
() => handler.bundleStatus(bundleHash),
|
|
@@ -2316,7 +2355,7 @@ function createFinalizationServices(client, protocolService = createWithdrawalPr
|
|
|
2316
2355
|
);
|
|
2317
2356
|
if (status !== 3 /* Unbundled */) return classifyWithdrawalOutcome(status);
|
|
2318
2357
|
const callStatus = Number(
|
|
2319
|
-
await
|
|
2358
|
+
await wrapAs10(
|
|
2320
2359
|
"RPC",
|
|
2321
2360
|
OP_WITHDRAWALS.finalize.isFinalized,
|
|
2322
2361
|
() => handler.callStatus(bundleHash, 0),
|
|
@@ -2376,7 +2415,7 @@ function createFinalizationServices(client, protocolService = createWithdrawalPr
|
|
|
2376
2415
|
async estimateFinalization(finalization) {
|
|
2377
2416
|
const target = await finalizationTarget(finalization.protocol);
|
|
2378
2417
|
const l1Signer = client.getL1Signer();
|
|
2379
|
-
const gasLimit = await
|
|
2418
|
+
const gasLimit = await wrapAs10(
|
|
2380
2419
|
"RPC",
|
|
2381
2420
|
OP_WITHDRAWALS.finalize.estimate,
|
|
2382
2421
|
() => {
|
|
@@ -2395,7 +2434,7 @@ function createFinalizationServices(client, protocolService = createWithdrawalPr
|
|
|
2395
2434
|
message: "Failed to estimate gas for withdrawal finalization."
|
|
2396
2435
|
}
|
|
2397
2436
|
);
|
|
2398
|
-
const feeData = await
|
|
2437
|
+
const feeData = await wrapAs10("RPC", OP_WITHDRAWALS.finalize.estimate, () => l1.getFeeData(), {
|
|
2399
2438
|
ctx: { where: "l1.getFeeData" },
|
|
2400
2439
|
message: "Failed to estimate fee data for withdrawal finalization."
|
|
2401
2440
|
});
|