@floorlaunchpad/sdk 0.3.2 → 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 (62) hide show
  1. package/CHANGELOG.md +66 -0
  2. package/README.md +14 -0
  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 +91 -17
  14. package/dist/indexer/client.js +34 -14
  15. package/dist/indexer/contract.js +132 -28
  16. package/dist/indexer/partners.js +3 -2
  17. package/dist/indexer/paths.js +61 -29
  18. package/dist/indexer/read.js +27 -15
  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/solana.js +17 -2
  28. package/dist/v2/tx/solana.js +1 -1
  29. package/docs/bot.md +36 -1
  30. package/docs/cursor-pages.md +56 -0
  31. package/docs/floor-line.md +9 -4
  32. package/examples/floor-line.html +6 -6
  33. package/package.json +1 -1
  34. package/src/abi/evm.gen.ts +1 -1
  35. package/src/abi/solana.gen.ts +1 -1
  36. package/src/client/evm/index.ts +16 -2
  37. package/src/client/solana/index.ts +19 -7
  38. package/src/client/types.ts +1 -1
  39. package/src/config/generated.ts +26864 -402
  40. package/src/config/index.ts +9 -2
  41. package/src/config/registry.gen.ts +33 -2
  42. package/src/events/types.gen.ts +2 -1
  43. package/src/evm/chains.ts +9 -1
  44. package/src/evm/floor/abi.gen.ts +1 -1
  45. package/src/evm/floor/events.ts +11 -1
  46. package/src/evm/floor/legacy-events.ts +27 -0
  47. package/src/indexer/bodies.ts +99 -17
  48. package/src/indexer/client.ts +52 -30
  49. package/src/indexer/contract.ts +151 -29
  50. package/src/indexer/partners.ts +3 -2
  51. package/src/indexer/paths.ts +84 -29
  52. package/src/indexer/read.ts +33 -17
  53. package/src/indexer/search.ts +138 -0
  54. package/src/indexer/stack-edge.ts +46 -0
  55. package/src/indexer/stream.ts +78 -24
  56. package/src/math/v2/split.ts +11 -3
  57. package/src/solana/floor/events.ts +1 -1
  58. package/src/solana/floor/genesis.ts +8 -2
  59. package/src/solana/floor/instructions.ts +13 -5
  60. package/src/solana/floor/registry.ts +4 -0
  61. package/src/v2/solana.ts +20 -3
  62. package/src/v2/tx/solana.ts +1 -1
