@floorlaunchpad/sdk 0.3.0 → 0.3.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 +30 -0
- package/README.md +9 -0
- package/dist/abi/solana.gen.js +2 -0
- package/dist/config/generated.js +121 -64
- package/dist/evm/chains.js +5 -1
- package/dist/evm/squid.js +107 -0
- package/dist/index.js +2 -0
- package/dist/indexer/client.js +1 -0
- package/dist/indexer/contract.js +11 -2
- package/dist/indexer/partners.js +5 -0
- package/dist/math/v2/trade.js +8 -8
- package/dist/solana/floor/accounts.js +3 -1
- package/dist/solana/floor/events.js +4 -0
- package/dist/solana/floor/instructions.js +13 -0
- package/dist/v2/router.js +22 -0
- package/docs/floor-line.md +66 -0
- package/examples/floor-line.html +104 -0
- package/package.json +2 -1
- package/src/abi/solana.gen.ts +2 -0
- package/src/config/generated.ts +121 -64
- package/src/config/index.ts +2 -0
- package/src/events/types.gen.ts +11 -0
- package/src/evm/chains.ts +5 -1
- package/src/evm/squid.ts +138 -0
- package/src/index.ts +2 -0
- package/src/indexer/client.ts +2 -0
- package/src/indexer/contract.ts +12 -3
- package/src/indexer/partners.ts +6 -0
- package/src/math/v2/trade.ts +8 -8
- package/src/solana/floor/accounts.ts +3 -1
- package/src/solana/floor/events.ts +4 -0
- package/src/solana/floor/instructions.ts +13 -0
- package/src/v2/router.ts +22 -0
package/src/math/v2/trade.ts
CHANGED
|
@@ -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
|
-
|
|
122
|
-
export const quoteSell = (book: Book, row: SplitRow, sup: Supply, tokens: bigint): BookSell =>
|
|
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 =>
|
|
145
|
-
export const quoteBookSell = (book: Book, tokens: bigint): BookSell =>
|
|
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
|
-
|
|
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/router.ts
ADDED
|
@@ -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
|
+
}
|