@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
@@ -3,102 +3,399 @@
3
3
  <head>
4
4
  <meta charset="utf-8">
5
5
  <meta name="viewport" content="width=device-width, initial-scale=1">
6
- <title>FLOOR line example</title>
6
+ <title>Show the FLOOR</title>
7
7
  <style>
8
- :root { --bg:#000000; --panel:#101113; --text:#F4F5F7; --muted:#9AA3B2; --price:#8EA0BC; --floor:#FF6A1A; --grid:#23262B; }
9
- * { box-sizing: border-box; }
10
- body { margin:0; background:var(--bg); color:var(--text); font:15px/1.5 system-ui, sans-serif; }
11
- main { max-width:1100px; margin:0 auto; padding:24px 16px 48px; }
12
- h1 { font-size:20px; margin:0 0 4px; }
13
- p.run { margin:0 0 16px; color:var(--muted); }
14
- .grid { display:grid; grid-template-columns:minmax(0,3fr) minmax(0,2fr); gap:16px; }
15
- @media (max-width:800px) { .grid { grid-template-columns:minmax(0,1fr); } }
16
- .panel { background:var(--panel); border-radius:8px; padding:16px; min-width:0; }
17
- .legend { display:flex; gap:16px; margin-bottom:8px; flex-wrap:wrap; }
18
- .legend span::before { content:""; display:inline-block; width:18px; height:3px; margin-right:6px; vertical-align:middle; background:currentColor; }
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; }
19
45
  .legend .p { color:var(--price); } .legend .f { color:var(--floor); }
46
+ .chartwrap { position:relative; }
20
47
  svg { width:100%; height:auto; display:block; }
21
- pre { margin:0; overflow:auto; font:13px/1.5 ui-monospace, Menlo, monospace; white-space:pre; }
22
- h2 { font-size:15px; margin:0 0 8px; }
23
- .read { margin-top:8px; color:var(--muted); min-height:1.5em; }
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; }
24
53
  .read b { color:var(--text); font-weight:600; }
25
- input[type=range] { width:100%; }
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; }
26
74
  </style>
27
75
  </head>
28
76
  <body>
29
77
  <main>
30
- <h1>Drawing the floor line</h1>
31
- <p class="run" id="run"></p>
32
- <div class="grid">
33
- <div class="panel">
34
- <div class="legend"><span class="p">Price</span><span class="f">FLOOR</span></div>
35
- <svg id="chart" viewBox="0 0 640 360" role="img" aria-label="Price and floor line over the run"></svg>
36
- <input id="at" type="range" min="0" value="0" aria-label="Move through the run">
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">Max Loss</div><div class="v" id="sMaxLoss">–</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>
37
108
  <div class="read" id="read"></div>
38
- </div>
39
- <div class="panel">
40
- <h2>The code that draws it</h2>
41
- <pre>// one fetch gives price and floor together
42
- const s = await (await fetch(
43
- `${API}/v2/dex/summary?id=${pair}`)).json();
44
- const price = Number(s.priceNative);
45
- const floor = Number(s.floorPriceNative);
46
-
47
- // hide the floor until the launch has one,
48
- // and when every token has been burned
49
- const hasFloor = floor &gt; 0 &amp;&amp;
50
- Number(s.circulatingSupply) &gt; 0;
51
-
52
- priceLine.push({ time, value: price });
53
- if (hasFloor) {
54
- floorLine.push({ time, value: floor });
55
- }
56
- // draw floorLine under priceLine:
57
- // colour #FF6A1A, label "FLOOR"</pre>
58
- </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>Max Loss</code> (1 − floor ÷ price, before fees)</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>
59
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>
60
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 maxLoss = launch.market.maxLossPct; // bonus: 1 − floor / price, in %, before fees
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;Max Loss ${maxLoss.toFixed(0)}%&lt;/span&gt; &lt;!-- bonus --&gt;
238
+ &lt;/div&gt;</script>
239
+
61
240
  <script>
