@matterlabs/zksync-js 0.0.14 → 0.0.15

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.
Files changed (63) hide show
  1. package/dist/adapters/ethers/client.cjs.map +1 -1
  2. package/dist/adapters/ethers/client.d.ts +1 -2
  3. package/dist/adapters/ethers/client.js +4 -5
  4. package/dist/adapters/ethers/index.cjs +117 -28
  5. package/dist/adapters/ethers/index.cjs.map +1 -1
  6. package/dist/adapters/ethers/index.js +6 -7
  7. package/dist/adapters/ethers/resources/interop/services/gas.d.ts +12 -0
  8. package/dist/adapters/ethers/sdk.cjs +117 -28
  9. package/dist/adapters/ethers/sdk.cjs.map +1 -1
  10. package/dist/adapters/ethers/sdk.js +5 -6
  11. package/dist/adapters/viem/client.cjs +787 -3
  12. package/dist/adapters/viem/client.cjs.map +1 -1
  13. package/dist/adapters/viem/client.d.ts +6 -1
  14. package/dist/adapters/viem/client.js +4 -5
  15. package/dist/adapters/viem/index.cjs +6463 -3014
  16. package/dist/adapters/viem/index.cjs.map +1 -1
  17. package/dist/adapters/viem/index.d.ts +5 -0
  18. package/dist/adapters/viem/index.js +6 -7
  19. package/dist/adapters/viem/resources/interop/address.d.ts +18 -0
  20. package/dist/adapters/viem/resources/interop/attributes/resource.d.ts +6 -0
  21. package/dist/adapters/viem/resources/interop/context.d.ts +31 -0
  22. package/dist/adapters/viem/resources/interop/index.d.ts +62 -0
  23. package/dist/adapters/viem/resources/interop/resolvers.d.ts +4 -0
  24. package/dist/adapters/viem/resources/interop/routes/direct.d.ts +2 -0
  25. package/dist/adapters/viem/resources/interop/routes/indirect.d.ts +2 -0
  26. package/dist/adapters/viem/resources/interop/routes/types.d.ts +23 -0
  27. package/dist/adapters/viem/resources/interop/services/erc20.d.ts +25 -0
  28. package/dist/adapters/viem/resources/interop/services/fee.d.ts +12 -0
  29. package/dist/adapters/viem/resources/interop/services/finalization/bundle.d.ts +15 -0
  30. package/dist/adapters/viem/resources/interop/services/finalization/data-fetchers.d.ts +17 -0
  31. package/dist/adapters/viem/resources/interop/services/finalization/decoders.d.ts +11 -0
  32. package/dist/adapters/viem/resources/interop/services/finalization/index.d.ts +13 -0
  33. package/dist/adapters/viem/resources/interop/services/finalization/polling.d.ts +7 -0
  34. package/dist/adapters/viem/resources/interop/services/finalization/status.d.ts +5 -0
  35. package/dist/adapters/viem/resources/interop/services/finalization/topics.d.ts +4 -0
  36. package/dist/adapters/viem/resources/interop/services/gas.d.ts +12 -0
  37. package/dist/adapters/viem/resources/interop/services/starter-data.d.ts +6 -0
  38. package/dist/adapters/viem/resources/interop/types.d.ts +8 -0
  39. package/dist/adapters/viem/sdk.cjs +6608 -3203
  40. package/dist/adapters/viem/sdk.cjs.map +1 -1
  41. package/dist/adapters/viem/sdk.d.ts +8 -1
  42. package/dist/adapters/viem/sdk.js +5 -5
  43. package/dist/{chunk-75IOOODG.js → chunk-4PZCNTQ3.js} +1142 -26
  44. package/dist/{chunk-5RRJDPAJ.js → chunk-65HAYKVL.js} +2 -2
  45. package/dist/{chunk-XKRNLFET.js → chunk-HGB3DOV2.js} +73 -376
  46. package/dist/{chunk-J47RI3G7.js → chunk-HVHMLAYH.js} +1 -1
  47. package/dist/{chunk-OTXPSNNC.js → chunk-JHRYNLZG.js} +64 -7
  48. package/dist/{chunk-JY62QO3W.js → chunk-JXR5V5YK.js} +419 -6
  49. package/dist/chunk-K2UVKMLN.js +658 -0
  50. package/dist/{chunk-HP3EWKJL.js → chunk-MDPX5LNW.js} +1 -1
  51. package/dist/{chunk-7CAVFIMW.js → chunk-MZBKM3GH.js} +2 -3
  52. package/dist/{chunk-XDRCN4FC.js → chunk-YIWXIP2M.js} +10 -2
  53. package/dist/core/index.js +2 -3
  54. package/dist/core/resources/deposits/chains.d.ts +1 -0
  55. package/dist/core/resources/deposits/gas.d.ts +7 -0
  56. package/dist/core/resources/deposits/priority.d.ts +4 -0
  57. package/dist/core/resources/interop/protocol.d.ts +3 -0
  58. package/dist/core/types/flows/interop.d.ts +0 -2
  59. package/dist/core/types/primitives.d.ts +2 -0
  60. package/dist/index.js +2 -3
  61. package/package.json +1 -1
  62. package/dist/chunk-DYJKK5FW.js +0 -417
  63. package/dist/chunk-EOBXYHTZ.js +0 -265
