@floorlaunchpad/sdk 0.3.1 → 0.4.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 (64) hide show
  1. package/CHANGELOG.md +97 -0
  2. package/README.md +20 -5
  3. package/dist/abi/evm.gen.js +1 -1
  4. package/dist/abi/solana.gen.js +1 -1
  5. package/dist/client/evm/index.js +16 -2
  6. package/dist/client/solana/index.js +19 -7
  7. package/dist/config/generated.js +26864 -402
  8. package/dist/config/registry.gen.js +33 -2
  9. package/dist/evm/chains.js +9 -1
  10. package/dist/evm/floor/abi.gen.js +1 -1
  11. package/dist/evm/floor/events.js +9 -1
  12. package/dist/evm/floor/legacy-events.js +25 -0
  13. package/dist/indexer/bodies.js +106 -16
  14. package/dist/indexer/client.js +35 -12
  15. package/dist/indexer/contract.js +138 -28
  16. package/dist/indexer/partners.js +3 -2
  17. package/dist/indexer/paths.js +63 -25
  18. package/dist/indexer/read.js +38 -13
  19. package/dist/indexer/search.js +130 -0
  20. package/dist/indexer/stack-edge.js +35 -0
  21. package/dist/indexer/stream.js +70 -23
  22. package/dist/math/v2/split.js +11 -3
  23. package/dist/solana/floor/events.js +1 -1
  24. package/dist/solana/floor/genesis.js +9 -3
  25. package/dist/solana/floor/instructions.js +14 -5
  26. package/dist/solana/floor/registry.js +4 -0
  27. package/dist/v2/devbuy.js +15 -0
  28. package/dist/v2/solana.js +17 -2
  29. package/dist/v2/tx/solana.js +1 -1
  30. package/docs/bot.md +36 -1
  31. package/docs/cursor-pages.md +56 -0
  32. package/docs/floor-line.md +208 -34
  33. package/examples/floor-line.html +373 -76
  34. package/package.json +1 -1
  35. package/src/abi/evm.gen.ts +1 -1
  36. package/src/abi/solana.gen.ts +1 -1
  37. package/src/client/evm/index.ts +16 -2
  38. package/src/client/solana/index.ts +19 -7
  39. package/src/client/types.ts +1 -1
  40. package/src/config/generated.ts +26864 -402
  41. package/src/config/index.ts +9 -2
  42. package/src/config/registry.gen.ts +33 -2
  43. package/src/events/types.gen.ts +2 -1
  44. package/src/evm/chains.ts +9 -1
  45. package/src/evm/floor/abi.gen.ts +1 -1
  46. package/src/evm/floor/events.ts +11 -1
  47. package/src/evm/floor/legacy-events.ts +27 -0
  48. package/src/indexer/bodies.ts +117 -16
  49. package/src/indexer/client.ts +54 -26
  50. package/src/indexer/contract.ts +158 -30
  51. package/src/indexer/partners.ts +3 -2
  52. package/src/indexer/paths.ts +86 -25
  53. package/src/indexer/read.ts +44 -15
  54. package/src/indexer/search.ts +138 -0
  55. package/src/indexer/stack-edge.ts +46 -0
  56. package/src/indexer/stream.ts +78 -24
  57. package/src/math/v2/split.ts +11 -3
  58. package/src/solana/floor/events.ts +1 -1
  59. package/src/solana/floor/genesis.ts +8 -2
  60. package/src/solana/floor/instructions.ts +13 -5
  61. package/src/solana/floor/registry.ts +4 -0
  62. package/src/v2/devbuy.ts +33 -0
  63. package/src/v2/solana.ts +20 -3
  64. package/src/v2/tx/solana.ts +1 -1
@@ -1,66 +1,240 @@
1
- # Drawing the floor line
1
+ # Show the FLOOR on your UI
2
2
 
3
- A FLOOR launch has a floor: a price in the quote token that the program's own money stands behind. The bare minimum we ask for is two things: the FLOOR line on the token's price chart, and the floor price somewhere on the token's page. Anything else is a bonus. It is a request, not a requirement, and it is highly appreciated. It costs one extra field and one extra line on the chart.
3
+ **If you list, chart, route or hold FLOOR tokens, please show the FLOOR.** Every FLOOR launch has a floor: a price in
4
+ its quote token that the program's own money stands behind, and that never falls. It is the single most useful number
5
+ a holder of a FLOOR token can see, and right now it is only visible on floor.supply. With your help it can be visible
6
+ wherever the token trades.
4
7
 
