@floorlaunchpad/sdk 0.3.0 → 0.3.2

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 (41) hide show
  1. package/CHANGELOG.md +61 -0
  2. package/README.md +10 -0
  3. package/dist/abi/solana.gen.js +2 -0
  4. package/dist/config/generated.js +121 -64
  5. package/dist/evm/chains.js +5 -1
  6. package/dist/evm/squid.js +107 -0
  7. package/dist/index.js +2 -0
  8. package/dist/indexer/bodies.js +16 -0
  9. package/dist/indexer/client.js +4 -0
  10. package/dist/indexer/contract.js +17 -2
  11. package/dist/indexer/partners.js +5 -0
  12. package/dist/indexer/paths.js +6 -0
  13. package/dist/indexer/read.js +13 -0
  14. package/dist/math/v2/trade.js +8 -8
  15. package/dist/solana/floor/accounts.js +3 -1
  16. package/dist/solana/floor/events.js +4 -0
  17. package/dist/solana/floor/instructions.js +13 -0
  18. package/dist/v2/devbuy.js +15 -0
  19. package/dist/v2/router.js +22 -0
  20. package/docs/floor-line.md +235 -0
  21. package/examples/floor-line.html +401 -0
  22. package/package.json +2 -1
  23. package/src/abi/solana.gen.ts +2 -0
  24. package/src/config/generated.ts +121 -64
  25. package/src/config/index.ts +2 -0
  26. package/src/events/types.gen.ts +11 -0
  27. package/src/evm/chains.ts +5 -1
  28. package/src/evm/squid.ts +138 -0
  29. package/src/index.ts +2 -0
  30. package/src/indexer/bodies.ts +19 -0
  31. package/src/indexer/client.ts +8 -0
  32. package/src/indexer/contract.ts +18 -3
  33. package/src/indexer/partners.ts +6 -0
  34. package/src/indexer/paths.ts +6 -0
  35. package/src/indexer/read.ts +13 -0
  36. package/src/math/v2/trade.ts +8 -8
  37. package/src/solana/floor/accounts.ts +3 -1
  38. package/src/solana/floor/events.ts +4 -0
  39. package/src/solana/floor/instructions.ts +13 -0
  40. package/src/v2/devbuy.ts +33 -0
  41. package/src/v2/router.ts +22 -0
@@ -83,7 +83,7 @@ export type Pagination =
83
83
 
84
84
  | { readonly kind: "range"; readonly from: string; readonly to: string; readonly span?: { readonly interval: string; readonly max: number } };
85
85
 
86
- export type PathParam = "launch" | "wallet";
86
+ export type PathParam = "launch" | "wallet" | "token" | "handle";
87
87
 
88
88
  export interface RouteContract<T = unknown> {
89
89
  readonly pattern: string;
@@ -116,7 +116,7 @@ const WALLET_ERR = [...GATED, "bad_query"] as const;
116
116
  type Spec<T> = Omit<RouteContract<T>, "aliases" | "mount" | "params" | "query" | "page" | "errors" | "gated" | "units" | "audience"> & Partial<RouteContract<T>>;
117
117
 
118
118
  function site<T>(s: Spec<T> & { v2?: boolean }): RouteContract<T> {
119
- const params = [...s.pattern.matchAll(/<(launch|wallet)>/g)].map((m) => m[1] as PathParam);
119
+ const params = [...s.pattern.matchAll(/<(launch|wallet|token|handle)>/g)].map((m) => m[1] as PathParam);
120
120
  const { v2, ...rest } = s;
121
121
  const aliases = s.aliases ?? (v2 ? [s.pattern.replace(/^\/floor-amm\//, "/floor-amm/v2/")] : []);
122
122
  return { mount: "chain", query: {}, page: NONE, errors: GATED, gated: true, units: "site", audience: "site", ...rest, params, aliases };
@@ -185,6 +185,10 @@ export const INDEXER_CONTRACT = {
185
185
  }),
186
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
187
  devBuys: site({ pattern: "/floor-amm/launches/<launch>/dev-buys", v2: true, errors: LAUNCH_ERR, body: B.DEV_BUYS }),
188
+
189
+ memberSold: site({ pattern: "/floor-amm/launches/<launch>/member-sold", v2: true, errors: LAUNCH_ERR, body: B.MEMBER_SOLD }),
190
+
191
+ launchAccount: site({ pattern: "/floor-amm/launches/<launch>/account", v2: true, errors: LAUNCH_ERR, body: B.LAUNCH_ACCOUNT }),
188
192
  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 }),
189
193
  quoteChain: site({ pattern: "/floor-amm/launches/<launch>/chain", v2: true, errors: LAUNCH_ERR, body: B.QUOTE_CHAIN }),
190
194
  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 }),
