@floorlaunchpad/sdk 0.3.2 → 0.4.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +94 -0
- package/README.md +16 -0
- package/dist/abi/evm.gen.js +6 -1
- package/dist/abi/solana.gen.js +1 -1
- package/dist/client/evm/index.js +16 -2
- package/dist/client/solana/index.js +31 -14
- package/dist/config/generated.js +26864 -402
- package/dist/config/registry.gen.js +33 -2
- package/dist/evm/chains.js +85 -16
- 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/evm/router.js +25 -1
- package/dist/evm/squid.js +9 -9
- package/dist/evm/zap.js +148 -35
- package/dist/indexer/bodies.js +96 -17
- package/dist/indexer/client.js +36 -14
- package/dist/indexer/contract.js +178 -28
- package/dist/indexer/partners.js +3 -2
- package/dist/indexer/paths.js +87 -29
- package/dist/indexer/read.js +30 -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/devbuy.js +6 -4
- package/dist/v2/presetRowEvm.js +21 -2
- package/dist/v2/solana.js +17 -2
- package/dist/v2/tx/solana.js +1 -1
- package/docs/aggregator.md +22 -0
- package/docs/bot.md +44 -1
- package/docs/cursor-pages.md +58 -0
- package/docs/floor-line.md +9 -4
- package/docs/frontend.md +2 -0
- package/docs/wallet.md +2 -0
- package/examples/floor-line.html +6 -6
- package/package.json +1 -1
- package/src/abi/evm.gen.ts +6 -1
- package/src/abi/solana.gen.ts +1 -1
- package/src/client/evm/index.ts +16 -2
- package/src/client/solana/index.ts +31 -14
- 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 +94 -15
- 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/evm/router.ts +26 -1
- package/src/evm/squid.ts +9 -9
- package/src/evm/zap.ts +185 -36
- package/src/indexer/bodies.ts +106 -17
- package/src/indexer/client.ts +56 -30
- package/src/indexer/contract.ts +197 -29
- package/src/indexer/partners.ts +3 -2
- package/src/indexer/paths.ts +131 -29
- package/src/indexer/read.ts +36 -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/devbuy.ts +6 -4
- package/src/v2/presetRowEvm.ts +21 -2
- package/src/v2/solana.ts +20 -3
- package/src/v2/tx/solana.ts +1 -1
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/devbuy.ts
CHANGED
|
@@ -36,18 +36,20 @@ export function teamSlotWallets(slot: DevTeam["teamSlot"]): string[] {
|
|
|
36
36
|
|
|
37
37
|
export const impactBps = (before: bigint, after: bigint): bigint => (before === 0n ? 0n : ((after - before) * 10_000n) / before);
|
|
38
38
|
|
|
39
|
-
export function devBuyFromTrade(t: TradeEventV2, team: DevTeam, ctx: { teamBuy?: boolean; teamShareBuy?: boolean } = {}): DevBuy | null {
|
|
39
|
+
export function devBuyFromTrade(t: TradeEventV2, team: DevTeam, ctx: { teamBuy?: boolean; teamShareBuy?: boolean; buyer?: string } = {}): DevBuy | null {
|
|
40
40
|
if (!t.isBuy) return null;
|
|
41
|
+
|
|
42
|
+
const person = ctx.buyer ?? t.trader;
|
|
41
43
|
let role: DevBuyRole | null = null;
|
|
42
44
|
if (t.kind === TRADE_KIND_TEAM_BUY || ctx.teamBuy) role = "team_buy";
|
|
43
45
|
else if (t.kind === TRADE_KIND_TEAM_SHARE_BUY || ctx.teamShareBuy) role = "team_share_buy";
|
|
44
|
-
else if (
|
|
45
|
-
else if (teamSlotWallets(team.teamSlot).includes(
|
|
46
|
+
else if (person === team.creator) role = "creator";
|
|
47
|
+
else if (teamSlotWallets(team.teamSlot).includes(person)) role = "team_member";
|
|
46
48
|
if (role === null) return null;
|
|
47
49
|
const priceBeforeX64 = priceX64(t.sqrtBefore);
|
|
48
50
|
const priceAfterX64 = priceX64(t.sqrtAfter);
|
|
49
51
|
return {
|
|
50
|
-
launch: t.launch, trader:
|
|
52
|
+
launch: t.launch, trader: person, role, quoteIn: t.quoteGross - t.refund, tokens: t.tokens, priceBeforeX64, priceAfterX64,
|
|
51
53
|
impactBps: impactBps(priceBeforeX64, priceAfterX64), slot: t.slot,
|
|
52
54
|
};
|
|
53
55
|
}
|
package/src/v2/presetRowEvm.ts
CHANGED
|
@@ -6,6 +6,7 @@ import { ROW_LEN, decodeRowV2 } from "../math/v2/preset.ts";
|
|
|
6
6
|
import type { RowV2 } from "../math/v2/preset.ts";
|
|
7
7
|
import type { PresetRowV2Account } from "./types.ts";
|
|
8
8
|
import { evmSignature } from "../generated/index.ts";
|
|
9
|
+
import { MULTICALL3_ADDRESS, aggregate3Call, decodeAggregate3Result } from "../evm/multicall.ts";
|
|
9
10
|
|
|
10
11
|
export const PRESET_ROW_VIEW_EVM = { sig: evmSignature("presetRow"), ret: ["(uint8,bool,bool,uint32,bytes32,bytes)"] } as const;
|
|
11
12
|
export const NEXT_PRESET_ID_VIEW_EVM = { sig: evmSignature("nextPresetId"), ret: ["uint8"] } as const;
|
|
@@ -46,9 +47,27 @@ export function presetMenuV2(rows: readonly (PresetRowV2Account | null)[]): Pres
|
|
|
46
47
|
.map((r) => ({ id: r.id, version: r.version, rowHash: bytesToHex(r.rowHash), row: decodeRowV2(r.row) }));
|
|
47
48
|
}
|
|
48
49
|
|
|
49
|
-
|
|
50
|
+
const PRESET_MENU_BATCH = 100;
|
|
51
|
+
|
|
52
|
+
export async function readPresetMenuEvmV2(
|
|
53
|
+
rpc: { ethCall: (to: string, data: string) => Promise<string> }, amm: string, opts: { multicall?: string | null } = {},
|
|
54
|
+
): Promise<PresetMenuItemV2[]> {
|
|
50
55
|
const next = decodeNextPresetIdEvmV2(await rpc.ethCall(amm, nextPresetIdCallV2()));
|
|
51
56
|
const ids = Array.from({ length: Math.max(0, next - 1) }, (_, i) => i + 1).filter((id) => id !== RETIRED_ID);
|
|
52
|
-
|
|
57
|
+
if (opts.multicall === null) {
|
|
58
|
+
return presetMenuV2(await Promise.all(ids.map(async (id) => decodePresetRowEvmV2(await rpc.ethCall(amm, presetRowCallV2(id))))));
|
|
59
|
+
}
|
|
60
|
+
const multicall = opts.multicall ?? MULTICALL3_ADDRESS;
|
|
61
|
+
const chunks: number[][] = [];
|
|
62
|
+
for (let i = 0; i < ids.length; i += PRESET_MENU_BATCH) chunks.push(ids.slice(i, i + PRESET_MENU_BATCH));
|
|
63
|
+
const rows = (await Promise.all(chunks.map(async (chunk) => {
|
|
64
|
+
const call = aggregate3Call(chunk.map((id) => ({ target: amm, allowFailure: true, callData: presetRowCallV2(id) })), multicall);
|
|
65
|
+
const res = decodeAggregate3Result(await rpc.ethCall(call.to, call.data));
|
|
66
|
+
if (res.length !== chunk.length) throw new RangeError(`aggregate3: ${res.length} results, ${chunk.length} calls`);
|
|
67
|
+
return res.map((r, i) => {
|
|
68
|
+
if (!r.success) throw new Error(`presetRow(${chunk[i]}) failed: ${r.returnData}`);
|
|
69
|
+
return decodePresetRowEvmV2(r.returnData);
|
|
70
|
+
});
|
|
71
|
+
}))).flat();
|
|
53
72
|
return presetMenuV2(rows);
|
|
54
73
|
}
|
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
|
}
|