@floorlaunchpad/sdk 0.3.0 → 0.3.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (41) hide show
  1. package/CHANGELOG.md +61 -0
  2. package/README.md +10 -0
  3. package/dist/abi/solana.gen.js +2 -0
  4. package/dist/config/generated.js +121 -64
  5. package/dist/evm/chains.js +5 -1
  6. package/dist/evm/squid.js +107 -0
  7. package/dist/index.js +2 -0
  8. package/dist/indexer/bodies.js +16 -0
  9. package/dist/indexer/client.js +4 -0
  10. package/dist/indexer/contract.js +17 -2
  11. package/dist/indexer/partners.js +5 -0
  12. package/dist/indexer/paths.js +6 -0
  13. package/dist/indexer/read.js +13 -0
  14. package/dist/math/v2/trade.js +8 -8
  15. package/dist/solana/floor/accounts.js +3 -1
  16. package/dist/solana/floor/events.js +4 -0
  17. package/dist/solana/floor/instructions.js +13 -0
  18. package/dist/v2/devbuy.js +15 -0
  19. package/dist/v2/router.js +22 -0
  20. package/docs/floor-line.md +235 -0
  21. package/examples/floor-line.html +401 -0
  22. package/package.json +2 -1
  23. package/src/abi/solana.gen.ts +2 -0
  24. package/src/config/generated.ts +121 -64
  25. package/src/config/index.ts +2 -0
  26. package/src/events/types.gen.ts +11 -0
  27. package/src/evm/chains.ts +5 -1
  28. package/src/evm/squid.ts +138 -0
  29. package/src/index.ts +2 -0
  30. package/src/indexer/bodies.ts +19 -0
  31. package/src/indexer/client.ts +8 -0
  32. package/src/indexer/contract.ts +18 -3
  33. package/src/indexer/partners.ts +6 -0
  34. package/src/indexer/paths.ts +6 -0
  35. package/src/indexer/read.ts +13 -0
  36. package/src/math/v2/trade.ts +8 -8
  37. package/src/solana/floor/accounts.ts +3 -1
  38. package/src/solana/floor/events.ts +4 -0
  39. package/src/solana/floor/instructions.ts +13 -0
  40. package/src/v2/devbuy.ts +33 -0
  41. package/src/v2/router.ts +22 -0