5
- [examples/floor-line.html](../examples/floor-line.html) is a working page: a price line, the floor line and the code that fetches and draws it. Open it in a browser.
8
+ It is a request, not a requirement, and it is highly appreciated. It costs one field and one line.
6
9
 
7
- ## What the floor is
10
+ [examples/floor-line.html](../examples/floor-line.html) shows the finished result: a token page with the FLOOR price next to
11
+ the price and the FLOOR line on the chart, a price / market-cap switch, a replay of a launch with a sell-off, and every
12
+ snippet on this page. Open it in a browser. It needs no network and no key.
8
13
 
9
- The program keeps money aside to buy tokens back at a fixed price. That price is the floor: the money in the floor pot divided by the tokens in circulation. A holder is backed by the floor the program's money holds. The floor is not a promise about the market price, and the market price can sit far above it.
14
+ ## What we ask
10
15
 
11
- Three facts shape the line:
16
+ **The minimum: two things.**
12
17
 
13
- - The floor is a price in the launch's quote token (USDC, SOL, ETH or another listed quote), per whole token.
14
- - It never falls in quote terms. Buys can lift it and sells do not lower it.
15
- - It starts when the launch graduates, which is when its flat-priced opening sale sells out. Before then the launch has no floor, and the field reads `0`.
18
+ 1. **The FLOOR line on the token's price chart.** One line, FLOOR orange `#FF6A1A`, 2 px, labelled `FLOOR`, under the
19
+ price.
20
+ 2. **The FLOOR price on the token's page,** next to the price. For example: `FLOOR $0.0189`.
16
21
 
17
- ## Which field to read
22
+ **Anything more is a bonus.** In rough order of how much it helps:
18
23
 
19
- **Partner API.** `GET /v2/dex/summary?id=<pair>` returns `floorPriceNative`, a decimal string in whole quote tokens per whole launch token, next to `priceNative` in the same units. The SDK decodes it as `DEX_SUMMARY` and builds the path as `dexSummary`. Read both fields from the same response so the two lines come from the same moment.
24
+ - The Max Loss: how far the price can fall to the floor, `1 − floor ÷ price` as a percentage before fees (`Max Loss 25%`), or `price is 1.33× the floor`.
25
+ - A FLOOR column in token lists and screeners.
26
+ - The FLOOR price in a wallet's holding row, next to the holding's value.
27
+ - An alert when the price comes near the floor.
28
+ - A "FLOOR" badge on launches that trade on the FLOOR program.
20
29
 
