@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.
- package/CHANGELOG.md +66 -0
- package/README.md +14 -0
- package/dist/abi/evm.gen.js +1 -1
- package/dist/abi/solana.gen.js +1 -1
- package/dist/client/evm/index.js +16 -2
- package/dist/client/solana/index.js +19 -7
- package/dist/config/generated.js +26864 -402
- package/dist/config/registry.gen.js +33 -2
- package/dist/evm/chains.js +9 -1
- package/dist/evm/floor/abi.gen.js +1 -1
- package/dist/evm/floor/events.js +9 -1
- package/dist/evm/floor/legacy-events.js +25 -0
- package/dist/indexer/bodies.js +91 -17
- package/dist/indexer/client.js +34 -14
- package/dist/indexer/contract.js +132 -28
- package/dist/indexer/partners.js +3 -2
- package/dist/indexer/paths.js +61 -29
- package/dist/indexer/read.js +27 -15
- package/dist/indexer/search.js +130 -0
- package/dist/indexer/stack-edge.js +35 -0
- package/dist/indexer/stream.js +70 -23
- package/dist/math/v2/split.js +11 -3
- package/dist/solana/floor/events.js +1 -1
- package/dist/solana/floor/genesis.js +9 -3
- package/dist/solana/floor/instructions.js +14 -5
- package/dist/solana/floor/registry.js +4 -0
- package/dist/v2/solana.js +17 -2
- package/dist/v2/tx/solana.js +1 -1
- package/docs/bot.md +36 -1
- package/docs/cursor-pages.md +56 -0
- package/docs/floor-line.md +9 -4
- package/examples/floor-line.html +6 -6
- package/package.json +1 -1
- package/src/abi/evm.gen.ts +1 -1
- package/src/abi/solana.gen.ts +1 -1
- package/src/client/evm/index.ts +16 -2
- package/src/client/solana/index.ts +19 -7
- package/src/client/types.ts +1 -1
- package/src/config/generated.ts +26864 -402
- package/src/config/index.ts +9 -2
- package/src/config/registry.gen.ts +33 -2
- package/src/events/types.gen.ts +2 -1
- package/src/evm/chains.ts +9 -1
- package/src/evm/floor/abi.gen.ts +1 -1
- package/src/evm/floor/events.ts +11 -1
- package/src/evm/floor/legacy-events.ts +27 -0
- package/src/indexer/bodies.ts +99 -17
- package/src/indexer/client.ts +52 -30
- package/src/indexer/contract.ts +151 -29
- package/src/indexer/partners.ts +3 -2
- package/src/indexer/paths.ts +84 -29
- package/src/indexer/read.ts +33 -17
- package/src/indexer/search.ts +138 -0
- package/src/indexer/stack-edge.ts +46 -0
- package/src/indexer/stream.ts +78 -24
- package/src/math/v2/split.ts +11 -3
- package/src/solana/floor/events.ts +1 -1
- package/src/solana/floor/genesis.ts +8 -2
- package/src/solana/floor/instructions.ts +13 -5
- package/src/solana/floor/registry.ts +4 -0
- package/src/v2/solana.ts +20 -3
- package/src/v2/tx/solana.ts +1 -1
package/src/indexer/read.ts
CHANGED
|
@@ -6,18 +6,21 @@ import * as B from "./bodies.ts";
|
|
|
6
6
|
import { indexerPath } from "./paths.ts";
|
|
7
7
|
import { errorCode } from "./contract.ts";
|
|
8
8
|
import type { IndexerErrorCode } from "./contract.ts";
|
|
9
|
-
import type { CandlesQuery, LaunchesQuery, Page, TradesQuery, WalletTradesQuery } from "./paths.ts";
|
|
9
|
+
import type { CandlesQuery, LaunchSearchQuery, LaunchesQuery, Page, TradesQuery, WalletPage, WalletTradesQuery } from "./paths.ts";
|
|
10
10
|
|
|
11
11
|
export * from "./bodies.ts";
|
|
12
12
|
export { ShapeError, decode } from "./decode.ts";
|
|
13
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";
|
|
14
|
+
export { FIRSTS_MAX, IDS_MAX, INDEXER_ROUTES, LAUNCHES_PAGE_DEFAULT, LAUNCHES_PAGE_MAX, LAUNCH_CURSOR_MAX, LAUNCH_SORTS, PRESET_FILTER_MAX, STREAM_STATE_MAX, INBOX_PAGE_DEFAULT, INBOX_PAGE_MAX, WALLET_CURSOR_MAX, WALLET_PAGE_DEFAULT, WALLET_PAGE_MAX, indexerPath, query } from "./paths.ts";
|
|
15
|
+
export { ADDRESS_PREFIX_MIN, SEARCH_PAGE_DEFAULT, SEARCH_PAGE_MAX, SEARCH_PARITY_CORPUS, SEARCH_Q_MAX, SEARCH_SUBSTRING_MIN, searchFold, searchNeedle, searchNeedles, searchServed, searchServedTier, searchTier, searchTierFolded } from "./search.ts";
|
|
16
|
+
export type { SearchSubject, SearchTier } from "./search.ts";
|
|
15
17
|
export * from "./partners.ts";
|
|
16
|
-
export
|
|
18
|
+
export * from "./stack-edge.ts";
|
|
19
|
+
export { INDEXER_CONTRACT, INDEXER_ERROR_CODES, LIMITS, OPEN_ROUTES, ROUTE_NAMES, UNITS, clampLimit, errorCode, matchRoute, pageAsked, pageLimit, queryArg, queryBool, queryLimit, queryRefusal, routeLimit, spanRefusal } from "./contract.ts";
|
|
17
20
|
export type { IndexerErrorCode, Pagination, PathParam, QueryKey, RouteBody, RouteContract, RouteName, Served, ServedBody, ServedKeys, Units } from "./contract.ts";
|
|
18
|
-
export { createIndexerClient, routePath } from "./client.ts";
|
|
21
|
+
export { DRAIN_NAMES, createIndexerClient, routePath } from "./client.ts";
|
|
19
22
|
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";
|
|
23
|
+
export type { CandlesQuery, IndexerRoute, IndexerRouteName, LaunchSearchQuery, LaunchSort, LaunchesQuery, Page, StreamQuery, TradesQuery, WalletPage, WalletTradesQuery } from "./paths.ts";
|
|
21
24
|
|
|
22
25
|
export type LaunchId = string;
|
|
23
26
|
|
|
@@ -65,6 +68,8 @@ export const readEvents = (get: Get, fromBlock: number, toBlock: number): Promis
|
|
|
65
68
|
|
|
66
69
|
export const readLaunches = (get: Get, q: LaunchesQuery = {}): Promise<B.Launches> => readRoute(get, indexerPath.launches(q), B.LAUNCHES);
|
|
67
70
|
|
|
71
|
+
export const readLaunchSearch = (get: Get, q: LaunchSearchQuery): Promise<B.LaunchSearch> => readRoute(get, indexerPath.search(q), B.LAUNCH_SEARCH);
|
|
72
|
+
|
|
68
73
|
export const readLaunch = (get: Get, id: LaunchId): Promise<At & { launch: B.ListedLaunch }> => readRoute(get, indexerPath.launch(id), B.LAUNCH_ONE);
|
|
69
74
|
|
|
70
75
|
export const readLaunchState = (get: Get, id: LaunchId): Promise<B.LaunchState> => readRoute(get, indexerPath.launchState(id), B.LAUNCH_STATE);
|
|
@@ -73,10 +78,10 @@ export const readMilestones = (get: Get, id: LaunchId): Promise<B.LaunchMileston
|
|
|
73
78
|
export const readHolders = (get: Get, id: LaunchId, q: { limit?: number } = {}): Promise<B.Holders> => readRoute(get, indexerPath.holders(id, q), B.HOLDERS);
|
|
74
79
|
|
|
75
80
|
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<
|
|
77
|
-
export const readDevBuys = (get: Get, id: LaunchId): Promise<B.DevBuys> => readRoute(get, indexerPath.devBuys(id), B.DEV_BUYS);
|
|
81
|
+
export const readLaunchClaims = (get: Get, id: LaunchId, q: Page & { claimer?: string } = {}): Promise<B.LaunchClaims> => readRoute(get, indexerPath.launchClaims(id, q), B.LAUNCH_CLAIMS);
|
|
82
|
+
export const readDevBuys = (get: Get, id: LaunchId, q: Page = {}): Promise<B.DevBuys> => readRoute(get, indexerPath.devBuys(id, q), B.DEV_BUYS);
|
|
78
83
|
|
|
79
|
-
export const readMemberSold = (get: Get, id: LaunchId): Promise<B.MemberSoldBody> => readRoute(get, indexerPath.memberSold(id), B.MEMBER_SOLD);
|
|
84
|
+
export const readMemberSold = (get: Get, id: LaunchId, q: Page = {}): Promise<B.MemberSoldBody> => readRoute(get, indexerPath.memberSold(id, q), B.MEMBER_SOLD);
|
|
80
85
|
|
|
81
86
|
export const readLaunchAccount = (get: Get, id: LaunchId): Promise<B.LaunchAccountBody> => readRoute(get, indexerPath.launchAccount(id), B.LAUNCH_ACCOUNT);
|
|
82
87
|
|
|
@@ -91,7 +96,7 @@ export const readTraders = (get: Get, id: LaunchId, q: { window?: B.TraderWindow
|
|
|
91
96
|
export const readQuoteChain = (get: Get, id: LaunchId): Promise<B.QuoteChain> => readRoute(get, indexerPath.quoteChain(id), B.QUOTE_CHAIN);
|
|
92
97
|
|
|
93
98
|
export const readDevTrades = (get: Get, id: LaunchId, q: { limit?: number } = {}): Promise<B.DevTrades> => readRoute(get, indexerPath.devTrades(id, q), B.DEV_TRADES);
|
|
94
|
-
export const readBurns = (get: Get, id: LaunchId): Promise<B.Burns> => readRoute(get, indexerPath.burns(id), B.BURNS);
|
|
99
|
+
export const readBurns = (get: Get, id: LaunchId, q: Page = {}): Promise<B.Burns> => readRoute(get, indexerPath.burns(id, q), B.BURNS);
|
|
95
100
|
export const readLaunchLocks = (get: Get, id: LaunchId): Promise<B.LaunchLocks> => readRoute(get, indexerPath.launchLocks(id), B.LAUNCH_LOCKS);
|
|
96
101
|
|
|
97
102
|
export const readMarks = (get: Get, id: LaunchId, q: Page = {}): Promise<B.Marks> => readRoute(get, indexerPath.marks(id, q), B.MARKS);
|
|
@@ -102,20 +107,22 @@ export const readCandleBundle = (get: Get, id: LaunchId, q: { intervals?: readon
|
|
|
102
107
|
export const readHighs = (get: Get, id: LaunchId, q: { atLeast?: bigint | string; limit?: number } = {}): Promise<B.Highs> => readRoute(get, indexerPath.highs(id, q), B.HIGHS);
|
|
103
108
|
|
|
104
109
|
export const readWalletTrades = (get: Get, wallet: string, q: WalletTradesQuery = {}): Promise<B.WalletTrades> => readRoute(get, indexerPath.walletTrades(wallet, q), B.WALLET_TRADES);
|
|
105
|
-
export const
|
|
110
|
+
export const readTonActivity = (get: Get, wallet: string, q: Page = {}): Promise<B.TonActivity> => readRoute(get, indexerPath.tonActivity(wallet, q), B.TON_ACTIVITY);
|
|
111
|
+
export const readTonOutcome = (get: Get, wallet: string, queryId: bigint | string): Promise<B.TonOutcome> => readRoute(get, indexerPath.tonOutcome(wallet, queryId), B.TON_OUTCOME);
|
|
112
|
+
export const readPositions = (get: Get, wallet: string, q: WalletPage = {}): Promise<B.Positions> => readRoute(get, indexerPath.positions(wallet, q), B.POSITIONS);
|
|
106
113
|
|
|
107
|
-
export const readInbox = (get: Get, wallet: string, q: { limit?: number } = {}): Promise<B.Inbox> => readRoute(get, indexerPath.inbox(wallet, q), B.INBOX);
|
|
108
|
-
export const readWalletLocks = (get: Get, wallet: string): Promise<B.WalletLocks> => readRoute(get, indexerPath.walletLocks(wallet), B.WALLET_LOCKS);
|
|
109
|
-
export const readClaimHistory = (get: Get, wallet: string): Promise<B.ClaimHistory> => readRoute(get, indexerPath.claimHistory(wallet), B.CLAIM_HISTORY);
|
|
114
|
+
export const readInbox = (get: Get, wallet: string, q: { limit?: number; before?: string } = {}): Promise<B.Inbox> => readRoute(get, indexerPath.inbox(wallet, q), B.INBOX);
|
|
115
|
+
export const readWalletLocks = (get: Get, wallet: string, q: WalletPage = {}): Promise<B.WalletLocks> => readRoute(get, indexerPath.walletLocks(wallet, q), B.WALLET_LOCKS);
|
|
116
|
+
export const readClaimHistory = (get: Get, wallet: string, q: WalletPage = {}): Promise<B.ClaimHistory> => readRoute(get, indexerPath.claimHistory(wallet, q), B.CLAIM_HISTORY);
|
|
110
117
|
|
|
111
|
-
export const readClaimView = (get: Get, wallet: string): Promise<B.ClaimView> => readRoute(get, indexerPath.claimView(wallet), B.CLAIM_VIEW);
|
|
118
|
+
export const readClaimView = (get: Get, wallet: string, q: WalletPage = {}): Promise<B.ClaimView> => readRoute(get, indexerPath.claimView(wallet, q), B.CLAIM_VIEW);
|
|
112
119
|
export const readFirsts = (get: Get, wallet: string): Promise<At & { wallet: string } & B.Firsts> => readRoute(get, indexerPath.firsts(wallet), B.FIRSTS);
|
|
113
120
|
|
|
114
121
|
export const readFirstsMany = (get: Get, wallets: readonly string[]): Promise<At & { wallets: Record<string, B.Firsts> }> => readRoute(get, indexerPath.firstsMany(wallets), B.FIRSTS_MANY);
|
|
115
|
-
export const readPeople = (get: Get, wallet: string): Promise<B.People> => readRoute(get, indexerPath.people(wallet), B.PEOPLE);
|
|
116
|
-
export const readRoles = (get: Get, wallet: string): Promise<B.Roles> => readRoute(get, indexerPath.roles(wallet), B.ROLES);
|
|
122
|
+
export const readPeople = (get: Get, wallet: string, q: WalletPage = {}): Promise<B.People> => readRoute(get, indexerPath.people(wallet, q), B.PEOPLE);
|
|
123
|
+
export const readRoles = (get: Get, wallet: string, q: WalletPage = {}): Promise<B.Roles> => readRoute(get, indexerPath.roles(wallet, q), B.ROLES);
|
|
117
124
|
|
|
118
|
-
export const readHandlePlaces = (get: Get, handle: string): Promise<B.HandlePlaces> => readRoute(get, indexerPath.handlePlaces(handle), B.HANDLE_PLACES);
|
|
125
|
+
export const readHandlePlaces = (get: Get, handle: string, q: WalletPage = {}): Promise<B.HandlePlaces> => readRoute(get, indexerPath.handlePlaces(handle, q), B.HANDLE_PLACES);
|
|
119
126
|
|
|
120
127
|
export const readTraderBoard = (get: Get, q: { window?: B.TraderWindow; limit?: number } = {}): Promise<B.TraderBoard> => readRoute(get, indexerPath.traderBoard(q), B.TRADER_BOARD);
|
|
121
128
|
export const readLauncherBoard = (get: Get, q: { limit?: number } = {}): Promise<B.LauncherBoard> => readRoute(get, indexerPath.launcherBoard(q), B.LAUNCHER_BOARD);
|
|
@@ -130,3 +137,12 @@ export function offPriceBps(price: Pick<B.Price, "livePriceX64">, quotedX64: big
|
|
|
130
137
|
if (p === 0n) return null;
|
|
131
138
|
return Number(((quotedX64 - p) * 10_000n) / p);
|
|
132
139
|
}
|
|
140
|
+
|
|
141
|
+
export interface CursorPage<T> {
|
|
142
|
+
rows: readonly T[];
|
|
143
|
+
next: string | null;
|
|
144
|
+
}
|
|
145
|
+
export function cursorPage<K extends string, T>(body: { readonly [k in K]: readonly T[] } & { next?: string | null }, rows: K): CursorPage<T> {
|
|
146
|
+
if (body.next === undefined) throw new Error(`not a page: the body has no next (rows ${rows})`);
|
|
147
|
+
return { rows: body[rows], next: body.next };
|
|
148
|
+
}
|
|
@@ -0,0 +1,138 @@
|
|
|
1
|
+
|
|
2
|
+
|
|
3
|
+
export const SEARCH_Q_MAX = 64;
|
|
4
|
+
|
|
5
|
+
export const SEARCH_PAGE_DEFAULT = 12;
|
|
6
|
+
|
|
7
|
+
export const SEARCH_PAGE_MAX = 100;
|
|
8
|
+
|
|
9
|
+
export const ADDRESS_PREFIX_MIN = 4;
|
|
10
|
+
|
|
11
|
+
export const SEARCH_SUBSTRING_MIN = 3;
|
|
12
|
+
|
|
13
|
+
export type SearchTier = 0 | 1 | 2 | 3 | 4 | 5;
|
|
14
|
+
|
|
15
|
+
export interface SearchSubject {
|
|
16
|
+
name: string | null;
|
|
17
|
+
symbol: string | null;
|
|
18
|
+
token: string;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export function searchFold(s: string): string {
|
|
22
|
+
return s.normalize("NFKC").toLowerCase().replace(/\s+/g, " ").trim();
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
export function searchNeedles(q: string): string[] {
|
|
26
|
+
const f = searchFold(q);
|
|
27
|
+
if (!f.startsWith("$")) return f === "" ? [] : [f];
|
|
28
|
+
const bare = f.slice(1).trim();
|
|
29
|
+
return bare === "" ? [f] : [bare, f];
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
export function searchNeedle(q: string): string {
|
|
33
|
+
return searchNeedles(q)[0] ?? "";
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
export function searchTierFolded(name: string, symbol: string, token: string, n: string): SearchTier | null {
|
|
37
|
+
if (n === "") return null;
|
|
38
|
+
if (symbol === n || name === n || token === n) return 0;
|
|
39
|
+
if (symbol.startsWith(n)) return 1;
|
|
40
|
+
if (name.startsWith(n) || name.includes(` ${n}`)) return 2;
|
|
41
|
+
if (symbol.includes(n) || name.includes(n)) return 3;
|
|
42
|
+
if (token.startsWith(n)) return 4;
|
|
43
|
+
if ((name + symbol + token).includes(n)) return 5;
|
|
44
|
+
return null;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
export function searchServed(tier: SearchTier, needle: string): boolean {
|
|
48
|
+
const n = [...needle].length;
|
|
49
|
+
if (tier <= 2) return true;
|
|
50
|
+
if (tier === 3) return n >= SEARCH_SUBSTRING_MIN;
|
|
51
|
+
if (tier === 4) return n >= ADDRESS_PREFIX_MIN;
|
|
52
|
+
return false;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
export function searchTier(l: SearchSubject, q: string): SearchTier | null {
|
|
56
|
+
const name = searchFold(l.name ?? ""), symbol = searchFold(l.symbol ?? ""), token = searchFold(l.token);
|
|
57
|
+
let best: SearchTier | null = null;
|
|
58
|
+
for (const n of searchNeedles(q)) {
|
|
59
|
+
const t = searchTierFolded(name, symbol, token, n);
|
|
60
|
+
if (t !== null && (best === null || t < best)) best = t;
|
|
61
|
+
}
|
|
62
|
+
return best;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
export function searchServedTier(l: SearchSubject, q: string): SearchTier | null {
|
|
66
|
+
const name = searchFold(l.name ?? ""), symbol = searchFold(l.symbol ?? ""), token = searchFold(l.token);
|
|
67
|
+
let best: SearchTier | null = null;
|
|
68
|
+
for (const n of searchNeedles(q)) {
|
|
69
|
+
const t = searchTierFolded(name, symbol, token, n);
|
|
70
|
+
if (t !== null && searchServed(t, n) && (best === null || t < best)) best = t;
|
|
71
|
+
}
|
|
72
|
+
return best;
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
const SOL = "So11111111111111111111111111111111111111112";
|
|
76
|
+
const EVM = "0xabCDeF0123456789AbcdEf0123456789aBCDEF01";
|
|
77
|
+
|
|
78
|
+
export const SEARCH_PARITY_CORPUS: readonly (readonly [string | null, string | null, string, string, SearchTier | null])[] = [
|
|
79
|
+
|
|
80
|
+
["Doge Wif Hat", "WIF", SOL, "wif", 0],
|
|
81
|
+
["Doge Wif Hat", "WIF", SOL, "WIF", 0],
|
|
82
|
+
["Doge Wif Hat", "WIF", SOL, "$wif", 0],
|
|
83
|
+
["Doge Wif Hat", "WIF", SOL, " doge wif hat ", 0],
|
|
84
|
+
["Doge Wif Hat", "WIF", SOL, SOL, 0],
|
|
85
|
+
["Doge Wif Hat", "WIF", EVM, EVM.toLowerCase(), 0],
|
|
86
|
+
["Doge Wif Hat", "WIF", EVM, EVM.toUpperCase().replace("0X", "0x"), 0],
|
|
87
|
+
["FLOOR", "FLR", SOL, "flr", 0],
|
|
88
|
+
["Café", "CAFE", SOL, "café", 0],
|
|
89
|
+
["Café", "CF", SOL, "café", 0],
|
|
90
|
+
["Ⅻ Club", "XII", SOL, "xii", 0],
|
|
91
|
+
["Dog", "DOG", SOL, "$dog", 0],
|
|
92
|
+
|
|
93
|
+
["Moon Rocket", "MOONR", SOL, "moo", 1],
|
|
94
|
+
["Moon Rocket", "MOONR", SOL, "$MOO", 1],
|
|
95
|
+
["Moon Rocket", "MOONR", SOL, "moo", 1],
|
|
96
|
+
|
|
97
|
+
["Moon Rocket", "MR", SOL, "moon", 2],
|
|
98
|
+
["Moon Rocket", "MR", SOL, "rock", 2],
|
|
99
|
+
["Moon Rocket", "MR", SOL, "moon rock", 2],
|
|
100
|
+
["Moon\tRocket", "MR", SOL, "moon r", 2],
|
|
101
|
+
["The Big Dog", "TBD", SOL, "big d", 2],
|
|
102
|
+
|
|
103
|
+
["Moon Rocket", "MR", SOL, "ocke", 3],
|
|
104
|
+
["Moon Rocket", "XMOONX", SOL, "oon", 3],
|
|
105
|
+
["Pepe", "PEPE", SOL, "ep", 3],
|
|
106
|
+
["Pepe Coin", "PC", SOL, "pe c", 3],
|
|
107
|
+
|
|
108
|
+
["Moon Rocket", "MR", SOL, "so1", 4],
|
|
109
|
+
["Moon Rocket", "MR", SOL, "so11", 4],
|
|
110
|
+
["Moon Rocket", "MR", EVM, "0xab", 4],
|
|
111
|
+
["Moon Rocket", "MR", EVM, "0xA", 4],
|
|
112
|
+
|
|
113
|
+
["Moon Rocket", "MR", SOL, "1111", 5],
|
|
114
|
+
["Moon Rocket", "MR", EVM, "cdef01", 5],
|
|
115
|
+
["Moon Rocket", "MR", SOL, "rocketmr", 5],
|
|
116
|
+
["Moon Rocket", "MR", SOL, "mrso", 5],
|
|
117
|
+
|
|
118
|
+
[null, "ZED", SOL, "zed", 0],
|
|
119
|
+
[null, null, SOL, "zed", null],
|
|
120
|
+
["Zed", null, SOL, "ze", 2],
|
|
121
|
+
[null, null, SOL, "so11", 4],
|
|
122
|
+
|
|
123
|
+
["Moon Rocket", "MR", SOL, "venus", null],
|
|
124
|
+
["Moon Rocket", "MR", SOL, "", null],
|
|
125
|
+
["Moon Rocket", "MR", SOL, " ", null],
|
|
126
|
+
["Moon Rocket", "MR", SOL, "$", null],
|
|
127
|
+
|
|
128
|
+
["$$ Bills", "BILL", SOL, "$$", 2],
|
|
129
|
+
["Bills", "$BILL", SOL, "$$bill", 0],
|
|
130
|
+
|
|
131
|
+
["Big Money", "BM", SOL, "$ money", 2],
|
|
132
|
+
|
|
133
|
+
["$WIF Coin", "$WIF", SOL, "$wif", 0],
|
|
134
|
+
["Doge Wif Hat", "WIF", SOL, "$wif", 0],
|
|
135
|
+
["$1 Coin", "ONE", SOL, "$1", 2],
|
|
136
|
+
["Cash $ Money", "CASH", SOL, "$", 2],
|
|
137
|
+
["Cash $ Money", "CASH", SOL, " $ ", 2],
|
|
138
|
+
];
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
|
|
2
|
+
|
|
3
|
+
export interface StackEdgeBar {
|
|
4
|
+
time: number;
|
|
5
|
+
high: number;
|
|
6
|
+
close: number;
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
export interface StackEdgePoint {
|
|
10
|
+
i: number;
|
|
11
|
+
edge: number;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
function startBar(bars: readonly StackEdgeBar[], graduatedAt: number): number {
|
|
15
|
+
let start = 0;
|
|
16
|
+
for (let j = 0; j < bars.length; j++) {
|
|
17
|
+
if (bars[j]!.time <= graduatedAt) start = j;
|
|
18
|
+
else break;
|
|
19
|
+
}
|
|
20
|
+
return start;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export function stackEdgeWalk(bars: readonly StackEdgeBar[], graduatedAt: number, endPrice: number | null): StackEdgePoint[] {
|
|
24
|
+
const out: StackEdgePoint[] = [];
|
|
25
|
+
let m = 0;
|
|
26
|
+
for (let j = startBar(bars, graduatedAt); j < bars.length; j++) {
|
|
27
|
+
const b = bars[j]!;
|
|
28
|
+
if (!(b.close > 0) || !(b.high > 0)) continue;
|
|
29
|
+
m = Math.max(m, b.high);
|
|
30
|
+
if (endPrice !== null && endPrice > 0 && m >= endPrice) break;
|
|
31
|
+
out.push({ i: j, edge: m });
|
|
32
|
+
}
|
|
33
|
+
return out;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
export function stackEdgeEnd(bars: readonly StackEdgeBar[], graduatedAt: number, endPrice: number | null): number | null {
|
|
37
|
+
if (endPrice === null || !(endPrice > 0)) return null;
|
|
38
|
+
let m = 0;
|
|
39
|
+
for (let j = startBar(bars, graduatedAt); j < bars.length; j++) {
|
|
40
|
+
const b = bars[j]!;
|
|
41
|
+
if (!(b.close > 0) || !(b.high > 0)) continue;
|
|
42
|
+
m = Math.max(m, b.high);
|
|
43
|
+
if (m >= endPrice) return j;
|
|
44
|
+
}
|
|
45
|
+
return null;
|
|
46
|
+
}
|
package/src/indexer/stream.ts
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
|
|
2
2
|
|
|
3
|
-
import { decode, int, nullable, object, str, unknown } from "./decode.ts";
|
|
3
|
+
import { decode, int, nullable, object, optional, str, unknown } from "./decode.ts";
|
|
4
4
|
import { HEAD, LIVE_LAUNCH, TRADE } from "./bodies.ts";
|
|
5
5
|
import type { Head, Launch, Trade } from "./bodies.ts";
|
|
6
6
|
import { indexerPath } from "./paths.ts";
|
|
7
7
|
import type { StreamQuery } from "./paths.ts";
|
|
8
8
|
|
|
9
|
-
const HELLO = object({ head: HEAD, window: int, oldest: nullable(str) });
|
|
9
|
+
const HELLO = object({ head: HEAD, window: int, oldest: nullable(str), epoch: optional(str) });
|
|
10
10
|
const HEAD_SEEN = object({ block: int, age: int });
|
|
11
11
|
const LAUNCH_FRAME = object({ launch: LIVE_LAUNCH });
|
|
12
12
|
const STATE = object({ launch: str, mint: str, block: int, ts: nullable(int), seq: int, prev: unknown, state: LIVE_LAUNCH });
|
|
@@ -14,7 +14,7 @@ const REORG = object({ block: int, rollbacks: int });
|
|
|
14
14
|
const RESET = object({ reason: str, head: HEAD });
|
|
15
15
|
|
|
16
16
|
export type StreamFrame =
|
|
17
|
-
| { event: "hello"; data: { head: Head; window: number; oldest: string | null } }
|
|
17
|
+
| { event: "hello"; data: { head: Head; window: number; oldest: string | null; epoch?: string } }
|
|
18
18
|
| { event: "head"; data: { block: number; age: number } }
|
|
19
19
|
| { event: "trade"; id: string; data: Trade }
|
|
20
20
|
| { event: "launch"; data: { launch: Launch } }
|
|
@@ -57,27 +57,81 @@ export function decodeStreamFrame(event: string, data: unknown, id?: string): St
|
|
|
57
57
|
|
|
58
58
|
export function parseStreamFrames(text: string): { frames: StreamFrame[]; rest: string } {
|
|
59
59
|
const frames: StreamFrame[] = [];
|
|
60
|
-
|
|
60
|
+
|
|
61
|
+
const t = text.indexOf("\r") < 0 ? text : text.replace(/\r\n/g, "\n");
|
|
62
|
+
let at = 0;
|
|
61
63
|
let cut: number;
|
|
62
|
-
while ((cut =
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
64
|
+
while ((cut = t.indexOf("\n\n", at)) >= 0) {
|
|
65
|
+
frameOf(t.slice(at, cut), frames);
|
|
66
|
+
at = cut + 2;
|
|
67
|
+
}
|
|
68
|
+
return { frames, rest: at === 0 ? t : t.slice(at) };
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
export interface StreamParser {
|
|
72
|
+
|
|
73
|
+
push(chunk: string): StreamFrame[];
|
|
74
|
+
|
|
75
|
+
rest(): string;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
export function createStreamParser(): StreamParser {
|
|
79
|
+
let pieces: string[] = [];
|
|
80
|
+
let cr = false;
|
|
81
|
+
let endsNl = false;
|
|
82
|
+
const parser: StreamParser = {
|
|
83
|
+
push(chunk: string): StreamFrame[] {
|
|
84
|
+
const frames: StreamFrame[] = [];
|
|
85
|
+
let c = cr ? `\r${chunk}` : chunk;
|
|
86
|
+
cr = c.endsWith("\r");
|
|
87
|
+
if (cr) c = c.slice(0, -1);
|
|
88
|
+
if (c.indexOf("\r") >= 0) c = c.replace(/\r\n/g, "\n");
|
|
89
|
+
if (c.length === 0) return frames;
|
|
90
|
+
let at = 0;
|
|
91
|
+
|
|
92
|
+
if (endsNl && pieces.length > 0 && c.charCodeAt(0) === 10) {
|
|
93
|
+
const block = pieces.join("");
|
|
94
|
+
pieces = [];
|
|
95
|
+
frameOf(block.slice(0, -1), frames);
|
|
96
|
+
at = 1;
|
|
97
|
+
}
|
|
98
|
+
let cut: number;
|
|
99
|
+
while ((cut = c.indexOf("\n\n", at)) >= 0) {
|
|
100
|
+
const head = c.slice(at, cut);
|
|
101
|
+
frameOf(pieces.length > 0 ? pieces.join("") + head : head, frames);
|
|
102
|
+
pieces = [];
|
|
103
|
+
at = cut + 2;
|
|
104
|
+
}
|
|
105
|
+
if (at < c.length) {
|
|
106
|
+
pieces.push(at === 0 ? c : c.slice(at));
|
|
107
|
+
endsNl = c.charCodeAt(c.length - 1) === 10;
|
|
108
|
+
} else endsNl = false;
|
|
109
|
+
return frames;
|
|
110
|
+
},
|
|
111
|
+
rest(): string {
|
|
112
|
+
const r = pieces.join("");
|
|
113
|
+
pieces = r.length > 0 ? [r] : [];
|
|
114
|
+
return cr ? `${r}\r` : r;
|
|
115
|
+
},
|
|
116
|
+
};
|
|
117
|
+
return parser;
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
function frameOf(block: string, frames: StreamFrame[]): void {
|
|
121
|
+
let event = "message";
|
|
122
|
+
let id: string | undefined;
|
|
123
|
+
const data: string[] = [];
|
|
124
|
+
let comment: string | null = null;
|
|
125
|
+
for (const line of block.split("\n")) {
|
|
126
|
+
if (line.startsWith(":")) comment = line.slice(1).trim();
|
|
127
|
+
else if (line.startsWith("event:")) event = line.slice(6).trim();
|
|
128
|
+
else if (line.startsWith("id:")) id = line.slice(3).trim();
|
|
129
|
+
else if (line.startsWith("data:")) data.push(line.slice(5).replace(/^ /, ""));
|
|
130
|
+
}
|
|
131
|
+
if (data.length === 0) {
|
|
132
|
+
if (comment !== null) frames.push({ event: "comment", text: comment });
|
|
133
|
+
return;
|
|
81
134
|
}
|
|
82
|
-
|
|
135
|
+
const f = decodeStreamFrame(event, JSON.parse(data.join("\n")), id);
|
|
136
|
+
if (f !== null) frames.push(f);
|
|
83
137
|
}
|
package/src/math/v2/split.ts
CHANGED
|
@@ -34,7 +34,7 @@ export interface SplitRow {
|
|
|
34
34
|
floorMsBps: number;
|
|
35
35
|
}
|
|
36
36
|
|
|
37
|
-
export function splitRowOfRowV2(r: { phiBps: number; ckTargetBps?: number; ckBps?: number; msClass: number; flags: number; platformMsBps: number; floorMsBps: number }): SplitRow {
|
|
37
|
+
export function splitRowOfRowV2(r: { phiBps: number; ckTargetBps?: number; ckBps?: number; wcBps?: number; msClass: number; flags: number; platformMsBps: number; floorMsBps: number }): SplitRow {
|
|
38
38
|
const ck = r.ckTargetBps ?? r.ckBps;
|
|
39
39
|
if (!Number.isInteger(ck)) throw new RangeError("splitRowOfRowV2: the row has no C + K share (`ckTargetBps`)");
|
|
40
40
|
if (r.ckTargetBps !== undefined && r.ckBps !== undefined && r.ckTargetBps !== r.ckBps) {
|
|
@@ -43,7 +43,8 @@ export function splitRowOfRowV2(r: { phiBps: number; ckTargetBps?: number; ckBps
|
|
|
43
43
|
return {
|
|
44
44
|
phiBps: r.phiBps,
|
|
45
45
|
ckBps: ck as number,
|
|
46
|
-
|
|
46
|
+
|
|
47
|
+
wcBps: r.wcBps ?? 300,
|
|
47
48
|
cShareBps: 5_000,
|
|
48
49
|
msClass: r.msClass,
|
|
49
50
|
platformMsBps: (r.flags & 1) !== 0 ? r.platformMsBps : 0,
|
|
@@ -89,12 +90,19 @@ export interface Split {
|
|
|
89
90
|
sqrtFNew: Sqrt;
|
|
90
91
|
}
|
|
91
92
|
|
|
93
|
+
export function surplus(sqrtF: Sqrt, back: bigint, n: bigint): bigint {
|
|
94
|
+
const base = flatMoneyForTokens(sqrtF, n, UP);
|
|
95
|
+
return base === null || base === undefined ? 0n : sat(back, base);
|
|
96
|
+
}
|
|
97
|
+
|
|
92
98
|
export function split(row: SplitRow, ranges: readonly Range[], inp: SplitIn, pieces: readonly Piece[]): Split {
|
|
93
99
|
let tokensSum = 0n;
|
|
94
100
|
for (const p of pieces) tokensSum += p.tokens;
|
|
95
101
|
let sr = inp.sNew - tokensSum;
|
|
96
102
|
if (sr < 0n) fail("Overflow");
|
|
97
103
|
let fr = inp.fTotal;
|
|
104
|
+
|
|
105
|
+
const s0 = surplus(inp.sqrtF, fr + inp.fClaims, sr + inp.held);
|
|
98
106
|
const phi = BigInt(row.phiBps);
|
|
99
107
|
let ckAdd = 0n;
|
|
100
108
|
let ms = 0n;
|
|
@@ -110,7 +118,7 @@ export function split(row: SplitRow, ranges: readonly Range[], inp: SplitIn, pie
|
|
|
110
118
|
const capB = cdiv(cdiv(pc.money * inp.sqrtF, lo) * inp.sqrtF, lo);
|
|
111
119
|
const cap = min(max(capA, capB), pc.money);
|
|
112
120
|
const n = sr + inp.held;
|
|
113
|
-
const needAll = max(flatUp(inp.sqrtF, n), cdiv(flatUp(pc.sqrtHi, n) * phi, 10_000n));
|
|
121
|
+
const needAll = max(flatUp(inp.sqrtF, n) + s0, cdiv(flatUp(pc.sqrtHi, n) * phi, 10_000n));
|
|
114
122
|
if (r.kind !== KIND_TAIL) topNeed = needAll;
|
|
115
123
|
const need = sat(needAll, fr + inp.fClaims);
|
|
116
124
|
const dF = min(cap, need);
|
|
@@ -11,7 +11,7 @@ const S = (...f: [string, T][]): [string, T][] => f;
|
|
|
11
11
|
export const EVENTS: Record<string, [string, T][]> = {
|
|
12
12
|
LaunchCreated: S(["launch", "pubkey"], ["mint", "pubkey"], ["quoteMint", "pubkey"], ["creator", "pubkey"], ["id", "u64"], ["presetId", "u8"], ["presetVersion", "u32"], ["presetHash", "bytes:32"], ["p0X64", "u128"], ["raise", "u64"], ["windowTokens", "u64"], ["creatorBuyTokens", "u64"], ["createFee", "u64"], ["name", "bytes:32"], ["symbol", "bytes:10"], ["slot", "u64"], ["ts", "i64"], ["listed", "bool"], ["quoteUsdCentsX64", "u128"], ["nativeCreateFee", "u64"]),
|
|
13
13
|
|
|
14
|
-
Graduated: S(["launch", "pubkey"], ["
|
|
14
|
+
Graduated: S(["launch", "pubkey"], ["windowPriceX64", "u128"], ["windowRaised", "u64"], ["windowTokens", "u64"], ["slot", "u64"], ["ts", "i64"], ["priceX64", "u128"]),
|
|
15
15
|
PotsSwept: S(["launch", "pubkey"], ["amount", "u64"], ["reason", "u8"]),
|
|
16
16
|
Claimed: S(["wallet", "pubkey"], ["sender", "pubkey"], ["launch", "pubkey"], ["quoteMint", "pubkey"], ["types", "u8"], ["creator", "u64"], ["creatorRef", "u64"], ["teamSlot", "u64"], ["traderRef", "u64"], ["extra", "u64"], ["amount", "u64"], ["teamBuy", "u64?"], ["shareBought", "u64?"], ["typesHi", "u8?"]),
|
|
17
17
|
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
|
|
2
2
|
|
|
3
3
|
import { BPS, fail } from "../../math/index.ts";
|
|
4
|
+
import { WAGMI_GENESIS_KEEP_USD } from "../../math/v2/rows.ts";
|
|
4
5
|
import { fixedRaiseClaim, genesisClaim, genesisWeightListed } from "../../math/genesis.ts";
|
|
5
6
|
import { GENESIS_ALLOC_CLAIMED, GENESIS_ALLOC_MIGRATED, GENESIS_ALLOC_REFUNDED, GENESIS_ALLOC_WAGMI_CLAIMED } from "./accounts.ts";
|
|
6
7
|
|
|
@@ -63,13 +64,18 @@ export interface GenesisWaterfall {
|
|
|
63
64
|
solUnconverted: bigint;
|
|
64
65
|
}
|
|
65
66
|
|
|
66
|
-
export function genesisWaterfall(p: { usdcConverted: bigint; floorCapUsdc: bigint; wagmiPinned: boolean; raisedFinal: bigint; solConverted: bigint; floorUsed?: bigint; wagmiSpent?: bigint }): GenesisWaterfall {
|
|
67
|
+
export function genesisWaterfall(p: { usdcConverted: bigint; floorCapUsdc: bigint; wagmiPinned: boolean; raisedFinal: bigint; solConverted: bigint; floorUsed?: bigint; wagmiSpent?: bigint; usdcDecimals?: number; usdcPxX64?: bigint }): GenesisWaterfall {
|
|
67
68
|
if (p.solConverted > p.raisedFinal) fail("Overflow");
|
|
68
69
|
const floorUsdc = p.usdcConverted < p.floorCapUsdc ? p.usdcConverted : p.floorCapUsdc;
|
|
69
70
|
const used = p.floorUsed ?? floorUsdc;
|
|
70
71
|
if (used > floorUsdc) fail("Overflow");
|
|
71
72
|
const left = p.usdcConverted - used;
|
|
72
|
-
|
|
73
|
+
|
|
74
|
+
const px = p.usdcPxX64 ?? 100n << 64n;
|
|
75
|
+
if (px <= 0n) fail("Zero");
|
|
76
|
+
const keepAll = (WAGMI_GENESIS_KEEP_USD * 100n * 10n ** BigInt(p.usdcDecimals ?? 6) << 64n) / px;
|
|
77
|
+
const keep = keepAll > U64_MAX ? U64_MAX : keepAll;
|
|
78
|
+
const wagmiOffer = p.wagmiPinned ? (left < keep ? left : keep) : 0n;
|
|
73
79
|
const wagmiUsdc = p.wagmiSpent ?? wagmiOffer;
|
|
74
80
|
if (wagmiUsdc > wagmiOffer) fail("Overflow");
|
|
75
81
|
return { floorUsdc, wagmiOffer, wagmiUsdc, usdcRefund: left - wagmiUsdc, solUnconverted: p.raisedFinal - p.solConverted };
|
|
@@ -13,6 +13,7 @@ import { launchMintPda } from "./mint.ts";
|
|
|
13
13
|
|
|
14
14
|
export type { Ctx } from "../../v2/solana.ts";
|
|
15
15
|
import type { Ctx } from "../../v2/solana.ts";
|
|
16
|
+
import { FLOOR_HOOK_PROGRAM_ID, extraAccountMetasPda, holderBookPda, holderPositionPda, quoteHookBlock } from "../../v2/solana.ts";
|
|
16
17
|
|
|
17
18
|
const pid = (c?: Ctx): string => c?.programId ?? FLOOR_AMM_PROGRAM_ID;
|
|
18
19
|
const evPair = (c?: Ctx): AccountMeta[] => [R(floorEventAuthorityPda(pid(c))[0]), R(pid(c))];
|
|
@@ -77,8 +78,11 @@ export function clearTraderRefInstruction(p: { authority: string; config: string
|
|
|
77
78
|
return withRest(i, (p.traderRefs ?? []).map((r) => W(r)));
|
|
78
79
|
}
|
|
79
80
|
|
|
80
|
-
export function withdrawPlatformInstruction(p: { authority: string; config: string; launch: string; quoteMint: string; quoteVault: string; destination: string; quoteTokenProgram: string; amount: bigint } & Ctx): Instruction {
|
|
81
|
-
|
|
81
|
+
export function withdrawPlatformInstruction(p: { authority: string; config: string; launch: string; quoteMint: string; quoteVault: string; destination: string; quoteTokenProgram: string; amount: bigint; quoteIsLaunch?: boolean; treasury?: string } & Ctx): Instruction {
|
|
82
|
+
const i = ix("withdraw_platform", [RS(p.authority), R(p.config), W(p.launch), R(p.quoteMint), W(p.quoteVault), W(p.destination), R(p.quoteTokenProgram)], (w) => w.u64(p.amount), p);
|
|
83
|
+
if (!p.quoteIsLaunch) return i;
|
|
84
|
+
if (!p.treasury) throw new RangeError("withdraw_platform: a launch-token quote needs the treasury (its position receives)");
|
|
85
|
+
return withRest(i, quoteHookBlock(p.quoteMint, p.treasury, [p.launch], p));
|
|
82
86
|
}
|
|
83
87
|
|
|
84
88
|
export function checkPresetInstruction(p: { authority: string; config: string; preset: string; id: number } & Ctx): Instruction {
|
|
@@ -224,12 +228,16 @@ export function openRefOwedInstruction(p: { payer: string; quoteMint: string; re
|
|
|
224
228
|
return ix("open_ref_owed", [WS(p.payer), R(p.quoteMint), W(p.refOwed), W(p.vault), R(p.quoteTokenProgram), R(ASSOCIATED_TOKEN_PROGRAM_ID), R(SYSTEM_PROGRAM_ID)], (w) => w.pubkey(p.referrer), p);
|
|
225
229
|
}
|
|
226
230
|
|
|
227
|
-
export function rollUpRefsInstruction(p: { quoteMint: string; quoteTokenProgram: string; traderRefs: readonly { traderRef: string; escrow: string }[]; refOwed: readonly { refOwed: string; vault: string }[] } & Ctx): Instruction {
|
|
231
|
+
export function rollUpRefsInstruction(p: { quoteMint: string; quoteTokenProgram: string; traderRefs: readonly { traderRef: string; escrow: string }[]; refOwed: readonly { refOwed: string; vault: string }[]; quoteIsLaunch?: boolean } & Ctx): Instruction {
|
|
228
232
|
if (p.traderRefs.length > 255) throw new RangeError("at most 255 links a roll-up");
|
|
229
233
|
const base = ix("roll_up_refs", [R(p.quoteMint), R(p.quoteTokenProgram)], (w) => w.u8(p.traderRefs.length), p);
|
|
230
234
|
const rest: AccountMeta[] = [];
|
|
231
|
-
|
|
232
|
-
|
|
235
|
+
const hook = p.hookProgramId;
|
|
236
|
+
const ql = p.quoteIsLaunch ? launchPda(p.quoteMint, pid(p))[0] : "";
|
|
237
|
+
const pos = (owner: string): AccountMeta[] => (p.quoteIsLaunch ? [W(holderPositionPda(ql, owner, hook)[0])] : []);
|
|
238
|
+
for (const t of p.traderRefs) rest.push(W(t.traderRef), W(t.escrow), ...pos(t.traderRef));
|
|
239
|
+
for (const r of p.refOwed) rest.push(W(r.refOwed), W(r.vault), ...pos(r.refOwed));
|
|
240
|
+
if (p.quoteIsLaunch) rest.push(R(extraAccountMetasPda(p.quoteMint, hook)[0]), R(ql), W(holderBookPda(ql, hook)[0]), R(hook ?? FLOOR_HOOK_PROGRAM_ID));
|
|
233
241
|
return { ...base, accounts: [...base.accounts, ...rest] };
|
|
234
242
|
}
|
|
235
243
|
|
|
@@ -73,6 +73,10 @@ export function nextClaimsPage(pages: readonly ClaimsPage[]): number {
|
|
|
73
73
|
return last.count < CLAIMS_PAGE_ENTRIES ? last.page : last.page + 1;
|
|
74
74
|
}
|
|
75
75
|
|
|
76
|
+
export function hookClaimsPage(pages: readonly ClaimsPage[]): number {
|
|
77
|
+
return pages.length === 0 ? 0 : pages[pages.length - 1].page;
|
|
78
|
+
}
|
|
79
|
+
|
|
76
80
|
function ix(name: string, accounts: AccountMeta[], args: (w: Writer) => Writer, programId = FLOOR_AMM_PROGRAM_ID): Instruction {
|
|
77
81
|
const ev = floorEventAuthorityPda(programId)[0];
|
|
78
82
|
return { programAddress: programId, accounts: [...accounts, R(ev), R(programId)], data: args(new Writer().bytes(instructionDiscriminator(name))).done() };
|
package/src/v2/solana.ts
CHANGED
|
@@ -177,15 +177,32 @@ export function presetV2Instructions(p: { name: "add_preset" | "update_preset" |
|
|
|
177
177
|
return out;
|
|
178
178
|
}
|
|
179
179
|
|
|
180
|
-
export type TeamShareBuyBaseV2 = {
|
|
180
|
+
export type TeamShareBuyBaseV2 = {
|
|
181
|
+
member: string; launch: string; baseMint: string; quoteMint: string; tokenVault: string; quoteVault: string; teamSlot?: string; memberBase: string;
|
|
182
|
+
|
|
183
|
+
traderRef?: string; escrow?: string; quoteTokenProgram?: string;
|
|
184
|
+
|
|
185
|
+
quoteIsLaunch?: boolean;
|
|
186
|
+
} & Ctx;
|
|
181
187
|
export function teamShareBuyInstructionV2(p: TeamShareBuyBaseV2 & { amountIn: bigint; minOut: bigint }): Instruction {
|
|
188
|
+
if (!p.traderRef !== !p.escrow) throw new RangeError("team_share_buy: traderRef and escrow go together");
|
|
189
|
+
const referred = Boolean(p.traderRef);
|
|
190
|
+
if (referred && !p.quoteTokenProgram) throw new RangeError("team_share_buy: a referred buyback needs quoteTokenProgram");
|
|
182
191
|
const base = ix(
|
|
183
192
|
"team_share_buy",
|
|
184
|
-
|
|
193
|
+
|
|
194
|
+
[WS(p.member), W(p.launch), R(p.baseMint), R(p.quoteMint), W(p.tokenVault), referred ? W(p.quoteVault) : R(p.quoteVault), R(p.teamSlot ?? teamSlotPda(p.launch, pid(p))[0]), W(p.memberBase), R(TOKEN_2022_PROGRAM_ID)],
|
|
185
195
|
(w) => w.u64(p.amountIn).u64(minOut(p.minOut, "minOut")),
|
|
186
196
|
p,
|
|
187
197
|
);
|
|
188
|
-
|
|
198
|
+
const accounts = [...base.accounts, ...hookAccountsFor({ baseMint: p.baseMint, srcOwner: p.launch, dstOwner: p.member, programId: p.programId, hookProgramId: p.hookProgramId })];
|
|
199
|
+
if (!referred) return { ...base, accounts };
|
|
200
|
+
accounts.push(W(p.traderRef!), W(p.escrow!), R(p.quoteTokenProgram!));
|
|
201
|
+
if (p.quoteIsLaunch) {
|
|
202
|
+
accounts.push(...hookAccountsFor({ baseMint: p.quoteMint, srcOwner: p.launch, dstOwner: p.traderRef!, programId: p.programId, hookProgramId: p.hookProgramId }));
|
|
203
|
+
accounts.push(W(holderPositionPda(launchPda(p.quoteMint, pid(p))[0], p.traderRef!, hid(p))[0]));
|
|
204
|
+
}
|
|
205
|
+
return { ...base, accounts };
|
|
189
206
|
}
|
|
190
207
|
|
|
191
208
|
const REM_HOOK_AT = 5;
|
package/src/v2/tx/solana.ts
CHANGED
|
@@ -134,7 +134,7 @@ export function teamShareBuyAndClaimInstructionsV2(
|
|
|
134
134
|
});
|
|
135
135
|
return [
|
|
136
136
|
...(open ? [createAssociatedTokenAccountIdempotentInstruction({ payer: p.member, owner: p.member, mint: p.baseMint, tokenProgram: TOKEN_2022_PROGRAM_ID })] : []),
|
|
137
|
-
teamShareBuyInstructionV2({ ...buy, teamSlot, memberBase }),
|
|
137
|
+
teamShareBuyInstructionV2({ ...buy, teamSlot, memberBase, quoteTokenProgram, quoteIsLaunch }),
|
|
138
138
|
claim,
|
|
139
139
|
];
|
|
140
140
|
}
|