@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,19 @@
1
+ /**
2
+ * How a bin mint spreads its two amounts across a span of bins.
3
+ *
4
+ * `BinPool.mint` takes, per bin, the share of `amount0` (X) and of `amount1`
5
+ * (Y) it receives, each scaled to 1e18. Bins strictly below the active id can
6
+ * only hold Y, bins strictly above it only X, and the active bin holds both.
7
+ * A share that sums to more than 1e18 on either side reverts; one that sums to
8
+ * less leaves part of the amount undeposited. The uniform spread here sums each
9
+ * side to EXACTLY 1e18 by pushing the rounding dust into that side's last bin.
10
+ *
11
+ * The active bin's composition is the pool's, not the depositor's: a deposit
12
+ * whose X:Y ratio differs from the active bin's reserves pays the pool's
13
+ * composition fee on the difference. This helper does not fold that in; the
14
+ * amounts a quote reports are what the position manager pulls.
15
+ */
16
+ import type { BinLiquidityShare } from "./protocol.js";
17
+ /** Spreads liquidity evenly across a bin span, as a bin mint requires. */
18
+ export declare function buildUniformBinDistribution(binIdLower: number, binIdUpper: number, activeId: number): BinLiquidityShare[];
19
+ //# sourceMappingURL=binDistribution.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"binDistribution.d.ts","sourceRoot":"","sources":["../../src/adapters/binDistribution.ts"],"names":[],"mappings":"AACA;;;;;;;;;;;;;;GAcG;AAEH,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,eAAe,CAAC;AAGvD,0EAA0E;AAC1E,wBAAgB,2BAA2B,CACzC,UAAU,EAAE,MAAM,EAClB,UAAU,EAAE,MAAM,EAClB,QAAQ,EAAE,MAAM,GACf,iBAAiB,EAAE,CA0BrB"}
@@ -0,0 +1,409 @@
1
+ /**
2
+ * The chain boundary.
3
+ *
4
+ * Every read and every write the widgets perform goes through
5
+ * {@link ProtocolAdapter}. No component, hook or controller in this package
6
+ * imports a viem client directly, which is what makes an implementation
7
+ * swappable without touching a line of UI.
8
+ *
9
+ * One implementation ships: {@link ../adapters/viem.js | ViemProtocolAdapter},
10
+ * real reads and writes through a viem transport. The package ships no mock
11
+ * adapter (source of truth only); the unit suites keep a test-only one under
12
+ * test/helpers/. A host can implement this interface itself, for example on
13
+ * top of wagmi or its own backend quoter - and if such an adapter serves
14
+ * anything not read from a chain, `isMock` must be `true` so the widgets say so.
15
+ */
16
+ import type { Address, Hex } from "viem";
17
+ import type { PoolKey, PoolId } from "@latchprotocol/sdk";
18
+ import type { LaunchGuard } from "../callpath/launch.js";
19
+ import type { ChainConfig } from "../config/chain.js";
20
+ import type { ResolvedIntegratorConfig } from "../config/integrator.js";
21
+ import type { TokenSaleAdapter } from "./sale.js";
22
+ /** Which flavour of pool a key addresses. */
23
+ export type PoolType = "CL" | "BIN";
24
+ /** Where a piece of data came from. Rendered by the UI; never cosmetic. */
25
+ export type DataSource = "live" | "mock";
26
+ /** ERC-20 (or native) token metadata. */
27
+ export interface TokenInfo {
28
+ readonly address: Address;
29
+ readonly symbol: string;
30
+ readonly name: string;
31
+ readonly decimals: number;
32
+ /** `https://` or `ipfs://` (resolved through the SDK's allow-listed gateways). Anything else renders as a monogram. */
33
+ readonly logoUrl?: string;
34
+ /** True for the chain's native asset (the zero address). */
35
+ readonly isNative?: boolean;
36
+ /**
37
+ * Provenance, once token lists are in play (`SwapWidget`'s `tokenLists` prop).
38
+ * `name` is the list the entry's fields came from, or `null` for a token the
39
+ * adapter itself offers (the pools this site routes through); `alsoIn` is
40
+ * every other list that names the same address. Absent when no list was given.
41
+ */
42
+ readonly listSource?: {
43
+ readonly name: string | null;
44
+ readonly alsoIn: readonly string[];
45
+ };
46
+ /** A tokenised stock, from a list's `extensions.stock`. The picker badges it; `rebasing` is a warning. */
47
+ readonly stock?: {
48
+ readonly issuer: string;
49
+ readonly ticker: string;
50
+ readonly rebasing: boolean;
51
+ };
52
+ /** The list's tag ids for this token (`native`, `stock`, `test`, `launch`, ...). */
53
+ readonly tags?: readonly string[];
54
+ }
55
+ /** A pool the widgets can route through or provide liquidity to. */
56
+ export interface PoolInfo {
57
+ readonly id: PoolId;
58
+ readonly key: PoolKey;
59
+ readonly poolType: PoolType;
60
+ readonly token0: TokenInfo;
61
+ readonly token1: TokenInfo;
62
+ /** Static LP fee in pips, or the dynamic-fee marker. */
63
+ readonly lpFeePips: number;
64
+ /** Concentrated-liquidity pools only. */
65
+ readonly tickSpacing?: number;
66
+ /** Liquidity-book pools only. */
67
+ readonly binStep?: number;
68
+ /** Hook contract, or the zero address. */
69
+ readonly hooks: Address;
70
+ }
71
+ /** Live-ish pool state needed to render ranges and prices. */
72
+ export interface PoolState {
73
+ readonly poolId: PoolId;
74
+ readonly poolType: PoolType;
75
+ /** Concentrated liquidity: current tick and price. */
76
+ readonly currentTick?: number;
77
+ readonly sqrtPriceX96?: bigint;
78
+ readonly liquidity?: bigint;
79
+ /** Liquidity book: currently active bin. */
80
+ readonly activeId?: number;
81
+ readonly source: DataSource;
82
+ }
83
+ /** One hop of a route. */
84
+ export interface RouteStep {
85
+ readonly poolId: PoolId;
86
+ readonly poolType: PoolType;
87
+ readonly tokenIn: TokenInfo;
88
+ readonly tokenOut: TokenInfo;
89
+ readonly lpFeePips: number;
90
+ readonly hooks: Address;
91
+ }
92
+ /** A swap quote request. Only exact-input is supported by the swap widget UI. */
93
+ export interface SwapQuoteRequest {
94
+ readonly tokenIn: TokenInfo;
95
+ readonly tokenOut: TokenInfo;
96
+ readonly amountIn: bigint;
97
+ /**
98
+ * Restrict the quote to ONE pool. A launch widget sets this: a token with
99
+ * both a CL and a Bin leg has two direct pools, and the schedule, the gate
100
+ * and the buy must all refer to the same one.
101
+ */
102
+ readonly poolId?: PoolId;
103
+ }
104
+ /**
105
+ * A swap quote.
106
+ *
107
+ * `grossAmountOut` is the pool's output **before** any integrator fee. The fee
108
+ * split is computed by {@link ../core/math.js | buildQuoteBreakdown}, never by
109
+ * the adapter, so that no adapter can under-report what an embedder earns.
110
+ */
111
+ export interface SwapQuoteResult {
112
+ readonly route: readonly RouteStep[];
113
+ readonly amountIn: bigint;
114
+ readonly grossAmountOut: bigint;
115
+ /** Output at the current price with no impact, if computable. */
116
+ readonly spotAmountOut: bigint | null;
117
+ /** LP fee paid, expressed in the input currency. */
118
+ readonly lpFeeAmount: bigint;
119
+ readonly lpFeePips: number;
120
+ /**
121
+ * `true` when the pool's fee is set per swap by its hook and the adapter
122
+ * could not read the rate in force (it can for a launch guard). `lpFeePips`
123
+ * is then `0` and must be rendered as "dynamic", never as "0%".
124
+ */
125
+ readonly lpFeeUnknown?: boolean;
126
+ readonly estimatedGas: bigint | null;
127
+ readonly source: DataSource;
128
+ }
129
+ /** A transaction the host is asked to sign, in adapter-neutral form. */
130
+ export interface WidgetTransactionRequest {
131
+ readonly to: Address;
132
+ readonly data: Hex;
133
+ readonly value: bigint;
134
+ /** Human-readable summary, used in confirmation UI and error messages. */
135
+ readonly summary: string;
136
+ /** Populated when the transaction includes an integrator fee step. */
137
+ readonly integratorFee?: {
138
+ readonly referrer: Address;
139
+ readonly feeBps: number;
140
+ readonly currency: Address;
141
+ readonly expectedAmount: bigint;
142
+ };
143
+ readonly source: DataSource;
144
+ }
145
+ /** The two-step allowance the router needs before it can pull the input token. */
146
+ export type ApprovalKind = "erc20-to-permit2" | "permit2-to-router";
147
+ /** An outstanding approval blocking a swap or liquidity action. */
148
+ export interface ApprovalRequirement {
149
+ readonly kind: ApprovalKind;
150
+ readonly token: TokenInfo;
151
+ readonly spender: Address;
152
+ readonly current: bigint;
153
+ readonly required: bigint;
154
+ }
155
+ /** Parameters for building a swap transaction. */
156
+ export interface SwapExecutionRequest {
157
+ readonly quote: SwapQuoteResult;
158
+ readonly tokenIn: TokenInfo;
159
+ readonly tokenOut: TokenInfo;
160
+ readonly amountIn: bigint;
161
+ /** Floor enforced by the swap action, before the integrator fee. */
162
+ readonly minAmountOutGross: bigint;
163
+ /** Floor on what the user receives, after the integrator fee. */
164
+ readonly minAmountOutNet: bigint;
165
+ /** Validated integrator config. Threaded straight into the call path. */
166
+ readonly integrator: ResolvedIntegratorConfig;
167
+ readonly recipient: Address;
168
+ readonly deadline: bigint;
169
+ /** Extra data forwarded to the pool's hook, if any. */
170
+ readonly hookData?: Hex;
171
+ }
172
+ /** A price range, expressed in whichever units the pool type uses. */
173
+ export type LiquidityRange = {
174
+ readonly type: "CL";
175
+ readonly tickLower: number;
176
+ readonly tickUpper: number;
177
+ } | {
178
+ readonly type: "BIN";
179
+ readonly activeIdDesired: number;
180
+ readonly binIdLower: number;
181
+ readonly binIdUpper: number;
182
+ /** How many bins the active id may drift before the mint reverts. */
183
+ readonly idSlippage: number;
184
+ };
185
+ /** Request to quote an add-liquidity operation. */
186
+ export interface AddLiquidityQuoteRequest {
187
+ readonly pool: PoolInfo;
188
+ readonly range: LiquidityRange;
189
+ readonly amount0Desired: bigint;
190
+ readonly amount1Desired: bigint;
191
+ }
192
+ /** Quoted result of adding liquidity. */
193
+ export interface AddLiquidityQuote {
194
+ readonly pool: PoolInfo;
195
+ readonly range: LiquidityRange;
196
+ readonly amount0: bigint;
197
+ readonly amount1: bigint;
198
+ /** CL: liquidity units. BIN: total liquidity minted across the bins. */
199
+ readonly liquidity: bigint;
200
+ /** Share of the pool this position would represent, in bps. Null if unknown. */
201
+ readonly shareBps: number | null;
202
+ /** BIN only: the per-bin distribution the call path will encode. */
203
+ readonly binDistribution?: readonly BinLiquidityShare[];
204
+ readonly source: DataSource;
205
+ }
206
+ /** One bin's share of a liquidity-book mint. */
207
+ export interface BinLiquidityShare {
208
+ readonly binId: number;
209
+ /** Offset from the active bin. */
210
+ readonly deltaId: number;
211
+ /** Share of `amount0`, scaled to 1e18. */
212
+ readonly distributionX: bigint;
213
+ /** Share of `amount1`, scaled to 1e18. */
214
+ readonly distributionY: bigint;
215
+ }
216
+ /** An existing liquidity position owned by the connected account. */
217
+ export interface PositionInfo {
218
+ readonly id: string;
219
+ /** CL positions are ERC-721 token ids; bin positions are ERC-6909-style. */
220
+ readonly tokenId?: bigint;
221
+ readonly pool: PoolInfo;
222
+ readonly range: LiquidityRange;
223
+ readonly liquidity: bigint;
224
+ readonly amount0: bigint;
225
+ readonly amount1: bigint;
226
+ readonly feesOwed0: bigint;
227
+ readonly feesOwed1: bigint;
228
+ /** BIN positions: the bins actually held, with their share amounts. */
229
+ readonly binAmounts?: readonly {
230
+ readonly binId: number;
231
+ readonly amount: bigint;
232
+ }[];
233
+ readonly inRange: boolean;
234
+ readonly source: DataSource;
235
+ }
236
+ /** Request to build an add-liquidity transaction. */
237
+ export interface AddLiquidityExecutionRequest {
238
+ readonly quote: AddLiquidityQuote;
239
+ readonly amount0Max: bigint;
240
+ readonly amount1Max: bigint;
241
+ readonly recipient: Address;
242
+ readonly deadline: bigint;
243
+ readonly integrator: ResolvedIntegratorConfig;
244
+ readonly hookData?: Hex;
245
+ /** Set to increase an existing CL position rather than mint a new one. */
246
+ readonly tokenId?: bigint;
247
+ }
248
+ /** Request to build a remove-liquidity transaction. */
249
+ export interface RemoveLiquidityExecutionRequest {
250
+ readonly position: PositionInfo;
251
+ /** Fraction of the position to withdraw, in bps of its liquidity. */
252
+ readonly percentBps: number;
253
+ readonly amount0Min: bigint;
254
+ readonly amount1Min: bigint;
255
+ readonly recipient: Address;
256
+ readonly deadline: bigint;
257
+ readonly integrator: ResolvedIntegratorConfig;
258
+ readonly hookData?: Hex;
259
+ }
260
+ /** Quote for removing liquidity. */
261
+ export interface RemoveLiquidityQuote {
262
+ readonly position: PositionInfo;
263
+ readonly percentBps: number;
264
+ readonly amount0: bigint;
265
+ readonly amount1: bigint;
266
+ readonly source: DataSource;
267
+ }
268
+ /**
269
+ * A Latch launch.
270
+ *
271
+ * Not a token sale. A launch is a concentrated-liquidity pool with
272
+ * `LaunchGuardHook` named in its `PoolKey` and a fee that decays from
273
+ * `initialFeePips` to `finalFeePips` over `guard.window`. Everything the
274
+ * hook knows is keyed by `PoolId`, and every field below is read from it or
275
+ * from the pool key — there is no sale record, no cap, no allocation and no
276
+ * per-account state to read, because none of those exist.
277
+ *
278
+ * Buying into a launch is an ordinary swap, quoted with `quoteSwap` and
279
+ * executed with `buildSwap`, which is why this interface adds no buy method.
280
+ */
281
+ export interface LaunchInfo {
282
+ readonly poolId: PoolId;
283
+ /** The pool itself: key, tokens, tick spacing. */
284
+ readonly pool: PoolInfo;
285
+ /** The launch guard the pool key names: `LaunchGuardHook` for a CL pool, `BinLaunchGuardHook` for a Bin pool. */
286
+ readonly hook: Address;
287
+ /** The token being launched, resolved from `guard.launchTokenIsCurrency0`. */
288
+ readonly launchToken: TokenInfo;
289
+ /** The other side of the pool: what buyers pay with, and what caps are in. */
290
+ readonly quoteToken: TokenInfo;
291
+ /** The decoded `getLaunch(poolId)` record. */
292
+ readonly guard: LaunchGuard;
293
+ /**
294
+ * `currentFee(poolId)` as the hook answered it, in pips.
295
+ *
296
+ * Read from chain rather than derived, so the number on screen is the number
297
+ * the contract will charge. {@link ../callpath/launch.js | launchFeeAt}
298
+ * reproduces the same maths locally for the projected schedule.
299
+ */
300
+ readonly currentFeePips: number;
301
+ /**
302
+ * "Now" on the hook's own clock when the reads above were taken
303
+ * (`guard.durationClock`): the latest `block.timestamp` for the timestamp
304
+ * build, or `block.number` as the hook sees it for the block-numbered one —
305
+ * NOT `eth_blockNumber`, which on an Arbitrum chain is the L2 block.
306
+ */
307
+ readonly readAt: bigint;
308
+ readonly source: DataSource;
309
+ }
310
+ /** Result of waiting on a transaction. */
311
+ export interface TransactionOutcome {
312
+ readonly hash: Hex;
313
+ readonly status: "success" | "reverted";
314
+ readonly blockNumber: bigint | null;
315
+ readonly source: DataSource;
316
+ }
317
+ /**
318
+ * The single interface every chain read and write passes through.
319
+ *
320
+ * Methods that a given deployment cannot support must throw
321
+ * {@link UnsupportedOperationError} rather than returning empty or zero data.
322
+ * Silence is indistinguishable from "there is no liquidity", which is a lie the
323
+ * UI would render as fact.
324
+ */
325
+ export interface ProtocolAdapter {
326
+ /** Identifies the implementation, e.g. `"viem"`. */
327
+ readonly kind: string;
328
+ /**
329
+ * `true` when nothing this adapter returns came from a chain. The styled
330
+ * widgets render a persistent banner when this is set, and it cannot be
331
+ * suppressed by configuration.
332
+ */
333
+ readonly isMock: boolean;
334
+ readonly chain: ChainConfig;
335
+ /** Connected account, or `null` when no wallet is connected. */
336
+ getAccount(): Promise<Address | null>;
337
+ /** Tokens this deployment knows about, for the token picker. */
338
+ listTokens(): Promise<readonly TokenInfo[]>;
339
+ getToken(address: Address): Promise<TokenInfo | null>;
340
+ getBalance(token: TokenInfo, owner: Address): Promise<bigint>;
341
+ /** Pools available for routing and liquidity provision. */
342
+ listPools(): Promise<readonly PoolInfo[]>;
343
+ getPoolState(pool: PoolInfo): Promise<PoolState>;
344
+ /**
345
+ * Approvals still required before `spender` can pull `amount` of `token`
346
+ * through Permit2. `spender` defaults to the universal router (a swap); a
347
+ * liquidity add passes the position manager that settles the deposit.
348
+ */
349
+ getApprovalRequirements(token: TokenInfo, owner: Address, amount: bigint, spender?: Address): Promise<readonly ApprovalRequirement[]>;
350
+ buildApproval(requirement: ApprovalRequirement): Promise<WidgetTransactionRequest>;
351
+ quoteSwap(request: SwapQuoteRequest): Promise<SwapQuoteResult>;
352
+ buildSwap(request: SwapExecutionRequest): Promise<WidgetTransactionRequest>;
353
+ quoteAddLiquidity(request: AddLiquidityQuoteRequest): Promise<AddLiquidityQuote>;
354
+ buildAddLiquidity(request: AddLiquidityExecutionRequest): Promise<WidgetTransactionRequest>;
355
+ listPositions(owner: Address, pool?: PoolInfo): Promise<readonly PositionInfo[]>;
356
+ quoteRemoveLiquidity(position: PositionInfo, percentBps: number): Promise<RemoveLiquidityQuote>;
357
+ buildRemoveLiquidity(request: RemoveLiquidityExecutionRequest): Promise<WidgetTransactionRequest>;
358
+ /**
359
+ * Launch pools this deployment surfaces.
360
+ *
361
+ * Must throw — not return `[]` — when the chain config carries neither a
362
+ * `launchGuardHook` nor a `binLaunchGuardHook` address. An empty array means
363
+ * "a guard is deployed and no pool uses it"; a `ChainConfigError` means "there is no guard here". A UI
364
+ * has to be able to tell those apart, and only one of them is a launchpad
365
+ * that does not exist on this chain.
366
+ */
367
+ listLaunches(): Promise<readonly LaunchInfo[]>;
368
+ /** One launch by pool id, or `null` when that pool has no launch record. */
369
+ getLaunch(poolId: PoolId): Promise<LaunchInfo | null>;
370
+ /**
371
+ * Every pool a `LaunchpadKitV2` launch opened for `token`, as launches, in
372
+ * the kit's leg order. Must throw `ChainConfigError` naming `launchpadKitV2`
373
+ * when no kit is configured; returns `[]` for a token the kit never launched.
374
+ */
375
+ getLaunchesForToken(token: Address): Promise<readonly LaunchInfo[]>;
376
+ /**
377
+ * Optional. A third-party token sale contract, which Latch does not have.
378
+ * Nothing in this package reads it; see {@link ./sale.js}.
379
+ */
380
+ readonly sale?: TokenSaleAdapter;
381
+ sendTransaction(request: WidgetTransactionRequest): Promise<Hex>;
382
+ waitForTransaction(hash: Hex): Promise<TransactionOutcome>;
383
+ /**
384
+ * The chain's clock, in seconds: the timestamp the next block will carry
385
+ * where the RPC can say (the pending block), else the latest block's (see
386
+ * `nextBlockClock` in config/chain). Transaction deadlines are
387
+ * compared with `block.timestamp`, so they are built from this clock rather
388
+ * than the browser's: a devnet whose time was advanced, or a visitor whose
389
+ * clock is wrong, would otherwise sign a trade that is already expired.
390
+ * Optional: without it the widgets fall back to the local clock.
391
+ */
392
+ getBlockTimestamp?(): Promise<bigint>;
393
+ }
394
+ /** Thrown when an adapter cannot perform an operation on this deployment. */
395
+ export declare class UnsupportedOperationError extends Error {
396
+ readonly operation: string;
397
+ constructor(operation: string, detail: string);
398
+ }
399
+ /** Thrown when a wallet action is required but no account is connected. */
400
+ export declare class WalletNotConnectedError extends Error {
401
+ constructor(action: string);
402
+ }
403
+ /** Thrown when the requested route does not exist in this deployment. */
404
+ export declare class NoRouteError extends Error {
405
+ readonly tokenIn: Address;
406
+ readonly tokenOut: Address;
407
+ constructor(tokenIn: Address, tokenOut: Address);
408
+ }
409
+ //# sourceMappingURL=protocol.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"protocol.d.ts","sourceRoot":"","sources":["../../src/adapters/protocol.ts"],"names":[],"mappings":"AACA;;;;;;;;;;;;;;GAcG;AAEH,OAAO,KAAK,EAAE,OAAO,EAAE,GAAG,EAAE,MAAM,MAAM,CAAC;AACzC,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,EAAE,MAAM,oBAAoB,CAAC;AAC1D,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,uBAAuB,CAAC;AACzD,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAC;AACtD,OAAO,KAAK,EAAE,wBAAwB,EAAE,MAAM,yBAAyB,CAAC;AACxE,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,WAAW,CAAC;AAElD,6CAA6C;AAC7C,MAAM,MAAM,QAAQ,GAAG,IAAI,GAAG,KAAK,CAAC;AAEpC,2EAA2E;AAC3E,MAAM,MAAM,UAAU,GAAG,MAAM,GAAG,MAAM,CAAC;AAEzC,yCAAyC;AACzC,MAAM,WAAW,SAAS;IACxB,QAAQ,CAAC,OAAO,EAAE,OAAO,CAAC;IAC1B,QAAQ,C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MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,UAAU,GAAG,IAAI,CAAC,CAAC;IACtD;;;;OAIG;IACH,mBAAmB,CAAC,KAAK,EAAE,OAAO,GAAG,OAAO,CAAC,SAAS,UAAU,EAAE,CAAC,CAAC;IAEpE;;;OAGG;IACH,QAAQ,CAAC,IAAI,CAAC,EAAE,gBAAgB,CAAC;IAEjC,eAAe,CAAC,OAAO,EAAE,wBAAwB,GAAG,OAAO,CAAC,GAAG,CAAC,CAAC;IACjE,kBAAkB,CAAC,IAAI,EAAE,GAAG,GAAG,OAAO,CAAC,kBAAkB,CAAC,CAAC;IAC3D;;;;;;;;OAQG;IACH,iBAAiB,CAAC,IAAI,OAAO,CAAC,MAAM,CAAC,CAAC;CACvC;AAED,6EAA6E;AAC7E,qBAAa,yBAA0B,SAAQ,KAAK;IAClD,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAC;gBAEf,SAAS,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM;CAK9C;AAED,2EAA2E;AAC3E,qBAAa,uBAAwB,SAAQ,KAAK;gBACpC,MAAM,EAAE,MAAM;CAI3B;AAED,yEAAyE;AACzE,qBAAa,YAAa,SAAQ,KAAK;IACrC,QAAQ,CAAC,OAAO,EAAE,OAAO,CAAC;IAC1B,QAAQ,CAAC,QAAQ,EAAE,OAAO,CAAC;gBAEf,OAAO,EAAE,OAAO,EAAE,QAAQ,EAAE,OAAO;CAMhD"}
@@ -0,0 +1,142 @@
1
+ /**
2
+ * Optional extension point: a third-party token sale.
3
+ *
4
+ * ## Nothing in Latch implements this, on purpose
5
+ *
6
+ * A Latch launch is a pool with `LaunchGuardHook` attached and a decaying LP
7
+ * fee. Buying into one is an ordinary swap. There is no `buy`, no soft or hard
8
+ * cap, no allocation, no claim, and no per-wallet limit anywhere in the
9
+ * protocol — see {@link ../callpath/launch.js} for why a per-wallet limit is
10
+ * not implementable at the hook layer at all.
11
+ *
12
+ * This package used to ship a `LAUNCHPAD_ABI` describing a sale contract with
13
+ * all of those features. No deployed contract implemented it, so every byte of
14
+ * calldata it produced was guaranteed to fail. It has been deleted.
15
+ *
16
+ * ## What replaces it
17
+ *
18
+ * The shape of an *answer*, not the shape of somebody's contract. If you run a
19
+ * genuine sale contract, you implement {@link TokenSaleAdapter} against your own
20
+ * ABI and hang it off `ProtocolAdapter.sale`. Your `buildBuy` returns a
21
+ * {@link ../adapters/protocol.js | WidgetTransactionRequest} — the same
22
+ * adapter-neutral `{to, data, value}` the rest of this package speaks — so this
23
+ * package never has to guess at a function selector it cannot verify.
24
+ *
25
+ * That is the whole point of putting it here: an unverifiable ABI is a
26
+ * liability wherever it lives, and the one place it is honest is behind an
27
+ * interface the integrator fills in from a contract they actually deployed.
28
+ *
29
+ * Nothing in this package reads `ProtocolAdapter.sale`. The styled
30
+ * `LaunchWidget` binds to `LaunchGuardHook` and to nothing else. Consuming
31
+ * these types means building your own UI on top of them.
32
+ */
33
+ import type { Address } from "viem";
34
+ import type { ResolvedIntegratorConfig } from "../config/integrator.js";
35
+ import type { DataSource, TokenInfo, WidgetTransactionRequest } from "./protocol.js";
36
+ /** Lifecycle of a third-party token sale. */
37
+ export type TokenSaleStatus = "upcoming" | "live" | "paused" | "ended" | "sold-out" | "cancelled";
38
+ /** Shape of a sale's price curve, if it has one. */
39
+ export type TokenSalePriceCurve = {
40
+ readonly kind: "fixed";
41
+ readonly price: bigint;
42
+ } | {
43
+ readonly kind: "linear";
44
+ readonly startPrice: bigint;
45
+ readonly endPrice: bigint;
46
+ } | {
47
+ readonly kind: "exponential";
48
+ readonly startPrice: bigint;
49
+ readonly endPrice: bigint;
50
+ /** Curvature exponent, scaled to 1e18. */
51
+ readonly exponent: bigint;
52
+ };
53
+ /**
54
+ * A sale, as your adapter reports it.
55
+ *
56
+ * Every field is optional-by-nullability where a sale might not have the
57
+ * concept. Return `null` rather than zero: a UI can say "no cap" from `null`,
58
+ * but `0n` reads as "cap reached".
59
+ */
60
+ export interface TokenSaleInfo {
61
+ /** The sale contract. */
62
+ readonly id: Address;
63
+ readonly token: TokenInfo;
64
+ /** Currency buyers pay in. */
65
+ readonly paymentToken: TokenInfo;
66
+ readonly status: TokenSaleStatus;
67
+ readonly totalForSale: bigint;
68
+ readonly sold: bigint;
69
+ readonly raised: bigint;
70
+ readonly softCap: bigint | null;
71
+ readonly hardCap: bigint | null;
72
+ /** Unix seconds. */
73
+ readonly startTime: bigint;
74
+ readonly endTime: bigint;
75
+ /** Maximum a single wallet may spend, in the payment currency. */
76
+ readonly perWalletCap: bigint | null;
77
+ readonly minPurchase: bigint;
78
+ readonly priceCurve: TokenSalePriceCurve | null;
79
+ readonly source: DataSource;
80
+ }
81
+ /** One account's standing in a sale. */
82
+ export interface TokenSaleAccountState {
83
+ readonly saleId: Address;
84
+ readonly account: Address;
85
+ readonly spent: bigint;
86
+ readonly allocated: bigint;
87
+ /** Remaining spend allowed under the per-wallet cap. `null` when uncapped. */
88
+ readonly capRemaining: bigint | null;
89
+ readonly eligible: boolean;
90
+ readonly ineligibleReason: string | null;
91
+ readonly source: DataSource;
92
+ }
93
+ /** Quote for a sale purchase. */
94
+ export interface TokenSaleQuote {
95
+ readonly sale: TokenSaleInfo;
96
+ readonly amountIn: bigint;
97
+ readonly tokensOut: bigint;
98
+ /** Effective price paid, in payment units per whole token. */
99
+ readonly effectivePrice: bigint;
100
+ readonly source: DataSource;
101
+ }
102
+ /** Request to build a sale purchase transaction. */
103
+ export interface TokenSaleBuyRequest {
104
+ readonly quote: TokenSaleQuote;
105
+ readonly minTokensOut: bigint;
106
+ readonly recipient: Address;
107
+ readonly deadline: bigint;
108
+ /**
109
+ * The validated integrator config from the provider.
110
+ *
111
+ * Whether a sale contract can pay a referrer at all is a property of that
112
+ * contract. If yours cannot, ignore this and do not silently drop the fee
113
+ * into a transfer the user does not see.
114
+ */
115
+ readonly integrator: ResolvedIntegratorConfig;
116
+ }
117
+ /**
118
+ * The seam. Implement it against your own sale contract.
119
+ *
120
+ * Every method may throw; the headless layer surfaces the error rather than
121
+ * substituting a default.
122
+ */
123
+ export interface TokenSaleAdapter {
124
+ /** Identifies the implementation in error messages, e.g. `"acme-launchpad"`. */
125
+ readonly kind: string;
126
+ listSales(): Promise<readonly TokenSaleInfo[]>;
127
+ getSale(id: Address): Promise<TokenSaleInfo | null>;
128
+ getSaleAccountState(id: Address, account: Address): Promise<TokenSaleAccountState>;
129
+ quoteBuy(sale: TokenSaleInfo, amountIn: bigint): Promise<TokenSaleQuote>;
130
+ buildBuy(request: TokenSaleBuyRequest): Promise<WidgetTransactionRequest>;
131
+ }
132
+ /** Thrown by a host that wires a sale UI without wiring a sale adapter. */
133
+ export declare class NoSaleAdapterError extends Error {
134
+ constructor();
135
+ }
136
+ /** Narrowing helper, so a host can branch without a cast. */
137
+ export declare function hasSaleAdapter(adapter: {
138
+ readonly sale?: TokenSaleAdapter;
139
+ }): adapter is {
140
+ readonly sale: TokenSaleAdapter;
141
+ };
142
+ //# sourceMappingURL=sale.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"sale.d.ts","sourceRoot":"","sources":["../../src/adapters/sale.ts"],"names":[],"mappings":"AACA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA+BG;AAEH,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,MAAM,CAAC;AACpC,OAAO,KAAK,EAAE,wBAAwB,EAAE,MAAM,yBAAyB,CAAC;AACxE,OAAO,KAAK,EAAE,UAAU,EAAE,SAAS,EAAE,wBAAwB,EAAE,MAAM,eAAe,CAAC;AAErF,6CAA6C;AAC7C,MAAM,MAAM,eAAe,GACvB,UAAU,GACV,MAAM,GACN,QAAQ,GACR,OAAO,GACP,UAAU,GACV,WAAW,CAAC;AAEhB,oDAAoD;AACpD,MAAM,MAAM,mBAAmB,GAC3B;IAAE,QAAQ,CAAC,IAAI,EAAE,OAAO,CAAC;IAAC,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAA;CAAE,GAClD;IAAE,QAAQ,CAAC,IAAI,EAAE,QA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