@@ -0,0 +1,401 @@
1
+ <!doctype html>
2
+ <html lang="en">
3
+ <head>
4
+ <meta charset="utf-8">
5
+ <meta name="viewport" content="width=device-width, initial-scale=1">
6
+ <title>Show the FLOOR</title>
7
+ <style>
8
+ :root { --bg:#000000; --panel:#101113; --panel2:#16181B; --line:#23262B; --text:#F4F5F7; --muted:#8A94A3; --price:#8EA0BC; --floor:#FF6A1A; --up:#2EBD85; --down:#F6465D; }
9
+ * { box-sizing:border-box; }
10
+ body { margin:0; background:var(--bg); color:var(--text); font:15px/1.5 system-ui, -apple-system, "Segoe UI", sans-serif; }
11
+ main { max-width:1180px; margin:0 auto; padding:28px 16px 64px; }
12
+ a { color:var(--floor); }
13
+ h1 { font-size:28px; line-height:1.2; margin:0 0 8px; letter-spacing:-0.01em; }
14
+ h1 em { font-style:normal; color:var(--floor); }
15
+ h2 { font-size:17px; margin:0 0 12px; }
16
+ .lede { color:var(--muted); max-width:760px; margin:0 0 24px; }
17
+ .lede b { color:var(--text); font-weight:600; }
18
+ .panel { background:var(--panel); border:1px solid var(--line); border-radius:10px; padding:16px; min-width:0; }
19
+ .layout { display:grid; grid-template-columns:minmax(0,1fr) 300px; gap:16px; }
20
+ @media (max-width:900px) { .layout { grid-template-columns:minmax(0,1fr); } }
21
+
22
+ /* the mock token page */
23
+ .tok { display:flex; align-items:center; gap:12px; flex-wrap:wrap; margin-bottom:14px; }
24
+ .ava { width:40px; height:40px; border-radius:50%; background:linear-gradient(135deg,#2a2d33,#4a505a); display:grid; place-items:center; font-weight:700; }
25
+ .name { font-weight:700; font-size:18px; }
26
+ .name small { color:var(--muted); font-weight:500; font-size:14px; }
27
+ .pill { font-size:12px; padding:2px 8px; border-radius:999px; border:1px solid var(--line); color:var(--muted); }
28
+ .pill.grad { color:var(--floor); border-color:rgba(255,106,26,.45); }
29
+ .stats { display:grid; grid-template-columns:repeat(4,minmax(0,1fr)); gap:8px; margin-bottom:14px; }
30
+ @media (max-width:560px) { .stats { grid-template-columns:repeat(2,minmax(0,1fr)); } }
31
+ .stat { background:var(--panel2); border-radius:8px; padding:8px 10px; min-width:0; position:relative; }
32
+ .stat .k { font-size:12px; color:var(--muted); }
33
+ .stat .v { font-size:18px; font-weight:650; font-variant-numeric:tabular-nums; overflow:hidden; text-overflow:ellipsis; white-space:nowrap; }
34
+ .stat.ask { outline:1px dashed rgba(255,106,26,.6); outline-offset:2px; }
35
+ .stat.ask .v { color:var(--floor); }
36
+ .tag { position:absolute; top:-9px; right:8px; font-size:10px; letter-spacing:.06em; text-transform:uppercase; background:var(--floor); color:#000; padding:0 6px; border-radius:4px; font-weight:700; }
37
+ .tag.bonus { background:var(--panel); color:var(--muted); border:1px solid var(--line); }
38
+
39
+ .bar { display:flex; gap:8px; align-items:center; flex-wrap:wrap; margin-bottom:8px; }
40
+ .seg { display:inline-flex; border:1px solid var(--line); border-radius:8px; overflow:hidden; }
41
+ .seg button { background:transparent; color:var(--muted); border:0; padding:5px 10px; font:inherit; font-size:13px; cursor:pointer; transition:color .15s, background .15s; }
42
+ .seg button[aria-pressed=true] { background:var(--panel2); color:var(--text); }
43
+ .legend { display:flex; gap:14px; font-size:13px; color:var(--muted); margin-left:auto; }
44
+ .legend span::before { content:""; display:inline-block; width:16px; height:2px; margin-right:6px; vertical-align:middle; background:currentColor; }
45
+ .legend .p { color:var(--price); } .legend .f { color:var(--floor); }
46
+ .chartwrap { position:relative; }
47
+ svg { width:100%; height:auto; display:block; }
48
+ .ask-chart { position:absolute; top:6px; left:8px; }
49
+ .replay { display:flex; gap:10px; align-items:center; margin-top:8px; }
50
+ .replay button { background:var(--panel2); color:var(--text); border:1px solid var(--line); border-radius:8px; padding:5px 12px; font:inherit; font-size:13px; cursor:pointer; }
51
+ input[type=range] { flex:1; accent-color:var(--floor); }
52
+ .read { margin-top:6px; color:var(--muted); font-size:13px; min-height:1.5em; }
53
+ .read b { color:var(--text); font-weight:600; }
54
+
55
+ /* the ask */
56
+ .ask ol, .ask ul { margin:0 0 12px; padding-left:20px; }
57
+ .ask li { margin:4px 0; }
58
+ .ask .min li::marker { color:var(--floor); font-weight:700; }
59
+ .ask h3 { font-size:13px; text-transform:uppercase; letter-spacing:.06em; color:var(--muted); margin:14px 0 6px; }
60
+ .ask h3:first-of-type { margin-top:0; }
61
+ .swatch { display:inline-block; width:10px; height:10px; border-radius:2px; background:var(--floor); vertical-align:middle; margin-right:4px; }
62
+ .ask p { color:var(--muted); font-size:13px; margin:8px 0 0; }
63
+
64
+ /* code */
65
+ .code { margin-top:16px; }
66
+ .tabs { display:flex; gap:4px; flex-wrap:wrap; margin-bottom:10px; }
67
+ .tabs button { background:transparent; border:1px solid var(--line); color:var(--muted); border-radius:8px; padding:5px 10px; font:inherit; font-size:13px; cursor:pointer; transition:color .15s, border-color .15s; }
68
+ .tabs button[aria-selected=true] { color:var(--text); border-color:var(--floor); }
69
+ .codebox { position:relative; background:#0A0B0C; border:1px solid var(--line); border-radius:8px; }
70
+ pre { margin:0; padding:14px; overflow:auto; font:13px/1.55 ui-monospace, SFMono-Regular, Menlo, monospace; white-space:pre; max-height:460px; }
71
+ .copy { position:absolute; top:8px; right:8px; background:var(--panel2); color:var(--text); border:1px solid var(--line); border-radius:6px; padding:3px 9px; font:inherit; font-size:12px; cursor:pointer; }
72
+ .note { color:var(--muted); font-size:13px; margin:8px 0 0; }
73
+ footer { color:var(--muted); font-size:13px; margin-top:24px; }
74
+ </style>
75
+ </head>
76
+ <body>
77
+ <main>
78
+ <h1>Show the <em>FLOOR</em> on your UI</h1>
79
+ <p class="lede">Every FLOOR launch has a floor: a price in its quote token that the program's own money stands behind, and that never falls. <b>We ask for two things: the FLOOR line on the chart and the FLOOR price on the token page.</b> Anything more is a bonus. It is a request, not a requirement, and it is highly appreciated. Below is what it looks like, then the code.</p>
80
+
81
+ <div class="layout">
82
+ <section class="panel" aria-label="Example token page">
83
+ <div class="tok">
84
+ <div class="ava" aria-hidden="true">D</div>
85
+ <div class="name">DEMO <small>/ USDC</small></div>
86
+ <span class="pill" id="phase">Bonding</span>
87
+ </div>
88
+ <div class="stats">
89
+ <div class="stat"><div class="k">Price</div><div class="v" id="sPrice">–</div></div>
90
+ <div class="stat ask"><span class="tag">asked</span><div class="k">FLOOR</div><div class="v" id="sFloor">–</div></div>
91
+ <div class="stat"><span class="tag bonus">bonus</span><div class="k">Backed</div><div class="v" id="sBacked">–</div></div>
92
+ <div class="stat"><div class="k">Market cap</div><div class="v" id="sMcap">–</div></div>
93
+ </div>
94
+ <div class="bar">
95
+ <div class="seg" role="group" aria-label="Chart units">
96
+ <button type="button" data-mode="price" aria-pressed="true">Price</button>
97
+ <button type="button" data-mode="mcap" aria-pressed="false">Market cap</button>
98
+ </div>
99
+ <div class="legend"><span class="p">Price</span><span class="f">FLOOR</span></div>
100
+ </div>
101
+ <div class="chartwrap">
102
+ <svg id="chart" viewBox="0 0 760 380" role="img" aria-label="Candles with the FLOOR line under them"></svg>
103
+ </div>
104
+ <div class="replay">
105
+ <button type="button" id="play">Replay</button>
106
+ <input id="at" type="range" min="0" value="0" aria-label="Move through the launch">
107
+ </div>
108
+ <div class="read" id="read"></div>
109
+ </section>
110
+
111
+ <aside class="panel ask" aria-label="What we ask">
112
+ <h3>The minimum</h3>
113
+ <ol class="min">
114
+ <li><b>The FLOOR line on the price chart.</b> <span class="swatch"></span><code>#FF6A1A</code>, 2 px, a step line, labelled <code>FLOOR</code>, under the price.</li>
115
+ <li><b>The FLOOR price on the token page,</b> next to the price.</li>
116
+ </ol>
117
+ <h3>Bonus</h3>
118
+ <ul>
119
+ <li><code>% backed</code> (floor ÷ price)</li>
120
+ <li>A FLOOR column in lists and screeners</li>
121
+ <li>The FLOOR price in a wallet's holding row</li>
122
+ <li>An alert near the floor</li>
123
+ </ul>
124
+ <h3>Rules of thumb</h3>
125
+ <ul>
126
+ <li>No line before graduation. Never draw a missing floor as 0.</li>
127
+ <li>It only steps up, in the quote token.</li>
128
+ <li>Keep it after graduation: same program, same pair.</li>
129
+ <li>In market-cap mode, scale it by the same supply as the price.</li>
130
+ </ul>
131
+ <p>The full guide is <code>docs/floor-line.md</code>. Shipped it, or stuck? contact@floor.supply</p>
132
+ </aside>
133
+ </div>
134
+
135
+ <section class="panel code" aria-label="The code">
136
+ <h2>The code</h2>
137
+ <div class="tabs" role="tablist" id="tabs"></div>
138
+ <div class="codebox"><button type="button" class="copy" id="copy">Copy</button><pre id="code"></pre></div>
139
+ <p class="note" id="codenote"></p>
140
+ </section>
141
+
142
+ <footer id="run"></footer>
143
+ </main>
144
+
145
+ <script type="text/plain" id="c-api" data-label="Partner API" data-note="Server to server; ask for a key at contact@floor.supply. floorPriceQuote is null before graduation.">// 1. the FLOOR price for the token page
146
+ const H = { headers: { Authorization: `Bearer ${process.env.FLOOR_API_KEY}` } };
147
+ const API = "https://floor.supply/api/v1";
148
+
149
+ const { data: launch } = await (await fetch(`${API}/launches/${chain}/${token}`, H)).json();
150
+ const price = launch.market.priceQuote;
151
+ const floor = launch.market.floorPriceQuote; // null: no floor yet
152
+ const backed = launch.market.backedPct; // bonus: floor / price, in %
153
+
154
+ // 2. the history of the line: the floor after every trade
155
+ const { data: trades, meta } = await (await fetch(`${API}/launches/${chain}/${token}/trades?limit=100`, H)).json();
156
+ const floorPoints = trades
157
+ .filter((t) => t.floorPriceQuote !== null)
158
+ .map((t) => ({ time: t.time, value: t.floorPriceQuote }))
159
+ .reverse(); // oldest first
160
+ // older pages: ?before=${meta.nextBefore}</script>
161
+
162
+ <script type="text/plain" id="c-lwc" data-label="Lightweight Charts" data-note="lightweight-charts v5. LineType.WithSteps holds the floor between trades and steps it up at the trade that lifts it.">import { createChart, CandlestickSeries, LineSeries, LineType } from "lightweight-charts";
163
+
164
+ const chart = createChart(el, { autoSize: true });
165
+ const candles = chart.addSeries(CandlestickSeries);
166
+ const floorLine = chart.addSeries(LineSeries, {
167
+ color: "#FF6A1A",
168
+ lineWidth: 2,
169
+ lineType: LineType.WithSteps,
170
+ title: "FLOOR",
171
+ priceLineVisible: false,
172
+ lastValueVisible: true,
173
+ crosshairMarkerVisible: false,
174
+ autoscaleInfoProvider: () => null, // the floor never stretches the price scale
175
+ });
176
+
177
+ candles.setData(ohlc); // your candles
178
+ floorLine.setData(floorPoints); // [{ time, value }], none before graduation
179
+
180
+ // live, on each trade
181
+ if (trade.floorPriceQuote !== null) {
182
+ floorLine.update({ time: trade.time, value: trade.floorPriceQuote });
183
+ }</script>
184
+
185
+ <script type="text/plain" id="c-tv" data-label="TradingView" data-note="The Charting Library (Advanced Charts): a locked horizontal line at the current floor. For the full step history, plot the floor series as a custom indicator in the same style.">const chart = widget.activeChart();
186
+
187
+ const id = await chart.createShape(
188
+ { price: floor },
189
+ {
190
+ shape: "horizontal_line",
191
+ lock: true,
192
+ disableSelection: true,
193
+ disableSave: true,
194
+ text: "FLOOR",
195
+ overrides: {
196
+ linecolor: "#FF6A1A",
197
+ linewidth: 2,
198
+ showLabel: true,
199
+ textcolor: "#FF6A1A",
200
+ showPrice: true,
201
+ },
202
+ },
203
+ );
204
+
205
+ // when a trade lifts the floor
206
+ chart.getShapeById(id).setPoints([{ price: newFloor }]);</script>
207
+
208
+ <script type="text/plain" id="c-chain" data-label="From the chain" data-note="For indexers that read events themselves. sqrtF has 72 fraction bits; it is 0 before graduation. Keep the math in bigint: sqrtF squared does not fit in 128 bits.">// EVM: FloorAmm `Trade` event, field `sqrtF` (uint128)
209
+ // Solana: floor_amm `TradeV2` event (Anchor CPI event), field `sqrt_f` (u128)
210
+ //
211
+ // floor (whole quote per whole token) = sqrtF^2 * 10^6 / (2^144 * 10^quoteDecimals)
212
+
213
+ function floorOf(sqrtF, quoteDecimals) {
214
+ if (sqrtF === 0n) return null; // no floor yet
215
+ return Number((sqrtF * sqrtF * 10n ** 6n * 10n ** 12n) >> 144n) / 10 ** (quoteDecimals + 12);
216
+ }
217
+
218
+ // quoteDecimals: 6 for USDC, 9 for SOL, 18 for ETH
219
+ const floor = floorOf(BigInt(event.sqrtF), quoteDecimals);</script>
220
+
221
+ <script type="text/plain" id="c-svg" data-label="Plain SVG" data-note="What this page runs: walk the trades oldest first; hold the floor flat, then step up.">function floorPath(points, x, y) {
222
+ // points: [{ i, floor }] oldest first; floor null before graduation
223
+ let d = "", prev = null;
224
+ points.forEach((p, k) => {
225
+ if (p.floor === null) { prev = null; return; }
226
+ d += prev === null
227
+ ? `M${x(k)},${y(p.floor)}`
228
+ : `L${x(k)},${y(prev)}L${x(k)},${y(p.floor)}`;
229
+ prev = p.floor;
230
+ });
231
+ return d; // <path d=... stroke="#FF6A1A" stroke-width="2" fill="none">
232
+ }</script>
233
+
234
+ <script type="text/plain" id="c-stat" data-label="Token page" data-note="The FLOOR price next to the price. Before graduation: FLOOR with a dash, or leave it out.">&lt;div class="stat"&gt;
235
+ &lt;span class="label"&gt;FLOOR&lt;/span&gt;
236
+ &lt;span class="value" style="color:#FF6A1A"&gt;${fmt(floor)}&lt;/span&gt;
237
+ &lt;span class="note"&gt;${backed.toFixed(0)}% backed&lt;/span&gt; &lt;!-- bonus --&gt;
238
+ &lt;/div&gt;</script>
239
+
240
+ <script>
241
+ const DATA = /*DATA*/{"run":"A simulated launch with a USDC quote at $1: 74 buys and 8 sells","quoteDecimals":6,"series":[{"i":0,"price":0.01,"floor":null,"graduated":false,"side":"open"},{"i":1,"price":0.01,"floor":null,"graduated":false,"side":"buy"},{"i":2,"price":0.01,"floor":null,"graduated":false,"side":"buy"},{"i":3,"price":0.01,"floor":null,"graduated":false,"side":"buy"},{"i":4,"price":0.01,"floor":null,"graduated":false,"side":"buy"},{"i":5,"price":0.01,"floor":null,"graduated":false,"side":"buy"},{"i":6,"price":0.01,"floor":null,"graduated":false,"side":"buy"},{"i":7,"price":0.01,"floor":null,"graduated":false,"side":"buy"},{"i":8,"price":0.01,"floor":null,"graduated":false,"side":"buy"},{"i":9,"price":0.01,"floor":null,"graduated":false,"side":"buy"},{"i":10,"price":0.01,"floor":null,"graduated":false,"side":"buy"},{"i":11,"price":0.01,"floor":null,"graduated":false,"side":"buy"},{"i":12,"price":0.01,"floor":null,"graduated":false,"side":"buy"},{"i":13,"price":0.01022274,"floor":0.01,"graduated":true,"side":"buy"},{"i":14,"price":0.01045981,"floor":0.01,"graduated":true,"side":"buy"},{"i":15,"price":0.01069961,"floor":0.01,"graduated":true,"side":"buy"},{"i":16,"price":0.01092692,"floor":0.01,"graduated":true,"side":"buy"},{"i":17,"price":0.01110845,"floor":0.01,"graduated":true,"side":"buy"},{"i":18,"price":0.0112915,"floor":0.01,"graduated":true,"side":"buy"},{"i":19,"price":0.01147605,"floor":0.01,"graduated":true,"side":"buy"},{"i":20,"price":0.0116621,"floor":0.01,"graduated":true,"side":"buy"},{"i":21,"price":0.01184832,"floor":0.01,"graduated":true,"side":"buy"},{"i":22,"price":0.0119884,"floor":0.01,"graduated":true,"side":"buy"},{"i":23,"price":0.01212932,"floor":0.01,"graduated":true,"side":"buy"},{"i":24,"price":0.01227106,"floor":0.01,"graduated":true,"side":"buy"},{"i":25,"price":0.01284634,"floor":0.01,"graduated":true,"side":"buy"},{"i":26,"price":0.01329322,"floor":0.01,"graduated":true,"side":"buy"},{"i":27,"price":0.01373598,"floor":0.01030198,"graduated":true,"side":"buy"},{"i":28,"price":0.01414542,"floor":0.01060907,"graduated":true,"side":"buy"},{"i":29,"price":0.01448348,"floor":0.01086261,"graduated":true,"side":"buy"},{"i":30,"price":0.01482555,"floor":0.01111917,"graduated":true,"side":"buy"},{"i":31,"price":0.01517165,"floor":0.01137874,"graduated":true,"side":"buy"},{"i":32,"price":0.01545607,"floor":0.01159206,"graduated":true,"side":"buy"},{"i":33,"price":0.0157178,"floor":0.01178835,"graduated":true,"side":"buy"},{"i":34,"price":0.01598174,"floor":0.01198631,"graduated":true,"side":"buy"},{"i":35,"price":0.01624789,"floor":0.01218592,"graduated":true,"side":"buy"},{"i":36,"price":0.01651626,"floor":0.0123872,"graduated":true,"side":"buy"},{"i":37,"price":0.01674282,"floor":0.01255712,"graduated":true,"side":"buy"},{"i":38,"price":0.01694468,"floor":0.01270851,"graduated":true,"side":"buy"},{"i":39,"price":0.01714776,"floor":0.01286082,"graduated":true,"side":"buy"},{"i":40,"price":0.01735205,"floor":0.01301404,"graduated":true,"side":"buy"},{"i":41,"price":0.01755756,"floor":0.01316817,"graduated":true,"side":"buy"},{"i":42,"price":0.01776429,"floor":0.01332322,"graduated":true,"side":"buy"},{"i":43,"price":0.01797224,"floor":0.01347918,"graduated":true,"side":"buy"},{"i":44,"price":0.01815632,"floor":0.01361724,"graduated":true,"side":"buy"},{"i":45,"price":0.01831214,"floor":0.01373411,"graduated":true,"side":"buy"},{"i":46,"price":0.01846863,"floor":0.01385147,"graduated":true,"side":"buy"},{"i":47,"price":0.0186258,"floor":0.01396935,"graduated":true,"side":"buy"},{"i":48,"price":0.01878363,"floor":0.01408772,"graduated":true,"side":"buy"},{"i":49,"price":0.01859303,"floor":0.01408772,"graduated":true,"side":"sell"},{"i":50,"price":0.01841113,"floor":0.01408772,"graduated":true,"side":"sell"},{"i":51,"price":0.01823746,"floor":0.01408772,"graduated":true,"side":"sell"},{"i":52,"price":0.01806707,"floor":0.01408772,"graduated":true,"side":"sell"},{"i":53,"price":0.01853992,"floor":0.01408772,"graduated":true,"side":"buy"},{"i":54,"price":0.01901433,"floor":0.01426075,"graduated":true,"side":"buy"},{"i":55,"price":0.01949479,"floor":0.0146211,"graduated":true,"side":"buy"},{"i":56,"price":0.01990367,"floor":0.01492776,"graduated":true,"side":"buy"},{"i":57,"price":0.02026771,"floor":0.01520078,"graduated":true,"side":"buy"},{"i":58,"price":0.02063506,"floor":0.0154763,"graduated":true,"side":"buy"},{"i":59,"price":0.02100574,"floor":0.0157543,"graduated":true,"side":"buy"},{"i":60,"price":0.02137974,"floor":0.0160348,"graduated":true,"side":"buy"},{"i":61,"price":0.02166974,"floor":0.01625231,"graduated":true,"side":"buy"},{"i":62,"price":0.02195119,"floor":0.01646339,"graduated":true,"side":"buy"},{"i":63,"price":0.02223446,"floor":0.01667585,"graduated":true,"side":"buy"},{"i":64,"price":0.02251957,"floor":0.01688968,"graduated":true,"side":"buy"},{"i":65,"price":0.0228065,"floor":0.01710487,"graduated":true,"side":"buy"},{"i":66,"price":0.02309526,"floor":0.01732144,"graduated":true,"side":"buy"},{"i":67,"price":0.02336672,"floor":0.01752504,"graduated":true,"side":"buy"},{"i":68,"price":0.02358335,"floor":0.01768751,"graduated":true,"side":"buy"},{"i":69,"price":0.02346715,"floor":0.01768751,"graduated":true,"side":"sell"},{"i":70,"price":0.02335372,"floor":0.01768751,"graduated":true,"side":"sell"},{"i":71,"price":0.02321907,"floor":0.01768751,"graduated":true,"side":"sell"},{"i":72,"price":0.02307369,"floor":0.01768751,"graduated":true,"side":"sell"},{"i":73,"price":0.02335063,"floor":0.01768751,"graduated":true,"side":"buy"},{"i":74,"price":0.02356718,"floor":0.01768751,"graduated":true,"side":"buy"},{"i":75,"price":0.02378474,"floor":0.01783855,"graduated":true,"side":"buy"},{"i":76,"price":0.02400331,"floor":0.01800248,"graduated":true,"side":"buy"},{"i":77,"price":0.02422288,"floor":0.01816716,"graduated":true,"side":"buy"},{"i":78,"price":0.02444346,"floor":0.0183326,"graduated":true,"side":"buy"},{"i":79,"price":0.02466505,"floor":0.01849879,"graduated":true,"side":"buy"},{"i":80,"price":0.02488764,"floor":0.01866573,"graduated":true,"side":"buy"},{"i":81,"price":0.02511124,"floor":0.01883343,"graduated":true,"side":"buy"},{"i":82,"price":0.02533585,"floor":0.01900189,"graduated":true,"side":"buy"}]}/*END*/;
242
+ const SUPPLY = 1e9; // a FLOOR launch mints 1B tokens; market cap = price x total supply
243
+ const pts = DATA.series;
244
+
245
+ /* ---------- the candles: three trades to a candle ---------- */
246
+ const PER = 3;
247
+ function candlesUpTo(n) {
248
+ const out = [];
249
+ for (let s = 1; s <= n; s += PER) {
250
+ const e = Math.min(s + PER - 1, n);
251
+ const seg = pts.slice(s, e + 1);
252
+ const open = pts[s - 1].price, close = seg[seg.length - 1].price;
253
+ const hi = Math.max(open, ...seg.map((p) => p.price)), lo = Math.min(open, ...seg.map((p) => p.price));
254
+ const fl = seg[seg.length - 1].floor;
255
+ out.push({ s, e, open, close, hi, lo, floor: fl });
256
+ }
257
+ return out;
258
+ }
259
+
260
+ /* ---------- drawing ---------- */
261
+ const W = 760, H = 380, L = 8, R = 78, T = 34, B = 26;
262
+ const NS = "http://www.w3.org/2000/svg";
263
+ const svg = document.getElementById("chart");
264
+ const el = (tag, attrs, text, parent = svg) => { const e = document.createElementNS(NS, tag); for (const k in attrs) e.setAttribute(k, attrs[k]); if (text != null) e.textContent = text; parent.appendChild(e); return e; };
265
+ let mode = "price";
266
+ const unit = (v) => (mode === "mcap" ? v * SUPPLY : v);
267
+ const fmtP = (v) => (v >= 1000 ? "$" + (v >= 1e6 ? (v / 1e6).toFixed(2) + "M" : (v / 1e3).toFixed(1) + "K") : "$" + v.toPrecision(4));
268
+
269
+ function floorPath(points, x, y) {
270
+ let d = "", prev = null;
271
+ points.forEach((p, k) => {
272
+ if (p.floor === null) { prev = null; return; }
273
+ d += prev === null ? `M${x(k)},${y(p.floor)}` : `L${x(k)},${y(prev)}L${x(k)},${y(p.floor)}`;
274
+ prev = p.floor;
275
+ });
276
+ return d;
277
+ }
278
+
279
+ function draw(n) {
280
+ svg.textContent = "";
281
+ const cs = candlesUpTo(Math.max(n, 1));
282
+ const all = candlesUpTo(pts.length - 1);
283
+ const slots = all.length;
284
+ const cw = (W - L - R) / slots;
285
+ const xs = (k) => L + cw * (k + 0.5);
286
+ // the scale follows the candles only; the floor never stretches it
287
+ const lo = Math.min(...all.map((c) => c.lo)), hi = Math.max(...all.map((c) => c.hi));
288
+ const pad = (hi - lo) * 0.12;
289
+ const min = unit(lo - pad * 3), max = unit(hi + pad);
290
+ const y = (v) => T + (1 - (unit(v) - min) / (max - min)) * (H - T - B);
291
+
292
+ // grid and axis
293
+ for (let k = 0; k <= 4; k++) {
294
+ const v = min + ((max - min) * k) / 4;
295
+ const yy = T + (1 - k / 4) * (H - T - B);
296
+ el("line", { x1: L, x2: W - R, y1: yy, y2: yy, stroke: "#1B1E22" });
297
+ el("text", { x: W - R + 8, y: yy + 4, fill: "#8A94A3", "font-size": 11 }, fmtP(v));
298
+ }
299
+
300
+ // Bonding: the flat opening window, no floor yet
301
+ const gradK = all.findIndex((c) => c.floor !== null);
302
+ if (gradK > 0) {
303
+ el("rect", { x: L, y: T, width: cw * gradK, height: H - T - B, fill: "#16181B" });
304
+ el("text", { x: L + 8, y: H - B - 8, fill: "#8A94A3", "font-size": 11 }, "Bonding: no floor yet");
305
+ el("line", { x1: L + cw * gradK, x2: L + cw * gradK, y1: T, y2: H - B, stroke: "#FF6A1A", "stroke-opacity": 0.35, "stroke-dasharray": "3 4" });
306
+ el("text", { x: L + cw * gradK + 6, y: T + 12, fill: "#FF6A1A", "font-size": 11, "fill-opacity": 0.8 }, "Graduated: the floor starts");
307
+ }
308
+
309
+ // candles
310
+ cs.forEach((c, k) => {
311
+ const up = c.close >= c.open, col = up ? "#2EBD85" : "#F6465D";
312
+ el("line", { x1: xs(k), x2: xs(k), y1: y(c.hi), y2: y(c.lo), stroke: col });
313
+ const top = y(Math.max(c.open, c.close)), bot = y(Math.min(c.open, c.close));
314
+ el("rect", { x: xs(k) - cw * 0.32, width: cw * 0.64, y: top, height: Math.max(1, bot - top), fill: col });
315
+ });
316
+
317
+ // the FLOOR line: a step line under the price
318
+ const fp = cs.map((c) => ({ floor: c.floor }));
319
+ const d = floorPath(fp, (k) => L + cw * k, y);
320
+ const lastC = cs[cs.length - 1];
321
+ if (d) {
322
+ const path = el("path", { d: d + (lastC.floor !== null ? `L${L + cw * cs.length},${y(lastC.floor)}` : ""), fill: "none", stroke: "#FF6A1A", "stroke-width": 2 });
323
+ // the inline tag and the axis value
324
+ const fy = y(lastC.floor);
325
+ const ex = L + cw * cs.length;
326
+ el("rect", { x: ex - 52, y: fy - 9, width: 46, height: 16, fill: "#000" });
327
+ el("text", { x: ex - 29, y: fy + 4, fill: "#FF6A1A", "font-size": 11, "font-weight": 700, "text-anchor": "middle" }, "FLOOR");
328
+ el("rect", { x: W - R + 2, y: fy - 9, width: R - 4, height: 18, rx: 3, fill: "#FF6A1A" });
329
+ el("text", { x: W - R + 8, y: fy + 4, fill: "#000", "font-size": 11, "font-weight": 700 }, fmtP(unit(lastC.floor)));
330
+ }
331
+ // the last price on the axis
332
+ const py = y(lastC.close);
333
+ el("rect", { x: W - R + 2, y: py - 9, width: R - 4, height: 18, rx: 3, fill: "#8EA0BC" });
334
+ el("text", { x: W - R + 8, y: py + 4, fill: "#000", "font-size": 11, "font-weight": 700 }, fmtP(unit(lastC.close)));
335
+ // the ask marker
336
+ el("text", { x: L + 8, y: 18, fill: "#FF6A1A", "font-size": 11, "font-weight": 700 }, "ASKED: the FLOOR line");
337
+ }
338
+
339
+ /* ---------- the stats and the readout ---------- */
340
+ const $ = (id) => document.getElementById(id);
341
+ function show() {
342
+ const n = +at.value, p = pts[n];
343
+ draw(n);
344
+ $("sPrice").textContent = fmtP(p.price);
345
+ $("sFloor").textContent = p.floor === null ? "—" : fmtP(p.floor);
346
+ $("sBacked").textContent = p.floor === null ? "—" : Math.round((100 * p.floor) / p.price) + "%";
347
+ $("sMcap").textContent = fmtP(p.price * SUPPLY);
348
+ const ph = $("phase");
349
+ ph.textContent = p.graduated ? "Graduated" : "Bonding";
350
+ ph.className = "pill" + (p.graduated ? " grad" : "");
351
+ let why = "";
352
+ if (p.floor === null) why = "Bonding sells at one flat price, so there is no floor and no line yet.";
353
+ else if (p.side === "sell") why = "A sell: the price comes down, the floor holds.";
354
+ else if (n > 0 && pts[n - 1].floor !== null && p.floor > pts[n - 1].floor) why = "A buy: part of its money joins the floor, which steps up.";
355
+ else why = "A buy: the floor holds until enough money has joined it to step up.";
356
+ $("read").innerHTML = `Trade ${n} of ${pts.length - 1} (${p.side}): price <b>${p.price}</b>` + (p.floor === null ? "" : `, FLOOR <b>${p.floor}</b>`) + ` USDC. ${why}`;
357
+ }
358
+ const at = $("at");
359
+ at.max = pts.length - 1; at.value = pts.length - 1;
360
+ at.addEventListener("input", show);
361
+ document.querySelectorAll(".seg button").forEach((b) => b.addEventListener("click", () => {
362
+ mode = b.dataset.mode;
363
+ document.querySelectorAll(".seg button").forEach((x) => x.setAttribute("aria-pressed", String(x === b)));
364
+ show();
365
+ }));
366
+ let timer = null;
367
+ $("play").addEventListener("click", () => {
368
+ if (timer) { clearInterval(timer); timer = null; $("play").textContent = "Replay"; return; }
369
+ at.value = 0; $("play").textContent = "Stop";
370
+ timer = setInterval(() => {
371
+ if (+at.value >= pts.length - 1) { clearInterval(timer); timer = null; $("play").textContent = "Replay"; return; }
372
+ at.value = +at.value + 1; show();
373
+ }, 90);
374
+ });
375
+ show();
376
+
377
+ /* ---------- the code tabs ---------- */
378
+ const blocks = [...document.querySelectorAll('script[type="text/plain"]')];
379
+ const tabs = $("tabs");
380
+ function pick(b) {
381
+ [...tabs.children].forEach((t) => t.setAttribute("aria-selected", String(t.dataset.id === b.id)));
382
+ const tmp = document.createElement("textarea"); tmp.innerHTML = b.textContent; // decode the HTML tab's entities
383
+ $("code").textContent = tmp.value.trim();
384
+ $("codenote").textContent = b.dataset.note;
385
+ }
386
+ blocks.forEach((b, i) => {
387
+ const t = document.createElement("button");
388
+ t.type = "button"; t.role = "tab"; t.dataset.id = b.id; t.textContent = b.dataset.label;
389
+ t.addEventListener("click", () => pick(b));
390
+ tabs.appendChild(t);
391
+ if (i === 0) pick(b);
392
+ });
393
+ $("copy").addEventListener("click", async () => {
394
+ try { await navigator.clipboard.writeText($("code").textContent); $("copy").textContent = "Copied"; } catch { $("copy").textContent = "Select and copy"; }
395
+ setTimeout(() => ($("copy").textContent = "Copy"), 1500);
396
+ });
397
+
398
+ $("run").textContent = DATA.run + ". The numbers come from the SDK's own math on a simulated launch, not from a live token.";
399
+ </script>
400
+ </body>
401
+ </html>
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@floorlaunchpad/sdk",
3
- "version": "0.3.0",
3
+ "version": "0.3.2",
4
4
  "description": "The FLOOR Program in TypeScript: the math, the quoter, decoders, PDAs and instruction builders for Solana and EVM",
5
5
  "license": "Apache-2.0",
6
6
  "type": "module",
@@ -12,6 +12,7 @@
12
12
  "dist",
13
13
  "src/**/*.ts",
14
14
  "docs",
15
+ "examples",
15
16
  "CHANGELOG.md"
16
17
  ],
17
18
  "exports": {
@@ -54,6 +54,8 @@ export const SOLANA_EVENT_SCHEMAS: readonly SolanaEventSchema[] = [
54
54
  { name: "GenesisListRootSet", discriminator: "85037264ea1a3265", source: "v1", fields: [["signer","pubkey"],["oldRoot","bytes:32"],["newRoot","bytes:32"]] },
55
55
  { name: "BurnsSynced", discriminator: "cfb2d288fed64590", source: "v1", fields: [["launch","pubkey"],["incinerated","u64"],["supply","u64"],["sOut","u64"],["floorAfterX64","u128"],["slot","u64"]] },
56
56
  { name: "TokensBurned", discriminator: "e6ff2271e235e309", source: "v1", fields: [["launch","pubkey"],["wallet","pubkey"],["role","u8"],["place","u8"],["fromTeamBuy","u64"],["fromWallet","u64"],["balanceBefore","u64"],["owedAfter","u64"],["split","u64[10]"],["supply","u64"],["sOut","u64"],["floorAfterX64","u128"],["slot","u64"],["fromShareBought","u64?"]] },
57
+ { name: "GenesisPublicStarted", discriminator: "0f963d81be5c82af", source: "v1", fields: [["signer","pubkey"],["at","i64"]] },
58
+ { name: "GenesisEndSet", discriminator: "2fc250f230dedba2", source: "v1", fields: [["signer","pubkey"],["oldEndsAt","i64"],["newEndsAt","i64"]] },
57
59
  { name: "LaunchCreatedV2", discriminator: "4c0e9eb9ef6b568e", source: "v2", fields: [["launch","pubkey"],["mint","pubkey"],["quoteMint","pubkey"],["creator","pubkey"],["id","u64"],["presetId","u8"],["presetVersion","u32"],["presetHash","bytes:32"],["p0X64","u128"],["raise","u64"],["windowTokens","u64"],["creatorBuyTokens","u64"],["createFee","u64"],["name","bytes:32"],["symbol","bytes:10"],["slot","u64"],["ts","i64"],["listed","bool"],["quoteUsdCentsX64","u128"],["nativeCreateFee","u64"],["rowVersion","u8"],["sqrtP0","u128"]] },
58
60
  { name: "Trade", discriminator: "18feda98fd2b1251", source: "v2", fields: [["launch","pubkey"],["trader","pubkey"],["isBuy","bool"],["quoteGross","u64"],["quoteNet","u64"],["refund","u64"],["tokens","u64"],["fees","u64[5]"],["traderRef","u64"],["fromResale","u64"],["fromFirst","u64"],["unfilled","u64"],["sqrtBefore","u128"],["sqrtAfter","u128"],["sqrtF","u128"],["floor","u64"],["cushion","u64"],["sCirc","u64"],["steps","u8"],["budgetHit","bool"],["slot","u64"],["ts","i64"],["kind","u8"],["creatorRef","u64"],["recipient","pubkey"],["bidMoney","u64"],["msPaid","u64[4]"]] },
59
61
  { name: "HolderPositionOpened", discriminator: "86a0f22128a8ddac", source: "v2", fields: [["launch","pubkey"],["owner","pubkey"],["amount","u64"]] },