@@ -0,0 +1,130 @@
1
+
2
+
3
+ export const SEARCH_Q_MAX = 64;
4
+
5
+ export const SEARCH_PAGE_DEFAULT = 12;
6
+
7
+ export const SEARCH_PAGE_MAX = 100;
8
+
9
+ export const ADDRESS_PREFIX_MIN = 4;
10
+
11
+ export const SEARCH_SUBSTRING_MIN = 3;
12
+
13
+ export function searchFold(s ) {
14
+ return s.normalize("NFKC").toLowerCase().replace(/\s+/g, " ").trim();
15
+ }
16
+
17
+ export function searchNeedles(q ) {
18
+ const f = searchFold(q);
19
+ if (!f.startsWith("$")) return f === "" ? [] : [f];
20
+ const bare = f.slice(1).trim();
21
+ return bare === "" ? [f] : [bare, f];
22
+ }
23
+
24
+ export function searchNeedle(q ) {
25
+ return searchNeedles(q)[0] ?? "";
26
+ }
27
+
28
+ export function searchTierFolded(name , symbol , token , n ) {
29
+ if (n === "") return null;
30
+ if (symbol === n || name === n || token === n) return 0;
31
+ if (symbol.startsWith(n)) return 1;
32
+ if (name.startsWith(n) || name.includes(` ${n}`)) return 2;
33
+ if (symbol.includes(n) || name.includes(n)) return 3;
34
+ if (token.startsWith(n)) return 4;
35
+ if ((name + symbol + token).includes(n)) return 5;
36
+ return null;
37
+ }
38
+
39
+ export function searchServed(tier , needle ) {
40
+ const n = [...needle].length;
41
+ if (tier <= 2) return true;
42
+ if (tier === 3) return n >= SEARCH_SUBSTRING_MIN;
43
+ if (tier === 4) return n >= ADDRESS_PREFIX_MIN;
44
+ return false;
45
+ }
46
+
47
+ export function searchTier(l , q ) {
48
+ const name = searchFold(l.name ?? ""), symbol = searchFold(l.symbol ?? ""), token = searchFold(l.token);
49
+ let best = null;
50
+ for (const n of searchNeedles(q)) {
51
+ const t = searchTierFolded(name, symbol, token, n);
52
+ if (t !== null && (best === null || t < best)) best = t;
53
+ }
54
+ return best;
55
+ }
56
+
57
+ export function searchServedTier(l , q ) {
58
+ const name = searchFold(l.name ?? ""), symbol = searchFold(l.symbol ?? ""), token = searchFold(l.token);
59
+ let best = null;
60
+ for (const n of searchNeedles(q)) {
61
+ const t = searchTierFolded(name, symbol, token, n);
62
+ if (t !== null && searchServed(t, n) && (best === null || t < best)) best = t;
63
+ }
64
+ return best;
65
+ }
66
+
67
+ const SOL = "So11111111111111111111111111111111111111112";
68
+ const EVM = "0xabCDeF0123456789AbcdEf0123456789aBCDEF01";
69
+
70
+ export const SEARCH_PARITY_CORPUS = [
71
+
72
+ ["Doge Wif Hat", "WIF", SOL, "wif", 0],
73
+ ["Doge Wif Hat", "WIF", SOL, "WIF", 0],
74
+ ["Doge Wif Hat", "WIF", SOL, "$wif", 0],
75
+ ["Doge Wif Hat", "WIF", SOL, " doge wif hat ", 0],
76
+ ["Doge Wif Hat", "WIF", SOL, SOL, 0],
77
+ ["Doge Wif Hat", "WIF", EVM, EVM.toLowerCase(), 0],
78
+ ["Doge Wif Hat", "WIF", EVM, EVM.toUpperCase().replace("0X", "0x"), 0],
79
+ ["FLOOR", "FLR", SOL, "flr", 0],
80
+ ["Café", "CAFE", SOL, "café", 0],
81
+ ["Café", "CF", SOL, "café", 0],
82
+ ["Ⅻ Club", "XII", SOL, "xii", 0],
83
+ ["Dog", "DOG", SOL, "$dog", 0],
84
+
85
+ ["Moon Rocket", "MOONR", SOL, "moo", 1],
86
+ ["Moon Rocket", "MOONR", SOL, "$MOO", 1],
87
+ ["Moon Rocket", "MOONR", SOL, "moo", 1],
88
+
89
+ ["Moon Rocket", "MR", SOL, "moon", 2],
90
+ ["Moon Rocket", "MR", SOL, "rock", 2],
91
+ ["Moon Rocket", "MR", SOL, "moon rock", 2],
92
+ ["Moon\tRocket", "MR", SOL, "moon r", 2],
93
+ ["The Big Dog", "TBD", SOL, "big d", 2],
94
+
95
+ ["Moon Rocket", "MR", SOL, "ocke", 3],
96
+ ["Moon Rocket", "XMOONX", SOL, "oon", 3],
97
+ ["Pepe", "PEPE", SOL, "ep", 3],
98
+ ["Pepe Coin", "PC", SOL, "pe c", 3],
99
+
100
+ ["Moon Rocket", "MR", SOL, "so1", 4],
101
+ ["Moon Rocket", "MR", SOL, "so11", 4],
102
+ ["Moon Rocket", "MR", EVM, "0xab", 4],
103
+ ["Moon Rocket", "MR", EVM, "0xA", 4],
104
+
105
+ ["Moon Rocket", "MR", SOL, "1111", 5],
106
+ ["Moon Rocket", "MR", EVM, "cdef01", 5],
107
+ ["Moon Rocket", "MR", SOL, "rocketmr", 5],
108
+ ["Moon Rocket", "MR", SOL, "mrso", 5],
109
+
110
+ [null, "ZED", SOL, "zed", 0],
111
+ [null, null, SOL, "zed", null],
112
+ ["Zed", null, SOL, "ze", 2],
113
+ [null, null, SOL, "so11", 4],
114
+
115
+ ["Moon Rocket", "MR", SOL, "venus", null],
116
+ ["Moon Rocket", "MR", SOL, "", null],
117
+ ["Moon Rocket", "MR", SOL, " ", null],
118
+ ["Moon Rocket", "MR", SOL, "$", null],
119
+
120
+ ["$$ Bills", "BILL", SOL, "$$", 2],
121
+ ["Bills", "$BILL", SOL, "$$bill", 0],
122
+
123
+ ["Big Money", "BM", SOL, "$ money", 2],
124
+
125
+ ["$WIF Coin", "$WIF", SOL, "$wif", 0],
126
+ ["Doge Wif Hat", "WIF", SOL, "$wif", 0],
127
+ ["$1 Coin", "ONE", SOL, "$1", 2],
128
+ ["Cash $ Money", "CASH", SOL, "$", 2],
129
+ ["Cash $ Money", "CASH", SOL, " $ ", 2],
130
+ ];
@@ -0,0 +1,35 @@
1
+
2
+
3
+ function startBar(bars , graduatedAt ) {
4
+ let start = 0;
5
+ for (let j = 0; j < bars.length; j++) {
6
+ if (bars[j] .time <= graduatedAt) start = j;
7
+ else break;
8
+ }
9
+ return start;
10
+ }
11
+
12
+ export function stackEdgeWalk(bars , graduatedAt , endPrice ) {
13
+ const out = [];
14
+ let m = 0;
15
+ for (let j = startBar(bars, graduatedAt); j < bars.length; j++) {
16
+ const b = bars[j] ;
17
+ if (!(b.close > 0) || !(b.high > 0)) continue;
18
+ m = Math.max(m, b.high);
19
+ if (endPrice !== null && endPrice > 0 && m >= endPrice) break;
20
+ out.push({ i: j, edge: m });
21
+ }
22
+ return out;
23
+ }
24
+
25
+ export function stackEdgeEnd(bars , graduatedAt , endPrice ) {
26
+ if (endPrice === null || !(endPrice > 0)) return null;
27
+ let m = 0;
28
+ for (let j = startBar(bars, graduatedAt); j < bars.length; j++) {
29
+ const b = bars[j] ;
30
+ if (!(b.close > 0) || !(b.high > 0)) continue;
31
+ m = Math.max(m, b.high);
32
+ if (m >= endPrice) return j;
33
+ }
34
+ return null;
35
+ }
@@ -1,11 +1,11 @@
1
1
 
