@floorlaunchpad/sdk 0.1.1 → 0.3.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 (292) hide show
  1. package/CHANGELOG.md +84 -0
  2. package/LICENSE +201 -60
  3. package/README.md +45 -24
  4. package/dist/abi/evm-event-names.js +12 -0
  5. package/dist/abi/evm.gen.js +130 -0
  6. package/dist/abi/functions.gen.js +144 -0
  7. package/dist/abi/index.js +17 -0
  8. package/dist/abi/solana.gen.js +128 -0
  9. package/dist/burn.js +21 -0
  10. package/dist/client/evm/index.js +191 -0
  11. package/dist/client/index.js +19 -0
  12. package/dist/client/solana/index.js +259 -0
  13. package/dist/client/types.js +5 -0
  14. package/dist/codec.js +77 -0
  15. package/dist/config/codeHash.js +9 -0
  16. package/dist/config/generated.js +746 -0
  17. package/dist/config/index.js +49 -0
  18. package/dist/config/registry.gen.js +118 -0
  19. package/dist/config/solana-genesis.js +7 -0
  20. package/dist/ed25519.js +31 -0
  21. package/dist/errors.js +249 -0
  22. package/dist/events/index.js +40 -0
  23. package/dist/events/types.gen.js +3 -0
  24. package/dist/evm/abi.js +283 -0
  25. package/dist/evm/balances.js +26 -0
  26. package/dist/evm/chains.js +144 -0
  27. package/dist/evm/floor/abi.gen.js +195 -0
  28. package/dist/evm/floor/calls.js +230 -0
  29. package/dist/evm/floor/create.js +49 -0
  30. package/dist/evm/floor/events.js +41 -0
  31. package/dist/evm/floor/iface.js +44 -0
  32. package/dist/evm/items.js +209 -0
  33. package/dist/evm/keccak.js +118 -0
  34. package/dist/evm/multicall.js +30 -0
  35. package/dist/evm/router.js +184 -0
  36. package/dist/evm/zap.js +128 -0
  37. package/dist/fixtures.js +53 -0
  38. package/dist/generated/index.js +28 -0
  39. package/dist/generated/interface.gen.js +146 -0
  40. package/dist/handle.js +22 -0
  41. package/dist/index.js +91 -7
  42. package/dist/indexer/bodies.js +473 -0
  43. package/dist/indexer/client.js +104 -0
  44. package/dist/indexer/contract.js +349 -0
  45. package/dist/indexer/decode.js +97 -0
  46. package/dist/indexer/partners.js +100 -0
  47. package/dist/indexer/paths.js +127 -0
  48. package/dist/indexer/read.js +109 -0
  49. package/dist/indexer/stream.js +71 -0
  50. package/dist/lock.js +16 -0
  51. package/dist/math/fixed.js +154 -0
  52. package/dist/math/genesis.js +39 -0
  53. package/dist/math/index.js +20 -0
  54. package/dist/math/u256.js +49 -0
  55. package/dist/math/v2/ask.js +162 -0
  56. package/dist/math/v2/book.js +607 -0
  57. package/dist/math/v2/circulating.js +62 -0
  58. package/dist/math/v2/create.js +122 -0
  59. package/dist/math/v2/display.js +208 -0
  60. package/dist/math/v2/error.js +17 -0
  61. package/dist/math/v2/feasibility.js +174 -0
  62. package/dist/math/v2/fees.js +121 -0
  63. package/dist/math/v2/holders.js +105 -0
  64. package/dist/math/v2/milestones.js +40 -0
  65. package/dist/math/v2/pow.js +69 -0
  66. package/dist/math/v2/preset.js +151 -0
  67. package/dist/math/v2/receipt.js +108 -0
  68. package/dist/math/v2/relay.js +217 -0
  69. package/dist/math/v2/rows.js +365 -0
  70. package/dist/math/v2/split.js +111 -0
  71. package/dist/math/v2/sqrt.js +84 -0
  72. package/dist/math/v2/supply.js +21 -0
  73. package/dist/math/v2/team.js +75 -0
  74. package/dist/math/v2/trade.js +126 -0
  75. package/dist/math/v2/wide.js +51 -0
  76. package/dist/quote.js +6 -0
  77. package/dist/registryPrice.js +23 -0
  78. package/dist/route/edge-jupiter.js +42 -0
  79. package/dist/route/edge.js +11 -0
  80. package/dist/route/graph.js +51 -0
  81. package/dist/route/path.js +75 -0
  82. package/dist/route/quote.js +15 -0
  83. package/dist/route-jupiter.js +35 -0
  84. package/dist/route.js +8 -0
  85. package/dist/sha256.js +61 -0
  86. package/dist/solana/alt.js +18 -0
  87. package/dist/solana/floor/accounts.js +390 -0
  88. package/dist/solana/floor/borsh.js +66 -0
  89. package/dist/solana/floor/create.js +65 -0
  90. package/dist/solana/floor/events.js +140 -0
  91. package/dist/solana/floor/genesis.js +91 -0
  92. package/dist/solana/floor/genesisList.js +68 -0
  93. package/dist/solana/floor/instructions.js +435 -0
  94. package/dist/solana/floor/metadata.js +198 -0
  95. package/dist/solana/floor/mint.js +206 -0
  96. package/dist/solana/floor/program.js +64 -0
  97. package/dist/solana/floor/registry.js +83 -0
  98. package/dist/solana/instruction.js +49 -0
  99. package/dist/solana/pda.js +88 -0
  100. package/dist/solana/tx.js +138 -0
  101. package/dist/v2/burnPreview.js +35 -0
  102. package/dist/v2/circulating.js +11 -0
  103. package/dist/v2/claimAllEvm.js +70 -0
  104. package/dist/v2/claims-evm.js +120 -0
  105. package/dist/v2/claims.js +218 -0
  106. package/dist/v2/dead.js +21 -0
  107. package/dist/v2/devbuy.js +37 -0
  108. package/dist/v2/events.js +115 -0
  109. package/dist/v2/evm.js +299 -0
  110. package/dist/v2/evmReads.js +76 -0
  111. package/dist/v2/genesis.js +76 -0
  112. package/dist/v2/layouts.js +217 -0
  113. package/dist/v2/market-evm.js +74 -0
  114. package/dist/v2/presetRowEvm.js +45 -0
  115. package/dist/v2/press.js +106 -0
  116. package/dist/v2/quoteMint.js +52 -0
  117. package/dist/v2/receipt-tx.js +149 -0
  118. package/dist/v2/route-alt.js +114 -0
  119. package/dist/v2/route.js +389 -0
  120. package/dist/v2/solana.js +391 -0
  121. package/dist/v2/solanaSettle.js +97 -0
  122. package/dist/v2/tx/evm.js +126 -0
  123. package/dist/v2/tx/genesis.js +47 -0
  124. package/dist/v2/tx/index.js +5 -0
  125. package/dist/v2/tx/solana.js +118 -0
  126. package/dist/v2/types.js +13 -0
  127. package/docs/aggregator.md +61 -0
  128. package/docs/bot.md +50 -0
  129. package/docs/frontend.md +29 -0
  130. package/docs/wallet.md +54 -0
  131. package/package.json +428 -32
  132. package/src/abi/evm-event-names.ts +12 -0
  133. package/src/abi/evm.gen.ts +139 -0
  134. package/src/abi/functions.gen.ts +154 -0
  135. package/src/abi/index.ts +30 -0
  136. package/src/abi/solana.gen.ts +138 -0
  137. package/src/burn.ts +37 -0
  138. package/src/client/evm/index.ts +199 -0
  139. package/src/client/index.ts +23 -0
  140. package/src/client/solana/index.ts +260 -0
  141. package/src/client/types.ts +162 -0
  142. package/src/codec.ts +77 -0
  143. package/src/config/codeHash.ts +9 -0
  144. package/src/config/generated.ts +746 -0
  145. package/src/config/index.ts +91 -0
  146. package/src/config/registry.gen.ts +118 -0
  147. package/src/config/solana-genesis.ts +7 -0
  148. package/src/ed25519.ts +31 -0
  149. package/src/errors.ts +270 -0
  150. package/src/events/index.ts +44 -0
  151. package/src/events/types.gen.ts +831 -0
  152. package/src/evm/abi.ts +292 -0
  153. package/src/evm/balances.ts +26 -0
  154. package/src/evm/chains.ts +167 -0
  155. package/src/evm/floor/abi.gen.ts +195 -0
  156. package/src/evm/floor/calls.ts +247 -0
  157. package/src/evm/floor/create.ts +68 -0
  158. package/src/evm/floor/events.ts +51 -0
  159. package/src/evm/floor/iface.ts +45 -0
  160. package/src/evm/items.ts +252 -0
  161. package/src/evm/keccak.ts +118 -0
  162. package/src/evm/multicall.ts +43 -0
  163. package/src/evm/router.ts +209 -0
  164. package/src/evm/zap.ts +152 -0
  165. package/src/fixtures.ts +53 -0
  166. package/src/generated/index.ts +29 -0
  167. package/src/generated/interface.gen.ts +153 -0
  168. package/src/handle.ts +22 -0
  169. package/src/index.ts +91 -6
  170. package/src/indexer/bodies.ts +528 -0
  171. package/src/indexer/client.ts +178 -0
  172. package/src/indexer/contract.ts +410 -0
  173. package/src/indexer/decode.ts +109 -0
  174. package/src/indexer/partners.ts +109 -0
  175. package/src/indexer/paths.ts +190 -0
  176. package/src/indexer/read.ts +119 -0
  177. package/src/indexer/stream.ts +83 -0
  178. package/src/lock.ts +16 -0
  179. package/src/math/fixed.ts +154 -0
  180. package/src/math/genesis.ts +39 -0
  181. package/src/math/index.ts +24 -0
  182. package/src/math/u256.ts +49 -0
  183. package/src/math/v2/ask.ts +218 -0
  184. package/src/math/v2/book.ts +660 -0
  185. package/src/math/v2/circulating.ts +69 -0
  186. package/src/math/v2/create.ts +139 -0
  187. package/src/math/v2/display.ts +250 -0
  188. package/src/math/v2/error.ts +19 -0
  189. package/src/math/v2/feasibility.ts +200 -0
  190. package/src/math/v2/fees.ts +121 -0
  191. package/src/math/v2/holders.ts +124 -0
  192. package/src/math/v2/milestones.ts +51 -0
  193. package/src/math/v2/pow.ts +71 -0
  194. package/src/math/v2/preset.ts +189 -0
  195. package/src/math/v2/receipt.ts +162 -0
  196. package/src/math/v2/relay.ts +235 -0
  197. package/src/math/v2/rows.ts +412 -0
  198. package/src/math/v2/split.ts +160 -0
  199. package/src/math/v2/sqrt.ts +86 -0
  200. package/src/math/v2/supply.ts +27 -0
  201. package/src/math/v2/team.ts +75 -0
  202. package/src/math/v2/trade.ts +145 -0
  203. package/src/math/v2/wide.ts +52 -0
  204. package/src/quote.ts +6 -0
  205. package/src/registryPrice.ts +28 -0
  206. package/src/route/edge-jupiter.ts +71 -0
  207. package/src/route/edge.ts +22 -0
  208. package/src/route/graph.ts +77 -0
  209. package/src/route/path.ts +84 -0
  210. package/src/route/quote.ts +46 -0
  211. package/src/route-jupiter.ts +36 -0
  212. package/src/route.ts +8 -0
  213. package/src/sha256.ts +61 -0
  214. package/src/solana/alt.ts +25 -0
  215. package/src/solana/floor/accounts.ts +393 -0
  216. package/src/solana/floor/borsh.ts +66 -0
  217. package/src/solana/floor/create.ts +89 -0
  218. package/src/solana/floor/events.ts +147 -0
  219. package/src/solana/floor/genesis.ts +111 -0
  220. package/src/solana/floor/genesisList.ts +75 -0
  221. package/src/solana/floor/instructions.ts +491 -0
  222. package/src/solana/floor/metadata.ts +246 -0
  223. package/src/solana/floor/mint.ts +242 -0
  224. package/src/solana/floor/program.ts +64 -0
  225. package/src/solana/floor/registry.ts +96 -0
  226. package/src/solana/instruction.ts +61 -0
  227. package/src/solana/pda.ts +91 -0
  228. package/src/solana/tx.ts +143 -0
  229. package/src/v2/burnPreview.ts +52 -0
  230. package/src/v2/circulating.ts +22 -0
  231. package/src/v2/claimAllEvm.ts +97 -0
  232. package/src/v2/claims-evm.ts +179 -0
  233. package/src/v2/claims.ts +288 -0
  234. package/src/v2/dead.ts +21 -0
  235. package/src/v2/devbuy.ts +55 -0
  236. package/src/v2/events.ts +131 -0
  237. package/src/v2/evm.ts +349 -0
  238. package/src/v2/evmReads.ts +121 -0
  239. package/src/v2/genesis.ts +80 -0
  240. package/src/v2/layouts.ts +219 -0
  241. package/src/v2/market-evm.ts +95 -0
  242. package/src/v2/presetRowEvm.ts +54 -0
  243. package/src/v2/press.ts +124 -0
  244. package/src/v2/quoteMint.ts +63 -0
  245. package/src/v2/receipt-tx.ts +251 -0
  246. package/src/v2/route-alt.ts +114 -0
  247. package/src/v2/route.ts +494 -0
  248. package/src/v2/solana.ts +439 -0
  249. package/src/v2/solanaSettle.ts +117 -0
  250. package/src/v2/tx/evm.ts +152 -0
  251. package/src/v2/tx/genesis.ts +66 -0
  252. package/src/v2/tx/index.ts +5 -0
  253. package/src/v2/tx/solana.ts +140 -0
  254. package/src/v2/types.ts +284 -0
  255. package/dist/adapter.d.ts +0 -28
  256. package/dist/adapter.d.ts.map +0 -1
  257. package/dist/adapter.js +0 -2
  258. package/dist/adapter.js.map +0 -1
  259. package/dist/chain.d.ts +0 -23
  260. package/dist/chain.d.ts.map +0 -1
  261. package/dist/chain.js +0 -25
  262. package/dist/chain.js.map +0 -1
  263. package/dist/client.d.ts +0 -26
  264. package/dist/client.d.ts.map +0 -1
  265. package/dist/client.js +0 -43
  266. package/dist/client.js.map +0 -1
  267. package/dist/dex-adapter.d.ts +0 -228
  268. package/dist/dex-adapter.d.ts.map +0 -1
  269. package/dist/dex-adapter.js +0 -407
  270. package/dist/dex-adapter.js.map +0 -1
  271. package/dist/index.d.ts +0 -7
  272. package/dist/index.d.ts.map +0 -1
  273. package/dist/index.js.map +0 -1
  274. package/dist/quotes.d.ts +0 -12
  275. package/dist/quotes.d.ts.map +0 -1
  276. package/dist/quotes.gen.d.ts +0 -8
  277. package/dist/quotes.gen.d.ts.map +0 -1
  278. package/dist/quotes.gen.js +0 -2170
  279. package/dist/quotes.gen.js.map +0 -1
  280. package/dist/quotes.js +0 -24
  281. package/dist/quotes.js.map +0 -1
  282. package/dist/types.d.ts +0 -111
  283. package/dist/types.d.ts.map +0 -1
  284. package/dist/types.js +0 -2
  285. package/dist/types.js.map +0 -1
  286. package/src/adapter.ts +0 -20
  287. package/src/chain.ts +0 -39
  288. package/src/client.ts +0 -41
  289. package/src/dex-adapter.ts +0 -477
  290. package/src/quotes.gen.ts +0 -2170
  291. package/src/quotes.ts +0 -29
  292. package/src/types.ts +0 -115
