@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
@@ -28,6 +28,8 @@ export const routePath = {
28
28
  trades: ({ launch, ...q }) => indexerPath.trades(launch, q),
29
29
  launchClaims: ({ launch, ...q }) => indexerPath.launchClaims(launch, q),
30
30
  devBuys: (a) => indexerPath.devBuys(a.launch),
31
+ memberSold: (a) => indexerPath.memberSold(a.launch),
32
+ launchAccount: (a) => indexerPath.launchAccount(a.launch),
31
33
  traders: ({ launch, ...q }) => indexerPath.traders(launch, q),
32
34
  quoteChain: (a) => indexerPath.quoteChain(a.launch),
33
35
  devTrades: ({ launch, ...q }) => indexerPath.devTrades(launch, q),
@@ -48,8 +50,10 @@ export const routePath = {
48
50
  claimView: (a) => indexerPath.claimView(a.wallet),
49
51
  people: (a) => indexerPath.people(a.wallet),
50
52
  roles: (a) => indexerPath.roles(a.wallet),
53
+ handlePlaces: (a) => indexerPath.handlePlaces(a.handle),
51
54
  traderBoard: (a) => indexerPath.traderBoard(a ?? {}),
52
55
  launcherBoard: (a) => indexerPath.launcherBoard(a ?? {}),
56
+ tokenHolders: (a) => `/floor-amm/holders/${encodeURIComponent(need(a.token, "token"))}${query({ limit: a.limit, offset: a.offset })}`,
53
57
  dexAsset: (a) => `/v2/dex/asset${query({ id: need(a.id, "id") })}`,
54
58
  dexSummary: (a) => `/v2/dex/summary${query({ id: need(a.id, "id") })}`,
55
59
  dexPair: (a) => `/v2/dex/pair${query({ id: need(a.id, "id") })}`,
@@ -71,7 +71,7 @@ const LAUNCH_ERR = [...GATED, "unknown_launch"] ;
71
71
  const WALLET_ERR = [...GATED, "bad_query"] ;
72
72
 
73
73
  function site (s ) {
74
- const params = [...s.pattern.matchAll(/<(launch|wallet)>/g)].map((m) => m[1] );
74
+ const params = [...s.pattern.matchAll(/<(launch|wallet|token|handle)>/g)].map((m) => m[1] );
75
75
  const { v2, ...rest } = s;
76
76
  const aliases = s.aliases ?? (v2 ? [s.pattern.replace(/^\/floor-amm\//, "/floor-amm/v2/")] : []);
77
77
  return { mount: "chain", query: {}, page: NONE, errors: GATED, gated: true, units: "site", audience: "site", ...rest, params, aliases };
@@ -140,6 +140,10 @@ export const INDEXER_CONTRACT = {
140
140
  }),
141
141
  launchClaims: site({ pattern: "/floor-amm/launches/<launch>/claims", v2: true, query: { claimer: { kind: "string", doc: "only this claimer's rows" } }, errors: LAUNCH_ERR, body: B.LAUNCH_CLAIMS }),
142
142
  devBuys: site({ pattern: "/floor-amm/launches/<launch>/dev-buys", v2: true, errors: LAUNCH_ERR, body: B.DEV_BUYS }),
143
+
144
+ memberSold: site({ pattern: "/floor-amm/launches/<launch>/member-sold", v2: true, errors: LAUNCH_ERR, body: B.MEMBER_SOLD }),
145
+
146
+ launchAccount: site({ pattern: "/floor-amm/launches/<launch>/account", v2: true, errors: LAUNCH_ERR, body: B.LAUNCH_ACCOUNT }),
143
147
  traders: site({ pattern: "/floor-amm/launches/<launch>/traders", v2: true, query: { window: WINDOW, limit: LIMIT(100, 500) }, page: limit(100, 500), errors: [...LAUNCH_ERR, "bad_query"], body: B.LAUNCH_TRADERS }),
144
148
  quoteChain: site({ pattern: "/floor-amm/launches/<launch>/chain", v2: true, errors: LAUNCH_ERR, body: B.QUOTE_CHAIN }),
145
149
  devTrades: site({ pattern: "/floor-amm/launches/<launch>/dev", v2: true, query: { limit: LIMIT(100, 500) }, page: limit(100, 500), errors: [...LAUNCH_ERR, "bad_query"], body: B.DEV_TRADES }),
@@ -207,9 +211,20 @@ export const INDEXER_CONTRACT = {
207
211
  people: site({ pattern: "/floor-amm/referrals/<wallet>/people", errors: WALLET_ERR, body: B.PEOPLE }),
208
212
  roles: site({ pattern: "/floor-amm/roles/<wallet>", errors: WALLET_ERR, body: B.ROLES }),
209
213
 
214
+ handlePlaces: site({ pattern: "/floor-amm/handles/<handle>/places", errors: WALLET_ERR, body: B.HANDLE_PLACES }),
215
+
210
216
  traderBoard: site({ pattern: "/floor-amm/leaderboards/traders", v2: true, query: { window: WINDOW, limit: LIMIT(100, 500) }, page: limit(100, 500), errors: [...GATED, "bad_query"], body: B.TRADER_BOARD }),
211
217
  launcherBoard: site({ pattern: "/floor-amm/leaderboards/launchers", v2: true, query: { limit: LIMIT(100, 500) }, page: limit(100, 500), errors: [...GATED, "bad_query"], body: B.LAUNCHER_BOARD }),
212
218
 
219
+ tokenHolders: partner({
220
+ pattern: "/floor-amm/holders/<token>",
221
+ aliases: ["/holders/<token>"],
222
+ params: ["token"],
223
+ query: { limit: LIMIT(100, 500), offset: { kind: "int", doc: "rows skipped", min: 0, default: 0 } },
224
+ page: { kind: "offset", limit: { default: 100, max: 500 }, total: "total" },
225
+ errors: [...GATED, "bad_query", "not_found"],
226
+ body: P.TOKEN_HOLDERS,
227
+ }),
213
228
  dexAsset: partner({ pattern: "/v2/dex/asset", aliases: ["/asset"], query: { id: { kind: "string", doc: "a launch's token, or a quote", required: true } }, errors: [...GATED, "bad_query", "not_found", "not_indexed"], body: P.DEX_ASSET }),
214
229
  dexSummary: partner({ pattern: "/v2/dex/summary", aliases: ["/summary"], query: { id: { kind: "string", doc: "the pair id", required: true } }, errors: [...GATED, "bad_query", "not_found"], body: P.DEX_SUMMARY }),
215
230
  dexPair: partner({ pattern: "/v2/dex/pair", aliases: ["/pair"], query: { id: { kind: "string", doc: "the pair id", required: true } }, errors: [...GATED, "unknown_launch"], body: P.DEX_PAIR }),
@@ -248,7 +263,7 @@ export function matchRoute(path )
248
263
  const c = INDEXER_CONTRACT[name];
249
264
  for (const pat of [c.pattern, ...c.aliases]) {
250
265
  const keys = [];
251
- const re = new RegExp(`^${pat.replace(/[.*+?^${}()|[\]\\]/g, "\\$&").replace(/<(launch|wallet)>/g, (_, k ) => (keys.push(k), "([^/]+)"))}$`);
266
+ const re = new RegExp(`^${pat.replace(/[.*+?^${}()|[\]\\]/g, "\\$&").replace(/<(launch|wallet|token|handle)>/g, (_, k ) => (keys.push(k), "([^/]+)"))}$`);
252
267
  const m = re.exec(p);
253
268
  if (m === null) continue;
254
269
  const params = {};
@@ -20,6 +20,8 @@ export const DEX_ASSET = object({
20
20
  }),
21
21
  });
22
22
 
23
+ export const TOKEN_HOLDERS = object({ total: int, holders: array(object({ address: str, balance: big })) });
24
+
23
25
  export const DEX_SUMMARY = object({
24
26
  pair: str,
25
27
  base: str,
@@ -65,6 +67,9 @@ export const CG_TICKERS = array(object({
65
67
  low: nullable(decimal),
66
68
  liquidity_in_usd: nullable(decimal),
67
69
  liquidity_in_quote: big,
70
+
71
+ depthUp2: nullable(decimal),
72
+ depthDown2: nullable(decimal),
68
73
  }));
69
74
 
70
75
  export const CG_TRADE = object({ trade_id: int, price: decimal, base_volume: decimal, target_volume: decimal, trade_timestamp: int, type: oneOf("buy", "sell") });
@@ -16,6 +16,8 @@ export const INDEXER_ROUTES = {
16
16
  trades: { pattern: "/floor-amm/launches/<launch>/trades", keys: ["limit", "before", "traders"] },
17
17
  launchClaims: { pattern: "/floor-amm/launches/<launch>/claims", keys: ["claimer"] },
18
18
  devBuys: { pattern: "/floor-amm/launches/<launch>/dev-buys", keys: [] },
19
+ memberSold: { pattern: "/floor-amm/launches/<launch>/member-sold", keys: [] },
20
+ launchAccount: { pattern: "/floor-amm/launches/<launch>/account", keys: [] },
19
21
  traders: { pattern: "/floor-amm/launches/<launch>/traders", keys: ["window", "limit"] },
20
22
  quoteChain: { pattern: "/floor-amm/launches/<launch>/chain", keys: [] },
21
23
  devTrades: { pattern: "/floor-amm/launches/<launch>/dev", keys: ["limit"] },
@@ -36,6 +38,7 @@ export const INDEXER_ROUTES = {
36
38
  claimView: { pattern: "/floor-amm/claims/<wallet>", keys: [] },
37
39
  people: { pattern: "/floor-amm/referrals/<wallet>/people", keys: [] },
38
40
  roles: { pattern: "/floor-amm/roles/<wallet>", keys: [] },
41
+ handlePlaces: { pattern: "/floor-amm/handles/<handle>/places", keys: [] },
39
42
  traderBoard: { pattern: "/floor-amm/leaderboards/traders", keys: ["window", "limit"] },
40
43
  launcherBoard: { pattern: "/floor-amm/leaderboards/launchers", keys: ["limit"] },
41
44
  } ;
@@ -93,6 +96,8 @@ export const indexerPath = {
93
96
  trades: (id , q = {}) => launchPath(id, `/trades${query({ limit: q.limit, before: q.before, traders: q.traders?.length ? q.traders : undefined })}`),
94
97
  launchClaims: (id , q = {}) => launchPath(id, `/claims${query({ claimer: q.claimer })}`),
95
98
  devBuys: (id ) => launchPath(id, "/dev-buys"),
99
+ memberSold: (id ) => launchPath(id, "/member-sold"),
100
+ launchAccount: (id ) => launchPath(id, "/account"),
96
101
  traders: (id , q = {}) => launchPath(id, `/traders${query({ window: q.window, limit: q.limit })}`),
97
102
  quoteChain: (id ) => launchPath(id, "/chain"),
98
103
  devTrades: (id , q = {}) => launchPath(id, `/dev${query({ limit: q.limit })}`),
@@ -122,6 +127,7 @@ export const indexerPath = {
122
127
  claimView: (w ) => `/floor-amm/claims/${seg(w)}`,
123
128
  people: (w ) => `/floor-amm/referrals/${seg(w)}/people`,
124
129
  roles: (w ) => `/floor-amm/roles/${seg(w)}`,
130
+ handlePlaces: (handle ) => `/floor-amm/handles/${seg(handle)}/places`,
125
131
  traderBoard: (q = {}) => `/floor-amm/leaderboards/traders${query({ window: q.window, limit: q.limit })}`,
126
132
  launcherBoard: (q = {}) => `/floor-amm/leaderboards/launchers${query({ limit: q.limit })}`,
127
133
  } ;
@@ -66,6 +66,17 @@ export const readTrades = (get , id , q = {})
66
66
  export const readLaunchClaims = (get , id , q = {}) => readRoute(get, indexerPath.launchClaims(id, q), B.LAUNCH_CLAIMS);
67
67
  export const readDevBuys = (get , id ) => readRoute(get, indexerPath.devBuys(id), B.DEV_BUYS);
68
68
 
69
+ export const readMemberSold = (get , id ) => readRoute(get, indexerPath.memberSold(id), B.MEMBER_SOLD);
70
+
71
+ export const readLaunchAccount = (get , id ) => readRoute(get, indexerPath.launchAccount(id), B.LAUNCH_ACCOUNT);
72
+
73
+ export function launchAccountBytes(body ) {
74
+ const bin = atob(body.data);
75
+ const out = new Uint8Array(bin.length);
76
+ for (let i = 0; i < bin.length; i++) out[i] = bin.charCodeAt(i);
77
+ return out;
78
+ }
79
+
69
80
  export const readTraders = (get , id , q = {}) => readRoute(get, indexerPath.traders(id, q), B.LAUNCH_TRADERS);
70
81
  export const readQuoteChain = (get , id ) => readRoute(get, indexerPath.quoteChain(id), B.QUOTE_CHAIN);
71
82
 
@@ -94,6 +105,8 @@ export const readFirstsMany = (get , wallets )
94
105
  export const readPeople = (get , wallet ) => readRoute(get, indexerPath.people(wallet), B.PEOPLE);
95
106
  export const readRoles = (get , wallet ) => readRoute(get, indexerPath.roles(wallet), B.ROLES);
96
107
 
108
+ export const readHandlePlaces = (get , handle ) => readRoute(get, indexerPath.handlePlaces(handle), B.HANDLE_PLACES);
109
+
97
110
  export const readTraderBoard = (get , q = {}) => readRoute(get, indexerPath.traderBoard(q), B.TRADER_BOARD);
98
111
  export const readLauncherBoard = (get , q = {}) => readRoute(get, indexerPath.launcherBoard(q), B.LAUNCHER_BOARD);
99
112
 
@@ -21,7 +21,7 @@ function commit(dst , src ) {
21
21
  Object.assign(dst, src);
22
22
  }
23
23
 
24
- function buyOn(book , side , gross , minTokens , walkSteps ) {
24
+ function buyOn(book , side , gross , minTokens , walkSteps , keep = true) {
25
25
  const ppm = feesNow(book);
26
26
  const budget = netFromGross(gross, ppm);
27
27
  if (budget === 0n) fail("NothingToDo");
@@ -63,11 +63,11 @@ function buyOn(book , side , gross , minTokens , walkSte
63
63
  steps: walked.steps, budgetHit: walked.budgetHit, graduatedNow: walked.graduatedNow, sqrtBefore: book.sqrtP, sqrtAfter: w.sqrtP,
64
64
  split: sp, relay: rl,
65
65
  };
66
- commit(book, w);
66
+ if (keep) commit(book, w);
67
67
  return r;
68
68
  }
69
69
 
70
- function sellOn(book , side , tokens , minOut ) {
70
+ function sellOn(book , side , tokens , minOut , keep = true) {
71
71
  if (tokens === 0n) fail("NothingToDo");
72
72
  const ppm = feesNow(book);
73
73
  const w = cloneBook(book);
@@ -86,7 +86,7 @@ function sellOn(book , side , tokens , minOut )
86
86
  tokensIn: tokens, unfilled: tokens - walked.tokens, gross: walked.money, fees, out, steps: walked.steps, sqrtBefore: book.sqrtP, sqrtAfter: w.sqrtP,
87
87
  fromF: walked.fromF, fromK: walked.fromK, fromC: walked.fromC, relay: rl,
88
88
  };
89
- commit(book, w);
89
+ if (keep) commit(book, w);
90
90
  return r;
91
91
  }
92
92
 
@@ -99,8 +99,8 @@ export function sell(book , row , sup , tokens , min
99
99
  }
100
100
 
101
101
  export const quoteBuy = (book , row , sup , gross , walkSteps = MAX_WALK_STEPS) =>
102
- buy(cloneBook(book), row, sup, gross, 0n, { walkSteps });
103
- export const quoteSell = (book , row , sup , tokens ) => sell(cloneBook(book), row, sup, tokens, 0n);
102
+ buyOn(book, { row, sup }, gross, 0n, walkSteps, false);
103
+ export const quoteSell = (book , row , sup , tokens ) => sellOn(book, { row, sup }, tokens, 0n, false);
104
104
 
105
105
  export function buyMinTokens(b , row , sup , gross , slippageBps , walkSteps = MAX_WALK_STEPS) {
106
106
  const less = buyLessIn(gross, slippageBps);
@@ -122,5 +122,5 @@ export function bookSell(book , tokens , minOut ) {
122
122
  return sellOn(book, null, tokens, minOut);
123
123
  }
124
124
 
125
- export const quoteBookBuy = (book , gross , walkSteps = MAX_WALK_STEPS) => bookBuy(cloneBook(book), gross, 0n, walkSteps);
126
- export const quoteBookSell = (book , tokens ) => bookSell(cloneBook(book), tokens, 0n);
125
+ export const quoteBookBuy = (book , gross , walkSteps = MAX_WALK_STEPS) => buyOn(book, null, gross, 0n, walkSteps, false);
126
+ export const quoteBookSell = (book , tokens ) => sellOn(book, null, tokens, 0n, false);
@@ -122,7 +122,9 @@ export const GENESIS_RAISE = [
122
122
 
123
123
  ["preset_id", "u8"],
124
124
  ["opened", "u8"],
125
- ["pad1", "bytes:6"],
125
+
126
+ ["public_open", "u8"],
127
+ ["pad1", "bytes:5"],
126
128
  ["cap", "u64"],
127
129
  ["ends_at", "i64"],
128
130
  ["migrated_refunded", "u64"],
@@ -73,6 +73,10 @@ export const EVENTS = {
73
73
  BurnsSynced: S(["launch", "pubkey"], ["incinerated", "u64"], ["supply", "u64"], ["sOut", "u64"], ["floorAfterX64", "u128"], ["slot", "u64"]),
74
74
 
75
75
  TokensBurned: S(["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?"]),
76
+
77
+ GenesisPublicStarted: S(["signer", "pubkey"], ["at", "i64"]),
78
+
79
+ GenesisEndSet: S(["signer", "pubkey"], ["oldEndsAt", "i64"], ["newEndsAt", "i64"]),
76
80
  };
77
81
 
78
82
  export const SWEPT_BURN = 0;
@@ -253,6 +253,19 @@ export function setGenesisListRootInstruction(p
253
253
  return ix("set_genesis_list_root", [RS(p.authority), R(p.config), W(p.genesisRaise)], (w) => w.bytes(p.listRoot), p);
254
254
  }
255
255
 
256
+ export const GENESIS_NO_END = (1n << 63n) - 1n;
257
+
258
+ export function startGenesisPublicInstruction(p ) {
259
+ const g = pid(p);
260
+ return ix("start_genesis_public", [RS(p.authority), R(p.config ?? configPda(g)[0]), W(p.genesisRaise ?? genesisRaisePda(g)[0])], none, p);
261
+ }
262
+
263
+ export function setGenesisEndInstruction(p ) {
264
+ if (p.endsAt < 0n || p.endsAt > GENESIS_NO_END) throw new RangeError(`setGenesisEndInstruction: endsAt ${p.endsAt} is not an i64 ≥ 0`);
265
+ const g = pid(p);
266
+ return ix("set_genesis_end", [RS(p.authority), R(p.config ?? configPda(g)[0]), W(p.genesisRaise ?? genesisRaisePda(g)[0])], (w) => w.u64(p.endsAt), p);
267
+ }
268
+
256
269
  export function setGenesisPresetInstruction(p ) {
257
270
  return ix("set_genesis_preset", [RS(p.authority), R(p.config), W(p.genesisRaise), R(p.preset)], (w) => w.u8(p.presetId), p);
258
271
  }
package/dist/v2/devbuy.js CHANGED
@@ -35,3 +35,18 @@ export function devBuyFromTrade(t , team , ctx
35
35
  }
36
36
 
37
37
  export const devBuyChangeSinceBps = (d , sqrtNow ) => impactBps(d.priceAfterX64, priceX64(sqrtNow));
38
+
39
+ export function memberSoldFromTrade(
40
+ t ,
41
+ seats ,
42
+ same = (a, b) => a === b,
43
+ ) {
44
+ if (t.isBuy) return null;
45
+ for (const who of t.recipient === undefined ? [t.trader] : [t.trader, t.recipient]) {
46
+ const held = seats.filter((s) => same(s.wallet, who));
47
+ if (held.length === 0) continue;
48
+ const seat = held.reduce((lo, s) => (s.place < lo.place ? s : lo));
49
+ return { launch: t.launch, member: seat.wallet, place: seat.place, amount: t.tokens, quoteOut: t.quoteNet, ...(t.slot === undefined ? {} : { slot: t.slot }) };
50
+ }
51
+ return null;
52
+ }
@@ -0,0 +1,22 @@
1
+
2
+
3
+ export function isDustRefund(gross , refund , budgetHit ) {
4
+ return refund > 0n && !budgetHit && refund * 1_000_000n <= gross;
5
+ }
6
+
7
+ export function carriesNoRefund(gross , refund , budgetHit ) {
8
+ return refund === 0n || isDustRefund(gross, refund, budgetHit);
9
+ }
10
+
11
+ export const GAS_FLAT = { buy: 700_000, sell: 750_000 } ;
12
+
13
+ export const GAS_PER_STEP = { buy: 40_000, sell: 40_000 } ;
14
+
15
+ export const GAS_FLAT_STEPS = 4;
16
+
17
+ export const GAS_MAX = 1_500_000;
18
+
19
+ export function gasFor(side , steps ) {
20
+ const extra = Math.max(0, Math.trunc(steps) - GAS_FLAT_STEPS);
21
+ return Math.min(GAS_MAX, GAS_FLAT[side] + extra * GAS_PER_STEP[side]);
22
+ }
@@ -0,0 +1,235 @@
1
+ # Show the FLOOR on your UI
2
+
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.
7
+
8
+ It is a request, not a requirement, and it is highly appreciated. It costs one field and one line.
9
+
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.
13
+
14
+ ## What we ask
15
+
16
+ **The minimum: two things.**
17
+
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`.
21
+
22
+ **Anything more is a bonus.** In rough order of how much it helps:
23
+
24
+ - How far the price is above the floor, as `% backed` (floor ÷ price) 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.
29
+
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.backedPct` | The price now, and floor ÷ price 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:
114
+
115
+ ```ts
116
+ const floor = Number((floorX64 * 10n ** 6n * 10n ** 12n) / (1n << 64n)) / 10 ** (quoteDecimals + 12);
117
+ ```
118
+
119
+ ## Draw it
120
+
121
+ **The look.** A solid line, 2 px, FLOOR orange `#FF6A1A`, labelled `FLOOR`, with its value on the price axis in the same
122
+ colour. The price stays your usual colour; the floor line goes under it.
123
+
124
+ **The shape.** A step line: it holds its value between trades and steps up at a trade that lifts it. It never steps down
125
+ in quote terms. It starts at graduation; before that there is no point to draw.
126
+
127
+ **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
128
+ own: if the floor is far below the visible candles, pin a small `FLOOR` tag to the bottom edge of the chart instead.
129
+
130
+ **Market-cap mode.** If your chart can show market cap instead of price, multiply the floor by the same supply you
131
+ multiply the price by, so the line stays in the same place under the candles. Keep the label `FLOOR`. Do not call that
132
+ number a market cap of its own.
133
+
134
+ ### Lightweight Charts (v5)
135
+
136
+ ```js
137
+ import { createChart, CandlestickSeries, LineSeries, LineType } from "lightweight-charts";
138
+
139
+ const chart = createChart(el, { autoSize: true });
140
+ const candles = chart.addSeries(CandlestickSeries);
141
+ const floorLine = chart.addSeries(LineSeries, {
142
+ color: "#FF6A1A",
143
+ lineWidth: 2,
144
+ lineType: LineType.WithSteps, // holds between trades, steps up
145
+ title: "FLOOR",
146
+ priceLineVisible: false,
147
+ lastValueVisible: true,
148
+ crosshairMarkerVisible: false,
149
+ autoscaleInfoProvider: () => null, // the floor never stretches the price scale
150
+ });
151
+
152
+ candles.setData(ohlc); // your candles, oldest first
153
+ floorLine.setData(floorPoints); // [{ time, value }] from the trades, oldest first; none before graduation
154
+
155
+ // live: on each new trade
156
+ floorLine.update({ time: trade.time, value: trade.floorPriceQuote });
157
+ ```
158
+
159
+ ### TradingView Advanced Charts (the Charting Library)
160
+
161
+ The simplest version is a locked horizontal line at the current floor, moved when the floor moves:
162
+
163
+ ```js
164
+ const chart = widget.activeChart();
165
+ const id = await chart.createShape(
166
+ { price: floor },
167
+ {
168
+ shape: "horizontal_line",
169
+ lock: true,
170
+ disableSelection: true,
171
+ disableSave: true,
172
+ text: "FLOOR",
173
+ overrides: { linecolor: "#FF6A1A", linewidth: 2, showLabel: true, textcolor: "#FF6A1A", showPrice: true },
174
+ },
175
+ );
176
+
177
+ // when a trade lifts the floor
178
+ chart.getShapeById(id).setPoints([{ price: newFloor }]);
179
+ ```
180
+
181
+ For the full step history, add a custom indicator that plots the floor series from your own trade store, styled as
182
+ above.
183
+
184
+ ### Your own canvas or SVG
185
+
186
+ Walk the trades oldest first. At each trade with a floor, draw a horizontal segment from the previous trade's time at the
187
+ previous floor, then a vertical step up to the new floor. The example page does exactly this in about fifteen lines
188
+ (`floorPath` in its script).
189
+
190
+ ### The FLOOR price on the token page
191
+
192
+ ```html
193
+ <div class="stat">
194
+ <span class="label">FLOOR</span>
195
+ <span class="value" style="color:#FF6A1A">$0.0189</span>
196
+ <span class="note">75% backed</span> <!-- bonus -->
197
+ </div>
198
+ ```
199
+
200
+ Before graduation, show `FLOOR —` (or leave the stat out) and, if you like, `Bonding: no floor yet`.
201
+
202
+ ## What to get right
203
+
204
+ **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
205
+ 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
206
+ quote. Chart in quote units where you can; where you cannot, say which units the chart uses.
207
+
208
+ **Read it, do not derive it.** Do not compute the floor from the money in the program and a supply you hold. The supply
209
+ the program uses is the live supply, and burns change it. Take `floorPriceQuote`, `sqrtF` or `floorPriceNative` as the
210
+ program reports it.
211
+
212
+ **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
213
+ (the Tail), the price can rise faster than the floor, so floor ÷ price can fall while both rise. The floor itself does not
214
+ drop. A widening gap is how the design works, not a loss of backing; do not label it as one.
215
+
216
+ **Graduation is not a migration.** The first window (Bonding, one flat price) selling out is graduation. The launch stays on
217
+ the same program, with the same pair and address, and the floor starts. Keep drawing the line after graduation and in the
218
+ Tail, and do not look for the token on another venue.
219
+
220
+ **No floor, no line.** Draw nothing before graduation (`null` or `sqrtF = 0`), and hide the line if circulating supply
221
+ reads 0 (every token outside the program burned).
222
+
223
+ **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
224
+ not a promise about the market price, and the market price can sit far above it.
225
+
226
+ ## Checklist
227
+
228
+ - [ ] The FLOOR price is on the token page, in the quote token or clearly marked as USD.
229
+ - [ ] The FLOOR line is on the chart: `#FF6A1A`, 2 px, a step line, labelled `FLOOR`, under the price.
230
+ - [ ] Nothing is drawn before graduation; `null` is never drawn as 0.
231
+ - [ ] The line keeps its history and keeps going after graduation.
232
+ - [ ] Market-cap mode scales the floor by the same supply as the price, or hides it.
233
+ - [ ] Optional: `% backed`, a list column, a wallet row, an alert.
234
+
235
+ Shipped it, or stuck? Tell us at contact@floor.supply. We will check it with you and point FLOOR holders to your page.