@@ -252,9 +256,20 @@ export const INDEXER_CONTRACT = {
252
256
  people: site({ pattern: "/floor-amm/referrals/<wallet>/people", errors: WALLET_ERR, body: B.PEOPLE }),
253
257
  roles: site({ pattern: "/floor-amm/roles/<wallet>", errors: WALLET_ERR, body: B.ROLES }),
254
258
 
259
+ handlePlaces: site({ pattern: "/floor-amm/handles/<handle>/places", errors: WALLET_ERR, body: B.HANDLE_PLACES }),
260
+
255
261
  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 }),
256
262
  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 }),
257
263
 
264
+ tokenHolders: partner({
265
+ pattern: "/floor-amm/holders/<token>",
266
+ aliases: ["/holders/<token>"],
267
+ params: ["token"],
268
+ query: { limit: LIMIT(100, 500), offset: { kind: "int", doc: "rows skipped", min: 0, default: 0 } },
269
+ page: { kind: "offset", limit: { default: 100, max: 500 }, total: "total" },
270
+ errors: [...GATED, "bad_query", "not_found"],
271
+ body: P.TOKEN_HOLDERS,
272
+ }),
258
273
  dexAsset: partner({ pattern: "/v2/dex/asset", aliases: ["/asset"], query: { id: { kind: "string", doc: "a launch's token, or a quote", required: true } }, errors: [...GATED, "bad_query", "not_found", "not_indexed"], body: P.DEX_ASSET }),
259
274
  dexSummary: partner({ pattern: "/v2/dex/summary", aliases: ["/summary"], query: { id: { kind: "string", doc: "the pair id", required: true } }, errors: [...GATED, "bad_query", "not_found"], body: P.DEX_SUMMARY }),
260
275
  dexPair: partner({ pattern: "/v2/dex/pair", aliases: ["/pair"], query: { id: { kind: "string", doc: "the pair id", required: true } }, errors: [...GATED, "unknown_launch"], body: P.DEX_PAIR }),
