@latchprotocol/widgets 0.1.0

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 (132) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +649 -0
  3. package/dist/adapters/binDistribution.d.ts +19 -0
  4. package/dist/adapters/binDistribution.d.ts.map +1 -0
  5. package/dist/adapters/protocol.d.ts +409 -0
  6. package/dist/adapters/protocol.d.ts.map +1 -0
  7. package/dist/adapters/sale.d.ts +142 -0
  8. package/dist/adapters/sale.d.ts.map +1 -0
  9. package/dist/adapters/viem.d.ts +89 -0
  10. package/dist/adapters/viem.d.ts.map +1 -0
  11. package/dist/callpath/constants.d.ts +218 -0
  12. package/dist/callpath/constants.d.ts.map +1 -0
  13. package/dist/callpath/launch.d.ts +1979 -0
  14. package/dist/callpath/launch.d.ts.map +1 -0
  15. package/dist/callpath/liquidity.d.ts +103 -0
  16. package/dist/callpath/liquidity.d.ts.map +1 -0
  17. package/dist/callpath/plan.d.ts +34 -0
  18. package/dist/callpath/plan.d.ts.map +1 -0
  19. package/dist/callpath/swap.d.ts +129 -0
  20. package/dist/callpath/swap.d.ts.map +1 -0
  21. package/dist/chunks/SwapWidget-DgyHAVc8.js +2404 -0
  22. package/dist/chunks/SwapWidget-DgyHAVc8.js.map +1 -0
  23. package/dist/chunks/scan-Dhu7f4Nl.js +2497 -0
  24. package/dist/chunks/scan-Dhu7f4Nl.js.map +1 -0
  25. package/dist/chunks/useLocker-D1c_NTk-.js +1613 -0
  26. package/dist/chunks/useLocker-D1c_NTk-.js.map +1 -0
  27. package/dist/components/LaunchWidget.d.ts +117 -0
  28. package/dist/components/LaunchWidget.d.ts.map +1 -0
  29. package/dist/components/LiquidityWidget.d.ts +33 -0
  30. package/dist/components/LiquidityWidget.d.ts.map +1 -0
  31. package/dist/components/LockerWidget.d.ts +51 -0
  32. package/dist/components/LockerWidget.d.ts.map +1 -0
  33. package/dist/components/LocksWidgets.d.ts +61 -0
  34. package/dist/components/LocksWidgets.d.ts.map +1 -0
  35. package/dist/components/SwapWidget.d.ts +165 -0
  36. package/dist/components/SwapWidget.d.ts.map +1 -0
  37. package/dist/components/TokenTrustPanel.d.ts +32 -0
  38. package/dist/components/TokenTrustPanel.d.ts.map +1 -0
  39. package/dist/components/lockCharts.d.ts +29 -0
  40. package/dist/components/lockCharts.d.ts.map +1 -0
  41. package/dist/components/portal.d.ts +10 -0
  42. package/dist/components/portal.d.ts.map +1 -0
  43. package/dist/components/primitives.d.ts +139 -0
  44. package/dist/components/primitives.d.ts.map +1 -0
  45. package/dist/components/swap/SwapSettings.d.ts +12 -0
  46. package/dist/components/swap/SwapSettings.d.ts.map +1 -0
  47. package/dist/components/swap/TokenSelect.d.ts +61 -0
  48. package/dist/components/swap/TokenSelect.d.ts.map +1 -0
  49. package/dist/components/swap/state.d.ts +208 -0
  50. package/dist/components/swap/state.d.ts.map +1 -0
  51. package/dist/config/chain.d.ts +163 -0
  52. package/dist/config/chain.d.ts.map +1 -0
  53. package/dist/config/integrator.d.ts +121 -0
  54. package/dist/config/integrator.d.ts.map +1 -0
  55. package/dist/context/WidgetProvider.d.ts +78 -0
  56. package/dist/context/WidgetProvider.d.ts.map +1 -0
  57. package/dist/core/clMath.d.ts +98 -0
  58. package/dist/core/clMath.d.ts.map +1 -0
  59. package/dist/core/errors.d.ts +18 -0
  60. package/dist/core/errors.d.ts.map +1 -0
  61. package/dist/core/format.d.ts +47 -0
  62. package/dist/core/format.d.ts.map +1 -0
  63. package/dist/core/liquidityGuards.d.ts +53 -0
  64. package/dist/core/liquidityGuards.d.ts.map +1 -0
  65. package/dist/core/liquidityRefresh.d.ts +35 -0
  66. package/dist/core/liquidityRefresh.d.ts.map +1 -0
  67. package/dist/core/math.d.ts +129 -0
  68. package/dist/core/math.d.ts.map +1 -0
  69. package/dist/core/pool.d.ts +33 -0
  70. package/dist/core/pool.d.ts.map +1 -0
  71. package/dist/core/tokenLists.d.ts +46 -0
  72. package/dist/core/tokenLists.d.ts.map +1 -0
  73. package/dist/embed/iframe.d.ts +185 -0
  74. package/dist/embed/iframe.d.ts.map +1 -0
  75. package/dist/embed/lockBadge.d.ts +55 -0
  76. package/dist/embed/lockBadge.d.ts.map +1 -0
  77. package/dist/embed/webComponent.d.ts +83 -0
  78. package/dist/embed/webComponent.d.ts.map +1 -0
  79. package/dist/embed.d.ts +25 -0
  80. package/dist/embed.d.ts.map +1 -0
  81. package/dist/embed.js +543 -0
  82. package/dist/embed.js.map +1 -0
  83. package/dist/headless.d.ts +60 -0
  84. package/dist/headless.d.ts.map +1 -0
  85. package/dist/headless.js +223 -0
  86. package/dist/headless.js.map +1 -0
  87. package/dist/hooks/useAsyncResource.d.ts +38 -0
  88. package/dist/hooks/useAsyncResource.d.ts.map +1 -0
  89. package/dist/hooks/useLaunch.d.ts +140 -0
  90. package/dist/hooks/useLaunch.d.ts.map +1 -0
  91. package/dist/hooks/useLiquidity.d.ts +91 -0
  92. package/dist/hooks/useLiquidity.d.ts.map +1 -0
  93. package/dist/hooks/useLocker.d.ts +77 -0
  94. package/dist/hooks/useLocker.d.ts.map +1 -0
  95. package/dist/hooks/useLocks.d.ts +33 -0
  96. package/dist/hooks/useLocks.d.ts.map +1 -0
  97. package/dist/hooks/useSwapExecute.d.ts +46 -0
  98. package/dist/hooks/useSwapExecute.d.ts.map +1 -0
  99. package/dist/hooks/useSwapQuote.d.ts +51 -0
  100. package/dist/hooks/useSwapQuote.d.ts.map +1 -0
  101. package/dist/hooks/useTokenLists.d.ts +26 -0
  102. package/dist/hooks/useTokenLists.d.ts.map +1 -0
  103. package/dist/hooks/useTokenTrust.d.ts +40 -0
  104. package/dist/hooks/useTokenTrust.d.ts.map +1 -0
  105. package/dist/hooks/useTokens.d.ts +15 -0
  106. package/dist/hooks/useTokens.d.ts.map +1 -0
  107. package/dist/index.d.ts +59 -0
  108. package/dist/index.d.ts.map +1 -0
  109. package/dist/index.js +1052 -0
  110. package/dist/index.js.map +1 -0
  111. package/dist/latch-embed.d.ts +19 -0
  112. package/dist/latch-embed.d.ts.map +1 -0
  113. package/dist/latch-embed.js +950 -0
  114. package/dist/latch-embed.js.map +1 -0
  115. package/dist/latch-embed.mjs +13162 -0
  116. package/dist/latch-embed.mjs.map +1 -0
  117. package/dist/locker/model.d.ts +73 -0
  118. package/dist/locker/model.d.ts.map +1 -0
  119. package/dist/locks/embedModel.d.ts +22 -0
  120. package/dist/locks/embedModel.d.ts.map +1 -0
  121. package/dist/locks/fetch.d.ts +60 -0
  122. package/dist/locks/fetch.d.ts.map +1 -0
  123. package/dist/locks/model.d.ts +143 -0
  124. package/dist/locks/model.d.ts.map +1 -0
  125. package/dist/locks/scan.d.ts +25 -0
  126. package/dist/locks/scan.d.ts.map +1 -0
  127. package/dist/styles/css.d.ts +32 -0
  128. package/dist/styles/css.d.ts.map +1 -0
  129. package/dist/styles.css +895 -0
  130. package/dist/trust/model.d.ts +48 -0
  131. package/dist/trust/model.d.ts.map +1 -0
  132. package/package.json +102 -0