62
- const DATA = /*DATA*/{"run":"A simulated launch with a USDC quote at $1: 64 buys, then 6 small 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.01926116,"floor":0.01444587,"graduated":true,"side":"buy"},{"i":50,"price":0.01972843,"floor":0.01479632,"graduated":true,"side":"buy"},{"i":51,"price":0.02009085,"floor":0.01506814,"graduated":true,"side":"buy"},{"i":52,"price":0.0204566,"floor":0.01534245,"graduated":true,"side":"buy"},{"i":53,"price":0.02082566,"floor":0.01561925,"graduated":true,"side":"buy"},{"i":54,"price":0.02119805,"floor":0.01589854,"graduated":true,"side":"buy"},{"i":55,"price":0.02153399,"floor":0.01615049,"graduated":true,"side":"buy"},{"i":56,"price":0.02181455,"floor":0.01636091,"graduated":true,"side":"buy"},{"i":57,"price":0.02209694,"floor":0.0165727,"graduated":true,"side":"buy"},{"i":58,"price":0.02238115,"floor":0.01678586,"graduated":true,"side":"buy"},{"i":59,"price":0.0226672,"floor":0.0170004,"graduated":true,"side":"buy"},{"i":60,"price":0.02295507,"floor":0.0172163,"graduated":true,"side":"buy"},{"i":61,"price":0.02324477,"floor":0.01743358,"graduated":true,"side":"buy"},{"i":62,"price":0.02347823,"floor":0.01760867,"graduated":true,"side":"buy"},{"i":63,"price":0.02369538,"floor":0.01777153,"graduated":true,"side":"buy"},{"i":64,"price":0.02391353,"floor":0.01793515,"graduated":true,"side":"buy"},{"i":65,"price":0.02389484,"floor":0.01793515,"graduated":true,"side":"sell"},{"i":66,"price":0.02387622,"floor":0.01793515,"graduated":true,"side":"sell"},{"i":67,"price":0.02385767,"floor":0.01793515,"graduated":true,"side":"sell"},{"i":68,"price":0.02383919,"floor":0.01793515,"graduated":true,"side":"sell"},{"i":69,"price":0.02382078,"floor":0.01793515,"graduated":true,"side":"sell"},{"i":70,"price":0.02380243,"floor":0.01793515,"graduated":true,"side":"sell"}]}/*END*/;
63
- const W = 640, H = 360, L = 52, R = 12, T = 12, B = 28;
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.01000702,"graduated":true,"side":"buy"},{"i":15,"price":0.01069961,"floor":0.01001356,"graduated":true,"side":"buy"},{"i":16,"price":0.01092692,"floor":0.01001968,"graduated":true,"side":"buy"},{"i":17,"price":0.01110845,"floor":0.01002545,"graduated":true,"side":"buy"},{"i":18,"price":0.0112915,"floor":0.0100309,"graduated":true,"side":"buy"},{"i":19,"price":0.01147605,"floor":0.01003607,"graduated":true,"side":"buy"},{"i":20,"price":0.0116621,"floor":0.01004098,"graduated":true,"side":"buy"},{"i":21,"price":0.01184832,"floor":0.01004568,"graduated":true,"side":"buy"},{"i":22,"price":0.0119884,"floor":0.01005016,"graduated":true,"side":"buy"},{"i":23,"price":0.01212932,"floor":0.01005447,"graduated":true,"side":"buy"},{"i":24,"price":0.01227106,"floor":0.0100586,"graduated":true,"side":"buy"},{"i":25,"price":0.01284634,"floor":0.01007293,"graduated":true,"side":"buy"},{"i":26,"price":0.01329322,"floor":0.01008562,"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
64
243
  const pts = DATA.series;
65
- const max = Math.max(...pts.map((p) => p.price)) * 1.05;
66
- const min = Math.min(...pts.map((p) => p.floor ?? p.price)) * 0.95;
67
- const x = (i) => L + (i / (pts.length - 1)) * (W - L - R);
68
- const y = (v) => T + (1 - (v - min) / (max - min)) * (H - T - B);
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;
69
262
  const NS = "http://www.w3.org/2000/svg";
70
263
  const svg = document.getElementById("chart");
71
- const el = (tag, attrs, text) => { const e = document.createElementNS(NS, tag); for (const k in attrs) e.setAttribute(k, attrs[k]); if (text) e.textContent = text; svg.appendChild(e); return e; };
72
- document.getElementById("run").textContent = DATA.run + ". The numbers come from the SDK's own math, not from a live pool.";
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));
73
268
 