@@ -297,7 +312,7 @@ export function matchRoute(path: string): { name: RouteName; params: Partial<Rec
297
312
  const c: RouteContract = INDEXER_CONTRACT[name];
298
313
  for (const pat of [c.pattern, ...c.aliases]) {
299
314
  const keys: PathParam[] = [];
300
- const re = new RegExp(`^${pat.replace(/[.*+?^${}()|[\]\\]/g, "\\$&").replace(/<(launch|wallet)>/g, (_, k: PathParam) => (keys.push(k), "([^/]+)"))}$`);
315
+ const re = new RegExp(`^${pat.replace(/[.*+?^${}()|[\]\\]/g, "\\$&").replace(/<(launch|wallet|token|handle)>/g, (_, k: PathParam) => (keys.push(k), "([^/]+)"))}$`);
301
316
  const m = re.exec(p);
302
317
  if (m === null) continue;
303
318
  const params: Partial<Record<PathParam, string>> = {};
@@ -21,6 +21,9 @@ export const DEX_ASSET = object({
21
21
  });
22
22
  export type DexAsset = Infer<typeof DEX_ASSET>;
23
23
 
24
+ export const TOKEN_HOLDERS = object({ total: int, holders: array(object({ address: str, balance: big })) });
25
+ export type TokenHolders = Infer<typeof TOKEN_HOLDERS>;
26
+
24
27
  export const DEX_SUMMARY = object({
25
28
  pair: str,
26
29
  base: str,
@@ -69,6 +72,9 @@ export const CG_TICKERS = array(object({
69
72
  low: nullable(decimal),
70
73
  liquidity_in_usd: nullable(decimal),
71
74
  liquidity_in_quote: big,
75
+
76
+ depthUp2: nullable(decimal),
77
+ depthDown2: nullable(decimal),
72
78
  }));
73
79
  export type CgTickers = Infer<typeof CG_TICKERS>;
74
80
 
@@ -21,6 +21,8 @@ export const INDEXER_ROUTES = {
21
21
  trades: { pattern: "/floor-amm/launches/<launch>/trades", keys: ["limit", "before", "traders"] },
22
22
  launchClaims: { pattern: "/floor-amm/launches/<launch>/claims", keys: ["claimer"] },
23
23
  devBuys: { pattern: "/floor-amm/launches/<launch>/dev-buys", keys: [] },
24
+ memberSold: { pattern: "/floor-amm/launches/<launch>/member-sold", keys: [] },
25
+ launchAccount: { pattern: "/floor-amm/launches/<launch>/account", keys: [] },
24
26
  traders: { pattern: "/floor-amm/launches/<launch>/traders", keys: ["window", "limit"] },
25
27
  quoteChain: { pattern: "/floor-amm/launches/<launch>/chain", keys: [] },
26
28
  devTrades: { pattern: "/floor-amm/launches/<launch>/dev", keys: ["limit"] },
@@ -41,6 +43,7 @@ export const INDEXER_ROUTES = {
41
43
  claimView: { pattern: "/floor-amm/claims/<wallet>", keys: [] },
42
44
  people: { pattern: "/floor-amm/referrals/<wallet>/people", keys: [] },
43
45
  roles: { pattern: "/floor-amm/roles/<wallet>", keys: [] },
46
+ handlePlaces: { pattern: "/floor-amm/handles/<handle>/places", keys: [] },
44
47
  traderBoard: { pattern: "/floor-amm/leaderboards/traders", keys: ["window", "limit"] },
45
48
  launcherBoard: { pattern: "/floor-amm/leaderboards/launchers", keys: ["limit"] },
46
49
  } as const satisfies Record<string, IndexerRoute>;
@@ -156,6 +159,8 @@ export const indexerPath = {
156
159
  trades: (id: string, q: TradesQuery = {}): string => launchPath(id, `/trades${query({ limit: q.limit, before: q.before, traders: q.traders?.length ? q.traders : undefined })}`),
157
160
  launchClaims: (id: string, q: { claimer?: string } = {}): string => launchPath(id, `/claims${query({ claimer: q.claimer })}`),
158
161
  devBuys: (id: string): string => launchPath(id, "/dev-buys"),
162
+ memberSold: (id: string): string => launchPath(id, "/member-sold"),
163
+ launchAccount: (id: string): string => launchPath(id, "/account"),
159
164
  traders: (id: string, q: { window?: "1h" | "24h" | "7d" | "all"; limit?: number } = {}): string => launchPath(id, `/traders${query({ window: q.window, limit: q.limit })}`),
160
165
  quoteChain: (id: string): string => launchPath(id, "/chain"),
161
166
  devTrades: (id: string, q: { limit?: number } = {}): string => launchPath(id, `/dev${query({ limit: q.limit })}`),
@@ -185,6 +190,7 @@ export const indexerPath = {
185
190
  claimView: (w: string): string => `/floor-amm/claims/${seg(w)}`,
186
191
  people: (w: string): string => `/floor-amm/referrals/${seg(w)}/people`,
187
192
  roles: (w: string): string => `/floor-amm/roles/${seg(w)}`,
193
+ handlePlaces: (handle: string): string => `/floor-amm/handles/${seg(handle)}/places`,
188
194
  traderBoard: (q: { window?: "1h" | "24h" | "7d" | "all"; limit?: number } = {}): string => `/floor-amm/leaderboards/traders${query({ window: q.window, limit: q.limit })}`,
189
195
  launcherBoard: (q: { limit?: number } = {}): string => `/floor-amm/leaderboards/launchers${query({ limit: q.limit })}`,
190
196
  } as const satisfies Record<IndexerRouteName, (...a: never[]) => string>;
@@ -76,6 +76,17 @@ export const readTrades = (get: Get, id: LaunchId, q: TradesQuery = {}): Promise
76
76
  export const readLaunchClaims = (get: Get, id: LaunchId, q: { claimer?: string } = {}): Promise<At & { claims: B.LaunchClaim[] }> => readRoute(get, indexerPath.launchClaims(id, q), B.LAUNCH_CLAIMS);
77
77
  export const readDevBuys = (get: Get, id: LaunchId): Promise<B.DevBuys> => readRoute(get, indexerPath.devBuys(id), B.DEV_BUYS);
78
78
 
79
+ export const readMemberSold = (get: Get, id: LaunchId): Promise<B.MemberSoldBody> => readRoute(get, indexerPath.memberSold(id), B.MEMBER_SOLD);
80
+
81
+ export const readLaunchAccount = (get: Get, id: LaunchId): Promise<B.LaunchAccountBody> => readRoute(get, indexerPath.launchAccount(id), B.LAUNCH_ACCOUNT);
82
+
83
+ export function launchAccountBytes(body: { data: string }): Uint8Array {
84
+ const bin = atob(body.data);
85
+ const out = new Uint8Array(bin.length);
86
+ for (let i = 0; i < bin.length; i++) out[i] = bin.charCodeAt(i);
87
+ return out;
88
+ }
89
+
79
90
  export const readTraders = (get: Get, id: LaunchId, q: { window?: B.TraderWindow; limit?: number } = {}): Promise<B.LaunchTraders> => readRoute(get, indexerPath.traders(id, q), B.LAUNCH_TRADERS);
80
91
  export const readQuoteChain = (get: Get, id: LaunchId): Promise<B.QuoteChain> => readRoute(get, indexerPath.quoteChain(id), B.QUOTE_CHAIN);
81
92
 
@@ -104,6 +115,8 @@ export const readFirstsMany = (get: Get, wallets: readonly string[]): Promise<At
104
115
  export const readPeople = (get: Get, wallet: string): Promise<B.People> => readRoute(get, indexerPath.people(wallet), B.PEOPLE);
105
116
  export const readRoles = (get: Get, wallet: string): Promise<B.Roles> => readRoute(get, indexerPath.roles(wallet), B.ROLES);
106
117
 
118
+ export const readHandlePlaces = (get: Get, handle: string): Promise<B.HandlePlaces> => readRoute(get, indexerPath.handlePlaces(handle), B.HANDLE_PLACES);
119
+
107
120
  export const readTraderBoard = (get: Get, q: { window?: B.TraderWindow; limit?: number } = {}): Promise<B.TraderBoard> => readRoute(get, indexerPath.traderBoard(q), B.TRADER_BOARD);
108
121
  export const readLauncherBoard = (get: Get, q: { limit?: number } = {}): Promise<B.LauncherBoard> => readRoute(get, indexerPath.launcherBoard(q), B.LAUNCHER_BOARD);
109
122
 
@@ -40,7 +40,7 @@ function commit(dst: Book, src: Book): void {
40
40
 
41
41
  type Side = { row: SplitRow; sup: Supply } | null;
42
42
 
43
- function buyOn(book: Book, side: Side, gross: bigint, minTokens: bigint, walkSteps: number): BookBuy {
43
+ function buyOn(book: Book, side: Side, gross: bigint, minTokens: bigint, walkSteps: number, keep = true): BookBuy {
44
44
  const ppm = feesNow(book);
45
45
  const budget = netFromGross(gross, ppm);
46
46
  if (budget === 0n) fail("NothingToDo");
@@ -82,11 +82,11 @@ function buyOn(book: Book, side: Side, gross: bigint, minTokens: bigint, walkSte
82
82
  steps: walked.steps, budgetHit: walked.budgetHit, graduatedNow: walked.graduatedNow, sqrtBefore: book.sqrtP, sqrtAfter: w.sqrtP,
83
83
  split: sp, relay: rl,
84
84
  };
85
- commit(book, w);
85
+ if (keep) commit(book, w);
86
86
  return r;
87
87
  }
88
88
 
89
- function sellOn(book: Book, side: Side, tokens: bigint, minOut: bigint): BookSell {
89
+ function sellOn(book: Book, side: Side, tokens: bigint, minOut: bigint, keep = true): BookSell {
90
90
  if (tokens === 0n) fail("NothingToDo");
91
91
  const ppm = feesNow(book);
92
92
  const w = cloneBook(book);
@@ -105,7 +105,7 @@ function sellOn(book: Book, side: Side, tokens: bigint, minOut: bigint): BookSel
105
105
  tokensIn: tokens, unfilled: tokens - walked.tokens, gross: walked.money, fees, out, steps: walked.steps, sqrtBefore: book.sqrtP, sqrtAfter: w.sqrtP,
106
106
  fromF: walked.fromF, fromK: walked.fromK, fromC: walked.fromC, relay: rl,
107
107
  };
108
- commit(book, w);
108
+ if (keep) commit(book, w);
109
109
  return r;
110
110
  }
111
111
 
@@ -118,8 +118,8 @@ export function sell(book: Book, row: SplitRow, sup: Supply, tokens: bigint, min
118
118
  }
119
119
 
120
120
  export const quoteBuy = (book: Book, row: SplitRow, sup: Supply, gross: bigint, walkSteps: number = MAX_WALK_STEPS): BookBuy =>
121
- buy(cloneBook(book), row, sup, gross, 0n, { walkSteps });
122
- export const quoteSell = (book: Book, row: SplitRow, sup: Supply, tokens: bigint): BookSell => sell(cloneBook(book), row, sup, tokens, 0n);
121
+ buyOn(book, { row, sup }, gross, 0n, walkSteps, false);
122
+ export const quoteSell = (book: Book, row: SplitRow, sup: Supply, tokens: bigint): BookSell => sellOn(book, { row, sup }, tokens, 0n, false);
123
123
 
124
124
  export function buyMinTokens(b: Book, row: SplitRow, sup: Supply, gross: bigint, slippageBps: number, walkSteps: number = MAX_WALK_STEPS): bigint {
125
125
  const less = buyLessIn(gross, slippageBps);
@@ -141,5 +141,5 @@ export function bookSell(book: Book, tokens: bigint, minOut: bigint): BookSell {
141
141
  return sellOn(book, null, tokens, minOut);
142
142
  }
143
143
 
144
- export const quoteBookBuy = (book: Book, gross: bigint, walkSteps: number = MAX_WALK_STEPS): BookBuy => bookBuy(cloneBook(book), gross, 0n, walkSteps);
145
- export const quoteBookSell = (book: Book, tokens: bigint): BookSell => bookSell(cloneBook(book), tokens, 0n);
144
+ export const quoteBookBuy = (book: Book, gross: bigint, walkSteps: number = MAX_WALK_STEPS): BookBuy => buyOn(book, null, gross, 0n, walkSteps, false);
145
+ export const quoteBookSell = (book: Book, tokens: bigint): BookSell => sellOn(book, null, tokens, 0n, false);
@@ -125,7 +125,9 @@ export const GENESIS_RAISE: Layout = [
125
125
 
126
126
  ["preset_id", "u8"],
127
127
  ["opened", "u8"],
128
- ["pad1", "bytes:6"],
128
+
129
+ ["public_open", "u8"],
130
+ ["pad1", "bytes:5"],
129
131
  ["cap", "u64"],
130
132
  ["ends_at", "i64"],
131
133
  ["migrated_refunded", "u64"],
@@ -75,6 +75,10 @@ export const EVENTS: Record<string, [string, T][]> = {
75
75
  BurnsSynced: S(["launch", "pubkey"], ["incinerated", "u64"], ["supply", "u64"], ["sOut", "u64"], ["floorAfterX64", "u128"], ["slot", "u64"]),
76
76
 
77
77
  TokensBurned: S(["launch", "pubkey"], ["wallet", "pubkey"], ["role", "u8"], ["place", "u8"], ["fromTeamBuy", "u64"], ["fromWallet", "u64"], ["balanceBefore", "u64"], ["owedAfter", "u64"], ["split", "u64[10]"], ["supply", "u64"], ["sOut", "u64"], ["floorAfterX64", "u128"], ["slot", "u64"], ["fromShareBought", "u64?"]),
78
+
79
+ GenesisPublicStarted: S(["signer", "pubkey"], ["at", "i64"]),
80
+
81
+ GenesisEndSet: S(["signer", "pubkey"], ["oldEndsAt", "i64"], ["newEndsAt", "i64"]),
78
82
  };
79
83
 
80
84
  export const SWEPT_BURN = 0;
@@ -295,6 +295,19 @@ export function setGenesisListRootInstruction(p: { authority: string; config: st
295
295
  return ix("set_genesis_list_root", [RS(p.authority), R(p.config), W(p.genesisRaise)], (w) => w.bytes(p.listRoot), p);
296
296
  }
297
297
 
298
+ export const GENESIS_NO_END = (1n << 63n) - 1n;
299
+
300
+ export function startGenesisPublicInstruction(p: { authority: string; config?: string; genesisRaise?: string } & Ctx): Instruction {
301
+ const g = pid(p);
302
+ return ix("start_genesis_public", [RS(p.authority), R(p.config ?? configPda(g)[0]), W(p.genesisRaise ?? genesisRaisePda(g)[0])], none, p);
303
+ }
304
+
305
+ export function setGenesisEndInstruction(p: { authority: string; endsAt: bigint; config?: string; genesisRaise?: string } & Ctx): Instruction {
306
+ if (p.endsAt < 0n || p.endsAt > GENESIS_NO_END) throw new RangeError(`setGenesisEndInstruction: endsAt ${p.endsAt} is not an i64 ≥ 0`);
307
+ const g = pid(p);
308
+ return ix("set_genesis_end", [RS(p.authority), R(p.config ?? configPda(g)[0]), W(p.genesisRaise ?? genesisRaisePda(g)[0])], (w) => w.u64(p.endsAt), p);
309
+ }
310
+
298
311
  export function setGenesisPresetInstruction(p: { authority: string; config: string; genesisRaise: string; preset: string; presetId: number } & Ctx): Instruction {
299
312
  return ix("set_genesis_preset", [RS(p.authority), R(p.config), W(p.genesisRaise), R(p.preset)], (w) => w.u8(p.presetId), p);
300
313
  }
package/src/v2/devbuy.ts CHANGED
@@ -53,3 +53,36 @@ export function devBuyFromTrade(t: TradeEventV2, team: DevTeam, ctx: { teamBuy?:
53
53
  }
54
54
 
55
55
  export const devBuyChangeSinceBps = (d: DevBuy, sqrtNow: bigint): bigint => impactBps(d.priceAfterX64, priceX64(sqrtNow));
56
+
57
+ export interface TeamSeat {
58
+ place: number;
59
+ wallet: string;
60
+ }
61
+
62
+ export interface MemberSold {
63
+ launch: string;
64
+
65
+ member: string;
66
+
67
+ place: number;
68
+
69
+ amount: bigint;
70
+
71
+ quoteOut: bigint;
72
+ slot?: bigint;
73
+ }
74
+
75
+ export function memberSoldFromTrade(
76
+ t: Pick<TradeEventV2, "launch" | "trader" | "isBuy" | "tokens" | "quoteNet"> & { recipient?: string; slot?: bigint },
77
+ seats: readonly TeamSeat[],
78
+ same: (a: string, b: string) => boolean = (a, b) => a === b,
79
+ ): MemberSold | null {
80
+ if (t.isBuy) return null;
81
+ for (const who of t.recipient === undefined ? [t.trader] : [t.trader, t.recipient]) {
82
+ const held = seats.filter((s) => same(s.wallet, who));
83
+ if (held.length === 0) continue;
84
+ const seat = held.reduce((lo, s) => (s.place < lo.place ? s : lo));
85
+ return { launch: t.launch, member: seat.wallet, place: seat.place, amount: t.tokens, quoteOut: t.quoteNet, ...(t.slot === undefined ? {} : { slot: t.slot }) };
86
+ }
87
+ return null;
88
+ }
@@ -0,0 +1,22 @@
1
+
2
+
3
+ export function isDustRefund(gross: bigint, refund: bigint, budgetHit: boolean): boolean {
4
+ return refund > 0n && !budgetHit && refund * 1_000_000n <= gross;
5
+ }
6
+
7
+ export function carriesNoRefund(gross: bigint, refund: bigint, budgetHit: boolean): boolean {
8
+ return refund === 0n || isDustRefund(gross, refund, budgetHit);
9
+ }
10
+
11
+ export const GAS_FLAT = { buy: 700_000, sell: 750_000 } as const;
12
+
13
+ export const GAS_PER_STEP = { buy: 40_000, sell: 40_000 } as const;
14
+
15
+ export const GAS_FLAT_STEPS = 4;
16
+
17
+ export const GAS_MAX = 1_500_000;
18
+
19
+ export function gasFor(side: "buy" | "sell", steps: number): number {
20
+ const extra = Math.max(0, Math.trunc(steps) - GAS_FLAT_STEPS);
21
+ return Math.min(GAS_MAX, GAS_FLAT[side] + extra * GAS_PER_STEP[side]);
22
+ }