@floorlaunchpad/sdk 0.3.2 → 0.4.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 (62) hide show
  1. package/CHANGELOG.md +66 -0
  2. package/README.md +14 -0
  3. package/dist/abi/evm.gen.js +1 -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 +19 -7
  7. package/dist/config/generated.js +26864 -402
  8. package/dist/config/registry.gen.js +33 -2
  9. package/dist/evm/chains.js +9 -1
  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/indexer/bodies.js +91 -17
  14. package/dist/indexer/client.js +34 -14
  15. package/dist/indexer/contract.js +132 -28
  16. package/dist/indexer/partners.js +3 -2
  17. package/dist/indexer/paths.js +61 -29
  18. package/dist/indexer/read.js +27 -15
  19. package/dist/indexer/search.js +130 -0
  20. package/dist/indexer/stack-edge.js +35 -0
  21. package/dist/indexer/stream.js +70 -23
  22. package/dist/math/v2/split.js +11 -3
  23. package/dist/solana/floor/events.js +1 -1
  24. package/dist/solana/floor/genesis.js +9 -3
  25. package/dist/solana/floor/instructions.js +14 -5
  26. package/dist/solana/floor/registry.js +4 -0
  27. package/dist/v2/solana.js +17 -2
  28. package/dist/v2/tx/solana.js +1 -1
  29. package/docs/bot.md +36 -1
  30. package/docs/cursor-pages.md +56 -0
  31. package/docs/floor-line.md +9 -4
  32. package/examples/floor-line.html +6 -6
  33. package/package.json +1 -1
  34. package/src/abi/evm.gen.ts +1 -1
  35. package/src/abi/solana.gen.ts +1 -1
  36. package/src/client/evm/index.ts +16 -2
  37. package/src/client/solana/index.ts +19 -7
  38. package/src/client/types.ts +1 -1
  39. package/src/config/generated.ts +26864 -402
  40. package/src/config/index.ts +9 -2
  41. package/src/config/registry.gen.ts +33 -2
  42. package/src/events/types.gen.ts +2 -1
  43. package/src/evm/chains.ts +9 -1
  44. package/src/evm/floor/abi.gen.ts +1 -1
  45. package/src/evm/floor/events.ts +11 -1
  46. package/src/evm/floor/legacy-events.ts +27 -0
  47. package/src/indexer/bodies.ts +99 -17
  48. package/src/indexer/client.ts +52 -30
  49. package/src/indexer/contract.ts +151 -29
  50. package/src/indexer/partners.ts +3 -2
  51. package/src/indexer/paths.ts +84 -29
  52. package/src/indexer/read.ts +33 -17
  53. package/src/indexer/search.ts +138 -0
  54. package/src/indexer/stack-edge.ts +46 -0
  55. package/src/indexer/stream.ts +78 -24
  56. package/src/math/v2/split.ts +11 -3
  57. package/src/solana/floor/events.ts +1 -1
  58. package/src/solana/floor/genesis.ts +8 -2
  59. package/src/solana/floor/instructions.ts +13 -5
  60. package/src/solana/floor/registry.ts +4 -0
  61. package/src/v2/solana.ts +20 -3
  62. package/src/v2/tx/solana.ts +1 -1
@@ -38,17 +38,24 @@ export interface ChainRow {
38
38
  name: ChainName;
39
39
 
40
40
  label: string;
41
- family: "solana" | "evm";
41
+ family: "solana" | "evm" | "ton";
42
42
  v2DayOne: boolean;
43
43
  chainId?: number;
44
44
  cluster?: string;
45
+
46
+ network?: string;
47
+ globalId?: number;
48
+
49
+ nativeDecimals?: number;
45
50
  native: string;
46
51
 
47
52
  nativeName: string;
48
53
 
49
54
  floorAmmAddress?: string | null;
55
+
56
+ tonFactoryAddress?: string | null;
50
57
  rpcEnv: string;
51
- soak: { name?: string; chainId?: number; cluster?: string; rpcEnv: string };
58
+ soak: { name?: string; chainId?: number; cluster?: string; network?: string; globalId?: number; rpcEnv: string };
52
59
  explorer: ExplorerRow;
53
60
  quotes: readonly QuoteRow[];
54
61
  }
@@ -110,9 +110,40 @@ export const CHAIN_REGISTRY = [
110
110
  },
111
111
  "finality": "finalized",
112
112
  "reorgWindow": 65
113
+ },
114
+ {
115
+ "slug": "elysium",
116
+ "label": "Elysium",
117
+ "family": "evm",
118
+ "v2DayOne": false,
119
+ "chainId": 99901,
120
+ "soakChainId": 99801,
121
+ "native": {
122
+ "name": "Hype",
123
+ "symbol": "HYPE"
124
+ },
125
+ "finality": "safe",
126
+ "reorgWindow": 3400
127
+ },
128
+ {
129
+ "slug": "ton",
130
+ "label": "TON",
131
+ "family": "ton",
132
+ "v2DayOne": false,
133
+ "network": "mainnet",
134
+ "globalId": -239,
135
+ "soakNetwork": "testnet",
136
+ "soakGlobalId": -3,
137
+ "native": {
138
+ "name": "Gram",
139
+ "symbol": "GRAM",
140
+ "decimals": 9
141
+ }
113
142
  }
114
143
  ] as const;
115
144
 
