@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,127 @@
1
+
2
+
3
+ export const INDEXER_ROUTES = {
4
+ head: { pattern: "/floor-amm/head", keys: [] },
5
+ latestBlock: { pattern: "/floor-amm/latest-block", keys: [] },
6
+ stream: { pattern: "/floor-amm/stream", keys: ["launch", "state", "lastEventId"] },
7
+ quotes: { pattern: "/floor-amm/quotes", keys: [] },
8
+ summary: { pattern: "/floor-amm/summary", keys: [] },
9
+ floorRouted: { pattern: "/floor-amm/floor-routed", keys: [] },
10
+ events: { pattern: "/floor-amm/events", keys: ["fromBlock", "toBlock"] },
11
+ launches: { pattern: "/floor-amm/launches", keys: ["sort", "order", "q", "ids", "quote", "creator", "rankable", "graduated", "limit", "offset"] },
12
+ launch: { pattern: "/floor-amm/launches/<launch>", keys: [] },
13
+ launchState: { pattern: "/floor-amm/launches/<launch>/state", keys: [] },
14
+ milestones: { pattern: "/floor-amm/launches/<launch>/milestones", keys: [] },
15
+ holders: { pattern: "/floor-amm/launches/<launch>/holders", keys: ["limit"] },
16
+ trades: { pattern: "/floor-amm/launches/<launch>/trades", keys: ["limit", "before", "traders"] },
17
+ launchClaims: { pattern: "/floor-amm/launches/<launch>/claims", keys: ["claimer"] },
18
+ devBuys: { pattern: "/floor-amm/launches/<launch>/dev-buys", keys: [] },
19
+ traders: { pattern: "/floor-amm/launches/<launch>/traders", keys: ["window", "limit"] },
20
+ quoteChain: { pattern: "/floor-amm/launches/<launch>/chain", keys: [] },
21
+ devTrades: { pattern: "/floor-amm/launches/<launch>/dev", keys: ["limit"] },
22
+ burns: { pattern: "/floor-amm/launches/<launch>/burns", keys: [] },
23
+ launchLocks: { pattern: "/floor-amm/launches/<launch>/locks", keys: [] },
24
+ marks: { pattern: "/floor-amm/launches/<launch>/marks", keys: ["limit", "before"] },
25
+ price: { pattern: "/floor-amm/launches/<launch>/price", keys: [] },
26
+ highs: { pattern: "/floor-amm/launches/<launch>/highs", keys: ["atLeast", "limit"] },
27
+ candleBundle: { pattern: "/floor-amm/launches/<launch>/candle-bundle", keys: ["intervals", "limit"] },
28
+ candles: { pattern: "/floor-amm/candles", keys: ["launch", "interval", "from", "to", "before", "limit"] },
29
+ walletTrades: { pattern: "/floor-amm/wallets/<wallet>/trades", keys: ["limit", "before", "launch"] },
30
+ positions: { pattern: "/floor-amm/wallets/<wallet>/positions", keys: [] },
31
+ inbox: { pattern: "/floor-amm/wallets/<wallet>/inbox", keys: ["limit"] },
32
+ walletLocks: { pattern: "/floor-amm/wallets/<wallet>/locks", keys: [] },
33
+ claimHistory: { pattern: "/floor-amm/wallets/<wallet>/claims", keys: [] },
34
+ firsts: { pattern: "/floor-amm/wallets/<wallet>/firsts", keys: [] },
35
+ firstsMany: { pattern: "/floor-amm/wallets/firsts", keys: ["wallets"] },
36
+ claimView: { pattern: "/floor-amm/claims/<wallet>", keys: [] },
37
+ people: { pattern: "/floor-amm/referrals/<wallet>/people", keys: [] },
38
+ roles: { pattern: "/floor-amm/roles/<wallet>", keys: [] },
39
+ traderBoard: { pattern: "/floor-amm/leaderboards/traders", keys: ["window", "limit"] },
40
+ launcherBoard: { pattern: "/floor-amm/leaderboards/launchers", keys: ["limit"] },
41
+ } ;
42
+
43
+ export const LAUNCH_SORTS = ["created", "newest", "volume1h", "volume24h", "volume7d", "volume", "marketCap", "liquidity", "backed", "trades24h", "holders", "change1h", "change24h", "lastTrade", "nearFloor", "trending", "newHolders24h"] ;
44
+
45
+ export const IDS_MAX = 100;
46
+
47
+ export const LAUNCHES_PAGE_MAX = 1_000;
48
+
49
+ export const FIRSTS_MAX = 100;
50
+
51
+ export const STREAM_STATE_MAX = 16;
52
+
53
+ export function query(q ) {
54
+ const p = new URLSearchParams();
55
+ for (const [k, v] of Object.entries(q)) {
56
+ if (v === undefined || v === null) continue;
57
+ p.set(k, Array.isArray(v) ? v.join(",") : String(v));
58
+ }
59
+ const s = p.toString();
60
+ return s === "" ? "" : `?${s}`;
61
+ }
62
+
63
+ const need = (s ) => {
64
+ if (s === "") throw new RangeError("an empty id or wallet");
65
+ return s;
66
+ };
67
+ const seg = (s ) => encodeURIComponent(need(s));
68
+
69
+ const launchPath = (id , tail = "") => `/floor-amm/launches/${seg(id)}${tail}`;
70
+ const walletPath = (w , tail ) => `/floor-amm/wallets/${seg(w)}${tail}`;
71
+
72
+ export const indexerPath = {
73
+ head: () => "/floor-amm/head",
74
+ latestBlock: () => "/floor-amm/latest-block",
75
+ stream: (q = {}) => {
76
+ if ((q.state?.length ?? 0) > STREAM_STATE_MAX) throw new RangeError(`at most ${STREAM_STATE_MAX} state ids`);
77
+ return `/floor-amm/stream${query({ launch: q.launch?.length ? q.launch : undefined, state: q.state?.length ? q.state : undefined, lastEventId: q.lastEventId })}`;
78
+ },
79
+ quotes: () => "/floor-amm/quotes",
80
+ summary: () => "/floor-amm/summary",
81
+ floorRouted: () => "/floor-amm/floor-routed",
82
+ events: (fromBlock , toBlock ) => `/floor-amm/events${query({ fromBlock, toBlock })}`,
83
+
84
+ launches: (q = {}) => {
85
+ if (q.ids !== undefined && q.ids.length > IDS_MAX) throw new RangeError(`at most ${IDS_MAX} ids`);
86
+ const sort = q.sort ?? (q.ids === undefined ? "created" : undefined);
87
+ return `/floor-amm/launches${query({ sort, order: q.order, q: q.q, ids: q.ids, quote: q.quote, creator: q.creator, rankable: q.rankable, graduated: q.graduated, limit: q.limit, offset: q.offset })}`;
88
+ },
89
+ launch: (id ) => launchPath(id),
90
+ launchState: (id ) => launchPath(id, "/state"),
91
+ milestones: (id ) => launchPath(id, "/milestones"),
92
+ holders: (id , q = {}) => launchPath(id, `/holders${query({ limit: q.limit })}`),
93
+ trades: (id , q = {}) => launchPath(id, `/trades${query({ limit: q.limit, before: q.before, traders: q.traders?.length ? q.traders : undefined })}`),
94
+ launchClaims: (id , q = {}) => launchPath(id, `/claims${query({ claimer: q.claimer })}`),
95
+ devBuys: (id ) => launchPath(id, "/dev-buys"),
96
+ traders: (id , q = {}) => launchPath(id, `/traders${query({ window: q.window, limit: q.limit })}`),
97
+ quoteChain: (id ) => launchPath(id, "/chain"),
98
+ devTrades: (id , q = {}) => launchPath(id, `/dev${query({ limit: q.limit })}`),
99
+ burns: (id ) => launchPath(id, "/burns"),
100
+ launchLocks: (id ) => launchPath(id, "/locks"),
101
+ marks: (id , q = {}) => launchPath(id, `/marks${query({ limit: q.limit, before: q.before })}`),
102
+ price: (id ) => launchPath(id, "/price"),
103
+
104
+ highs: (id , q = {}) => launchPath(id, `/highs${query({ atLeast: q.atLeast === undefined ? undefined : String(q.atLeast), limit: q.limit })}`),
105
+
106
+ candleBundle: (id , q = {}) => launchPath(id, `/candle-bundle${query({ intervals: q.intervals?.length ? q.intervals : undefined, limit: q.limit })}`),
107
+ candles: (q ) => {
108
+ if (q.before !== undefined && (q.from !== undefined || q.to !== undefined)) throw new RangeError("before cannot be given with from / to");
109
+ if (q.limit !== undefined && q.before === undefined) throw new RangeError("limit is read only with before");
110
+ return `/floor-amm/candles${query({ launch: need(q.launch), interval: q.interval, from: q.from, to: q.to, before: q.before, limit: q.limit })}`;
111
+ },
112
+ walletTrades: (w , q = {}) => walletPath(w, `/trades${query({ limit: q.limit, before: q.before, launch: q.launch })}`),
113
+ positions: (w ) => walletPath(w, "/positions"),
114
+ inbox: (w , q = {}) => walletPath(w, `/inbox${query({ limit: q.limit })}`),
115
+ walletLocks: (w ) => walletPath(w, "/locks"),
116
+ claimHistory: (w ) => walletPath(w, "/claims"),
117
+ firsts: (w ) => walletPath(w, "/firsts"),
118
+ firstsMany: (wallets ) => {
119
+ if (wallets.length === 0 || wallets.length > FIRSTS_MAX) throw new RangeError(`1..${FIRSTS_MAX} wallets`);
120
+ return `/floor-amm/wallets/firsts${query({ wallets })}`;
121
+ },
122
+ claimView: (w ) => `/floor-amm/claims/${seg(w)}`,
123
+ people: (w ) => `/floor-amm/referrals/${seg(w)}/people`,
124
+ roles: (w ) => `/floor-amm/roles/${seg(w)}`,
125
+ traderBoard: (q = {}) => `/floor-amm/leaderboards/traders${query({ window: q.window, limit: q.limit })}`,
126
+ launcherBoard: (q = {}) => `/floor-amm/leaderboards/launchers${query({ limit: q.limit })}`,
127
+ } ;
@@ -0,0 +1,109 @@
1
+
2
+
3
+ import { decode } from "./decode.js";
4
+
5
+ import * as B from "./bodies.js";
6
+ import { indexerPath } from "./paths.js";
7
+ import { errorCode } from "./contract.js";
8
+
9
+ export * from "./bodies.js";
10
+ export { ShapeError, decode } from "./decode.js";
11
+
12
+ export { FIRSTS_MAX, IDS_MAX, INDEXER_ROUTES, LAUNCHES_PAGE_MAX, LAUNCH_SORTS, STREAM_STATE_MAX, indexerPath, query } from "./paths.js";
13
+ export * from "./partners.js";
14
+ export { INDEXER_CONTRACT, INDEXER_ERROR_CODES, LIMITS, OPEN_ROUTES, ROUTE_NAMES, UNITS, clampLimit, errorCode, matchRoute, queryArg, queryBool, queryLimit, queryRefusal, routeLimit, spanRefusal } from "./contract.js";
15
+
16
+ export { createIndexerClient, routePath } from "./client.js";
17
+
18
+ export class IndexerError extends Error {
19
+ status ;
20
+ body ;
21
+ constructor(status , body ) {
22
+ super(`indexer ${status}: ${errorOf(body) ?? "error"}`);
23
+ this.status = status;
24
+ this.body = body;
25
+ }
26
+
27
+ get code() {
28
+ return errorCode(this.status, this.body);
29
+ }
30
+
31
+ get notReady() {
32
+ return this.status === 503 && errorOf(this.body) === "not ready";
33
+ }
34
+
35
+ get unknownLaunch() {
36
+ return this.status === 404 && errorOf(this.body) === "unknown launch";
37
+ }
38
+ }
39
+
40
+ const errorOf = (body ) => (typeof body === "object" && body !== null && "error" in body ? String((body ).error) : null);
41
+
42
+ export async function readRoute (get , path , d ) {
43
+ const r = await get(path);
44
+ if (r.status !== 200) throw new IndexerError(r.status, r.body);
45
+ return decode(d, r.body);
46
+ }
47
+
48
+ export const readHead = (get ) => readRoute(get, indexerPath.head(), B.HEAD);
49
+ export const readLatestBlock = (get ) => readRoute(get, indexerPath.latestBlock(), B.LATEST_BLOCK);
50
+ export const readQuotes = (get ) => readRoute(get, indexerPath.quotes(), B.QUOTES);
51
+ export const readSummary = (get ) => readRoute(get, indexerPath.summary(), B.SUMMARY);
52
+ export const readFloorRouted = (get ) => readRoute(get, indexerPath.floorRouted(), B.FLOOR_ROUTED);
53
+
54
+ export const readEvents = (get , fromBlock , toBlock ) => readRoute(get, indexerPath.events(fromBlock, toBlock), B.EVENTS);
55
+
56
+ export const readLaunches = (get , q = {}) => readRoute(get, indexerPath.launches(q), B.LAUNCHES);
57
+
58
+ export const readLaunch = (get , id ) => readRoute(get, indexerPath.launch(id), B.LAUNCH_ONE);
59
+
60
+ export const readLaunchState = (get , id ) => readRoute(get, indexerPath.launchState(id), B.LAUNCH_STATE);
61
+ export const readMilestones = (get , id ) => readRoute(get, indexerPath.milestones(id), B.LAUNCH_MILESTONES);
62
+
63
+ export const readHolders = (get , id , q = {}) => readRoute(get, indexerPath.holders(id, q), B.HOLDERS);
64
+
65
+ export const readTrades = (get , id , q = {}) => readRoute(get, indexerPath.trades(id, q), B.TRADES);
66
+ export const readLaunchClaims = (get , id , q = {}) => readRoute(get, indexerPath.launchClaims(id, q), B.LAUNCH_CLAIMS);
67
+ export const readDevBuys = (get , id ) => readRoute(get, indexerPath.devBuys(id), B.DEV_BUYS);
68
+
69
+ export const readTraders = (get , id , q = {}) => readRoute(get, indexerPath.traders(id, q), B.LAUNCH_TRADERS);
70
+ export const readQuoteChain = (get , id ) => readRoute(get, indexerPath.quoteChain(id), B.QUOTE_CHAIN);
71
+
72
+ export const readDevTrades = (get , id , q = {}) => readRoute(get, indexerPath.devTrades(id, q), B.DEV_TRADES);
73
+ export const readBurns = (get , id ) => readRoute(get, indexerPath.burns(id), B.BURNS);
74
+ export const readLaunchLocks = (get , id ) => readRoute(get, indexerPath.launchLocks(id), B.LAUNCH_LOCKS);
75
+
76
+ export const readMarks = (get , id , q = {}) => readRoute(get, indexerPath.marks(id, q), B.MARKS);
77
+ export const readPrice = (get , id ) => readRoute(get, indexerPath.price(id), B.PRICE);
78
+
79
+ export const readCandles = (get , q ) => readRoute(get, indexerPath.candles(q), B.CANDLES);
80
+ export const readCandleBundle = (get , id , q = {}) => readRoute(get, indexerPath.candleBundle(id, q), B.CANDLE_BUNDLE);
81
+ export const readHighs = (get , id , q = {}) => readRoute(get, indexerPath.highs(id, q), B.HIGHS);
82
+
83
+ export const readWalletTrades = (get , wallet , q = {}) => readRoute(get, indexerPath.walletTrades(wallet, q), B.WALLET_TRADES);
84
+ export const readPositions = (get , wallet ) => readRoute(get, indexerPath.positions(wallet), B.POSITIONS);
85
+
86
+ export const readInbox = (get , wallet , q = {}) => readRoute(get, indexerPath.inbox(wallet, q), B.INBOX);
87
+ export const readWalletLocks = (get , wallet ) => readRoute(get, indexerPath.walletLocks(wallet), B.WALLET_LOCKS);
88
+ export const readClaimHistory = (get , wallet ) => readRoute(get, indexerPath.claimHistory(wallet), B.CLAIM_HISTORY);
89
+
90
+ export const readClaimView = (get , wallet ) => readRoute(get, indexerPath.claimView(wallet), B.CLAIM_VIEW);
91
+ export const readFirsts = (get , wallet ) => readRoute(get, indexerPath.firsts(wallet), B.FIRSTS);
92
+
93
+ export const readFirstsMany = (get , wallets ) => readRoute(get, indexerPath.firstsMany(wallets), B.FIRSTS_MANY);
94
+ export const readPeople = (get , wallet ) => readRoute(get, indexerPath.people(wallet), B.PEOPLE);
95
+ export const readRoles = (get , wallet ) => readRoute(get, indexerPath.roles(wallet), B.ROLES);
96
+
97
+ export const readTraderBoard = (get , q = {}) => readRoute(get, indexerPath.traderBoard(q), B.TRADER_BOARD);
98
+ export const readLauncherBoard = (get , q = {}) => readRoute(get, indexerPath.launcherBoard(q), B.LAUNCHER_BOARD);
99
+
100
+ export function chainCoins(c ) {
101
+ if (c.chain.length === 0) return [];
102
+ return [c.chain[0].token, ...c.chain.map((h) => h.quote)];
103
+ }
104
+
105
+ export function offPriceBps(price , quotedX64 ) {
106
+ const p = price.livePriceX64;
107
+ if (p === 0n) return null;
108
+ return Number(((quotedX64 - p) * 10_000n) / p);
109
+ }
@@ -0,0 +1,71 @@
1
+
2
+
3
+ import { decode, int, nullable, object, str, unknown } from "./decode.js";
4
+ import { HEAD, LIVE_LAUNCH, TRADE } from "./bodies.js";
5
+
6
+ import { indexerPath } from "./paths.js";
7
+
8
+ const HELLO = object({ head: HEAD, window: int, oldest: nullable(str) });
9
+ const HEAD_SEEN = object({ block: int, age: int });
10
+ const LAUNCH_FRAME = object({ launch: LIVE_LAUNCH });
11
+ const STATE = object({ launch: str, mint: str, block: int, ts: nullable(int), seq: int, prev: unknown, state: LIVE_LAUNCH });
12
+ const REORG = object({ block: int, rollbacks: int });
13
+ const RESET = object({ reason: str, head: HEAD });
14
+
15
+ export function streamPath(q = {}) {
16
+ return indexerPath.stream(q);
17
+ }
18
+
19
+ export function decodeStreamFrame(event , data , id ) {
20
+ switch (event) {
21
+ case "hello":
22
+ return { event, data: decode(HELLO, data) };
23
+ case "head":
24
+ return { event, data: decode(HEAD_SEEN, data) };
25
+ case "trade":
26
+ if (id === undefined) return null;
27
+ return { event, id, data: decode(TRADE, data) };
28
+ case "launch": {
29
+ const d = data ;
30
+ if (d !== null && typeof d === "object" && d.gone === true) return { event: "launchGone", data: { launch: str(d.launch, "launch"), gone: true } };
31
+ return { event, data: decode(LAUNCH_FRAME, data) };
32
+ }
33
+ case "state": {
34
+ const s = decode(STATE, data);
35
+ return { event, data: { launch: s.launch, mint: s.mint, block: s.block, ts: s.ts, seq: s.seq, state: s.state } };
36
+ }
37
+ case "reorg":
38
+ return { event, data: decode(REORG, data) };
39
+ case "reset":
40
+ return { event, data: decode(RESET, data) };
41
+ default:
42
+ return null;
43
+ }
44
+ }
45
+
46
+ export function parseStreamFrames(text ) {
47
+ const frames = [];
48
+ let rest = text.replace(/\r\n/g, "\n");
49
+ let cut ;
50
+ while ((cut = rest.indexOf("\n\n")) >= 0) {
51
+ const block = rest.slice(0, cut);
52
+ rest = rest.slice(cut + 2);
53
+ let event = "message";
54
+ let id ;
55
+ const data = [];
56
+ let comment = null;
57
+ for (const line of block.split("\n")) {
58
+ if (line.startsWith(":")) comment = line.slice(1).trim();
59
+ else if (line.startsWith("event:")) event = line.slice(6).trim();
60
+ else if (line.startsWith("id:")) id = line.slice(3).trim();
61
+ else if (line.startsWith("data:")) data.push(line.slice(5).replace(/^ /, ""));
62
+ }
63
+ if (data.length === 0) {
64
+ if (comment !== null) frames.push({ event: "comment", text: comment });
65
+ continue;
66
+ }
67
+ const f = decodeStreamFrame(event, JSON.parse(data.join("\n")), id);
68
+ if (f !== null) frames.push(f);
69
+ }
70
+ return { frames, rest };
71
+ }
package/dist/lock.js ADDED
@@ -0,0 +1,16 @@
1
+
2
+
3
+ export function lockVested(amount , start , cliff , end , now , scale = 1n) {
4
+ if (now < cliff) return 0n;
5
+ if (now >= end) return amount;
6
+ return ((amount / scale) * (now - start)) / (end - start) * scale;
7
+ }
8
+
9
+ export function lockClaimable(l , now , scale = 1n) {
10
+ const v = lockVested(l.amount, l.start, l.cliff, l.end, now, scale);
11
+ return v > l.claimed ? v - l.claimed : 0n;
12
+ }
13
+
14
+ export function lockScheduleOk(amount , start , cliff , end , now ) {
15
+ return amount > 0n && start <= cliff && cliff <= end && end > now;
16
+ }
@@ -0,0 +1,154 @@
1
+
2
+
3
+ import { U128_MAX, assertU128 } from "./u256.js";
4
+
5
+ const K = [
6
+ 0xb504f333f9de6484597d89b3754abe9fn,
7
+ 0x9837f0518db8a96f46ad23182e42f6f6n,
8
+ 0x8b95c1e3ea8bd6e6fbe4628758a53c90n,
9
+ 0x85aac367cc487b14c5c95b8c2154c1b2n,
10
+ 0x82cd8698ac2ba1d73e2a475b46520bffn,
11
+ 0x8164d1f3bc0307737be56527bd14def4n,
12
+ 0x80b1ed4fd999ab6c25335719b6e6fd20n,
13
+ 0x8058d7d2d5e5f6b094d589f608ee4aa2n,
14
+ 0x802c6436d0e04f50ff8ce94a6797b3cen,
15
+ 0x8016302f174676283690dfe44d11d008n,
16
+ 0x800b179c82028fd0945e54e2ae18f2f0n,
17
+ 0x80058baf7fee3b5d1c718b38e549cb93n,
18
+ 0x8002c5d00fdcfcb6b6566a58c048be1fn,
19
+ 0x800162e61bed4a48e84c2e1a463473d9n,
20
+ 0x8000b17292f702a3aa22beacca949013n,
21
+ 0x800058b92abbae02030c5fa5256f41fen,
22
+ 0x80002c5c8dade4d71776c0f4dbea67d6n,
23
+ 0x8000162e44eaf636526be456600bdbe4n,
24
+ 0x80000b1721fa7c188307016c1cd4e8b6n,
25
+ 0x8000058b90de7e4cecfc487503488bb1n,
26
+ 0x800002c5c8678f36cbfce50a6de60b14n,
27
+ 0x80000162e431db9f80b2347b5d62e516n,
28
+ 0x800000b1721872d0c7b08cf1e0114152n,
29
+ 0x80000058b90c1aa8a5c3736cb77e8dffn,
30
+ 0x8000002c5c8605a4635f2efc2362d978n,
31
+ 0x800000162e4300e635cf4a109e3939bdn,
32
+ 0x8000000b17217ff81bef9c551590cf83n,
33
+ 0x800000058b90bfdd4e39cd52c0cfa27cn,
34
+ 0x80000002c5c85fe6f72d669e0e76e411n,
35
+ 0x8000000162e42ff18f9ad35186d0df28n,
36
+ 0x80000000b17217f84cce71aa0dcfffe7n,
37
+ 0x8000000058b90bfc07a77ad56ed22aaan,
38
+ 0x800000002c5c85fdfc23cdead40da8d6n,
39
+ 0x80000000162e42fefc25eb1571853a66n,
40
+ 0x800000000b17217f7d97f692baacded5n,
41
+ 0x80000000058b90bfbead3b8b5dd254d7n,
42
+ 0x8000000002c5c85fdf4eedd62f084e67n,
43
+ 0x800000000162e42fefa58aef378bf586n,
44
+ 0x8000000000b17217f7d24a78a3c7ef02n,
45
+ 0x800000000058b90bfbe9067c93e474a6n,
46
+ 0x80000000002c5c85fdf47b8e5a72599fn,
47
+ 0x8000000000162e42fefa3bdb315934a2n,
48
+ 0x80000000000b17217f7d1d7299b49c46n,
49
+ 0x8000000000058b90bfbe8e9a8d1c4ea0n,
50
+ 0x800000000002c5c85fdf4745969ea76fn,
51
+ 0x80000000000162e42fefa3a0df5373bfn,
52
+ 0x800000000000b17217f7d1cff4aac1e1n,
53
+ 0x80000000000058b90bfbe8e7db95a2f1n,
54
+ 0x8000000000002c5c85fdf473e61ae1f8n,
55
+ 0x800000000000162e42fefa39f121751cn,
56
+ 0x8000000000000b17217f7d1cf815bb96n,
57
+ 0x800000000000058b90bfbe8e7bec1e0dn,
58
+ 0x80000000000002c5c85fdf473dee5f17n,
59
+ 0x8000000000000162e42fefa39ef5438fn,
60
+ 0x80000000000000b17217f7d1cf7a26c8n,
61
+ 0x8000000000000058b90bfbe8e7bcf4a4n,
62
+ 0x800000000000002c5c85fdf473de72a2n,
63
+ 0x80000000000000162e42fefa39ef3765n,
64
+ 0x800000000000000b17217f7d1cf79b37n,
65
+ 0x80000000000000058b90bfbe8e7bcd7dn,
66
+ 0x8000000000000002c5c85fdf473de6b6n,
67
+ 0x800000000000000162e42fefa39ef359n,
68
+ 0x8000000000000000b17217f7d1cf79acn,
69
+ 0x800000000000000058b90bfbe8e7bcd6n,
70
+ ];
71
+
72
+ const ONE_127 = 1n << 127n;
73
+ const TWO_255 = 1n << 255n;
74
+
75
+ const POW2 = Array.from({ length: 257 }, (_, k) => 1n << BigInt(k));
76
+
77
+ const FRAC_BIT = Array.from({ length: 65 }, (_, i) => (i === 0 ? 0n : 1n << BigInt(64 - i)));
78
+ const U32 = 0xffffffffn;
79
+
80
+ export function bitLength(n ) {
81
+ let lo = 0;
82
+ let hi = 256;
83
+ while (lo < hi) {
84
+ const mid = (lo + hi) >> 1;
85
+ if (n >= POW2[mid]) lo = mid + 1;
86
+ else hi = mid;
87
+ }
88
+ return lo;
89
+ }
90
+
91
+ export const FIXED_MEMO_MAX = 4096;
92
+ const LOG2_MEMO = new Map ();
93
+ const EXP2_MEMO = new Map ();
94
+
95
+ export function clearFixedMemo() {
96
+ LOG2_MEMO.clear();
97
+ EXP2_MEMO.clear();
98
+ }
99
+
100
+ function remember(memo , k , v ) {
101
+ if (memo.size >= FIXED_MEMO_MAX) memo.clear();
102
+ memo.set(k, v);
103
+ return v;
104
+ }
105
+
106
+ export function log2X64(n ) {
107
+ const hit = LOG2_MEMO.get(n);
108
+ return hit !== undefined ? hit : remember(LOG2_MEMO, n, log2X64Uncached(n));
109
+ }
110
+
111
+ export function exp2X64(y ) {
112
+ const hit = EXP2_MEMO.get(y);
113
+ return hit !== undefined ? hit : remember(EXP2_MEMO, y, exp2X64Uncached(y));
114
+ }
115
+
116
+ export function log2X64Uncached(n ) {
117
+ assertU128(n, "n");
118
+ if (n === 0n) return null;
119
+
120
+ const m0 = bitLength(n) - 1;
121
+
122
+ let m = (n << BigInt(127 - m0)) & U128_MAX;
123
+ let frac = 0n;
124
+ for (let i = 1; i <= 64; i++) {
125
+
126
+ const p = m * m;
127
+ if (p >= TWO_255) {
128
+
129
+ frac |= FRAC_BIT[i];
130
+ m = p >> 128n;
131
+ } else {
132
+
133
+ m = p >> 127n;
134
+ }
135
+ }
136
+ return (BigInt(m0) << 64n) | frac;
137
+ }
138
+
139
+ export function exp2X64Uncached(y ) {
140
+ assertU128(y, "y");
141
+ const int = y >> 64n;
142
+ if (int >= 64n) return null;
143
+
144
+ const fHi = Number((y >> 32n) & U32);
145
+ const fLo = Number(y & U32);
146
+ let r = ONE_127;
147
+ for (let i = 1; i <= 64; i++) {
148
+ const bit = i <= 32 ? (fHi >>> (32 - i)) & 1 : (fLo >>> (64 - i)) & 1;
149
+
150
+ if (bit === 1) r = ((r * K[i - 1]) >> 127n) & U128_MAX;
151
+ }
152
+
153
+ return r >> (63n - int);
154
+ }
@@ -0,0 +1,39 @@
1
+
2
+
3
+ import { BPS, fail } from "./index.js";
4
+
5
+ const U128_MAX = (1n << 128n) - 1n;
6
+ const u128 = (v ) => (v > U128_MAX ? fail("Overflow") : v);
7
+
8
+ export function fixedRaiseClaim(c , raised , out , refund ) {
9
+ if (raised === 0n) fail("Zero");
10
+ if (c > raised) fail("Overflow");
11
+ return [u128((out * c) / raised), u128((refund * c) / raised)];
12
+ }
13
+
14
+ export const GENESIS_MIGRATED_DISCOUNT_BPS = 7_500;
15
+
16
+ export function genesisWeight(migrated , publicIn ) {
17
+ const w = migrated * BPS + publicIn * (BPS - BigInt(GENESIS_MIGRATED_DISCOUNT_BPS));
18
+ return w >> 128n === 0n ? w : null;
19
+ }
20
+
21
+ export function genesisShare(tokensOut , w , weightTotal ) {
22
+ if (weightTotal === 0n) return 0n;
23
+ const v = (tokensOut * w) / weightTotal;
24
+ if (v >> 128n !== 0n) fail("Overflow");
25
+ return v;
26
+ }
27
+
28
+ export function genesisWeightListed(migrated , publicIn , listed , listedDiscount ) {
29
+ return listedDiscount ? genesisWeight(migrated + listed, publicIn) : genesisWeight(migrated, publicIn + listed);
30
+ }
31
+
32
+ export function genesisClaim(c , w , raised , weightTotal , out , refund ) {
33
+ if (raised === 0n || weightTotal === 0n) fail("Zero");
34
+ const lo = c * (BPS - BigInt(GENESIS_MIGRATED_DISCOUNT_BPS));
35
+ const hi = c * BPS;
36
+ if (lo >> 128n !== 0n || hi >> 128n !== 0n) fail("Overflow");
37
+ if (c > raised || w > weightTotal || w < lo || w > hi) fail("Overflow");
38
+ return [u128((out * w) / weightTotal), u128((refund * c) / raised)];
39
+ }
@@ -0,0 +1,20 @@
1
+
2
+
3
+ export { log2X64, exp2X64 } from "./fixed.js";
4
+
5
+ export const BPS = 10_000n;
6
+
7
+  
8
+
9
+ export class FloorMathError extends Error {
10
+ code ;
11
+ constructor(code ) {
12
+ super(`floor-math: ${code}`);
13
+ this.name = "FloorMathError";
14
+ this.code = code;
15
+ }
16
+ }
17
+
18
+ export function fail(code ) {
19
+ throw new FloorMathError(code);
20
+ }
@@ -0,0 +1,49 @@
1
+
2
+
3
+ import { U128_MAX, U64_MAX, toU128 } from "./v2/wide.js";
4
+
5
+ export { U128_MAX, U64_MAX, toU128 };
6
+
7
+ export const U256_MAX = (1n << 256n) - 1n;
8
+
9
+ export function assertU128(v , name ) {
10
+ if (typeof v !== "bigint" || v < 0n || v > U128_MAX) {
11
+ throw new RangeError(`${name} must be a bigint in [0, 2^128): got ${String(v)}`);
12
+ }
13
+ }
14
+
15
+ export function mulU128(a , b ) {
16
+ return a * b;
17
+ }
18
+
19
+ export function checkedMulU64(x , m ) {
20
+ const p = x * m;
21
+ return p > U256_MAX ? null : p;
22
+ }
23
+
24
+ export function checkedAdd(a , b ) {
25
+ const p = a + b;
26
+ return p > U256_MAX ? null : p;
27
+ }
28
+
29
+ export function checkedSub(a , b ) {
30
+ return a < b ? null : a - b;
31
+ }
32
+
33
+ export function checkedShl64(x ) {
34
+ return x >> 192n !== 0n ? null : x << 64n;
35
+ }
36
+
37
+ export function divRemU128(x , d ) {
38
+ if (d === 0n) throw new RangeError("division by zero");
39
+ return [x / d, x % d];
40
+ }
41
+
42
+ export function divCeilU128(x , d ) {
43
+ const [q, r] = divRemU128(x, d);
44
+ return r === 0n ? q : q + 1n;
45
+ }
46
+
47
+ export function hiLo(x ) {
48
+ return [x >> 128n, x & U128_MAX];
49
+ }