21
- **SDK, from the indexer.** `readLaunch(get, id)` in `@floorlaunchpad/sdk/indexer/read` returns the launch with `floorX64`. That is a Q64.64 price in quote base units per token math unit. One math unit is a millionth of a token on both chains. To get whole quote per whole token:
30
+ | You are | Show |
31
+ |---|---|
32
+ | A chart site or screener (DexScreener-style) | The line on the chart, the floor price in the pair's stats |
33
+ | A terminal or trading bot UI | The line on the chart, the floor price next to the buy and sell box |
34
+ | An aggregator or swap UI with a token page | The floor price on the token page; the line if you draw a chart |
35
+ | A wallet | The floor price on the token's detail screen |
36
+ | A data API that others build on | The floor as a field on the pair (and on each trade, if you serve trades) |
37
+
38
+ ## Get the number
39
+
40
+ There are three ways. Use the first one you can.
41
+
42
+ ### 1. The FLOOR Partner API (simplest)
43
+
44
+ Base URL `https://floor.supply/api/v1`. Server to server, with a key sent as `Authorization: Bearer <key>` (a key in the
45
+ URL is refused). Ask for a key at contact@floor.supply or on X. The reference is
46
+ <https://floor.supply/developers> and the OpenAPI document is `https://floor.supply/api/v1/openapi.json`. Every answer is
47
+ `{ data, meta }`.
48
+
49
+ | Read | Field | Gives |
50
+ |---|---|---|
51
+ | `GET /launches/{chain}/{token}` | `data.market.floorPriceQuote` | The floor now, whole quote per whole token |
52
+ | | `data.market.floorPriceUsd` | The same in USD at the live rate |
53
+ | | `data.market.priceQuote`, `data.market.maxLossPct` | The price now, and the Max Loss (1 − floor ÷ price, before fees) as a percentage |
54
+ | `GET /launches/{chain}/{token}/trades` | `data[].floorPriceQuote` | The floor after each trade: the history of the line |
55
+
56
+ `null` means there is no floor yet (the launch is still in Bonding) or the figure was not read. Never draw a `null` as 0.
57
+
58
+ ```js
59
+ // server side: the FLOOR price for the token page
60
+ const r = await fetch(`https://floor.supply/api/v1/launches/${chain}/${token}`, {
61
+ headers: { Authorization: `Bearer ${process.env.FLOOR_API_KEY}` },
62
+ });
63
+ const { data } = await r.json();
64
+ const floor = data.market.floorPriceQuote; // null before graduation
65
+ const price = data.market.priceQuote;
66
+ ```
67
+
68
+ ```js
69
+ // server side: the history of the line, newest trade first (page with meta.nextBefore)
70
+ const t = await fetch(`https://floor.supply/api/v1/launches/${chain}/${token}/trades?limit=100`, {
71
+ headers: { Authorization: `Bearer ${process.env.FLOOR_API_KEY}` },
72
+ });
73
+ const { data: trades, meta } = await t.json();
74
+ const floorPoints = trades
75
+ .filter((x) => x.floorPriceQuote !== null)
76
+ .map((x) => ({ time: x.time, value: x.floorPriceQuote }))
77
+ .reverse(); // oldest first, for a chart
78
+ ```
79
+
80
+ ### 2. From the chain, if you index trades yourself
81
+
82
+ Every trade event carries the floor after the trade, as `sqrtF`:
83
+
84
+ | Chain | Event | Field |
85
+ |---|---|---|
86
+ | EVM | `Trade` on the `FloorAmm` contract | `sqrtF` (`uint128`) |
87
+ | Solana | `TradeV2` from `floor_amm` (an Anchor CPI event) | `sqrt_f` (`u128`) |
88
+
89
+ `sqrtF` is the square root of the floor price in fixed point, with 72 fraction bits. The floor in whole quote per whole
90
+ token is:
91
+
92
+ ```
93
+ floor = sqrtF² × 10^6 ÷ (2^144 × 10^quoteDecimals)
94
+ ```
95
+
96
+ `quoteDecimals` is the quote token's decimals (6 for USDC, 9 for SOL, 18 for ETH). The `10^6` is there because the
97
+ program counts tokens in millionths on both chains. `sqrtF` is `0` until the launch graduates: draw no line then.
98
+
99
+ ```js
100
+ const floorOf = (sqrtF, quoteDecimals) =>
101
+ Number((sqrtF * sqrtF * 10n ** 6n * 10n ** 12n) >> 144n) / 10 ** (quoteDecimals + 12);
102
+ ```
103
+
104
+ Keep the multiplications in `bigint` (or a 256-bit integer); `sqrtF²` does not fit in 128 bits. The `10n ** 12n` keeps
105
+ twelve more digits through the shift. This is exactly what the example page's generator checks against the SDK.
106
+
107
+ ### 3. With the SDK
108
+
109
+ `@floorlaunchpad/sdk` reads the same number from a decoded launch: `priceX64(book.sqrtF)` in
110
+ `@floorlaunchpad/sdk/math/v2/sqrt` gives a Q64.64 price in quote base units per millionth of a token. If you run the FLOOR
111
+ indexer, `readLaunch(get, id)` in `@floorlaunchpad/sdk/indexer/read` returns it as `floorX64`, and the indexer's
112
+ `/v2/dex/summary?id=<pair>` serves it as `floorPriceNative`, next to `priceNative` in the same units. To get whole quote
113
+ per whole token from a Q64.64 value:
22
114
 
23
115
  ```ts
24
116
  const floor = Number((floorX64 * 10n ** 6n * 10n ** 12n) / (1n << 64n)) / 10 ** (quoteDecimals + 12);
25
117
  ```
26
118
 
27
- **SDK, from the chain.** The math reads the same number from a decoded book: `priceX64(book.sqrtF)` (`@floorlaunchpad/sdk/math/v2/sqrt`). `sqrtF` is 0 until the launch has a floor. The example page's numbers come from this math (see the note at the end).
119
+ If you draw candles from the FLOOR indexer, you need no second read: every candle of `readCandles(get, { launch, interval })`
120
+ carries `floorX64`, the floor at that bucket's close, in the same Q64.64 units. Draw one floor point per candle. It is
121
+ `null` where a bucket has none and absent from an indexer older than SDK 0.4.0, so fall back to the launch's own
122
+ `floorX64` then.
123
+
124
+ ## Draw it
125
+
126
+ **The look.** A solid line, 2 px, FLOOR orange `#FF6A1A`, labelled `FLOOR`, with its value on the price axis in the same
127
+ colour. The price stays your usual colour; the floor line goes under it.
128
+
129
+ **The shape.** A step line: it holds its value between trades and steps up at a trade that lifts it. It never steps down
130
+ in quote terms. It starts at graduation; before that there is no point to draw.
131
+
132
+ **The axis.** The same y axis and the same time axis as the price. Do not let the floor line widen the price scale on its
133
+ own: if the floor is far below the visible candles, pin a small `FLOOR` tag to the bottom edge of the chart instead.
28
134
 
