@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,259 @@
1
+
2
+
3
+ import { readUintLE } from "../../codec.js";
4
+ import { FloorError, decodeSolanaProgramError, errorCodeOf } from "../../errors.js";
5
+ import { FloorMathError } from "../../math/index.js";
6
+ import { nextBuyPriceX64 } from "../../math/v2/display.js";
7
+ import { LEG_BACKING, LEG_FLOOR, LEG_HOLDER, LEG_PLATFORM, LEG_TEAM } from "../../math/v2/fees.js";
8
+ import { priceImpactV2, quoteSellImpactV2 } from "../../math/v2/receipt.js";
9
+ import { sCirc } from "../../math/v2/supply.js";
10
+ import { CLAIM_SHARE_BOUGHT, CLAIM_TEAM_BUY, CLAIM_TRADER_REF } from "../../solana/floor/instructions.js";
11
+ import { FLOOR_AMM_PROGRAM_ID, configPda, launchPda, refOwedPda, refOwedVault, teamSlotPda, traderRefEscrow, traderRefPda } from "../../solana/floor/program.js";
12
+ import { MAX_COMPUTE_UNIT_LIMIT, computeUnitLimitInstruction } from "../../solana/instruction.js";
13
+
14
+ import { TOKEN_2022_PROGRAM_ID, TOKEN_PROGRAM_ID, WSOL_MINT, associatedTokenAddress } from "../../solana/pda.js";
15
+ import { closeAccountInstruction, createAssociatedTokenAccountIdempotentInstruction, syncNativeInstruction, systemTransferInstruction } from "../../solana/tx.js";
16
+ import { CLAIM_COMPUTE_UNIT_LIMIT_V2 } from "../../v2/claims.js";
17
+ import { FLOOR_HOOK_PROGRAM_ID, buyWithPositionInstructions, claimInstructionV2, holderPositionPda, sellInstructionV2 } from "../../v2/solana.js";
18
+
19
+ import { quoteBuySolanaV2, solanaSettleInputsV2 } from "../../v2/solanaSettle.js";
20
+ import { buyLessIn, buyMinTokens } from "../../math/v2/trade.js";
21
+ import { SOL_BUY_WALK_STEPS } from "../../math/v2/book.js";
22
+ import { MAX_SLIPPAGE_BPS, minOutAt } from "../../v2/press.js";
23
+ import { fillsNothing } from "../../v2/route.js";
24
+ import { decodeQuoteTransferFeeV2, quoteReceivedV2, quoteTransferFeeV2 } from "../../v2/quoteMint.js";
25
+
26
+ import { decodeLaunchV2Typed } from "../../v2/types.js";
27
+
28
+ import { DEFAULT_SLIPPAGE_BPS } from "../types.js";
29
+
30
+ const MINT_SUPPLY_AT = 36;
31
+
32
+ function asFloorError(e ) {
33
+ if (e instanceof FloorError) return e;
34
+ if (e instanceof FloorMathError) {
35
+ const code = errorCodeOf(e.code);
36
+ return new FloorError(code === "Unknown" || code === "Genesis" ? "MathFailed" : code, e.message, { source: "sdk", name: e.code, mathError: e.code, cause: e });
37
+ }
38
+ if (e instanceof RangeError) return new FloorError("BadArgument", e.message, { source: "sdk", cause: e });
39
+ return new FloorError("Unknown", e instanceof Error ? e.message : String(e), { source: "sdk", cause: e });
40
+ }
41
+
42
+ async function guard (f ) {
43
+ try {
44
+ return await f();
45
+ } catch (e) {
46
+ throw asFloorError(e);
47
+ }
48
+ }
49
+
50
+ const bad = (message ) => new FloorError("BadArgument", message, { source: "sdk" });
51
+
52
+ function slippageOf(bps ) {
53
+ const s = bps ?? DEFAULT_SLIPPAGE_BPS;
54
+ if (!Number.isInteger(s) || s < 0 || s > MAX_SLIPPAGE_BPS) throw bad(`slippageBps ${s}: 0 ..= ${MAX_SLIPPAGE_BPS}`);
55
+ return s;
56
+ }
57
+
58
+ const lessSlippage = (x , bps ) => (x > 0n ? minOutAt(x, bps) : 1n);
59
+
60
+ function feeLegs(f ) {
61
+ return { backing: f[LEG_BACKING], team: f[LEG_TEAM], platform: f[LEG_PLATFORM], floor: f[LEG_FLOOR], holder: f[LEG_HOLDER], total: f.reduce((a, x) => a + x, 0n) };
62
+ }
63
+
64
+ const impactBps = (ppm ) => (ppm === null ? null : Number(ppm / 100n));
65
+
66
+ export function createSolanaClient(opts ) {
67
+ const { chain, transport } = opts;
68
+ if (chain?.family !== "solana") throw bad(`createSolanaClient: chain family ${String((chain )?.family)}`);
69
+ const pid = chain.programId ?? FLOOR_AMM_PROGRAM_ID;
70
+ const hid = chain.hookProgramId ?? FLOOR_HOOK_PROGRAM_ID;
71
+ const ids = { programId: pid, hookProgramId: hid };
72
+
73
+ async function get(address ) {
74
+ try {
75
+ return await transport.rpc.getAccount(address);
76
+ } catch (e) {
77
+ throw new FloorError("Transport", `getAccount ${address}: ${e instanceof Error ? e.message : String(e)}`, { source: "sdk", cause: e });
78
+ }
79
+ }
80
+
81
+ async function launchOf(mint ) {
82
+ const address = launchPda(mint, pid)[0];
83
+ const a = await get(address);
84
+ if (a === null) throw new FloorError("BadAccount", `no launch for mint ${mint} (${address})`, { source: "sdk" });
85
+ if (a.owner !== pid) throw new FloorError("BadAccount", `launch ${address} is owned by ${a.owner}, not ${pid}`, { source: "sdk" });
86
+ let l ;
87
+ try {
88
+ l = decodeLaunchV2Typed(a.data);
89
+ } catch (e) {
90
+ throw new FloorError("BadAccount", `launch ${address}: ${e instanceof Error ? e.message : String(e)}`, { source: "sdk", cause: e });
91
+ }
92
+ if (l.baseMint !== mint) throw new FloorError("BadAccount", `launch ${address} holds mint ${l.baseMint}, not ${mint}`, { source: "sdk" });
93
+ const m = await get(mint);
94
+ if (m !== null && m.data.length >= MINT_SUPPLY_AT + 8) {
95
+ const live = readUintLE(m.data, MINT_SUPPLY_AT, 8);
96
+ if (live < l.supply) l = { ...l, supply: live };
97
+ }
98
+ return { address, l };
99
+ }
100
+
101
+ async function tradeAccounts(address , l , trader , baseOwner , quoteOwner ) {
102
+ const ref = traderRefPda(trader, l.quoteMint, pid)[0];
103
+ const hasRef = (await get(ref)) !== null;
104
+ return {
105
+ programId: pid, hookProgramId: hid, trader, launch: address, baseMint: l.baseMint, quoteMint: l.quoteMint, tokenVault: l.tokenVault, quoteVault: l.quoteVault,
106
+ traderBase: associatedTokenAddress(baseOwner, l.baseMint, TOKEN_2022_PROGRAM_ID), traderQuote: associatedTokenAddress(quoteOwner, l.quoteMint, l.quoteTokenProgram),
107
+ quoteTokenProgram: l.quoteTokenProgram, traderRef: hasRef ? ref : null, escrow: hasRef ? traderRefEscrow(ref, l.quoteMint, l.quoteTokenProgram) : null,
108
+ baseOwner, quoteOwner,
109
+ };
110
+ }
111
+
112
+ async function wsolLegs(l , owner , payer ) {
113
+ if (l.quoteMint !== WSOL_MINT) return null;
114
+ const account = associatedTokenAddress(owner, WSOL_MINT, l.quoteTokenProgram);
115
+ const existed = (await get(account)) !== null;
116
+ return {
117
+ account,
118
+ open: createAssociatedTokenAccountIdempotentInstruction({ payer, owner, mint: WSOL_MINT, tokenProgram: l.quoteTokenProgram }),
119
+ close: existed || owner !== payer ? null : closeAccountInstruction({ account, destination: owner, owner, tokenProgram: l.quoteTokenProgram }),
120
+ };
121
+ }
122
+
123
+ async function quoteFeeOf(l ) {
124
+ if (l.quoteTokenProgram !== TOKEN_2022_PROGRAM_ID) return null;
125
+ const m = await get(l.quoteMint);
126
+ const fee = m === null ? null : decodeQuoteTransferFeeV2(m.data);
127
+ if (fee === null || (fee.older.basisPoints === 0 && fee.newer.basisPoints === 0)) return null;
128
+ if (transport.rpc.getEpoch) {
129
+ try {
130
+ return { fee, epoch: await transport.rpc.getEpoch() };
131
+ } catch (e) {
132
+ throw new FloorError("Transport", `getEpoch: ${e instanceof Error ? e.message : String(e)}`, { source: "sdk", cause: e });
133
+ }
134
+ }
135
+ const newerHigher = fee.newer.basisPoints >= fee.older.basisPoints;
136
+ return { fee, epoch: newerHigher || fee.newer.epoch === 0n ? fee.newer.epoch : fee.newer.epoch - 1n };
137
+ }
138
+
139
+ const client = {
140
+ family: "solana",
141
+ chain,
142
+
143
+ quoteBuy: (p ) => guard(async () => {
144
+ const slippageBps = slippageOf(p.slippageBps);
145
+ const { l } = await launchOf(p.launch);
146
+ const tf = await quoteFeeOf(l);
147
+
148
+ const r = quoteBuySolanaV2(l, p.amountIn, { quoteTransferFee: tf });
149
+
150
+ const s = solanaSettleInputsV2(l);
151
+ const less = buyLessIn(p.amountIn, slippageBps);
152
+ const lessFee = tf ? quoteTransferFeeV2(tf.fee, tf.epoch, less) : 0n;
153
+
154
+ let m = 0n;
155
+ if (less > lessFee) {
156
+ try {
157
+ m = buyMinTokens(s.book, s.row, s.sup, less - lessFee, 0, SOL_BUY_WALK_STEPS);
158
+ } catch (e) {
159
+ if (!fillsNothing(e)) throw e;
160
+ }
161
+ }
162
+ const minOut = m > 0n ? m : 1n;
163
+ const spot = nextBuyPriceX64(s.book);
164
+ return {
165
+ family: "solana", chainId: null, side: "buy", launch: p.launch, amountIn: p.amountIn, amountOut: r.buy.tokens, minOut, slippageBps,
166
+ fees: feeLegs(r.buy.fees), priceImpactBps: impactBps(priceImpactV2(spot, r.buy.net, r.buy.tokens, "buy").ppm), refund: r.refundReceived,
167
+ graduates: r.buy.graduatedNow,
168
+ };
169
+ }),
170
+
171
+ quoteSell: (p ) => guard(async () => {
172
+ const slippageBps = slippageOf(p.slippageBps);
173
+ if (p.tokensIn <= 0n) throw bad("tokensIn must be > 0");
174
+ const { l } = await launchOf(p.launch);
175
+ const s = solanaSettleInputsV2(l);
176
+ const { quote, impact } = quoteSellImpactV2(s.book, p.tokensIn, sCirc(s.book, s.sup));
177
+
178
+ const tf = await quoteFeeOf(l);
179
+ const amountOut = tf ? quoteReceivedV2(tf.fee, tf.epoch, quote.out) : quote.out;
180
+ return {
181
+ family: "solana", chainId: null, side: "sell", launch: p.launch, amountIn: p.tokensIn, amountOut, minOut: lessSlippage(quote.out, slippageBps),
182
+ slippageBps, fees: feeLegs(quote.fees), priceImpactBps: impactBps(impact.ppm), refund: quote.unfilled, graduates: false,
183
+ };
184
+ }),
185
+
186
+ buildBuy: (p ) => guard(async () => {
187
+ if (p.amountIn <= 0n) throw bad("amountIn must be > 0");
188
+ const { address, l } = await launchOf(p.launch);
189
+ const owner = p.recipient ?? p.trader;
190
+ const a = await tradeAccounts(address, l, p.trader, owner, p.trader);
191
+
192
+ const hasPosition = owner !== p.trader || (await get(holderPositionPda(address, owner, hid)[0])) !== null;
193
+ const wsol = await wsolLegs(l, p.trader, p.trader);
194
+ const instructions = [
195
+ computeUnitLimitInstruction(MAX_COMPUTE_UNIT_LIMIT),
196
+ createAssociatedTokenAccountIdempotentInstruction({ payer: p.trader, owner, mint: l.baseMint, tokenProgram: TOKEN_2022_PROGRAM_ID }),
197
+ ...(wsol ? [wsol.open, systemTransferInstruction({ from: p.trader, to: wsol.account, lamports: p.amountIn }), syncNativeInstruction(wsol.account)] : []),
198
+ ...buyWithPositionInstructions({ ...a, amountIn: p.amountIn, minOut: p.minOut, hasPosition }),
199
+ ...(wsol?.close ? [wsol.close] : []),
200
+ ];
201
+ return { family: "solana", instructions };
202
+ }),
203
+
204
+ buildSell: (p ) => guard(async () => {
205
+ if (p.tokensIn <= 0n) throw bad("tokensIn must be > 0");
206
+ const { address, l } = await launchOf(p.launch);
207
+ const to = p.recipient ?? p.trader;
208
+ const a = await tradeAccounts(address, l, p.trader, p.trader, to);
209
+ const wsol = await wsolLegs(l, to, p.trader);
210
+ const instructions = [
211
+ computeUnitLimitInstruction(MAX_COMPUTE_UNIT_LIMIT),
212
+ wsol ? wsol.open : createAssociatedTokenAccountIdempotentInstruction({ payer: p.trader, owner: to, mint: l.quoteMint, tokenProgram: l.quoteTokenProgram }),
213
+ sellInstructionV2({ ...a, tokensIn: p.tokensIn, minOut: p.minOut }),
214
+ ...(wsol?.close ? [wsol.close] : []),
215
+ ];
216
+ return { family: "solana", instructions };
217
+ }),
218
+
219
+ claim: (p ) => guard(async () => {
220
+ const tok = (p.types & (CLAIM_TEAM_BUY | CLAIM_SHARE_BOUGHT)) !== 0;
221
+ const launches = [];
222
+ let qtp = null;
223
+ for (const mint of p.launches) {
224
+ const { address, l } = await launchOf(mint);
225
+ if (l.quoteMint !== p.quote) throw bad(`launch ${mint} trades in ${l.quoteMint}, not ${p.quote}`);
226
+ qtp = l.quoteTokenProgram;
227
+ const slot = teamSlotPda(address, pid)[0];
228
+ launches.push({
229
+ launch: address, quoteVault: l.quoteVault, teamSlot: (await get(slot)) !== null ? slot : null, baseMint: l.baseMint,
230
+ ...(tok ? { teamBuy: { baseMint: l.baseMint, tokenVault: l.tokenVault, walletBase: associatedTokenAddress(p.wallet, l.baseMint, TOKEN_2022_PROGRAM_ID) } } : {}),
231
+ });
232
+ }
233
+ if (qtp === null) {
234
+ const m = await get(p.quote);
235
+ if (m === null) throw new FloorError("BadAccount", `no quote mint ${p.quote}`, { source: "sdk" });
236
+ qtp = m.owner;
237
+ }
238
+ const ro = (p.types & CLAIM_TRADER_REF) !== 0 ? refOwedPda(p.wallet, p.quote, pid)[0] : null;
239
+ const claim = claimInstructionV2({
240
+ ...ids, sender: p.wallet, wallet: p.wallet, quoteMint: p.quote, quoteTokenProgram: qtp, destination: associatedTokenAddress(p.wallet, p.quote, qtp),
241
+ config: configPda(pid)[0], refOwed: ro, refOwedVault: ro ? refOwedVault(ro, p.quote, qtp) : null, types: p.types, launches,
242
+ unwrap: p.quote === WSOL_MINT && qtp === TOKEN_PROGRAM_ID,
243
+ });
244
+ return { family: "solana", instructions: [computeUnitLimitInstruction(CLAIM_COMPUTE_UNIT_LIMIT_V2), claim] };
245
+ }),
246
+
247
+ send: async (tx ) => {
248
+ if (!transport.send) throw new FloorError("NoSend", "this client was given no transport.send", { source: "sdk" });
249
+ try {
250
+ return [await transport.send(tx)];
251
+ } catch (e) {
252
+ throw decodeSolanaProgramError(e, ids) ?? new FloorError("Transport", `send: ${e instanceof Error ? e.message : String(e)}`, { source: "sdk", cause: e });
253
+ }
254
+ },
255
+
256
+ decodeError: (raw ) => decodeSolanaProgramError(raw, ids),
257
+ };
258
+ return client;
259
+ }
@@ -0,0 +1,5 @@
1
+
2
+
3
+  
4
+
5
+ export const DEFAULT_SLIPPAGE_BPS = 100;
package/dist/codec.js ADDED
@@ -0,0 +1,77 @@
1
+
2
+
3
+ const ALPHABET = "123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz";
4
+ const INDEX = new Map ([...ALPHABET].map((c, i) => [c, i]));
5
+
6
+ export function base58Encode(bytes ) {
7
+ let zeros = 0;
8
+ while (zeros < bytes.length && bytes[zeros] === 0) zeros++;
9
+ let n = 0n;
10
+ for (const b of bytes) n = (n << 8n) | BigInt(b);
11
+ let out = "";
12
+ while (n > 0n) {
13
+ out = ALPHABET[Number(n % 58n)] + out;
14
+ n /= 58n;
15
+ }
16
+ return "1".repeat(zeros) + out;
17
+ }
18
+
19
+ export function base58Decode(s ) {
20
+ let zeros = 0;
21
+ while (zeros < s.length && s[zeros] === "1") zeros++;
22
+ let n = 0n;
23
+ for (const c of s) {
24
+ const v = INDEX.get(c);
25
+ if (v === undefined) throw new RangeError(`not base58: ${JSON.stringify(c)}`);
26
+ n = n * 58n + BigInt(v);
27
+ }
28
+ const body = [];
29
+ while (n > 0n) {
30
+ body.unshift(Number(n & 0xffn));
31
+ n >>= 8n;
32
+ }
33
+ return Uint8Array.from([...new Array (zeros).fill(0), ...body]);
34
+ }
35
+
36
+ export function addressBytes(address ) {
37
+ const b = base58Decode(address);
38
+ if (b.length !== 32) throw new RangeError(`not a 32-byte address: ${address}`);
39
+ return b;
40
+ }
41
+
42
+ export function hex(bytes ) {
43
+ return [...bytes].map((b) => b.toString(16).padStart(2, "0")).join("");
44
+ }
45
+
46
+ export function concatBytes(...parts ) {
47
+ const out = new Uint8Array(parts.reduce((n, p) => n + p.length, 0));
48
+ let o = 0;
49
+ for (const p of parts) {
50
+ out.set(p, o);
51
+ o += p.length;
52
+ }
53
+ return out;
54
+ }
55
+
56
+ export function readUintLE(b , off , len ) {
57
+ if (off + len > b.length) throw new RangeError(`read past the end: ${off}+${len} > ${b.length}`);
58
+ let v = 0n;
59
+ for (let i = len - 1; i >= 0; i--) v = (v << 8n) | BigInt(b[off + i]);
60
+ return v;
61
+ }
62
+
63
+ export function readI32LE(b , off ) {
64
+ return Number(BigInt.asIntN(32, readUintLE(b, off, 4)));
65
+ }
66
+
67
+ export function uintLE(v , len ) {
68
+ if (v < 0n || v >> BigInt(8 * len) !== 0n) throw new RangeError(`${v} does not fit ${len} bytes`);
69
+ const out = new Uint8Array(len);
70
+ for (let i = 0; i < len; i++) out[i] = Number((v >> BigInt(8 * i)) & 0xffn);
71
+ return out;
72
+ }
73
+
74
+ export function i32LE(v ) {
75
+ if (!Number.isInteger(v) || v < -(2 ** 31) || v >= 2 ** 31) throw new RangeError(`${v} is not an i32`);
76
+ return uintLE(BigInt.asUintN(32, BigInt(v)), 4);
77
+ }
@@ -0,0 +1,9 @@
1
+
2
+
3
+ import { bytesToHex, hexToBytes } from "../evm/abi.js";
4
+ import { keccak256 } from "../evm/keccak.js";
5
+
6
+ export function evmCodeHash(code ) {
7
+ if (typeof code !== "string" || !/^0x([0-9a-fA-F]{2})*$/.test(code) || /^0x0*$/.test(code)) throw new Error(`evmCodeHash: not runtime code: ${String(code).slice(0, 20)}`);
8
+ return bytesToHex(keccak256(hexToBytes(code))).toLowerCase();
9
+ }