@floorlaunchpad/sdk 0.3.2 → 0.4.1

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 (75) hide show
  1. package/CHANGELOG.md +94 -0
  2. package/README.md +16 -0
  3. package/dist/abi/evm.gen.js +6 -1
  4. package/dist/abi/solana.gen.js +1 -1
  5. package/dist/client/evm/index.js +16 -2
  6. package/dist/client/solana/index.js +31 -14
  7. package/dist/config/generated.js +26864 -402
  8. package/dist/config/registry.gen.js +33 -2
  9. package/dist/evm/chains.js +85 -16
  10. package/dist/evm/floor/abi.gen.js +1 -1
  11. package/dist/evm/floor/events.js +9 -1
  12. package/dist/evm/floor/legacy-events.js +25 -0
  13. package/dist/evm/router.js +25 -1
  14. package/dist/evm/squid.js +9 -9
  15. package/dist/evm/zap.js +148 -35
  16. package/dist/indexer/bodies.js +96 -17
  17. package/dist/indexer/client.js +36 -14
  18. package/dist/indexer/contract.js +178 -28
  19. package/dist/indexer/partners.js +3 -2
  20. package/dist/indexer/paths.js +87 -29
  21. package/dist/indexer/read.js +30 -15
  22. package/dist/indexer/search.js +130 -0
  23. package/dist/indexer/stack-edge.js +35 -0
  24. package/dist/indexer/stream.js +70 -23
  25. package/dist/math/v2/split.js +11 -3
  26. package/dist/solana/floor/events.js +1 -1
  27. package/dist/solana/floor/genesis.js +9 -3
  28. package/dist/solana/floor/instructions.js +14 -5
  29. package/dist/solana/floor/registry.js +4 -0
  30. package/dist/v2/devbuy.js +6 -4
  31. package/dist/v2/presetRowEvm.js +21 -2
  32. package/dist/v2/solana.js +17 -2
  33. package/dist/v2/tx/solana.js +1 -1
  34. package/docs/aggregator.md +22 -0
  35. package/docs/bot.md +44 -1
  36. package/docs/cursor-pages.md +58 -0
  37. package/docs/floor-line.md +9 -4
  38. package/docs/frontend.md +2 -0
  39. package/docs/wallet.md +2 -0
  40. package/examples/floor-line.html +6 -6
  41. package/package.json +1 -1
  42. package/src/abi/evm.gen.ts +6 -1
  43. package/src/abi/solana.gen.ts +1 -1
  44. package/src/client/evm/index.ts +16 -2
  45. package/src/client/solana/index.ts +31 -14
  46. package/src/client/types.ts +1 -1
  47. package/src/config/generated.ts +26864 -402
  48. package/src/config/index.ts +9 -2
  49. package/src/config/registry.gen.ts +33 -2
  50. package/src/events/types.gen.ts +2 -1
  51. package/src/evm/chains.ts +94 -15
  52. package/src/evm/floor/abi.gen.ts +1 -1
  53. package/src/evm/floor/events.ts +11 -1
  54. package/src/evm/floor/legacy-events.ts +27 -0
  55. package/src/evm/router.ts +26 -1
  56. package/src/evm/squid.ts +9 -9
  57. package/src/evm/zap.ts +185 -36
  58. package/src/indexer/bodies.ts +106 -17
  59. package/src/indexer/client.ts +56 -30
  60. package/src/indexer/contract.ts +197 -29
  61. package/src/indexer/partners.ts +3 -2
  62. package/src/indexer/paths.ts +131 -29
  63. package/src/indexer/read.ts +36 -17
  64. package/src/indexer/search.ts +138 -0
  65. package/src/indexer/stack-edge.ts +46 -0
  66. package/src/indexer/stream.ts +78 -24
  67. package/src/math/v2/split.ts +11 -3
  68. package/src/solana/floor/events.ts +1 -1
  69. package/src/solana/floor/genesis.ts +8 -2
  70. package/src/solana/floor/instructions.ts +13 -5
  71. package/src/solana/floor/registry.ts +4 -0
  72. package/src/v2/devbuy.ts +6 -4
  73. package/src/v2/presetRowEvm.ts +21 -2
  74. package/src/v2/solana.ts +20 -3
  75. package/src/v2/tx/solana.ts +1 -1
@@ -1,10 +1,10 @@
1
1
 
2
2
 
3
3
  import { decode } from "./decode.ts";
4
- import { INDEXER_CONTRACT, clampLimit, routeLimit } from "./contract.ts";
4
+ import { INDEXER_CONTRACT, clampLimit, pageAsked, routeLimit } from "./contract.ts";
5
5
  import type { RouteBody, RouteName } from "./contract.ts";
6
6
  import { indexerPath, query } from "./paths.ts";
7
- import type { CandlesQuery, LaunchesQuery, Page, StreamQuery, TradesQuery, WalletTradesQuery } from "./paths.ts";
7
+ import type { CandlesManyQuery, CandlesQuery, LaunchListsQuery, LaunchSearchQuery, LaunchesQuery, Page, StreamQuery, TradesQuery, WalletPage, WalletTradesQuery } from "./paths.ts";
8
8
  import { IndexerError } from "./read.ts";
9
9
  import type { Get } from "./read.ts";
10
10
  import type { TraderWindow } from "./bodies.ts";