74
- for (let k = 0; k <= 4; k++) {
75
- const v = min + ((max - min) * k) / 4;
76
- el("line", { x1: L, x2: W - R, y1: y(v), y2: y(v), stroke: "#23262B" });
77
- el("text", { x: L - 6, y: y(v) + 4, "text-anchor": "end", fill: "#9AA3B2", "font-size": 11 }, v.toFixed(4));
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;
78
277
  }
79
- el("text", { x: L, y: H - 6, fill: "#9AA3B2", "font-size": 11 }, "trades, in order");
80
- // the price line, then the floor line under it (a step line: it holds between trades)
81
- const priceD = pts.map((p, i) => `${i ? "L" : "M"}${x(i)},${y(p.price)}`).join("");
82
- let floorD = "", pen = false, prev = null;
83
- pts.forEach((p, i) => {
84
- if (p.floor === null) { pen = false; return; }
85
- floorD += pen ? `L${x(i)},${y(prev)}L${x(i)},${y(p.floor)}` : `M${x(i)},${y(p.floor)}`;
86
- pen = true; prev = p.floor;
87
- });
88
- el("path", { d: priceD, fill: "none", stroke: "#8EA0BC", "stroke-width": 2 });
89
- el("path", { d: floorD, fill: "none", stroke: "#FF6A1A", "stroke-width": 2 });
90
- const last = pts[pts.length - 1];
91
- el("text", { x: W - R - 4, y: y(last.floor) + 16, "text-anchor": "end", fill: "#FF6A1A", "font-size": 12 }, "FLOOR");
92
- const mark = el("line", { y1: T, y2: H - B, stroke: "#F4F5F7", "stroke-opacity": 0.4 });
93
278
 