29
- ## How to draw it
135
+ **Market-cap mode.** If your chart can show market cap instead of price, multiply the floor by the same supply you
136
+ multiply the price by, so the line stays in the same place under the candles. Keep the label `FLOOR`. Do not call that
137
+ number a market cap of its own.
30
138
 
31
- Draw a horizontal line at the floor value, under the price line, in FLOOR orange `#FF6A1A`, and label it "FLOOR". The line is a step line: it holds its value between trades and moves up at a trade that lifts it. If your chart already has a price line, use the same y axis and the same time axis.
139
+ ### Lightweight Charts (v5)
32
140
 
33
141
  ```js
34
- const s = await (await fetch(`${API}/v2/dex/summary?id=${pair}`)).json();
35
- const price = Number(s.priceNative);
36
- const floor = Number(s.floorPriceNative);
37
- const showFloor = floor > 0 && Number(s.circulatingSupply) > 0;
38
- series.price.update({ time, value: price });
39
- if (showFloor) series.floor.update({ time, value: floor });
142
+ import { createChart, CandlestickSeries, LineSeries, LineType } from "lightweight-charts";
143
+
144
+ const chart = createChart(el, { autoSize: true });
145
+ const candles = chart.addSeries(CandlestickSeries);
146
+ const floorLine = chart.addSeries(LineSeries, {
147
+ color: "#FF6A1A",
148
+ lineWidth: 2,
149
+ lineType: LineType.WithSteps, // holds between trades, steps up
150
+ title: "FLOOR",
151
+ priceLineVisible: false,
152
+ lastValueVisible: true,
153
+ crosshairMarkerVisible: false,
154
+ autoscaleInfoProvider: () => null, // the floor never stretches the price scale
155
+ });
156
+
157
+ candles.setData(ohlc); // your candles, oldest first
158
+ floorLine.setData(floorPoints); // [{ time, value }] from the trades, oldest first; none before graduation
159
+
160
+ // live: on each new trade
161
+ floorLine.update({ time: trade.time, value: trade.floorPriceQuote });
40
162
  ```
41
163
 
42
- ## Pitfalls
164
+ ### TradingView Advanced Charts (the Charting Library)
43
165
 
44
- **Units.** The floor is a price in the quote token. In quote terms it never falls. If you chart in USD, the line moves with the quote token's own USD price. A floor in a falling quote token then falls in dollars, though it has not fallen in the quote. Chart in quote units where you can, and say which units the chart uses where you cannot.
166
+ The simplest version is a locked horizontal line at the current floor, moved when the floor moves:
167
+
168
+ ```js
169
+ const chart = widget.activeChart();
170
+ const id = await chart.createShape(
171
+ { price: floor },
172
+ {
173
+ shape: "horizontal_line",
174
+ lock: true,
175
+ disableSelection: true,
176
+ disableSave: true,
177
+ text: "FLOOR",
178
+ overrides: { linecolor: "#FF6A1A", linewidth: 2, showLabel: true, textcolor: "#FF6A1A", showPrice: true },
179
+ },
180
+ );
181
+
182
+ // when a trade lifts the floor
183
+ chart.getShapeById(id).setPoints([{ price: newFloor }]);
184
+ ```
185
+
186
+ For the full step history, add a custom indicator that plots the floor series from your own trade store, styled as
187
+ above.
188
+
189
+ ### Your own canvas or SVG
190
+
191
+ Walk the trades oldest first. At each trade with a floor, draw a horizontal segment from the previous trade's time at the
192
+ previous floor, then a vertical step up to the new floor. The example page does exactly this in about fifteen lines
193
+ (`floorPath` in its script).
194
+
195
+ ### The FLOOR price on the token page
196
+
197
+ ```html
198
+ <div class="stat">
199
+ <span class="label">FLOOR</span>
200
+ <span class="value" style="color:#FF6A1A">$0.0189</span>
201
+ <span class="note">Max Loss 25%</span> <!-- bonus -->
202
+ </div>
203
+ ```
45
204
 