@@ -18,39 +18,44 @@ export interface RouteArgs {
18
18
  stream: StreamQuery;
19
19
  quotes: void;
20
20
  summary: void;
21
- floorRouted: void;
21
+ floorRouted: { limit?: number; cursor?: string } | void;
22
22
  events: { fromBlock: number; toBlock: number };
23
23
  launches: LaunchesQuery | void;
24
+ launchLists: LaunchListsQuery;
25
+ search: LaunchSearchQuery;
24
26
  launch: L;
25
27
  launchState: L;
26
28
  milestones: L;
27
29
  holders: L & { limit?: number };
28
30
  trades: L & TradesQuery;
29
- launchClaims: L & { claimer?: string };
30
- devBuys: L;
31
- memberSold: L;
31
+ launchClaims: L & Page & { claimer?: string };
32
+ devBuys: L & Page;
33
+ memberSold: L & Page;
32
34
  launchAccount: L;
33
35
  traders: L & { window?: TraderWindow; limit?: number };
34
36
  quoteChain: L;
35
37
  devTrades: L & { limit?: number };
36
- burns: L;
38
+ burns: L & Page;
37
39
  launchLocks: L;
38
40
  marks: L & Page;
39
41
  price: L;
40
42
  highs: L & { atLeast?: bigint | string; limit?: number };
41
43
  candles: CandlesQuery;
44
+ candlesMany: CandlesManyQuery;
42
45
  candleBundle: L & { intervals?: readonly string[]; limit?: number };
43
46
  walletTrades: W & WalletTradesQuery;
44
- positions: W;
45
- inbox: W & { limit?: number };
46
- walletLocks: W;
47
- claimHistory: W;
47
+ tonActivity: W & Page;
48
+ tonOutcome: W & { queryId: bigint | string };
49
+ positions: W & WalletPage;
50
+ inbox: W & { limit?: number; before?: string };
51
+ walletLocks: W & WalletPage;
52
+ claimHistory: W & WalletPage;
48
53
  firsts: W;
49
54
  firstsMany: { wallets: readonly string[] };
50
- claimView: W;
51
- people: W;
52
- roles: W;
53
- handlePlaces: { handle: string };
55
+ claimView: W & WalletPage;
56
+ people: W & WalletPage;
57
+ roles: W & WalletPage;
58
+ handlePlaces: { handle: string } & WalletPage;
54
59
  traderBoard: { window?: TraderWindow; limit?: number } | void;
55
60
  launcherBoard: { limit?: number } | void;
56
61
  tokenHolders: { token: string; limit?: number; offset?: number };
@@ -59,7 +64,7 @@ export interface RouteArgs {
59
64
  dexPair: { id: string };
60
65
  cgPairs: void;
61
66
  cgTickers: void;
62
- cgHistoricalTrades: { ticker_id: string; type?: "buy" | "sell"; limit?: number; start_time?: number; end_time?: number };
67
+ cgHistoricalTrades: { ticker_id: string; type?: "buy" | "sell"; limit?: number; before?: string; start_time?: number; end_time?: number };
63
68
  llamaTvl: void;
64
69
  llamaFees: { from: number; to: number } | void;
65
70
  health: void;
@@ -76,39 +81,44 @@ export const routePath: { [N in RouteName]: (a: RouteArgs[N]) => string } = {
76
81
  stream: (a) => indexerPath.stream(a),
77
82
  quotes: () => indexerPath.quotes(),
78
83
  summary: () => indexerPath.summary(),
79
- floorRouted: () => indexerPath.floorRouted(),
84
+ floorRouted: (a) => indexerPath.floorRouted(a ?? {}),
80
85
  events: (a) => indexerPath.events(a.fromBlock, a.toBlock),
81
86
  launches: (a) => indexerPath.launches(a ?? {}),
87
+ launchLists: (a) => indexerPath.launchLists(a),
88
+ search: (a) => indexerPath.search(a),
82
89
  launch: (a) => indexerPath.launch(a.launch),
83
90
  launchState: (a) => indexerPath.launchState(a.launch),
84
91
  milestones: (a) => indexerPath.milestones(a.launch),
85
92
  holders: ({ launch, ...q }) => indexerPath.holders(launch, q),
86
93
  trades: ({ launch, ...q }) => indexerPath.trades(launch, q),
87
94
  launchClaims: ({ launch, ...q }) => indexerPath.launchClaims(launch, q),
88
- devBuys: (a) => indexerPath.devBuys(a.launch),
89
- memberSold: (a) => indexerPath.memberSold(a.launch),
95
+ devBuys: ({ launch, ...q }) => indexerPath.devBuys(launch, q),
96
+ memberSold: ({ launch, ...q }) => indexerPath.memberSold(launch, q),
90
97
  launchAccount: (a) => indexerPath.launchAccount(a.launch),
91
98
  traders: ({ launch, ...q }) => indexerPath.traders(launch, q),
92
99
  quoteChain: (a) => indexerPath.quoteChain(a.launch),
93
100
  devTrades: ({ launch, ...q }) => indexerPath.devTrades(launch, q),
94
- burns: (a) => indexerPath.burns(a.launch),
101
+ burns: ({ launch, ...q }) => indexerPath.burns(launch, q),
95
102
  launchLocks: (a) => indexerPath.launchLocks(a.launch),
96
103
  marks: ({ launch, ...q }) => indexerPath.marks(launch, q),
97
104
  price: (a) => indexerPath.price(a.launch),
98
105
  highs: ({ launch, ...q }) => indexerPath.highs(launch, q),
99
106
  candles: (a) => indexerPath.candles(a),
107
+ candlesMany: (a) => indexerPath.candlesMany(a),
100
108
  candleBundle: ({ launch, ...q }) => indexerPath.candleBundle(launch, q),
101
109
  walletTrades: ({ wallet, ...q }) => indexerPath.walletTrades(wallet, q),
102
- positions: (a) => indexerPath.positions(a.wallet),
110
+ tonActivity: ({ wallet, ...q }) => indexerPath.tonActivity(wallet, q),
111
+ tonOutcome: (a) => indexerPath.tonOutcome(a.wallet, a.queryId),
112
+ positions: ({ wallet, ...q }) => indexerPath.positions(wallet, q),
103
113
  inbox: ({ wallet, ...q }) => indexerPath.inbox(wallet, q),
104
- walletLocks: (a) => indexerPath.walletLocks(a.wallet),
105
- claimHistory: (a) => indexerPath.claimHistory(a.wallet),
114
+ walletLocks: ({ wallet, ...q }) => indexerPath.walletLocks(wallet, q),
115
+ claimHistory: ({ wallet, ...q }) => indexerPath.claimHistory(wallet, q),
106
116
  firsts: (a) => indexerPath.firsts(a.wallet),
107
117
  firstsMany: (a) => indexerPath.firstsMany(a.wallets),
108
- claimView: (a) => indexerPath.claimView(a.wallet),
109
- people: (a) => indexerPath.people(a.wallet),
110
- roles: (a) => indexerPath.roles(a.wallet),
111
- handlePlaces: (a) => indexerPath.handlePlaces(a.handle),
118
+ claimView: ({ wallet, ...q }) => indexerPath.claimView(wallet, q),
119
+ people: ({ wallet, ...q }) => indexerPath.people(wallet, q),
120
+ roles: ({ wallet, ...q }) => indexerPath.roles(wallet, q),
121
+ handlePlaces: ({ handle, ...q }) => indexerPath.handlePlaces(handle, q),
112
122
  traderBoard: (a) => indexerPath.traderBoard(a ?? {}),
113
123
  launcherBoard: (a) => indexerPath.launcherBoard(a ?? {}),
114
124
  tokenHolders: (a) => `/floor-amm/holders/${encodeURIComponent(need(a.token, "token"))}${query({ limit: a.limit, offset: a.offset })}`,
@@ -117,7 +127,7 @@ export const routePath: { [N in RouteName]: (a: RouteArgs[N]) => string } = {
117
127
  dexPair: (a) => `/v2/dex/pair${query({ id: need(a.id, "id") })}`,
118
128
  cgPairs: () => "/v2/coingecko/pairs",
119
129
  cgTickers: () => "/v2/coingecko/tickers",
120
- cgHistoricalTrades: (a) => `/v2/coingecko/historical_trades${query({ ticker_id: need(a.ticker_id, "ticker_id"), type: a.type, limit: a.limit, start_time: a.start_time, end_time: a.end_time })}`,
130
+ cgHistoricalTrades: (a) => `/v2/coingecko/historical_trades${query({ ticker_id: need(a.ticker_id, "ticker_id"), type: a.type, limit: a.limit, before: a.before, start_time: a.start_time, end_time: a.end_time })}`,
121
131
  llamaTvl: () => "/v2/defillama/tvl",
122
132
  llamaFees: (a) => {
123
133
  if (a && a.to < a.from) throw new RangeError("from > to");
@@ -126,7 +136,8 @@ export const routePath: { [N in RouteName]: (a: RouteArgs[N]) => string } = {
126
136
  health: () => "/health",
127
137
  };
128
138
 
129
- export type DrainName = "trades" | "walletTrades" | "launches" | "marks";
139
+ export const DRAIN_NAMES = ["trades", "launchClaims", "memberSold", "burns", "walletTrades", "launches", "search", "marks", "inbox", "positions", "walletLocks", "claimHistory", "people", "roles", "tokenHolders", "tonActivity", "cgHistoricalTrades", "floorRouted", "devBuys", "claimView", "handlePlaces"] as const;
140
+ export type DrainName = (typeof DRAIN_NAMES)[number];
130
141
 
131
142
  export type ReadName = Exclude<RouteName, "stream">;
132
143
 
@@ -150,7 +161,7 @@ export function createIndexerClient(opts: IndexerClientOptions): IndexerClient {
150
161
 
151
162
  const clamp = (name: RouteName, a: unknown): unknown => {
152
163
  if (typeof a !== "object" || a === null || !("limit" in a) || typeof (a as { limit: unknown }).limit !== "number") return a;
153
- return { ...a, limit: clampLimit(name, (a as { limit: number }).limit) };
164
+ return { ...a, limit: clampLimit(name, (a as { limit: number }).limit, pageAsked(name, a as Record<string, unknown>)) };
154
165
  };
155
166
  const path = (name: RouteName, a?: unknown): string => (routePath[name] as (x: unknown) => string)(clamp(name, a));
156
167
  const read = async (name: ReadName, a?: unknown): Promise<unknown> => {
@@ -166,12 +177,27 @@ export function createIndexerClient(opts: IndexerClientOptions): IndexerClient {
166
177
  const max = o.maxPages ?? 100;
167
178
  const lim = routeLimit(name)!;
168
179
  let args: Record<string, unknown> = { ...a };
180
+
181
+ if (page.kind === "cursor" && page.optIn !== undefined && args.before === undefined) args = { ...args, before: "" };
182
+ if (page.kind === "keyset" && page.optIn === true && args.limit === undefined && args.cursor === undefined) args = { ...args, limit: lim.default };
169
183
  for (let i = 0; i < max; i++) {
170
184
  const body = (await read(name, args)) as { next?: string | null; total?: number };
171
185
  yield body;
172
186
  if (page.kind === "cursor") {
173
187
  if (body.next === null || body.next === undefined) return;
174
188
  args = { ...args, before: body.next };
189
+ } else if (page.kind === "keyset") {
190
+
191
+ if (args.ids !== undefined) return;
192
+ if (args.offset !== undefined) {
193
+ const step = clampLimit(name, (args.limit as number | undefined) ?? lim.default);
194
+ const offset = (args.offset as number) + step;
195
+ if (offset >= (body.total ?? 0)) return;
196
+ args = { ...args, offset };
197
+ continue;
198
+ }
199
+ if (body.next === null || body.next === undefined) return;
200
+ args = { ...args, cursor: body.next };
175
201
  } else if (page.kind === "offset") {
176
202
  const step = clampLimit(name, (args.limit as number | undefined) ?? lim.default);
177
203
  const offset = ((args.offset as number | undefined) ?? 0) + step;
@@ -4,7 +4,8 @@ import type { Decoder } from "./decode.ts";
4
4
  import { unknown } from "./decode.ts";
5
5
  import * as B from "./bodies.ts";
6
6
  import * as P from "./partners.ts";
7
- import { FIRSTS_MAX, IDS_MAX, LAUNCHES_PAGE_MAX, LAUNCH_SORTS, STREAM_STATE_MAX } from "./paths.ts";
7
+ import { CANDLES_MANY_IDS_MAX, CANDLES_MANY_LIMIT_DEFAULT, CANDLES_MANY_ROWS_MAX, FIRSTS_MAX, IDS_MAX, LAUNCH_LISTS_QUOTES_MAX, LAUNCH_LISTS_ROWS_MAX, INBOX_PAGE_DEFAULT, INBOX_PAGE_MAX, LAUNCHES_PAGE_DEFAULT, LAUNCHES_PAGE_MAX, LAUNCH_CURSOR_MAX, LAUNCH_SORTS, PRESET_FILTER_MAX, STREAM_STATE_MAX, WALLET_CURSOR_MAX, WALLET_PAGE_DEFAULT, WALLET_PAGE_MAX } from "./paths.ts";
8
+ import { SEARCH_PAGE_DEFAULT, SEARCH_PAGE_MAX, SEARCH_Q_MAX } from "./search.ts";
8
9
 
9
10
  export const UNITS = {
10
11
  site: "raw quote base units, token math units (6 dp), Q64.64 prices, unix s; bigint as decimal strings; USD as decimal strings",
@@ -68,6 +69,8 @@ export interface QueryKey {
68
69
  readonly values?: readonly string[];
69
70
  readonly min?: number;
70
71
  readonly max?: number;
72
+ readonly item?: { readonly kind: "int"; readonly min: number; readonly max: number };
73
+ readonly without?: readonly string[];
71
74
  readonly default?: string | number;
72
75
  readonly required?: boolean;
73
76
  }
@@ -79,7 +82,23 @@ export type Pagination =
79
82
 
80
83
  | { readonly kind: "offset"; readonly limit: { readonly default: number; readonly max: number }; readonly total: "total" }
81
84
 
82
- | { readonly kind: "cursor"; readonly limit: { readonly default: number; readonly max: number }; readonly cursor: "before"; readonly next: "next" }
85
+ | {
86
+ readonly kind: "cursor";
87
+ readonly limit: { readonly default: number; readonly max: number };
88
+ readonly cursor: "before";
89
+ readonly next: "next";
90
+
91
+ readonly optIn?: { readonly default: number; readonly max: number };
92
+ }
93
+
94
+ | {
95
+ readonly kind: "keyset";
96
+ readonly limit: { readonly default: number; readonly max: number };
97
+ readonly cursor: "cursor";
98
+ readonly next: "next";
99
+
100
+ readonly optIn?: true;
101
+ }
83
102
 
84
103
  | { readonly kind: "range"; readonly from: string; readonly to: string; readonly span?: { readonly interval: string; readonly max: number } };
85
104
 
@@ -107,6 +126,15 @@ const limit = (dflt: number, max: number) => ({ kind: "limit", limit: { default:
107
126
  const cursor = (dflt: number, max: number) => ({ kind: "cursor", limit: { default: dflt, max }, cursor: "before", next: "next" }) as const;
108
127
  const LIMIT = (dflt: number, max: number): QueryKey => ({ kind: "int", doc: "rows", min: 1, max, default: dflt });
109
128
  const BEFORE: QueryKey = { kind: "cursor", doc: "a block, or a row id <block>:<txnIndex>:<eventIndex> (a page's next): rows strictly before it" };
129
+ const keyset = (dflt: number, max: number) => ({ kind: "keyset", limit: { default: dflt, max }, cursor: "cursor", next: "next" }) as const;
130
+ const PRESETS: QueryKey = { kind: "list", doc: "only launches of these presets (ids 0..255)", max: PRESET_FILTER_MAX, item: { kind: "int", min: 0, max: 255 } } as const;
131
+
132
+ const WALLET_PAGE = { kind: "keyset", limit: { default: WALLET_PAGE_DEFAULT, max: WALLET_PAGE_MAX }, cursor: "cursor", next: "next", optIn: true } as const;
133
+ const WALLET_PAGE_KEYS = (cursorDoc: string): Record<string, QueryKey> => ({
134
+ limit: { kind: "int", doc: "rows (asks a page)", min: 1, max: WALLET_PAGE_MAX, default: WALLET_PAGE_DEFAULT },
135
+ cursor: { kind: "string", doc: `a page's next (asks a page): ${cursorDoc}`, max: WALLET_CURSOR_MAX },
136
+ });
137
+ const KEYSET_CURSOR = (without: readonly string[]): QueryKey => ({ kind: "string", doc: "a page's next: the rows after its last one (opaque)", max: LAUNCH_CURSOR_MAX, ...(without.length > 0 ? { without } : {}) });
110
138
  const WINDOW: QueryKey = { kind: "enum", doc: "the volume window", values: B.TRADER_WINDOWS, default: "24h" };
111
139
 
112
140
  const GATED = ["not_ready", "upstream"] as const;
@@ -142,7 +170,16 @@ export const INDEXER_CONTRACT = {
142
170
  }),
143
171
  quotes: site({ pattern: "/floor-amm/quotes", body: B.QUOTES }),
144
172
  summary: site({ pattern: "/floor-amm/summary", aliases: ["/floor-amm/v2/summary"], body: B.SUMMARY }),
145
- floorRouted: site({ pattern: "/floor-amm/floor-routed", aliases: ["/floor-amm/v2/floor-routed"], body: B.FLOOR_ROUTED }),
173
+ floorRouted: site({
174
+ pattern: "/floor-amm/floor-routed",
175
+ aliases: ["/floor-amm/v2/floor-routed"],
176
+ query: {
177
+ limit: LIMIT(LAUNCHES_PAGE_DEFAULT, LAUNCHES_PAGE_MAX),
178
+ cursor: { kind: "string", doc: "a page's next: the launches after this launch id, in create order", max: LAUNCH_CURSOR_MAX },
179
+ },
180
+ page: keyset(LAUNCHES_PAGE_DEFAULT, LAUNCHES_PAGE_MAX),
181
+ body: B.FLOOR_ROUTED,
182
+ }),
146
183
  events: site({
147
184
  pattern: "/floor-amm/events",
148
185
  aliases: ["/events", "/v2/dex/events"],
@@ -158,19 +195,57 @@ export const INDEXER_CONTRACT = {
158
195
  query: {
159
196
  sort: { kind: "enum", doc: "the order (larger first with order=desc)", values: LAUNCH_SORTS, default: "created" },
160
197
  order: { kind: "enum", doc: "asc or desc", values: ["asc", "desc"], default: "desc" },
161
- q: { kind: "string", doc: "name or symbol contains, or an id, token or creator equals" },
198
+ q: { kind: "string", doc: "name or symbol contains, or an id, token or creator equals", max: SEARCH_Q_MAX },
162
199
  ids: { kind: "list", doc: "these launches (ids or tokens), in the order asked without sort", max: IDS_MAX },
163
200
  quote: { kind: "string", doc: "launches quoted in this coin" },
164
201
  creator: { kind: "string", doc: "launches by this creator" },
165
202
  rankable: { kind: "bool", doc: "true (or 1) listed only, false (or 0) unlisted only" },
166
203
  graduated: { kind: "bool", doc: "graduated or not (true / false, or 1 / 0)" },
167
- limit: LIMIT(LAUNCHES_PAGE_MAX, LAUNCHES_PAGE_MAX),
168
- offset: { kind: "int", doc: "rows skipped", min: 0, default: 0 },
204
+ preset: PRESETS,
205
+ limit: LIMIT(LAUNCHES_PAGE_DEFAULT, LAUNCHES_PAGE_MAX),
206
+ cursor: KEYSET_CURSOR(["offset", "ids"]),
207
+ offset: { kind: "int", doc: "rows skipped (with total: an offset page)", min: 0, default: 0 },
169
208
  },
170
- page: { kind: "offset", limit: { default: LAUNCHES_PAGE_MAX, max: LAUNCHES_PAGE_MAX }, total: "total" },
209
+
210
+ page: keyset(LAUNCHES_PAGE_DEFAULT, LAUNCHES_PAGE_MAX),
171
211
  errors: [...GATED, "bad_query"],
172
212
  body: B.LAUNCHES,
173
213
  }),
214
+
215
+ launchLists: site({
216
+ pattern: "/floor-amm/launch-lists",
217
+ v2: true,
218
+ query: {
219
+ quotes: { kind: "list", doc: "one list per quote coin, in this order (no repeat)", required: true, min: 1, max: LAUNCH_LISTS_QUOTES_MAX },
220
+ cursors: { kind: "list", doc: "parallel to quotes, one each: that list's page next (- = its first page)", max: LAUNCH_LISTS_QUOTES_MAX },
221
+ sort: { kind: "enum", doc: "the order (larger first with order=desc)", values: LAUNCH_SORTS, default: "created" },
222
+ order: { kind: "enum", doc: "asc or desc", values: ["asc", "desc"], default: "desc" },
223
+ creator: { kind: "string", doc: "launches by this creator" },
224
+ rankable: { kind: "bool", doc: "true (or 1) listed only, false (or 0) unlisted only" },
225
+ graduated: { kind: "bool", doc: "graduated or not (true / false, or 1 / 0)" },
226
+ preset: PRESETS,
227
+ limit: LIMIT(LAUNCHES_PAGE_DEFAULT, LAUNCHES_PAGE_MAX),
228
+ },
229
+ page: limit(LAUNCHES_PAGE_DEFAULT, LAUNCHES_PAGE_MAX),
230
+ errors: [...GATED, "bad_query"],
231
+ body: B.LAUNCH_LISTS,
232
+ }),
233
+ search: site({
234
+ pattern: "/floor-amm/search",
235
+ v2: true,
236
+ query: {
237
+ q: { kind: "string", doc: "the search: symbol, name or token (tiers 0-4, search.ts)", required: true, max: SEARCH_Q_MAX },
238
+ limit: LIMIT(SEARCH_PAGE_DEFAULT, SEARCH_PAGE_MAX),
239
+ cursor: KEYSET_CURSOR([]),
240
+ rankable: { kind: "bool", doc: "true (or 1) listed only, false (or 0) unlisted only" },
241
+ graduated: { kind: "bool", doc: "graduated or not (true / false, or 1 / 0)" },
242
+ quote: { kind: "string", doc: "launches quoted in this coin" },
243
+ preset: PRESETS,
244
+ },
245
+ page: keyset(SEARCH_PAGE_DEFAULT, SEARCH_PAGE_MAX),
246
+ errors: [...GATED, "bad_query"],
247
+ body: B.LAUNCH_SEARCH,
248
+ }),
174
249
  launch: site({ pattern: "/floor-amm/launches/<launch>", v2: true, errors: LAUNCH_ERR, body: B.LAUNCH_ONE }),
175
250
  launchState: site({ pattern: "/floor-amm/launches/<launch>/state", v2: true, errors: ["not_ready", "unknown_launch"], body: B.LAUNCH_STATE }),
176
251
  milestones: site({ pattern: "/floor-amm/launches/<launch>/milestones", v2: true, errors: LAUNCH_ERR, body: B.LAUNCH_MILESTONES }),
@@ -183,16 +258,16 @@ export const INDEXER_CONTRACT = {
183
258
  errors: [...LAUNCH_ERR, "bad_query"],
184
259
  body: B.TRADES,
185
260
  }),
186
- 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 }),
187
- devBuys: site({ pattern: "/floor-amm/launches/<launch>/dev-buys", v2: true, errors: LAUNCH_ERR, body: B.DEV_BUYS }),
261
+ launchClaims: site({ pattern: "/floor-amm/launches/<launch>/claims", v2: true, query: { limit: LIMIT(100, 500), before: BEFORE, claimer: { kind: "string", doc: "only this claimer's rows" } }, page: cursor(100, 500), errors: [...LAUNCH_ERR, "bad_query"], body: B.LAUNCH_CLAIMS }),
262
+ devBuys: site({ pattern: "/floor-amm/launches/<launch>/dev-buys", v2: true, query: { limit: LIMIT(100, 500), before: BEFORE }, page: cursor(100, 500), errors: [...LAUNCH_ERR, "bad_query"], body: B.DEV_BUYS }),
188
263
 
189
- memberSold: site({ pattern: "/floor-amm/launches/<launch>/member-sold", v2: true, errors: LAUNCH_ERR, body: B.MEMBER_SOLD }),
264
+ memberSold: site({ pattern: "/floor-amm/launches/<launch>/member-sold", v2: true, query: { limit: LIMIT(100, 500), before: BEFORE }, page: cursor(100, 500), errors: [...LAUNCH_ERR, "bad_query"], body: B.MEMBER_SOLD }),
190
265
 
191
266
  launchAccount: site({ pattern: "/floor-amm/launches/<launch>/account", v2: true, errors: LAUNCH_ERR, body: B.LAUNCH_ACCOUNT }),
192
267
  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 }),
193
268
  quoteChain: site({ pattern: "/floor-amm/launches/<launch>/chain", v2: true, errors: LAUNCH_ERR, body: B.QUOTE_CHAIN }),
194
269
  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 }),
195
- burns: site({ pattern: "/floor-amm/launches/<launch>/burns", v2: true, errors: LAUNCH_ERR, body: B.BURNS }),
270
+ burns: site({ pattern: "/floor-amm/launches/<launch>/burns", v2: true, query: { limit: LIMIT(100, 500), before: BEFORE }, page: cursor(100, 500), errors: [...LAUNCH_ERR, "bad_query"], body: B.BURNS }),
196
271
  launchLocks: site({ pattern: "/floor-amm/launches/<launch>/locks", v2: true, errors: LAUNCH_ERR, body: B.LAUNCH_LOCKS }),
197
272
  marks: site({
198
273
  pattern: "/floor-amm/launches/<launch>/marks",
@@ -226,6 +301,20 @@ export const INDEXER_CONTRACT = {
226
301
  errors: [...GATED, "bad_query", "unknown_launch", "not_found"],
227
302
  body: B.CANDLES,
228
303
  }),
304
+
305
+ candlesMany: site({
306
+ pattern: "/floor-amm/candles/many",
307
+ aliases: ["/floor-amm/v2/candles/many"],
308
+ query: {
309
+ ids: { kind: "list", doc: "these launches (ids or tokens), one series each in the order asked", required: true, min: 1, max: CANDLES_MANY_IDS_MAX },
310
+ interval: { kind: "enum", doc: "the bucket", values: B.CANDLE_INTERVALS, default: "1h" },
311
+ before: { kind: "unix", doc: "the newest limit traded buckets starting before it (absent: past the indexed head)" },
312
+ limit: { kind: "int", doc: "buckets per launch", min: 1, max: B.CANDLES_MAX, default: CANDLES_MANY_LIMIT_DEFAULT },
313
+ },
314
+ page: limit(CANDLES_MANY_LIMIT_DEFAULT, B.CANDLES_MAX),
315
+ errors: [...GATED, "bad_query"],
316
+ body: B.CANDLES_MANY,
317
+ }),
229
318
  candleBundle: site({
230
319
  pattern: "/floor-amm/launches/<launch>/candle-bundle",
231
320
  v2: true,
@@ -246,17 +335,44 @@ export const INDEXER_CONTRACT = {
246
335
  errors: [...WALLET_ERR, "unknown_launch"],
247
336
  body: B.WALLET_TRADES,
248
337
  }),
249
- positions: site({ pattern: "/floor-amm/wallets/<wallet>/positions", v2: true, errors: WALLET_ERR, body: B.POSITIONS }),
250
- 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 }),
251
- walletLocks: site({ pattern: "/floor-amm/wallets/<wallet>/locks", v2: true, errors: WALLET_ERR, body: B.WALLET_LOCKS }),
252
- claimHistory: site({ pattern: "/floor-amm/wallets/<wallet>/claims", errors: WALLET_ERR, body: B.CLAIM_HISTORY }),
338
+
339
+ tonActivity: site({
340
+ pattern: "/floor-amm/wallets/<wallet>/ton-activity",
341
+ query: { limit: LIMIT(100, 200), before: BEFORE },
342
+ page: cursor(100, 200),
343
+ errors: WALLET_ERR,
344
+ body: B.TON_ACTIVITY,
345
+ }),
346
+ tonOutcome: site({
347
+ pattern: "/floor-amm/wallets/<wallet>/ton-outcome",
348
+ query: { queryId: { kind: "string", doc: "the query id (uint64, decimal) the SDK message carried", required: true } },
349
+ errors: WALLET_ERR,
350
+ body: B.TON_OUTCOME,
351
+ }),
352
+
353
+ positions: site({ pattern: "/floor-amm/wallets/<wallet>/positions", v2: true, query: WALLET_PAGE_KEYS("opaque, launch create order"), page: WALLET_PAGE, errors: WALLET_ERR, body: B.POSITIONS }),
354
+
355
+ inbox: site({
356
+ pattern: "/floor-amm/wallets/<wallet>/inbox",
357
+ v2: true,
358
+ query: { limit: LIMIT(1_000, 1_000), before: { kind: "cursor", doc: "asks a page: empty = the newest; a page's next (opaque): items strictly before it" } },
359
+ page: { kind: "cursor", limit: { default: 1_000, max: 1_000 }, cursor: "before", next: "next", optIn: { default: INBOX_PAGE_DEFAULT, max: INBOX_PAGE_MAX } },
360
+ errors: WALLET_ERR,
361
+ body: B.INBOX,
362
+ }),
363
+ walletLocks: site({ pattern: "/floor-amm/wallets/<wallet>/locks", v2: true, query: WALLET_PAGE_KEYS("opaque, launch create order"), page: WALLET_PAGE, errors: WALLET_ERR, body: B.WALLET_LOCKS }),
364
+ claimHistory: site({ pattern: "/floor-amm/wallets/<wallet>/claims", query: WALLET_PAGE_KEYS("opaque, newest first"), page: WALLET_PAGE, errors: WALLET_ERR, body: B.CLAIM_HISTORY }),
253
365
  firsts: site({ pattern: "/floor-amm/wallets/<wallet>/firsts", errors: WALLET_ERR, body: B.FIRSTS }),
254
366
  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 }),
255
- claimView: site({ pattern: "/floor-amm/claims/<wallet>", errors: [...WALLET_ERR, "no_reader"], body: B.CLAIM_VIEW }),
256
- people: site({ pattern: "/floor-amm/referrals/<wallet>/people", errors: WALLET_ERR, body: B.PEOPLE }),
257
- roles: site({ pattern: "/floor-amm/roles/<wallet>", errors: WALLET_ERR, body: B.ROLES }),
367
+ claimView: site({ pattern: "/floor-amm/claims/<wallet>", query: WALLET_PAGE_KEYS("a page's next: the last row key (l:<launch>, r:<account>, p:<traderRef>, o:<quote>), string order"), page: WALLET_PAGE, errors: [...WALLET_ERR, "bad_query", "no_reader"], body: B.CLAIM_VIEW }),
368
+ people: site({ pattern: "/floor-amm/referrals/<wallet>/people", query: WALLET_PAGE_KEYS("opaque, referred wallet order"), page: WALLET_PAGE, errors: WALLET_ERR, body: B.PEOPLE }),
369
+ roles: site({ pattern: "/floor-amm/roles/<wallet>", query: WALLET_PAGE_KEYS("opaque, a page of launches in create order"), page: WALLET_PAGE, errors: WALLET_ERR, body: B.ROLES }),
258
370
 
259
- handlePlaces: site({ pattern: "/floor-amm/handles/<handle>/places", errors: WALLET_ERR, body: B.HANDLE_PLACES }),
371
+ handlePlaces: site({
372
+ pattern: "/floor-amm/handles/<handle>/places",
373
+ query: { limit: LIMIT(100, 500), cursor: { kind: "string", doc: "a page's next: <launch>:<place>, rows strictly after it", max: WALLET_CURSOR_MAX } },
374
+ page: keyset(100, 500),
375
+ errors: WALLET_ERR, body: B.HANDLE_PLACES }),
260
376
 
261
377
  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 }),
262
378
  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 }),
@@ -281,12 +397,14 @@ export const INDEXER_CONTRACT = {
281
397
  query: {
282
398
  ticker_id: { kind: "string", doc: "<token>_<quote>", required: true },
283
399
  type: { kind: "enum", doc: "one side only", values: ["buy", "sell"] },
284
- limit: { kind: "int", doc: "rows per side (0: all)", min: 0 },
400
+ limit: { kind: "int", doc: "rows per side (absent: 500; 0: all, refused past 5000 rows in all: 413, page with before)", min: 0, max: 5000, default: 500 },
401
+ before: BEFORE,
285
402
  start_time: { kind: "unix", doc: "from (10^11 and over: milliseconds)" },
286
403
  end_time: { kind: "unix", doc: "to (10^11 and over: milliseconds)" },
287
404
  },
288
- page: { kind: "range", from: "start_time", to: "end_time" },
289
- errors: [...GATED, "bad_query", "not_found"],
405
+
406
+ page: cursor(500, 5000),
407
+ errors: [...GATED, "bad_query", "not_found", "too_many"],
290
408
  body: P.CG_HISTORICAL,
291
409
  }),
