@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,491 @@
1
+
2
+
3
+ import { R, RS, W, WS, instructionDiscriminator } from "../instruction.ts";
4
+ import type { AccountMeta, Instruction } from "../instruction.ts";
5
+ import { SYSTEM_PROGRAM_ID, TOKEN_2022_PROGRAM_ID, TOKEN_PROGRAM_ID, ASSOCIATED_TOKEN_PROGRAM_ID, WSOL_MINT, associatedTokenAddress } from "../pda.ts";
6
+ import {
7
+ FLOOR_AMM_PROGRAM_ID, GENESIS_USDC_MINT, INSTRUCTIONS_SYSVAR_ID, METADATA_PROGRAM_ID, configPda, floorEventAuthorityPda, genesisAllocPda, genesisConvertBandPda, genesisMigrationVaultPda, genesisRaisePda, genesisRaiseTokenVault,
8
+ genesisVaultFloor, genesisVaultUsdc, launchPda, metadataPda, presetPda, quoteEntryPda, teamSlotPda, traderLinkPda,
9
+ } from "./program.ts";
10
+ import { Writer } from "./borsh.ts";
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.ts";
12
+ import { launchMintPda } from "./mint.ts";
13
+
14
+ export type { Ctx } from "../../v2/solana.ts";
15
+ import type { Ctx } from "../../v2/solana.ts";
16
+
17
+ const pid = (c?: Ctx): string => c?.programId ?? FLOOR_AMM_PROGRAM_ID;
18
+ const evPair = (c?: Ctx): AccountMeta[] => [R(floorEventAuthorityPda(pid(c))[0]), R(pid(c))];
19
+ function ix(name: string, accounts: AccountMeta[], args: (w: Writer) => Writer, c?: Ctx): Instruction {
20
+ const w = new Writer().bytes(instructionDiscriminator(name));
21
+ return { programAddress: pid(c), accounts: [...accounts, ...evPair(c)], data: args(w).done() };
22
+ }
23
+ const none = (w: Writer): Writer => w;
24
+
25
+ const withRest = (i: Instruction, rest: AccountMeta[]): Instruction => (rest.length ? { ...i, accounts: [...i.accounts, ...rest] } : i);
26
+
27
+ export function initializeConfigInstruction(p: { upgradeAuthority: string; config: string; programData: string; authority: string; timelock: string; referralAuthority: string } & Ctx): Instruction {
28
+ return ix("initialize_config", [WS(p.upgradeAuthority), W(p.config), R(p.programData), R(SYSTEM_PROGRAM_ID)], (w) => w.pubkey(p.authority).pubkey(p.timelock).pubkey(p.referralAuthority), p);
29
+ }
30
+ export function transferAuthorityInstruction(p: { authority: string; config: string; newAuthority: string } & Ctx): Instruction {
31
+ return ix("transfer_authority", [RS(p.authority), W(p.config)], (w) => w.pubkey(p.newAuthority), p);
32
+ }
33
+ export function acceptAuthorityInstruction(p: { signer: string; config: string } & Ctx): Instruction {
34
+ return ix("accept_authority", [RS(p.signer), W(p.config)], none, p);
35
+ }
36
+
37
+ export function setTreasuryInstruction(p: { signer: string; config: string; treasury: string } & Ctx): Instruction {
38
+ return ix("set_treasury", [RS(p.signer), W(p.config)], (w) => w.pubkey(p.treasury), p);
39
+ }
40
+
41
+ export function setPriceUpdaterInstruction(p: { authority: string; config: string; priceUpdater: string } & Ctx): Instruction {
42
+ return ix("set_price_updater", [RS(p.authority), W(p.config)], (w) => w.pubkey(p.priceUpdater), p);
43
+ }
44
+
45
+ export function setQuotePriceInstruction(p: { priceUpdater: string; config: string; quoteMint: string; quote?: string; usdCentsX64: bigint } & Ctx): Instruction {
46
+ if (p.usdCentsX64 <= 0n || p.usdCentsX64 >= 1n << 128n) throw new RangeError("usdCentsX64 is in (0, 2^128 - 1] (BadArgument)");
47
+ const quote = p.quote ?? quoteEntryPda(p.quoteMint, pid(p))[0];
48
+ return ix("set_quote_price", [RS(p.priceUpdater), R(p.config), R(p.quoteMint), W(quote)], (w) => w.u128(p.usdCentsX64), p);
49
+ }
50
+ export function setTimelockInstruction(p: { signer: string; config: string; timelock: string } & Ctx): Instruction {
51
+ return ix("set_timelock", [RS(p.signer), W(p.config)], (w) => w.pubkey(p.timelock), p);
52
+ }
53
+
54
+ export function setCreatePausedInstruction(p: { authority: string; config: string; paused: boolean } & Ctx): Instruction {
55
+ return ix("set_create_paused", [RS(p.authority), W(p.config)], (w) => w.bool(p.paused), p);
56
+ }
57
+ export function setReferralAuthorityInstruction(p: { authority: string; config: string; referralAuthority: string } & Ctx): Instruction {
58
+ return ix("set_referral_authority", [RS(p.authority), W(p.config)], (w) => w.pubkey(p.referralAuthority), p);
59
+ }
60
+
61
+ export function setHolderDestInstruction(p: { authority: string; config: string; holderDest: string } & Ctx): Instruction {
62
+ return ix("set_holder_dest", [RS(p.authority), W(p.config)], (w) => w.pubkey(p.holderDest), p);
63
+ }
64
+
65
+ export function withdrawHolderInstruction(p: { authority: string; config: string; launch: string; quoteMint: string; quoteVault: string; destination: string; quoteTokenProgram: string; amount: bigint } & Ctx): Instruction {
66
+ return ix("withdraw_holder", [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);
67
+ }
68
+
69
+ export function withdrawHolderManyInstruction(p: { authority: string; config: string; quoteMint: string; destination: string; quoteTokenProgram: string; launches: readonly { launch: string; quoteVault: string }[] } & Ctx): Instruction {
70
+ if (p.launches.length === 0) throw new RangeError("withdraw_holder_many: no launch");
71
+ const base = ix("withdraw_holder_many", [RS(p.authority), R(p.config), R(p.quoteMint), W(p.destination), R(p.quoteTokenProgram)], (w) => w.u8(p.launches.length), p);
72
+ return { ...base, accounts: [...base.accounts, ...p.launches.flatMap((l) => [W(l.launch), W(l.quoteVault)])] };
73
+ }
74
+
75
+ export function clearTraderRefInstruction(p: { authority: string; config: string; trader: string; traderLink?: string; traderRefs?: string[] } & Ctx): Instruction {
76
+ const i = ix("clear_trader_ref", [RS(p.authority), R(p.config), W(p.traderLink ?? traderLinkPda(p.trader, p.programId)[0])], none, p);
77
+ return withRest(i, (p.traderRefs ?? []).map((r) => W(r)));
78
+ }
79
+
80
+ export function withdrawPlatformInstruction(p: { authority: string; config: string; launch: string; quoteMint: string; quoteVault: string; destination: string; quoteTokenProgram: string; amount: bigint } & Ctx): Instruction {
81
+ 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);
82
+ }
83
+
84
+ export function checkPresetInstruction(p: { authority: string; config: string; preset: string; id: number } & Ctx): Instruction {
85
+ return ix("check_preset", [RS(p.authority), R(p.config), W(p.preset)], (w) => w.u8(p.id), p);
86
+ }
87
+
88
+ export function setPresetEnabledInstruction(p: { authority: string; config: string; preset: string; id: number; enabled: boolean } & Ctx): Instruction {
89
+ return ix("set_preset_enabled", [RS(p.authority), R(p.config), W(p.preset)], (w) => w.u8(p.id).bool(p.enabled), p);
90
+ }
91
+ export function deletePresetInstruction(p: { authority: string; config: string; preset: string; id: number } & Ctx): Instruction {
92
+ return ix("delete_preset", [RS(p.authority), R(p.config), W(p.preset)], (w) => w.u8(p.id), p);
93
+ }
94
+
95
+ export function addQuoteInstruction(p: { authority: string; config: string; mint: string; quote: string; createFee: bigint; usdCentsX64: bigint; admittedCaps?: number } & Ctx): Instruction {
96
+ return ix("add_quote", [WS(p.authority), R(p.config), R(p.mint), W(p.quote), R(SYSTEM_PROGRAM_ID)], (w) => w.u64(p.createFee).u128(p.usdCentsX64).u32(p.admittedCaps ?? 0), p);
97
+ }
98
+
99
+ export function setQuoteCapsInstruction(p: { authority: string; config: string; quote: string; admittedCaps: number } & Ctx): Instruction {
100
+ return ix("set_quote_caps", [RS(p.authority), R(p.config), W(p.quote)], (w) => w.u32(p.admittedCaps), p);
101
+ }
102
+ export function updateQuoteInstruction(p: { authority: string; config: string; quote: string; enabled: boolean; createFee: bigint; usdCentsX64: bigint } & Ctx): Instruction {
103
+ return ix("update_quote", [RS(p.authority), R(p.config), W(p.quote)], (w) => w.bool(p.enabled).u64(p.createFee).u128(p.usdCentsX64), p);
104
+ }
105
+
106
+ export const MAX_NAME_LEN = 32;
107
+ export const MAX_SYMBOL_LEN = 10;
108
+ export const MAX_URI_LEN = 200;
109
+
110
+ export const MAX_METADATA_BASE_LEN = 72;
111
+ export const METADATA_BASE_SCHEMES = ["https://", "ipfs://", "ar://"] as const;
112
+
113
+ export function metadataBaseOk(base: string): boolean {
114
+ if (base === "") return true;
115
+ return (
116
+ base.length <= MAX_METADATA_BASE_LEN &&
117
+ METADATA_BASE_SCHEMES.some((s) => base.startsWith(s) && base.length > s.length) &&
118
+ /^[\x21-\x7e]+$/.test(base) &&
119
+ !base.endsWith("/")
120
+ );
121
+ }
122
+
123
+ export const metadataUri = (base: string, baseMint: string): string => `${base}/${baseMint}.json`;
124
+
125
+ export function setMetadataBaseInstruction(p: { authority: string; config: string; base: string } & Ctx): Instruction {
126
+ if (!metadataBaseOk(p.base)) throw new RangeError("the metadata base is \"\" or https:// · ipfs:// · ar://, printable ASCII, no space, no trailing slash, ≤ 72 bytes");
127
+ return ix("set_metadata_base", [RS(p.authority), W(p.config)], (w) => w.string(p.base), p);
128
+ }
129
+
130
+ export interface CreateMintAccounts {
131
+ mintNonce: bigint;
132
+ baseMint: string;
133
+ launch: string;
134
+ tokenVault: string;
135
+ quoteVault: string;
136
+ metadata: string;
137
+ }
138
+
139
+ export function createMintAccounts(p: { creator: string; quoteMint: string; quoteTokenProgram: string; baseMint?: string; launch?: string; tokenVault?: string; quoteVault?: string; metadata?: string; args: { mintNonce: bigint } } & Ctx): CreateMintAccounts {
140
+ const nonce = p.args.mintNonce;
141
+ if (typeof nonce !== "bigint") throw new RangeError("args.mintNonce (a u64 bigint) is required: the mint is the PDA [\"mint\", creator, mintNonce LE]");
142
+ const baseMint = launchMintPda(p.creator, nonce, pid(p))[0];
143
+ if (p.baseMint !== undefined && p.baseMint !== baseMint) throw new RangeError(`baseMint ${p.baseMint} is not the creator's mint PDA for nonce ${nonce} (${baseMint})`);
144
+ const launch = p.launch ?? launchPda(baseMint, pid(p))[0];
145
+ return {
146
+ mintNonce: nonce,
147
+ baseMint,
148
+ launch,
149
+ tokenVault: p.tokenVault ?? associatedTokenAddress(launch, baseMint, TOKEN_2022_PROGRAM_ID),
150
+ quoteVault: p.quoteVault ?? associatedTokenAddress(launch, p.quoteMint, p.quoteTokenProgram),
151
+ metadata: p.metadata ?? metadataPda(baseMint)[0],
152
+ };
153
+ }
154
+
155
+ export interface TradeAccounts {
156
+ trader: string;
157
+ launch: string;
158
+ baseMint: string;
159
+ quoteMint: string;
160
+ tokenVault: string;
161
+ quoteVault: string;
162
+ traderBase: string;
163
+ traderQuote: string;
164
+ quoteTokenProgram: string;
165
+ traderRef?: string | null;
166
+ escrow?: string | null;
167
+
168
+ user?: string | null;
169
+
170
+ linkWallet?: string | null;
171
+
172
+ recipient?: string | null;
173
+ }
174
+
175
+ export function initTeamSlotInstruction(p: { creator: string; launch: string; quote: string; teamSlot: string; rateBps: number } & Ctx): Instruction {
176
+ return ix("init_team_slot", [WS(p.creator), W(p.launch), R(p.quote), W(p.teamSlot), R(SYSTEM_PROGRAM_ID)], (w) => w.u16(p.rateBps), p);
177
+ }
178
+ interface TeamSlotPayment {
179
+ payer: string;
180
+ launch: string;
181
+ teamSlot: string;
182
+ quoteMint: string;
183
+ payerQuote: string;
184
+ quoteVault: string;
185
+ quoteTokenProgram: string;
186
+
187
+ baseMint: string;
188
+ }
189
+ const slotPay = (a: TeamSlotPayment): AccountMeta[] => [WS(a.payer), W(a.launch), W(a.teamSlot), R(a.quoteMint), W(a.payerQuote), W(a.quoteVault), R(a.quoteTokenProgram), R(a.baseMint)];
190
+ export const TEAM_SLOT_WALLET = 0;
191
+ export const TEAM_SLOT_PENDING_HANDLE = 1;
192
+ export function teamSlotAddInstruction(p: TeamSlotPayment & { key: string; kind: number; amount: bigint; payNow: boolean } & Ctx): Instruction {
193
+ return ix("team_slot_add", slotPay(p), (w) => w.pubkey(p.key).u8(p.kind).u64(p.amount).bool(p.payNow), p);
194
+ }
195
+
196
+ export function bindHandleInstruction(p: { referralAuthority: string; config: string; launch: string; teamSlot: string; index: number; handle: Uint8Array; wallet: string } & Ctx): Instruction {
197
+ if (p.handle.length !== 32) throw new RangeError("a handle is 32 bytes");
198
+
199
+ return ix("bind_handle", [RS(p.referralAuthority), R(p.config), R(p.launch), W(p.teamSlot), RS(p.wallet)], (w) => w.u8(p.index).bytes(p.handle).pubkey(p.wallet), p);
200
+ }
201
+
202
+ export function openTraderRefInstruction(p: { payer: string; referralAuthority: string; config: string; quoteMint: string; traderRef: string; escrow: string; quoteTokenProgram: string; trader: string; tiers: [string, string, string]; withLink?: boolean } & Ctx): Instruction {
203
+ return withRest(
204
+ ix(
205
+ "open_trader_ref",
206
+ [WS(p.payer), RS(p.referralAuthority), R(p.config), R(p.quoteMint), W(p.traderRef), W(p.escrow), R(p.quoteTokenProgram), R(ASSOCIATED_TOKEN_PROGRAM_ID), R(SYSTEM_PROGRAM_ID), RS(p.trader)],
207
+ (w) => w.pubkey(p.trader).pubkey(p.tiers[0]).pubkey(p.tiers[1]).pubkey(p.tiers[2]),
208
+ p,
209
+ ),
210
+ [W(traderLinkPda(p.trader, p.programId)[0])],
211
+ );
212
+ }
213
+
214
+ export function openTraderLinkInstruction(p: { payer: string; referralAuthority: string; config: string; traderLink?: string; trader: string; tiers: [string, string, string] } & Ctx): Instruction {
215
+ return ix(
216
+ "open_trader_link",
217
+ [WS(p.payer), RS(p.referralAuthority), R(p.config), W(p.traderLink ?? traderLinkPda(p.trader, p.programId)[0]), R(SYSTEM_PROGRAM_ID), RS(p.trader)],
218
+ (w) => w.pubkey(p.trader).pubkey(p.tiers[0]).pubkey(p.tiers[1]).pubkey(p.tiers[2]),
219
+ p,
220
+ );
221
+ }
222
+
223
+ export function openRefOwedInstruction(p: { payer: string; quoteMint: string; refOwed: string; vault: string; quoteTokenProgram: string; referrer: string } & Ctx): Instruction {
224
+ 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);
225
+ }
226
+
227
+ export function rollUpRefsInstruction(p: { quoteMint: string; quoteTokenProgram: string; traderRefs: readonly { traderRef: string; escrow: string }[]; refOwed: readonly { refOwed: string; vault: string }[] } & Ctx): Instruction {
228
+ if (p.traderRefs.length > 255) throw new RangeError("at most 255 links a roll-up");
229
+ const base = ix("roll_up_refs", [R(p.quoteMint), R(p.quoteTokenProgram)], (w) => w.u8(p.traderRefs.length), p);
230
+ const rest: AccountMeta[] = [];
231
+ for (const t of p.traderRefs) rest.push(W(t.traderRef), W(t.escrow));
232
+ for (const r of p.refOwed) rest.push(W(r.refOwed), W(r.vault));
233
+ return { ...base, accounts: [...base.accounts, ...rest] };
234
+ }
235
+
236
+ export { CLAIM_CREATOR, CLAIM_CREATOR_REF, CLAIM_TEAM_SLOT, CLAIM_TRADER_REF, CLAIM_RESERVED_HOLDER, CLAIM_EXTRA, CLAIM_TEAM_BUY, CLAIM_SHARE_BOUGHT };
237
+
238
+ export const CLAIM_RESERVED_PAYOUT = CLAIM_RESERVED.solana.payout;
239
+
240
+ export const CLAIM_KNOWN = CLAIM_KNOWN_MASKS.solana.claim;
241
+
242
+ export const CLAIM_KNOWN_WIDE = CLAIM_KNOWN_MASKS.solana.claimWideV1;
243
+
244
+ export interface ClaimLaunch {
245
+ launch: string;
246
+ quoteVault: string;
247
+ teamSlot: string | null;
248
+
249
+ teamBuy?: { baseMint: string; tokenVault: string; walletBase: string };
250
+ }
251
+
252
+ export function setNativeCreateFeeInstruction(p: { authority: string; config: string; lamports: bigint } & Ctx): Instruction {
253
+ return ix("set_native_create_fee", [RS(p.authority), W(p.config)], (w) => w.u64(p.lamports), p);
254
+ }
255
+
256
+ export function withdrawPlatformManyInstruction(p: { authority: string; config: string; quoteMint: string; destination: string; quoteTokenProgram: string; launches: readonly { launch: string; quoteVault: string }[]; nativeTo?: string; quoteHook?: readonly AccountMeta[] } & Ctx): Instruction {
257
+ if (p.launches.length === 0 && !p.nativeTo) throw new RangeError("withdraw_platform_many: no launch and no native fees");
258
+
259
+ if (p.quoteHook?.length && p.launches.length === 0) throw new RangeError("withdraw_platform_many: a quote hook block needs a launch");
260
+ const base = ix("withdraw_platform_many", [RS(p.authority), p.nativeTo ? W(p.config) : R(p.config), R(p.quoteMint), W(p.destination), R(p.quoteTokenProgram)], (w) => w.u8(p.launches.length), p);
261
+ return { ...base, accounts: [...base.accounts, ...p.launches.flatMap((l) => [W(l.launch), W(l.quoteVault)]), ...(p.quoteHook ?? []), ...(p.nativeTo ? [W(p.nativeTo)] : [])] };
262
+ }
263
+
264
+ export const INCINERATOR = "1nc1nerator11111111111111111111111111111111";
265
+
266
+ export function syncBurnsInstruction(p: { launch: string; baseMint: string; incineratorAta?: string; extra?: readonly string[] } & Ctx): Instruction {
267
+ const base = ix("sync_burns", [W(p.launch), R(p.baseMint), R(p.incineratorAta ?? associatedTokenAddress(INCINERATOR, p.baseMint, TOKEN_2022_PROGRAM_ID))], none, p);
268
+ return { ...base, accounts: [...base.accounts, ...(p.extra ?? []).map((a) => R(a))] };
269
+ }
270
+
271
+ export function contributeGenesisInstruction(p: { contributor: string; genesisRaise: string; migrationVault: string; allocation: string; amount: bigint } & Ctx): Instruction {
272
+ return ix("contribute_genesis", [WS(p.contributor), W(p.genesisRaise), W(p.migrationVault), W(p.allocation), R(SYSTEM_PROGRAM_ID)], (w) => w.u64(p.amount), p);
273
+ }
274
+
275
+ export function contributeGenesisListedInstruction(p: { contributor: string; genesisRaise: string; migrationVault: string; allocation: string; amount: bigint; proof: readonly Uint8Array[] } & Ctx): Instruction {
276
+ for (const s of p.proof) if (s.length !== 32) throw new RangeError("contributeGenesisListedInstruction: a proof sibling is 32 bytes");
277
+ return ix(
278
+ "contribute_genesis_listed",
279
+ [WS(p.contributor), W(p.genesisRaise), W(p.migrationVault), W(p.allocation), R(SYSTEM_PROGRAM_ID)],
280
+ (w) => p.proof.reduce((x, s) => x.bytes(s), w.u64(p.amount).u32(p.proof.length)),
281
+ p,
282
+ );
283
+ }
284
+
285
+ export function refundGenesisMigratedInstruction(p: { wallet: string; genesisRaise: string; migrationVault: string; allocation: string } & Ctx): Instruction {
286
+ return ix("refund_genesis_migrated", [WS(p.wallet), W(p.genesisRaise), W(p.migrationVault), W(p.allocation), R(SYSTEM_PROGRAM_ID)], none, p);
287
+ }
288
+
289
+ export function setGenesisCreatorInstruction(p: { authority: string; config: string; genesisRaise: string; creator: string } & Ctx): Instruction {
290
+ return ix("set_genesis_creator", [RS(p.authority), R(p.config), W(p.genesisRaise)], (w) => w.pubkey(p.creator), p);
291
+ }
292
+
293
+ export function setGenesisListRootInstruction(p: { authority: string; config: string; genesisRaise: string; listRoot: Uint8Array } & Ctx): Instruction {
294
+ if (p.listRoot.length !== 32) throw new RangeError("setGenesisListRootInstruction: the root is 32 bytes");
295
+ return ix("set_genesis_list_root", [RS(p.authority), R(p.config), W(p.genesisRaise)], (w) => w.bytes(p.listRoot), p);
296
+ }
297
+
298
+ export function setGenesisPresetInstruction(p: { authority: string; config: string; genesisRaise: string; preset: string; presetId: number } & Ctx): Instruction {
299
+ return ix("set_genesis_preset", [RS(p.authority), R(p.config), W(p.genesisRaise), R(p.preset)], (w) => w.u8(p.presetId), p);
300
+ }
301
+
302
+ export function setGenesisWagmiPresetInstruction(p: { authority: string; presetId: number; config?: string; genesisRaise?: string; preset?: string } & Ctx): Instruction {
303
+ const g = pid(p);
304
+ const preset = p.preset ?? (p.presetId === 0 ? g : presetPda(p.presetId, g)[0]);
305
+ return ix("set_genesis_wagmi_preset", [RS(p.authority), R(p.config ?? configPda(g)[0]), W(p.genesisRaise ?? genesisRaisePda(g)[0]), R(preset)], (w) => w.u8(p.presetId), p);
306
+ }
307
+
308
+ export function setGenesisWagmiCapInstruction(p: { authority: string; capTokens: bigint; config?: string; genesisRaise?: string } & Ctx): Instruction {
309
+ if (p.capTokens < 0n || p.capTokens >> 64n !== 0n) throw new RangeError("set_genesis_wagmi_cap: cap_tokens is a u64");
310
+ const g = pid(p);
311
+ return ix("set_genesis_wagmi_cap", [RS(p.authority), R(p.config ?? configPda(g)[0]), W(p.genesisRaise ?? genesisRaisePda(g)[0])], (w) => w.u64(p.capTokens), p);
312
+ }
313
+
314
+ export function convertGenesisSolInstruction(p: {
315
+ caller: string; lamports: bigint; maxUsdc: bigint; preset: string; wagmiPreset?: string;
316
+ callerUsdc?: string; genesisRaise?: string; migrationVault?: string; solQuote?: string; usdcQuote?: string; vaultUsdc?: string; usdcMint?: string;
317
+
318
+ convertBand?: string | true;
319
+ } & Ctx): Instruction {
320
+ if (p.lamports <= 0n) throw new RangeError("convert_genesis_sol: the lamports must be > 0");
321
+ const g = pid(p);
322
+ const usdc = p.usdcMint ?? GENESIS_USDC_MINT;
323
+ return ix(
324
+ "convert_genesis_sol",
325
+ [
326
+ WS(p.caller), W(p.genesisRaise ?? genesisRaisePda(g)[0]), W(p.migrationVault ?? genesisMigrationVaultPda(g)[0]), R(p.solQuote ?? quoteEntryPda(WSOL_MINT, g)[0]), R(p.usdcQuote ?? quoteEntryPda(usdc, g)[0]), R(usdc),
327
+ W(p.callerUsdc ?? associatedTokenAddress(p.caller, usdc, TOKEN_PROGRAM_ID)), W(p.vaultUsdc ?? genesisVaultUsdc(g, usdc)), R(p.preset), R(p.wagmiPreset ?? g),
328
+ R(TOKEN_PROGRAM_ID), R(ASSOCIATED_TOKEN_PROGRAM_ID), R(SYSTEM_PROGRAM_ID),
329
+ R(typeof p.convertBand === "string" ? p.convertBand : genesisConvertBandPda(g)[0]),
330
+ ],
331
+ (w) => w.u64(p.lamports).u64(p.maxUsdc),
332
+ p,
333
+ );
334
+ }
335
+
336
+ export function openGenesisLaunchInstruction(p: {
337
+ authority: string; config: string; genesisRaise: string; migrationVault: string; deployer: string; preset: string; quote: string; quoteMint: string; baseMint: string;
338
+ launch: string; tokenVault: string; quoteVault: string; raiseTokenVault: string; teamSlot: string; metadata: string; metadataProgram?: string;
339
+ vaultUsdc?: string; vaultFloor?: string; wagmiPreset?: string; wagmiPresetId?: number; solQuote?: string;
340
+ args: { name: string; symbol: string; uri?: string };
341
+ } & Ctx): Instruction {
342
+ const g = pid(p);
343
+ const wagmiPreset = p.wagmiPreset ?? (p.wagmiPresetId ? presetPda(p.wagmiPresetId, g)[0] : g);
344
+ return ix(
345
+ "open_genesis_launch",
346
+ [
347
+ WS(p.authority), W(p.config), W(p.genesisRaise), W(p.migrationVault), W(p.deployer), R(p.preset), W(p.quote), R(p.quoteMint), WS(p.baseMint), W(p.launch), W(p.tokenVault), W(p.quoteVault),
348
+ W(p.raiseTokenVault), W(p.teamSlot), W(p.metadata), R(p.metadataProgram ?? METADATA_PROGRAM_ID), R(TOKEN_2022_PROGRAM_ID), R(TOKEN_PROGRAM_ID), R(ASSOCIATED_TOKEN_PROGRAM_ID), R(SYSTEM_PROGRAM_ID), R(INSTRUCTIONS_SYSVAR_ID),
349
+ W(p.vaultUsdc ?? genesisVaultUsdc(g, p.quoteMint)), W(p.vaultFloor ?? genesisVaultFloor(p.baseMint, g)), R(wagmiPreset), R(p.solQuote ?? quoteEntryPda(WSOL_MINT, g)[0]),
350
+ ],
351
+ (w) => w.string(p.args.name).string(p.args.symbol).string(p.args.uri ?? ""),
352
+ p,
353
+ );
354
+ }
355
+
356
+ export function openGenesisLaunchDefaults(p: { authority: string; deployer: string; baseMint: string; presetId: number; wagmiPresetId?: number; usdcMint?: string } & Ctx): Omit<Parameters<typeof openGenesisLaunchInstruction>[0], "args"> {
357
+ const g = pid(p);
358
+ const usdc = p.usdcMint ?? GENESIS_USDC_MINT;
359
+ const launch = launchPda(p.baseMint, g)[0];
360
+ return {
361
+ programId: g, authority: p.authority, config: configPda(g)[0], genesisRaise: genesisRaisePda(g)[0], migrationVault: genesisMigrationVaultPda(g)[0], deployer: p.deployer,
362
+ preset: presetPda(p.presetId, g)[0], quote: quoteEntryPda(usdc, g)[0], quoteMint: usdc, baseMint: p.baseMint, launch,
363
+ tokenVault: associatedTokenAddress(launch, p.baseMint, TOKEN_2022_PROGRAM_ID), quoteVault: associatedTokenAddress(launch, usdc, TOKEN_PROGRAM_ID),
364
+ raiseTokenVault: genesisRaiseTokenVault(p.baseMint, g), teamSlot: teamSlotPda(launch, g)[0], metadata: metadataPda(p.baseMint)[0],
365
+ vaultUsdc: genesisVaultUsdc(g, usdc), vaultFloor: genesisVaultFloor(p.baseMint, g), wagmiPresetId: p.wagmiPresetId ?? 0,
366
+ };
367
+ }
368
+
369
+ export function openGenesisWagmiInstruction(p: {
370
+ authority: string; config: string; genesisRaise: string; preset: string; quote: string; quoteMint: string; baseMint: string; launch: string; tokenVault: string;
371
+ quoteVault: string; raiseTokenVault: string; teamSlot: string; vault: string; vaultFloor: string; metadata: string; metadataProgram?: string;
372
+ floorLaunch?: string; usdcQuote?: string;
373
+ args: { name: string; symbol: string; uri?: string };
374
+ } & Ctx): Instruction {
375
+ const g = pid(p);
376
+ return ix(
377
+ "open_genesis_wagmi",
378
+ [
379
+ WS(p.authority), W(p.config), W(p.genesisRaise), R(p.preset), W(p.quote), R(p.quoteMint), WS(p.baseMint), W(p.launch), W(p.tokenVault), W(p.quoteVault), W(p.raiseTokenVault),
380
+ W(p.teamSlot), R(p.vault), W(p.vaultFloor), W(p.metadata), R(p.metadataProgram ?? METADATA_PROGRAM_ID), R(TOKEN_2022_PROGRAM_ID), R(ASSOCIATED_TOKEN_PROGRAM_ID), R(SYSTEM_PROGRAM_ID), R(INSTRUCTIONS_SYSVAR_ID),
381
+ R(p.floorLaunch ?? launchPda(p.quoteMint, g)[0]), R(p.usdcQuote ?? quoteEntryPda(GENESIS_USDC_MINT, g)[0]),
382
+ ],
383
+ (w) => w.string(p.args.name).string(p.args.symbol).string(p.args.uri ?? ""),
384
+ p,
385
+ );
386
+ }
387
+
388
+ export function openGenesisWagmiDefaults(p: { authority: string; floorMint: string; baseMint: string; wagmiPresetId: number; usdcMint?: string } & Ctx): Omit<Parameters<typeof openGenesisWagmiInstruction>[0], "args"> {
389
+ const g = pid(p);
390
+ const launch = launchPda(p.baseMint, g)[0];
391
+ return {
392
+ programId: g, authority: p.authority, config: configPda(g)[0], genesisRaise: genesisRaisePda(g)[0], preset: presetPda(p.wagmiPresetId, g)[0],
393
+ quote: quoteEntryPda(p.floorMint, g)[0], quoteMint: p.floorMint, baseMint: p.baseMint, launch,
394
+ tokenVault: associatedTokenAddress(launch, p.baseMint, TOKEN_2022_PROGRAM_ID), quoteVault: associatedTokenAddress(launch, p.floorMint, TOKEN_2022_PROGRAM_ID),
395
+ raiseTokenVault: genesisRaiseTokenVault(p.baseMint, g), teamSlot: teamSlotPda(launch, g)[0], vault: genesisMigrationVaultPda(g)[0], vaultFloor: genesisVaultFloor(p.floorMint, g),
396
+ metadata: metadataPda(p.baseMint)[0], floorLaunch: launchPda(p.floorMint, g)[0], usdcQuote: quoteEntryPda(p.usdcMint ?? GENESIS_USDC_MINT, g)[0],
397
+ };
398
+ }
399
+
400
+ export function claimGenesisInstruction(p: { sender: string; wallet: string; genesisRaise: string; allocation: string; baseMint: string; raiseTokenVault: string; destination: string; migrationVault?: string; usdcMint?: string; vaultUsdc?: string; usdcDestination?: string } & Ctx): Instruction {
401
+ const usdc = p.usdcMint ?? GENESIS_USDC_MINT;
402
+ return ix(
403
+ "claim_genesis",
404
+ [
405
+ WS(p.sender), W(p.wallet), W(p.genesisRaise), W(p.allocation), R(p.baseMint), W(p.raiseTokenVault), W(p.destination), R(TOKEN_2022_PROGRAM_ID), R(ASSOCIATED_TOKEN_PROGRAM_ID), R(SYSTEM_PROGRAM_ID), W(p.migrationVault ?? genesisMigrationVaultPda(pid(p))[0]),
406
+ R(usdc), W(p.vaultUsdc ?? genesisVaultUsdc(pid(p), usdc)), W(p.usdcDestination ?? associatedTokenAddress(p.wallet, usdc, TOKEN_PROGRAM_ID)), R(TOKEN_PROGRAM_ID),
407
+ ],
408
+ (w) => w.pubkey(p.wallet),
409
+ p,
410
+ );
411
+ }
412
+
413
+ export function claimGenesisRefundInstruction(p: { claimer: string; wallet: string; to?: string; genesisRaise?: string; allocation?: string; migrationVault?: string; vaultUsdc?: string; usdcMint?: string; usdcTo?: string } & Ctx): Instruction {
414
+ const g = pid(p);
415
+ const usdc = p.usdcMint ?? GENESIS_USDC_MINT;
416
+ return ix(
417
+ "claim_genesis_refund",
418
+ [
419
+ RS(p.claimer), W(p.genesisRaise ?? genesisRaisePda(g)[0]), W(p.allocation ?? genesisAllocPda(p.wallet, g)[0]), W(p.to ?? p.wallet), W(p.migrationVault ?? genesisMigrationVaultPda(g)[0]), R(SYSTEM_PROGRAM_ID),
420
+ W(p.vaultUsdc ?? genesisVaultUsdc(g, usdc)), R(usdc), W(p.usdcTo ?? associatedTokenAddress(p.wallet, usdc, TOKEN_PROGRAM_ID)), R(TOKEN_PROGRAM_ID),
421
+ ],
422
+ (w) => w.pubkey(p.wallet),
423
+ p,
424
+ );
425
+ }
426
+
427
+ export function sweepGenesisDustInstruction(p: { launch: string; quoteVault: string; genesisRaise?: string; migrationVault?: string; config?: string; vaultUsdc?: string; usdcMint?: string } & Ctx): Instruction {
428
+ const g = pid(p);
429
+ const usdc = p.usdcMint ?? GENESIS_USDC_MINT;
430
+ return ix(
431
+ "sweep_genesis_dust",
432
+ [
433
+ W(p.genesisRaise ?? genesisRaisePda(g)[0]), W(p.launch), W(p.quoteVault), W(p.migrationVault ?? genesisMigrationVaultPda(g)[0]), R(TOKEN_PROGRAM_ID), R(SYSTEM_PROGRAM_ID),
434
+ W(p.config ?? configPda(g)[0]), W(p.vaultUsdc ?? genesisVaultUsdc(g, usdc)), R(usdc),
435
+ ],
436
+ none,
437
+ p,
438
+ );
439
+ }
440
+
441
+ export function claimGenesisWagmiInstruction(p: {
442
+ sender: string; wallet: string; wagmiMint: string; floorMint: string;
443
+ genesisRaise?: string; allocation?: string; raiseWagmiVault?: string; wagmiDestination?: string; migrationVault?: string; vaultFloor?: string; floorDestination?: string;
444
+ } & Ctx): Instruction {
445
+ const g = pid(p);
446
+ return ix(
447
+ "claim_genesis_wagmi",
448
+ [
449
+ WS(p.sender), R(p.wallet), W(p.genesisRaise ?? genesisRaisePda(g)[0]), W(p.allocation ?? genesisAllocPda(p.wallet, g)[0]),
450
+ R(p.wagmiMint), W(p.raiseWagmiVault ?? genesisRaiseTokenVault(p.wagmiMint, g)), W(p.wagmiDestination ?? associatedTokenAddress(p.wallet, p.wagmiMint, TOKEN_2022_PROGRAM_ID)),
451
+ R(p.floorMint), R(p.migrationVault ?? genesisMigrationVaultPda(g)[0]), W(p.vaultFloor ?? genesisVaultFloor(p.floorMint, g)), W(p.floorDestination ?? associatedTokenAddress(p.wallet, p.floorMint, TOKEN_2022_PROGRAM_ID)),
452
+ R(TOKEN_2022_PROGRAM_ID), R(ASSOCIATED_TOKEN_PROGRAM_ID), R(SYSTEM_PROGRAM_ID),
453
+ ],
454
+ (w) => w.pubkey(p.wallet),
455
+ p,
456
+ );
457
+ }
458
+
459
+ export function sweepGenesisWagmiDustInstruction(p: { launch: string; floorMint: string; quoteVault?: string; genesisRaise?: string; vault?: string; vaultFloor?: string } & Ctx): Instruction {
460
+ const g = pid(p);
461
+ return ix(
462
+ "sweep_genesis_wagmi_dust",
463
+ [
464
+ W(p.genesisRaise ?? genesisRaisePda(g)[0]), W(p.launch), W(p.quoteVault ?? associatedTokenAddress(p.launch, p.floorMint, TOKEN_2022_PROGRAM_ID)), R(p.floorMint),
465
+ R(p.vault ?? genesisMigrationVaultPda(g)[0]), W(p.vaultFloor ?? genesisVaultFloor(p.floorMint, g)), R(TOKEN_2022_PROGRAM_ID),
466
+ ],
467
+ none,
468
+ p,
469
+ );
470
+ }
471
+
472
+ export function acceptGenesisMigrationInstruction(p: {
473
+ authority: string;
474
+ config: string;
475
+ genesisRaise: string;
476
+ migrationVault: string;
477
+ oldSale: string;
478
+ contributors: readonly { contribution: string; allocation: string }[];
479
+ expectedTotal: bigint;
480
+ } & Ctx): Instruction {
481
+ const base = ix("accept_genesis_migration", [WS(p.authority), R(p.config), W(p.genesisRaise), W(p.migrationVault), R(p.oldSale), R(SYSTEM_PROGRAM_ID)], (w) => w.u16(p.contributors.length).u64(p.expectedTotal), p);
482
+ return { ...base, accounts: [...base.accounts, ...p.contributors.flatMap((c) => [R(c.contribution), W(c.allocation)])] };
483
+ }
484
+
485
+ export function tokenBurnCheckedInstruction(p: { owner: string; account: string; mint: string; amount: bigint; decimals: number }): Instruction {
486
+ const data = new Uint8Array(10);
487
+ data[0] = 15;
488
+ new DataView(data.buffer).setBigUint64(1, p.amount, true);
489
+ data[9] = p.decimals;
490
+ return { programAddress: TOKEN_2022_PROGRAM_ID, accounts: [W(p.account), W(p.mint), RS(p.owner)], data };
491
+ }