46
- **Read it, do not derive it.** Do not compute the floor from the money in the program and the total supply. The supply the program uses is the live supply, and it changes with every burn, including burns that happen with no trade. Take `floorPriceNative` as the program reports it.
205
+ Before graduation, show `FLOOR —` (or leave the stat out) and, if you like, `Bonding: no floor yet`.
47
206
 
48
- **The gap.** The floor divided by the price can fall as the price rises. This happens once the price is above the end of the launch's sales curve. It also happens in the Tail, the open-ended stretch after the curve ends. The price keeps rising in both, while the floor rises more slowly. The floor itself does not drop. A widening gap between the two lines is how the design works, not a bug in your chart. Do not label it as a loss of backing.
207
+ ## What to get right
49
208
 
50
- **Lifecycle.** Keep the line after graduation and in the Tail. A graduated launch stays on the same program, trades there as before and keeps its floor. Do not stop drawing the floor when the launch graduates, and do not look for it on another venue.
209
+ **Units.** The floor is a price in the quote token, and in quote terms it never falls. If you chart in USD, the line moves
210
+ with the quote token's own USD price: a floor in a falling quote token falls in dollars though it has not fallen in the
211
+ quote. Chart in quote units where you can; where you cannot, say which units the chart uses.
51
212
 
52
- **All tokens burned.** If every token in circulation has been burned, nothing is left to back and the program sends its backing money to the platform. There is no floor to show. Hide the line. Do not plot 0, and do not divide by a zero supply to work one out. A zero `circulatingSupply` in the summary is the signal.
213
+ **Read it, do not derive it.** Do not compute the floor from the money in the program and a supply you hold. The supply
214
+ the program uses is the live supply, and burns change it. Take `floorPriceQuote`, `sqrtF` or `floorPriceNative` as the
215
+ program reports it.
53
216
 
54
- **Before graduation.** A launch that has not graduated has no floor yet and the field reads `0`. Hide the line until it is above zero.
217
+ **The gap.** Once the price is past the end of the launch's sales curve (the Stack), and in the open-ended stretch after it
218
+ (the Tail), the price can rise faster than the floor, so floor ÷ price can fall while both rise. The floor itself does not
219
+ drop. A widening gap is how the design works, not a loss of backing; do not label it as one.
55
220
 
56
- **Caching.** Refresh the floor together with the price. If you cache the price for ten seconds, cache the floor for ten seconds with it, and never keep the floor longer than the price. A floor older than the price can look as if it has fallen behind.
221
+ **Graduation is not a migration.** The first window (Bonding, one flat price) selling out is graduation. The launch stays on
222
+ the same program, with the same pair and address, and the floor starts. Keep drawing the line after graduation and in the
223
+ Tail, and do not look for the token on another venue.
57
224
 
58
- **Words.** Never write that the floor is "guaranteed", and never call it a "floor market cap". Write "backed by the floor the program's money holds".
225
+ **No floor, no line.** Draw nothing before graduation (`null` or `sqrtF = 0`), and hide the line if circulating supply
226
+ reads 0 (every token outside the program burned).
59
227
 
60
- ## The example page
228
+ **Words.** Call it the "FLOOR" or the "floor price". It is what the program's money pays for a token sold into it. It is
229
+ not a promise about the market price, and the market price can sit far above it.
61
230
 
62
- `examples/floor-line.html` draws a simulated launch: a run of buys and sells through the SDK's own math, not a live pool. The source repository holds the small script that makes its data (`examples/gen-floor-line.mjs`), so the page can be rebuilt after a change to the math. The npm package ships the page and not the script.
231
+ ## Checklist
63
232
 
64
- ## Optional extras
233
+ - [ ] The FLOOR price is on the token page, in the quote token or clearly marked as USD.
234
+ - [ ] The FLOOR line is on the chart: `#FF6A1A`, 2 px, a step line, labelled `FLOOR`, under the price.
235
+ - [ ] Nothing is drawn before graduation; `null` is never drawn as 0.
236
+ - [ ] The line keeps its history and keeps going after graduation.
237
+ - [ ] Market-cap mode scales the floor by the same supply as the price, or hides it.
238
+ - [ ] Optional: the Max Loss, a list column, a wallet row, an alert.
65
239
 
66
- None of these is asked for. If you want to go further: show the gap between price and floor as a percentage, add the floor to a tooltip or a table of pools, or link a holder to this guide's explanation of what backs the token.
240
+ Shipped it, or stuck? Tell us at contact@floor.supply. We will check it with you and point FLOOR holders to your page.