292
410
  llamaTvl: partner({ pattern: "/v2/defillama/tvl", errors: GATED, body: P.LLAMA_TVL }),
@@ -344,7 +462,7 @@ export const OPEN_ROUTES = {
344
462
 
345
463
  export function routeLimit(name: RouteName): { readonly default: number; readonly max: number } | null {
346
464
  const p: Pagination = INDEXER_CONTRACT[name].page;
347
- return p.kind === "limit" || p.kind === "offset" || p.kind === "cursor" ? p.limit : null;
465
+ return p.kind === "limit" || p.kind === "offset" || p.kind === "cursor" || p.kind === "keyset" ? p.limit : null;
348
466
  }
349
467
 
350
468
  export const LIMITS = Object.fromEntries(ROUTE_NAMES.flatMap((n) => {
@@ -352,9 +470,29 @@ export const LIMITS = Object.fromEntries(ROUTE_NAMES.flatMap((n) => {
352
470
  return l === null ? [] : [[n, l]];
353
471
  })) as Readonly<Partial<Record<RouteName, { readonly default: number; readonly max: number }>>>;
354
472
 
355
- export function clampLimit(name: RouteName, n: number): number {
356
- const l = routeLimit(name);
357
- return l === null ? n : Math.min(Math.max(1, Math.trunc(n)), l.max);
473
+ export function clampLimit(name: RouteName, n: number, paged = false): number {
474
+ const p: Pagination = INDEXER_CONTRACT[name].page;
475
+ const l = paged && p.kind === "cursor" && p.optIn !== undefined ? p.optIn : routeLimit(name);
476
+
477
+ const lo = (INDEXER_CONTRACT[name].query as Record<string, QueryKey>).limit?.min ?? 1;
478
+ return l === null ? n : Math.min(Math.max(lo, Math.trunc(n)), l.max);
479
+ }
480
+
481
+ export function pageAsked(name: RouteName, _q?: URLSearchParams | Record<string, unknown>): boolean {
482
+ const p: Pagination = INDEXER_CONTRACT[name].page;
483
+
484
+ if (p.kind === "cursor" && p.optIn !== undefined) return true;
485
+ if (p.kind === "keyset" && p.optIn === true) return true;
486
+ return false;
487
+ }
488
+
489
+ export function pageLimit(name: RouteName, q: URLSearchParams): number {
490
+ const p: Pagination = INDEXER_CONTRACT[name].page;
491
+ if (p.kind === "cursor" && p.optIn !== undefined) {
492
+ const raw = q.get("limit");
493
+ return raw === null || raw === "" || !DIGITS.test(raw) ? p.optIn.default : Math.min(Math.max(1, Number(raw)), p.optIn.max);
494
+ }
495
+ return queryLimit(name, q);
358
496
  }
359
497
 
360
498
  const DIGITS = /^\d+$/;
@@ -370,7 +508,11 @@ export function queryRefusal(name: RouteName, q: URLSearchParams): string | null
370
508
  const spec: Readonly<Record<string, QueryKey>> = INDEXER_CONTRACT[name].query;
371
509
  for (const [key, k] of Object.entries(spec)) {
372
510
  const raw = q.get(key);
373
- if (raw === null || raw === "") continue;
511
+ if (raw === null || raw === "") {
512
+ if (k.required === true && TABLE_REQUIRED.has(name)) return `${key} is required`;
513
+ continue;
514
+ }
515
+ for (const w of k.without ?? []) if ((q.get(w) ?? "") !== "") return `${key} cannot be given with ${w}`;
374
516
  switch (k.kind) {
375
517
  case "int": {
376
518
  const lo = k.min ?? 0;
@@ -379,10 +521,15 @@ export function queryRefusal(name: RouteName, q: URLSearchParams): string | null
379
521
  break;
380
522
  }
381
523
  case "list": {
382
- const n = raw.split(",").filter((s) => s !== "").length;
383
- if (k.max !== undefined && n > k.max) return `at most ${k.max} ${key}`;
524
+ const parts = raw.split(",").filter((s) => s !== "");
525
+ if (k.max !== undefined && parts.length > k.max) return `at most ${k.max} ${key}`;
526
+ const it = k.item;
527
+ if (it !== undefined && parts.some((x) => !DIGITS.test(x) || Number(x) < it.min || Number(x) > it.max)) return `each ${key} must be an integer ${it.min}..${it.max}`;
384
528
  break;
385
529
  }
530
+ case "string":
531
+ if (k.max !== undefined && raw.length > k.max) return `${key} must be at most ${k.max} characters`;
532
+ break;
386
533
  case "enum":
387
534
  if (k.values !== undefined && !k.values.includes(raw)) return `${key} must be one of ${k.values.join(", ")}`;
388
535
  break;
@@ -393,9 +540,30 @@ export function queryRefusal(name: RouteName, q: URLSearchParams): string | null
393
540
  break;
394
541
  }
395
542
  }
543
+
544
+ const prod = ROWS_PRODUCT[name];
545
+ if (prod !== undefined) {
546
+ const n = (q.get(prod.list) ?? "").split(",").filter((s) => s !== "").length;
547
+ const raw = q.get("limit");
548
+ const lim = raw === null || raw === "" ? routeLimit(name)!.default : Number(raw);
549
+ if (n * lim > prod.max) return `${prod.list} × limit must be at most ${prod.max} (asked ${n} × ${lim})`;
550
+ }
551
+
552
+ const pg: Pagination = INDEXER_CONTRACT[name].page;
553
+ if (pg.kind === "cursor" && pg.optIn !== undefined && q.get(pg.cursor) !== null) {
554
+ const raw = q.get("limit");
555
+ if (raw !== null && raw !== "" && Number(raw) > pg.optIn.max) return `limit must be 1..${pg.optIn.max} with ${pg.cursor}`;
556
+ }
396
557
  return spanRefusal(name, q);
397
558
  }
398
559
 
560
+ const ROWS_PRODUCT: Partial<Record<RouteName, { list: string; max: number }>> = {
561
+ launchLists: { list: "quotes", max: LAUNCH_LISTS_ROWS_MAX },
562
+ candlesMany: { list: "ids", max: CANDLES_MANY_ROWS_MAX },
563
+ };
564
+
565
+ const TABLE_REQUIRED: ReadonlySet<RouteName> = new Set<RouteName>(["search", "launchLists", "candlesMany"]);
566
+
399
567
  const BOOLS: Readonly<Record<string, boolean>> = { true: true, false: false, 1: true, 0: false };
400
568
 
401
569
  export function queryArg(name: RouteName, q: URLSearchParams, key: string): string | undefined {
@@ -50,7 +50,8 @@ export const DEX_SUMMARY = object({
50
50
  export type DexSummary = Infer<typeof DEX_SUMMARY>;
51
51
 
52
52
  export const DEX_PAIR = object({
53
- pair: object({ id: str, asset0Id: str, asset1Id: str, createdAtBlockNumber: int, createdAtBlockTimestamp: int, feeBps: nullable(num) }),
53
+ pair: object({ id: str, asset0Id: str, asset1Id: str, createdAtBlockNumber: int, createdAtBlockTimestamp: int, feeBps: nullable(num), dexKey: str, createdAtTxnId: optional(str), creator: str }),
54
+ launch: optional(object({ id: str, token: str })),
54
55
  });
55
56
  export type DexPair = Infer<typeof DEX_PAIR>;
56
57
 
@@ -81,7 +82,7 @@ export type CgTickers = Infer<typeof CG_TICKERS>;
81
82
  export const CG_TRADE = object({ trade_id: int, price: decimal, base_volume: decimal, target_volume: decimal, trade_timestamp: int, type: oneOf("buy", "sell") });
82
83
  export type CgTrade = Infer<typeof CG_TRADE>;
83
84
 
84
- export const CG_HISTORICAL = object({ buy: optional(array(CG_TRADE)), sell: optional(array(CG_TRADE)) });
85
+ export const CG_HISTORICAL = object({ buy: optional(array(CG_TRADE)), sell: optional(array(CG_TRADE)), next: optional(nullable(str)) });
85
86
  export type CgHistorical = Infer<typeof CG_HISTORICAL>;
86
87
 
87
88
  export const LLAMA_TVL = object({ mode: LIQUIDITY_MODE, tvl: record(big), launchTokens: array(str) });