@floorlaunchpad/sdk 0.1.0 → 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,349 @@
1
+
2
+
3
+ import { unknown } from "./decode.js";
4
+ import * as B from "./bodies.js";
5
+ import * as P from "./partners.js";
6
+ import { FIRSTS_MAX, IDS_MAX, LAUNCHES_PAGE_MAX, LAUNCH_SORTS, STREAM_STATE_MAX } from "./paths.js";
7
+
8
+ export const UNITS = {
9
+ site: "raw quote base units, token math units (6 dp), Q64.64 prices, unix s; bigint as decimal strings; USD as decimal strings",
10
+ partner: "the partner's format: whole-unit decimal strings unless a field says raw base units; unix s",
11
+ } ;
12
+
13
+ export const INDEXER_ERROR_CODES = [
14
+
15
+ "not_ready",
16
+
17
+ "unknown_route",
18
+
19
+ "unknown_launch",
20
+
21
+ "not_found",
22
+
23
+ "bad_query",
24
+
25
+ "too_many",
26
+
27
+ "no_reader",
28
+
29
+ "not_indexed",
30
+
31
+ "upstream",
32
+
33
+ "method",
34
+
35
+ "unknown",
36
+ ] ;
37
+
38
+ const errorWord = (body ) => (typeof body === "object" && body !== null && "error" in body ? String((body ).error) : null);
39
+
40
+ export function errorCode(status , body ) {
41
+ const w = errorWord(body);
42
+ switch (status) {
43
+ case 400:
44
+ return "bad_query";
45
+ case 404:
46
+ return w === "unknown route" ? "unknown_route" : w === "unknown launch" ? "unknown_launch" : "not_found";
47
+ case 405:
48
+ return "method";
49
+ case 413:
50
+ return "too_many";
51
+ case 501:
52
+ return "no_reader";
53
+ case 502:
54
+ return "upstream";
55
+ case 503:
56
+ return w === "not ready" ? "not_ready" : "not_indexed";
57
+ default:
58
+ return "unknown";
59
+ }
60
+ }
61
+
62
+ const NONE = { kind: "none" } ;
63
+ const limit = (dflt , max ) => ({ kind: "limit", limit: { default: dflt, max } }) ;
64
+ const cursor = (dflt , max ) => ({ kind: "cursor", limit: { default: dflt, max }, cursor: "before", next: "next" }) ;
65
+ const LIMIT = (dflt , max ) => ({ kind: "int", doc: "rows", min: 1, max, default: dflt });
66
+ const BEFORE = { kind: "cursor", doc: "a block, or a row id <block>:<txnIndex>:<eventIndex> (a page's next): rows strictly before it" };
67
+ const WINDOW = { kind: "enum", doc: "the volume window", values: B.TRADER_WINDOWS, default: "24h" };
68
+
69
+ const GATED = ["not_ready", "upstream"] ;
70
+ const LAUNCH_ERR = [...GATED, "unknown_launch"] ;
71
+ const WALLET_ERR = [...GATED, "bad_query"] ;
72
+
73
+ function site (s ) {
74
+ const params = [...s.pattern.matchAll(/<(launch|wallet)>/g)].map((m) => m[1] );
75
+ const { v2, ...rest } = s;
76
+ const aliases = s.aliases ?? (v2 ? [s.pattern.replace(/^\/floor-amm\//, "/floor-amm/v2/")] : []);
77
+ return { mount: "chain", query: {}, page: NONE, errors: GATED, gated: true, units: "site", audience: "site", ...rest, params, aliases };
78
+ }
79
+ function partner (s ) {
80
+ return { mount: "chain", params: [], query: {}, page: NONE, errors: [...GATED, "bad_query"], gated: true, units: "partner", audience: "partner", aliases: [], ...s };
81
+ }
82
+
83
+ export const INDEXER_CONTRACT = {
84
+
85
+ head: site({ pattern: "/floor-amm/head", aliases: ["/head"], gated: false, errors: [], body: B.HEAD }),
86
+ latestBlock: site({ pattern: "/floor-amm/latest-block", aliases: ["/latest-block"], errors: [...GATED, "not_found"], body: B.LATEST_BLOCK }),
87
+ stream: site({
88
+ pattern: "/floor-amm/stream",
89
+ aliases: ["/stream"],
90
+ sse: true,
91
+ query: {
92
+ launch: { kind: "list", doc: "only these launches' frames (and their quote chains' relatives)" },
93
+ state: { kind: "list", doc: "state frames (the launch whole on each change) for these", max: STREAM_STATE_MAX },
94
+ lastEventId: { kind: "string", doc: "resume after this frame id (EventSource sends Last-Event-ID itself)" },
95
+ },
96
+ body: unknown,
97
+ }),
98
+ quotes: site({ pattern: "/floor-amm/quotes", body: B.QUOTES }),
99
+ summary: site({ pattern: "/floor-amm/summary", aliases: ["/floor-amm/v2/summary"], body: B.SUMMARY }),
100
+ floorRouted: site({ pattern: "/floor-amm/floor-routed", aliases: ["/floor-amm/v2/floor-routed"], body: B.FLOOR_ROUTED }),
101
+ events: site({
102
+ pattern: "/floor-amm/events",
103
+ aliases: ["/events", "/v2/dex/events"],
104
+ query: { fromBlock: { kind: "block", doc: "first block, inclusive", required: true }, toBlock: { kind: "block", doc: "last block, inclusive", required: true } },
105
+ page: { kind: "range", from: "fromBlock", to: "toBlock" },
106
+ errors: [...GATED, "bad_query", "too_many"],
107
+ body: B.EVENTS,
108
+ }),
109
+
110
+ launches: site({
111
+ pattern: "/floor-amm/launches",
112
+ v2: true,
113
+ query: {
114
+ sort: { kind: "enum", doc: "the order (larger first with order=desc)", values: LAUNCH_SORTS, default: "created" },
115
+ order: { kind: "enum", doc: "asc or desc", values: ["asc", "desc"], default: "desc" },
116
+ q: { kind: "string", doc: "name or symbol contains, or an id, token or creator equals" },
117
+ ids: { kind: "list", doc: "these launches (ids or tokens), in the order asked without sort", max: IDS_MAX },
118
+ quote: { kind: "string", doc: "launches quoted in this coin" },
119
+ creator: { kind: "string", doc: "launches by this creator" },
120
+ rankable: { kind: "bool", doc: "true (or 1) listed only, false (or 0) unlisted only" },
121
+ graduated: { kind: "bool", doc: "graduated or not (true / false, or 1 / 0)" },
122
+ limit: LIMIT(LAUNCHES_PAGE_MAX, LAUNCHES_PAGE_MAX),
123
+ offset: { kind: "int", doc: "rows skipped", min: 0, default: 0 },
124
+ },
125
+ page: { kind: "offset", limit: { default: LAUNCHES_PAGE_MAX, max: LAUNCHES_PAGE_MAX }, total: "total" },
126
+ errors: [...GATED, "bad_query"],
127
+ body: B.LAUNCHES,
128
+ }),
129
+ launch: site({ pattern: "/floor-amm/launches/<launch>", v2: true, errors: LAUNCH_ERR, body: B.LAUNCH_ONE }),
130
+ launchState: site({ pattern: "/floor-amm/launches/<launch>/state", v2: true, errors: ["not_ready", "unknown_launch"], body: B.LAUNCH_STATE }),
131
+ milestones: site({ pattern: "/floor-amm/launches/<launch>/milestones", v2: true, errors: LAUNCH_ERR, body: B.LAUNCH_MILESTONES }),
132
+ holders: site({ pattern: "/floor-amm/launches/<launch>/holders", v2: true, query: { limit: LIMIT(100, 500) }, page: limit(100, 500), errors: [...LAUNCH_ERR, "bad_query"], body: B.HOLDERS }),
133
+ trades: site({
134
+ pattern: "/floor-amm/launches/<launch>/trades",
135
+ v2: true,
136
+ query: { limit: LIMIT(100, 500), before: BEFORE, traders: { kind: "list", doc: "only these wallets' trades (EVM case-blind)" } },
137
+ page: cursor(100, 500),
138
+ errors: [...LAUNCH_ERR, "bad_query"],
139
+ body: B.TRADES,
140
+ }),
141
+ launchClaims: site({ pattern: "/floor-amm/launches/<launch>/claims", v2: true, query: { claimer: { kind: "string", doc: "only this claimer's rows" } }, errors: LAUNCH_ERR, body: B.LAUNCH_CLAIMS }),
142
+ devBuys: site({ pattern: "/floor-amm/launches/<launch>/dev-buys", v2: true, errors: LAUNCH_ERR, body: B.DEV_BUYS }),
143
+ traders: site({ pattern: "/floor-amm/launches/<launch>/traders", v2: true, query: { window: WINDOW, limit: LIMIT(100, 500) }, page: limit(100, 500), errors: [...LAUNCH_ERR, "bad_query"], body: B.LAUNCH_TRADERS }),
144
+ quoteChain: site({ pattern: "/floor-amm/launches/<launch>/chain", v2: true, errors: LAUNCH_ERR, body: B.QUOTE_CHAIN }),
145
+ devTrades: site({ pattern: "/floor-amm/launches/<launch>/dev", v2: true, query: { limit: LIMIT(100, 500) }, page: limit(100, 500), errors: [...LAUNCH_ERR, "bad_query"], body: B.DEV_TRADES }),
146
+ burns: site({ pattern: "/floor-amm/launches/<launch>/burns", v2: true, errors: LAUNCH_ERR, body: B.BURNS }),
147
+ launchLocks: site({ pattern: "/floor-amm/launches/<launch>/locks", v2: true, errors: LAUNCH_ERR, body: B.LAUNCH_LOCKS }),
148
+ marks: site({
149
+ pattern: "/floor-amm/launches/<launch>/marks",
150
+ v2: true,
151
+ query: { limit: LIMIT(100, 1_000), before: BEFORE },
152
+ page: cursor(100, 1_000),
153
+ errors: [...LAUNCH_ERR, "bad_query"],
154
+ body: B.MARKS,
155
+ }),
156
+ price: site({ pattern: "/floor-amm/launches/<launch>/price", v2: true, errors: LAUNCH_ERR, body: B.PRICE }),
157
+ highs: site({
158
+ pattern: "/floor-amm/launches/<launch>/highs",
159
+ v2: true,
160
+ query: { atLeast: { kind: "int", doc: "only the highs whose market cap reaches this (quote base units)", min: 0 }, limit: LIMIT(100, 1_000) },
161
+ page: limit(100, 1_000),
162
+ errors: [...LAUNCH_ERR, "bad_query"],
163
+ body: B.HIGHS,
164
+ }),
165
+ candles: site({
166
+ pattern: "/floor-amm/candles",
167
+ aliases: ["/candles", "/floor-amm/v2/candles", "/floor-amm/v2/launches/<launch>/candles"],
168
+ query: {
169
+ launch: { kind: "string", doc: "a launch id or its token", required: true },
170
+ interval: { kind: "enum", doc: "the bucket", values: B.CANDLE_INTERVALS, default: "1h" },
171
+ from: { kind: "unix", doc: "range start (absent: the most candles one read spans, back from to)" },
172
+ to: { kind: "unix", doc: "range end (absent: the indexed head's time)" },
173
+ before: { kind: "unix", doc: "instead of from / to: the newest limit traded buckets starting before it" },
174
+ limit: { kind: "int", doc: "with before only", min: 1, max: B.CANDLES_MAX, default: B.CANDLES_MAX },
175
+ },
176
+ page: { kind: "range", from: "from", to: "to", span: { interval: "interval", max: B.CANDLES_MAX } },
177
+ errors: [...GATED, "bad_query", "unknown_launch", "not_found"],
178
+ body: B.CANDLES,
179
+ }),
180
+ candleBundle: site({
181
+ pattern: "/floor-amm/launches/<launch>/candle-bundle",
182
+ v2: true,
183
+ query: {
184
+ intervals: { kind: "list", doc: "these buckets' pages (absent: every one, in CANDLE_INTERVALS order)", max: B.CANDLE_INTERVALS.length },
185
+ limit: LIMIT(B.CANDLE_BUNDLE_LIMIT, B.CANDLES_MAX),
186
+ },
187
+ page: limit(B.CANDLE_BUNDLE_LIMIT, B.CANDLES_MAX),
188
+ errors: [...LAUNCH_ERR, "bad_query", "not_found"],
189
+ body: B.CANDLE_BUNDLE,
190
+ }),
191
+
192
+ walletTrades: site({
193
+ pattern: "/floor-amm/wallets/<wallet>/trades",
194
+ v2: true,
195
+ query: { limit: LIMIT(100, 500), before: BEFORE, launch: { kind: "string", doc: "only this launch (an id or its token)" } },
196
+ page: cursor(100, 500),
197
+ errors: [...WALLET_ERR, "unknown_launch"],
198
+ body: B.WALLET_TRADES,
199
+ }),
200
+ positions: site({ pattern: "/floor-amm/wallets/<wallet>/positions", v2: true, errors: WALLET_ERR, body: B.POSITIONS }),
201
+ inbox: site({ pattern: "/floor-amm/wallets/<wallet>/inbox", v2: true, query: { limit: LIMIT(1_000, 1_000) }, page: limit(1_000, 1_000), errors: WALLET_ERR, body: B.INBOX }),
202
+ walletLocks: site({ pattern: "/floor-amm/wallets/<wallet>/locks", v2: true, errors: WALLET_ERR, body: B.WALLET_LOCKS }),
203
+ claimHistory: site({ pattern: "/floor-amm/wallets/<wallet>/claims", errors: WALLET_ERR, body: B.CLAIM_HISTORY }),
204
+ firsts: site({ pattern: "/floor-amm/wallets/<wallet>/firsts", errors: WALLET_ERR, body: B.FIRSTS }),
205
+ firstsMany: site({ pattern: "/floor-amm/wallets/firsts", query: { wallets: { kind: "list", doc: "the wallets", required: true, min: 1, max: FIRSTS_MAX } }, errors: WALLET_ERR, body: B.FIRSTS_MANY }),
206
+ claimView: site({ pattern: "/floor-amm/claims/<wallet>", errors: [...WALLET_ERR, "no_reader"], body: B.CLAIM_VIEW }),
207
+ people: site({ pattern: "/floor-amm/referrals/<wallet>/people", errors: WALLET_ERR, body: B.PEOPLE }),
208
+ roles: site({ pattern: "/floor-amm/roles/<wallet>", errors: WALLET_ERR, body: B.ROLES }),
209
+
210
+ traderBoard: site({ pattern: "/floor-amm/leaderboards/traders", v2: true, query: { window: WINDOW, limit: LIMIT(100, 500) }, page: limit(100, 500), errors: [...GATED, "bad_query"], body: B.TRADER_BOARD }),
211
+ launcherBoard: site({ pattern: "/floor-amm/leaderboards/launchers", v2: true, query: { limit: LIMIT(100, 500) }, page: limit(100, 500), errors: [...GATED, "bad_query"], body: B.LAUNCHER_BOARD }),
212
+
213
+ dexAsset: partner({ pattern: "/v2/dex/asset", aliases: ["/asset"], query: { id: { kind: "string", doc: "a launch's token, or a quote", required: true } }, errors: [...GATED, "bad_query", "not_found", "not_indexed"], body: P.DEX_ASSET }),
214
+ dexSummary: partner({ pattern: "/v2/dex/summary", aliases: ["/summary"], query: { id: { kind: "string", doc: "the pair id", required: true } }, errors: [...GATED, "bad_query", "not_found"], body: P.DEX_SUMMARY }),
215
+ dexPair: partner({ pattern: "/v2/dex/pair", aliases: ["/pair"], query: { id: { kind: "string", doc: "the pair id", required: true } }, errors: [...GATED, "unknown_launch"], body: P.DEX_PAIR }),
216
+ cgPairs: partner({ pattern: "/v2/coingecko/pairs", aliases: ["/coingecko/pairs"], errors: GATED, body: P.CG_PAIRS }),
217
+ cgTickers: partner({ pattern: "/v2/coingecko/tickers", aliases: ["/coingecko/tickers"], errors: GATED, body: P.CG_TICKERS }),
218
+ cgHistoricalTrades: partner({
219
+ pattern: "/v2/coingecko/historical_trades",
220
+ aliases: ["/coingecko/historical_trades", "/historical_trades"],
221
+ query: {
222
+ ticker_id: { kind: "string", doc: "<token>_<quote>", required: true },
223
+ type: { kind: "enum", doc: "one side only", values: ["buy", "sell"] },
224
+ limit: { kind: "int", doc: "rows per side (0: all)", min: 0 },
225
+ start_time: { kind: "unix", doc: "from (10^11 and over: milliseconds)" },
226
+ end_time: { kind: "unix", doc: "to (10^11 and over: milliseconds)" },
227
+ },
228
+ page: { kind: "range", from: "start_time", to: "end_time" },
229
+ errors: [...GATED, "bad_query", "not_found"],
230
+ body: P.CG_HISTORICAL,
231
+ }),
232
+ llamaTvl: partner({ pattern: "/v2/defillama/tvl", errors: GATED, body: P.LLAMA_TVL }),
233
+ llamaFees: partner({
234
+ pattern: "/v2/defillama/fees",
235
+ query: { from: { kind: "unix", doc: "window start, inclusive (with to)" }, to: { kind: "unix", doc: "window end, exclusive (with from)" } },
236
+ page: { kind: "range", from: "from", to: "to" },
237
+ body: P.LLAMA_FEES,
238
+ }),
239
+
240
+ health: { pattern: "/health", aliases: [], mount: "root", params: [], query: {}, page: NONE, errors: [], gated: false, units: "site", audience: "ops", body: P.HEALTH },
241
+ } ;
242
+
243
+ export const ROUTE_NAMES = Object.keys(INDEXER_CONTRACT) ;
244
+
245
+ export function matchRoute(path ) {
246
+ const p = path.replace(/\/+$/, "") || "/";
247
+ for (const name of ROUTE_NAMES) {
248
+ const c = INDEXER_CONTRACT[name];
249
+ for (const pat of [c.pattern, ...c.aliases]) {
250
+ const keys = [];
251
+ const re = new RegExp(`^${pat.replace(/[.*+?^${}()|[\]\\]/g, "\\$&").replace(/<(launch|wallet)>/g, (_, k ) => (keys.push(k), "([^/]+)"))}$`);
252
+ const m = re.exec(p);
253
+ if (m === null) continue;
254
+ const params = {};
255
+ keys.forEach((k, i) => (params[k] = decodeURIComponent(m[i + 1])));
256
+ return { name, params };
257
+ }
258
+ }
259
+ return null;
260
+ }
261
+
262
+ export const OPEN_ROUTES = {
263
+
264
+ genesisSeries: { pattern: "/floor-amm/genesis/series", served: false, open: "undecided: kept or dropped with the site's row" },
265
+
266
+ points: { pattern: null, served: false, open: "undecided: a points route, or the trades drain as now" },
267
+ } ;
268
+
269
+ export function routeLimit(name ) {
270
+ const p = INDEXER_CONTRACT[name].page;
271
+ return p.kind === "limit" || p.kind === "offset" || p.kind === "cursor" ? p.limit : null;
272
+ }
273
+
274
+ export const LIMITS = Object.fromEntries(ROUTE_NAMES.flatMap((n) => {
275
+ const l = routeLimit(n);
276
+ return l === null ? [] : [[n, l]];
277
+ })) ;
278
+
279
+ export function clampLimit(name , n ) {
280
+ const l = routeLimit(name);
281
+ return l === null ? n : Math.min(Math.max(1, Math.trunc(n)), l.max);
282
+ }
283
+
284
+ const DIGITS = /^\d+$/;
285
+
286
+ export function queryLimit(name , q ) {
287
+ const l = routeLimit(name);
288
+ if (l === null) throw new TypeError(`${name} takes no limit`);
289
+ const raw = q.get("limit");
290
+ return raw === null || raw === "" || !DIGITS.test(raw) ? l.default : clampLimit(name, Number(raw));
291
+ }
292
+
293
+ export function queryRefusal(name , q ) {
294
+ const spec = INDEXER_CONTRACT[name].query;
295
+ for (const [key, k] of Object.entries(spec)) {
296
+ const raw = q.get(key);
297
+ if (raw === null || raw === "") continue;
298
+ switch (k.kind) {
299
+ case "int": {
300
+ const lo = k.min ?? 0;
301
+ const n = DIGITS.test(raw) ? Number(raw) : NaN;
302
+ if (!(n >= lo) || (k.max !== undefined && n > k.max)) return k.max === undefined ? `${key} must be an integer ≥ ${lo}` : `${key} must be ${lo}..${k.max}`;
303
+ break;
304
+ }
305
+ case "list": {
306
+ const n = raw.split(",").filter((s) => s !== "").length;
307
+ if (k.max !== undefined && n > k.max) return `at most ${k.max} ${key}`;
308
+ break;
309
+ }
310
+ case "enum":
311
+ if (k.values !== undefined && !k.values.includes(raw)) return `${key} must be one of ${k.values.join(", ")}`;
312
+ break;
313
+ case "bool":
314
+ if (!(raw in BOOLS)) return `${key} must be true or false`;
315
+ break;
316
+ default:
317
+ break;
318
+ }
319
+ }
320
+ return spanRefusal(name, q);
321
+ }
322
+
323
+ const BOOLS = { true: true, false: false, 1: true, 0: false };
324
+
325
+ export function queryArg(name , q , key ) {
326
+ const k = (INDEXER_CONTRACT[name].query )[key];
327
+ if (k === undefined) throw new TypeError(`${name} reads no ${key}`);
328
+ const raw = q.get(key);
329
+ return raw !== null && raw !== "" ? raw : k.default === undefined ? undefined : String(k.default);
330
+ }
331
+
332
+ export function queryBool(name , q , key ) {
333
+ const raw = queryArg(name, q, key);
334
+ return raw === undefined ? null : (BOOLS[raw] ?? null);
335
+ }
336
+
337
+ export function spanRefusal(name , q , toDefault ) {
338
+ const p = INDEXER_CONTRACT[name].page;
339
+ if (p.kind !== "range" || p.span === undefined) return null;
340
+ const sec = (B.CANDLE_INTERVAL_SECS )[queryArg(name, q, p.span.interval) ?? ""];
341
+ const fromRaw = q.get(p.from), toRaw = q.get(p.to);
342
+ if (sec === undefined || fromRaw === null || !DIGITS.test(fromRaw)) return null;
343
+ const to = toRaw === null ? toDefault : DIGITS.test(toRaw) ? Number(toRaw) : undefined;
344
+ if (to === undefined) return null;
345
+ const from = Number(fromRaw);
346
+ if (from > to) return null;
347
+ const bucket = (t ) => Math.floor(t / sec) * sec;
348
+ return (bucket(to) - bucket(from)) / sec + 1 > p.span.max ? `the range spans more than ${p.span.max} candles` : null;
349
+ }
@@ -0,0 +1,97 @@
1
+
2
+
3
+ export class ShapeError extends TypeError {
4
+ path ;
5
+ constructor(path , want , got ) {
6
+ super(`${path || "body"}: want ${want}, got ${preview(got)}`);
7
+ this.path = path;
8
+ }
9
+ }
10
+
11
+ const preview = (v ) => {
12
+ if (v === undefined) return "nothing";
13
+ const s = JSON.stringify(v) ?? String(v);
14
+ return s.length > 60 ? `${s.slice(0, 57)}...` : s;
15
+ };
16
+
17
+ export const str = (v, p) => {
18
+ if (typeof v !== "string") throw new ShapeError(p, "a string", v);
19
+ return v;
20
+ };
21
+
22
+ export const num = (v, p) => {
23
+ if (typeof v !== "number" || !Number.isFinite(v)) throw new ShapeError(p, "a number", v);
24
+ return v;
25
+ };
26
+
27
+ export const int = (v, p) => {
28
+ const n = typeof v === "string" && /^-?\d+$/.test(v) ? Number(v) : v;
29
+ if (typeof n !== "number" || !Number.isSafeInteger(n)) throw new ShapeError(p, "a safe integer", v);
30
+ return n;
31
+ };
32
+
33
+ export const bool = (v, p) => {
34
+ if (typeof v !== "boolean") throw new ShapeError(p, "a boolean", v);
35
+ return v;
36
+ };
37
+
38
+ export const big = (v, p) => {
39
+ if (typeof v === "string" && /^-?\d+$/.test(v)) return BigInt(v);
40
+ if (typeof v === "number" && Number.isSafeInteger(v)) return BigInt(v);
41
+ throw new ShapeError(p, "an integer string", v);
42
+ };
43
+
44
+ export const decimal = (v, p) => {
45
+ if (typeof v !== "string" || !/^-?\d+(\.\d+)?$/.test(v)) throw new ShapeError(p, "a decimal string", v);
46
+ return v;
47
+ };
48
+
49
+ export const unknown = (v) => v;
50
+
51
+ export function oneOf (...values ) {
52
+ return (v, p) => {
53
+ if (typeof v !== "string" || !values.includes(v)) throw new ShapeError(p, values.map((x) => JSON.stringify(x)).join(" | "), v);
54
+ return v ;
55
+ };
56
+ }
57
+
58
+ export function nullable (d ) {
59
+ return (v, p) => (v === null ? null : d(v, p));
60
+ }
61
+
62
+ export function optional (d ) {
63
+ return Object.assign((v , p ) => (v === undefined ? undefined : d(v, p)), { optional: true });
64
+ }
65
+
66
+ export function array (d ) {
67
+ return (v, p) => {
68
+ if (!Array.isArray(v)) throw new ShapeError(p, "an array", v);
69
+ return v.map((x, i) => d(x, `${p}[${i}]`));
70
+ };
71
+ }
72
+
73
+ export function record (d ) {
74
+ return (v, p) => {
75
+ if (typeof v !== "object" || v === null || Array.isArray(v)) throw new ShapeError(p, "an object", v);
76
+ const out = {};
77
+ for (const [k, x] of Object.entries(v)) out[k] = d(x, `${p}.${k}`);
78
+ return out;
79
+ };
80
+ }
81
+
82
+ export function object (shape ) {
83
+ return (v, p) => {
84
+ if (typeof v !== "object" || v === null || Array.isArray(v)) throw new ShapeError(p, "an object", v);
85
+ const o = v ;
86
+ const out = {};
87
+ for (const [k, d] of Object.entries(shape)) {
88
+ const x = d(o[k], p === "" ? k : `${p}.${k}`);
89
+ if (x !== undefined || !("optional" in d)) out[k] = x;
90
+ }
91
+ return out ;
92
+ };
93
+ }
94
+
95
+ export function decode (d , body ) {
96
+ return d(body, "");
97
+ }
@@ -0,0 +1,100 @@
1
+
2
+
3
+ import { array, big, bool, decimal, int, nullable, num, object, oneOf, optional, record, str, unknown } from "./decode.js";
4
+
5
+ import { FEES, MILESTONES } from "./bodies.js";
6
+
7
+ const LIQUIDITY_MODE = oneOf("all", "bid");
8
+
9
+ export const DEX_ASSET = object({
10
+ asset: object({
11
+ id: str,
12
+ name: str,
13
+ symbol: str,
14
+
15
+ decimals: int,
16
+ totalSupply: optional(decimal),
17
+ circulatingSupply: optional(decimal),
18
+
19
+ coinGeckoId: optional(str),
20
+ }),
21
+ });
22
+
23
+ export const DEX_SUMMARY = object({
24
+ pair: str,
25
+ base: str,
26
+ quote: str,
27
+ priceNative: decimal,
28
+
29
+ floorPriceNative: decimal,
30
+ liquidityQuote: decimal,
31
+ liquidityMode: LIQUIDITY_MODE,
32
+
33
+ vault: decimal,
34
+
35
+ bidMoney: decimal,
36
+ floor: decimal,
37
+ cushion: decimal,
38
+ totalSupply: decimal,
39
+ circulatingSupply: decimal,
40
+ marketCapQuote: decimal,
41
+ volumeQuote: decimal,
42
+ trades: int,
43
+ graduated: bool,
44
+ unlisted: bool,
45
+ });
46
+
47
+ export const DEX_PAIR = object({
48
+ pair: object({ id: str, asset0Id: str, asset1Id: str, createdAtBlockNumber: int, createdAtBlockTimestamp: int, feeBps: nullable(num) }),
49
+ });
50
+
51
+ export const CG_PAIRS = array(object({ ticker_id: str, base: str, target: str, pool_id: str }));
52
+
53
+ export const CG_TICKERS = array(object({
54
+ ticker_id: str,
55
+ base_currency: str,
56
+ target_currency: str,
57
+ pool_id: str,
58
+ last_price: decimal,
59
+ ask: decimal,
60
+
61
+ bid: decimal,
62
+ base_volume: decimal,
63
+ target_volume: decimal,
64
+ high: nullable(decimal),
65
+ low: nullable(decimal),
66
+ liquidity_in_usd: nullable(decimal),
67
+ liquidity_in_quote: big,
68
+ }));
69
+
70
+ export const CG_TRADE = object({ trade_id: int, price: decimal, base_volume: decimal, target_volume: decimal, trade_timestamp: int, type: oneOf("buy", "sell") });
71
+
72
+ export const CG_HISTORICAL = object({ buy: optional(array(CG_TRADE)), sell: optional(array(CG_TRADE)) });
73
+
74
+ export const LLAMA_TVL = object({ mode: LIQUIDITY_MODE, tvl: record(big), launchTokens: array(str) });
75
+
76
+ const LLAMA_SUMS = {
77
+ volume: big,
78
+ fees: FEES,
79
+ createFees: big,
80
+
81
+ milestonesPaid: MILESTONES,
82
+ protocolRevenue: big,
83
+ holdersRevenue: big,
84
+
85
+ traderRef: optional(big),
86
+ };
87
+
88
+ export const LLAMA_FEES = object({ ...LLAMA_SUMS, from: optional(int), to: optional(int), byQuote: record(object(LLAMA_SUMS)) });
89
+
90
+ export const HEALTH = object({
91
+ ok: bool,
92
+ head: nullable(int),
93
+ launches: int,
94
+ ready: bool,
95
+ lag: nullable(int),
96
+ stalled: nullable(object({ slot: int, signature: str, cycles: int, error: str, ok: bool })),
97
+
98
+ metrics: optional(unknown),
99
+ });
100
+