2
2
 
3
- import { decode, int, nullable, object, str, unknown } from "./decode.js";
3
+ import { decode, int, nullable, object, optional, str, unknown } from "./decode.js";
4
4
  import { HEAD, LIVE_LAUNCH, TRADE } from "./bodies.js";
5
5
 
6
6
  import { indexerPath } from "./paths.js";
7
7
 
8
- const HELLO = object({ head: HEAD, window: int, oldest: nullable(str) });
8
+ const HELLO = object({ head: HEAD, window: int, oldest: nullable(str), epoch: optional(str) });
9
9
  const HEAD_SEEN = object({ block: int, age: int });
10
10
  const LAUNCH_FRAME = object({ launch: LIVE_LAUNCH });
11
11
  const STATE = object({ launch: str, mint: str, block: int, ts: nullable(int), seq: int, prev: unknown, state: LIVE_LAUNCH });
@@ -45,27 +45,74 @@ export function decodeStreamFrame(event , data , id )
45
45
 
46
46
  export function parseStreamFrames(text ) {
47
47
  const frames = [];
48
- let rest = text.replace(/\r\n/g, "\n");
48
+
49
+ const t = text.indexOf("\r") < 0 ? text : text.replace(/\r\n/g, "\n");
50
+ let at = 0;
49
51
  let cut ;
50
- while ((cut = rest.indexOf("\n\n")) >= 0) {
51
- const block = rest.slice(0, cut);
52
- rest = rest.slice(cut + 2);
53
- let event = "message";
54
- let id ;
55
- const data = [];
56
- let comment = null;
57
- for (const line of block.split("\n")) {
58
- if (line.startsWith(":")) comment = line.slice(1).trim();
59
- else if (line.startsWith("event:")) event = line.slice(6).trim();
60
- else if (line.startsWith("id:")) id = line.slice(3).trim();
61
- else if (line.startsWith("data:")) data.push(line.slice(5).replace(/^ /, ""));
62
- }
63
- if (data.length === 0) {
64
- if (comment !== null) frames.push({ event: "comment", text: comment });
65
- continue;
66
- }
67
- const f = decodeStreamFrame(event, JSON.parse(data.join("\n")), id);
68
- if (f !== null) frames.push(f);
52
+ while ((cut = t.indexOf("\n\n", at)) >= 0) {
53
+ frameOf(t.slice(at, cut), frames);
54
+ at = cut + 2;
55
+ }
56
+ return { frames, rest: at === 0 ? t : t.slice(at) };
57
+ }
58
+
59
+ export function createStreamParser() {
60
+ let pieces = [];
61
+ let cr = false;
62
+ let endsNl = false;
63
+ const parser = {
64
+ push(chunk ) {
65
+ const frames = [];
66
+ let c = cr ? `\r${chunk}` : chunk;
67
+ cr = c.endsWith("\r");
68
+ if (cr) c = c.slice(0, -1);
69
+ if (c.indexOf("\r") >= 0) c = c.replace(/\r\n/g, "\n");
70
+ if (c.length === 0) return frames;
71
+ let at = 0;
72
+
73
+ if (endsNl && pieces.length > 0 && c.charCodeAt(0) === 10) {
74
+ const block = pieces.join("");
75
+ pieces = [];
76
+ frameOf(block.slice(0, -1), frames);
77
+ at = 1;
78
+ }
79
+ let cut ;
80
+ while ((cut = c.indexOf("\n\n", at)) >= 0) {
81
+ const head = c.slice(at, cut);
82
+ frameOf(pieces.length > 0 ? pieces.join("") + head : head, frames);
83
+ pieces = [];
84
+ at = cut + 2;
85
+ }
86
+ if (at < c.length) {
87
+ pieces.push(at === 0 ? c : c.slice(at));
88
+ endsNl = c.charCodeAt(c.length - 1) === 10;
89
+ } else endsNl = false;
90
+ return frames;
91
+ },
92
+ rest() {
93
+ const r = pieces.join("");
94
+ pieces = r.length > 0 ? [r] : [];
95
+ return cr ? `${r}\r` : r;
96
+ },
97
+ };
98
+ return parser;
99
+ }
100
+
101
+ function frameOf(block , frames ) {
102
+ let event = "message";
103
+ let id ;
104
+ const data = [];
105
+ let comment = null;
106
+ for (const line of block.split("\n")) {
107
+ if (line.startsWith(":")) comment = line.slice(1).trim();
108
+ else if (line.startsWith("event:")) event = line.slice(6).trim();
109
+ else if (line.startsWith("id:")) id = line.slice(3).trim();
110
+ else if (line.startsWith("data:")) data.push(line.slice(5).replace(/^ /, ""));
111
+ }
112
+ if (data.length === 0) {
113
+ if (comment !== null) frames.push({ event: "comment", text: comment });
114
+ return;
69
115
  }
70
- return { frames, rest };
116
+ const f = decodeStreamFrame(event, JSON.parse(data.join("\n")), id);
117
+ if (f !== null) frames.push(f);
71
118
  }
@@ -23,7 +23,7 @@ const flatUp = (s , n ) => ov(flatMoneyForTokens(s, n, UP));
23
23
 
24
24
       
25
25
 
26
- export function splitRowOfRowV2(r ) {
26
+ export function splitRowOfRowV2(r ) {
27
27
  const ck = r.ckTargetBps ?? r.ckBps;
28
28
  if (!Number.isInteger(ck)) throw new RangeError("splitRowOfRowV2: the row has no C + K share (`ckTargetBps`)");
29
29
  if (r.ckTargetBps !== undefined && r.ckBps !== undefined && r.ckTargetBps !== r.ckBps) {
@@ -32,7 +32,8 @@ export function splitRowOfRowV2(r
32
32
  return {
33
33
  phiBps: r.phiBps,
34
34
  ckBps: ck ,
35
- wcBps: 300,
35
+
36
+ wcBps: r.wcBps ?? 300,
36
37
  cShareBps: 5_000,
37
38
  msClass: r.msClass,
38
39
  platformMsBps: (r.flags & 1) !== 0 ? r.platformMsBps : 0,
@@ -40,12 +41,19 @@ export function splitRowOfRowV2(r
40
41
  };
41
42
  }
42
43
 
44
+ export function surplus(sqrtF , back , n ) {
45
+ const base = flatMoneyForTokens(sqrtF, n, UP);
46
+ return base === null || base === undefined ? 0n : sat(back, base);
47
+ }
48
+
43
49
  export function split(row , ranges , inp , pieces ) {
44
50
  let tokensSum = 0n;
45
51
  for (const p of pieces) tokensSum += p.tokens;
46
52
  let sr = inp.sNew - tokensSum;
47
53
  if (sr < 0n) fail("Overflow");
48
54
  let fr = inp.fTotal;
55
+
56
+ const s0 = surplus(inp.sqrtF, fr + inp.fClaims, sr + inp.held);
49
57
  const phi = BigInt(row.phiBps);
50
58
  let ckAdd = 0n;
51
59
  let ms = 0n;
@@ -61,7 +69,7 @@ export function split(row , ranges , inp , pie
61
69
  const capB = cdiv(cdiv(pc.money * inp.sqrtF, lo) * inp.sqrtF, lo);
62
70
  const cap = min(max(capA, capB), pc.money);
63
71
  const n = sr + inp.held;
64
- const needAll = max(flatUp(inp.sqrtF, n), cdiv(flatUp(pc.sqrtHi, n) * phi, 10_000n));
72
+ const needAll = max(flatUp(inp.sqrtF, n) + s0, cdiv(flatUp(pc.sqrtHi, n) * phi, 10_000n));
65
73
  if (r.kind !== KIND_TAIL) topNeed = needAll;
66
74
  const need = sat(needAll, fr + inp.fClaims);
67
75
  const dF = min(cap, need);
@@ -9,7 +9,7 @@ const S = (...f ) => f;
9
9
  export const EVENTS = {
10
10
  LaunchCreated: S(["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"]),
11
11
 
12
- Graduated: S(["launch", "pubkey"], ["priceX64", "u128"], ["windowRaised", "u64"], ["windowTokens", "u64"], ["slot", "u64"], ["ts", "i64"]),
12
+ Graduated: S(["launch", "pubkey"], ["windowPriceX64", "u128"], ["windowRaised", "u64"], ["windowTokens", "u64"], ["slot", "u64"], ["ts", "i64"], ["priceX64", "u128"]),
13
13
  PotsSwept: S(["launch", "pubkey"], ["amount", "u64"], ["reason", "u8"]),
14
14
  Claimed: S(["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?"]),
15
15
 
@@ -1,6 +1,7 @@
1
1
 
2
2
 
3
3
  import { BPS, fail } from "../../math/index.js";
4
+ import { WAGMI_GENESIS_KEEP_USD } from "../../math/v2/rows.js";
4
5
  import { fixedRaiseClaim, genesisClaim, genesisWeightListed } from "../../math/genesis.js";
5
6
  import { GENESIS_ALLOC_CLAIMED, GENESIS_ALLOC_MIGRATED, GENESIS_ALLOC_REFUNDED, GENESIS_ALLOC_WAGMI_CLAIMED } from "./accounts.js";
6
7
 
@@ -50,15 +51,20 @@ export function genesisConvertTake(want , room , quote
50
51
  return [take, usdc];
51
52
  }
52
53
 
53
-    
54
+  
54
55
 
55
- export function genesisWaterfall(p ) {
56
+ export function genesisWaterfall(p ) {
56
57
  if (p.solConverted > p.raisedFinal) fail("Overflow");
57
58
  const floorUsdc = p.usdcConverted < p.floorCapUsdc ? p.usdcConverted : p.floorCapUsdc;
58
59
  const used = p.floorUsed ?? floorUsdc;
59
60
  if (used > floorUsdc) fail("Overflow");
60
61
  const left = p.usdcConverted - used;
61
- const wagmiOffer = p.wagmiPinned ? left : 0n;
62
+
63
+ const px = p.usdcPxX64 ?? 100n << 64n;
64
+ if (px <= 0n) fail("Zero");
65
+ const keepAll = (WAGMI_GENESIS_KEEP_USD * 100n * 10n ** BigInt(p.usdcDecimals ?? 6) << 64n) / px;
66
+ const keep = keepAll > U64_MAX ? U64_MAX : keepAll;
67
+ const wagmiOffer = p.wagmiPinned ? (left < keep ? left : keep) : 0n;
62
68
  const wagmiUsdc = p.wagmiSpent ?? wagmiOffer;
63
69
  if (wagmiUsdc > wagmiOffer) fail("Overflow");
64
70
  return { floorUsdc, wagmiOffer, wagmiUsdc, usdcRefund: left - wagmiUsdc, solUnconverted: p.raisedFinal - p.solConverted };
@@ -11,6 +11,8 @@ import { Writer } from "./borsh.js";
11
11
  import { CLAIM_BITS, CLAIM_KNOWN_MASKS, CLAIM_RESERVED, CLAIM_CREATOR, CLAIM_CREATOR_REF, CLAIM_TEAM_SLOT, CLAIM_TRADER_REF, CLAIM_RESERVED_HOLDER, CLAIM_EXTRA, CLAIM_TEAM_BUY, CLAIM_SHARE_BOUGHT } from "../../generated/index.js";
12
12
  import { launchMintPda } from "./mint.js";
13
13
 
14
+ import { FLOOR_HOOK_PROGRAM_ID, extraAccountMetasPda, holderBookPda, holderPositionPda, quoteHookBlock } from "../../v2/solana.js";
15
+
14
16
  const pid = (c ) => c?.programId ?? FLOOR_AMM_PROGRAM_ID;
15
17
  const evPair = (c ) => [R(floorEventAuthorityPda(pid(c))[0]), R(pid(c))];
16
18
  function ix(name , accounts , args , c ) {
@@ -74,8 +76,11 @@ export function clearTraderRefInstruction(p
74
76
  return withRest(i, (p.traderRefs ?? []).map((r) => W(r)));
75
77
  }
76
78
 
77
- export function withdrawPlatformInstruction(p ) {
78
- return ix("withdraw_platform", [RS(p.authority), R(p.config), W(p.launch), R(p.quoteMint), W(p.quoteVault), W(p.destination), R(p.quoteTokenProgram)], (w) => w.u64(p.amount), p);
79
+ export function withdrawPlatformInstruction(p ) {
80
+ const i = ix("withdraw_platform", [RS(p.authority), R(p.config), W(p.launch), R(p.quoteMint), W(p.quoteVault), W(p.destination), R(p.quoteTokenProgram)], (w) => w.u64(p.amount), p);
81
+ if (!p.quoteIsLaunch) return i;
82
+ if (!p.treasury) throw new RangeError("withdraw_platform: a launch-token quote needs the treasury (its position receives)");
83
+ return withRest(i, quoteHookBlock(p.quoteMint, p.treasury, [p.launch], p));
79
84
  }
80
85
 
81
86
  export function checkPresetInstruction(p ) {
@@ -188,12 +193,16 @@ export function openRefOwedInstruction(p
188
193
  return ix("open_ref_owed", [WS(p.payer), R(p.quoteMint), W(p.refOwed), W(p.vault), R(p.quoteTokenProgram), R(ASSOCIATED_TOKEN_PROGRAM_ID), R(SYSTEM_PROGRAM_ID)], (w) => w.pubkey(p.referrer), p);
189
194
  }
190
195
 
191
- export function rollUpRefsInstruction(p ) {
196
+ export function rollUpRefsInstruction(p ) {
192
197
  if (p.traderRefs.length > 255) throw new RangeError("at most 255 links a roll-up");
193
198
  const base = ix("roll_up_refs", [R(p.quoteMint), R(p.quoteTokenProgram)], (w) => w.u8(p.traderRefs.length), p);
194
199
  const rest = [];
195
- for (const t of p.traderRefs) rest.push(W(t.traderRef), W(t.escrow));
196
- for (const r of p.refOwed) rest.push(W(r.refOwed), W(r.vault));
200
+ const hook = p.hookProgramId;
201
+ const ql = p.quoteIsLaunch ? launchPda(p.quoteMint, pid(p))[0] : "";
202
+ const pos = (owner ) => (p.quoteIsLaunch ? [W(holderPositionPda(ql, owner, hook)[0])] : []);
203
+ for (const t of p.traderRefs) rest.push(W(t.traderRef), W(t.escrow), ...pos(t.traderRef));
204
+ for (const r of p.refOwed) rest.push(W(r.refOwed), W(r.vault), ...pos(r.refOwed));
205
+ if (p.quoteIsLaunch) rest.push(R(extraAccountMetasPda(p.quoteMint, hook)[0]), R(ql), W(holderBookPda(ql, hook)[0]), R(hook ?? FLOOR_HOOK_PROGRAM_ID));
197
206
  return { ...base, accounts: [...base.accounts, ...rest] };
198
207
  }
199
208
 
@@ -60,6 +60,10 @@ export function nextClaimsPage(pages ) {
60
60
  return last.count < CLAIMS_PAGE_ENTRIES ? last.page : last.page + 1;
61
61
  }
62
62
 
63
+ export function hookClaimsPage(pages ) {
64
+ return pages.length === 0 ? 0 : pages[pages.length - 1].page;
65
+ }
66
+
63
67
  function ix(name , accounts , args , programId = FLOOR_AMM_PROGRAM_ID) {
64
68
  const ev = floorEventAuthorityPda(programId)[0];
65
69
  return { programAddress: programId, accounts: [...accounts, R(ev), R(programId)], data: args(new Writer().bytes(instructionDiscriminator(name))).done() };
package/dist/v2/solana.js CHANGED
@@ -173,14 +173,29 @@ export function presetV2Instructions(p
173
173
  return out;
174
174
  }
175
175
 
176
+  
177
+
178
+  
179
+
176
180
  export function teamShareBuyInstructionV2(p ) {
181
+ if (!p.traderRef !== !p.escrow) throw new RangeError("team_share_buy: traderRef and escrow go together");
182
+ const referred = Boolean(p.traderRef);
183
+ if (referred && !p.quoteTokenProgram) throw new RangeError("team_share_buy: a referred buyback needs quoteTokenProgram");
177
184
  const base = ix(
178
185
  "team_share_buy",
179
- [WS(p.member), W(p.launch), R(p.baseMint), R(p.quoteMint), W(p.tokenVault), R(p.quoteVault), R(p.teamSlot ?? teamSlotPda(p.launch, pid(p))[0]), W(p.memberBase), R(TOKEN_2022_PROGRAM_ID)],
186
+
187
+ [WS(p.member), W(p.launch), R(p.baseMint), R(p.quoteMint), W(p.tokenVault), referred ? W(p.quoteVault) : R(p.quoteVault), R(p.teamSlot ?? teamSlotPda(p.launch, pid(p))[0]), W(p.memberBase), R(TOKEN_2022_PROGRAM_ID)],
180
188
  (w) => w.u64(p.amountIn).u64(minOut(p.minOut, "minOut")),
181
189
  p,
182
190
  );
183
- return { ...base, accounts: [...base.accounts, ...hookAccountsFor({ baseMint: p.baseMint, srcOwner: p.launch, dstOwner: p.member, programId: p.programId, hookProgramId: p.hookProgramId })] };
191
+ const accounts = [...base.accounts, ...hookAccountsFor({ baseMint: p.baseMint, srcOwner: p.launch, dstOwner: p.member, programId: p.programId, hookProgramId: p.hookProgramId })];
192
+ if (!referred) return { ...base, accounts };
193
+ accounts.push(W(p.traderRef ), W(p.escrow ), R(p.quoteTokenProgram ));
194
+ if (p.quoteIsLaunch) {
195
+ accounts.push(...hookAccountsFor({ baseMint: p.quoteMint, srcOwner: p.launch, dstOwner: p.traderRef , programId: p.programId, hookProgramId: p.hookProgramId }));
196
+ accounts.push(W(holderPositionPda(launchPda(p.quoteMint, pid(p))[0], p.traderRef , hid(p))[0]));
197
+ }
198
+ return { ...base, accounts };
184
199
  }
185
200
 
186
201
  const REM_HOOK_AT = 5;
@@ -112,7 +112,7 @@ export function teamShareBuyAndClaimInstructionsV2(
112
112
  });
113
113
  return [
114
114
  ...(open ? [createAssociatedTokenAccountIdempotentInstruction({ payer: p.member, owner: p.member, mint: p.baseMint, tokenProgram: TOKEN_2022_PROGRAM_ID })] : []),
115
- teamShareBuyInstructionV2({ ...buy, teamSlot, memberBase }),
115
+ teamShareBuyInstructionV2({ ...buy, teamSlot, memberBase, quoteTokenProgram, quoteIsLaunch }),
116
116
  claim,
117
117
  ];
118
118
  }
package/docs/bot.md CHANGED
@@ -18,7 +18,42 @@ const { launch } = await readLaunch(get, "42");
18
18
  const page = await readTrades(get, launch.id, { limit: 100 });
19
19
  ```
20
20
 
21
- Pages carry a `next` cursor; pass it as `before` for the next page, and stop when it is `null`. Amounts are `bigint`. A non-200 answer throws an `IndexerError` (`notReady` while the indexer catches up, `unknownLaunch` for an id it does not know). A body of the wrong shape throws a `ShapeError` that names the field.
21
+ Pages carry a `next` cursor; stop when it is `null`. On trades, marks and the inbox pass it back as `before`; on `launches`, `search` and the other wallet routes pass it back as `cursor`. Amounts are `bigint`. A non-200 answer throws an `IndexerError` (`notReady` while the indexer catches up, `unknownLaunch` for an id it does not know). A body of the wrong shape throws a `ShapeError` that names the field.
22
+
23
+ ### List and search launches
24
+
25
+ `readLaunches` answers one page, 100 launches by default. No request answers every launch, so walk the pages:
26
+
27
+ ```ts
28
+ import { readLaunches, readLaunchSearch, readCandles } from "@floorlaunchpad/sdk/indexer/read";
29
+
30
+ let cursor: string | undefined;
31
+ do {
32
+ const page = await readLaunches(get, { limit: 100, cursor });
33
+ // page.launches …
34
+ cursor = page.next ?? undefined;
35
+ } while (cursor !== undefined);
36
+
37
+ const hits = await readLaunchSearch(get, { q: "wagmi" }); // best match first, each row with its tier
38
+ ```
39
+
40
+ A client made with `createIndexerClient` walks them for you: `for await (const page of ix.drain("launches", {}))`.
41
+
42
+ ### Wallet lists
43
+
44
+ Called with neither `limit` nor `cursor`, `readPositions`, `readWalletLocks`, `readClaimHistory`, `readRoles` and
45
+ `readPeople` return the whole list. Pass either one to get pages: a page is 100 rows unless `limit` asks for another
46
+ size, and 500 at most. `readInbox` pages with `before`. Every list is in [cursor-pages.md](cursor-pages.md).
47
+
48
+ ### Candles with the floor
49
+
50
+ ```ts
51
+ const { candles } = await readCandles(get, { launch: launch.id, interval: "1h" });
52
+ ```
53
+
54
+ Each candle carries `floorX64`, the floor at the bucket's close, in the same Q64.64 units as a launch's `floorX64`. It is
55
+ `null` where a bucket has none, and absent from an indexer older than this build. Use the launch's own `floorX64` for
56
+ that candle then. [floor-line.md](floor-line.md) shows how to draw it.
22
57
 
23
58
  ## Follow the live stream
24
59
 
@@ -0,0 +1,56 @@
1
+ # Cursor pages
2
+
3
+ Every list route of the FLOOR indexer that pages by cursor follows one contract.
4
+
5
+ ## Request
6
+
7
+ `?<cursor key>=<cursor>&limit=<n>`. The cursor key is `cursor` on every route, except where a route already took `before`
8
+ before cursor pages existed (`launches/<id>/trades`, `wallets/<w>/trades`, `launches/<id>/marks`, `wallets/<w>/inbox`).
9
+ `limit` has a per-route maximum (500 at most for a wallet page); the contract table (`INDEXER_CONTRACT`, `routeLimit`)
10
+ holds each route's default and maximum. A `limit` above the maximum is a 400 (`limit must be 1..500`, with the route's
11
+ own bounds), never a silent clamp.
12
+
13
+ The wallet routes `positions`, `locks`, `claims`, `roles` and `referrals/<w>/people` answer a page only when one is asked
14
+ (`limit`, or a non-empty `cursor`). The inbox answers a page when `before` is present, and an empty `before` asks the
15
+ newest page. Asked with none of these, each route answers its whole list in one body.
16
+
17
+ ## Defaults
18
+
19
+ | route | reader | cursor key | `limit` default | `limit` maximum |
20
+ |---|---|---|---|---|
21
+ | `launches` | `readLaunches` | `cursor` | `LAUNCHES_PAGE_DEFAULT` (100) | `LAUNCHES_PAGE_MAX` (1,000) |
22
+ | `search?q=` | `readLaunchSearch` | `cursor` | `SEARCH_PAGE_DEFAULT` (12) | `SEARCH_PAGE_MAX` (100) |
23
+ | `wallets/<w>/positions`, `locks`, `claims`, `roles/<w>`, `referrals/<w>/people` | `readPositions`, `readWalletLocks`, `readClaimHistory`, `readRoles`, `readPeople` | `cursor` | `WALLET_PAGE_DEFAULT` (100) | `WALLET_PAGE_MAX` (500) |
24
+ | `wallets/<w>/inbox` | `readInbox` | `before` | `INBOX_PAGE_DEFAULT` (100) | `INBOX_PAGE_MAX` (500) |
25
+
26
+ No request answers every launch: a bare `launches` is one page of 100. The list body also carries `cursors` (the cursor
27
+ after each row) and `keys` (each row's ranked key); `launches` takes a `preset` filter.
28
+
29
+ ## Answer
30
+
31
+ `{ …, <rows>: [...], next: <string> | null }`. `next` is null at the end; passing it back as the cursor returns the
32
+ following page. `cursorPage(body, rowsKey)` reads any decoded page body as `{ rows, next }`; `drain` walks every page.
33
+
34
+ ## Cursor
35
+
36
+ One format on every cursored route, except the trades pages' `before` (see below). The indexer alone writes and reads
37
+ it: it is base64url of a small JSON object whose first keys are
38
+ `v` (the version, 1), `r` (the route) and `f` (a hash of the query). The position of the page's last row follows. A
39
+ client treats it as opaque: it passes back the `next` the indexer served, and bounds the length
40
+ (`WALLET_CURSOR_MAX` for a wallet page, `LAUNCH_CURSOR_MAX` for `launches` and `search`).
41
+
42
+ | route | order | `next` positions the page after |
43
+ |---|---|---|
44
+ | `wallets/<w>/inbox` (`before`), `wallets/<w>/claims` | newest first | the last row (block, txnIndex, eventIndex) |
45
+ | `wallets/<w>/positions`, `wallets/<w>/locks`, `roles/<w>` | launch create order | the last launch (createdBlock, id) |
46
+ | `referrals/<w>/people` | referred wallet ascending | the last wallet |
47
+ | `launches`, `search` | the asked sort | the last row's key and tie (`cursors[i]` per row on the list) |
48
+
49
+ A cursor names its query: one served for another route, another wallet or other filters is a 400 `cursor: not for this
50
+ query`. One that does not decode, or whose fields do not fit the chain, is a 400 `cursor: malformed`. A row id or a bare
51
+ block is not a cursor. A row keeps its own `id` (the inbox's `<block>:<txnIndex>:<eventIndex>`).
52
+
53
+ A page never splits rows that share one position: it ends before them, or takes them all when they alone fill it.
54
+
55
+ The trades pages (`launches/<id>/trades`, `wallets/<w>/trades`, `launches/<id>/marks`) predate this format and keep
56
+ `before` = a block or a trade's `id` (`<block>:<txnIndex>:<eventIndex>`), with `next` the last trade's `id`.
@@ -21,7 +21,7 @@ snippet on this page. Open it in a browser. It needs no network and no key.
21
21
 
22
22
  **Anything more is a bonus.** In rough order of how much it helps:
23
23
 
24
- - How far the price is above the floor, as `% backed` (floor ÷ price) or `price is 1.33× the floor`.
24
+ - The Max Loss: how far the price can fall to the floor, `1 − floor ÷ price` as a percentage before fees (`Max Loss 25%`), or `price is 1.33× the floor`.
25
25
  - A FLOOR column in token lists and screeners.
26
26
  - The FLOOR price in a wallet's holding row, next to the holding's value.
27
27
  - An alert when the price comes near the floor.
@@ -50,7 +50,7 @@ URL is refused). Ask for a key at contact@floor.supply or on X. The reference is
50
50
  |---|---|---|
51
51
  | `GET /launches/{chain}/{token}` | `data.market.floorPriceQuote` | The floor now, whole quote per whole token |
52
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 |
53
+ | | `data.market.priceQuote`, `data.market.maxLossPct` | The price now, and the Max Loss (1 − floor ÷ price, before fees) as a percentage |
54
54
  | `GET /launches/{chain}/{token}/trades` | `data[].floorPriceQuote` | The floor after each trade: the history of the line |
55
55
 
56
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.
@@ -116,6 +116,11 @@ per whole token from a Q64.64 value:
116
116
  const floor = Number((floorX64 * 10n ** 6n * 10n ** 12n) / (1n << 64n)) / 10 ** (quoteDecimals + 12);
117
117
  ```
118
118
 
119
+ If you draw candles from the FLOOR indexer, you need no second read: every candle of `readCandles(get, { launch, interval })`
120
+ carries `floorX64`, the floor at that bucket's close, in the same Q64.64 units. Draw one floor point per candle. It is
121
+ `null` where a bucket has none and absent from an indexer older than SDK 0.4.0, so fall back to the launch's own
122
+ `floorX64` then.
123
+
119
124
  ## Draw it
120
125
 
121
126
  **The look.** A solid line, 2 px, FLOOR orange `#FF6A1A`, labelled `FLOOR`, with its value on the price axis in the same
@@ -193,7 +198,7 @@ previous floor, then a vertical step up to the new floor. The example page does
193
198
  <div class="stat">
194
199
  <span class="label">FLOOR</span>
195
200
  <span class="value" style="color:#FF6A1A">$0.0189</span>
196
- <span class="note">75% backed</span> <!-- bonus -->
201
+ <span class="note">Max Loss 25%</span> <!-- bonus -->
197
202
  </div>
198
203
  ```
199
204
 
@@ -230,6 +235,6 @@ not a promise about the market price, and the market price can sit far above it.
230
235
  - [ ] Nothing is drawn before graduation; `null` is never drawn as 0.
231
236
  - [ ] The line keeps its history and keeps going after graduation.
232
237
  - [ ] 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.
238
+ - [ ] Optional: the Max Loss, a list column, a wallet row, an alert.
234
239
 
235
240
  Shipped it, or stuck? Tell us at contact@floor.supply. We will check it with you and point FLOOR holders to your page.