@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
@@ -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/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
+ }
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`.