@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,109 @@
1
+
2
+
3
+ export class ShapeError extends TypeError {
4
+ readonly path: string;
5
+ constructor(path: string, want: string, got: unknown) {
6
+ super(`${path || "body"}: want ${want}, got ${preview(got)}`);
7
+ this.path = path;
8
+ }
9
+ }
10
+
11
+ const preview = (v: unknown): string => {
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 type Decoder<T> = (v: unknown, path: string) => T;
18
+
19
+ export type Optional<T> = Decoder<T | undefined> & { readonly optional: true };
20
+
21
+ export type Infer<D> = D extends Decoder<infer T> ? T : never;
22
+
23
+ type Shape = Record<string, Decoder<unknown>>;
24
+ type OptionalKeys<S extends Shape> = { [K in keyof S]: S[K] extends { readonly optional: true } ? K : never }[keyof S];
25
+ type Flat<T> = { [K in keyof T]: T[K] };
26
+
27
+ export type ObjectOf<S extends Shape> = Flat<{ [K in Exclude<keyof S, OptionalKeys<S>>]: Infer<S[K]> } & { [K in OptionalKeys<S>]?: Exclude<Infer<S[K]>, undefined> }>;
28
+
29
+ export const str: Decoder<string> = (v, p) => {
30
+ if (typeof v !== "string") throw new ShapeError(p, "a string", v);
31
+ return v;
32
+ };
33
+
34
+ export const num: Decoder<number> = (v, p) => {
35
+ if (typeof v !== "number" || !Number.isFinite(v)) throw new ShapeError(p, "a number", v);
36
+ return v;
37
+ };
38
+
39
+ export const int: Decoder<number> = (v, p) => {
40
+ const n = typeof v === "string" && /^-?\d+$/.test(v) ? Number(v) : v;
41
+ if (typeof n !== "number" || !Number.isSafeInteger(n)) throw new ShapeError(p, "a safe integer", v);
42
+ return n;
43
+ };
44
+
45
+ export const bool: Decoder<boolean> = (v, p) => {
46
+ if (typeof v !== "boolean") throw new ShapeError(p, "a boolean", v);
47
+ return v;
48
+ };
49
+
50
+ export const big: Decoder<bigint> = (v, p) => {
51
+ if (typeof v === "string" && /^-?\d+$/.test(v)) return BigInt(v);
52
+ if (typeof v === "number" && Number.isSafeInteger(v)) return BigInt(v);
53
+ throw new ShapeError(p, "an integer string", v);
54
+ };
55
+
56
+ export const decimal: Decoder<string> = (v, p) => {
57
+ if (typeof v !== "string" || !/^-?\d+(\.\d+)?$/.test(v)) throw new ShapeError(p, "a decimal string", v);
58
+ return v;
59
+ };
60
+
61
+ export const unknown: Decoder<unknown> = (v) => v;
62
+
63
+ export function oneOf<const T extends readonly string[]>(...values: T): Decoder<T[number]> {
64
+ return (v, p) => {
65
+ if (typeof v !== "string" || !values.includes(v)) throw new ShapeError(p, values.map((x) => JSON.stringify(x)).join(" | "), v);
66
+ return v as T[number];
67
+ };
68
+ }
69
+
70
+ export function nullable<T>(d: Decoder<T>): Decoder<T | null> {
71
+ return (v, p) => (v === null ? null : d(v, p));
72
+ }
73
+
74
+ export function optional<T>(d: Decoder<T>): Optional<T> {
75
+ return Object.assign((v: unknown, p: string) => (v === undefined ? undefined : d(v, p)), { optional: true as const });
76
+ }
77
+
78
+ export function array<T>(d: Decoder<T>): Decoder<T[]> {
79
+ return (v, p) => {
80
+ if (!Array.isArray(v)) throw new ShapeError(p, "an array", v);
81
+ return v.map((x, i) => d(x, `${p}[${i}]`));
82
+ };
83
+ }
84
+
85
+ export function record<T>(d: Decoder<T>): Decoder<Record<string, T>> {
86
+ return (v, p) => {
87
+ if (typeof v !== "object" || v === null || Array.isArray(v)) throw new ShapeError(p, "an object", v);
88
+ const out: Record<string, T> = {};
89
+ for (const [k, x] of Object.entries(v)) out[k] = d(x, `${p}.${k}`);
90
+ return out;
91
+ };
92
+ }
93
+
94
+ export function object<S extends Shape>(shape: S): Decoder<ObjectOf<S>> {
95
+ return (v, p) => {
96
+ if (typeof v !== "object" || v === null || Array.isArray(v)) throw new ShapeError(p, "an object", v);
97
+ const o = v as Record<string, unknown>;
98
+ const out: Record<string, unknown> = {};
99
+ for (const [k, d] of Object.entries(shape)) {
100
+ const x = d(o[k], p === "" ? k : `${p}.${k}`);
101
+ if (x !== undefined || !("optional" in d)) out[k] = x;
102
+ }
103
+ return out as ObjectOf<S>;
104
+ };
105
+ }
106
+
107
+ export function decode<T>(d: Decoder<T>, body: unknown): T {
108
+ return d(body, "");
109
+ }
@@ -0,0 +1,109 @@
1
+
2
+
3
+ import { array, big, bool, decimal, int, nullable, num, object, oneOf, optional, record, str, unknown } from "./decode.ts";
4
+ import type { Infer } from "./decode.ts";
5
+ import { FEES, MILESTONES } from "./bodies.ts";
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
+ export type DexAsset = Infer<typeof DEX_ASSET>;
23
+
24
+ export const DEX_SUMMARY = object({
25
+ pair: str,
26
+ base: str,
27
+ quote: str,
28
+ priceNative: decimal,
29
+
30
+ floorPriceNative: decimal,
31
+ liquidityQuote: decimal,
32
+ liquidityMode: LIQUIDITY_MODE,
33
+
34
+ vault: decimal,
35
+
36
+ bidMoney: decimal,
37
+ floor: decimal,
38
+ cushion: decimal,
39
+ totalSupply: decimal,
40
+ circulatingSupply: decimal,
41
+ marketCapQuote: decimal,
42
+ volumeQuote: decimal,
43
+ trades: int,
44
+ graduated: bool,
45
+ unlisted: bool,
46
+ });
47
+ export type DexSummary = Infer<typeof DEX_SUMMARY>;
48
+
49
+ export const DEX_PAIR = object({
50
+ pair: object({ id: str, asset0Id: str, asset1Id: str, createdAtBlockNumber: int, createdAtBlockTimestamp: int, feeBps: nullable(num) }),
51
+ });
52
+ export type DexPair = Infer<typeof DEX_PAIR>;
53
+
54
+ export const CG_PAIRS = array(object({ ticker_id: str, base: str, target: str, pool_id: str }));
55
+ export type CgPairs = Infer<typeof CG_PAIRS>;
56
+
57
+ export const CG_TICKERS = array(object({
58
+ ticker_id: str,
59
+ base_currency: str,
60
+ target_currency: str,
61
+ pool_id: str,
62
+ last_price: decimal,
63
+ ask: decimal,
64
+
65
+ bid: decimal,
66
+ base_volume: decimal,
67
+ target_volume: decimal,
68
+ high: nullable(decimal),
69
+ low: nullable(decimal),
70
+ liquidity_in_usd: nullable(decimal),
71
+ liquidity_in_quote: big,
72
+ }));
73
+ export type CgTickers = Infer<typeof CG_TICKERS>;
74
+
75
+ export const CG_TRADE = object({ trade_id: int, price: decimal, base_volume: decimal, target_volume: decimal, trade_timestamp: int, type: oneOf("buy", "sell") });
76
+ export type CgTrade = Infer<typeof CG_TRADE>;
77
+
78
+ export const CG_HISTORICAL = object({ buy: optional(array(CG_TRADE)), sell: optional(array(CG_TRADE)) });
79
+ export type CgHistorical = Infer<typeof CG_HISTORICAL>;
80
+
81
+ export const LLAMA_TVL = object({ mode: LIQUIDITY_MODE, tvl: record(big), launchTokens: array(str) });
82
+ export type LlamaTvl = Infer<typeof LLAMA_TVL>;
83
+
84
+ const LLAMA_SUMS = {
85
+ volume: big,
86
+ fees: FEES,
87
+ createFees: big,
88
+
89
+ milestonesPaid: MILESTONES,
90
+ protocolRevenue: big,
91
+ holdersRevenue: big,
92
+
93
+ traderRef: optional(big),
94
+ };
95
+
96
+ export const LLAMA_FEES = object({ ...LLAMA_SUMS, from: optional(int), to: optional(int), byQuote: record(object(LLAMA_SUMS)) });
97
+ export type LlamaFees = Infer<typeof LLAMA_FEES>;
98
+
99
+ export const HEALTH = object({
100
+ ok: bool,
101
+ head: nullable(int),
102
+ launches: int,
103
+ ready: bool,
104
+ lag: nullable(int),
105
+ stalled: nullable(object({ slot: int, signature: str, cycles: int, error: str, ok: bool })),
106
+
107
+ metrics: optional(unknown),
108
+ });
109
+ export type Health = Infer<typeof HEALTH>;
@@ -0,0 +1,190 @@
1
+
2
+
3
+ export interface IndexerRoute {
4
+ readonly pattern: string;
5
+ readonly keys: readonly string[];
6
+ }
7
+
8
+ export const INDEXER_ROUTES = {
9
+ head: { pattern: "/floor-amm/head", keys: [] },
10
+ latestBlock: { pattern: "/floor-amm/latest-block", keys: [] },
11
+ stream: { pattern: "/floor-amm/stream", keys: ["launch", "state", "lastEventId"] },
12
+ quotes: { pattern: "/floor-amm/quotes", keys: [] },
13
+ summary: { pattern: "/floor-amm/summary", keys: [] },
14
+ floorRouted: { pattern: "/floor-amm/floor-routed", keys: [] },
15
+ events: { pattern: "/floor-amm/events", keys: ["fromBlock", "toBlock"] },
16
+ launches: { pattern: "/floor-amm/launches", keys: ["sort", "order", "q", "ids", "quote", "creator", "rankable", "graduated", "limit", "offset"] },
17
+ launch: { pattern: "/floor-amm/launches/<launch>", keys: [] },
18
+ launchState: { pattern: "/floor-amm/launches/<launch>/state", keys: [] },
19
+ milestones: { pattern: "/floor-amm/launches/<launch>/milestones", keys: [] },
20
+ holders: { pattern: "/floor-amm/launches/<launch>/holders", keys: ["limit"] },
21
+ trades: { pattern: "/floor-amm/launches/<launch>/trades", keys: ["limit", "before", "traders"] },
22
+ launchClaims: { pattern: "/floor-amm/launches/<launch>/claims", keys: ["claimer"] },
23
+ devBuys: { pattern: "/floor-amm/launches/<launch>/dev-buys", keys: [] },
24
+ traders: { pattern: "/floor-amm/launches/<launch>/traders", keys: ["window", "limit"] },
25
+ quoteChain: { pattern: "/floor-amm/launches/<launch>/chain", keys: [] },
26
+ devTrades: { pattern: "/floor-amm/launches/<launch>/dev", keys: ["limit"] },
27
+ burns: { pattern: "/floor-amm/launches/<launch>/burns", keys: [] },
28
+ launchLocks: { pattern: "/floor-amm/launches/<launch>/locks", keys: [] },
29
+ marks: { pattern: "/floor-amm/launches/<launch>/marks", keys: ["limit", "before"] },
30
+ price: { pattern: "/floor-amm/launches/<launch>/price", keys: [] },
31
+ highs: { pattern: "/floor-amm/launches/<launch>/highs", keys: ["atLeast", "limit"] },
32
+ candleBundle: { pattern: "/floor-amm/launches/<launch>/candle-bundle", keys: ["intervals", "limit"] },
33
+ candles: { pattern: "/floor-amm/candles", keys: ["launch", "interval", "from", "to", "before", "limit"] },
34
+ walletTrades: { pattern: "/floor-amm/wallets/<wallet>/trades", keys: ["limit", "before", "launch"] },
35
+ positions: { pattern: "/floor-amm/wallets/<wallet>/positions", keys: [] },
36
+ inbox: { pattern: "/floor-amm/wallets/<wallet>/inbox", keys: ["limit"] },
37
+ walletLocks: { pattern: "/floor-amm/wallets/<wallet>/locks", keys: [] },
38
+ claimHistory: { pattern: "/floor-amm/wallets/<wallet>/claims", keys: [] },
39
+ firsts: { pattern: "/floor-amm/wallets/<wallet>/firsts", keys: [] },
40
+ firstsMany: { pattern: "/floor-amm/wallets/firsts", keys: ["wallets"] },
41
+ claimView: { pattern: "/floor-amm/claims/<wallet>", keys: [] },
42
+ people: { pattern: "/floor-amm/referrals/<wallet>/people", keys: [] },
43
+ roles: { pattern: "/floor-amm/roles/<wallet>", keys: [] },
44
+ traderBoard: { pattern: "/floor-amm/leaderboards/traders", keys: ["window", "limit"] },
45
+ launcherBoard: { pattern: "/floor-amm/leaderboards/launchers", keys: ["limit"] },
46
+ } as const satisfies Record<string, IndexerRoute>;
47
+
48
+ export type IndexerRouteName = keyof typeof INDEXER_ROUTES;
49
+
50
+ export const LAUNCH_SORTS = ["created", "newest", "volume1h", "volume24h", "volume7d", "volume", "marketCap", "liquidity", "backed", "trades24h", "holders", "change1h", "change24h", "lastTrade", "nearFloor", "trending", "newHolders24h"] as const;
51
+ export type LaunchSort = (typeof LAUNCH_SORTS)[number];
52
+
53
+ export const IDS_MAX = 100;
54
+
55
+ export const LAUNCHES_PAGE_MAX = 1_000;
56
+
57
+ export const FIRSTS_MAX = 100;
58
+
59
+ export const STREAM_STATE_MAX = 16;
60
+
61
+ type QueryValue = string | number | boolean | readonly string[] | undefined | null;
62
+
63
+ export function query(q: Record<string, QueryValue>): string {
64
+ const p = new URLSearchParams();
65
+ for (const [k, v] of Object.entries(q)) {
66
+ if (v === undefined || v === null) continue;
67
+ p.set(k, Array.isArray(v) ? v.join(",") : String(v));
68
+ }
69
+ const s = p.toString();
70
+ return s === "" ? "" : `?${s}`;
71
+ }
72
+
73
+ const need = (s: string): string => {
74
+ if (s === "") throw new RangeError("an empty id or wallet");
75
+ return s;
76
+ };
77
+ const seg = (s: string): string => encodeURIComponent(need(s));
78
+
79
+ const launchPath = (id: string, tail = ""): string => `/floor-amm/launches/${seg(id)}${tail}`;
80
+ const walletPath = (w: string, tail: string): string => `/floor-amm/wallets/${seg(w)}${tail}`;
81
+
82
+ export interface LaunchesQuery {
83
+
84
+ ids?: readonly string[];
85
+ sort?: LaunchSort;
86
+ order?: "asc" | "desc";
87
+
88
+ q?: string;
89
+ quote?: string;
90
+ creator?: string;
91
+
92
+ rankable?: boolean;
93
+ graduated?: boolean;
94
+ limit?: number;
95
+ offset?: number;
96
+ }
97
+
98
+ export interface Page {
99
+ limit?: number;
100
+
101
+ before?: number | string;
102
+ }
103
+
104
+ export interface TradesQuery extends Page {
105
+ traders?: readonly string[];
106
+ }
107
+
108
+ export interface WalletTradesQuery extends Page {
109
+ launch?: string;
110
+ }
111
+
112
+ export interface CandlesQuery {
113
+
114
+ launch: string;
115
+ interval?: string;
116
+
117
+ from?: number;
118
+
119
+ to?: number;
120
+
121
+ before?: number;
122
+
123
+ limit?: number;
124
+ }
125
+
126
+ export interface StreamQuery {
127
+
128
+ launch?: readonly string[];
129
+
130
+ state?: readonly string[];
131
+
132
+ lastEventId?: string;
133
+ }
134
+
135
+ export const indexerPath = {
136
+ head: (): string => "/floor-amm/head",
137
+ latestBlock: (): string => "/floor-amm/latest-block",
138
+ stream: (q: StreamQuery = {}): string => {
139
+ if ((q.state?.length ?? 0) > STREAM_STATE_MAX) throw new RangeError(`at most ${STREAM_STATE_MAX} state ids`);
140
+ return `/floor-amm/stream${query({ launch: q.launch?.length ? q.launch : undefined, state: q.state?.length ? q.state : undefined, lastEventId: q.lastEventId })}`;
141
+ },
142
+ quotes: (): string => "/floor-amm/quotes",
143
+ summary: (): string => "/floor-amm/summary",
144
+ floorRouted: (): string => "/floor-amm/floor-routed",
145
+ events: (fromBlock: number, toBlock: number): string => `/floor-amm/events${query({ fromBlock, toBlock })}`,
146
+
147
+ launches: (q: LaunchesQuery = {}): string => {
148
+ if (q.ids !== undefined && q.ids.length > IDS_MAX) throw new RangeError(`at most ${IDS_MAX} ids`);
149
+ const sort = q.sort ?? (q.ids === undefined ? "created" : undefined);
150
+ 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 })}`;
151
+ },
152
+ launch: (id: string): string => launchPath(id),
153
+ launchState: (id: string): string => launchPath(id, "/state"),
154
+ milestones: (id: string): string => launchPath(id, "/milestones"),
155
+ holders: (id: string, q: { limit?: number } = {}): string => launchPath(id, `/holders${query({ limit: q.limit })}`),
156
+ trades: (id: string, q: TradesQuery = {}): string => launchPath(id, `/trades${query({ limit: q.limit, before: q.before, traders: q.traders?.length ? q.traders : undefined })}`),
157
+ launchClaims: (id: string, q: { claimer?: string } = {}): string => launchPath(id, `/claims${query({ claimer: q.claimer })}`),
158
+ devBuys: (id: string): string => launchPath(id, "/dev-buys"),
159
+ traders: (id: string, q: { window?: "1h" | "24h" | "7d" | "all"; limit?: number } = {}): string => launchPath(id, `/traders${query({ window: q.window, limit: q.limit })}`),
160
+ quoteChain: (id: string): string => launchPath(id, "/chain"),
161
+ devTrades: (id: string, q: { limit?: number } = {}): string => launchPath(id, `/dev${query({ limit: q.limit })}`),
162
+ burns: (id: string): string => launchPath(id, "/burns"),
163
+ launchLocks: (id: string): string => launchPath(id, "/locks"),
164
+ marks: (id: string, q: Page = {}): string => launchPath(id, `/marks${query({ limit: q.limit, before: q.before })}`),
165
+ price: (id: string): string => launchPath(id, "/price"),
166
+
167
+ highs: (id: string, q: { atLeast?: bigint | string; limit?: number } = {}): string => launchPath(id, `/highs${query({ atLeast: q.atLeast === undefined ? undefined : String(q.atLeast), limit: q.limit })}`),
168
+
169
+ candleBundle: (id: string, q: { intervals?: readonly string[]; limit?: number } = {}): string => launchPath(id, `/candle-bundle${query({ intervals: q.intervals?.length ? q.intervals : undefined, limit: q.limit })}`),
170
+ candles: (q: CandlesQuery): string => {
171
+ if (q.before !== undefined && (q.from !== undefined || q.to !== undefined)) throw new RangeError("before cannot be given with from / to");
172
+ if (q.limit !== undefined && q.before === undefined) throw new RangeError("limit is read only with before");
173
+ return `/floor-amm/candles${query({ launch: need(q.launch), interval: q.interval, from: q.from, to: q.to, before: q.before, limit: q.limit })}`;
174
+ },
175
+ walletTrades: (w: string, q: WalletTradesQuery = {}): string => walletPath(w, `/trades${query({ limit: q.limit, before: q.before, launch: q.launch })}`),
176
+ positions: (w: string): string => walletPath(w, "/positions"),
177
+ inbox: (w: string, q: { limit?: number } = {}): string => walletPath(w, `/inbox${query({ limit: q.limit })}`),
178
+ walletLocks: (w: string): string => walletPath(w, "/locks"),
179
+ claimHistory: (w: string): string => walletPath(w, "/claims"),
180
+ firsts: (w: string): string => walletPath(w, "/firsts"),
181
+ firstsMany: (wallets: readonly string[]): string => {
182
+ if (wallets.length === 0 || wallets.length > FIRSTS_MAX) throw new RangeError(`1..${FIRSTS_MAX} wallets`);
183
+ return `/floor-amm/wallets/firsts${query({ wallets })}`;
184
+ },
185
+ claimView: (w: string): string => `/floor-amm/claims/${seg(w)}`,
186
+ people: (w: string): string => `/floor-amm/referrals/${seg(w)}/people`,
187
+ roles: (w: string): string => `/floor-amm/roles/${seg(w)}`,
188
+ traderBoard: (q: { window?: "1h" | "24h" | "7d" | "all"; limit?: number } = {}): string => `/floor-amm/leaderboards/traders${query({ window: q.window, limit: q.limit })}`,
189
+ launcherBoard: (q: { limit?: number } = {}): string => `/floor-amm/leaderboards/launchers${query({ limit: q.limit })}`,
190
+ } as const satisfies Record<IndexerRouteName, (...a: never[]) => string>;
@@ -0,0 +1,119 @@
1
+
2
+
3
+ import { decode } from "./decode.ts";
4
+ import type { Decoder } from "./decode.ts";
5
+ import * as B from "./bodies.ts";
6
+ import { indexerPath } from "./paths.ts";
7
+ import { errorCode } from "./contract.ts";
8
+ import type { IndexerErrorCode } from "./contract.ts";
9
+ import type { CandlesQuery, LaunchesQuery, Page, TradesQuery, WalletTradesQuery } from "./paths.ts";
10
+
11
+ export * from "./bodies.ts";
12
+ export { ShapeError, decode } from "./decode.ts";
13
+ export type { Decoder, Infer } from "./decode.ts";
14
+ export { FIRSTS_MAX, IDS_MAX, INDEXER_ROUTES, LAUNCHES_PAGE_MAX, LAUNCH_SORTS, STREAM_STATE_MAX, indexerPath, query } from "./paths.ts";
15
+ export * from "./partners.ts";
16
+ export { INDEXER_CONTRACT, INDEXER_ERROR_CODES, LIMITS, OPEN_ROUTES, ROUTE_NAMES, UNITS, clampLimit, errorCode, matchRoute, queryArg, queryBool, queryLimit, queryRefusal, routeLimit, spanRefusal } from "./contract.ts";
17
+ export type { IndexerErrorCode, Pagination, PathParam, QueryKey, RouteBody, RouteContract, RouteName, Served, ServedBody, ServedKeys, Units } from "./contract.ts";
18
+ export { createIndexerClient, routePath } from "./client.ts";
19
+ export type { DrainName, IndexerClient, IndexerClientOptions, ReadName, RouteArgs } from "./client.ts";
20
+ export type { CandlesQuery, IndexerRoute, IndexerRouteName, LaunchSort, LaunchesQuery, Page, StreamQuery, TradesQuery, WalletTradesQuery } from "./paths.ts";
21
+
22
+ export type LaunchId = string;
23
+
24
+ export type Get = (path: string) => Promise<{ status: number; body: unknown }>;
25
+
26
+ export class IndexerError extends Error {
27
+ readonly status: number;
28
+ readonly body: unknown;
29
+ constructor(status: number, body: unknown) {
30
+ super(`indexer ${status}: ${errorOf(body) ?? "error"}`);
31
+ this.status = status;
32
+ this.body = body;
33
+ }
34
+
35
+ get code(): IndexerErrorCode {
36
+ return errorCode(this.status, this.body);
37
+ }
38
+
39
+ get notReady(): boolean {
40
+ return this.status === 503 && errorOf(this.body) === "not ready";
41
+ }
42
+
43
+ get unknownLaunch(): boolean {
44
+ return this.status === 404 && errorOf(this.body) === "unknown launch";
45
+ }
46
+ }
47
+
48
+ const errorOf = (body: unknown): string | null => (typeof body === "object" && body !== null && "error" in body ? String((body as { error: unknown }).error) : null);
49
+
50
+ export async function readRoute<T>(get: Get, path: string, d: Decoder<T>): Promise<T> {
51
+ const r = await get(path);
52
+ if (r.status !== 200) throw new IndexerError(r.status, r.body);
53
+ return decode(d, r.body);
54
+ }
55
+
56
+ type At = { indexed: B.Indexed | null };
57
+
58
+ export const readHead = (get: Get): Promise<B.Head> => readRoute(get, indexerPath.head(), B.HEAD);
59
+ export const readLatestBlock = (get: Get): Promise<B.LatestBlock> => readRoute(get, indexerPath.latestBlock(), B.LATEST_BLOCK);
60
+ export const readQuotes = (get: Get): Promise<B.Quotes> => readRoute(get, indexerPath.quotes(), B.QUOTES);
61
+ export const readSummary = (get: Get): Promise<B.Summary> => readRoute(get, indexerPath.summary(), B.SUMMARY);
62
+ export const readFloorRouted = (get: Get): Promise<B.FloorRouted> => readRoute(get, indexerPath.floorRouted(), B.FLOOR_ROUTED);
63
+
64
+ export const readEvents = (get: Get, fromBlock: number, toBlock: number): Promise<B.Events> => readRoute(get, indexerPath.events(fromBlock, toBlock), B.EVENTS);
65
+
66
+ export const readLaunches = (get: Get, q: LaunchesQuery = {}): Promise<B.Launches> => readRoute(get, indexerPath.launches(q), B.LAUNCHES);
67
+
68
+ export const readLaunch = (get: Get, id: LaunchId): Promise<At & { launch: B.ListedLaunch }> => readRoute(get, indexerPath.launch(id), B.LAUNCH_ONE);
69
+
70
+ export const readLaunchState = (get: Get, id: LaunchId): Promise<B.LaunchState> => readRoute(get, indexerPath.launchState(id), B.LAUNCH_STATE);
71
+ export const readMilestones = (get: Get, id: LaunchId): Promise<B.LaunchMilestones> => readRoute(get, indexerPath.milestones(id), B.LAUNCH_MILESTONES);
72
+
73
+ export const readHolders = (get: Get, id: LaunchId, q: { limit?: number } = {}): Promise<B.Holders> => readRoute(get, indexerPath.holders(id, q), B.HOLDERS);
74
+
75
+ export const readTrades = (get: Get, id: LaunchId, q: TradesQuery = {}): Promise<B.Trades> => readRoute(get, indexerPath.trades(id, q), B.TRADES);
76
+ export const readLaunchClaims = (get: Get, id: LaunchId, q: { claimer?: string } = {}): Promise<At & { claims: B.LaunchClaim[] }> => readRoute(get, indexerPath.launchClaims(id, q), B.LAUNCH_CLAIMS);
77
+ export const readDevBuys = (get: Get, id: LaunchId): Promise<B.DevBuys> => readRoute(get, indexerPath.devBuys(id), B.DEV_BUYS);
78
+
79
+ export const readTraders = (get: Get, id: LaunchId, q: { window?: B.TraderWindow; limit?: number } = {}): Promise<B.LaunchTraders> => readRoute(get, indexerPath.traders(id, q), B.LAUNCH_TRADERS);
80
+ export const readQuoteChain = (get: Get, id: LaunchId): Promise<B.QuoteChain> => readRoute(get, indexerPath.quoteChain(id), B.QUOTE_CHAIN);
81
+
82
+ export const readDevTrades = (get: Get, id: LaunchId, q: { limit?: number } = {}): Promise<B.DevTrades> => readRoute(get, indexerPath.devTrades(id, q), B.DEV_TRADES);
83
+ export const readBurns = (get: Get, id: LaunchId): Promise<B.Burns> => readRoute(get, indexerPath.burns(id), B.BURNS);
84
+ export const readLaunchLocks = (get: Get, id: LaunchId): Promise<B.LaunchLocks> => readRoute(get, indexerPath.launchLocks(id), B.LAUNCH_LOCKS);
85
+
86
+ export const readMarks = (get: Get, id: LaunchId, q: Page = {}): Promise<B.Marks> => readRoute(get, indexerPath.marks(id, q), B.MARKS);
87
+ export const readPrice = (get: Get, id: LaunchId): Promise<B.Price> => readRoute(get, indexerPath.price(id), B.PRICE);
88
+
89
+ export const readCandles = (get: Get, q: CandlesQuery): Promise<B.Candles> => readRoute(get, indexerPath.candles(q), B.CANDLES);
90
+ export const readCandleBundle = (get: Get, id: LaunchId, q: { intervals?: readonly string[]; limit?: number } = {}): Promise<B.CandleBundle> => readRoute(get, indexerPath.candleBundle(id, q), B.CANDLE_BUNDLE);
91
+ export const readHighs = (get: Get, id: LaunchId, q: { atLeast?: bigint | string; limit?: number } = {}): Promise<B.Highs> => readRoute(get, indexerPath.highs(id, q), B.HIGHS);
92
+
93
+ export const readWalletTrades = (get: Get, wallet: string, q: WalletTradesQuery = {}): Promise<B.WalletTrades> => readRoute(get, indexerPath.walletTrades(wallet, q), B.WALLET_TRADES);
94
+ export const readPositions = (get: Get, wallet: string): Promise<B.Positions> => readRoute(get, indexerPath.positions(wallet), B.POSITIONS);
95
+
96
+ export const readInbox = (get: Get, wallet: string, q: { limit?: number } = {}): Promise<B.Inbox> => readRoute(get, indexerPath.inbox(wallet, q), B.INBOX);
97
+ export const readWalletLocks = (get: Get, wallet: string): Promise<B.WalletLocks> => readRoute(get, indexerPath.walletLocks(wallet), B.WALLET_LOCKS);
98
+ export const readClaimHistory = (get: Get, wallet: string): Promise<B.ClaimHistory> => readRoute(get, indexerPath.claimHistory(wallet), B.CLAIM_HISTORY);
99
+
100
+ export const readClaimView = (get: Get, wallet: string): Promise<B.ClaimView> => readRoute(get, indexerPath.claimView(wallet), B.CLAIM_VIEW);
101
+ export const readFirsts = (get: Get, wallet: string): Promise<At & { wallet: string } & B.Firsts> => readRoute(get, indexerPath.firsts(wallet), B.FIRSTS);
102
+
103
+ export const readFirstsMany = (get: Get, wallets: readonly string[]): Promise<At & { wallets: Record<string, B.Firsts> }> => readRoute(get, indexerPath.firstsMany(wallets), B.FIRSTS_MANY);
104
+ export const readPeople = (get: Get, wallet: string): Promise<B.People> => readRoute(get, indexerPath.people(wallet), B.PEOPLE);
105
+ export const readRoles = (get: Get, wallet: string): Promise<B.Roles> => readRoute(get, indexerPath.roles(wallet), B.ROLES);
106
+
107
+ export const readTraderBoard = (get: Get, q: { window?: B.TraderWindow; limit?: number } = {}): Promise<B.TraderBoard> => readRoute(get, indexerPath.traderBoard(q), B.TRADER_BOARD);
108
+ export const readLauncherBoard = (get: Get, q: { limit?: number } = {}): Promise<B.LauncherBoard> => readRoute(get, indexerPath.launcherBoard(q), B.LAUNCHER_BOARD);
109
+
110
+ export function chainCoins(c: Pick<B.QuoteChain, "chain">): string[] {
111
+ if (c.chain.length === 0) return [];
112
+ return [c.chain[0].token, ...c.chain.map((h) => h.quote)];
113
+ }
114
+
115
+ export function offPriceBps(price: Pick<B.Price, "livePriceX64">, quotedX64: bigint): number | null {
116
+ const p = price.livePriceX64;
117
+ if (p === 0n) return null;
118
+ return Number(((quotedX64 - p) * 10_000n) / p);
119
+ }
@@ -0,0 +1,83 @@
1
+
2
+
3
+ import { decode, int, nullable, object, str, unknown } from "./decode.ts";
4
+ import { HEAD, LIVE_LAUNCH, TRADE } from "./bodies.ts";
5
+ import type { Head, Launch, Trade } from "./bodies.ts";
6
+ import { indexerPath } from "./paths.ts";
7
+ import type { StreamQuery } from "./paths.ts";
8
+
9
+ const HELLO = object({ head: HEAD, window: int, oldest: nullable(str) });
10
+ const HEAD_SEEN = object({ block: int, age: int });
11
+ const LAUNCH_FRAME = object({ launch: LIVE_LAUNCH });
12
+ const STATE = object({ launch: str, mint: str, block: int, ts: nullable(int), seq: int, prev: unknown, state: LIVE_LAUNCH });
13
+ const REORG = object({ block: int, rollbacks: int });
14
+ const RESET = object({ reason: str, head: HEAD });
15
+
16
+ export type StreamFrame =
17
+ | { event: "hello"; data: { head: Head; window: number; oldest: string | null } }
18
+ | { event: "head"; data: { block: number; age: number } }
19
+ | { event: "trade"; id: string; data: Trade }
20
+ | { event: "launch"; data: { launch: Launch } }
21
+ | { event: "launchGone"; data: { launch: string; gone: true } }
22
+ | { event: "state"; data: { launch: string; mint: string; block: number; ts: number | null; seq: number; state: Launch } }
23
+ | { event: "reorg"; data: { block: number; rollbacks: number } }
24
+ | { event: "reset"; data: { reason: string; head: Head } }
25
+ | { event: "comment"; text: string };
26
+
27
+ export function streamPath(q: StreamQuery = {}): string {
28
+ return indexerPath.stream(q);
29
+ }
30
+
31
+ export function decodeStreamFrame(event: string, data: unknown, id?: string): StreamFrame | null {
32
+ switch (event) {
33
+ case "hello":
34
+ return { event, data: decode(HELLO, data) };
35
+ case "head":
36
+ return { event, data: decode(HEAD_SEEN, data) };
37
+ case "trade":
38
+ if (id === undefined) return null;
39
+ return { event, id, data: decode(TRADE, data) };
40
+ case "launch": {
41
+ const d = data as { launch?: unknown; gone?: unknown } | null;
42
+ if (d !== null && typeof d === "object" && d.gone === true) return { event: "launchGone", data: { launch: str(d.launch, "launch"), gone: true } };
43
+ return { event, data: decode(LAUNCH_FRAME, data) };
44
+ }
45
+ case "state": {
46
+ const s = decode(STATE, data);
47
+ return { event, data: { launch: s.launch, mint: s.mint, block: s.block, ts: s.ts, seq: s.seq, state: s.state } };
48
+ }
49
+ case "reorg":
50
+ return { event, data: decode(REORG, data) };
51
+ case "reset":
52
+ return { event, data: decode(RESET, data) };
53
+ default:
54
+ return null;
55
+ }
56
+ }
57
+
58
+ export function parseStreamFrames(text: string): { frames: StreamFrame[]; rest: string } {
59
+ const frames: StreamFrame[] = [];
60
+ let rest = text.replace(/\r\n/g, "\n");
61
+ let cut: number;
62
+ while ((cut = rest.indexOf("\n\n")) >= 0) {
63
+ const block = rest.slice(0, cut);
64
+ rest = rest.slice(cut + 2);
65
+ let event = "message";
66
+ let id: string | undefined;
67
+ const data: string[] = [];
68
+ let comment: string | null = null;
69
+ for (const line of block.split("\n")) {
70
+ if (line.startsWith(":")) comment = line.slice(1).trim();
71
+ else if (line.startsWith("event:")) event = line.slice(6).trim();
72
+ else if (line.startsWith("id:")) id = line.slice(3).trim();
73
+ else if (line.startsWith("data:")) data.push(line.slice(5).replace(/^ /, ""));
74
+ }
75
+ if (data.length === 0) {
76
+ if (comment !== null) frames.push({ event: "comment", text: comment });
77
+ continue;
78
+ }
79
+ const f = decodeStreamFrame(event, JSON.parse(data.join("\n")), id);
80
+ if (f !== null) frames.push(f);
81
+ }
82
+ return { frames, rest };
83
+ }
package/src/lock.ts ADDED
@@ -0,0 +1,16 @@
1
+
2
+
3
+ export function lockVested(amount: bigint, start: bigint, cliff: bigint, end: bigint, now: bigint, scale = 1n): bigint {
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: { amount: bigint; claimed: bigint; start: bigint; cliff: bigint; end: bigint }, now: bigint, scale = 1n): bigint {
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: bigint, start: bigint, cliff: bigint, end: bigint, now: bigint): boolean {
15
+ return amount > 0n && start <= cliff && cliff <= end && end > now;
16
+ }