116
- export const CHAIN_SLUGS = ["solana","ethereum","base","bsc","arbitrum","arc","robinhood","hyperevm"] as const;
145
+ export const CHAIN_SLUGS = ["solana","ethereum","base","bsc","arbitrum","arc","robinhood","hyperevm","elysium","ton"] as const;
146
+
147
+ export const EVM_CHAIN_SLUGS = ["ethereum","base","bsc","arbitrum","arc","robinhood","hyperevm","elysium"] as const;
117
148
 
118
- export const EVM_CHAIN_SLUGS = ["ethereum","base","bsc","arbitrum","arc","robinhood","hyperevm"] as const;
149
+ export const TON_CHAIN_SLUGS = ["ton"] as const;
@@ -24,11 +24,12 @@ export interface SolLaunchCreatedFields {
24
24
  }
25
25
  export interface SolGraduatedFields {
26
26
  launch: string;
27
- priceX64: bigint;
27
+ windowPriceX64: bigint;
28
28
  windowRaised: bigint;
29
29
  windowTokens: bigint;
30
30
  slot: bigint;
31
31
  ts: bigint;
32
+ priceX64: bigint;
32
33
  }
33
34
  export interface SolPotsSweptFields {
34
35
  launch: string;
package/src/evm/chains.ts CHANGED
@@ -109,6 +109,14 @@ const ROUTES: Record<ChainKey, Omit<EvmChain, "key" | "chainId" | "name" | "nati
109
109
  "⚠ No WETH9: WRAP_ETH does not apply; only v4 pools in address(0) take the native coin. The zap is for third-token quotes only.",
110
110
  ],
111
111
  },
112
+ elysium: {
113
+ wrappedNative: null,
114
+ zapRouters: [],
115
+ notes: [
116
+ "⚠ Arbitrum Orbit on HyperEVM: in a contract block.number is HyperEVM's block; the receipt's block is Elysium's.",
117
+ "⚠ No zap routers yet (no DEX read back on chain) and no wrapped HYPE address published: the native coin and listed quotes only.",
118
+ ],
119
+ },
112
120
  };
113
121
 