94
- const at = document.getElementById("at"), read = document.getElementById("read");
95
- at.max = pts.length - 1; at.value = pts.length - 1;
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);
96
341
  function show() {
97
- const p = pts[+at.value];
98
- mark.setAttribute("x1", x(+at.value)); mark.setAttribute("x2", x(+at.value));
99
- read.innerHTML = `Trade ${p.i} (${p.side}): price <b>${p.price}</b>, ` + (p.floor === null ? "no floor yet (the launch has not graduated)" : `floor <b>${p.floor}</b>, ${(100 * p.floor / p.price).toFixed(1)}% of the price`) + ", in USDC per token.";
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
+ $("sMaxLoss").textContent = p.floor === null ? "—" : Math.round(100 - (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}`;
100
357
  }
101
- at.addEventListener("input", show); show();
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.";
102
399
  </script>
103
400
  </body>
104
401
  </html>
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@floorlaunchpad/sdk",
3
- "version": "0.3.1",
3
+ "version": "0.4.0",
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",
@@ -17,7 +17,7 @@ export const EVM_EVENT_SCHEMAS: readonly EvmEventSchema[] = [
17
17
  { name: "TokensBurnedV2", signature: "TokensBurnedV2(uint256,address,uint8,uint8,uint256,uint256,uint256,uint256,uint256[10],uint256,uint256,uint256,uint256)", topic: "0xf6e435381411d86653aa1fb249000f3ead53faa462387a4492da7021bb1ed930", params: [{"name":"launchId","type":"uint256","indexed":true},{"name":"wallet","type":"address","indexed":true},{"name":"role","type":"uint8","indexed":false},{"name":"place","type":"uint8","indexed":false},{"name":"fromTeamBuy","type":"uint256","indexed":false},{"name":"fromWallet","type":"uint256","indexed":false},{"name":"balanceBefore","type":"uint256","indexed":false},{"name":"owedAfter","type":"uint256","indexed":false},{"name":"split","type":"uint256[10]","indexed":false},{"name":"supply","type":"uint256","indexed":false},{"name":"sOut","type":"uint256","indexed":false},{"name":"floorAfterX64","type":"uint256","indexed":false},{"name":"fromShareBought","type":"uint256","indexed":false}] },
18
18
  { name: "OptedIn", signature: "OptedIn(address)", topic: "0x25f9c685db8e2630204f5e7c890a95f58852ccac883a9d96f44a72b777b06c59", params: [{"name":"a","type":"address","indexed":true}] },
19
19
  { name: "ClaimSkipped", signature: "ClaimSkipped(address,address,uint256)", topic: "0x4db58311c6a38618cc6dd27586cfb08657be781d572fb89d63886e3a04b654fa", params: [{"name":"wallet","type":"address","indexed":true},{"name":"quote","type":"address","indexed":true},{"name":"amount","type":"uint256","indexed":false}] },
20
- { name: "Claimed", signature: "Claimed(address,address,address,uint8,uint256,uint256,uint256,uint256,uint256,uint256,uint256)", topic: "0x586c69c7198e9e5c48c058d0267bd1388a73f9a8878aeb9d72d25331acc39aeb", params: [{"name":"wallet","type":"address","indexed":true},{"name":"sender","type":"address","indexed":true},{"name":"quote","type":"address","indexed":true},{"name":"types","type":"uint8","indexed":false},{"name":"creator","type":"uint256","indexed":false},{"name":"creatorRef","type":"uint256","indexed":false},{"name":"teamSlot","type":"uint256","indexed":false},{"name":"traderRef","type":"uint256","indexed":false},{"name":"holder","type":"uint256","indexed":false},{"name":"extra","type":"uint256","indexed":false},{"name":"amount","type":"uint256","indexed":false}] },
20
+ { name: "Claimed", signature: "Claimed(address,address,address,uint16,uint256,uint256,uint256,uint256,uint256,uint256,uint256)", topic: "0xc65b75258efd65cacbab47f067226591f78c24d2ee3c3deedf737ca24dc84ada", params: [{"name":"wallet","type":"address","indexed":true},{"name":"sender","type":"address","indexed":true},{"name":"quote","type":"address","indexed":true},{"name":"types","type":"uint16","indexed":false},{"name":"creator","type":"uint256","indexed":false},{"name":"creatorRef","type":"uint256","indexed":false},{"name":"teamSlot","type":"uint256","indexed":false},{"name":"traderRef","type":"uint256","indexed":false},{"name":"holder","type":"uint256","indexed":false},{"name":"extra","type":"uint256","indexed":false},{"name":"amount","type":"uint256","indexed":false}] },
21
21
  { name: "ConfigWritten", signature: "ConfigWritten(address,address,address,address,bool,address)", topic: "0x8f06444aa7d0507d408688b0ec6fc465e012cf24967de8b2205cfd16fcb4566d", params: [{"name":"authority","type":"address","indexed":false},{"name":"pendingAuthority","type":"address","indexed":false},{"name":"timelock","type":"address","indexed":false},{"name":"referralAuthority","type":"address","indexed":false},{"name":"createPaused","type":"bool","indexed":false},{"name":"holderDest","type":"address","indexed":false}] },
22
22
  { name: "CreatorBuyUnlocked", signature: "CreatorBuyUnlocked(uint256,address,uint256,uint256[10],uint256)", topic: "0x39c11edf00e81e75225d0fc2b6f83cabd8ba915d7a071fa450cfb032204eb0f4", params: [{"name":"launchId","type":"uint256","indexed":true},{"name":"creator","type":"address","indexed":true},{"name":"tokens","type":"uint256","indexed":false},{"name":"members","type":"uint256[10]","indexed":false},{"name":"paid","type":"uint256","indexed":false}] },
23
23
  { name: "Graduated", signature: "Graduated(uint256,uint256,uint256,uint256,uint256)", topic: "0x0ba53bc3beab16da02bf51a54e938fd7c98b7838adc8b1368fc596f9cc85ec5b", params: [{"name":"launchId","type":"uint256","indexed":true},{"name":"windowPriceX64","type":"uint256","indexed":false},{"name":"priceX64","type":"uint256","indexed":false},{"name":"windowRaised","type":"uint256","indexed":false},{"name":"windowTokens","type":"uint256","indexed":false}] },
@@ -12,7 +12,7 @@ export interface SolanaEventSchema {
12
12
 
13
13
  export const SOLANA_EVENT_SCHEMAS: readonly SolanaEventSchema[] = [
14
14
  { name: "LaunchCreated", discriminator: "3b26bee621225914", source: "v1", 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"]] },
15
- { name: "Graduated", discriminator: "33f142328cf59cc0", source: "v1", fields: [["launch","pubkey"],["priceX64","u128"],["windowRaised","u64"],["windowTokens","u64"],["slot","u64"],["ts","i64"]] },
15
+ { name: "Graduated", discriminator: "33f142328cf59cc0", source: "v1", fields: [["launch","pubkey"],["windowPriceX64","u128"],["windowRaised","u64"],["windowTokens","u64"],["slot","u64"],["ts","i64"],["priceX64","u128"]] },
16
16
  { name: "PotsSwept", discriminator: "33480c25b092b903", source: "v1", fields: [["launch","pubkey"],["amount","u64"],["reason","u8"]] },
17
17
  { name: "Claimed", discriminator: "d9c07b486c96f821", source: "v1", fields: [["wallet","pubkey"],["sender","pubkey"],["launch","pubkey"],["quoteMint","pubkey"],["types","u8"],["creator","u64"],["creatorRef","u64"],["teamSlot","u64"],["traderRef","u64"],["extra","u64"],["amount","u64"],["teamBuy","u64?"],["shareBought","u64?"],["typesHi","u8?"]] },
18
18
  { name: "TeamShareBought", discriminator: "40e04bbcf76ac766", source: "v1", fields: [["launch","pubkey"],["member","pubkey"],["place","u8"],["spent","u64"],["refund","u64"],["tokens","u64"],["shareLeft","u64"],["boughtOwed","u64"],["day","u64"],["firstToday","bool"],["ts","i64"]] },
@@ -80,6 +80,20 @@ export function createEvmClient(opts: FloorClientOptions<"evm">): EvmFloorClient
80
80
  throw decodeEvmProgramError(e) ?? new FloorError("Transport", `eth_call to ${c.to} failed`, { source: "sdk", cause: e });
81
81
  }
82
82
  };
83
+
84
+ const approvals = async (token: string, owner: string, amount: bigint): Promise<EvmCall[]> => {
85
+ let have: bigint | null = null;
86
+ try {
87
+ const pad = (a: string): string => a.toLowerCase().replace(/^0x/, "").padStart(64, "0");
88
+ const out = await transport.rpc.call({ to: token, data: `0xdd62ed3e${pad(owner)}${pad(floorAmm)}` } as EvmCall);
89
+ if (typeof out === "string" && /^0x[0-9a-fA-F]{64}$/.test(out)) have = BigInt(out);
90
+ } catch {
91
+ have = null;
92
+ }
93
+ if (have !== null && have >= amount) return [];
94
+ if (have !== null && have > 0n) return [approveCall(token, floorAmm, 0n), approveCall(token, floorAmm, amount)];
95
+ return [approveCall(token, floorAmm, amount)];
96
+ };
83
97
  const tx = (calls: EvmCall[]): EvmTx => ({ family: "evm", chainId, calls });
84
98
  const launchIdOf = (launch: bigint): bigint => {
85
99
  if (typeof launch !== "bigint" || launch <= 0n) throw bad("launch: an EVM launch is its launchId, a bigint > 0");
@@ -167,14 +181,14 @@ export function createEvmClient(opts: FloorClientOptions<"evm">): EvmFloorClient
167
181
  const launchId = launchIdOf(p.launch);
168
182
  const { quote } = await launchState(launchId);
169
183
  const buy = buyCall({ floorAmm, quote, launchId, amountIn: p.amountIn, minTokensOut: p.minOut, to: p.recipient ?? p.trader, ...(p.deadline !== undefined ? { deadline: p.deadline } : {}) });
170
- return tx(quote.toLowerCase() === NATIVE_QUOTE ? [buy] : [approveCall(quote, floorAmm, p.amountIn), buy]);
184
+ return tx(quote.toLowerCase() === NATIVE_QUOTE ? [buy] : [...(await approvals(quote, p.trader, p.amountIn)), buy]);
171
185
  }),
172
186
 
173
187
  buildSell: (p) => guard(async () => {
174
188
  const launchId = launchIdOf(p.launch);
175
189
  const sell = sellCall({ floorAmm, launchId, tokensIn: p.tokensIn, minQuoteOut: p.minOut, to: p.recipient ?? p.trader, ...(p.deadline !== undefined ? { deadline: p.deadline } : {}) });
176
190
  const { token } = await launchState(launchId);
177
- return tx([approveCall(token, floorAmm, p.tokensIn), sell]);
191
+ return tx([...(await approvals(token, p.trader, p.tokensIn)), sell]);
178
192
  }),
179
193
 
180
194
  claim: (p) => guard(async () => tx([claimV2Call({ floorAmm, wallet: p.wallet, types: p.types, quotes: [p.quote], launchIds: p.launches.map(launchIdOf) })])),