@matterlabs/zksync-js 0.0.1 → 0.0.3
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/README.md +12 -12
- package/dist/adapters/ethers/client.cjs +642 -1
- package/dist/adapters/ethers/client.cjs.map +1 -1
- package/dist/adapters/ethers/client.js +6 -5
- package/dist/adapters/ethers/estimator.d.ts +4 -0
- package/dist/adapters/ethers/index.cjs +1279 -925
- package/dist/adapters/ethers/index.cjs.map +1 -1
- package/dist/adapters/ethers/index.d.ts +1 -0
- package/dist/adapters/ethers/index.js +9 -8
- package/dist/adapters/ethers/resources/contracts/contracts.d.ts +9 -0
- package/dist/adapters/ethers/resources/contracts/index.d.ts +2 -0
- package/dist/adapters/ethers/resources/contracts/types.d.ts +60 -0
- package/dist/adapters/ethers/resources/deposits/context.d.ts +21 -7
- package/dist/adapters/ethers/resources/deposits/index.d.ts +3 -1
- package/dist/adapters/ethers/resources/deposits/routes/types.d.ts +2 -6
- package/dist/adapters/ethers/resources/deposits/services/fee.d.ts +6 -0
- package/dist/adapters/ethers/resources/deposits/services/gas.d.ts +41 -0
- package/dist/adapters/ethers/resources/tokens/index.d.ts +1 -0
- package/dist/adapters/ethers/resources/tokens/tokens.d.ts +10 -0
- package/dist/adapters/ethers/resources/utils.d.ts +3 -17
- package/dist/adapters/ethers/resources/withdrawals/context.d.ts +15 -7
- package/dist/adapters/ethers/resources/withdrawals/index.d.ts +3 -1
- package/dist/adapters/ethers/resources/withdrawals/routes/types.d.ts +2 -2
- package/dist/adapters/ethers/resources/withdrawals/services/fees.d.ts +14 -0
- package/dist/adapters/ethers/resources/withdrawals/services/gas.d.ts +12 -0
- package/dist/adapters/ethers/sdk.cjs +1388 -1501
- package/dist/adapters/ethers/sdk.cjs.map +1 -1
- package/dist/adapters/ethers/sdk.d.ts +5 -22
- package/dist/adapters/ethers/sdk.js +7 -6
- package/dist/adapters/viem/client.cjs.map +1 -1
- package/dist/adapters/viem/client.d.ts +1 -1
- package/dist/adapters/viem/client.js +4 -5
- package/dist/adapters/viem/estimator.d.ts +4 -0
- package/dist/adapters/viem/index.cjs +1233 -744
- package/dist/adapters/viem/index.cjs.map +1 -1
- package/dist/adapters/viem/index.d.ts +3 -0
- package/dist/adapters/viem/index.js +8 -8
- package/dist/adapters/viem/resources/contracts/contracts.d.ts +9 -0
- package/dist/adapters/viem/resources/contracts/index.d.ts +2 -0
- package/dist/adapters/viem/resources/contracts/types.d.ts +61 -0
- package/dist/adapters/viem/resources/deposits/context.d.ts +21 -7
- package/dist/adapters/viem/resources/deposits/index.d.ts +3 -1
- package/dist/adapters/viem/resources/deposits/routes/types.d.ts +2 -6
- package/dist/adapters/viem/resources/deposits/services/fee.d.ts +6 -0
- package/dist/adapters/viem/resources/deposits/services/gas.d.ts +37 -0
- package/dist/adapters/viem/resources/tokens/index.d.ts +1 -0
- package/dist/adapters/viem/resources/tokens/tokens.d.ts +3 -0
- package/dist/adapters/viem/resources/utils.d.ts +3 -19
- package/dist/adapters/viem/resources/withdrawals/context.d.ts +14 -9
- package/dist/adapters/viem/resources/withdrawals/index.d.ts +3 -1
- package/dist/adapters/viem/resources/withdrawals/routes/types.d.ts +12 -2
- package/dist/adapters/viem/resources/withdrawals/services/fee.d.ts +17 -0
- package/dist/adapters/viem/resources/withdrawals/services/gas.d.ts +12 -0
- package/dist/adapters/viem/sdk.cjs +1225 -699
- package/dist/adapters/viem/sdk.cjs.map +1 -1
- package/dist/adapters/viem/sdk.d.ts +5 -25
- package/dist/adapters/viem/sdk.js +6 -6
- package/dist/{chunk-3LALBFFE.js → chunk-3MRGU4HV.js} +9 -5
- package/dist/{chunk-CGO27P7F.js → chunk-5YWP4CZP.js} +849 -835
- package/dist/{chunk-4HLJJKIY.js → chunk-6K6VJQAL.js} +2 -2
- package/dist/{chunk-6GCT6TLS.js → chunk-F2ENUV3A.js} +13 -1
- package/dist/{chunk-7M4V3FMT.js → chunk-JXUFGIJG.js} +986 -678
- package/dist/chunk-LL3WKCFJ.js +231 -0
- package/dist/{chunk-Y75OMFK6.js → chunk-M5J2MM2U.js} +351 -1
- package/dist/{chunk-263G6636.js → chunk-NCAIVYBR.js} +1 -14
- package/dist/{chunk-DI2CJDPZ.js → chunk-NEC2ZKHI.js} +5 -13
- package/dist/chunk-NTEIA5KA.js +13 -0
- package/dist/chunk-XRE7H466.js +157 -0
- package/dist/{chunk-BD2LUO5T.js → chunk-YUK547UF.js} +3 -3
- package/dist/core/abi.d.ts +9 -0
- package/dist/core/adapters/interfaces.d.ts +25 -0
- package/dist/core/codec/ntv.d.ts +48 -0
- package/dist/core/constants.cjs +12 -0
- package/dist/core/constants.cjs.map +1 -1
- package/dist/core/constants.d.ts +6 -0
- package/dist/core/constants.js +1 -1
- package/dist/core/index.cjs +4508 -1
- package/dist/core/index.cjs.map +1 -1
- package/dist/core/index.d.ts +2 -0
- package/dist/core/index.js +5 -4
- package/dist/core/resources/deposits/fee.d.ts +15 -0
- package/dist/core/resources/deposits/gas.d.ts +38 -0
- package/dist/core/resources/withdrawals/gas.d.ts +14 -0
- package/dist/core/types/errors.d.ts +1 -1
- package/dist/core/types/fees.d.ts +40 -0
- package/dist/core/types/flows/base.d.ts +0 -10
- package/dist/core/types/flows/deposits.d.ts +20 -6
- package/dist/core/types/flows/route.d.ts +2 -3
- package/dist/core/types/flows/token.d.ts +192 -0
- package/dist/core/types/flows/withdrawals.d.ts +12 -6
- package/dist/core/utils/addr.d.ts +2 -0
- package/dist/index.cjs +4520 -1
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +2 -0
- package/dist/index.js +5 -4
- package/package.json +5 -1
- package/dist/adapters/ethers/resources/token-info.d.ts +0 -31
- package/dist/adapters/ethers/resources/withdrawals/routes/eth-nonbase.d.ts +0 -2
- package/dist/adapters/viem/resources/token-info.d.ts +0 -34
- package/dist/adapters/viem/resources/withdrawals/routes/eth-nonbase.d.ts +0 -2
- package/dist/chunk-B77GWPO5.js +0 -339
- package/dist/core/internal/abi-registry.d.ts +0 -9
- package/dist/core/utils/gas.d.ts +0 -13
|
@@ -0,0 +1,231 @@
|
|
|
1
|
+
import { IBridgehub_default } from './chunk-M5J2MM2U.js';
|
|
2
|
+
import { BUFFER, DEFAULT_ABI_BYTES, DEFAULT_PUBDATA_BYTES, TX_MEMORY_OVERHEAD_GAS, TX_OVERHEAD_GAS } from './chunk-F2ENUV3A.js';
|
|
3
|
+
|
|
4
|
+
// src/core/codec/ntv.ts
|
|
5
|
+
function createNTVCodec(deps) {
|
|
6
|
+
function encodeAssetId(originChainId, ntvAddress, tokenAddress) {
|
|
7
|
+
const encoded = deps.encode(
|
|
8
|
+
["uint256", "address", "address"],
|
|
9
|
+
[originChainId, ntvAddress, tokenAddress]
|
|
10
|
+
);
|
|
11
|
+
return deps.keccak256(encoded);
|
|
12
|
+
}
|
|
13
|
+
return {
|
|
14
|
+
encodeAssetId
|
|
15
|
+
};
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
// src/core/resources/deposits/fee.ts
|
|
19
|
+
function buildFeeBreakdown(p) {
|
|
20
|
+
const l1MaxTotal = p.l1Gas?.maxCost ?? 0n;
|
|
21
|
+
const l2Total = p.l2BaseCost + p.operatorTip;
|
|
22
|
+
const l1 = {
|
|
23
|
+
gasLimit: p.l1Gas?.gasLimit ?? 0n,
|
|
24
|
+
maxFeePerGas: p.l1Gas?.maxFeePerGas ?? 0n,
|
|
25
|
+
maxPriorityFeePerGas: p.l1Gas?.maxPriorityFeePerGas,
|
|
26
|
+
maxTotal: l1MaxTotal
|
|
27
|
+
};
|
|
28
|
+
const l2 = {
|
|
29
|
+
total: l2Total,
|
|
30
|
+
baseCost: p.l2BaseCost,
|
|
31
|
+
operatorTip: p.operatorTip,
|
|
32
|
+
gasLimit: p.l2Gas?.gasLimit ?? 0n,
|
|
33
|
+
maxFeePerGas: p.l2Gas?.maxFeePerGas ?? 0n,
|
|
34
|
+
maxPriorityFeePerGas: p.l2Gas?.maxPriorityFeePerGas,
|
|
35
|
+
gasPerPubdata: p.l2Gas?.gasPerPubdata ?? 0n
|
|
36
|
+
};
|
|
37
|
+
return {
|
|
38
|
+
token: p.feeToken,
|
|
39
|
+
maxTotal: l1MaxTotal + l2Total,
|
|
40
|
+
mintValue: p.mintValue,
|
|
41
|
+
l1,
|
|
42
|
+
l2
|
|
43
|
+
};
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
// src/core/resources/deposits/gas.ts
|
|
47
|
+
function makeGasQuote(p) {
|
|
48
|
+
const maxPriorityFeePerGas = p.maxPriorityFeePerGas ?? 0n;
|
|
49
|
+
return {
|
|
50
|
+
gasLimit: p.gasLimit,
|
|
51
|
+
maxFeePerGas: p.maxFeePerGas,
|
|
52
|
+
maxPriorityFeePerGas,
|
|
53
|
+
gasPerPubdata: p.gasPerPubdata,
|
|
54
|
+
maxCost: p.gasLimit * p.maxFeePerGas
|
|
55
|
+
};
|
|
56
|
+
}
|
|
57
|
+
async function fetchFees(estimator) {
|
|
58
|
+
try {
|
|
59
|
+
const fees = await estimator.estimateFeesPerGas();
|
|
60
|
+
if (fees.maxFeePerGas != null) {
|
|
61
|
+
return {
|
|
62
|
+
maxFeePerGas: fees.maxFeePerGas,
|
|
63
|
+
maxPriorityFeePerGas: fees.maxPriorityFeePerGas ?? 0n
|
|
64
|
+
};
|
|
65
|
+
}
|
|
66
|
+
if (fees.gasPrice != null) {
|
|
67
|
+
return {
|
|
68
|
+
maxFeePerGas: fees.gasPrice,
|
|
69
|
+
maxPriorityFeePerGas: 0n
|
|
70
|
+
};
|
|
71
|
+
}
|
|
72
|
+
} catch {
|
|
73
|
+
}
|
|
74
|
+
try {
|
|
75
|
+
const gp = await estimator.getGasPrice();
|
|
76
|
+
return { maxFeePerGas: gp, maxPriorityFeePerGas: 0n };
|
|
77
|
+
} catch {
|
|
78
|
+
return { maxFeePerGas: 0n, maxPriorityFeePerGas: 0n };
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
async function quoteL1Gas(input) {
|
|
82
|
+
const { estimator, tx, overrides, fallbackGasLimit } = input;
|
|
83
|
+
let market;
|
|
84
|
+
const getMarket = async () => {
|
|
85
|
+
if (market) return market;
|
|
86
|
+
market = await fetchFees(estimator);
|
|
87
|
+
return market;
|
|
88
|
+
};
|
|
89
|
+
const maxFeePerGas = overrides?.maxFeePerGas ?? (tx.maxFeePerGas != null ? BigInt(tx.maxFeePerGas) : (await getMarket()).maxFeePerGas);
|
|
90
|
+
const maxPriorityFeePerGas = overrides?.maxPriorityFeePerGas ?? (tx.maxPriorityFeePerGas != null ? BigInt(tx.maxPriorityFeePerGas) : (await getMarket()).maxPriorityFeePerGas);
|
|
91
|
+
const explicitGasLimit = overrides?.gasLimit ?? (tx.gasLimit != null ? BigInt(tx.gasLimit) : void 0);
|
|
92
|
+
if (explicitGasLimit != null) {
|
|
93
|
+
return makeGasQuote({ gasLimit: explicitGasLimit, maxFeePerGas, maxPriorityFeePerGas });
|
|
94
|
+
}
|
|
95
|
+
try {
|
|
96
|
+
const est = await estimator.estimateGas(tx);
|
|
97
|
+
const buffered = BigInt(est) * (100n + BUFFER) / 100n;
|
|
98
|
+
return makeGasQuote({ gasLimit: buffered, maxFeePerGas, maxPriorityFeePerGas });
|
|
99
|
+
} catch (err) {
|
|
100
|
+
if (fallbackGasLimit != null) {
|
|
101
|
+
return makeGasQuote({ gasLimit: fallbackGasLimit, maxFeePerGas, maxPriorityFeePerGas });
|
|
102
|
+
}
|
|
103
|
+
console.warn("L1 gas estimation failed", err);
|
|
104
|
+
return void 0;
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
async function quoteL2Gas(input) {
|
|
108
|
+
const { estimator, route, tx, gasPerPubdata, l2GasLimit, overrideGasLimit, stateOverrides } = input;
|
|
109
|
+
const market = await fetchFees(estimator);
|
|
110
|
+
const maxFeePerGas = market.maxFeePerGas || market.maxPriorityFeePerGas || 0n;
|
|
111
|
+
const txGasLimit = tx?.gasLimit != null ? BigInt(tx.gasLimit) : void 0;
|
|
112
|
+
const explicit = overrideGasLimit ?? txGasLimit;
|
|
113
|
+
if (explicit != null) {
|
|
114
|
+
return makeGasQuote({
|
|
115
|
+
gasLimit: explicit,
|
|
116
|
+
maxFeePerGas,
|
|
117
|
+
gasPerPubdata
|
|
118
|
+
});
|
|
119
|
+
}
|
|
120
|
+
if (!tx) {
|
|
121
|
+
return makeGasQuote({
|
|
122
|
+
gasLimit: l2GasLimit ?? 0n,
|
|
123
|
+
maxFeePerGas,
|
|
124
|
+
gasPerPubdata
|
|
125
|
+
});
|
|
126
|
+
}
|
|
127
|
+
try {
|
|
128
|
+
const execEstimate = await estimator.estimateGas(tx, stateOverrides);
|
|
129
|
+
const memoryBytes = route === "erc20-nonbase" ? 500n : DEFAULT_ABI_BYTES;
|
|
130
|
+
const pubdataBytes = route === "erc20-nonbase" ? 200n : DEFAULT_PUBDATA_BYTES;
|
|
131
|
+
const pp = gasPerPubdata ?? 800n;
|
|
132
|
+
const memoryOverhead = memoryBytes * TX_MEMORY_OVERHEAD_GAS;
|
|
133
|
+
const pubdataOverhead = pubdataBytes * pp;
|
|
134
|
+
let total = BigInt(execEstimate) + TX_OVERHEAD_GAS + memoryOverhead + pubdataOverhead;
|
|
135
|
+
total = total * (100n + BUFFER) / 100n;
|
|
136
|
+
return makeGasQuote({
|
|
137
|
+
gasLimit: total,
|
|
138
|
+
maxFeePerGas,
|
|
139
|
+
gasPerPubdata: pp
|
|
140
|
+
});
|
|
141
|
+
} catch (err) {
|
|
142
|
+
console.warn("L2 gas estimation failed", err);
|
|
143
|
+
return makeGasQuote({
|
|
144
|
+
gasLimit: l2GasLimit ?? 0n,
|
|
145
|
+
maxFeePerGas,
|
|
146
|
+
gasPerPubdata
|
|
147
|
+
});
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
async function quoteL2BaseCost(input) {
|
|
151
|
+
const { estimator, encode, bridgehub, chainIdL2, l2GasLimit, gasPerPubdata } = input;
|
|
152
|
+
const market = await fetchFees(estimator);
|
|
153
|
+
const l1GasPrice = market.maxFeePerGas || market.maxPriorityFeePerGas || 0n;
|
|
154
|
+
if (l1GasPrice === 0n) {
|
|
155
|
+
throw new Error("Could not fetch L1 gas price for Bridgehub base cost calculation.");
|
|
156
|
+
}
|
|
157
|
+
const data = encode(IBridgehub_default, "l2TransactionBaseCost", [
|
|
158
|
+
chainIdL2,
|
|
159
|
+
l1GasPrice,
|
|
160
|
+
l2GasLimit,
|
|
161
|
+
gasPerPubdata
|
|
162
|
+
]);
|
|
163
|
+
const raw = await estimator.call({
|
|
164
|
+
to: bridgehub,
|
|
165
|
+
data
|
|
166
|
+
});
|
|
167
|
+
return BigInt(raw);
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
// src/core/resources/withdrawals/gas.ts
|
|
171
|
+
function makeGasQuote2(p) {
|
|
172
|
+
return {
|
|
173
|
+
gasLimit: p.gasLimit,
|
|
174
|
+
maxFeePerGas: p.maxFeePerGas,
|
|
175
|
+
maxPriorityFeePerGas: p.maxPriorityFeePerGas,
|
|
176
|
+
maxCost: p.gasLimit * p.maxFeePerGas
|
|
177
|
+
};
|
|
178
|
+
}
|
|
179
|
+
async function fetchFees2(estimator) {
|
|
180
|
+
try {
|
|
181
|
+
const fees = await estimator.estimateFeesPerGas();
|
|
182
|
+
if (fees.maxFeePerGas != null) {
|
|
183
|
+
return {
|
|
184
|
+
maxFeePerGas: fees.maxFeePerGas,
|
|
185
|
+
maxPriorityFeePerGas: fees.maxPriorityFeePerGas ?? 0n
|
|
186
|
+
};
|
|
187
|
+
}
|
|
188
|
+
if (fees.gasPrice != null) {
|
|
189
|
+
return {
|
|
190
|
+
maxFeePerGas: fees.gasPrice,
|
|
191
|
+
maxPriorityFeePerGas: 0n
|
|
192
|
+
};
|
|
193
|
+
}
|
|
194
|
+
} catch {
|
|
195
|
+
}
|
|
196
|
+
try {
|
|
197
|
+
const gp = await estimator.getGasPrice();
|
|
198
|
+
return { maxFeePerGas: gp, maxPriorityFeePerGas: 0n };
|
|
199
|
+
} catch {
|
|
200
|
+
return { maxFeePerGas: 0n, maxPriorityFeePerGas: 0n };
|
|
201
|
+
}
|
|
202
|
+
}
|
|
203
|
+
async function quoteL2Gas2(input) {
|
|
204
|
+
const { estimator, tx, overrides } = input;
|
|
205
|
+
const market = await fetchFees2(estimator);
|
|
206
|
+
const o = overrides;
|
|
207
|
+
const maxFeePerGas = o?.maxFeePerGas ?? (tx.maxFeePerGas != null ? BigInt(tx.maxFeePerGas) : market.maxFeePerGas);
|
|
208
|
+
const maxPriorityFeePerGas = o?.maxPriorityFeePerGas ?? (tx.maxPriorityFeePerGas != null ? BigInt(tx.maxPriorityFeePerGas) : market.maxPriorityFeePerGas);
|
|
209
|
+
const explicitGasLimit = o?.gasLimit ?? (tx.gasLimit != null ? BigInt(tx.gasLimit) : void 0);
|
|
210
|
+
if (explicitGasLimit != null) {
|
|
211
|
+
return makeGasQuote2({
|
|
212
|
+
gasLimit: explicitGasLimit,
|
|
213
|
+
maxFeePerGas,
|
|
214
|
+
maxPriorityFeePerGas
|
|
215
|
+
});
|
|
216
|
+
}
|
|
217
|
+
try {
|
|
218
|
+
const est = await estimator.estimateGas(tx);
|
|
219
|
+
const buffered = BigInt(est) * (100n + BUFFER) / 100n;
|
|
220
|
+
return makeGasQuote2({
|
|
221
|
+
gasLimit: buffered,
|
|
222
|
+
maxFeePerGas,
|
|
223
|
+
maxPriorityFeePerGas
|
|
224
|
+
});
|
|
225
|
+
} catch (err) {
|
|
226
|
+
console.warn("Failed to estimate L2 gas for withdrawal.", err);
|
|
227
|
+
return void 0;
|
|
228
|
+
}
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
export { buildFeeBreakdown, createNTVCodec, quoteL1Gas, quoteL2BaseCost, quoteL2Gas, quoteL2Gas2 };
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import { __export } from './chunk-F2ENUV3A.js';
|
|
2
|
+
|
|
1
3
|
// src/core/internal/abis/IBridgehub.ts
|
|
2
4
|
var IBridgehubABI = [
|
|
3
5
|
{
|
|
@@ -3980,6 +3982,20 @@ var IBaseTokenABI = [
|
|
|
3980
3982
|
];
|
|
3981
3983
|
var IBaseToken_default = IBaseTokenABI;
|
|
3982
3984
|
|
|
3985
|
+
// src/core/abi.ts
|
|
3986
|
+
var abi_exports = {};
|
|
3987
|
+
__export(abi_exports, {
|
|
3988
|
+
IBaseTokenABI: () => IBaseToken_default,
|
|
3989
|
+
IBridgehubABI: () => IBridgehub_default,
|
|
3990
|
+
IERC20ABI: () => IERC20_default,
|
|
3991
|
+
IL1AssetRouterABI: () => IL1AssetRouter_default,
|
|
3992
|
+
IL1NullifierABI: () => IL1Nullifier_default,
|
|
3993
|
+
IL2AssetRouterABI: () => IL2AssetRouter_default,
|
|
3994
|
+
L1NativeTokenVaultABI: () => L1NativeTokenVault_default,
|
|
3995
|
+
L2NativeTokenVaultABI: () => L2NativeTokenVault_default,
|
|
3996
|
+
MailboxABI: () => Mailbox_default
|
|
3997
|
+
});
|
|
3998
|
+
|
|
3983
3999
|
// src/core/internal/abis/IERC20.ts
|
|
3984
4000
|
var IERC20ABI = [
|
|
3985
4001
|
{
|
|
@@ -4486,4 +4502,338 @@ var MailboxABI = [
|
|
|
4486
4502
|
];
|
|
4487
4503
|
var Mailbox_default = MailboxABI;
|
|
4488
4504
|
|
|
4489
|
-
|
|
4505
|
+
// src/core/errors/formatter.ts
|
|
4506
|
+
function elideMiddle(s, max = 96) {
|
|
4507
|
+
if (s.length <= max) return s;
|
|
4508
|
+
const keep = Math.max(10, Math.floor((max - 1) / 2));
|
|
4509
|
+
return `${s.slice(0, keep)}\u2026${s.slice(-keep)}`;
|
|
4510
|
+
}
|
|
4511
|
+
function shortJSON(v, max = 240) {
|
|
4512
|
+
try {
|
|
4513
|
+
const s = JSON.stringify(
|
|
4514
|
+
v,
|
|
4515
|
+
(_k, val) => typeof val === "bigint" ? `${val.toString()}n` : val
|
|
4516
|
+
);
|
|
4517
|
+
return s.length > max ? elideMiddle(s, max) : s;
|
|
4518
|
+
} catch {
|
|
4519
|
+
return String(v);
|
|
4520
|
+
}
|
|
4521
|
+
}
|
|
4522
|
+
function kv(label, value) {
|
|
4523
|
+
const width = 10;
|
|
4524
|
+
const pad = label.length >= width ? " " : " ".repeat(width - label.length);
|
|
4525
|
+
return `${label + pad}: ${value}`;
|
|
4526
|
+
}
|
|
4527
|
+
function formatContextLine(ctx) {
|
|
4528
|
+
if (!ctx) return;
|
|
4529
|
+
const txHash = ctx["txHash"] ?? ctx["l1TxHash"] ?? ctx["hash"];
|
|
4530
|
+
const nonce = ctx["nonce"];
|
|
4531
|
+
const parts = [];
|
|
4532
|
+
if (txHash !== void 0)
|
|
4533
|
+
parts.push(`txHash=${typeof txHash === "string" ? txHash : shortJSON(txHash, 96)}`);
|
|
4534
|
+
if (nonce !== void 0) {
|
|
4535
|
+
const nonceStr = typeof nonce === "string" || typeof nonce === "number" || typeof nonce === "bigint" ? String(nonce) : shortJSON(nonce, 48);
|
|
4536
|
+
parts.push(`nonce=${nonceStr}`);
|
|
4537
|
+
}
|
|
4538
|
+
return parts.length ? ` ${kv("Context", parts.join(" \u2022 "))}` : void 0;
|
|
4539
|
+
}
|
|
4540
|
+
function formatStep(ctx) {
|
|
4541
|
+
const step = ctx && typeof ctx["step"] === "string" ? ctx["step"] : void 0;
|
|
4542
|
+
return step ? ` ${kv("Step", step)}` : void 0;
|
|
4543
|
+
}
|
|
4544
|
+
function formatRevert(r) {
|
|
4545
|
+
if (!r) return;
|
|
4546
|
+
const first = [`selector=${r.selector}`];
|
|
4547
|
+
const lines = [];
|
|
4548
|
+
lines.push(` ${kv("Revert", first.join(" "))}`);
|
|
4549
|
+
if (r.name) lines.push(` name=${r.name}`);
|
|
4550
|
+
if (r.contract) lines.push(` contract=${r.contract}`);
|
|
4551
|
+
if (r.fn) lines.push(` fn=${r.fn}`);
|
|
4552
|
+
if (r.args && r.args.length) {
|
|
4553
|
+
lines.push(` args=${shortJSON(r.args, 120)}`);
|
|
4554
|
+
}
|
|
4555
|
+
return lines.join("\n");
|
|
4556
|
+
}
|
|
4557
|
+
function formatCause(c) {
|
|
4558
|
+
if (!c) return [];
|
|
4559
|
+
const out = [];
|
|
4560
|
+
if (typeof c === "object" && c !== null) {
|
|
4561
|
+
const obj = c;
|
|
4562
|
+
const head = [];
|
|
4563
|
+
if (obj.name !== void 0) {
|
|
4564
|
+
const nameVal = obj.name;
|
|
4565
|
+
const nameStr = typeof nameVal === "string" || typeof nameVal === "number" || typeof nameVal === "bigint" || typeof nameVal === "boolean" ? String(nameVal) : shortJSON(nameVal, 120);
|
|
4566
|
+
head.push(`name=${nameStr}`);
|
|
4567
|
+
}
|
|
4568
|
+
if (obj.code !== void 0) {
|
|
4569
|
+
const codeVal = obj.code;
|
|
4570
|
+
const codeStr = typeof codeVal === "string" || typeof codeVal === "number" || typeof codeVal === "bigint" || typeof codeVal === "boolean" ? String(codeVal) : shortJSON(codeVal, 120);
|
|
4571
|
+
head.push(`code=${codeStr}`);
|
|
4572
|
+
}
|
|
4573
|
+
if (head.length) out.push(` ${kv("Cause", head.join(" "))}`);
|
|
4574
|
+
if (obj.message) {
|
|
4575
|
+
const messageStr = typeof obj.message === "string" || typeof obj.message === "number" || typeof obj.message === "bigint" || typeof obj.message === "boolean" ? String(obj.message) : shortJSON(obj.message, 600);
|
|
4576
|
+
out.push(` message=${elideMiddle(messageStr, 600)}`);
|
|
4577
|
+
}
|
|
4578
|
+
if (obj.data) {
|
|
4579
|
+
const dataStr = shortJSON(obj.data, 200);
|
|
4580
|
+
out.push(` data=${elideMiddle(dataStr, 200)}`);
|
|
4581
|
+
}
|
|
4582
|
+
} else {
|
|
4583
|
+
out.push(` ${kv("Cause", shortJSON(c, 200))}`);
|
|
4584
|
+
}
|
|
4585
|
+
return out;
|
|
4586
|
+
}
|
|
4587
|
+
function formatEnvelopePretty(e) {
|
|
4588
|
+
const lines = [];
|
|
4589
|
+
lines.push(`\u2716 ZKsyncError [${e.type}]`);
|
|
4590
|
+
lines.push(` ${kv("Message", e.message)}`);
|
|
4591
|
+
lines.push("");
|
|
4592
|
+
lines.push(` ${kv("Operation", e.operation)}`);
|
|
4593
|
+
const ctx = (() => {
|
|
4594
|
+
const u = e;
|
|
4595
|
+
if (!u || typeof u !== "object") return void 0;
|
|
4596
|
+
const obj = u;
|
|
4597
|
+
const candidate = obj["ctx"] ?? obj["context"];
|
|
4598
|
+
if (candidate && typeof candidate === "object" && candidate !== null) {
|
|
4599
|
+
return candidate;
|
|
4600
|
+
}
|
|
4601
|
+
return void 0;
|
|
4602
|
+
})();
|
|
4603
|
+
const ctxLine = formatContextLine(ctx);
|
|
4604
|
+
if (ctxLine) lines.push(ctxLine);
|
|
4605
|
+
const stepLine = formatStep(ctx);
|
|
4606
|
+
if (stepLine) lines.push(stepLine);
|
|
4607
|
+
const rv = formatRevert(e.revert);
|
|
4608
|
+
if (rv) lines.push(rv);
|
|
4609
|
+
const causeLines = formatCause(e.cause);
|
|
4610
|
+
if (causeLines.length) {
|
|
4611
|
+
if (!ctxLine && !rv) lines.push("");
|
|
4612
|
+
lines.push(...causeLines);
|
|
4613
|
+
}
|
|
4614
|
+
return lines.join("\n");
|
|
4615
|
+
}
|
|
4616
|
+
|
|
4617
|
+
// src/core/types/errors.ts
|
|
4618
|
+
var hasSymbolInspect = typeof Symbol === "function" && typeof Symbol.for === "function";
|
|
4619
|
+
var kInspect = hasSymbolInspect ? Symbol.for("nodejs.util.inspect.custom") : void 0;
|
|
4620
|
+
function safeInspect(val) {
|
|
4621
|
+
try {
|
|
4622
|
+
if (typeof val === "string") return val;
|
|
4623
|
+
return JSON.stringify(val, null, 2);
|
|
4624
|
+
} catch {
|
|
4625
|
+
try {
|
|
4626
|
+
return String(val);
|
|
4627
|
+
} catch {
|
|
4628
|
+
return Object.prototype.toString.call(val);
|
|
4629
|
+
}
|
|
4630
|
+
}
|
|
4631
|
+
}
|
|
4632
|
+
var ZKsyncError = class extends Error {
|
|
4633
|
+
constructor(envelope) {
|
|
4634
|
+
super(formatEnvelopePretty(envelope), envelope.cause ? { cause: envelope.cause } : void 0);
|
|
4635
|
+
this.envelope = envelope;
|
|
4636
|
+
this.name = "ZKsyncError";
|
|
4637
|
+
}
|
|
4638
|
+
toJSON() {
|
|
4639
|
+
return { name: this.name, ...this.envelope };
|
|
4640
|
+
}
|
|
4641
|
+
};
|
|
4642
|
+
if (kInspect) {
|
|
4643
|
+
Object.defineProperty(ZKsyncError.prototype, kInspect, {
|
|
4644
|
+
value() {
|
|
4645
|
+
return `${this.name}: ${formatEnvelopePretty(this.envelope)}`;
|
|
4646
|
+
},
|
|
4647
|
+
enumerable: false
|
|
4648
|
+
});
|
|
4649
|
+
}
|
|
4650
|
+
function isZKsyncError(e) {
|
|
4651
|
+
if (!e || typeof e !== "object") return false;
|
|
4652
|
+
const maybe = e;
|
|
4653
|
+
if (!("envelope" in maybe)) return false;
|
|
4654
|
+
const envelope = maybe.envelope;
|
|
4655
|
+
return typeof envelope?.type === "string" && typeof envelope?.message === "string";
|
|
4656
|
+
}
|
|
4657
|
+
function isReceiptNotFound(e) {
|
|
4658
|
+
const chain = [];
|
|
4659
|
+
let cur = e;
|
|
4660
|
+
for (let i = 0; i < 5 && cur; i++) {
|
|
4661
|
+
chain.push(cur);
|
|
4662
|
+
cur = cur.cause;
|
|
4663
|
+
}
|
|
4664
|
+
const NAME_HITS = /* @__PURE__ */ new Set([
|
|
4665
|
+
"TransactionReceiptNotFoundError",
|
|
4666
|
+
// viem
|
|
4667
|
+
"TransactionNotFoundError",
|
|
4668
|
+
// viem
|
|
4669
|
+
"NotFoundError"
|
|
4670
|
+
// some RPC wrappers
|
|
4671
|
+
]);
|
|
4672
|
+
const CODE_HITS = /* @__PURE__ */ new Set([
|
|
4673
|
+
"TRANSACTION_NOT_FOUND",
|
|
4674
|
+
// some ethers-ish shapes / providers
|
|
4675
|
+
"RECEIPT_NOT_FOUND",
|
|
4676
|
+
"NOT_FOUND",
|
|
4677
|
+
-32e3
|
|
4678
|
+
// JSON-RPC server error
|
|
4679
|
+
]);
|
|
4680
|
+
const MSG_RE = /(transaction|receipt)[^]*?(not\s+(?:be\s+)?found|missing)/i;
|
|
4681
|
+
for (const node of chain) {
|
|
4682
|
+
const name = node?.name;
|
|
4683
|
+
const code = node?.code;
|
|
4684
|
+
const short = node?.shortMessage;
|
|
4685
|
+
const msg = String(short ?? node?.message ?? "");
|
|
4686
|
+
if (name && NAME_HITS.has(name)) return true;
|
|
4687
|
+
if (code && CODE_HITS.has(code)) return true;
|
|
4688
|
+
if (MSG_RE.test(msg)) return true;
|
|
4689
|
+
}
|
|
4690
|
+
const raw = (() => {
|
|
4691
|
+
const node = e;
|
|
4692
|
+
const short = node?.shortMessage;
|
|
4693
|
+
const msg = node?.message;
|
|
4694
|
+
if (typeof short === "string" && short) return short;
|
|
4695
|
+
if (typeof msg === "string" && msg) return msg;
|
|
4696
|
+
if (e == null) return "";
|
|
4697
|
+
if (typeof e === "string") return e;
|
|
4698
|
+
return safeInspect(e);
|
|
4699
|
+
})();
|
|
4700
|
+
return MSG_RE.test(raw);
|
|
4701
|
+
}
|
|
4702
|
+
var OP_DEPOSITS = {
|
|
4703
|
+
// high-level flow ops
|
|
4704
|
+
quote: "deposits.quote",
|
|
4705
|
+
tryQuote: "deposits.tryQuote",
|
|
4706
|
+
prepare: "deposits.prepare",
|
|
4707
|
+
tryPrepare: "deposits.tryPrepare",
|
|
4708
|
+
create: "deposits.create",
|
|
4709
|
+
tryCreate: "deposits.tryCreate",
|
|
4710
|
+
status: "deposits.status",
|
|
4711
|
+
wait: "deposits.wait",
|
|
4712
|
+
tryWait: "deposits.tryWait",
|
|
4713
|
+
base: {
|
|
4714
|
+
assertErc20Asset: "deposits.erc20-base:assertErc20Asset",
|
|
4715
|
+
assertMatchesBase: "deposits.erc20-base:assertMatchesBase",
|
|
4716
|
+
baseToken: "deposits.erc20-base:baseToken",
|
|
4717
|
+
allowance: "deposits.erc20-base:allowance",
|
|
4718
|
+
baseCost: "deposits.erc20-base:l2TransactionBaseCost",
|
|
4719
|
+
estGas: "deposits.erc20-base:estimateGas"
|
|
4720
|
+
},
|
|
4721
|
+
nonbase: {
|
|
4722
|
+
baseToken: "deposits.erc20-nonbase:baseToken",
|
|
4723
|
+
assertNotEthAsset: "deposits.erc20-nonbase:assertNotEthAsset",
|
|
4724
|
+
allowance: "deposits.erc20-nonbase:allowance",
|
|
4725
|
+
allowanceFees: "deposits.erc20-nonbase:allowanceFeesBaseToken",
|
|
4726
|
+
baseCost: "deposits.erc20-nonbase:l2TransactionBaseCost",
|
|
4727
|
+
encodeCalldata: "deposits.erc20-nonbase:encodeSecondBridgeErc20Args",
|
|
4728
|
+
estGas: "deposits.erc20-nonbase:estimateGas",
|
|
4729
|
+
assertBaseIsEth: "deposits.erc20-nonbase:assertBaseIsEth",
|
|
4730
|
+
assertBaseIsErc20: "deposits.erc20-nonbase:assertBaseIsErc20",
|
|
4731
|
+
assertNonBaseToken: "deposits.erc20-nonbase:assertNonBaseToken",
|
|
4732
|
+
allowanceToken: "deposits.erc20-nonbase:allowanceToken",
|
|
4733
|
+
allowanceBase: "deposits.erc20-nonbase:allowanceBase"
|
|
4734
|
+
},
|
|
4735
|
+
eth: {
|
|
4736
|
+
baseCost: "deposits.eth:l2TransactionBaseCost",
|
|
4737
|
+
estGas: "deposits.eth:estimateGas"
|
|
4738
|
+
},
|
|
4739
|
+
ethNonBase: {
|
|
4740
|
+
baseToken: "deposits.eth-nonbase:baseToken",
|
|
4741
|
+
baseCost: "deposits.eth-nonbase:l2TransactionBaseCost",
|
|
4742
|
+
allowanceBase: "deposits.eth-nonbase:allowanceBaseToken",
|
|
4743
|
+
ethBalance: "deposits.eth-nonbase:getEthBalance",
|
|
4744
|
+
encodeCalldata: "deposits.eth-nonbase:encodeSecondBridgeEthArgs",
|
|
4745
|
+
estGas: "deposits.eth-nonbase:estimateGas",
|
|
4746
|
+
assertEthAsset: "deposits.eth-nonbase:assertEthAsset",
|
|
4747
|
+
assertNonEthBase: "deposits.eth-nonbase:assertNonEthBase",
|
|
4748
|
+
assertEthBalance: "deposits.eth-nonbase:assertEthBalance"
|
|
4749
|
+
}
|
|
4750
|
+
};
|
|
4751
|
+
var OP_WITHDRAWALS = {
|
|
4752
|
+
quote: "withdrawals.quote",
|
|
4753
|
+
tryQuote: "withdrawals.tryQuote",
|
|
4754
|
+
prepare: "withdrawals.prepare",
|
|
4755
|
+
tryPrepare: "withdrawals.tryPrepare",
|
|
4756
|
+
create: "withdrawals.create",
|
|
4757
|
+
tryCreate: "withdrawals.tryCreate",
|
|
4758
|
+
status: "withdrawals.status",
|
|
4759
|
+
wait: "withdrawals.wait",
|
|
4760
|
+
tryWait: "withdrawals.tryWait",
|
|
4761
|
+
erc20: {
|
|
4762
|
+
allowance: "withdrawals.erc20:allowance",
|
|
4763
|
+
ensureRegistered: "withdrawals.erc20:ensureTokenIsRegistered",
|
|
4764
|
+
encodeAssetData: "withdrawals.erc20:encodeAssetData",
|
|
4765
|
+
encodeWithdraw: "withdrawals.erc20:encodeWithdraw",
|
|
4766
|
+
estGas: "withdrawals.erc20:estimateGas"
|
|
4767
|
+
},
|
|
4768
|
+
eth: {
|
|
4769
|
+
encodeWithdraw: "withdrawals.eth:encodeWithdraw",
|
|
4770
|
+
estGas: "withdrawals.eth:estimateGas"
|
|
4771
|
+
},
|
|
4772
|
+
ethNonBase: {
|
|
4773
|
+
allowance: "withdrawals.eth-nonbase:allowance",
|
|
4774
|
+
ensureRegistered: "withdrawals.eth-nonbase:ensureTokenIsRegistered",
|
|
4775
|
+
encodeAssetData: "withdrawals.eth-nonbase:encodeAssetData",
|
|
4776
|
+
encodeWithdraw: "withdrawals.eth-nonbase:encodeWithdraw",
|
|
4777
|
+
estGas: "withdrawals.eth-nonbase:estimateGas",
|
|
4778
|
+
baseToken: "withdrawals.eth-nonbase:baseToken",
|
|
4779
|
+
assertNonEthBase: "withdrawals.eth-nonbase:assertNonEthBase"
|
|
4780
|
+
},
|
|
4781
|
+
finalize: {
|
|
4782
|
+
fetchParams: {
|
|
4783
|
+
receipt: "withdrawals.finalize.fetchParams:receipt",
|
|
4784
|
+
findMessage: "withdrawals.finalize.fetchParams:findMessage",
|
|
4785
|
+
decodeMessage: "withdrawals.finalize.fetchParams:decodeMessage",
|
|
4786
|
+
rawReceipt: "withdrawals.finalize.fetchParams:rawReceipt",
|
|
4787
|
+
messengerIndex: "withdrawals.finalize.fetchParams:messengerIndex",
|
|
4788
|
+
proof: "withdrawals.finalize.fetchParams:proof",
|
|
4789
|
+
network: "withdrawals.finalize.fetchParams:network",
|
|
4790
|
+
ensureAddresses: "withdrawals.finalize.fetchParams:ensureAddresses"
|
|
4791
|
+
},
|
|
4792
|
+
readiness: {
|
|
4793
|
+
ensureAddresses: "withdrawals.finalize.readiness:ensureAddresses",
|
|
4794
|
+
isFinalized: "withdrawals.finalize.readiness:isWithdrawalFinalized",
|
|
4795
|
+
simulate: "withdrawals.finalize.readiness:simulate"
|
|
4796
|
+
},
|
|
4797
|
+
isFinalized: "withdrawals.finalize.isWithdrawalFinalized",
|
|
4798
|
+
send: "withdrawals.finalize.finalizeDeposit:send",
|
|
4799
|
+
wait: "withdrawals.finalize.finalizeDeposit:wait",
|
|
4800
|
+
estimate: "withdrawals.finalize.estimateFinalizationFees"
|
|
4801
|
+
}
|
|
4802
|
+
};
|
|
4803
|
+
|
|
4804
|
+
// src/core/errors/factory.ts
|
|
4805
|
+
var factory_exports = {};
|
|
4806
|
+
__export(factory_exports, {
|
|
4807
|
+
createError: () => createError,
|
|
4808
|
+
shapeCause: () => shapeCause
|
|
4809
|
+
});
|
|
4810
|
+
function createError(type, input) {
|
|
4811
|
+
return new ZKsyncError({ ...input, type });
|
|
4812
|
+
}
|
|
4813
|
+
function shapeCause(err) {
|
|
4814
|
+
const isRecord = (x) => x !== null && typeof x === "object";
|
|
4815
|
+
let data = void 0;
|
|
4816
|
+
if (isRecord(err)) {
|
|
4817
|
+
const r2 = err;
|
|
4818
|
+
const d = r2.data;
|
|
4819
|
+
if (isRecord(d) && "data" in d) {
|
|
4820
|
+
data = d.data;
|
|
4821
|
+
} else if ("error" in r2 && isRecord(r2.error) && "data" in r2.error) {
|
|
4822
|
+
data = r2.error.data;
|
|
4823
|
+
} else if ("data" in r2) {
|
|
4824
|
+
data = r2.data;
|
|
4825
|
+
}
|
|
4826
|
+
}
|
|
4827
|
+
const r = isRecord(err) ? err : void 0;
|
|
4828
|
+
const name = r && typeof r.name === "string" ? r.name : void 0;
|
|
4829
|
+
const message = r && typeof r.message === "string" ? r.message : r && typeof r.shortMessage === "string" ? r.shortMessage : void 0;
|
|
4830
|
+
const code = r && "code" in r ? r.code : void 0;
|
|
4831
|
+
return {
|
|
4832
|
+
name,
|
|
4833
|
+
message,
|
|
4834
|
+
code,
|
|
4835
|
+
data: typeof data === "string" && data.startsWith("0x") ? `${data.slice(0, 10)}\u2026` : void 0
|
|
4836
|
+
};
|
|
4837
|
+
}
|
|
4838
|
+
|
|
4839
|
+
export { IBaseToken_default, IBridgehub_default, IERC20_default, IL1AssetRouter_default, IL1Nullifier_default, IL2AssetRouter_default, L1NativeTokenVault_default, L2NativeTokenVault_default, Mailbox_default, OP_DEPOSITS, OP_WITHDRAWALS, abi_exports, createError, factory_exports, formatEnvelopePretty, isReceiptNotFound, isZKsyncError, shapeCause };
|
|
@@ -1,16 +1,3 @@
|
|
|
1
|
-
// src/core/utils/gas.ts
|
|
2
|
-
function assertNoLegacyGas(overrides) {
|
|
3
|
-
if (!overrides) return;
|
|
4
|
-
if ("gasPrice" in overrides && overrides.gasPrice !== void 0) {
|
|
5
|
-
throw new Error("Legacy gasPrice is not supported; use EIP-1559 fields instead.");
|
|
6
|
-
}
|
|
7
|
-
}
|
|
8
|
-
function assertPriorityFeeBounds(fees) {
|
|
9
|
-
if (fees.maxPriorityFeePerGas > fees.maxFeePerGas) {
|
|
10
|
-
throw new Error("maxPriorityFeePerGas cannot exceed maxFeePerGas.");
|
|
11
|
-
}
|
|
12
|
-
}
|
|
13
|
-
|
|
14
1
|
// src/core/errors/withdrawal-revert-map.ts
|
|
15
2
|
var REVERT_TO_READINESS = {
|
|
16
3
|
// Already done
|
|
@@ -33,4 +20,4 @@ var REVERT_TO_READINESS = {
|
|
|
33
20
|
LocalRootMustBeZero: { kind: "UNFINALIZABLE", reason: "unsupported" }
|
|
34
21
|
};
|
|
35
22
|
|
|
36
|
-
export { REVERT_TO_READINESS
|
|
23
|
+
export { REVERT_TO_READINESS };
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { FORMAL_ETH_ADDRESS, L2_BASE_TOKEN_ADDRESS,
|
|
1
|
+
import { ETH_ADDRESS, FORMAL_ETH_ADDRESS, L2_BASE_TOKEN_ADDRESS, L2_ASSET_ROUTER_ADDRESS, L1_MESSENGER_ADDRESS, TOPIC_L1_MESSAGE_SENT_NEW, TOPIC_L1_MESSAGE_SENT_LEG } from './chunk-F2ENUV3A.js';
|
|
2
2
|
|
|
3
3
|
// src/core/utils/addr.ts
|
|
4
4
|
var isHash66 = (x) => !!x && x.startsWith("0x") && x.length === 66;
|
|
@@ -17,16 +17,8 @@ function normalizeAddrEq(a, b) {
|
|
|
17
17
|
};
|
|
18
18
|
return normalize(a) === normalize(b);
|
|
19
19
|
}
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
async function pickDepositRoute(client, chainIdL2, token) {
|
|
23
|
-
if (isETH(token)) {
|
|
24
|
-
const base2 = await client.baseToken(chainIdL2);
|
|
25
|
-
return isETH(base2) ? "eth-base" : "eth-nonbase";
|
|
26
|
-
}
|
|
27
|
-
const base = await client.baseToken(chainIdL2);
|
|
28
|
-
return normalizeAddrEq(token, base) ? "erc20-base" : "erc20-nonbase";
|
|
29
|
-
}
|
|
20
|
+
var hexEq = (a, b) => a.toLowerCase() === b.toLowerCase();
|
|
21
|
+
var normalizeL1Token = (token) => isAddressEq(token, FORMAL_ETH_ADDRESS) ? ETH_ADDRESS : token;
|
|
30
22
|
|
|
31
23
|
// src/core/resources/withdrawals/route.ts
|
|
32
24
|
function normalizeTokenForRouting(token) {
|
|
@@ -37,7 +29,7 @@ function normalizeTokenForRouting(token) {
|
|
|
37
29
|
function pickWithdrawRoute(args) {
|
|
38
30
|
const tokenNorm = normalizeTokenForRouting(args.token);
|
|
39
31
|
const isL2BaseAlias = tokenNorm.toLowerCase() === L2_BASE_TOKEN_ADDRESS.toLowerCase();
|
|
40
|
-
if (isL2BaseAlias) return
|
|
32
|
+
if (isL2BaseAlias) return "base";
|
|
41
33
|
return "erc20-nonbase";
|
|
42
34
|
}
|
|
43
35
|
|
|
@@ -73,4 +65,4 @@ function messengerLogIndex(raw, opts) {
|
|
|
73
65
|
return (hits[index] ?? hits[0]).i;
|
|
74
66
|
}
|
|
75
67
|
|
|
76
|
-
export { findL1MessageSentLog, isAddressEq, isETH, isHash66, messengerLogIndex, normalizeAddrEq,
|
|
68
|
+
export { findL1MessageSentLog, hexEq, isAddressEq, isETH, isHash66, messengerLogIndex, normalizeAddrEq, normalizeL1Token, pickWithdrawRoute };
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { isETH, normalizeAddrEq } from './chunk-NEC2ZKHI.js';
|
|
2
|
+
|
|
3
|
+
// src/core/resources/deposits/route.ts
|
|
4
|
+
async function pickDepositRoute(client, chainIdL2, token) {
|
|
5
|
+
if (isETH(token)) {
|
|
6
|
+
const base2 = await client.baseToken(chainIdL2);
|
|
7
|
+
return isETH(base2) ? "eth-base" : "eth-nonbase";
|
|
8
|
+
}
|
|
9
|
+
const base = await client.baseToken(chainIdL2);
|
|
10
|
+
return normalizeAddrEq(token, base) ? "erc20-base" : "erc20-nonbase";
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export { pickDepositRoute };
|