@@ -0,0 +1,218 @@
1
+
2
+
3
+ import { addressBytes, base58Encode } from "../codec.js";
4
+ import { computeUnitLimitInstruction, computeUnitPriceInstruction } from "../solana/instruction.js";
5
+
6
+ import { PACKET_DATA_SIZE, compileV0Message, transactionSize } from "../solana/tx.js";
7
+
8
+ import { decodeTeamSlot } from "../solana/floor/accounts.js";
9
+ import { CLAIM_CREATOR, CLAIM_CREATOR_REF, CLAIM_SHARE_BOUGHT, CLAIM_TEAM_BUY, CLAIM_TEAM_SLOT, CLAIM_TRADER_REF } from "../solana/floor/instructions.js";
10
+ import { FLOOR_AMM_PROGRAM_ID, configPda, refOwedPda, refOwedVault } from "../solana/floor/program.js";
11
+ import { TOKEN_2022_PROGRAM_ID, TOKEN_PROGRAM_ID, WSOL_MINT, associatedTokenAddress } from "../solana/pda.js";
12
+ import { CREATOR_BUY_LOCK_SECS, MAX_MEMBERS, splitTeamBuyV2 } from "../math/v2/team.js";
13
+ import { holderSync, holderTake } from "../math/v2/holders.js";
14
+ import { FloorMathError } from "../math/index.js";
15
+ import { decodeHolderBook, decodeHolderPosition, decodeLaunchV2 } from "./layouts.js";
16
+ import { CLAIM_HOLDER, claimInstructionV2 } from "./solana.js";
17
+
18
+ export const MAX_TX_ACCOUNT_LOCKS_V2 = 64;
19
+
20
+ export const CLAIM_COMPUTE_UNIT_LIMIT_V2 = 1_400_000;
21
+
22
+ const MEMBER_IN = 2;
23
+ const KIND_WALLET = 0;
24
+
25
+ export function teamBuyDueV2(createdAt , now ) {
26
+ const c = createdAt < 0n ? 0n : createdAt;
27
+ const due = c + CREATOR_BUY_LOCK_SECS > 0xffff_ffff_ffff_ffffn ? 0xffff_ffff_ffff_ffffn : c + CREATOR_BUY_LOCK_SECS;
28
+ return now >= due;
29
+ }
30
+
31
+ export function holderOwedNowV2(p ) {
32
+ if (!p.positionData) return 0n;
33
+ const pos = decodeHolderPosition(p.positionData) ;
34
+ const book = decodeHolderBook(p.bookData) ;
35
+ if (pos.launch !== book.launch) throw new RangeError("this HolderPosition is not the book's launch");
36
+ const b = { index: book.index , w: book.w , carry: book.carry , bookedTotal: book.bookedTotal , paidTotal: book.paidTotal };
37
+ const q = { amount: pos.amount , owed: pos.owed , indexSnap: pos.indexSnap , optedOut: false };
38
+ holderSync(b, q, p.balance);
39
+ return holderTake(b, q);
40
+ }
41
+
42
+ export const claimBitsV2 = (o ) =>
43
+ (o.creator > 0n ? CLAIM_CREATOR : 0) | (o.creatorRef > 0n ? CLAIM_CREATOR_REF : 0) | (o.teamSlot > 0n ? CLAIM_TEAM_SLOT : 0) |
44
+ (o.teamBuy > 0n ? CLAIM_TEAM_BUY : 0) | (o.shareBought > 0n ? CLAIM_SHARE_BOUGHT : 0) | (o.holder > 0n ? CLAIM_HOLDER : 0);
45
+ const quoteOf = (o ) => o.creator + o.creatorRef + o.teamSlot + o.holder;
46
+
47
+ export function launchOwedV2(p
48
+
49
+ ) {
50
+ const a = decodeLaunchV2(p.launchData);
51
+ const owed = { creator: 0n, creatorRef: 0n, teamSlot: 0n, teamBuy: 0n, shareBought: 0n, holder: p.holderOwed ?? 0n };
52
+ const places = Array(MAX_MEMBERS).fill(false);
53
+ if (a.creator === p.wallet) {
54
+ owed.creator = a.creatorOwed;
55
+ places[0] = true;
56
+ }
57
+ (a.creatorRef ).forEach((r, i) => {
58
+ if (r === p.wallet) owed.creatorRef += a.creatorRefOwed[i];
59
+ });
60
+ if (p.teamSlot) {
61
+ const t = decodeTeamSlot(p.teamSlot.data);
62
+ if (t.launch !== p.launch) throw new RangeError("this TeamSlot is not the launch's");
63
+ const k = addressBytes(p.wallet);
64
+ const i = (t.members ).findIndex((m) => m.state === MEMBER_IN && m.kind === KIND_WALLET && (m.key ).every((x, j) => x === k[j]));
65
+ if (i >= 0) {
66
+ owed.teamSlot = a.slotOwed[i];
67
+ places[i] = true;
68
+ }
69
+ }
70
+ const createdAt = a.createdAt < 0n ? 0n : (a.createdAt );
71
+ let buy = a.teamBuyOwed.slice();
72
+ const due = teamBuyDueV2(a.createdAt, p.now);
73
+ if (a.creatorLocked > 0n) {
74
+ try {
75
+ const split = splitTeamBuyV2(a.creatorLocked, a.slotWeightPpb, createdAt, p.now);
76
+ buy = buy.map((x, i) => x + split[i]);
77
+ } catch (e) {
78
+ if (!(e instanceof FloorMathError && e.code === "NotDue")) throw e;
79
+ }
80
+ }
81
+ for (let i = 0; i < MAX_MEMBERS; i++) {
82
+ if (!places[i]) continue;
83
+ if (due) owed.teamBuy += buy[i];
84
+ owed.shareBought += a.slotBoughtOwed[i];
85
+ }
86
+ return {
87
+ launch: p.launch, quoteMint: a.quoteMint, quoteTokenProgram: a.quoteTokenProgram, quoteVault: a.quoteVault, baseMint: a.baseMint,
88
+ tokenVault: a.tokenVault, teamSlot: p.teamSlot?.address ?? null, owed,
89
+ };
90
+ }
91
+
92
+ function locksOf(payer , ixs ) {
93
+ const s = new Set ([payer]);
94
+ for (const ix of ixs) {
95
+ s.add(ix.programAddress);
96
+ for (const a of ix.accounts) s.add(a.address);
97
+ }
98
+ return s.size;
99
+ }
100
+
101
+ export function planClaimAllV2(p
102
+
103
+  
104
+
105
+ ) {
106
+ const sender = p.sender ?? p.wallet;
107
+ const skipped = [];
108
+
109
+ const byQuote = new Map ();
110
+ const group = (q , tp ) => {
111
+ let g = byQuote.get(q);
112
+ if (!g) byQuote.set(q, (g = { tp, classes: new Map(), refs: 0n }));
113
+ return g;
114
+ };
115
+ const classOf = (o ) => (o.teamBuy > 0n || o.shareBought > 0n ? 1 : 0) | (o.holder > 0n ? 2 : 0);
116
+ for (const l of p.launches) {
117
+ if (claimBitsV2(l.owed) === 0) {
118
+ skipped.push(l.launch);
119
+ continue;
120
+ }
121
+ const g = group(l.quoteMint, l.quoteTokenProgram);
122
+ const c = classOf(l.owed);
123
+ if (!g.classes.has(c)) g.classes.set(c, []);
124
+ g.classes.get(c) .push(l);
125
+ }
126
+ for (const r of p.refOwed ?? []) {
127
+ if (r.owed === 0n) {
128
+ skipped.push(`ref_owed:${r.quoteMint}`);
129
+ continue;
130
+ }
131
+ const known = byQuote.get(r.quoteMint);
132
+ if (!known && !r.quoteTokenProgram) throw new RangeError(`the RefOwed in ${r.quoteMint} needs its quote's token program`);
133
+ group(r.quoteMint, known?.tp ?? r.quoteTokenProgram ).refs = r.owed;
134
+ }
135
+ const pid = p.programId ?? FLOOR_AMM_PROGRAM_ID;
136
+ const budget = () => [computeUnitLimitInstruction(p.computeUnitLimit ?? CLAIM_COMPUTE_UNIT_LIMIT_V2), ...(p.microLamports !== undefined ? [computeUnitPriceInstruction(p.microLamports)] : [])];
137
+ const fits = (t ) => t.size <= PACKET_DATA_SIZE && t.locks <= MAX_TX_ACCOUNT_LOCKS_V2;
138
+ const txs = [];
139
+ for (const [quoteMint, g] of byQuote) {
140
+ const unwrap = (p.unwrapSol ?? true) && quoteMint === WSOL_MINT && g.tp === TOKEN_PROGRAM_ID;
141
+ const build = (ls , refs ) => {
142
+ const types = ls.reduce((a, l) => a | claimBitsV2(l.owed), 0) | (refs > 0n ? CLAIM_TRADER_REF : 0);
143
+ const tok = (types & (CLAIM_TEAM_BUY | CLAIM_SHARE_BOUGHT)) !== 0;
144
+ const ro = refOwedPda(p.wallet, quoteMint, pid)[0];
145
+ const claim = claimInstructionV2({
146
+ sender, wallet: p.wallet, quoteMint, quoteTokenProgram: g.tp, destination: associatedTokenAddress(p.wallet, quoteMint, g.tp),
147
+ config: configPda(pid)[0], refOwed: refs > 0n ? ro : null, refOwedVault: refs > 0n ? refOwedVault(ro, quoteMint, g.tp) : null, types,
148
+ launches: ls.map((l) => ({
149
+ launch: l.launch, quoteVault: l.quoteVault, teamSlot: l.teamSlot, baseMint: l.baseMint,
150
+ ...(tok ? { teamBuy: { baseMint: l.baseMint, tokenVault: l.tokenVault, walletBase: associatedTokenAddress(p.wallet, l.baseMint, TOKEN_2022_PROGRAM_ID) } } : {}),
151
+ })),
152
+ unwrap, quoteIsLaunch: p.launchQuotes?.includes(quoteMint) ?? false, programId: p.programId, hookProgramId: p.hookProgramId,
153
+ });
154
+ const instructions = [...budget(), claim];
155
+ const message = compileV0Message({ payer: sender, instructions, recentBlockhash: p.recentBlockhash, lookupTables: p.lookupTables });
156
+ return {
157
+ quoteMint, instructions, message, size: transactionSize(message), locks: locksOf(sender, instructions), launches: ls.map((l) => l.launch),
158
+ refOwed: refs > 0n, types, unwrap, amount: ls.reduce((a, l) => a + quoteOf(l.owed), 0n) + refs, tokens: ls.reduce((a, l) => a + l.owed.teamBuy + l.owed.shareBought, 0n),
159
+ };
160
+ };
161
+ const alone = (ls , refs , what ) => {
162
+ const t = build(ls, refs);
163
+ if (!fits(t)) throw new RangeError(`${what} alone does not fit one transaction`);
164
+ return t;
165
+ };
166
+ let refs = g.refs;
167
+ for (const c of [...g.classes.keys()].sort()) {
168
+ let cur = [];
169
+ let last = null;
170
+ for (const l of g.classes.get(c) ) {
171
+ const t = build([...cur, l], refs);
172
+ if (fits(t)) {
173
+ cur.push(l);
174
+ last = t;
175
+ continue;
176
+ }
177
+ if (cur.length === 0 && refs > 0n) {
178
+
179
+ txs.push(alone([], refs, "the referral claim"));
180
+ refs = 0n;
181
+ } else if (cur.length === 0) throw new RangeError(`launch ${l.launch} alone does not fit one transaction`);
182
+ else {
183
+ txs.push(last );
184
+ refs = 0n;
185
+ }
186
+ cur = [l];
187
+ last = alone(cur, 0n, `launch ${l.launch}`);
188
+ }
189
+ if (last) {
190
+ txs.push(last);
191
+ refs = 0n;
192
+ }
193
+ }
194
+ if (refs > 0n) txs.push(alone([], refs, "the referral claim"));
195
+ }
196
+ return { transactions: txs, skipped };
197
+ }
198
+
199
+ export function claimLaunchesPerTxV2(p = {}) {
200
+ const key = (i ) => {
201
+ const b = new Uint8Array(32);
202
+ b[0] = 0xf1;
203
+ b[1] = i & 0xff;
204
+ b[2] = i >> 8;
205
+ return base58Encode(b);
206
+ };
207
+ const quoteMint = p.quoteMint ?? key(0xfff0);
208
+ const quoteTokenProgram = p.quoteTokenProgram ?? TOKEN_PROGRAM_ID;
209
+ const measure = (o ) => {
210
+ const launches = Array.from({ length: 64 }, (_, i) => ({
211
+ launch: key(i), quoteMint, quoteTokenProgram, quoteVault: key(0x100 + i), baseMint: key(0x200 + i), tokenVault: key(0x300 + i), teamSlot: key(0x400 + i),
212
+ owed: { creator: 0n, creatorRef: 0n, teamSlot: 0n, teamBuy: 0n, shareBought: 0n, holder: 0n, ...o },
213
+ }));
214
+ const plan = planClaimAllV2({ wallet: key(0xfff1), launches, recentBlockhash: key(0xfff2), lookupTables: p.lookupTables, microLamports: p.microLamports, programId: p.programId, hookProgramId: p.hookProgramId });
215
+ return plan.transactions[0].launches.length;
216
+ };
217
+ return { plain: measure({ creator: 1n, teamSlot: 1n }), tokens: measure({ creator: 1n, teamBuy: 1n }), holder: measure({ holder: 1n }), both: measure({ teamBuy: 1n, holder: 1n }) };
218
+ }
@@ -0,0 +1,21 @@
1
+
2
+
3
+ export const SOLANA_DEAD_OWNERS = [
4
+ "1nc1nerator11111111111111111111111111111111",
5
+ "11111111111111111111111111111111",
6
+ ];
7
+
8
+ export const EVM_DEAD_ADDRESSES = [
9
+ "0x0000000000000000000000000000000000000000",
10
+ "0x000000000000000000000000000000000000dead",
11
+ "0x0000000000000000000000000000000000000001",
12
+ "0xdead000000000000000042069420694206942069",
13
+ ];
14
+
15
+ export function isSolanaDeadOwner(owner ) {
16
+ return SOLANA_DEAD_OWNERS.includes(owner);
17
+ }
18
+
19
+ export function isEvmDead(address ) {
20
+ return EVM_DEAD_ADDRESSES.includes(address.toLowerCase());
21
+ }
@@ -0,0 +1,37 @@
1
+
2
+
3
+ import { base58Encode } from "../codec.js";
4
+ import { SLOT_ACTIVE } from "../solana/floor/accounts.js";
5
+ import { TEAM_SLOT_WALLET } from "../solana/floor/instructions.js";
6
+ import { priceX64 } from "../math/v2/sqrt.js";
7
+ import { TRADE_KIND_TEAM_BUY, TRADE_KIND_TEAM_SHARE_BUY } from "./events.js";
8
+
9
+  
10
+
11
+    
12
+
13
+            
14
+
15
+ export function teamSlotWallets(slot ) {
16
+ return (slot?.members ?? []).filter((m) => m.kind === TEAM_SLOT_WALLET && m.state === SLOT_ACTIVE).map((m) => base58Encode(m.key));
17
+ }
18
+
19
+ export const impactBps = (before , after ) => (before === 0n ? 0n : ((after - before) * 10_000n) / before);
20
+
21
+ export function devBuyFromTrade(t , team , ctx = {}) {
22
+ if (!t.isBuy) return null;
23
+ let role = null;
24
+ if (t.kind === TRADE_KIND_TEAM_BUY || ctx.teamBuy) role = "team_buy";
25
+ else if (t.kind === TRADE_KIND_TEAM_SHARE_BUY || ctx.teamShareBuy) role = "team_share_buy";
26
+ else if (t.trader === team.creator) role = "creator";
27
+ else if (teamSlotWallets(team.teamSlot).includes(t.trader)) role = "team_member";
28
+ if (role === null) return null;
29
+ const priceBeforeX64 = priceX64(t.sqrtBefore);
30
+ const priceAfterX64 = priceX64(t.sqrtAfter);
31
+ return {
32
+ launch: t.launch, trader: t.trader, role, quoteIn: t.quoteGross - t.refund, tokens: t.tokens, priceBeforeX64, priceAfterX64,
33
+ impactBps: impactBps(priceBeforeX64, priceAfterX64), slot: t.slot,
34
+ };
35
+ }
36
+
37
+ export const devBuyChangeSinceBps = (d , sqrtNow ) => impactBps(d.priceAfterX64, priceX64(sqrtNow));
@@ -0,0 +1,115 @@
1
+
2
+
3
+ import { hex } from "../codec.js";
4
+ import { EVENT_IX_TAG_LE, eventDiscriminator } from "../solana/instruction.js";
5
+ import { Reader, Writer } from "../solana/floor/borsh.js";
6
+
7
+ const S = (...f ) => f;
8
+
9
+ export const EVENTS_V2 = {
10
+
11
+ LaunchCreatedV2: S(["launch", "pubkey"], ["mint", "pubkey"], ["quoteMint", "pubkey"], ["creator", "pubkey"], ["id", "u64"], ["presetId", "u8"], ["presetVersion", "u32"], ["presetHash", "bytes:32"],
12
+ ["p0X64", "u128"], ["raise", "u64"], ["windowTokens", "u64"], ["creatorBuyTokens", "u64"], ["createFee", "u64"], ["name", "bytes:32"], ["symbol", "bytes:10"], ["slot", "u64"], ["ts", "i64"],
13
+ ["listed", "bool"], ["quoteUsdCentsX64", "u128"], ["nativeCreateFee", "u64"], ["rowVersion", "u8"], ["sqrtP0", "u128"]),
14
+ Trade: S(["launch", "pubkey"], ["trader", "pubkey"], ["isBuy", "bool"], ["quoteGross", "u64"], ["quoteNet", "u64"], ["refund", "u64"], ["tokens", "u64"], ["fees", "u64[5]"], ["traderRef", "u64"], ["fromResale", "u64"], ["fromFirst", "u64"], ["unfilled", "u64"], ["sqrtBefore", "u128"], ["sqrtAfter", "u128"], ["sqrtF", "u128"], ["floor", "u64"], ["cushion", "u64"], ["sCirc", "u64"], ["steps", "u8"], ["budgetHit", "bool"], ["slot", "u64"], ["ts", "i64"],
15
+
16
+ ["kind", "u8"],
17
+
18
+ ["creatorRef", "u64"],
19
+
20
+ ["recipient", "pubkey"],
21
+
22
+ ["bidMoney", "u64"], ["msPaid", "u64[4]"]),
23
+ HolderPositionOpened: S(["launch", "pubkey"], ["owner", "pubkey"], ["amount", "u64"]),
24
+ HolderPositionClosed: S(["launch", "pubkey"], ["owner", "pubkey"], ["amount", "u64"], ["paid", "u64"]),
25
+ HolderIndexRolled: S(["launch", "pubkey"], ["index", "u128"], ["wMatured", "u64"], ["wPending", "u64"], ["carry", "u64"]),
26
+ DeadSynced: S(["launch", "pubkey"], ["added", "u64"], ["deadTokens", "u64"], ["sCirc", "u64"]),
27
+ };
28
+
29
+ EVENTS_V2.GenesisRaiseBought = EVENTS_V2.Trade;
30
+
31
+ export const TRADE_KIND_ORDINARY = 0;
32
+ export const TRADE_KIND_TEAM_BUY = 1;
33
+ export const TRADE_KIND_TEAM_SHARE_BUY = 2;
34
+ export const TRADE_KIND_GENESIS_RAISE = 3;
35
+ export const TRADE_KIND_GENESIS_SHARE = 4;
36
+ export const TRADE_KIND_GENESIS_OVERFLOW = 5;
37
+ export const TRADE_KIND_GENESIS_OVERFLOW_SHARE = 6;
38
+
39
+ export const isPersonTradeV2 = (kind ) => kind !== TRADE_KIND_GENESIS_RAISE && kind !== TRADE_KIND_GENESIS_OVERFLOW;
40
+
41
+ export const movesBookV2 = (kind ) => kind !== TRADE_KIND_GENESIS_SHARE && kind !== TRADE_KIND_GENESIS_OVERFLOW_SHARE;
42
+
43
+ export const FEE_LEGS_V2 = ["backing", "team", "platform", "floor", "holder"] ;
44
+ export const MS_CLASSES_V2 = ["team", "holder", "platform", "floor"] ;
45
+
46
+ let disc ;
47
+
48
+ const PRE_CUTOVER = [["TradeV2", "Trade"]];
49
+ const DISC = () =>
50
+ (disc ??= new Map([...Object.keys(EVENTS_V2).map((n) => [hex(eventDiscriminator(n)), n]), ...PRE_CUTOVER.map(([a, n]) => [hex(eventDiscriminator(a)), n])]));
51
+
52
+ function read(r , t ) {
53
+ const bm = /^bytes:(\d+)$/.exec(t);
54
+ if (bm) return r.bytes(Number(bm[1]));
55
+ const m = /^u64\[(\d)\]$/.exec(t);
56
+ if (m) return Array.from({ length: Number(m[1]) }, () => r.u64());
57
+ return (r )[t]();
58
+ }
59
+ function write(w , t , v ) {
60
+ const bm = /^bytes:(\d+)$/.exec(t);
61
+ if (bm) {
62
+ if (v.length !== Number(bm[1])) throw new RangeError(`${t}: ${v.length} bytes`);
63
+ w.bytes(v);
64
+ return;
65
+ }
66
+ const m = /^u64\[(\d)\]$/.exec(t);
67
+ if (m) {
68
+ if (v.length !== Number(m[1])) throw new RangeError(`${t}: ${v.length} values`);
69
+ for (const x of v) w.u64(x);
70
+ } else if (t === "i64") w.uint(BigInt.asUintN(64, v), 8);
71
+ else (w )[t](v);
72
+ }
73
+
74
+ export function decodeEventDataV2(data ) {
75
+ const name = DISC().get(hex(data.slice(0, 8)));
76
+ if (!name) return null;
77
+ const r = new Reader(data.slice(8));
78
+ const fields = {};
79
+ for (const [f, t] of EVENTS_V2[name]) fields[f] = read(r, t);
80
+ if (r.o !== r.b.length) throw new RangeError(`${name}: ${r.b.length} body bytes, the schema reads ${r.o}`);
81
+ return { name, fields };
82
+ }
83
+
84
+ export function encodeEventDataV2(e ) {
85
+ const w = new Writer().bytes(eventDiscriminator(e.name));
86
+ for (const [f, t] of EVENTS_V2[e.name] ?? []) write(w, t, e.fields[f]);
87
+ return w.done();
88
+ }
89
+
90
+ export function decodeEventCpiV2(ixData ) {
91
+ if (ixData.length < 16 || hex(ixData.slice(0, 8)) !== hex(EVENT_IX_TAG_LE)) return null;
92
+ return decodeEventDataV2(ixData.slice(8));
93
+ }
94
+
95
+ export function platformWithdrawalsV2(events ) {
96
+ const by = new Map ();
97
+ const row = (launch ) => {
98
+ let r = by.get(launch);
99
+ if (!r) by.set(launch, (r = { launch, platform: 0n, cut: 0n, paid: 0n, platformOwedAfter: 0n, cutOwedAfter: 0n }));
100
+ return r;
101
+ };
102
+ for (const e of events) {
103
+ if (e.name === "PlatformWithdrawn") {
104
+ const r = row(e.fields.launch);
105
+ r.platform += e.fields.amount;
106
+ r.platformOwedAfter = e.fields.owedAfter;
107
+ } else if (e.name === "CutWithdrawn") {
108
+ const r = row(e.fields.launch);
109
+ r.cut += e.fields.amount;
110
+ r.cutOwedAfter = e.fields.cutOwedAfter;
111
+ }
112
+ }
113
+ for (const r of by.values()) r.paid = r.platform + r.cut;
114
+ return [...by.values()];
115
+ }