@@ -0,0 +1,2497 @@
1
+ import { createContext as In, useMemo as N, useEffect as z, useContext as Ze, useState as I, useRef as fe, useCallback as y } from "react";
2
+ import { isAddress as xe, getAddress as Qe, formatUnits as ze, parseUnits as vn, concatHex as Tn, encodeAbiParameters as P, isAddressEqual as R, encodeFunctionData as En, decodeErrorResult as An, BaseError as Je, parseAbi as Ln, zeroAddress as W, keccak256 as Sn, erc20Abi as qe } from "viem";
3
+ import { LAUNCH_GUARD_HOOK_ABI as en, LAUNCH_GUARD_HOOK_BLOCK_ABI as $n, UNIVERSAL_ROUTER_ABI as Bn, CL_QUOTER_ABI as Pn, BIN_QUOTER_ABI as Nn, CL_POSITION_MANAGER_ABI as On, BIN_POSITION_MANAGER_ABI as xn, BIN_LAUNCH_GUARD_HOOK_ABI as _n, readBinPoolKeyParameters as Rn, readCLPoolKeyParameters as Cn, ipfsToHttp as Mn, mergeTokenLists as nn, stockExtensionOf as Fn, fetchTokenList as qn } from "@latchprotocol/sdk";
4
+ import { LATCH_POSITION_LOCK_ABI as Un, LATCH_TOKEN_LOCK_ABI as Dn, readBinPoolPermanent as Gn, readChainNow as Ie, summarizePoolLocks as Ue, readPoolLocks as Wn, readClPoolPermanent as Kn, readCurrencyLocks as Hn, readClLpLockerPositionsPriced as Xn, readBinLpLockerLocks as Vn, permanentTokenPools as jn, findClLpLockerTokenIds as tn, vestedAt as Yn } from "@latchprotocol/sdk/lock";
5
+ import { jsx as Zn } from "react/jsx-runtime";
6
+ class G extends Error {
7
+ chainId;
8
+ contract;
9
+ constructor(n, t, o = null) {
10
+ super(`[@latchprotocol/widgets] ${n}`), this.name = "ChainConfigError", this.chainId = t, this.contract = o;
11
+ }
12
+ }
13
+ const Qn = "0x0000000000000000000000000000000000000000";
14
+ function on(e, n, t, o) {
15
+ if (typeof e != "string" || !xe(e))
16
+ throw new G(
17
+ `chain ${t}: ${n} is not a valid address: ${JSON.stringify(e)}`,
18
+ t,
19
+ o
20
+ );
21
+ const r = Qe(e);
22
+ if (r === Qn)
23
+ throw new G(
24
+ `chain ${t}: ${n} is the zero address. Pass the deployed address from the address book.`,
25
+ t,
26
+ o
27
+ );
28
+ return r;
29
+ }
30
+ function zn(e) {
31
+ if (!Number.isInteger(e.chainId) || e.chainId <= 0)
32
+ throw new G(
33
+ `chainId must be a positive integer, received ${String(e.chainId)}`,
34
+ Number(e.chainId) || 0
35
+ );
36
+ if (e.nativeCurrency.decimals < 0 || e.nativeCurrency.decimals > 36)
37
+ throw new G(
38
+ `nativeCurrency.decimals is out of range: ${e.nativeCurrency.decimals}`,
39
+ e.chainId
40
+ );
41
+ if (on(e.contracts.vault, "contracts.vault", e.chainId, "vault"), !e.contracts.clPoolManager && !e.contracts.binPoolManager)
42
+ throw new G(
43
+ `chain ${e.chainId}: at least one of contracts.clPoolManager or contracts.binPoolManager must be set`,
44
+ e.chainId
45
+ );
46
+ }
47
+ function wo(e, n, t) {
48
+ const o = e.contracts[n];
49
+ if (o === void 0)
50
+ throw new G(
51
+ `chain ${e.chainId} (${e.name}): contracts.${n} is not configured, but it is required to ${t}.`,
52
+ e.chainId,
53
+ n
54
+ );
55
+ return on(o, `contracts.${n}`, e.chainId, n);
56
+ }
57
+ function bo(e, n) {
58
+ return e === null ? n : n === null || e > n ? e : n;
59
+ }
60
+ function he(e, n) {
61
+ const t = BigInt(e.defaultDeadlineSeconds ?? 1200), o = BigInt(Math.floor(Date.now() / 1e3)), r = n === void 0 ? o : BigInt(n);
62
+ return (r > o ? r : o) + t;
63
+ }
64
+ async function _e(e, n) {
65
+ if (n.getBlockTimestamp === void 0) return he(e);
66
+ try {
67
+ return he(e, await n.getBlockTimestamp());
68
+ } catch {
69
+ return he(e);
70
+ }
71
+ }
72
+ function ko(e, n) {
73
+ const t = (e.blockExplorerUrl ?? "").trim().replace(/\/+$/, "");
74
+ return t === "" ? null : `${t}/tx/${n}`;
75
+ }
76
+ const me = 1e4, J = 100, ae = "0x0000000000000000000000000000000000000000";
77
+ class F extends Error {
78
+ code;
79
+ constructor(n, t) {
80
+ super(`[@latchprotocol/widgets] integrator config rejected (${n}): ${t}`), this.name = "IntegratorConfigError", this.code = n;
81
+ }
82
+ }
83
+ const rn = ["take-portion", "pay-portion"];
84
+ function Jn(e) {
85
+ return rn.includes(e);
86
+ }
87
+ function et(e) {
88
+ const { feeBps: n } = e;
89
+ if (typeof n != "number" || Number.isNaN(n))
90
+ throw new F(
91
+ "FEE_BPS_NOT_A_NUMBER",
92
+ `feeBps must be a number, received ${JSON.stringify(n)}`
93
+ );
94
+ if (!Number.isFinite(n) || !Number.isInteger(n))
95
+ throw new F(
96
+ "FEE_BPS_NOT_AN_INTEGER",
97
+ `feeBps must be a whole number of basis points, received ${n}. There is no sub-basis-point precision on-chain.`
98
+ );
99
+ if (n < 0)
100
+ throw new F(
101
+ "FEE_BPS_NEGATIVE",
102
+ `feeBps must not be negative, received ${n}`
103
+ );
104
+ if (n > J)
105
+ throw new F(
106
+ "FEE_BPS_ABOVE_MAX",
107
+ `feeBps ${n} exceeds MAX_INTEGRATOR_FEE_BPS (${J} bps = ${J / 100}%). Raise it only by forking this package and owning the consequences for your users.`
108
+ );
109
+ const t = e.feeMode ?? "take-portion";
110
+ if (!Jn(t))
111
+ throw new F(
112
+ "FEE_MODE_UNKNOWN",
113
+ `feeMode must be one of ${rn.join(" | ")}, received ${JSON.stringify(t)}`
114
+ );
115
+ const o = [], r = e.referrer, s = n > 0;
116
+ if (r == null || r === "") {
117
+ if (s)
118
+ throw new F(
119
+ "REFERRER_MISSING",
120
+ `feeBps is ${n} but no referrer address was provided. A fee with no destination would be silently forfeited; refusing to build the call path.`
121
+ );
122
+ return {
123
+ referrer: ae,
124
+ feeBps: 0,
125
+ feeMode: t,
126
+ label: e.label ?? null,
127
+ active: !1,
128
+ warnings: o
129
+ };
130
+ }
131
+ if (typeof r != "string" || !xe(r))
132
+ throw new F(
133
+ "REFERRER_MALFORMED",
134
+ `referrer is not a valid EVM address: ${JSON.stringify(r)}`
135
+ );
136
+ const i = Qe(r);
137
+ if (i === ae) {
138
+ if (s)
139
+ throw new F(
140
+ "REFERRER_ZERO_ADDRESS",
141
+ `feeBps is ${n} but referrer is the zero address. The fee would be burned.`
142
+ );
143
+ return {
144
+ referrer: ae,
145
+ feeBps: 0,
146
+ feeMode: t,
147
+ label: e.label ?? null,
148
+ active: !1,
149
+ warnings: o
150
+ };
151
+ }
152
+ return s || o.push(
153
+ `referrer ${i} is configured but feeBps is 0, so this widget will earn the integrator nothing. Set feeBps to start collecting.`
154
+ ), {
155
+ referrer: i,
156
+ feeBps: n,
157
+ feeMode: t,
158
+ label: e.label ?? null,
159
+ active: s,
160
+ warnings: o
161
+ };
162
+ }
163
+ const nt = {
164
+ referrer: ae,
165
+ feeBps: 0,
166
+ feeMode: "take-portion",
167
+ label: null,
168
+ active: !1,
169
+ warnings: []
170
+ };
171
+ function tt(e) {
172
+ return e == null ? nt : et(e);
173
+ }
174
+ function Re(e, n) {
175
+ if (e < 0n)
176
+ throw new RangeError(`calculateIntegratorFee: grossAmount must not be negative: ${e}`);
177
+ if (!Number.isInteger(n) || n < 0 || n > me)
178
+ throw new RangeError(
179
+ `calculateIntegratorFee: feeBps must be an integer in [0, ${me}]: ${n}`
180
+ );
181
+ return e * BigInt(n) / BigInt(me);
182
+ }
183
+ function ot(e, n) {
184
+ if (!n.active)
185
+ return {
186
+ grossAmount: e,
187
+ integratorFee: 0n,
188
+ netAmount: e,
189
+ feeBps: 0,
190
+ referrer: null
191
+ };
192
+ const t = Re(e, n.feeBps);
193
+ return {
194
+ grossAmount: e,
195
+ integratorFee: t,
196
+ netAmount: e - t,
197
+ feeBps: n.feeBps,
198
+ referrer: n.referrer
199
+ };
200
+ }
201
+ function go(e) {
202
+ const n = e / 100;
203
+ return `${Number.isInteger(n) ? n.toString() : n.toFixed(2)}%`;
204
+ }
205
+ const U = 10000n, rt = 1000000n, _ = 5e3, st = 50, it = 300, at = 1e3;
206
+ function K(e, n) {
207
+ if (e < 0n) throw new RangeError(`${n} must not be negative: ${e}`);
208
+ }
209
+ function oe(e, n, t) {
210
+ if (!Number.isInteger(e) || e < 0 || e > t)
211
+ throw new RangeError(`${n} must be an integer in [0, ${t}]: ${e}`);
212
+ }
213
+ function Io(e, n) {
214
+ return K(e, "amount"), oe(n, "bps", 1e4), e * BigInt(n) / U;
215
+ }
216
+ function vo(e, n) {
217
+ return K(e, "amount"), oe(n, "pips", 1e6), e * BigInt(n) / rt;
218
+ }
219
+ function ve(e, n) {
220
+ return K(e, "expected"), oe(n, "slippageBps", _), e * (U - BigInt(n)) / U;
221
+ }
222
+ function De(e, n) {
223
+ K(e, "expected"), oe(n, "slippageBps", _);
224
+ const t = e * (U + BigInt(n));
225
+ return t % U === 0n ? t / U : t / U + 1n;
226
+ }
227
+ function ut(e, n) {
228
+ if (n == null || n <= 0n) return null;
229
+ if (K(e, "grossAmountOut"), e >= n) return 0;
230
+ const t = (n - e) * U / n;
231
+ return Number(t);
232
+ }
233
+ function lt(e) {
234
+ return e === null ? "unknown" : e >= at ? "severe" : e >= it ? "high" : e >= 100 ? "elevated" : "low";
235
+ }
236
+ function ct(e) {
237
+ const { amountIn: n, grossAmountOut: t, slippageBps: o, integrator: r } = e;
238
+ K(n, "amountIn"), K(t, "grossAmountOut"), oe(o, "slippageBps", _);
239
+ const s = ot(t, r), i = ve(t, o), u = r.active ? i - Re(i, r.feeBps) : i, a = ut(t, e.spotAmountOut ?? null);
240
+ return {
241
+ amountIn: n,
242
+ grossAmountOut: t,
243
+ integratorFee: s.integratorFee,
244
+ integratorFeeBps: s.feeBps,
245
+ netAmountOut: s.netAmount,
246
+ minAmountOutGross: i,
247
+ minAmountOutNet: u,
248
+ lpFeeAmount: e.lpFeeAmount ?? 0n,
249
+ lpFeePips: e.lpFeePips ?? 0,
250
+ lpFeeUnknown: e.lpFeeUnknown ?? !1,
251
+ slippageBps: o,
252
+ priceImpactBps: a,
253
+ priceImpactSeverity: lt(a)
254
+ };
255
+ }
256
+ function dt(e, n, t, o) {
257
+ if (e <= 0n || t <= 0n) return null;
258
+ const r = Number(e) / 10 ** n, s = Number(t) / 10 ** o;
259
+ return !Number.isFinite(r) || r === 0 ? null : s / r;
260
+ }
261
+ function To(e, n) {
262
+ if (n <= 0n) return 0;
263
+ const t = e > n ? n : e;
264
+ return Number(t * 10000n / n) / 100;
265
+ }
266
+ function Eo(e, n, t) {
267
+ if (n > t) throw new RangeError(`clampBigInt: min ${n} exceeds max ${t}`);
268
+ return e < n ? n : e > t ? t : e;
269
+ }
270
+ function pt(e, n) {
271
+ if (!Number.isInteger(n) || n <= 0)
272
+ throw new RangeError(`tickSpacing must be a positive integer: ${n}`);
273
+ return Math.floor(e / n) * n;
274
+ }
275
+ function ft(e, n) {
276
+ if (!Number.isInteger(n) || n <= 0)
277
+ throw new RangeError(`tickSpacing must be a positive integer: ${n}`);
278
+ return Math.ceil(e / n) * n;
279
+ }
280
+ const Ce = In(null);
281
+ function Ao(e) {
282
+ const {
283
+ adapter: n,
284
+ integrator: t,
285
+ defaultSlippageBps: o = st,
286
+ theme: r = "system",
287
+ locale: s,
288
+ onConnectRequest: i,
289
+ children: u
290
+ } = e, a = N(
291
+ () => tt(t ?? null),
292
+ [t]
293
+ ), l = n.chain;
294
+ if (N(() => (zn(l), null), [l]), !Number.isInteger(o) || o < 0)
295
+ throw new RangeError(
296
+ `[@latchprotocol/widgets] defaultSlippageBps must be a non-negative integer: ${o}`
297
+ );
298
+ if (o > _)
299
+ throw new RangeError(
300
+ `[@latchprotocol/widgets] defaultSlippageBps ${o} exceeds MAX_SLIPPAGE_BPS (${_})`
301
+ );
302
+ z(() => {
303
+ for (const d of a.warnings)
304
+ console.warn(`[@latchprotocol/widgets] ${d}`);
305
+ }, [a]);
306
+ const c = N(
307
+ () => ({
308
+ adapter: n,
309
+ chain: l,
310
+ integrator: a,
311
+ defaultSlippageBps: o,
312
+ theme: r,
313
+ locale: s,
314
+ onConnectRequest: i
315
+ }),
316
+ [n, l, a, o, r, s, i]
317
+ );
318
+ return /* @__PURE__ */ Zn(Ce.Provider, { value: c, children: u });
319
+ }
320
+ function E() {
321
+ const e = Ze(Ce);
322
+ if (e === null)
323
+ throw new Error(
324
+ "[@latchprotocol/widgets] no WidgetProvider found. Wrap your app (or just the widget) in <WidgetProvider adapter={...} integrator={...}>."
325
+ );
326
+ return e;
327
+ }
328
+ function Lo() {
329
+ return Ze(Ce);
330
+ }
331
+ function So() {
332
+ return E().adapter;
333
+ }
334
+ function $o() {
335
+ return E().integrator;
336
+ }
337
+ const ht = /^\d*(?:\.\d*)?$/;
338
+ function Bo(e, n, t = !1) {
339
+ const o = e.trim();
340
+ if (o === "" || o === ".")
341
+ return { ok: !1, reason: "empty", message: "Enter an amount" };
342
+ if (o.startsWith("-"))
343
+ return { ok: !1, reason: "negative", message: "Amount must be positive" };
344
+ if (!ht.test(o))
345
+ return { ok: !1, reason: "not-a-number", message: "Amount must be a number" };
346
+ const [, r = ""] = o.split(".");
347
+ if (r.length > n)
348
+ return {
349
+ ok: !1,
350
+ reason: "too-many-decimals",
351
+ message: `This token has ${n} decimals; ${r.length} were entered`
352
+ };
353
+ const s = vn(o, n);
354
+ return s === 0n && !t ? { ok: !1, reason: "zero", message: "Enter an amount greater than zero" } : { ok: !0, value: s };
355
+ }
356
+ function Po(e, n, t = 6) {
357
+ if (e === 0n) return "0";
358
+ const o = e < 0n, r = ze(o ? -e : e, n), [s = "0", i = ""] = r.split("."), u = o ? "-" : "";
359
+ if (i === "") return `${u}${ye(s)}`;
360
+ const a = i.slice(0, t).replace(/0+$/, "");
361
+ if (a === "") {
362
+ if (s === "0") {
363
+ const l = `0.${"0".repeat(Math.max(0, t - 1))}1`;
364
+ return `${u}<${l}`;
365
+ }
366
+ return `${u}${ye(s)}`;
367
+ }
368
+ return `${u}${ye(s)}.${a}`;
369
+ }
370
+ function ye(e) {
371
+ return e.replace(/\B(?=(\d{3})+(?!\d))/g, ",");
372
+ }
373
+ function No(e, n, t) {
374
+ if (e === null || !Number.isFinite(e) || e <= 0) return "-";
375
+ const o = e >= 1e3 ? 2 : e >= 1 ? 4 : 6;
376
+ return `1 ${n} = ${e.toLocaleString(void 0, {
377
+ maximumFractionDigits: o
378
+ })} ${t}`;
379
+ }
380
+ function Oo(e) {
381
+ if (e === null) return "unknown";
382
+ const n = e / 100;
383
+ return n > 0 && n < 0.01 ? "<0.01%" : `${n.toFixed(2)}%`;
384
+ }
385
+ function mt(e) {
386
+ const n = e / 1e4;
387
+ return n > 0 && n < 1e-3 ? "<0.001%" : `${yt(n.toFixed(3))}%`;
388
+ }
389
+ function yt(e) {
390
+ return e.includes(".") ? e.replace(/\.?0+$/, "") : e;
391
+ }
392
+ function wt(e) {
393
+ return e.length <= 12 ? e : `${e.slice(0, 6)}...${e.slice(-4)}`;
394
+ }
395
+ function xo(e) {
396
+ if (!Number.isFinite(e) || e <= 0) return "0s";
397
+ const n = Math.floor(e), t = Math.floor(n / 86400), o = Math.floor(n % 86400 / 3600), r = Math.floor(n % 3600 / 60), s = n % 60, i = [];
398
+ return t > 0 && i.push(`${t}d`), o > 0 && i.push(`${o}h`), r > 0 && t === 0 && i.push(`${r}m`), i.length === 0 && i.push(`${s}s`), i.join(" ");
399
+ }
400
+ function _o(e) {
401
+ const n = Number(e) * 1e3;
402
+ return Number.isFinite(n) ? new Date(n).toLocaleString() : "-";
403
+ }
404
+ const we = {
405
+ SWEEP: 4,
406
+ TRANSFER: 5,
407
+ /** Pays a bps portion of the router's balance of a token to a recipient. */
408
+ PAY_PORTION: 6,
409
+ WRAP_ETH: 11,
410
+ UNWRAP_WETH: 12,
411
+ /** Runs an encoded periphery action plan inside one vault lock. */
412
+ INFI_SWAP: 16
413
+ }, O = {
414
+ CL_INCREASE_LIQUIDITY: 0,
415
+ CL_DECREASE_LIQUIDITY: 1,
416
+ CL_MINT_POSITION: 2,
417
+ CL_BURN_POSITION: 3,
418
+ CL_SWAP_EXACT_IN_SINGLE: 6,
419
+ CL_SWAP_EXACT_IN: 7,
420
+ CL_SWAP_EXACT_OUT_SINGLE: 8,
421
+ CL_SWAP_EXACT_OUT: 9,
422
+ SETTLE: 11,
423
+ SETTLE_ALL: 12,
424
+ SETTLE_PAIR: 13,
425
+ TAKE: 14,
426
+ TAKE_ALL: 15,
427
+ /** Takes a bps portion of the open credit straight to a recipient. */
428
+ TAKE_PORTION: 16,
429
+ TAKE_PAIR: 17,
430
+ CLOSE_CURRENCY: 18,
431
+ CLEAR_OR_TAKE: 19,
432
+ SWEEP: 20,
433
+ BIN_ADD_LIQUIDITY: 25,
434
+ BIN_REMOVE_LIQUIDITY: 26,
435
+ BIN_SWAP_EXACT_IN_SINGLE: 28,
436
+ BIN_SWAP_EXACT_IN: 29,
437
+ BIN_SWAP_EXACT_OUT_SINGLE: 30,
438
+ BIN_SWAP_EXACT_OUT: 31
439
+ }, sn = "0x0000000000000000000000000000000000000001", bt = "0x0000000000000000000000000000000000000002", Ge = 0n, Ro = 1n << 255n, Co = "0x0000000000000000000000000000000000000000", Mo = 10n ** 18n, kt = [
440
+ {
441
+ type: "function",
442
+ name: "execute",
443
+ stateMutability: "payable",
444
+ inputs: [
445
+ { name: "commands", type: "bytes" },
446
+ { name: "inputs", type: "bytes[]" },
447
+ { name: "deadline", type: "uint256" }
448
+ ],
449
+ outputs: []
450
+ }
451
+ ], Fo = [
452
+ {
453
+ type: "function",
454
+ name: "modifyLiquidities",
455
+ stateMutability: "payable",
456
+ inputs: [
457
+ { name: "unlockData", type: "bytes" },
458
+ { name: "deadline", type: "uint256" }
459
+ ],
460
+ outputs: []
461
+ }
462
+ ], qo = [
463
+ {
464
+ type: "function",
465
+ name: "approve",
466
+ stateMutability: "nonpayable",
467
+ inputs: [
468
+ { name: "spender", type: "address" },
469
+ { name: "amount", type: "uint256" }
470
+ ],
471
+ outputs: [{ name: "", type: "bool" }]
472
+ },
473
+ {
474
+ type: "function",
475
+ name: "allowance",
476
+ stateMutability: "view",
477
+ inputs: [
478
+ { name: "owner", type: "address" },
479
+ { name: "spender", type: "address" }
480
+ ],
481
+ outputs: [{ name: "", type: "uint256" }]
482
+ },
483
+ {
484
+ type: "function",
485
+ name: "balanceOf",
486
+ stateMutability: "view",
487
+ inputs: [{ name: "account", type: "address" }],
488
+ outputs: [{ name: "", type: "uint256" }]
489
+ },
490
+ {
491
+ type: "function",
492
+ name: "decimals",
493
+ stateMutability: "view",
494
+ inputs: [],
495
+ outputs: [{ name: "", type: "uint8" }]
496
+ },
497
+ {
498
+ type: "function",
499
+ name: "symbol",
500
+ stateMutability: "view",
501
+ inputs: [],
502
+ outputs: [{ name: "", type: "string" }]
503
+ },
504
+ {
505
+ type: "function",
506
+ name: "name",
507
+ stateMutability: "view",
508
+ inputs: [],
509
+ outputs: [{ name: "", type: "string" }]
510
+ }
511
+ ], Uo = [
512
+ {
513
+ type: "function",
514
+ name: "allowance",
515
+ stateMutability: "view",
516
+ inputs: [
517
+ { name: "user", type: "address" },
518
+ { name: "token", type: "address" },
519
+ { name: "spender", type: "address" }
520
+ ],
521
+ outputs: [
522
+ { name: "amount", type: "uint160" },
523
+ { name: "expiration", type: "uint48" },
524
+ { name: "nonce", type: "uint48" }
525
+ ]
526
+ },
527
+ {
528
+ type: "function",
529
+ name: "approve",
530
+ stateMutability: "nonpayable",
531
+ inputs: [
532
+ { name: "token", type: "address" },
533
+ { name: "spender", type: "address" },
534
+ { name: "amount", type: "uint160" },
535
+ { name: "expiration", type: "uint48" }
536
+ ],
537
+ outputs: []
538
+ }
539
+ ], Do = (1n << 160n) - 1n, Go = (1n << 48n) - 1n, Wo = (1n << 256n) - 1n;
540
+ class gt {
541
+ #e = [];
542
+ /** Appends an action. Order is the execution order. */
543
+ add(n, t, o) {
544
+ if (!Number.isInteger(n) || n < 0 || n > 255)
545
+ throw new RangeError(`action id must fit in one byte: ${n}`);
546
+ return this.#e.push({ action: n, params: t, label: o }), this;
547
+ }
548
+ /** The planned steps, in order. */
549
+ get steps() {
550
+ return this.#e;
551
+ }
552
+ /** Human-readable trace of the plan, used in dev tooling and error messages. */
553
+ describe() {
554
+ return this.#e.map((n, t) => `${t}. ${n.label} (0x${n.action.toString(16).padStart(2, "0")})`).join(`
555
+ `);
556
+ }
557
+ /** `abi.encode(bytes actions, bytes[] params)`. */
558
+ encode() {
559
+ if (this.#e.length === 0)
560
+ throw new Error("[@latchprotocol/widgets] cannot encode an empty action plan");
561
+ const n = Tn(
562
+ this.#e.map((o) => `0x${o.action.toString(16).padStart(2, "0")}`)
563
+ ), t = this.#e.map((o) => o.params);
564
+ return P(
565
+ [
566
+ { name: "actions", type: "bytes" },
567
+ { name: "params", type: "bytes[]" }
568
+ ],
569
+ [n, t]
570
+ );
571
+ }
572
+ }
573
+ function It() {
574
+ return new gt();
575
+ }
576
+ const vt = [
577
+ { name: "currency0", type: "address" },
578
+ { name: "currency1", type: "address" },
579
+ { name: "hooks", type: "address" },
580
+ { name: "poolManager", type: "address" },
581
+ { name: "fee", type: "uint24" },
582
+ { name: "parameters", type: "bytes32" }
583
+ ], Tt = [
584
+ {
585
+ name: "params",
586
+ type: "tuple",
587
+ components: [
588
+ { name: "poolKey", type: "tuple", components: vt },
589
+ { name: "swapDirection", type: "bool" },
590
+ { name: "amountIn", type: "uint128" },
591
+ { name: "amountOutMinimum", type: "uint128" },
592
+ { name: "hookData", type: "bytes" }
593
+ ]
594
+ }
595
+ ], Et = [
596
+ { name: "intermediateCurrency", type: "address" },
597
+ { name: "fee", type: "uint24" },
598
+ { name: "hooks", type: "address" },
599
+ { name: "poolManager", type: "address" },
600
+ { name: "hookData", type: "bytes" },
601
+ { name: "parameters", type: "bytes32" }
602
+ ], At = [
603
+ {
604
+ name: "params",
605
+ type: "tuple",
606
+ components: [
607
+ { name: "currencyIn", type: "address" },
608
+ { name: "path", type: "tuple[]", components: Et },
609
+ { name: "amountIn", type: "uint128" },
610
+ { name: "amountOutMinimum", type: "uint128" }
611
+ ]
612
+ }
613
+ ], We = [
614
+ { name: "currency", type: "address" },
615
+ { name: "amount", type: "uint256" }
616
+ ], ee = [
617
+ { name: "currency", type: "address" },
618
+ { name: "recipient", type: "address" },
619
+ { name: "amount", type: "uint256" }
620
+ ];
621
+ function an(e) {
622
+ return R(e, "0x0000000000000000000000000000000000000000");
623
+ }
624
+ function Lt(e) {
625
+ return R(e.poolKey.currency0, e.currencyIn);
626
+ }
627
+ function St(e) {
628
+ if (e.length === 0)
629
+ throw new Error("[@latchprotocol/widgets] cannot encode a swap with no hops");
630
+ for (let n = 1; n < e.length; n += 1) {
631
+ const t = e[n - 1], o = e[n];
632
+ if (!(t === void 0 || o === void 0) && !R(t.currencyOut, o.currencyIn))
633
+ throw new Error(
634
+ `[@latchprotocol/widgets] route is not contiguous: hop ${n - 1} outputs ${t.currencyOut} but hop ${n} takes ${o.currencyIn}`
635
+ );
636
+ }
637
+ }
638
+ function $t(e) {
639
+ const n = e[0];
640
+ if (n === void 0)
641
+ throw new Error("[@latchprotocol/widgets] cannot encode a swap with no hops");
642
+ for (const t of e)
643
+ if (t.poolType !== n.poolType)
644
+ throw new Error(
645
+ "[@latchprotocol/widgets] a single swap action cannot mix CL and BIN hops. Split the route into one action per pool type, or route through a single type."
646
+ );
647
+ return n.poolType;
648
+ }
649
+ function Bt(e, n, t) {
650
+ return P(Tt, [
651
+ {
652
+ poolKey: {
653
+ currency0: e.poolKey.currency0,
654
+ currency1: e.poolKey.currency1,
655
+ hooks: e.poolKey.hooks,
656
+ poolManager: e.poolKey.poolManager,
657
+ fee: e.poolKey.fee,
658
+ parameters: e.poolKey.parameters
659
+ },
660
+ // CL calls this `zeroForOne`, BIN calls it `swapForY`; same bit, same meaning.
661
+ swapDirection: Lt(e),
662
+ amountIn: n,
663
+ amountOutMinimum: t,
664
+ hookData: e.hookData ?? "0x"
665
+ }
666
+ ]);
667
+ }
668
+ function Pt(e, n, t) {
669
+ const o = e[0];
670
+ if (o === void 0) throw new Error("[@latchprotocol/widgets] empty route");
671
+ return P(At, [
672
+ {
673
+ currencyIn: o.currencyIn,
674
+ path: e.map((r) => ({
675
+ intermediateCurrency: r.currencyOut,
676
+ fee: r.poolKey.fee,
677
+ hooks: r.poolKey.hooks,
678
+ poolManager: r.poolKey.poolManager,
679
+ hookData: r.hookData ?? "0x",
680
+ parameters: r.poolKey.parameters
681
+ })),
682
+ amountIn: n,
683
+ amountOutMinimum: t
684
+ }
685
+ ]);
686
+ }
687
+ function Nt(e) {
688
+ St(e.hops);
689
+ const n = $t(e.hops), t = e.hops[0], o = e.hops[e.hops.length - 1];
690
+ if (t === void 0 || o === void 0)
691
+ throw new Error("[@latchprotocol/widgets] empty route");
692
+ const r = t.currencyIn, s = o.currencyOut;
693
+ Ot(e);
694
+ const i = e.hops.length === 1, u = i ? n === "CL" ? O.CL_SWAP_EXACT_IN_SINGLE : O.BIN_SWAP_EXACT_IN_SINGLE : n === "CL" ? O.CL_SWAP_EXACT_IN : O.BIN_SWAP_EXACT_IN, a = i ? Bt(t, e.amountIn, e.minAmountOutGross) : Pt(e.hops, e.amountIn, e.minAmountOutGross), l = It().add(
695
+ u,
696
+ a,
697
+ `${n} swap exact-in${i ? " (single hop)" : ` (${e.hops.length} hops)`}`
698
+ );
699
+ l.add(
700
+ O.SETTLE_ALL,
701
+ P(We, [r, e.amountIn]),
702
+ "settle input currency from the caller"
703
+ );
704
+ const c = R(e.recipient, e.sender), d = c ? sn : e.recipient;
705
+ return e.integrator.feeMode === "pay-portion" ? (l.add(
706
+ O.TAKE,
707
+ P(ee, [
708
+ s,
709
+ bt,
710
+ Ge
711
+ ]),
712
+ "take output to the router for the fee split"
713
+ ), { plan: l, currencyIn: r, currencyOut: s }) : (e.integrator.active && l.add(
714
+ O.TAKE_PORTION,
715
+ P(ee, [
716
+ s,
717
+ e.integrator.referrer,
718
+ BigInt(e.integrator.feeBps)
719
+ ]),
720
+ `integrator fee: ${e.integrator.feeBps} bps of output to ${e.integrator.referrer}`
721
+ ), c ? l.add(
722
+ O.TAKE_ALL,
723
+ P(We, [s, e.minAmountOutNet]),
724
+ "take remaining output to the caller, floored at minAmountOutNet"
725
+ ) : l.add(
726
+ O.TAKE,
727
+ P(ee, [
728
+ s,
729
+ d,
730
+ Ge
731
+ ]),
732
+ "take remaining output to the configured recipient"
733
+ ), { plan: l, currencyIn: r, currencyOut: s });
734
+ }
735
+ function Ot(e) {
736
+ const { integrator: n } = e;
737
+ if (n.active) {
738
+ if (n.feeBps <= 0 || n.feeBps > J)
739
+ throw new RangeError(
740
+ `[@latchprotocol/widgets] refusing to encode integrator feeBps ${n.feeBps}; expected 1..${J}. This config should have been rejected by validateIntegratorConfig - do not construct ResolvedIntegratorConfig by hand.`
741
+ );
742
+ if (an(n.referrer))
743
+ throw new Error(
744
+ "[@latchprotocol/widgets] refusing to encode an integrator fee to the zero address"
745
+ );
746
+ }
747
+ if (e.minAmountOutNet > e.minAmountOutGross)
748
+ throw new RangeError(
749
+ `[@latchprotocol/widgets] minAmountOutNet (${e.minAmountOutNet}) exceeds minAmountOutGross (${e.minAmountOutGross}); the fee step can only reduce the output`
750
+ );
751
+ if (e.amountIn <= 0n)
752
+ throw new RangeError(`[@latchprotocol/widgets] amountIn must be positive: ${e.amountIn}`);
753
+ }
754
+ function xt(e) {
755
+ const { plan: n, currencyIn: t, currencyOut: o } = Nt(e), r = [we.INFI_SWAP], s = [n.encode()], i = e.integrator.feeMode === "pay-portion", a = R(e.recipient, e.sender) ? sn : e.recipient;
756
+ i && (e.integrator.active && (r.push(we.PAY_PORTION), s.push(
757
+ P(ee, [
758
+ o,
759
+ e.integrator.referrer,
760
+ BigInt(e.integrator.feeBps)
761
+ ])
762
+ )), r.push(we.SWEEP), s.push(
763
+ P(ee, [
764
+ o,
765
+ a,
766
+ e.minAmountOutNet
767
+ ])
768
+ ));
769
+ const l = `0x${r.map((p) => p.toString(16).padStart(2, "0")).join("")}`, c = En({
770
+ abi: kt,
771
+ functionName: "execute",
772
+ args: [l, s, e.deadline]
773
+ }), d = e.integrator.active ? Re(
774
+ e.expectedAmountOutGross ?? e.minAmountOutGross,
775
+ e.integrator.feeBps
776
+ ) : 0n;
777
+ return {
778
+ to: e.router,
779
+ data: c,
780
+ value: an(t) ? e.amountIn : 0n,
781
+ commands: l,
782
+ inputs: s,
783
+ planTrace: n.describe(),
784
+ integratorFee: e.integrator.active ? {
785
+ referrer: e.integrator.referrer,
786
+ feeBps: e.integrator.feeBps,
787
+ currency: o,
788
+ mode: e.integrator.feeMode,
789
+ expectedAmount: d
790
+ } : null
791
+ };
792
+ }
793
+ function Ko(e) {
794
+ return e === "timestamp" ? en : $n;
795
+ }
796
+ const Ho = 1e6, un = "0x0000000000000000000000000000000000000000";
797
+ function Xo(e, n) {
798
+ const t = n === "timestamp" ? e.startTime : e.startBlock, o = n === "timestamp" ? e.decaySeconds : e.decayBlocks;
799
+ if (t === void 0 || o === void 0)
800
+ throw new Error(
801
+ `[@latchprotocol/widgets] getLaunch result has no ${n === "timestamp" ? "startTime/decaySeconds" : "startBlock/decayBlocks"}: it was decoded with the other hook generation's ABI.`
802
+ );
803
+ return {
804
+ durationClock: n,
805
+ owner: e.owner,
806
+ start: BigInt(t),
807
+ window: Number(o),
808
+ enabled: e.enabled,
809
+ initialFeePips: e.initialFeeBips,
810
+ finalFeePips: e.finalFeeBips,
811
+ maxBuyPerTx: e.maxBuyPerTx,
812
+ launchTokenIsCurrency0: e.launchTokenIsCurrency0,
813
+ launched: e.launched
814
+ };
815
+ }
816
+ function ln(e) {
817
+ return !R(e.owner, un);
818
+ }
819
+ function _t(e, n) {
820
+ if (!ln(e)) return null;
821
+ if (!e.enabled) return e.finalFeePips;
822
+ if (n < e.start) return e.initialFeePips;
823
+ const t = BigInt(e.window), o = n - e.start;
824
+ if (t <= 0n || o >= t) return e.finalFeePips;
825
+ const s = BigInt(e.initialFeePips - e.finalFeePips) * o / t;
826
+ return e.initialFeePips - Number(s);
827
+ }
828
+ function cn(e, n) {
829
+ const t = e.durationClock;
830
+ if (!ln(e))
831
+ return {
832
+ phase: "unclaimed",
833
+ durationClock: t,
834
+ now: n,
835
+ start: null,
836
+ end: null,
837
+ untilOpen: null,
838
+ remaining: null,
839
+ decayProgressBps: null,
840
+ feePips: null,
841
+ initialFeePips: null,
842
+ finalFeePips: null,
843
+ tradingOpen: !1,
844
+ maxBuyPerTx: null,
845
+ maxBuyPerTxEnforced: !1
846
+ };
847
+ const o = BigInt(e.window), r = e.start + o, s = _t(e, n), i = e.maxBuyPerTx === 0n ? null : e.maxBuyPerTx;
848
+ if (!e.enabled)
849
+ return {
850
+ phase: "disabled",
851
+ durationClock: t,
852
+ now: n,
853
+ start: e.start,
854
+ end: r,
855
+ untilOpen: null,
856
+ remaining: null,
857
+ decayProgressBps: null,
858
+ feePips: s,
859
+ initialFeePips: e.initialFeePips,
860
+ finalFeePips: e.finalFeePips,
861
+ tradingOpen: !0,
862
+ maxBuyPerTx: i,
863
+ maxBuyPerTxEnforced: !1
864
+ };
865
+ if (n < e.start)
866
+ return {
867
+ phase: "pending",
868
+ durationClock: t,
869
+ now: n,
870
+ start: e.start,
871
+ end: r,
872
+ untilOpen: e.start - n,
873
+ remaining: null,
874
+ decayProgressBps: 0,
875
+ feePips: s,
876
+ initialFeePips: e.initialFeePips,
877
+ finalFeePips: e.finalFeePips,
878
+ tradingOpen: !1,
879
+ maxBuyPerTx: i,
880
+ maxBuyPerTxEnforced: !1
881
+ };
882
+ const u = n - e.start;
883
+ return o > 0n && u < o ? {
884
+ phase: "decaying",
885
+ durationClock: t,
886
+ now: n,
887
+ start: e.start,
888
+ end: r,
889
+ untilOpen: null,
890
+ remaining: o - u,
891
+ decayProgressBps: Number(u * 10000n / o),
892
+ feePips: s,
893
+ initialFeePips: e.initialFeePips,
894
+ finalFeePips: e.finalFeePips,
895
+ tradingOpen: !0,
896
+ maxBuyPerTx: i,
897
+ maxBuyPerTxEnforced: i !== null
898
+ } : {
899
+ phase: "settled",
900
+ durationClock: t,
901
+ now: n,
902
+ start: e.start,
903
+ end: r,
904
+ untilOpen: null,
905
+ remaining: null,
906
+ decayProgressBps: 1e4,
907
+ feePips: s,
908
+ initialFeePips: e.initialFeePips,
909
+ finalFeePips: e.finalFeePips,
910
+ tradingOpen: !0,
911
+ maxBuyPerTx: i,
912
+ maxBuyPerTxEnforced: !1
913
+ };
914
+ }
915
+ function dn(e) {
916
+ const n = cn(e.guard, e.now);
917
+ return n.phase === "unclaimed" ? {
918
+ reason: "not-configured",
919
+ message: "No launch is configured for this pool",
920
+ revert: "LaunchNotConfigured"
921
+ } : n.tradingOpen ? n.maxBuyPerTxEnforced && n.maxBuyPerTx !== null && e.amountIn !== null && e.amountIn > n.maxBuyPerTx ? {
922
+ reason: "exceeds-max-buy-per-tx",
923
+ message: "Amount is over the per-transaction cap for this launch",
924
+ revert: "BuyExceedsMaxPerTx"
925
+ } : { reason: null, message: null, revert: null } : {
926
+ reason: "trading-not-open",
927
+ message: "Trading has not opened yet",
928
+ revert: "TradingNotOpen"
929
+ };
930
+ }
931
+ function Rt(e, n) {
932
+ const t = R(e.poolKey.currency0, e.currencyIn);
933
+ return n.launchTokenIsCurrency0 ? !t : t;
934
+ }
935
+ function Vo(e) {
936
+ if (R(e.hop.poolKey.hooks, un))
937
+ throw new Error(
938
+ "[@latchprotocol/widgets] the pool key names no hook, so it is not a launch pool"
939
+ );
940
+ if (!Rt(e.hop, e.guard))
941
+ throw new Error(
942
+ "[@latchprotocol/widgets] this hop sells the launch token rather than buying it. Sells are ordinary swaps: use buildSwapCall directly."
943
+ );
944
+ const n = dn({
945
+ guard: e.guard,
946
+ now: e.now,
947
+ amountIn: e.amountIn
948
+ });
949
+ if (n.reason !== null)
950
+ throw new Error(
951
+ `[@latchprotocol/widgets] refusing to encode a launch buy: ${n.message} (the hook would revert ${n.revert})`
952
+ );
953
+ const { hop: t, guard: o, now: r, ...s } = e;
954
+ return xt({ ...s, hops: [t] });
955
+ }
956
+ function Ct(e) {
957
+ return e instanceof Error ? e : new Error(String(e));
958
+ }
959
+ function A(e, n, t = {}) {
960
+ const { enabled: o = !0, refetchIntervalMs: r = 0 } = t, [s, i] = I("idle"), [u, a] = I(null), [l, c] = I(null), [d, p] = I(null), [f, k] = I(!1), [v, h] = I(0), m = fe(!0), T = fe(0), C = fe(e);
961
+ C.current = e, z(() => (m.current = !0, () => {
962
+ m.current = !1;
963
+ }), []);
964
+ const b = y(() => {
965
+ h((L) => L + 1);
966
+ }, []);
967
+ return z(() => {
968
+ if (!o) {
969
+ i("idle"), k(!1);
970
+ return;
971
+ }
972
+ T.current += 1;
973
+ const L = T.current;
974
+ u !== null ? k(!0) : i("loading"), C.current().then((S) => {
975
+ !m.current || L !== T.current || (a(S), c(null), i("success"), p(Date.now()), k(!1));
976
+ }).catch((S) => {
977
+ !m.current || L !== T.current || (c(Ct(S)), i("error"), k(!1));
978
+ });
979
+ }, [o, v, ...n]), z(() => {
980
+ if (!o || r <= 0) return;
981
+ const L = setInterval(b, r);
982
+ return () => clearInterval(L);
983
+ }, [o, r, b]), { status: s, data: u, error: l, updatedAt: d, isRefreshing: f, refetch: b };
984
+ }
985
+ class Mt extends Error {
986
+ operation;
987
+ constructor(n, t) {
988
+ super(`[@latchprotocol/widgets] ${n} is not available: ${t}`), this.name = "UnsupportedOperationError", this.operation = n;
989
+ }
990
+ }
991
+ class ue extends Error {
992
+ constructor(n) {
993
+ super(`[@latchprotocol/widgets] connect a wallet before attempting to ${n}`), this.name = "WalletNotConnectedError";
994
+ }
995
+ }
996
+ class Ft extends Error {
997
+ tokenIn;
998
+ tokenOut;
999
+ constructor(n, t) {
1000
+ super(`[@latchprotocol/widgets] no pool connects ${n} to ${t}`), this.name = "NoRouteError", this.tokenIn = n, this.tokenOut = t;
1001
+ }
1002
+ }
1003
+ const qt = Ln([
1004
+ "error WrappedError(address target, bytes4 selector, bytes reason, bytes details)",
1005
+ "error UnexpectedRevertBytes(bytes revertData)",
1006
+ "error PoolNotInitialized()",
1007
+ "error InvalidFeeForExactOut()",
1008
+ "error InvalidSqrtPriceLimit(uint160 sqrtPriceCurrentX96, uint160 sqrtPriceLimitX96)",
1009
+ "error NoLiquidityToReceiveFees()",
1010
+ "error BinPool__OutOfLiquidity()",
1011
+ "error BinPool__InsufficientAmountUnSpecified()",
1012
+ "error CurrencyNotSettled()",
1013
+ "error HookDeltaExceedsSwapAmount()",
1014
+ "error InvalidHookResponse()",
1015
+ "error HookCallFailed()",
1016
+ "error Error(string)"
1017
+ ]), Ut = (() => {
1018
+ const e = /* @__PURE__ */ new Set(), n = [];
1019
+ for (const t of [
1020
+ qt,
1021
+ Bn,
1022
+ Pn,
1023
+ Nn,
1024
+ On,
1025
+ xn,
1026
+ en,
1027
+ _n,
1028
+ Un,
1029
+ Dn
1030
+ ])
1031
+ for (const o of t) {
1032
+ if (o.type !== "error" || o.name === void 0) continue;
1033
+ const r = `${o.name}(${(o.inputs ?? []).map((s) => s.type).join(",")})`;
1034
+ e.has(r) || (e.add(r), n.push(o));
1035
+ }
1036
+ return n;
1037
+ })(), Dt = {
1038
+ TransactionDeadlinePassed: "The transaction's deadline passed before it was mined. Nothing was spent; try again.",
1039
+ DeadlinePassed: "The transaction's deadline passed before it was mined. Nothing was spent; try again.",
1040
+ SignatureDeadlineExpired: "The signature's deadline passed. Sign again.",
1041
+ TooLittleReceived: "The price moved past your slippage tolerance, so the trade was refused.",
1042
+ V3TooLittleReceived: "The price moved past your slippage tolerance, so the trade was refused.",
1043
+ V2TooLittleReceived: "The price moved past your slippage tolerance, so the trade was refused.",
1044
+ TooMuchRequested: "The price moved past your slippage tolerance, so the trade was refused.",
1045
+ MinimumAmountInsufficient: "The pool would return less than your minimum, so it was refused. Widen slippage or try again.",
1046
+ MaximumAmountExceeded: "The pool would take more than your maximum, so it was refused. Widen slippage or try again.",
1047
+ LiquiditySlippageCaught: "The pool price moved while you were adding liquidity, so it was refused.",
1048
+ IdSlippageCaught: "The active bin moved while you were adding liquidity, so it was refused.",
1049
+ NotEnoughLiquidity: "The pool does not hold enough liquidity to fill this amount.",
1050
+ BinPool__OutOfLiquidity: "The pool does not hold enough liquidity to fill this amount.",
1051
+ InvalidSqrtPriceLimit: "This amount would move the price past the pool's limit. Try a smaller amount.",
1052
+ PoolNotInitialized: "This pool has not been initialised yet.",
1053
+ InsufficientBalance: "Your balance is too low for this transaction.",
1054
+ InsufficientETH: "Not enough native currency was sent with this transaction.",
1055
+ InsufficientToken: "Your token balance is too low for this transaction.",
1056
+ BalanceTooLow: "Your balance is too low for this transaction.",
1057
+ TradingNotOpen: "Trading on this launch pool has not opened yet.",
1058
+ BuyExceedsMaxPerTx: "This buy is larger than the launch's per-transaction cap. Try a smaller amount.",
1059
+ ExactOutputBuyBlockedDuringLaunch: "Exact-output buys are blocked while the launch is decaying.",
1060
+ TaxedActiveBinMintBlocked: "Liquidity cannot be added to the active bin while the launch's creator tax is live.",
1061
+ EnforcedPause: "The router is paused.",
1062
+ ContractLocked: "The contract is busy with another call. Try again.",
1063
+ /* LatchPositionLock / LatchTokenLock (the locker widget). */
1064
+ InsufficientFee: "Less than the lock fee was sent. The fee may have risen since it was read; reload and try again.",
1065
+ AlreadyLocked: "This position is already locked.",
1066
+ EmptyPosition: "This position holds no liquidity, so there is nothing to lock.",
1067
+ NotPositionOwner: "The connected wallet does not own this position.",
1068
+ InvalidUnlock: "The unlock date must be in the future and at most 100 years away.",
1069
+ InvalidOwner: "The lock owner is not a valid address.",
1070
+ NotLater: "A lock can only be extended to a later date, never shortened.",
1071
+ NotLockOwner: "Only the lock owner can do this.",
1072
+ NotPendingOwner: "Only the address the lock was offered to can accept it.",
1073
+ NotLocked: "No lock exists for this position.",
1074
+ StillLocked: "The lock has not reached its unlock date yet.",
1075
+ PositionIsLocked: "This position is held by a lock.",
1076
+ InvalidSchedule: "The schedule is invalid: it needs start <= cliff <= end, an end in the future, at most 100 years away.",
1077
+ InvalidBeneficiary: "The beneficiary is not a valid address.",
1078
+ NativeValueMismatch: "The native amount sent does not match the amount plus the fee.",
1079
+ NoSuchLock: "No lock exists with this id.",
1080
+ NotBeneficiary: "Only the beneficiary can claim or move this lock.",
1081
+ NotPendingBeneficiary: "Only the address the lock was offered to can accept it.",
1082
+ NothingToClaim: "Nothing has vested beyond what was already claimed.",
1083
+ ZeroAmount: "Lock an amount above zero.",
1084
+ SafeERC20FailedOperation: "The token transfer failed. Check the balance and the approval."
1085
+ };
1086
+ function Gt(e) {
1087
+ let n = null;
1088
+ const t = (i) => {
1089
+ if (n !== null || i === null || typeof i != "object") return;
1090
+ const u = i;
1091
+ for (const a of ["raw", "data"]) {
1092
+ const l = u[a];
1093
+ if (typeof l == "string" && /^0x[0-9a-fA-F]{8,}$/.test(l)) {
1094
+ n = l;
1095
+ return;
1096
+ }
1097
+ if (l !== null && typeof l == "object" && typeof l.data == "string") {
1098
+ const c = l.data;
1099
+ if (/^0x[0-9a-fA-F]{8,}$/.test(c)) {
1100
+ n = c;
1101
+ return;
1102
+ }
1103
+ }
1104
+ }
1105
+ t(u.cause);
1106
+ };
1107
+ if (t(e), n !== null) return n;
1108
+ const o = Me(e), r = /custom error (0x[0-9a-fA-F]{8})(?::\s*(?:0x)?([0-9a-fA-F]*))?/.exec(o);
1109
+ if (r !== null) return `${r[1]}${r[2] ?? ""}`;
1110
+ const s = /signature:\s*\n?\s*(0x[0-9a-fA-F]{8,})/.exec(o);
1111
+ return s !== null ? s[1] : null;
1112
+ }
1113
+ function Me(e) {
1114
+ return e instanceof Je ? `${e.message}` : e instanceof Error ? e.message : String(e);
1115
+ }
1116
+ function Te(e, n = 0) {
1117
+ if (n > 4 || e.length < 10) return null;
1118
+ try {
1119
+ const t = An({ abi: Ut, data: e }), o = t.args ?? [];
1120
+ if (t.errorName === "WrappedError") {
1121
+ const r = o[2];
1122
+ return typeof r == "string" && r.length >= 10 ? Te(r, n + 1) ?? "WrappedError" : "WrappedError";
1123
+ }
1124
+ if (t.errorName === "UnexpectedRevertBytes") {
1125
+ const r = o[0];
1126
+ return typeof r == "string" && r.length >= 10 ? Te(r, n + 1) : null;
1127
+ }
1128
+ return t.errorName === "Error" && typeof o[0] == "string" ? `Error: ${o[0]}` : t.errorName;
1129
+ } catch {
1130
+ return null;
1131
+ }
1132
+ }
1133
+ function Wt(e) {
1134
+ return e.startsWith("Error: ") ? `The contract refused: ${e.slice(7)}` : Dt[e] ?? `The contract refused the transaction (${e}).`;
1135
+ }
1136
+ function Kt(e) {
1137
+ let n = !1;
1138
+ const t = (o, r) => {
1139
+ if (n || r > 6 || o === null || typeof o != "object") return;
1140
+ const s = o;
1141
+ if (s.code === 4001 || s.name === "UserRejectedRequestError") {
1142
+ n = !0;
1143
+ return;
1144
+ }
1145
+ t(s.cause, r + 1);
1146
+ };
1147
+ return t(e, 0), n || /user rejected|user denied|rejected the request/i.test(Me(e));
1148
+ }
1149
+ function Ke(e) {
1150
+ const t = e.replace(/^\[@latchprotocol\/widgets\]\s*/, "").split(`
1151
+ `)[0]?.trim() ?? "";
1152
+ return t.length > 180 ? `${t.slice(0, 177)}…` : t;
1153
+ }
1154
+ function pn(e, n = "transaction") {
1155
+ if (e == null) return "Something went wrong.";
1156
+ if (Kt(e)) return "You rejected the request in your wallet. Nothing was sent.";
1157
+ if (e instanceof ue) return "Connect a wallet first.";
1158
+ if (e instanceof Ft) return "No pool on this site connects these two tokens.";
1159
+ const t = Gt(e), o = t === null ? null : Te(t);
1160
+ if (o !== null) return Wt(o);
1161
+ if (e instanceof Mt) {
1162
+ if (e.operation === "quoteSwap") {
1163
+ if (/every direct pool for this pair failed to quote/.test(e.message))
1164
+ return "No pool could quote this trade. The amount may be more than the pool can fill, or trading may not be open yet.";
1165
+ if (/no configured pool holds both/.test(e.message)) return "No pool on this site connects these two tokens.";
1166
+ if (/no quoter is configured/.test(e.message)) return "This site has no quoter for that pool type, so it will not price the trade.";
1167
+ }
1168
+ return e.operation === "quoteAddLiquidity" ? /mint no liquidity/.test(e.message) ? "These amounts add no liquidity to this range. Enter a larger amount of the token the range holds." : /active bin is/.test(e.message) ? "The active bin moved since the range was set. Reset the range and try again." : /nothing to deposit/.test(e.message) ? "The chosen bins take only the token whose amount is zero. Enter an amount of the other token." : "This position cannot be priced on this pool. Check the range and the amounts." : "This action is not available on this deployment.";
1169
+ }
1170
+ if (t !== null) return `The contract refused the transaction (unrecognised error ${t.slice(0, 10)}).`;
1171
+ if (e instanceof Je && typeof e.shortMessage == "string" && e.shortMessage !== "")
1172
+ return /reverted/i.test(e.shortMessage) ? n === "quote" ? "The pool refused to quote this trade." : "The transaction would revert, so it was not sent." : Ke(e.shortMessage);
1173
+ const r = Ke(Me(e));
1174
+ return r === "" ? "Something went wrong." : r;
1175
+ }
1176
+ function He(e) {
1177
+ return e instanceof Error ? e : new Error(String(e));
1178
+ }
1179
+ function Ht(e) {
1180
+ const { adapter: n, chain: t, integrator: o } = E(), { tokenIn: r, tokenOut: s, amountIn: i, quote: u, breakdown: a } = e, [l, c] = I("idle"), [d, p] = I(null), [f, k] = I(null), [v, h] = I(null), [m, T] = I(0), b = A(
1181
+ y(() => n.getAccount(), [n]),
1182
+ [n]
1183
+ ).data, L = y(async () => r === null || i === null || b === null ? [] : n.getApprovalRequirements(r, b, i), [n, r, i, b]), S = A(
1184
+ L,
1185
+ [
1186
+ n,
1187
+ r?.address ?? null,
1188
+ i === null ? null : i.toString(),
1189
+ b,
1190
+ m
1191
+ ],
1192
+ { enabled: r !== null && i !== null && i > 0n && b !== null }
1193
+ ).data ?? [], j = S.length > 0, Fe = r !== null && s !== null && i !== null && i > 0n && u !== null && a !== null && b !== null && !j && (l === "idle" || l === "error" || l === "success"), M = y(async () => {
1194
+ const w = S[0];
1195
+ if (w !== void 0) {
1196
+ p(null), c("approving");
1197
+ try {
1198
+ const g = await n.buildApproval(w), $ = await n.sendTransaction(g);
1199
+ await n.waitForTransaction($), T((ie) => ie + 1), c("idle");
1200
+ } catch (g) {
1201
+ const $ = He(g);
1202
+ p($), c("error"), e.onError?.($);
1203
+ }
1204
+ }
1205
+ }, [n, S, e]), ce = y(async () => {
1206
+ if (!(r === null || s === null || i === null) && !(u === null || a === null)) {
1207
+ if (b === null) {
1208
+ const w = new ue("swap");
1209
+ p(w), c("error"), e.onError?.(w);
1210
+ return;
1211
+ }
1212
+ p(null), k(null), c("building");
1213
+ try {
1214
+ const w = await n.buildSwap({
1215
+ quote: u,
1216
+ tokenIn: r,
1217
+ tokenOut: s,
1218
+ amountIn: i,
1219
+ minAmountOutGross: a.minAmountOutGross,
1220
+ minAmountOutNet: a.minAmountOutNet,
1221
+ // The validated config from context. Never a raw prop.
1222
+ integrator: o,
1223
+ recipient: e.recipient ?? b,
1224
+ deadline: await _e(t, n)
1225
+ });
1226
+ h(w), c("awaiting-signature");
1227
+ const g = await n.sendTransaction(w);
1228
+ if (k(g), c("pending"), (await n.waitForTransaction(g)).status === "reverted")
1229
+ throw new Error(`The swap was mined but reverted (${g}).`);
1230
+ c("success"), e.onSuccess?.(g);
1231
+ } catch (w) {
1232
+ const g = He(w);
1233
+ p(g), c("error"), e.onError?.(g);
1234
+ }
1235
+ }
1236
+ }, [
1237
+ n,
1238
+ b,
1239
+ i,
1240
+ a,
1241
+ t,
1242
+ o,
1243
+ e,
1244
+ u,
1245
+ r,
1246
+ s
1247
+ ]), de = y(() => {
1248
+ c("idle"), p(null), k(null), h(null);
1249
+ }, []), Y = l === "idle" && j ? "needs-approval" : l, se = N(
1250
+ () => Xt(Y, S[0], d, n.isMock),
1251
+ [Y, S, d, n.isMock]
1252
+ );
1253
+ return {
1254
+ step: Y,
1255
+ error: d,
1256
+ txHash: f,
1257
+ approvals: S,
1258
+ needsApproval: j,
1259
+ canExecute: Fe,
1260
+ statusMessage: se,
1261
+ preparedTransaction: v,
1262
+ approve: M,
1263
+ execute: ce,
1264
+ reset: de
1265
+ };
1266
+ }
1267
+ function Xt(e, n, t, o) {
1268
+ const r = o ? "Simulated (mock adapter): " : "";
1269
+ switch (e) {
1270
+ case "idle":
1271
+ return "";
1272
+ case "needs-approval":
1273
+ return n === void 0 ? "Approval required" : n.kind === "erc20-to-permit2" ? `Approve ${n.token.symbol} for Permit2 before swapping` : `Approve the router to spend ${n.token.symbol} via Permit2`;
1274
+ case "approving":
1275
+ return `${r}Waiting for the approval transaction to confirm`;
1276
+ case "building":
1277
+ return `${r}Preparing the swap transaction`;
1278
+ case "awaiting-signature":
1279
+ return `${r}Confirm the transaction in your wallet`;
1280
+ case "pending":
1281
+ return `${r}Swap submitted, waiting for confirmation`;
1282
+ case "success":
1283
+ return `${r}Swap confirmed`;
1284
+ case "error":
1285
+ return t === null ? "Something went wrong" : pn(t, "swap");
1286
+ default:
1287
+ return "";
1288
+ }
1289
+ }
1290
+ function Vt(e) {
1291
+ const { adapter: n, integrator: t, defaultSlippageBps: o } = E(), { tokenIn: r, tokenOut: s, amountIn: i } = e, u = e.slippageBps ?? o;
1292
+ if (!Number.isInteger(u) || u < 0 || u > _)
1293
+ throw new RangeError(
1294
+ `[@latchprotocol/widgets] slippageBps must be an integer in [0, ${_}]: ${u}`
1295
+ );
1296
+ const a = (e.enabled ?? !0) && r !== null && s !== null && i !== null && i > 0n && r.address.toLowerCase() !== s.address.toLowerCase(), l = y(async () => {
1297
+ if (r === null || s === null || i === null)
1298
+ throw new Error("useSwapQuote: called without a complete request");
1299
+ return n.quoteSwap({ tokenIn: r, tokenOut: s, amountIn: i, ...e.poolId === void 0 ? {} : { poolId: e.poolId } });
1300
+ }, [n, r, s, i, e.poolId]), c = A(
1301
+ l,
1302
+ [
1303
+ n,
1304
+ r?.address ?? null,
1305
+ s?.address ?? null,
1306
+ i === null ? null : i.toString(),
1307
+ e.poolId ?? null
1308
+ ],
1309
+ {
1310
+ enabled: a,
1311
+ refetchIntervalMs: e.refetchIntervalMs ?? 15e3
1312
+ }
1313
+ ), d = N(() => {
1314
+ const v = c.data;
1315
+ if (v === null || !a || c.status === "error" && !c.isRefreshing || r === null || s === null || i === null || v.amountIn !== i) return null;
1316
+ const h = v.route[0], m = v.route[v.route.length - 1];
1317
+ return h !== void 0 && h.tokenIn.address.toLowerCase() !== r.address.toLowerCase() || m !== void 0 && m.tokenOut.address.toLowerCase() !== s.address.toLowerCase() ? null : v;
1318
+ }, [c.data, c.status, c.isRefreshing, a, r, s, i]), p = a ? d !== null ? "success" : c.isRefreshing || c.status === "success" ? "loading" : c.status : "idle", f = N(() => d === null ? null : ct({
1319
+ amountIn: d.amountIn,
1320
+ grossAmountOut: d.grossAmountOut,
1321
+ spotAmountOut: d.spotAmountOut,
1322
+ lpFeeAmount: d.lpFeeAmount,
1323
+ lpFeePips: d.lpFeePips,
1324
+ ...d.lpFeeUnknown === void 0 ? {} : { lpFeeUnknown: d.lpFeeUnknown },
1325
+ slippageBps: u,
1326
+ integrator: t
1327
+ }), [d, u, t]), k = N(() => f === null || r === null || s === null ? null : dt(
1328
+ f.amountIn,
1329
+ r.decimals,
1330
+ f.netAmountOut,
1331
+ s.decimals
1332
+ ), [f, r, s]);
1333
+ return {
1334
+ status: p,
1335
+ quote: d,
1336
+ breakdown: f,
1337
+ error: p === "error" ? c.error : null,
1338
+ isRefreshing: c.isRefreshing && d !== null,
1339
+ updatedAt: c.updatedAt,
1340
+ isMock: n.isMock,
1341
+ rate: k,
1342
+ slippageBps: u,
1343
+ refetch: c.refetch
1344
+ };
1345
+ }
1346
+ function jo(e) {
1347
+ const { defaultSlippageBps: n } = E(), [t, o] = I(e ?? n), [r, s] = I(null), i = y((u) => {
1348
+ if (!Number.isInteger(u) || u < 0) {
1349
+ s("Slippage must be a whole number of basis points");
1350
+ return;
1351
+ }
1352
+ if (u > _) {
1353
+ s(`Slippage above ${_ / 100}% is not accepted`);
1354
+ return;
1355
+ }
1356
+ s(null), o(u);
1357
+ }, []);
1358
+ return { slippageBps: t, setSlippageBps: i, error: r };
1359
+ }
1360
+ function jt(e) {
1361
+ return e instanceof G && e.contract === "launchGuardHook";
1362
+ }
1363
+ function Yo(e) {
1364
+ return e.status === "error" ? jt(e.error) || Yt(e.error) ? "not-configured" : "error" : e.status === "loading" || e.status === "idle" ? "loading" : e.data === null || Array.isArray(e.data) && e.data.length === 0 ? "empty" : "ready";
1365
+ }
1366
+ function Zo() {
1367
+ const { adapter: e } = E();
1368
+ return A(
1369
+ y(() => e.listLaunches(), [e]),
1370
+ [e],
1371
+ { refetchIntervalMs: 12e3 }
1372
+ );
1373
+ }
1374
+ function Yt(e) {
1375
+ return e instanceof G && e.contract === "launchpadKitV2";
1376
+ }
1377
+ function Qo(e) {
1378
+ const { adapter: n } = E(), t = y(async () => e === null ? [] : n.getLaunchesForToken(e), [n, e]);
1379
+ return A(t, [n, e], { enabled: e !== null, refetchIntervalMs: 12e3 });
1380
+ }
1381
+ function zo(e) {
1382
+ const { adapter: n } = E(), t = y(async () => e === null ? null : n.getLaunch(e), [n, e]);
1383
+ return A(t, [n, e], {
1384
+ enabled: e !== null,
1385
+ refetchIntervalMs: 12e3
1386
+ });
1387
+ }
1388
+ function Jo(e) {
1389
+ const n = cn(e.guard, e.readAt), { initialFeePips: t, finalFeePips: o } = e.guard, r = t - o, s = r <= 0 ? null : Math.max(
1390
+ 0,
1391
+ Math.min(1e4, Math.round((t - e.currentFeePips) * 1e4 / r))
1392
+ );
1393
+ return {
1394
+ launch: e,
1395
+ schedule: n,
1396
+ feeSpanProgressBps: s,
1397
+ feeProjectionDriftPips: n.feePips === null ? null : e.currentFeePips - n.feePips
1398
+ };
1399
+ }
1400
+ function er(e) {
1401
+ const { launch: n, amountIn: t } = e, o = N(() => n === null ? { reason: "not-configured", message: "No launch loaded", revert: null } : dn({
1402
+ guard: n.guard,
1403
+ now: n.readAt,
1404
+ amountIn: t
1405
+ }), [n, t]), r = Vt({
1406
+ tokenIn: n?.quoteToken ?? null,
1407
+ tokenOut: n?.launchToken ?? null,
1408
+ amountIn: t,
1409
+ ...e.slippageBps === void 0 ? {} : { slippageBps: e.slippageBps },
1410
+ /* THIS pool. A v2 token can have a CL and a Bin leg against the same quote;
1411
+ the schedule shown and the pool bought through must be the same one. */
1412
+ ...n === null ? {} : { poolId: n.poolId },
1413
+ enabled: n !== null && o.reason === null
1414
+ }), s = Ht({
1415
+ tokenIn: n?.quoteToken ?? null,
1416
+ tokenOut: n?.launchToken ?? null,
1417
+ amountIn: t,
1418
+ quote: r.quote,
1419
+ breakdown: r.breakdown,
1420
+ ...e.recipient === void 0 ? {} : { recipient: e.recipient },
1421
+ ...e.onSuccess === void 0 ? {} : { onSuccess: e.onSuccess }
1422
+ });
1423
+ return {
1424
+ gate: o,
1425
+ breakdown: r.breakdown,
1426
+ quoteStatus: r.status,
1427
+ quoteError: r.error,
1428
+ quoteIsRefreshing: r.isRefreshing,
1429
+ rate: r.rate,
1430
+ execution: s,
1431
+ canBuy: o.reason === null && s.canExecute && r.status === "success"
1432
+ };
1433
+ }
1434
+ function nr() {
1435
+ const { adapter: e } = E();
1436
+ return A(y(() => e.listTokens(), [e]), [e]);
1437
+ }
1438
+ function tr() {
1439
+ const { adapter: e } = E();
1440
+ return A(y(() => e.getAccount(), [e]), [e]);
1441
+ }
1442
+ function or(e, n) {
1443
+ const { adapter: t } = E(), o = y(async () => e === null || n === null ? 0n : t.getBalance(e, n), [t, e, n]);
1444
+ return A(o, [t, e?.address ?? null, n], {
1445
+ enabled: e !== null && n !== null,
1446
+ refetchIntervalMs: 3e4
1447
+ });
1448
+ }
1449
+ function rr() {
1450
+ const { adapter: e } = E();
1451
+ return A(y(() => e.listPools(), [e]), [e]);
1452
+ }
1453
+ function sr(e) {
1454
+ const { adapter: n } = E(), t = y(async () => e === null ? null : n.getPoolState(e), [n, e]);
1455
+ return A(t, [n, e?.id ?? null], { enabled: e !== null });
1456
+ }
1457
+ const X = 1n << 96n, Ee = 1n << 128n, Zt = (1n << 256n) - 1n, be = 1n << 256n, Ae = -887272, Le = 887272, Qt = [
1458
+ [0x2n, 0xfff97272373d413259a46990580e213an],
1459
+ [0x4n, 0xfff2e50f5f656932ef12357cf3c7fdccn],
1460
+ [0x8n, 0xffe5caca7e10e4e61c3624eaa0941cd0n],
1461
+ [0x10n, 0xffcb9843d60f6159c9db58835c926644n],
1462
+ [0x20n, 0xff973b41fa98c081472e6896dfb254c0n],
1463
+ [0x40n, 0xff2ea16466c96a3843ec78b326b52861n],
1464
+ [0x80n, 0xfe5dee046a99a2a811c461f1969c3053n],
1465
+ [0x100n, 0xfcbe86c7900a88aedcffc83b479aa3a4n],
1466
+ [0x200n, 0xf987a7253ac413176f2b074cf7815e54n],
1467
+ [0x400n, 0xf3392b0822b70005940c7a398e4b70f3n],
1468
+ [0x800n, 0xe7159475a2c29b7443b29c7fa6e889d9n],
1469
+ [0x1000n, 0xd097f3bdfd2022b8845ad8f792aa5825n],
1470
+ [0x2000n, 0xa9f746462d870fdf8a65dc1f90e061e5n],
1471
+ [0x4000n, 0x70d869a156d2a1b890bb3df62baf32f7n],
1472
+ [0x8000n, 0x31be135f97d08fd981231505542fcfa6n],
1473
+ [0x10000n, 0x9aa508b5b7a84e1c677de54f3e99bc9n],
1474
+ [0x20000n, 0x5d6af8dedb81196699c329225ee604n],
1475
+ [0x40000n, 0x2216e584f5fa1ea926041bedfe98n],
1476
+ [0x80000n, 0x48a170391f7dc42444e8fa2n]
1477
+ ];
1478
+ function B(e) {
1479
+ if (!Number.isInteger(e) || e < Ae || e > Le)
1480
+ throw new RangeError(`tick out of range: ${e}`);
1481
+ const n = BigInt(Math.abs(e));
1482
+ let t = (n & 0x1n) !== 0n ? 0xfffcb933bd6fad37aa2d162d1a594001n : Ee;
1483
+ for (const [o, r] of Qt)
1484
+ (n & o) !== 0n && (t = t * r >> 128n);
1485
+ return e > 0 && (t = Zt / t), (t >> 32n) + (t % (1n << 32n) === 0n ? 0n : 1n);
1486
+ }
1487
+ function fn(e, n, t) {
1488
+ const o = e * n;
1489
+ return o % t === 0n ? o / t : o / t + 1n;
1490
+ }
1491
+ function zt(e, n) {
1492
+ return e % n === 0n ? e / n : e / n + 1n;
1493
+ }
1494
+ function re(e, n) {
1495
+ return e <= n ? [e, n] : [n, e];
1496
+ }
1497
+ function Se(e, n, t, o) {
1498
+ const [r, s] = re(e, n), i = t << 96n, u = s - r;
1499
+ return o ? zt(fn(i, u, s), r) : i * u / s / r;
1500
+ }
1501
+ function $e(e, n, t, o) {
1502
+ const [r, s] = re(e, n);
1503
+ return o ? fn(t, s - r, X) : t * (s - r) / X;
1504
+ }
1505
+ function Be(e, n, t) {
1506
+ const [o, r] = re(e, n), s = o * r / X;
1507
+ return t * s / (r - o);
1508
+ }
1509
+ function Pe(e, n, t) {
1510
+ const [o, r] = re(e, n);
1511
+ return t * X / (r - o);
1512
+ }
1513
+ function ir(e, n, t, o, r) {
1514
+ const [s, i] = re(n, t);
1515
+ if (e <= s) return Be(s, i, o);
1516
+ if (e < i) {
1517
+ const u = Be(e, i, o), a = Pe(s, e, r);
1518
+ return u < a ? u : a;
1519
+ }
1520
+ return Pe(s, i, r);
1521
+ }
1522
+ function ar(e, n, t, o, r) {
1523
+ const s = B(n), i = B(t);
1524
+ return e <= s ? { amount0: Se(s, i, o, r), amount1: 0n } : e < i ? {
1525
+ amount0: Se(e, i, o, r),
1526
+ amount1: $e(s, e, o, r)
1527
+ } : { amount0: 0n, amount1: $e(s, i, o, r) };
1528
+ }
1529
+ function Jt(e, n, t) {
1530
+ const o = B(n), r = B(t);
1531
+ return e <= o ? "token0-only" : e >= r ? "token1-only" : "both";
1532
+ }
1533
+ function ur(e, n, t, o, r) {
1534
+ if (Jt(e, n, t) !== "both") return null;
1535
+ const s = B(n), i = B(t);
1536
+ if (r <= 0n) return 0n;
1537
+ if (o === "token0") {
1538
+ const a = Be(e, i, r);
1539
+ return $e(s, e, a, !0);
1540
+ }
1541
+ const u = Pe(s, e, r);
1542
+ return Se(e, i, u, !0);
1543
+ }
1544
+ const q = (e) => (e % be + be) % be;
1545
+ function lr(e) {
1546
+ const { currentTick: n, tickLower: t, tickUpper: o, lower: r, upper: s } = e, i = e.feeGrowthGlobal0X128, u = e.feeGrowthGlobal1X128, a = n >= t ? r.feeGrowthOutside0X128 : q(i - r.feeGrowthOutside0X128), l = n >= t ? r.feeGrowthOutside1X128 : q(u - r.feeGrowthOutside1X128), c = n < o ? s.feeGrowthOutside0X128 : q(i - s.feeGrowthOutside0X128), d = n < o ? s.feeGrowthOutside1X128 : q(u - s.feeGrowthOutside1X128), p = q(i - a - c), f = q(u - l - d);
1547
+ return {
1548
+ fees0: q(p - e.feeGrowthInside0LastX128) * e.liquidity / Ee,
1549
+ fees1: q(f - e.feeGrowthInside1LastX128) * e.liquidity / Ee
1550
+ };
1551
+ }
1552
+ function cr() {
1553
+ if (B(0) !== X)
1554
+ throw new Error(`getSqrtRatioAtTick(0) is ${B(0)}, expected 2^96 (${X})`);
1555
+ const e = 1461446703485210103287273052203988822378723970342n;
1556
+ if (B(Le) !== e)
1557
+ throw new Error(
1558
+ `getSqrtRatioAtTick(MAX_TICK) is ${B(Le)}, expected ${e}`
1559
+ );
1560
+ const n = 4295128739n;
1561
+ if (B(Ae) !== n)
1562
+ throw new Error(
1563
+ `getSqrtRatioAtTick(MIN_TICK) is ${B(Ae)}, expected ${n}`
1564
+ );
1565
+ }
1566
+ function eo(e) {
1567
+ return e.isNative === !0 || R(e.address, W);
1568
+ }
1569
+ function no(e, n, t) {
1570
+ const o = [], r = (s, i, u) => {
1571
+ const a = eo(s) ? u : i;
1572
+ a > 0n && o.push({ token: s, required: a });
1573
+ };
1574
+ return r(e.pool.token0, e.amount0, n), r(e.pool.token1, e.amount1, t), o;
1575
+ }
1576
+ function to(e, n) {
1577
+ for (const [t, o] of e.entries()) {
1578
+ const r = n[t] ?? null;
1579
+ if (r !== null && r < o.required) return o.token;
1580
+ }
1581
+ return null;
1582
+ }
1583
+ class Xe extends Error {
1584
+ token;
1585
+ constructor(n) {
1586
+ super(`Insufficient ${n.symbol}: the wallet holds less than this deposit needs. Nothing was signed.`), this.name = "InsufficientBalanceError", this.token = n;
1587
+ }
1588
+ }
1589
+ function hn(e) {
1590
+ return e.tickSpacing !== void 0 ? e.tickSpacing : Cn(e.key).tickSpacing;
1591
+ }
1592
+ function dr(e) {
1593
+ return e.binStep !== void 0 ? e.binStep : Rn(e.key).binStep;
1594
+ }
1595
+ function pr(e, n) {
1596
+ const t = P(
1597
+ [
1598
+ { name: "poolId", type: "bytes32" },
1599
+ { name: "binId", type: "uint256" }
1600
+ ],
1601
+ [e, BigInt(n)]
1602
+ );
1603
+ return BigInt(Sn(t));
1604
+ }
1605
+ function fr(e) {
1606
+ return e.totalShares === 0n || e.shares === 0n ? { amount0: 0n, amount1: 0n } : {
1607
+ amount0: e.reserveX * e.shares / e.totalShares,
1608
+ amount1: e.reserveY * e.shares / e.totalShares
1609
+ };
1610
+ }
1611
+ function hr(e, n, t, o = 10) {
1612
+ if (e.poolType === "CL") {
1613
+ const r = hn(e);
1614
+ if (n === null) return null;
1615
+ const s = r * o;
1616
+ return {
1617
+ type: "CL",
1618
+ tickLower: pt(n - s, r),
1619
+ tickUpper: ft(n + s, r)
1620
+ };
1621
+ }
1622
+ return t === null ? null : {
1623
+ type: "BIN",
1624
+ activeIdDesired: t,
1625
+ binIdLower: t - o,
1626
+ binIdUpper: t + o,
1627
+ idSlippage: 5
1628
+ };
1629
+ }
1630
+ function mr(e, n, t) {
1631
+ if (e.type === "CL") {
1632
+ const s = hn(n), i = e.tickLower - t * s, u = e.tickUpper + t * s;
1633
+ return i >= u ? e : { type: "CL", tickLower: i, tickUpper: u };
1634
+ }
1635
+ const o = e.binIdLower - t, r = e.binIdUpper + t;
1636
+ return o > r ? e : { ...e, binIdLower: o, binIdUpper: r };
1637
+ }
1638
+ function yr(e) {
1639
+ if (e.type === "CL")
1640
+ return `Ticks ${e.tickLower} to ${e.tickUpper}`;
1641
+ const n = e.binIdUpper - e.binIdLower + 1;
1642
+ return `Bins ${e.binIdLower} to ${e.binIdUpper} (${n} bins, active ${e.activeIdDesired})`;
1643
+ }
1644
+ function wr(e) {
1645
+ const { adapter: n } = E(), { pool: t, range: o, amount0Desired: r, amount1Desired: s } = e, i = (e.enabled ?? !0) && t !== null && o !== null && (r ?? 0n) + (s ?? 0n) > 0n, u = y(async () => t === null || o === null ? null : n.quoteAddLiquidity({
1646
+ pool: t,
1647
+ range: o,
1648
+ amount0Desired: r ?? 0n,
1649
+ amount1Desired: s ?? 0n
1650
+ }), [n, t, o, r, s]);
1651
+ return { ...A(
1652
+ u,
1653
+ [
1654
+ n,
1655
+ t?.id ?? null,
1656
+ o === null ? null : JSON.stringify(o),
1657
+ r?.toString() ?? null,
1658
+ s?.toString() ?? null
1659
+ ],
1660
+ { enabled: i }
1661
+ ), isMock: n.isMock };
1662
+ }
1663
+ function Ne(e) {
1664
+ return e instanceof Error ? e : new Error(String(e));
1665
+ }
1666
+ function br(e) {
1667
+ const { adapter: n, chain: t, integrator: o, defaultSlippageBps: r } = E(), { quote: s } = e, i = e.slippageBps ?? r, [u, a] = I("idle"), [l, c] = I(null), [d, p] = I(null), [f, k] = I(0), h = A(
1668
+ y(() => n.getAccount(), [n]),
1669
+ [n]
1670
+ ).data, m = N(() => s === null ? null : {
1671
+ amount0Max: De(s.amount0, i),
1672
+ amount1Max: De(s.amount1, i)
1673
+ }, [s, i]), T = N(
1674
+ () => s === null || m === null ? [] : no(s, m.amount0Max, m.amount1Max),
1675
+ [s, m]
1676
+ ), C = T.map((w) => `${w.token.address}:${w.required.toString()}`).join(","), b = y(async () => {
1677
+ if (h === null || T.length === 0) return null;
1678
+ const w = await Promise.all(T.map((g) => n.getBalance(g.token, h)));
1679
+ return to(T, w);
1680
+ }, [n, h, T]), L = A(
1681
+ b,
1682
+ [n, h, C, f],
1683
+ { enabled: h !== null && T.length > 0, refetchIntervalMs: 3e4 }
1684
+ ), V = T.length === 0 || h === null ? null : L.data ?? null, S = L.refetch, j = y(async () => {
1685
+ if (s === null || h === null || m === null) return [];
1686
+ const w = s.pool.poolType === "CL" ? t.contracts.clPositionManager : t.contracts.binPositionManager, [g, $] = await Promise.all([
1687
+ n.getApprovalRequirements(s.pool.token0, h, m.amount0Max, w),
1688
+ n.getApprovalRequirements(s.pool.token1, h, m.amount1Max, w)
1689
+ ]);
1690
+ return [...g, ...$];
1691
+ }, [n, t, s, h, m]), M = A(
1692
+ j,
1693
+ [n, s?.pool.id ?? null, h, m?.amount0Max.toString() ?? null, f],
1694
+ { enabled: s !== null && h !== null }
1695
+ ).data ?? [], ce = y(async () => {
1696
+ const w = M[0];
1697
+ if (w !== void 0) {
1698
+ c(null), a("approving");
1699
+ try {
1700
+ const g = await b();
1701
+ if (g !== null)
1702
+ throw S(), new Xe(g);
1703
+ const $ = await n.buildApproval(w), ie = await n.sendTransaction($);
1704
+ await n.waitForTransaction(ie), k((pe) => pe + 1), a("idle");
1705
+ } catch (g) {
1706
+ c(Ne(g)), a("error");
1707
+ }
1708
+ }
1709
+ }, [n, M, b, S]), de = y(async () => {
1710
+ if (!(s === null || m === null)) {
1711
+ if (h === null) {
1712
+ c(new ue("add liquidity")), a("error");
1713
+ return;
1714
+ }
1715
+ c(null), a("building");
1716
+ try {
1717
+ const w = await b();
1718
+ if (w !== null)
1719
+ throw S(), new Xe(w);
1720
+ const g = await n.buildAddLiquidity({
1721
+ quote: s,
1722
+ amount0Max: m.amount0Max,
1723
+ amount1Max: m.amount1Max,
1724
+ recipient: e.recipient ?? h,
1725
+ deadline: await _e(t, n),
1726
+ integrator: o,
1727
+ ...e.hookData ? { hookData: e.hookData } : {}
1728
+ });
1729
+ a("awaiting-signature");
1730
+ const $ = await n.sendTransaction(g);
1731
+ if (p($), a("pending"), (await n.waitForTransaction($)).status === "reverted") throw new Error(`The transaction was mined but reverted (${$}).`);
1732
+ a("success"), k((pe) => pe + 1), e.onSuccess?.($);
1733
+ } catch (w) {
1734
+ c(Ne(w)), a("error");
1735
+ }
1736
+ }
1737
+ }, [n, h, m, t, o, e, s, b, S]), Y = y(() => {
1738
+ a("idle"), c(null), p(null);
1739
+ }, []), se = u === "idle" && M.length > 0 && V === null ? "needs-approval" : u;
1740
+ return {
1741
+ step: se,
1742
+ error: l,
1743
+ txHash: d,
1744
+ approvals: M,
1745
+ needsApproval: M.length > 0,
1746
+ insufficient: V,
1747
+ statusMessage: mn(se, M[0], l, n.isMock),
1748
+ approve: ce,
1749
+ execute: de,
1750
+ reset: Y
1751
+ };
1752
+ }
1753
+ function kr(e, n, t = 0) {
1754
+ const { adapter: o } = E(), r = y(async () => e === null ? [] : n == null ? o.listPositions(e) : o.listPositions(e, n), [o, e, n]);
1755
+ return A(r, [o, e, n?.id ?? null, t], {
1756
+ enabled: e !== null
1757
+ });
1758
+ }
1759
+ function gr(e) {
1760
+ const { adapter: n, chain: t, integrator: o, defaultSlippageBps: r } = E(), { position: s, percentBps: i } = e, u = e.slippageBps ?? r, [a, l] = I("idle"), [c, d] = I(null), [p, f] = I(null), k = y(async () => s === null ? null : n.quoteRemoveLiquidity(s, i), [n, s, i]), v = A(
1761
+ k,
1762
+ /* Keyed on the position RECORD, not its id: after a partial removal the
1763
+ re-read list hands over a new record with less liquidity, and the quote
1764
+ must follow it rather than keep pricing the old one. */
1765
+ [n, s, i],
1766
+ { enabled: s !== null && i > 0 }
1767
+ ), h = y(async () => {
1768
+ const T = v.data;
1769
+ if (s === null || T === null) return;
1770
+ const C = await n.getAccount();
1771
+ if (C === null) {
1772
+ d(new ue("remove liquidity")), l("error");
1773
+ return;
1774
+ }
1775
+ d(null), l("building");
1776
+ try {
1777
+ const b = await n.buildRemoveLiquidity({
1778
+ position: s,
1779
+ percentBps: i,
1780
+ amount0Min: ve(T.amount0, u),
1781
+ amount1Min: ve(T.amount1, u),
1782
+ recipient: e.recipient ?? C,
1783
+ deadline: await _e(t, n),
1784
+ integrator: o
1785
+ });
1786
+ l("awaiting-signature");
1787
+ const L = await n.sendTransaction(b);
1788
+ if (f(L), l("pending"), (await n.waitForTransaction(L)).status === "reverted") throw new Error(`The transaction was mined but reverted (${L}).`);
1789
+ l("success"), e.onSuccess?.(L);
1790
+ } catch (b) {
1791
+ d(Ne(b)), l("error");
1792
+ }
1793
+ }, [n, t, o, e, i, s, v.data, u]), m = y(() => {
1794
+ l("idle"), d(null), f(null);
1795
+ }, []);
1796
+ return {
1797
+ quote: v.data,
1798
+ quoteStatus: v.status,
1799
+ step: a,
1800
+ error: c,
1801
+ txHash: p,
1802
+ statusMessage: mn(a, void 0, c, n.isMock),
1803
+ execute: h,
1804
+ reset: m
1805
+ };
1806
+ }
1807
+ function mn(e, n, t, o) {
1808
+ const r = o ? "Simulated (mock adapter): " : "";
1809
+ switch (e) {
1810
+ case "idle":
1811
+ return "";
1812
+ case "needs-approval":
1813
+ return n === void 0 ? "Approval required" : `Approve ${n.token.symbol} before continuing`;
1814
+ case "approving":
1815
+ return `${r}Waiting for the approval to confirm`;
1816
+ case "building":
1817
+ return `${r}Preparing the transaction`;
1818
+ case "awaiting-signature":
1819
+ return `${r}Confirm the transaction in your wallet`;
1820
+ case "pending":
1821
+ return `${r}Submitted, waiting for confirmation`;
1822
+ case "success":
1823
+ return `${r}Confirmed`;
1824
+ case "error":
1825
+ return t === null ? "Something went wrong" : pn(t, "liquidity");
1826
+ default:
1827
+ return "";
1828
+ }
1829
+ }
1830
+ function Ir(e, n) {
1831
+ return (t) => {
1832
+ e(), n?.(t);
1833
+ };
1834
+ }
1835
+ function vr(e) {
1836
+ return e.filter((n) => n.liquidity > 0n || n.feesOwed0 > 0n || n.feesOwed1 > 0n);
1837
+ }
1838
+ function Tr(e, n) {
1839
+ if (e !== null) {
1840
+ const t = n.find((o) => o.id === e.id);
1841
+ if (t !== void 0) return t;
1842
+ }
1843
+ return n[0] ?? null;
1844
+ }
1845
+ function yn(e) {
1846
+ return typeof e.url == "string";
1847
+ }
1848
+ const oo = "0x0000000000000000000000000000000000000000";
1849
+ function wn(e) {
1850
+ const n = [];
1851
+ for (const t of e.tokens) {
1852
+ if (!xe(t.address)) continue;
1853
+ const o = Fn(t), r = {
1854
+ address: t.address,
1855
+ symbol: t.symbol,
1856
+ name: t.name,
1857
+ decimals: t.decimals,
1858
+ ...t.logoURI === void 0 ? {} : { logoUrl: t.logoURI },
1859
+ ...t.address.toLowerCase() === oo ? { isNative: !0 } : {},
1860
+ listSource: { name: t.source.name, alsoIn: t.alsoIn.map((s) => s.name) },
1861
+ ...o === null ? {} : { stock: o },
1862
+ ...t.tags === void 0 ? {} : { tags: t.tags }
1863
+ };
1864
+ n.push(r);
1865
+ }
1866
+ return n;
1867
+ }
1868
+ function Er(e, n) {
1869
+ const t = /* @__PURE__ */ new Map();
1870
+ for (const o of e) t.set(o.address.toLowerCase(), o);
1871
+ for (const o of n) {
1872
+ const r = o.address.toLowerCase(), s = t.get(r);
1873
+ if (s === void 0) {
1874
+ t.set(r, o);
1875
+ continue;
1876
+ }
1877
+ t.set(r, {
1878
+ ...s,
1879
+ ...s.logoUrl === void 0 && o.logoUrl !== void 0 ? { logoUrl: o.logoUrl } : {},
1880
+ /* The adapter's token stays the adapter's; the lists that also name it are recorded as corroboration. */
1881
+ ...o.listSource !== void 0 ? { listSource: { name: s.listSource?.name ?? null, alsoIn: [...s.listSource?.alsoIn ?? [], o.listSource.name ?? "", ...o.listSource.alsoIn].filter((i) => i !== "") } } : {},
1882
+ ...s.stock === void 0 && o.stock !== void 0 ? { stock: o.stock } : {},
1883
+ ...s.tags === void 0 && o.tags !== void 0 ? { tags: o.tags } : {}
1884
+ });
1885
+ }
1886
+ return [...t.values()];
1887
+ }
1888
+ function Ar(e, n) {
1889
+ return wn(nn(e, { chainId: n }));
1890
+ }
1891
+ function Lr(e, n) {
1892
+ if (e === void 0) return null;
1893
+ if (e.startsWith("https://")) return e;
1894
+ if (e.startsWith("ipfs://")) {
1895
+ const t = Mn(e, n === void 0 ? {} : { gateways: n });
1896
+ return t === null || t.length === 0 ? null : t[0] ?? null;
1897
+ }
1898
+ return null;
1899
+ }
1900
+ function Sr(e) {
1901
+ const n = /* @__PURE__ */ new Map();
1902
+ n.set(null, []);
1903
+ for (const t of e) {
1904
+ const o = t.listSource?.name ?? null, r = n.get(o);
1905
+ r === void 0 ? n.set(o, [t]) : r.push(t);
1906
+ }
1907
+ return [...n.entries()].filter(([, t]) => t.length > 0).map(([t, o]) => ({ source: t, tokens: o }));
1908
+ }
1909
+ const Z = { tokens: [], status: "idle", failures: [], sources: [] };
1910
+ function ro(e) {
1911
+ return e === void 0 ? "" : e.map((n) => yn(n) ? `url:${n.url}` : `list:${n.name}@${n.version.major}.${n.version.minor}.${n.version.patch}:${n.tokens.length}`).join("|");
1912
+ }
1913
+ function $r(e) {
1914
+ const { chain: n } = E(), t = ro(e), [o, r] = I({ key: "", resource: Z });
1915
+ return z(() => {
1916
+ if (e === void 0 || e.length === 0) {
1917
+ r({ key: t, resource: Z });
1918
+ return;
1919
+ }
1920
+ let s = !1;
1921
+ return r((i) => i.key === t ? i : { key: t, resource: { ...Z, status: "loading" } }), Promise.all(
1922
+ e.map(async (i) => {
1923
+ if (!yn(i)) return i;
1924
+ try {
1925
+ return (await qn(i.url)).list;
1926
+ } catch (u) {
1927
+ return { url: i.url, message: u instanceof Error ? u.message : String(u) };
1928
+ }
1929
+ })
1930
+ ).then((i) => {
1931
+ if (s) return;
1932
+ const u = i.filter((c) => !("url" in c && "message" in c)), a = i.filter((c) => "url" in c && "message" in c), l = nn(u, { chainId: n.chainId });
1933
+ r({ key: t, resource: { tokens: wn(l), status: "ready", failures: a, sources: u.map((c) => c.name) } });
1934
+ }), () => {
1935
+ s = !0;
1936
+ };
1937
+ }, [t, n.chainId]), N(() => o.key === t ? o.resource : e === void 0 || e.length === 0 ? Z : { ...Z, status: "loading" }, [o, t, e]);
1938
+ }
1939
+ function bn(e) {
1940
+ return "token" in e ? { token: e.token, quote: e.quote } : { token: e.tokenOut, quote: e.tokenIn };
1941
+ }
1942
+ function Ve(e) {
1943
+ return (typeof e == "string" ? e : e.address).toLowerCase();
1944
+ }
1945
+ function Br(e) {
1946
+ if (e === void 0) return null;
1947
+ const n = bn(e);
1948
+ return `${Ve(n.token)}:${Ve(n.quote)}`;
1949
+ }
1950
+ function Oe(e, n) {
1951
+ if (n === void 0) return null;
1952
+ const t = n.toLowerCase();
1953
+ return e.find((o) => o.address.toLowerCase() === t) ?? null;
1954
+ }
1955
+ function Pr(e, n) {
1956
+ return typeof e != "string" ? e : Oe(n, e);
1957
+ }
1958
+ function ke(e, n) {
1959
+ return n === "buy" ? { tokenIn: e.quote, tokenOut: e.token } : { tokenIn: e.token, tokenOut: e.quote };
1960
+ }
1961
+ function ge(e, n) {
1962
+ return n === "buy" ? { token: e.tokenOut, quote: e.tokenIn } : { token: e.tokenIn, quote: e.tokenOut };
1963
+ }
1964
+ function Nr(e) {
1965
+ return e === "buy" ? "sell" : "buy";
1966
+ }
1967
+ const so = [0.25, 0.5, 0.75, 1], je = 10n ** 15n;
1968
+ function Or(e) {
1969
+ if (e === void 0) return so;
1970
+ for (const n of e)
1971
+ if (typeof n != "number" || !Number.isFinite(n) || n <= 0 || n > 1)
1972
+ throw new RangeError(`[@latchprotocol/widgets] portions must be fractions in (0, 1]: ${String(n)}`);
1973
+ return e;
1974
+ }
1975
+ function xr(e) {
1976
+ if (e === 1) return "Max";
1977
+ const n = e * 100;
1978
+ return `${Number.isInteger(n) ? n : Number(n.toFixed(2))}%`;
1979
+ }
1980
+ function io(e, n, t) {
1981
+ const o = BigInt(Math.round(n * 1e4)), r = e * o / 10000n;
1982
+ return t.isNative === !0 && n === 1 ? r > je ? r - je : 0n : r;
1983
+ }
1984
+ function _r(e, n, t) {
1985
+ return e === null || n === null ? null : ze(io(n, t, e), e.decimals);
1986
+ }
1987
+ const Ye = {
1988
+ anchor: { token: null, quote: null },
1989
+ side: "buy",
1990
+ amountText: "",
1991
+ impactAck: !1
1992
+ };
1993
+ function Rr(e) {
1994
+ const n = e.side ?? "buy";
1995
+ if (e.pair === void 0) return { ...Ye, side: n };
1996
+ const t = bn(e.pair);
1997
+ return {
1998
+ ...Ye,
1999
+ side: n,
2000
+ anchor: {
2001
+ token: typeof t.token == "string" ? null : t.token,
2002
+ quote: typeof t.quote == "string" ? null : t.quote
2003
+ }
2004
+ };
2005
+ }
2006
+ function Cr(e, n) {
2007
+ switch (n.type) {
2008
+ case "seed": {
2009
+ if (n.tokens.length === 0) return e;
2010
+ const t = ke(e.anchor, n.side), o = t.tokenIn ?? Oe(n.tokens, n.defaultTokenIn) ?? n.tokens[0] ?? null, r = t.tokenOut ?? Oe(n.tokens, n.defaultTokenOut) ?? n.tokens[1] ?? null;
2011
+ return o === t.tokenIn && r === t.tokenOut ? e : { ...e, anchor: ge({ tokenIn: o, tokenOut: r }, n.side) };
2012
+ }
2013
+ case "pin":
2014
+ return n.anchor.token === e.anchor.token && n.anchor.quote === e.anchor.quote ? e : { ...e, anchor: n.anchor, impactAck: !1 };
2015
+ case "select-in": {
2016
+ const t = ke(e.anchor, n.side);
2017
+ return { ...e, anchor: ge({ tokenIn: n.token, tokenOut: t.tokenOut }, n.side), impactAck: !1 };
2018
+ }
2019
+ case "select-out": {
2020
+ const t = ke(e.anchor, n.side);
2021
+ return { ...e, anchor: ge({ tokenIn: t.tokenIn, tokenOut: n.token }, n.side), impactAck: !1 };
2022
+ }
2023
+ case "set-side":
2024
+ return n.side === e.side ? e : { ...e, side: n.side, impactAck: !1, ...n.amountText === void 0 ? {} : { amountText: n.amountText } };
2025
+ case "amount":
2026
+ return n.text === e.amountText ? e : { ...e, amountText: n.text, impactAck: !1 };
2027
+ case "ack":
2028
+ return e.impactAck === n.value ? e : { ...e, impactAck: n.value };
2029
+ default:
2030
+ return e;
2031
+ }
2032
+ }
2033
+ function ao(e) {
2034
+ if (e.length === 0) return [];
2035
+ const n = [e[0]?.tokenIn.symbol ?? ""];
2036
+ for (const t of e) n.push(t.tokenOut.symbol);
2037
+ return n.filter((t) => t !== "");
2038
+ }
2039
+ function Mr(e) {
2040
+ const { tokenIn: n, tokenOut: t, quote: o, breakdown: r } = e;
2041
+ return n === null || t === null || o === null || r === null ? null : {
2042
+ tokenIn: n,
2043
+ tokenOut: t,
2044
+ amountIn: r.amountIn,
2045
+ amountOut: r.netAmountOut,
2046
+ grossAmountOut: r.grossAmountOut,
2047
+ minReceived: r.minAmountOutNet,
2048
+ integratorFee: r.integratorFee,
2049
+ slippageBps: r.slippageBps,
2050
+ priceImpactBps: r.priceImpactBps,
2051
+ priceImpactSeverity: r.priceImpactSeverity,
2052
+ lpFee: {
2053
+ pips: r.lpFeePips,
2054
+ unknown: r.lpFeeUnknown,
2055
+ label: r.lpFeeUnknown ? "dynamic (hook-set)" : mt(r.lpFeePips)
2056
+ },
2057
+ route: o.route,
2058
+ routeSymbols: ao(o.route),
2059
+ rate: e.rate,
2060
+ status: e.status,
2061
+ isRefreshing: e.isRefreshing,
2062
+ isMock: e.isMock,
2063
+ updatedAt: e.updatedAt
2064
+ };
2065
+ }
2066
+ const kn = { symbol: "ETH", decimals: 18 };
2067
+ async function Q(e, n, t) {
2068
+ if (n.toLowerCase() === W) return { address: W, symbol: t.symbol, decimals: t.decimals };
2069
+ const [o, r] = await Promise.all([
2070
+ e.readContract({ address: n, abi: qe, functionName: "symbol" }).catch(() => null),
2071
+ e.readContract({ address: n, abi: qe, functionName: "decimals" }).catch(() => null)
2072
+ ]);
2073
+ return { address: n, symbol: o ?? wt(n), decimals: r === null ? null : Number(r) };
2074
+ }
2075
+ async function gn(e, n, t) {
2076
+ if (!n.lpLocker) return [];
2077
+ if (n.lpLockerTokenIds) return n.lpLockerTokenIds;
2078
+ if (n.lpLockerFromBlock === void 0) return [];
2079
+ const o = await e.getBlockNumber();
2080
+ return (await tn(e, n.lpLocker, { fromBlock: n.lpLockerFromBlock, toBlock: o }, t)).map((r) => r.tokenId);
2081
+ }
2082
+ async function Fr(e, n, t, o = {}) {
2083
+ const r = o.native ?? kn, s = o.lp ?? {};
2084
+ if (s.poolType === "bin") {
2085
+ const [p, f] = await Promise.all([Gn(e, s.binLpLocker, t), Ie(e)]), k = Date.now(), v = p.locks[0], [h, m] = await Promise.all([Q(e, v?.currency0 ?? W, r), Q(e, v?.currency1 ?? W, r)]);
2086
+ return { summary: Ue({ poolId: t, currency0: h.address, currency1: m.address, pool: null, locks: [] }), bin: p, currency0: h, currency1: m, chainNow: f, readAtMs: k };
2087
+ }
2088
+ const i = await gn(e, s, t);
2089
+ let u, a;
2090
+ if (n !== null) {
2091
+ const p = await Wn(e, n, t, { lpLocker: s.lpLocker ?? null, lpLockerTokenIds: i });
2092
+ u = p, a = p.now;
2093
+ } else {
2094
+ const [p, f] = await Promise.all([Kn(e, s.lpLocker, t, { tokenIds: i }), Ie(e)]), k = p.permanent[0];
2095
+ u = Ue({ poolId: t, currency0: k?.currency0 ?? W, currency1: k?.currency1 ?? W, pool: p.pool, locks: [], permanent: p.permanent }), a = f;
2096
+ }
2097
+ const l = Date.now(), [c, d] = await Promise.all([Q(e, u.currency0, r), Q(e, u.currency1, r)]);
2098
+ return { summary: u, bin: null, currency0: c, currency1: d, chainNow: a, readAtMs: l };
2099
+ }
2100
+ function qr(e, n = {}) {
2101
+ return n.poolType === "bin" ? !!n.binLpLocker : e !== null || !!n.lpLocker;
2102
+ }
2103
+ async function Ur(e, n, t, o = {}) {
2104
+ const r = o.native ?? kn, s = o.lp ?? {}, i = !!s.lpLocker || !!s.binLpLocker, [u, a, l, c] = await Promise.all([
2105
+ n === null ? Promise.resolve(null) : Hn(e, n, t),
2106
+ Q(e, t, r),
2107
+ Ie(e),
2108
+ i ? (async () => {
2109
+ const d = await gn(e, s), [p, f] = await Promise.all([
2110
+ s.lpLocker ? Xn(e, s.lpLocker, d) : Promise.resolve([]),
2111
+ s.binLpLocker ? Vn(e, s.binLpLocker).then((k) => k.locks) : Promise.resolve([])
2112
+ ]);
2113
+ return jn(t, p, f);
2114
+ })() : Promise.resolve(null)
2115
+ ]);
2116
+ return { summary: u, permanent: c, token: a, chainNow: u?.now ?? l, readAtMs: Date.now() };
2117
+ }
2118
+ function Dr(e, n, t = {}) {
2119
+ const o = e.replace(/\/+$/, ""), r = `/${(t.pathBase ?? "/app/locks").replace(/^\/+|\/+$/g, "")}`, s = t.query ? `?${t.query.replace(/^\?/, "")}` : "";
2120
+ return n.kind === "pool" ? `${o}${r}/pool/${n.poolId ?? ""}${s}` : `${o}${r}/token/${n.token ?? ""}${s}`;
2121
+ }
2122
+ function x(e) {
2123
+ const n = Math.floor(e / 100), t = e % 100;
2124
+ return t === 0 ? `${n}%` : `${n}.${String(t).padStart(2, "0")}%`;
2125
+ }
2126
+ function Gr(e) {
2127
+ if (e <= 0n) return "now";
2128
+ const n = Number(e), t = Math.floor(n / 86400), o = Math.floor(n % 86400 / 3600), r = Math.floor(n % 3600 / 60), s = n % 60, i = (u) => String(u).padStart(2, "0");
2129
+ return t >= 365 ? `${Math.floor(t / 365)}y ${t % 365}d` : t > 0 ? `${t}d ${i(o)}h ${i(r)}m` : o > 0 ? `${o}h ${i(r)}m ${i(s)}s` : `${r}m ${i(s)}s`;
2130
+ }
2131
+ function te(e) {
2132
+ return `${new Date(Number(e) * 1e3).toISOString().replace("T", " ").slice(0, 16)} UTC`;
2133
+ }
2134
+ function D(e, n, t = 6) {
2135
+ if (n.decimals === null) return `${e.toLocaleString("en-US")} base units ${n.symbol}`;
2136
+ if (e === 0n) return `0 ${n.symbol}`;
2137
+ const o = 10n ** BigInt(n.decimals), r = e / o, s = (e % o).toString().padStart(n.decimals, "0").slice(0, t).replace(/0+$/, "");
2138
+ return r === 0n && s === "" ? `<0.${"0".repeat(Math.max(0, t - 1))}1 ${n.symbol}` : `${r.toLocaleString("en-US")}${s === "" ? "" : `.${s}`} ${n.symbol}`;
2139
+ }
2140
+ const H = (e, n, t) => `${e.toLocaleString("en-US")} ${e === 1 ? n : t}`;
2141
+ function uo(e) {
2142
+ const n = e.permanent ?? [], t = n.length > 0;
2143
+ if (e.locks.length === 0 && !t)
2144
+ return { tone: "none", headline: "No locked liquidity", detail: "No position in this pool is time-locked (LatchPositionLock) or held permanently by the protocol's LP locker.", countdownTo: null, countdownLabel: null };
2145
+ if (e.lockedCount === 0 && !t) {
2146
+ const s = e.liveCount;
2147
+ return {
2148
+ tone: "open",
2149
+ headline: "No time-locked positions now",
2150
+ detail: s > 0 ? `${H(s, "lock is", "locks are")} past the unlock date and can be withdrawn by the lock owner.` : "Every lock on this pool has been withdrawn.",
2151
+ countdownTo: null,
2152
+ countdownLabel: null
2153
+ };
2154
+ }
2155
+ const o = e.lockedActiveBps === null ? t && e.lockedCount === 0 ? "Locked permanently (LP locker) · share of active liquidity not measurable" : `${H(e.lockedCount + n.length, "locked position", "locked positions")} · share of active liquidity not measurable` : `${x(e.lockedActiveBps)} of active liquidity locked`, r = [];
2156
+ if (e.lockedActiveBps === null)
2157
+ r.push(e.pool === null ? "The pool's state could not be read." : "The pool has no liquidity at the current price, so no share can be measured.");
2158
+ else {
2159
+ const s = [];
2160
+ t && s.push(`${x(e.permanentActiveBps ?? 0)} locked permanently (LP locker, no withdraw path)`), e.lockedCount > 0 && s.push(`${x(e.timeLockedActiveBps ?? 0)} time-locked until a date`), r.push(`${s.join(", ")}. The share is of liquidity at the current price and moves with it.`);
2161
+ const i = e.outOfRangeLocked + (e.permanentOutOfRange ?? 0);
2162
+ i > 0 && r.push(`${H(i, "locked position is", "locked positions are")} out of range and not counted.`);
2163
+ }
2164
+ return e.lastUnlockAt !== null && e.nextUnlockAt !== null && e.lastUnlockAt !== e.nextUnlockAt && r.push(`Last time-lock unlock ${te(e.lastUnlockAt)}.`), {
2165
+ tone: "locked",
2166
+ headline: o,
2167
+ detail: r.join(" "),
2168
+ countdownTo: e.nextUnlockAt,
2169
+ countdownLabel: e.nextUnlockAt === null ? null : `first time-lock unlock ${te(e.nextUnlockAt)}`
2170
+ };
2171
+ }
2172
+ function lo(e, n, t) {
2173
+ if (e.locks.length === 0)
2174
+ return { tone: "none", headline: "No locked liquidity", detail: "The protocol's Bin LP locker holds nothing in this pool. Time locks cover CL positions only.", countdownTo: null, countdownLabel: null };
2175
+ const o = `${D(e.amount0, n)} + ${D(e.amount1, t)}`, r = e.locks.reduce((s, i) => s + i.bins.length, 0);
2176
+ return {
2177
+ tone: "locked",
2178
+ headline: e.activeBinLockedBps === null ? "Locked permanently (LP locker)" : `${x(e.activeBinLockedBps)} of the active bin locked permanently (LP locker)`,
2179
+ detail: `${o} held forever by the Bin LP locker across ${H(r, "bin", "bins")}.${e.activeBinLockedBps === null ? " No lock holds the bin that trades at the current price." : " The share is of the bin that trades at the current price; a pool-wide share across all bins is not computed."}`,
2180
+ countdownTo: null,
2181
+ countdownLabel: null
2182
+ };
2183
+ }
2184
+ function Wr(e, n, t = null) {
2185
+ const o = t !== null && t.pools.length > 0 ? `${D(t.total, n)}${e.totalSupply ? ` (${x(Number(t.total * 10000n / e.totalSupply))} of supply)` : ""} locked permanently as pool liquidity (LP locker) in ${H(t.pools.length, "pool", "pools")}, at the current price.` : null;
2186
+ if (e.locks.length === 0 && o !== null)
2187
+ return { tone: "locked", headline: `${n.symbol} liquidity locked permanently (LP locker)`, detail: `${o} No time lock or vesting of ${n.symbol} with the Latch token lock.`, countdownTo: null, countdownLabel: null };
2188
+ if (e.locks.length === 0)
2189
+ return { tone: "none", headline: `No ${n.symbol} locked`, detail: "No lock of this token has been made with the Latch token lock.", countdownTo: null, countdownLabel: null };
2190
+ if (e.totalHeld === 0n)
2191
+ return {
2192
+ tone: o !== null ? "locked" : "open",
2193
+ headline: o !== null ? `${n.symbol} liquidity locked permanently (LP locker)` : `No ${n.symbol} locked now`,
2194
+ detail: `${H(e.locks.length, "time lock has", "time locks have")} been fully released and claimed.${o !== null ? ` ${o}` : ""}`,
2195
+ countdownTo: null,
2196
+ countdownLabel: null
2197
+ };
2198
+ const r = e.heldBps === null ? `${D(e.totalHeld, n)} held in locks` : `${x(e.heldBps)} of supply held in locks`, s = [];
2199
+ return s.push(
2200
+ e.unvestedBps === null ? `${D(e.unvested, n)} not yet vested.` : `${x(e.unvestedBps)} of supply (${D(e.unvested, n)}) not yet vested; the rest is vested and waiting to be claimed.`
2201
+ ), e.lastEnd !== null && s.push(`Fully vested ${te(e.lastEnd)}.`), o !== null && s.push(o), {
2202
+ tone: e.unvested > 0n ? "locked" : "open",
2203
+ headline: r,
2204
+ detail: s.join(" "),
2205
+ countdownTo: e.nextCliffOrEnd,
2206
+ countdownLabel: e.nextCliffOrEnd === null ? null : `next release ${te(e.nextCliffOrEnd)}`
2207
+ };
2208
+ }
2209
+ const Kr = {
2210
+ locked: "Locked",
2211
+ unlockable: "Unlockable",
2212
+ withdrawn: "Withdrawn"
2213
+ }, Hr = {
2214
+ cliff: "Before cliff",
2215
+ vesting: "Vesting",
2216
+ vested: "Fully vested",
2217
+ claimed: "Claimed"
2218
+ };
2219
+ function Xr(e) {
2220
+ return e.amount === 0n ? 0 : Number(e.vested * 10000n / e.amount);
2221
+ }
2222
+ function Vr(e, n, t) {
2223
+ return e + BigInt(Math.max(0, Math.floor((t - n) / 1e3)));
2224
+ }
2225
+ const ne = (e, n) => {
2226
+ const t = e * 10000n / n;
2227
+ return Number(t > 10000n ? 10000n : t);
2228
+ };
2229
+ function le(e, n) {
2230
+ return { parts: e.filter((t) => t.bps > 0 || t.nonZero), of: n, restBps: Math.max(0, 1e4 - e.reduce((t, o) => t + o.bps, 0)) };
2231
+ }
2232
+ function jr(e) {
2233
+ const n = e.pool?.activeLiquidity ?? 0n;
2234
+ if (e.pool === null || n === 0n) return null;
2235
+ const t = e.permanentActiveLiquidity ?? 0n, o = e.timeLockedActiveLiquidity ?? e.lockedActiveLiquidity - t;
2236
+ return le(
2237
+ [
2238
+ { key: "permanent", label: "Locked permanently (LP locker)", bps: ne(t, n), nonZero: t > 0n },
2239
+ { key: "time", label: "Time-locked until a date", bps: ne(o, n), nonZero: o > 0n }
2240
+ ],
2241
+ "of active liquidity"
2242
+ );
2243
+ }
2244
+ function Yr(e) {
2245
+ return e.activeBinLockedBps === null ? null : le([{ key: "permanent", label: "Locked permanently (LP locker)", bps: e.activeBinLockedBps, nonZero: e.activeBinLockedBps > 0 }], "of the active bin");
2246
+ }
2247
+ function Zr(e, n = null) {
2248
+ const t = e.totalSupply ?? null;
2249
+ if (t === null || t === 0n) return null;
2250
+ const o = e.totalHeld > e.unvested ? e.totalHeld - e.unvested : 0n, r = n ?? 0n;
2251
+ return le(
2252
+ [
2253
+ { key: "unvested", label: "Not yet vested", bps: ne(e.unvested, t), nonZero: e.unvested > 0n },
2254
+ { key: "vested", label: "Vested, not yet claimed", bps: ne(o, t), nonZero: o > 0n },
2255
+ { key: "lp", label: "In permanent LP (LP locker)", bps: ne(r, t), nonZero: r > 0n }
2256
+ ],
2257
+ "of supply"
2258
+ );
2259
+ }
2260
+ function Qr(e, n, t = 24) {
2261
+ if (e.length === 0) return null;
2262
+ const o = e.reduce((a, l) => l.start < a ? l.start : a, e[0].start), r = e.reduce((a, l) => l.end > a ? l.end : a, e[0].end);
2263
+ if (r <= o) return null;
2264
+ const s = /* @__PURE__ */ new Set([o, r]);
2265
+ n !== null && n > o && n < r && s.add(n);
2266
+ for (const a of e)
2267
+ s.add(a.start), s.add(a.end), a.cliff > a.start && (s.add(a.cliff - 1n), s.add(a.cliff));
2268
+ const i = (r - o) / BigInt(t);
2269
+ if (i > 0n) for (let a = 1n; a < BigInt(t); a++) s.add(o + i * a);
2270
+ return { points: [...s].sort((a, l) => a < l ? -1 : a > l ? 1 : 0).map((a) => ({ t: a, vested: e.reduce((l, c) => l + Yn(c, a), 0n) })), total: e.reduce((a, l) => a + l.amount, 0n) };
2271
+ }
2272
+ function zr(e, n) {
2273
+ return e.every((t) => t.bps === null) ? null : le(
2274
+ e.map((t) => ({ key: t.key, label: t.label, bps: t.bps ?? 0, nonZero: !1 })),
2275
+ n
2276
+ );
2277
+ }
2278
+ function Jr(e) {
2279
+ return e.bin !== null ? lo(e.bin, e.currency0, e.currency1) : uo(e.summary);
2280
+ }
2281
+ function es(e) {
2282
+ const n = e.summary, t = e.token, o = e.permanent !== null && e.permanent.pools.length > 0 ? e.permanent : null, r = n?.totalSupply ?? null, s = o === null ? null : `${D(o.total, t)}${r !== null && r > 0n ? ` (${x(Number(o.total * 10000n / r))} of supply)` : ""} locked permanently as liquidity (LP locker)`;
2283
+ if (n !== null && n.unvested > 0n) {
2284
+ const i = n.unvestedBps === null ? `${D(n.unvested, t)} locked` : n.unvestedBps === 0 ? "<0.01% of supply locked" : `${x(n.unvestedBps)} of supply locked`, u = [`Not yet vested in ${n.locks.length === 1 ? "1 Latch token lock" : `${n.locks.length.toLocaleString("en-US")} Latch token locks`}.`];
2285
+ return s !== null && u.push(`${s}.`), { tone: "locked", headline: i, detail: u.join(" "), countdownTo: n.nextCliffOrEnd, countdownLabel: n.nextCliffOrEnd === null ? null : `next release ${te(n.nextCliffOrEnd)}` };
2286
+ }
2287
+ return s !== null ? { tone: "locked", headline: "Liquidity locked permanently (LP locker)", detail: `${s}.`, countdownTo: null, countdownLabel: null } : n !== null && n.locks.length > 0 ? { tone: "open", headline: `No ${t.symbol} locked now`, detail: "Every Latch token lock of it has fully vested.", countdownTo: null, countdownLabel: null } : { tone: "none", headline: `No ${t.symbol} locked`, detail: "No Latch token lock or LP-locker liquidity holds it.", countdownTo: null, countdownLabel: null };
2288
+ }
2289
+ function co(e, n, t) {
2290
+ if (t <= 0n) throw new RangeError("window size must be positive");
2291
+ const o = [];
2292
+ for (let r = e; r <= n; r += t) o.push({ from: r, to: r + t - 1n > n ? n : r + t - 1n });
2293
+ return o;
2294
+ }
2295
+ async function ns(e, n, t, o) {
2296
+ const r = t.toBlock ?? await e.getBlockNumber(), s = t.minWindow ?? 2000n, i = /* @__PURE__ */ new Set(), u = [], a = async (l, c) => {
2297
+ try {
2298
+ const d = await tn(e, n, { fromBlock: l, toBlock: c }, o);
2299
+ for (const p of d) {
2300
+ const f = p.tokenId.toString();
2301
+ i.has(f) || (i.add(f), u.push(p.tokenId));
2302
+ }
2303
+ } catch (d) {
2304
+ const p = c - l + 1n;
2305
+ if (p <= s) throw d;
2306
+ const f = l + p / 2n;
2307
+ await a(l, f - 1n), await a(f, c);
2308
+ }
2309
+ };
2310
+ for (const l of co(t.fromBlock, r, t.window ?? 500000n)) await a(l.from, l.to);
2311
+ return u;
2312
+ }
2313
+ export {
2314
+ pr as $,
2315
+ O as A,
2316
+ Mo as B,
2317
+ we as C,
2318
+ so as D,
2319
+ qo as E,
2320
+ Vr as F,
2321
+ ar as G,
2322
+ it as H,
2323
+ Ye as I,
2324
+ cr as J,
2325
+ zn as K,
2326
+ Ho as L,
2327
+ J as M,
2328
+ Co as N,
2329
+ Ge as O,
2330
+ Uo as P,
2331
+ X as Q,
2332
+ io as R,
2333
+ at as S,
2334
+ Hr as T,
2335
+ kt as U,
2336
+ lo as V,
2337
+ ue as W,
2338
+ fr as X,
2339
+ Yr as Y,
2340
+ ae as Z,
2341
+ dr as _,
2342
+ bt as a,
2343
+ Nr as a$,
2344
+ co as a0,
2345
+ Vo as a1,
2346
+ Jo as a2,
2347
+ ct as a3,
2348
+ xt as a4,
2349
+ Nt as a5,
2350
+ Mr as a6,
2351
+ Ir as a7,
2352
+ Re as a8,
2353
+ ft as a9,
2354
+ mt as aA,
2355
+ No as aB,
2356
+ _o as aC,
2357
+ te as aD,
2358
+ Se as aE,
2359
+ $e as aF,
2360
+ Be as aG,
2361
+ Pe as aH,
2362
+ ir as aI,
2363
+ B as aJ,
2364
+ Sr as aK,
2365
+ Rt as aL,
2366
+ Rr as aM,
2367
+ ln as aN,
2368
+ Yt as aO,
2369
+ jt as aP,
2370
+ eo as aQ,
2371
+ yn as aR,
2372
+ _t as aS,
2373
+ Ko as aT,
2374
+ cn as aU,
2375
+ Dr as aV,
2376
+ De as aW,
2377
+ ve as aX,
2378
+ bo as aY,
2379
+ bn as aZ,
2380
+ Or as a_,
2381
+ _e as aa,
2382
+ Jt as ab,
2383
+ Eo as ac,
2384
+ Er as ad,
2385
+ Xo as ae,
2386
+ Te as af,
2387
+ he as ag,
2388
+ hr as ah,
2389
+ no as ai,
2390
+ pn as aj,
2391
+ yr as ak,
2392
+ dn as al,
2393
+ dt as am,
2394
+ ko as an,
2395
+ Fr as ao,
2396
+ Ur as ap,
2397
+ to as aq,
2398
+ Oe as ar,
2399
+ pt as as,
2400
+ Po as at,
2401
+ go as au,
2402
+ Gr as av,
2403
+ xo as aw,
2404
+ D as ax,
2405
+ x as ay,
2406
+ Oo as az,
2407
+ gt as b,
2408
+ kn as b$,
2409
+ ke as b0,
2410
+ Ve as b1,
2411
+ Br as b2,
2412
+ ur as b3,
2413
+ Bo as b4,
2414
+ vo as b5,
2415
+ It as b6,
2416
+ uo as b7,
2417
+ Jr as b8,
2418
+ qr as b9,
2419
+ lr as bA,
2420
+ ge as bB,
2421
+ tr as bC,
2422
+ br as bD,
2423
+ wr as bE,
2424
+ A as bF,
2425
+ $o as bG,
2426
+ zo as bH,
2427
+ er as bI,
2428
+ Zo as bJ,
2429
+ Qo as bK,
2430
+ Lo as bL,
2431
+ sr as bM,
2432
+ rr as bN,
2433
+ kr as bO,
2434
+ So as bP,
2435
+ gr as bQ,
2436
+ jo as bR,
2437
+ Ht as bS,
2438
+ Vt as bT,
2439
+ or as bU,
2440
+ nr as bV,
2441
+ $r as bW,
2442
+ E as bX,
2443
+ et as bY,
2444
+ Xr as bZ,
2445
+ vr as b_,
2446
+ jr as ba,
2447
+ _r as bb,
2448
+ xr as bc,
2449
+ Io as bd,
2450
+ ut as be,
2451
+ lt as bf,
2452
+ To as bg,
2453
+ Tr as bh,
2454
+ Qr as bi,
2455
+ wo as bj,
2456
+ tt as bk,
2457
+ Yo as bl,
2458
+ Lr as bm,
2459
+ Pr as bn,
2460
+ ao as bo,
2461
+ ns as bp,
2462
+ zr as bq,
2463
+ wt as br,
2464
+ ot as bs,
2465
+ Cr as bt,
2466
+ hn as bu,
2467
+ Wr as bv,
2468
+ es as bw,
2469
+ Zr as bx,
2470
+ Ar as by,
2471
+ wn as bz,
2472
+ U as c,
2473
+ me as d,
2474
+ Ro as e,
2475
+ G as f,
2476
+ st as g,
2477
+ Xe as h,
2478
+ F as i,
2479
+ _ as j,
2480
+ Le as k,
2481
+ Do as l,
2482
+ Wo as m,
2483
+ Go as n,
2484
+ Ae as o,
2485
+ sn as p,
2486
+ nt as q,
2487
+ Ft as r,
2488
+ rt as s,
2489
+ vt as t,
2490
+ Fo as u,
2491
+ Kr as v,
2492
+ Mt as w,
2493
+ Ce as x,
2494
+ Ao as y,
2495
+ mr as z
2496
+ };
2497
+ //# sourceMappingURL=scan-Dhu7f4Nl.js.map