@@ -1,265 +0,0 @@
1
- import { IBridgehub_default } from './chunk-JY62QO3W.js';
2
- import { L1_TX_MIN_L2_GAS_BASE, L1_TX_INTRINSIC_L2_GAS, L1_TX_DELTA_544_ENCODING_BYTES, L1_TX_DELTA_FACTORY_DEPS_L2_GAS, L1_TX_INTRINSIC_PUBDATA, L1_TX_DELTA_FACTORY_DEPS_PUBDATA, TX_MEMORY_OVERHEAD_GAS, TX_SLOT_OVERHEAD_L2_GAS, PRIORITY_TX_MAX_GAS_LIMIT, BUFFER, DEFAULT_ABI_BYTES, DEFAULT_PUBDATA_BYTES, TX_OVERHEAD_GAS } from './chunk-MT4X5FEO.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/types/fees.ts
19
- function toGasOverrides(overrides) {
20
- const { nonce: _, ...gas } = overrides;
21
- return gas;
22
- }
23
-
24
- // src/core/resources/deposits/fee.ts
25
- function buildFeeBreakdown(p) {
26
- const l1MaxTotal = p.l1Gas?.maxCost ?? 0n;
27
- const l2Total = p.l2BaseCost + p.operatorTip;
28
- const l1 = {
29
- gasLimit: p.l1Gas?.gasLimit ?? 0n,
30
- maxFeePerGas: p.l1Gas?.maxFeePerGas ?? 0n,
31
- maxPriorityFeePerGas: p.l1Gas?.maxPriorityFeePerGas,
32
- maxTotal: l1MaxTotal
33
- };
34
- const l2 = {
35
- total: l2Total,
36
- baseCost: p.l2BaseCost,
37
- operatorTip: p.operatorTip,
38
- gasLimit: p.l2Gas?.gasLimit ?? 0n,
39
- maxFeePerGas: p.l2Gas?.maxFeePerGas ?? 0n,
40
- maxPriorityFeePerGas: p.l2Gas?.maxPriorityFeePerGas,
41
- gasPerPubdata: p.l2Gas?.gasPerPubdata ?? 0n
42
- };
43
- return {
44
- token: p.feeToken,
45
- maxTotal: l1MaxTotal + l2Total,
46
- mintValue: p.mintValue,
47
- l1,
48
- l2
49
- };
50
- }
51
-
52
- // src/core/resources/deposits/priority.ts
53
- var PRIORITY_TX_ENCODING_STEP_BYTES = 544n;
54
- var DEFAULT_PRIORITY_BODY_GAS_ESTIMATE_MULTIPLIER = 6n;
55
- var maxBigInt = (a, b) => a > b ? a : b;
56
- var ceilDiv = (a, b) => (a + b - 1n) / b;
57
- function derivePriorityTxGasBreakdown(input) {
58
- const factoryDepsCount = input.factoryDepsCount ?? 0n;
59
- const minBodyGas = maxBigInt(
60
- L1_TX_INTRINSIC_L2_GAS + ceilDiv(
61
- input.encodedLength * L1_TX_DELTA_544_ENCODING_BYTES,
62
- PRIORITY_TX_ENCODING_STEP_BYTES
63
- ) + factoryDepsCount * L1_TX_DELTA_FACTORY_DEPS_L2_GAS,
64
- L1_TX_MIN_L2_GAS_BASE
65
- ) + L1_TX_INTRINSIC_PUBDATA * input.gasPerPubdata + factoryDepsCount * L1_TX_DELTA_FACTORY_DEPS_PUBDATA * input.gasPerPubdata;
66
- const overhead = maxBigInt(TX_SLOT_OVERHEAD_L2_GAS, TX_MEMORY_OVERHEAD_GAS * input.encodedLength);
67
- const derivedBodyGas = minBodyGas;
68
- return {
69
- encodedLength: input.encodedLength,
70
- minBodyGas,
71
- overhead,
72
- derivedBodyGas,
73
- derivedL2GasLimit: derivedBodyGas + overhead,
74
- priorityTxMaxGasLimit: PRIORITY_TX_MAX_GAS_LIMIT,
75
- priorityTxMaxGasLimitExceeded: derivedBodyGas > PRIORITY_TX_MAX_GAS_LIMIT
76
- };
77
- }
78
- function derivePriorityBodyGasEstimateCap(input) {
79
- return input.minBodyGas * (input.multiplier ?? DEFAULT_PRIORITY_BODY_GAS_ESTIMATE_MULTIPLIER);
80
- }
81
-
82
- // src/core/resources/deposits/gas.ts
83
- function makeGasQuote(p) {
84
- const maxPriorityFeePerGas = p.maxPriorityFeePerGas ?? 0n;
85
- return {
86
- gasLimit: p.gasLimit,
87
- maxFeePerGas: p.maxFeePerGas,
88
- maxPriorityFeePerGas,
89
- gasPerPubdata: p.gasPerPubdata,
90
- maxCost: p.gasLimit * p.maxFeePerGas
91
- };
92
- }
93
- async function fetchFees(estimator) {
94
- try {
95
- const fees = await estimator.estimateFeesPerGas();
96
- if (fees.maxFeePerGas != null) {
97
- return {
98
- maxFeePerGas: fees.maxFeePerGas,
99
- maxPriorityFeePerGas: fees.maxPriorityFeePerGas ?? 0n
100
- };
101
- }
102
- if (fees.gasPrice != null) {
103
- return {
104
- maxFeePerGas: fees.gasPrice,
105
- maxPriorityFeePerGas: 0n
106
- };
107
- }
108
- } catch {
109
- }
110
- try {
111
- const gp = await estimator.getGasPrice();
112
- return { maxFeePerGas: gp, maxPriorityFeePerGas: 0n };
113
- } catch {
114
- return { maxFeePerGas: 0n, maxPriorityFeePerGas: 0n };
115
- }
116
- }
117
- async function quoteL1Gas(input) {
118
- const { estimator, tx, overrides, fallbackGasLimit } = input;
119
- let market;
120
- const getMarket = async () => {
121
- if (market) return market;
122
- market = await fetchFees(estimator);
123
- return market;
124
- };
125
- const maxFeePerGas = overrides?.maxFeePerGas ?? (tx.maxFeePerGas != null ? BigInt(tx.maxFeePerGas) : (await getMarket()).maxFeePerGas);
126
- const maxPriorityFeePerGas = overrides?.maxPriorityFeePerGas ?? (tx.maxPriorityFeePerGas != null ? BigInt(tx.maxPriorityFeePerGas) : (await getMarket()).maxPriorityFeePerGas);
127
- const explicitGasLimit = overrides?.gasLimit ?? (tx.gasLimit != null ? BigInt(tx.gasLimit) : void 0);
128
- if (explicitGasLimit != null) {
129
- return makeGasQuote({ gasLimit: explicitGasLimit, maxFeePerGas, maxPriorityFeePerGas });
130
- }
131
- try {
132
- const est = await estimator.estimateGas(tx);
133
- const buffered = BigInt(est) * (100n + BUFFER) / 100n;
134
- return makeGasQuote({ gasLimit: buffered, maxFeePerGas, maxPriorityFeePerGas });
135
- } catch {
136
- if (fallbackGasLimit != null) {
137
- return makeGasQuote({ gasLimit: fallbackGasLimit, maxFeePerGas, maxPriorityFeePerGas });
138
- }
139
- return void 0;
140
- }
141
- }
142
- async function quoteL2Gas(input) {
143
- const { estimator, route, tx, gasPerPubdata, l2GasLimit, overrideGasLimit, stateOverrides } = input;
144
- const market = await fetchFees(estimator);
145
- const maxFeePerGas = market.maxFeePerGas || market.maxPriorityFeePerGas || 0n;
146
- const txGasLimit = tx?.gasLimit != null ? BigInt(tx.gasLimit) : void 0;
147
- const explicit = overrideGasLimit ?? txGasLimit;
148
- if (explicit != null) {
149
- return makeGasQuote({
150
- gasLimit: explicit,
151
- maxFeePerGas,
152
- gasPerPubdata
153
- });
154
- }
155
- if (!tx) {
156
- return makeGasQuote({
157
- gasLimit: l2GasLimit ?? 0n,
158
- maxFeePerGas,
159
- gasPerPubdata
160
- });
161
- }
162
- try {
163
- const execEstimate = await estimator.estimateGas(tx, stateOverrides);
164
- const memoryBytes = route === "erc20-nonbase" ? 500n : DEFAULT_ABI_BYTES;
165
- const pubdataBytes = route === "erc20-nonbase" ? 200n : DEFAULT_PUBDATA_BYTES;
166
- const pp = gasPerPubdata ?? 800n;
167
- const memoryOverhead = memoryBytes * TX_MEMORY_OVERHEAD_GAS;
168
- const pubdataOverhead = pubdataBytes * pp;
169
- let total = BigInt(execEstimate) + TX_OVERHEAD_GAS + memoryOverhead + pubdataOverhead;
170
- total = total * (100n + BUFFER) / 100n;
171
- return makeGasQuote({
172
- gasLimit: total,
173
- maxFeePerGas,
174
- gasPerPubdata: pp
175
- });
176
- } catch {
177
- return makeGasQuote({
178
- gasLimit: l2GasLimit ?? 0n,
179
- maxFeePerGas,
180
- gasPerPubdata
181
- });
182
- }
183
- }
184
- async function quoteL2BaseCost(input) {
185
- const { estimator, encode, bridgehub, chainIdL2, l2GasLimit, gasPerPubdata } = input;
186
- const market = await fetchFees(estimator);
187
- const l1GasPrice = market.maxFeePerGas || market.maxPriorityFeePerGas || 0n;
188
- if (l1GasPrice === 0n) {
189
- throw new Error("Could not fetch L1 gas price for Bridgehub base cost calculation.");
190
- }
191
- const data = encode(IBridgehub_default, "l2TransactionBaseCost", [
192
- chainIdL2,
193
- l1GasPrice,
194
- l2GasLimit,
195
- gasPerPubdata
196
- ]);
197
- const raw = await estimator.call({
198
- to: bridgehub,
199
- data
200
- });
201
- return BigInt(raw);
202
- }
203
-
204
- // src/core/resources/withdrawals/gas.ts
205
- function makeGasQuote2(p) {
206
- return {
207
- gasLimit: p.gasLimit,
208
- maxFeePerGas: p.maxFeePerGas,
209
- maxPriorityFeePerGas: p.maxPriorityFeePerGas,
210
- maxCost: p.gasLimit * p.maxFeePerGas
211
- };
212
- }
213
- async function fetchFees2(estimator) {
214
- try {
215
- const fees = await estimator.estimateFeesPerGas();
216
- if (fees.maxFeePerGas != null) {
217
- return {
218
- maxFeePerGas: fees.maxFeePerGas,
219
- maxPriorityFeePerGas: fees.maxPriorityFeePerGas ?? 0n
220
- };
221
- }
222
- if (fees.gasPrice != null) {
223
- return {
224
- maxFeePerGas: fees.gasPrice,
225
- maxPriorityFeePerGas: 0n
226
- };
227
- }
228
- } catch {
229
- }
230
- try {
231
- const gp = await estimator.getGasPrice();
232
- return { maxFeePerGas: gp, maxPriorityFeePerGas: 0n };
233
- } catch {
234
- return { maxFeePerGas: 0n, maxPriorityFeePerGas: 0n };
235
- }
236
- }
237
- async function quoteL2Gas2(input) {
238
- const { estimator, tx, overrides } = input;
239
- const market = await fetchFees2(estimator);
240
- const o = overrides;
241
- const maxFeePerGas = o?.maxFeePerGas ?? (tx.maxFeePerGas != null ? BigInt(tx.maxFeePerGas) : market.maxFeePerGas);
242
- const maxPriorityFeePerGas = o?.maxPriorityFeePerGas ?? (tx.maxPriorityFeePerGas != null ? BigInt(tx.maxPriorityFeePerGas) : market.maxPriorityFeePerGas);
243
- const explicitGasLimit = o?.gasLimit ?? (tx.gasLimit != null ? BigInt(tx.gasLimit) : void 0);
244
- if (explicitGasLimit != null) {
245
- return makeGasQuote2({
246
- gasLimit: explicitGasLimit,
247
- maxFeePerGas,
248
- maxPriorityFeePerGas
249
- });
250
- }
251
- try {
252
- const est = await estimator.estimateGas(tx);
253
- const buffered = BigInt(est) * (100n + BUFFER) / 100n;
254
- return makeGasQuote2({
255
- gasLimit: buffered,
256
- maxFeePerGas,
257
- maxPriorityFeePerGas
258
- });
259
- } catch (err) {
260
- console.warn("Failed to estimate L2 gas for withdrawal.", err);
261
- return void 0;
262
- }
263
- }
264
-
265
- export { buildFeeBreakdown, createNTVCodec, derivePriorityBodyGasEstimateCap, derivePriorityTxGasBreakdown, quoteL1Gas, quoteL2BaseCost, quoteL2Gas, quoteL2Gas2, toGasOverrides };