@matterlabs/zksync-js 0.0.1 → 0.0.2
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 +934 -801
- package/dist/adapters/ethers/index.cjs.map +1 -1
- package/dist/adapters/ethers/index.js +9 -8
- package/dist/adapters/ethers/resources/deposits/context.d.ts +5 -5
- 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 +40 -0
- package/dist/adapters/ethers/resources/utils.d.ts +4 -15
- package/dist/adapters/ethers/resources/withdrawals/context.d.ts +4 -4
- 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 +947 -1292
- package/dist/adapters/ethers/sdk.cjs.map +1 -1
- 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 +944 -662
- package/dist/adapters/viem/index.cjs.map +1 -1
- package/dist/adapters/viem/index.js +8 -8
- package/dist/adapters/viem/resources/deposits/context.d.ts +5 -5
- 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 +36 -0
- package/dist/adapters/viem/resources/utils.d.ts +3 -16
- package/dist/adapters/viem/resources/withdrawals/context.d.ts +3 -6
- 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 +877 -563
- package/dist/adapters/viem/sdk.cjs.map +1 -1
- package/dist/adapters/viem/sdk.d.ts +1 -1
- package/dist/adapters/viem/sdk.js +6 -6
- package/dist/{chunk-3LALBFFE.js → chunk-3MRGU4HV.js} +9 -5
- package/dist/{chunk-4HLJJKIY.js → chunk-6K6VJQAL.js} +2 -2
- package/dist/{chunk-CGO27P7F.js → chunk-BCCKWWOX.js} +540 -741
- package/dist/{chunk-6GCT6TLS.js → chunk-F2ENUV3A.js} +13 -1
- package/dist/{chunk-DI2CJDPZ.js → chunk-HLUANWGN.js} +2 -2
- package/dist/{chunk-Y75OMFK6.js → chunk-M5J2MM2U.js} +351 -1
- package/dist/{chunk-263G6636.js → chunk-NCAIVYBR.js} +1 -14
- package/dist/{chunk-7M4V3FMT.js → chunk-OC6ZVLSP.js} +669 -559
- package/dist/chunk-QJS6ETEE.js +217 -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/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 +4504 -1
- package/dist/core/index.cjs.map +1 -1
- package/dist/core/index.d.ts +1 -0
- package/dist/core/index.js +4 -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/withdrawals.d.ts +12 -6
- package/dist/index.cjs +4516 -1
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +1 -0
- package/dist/index.js +4 -4
- package/package.json +5 -1
- package/dist/adapters/ethers/resources/withdrawals/routes/eth-nonbase.d.ts +0 -2
- 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,217 @@
|
|
|
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/resources/deposits/fee.ts
|
|
5
|
+
function buildFeeBreakdown(p) {
|
|
6
|
+
const l1MaxTotal = p.l1Gas?.maxCost ?? 0n;
|
|
7
|
+
const l2Total = p.l2BaseCost + p.operatorTip;
|
|
8
|
+
const l1 = {
|
|
9
|
+
gasLimit: p.l1Gas?.gasLimit ?? 0n,
|
|
10
|
+
maxFeePerGas: p.l1Gas?.maxFeePerGas ?? 0n,
|
|
11
|
+
maxPriorityFeePerGas: p.l1Gas?.maxPriorityFeePerGas,
|
|
12
|
+
maxTotal: l1MaxTotal
|
|
13
|
+
};
|
|
14
|
+
const l2 = {
|
|
15
|
+
total: l2Total,
|
|
16
|
+
baseCost: p.l2BaseCost,
|
|
17
|
+
operatorTip: p.operatorTip,
|
|
18
|
+
gasLimit: p.l2Gas?.gasLimit ?? 0n,
|
|
19
|
+
maxFeePerGas: p.l2Gas?.maxFeePerGas ?? 0n,
|
|
20
|
+
maxPriorityFeePerGas: p.l2Gas?.maxPriorityFeePerGas,
|
|
21
|
+
gasPerPubdata: p.l2Gas?.gasPerPubdata ?? 0n
|
|
22
|
+
};
|
|
23
|
+
return {
|
|
24
|
+
token: p.feeToken,
|
|
25
|
+
maxTotal: l1MaxTotal + l2Total,
|
|
26
|
+
mintValue: p.mintValue,
|
|
27
|
+
l1,
|
|
28
|
+
l2
|
|
29
|
+
};
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
// src/core/resources/deposits/gas.ts
|
|
33
|
+
function makeGasQuote(p) {
|
|
34
|
+
const maxPriorityFeePerGas = p.maxPriorityFeePerGas ?? 0n;
|
|
35
|
+
return {
|
|
36
|
+
gasLimit: p.gasLimit,
|
|
37
|
+
maxFeePerGas: p.maxFeePerGas,
|
|
38
|
+
maxPriorityFeePerGas,
|
|
39
|
+
gasPerPubdata: p.gasPerPubdata,
|
|
40
|
+
maxCost: p.gasLimit * p.maxFeePerGas
|
|
41
|
+
};
|
|
42
|
+
}
|
|
43
|
+
async function fetchFees(estimator) {
|
|
44
|
+
try {
|
|
45
|
+
const fees = await estimator.estimateFeesPerGas();
|
|
46
|
+
if (fees.maxFeePerGas != null) {
|
|
47
|
+
return {
|
|
48
|
+
maxFeePerGas: fees.maxFeePerGas,
|
|
49
|
+
maxPriorityFeePerGas: fees.maxPriorityFeePerGas ?? 0n
|
|
50
|
+
};
|
|
51
|
+
}
|
|
52
|
+
if (fees.gasPrice != null) {
|
|
53
|
+
return {
|
|
54
|
+
maxFeePerGas: fees.gasPrice,
|
|
55
|
+
maxPriorityFeePerGas: 0n
|
|
56
|
+
};
|
|
57
|
+
}
|
|
58
|
+
} catch {
|
|
59
|
+
}
|
|
60
|
+
try {
|
|
61
|
+
const gp = await estimator.getGasPrice();
|
|
62
|
+
return { maxFeePerGas: gp, maxPriorityFeePerGas: 0n };
|
|
63
|
+
} catch {
|
|
64
|
+
return { maxFeePerGas: 0n, maxPriorityFeePerGas: 0n };
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
async function quoteL1Gas(input) {
|
|
68
|
+
const { estimator, tx, overrides, fallbackGasLimit } = input;
|
|
69
|
+
let market;
|
|
70
|
+
const getMarket = async () => {
|
|
71
|
+
if (market) return market;
|
|
72
|
+
market = await fetchFees(estimator);
|
|
73
|
+
return market;
|
|
74
|
+
};
|
|
75
|
+
const maxFeePerGas = overrides?.maxFeePerGas ?? (tx.maxFeePerGas != null ? BigInt(tx.maxFeePerGas) : (await getMarket()).maxFeePerGas);
|
|
76
|
+
const maxPriorityFeePerGas = overrides?.maxPriorityFeePerGas ?? (tx.maxPriorityFeePerGas != null ? BigInt(tx.maxPriorityFeePerGas) : (await getMarket()).maxPriorityFeePerGas);
|
|
77
|
+
const explicitGasLimit = overrides?.gasLimit ?? (tx.gasLimit != null ? BigInt(tx.gasLimit) : void 0);
|
|
78
|
+
if (explicitGasLimit != null) {
|
|
79
|
+
return makeGasQuote({ gasLimit: explicitGasLimit, maxFeePerGas, maxPriorityFeePerGas });
|
|
80
|
+
}
|
|
81
|
+
try {
|
|
82
|
+
const est = await estimator.estimateGas(tx);
|
|
83
|
+
const buffered = BigInt(est) * (100n + BUFFER) / 100n;
|
|
84
|
+
return makeGasQuote({ gasLimit: buffered, maxFeePerGas, maxPriorityFeePerGas });
|
|
85
|
+
} catch (err) {
|
|
86
|
+
if (fallbackGasLimit != null) {
|
|
87
|
+
return makeGasQuote({ gasLimit: fallbackGasLimit, maxFeePerGas, maxPriorityFeePerGas });
|
|
88
|
+
}
|
|
89
|
+
console.warn("L1 gas estimation failed", err);
|
|
90
|
+
return void 0;
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
async function quoteL2Gas(input) {
|
|
94
|
+
const { estimator, route, tx, gasPerPubdata, l2GasLimit, overrideGasLimit, stateOverrides } = input;
|
|
95
|
+
const market = await fetchFees(estimator);
|
|
96
|
+
const maxFeePerGas = market.maxFeePerGas || market.maxPriorityFeePerGas || 0n;
|
|
97
|
+
const txGasLimit = tx?.gasLimit != null ? BigInt(tx.gasLimit) : void 0;
|
|
98
|
+
const explicit = overrideGasLimit ?? txGasLimit;
|
|
99
|
+
if (explicit != null) {
|
|
100
|
+
return makeGasQuote({
|
|
101
|
+
gasLimit: explicit,
|
|
102
|
+
maxFeePerGas,
|
|
103
|
+
gasPerPubdata
|
|
104
|
+
});
|
|
105
|
+
}
|
|
106
|
+
if (!tx) {
|
|
107
|
+
return makeGasQuote({
|
|
108
|
+
gasLimit: l2GasLimit ?? 0n,
|
|
109
|
+
maxFeePerGas,
|
|
110
|
+
gasPerPubdata
|
|
111
|
+
});
|
|
112
|
+
}
|
|
113
|
+
try {
|
|
114
|
+
const execEstimate = await estimator.estimateGas(tx, stateOverrides);
|
|
115
|
+
const memoryBytes = route === "erc20-nonbase" ? 500n : DEFAULT_ABI_BYTES;
|
|
116
|
+
const pubdataBytes = route === "erc20-nonbase" ? 200n : DEFAULT_PUBDATA_BYTES;
|
|
117
|
+
const pp = gasPerPubdata ?? 800n;
|
|
118
|
+
const memoryOverhead = memoryBytes * TX_MEMORY_OVERHEAD_GAS;
|
|
119
|
+
const pubdataOverhead = pubdataBytes * pp;
|
|
120
|
+
let total = BigInt(execEstimate) + TX_OVERHEAD_GAS + memoryOverhead + pubdataOverhead;
|
|
121
|
+
total = total * (100n + BUFFER) / 100n;
|
|
122
|
+
return makeGasQuote({
|
|
123
|
+
gasLimit: total,
|
|
124
|
+
maxFeePerGas,
|
|
125
|
+
gasPerPubdata: pp
|
|
126
|
+
});
|
|
127
|
+
} catch (err) {
|
|
128
|
+
console.warn("L2 gas estimation failed", err);
|
|
129
|
+
return makeGasQuote({
|
|
130
|
+
gasLimit: l2GasLimit ?? 0n,
|
|
131
|
+
maxFeePerGas,
|
|
132
|
+
gasPerPubdata
|
|
133
|
+
});
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
async function quoteL2BaseCost(input) {
|
|
137
|
+
const { estimator, encode, bridgehub, chainIdL2, l2GasLimit, gasPerPubdata } = input;
|
|
138
|
+
const market = await fetchFees(estimator);
|
|
139
|
+
const l1GasPrice = market.maxFeePerGas || market.maxPriorityFeePerGas || 0n;
|
|
140
|
+
if (l1GasPrice === 0n) {
|
|
141
|
+
throw new Error("Could not fetch L1 gas price for Bridgehub base cost calculation.");
|
|
142
|
+
}
|
|
143
|
+
const data = encode(IBridgehub_default, "l2TransactionBaseCost", [
|
|
144
|
+
chainIdL2,
|
|
145
|
+
l1GasPrice,
|
|
146
|
+
l2GasLimit,
|
|
147
|
+
gasPerPubdata
|
|
148
|
+
]);
|
|
149
|
+
const raw = await estimator.call({
|
|
150
|
+
to: bridgehub,
|
|
151
|
+
data
|
|
152
|
+
});
|
|
153
|
+
return BigInt(raw);
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
// src/core/resources/withdrawals/gas.ts
|
|
157
|
+
function makeGasQuote2(p) {
|
|
158
|
+
return {
|
|
159
|
+
gasLimit: p.gasLimit,
|
|
160
|
+
maxFeePerGas: p.maxFeePerGas,
|
|
161
|
+
maxPriorityFeePerGas: p.maxPriorityFeePerGas,
|
|
162
|
+
maxCost: p.gasLimit * p.maxFeePerGas
|
|
163
|
+
};
|
|
164
|
+
}
|
|
165
|
+
async function fetchFees2(estimator) {
|
|
166
|
+
try {
|
|
167
|
+
const fees = await estimator.estimateFeesPerGas();
|
|
168
|
+
if (fees.maxFeePerGas != null) {
|
|
169
|
+
return {
|
|
170
|
+
maxFeePerGas: fees.maxFeePerGas,
|
|
171
|
+
maxPriorityFeePerGas: fees.maxPriorityFeePerGas ?? 0n
|
|
172
|
+
};
|
|
173
|
+
}
|
|
174
|
+
if (fees.gasPrice != null) {
|
|
175
|
+
return {
|
|
176
|
+
maxFeePerGas: fees.gasPrice,
|
|
177
|
+
maxPriorityFeePerGas: 0n
|
|
178
|
+
};
|
|
179
|
+
}
|
|
180
|
+
} catch {
|
|
181
|
+
}
|
|
182
|
+
try {
|
|
183
|
+
const gp = await estimator.getGasPrice();
|
|
184
|
+
return { maxFeePerGas: gp, maxPriorityFeePerGas: 0n };
|
|
185
|
+
} catch {
|
|
186
|
+
return { maxFeePerGas: 0n, maxPriorityFeePerGas: 0n };
|
|
187
|
+
}
|
|
188
|
+
}
|
|
189
|
+
async function quoteL2Gas2(input) {
|
|
190
|
+
const { estimator, tx, overrides } = input;
|
|
191
|
+
const market = await fetchFees2(estimator);
|
|
192
|
+
const o = overrides;
|
|
193
|
+
const maxFeePerGas = o?.maxFeePerGas ?? (tx.maxFeePerGas != null ? BigInt(tx.maxFeePerGas) : market.maxFeePerGas);
|
|
194
|
+
const maxPriorityFeePerGas = o?.maxPriorityFeePerGas ?? (tx.maxPriorityFeePerGas != null ? BigInt(tx.maxPriorityFeePerGas) : market.maxPriorityFeePerGas);
|
|
195
|
+
const explicitGasLimit = o?.gasLimit ?? (tx.gasLimit != null ? BigInt(tx.gasLimit) : void 0);
|
|
196
|
+
if (explicitGasLimit != null) {
|
|
197
|
+
return makeGasQuote2({
|
|
198
|
+
gasLimit: explicitGasLimit,
|
|
199
|
+
maxFeePerGas,
|
|
200
|
+
maxPriorityFeePerGas
|
|
201
|
+
});
|
|
202
|
+
}
|
|
203
|
+
try {
|
|
204
|
+
const est = await estimator.estimateGas(tx);
|
|
205
|
+
const buffered = BigInt(est) * (100n + BUFFER) / 100n;
|
|
206
|
+
return makeGasQuote2({
|
|
207
|
+
gasLimit: buffered,
|
|
208
|
+
maxFeePerGas,
|
|
209
|
+
maxPriorityFeePerGas
|
|
210
|
+
});
|
|
211
|
+
} catch (err) {
|
|
212
|
+
console.warn("Failed to estimate L2 gas for withdrawal.", err);
|
|
213
|
+
return void 0;
|
|
214
|
+
}
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
export { buildFeeBreakdown, quoteL1Gas, quoteL2BaseCost, quoteL2Gas, quoteL2Gas2 };
|
|
@@ -0,0 +1,157 @@
|
|
|
1
|
+
import { REVERT_TO_READINESS } from './chunk-NCAIVYBR.js';
|
|
2
|
+
import { IL1Nullifier_default, IERC20_default, L1NativeTokenVault_default, L2NativeTokenVault_default, Mailbox_default, isZKsyncError, createError, shapeCause } from './chunk-M5J2MM2U.js';
|
|
3
|
+
import { Interface } from 'ethers';
|
|
4
|
+
|
|
5
|
+
var ERROR_IFACES = [];
|
|
6
|
+
var IFACE_ERROR_STRING = new Interface(["error Error(string)"]);
|
|
7
|
+
var IFACE_PANIC = new Interface(["error Panic(uint256)"]);
|
|
8
|
+
(function bootstrapDefaultIfaces() {
|
|
9
|
+
try {
|
|
10
|
+
ERROR_IFACES.push({
|
|
11
|
+
name: "IL1Nullifier",
|
|
12
|
+
iface: new Interface(IL1Nullifier_default)
|
|
13
|
+
});
|
|
14
|
+
} catch {
|
|
15
|
+
}
|
|
16
|
+
try {
|
|
17
|
+
ERROR_IFACES.push({ name: "IERC20", iface: new Interface(IERC20_default) });
|
|
18
|
+
} catch {
|
|
19
|
+
}
|
|
20
|
+
try {
|
|
21
|
+
ERROR_IFACES.push({
|
|
22
|
+
name: "IL1NativeTokenVault",
|
|
23
|
+
iface: new Interface(L1NativeTokenVault_default)
|
|
24
|
+
});
|
|
25
|
+
} catch {
|
|
26
|
+
}
|
|
27
|
+
try {
|
|
28
|
+
ERROR_IFACES.push({
|
|
29
|
+
name: "IL2NativeTokenVault",
|
|
30
|
+
iface: new Interface(L2NativeTokenVault_default)
|
|
31
|
+
});
|
|
32
|
+
} catch {
|
|
33
|
+
}
|
|
34
|
+
try {
|
|
35
|
+
ERROR_IFACES.push({ name: "Mailbox", iface: new Interface(Mailbox_default) });
|
|
36
|
+
} catch {
|
|
37
|
+
}
|
|
38
|
+
})();
|
|
39
|
+
function registerErrorAbi(name, abi) {
|
|
40
|
+
const existing = ERROR_IFACES.findIndex((x) => x.name === name);
|
|
41
|
+
const entry = { name, iface: new Interface(abi) };
|
|
42
|
+
if (existing >= 0) ERROR_IFACES[existing] = entry;
|
|
43
|
+
else ERROR_IFACES.push(entry);
|
|
44
|
+
}
|
|
45
|
+
function extractRevertData(e) {
|
|
46
|
+
const maybe = (
|
|
47
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
|
|
48
|
+
e?.data?.data ?? e?.error?.data ?? e?.data ?? e?.error?.error?.data ?? e?.info?.error?.data
|
|
49
|
+
);
|
|
50
|
+
if (typeof maybe === "string" && maybe.startsWith("0x") && maybe.length >= 10) {
|
|
51
|
+
return maybe;
|
|
52
|
+
}
|
|
53
|
+
return void 0;
|
|
54
|
+
}
|
|
55
|
+
function decodeRevert(e) {
|
|
56
|
+
const data = extractRevertData(e);
|
|
57
|
+
if (!data) return;
|
|
58
|
+
const selector = `0x${data.slice(2, 10)}`;
|
|
59
|
+
try {
|
|
60
|
+
const parsed = IFACE_ERROR_STRING.parseError(data);
|
|
61
|
+
if (parsed?.name === "Error") {
|
|
62
|
+
const args = parsed.args ? Array.from(parsed.args) : void 0;
|
|
63
|
+
return { selector, name: "Error", args };
|
|
64
|
+
}
|
|
65
|
+
} catch {
|
|
66
|
+
}
|
|
67
|
+
try {
|
|
68
|
+
const parsed = IFACE_PANIC.parseError(data);
|
|
69
|
+
if (parsed?.name === "Panic") {
|
|
70
|
+
const args = parsed.args ? Array.from(parsed.args) : void 0;
|
|
71
|
+
return { selector, name: "Panic", args };
|
|
72
|
+
}
|
|
73
|
+
} catch {
|
|
74
|
+
}
|
|
75
|
+
for (const { name, iface } of ERROR_IFACES) {
|
|
76
|
+
try {
|
|
77
|
+
const parsed = iface.parseError(data);
|
|
78
|
+
if (parsed) {
|
|
79
|
+
const args = parsed.args ? Array.from(parsed.args) : void 0;
|
|
80
|
+
return {
|
|
81
|
+
selector,
|
|
82
|
+
name: parsed.name,
|
|
83
|
+
args,
|
|
84
|
+
contract: name
|
|
85
|
+
};
|
|
86
|
+
}
|
|
87
|
+
} catch {
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
return { selector };
|
|
91
|
+
}
|
|
92
|
+
function classifyReadinessFromRevert(e) {
|
|
93
|
+
const r = decodeRevert(e);
|
|
94
|
+
const name = r?.name;
|
|
95
|
+
if (name && REVERT_TO_READINESS[name]) return REVERT_TO_READINESS[name];
|
|
96
|
+
const msg = (() => {
|
|
97
|
+
if (typeof e !== "object" || e === null) return "";
|
|
98
|
+
const obj = e;
|
|
99
|
+
const maybeMsg = obj["shortMessage"] ?? obj["message"];
|
|
100
|
+
return typeof maybeMsg === "string" ? maybeMsg : "";
|
|
101
|
+
})();
|
|
102
|
+
const lower = String(msg).toLowerCase();
|
|
103
|
+
if (lower.includes("paused")) return { kind: "NOT_READY", reason: "paused" };
|
|
104
|
+
if (name || r?.selector) {
|
|
105
|
+
return { kind: "UNFINALIZABLE", reason: "unsupported", detail: name ?? r?.selector };
|
|
106
|
+
}
|
|
107
|
+
return { kind: "NOT_READY", reason: "unknown", detail: lower || void 0 };
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
// src/adapters/ethers/errors/error-ops.ts
|
|
111
|
+
function toZKsyncError(type, base, err) {
|
|
112
|
+
if (isZKsyncError(err)) return err;
|
|
113
|
+
const revert = decodeRevert(err);
|
|
114
|
+
return createError(type, { ...base, ...revert ? { revert } : {}, cause: shapeCause(err) });
|
|
115
|
+
}
|
|
116
|
+
function resolveMessage(op, msg) {
|
|
117
|
+
if (!msg) return `Error during ${op}.`;
|
|
118
|
+
return typeof msg === "function" ? msg() : msg;
|
|
119
|
+
}
|
|
120
|
+
function createErrorHandlers(resource) {
|
|
121
|
+
async function run(kind, operation, fn, opts) {
|
|
122
|
+
try {
|
|
123
|
+
return await fn();
|
|
124
|
+
} catch (e) {
|
|
125
|
+
if (isZKsyncError(e)) throw e;
|
|
126
|
+
const message = resolveMessage(operation, opts?.message);
|
|
127
|
+
throw toZKsyncError(kind, { resource, operation, context: opts?.ctx ?? {}, message }, e);
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
function wrap(operation, fn, opts) {
|
|
131
|
+
return run("INTERNAL", operation, fn, opts);
|
|
132
|
+
}
|
|
133
|
+
function wrapAs(kind, operation, fn, opts) {
|
|
134
|
+
return run(kind, operation, fn, opts);
|
|
135
|
+
}
|
|
136
|
+
async function toResult(operation, fn, opts) {
|
|
137
|
+
try {
|
|
138
|
+
const value = await wrap(operation, fn, opts);
|
|
139
|
+
return { ok: true, value };
|
|
140
|
+
} catch (e) {
|
|
141
|
+
const shaped = isZKsyncError(e) ? e : toZKsyncError(
|
|
142
|
+
"INTERNAL",
|
|
143
|
+
{
|
|
144
|
+
resource,
|
|
145
|
+
operation,
|
|
146
|
+
context: opts?.ctx ?? {},
|
|
147
|
+
message: resolveMessage(operation, opts?.message)
|
|
148
|
+
},
|
|
149
|
+
e
|
|
150
|
+
);
|
|
151
|
+
return { ok: false, error: shaped };
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
return { wrap, wrapAs, toResult };
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
export { classifyReadinessFromRevert, createErrorHandlers, decodeRevert, registerErrorAbi, toZKsyncError };
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { createZksRpc, makeTransportFromViem } from './chunk-
|
|
2
|
-
import { IBridgehub_default, IL1AssetRouter_default, IL1Nullifier_default, IBaseToken_default, L2NativeTokenVault_default, IL2AssetRouter_default, L1NativeTokenVault_default } from './chunk-
|
|
3
|
-
import { L2_ASSET_ROUTER_ADDRESS, L2_NATIVE_TOKEN_VAULT_ADDRESS, L2_BASE_TOKEN_ADDRESS } from './chunk-
|
|
1
|
+
import { createZksRpc, makeTransportFromViem } from './chunk-6K6VJQAL.js';
|
|
2
|
+
import { IBridgehub_default, IL1AssetRouter_default, IL1Nullifier_default, IBaseToken_default, L2NativeTokenVault_default, IL2AssetRouter_default, L1NativeTokenVault_default } from './chunk-M5J2MM2U.js';
|
|
3
|
+
import { L2_ASSET_ROUTER_ADDRESS, L2_NATIVE_TOKEN_VAULT_ADDRESS, L2_BASE_TOKEN_ADDRESS } from './chunk-F2ENUV3A.js';
|
|
4
4
|
import { getContract, createWalletClient } from 'viem';
|
|
5
5
|
|
|
6
6
|
// src/adapters/viem/rpc.ts
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
export { default as IBridgehubABI } from './internal/abis/IBridgehub';
|
|
2
|
+
export { default as IL1AssetRouterABI } from './internal/abis/IL1AssetRouter';
|
|
3
|
+
export { default as IL1NullifierABI } from './internal/abis/IL1Nullifier';
|
|
4
|
+
export { default as IL2AssetRouterABI } from './internal/abis/IL2AssetRouter';
|
|
5
|
+
export { default as L1NativeTokenVaultABI } from './internal/abis/L1NativeTokenVault';
|
|
6
|
+
export { default as L2NativeTokenVaultABI } from './internal/abis/L2NativeTokenVault';
|
|
7
|
+
export { default as IBaseTokenABI } from './internal/abis/IBaseToken';
|
|
8
|
+
export { default as IERC20ABI } from './internal/abis/IERC20';
|
|
9
|
+
export { default as MailboxABI } from './internal/abis/Mailbox';
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import type { Address } from '../types/primitives';
|
|
2
|
+
export interface CoreTransactionRequest {
|
|
3
|
+
to: Address;
|
|
4
|
+
from?: Address;
|
|
5
|
+
data?: string;
|
|
6
|
+
value?: bigint;
|
|
7
|
+
gasLimit?: bigint;
|
|
8
|
+
maxFeePerGas?: bigint;
|
|
9
|
+
maxPriorityFeePerGas?: bigint;
|
|
10
|
+
}
|
|
11
|
+
export interface GasEstimator {
|
|
12
|
+
estimateGas(tx: CoreTransactionRequest, stateOverrides?: Record<string, unknown>): Promise<bigint>;
|
|
13
|
+
estimateFeesPerGas(): Promise<{
|
|
14
|
+
maxFeePerGas?: bigint;
|
|
15
|
+
maxPriorityFeePerGas?: bigint;
|
|
16
|
+
gasPrice?: bigint;
|
|
17
|
+
}>;
|
|
18
|
+
getGasPrice(): Promise<bigint>;
|
|
19
|
+
call(tx: {
|
|
20
|
+
to: Address;
|
|
21
|
+
data?: string;
|
|
22
|
+
value?: bigint;
|
|
23
|
+
from?: Address;
|
|
24
|
+
}): Promise<string>;
|
|
25
|
+
}
|
package/dist/core/constants.cjs
CHANGED
|
@@ -17,9 +17,18 @@ var TOPIC_L1_MESSAGE_SENT_NEW = k256hex("L1MessageSent(uint256,bytes32,bytes)");
|
|
|
17
17
|
var TOPIC_L1_MESSAGE_SENT_LEG = k256hex("L1MessageSent(address,bytes32,bytes)");
|
|
18
18
|
var TOPIC_CANONICAL_ASSIGNED = "0x779f441679936c5441b671969f37400b8c3ed0071cb47444431bf985754560df";
|
|
19
19
|
var TOPIC_CANONICAL_SUCCESS = "0xe4def01b981193a97a9e81230d7b9f31812ceaf23f864a828a82c687911cb2df";
|
|
20
|
+
var BUFFER = 20n;
|
|
21
|
+
var TX_OVERHEAD_GAS = 10000n;
|
|
22
|
+
var TX_MEMORY_OVERHEAD_GAS = 10n;
|
|
23
|
+
var DEFAULT_PUBDATA_BYTES = 155n;
|
|
24
|
+
var DEFAULT_ABI_BYTES = 400n;
|
|
25
|
+
var SAFE_L1_BRIDGE_GAS = 600000n;
|
|
20
26
|
var L1_FEE_ESTIMATION_COEF_NUMERATOR = 12;
|
|
21
27
|
var L1_FEE_ESTIMATION_COEF_DENOMINATOR = 10;
|
|
22
28
|
|
|
29
|
+
exports.BUFFER = BUFFER;
|
|
30
|
+
exports.DEFAULT_ABI_BYTES = DEFAULT_ABI_BYTES;
|
|
31
|
+
exports.DEFAULT_PUBDATA_BYTES = DEFAULT_PUBDATA_BYTES;
|
|
23
32
|
exports.ETH_ADDRESS = ETH_ADDRESS;
|
|
24
33
|
exports.FORMAL_ETH_ADDRESS = FORMAL_ETH_ADDRESS;
|
|
25
34
|
exports.L1_FEE_ESTIMATION_COEF_DENOMINATOR = L1_FEE_ESTIMATION_COEF_DENOMINATOR;
|
|
@@ -29,11 +38,14 @@ exports.L1_SOPH_TOKEN_ADDRESS = L1_SOPH_TOKEN_ADDRESS;
|
|
|
29
38
|
exports.L2_ASSET_ROUTER_ADDRESS = L2_ASSET_ROUTER_ADDRESS;
|
|
30
39
|
exports.L2_BASE_TOKEN_ADDRESS = L2_BASE_TOKEN_ADDRESS;
|
|
31
40
|
exports.L2_NATIVE_TOKEN_VAULT_ADDRESS = L2_NATIVE_TOKEN_VAULT_ADDRESS;
|
|
41
|
+
exports.SAFE_L1_BRIDGE_GAS = SAFE_L1_BRIDGE_GAS;
|
|
32
42
|
exports.TOPIC_CANONICAL_ASSIGNED = TOPIC_CANONICAL_ASSIGNED;
|
|
33
43
|
exports.TOPIC_CANONICAL_SUCCESS = TOPIC_CANONICAL_SUCCESS;
|
|
34
44
|
exports.TOPIC_L1_MESSAGE_SENT = TOPIC_L1_MESSAGE_SENT;
|
|
35
45
|
exports.TOPIC_L1_MESSAGE_SENT_LEG = TOPIC_L1_MESSAGE_SENT_LEG;
|
|
36
46
|
exports.TOPIC_L1_MESSAGE_SENT_NEW = TOPIC_L1_MESSAGE_SENT_NEW;
|
|
47
|
+
exports.TX_MEMORY_OVERHEAD_GAS = TX_MEMORY_OVERHEAD_GAS;
|
|
48
|
+
exports.TX_OVERHEAD_GAS = TX_OVERHEAD_GAS;
|
|
37
49
|
exports.k256hex = k256hex;
|
|
38
50
|
//# sourceMappingURL=constants.cjs.map
|
|
39
51
|
//# sourceMappingURL=constants.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/core/constants.ts"],"names":["bytesToHex","keccak_256","utf8ToBytes"],"mappings":";;;;;;AAQO,IAAM,OAAA,GAAU,CAAC,CAAA,KACtB,CAAA,EAAA,EAAKA,gBAAA,CAAWC,eAAA,CAAWC,iBAAA,CAAY,CAAC,CAAC,CAAC,CAAC,CAAA,CAAA,CAAG,WAAA;AAOzC,IAAM,kBAAA,GAA8B;AAGpC,IAAM,WAAA,GAAuB;AAG7B,IAAM,uBAAA,GAAmC;AAGzC,IAAM,6BAAA,GAAyC;AAG/C,IAAM,oBAAA,GAAgC;AAGtC,IAAM,qBAAA,GAAiC;AAGvC,IAAM,qBAAA,GAAiC;AAOvC,IAAM,qBAAA,GACX;AAGK,IAAM,yBAAA,GAAiC,QAAQ,sCAAsC;AAGrF,IAAM,yBAAA,GAAiC,QAAQ,sCAAsC;AAGrF,IAAM,wBAAA,GACX;AAGK,IAAM,uBAAA,GACX;
|
|
1
|
+
{"version":3,"sources":["../../src/core/constants.ts"],"names":["bytesToHex","keccak_256","utf8ToBytes"],"mappings":";;;;;;AAQO,IAAM,OAAA,GAAU,CAAC,CAAA,KACtB,CAAA,EAAA,EAAKA,gBAAA,CAAWC,eAAA,CAAWC,iBAAA,CAAY,CAAC,CAAC,CAAC,CAAC,CAAA,CAAA,CAAG,WAAA;AAOzC,IAAM,kBAAA,GAA8B;AAGpC,IAAM,WAAA,GAAuB;AAG7B,IAAM,uBAAA,GAAmC;AAGzC,IAAM,6BAAA,GAAyC;AAG/C,IAAM,oBAAA,GAAgC;AAGtC,IAAM,qBAAA,GAAiC;AAGvC,IAAM,qBAAA,GAAiC;AAOvC,IAAM,qBAAA,GACX;AAGK,IAAM,yBAAA,GAAiC,QAAQ,sCAAsC;AAGrF,IAAM,yBAAA,GAAiC,QAAQ,sCAAsC;AAGrF,IAAM,wBAAA,GACX;AAGK,IAAM,uBAAA,GACX;AASK,IAAM,MAAA,GAAS;AAEf,IAAM,eAAA,GAAkB;AAExB,IAAM,sBAAA,GAAyB;AAE/B,IAAM,qBAAA,GAAwB;AAE9B,IAAM,iBAAA,GAAoB;AAE1B,IAAM,kBAAA,GAAqB;AAM3B,IAAM,gCAAA,GAAmC;AAMzC,IAAM,kCAAA,GAAqC","file":"constants.cjs"}
|
package/dist/core/constants.d.ts
CHANGED
|
@@ -24,6 +24,12 @@ export declare const TOPIC_L1_MESSAGE_SENT_LEG: Hex;
|
|
|
24
24
|
export declare const TOPIC_CANONICAL_ASSIGNED: Hex;
|
|
25
25
|
/** Optional canonical success marker. */
|
|
26
26
|
export declare const TOPIC_CANONICAL_SUCCESS: Hex;
|
|
27
|
+
export declare const BUFFER = 20n;
|
|
28
|
+
export declare const TX_OVERHEAD_GAS = 10000n;
|
|
29
|
+
export declare const TX_MEMORY_OVERHEAD_GAS = 10n;
|
|
30
|
+
export declare const DEFAULT_PUBDATA_BYTES = 155n;
|
|
31
|
+
export declare const DEFAULT_ABI_BYTES = 400n;
|
|
32
|
+
export declare const SAFE_L1_BRIDGE_GAS = 600000n;
|
|
27
33
|
/**
|
|
28
34
|
* Numerator used in scaling the gas limit to help ensure acceptance of L1->L2 txs.
|
|
29
35
|
* Used with {@link L1_FEE_ESTIMATION_COEF_DENOMINATOR}.
|
package/dist/core/constants.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export { ETH_ADDRESS, FORMAL_ETH_ADDRESS, L1_FEE_ESTIMATION_COEF_DENOMINATOR, L1_FEE_ESTIMATION_COEF_NUMERATOR, L1_MESSENGER_ADDRESS, L1_SOPH_TOKEN_ADDRESS, L2_ASSET_ROUTER_ADDRESS, L2_BASE_TOKEN_ADDRESS, L2_NATIVE_TOKEN_VAULT_ADDRESS, TOPIC_CANONICAL_ASSIGNED, TOPIC_CANONICAL_SUCCESS, TOPIC_L1_MESSAGE_SENT, TOPIC_L1_MESSAGE_SENT_LEG, TOPIC_L1_MESSAGE_SENT_NEW, k256hex } from '../chunk-
|
|
1
|
+
export { BUFFER, DEFAULT_ABI_BYTES, DEFAULT_PUBDATA_BYTES, ETH_ADDRESS, FORMAL_ETH_ADDRESS, L1_FEE_ESTIMATION_COEF_DENOMINATOR, L1_FEE_ESTIMATION_COEF_NUMERATOR, L1_MESSENGER_ADDRESS, L1_SOPH_TOKEN_ADDRESS, L2_ASSET_ROUTER_ADDRESS, L2_BASE_TOKEN_ADDRESS, L2_NATIVE_TOKEN_VAULT_ADDRESS, SAFE_L1_BRIDGE_GAS, TOPIC_CANONICAL_ASSIGNED, TOPIC_CANONICAL_SUCCESS, TOPIC_L1_MESSAGE_SENT, TOPIC_L1_MESSAGE_SENT_LEG, TOPIC_L1_MESSAGE_SENT_NEW, TX_MEMORY_OVERHEAD_GAS, TX_OVERHEAD_GAS, k256hex } from '../chunk-F2ENUV3A.js';
|