114
122
  export const EVM_CHAINS: Record<ChainKey, EvmChain> = Object.fromEntries(
@@ -133,7 +141,7 @@ export const FLOOR_SALTS = {
133
141
  export const FLOOR_AMM_ADDRESS: string | null = "0xF10000bd05c2C01793C6d55F027346469683d225";
134
142
 
135
143
  export const FLOOR_AMM_FROM_BLOCK: Readonly<Record<ChainKey, number | null>> = {
136
- ethereum: 26327910, base: 53421827, bsc: 131270813, arbitrum: 520655168, arc: 29205598, robinhood: 104455459, hyperevm: 50398055,
144
+ ethereum: 26327910, base: 53421827, bsc: 131270813, arbitrum: 520655168, arc: 29205598, robinhood: 104455459, hyperevm: 50398055, elysium: 6058368,
137
145
  };
138
146
 
139
147
  const cat = (...h: string[]): string => "0x" + h.map((x) => bytesToHex(hexToBytes(x)).slice(2)).join("");
@@ -51,7 +51,7 @@ export const FLOOR_AMM_ABI = [
51
51
  {"type":"error","name":"UnknownClaimType","inputs":[]},
52
52
  {"type":"error","name":"UnknownLaunch","inputs":[]},
53
53
  {"type":"event","name":"ClaimSkipped","inputs":[{"name":"wallet","type":"address","indexed":true},{"name":"quote","type":"address","indexed":true},{"name":"amount","type":"uint256","indexed":false}],"anonymous":false},
54
- {"type":"event","name":"Claimed","inputs":[{"name":"wallet","type":"address","indexed":true},{"name":"sender","type":"address","indexed":true},{"name":"quote","type":"address","indexed":true},{"name":"types","type":"uint8","indexed":false},{"name":"creator","type":"uint256","indexed":false},{"name":"creatorRef","type":"uint256","indexed":false},{"name":"teamSlot","type":"uint256","indexed":false},{"name":"traderRef","type":"uint256","indexed":false},{"name":"holder","type":"uint256","indexed":false},{"name":"extra","type":"uint256","indexed":false},{"name":"amount","type":"uint256","indexed":false}],"anonymous":false},
54
+ {"type":"event","name":"Claimed","inputs":[{"name":"wallet","type":"address","indexed":true},{"name":"sender","type":"address","indexed":true},{"name":"quote","type":"address","indexed":true},{"name":"types","type":"uint16","indexed":false},{"name":"creator","type":"uint256","indexed":false},{"name":"creatorRef","type":"uint256","indexed":false},{"name":"teamSlot","type":"uint256","indexed":false},{"name":"traderRef","type":"uint256","indexed":false},{"name":"holder","type":"uint256","indexed":false},{"name":"extra","type":"uint256","indexed":false},{"name":"amount","type":"uint256","indexed":false}],"anonymous":false},
55
55
  {"type":"event","name":"ConfigWritten","inputs":[{"name":"authority","type":"address","indexed":false},{"name":"pendingAuthority","type":"address","indexed":false},{"name":"timelock","type":"address","indexed":false},{"name":"referralAuthority","type":"address","indexed":false},{"name":"createPaused","type":"bool","indexed":false},{"name":"holderDest","type":"address","indexed":false}],"anonymous":false},
56
56
  {"type":"event","name":"CreatorBuyUnlocked","inputs":[{"name":"launchId","type":"uint256","indexed":true},{"name":"creator","type":"address","indexed":true},{"name":"tokens","type":"uint256","indexed":false},{"name":"members","type":"uint256[10]","indexed":false},{"name":"paid","type":"uint256","indexed":false}],"anonymous":false},
57
57
  {"type":"event","name":"Graduated","inputs":[{"name":"launchId","type":"uint256","indexed":true},{"name":"windowPriceX64","type":"uint256","indexed":false},{"name":"priceX64","type":"uint256","indexed":false},{"name":"windowRaised","type":"uint256","indexed":false},{"name":"windowTokens","type":"uint256","indexed":false}],"anonymous":false},
@@ -3,6 +3,7 @@
3
3
  import { checksumAddress } from "../abi.ts";
4
4
  import { decodeEventLog, itemTopic } from "../items.ts";
5
5
  import type { EventArgsOf, EventName, Log } from "../items.ts";
6
+ import { LEGACY_CLAIMED_TOPIC, LEGACY_EVENTS, normalizeLegacyClaimed } from "./legacy-events.ts";
6
7
  import { FLOOR_AMM_ABI, FLOOR_AMM_UNFROZEN_EVENTS, FLOOR_ZAP_ABI } from "./iface.ts";
7
8
 
8
9
  export type FloorEventName = EventName<typeof FLOOR_AMM_ABI> | EventName<typeof FLOOR_ZAP_ABI>;
@@ -15,6 +16,8 @@ export interface FloorEvmEvent {
15
16
  address?: string;
16
17
 
17
18
  unfrozen?: true;
19
+
20
+ legacy?: true;
18
21
  }
19
22
 
20
23
  const ALL = [...FLOOR_AMM_ABI, ...FLOOR_ZAP_ABI, ...FLOOR_AMM_UNFROZEN_EVENTS];
@@ -38,10 +41,17 @@ for (const i of ALL.filter((i) => i.type === "event").reverse()) {
38
41
  });
39
42
  }
40
43
 
44
+ export const FLOOR_LEGACY_EVENT_TOPICS: Record<string, string> = { Claimed: LEGACY_CLAIMED_TOPIC };
45
+
41
46
  export function decodeFloorLog(log: Log, from?: readonly string[]): FloorEvmEvent | null {
42
47
  if (from && (!log.address || !from.some((a) => a.toLowerCase() === log.address!.toLowerCase()))) return null;
43
48
  const d: FloorEvmEvent | null = decodeEventLog(ALL, log);
44
- if (!d) return null;
49
+ if (!d) {
50
+ const old = decodeEventLog(LEGACY_EVENTS, log);
51
+ if (!old) return null;
52
+ const e: FloorEvmEvent = { ...old, args: normalizeLegacyClaimed(old.args), legacy: true };
53
+ return log.address ? { ...e, address: checksumAddress(log.address) } : e;
54
+ }
45
55
  if (UNFROZEN().has((log.topics[0] ?? "").toLowerCase())) d.unfrozen = true;
46
56
  return log.address ? { ...d, address: checksumAddress(log.address) } : d;
47
57
  }
@@ -0,0 +1,27 @@
1
+
2
+
3
+ import type { AbiItem } from "../items.ts";
4
+
5
+ export const LEGACY_CLAIMED_SIGNATURE =
6
+ "Claimed(address,address,address,uint8,uint256,uint256,uint256,uint256,uint256,uint256,uint256)";
7
+ export const LEGACY_CLAIMED_TOPIC = "0x586c69c7198e9e5c48c058d0267bd1388a73f9a8878aeb9d72d25331acc39aeb";
8
+
9
+ export const LEGACY_EVENTS: readonly AbiItem[] = [
10
+ {
11
+ type: "event", name: "Claimed", anonymous: false, inputs: [
12
+ { name: "wallet", type: "address", indexed: true }, { name: "sender", type: "address", indexed: true },
13
+ { name: "quote", type: "address", indexed: true }, { name: "types", type: "uint8", indexed: false },
14
+ { name: "creator", type: "uint256", indexed: false }, { name: "creatorRef", type: "uint256", indexed: false },
15
+ { name: "teamSlot", type: "uint256", indexed: false }, { name: "traderRef", type: "uint256", indexed: false },
16
+ { name: "holder", type: "uint256", indexed: false }, { name: "extra", type: "uint256", indexed: false },
17
+ { name: "amount", type: "uint256", indexed: false },
18
+ ],
19
+ },
20
+ ];
21
+
22
+ export const CLAIM_HOLDER_BIT = 512n;
23
+
24
+ export function normalizeLegacyClaimed(args: Record<string, any>): Record<string, any> {
25
+ const types = BigInt(args.types);
26
+ return { ...args, types: BigInt(args.holder) > 0n ? types | CLAIM_HOLDER_BIT : types };
27
+ }
@@ -1,6 +1,6 @@
1
1
 
2
2
 
3
- import { array, big, bool, decimal, int, nullable, object, oneOf, optional, record, str } from "./decode.ts";
3
+ import { ShapeError, array, big, bool, decimal, int, nullable, object, oneOf, optional, record, str } from "./decode.ts";
4
4
  import type { Decoder, Infer } from "./decode.ts";
5
5
  import type { DevBuy, DevBuyRole } from "../v2/devbuy.ts";
6
6
 
@@ -30,6 +30,7 @@ export const DEV_BUY = object({
30
30
  block: int,
31
31
  timestamp: int,
32
32
  tx: str,
33
+ id: str,
33
34
  });
34
35
 
35
36
  export type DevBuyItem = Infer<typeof DEV_BUY>;
@@ -103,6 +104,12 @@ const LAUNCH_FIELDS = {
103
104
  unlisted: bool,
104
105
  quoteDecimals: nullable(int),
105
106
  teamSlotRateBps: nullable(int),
107
+
108
+ nextBuyPriceX64: optional(nullable(big)),
109
+ stackEndX64: optional(nullable(big)),
110
+ stackLeft: optional(nullable(big)),
111
+ stackSold: optional(nullable(big)),
112
+ stackSoldBps: optional(nullable(int)),
106
113
  bidTopX64: nullable(big),
107
114
  teamBuyUnlockAt: nullable(int),
108
115
  teamBuyUnlocked: bool,
@@ -123,19 +130,25 @@ const LAUNCH_FIELDS = {
123
130
  export const LAUNCH = object(LAUNCH_FIELDS);
124
131
  export type Launch = Infer<typeof LAUNCH>;
125
132
 
126
- export const LISTED_LAUNCH = object({
133
+ const LISTED_FIELDS = {
127
134
  ...LAUNCH_FIELDS,
128
135
  volume24hGross: nullable(big),
129
136
  holders: int,
137
+
138
+ maxLossPpm: optional(nullable(int)),
139
+
130
140
  backedPpm: nullable(int),
131
141
  volume24hUsd: nullable(decimal),
132
142
  marketCapUsd: nullable(decimal),
133
143
 
134
144
  trendingScore: nullable(big),
135
- });
145
+
146
+ change24hBps: optional(nullable(int)),
147
+ };
148
+ export const LISTED_LAUNCH = object(LISTED_FIELDS);
136
149
  export type ListedLaunch = Infer<typeof LISTED_LAUNCH>;
137
150
 
138
- export const LIVE_LAUNCH = object({ ...LAUNCH_FIELDS, volume24hGross: nullable(big), holders: int });
151
+ export const LIVE_LAUNCH = object({ ...LAUNCH_FIELDS, volume24hGross: nullable(big), holders: int, change24hBps: optional(nullable(int)) });
139
152
  export type LiveLaunch = Infer<typeof LIVE_LAUNCH>;
140
153
 
141
154
  const TRADE_FIELDS = {
@@ -226,6 +239,8 @@ export const FLOOR_ROUTED = object({
226
239
  indexed,
227
240
  launches: array(object({ launch: str, quote: str, floorFee: big, floorMilestone: big })),
228
241
  pending: array(object({ quote: str, amount: big })),
242
+
243
+ next: optional(nullable(str)),
229
244
  });
230
245
  export type FloorRouted = Infer<typeof FLOOR_ROUTED>;
231
246
 
@@ -249,11 +264,25 @@ export const EVENTS = object({
249
264
  });
250
265
  export type Events = Infer<typeof EVENTS>;
251
266
 
252
- export const LAUNCHES_ALL = object({ indexed, launches: array(LISTED_LAUNCH) });
267
+ const nextCursor: Decoder<string | null> = (v, p) => (v === undefined || v === null ? null : str(v, p));
268
+
269
+ const perRow = <T>(d: Decoder<T>): Decoder<T[]> => (v, p) => (v === undefined ? [] : array(d)(v, p));
253
270
 
254
- export const LAUNCHES = object({ indexed, total: int, offset: int, launches: array(LISTED_LAUNCH), missing: array(str) });
271
+ export const LAUNCHES = object({
272
+ indexed, total: int, offset: int, launches: array(LISTED_LAUNCH), missing: array(str),
273
+ cursors: perRow(str), keys: perRow(nullable(str)), next: optional(nullable(str)),
274
+ });
255
275
  export type Launches = Infer<typeof LAUNCHES>;
256
276
 
277
+ const SEARCH_SERVED_TIER: Decoder<0 | 1 | 2 | 3 | 4> = (v, p) => {
278
+ const n = int(v, p);
279
+ if (n < 0 || n > 4) throw new ShapeError(p, "a tier 0..4", v);
280
+ return n as 0 | 1 | 2 | 3 | 4;
281
+ };
282
+
283
+ export const LAUNCH_SEARCH = object({ indexed, q: str, launches: array(object({ ...LISTED_FIELDS, tier: SEARCH_SERVED_TIER })), next: nextCursor });
284
+ export type LaunchSearch = Infer<typeof LAUNCH_SEARCH>;
285
+
257
286
  export const LAUNCH_ONE = object({ indexed, launch: LISTED_LAUNCH });
258
287
 
259
288
  export const LAUNCH_STATE = object({ launch: str, mint: str, block: nullable(int), ts: nullable(int), seq: int, state: LIVE_LAUNCH });
@@ -268,16 +297,17 @@ export type Holders = Infer<typeof HOLDERS>;
268
297
  export const TRADES = object({ indexed, trades: array(PAGED_TRADE), next: nullable(str) });
269
298
  export type Trades = Infer<typeof TRADES>;
270
299
 
271
- export const LAUNCH_CLAIM = object({ launch: str, claimer: str, types: int, quote: str, amount: big, holder: big, teamBuy: optional(big), block: int, ts: int, tx: str });
300
+ export const LAUNCH_CLAIM = object({ launch: str, claimer: str, types: int, quote: str, amount: big, holder: big, teamBuy: optional(big), block: int, ts: int, tx: str, id: optional(str) });
272
301
  export type LaunchClaim = Infer<typeof LAUNCH_CLAIM>;
273
- export const LAUNCH_CLAIMS = object({ indexed, claims: array(LAUNCH_CLAIM) });
302
+ export const LAUNCH_CLAIMS = object({ indexed, claims: array(LAUNCH_CLAIM), next: optional(nullable(str)) });
303
+ export type LaunchClaims = Infer<typeof LAUNCH_CLAIMS>;
274
304
 
275
- export const DEV_BUYS = object({ indexed, teamBuyUnlocked: bool, teamBuyUnlockedTs: nullable(int), devBuys: array(DEV_BUY) });
305
+ export const DEV_BUYS = object({ indexed, teamBuyUnlocked: bool, teamBuyUnlockedTs: nullable(int), devBuys: array(DEV_BUY), next: optional(nullable(str)) });
276
306
  export type DevBuys = Infer<typeof DEV_BUYS>;
277
307
 
278
308
  export const MEMBER_SOLD_ROW = object({ launch: str, member: str, place: int, amount: big, quoteOut: big, block: int, timestamp: int, tx: str, id: str });
279
309
  export type MemberSoldRow = Infer<typeof MEMBER_SOLD_ROW>;
280
- export const MEMBER_SOLD = object({ indexed, memberSold: array(MEMBER_SOLD_ROW) });
310
+ export const MEMBER_SOLD = object({ indexed, memberSold: array(MEMBER_SOLD_ROW), next: optional(nullable(str)) });
281
311
  export type MemberSoldBody = Infer<typeof MEMBER_SOLD>;
282
312
 
283
313
  export const LAUNCH_ACCOUNT = object({ indexed, launch: str, mint: str, slot: int, data: str });
@@ -313,6 +343,8 @@ export const CANDLE = object({
313
343
  volumeSellQuoteRaw: big,
314
344
  buys: int,
315
345
  sells: int,
346
+
347
+ floorX64: optional(nullable(big)),
316
348
  });
317
349
  export type Candle = Infer<typeof CANDLE>;
318
350
 
@@ -368,7 +400,7 @@ export type QuoteChain = Infer<typeof QUOTE_CHAIN>;
368
400
  export const DEV_TRADES = object({ indexed, launch: str, creator: str, trades: array(TRADE) });
369
401
  export type DevTrades = Infer<typeof DEV_TRADES>;
370
402
 
371
- export const BURNS = object({ indexed, launch: str, burns: array(object({ amount: big, block: int, timestamp: int })), program: array(BURN), wallet: array(BURN) });
403
+ export const BURNS = object({ indexed, launch: str, burns: array(object({ id: optional(str), amount: big, block: int, timestamp: int })), program: array(object({ ...BURN_FIELDS, id: optional(str) })), wallet: array(object({ ...BURN_FIELDS, id: optional(str) })), next: optional(nullable(str)) });
372
404
  export type Burns = Infer<typeof BURNS>;
373
405
 
374
406
  const LOCK_HOLDER = object({ wallet: str, place: nullable(int) });
@@ -394,6 +426,9 @@ export const PRICE = object({
394
426
  priceX64: big,
395
427
  livePriceX64: big,
396
428
  floorX64: big,
429
+
430
+ maxLossPpm: optional(nullable(int)),
431
+
397
432
  backedPpm: int,
398
433
  bidTopX64: nullable(big),
399
434
  lastTrade: nullable(object({ priceAfterX64: big, timestamp: int, block: int })),
@@ -407,17 +442,50 @@ export type Price = Infer<typeof PRICE>;
407
442
  export const WALLET_TRADES = object({ indexed, wallet: str, trades: array(PAGED_TRADE), next: nullable(str) });
408
443
  export type WalletTrades = Infer<typeof WALLET_TRADES>;
409
444
 
410
- export const POSITIONS = object({ indexed, wallet: str, positions: array(object({ launch: str, token: str, quote: str, tokens: big })) });
445
+ export const TON_ACTIVITY_KINDS = ["buy", "sell", "claim", "team_slot_add", "team_share_buy", "burn", "withdraw", "create", "unlock_team_buy", "backing", "refused", "aborted"] as const;
446
+
447
+ export const TON_FILL = object({ tokensIn: nullable(big), tokensOut: nullable(big), quoteIn: nullable(big), quoteOut: nullable(big), refund: nullable(big) });
448
+ export type TonFill = Infer<typeof TON_FILL>;
449
+
450
+ export const TON_REASON = object({ code: oneOf("aborted", "refused"), op: nullable(int), class: nullable(int), refunded: nullable(big) });
451
+ export type TonReason = Infer<typeof TON_REASON>;
452
+
453
+ export const TON_ACTIVITY_ROW = object({
454
+ id: str,
455
+ txnId: str,
456
+ block: int,
457
+ timestamp: int,
458
+ kind: oneOf(...TON_ACTIVITY_KINDS),
459
+ status: oneOf("landed", "failed"),
460
+ final: bool,
461
+ launch: nullable(str),
462
+ quote: nullable(str),
463
+ queryId: nullable(str),
464
+ types: nullable(int),
465
+ fill: TON_FILL,
466
+ reason: nullable(TON_REASON),
467
+ });
468
+ export type TonActivityRow = Infer<typeof TON_ACTIVITY_ROW>;
469
+
470
+ export const TON_ACTIVITY = object({ indexed, wallet: str, activity: array(TON_ACTIVITY_ROW), next: nullable(str) });
471
+ export type TonActivity = Infer<typeof TON_ACTIVITY>;
472
+
473
+ export const TON_OUTCOME = object({ indexed, wallet: str, queryId: str, outcome: oneOf("pending", "landed", "failed"), seen: bool, row: nullable(TON_ACTIVITY_ROW) });
474
+ export type TonOutcome = Infer<typeof TON_OUTCOME>;
475
+
476
+ export const POSITIONS = object({ indexed, wallet: str, positions: array(object({ launch: str, token: str, quote: str, tokens: big })), next: optional(nullable(str)) });
411
477
  export type Positions = Infer<typeof POSITIONS>;
412
478
 
413
479
  export const WALLET_LOCKS = object({
414
480
  indexed,
415
481
  wallet: str,
416
482
  locks: array(object({ launch: str, token: str, kind: oneOf("teamBuy"), direction: oneOf("incoming", "outgoing"), tokens: big, place: nullable(int), createdAt: int, unlocked: bool, unlockedAt: nullable(int), unlockAt: nullable(int), locked: big, claimed: big, holders: array(LOCK_HOLDER) })),
483
+
484
+ next: optional(nullable(str)),
417
485
  });
418
486
  export type WalletLocks = Infer<typeof WALLET_LOCKS>;
419
487
 
420
- const AT = { timestamp: int, block: int };
488
+ const AT = { timestamp: int, block: int, id: optional(str) };
421
489
 
422
490
  export const INBOX_CLAIMED = object({ ...AT, kind: oneOf("claimed"), launch: str, quote: str, types: int, amount: big, holder: big, txnId: nullable(str) });
423
491
 
@@ -425,7 +493,7 @@ export const INBOX_GRADUATED = object({ ...AT, kind: oneOf("graduated"), launch:
425
493
 
426
494
  export const INBOX_SLOT = object({ ...AT, kind: oneOf("slot"), launch: str, place: int });
427
495
 
428
- export const INBOX_DEV_BURN = object({ ...BURN_FIELDS, kind: oneOf("devBurn"), launch: str });
496
+ export const INBOX_DEV_BURN = object({ ...BURN_FIELDS, id: optional(str), kind: oneOf("devBurn"), launch: str });
429
497
 
430
498
  export const INBOX_DEV_BUY = object({ ...AT, kind: oneOf("devBuy"), launch: str, wallet: str, role: DEV_BUY_ROLE, count: int, quoteIn: big, tokens: big, txnId: nullable(str) });
431
499
 
@@ -444,7 +512,7 @@ export function inboxItem(v: unknown, p: string): InboxItem | null {
444
512
  return d(v, p) as InboxItem;
445
513
  }
446
514
 
447
- export const INBOX = object({ indexed, wallet: str, items: (v: unknown, p: string) => array(inboxItem)(v, p).filter((x): x is InboxItem => x !== null) });
515
+ export const INBOX = object({ indexed, wallet: str, items: (v: unknown, p: string) => array(inboxItem)(v, p).filter((x): x is InboxItem => x !== null), next: optional(nullable(str)) });
448
516
  export type Inbox = Infer<typeof INBOX>;
449
517
 
450
518
  export const CLAIM_ROW = object({
@@ -452,7 +520,7 @@ export const CLAIM_ROW = object({
452
520
  timestamp: int,
453
521
  txnId: nullable(str),
454
522
  sender: str,
455
- launch: str,
523
+ launch: nullable(str),
456
524
  quote: str,
457
525
  types: int,
458
526
  creator: big,
@@ -466,7 +534,7 @@ export const CLAIM_ROW = object({
466
534
  });
467
535
  export type ClaimRow = Infer<typeof CLAIM_ROW>;
468
536
 
469
- export const CLAIM_HISTORY = object({ indexed, wallet: str, claims: array(CLAIM_ROW) });
537
+ export const CLAIM_HISTORY = object({ indexed, wallet: str, claims: array(CLAIM_ROW), next: optional(nullable(str)) });
470
538
  export type ClaimHistory = Infer<typeof CLAIM_HISTORY>;
471
539
 
472
540
  const QUOTE_TOTAL = object({ quote: str, total: big, types: int });
@@ -489,6 +557,8 @@ export const CLAIM_VIEW = object({
489
557
  refOwed: optional(array(object({ account: str, quoteMint: str, owed: big }))),
490
558
  pendingRollUp: optional(array(object({ traderRef: str, quoteMint: str, amount: big }))),
491
559
  owed: optional(array(object({ quote: str, creator: big, creatorRef: big, teamSlot: big, traderRef: big, holder: big, teamBuy: big }))),
560
+
561
+ next: optional(nullable(str)),
492
562
  }),
493
563
  });
494
564
  export type ClaimView = Infer<typeof CLAIM_VIEW>;
@@ -504,6 +574,8 @@ export const PEOPLE = object({
504
574
  indexed,
505
575
  wallet: str,
506
576
  people: array(object({ wallet: str, chain: str, roles: array(object({ kind: oneOf("trader", "creator"), tier: int })), earned: PER_QUOTE, teamMilestone: PER_QUOTE })),
577
+
578
+ next: optional(nullable(str)),
507
579
  });
508
580
  export type People = Infer<typeof PEOPLE>;
509
581
 
@@ -523,6 +595,8 @@ export const ROLES = object({
523
595
  holdings: array(object({ launch: str, token: str, amount: big })),
524
596
  }),
525
597
  claimed: record(big),
598
+
599
+ next: optional(nullable(str)),
526
600
  });
527
601
  export type Roles = Infer<typeof ROLES>;
528
602
 
@@ -530,6 +604,8 @@ export const HANDLE_PLACES = object({
530
604
  indexed,
531
605
  handle: str,
532
606
  places: array(object({ launch: str, place: int })),
607
+
608
+ next: optional(nullable(str)),
533
609
  });
534
610
  export type HandlePlaces = Infer<typeof HANDLE_PLACES>;
535
611
 
@@ -545,3 +621,9 @@ export const LAUNCHER_BOARD = object({
545
621
  launchers: array(object({ creator: str, launches: int, graduated: int, volumeUsd: decimal, liquidityUsd: decimal, bestLaunch: nullable(str), byQuote: record(object({ volume: big, liquidity: big, launches: int })) })),
546
622
  });
547
623
  export type LauncherBoard = Infer<typeof LAUNCHER_BOARD>;
624
+
625
+ export function maxLossPct(b: { maxLossPpm?: number | null; backedPpm?: number | null; graduated?: boolean }): number | null {
626
+ if (b.maxLossPpm != null) return b.maxLossPpm / 10_000;
627
+ if (b.maxLossPpm === undefined && b.graduated === true && b.backedPpm != null) return Math.max(0, 1_000_000 - b.backedPpm) / 10_000;
628
+ return null;
629
+ }
@@ -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 { CandlesQuery, 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,22 +18,23 @@ 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
+ search: LaunchSearchQuery;
24
25
  launch: L;
25
26
  launchState: L;
26
27
  milestones: L;
27
28
  holders: L & { limit?: number };
28
29
  trades: L & TradesQuery;
29
- launchClaims: L & { claimer?: string };
30
- devBuys: L;
31
- memberSold: L;
30
+ launchClaims: L & Page & { claimer?: string };
31
+ devBuys: L & Page;
32
+ memberSold: L & Page;
32
33
  launchAccount: L;
33
34
  traders: L & { window?: TraderWindow; limit?: number };
34
35
  quoteChain: L;
35
36
  devTrades: L & { limit?: number };
36
- burns: L;
37
+ burns: L & Page;
37
38
  launchLocks: L;
38
39
  marks: L & Page;
39
40
  price: L;
@@ -41,16 +42,18 @@ export interface RouteArgs {
41
42
  candles: CandlesQuery;
42
43
  candleBundle: L & { intervals?: readonly string[]; limit?: number };
43
44
  walletTrades: W & WalletTradesQuery;
44
- positions: W;
45
- inbox: W & { limit?: number };
46
- walletLocks: W;
47
- claimHistory: W;
45
+ tonActivity: W & Page;
46
+ tonOutcome: W & { queryId: bigint | string };
47
+ positions: W & WalletPage;
48
+ inbox: W & { limit?: number; before?: string };
49
+ walletLocks: W & WalletPage;
50
+ claimHistory: W & WalletPage;
48
51
  firsts: W;
49
52
  firstsMany: { wallets: readonly string[] };
50
- claimView: W;
51
- people: W;
52
- roles: W;
53
- handlePlaces: { handle: string };
53
+ claimView: W & WalletPage;
54
+ people: W & WalletPage;
55
+ roles: W & WalletPage;
56
+ handlePlaces: { handle: string } & WalletPage;
54
57
  traderBoard: { window?: TraderWindow; limit?: number } | void;
55
58
  launcherBoard: { limit?: number } | void;
56
59
  tokenHolders: { token: string; limit?: number; offset?: number };
@@ -59,7 +62,7 @@ export interface RouteArgs {
59
62
  dexPair: { id: string };
60
63
  cgPairs: void;
61
64
  cgTickers: void;
62
- cgHistoricalTrades: { ticker_id: string; type?: "buy" | "sell"; limit?: number; start_time?: number; end_time?: number };
65
+ cgHistoricalTrades: { ticker_id: string; type?: "buy" | "sell"; limit?: number; before?: string; start_time?: number; end_time?: number };
63
66
  llamaTvl: void;
64
67
  llamaFees: { from: number; to: number } | void;
65
68
  health: void;
@@ -76,22 +79,23 @@ export const routePath: { [N in RouteName]: (a: RouteArgs[N]) => string } = {
76
79
  stream: (a) => indexerPath.stream(a),
77
80
  quotes: () => indexerPath.quotes(),
78
81
  summary: () => indexerPath.summary(),
79
- floorRouted: () => indexerPath.floorRouted(),
82
+ floorRouted: (a) => indexerPath.floorRouted(a ?? {}),
80
83
  events: (a) => indexerPath.events(a.fromBlock, a.toBlock),
81
84
  launches: (a) => indexerPath.launches(a ?? {}),
85
+ search: (a) => indexerPath.search(a),
82
86
  launch: (a) => indexerPath.launch(a.launch),
83
87
  launchState: (a) => indexerPath.launchState(a.launch),
84
88
  milestones: (a) => indexerPath.milestones(a.launch),
85
89
  holders: ({ launch, ...q }) => indexerPath.holders(launch, q),
86
90
  trades: ({ launch, ...q }) => indexerPath.trades(launch, q),
87
91
  launchClaims: ({ launch, ...q }) => indexerPath.launchClaims(launch, q),
88
- devBuys: (a) => indexerPath.devBuys(a.launch),
89
- memberSold: (a) => indexerPath.memberSold(a.launch),
92
+ devBuys: ({ launch, ...q }) => indexerPath.devBuys(launch, q),
93
+ memberSold: ({ launch, ...q }) => indexerPath.memberSold(launch, q),
90
94
  launchAccount: (a) => indexerPath.launchAccount(a.launch),
91
95
  traders: ({ launch, ...q }) => indexerPath.traders(launch, q),
92
96
  quoteChain: (a) => indexerPath.quoteChain(a.launch),
93
97
  devTrades: ({ launch, ...q }) => indexerPath.devTrades(launch, q),
94
- burns: (a) => indexerPath.burns(a.launch),
98
+ burns: ({ launch, ...q }) => indexerPath.burns(launch, q),
95
99
  launchLocks: (a) => indexerPath.launchLocks(a.launch),
96
100
  marks: ({ launch, ...q }) => indexerPath.marks(launch, q),
97
101
  price: (a) => indexerPath.price(a.launch),
@@ -99,16 +103,18 @@ export const routePath: { [N in RouteName]: (a: RouteArgs[N]) => string } = {
99
103
  candles: (a) => indexerPath.candles(a),
100
104
  candleBundle: ({ launch, ...q }) => indexerPath.candleBundle(launch, q),
101
105
  walletTrades: ({ wallet, ...q }) => indexerPath.walletTrades(wallet, q),
102
- positions: (a) => indexerPath.positions(a.wallet),
106
+ tonActivity: ({ wallet, ...q }) => indexerPath.tonActivity(wallet, q),
107
+ tonOutcome: (a) => indexerPath.tonOutcome(a.wallet, a.queryId),
108
+ positions: ({ wallet, ...q }) => indexerPath.positions(wallet, q),
103
109
  inbox: ({ wallet, ...q }) => indexerPath.inbox(wallet, q),
104
- walletLocks: (a) => indexerPath.walletLocks(a.wallet),
105
- claimHistory: (a) => indexerPath.claimHistory(a.wallet),
110
+ walletLocks: ({ wallet, ...q }) => indexerPath.walletLocks(wallet, q),
111
+ claimHistory: ({ wallet, ...q }) => indexerPath.claimHistory(wallet, q),
106
112
  firsts: (a) => indexerPath.firsts(a.wallet),
107
113
  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),
114
+ claimView: ({ wallet, ...q }) => indexerPath.claimView(wallet, q),
115
+ people: ({ wallet, ...q }) => indexerPath.people(wallet, q),
116
+ roles: ({ wallet, ...q }) => indexerPath.roles(wallet, q),
117
+ handlePlaces: ({ handle, ...q }) => indexerPath.handlePlaces(handle, q),
112
118
  traderBoard: (a) => indexerPath.traderBoard(a ?? {}),
113
119
  launcherBoard: (a) => indexerPath.launcherBoard(a ?? {}),
114
120
  tokenHolders: (a) => `/floor-amm/holders/${encodeURIComponent(need(a.token, "token"))}${query({ limit: a.limit, offset: a.offset })}`,
@@ -117,7 +123,7 @@ export const routePath: { [N in RouteName]: (a: RouteArgs[N]) => string } = {
117
123
  dexPair: (a) => `/v2/dex/pair${query({ id: need(a.id, "id") })}`,
118
124
  cgPairs: () => "/v2/coingecko/pairs",
119
125
  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 })}`,
126
+ 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
127
  llamaTvl: () => "/v2/defillama/tvl",
122
128
  llamaFees: (a) => {
123
129
  if (a && a.to < a.from) throw new RangeError("from > to");
@@ -126,7 +132,8 @@ export const routePath: { [N in RouteName]: (a: RouteArgs[N]) => string } = {
126
132
  health: () => "/health",
127
133
  };
128
134
 
129
- export type DrainName = "trades" | "walletTrades" | "launches" | "marks";
135
+ 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;
136
+ export type DrainName = (typeof DRAIN_NAMES)[number];
130
137
 
131
138
  export type ReadName = Exclude<RouteName, "stream">;
132
139
 
@@ -150,7 +157,7 @@ export function createIndexerClient(opts: IndexerClientOptions): IndexerClient {
150
157
 
151
158
  const clamp = (name: RouteName, a: unknown): unknown => {
152
159
  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) };
160
+ return { ...a, limit: clampLimit(name, (a as { limit: number }).limit, pageAsked(name, a as Record<string, unknown>)) };
154
161
  };
155
162
  const path = (name: RouteName, a?: unknown): string => (routePath[name] as (x: unknown) => string)(clamp(name, a));
156
163
  const read = async (name: ReadName, a?: unknown): Promise<unknown> => {
@@ -166,12 +173,27 @@ export function createIndexerClient(opts: IndexerClientOptions): IndexerClient {
166
173
  const max = o.maxPages ?? 100;
167
174
  const lim = routeLimit(name)!;
168
175
  let args: Record<string, unknown> = { ...a };
176
+
177
+ if (page.kind === "cursor" && page.optIn !== undefined && args.before === undefined) args = { ...args, before: "" };
178
+ if (page.kind === "keyset" && page.optIn === true && args.limit === undefined && args.cursor === undefined) args = { ...args, limit: lim.default };
169
179
  for (let i = 0; i < max; i++) {
170
180
  const body = (await read(name, args)) as { next?: string | null; total?: number };
171
181
  yield body;
172
182
  if (page.kind === "cursor") {
173
183
  if (body.next === null || body.next === undefined) return;
174
184
  args = { ...args, before: body.next };
185
+ } else if (page.kind === "keyset") {
186
+
187
+ if (args.ids !== undefined) return;
188
+ if (args.offset !== undefined) {
189
+ const step = clampLimit(name, (args.limit as number | undefined) ?? lim.default);
190
+ const offset = (args.offset as number) + step;
191
+ if (offset >= (body.total ?? 0)) return;
192
+ args = { ...args, offset };
193
+ continue;
194
+ }
195
+ if (body.next === null || body.next === undefined) return;
196
+ args = { ...args, cursor: body.next };
175
197
  } else if (page.kind === "offset") {
176
198
  const step = clampLimit(name, (args.limit as number | undefined) ?? lim.default);
177
199
  const offset = ((args.offset as number | undefined) ?? 0) + step;