@floorlaunchpad/sdk 0.1.1 → 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 +114 -0
- package/LICENSE +201 -60
- package/README.md +54 -24
- package/dist/abi/evm-event-names.js +12 -0
- package/dist/abi/evm.gen.js +130 -0
- package/dist/abi/functions.gen.js +144 -0
- package/dist/abi/index.js +17 -0
- package/dist/abi/solana.gen.js +130 -0
- package/dist/burn.js +21 -0
- package/dist/client/evm/index.js +191 -0
- package/dist/client/index.js +19 -0
- package/dist/client/solana/index.js +259 -0
- package/dist/client/types.js +5 -0
- package/dist/codec.js +77 -0
- package/dist/config/codeHash.js +9 -0
- package/dist/config/generated.js +803 -0
- package/dist/config/index.js +49 -0
- package/dist/config/registry.gen.js +118 -0
- package/dist/config/solana-genesis.js +7 -0
- package/dist/ed25519.js +31 -0
- package/dist/errors.js +249 -0
- package/dist/events/index.js +40 -0
- package/dist/events/types.gen.js +3 -0
- package/dist/evm/abi.js +283 -0
- package/dist/evm/balances.js +26 -0
- package/dist/evm/chains.js +148 -0
- package/dist/evm/floor/abi.gen.js +195 -0
- package/dist/evm/floor/calls.js +230 -0
- package/dist/evm/floor/create.js +49 -0
- package/dist/evm/floor/events.js +41 -0
- package/dist/evm/floor/iface.js +44 -0
- package/dist/evm/items.js +209 -0
- package/dist/evm/keccak.js +118 -0
- package/dist/evm/multicall.js +30 -0
- package/dist/evm/router.js +184 -0
- package/dist/evm/squid.js +107 -0
- package/dist/evm/zap.js +128 -0
- package/dist/fixtures.js +53 -0
- package/dist/generated/index.js +28 -0
- package/dist/generated/interface.gen.js +146 -0
- package/dist/handle.js +22 -0
- package/dist/index.js +93 -7
- package/dist/indexer/bodies.js +473 -0
- package/dist/indexer/client.js +105 -0
- package/dist/indexer/contract.js +358 -0
- package/dist/indexer/decode.js +97 -0
- package/dist/indexer/partners.js +105 -0
- package/dist/indexer/paths.js +127 -0
- package/dist/indexer/read.js +109 -0
- package/dist/indexer/stream.js +71 -0
- package/dist/lock.js +16 -0
- package/dist/math/fixed.js +154 -0
- package/dist/math/genesis.js +39 -0
- package/dist/math/index.js +20 -0
- package/dist/math/u256.js +49 -0
- package/dist/math/v2/ask.js +162 -0
- package/dist/math/v2/book.js +607 -0
- package/dist/math/v2/circulating.js +62 -0
- package/dist/math/v2/create.js +122 -0
- package/dist/math/v2/display.js +208 -0
- package/dist/math/v2/error.js +17 -0
- package/dist/math/v2/feasibility.js +174 -0
- package/dist/math/v2/fees.js +121 -0
- package/dist/math/v2/holders.js +105 -0
- package/dist/math/v2/milestones.js +40 -0
- package/dist/math/v2/pow.js +69 -0
- package/dist/math/v2/preset.js +151 -0
- package/dist/math/v2/receipt.js +108 -0
- package/dist/math/v2/relay.js +217 -0
- package/dist/math/v2/rows.js +365 -0
- package/dist/math/v2/split.js +111 -0
- package/dist/math/v2/sqrt.js +84 -0
- package/dist/math/v2/supply.js +21 -0
- package/dist/math/v2/team.js +75 -0
- package/dist/math/v2/trade.js +126 -0
- package/dist/math/v2/wide.js +51 -0
- package/dist/quote.js +6 -0
- package/dist/registryPrice.js +23 -0
- package/dist/route/edge-jupiter.js +42 -0
- package/dist/route/edge.js +11 -0
- package/dist/route/graph.js +51 -0
- package/dist/route/path.js +75 -0
- package/dist/route/quote.js +15 -0
- package/dist/route-jupiter.js +35 -0
- package/dist/route.js +8 -0
- package/dist/sha256.js +61 -0
- package/dist/solana/alt.js +18 -0
- package/dist/solana/floor/accounts.js +392 -0
- package/dist/solana/floor/borsh.js +66 -0
- package/dist/solana/floor/create.js +65 -0
- package/dist/solana/floor/events.js +144 -0
- package/dist/solana/floor/genesis.js +91 -0
- package/dist/solana/floor/genesisList.js +68 -0
- package/dist/solana/floor/instructions.js +448 -0
- package/dist/solana/floor/metadata.js +198 -0
- package/dist/solana/floor/mint.js +206 -0
- package/dist/solana/floor/program.js +64 -0
- package/dist/solana/floor/registry.js +83 -0
- package/dist/solana/instruction.js +49 -0
- package/dist/solana/pda.js +88 -0
- package/dist/solana/tx.js +138 -0
- package/dist/v2/burnPreview.js +35 -0
- package/dist/v2/circulating.js +11 -0
- package/dist/v2/claimAllEvm.js +70 -0
- package/dist/v2/claims-evm.js +120 -0
- package/dist/v2/claims.js +218 -0
- package/dist/v2/dead.js +21 -0
- package/dist/v2/devbuy.js +37 -0
- package/dist/v2/events.js +115 -0
- package/dist/v2/evm.js +299 -0
- package/dist/v2/evmReads.js +76 -0
- package/dist/v2/genesis.js +76 -0
- package/dist/v2/layouts.js +217 -0
- package/dist/v2/market-evm.js +74 -0
- package/dist/v2/presetRowEvm.js +45 -0
- package/dist/v2/press.js +106 -0
- package/dist/v2/quoteMint.js +52 -0
- package/dist/v2/receipt-tx.js +149 -0
- package/dist/v2/route-alt.js +114 -0
- package/dist/v2/route.js +389 -0
- package/dist/v2/router.js +22 -0
- package/dist/v2/solana.js +391 -0
- package/dist/v2/solanaSettle.js +97 -0
- package/dist/v2/tx/evm.js +126 -0
- package/dist/v2/tx/genesis.js +47 -0
- package/dist/v2/tx/index.js +5 -0
- package/dist/v2/tx/solana.js +118 -0
- package/dist/v2/types.js +13 -0
- package/docs/aggregator.md +61 -0
- package/docs/bot.md +50 -0
- package/docs/floor-line.md +66 -0
- package/docs/frontend.md +29 -0
- package/docs/wallet.md +54 -0
- package/examples/floor-line.html +104 -0
- package/package.json +429 -32
- package/src/abi/evm-event-names.ts +12 -0
- package/src/abi/evm.gen.ts +139 -0
- package/src/abi/functions.gen.ts +154 -0
- package/src/abi/index.ts +30 -0
- package/src/abi/solana.gen.ts +140 -0
- package/src/burn.ts +37 -0
- package/src/client/evm/index.ts +199 -0
- package/src/client/index.ts +23 -0
- package/src/client/solana/index.ts +260 -0
- package/src/client/types.ts +162 -0
- package/src/codec.ts +77 -0
- package/src/config/codeHash.ts +9 -0
- package/src/config/generated.ts +803 -0
- package/src/config/index.ts +93 -0
- package/src/config/registry.gen.ts +118 -0
- package/src/config/solana-genesis.ts +7 -0
- package/src/ed25519.ts +31 -0
- package/src/errors.ts +270 -0
- package/src/events/index.ts +44 -0
- package/src/events/types.gen.ts +842 -0
- package/src/evm/abi.ts +292 -0
- package/src/evm/balances.ts +26 -0
- package/src/evm/chains.ts +171 -0
- package/src/evm/floor/abi.gen.ts +195 -0
- package/src/evm/floor/calls.ts +247 -0
- package/src/evm/floor/create.ts +68 -0
- package/src/evm/floor/events.ts +51 -0
- package/src/evm/floor/iface.ts +45 -0
- package/src/evm/items.ts +252 -0
- package/src/evm/keccak.ts +118 -0
- package/src/evm/multicall.ts +43 -0
- package/src/evm/router.ts +209 -0
- package/src/evm/squid.ts +138 -0
- package/src/evm/zap.ts +152 -0
- package/src/fixtures.ts +53 -0
- package/src/generated/index.ts +29 -0
- package/src/generated/interface.gen.ts +153 -0
- package/src/handle.ts +22 -0
- package/src/index.ts +93 -6
- package/src/indexer/bodies.ts +528 -0
- package/src/indexer/client.ts +180 -0
- package/src/indexer/contract.ts +419 -0
- package/src/indexer/decode.ts +109 -0
- package/src/indexer/partners.ts +115 -0
- package/src/indexer/paths.ts +190 -0
- package/src/indexer/read.ts +119 -0
- package/src/indexer/stream.ts +83 -0
- package/src/lock.ts +16 -0
- package/src/math/fixed.ts +154 -0
- package/src/math/genesis.ts +39 -0
- package/src/math/index.ts +24 -0
- package/src/math/u256.ts +49 -0
- package/src/math/v2/ask.ts +218 -0
- package/src/math/v2/book.ts +660 -0
- package/src/math/v2/circulating.ts +69 -0
- package/src/math/v2/create.ts +139 -0
- package/src/math/v2/display.ts +250 -0
- package/src/math/v2/error.ts +19 -0
- package/src/math/v2/feasibility.ts +200 -0
- package/src/math/v2/fees.ts +121 -0
- package/src/math/v2/holders.ts +124 -0
- package/src/math/v2/milestones.ts +51 -0
- package/src/math/v2/pow.ts +71 -0
- package/src/math/v2/preset.ts +189 -0
- package/src/math/v2/receipt.ts +162 -0
- package/src/math/v2/relay.ts +235 -0
- package/src/math/v2/rows.ts +412 -0
- package/src/math/v2/split.ts +160 -0
- package/src/math/v2/sqrt.ts +86 -0
- package/src/math/v2/supply.ts +27 -0
- package/src/math/v2/team.ts +75 -0
- package/src/math/v2/trade.ts +145 -0
- package/src/math/v2/wide.ts +52 -0
- package/src/quote.ts +6 -0
- package/src/registryPrice.ts +28 -0
- package/src/route/edge-jupiter.ts +71 -0
- package/src/route/edge.ts +22 -0
- package/src/route/graph.ts +77 -0
- package/src/route/path.ts +84 -0
- package/src/route/quote.ts +46 -0
- package/src/route-jupiter.ts +36 -0
- package/src/route.ts +8 -0
- package/src/sha256.ts +61 -0
- package/src/solana/alt.ts +25 -0
- package/src/solana/floor/accounts.ts +395 -0
- package/src/solana/floor/borsh.ts +66 -0
- package/src/solana/floor/create.ts +89 -0
- package/src/solana/floor/events.ts +151 -0
- package/src/solana/floor/genesis.ts +111 -0
- package/src/solana/floor/genesisList.ts +75 -0
- package/src/solana/floor/instructions.ts +504 -0
- package/src/solana/floor/metadata.ts +246 -0
- package/src/solana/floor/mint.ts +242 -0
- package/src/solana/floor/program.ts +64 -0
- package/src/solana/floor/registry.ts +96 -0
- package/src/solana/instruction.ts +61 -0
- package/src/solana/pda.ts +91 -0
- package/src/solana/tx.ts +143 -0
- package/src/v2/burnPreview.ts +52 -0
- package/src/v2/circulating.ts +22 -0
- package/src/v2/claimAllEvm.ts +97 -0
- package/src/v2/claims-evm.ts +179 -0
- package/src/v2/claims.ts +288 -0
- package/src/v2/dead.ts +21 -0
- package/src/v2/devbuy.ts +55 -0
- package/src/v2/events.ts +131 -0
- package/src/v2/evm.ts +349 -0
- package/src/v2/evmReads.ts +121 -0
- package/src/v2/genesis.ts +80 -0
- package/src/v2/layouts.ts +219 -0
- package/src/v2/market-evm.ts +95 -0
- package/src/v2/presetRowEvm.ts +54 -0
- package/src/v2/press.ts +124 -0
- package/src/v2/quoteMint.ts +63 -0
- package/src/v2/receipt-tx.ts +251 -0
- package/src/v2/route-alt.ts +114 -0
- package/src/v2/route.ts +494 -0
- package/src/v2/router.ts +22 -0
- package/src/v2/solana.ts +439 -0
- package/src/v2/solanaSettle.ts +117 -0
- package/src/v2/tx/evm.ts +152 -0
- package/src/v2/tx/genesis.ts +66 -0
- package/src/v2/tx/index.ts +5 -0
- package/src/v2/tx/solana.ts +140 -0
- package/src/v2/types.ts +284 -0
- package/dist/adapter.d.ts +0 -28
- package/dist/adapter.d.ts.map +0 -1
- package/dist/adapter.js +0 -2
- package/dist/adapter.js.map +0 -1
- package/dist/chain.d.ts +0 -23
- package/dist/chain.d.ts.map +0 -1
- package/dist/chain.js +0 -25
- package/dist/chain.js.map +0 -1
- package/dist/client.d.ts +0 -26
- package/dist/client.d.ts.map +0 -1
- package/dist/client.js +0 -43
- package/dist/client.js.map +0 -1
- package/dist/dex-adapter.d.ts +0 -228
- package/dist/dex-adapter.d.ts.map +0 -1
- package/dist/dex-adapter.js +0 -407
- package/dist/dex-adapter.js.map +0 -1
- package/dist/index.d.ts +0 -7
- package/dist/index.d.ts.map +0 -1
- package/dist/index.js.map +0 -1
- package/dist/quotes.d.ts +0 -12
- package/dist/quotes.d.ts.map +0 -1
- package/dist/quotes.gen.d.ts +0 -8
- package/dist/quotes.gen.d.ts.map +0 -1
- package/dist/quotes.gen.js +0 -2170
- package/dist/quotes.gen.js.map +0 -1
- package/dist/quotes.js +0 -24
- package/dist/quotes.js.map +0 -1
- package/dist/types.d.ts +0 -111
- package/dist/types.d.ts.map +0 -1
- package/dist/types.js +0 -2
- package/dist/types.js.map +0 -1
- package/src/adapter.ts +0 -20
- package/src/chain.ts +0 -39
- package/src/client.ts +0 -41
- package/src/dex-adapter.ts +0 -477
- package/src/quotes.gen.ts +0 -2170
- package/src/quotes.ts +0 -29
- package/src/types.ts +0 -115
|
@@ -0,0 +1,251 @@
|
|
|
1
|
+
|
|
2
|
+
|
|
3
|
+
import { decodeEvmLogs, decodeSolanaEventCpi } from "../events/index.ts";
|
|
4
|
+
import type { EvmEvent, FloorEvent, SolanaEvent } from "../events/index.ts";
|
|
5
|
+
import type { Log } from "../evm/items.ts";
|
|
6
|
+
import type { FeeLegs, FloorFamily } from "../client/types.ts";
|
|
7
|
+
import { base58Decode } from "../codec.ts";
|
|
8
|
+
import { FLOOR_AMM_PROGRAM_ID } from "../solana/floor/program.ts";
|
|
9
|
+
|
|
10
|
+
export interface EvmLandedTx {
|
|
11
|
+
logs: readonly Log[];
|
|
12
|
+
}
|
|
13
|
+
export interface SolanaLandedTx {
|
|
14
|
+
innerInstructions: readonly { programId: string; data: Uint8Array | string }[];
|
|
15
|
+
}
|
|
16
|
+
export type LandedTx = EvmLandedTx | SolanaLandedTx;
|
|
17
|
+
|
|
18
|
+
export interface ReceiptScope {
|
|
19
|
+
|
|
20
|
+
floorAmm?: string | readonly string[];
|
|
21
|
+
|
|
22
|
+
programId?: string;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
const isEvm = (t: LandedTx): t is EvmLandedTx => "logs" in t;
|
|
26
|
+
|
|
27
|
+
const same = (chain: FloorFamily, a: string, b: string): boolean => (chain === "evm" ? a.toLowerCase() === b.toLowerCase() : a === b);
|
|
28
|
+
|
|
29
|
+
export function eventsOf(landed: LandedTx, scope: ReceiptScope = {}): FloorEvent[] {
|
|
30
|
+
if (isEvm(landed)) {
|
|
31
|
+
const from = scope.floorAmm === undefined ? undefined : typeof scope.floorAmm === "string" ? [scope.floorAmm] : scope.floorAmm;
|
|
32
|
+
return decodeEvmLogs(landed.logs, from);
|
|
33
|
+
}
|
|
34
|
+
const pid = scope.programId ?? FLOOR_AMM_PROGRAM_ID;
|
|
35
|
+
const out: SolanaEvent[] = [];
|
|
36
|
+
for (const ix of landed.innerInstructions) {
|
|
37
|
+
if (ix.programId !== pid) continue;
|
|
38
|
+
const e = decodeSolanaEventCpi(typeof ix.data === "string" ? base58Decode(ix.data) : ix.data);
|
|
39
|
+
if (e) out.push(e);
|
|
40
|
+
}
|
|
41
|
+
return out;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
const launchOf = (e: FloorEvent): string => (e.chain === "evm" ? String((e.fields as { launchId: bigint }).launchId) : (e.fields as { launch: string }).launch);
|
|
45
|
+
const launchKey = (l: string | bigint | undefined): string | undefined => (l === undefined ? undefined : String(l));
|
|
46
|
+
const pick = <N extends string>(es: FloorEvent[], name: N): Extract<FloorEvent, { name: N }>[] => es.filter((e): e is Extract<FloorEvent, { name: N }> => e.name === name);
|
|
47
|
+
|
|
48
|
+
export interface ReceiptFill {
|
|
49
|
+
family: FloorFamily;
|
|
50
|
+
side: "buy" | "sell";
|
|
51
|
+
|
|
52
|
+
launch: string;
|
|
53
|
+
trader: string;
|
|
54
|
+
recipient: string;
|
|
55
|
+
|
|
56
|
+
amountIn: bigint;
|
|
57
|
+
|
|
58
|
+
amountOut: bigint;
|
|
59
|
+
|
|
60
|
+
refund: bigint;
|
|
61
|
+
quoteGross: bigint;
|
|
62
|
+
quoteNet: bigint;
|
|
63
|
+
|
|
64
|
+
fees: FeeLegs;
|
|
65
|
+
|
|
66
|
+
kind: number;
|
|
67
|
+
sqrtBefore: bigint;
|
|
68
|
+
sqrtAfter: bigint;
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
export function fillOf(side: "buy" | "sell", landed: LandedTx, p: { trader?: string; launch?: string | bigint } & ReceiptScope = {}): ReceiptFill | null {
|
|
72
|
+
const want = launchKey(p.launch);
|
|
73
|
+
for (const e of pick(eventsOf(landed, p), "Trade")) {
|
|
74
|
+
const f = e.fields;
|
|
75
|
+
if (f.isBuy !== (side === "buy")) continue;
|
|
76
|
+
if (p.trader !== undefined && !same(e.chain, f.trader, p.trader)) continue;
|
|
77
|
+
const launch = launchOf(e);
|
|
78
|
+
if (want !== undefined && launch !== want) continue;
|
|
79
|
+
const [backing, team, platform, floor, holder] = f.fees;
|
|
80
|
+
return {
|
|
81
|
+
family: e.chain, side, launch, trader: f.trader, recipient: f.recipient,
|
|
82
|
+
amountIn: f.isBuy ? f.quoteGross - f.refund : f.tokens, amountOut: f.isBuy ? f.tokens : f.quoteNet, refund: f.isBuy ? f.refund : f.unfilled,
|
|
83
|
+
quoteGross: f.quoteGross, quoteNet: f.quoteNet,
|
|
84
|
+
fees: { backing, team, platform, floor, holder, total: backing + team + platform + floor + holder },
|
|
85
|
+
kind: Number(f.kind), sqrtBefore: f.sqrtBefore, sqrtAfter: f.sqrtAfter,
|
|
86
|
+
};
|
|
87
|
+
}
|
|
88
|
+
return null;
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
export interface ReceiptClaimed {
|
|
92
|
+
quote: string;
|
|
93
|
+
launch: string | null;
|
|
94
|
+
|
|
95
|
+
types: number;
|
|
96
|
+
creator: bigint;
|
|
97
|
+
creatorRef: bigint;
|
|
98
|
+
teamSlot: bigint;
|
|
99
|
+
traderRef: bigint;
|
|
100
|
+
holder: bigint;
|
|
101
|
+
extra: bigint;
|
|
102
|
+
|
|
103
|
+
amount: bigint;
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
export interface ReceiptPayout {
|
|
107
|
+
quote: string;
|
|
108
|
+
to: string;
|
|
109
|
+
amount: bigint;
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
export interface ReceiptTokensPaid {
|
|
113
|
+
launch: string;
|
|
114
|
+
kind: "teamBuy" | "shareBought" | "teamBuyUnlocked";
|
|
115
|
+
tokens: bigint;
|
|
116
|
+
}
|
|
117
|
+
export interface ReceiptPaid {
|
|
118
|
+
claims: ReceiptClaimed[];
|
|
119
|
+
payouts: ReceiptPayout[];
|
|
120
|
+
tokens: ReceiptTokensPaid[];
|
|
121
|
+
|
|
122
|
+
byQuote: Record<string, bigint>;
|
|
123
|
+
|
|
124
|
+
tokensTotal: bigint;
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
export function paidOf(landed: LandedTx, p: { wallet: string } & ReceiptScope): ReceiptPaid {
|
|
128
|
+
const out: ReceiptPaid = { claims: [], payouts: [], tokens: [], byQuote: {}, tokensTotal: 0n };
|
|
129
|
+
const add = (q: string, a: bigint) => {
|
|
130
|
+
out.byQuote[q] = (out.byQuote[q] ?? 0n) + a;
|
|
131
|
+
};
|
|
132
|
+
const tok = (launch: string, kind: ReceiptTokensPaid["kind"], tokens: bigint | null) => {
|
|
133
|
+
if (tokens === null || tokens === 0n) return;
|
|
134
|
+
out.tokens.push({ launch, kind, tokens });
|
|
135
|
+
out.tokensTotal += tokens;
|
|
136
|
+
};
|
|
137
|
+
for (const e of eventsOf(landed, p)) {
|
|
138
|
+
if (e.chain === "solana") {
|
|
139
|
+
if (e.name === "Claimed" && e.fields.wallet === p.wallet) {
|
|
140
|
+
const f = e.fields;
|
|
141
|
+
out.claims.push({
|
|
142
|
+
quote: f.quoteMint, launch: f.launch, types: f.types | ((f.typesHi ?? 0) << 8), creator: f.creator, creatorRef: f.creatorRef, teamSlot: f.teamSlot,
|
|
143
|
+
traderRef: f.traderRef, holder: 0n, extra: f.extra, amount: f.amount,
|
|
144
|
+
});
|
|
145
|
+
add(f.quoteMint, f.amount);
|
|
146
|
+
tok(f.launch, "teamBuy", f.teamBuy);
|
|
147
|
+
tok(f.launch, "shareBought", f.shareBought);
|
|
148
|
+
} else if (e.name === "CreatorBuyUnlocked" && e.fields.creator === p.wallet) tok(e.fields.launch, "teamBuyUnlocked", e.fields.paid ?? e.fields.tokens);
|
|
149
|
+
continue;
|
|
150
|
+
}
|
|
151
|
+
evmPaid(e, p.wallet, out, add, tok);
|
|
152
|
+
}
|
|
153
|
+
return out;
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
function evmPaid(e: EvmEvent, wallet: string, out: ReceiptPaid, add: (q: string, a: bigint) => void, tok: (l: string, k: ReceiptTokensPaid["kind"], t: bigint) => void): void {
|
|
157
|
+
switch (e.name) {
|
|
158
|
+
case "Claimed": {
|
|
159
|
+
const f = e.fields;
|
|
160
|
+
if (!same("evm", f.wallet, wallet)) return;
|
|
161
|
+
out.claims.push({ quote: f.quote, launch: null, types: Number(f.types), creator: f.creator, creatorRef: f.creatorRef, teamSlot: f.teamSlot, traderRef: f.traderRef, holder: f.holder, extra: f.extra, amount: f.amount });
|
|
162
|
+
add(f.quote, f.amount);
|
|
163
|
+
return;
|
|
164
|
+
}
|
|
165
|
+
case "PayoutClaimed":
|
|
166
|
+
if (!same("evm", e.fields.wallet, wallet)) return;
|
|
167
|
+
out.payouts.push({ quote: e.fields.quote, to: e.fields.to, amount: e.fields.amount });
|
|
168
|
+
add(e.fields.quote, e.fields.amount);
|
|
169
|
+
return;
|
|
170
|
+
case "TeamBuyClaimed":
|
|
171
|
+
if (same("evm", e.fields.wallet, wallet)) tok(String(e.fields.launchId), "teamBuy", e.fields.tokens);
|
|
172
|
+
return;
|
|
173
|
+
case "TeamShareBoughtClaimed":
|
|
174
|
+
if (same("evm", e.fields.wallet, wallet)) tok(String(e.fields.launchId), "shareBought", e.fields.tokens);
|
|
175
|
+
return;
|
|
176
|
+
case "CreatorBuyUnlocked":
|
|
177
|
+
if (same("evm", e.fields.creator, wallet)) tok(String(e.fields.launchId), "teamBuyUnlocked", e.fields.paid);
|
|
178
|
+
return;
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
export interface ReceiptCreated {
|
|
183
|
+
family: FloorFamily;
|
|
184
|
+
|
|
185
|
+
launch: string;
|
|
186
|
+
launchId: bigint;
|
|
187
|
+
|
|
188
|
+
token: string;
|
|
189
|
+
quote: string;
|
|
190
|
+
creator: string;
|
|
191
|
+
presetId: number;
|
|
192
|
+
creatorBuyTokens: bigint;
|
|
193
|
+
createFee: bigint;
|
|
194
|
+
nativeCreateFee: bigint;
|
|
195
|
+
name: string;
|
|
196
|
+
symbol: string;
|
|
197
|
+
listed: boolean;
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
const text = (b: Uint8Array): string => {
|
|
201
|
+
let n = b.length;
|
|
202
|
+
while (n > 0 && b[n - 1] === 0) n--;
|
|
203
|
+
return new TextDecoder().decode(b.slice(0, n));
|
|
204
|
+
};
|
|
205
|
+
|
|
206
|
+
export function createdOf(landed: LandedTx, scope: ReceiptScope = {}): ReceiptCreated | null {
|
|
207
|
+
for (const e of eventsOf(landed, scope)) {
|
|
208
|
+
if (e.chain === "solana" && (e.name === "LaunchCreatedV2" || e.name === "LaunchCreated")) {
|
|
209
|
+
const f = e.fields;
|
|
210
|
+
return {
|
|
211
|
+
family: "solana", launch: f.launch, launchId: f.id, token: f.mint, quote: f.quoteMint, creator: f.creator, presetId: f.presetId, creatorBuyTokens: f.creatorBuyTokens,
|
|
212
|
+
createFee: f.createFee, nativeCreateFee: f.nativeCreateFee, name: text(f.name), symbol: text(f.symbol), listed: f.listed,
|
|
213
|
+
};
|
|
214
|
+
}
|
|
215
|
+
if (e.chain === "evm" && e.name === "LaunchCreated") {
|
|
216
|
+
const f = e.fields;
|
|
217
|
+
return {
|
|
218
|
+
family: "evm", launch: String(f.launchId), launchId: f.launchId, token: f.token, quote: f.quote, creator: f.creator, presetId: Number(f.presetId),
|
|
219
|
+
creatorBuyTokens: f.creatorBuyTokens, createFee: f.createFee, nativeCreateFee: f.nativeCreateFee, name: f.name, symbol: f.symbol, listed: f.listed,
|
|
220
|
+
};
|
|
221
|
+
}
|
|
222
|
+
}
|
|
223
|
+
return null;
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
export interface ReceiptBurned {
|
|
227
|
+
launch: string;
|
|
228
|
+
fromTeamBuy: bigint;
|
|
229
|
+
fromWallet: bigint;
|
|
230
|
+
fromShareBought: bigint;
|
|
231
|
+
total: bigint;
|
|
232
|
+
|
|
233
|
+
supply: bigint;
|
|
234
|
+
sOut: bigint;
|
|
235
|
+
floorAfterX64: bigint;
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
export function burnedOf(landed: LandedTx, p: { wallet: string } & ReceiptScope): ReceiptBurned[] {
|
|
239
|
+
const out: ReceiptBurned[] = [];
|
|
240
|
+
for (const e of eventsOf(landed, p)) {
|
|
241
|
+
if (!((e.chain === "solana" && e.name === "TokensBurned") || (e.chain === "evm" && e.name === "TokensBurnedV2"))) continue;
|
|
242
|
+
const f = e.fields as { wallet: string; fromTeamBuy: bigint; fromWallet: bigint; fromShareBought: bigint | null; supply: bigint; sOut: bigint; floorAfterX64: bigint };
|
|
243
|
+
if (!same(e.chain, f.wallet, p.wallet)) continue;
|
|
244
|
+
const share = f.fromShareBought ?? 0n;
|
|
245
|
+
out.push({
|
|
246
|
+
launch: launchOf(e), fromTeamBuy: f.fromTeamBuy, fromWallet: f.fromWallet, fromShareBought: share, total: f.fromTeamBuy + f.fromWallet + share,
|
|
247
|
+
supply: f.supply, sOut: f.sOut, floorAfterX64: f.floorAfterX64,
|
|
248
|
+
});
|
|
249
|
+
}
|
|
250
|
+
return out;
|
|
251
|
+
}
|
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
|
|
2
|
+
|
|
3
|
+
import { addressBytes, concatBytes } from "../codec.ts";
|
|
4
|
+
import { coinKey } from "../route/graph.ts";
|
|
5
|
+
import { AccountRole } from "../solana/instruction.ts";
|
|
6
|
+
import type { Instruction } from "../solana/instruction.ts";
|
|
7
|
+
import { ADDRESS_LOOKUP_TABLE_PROGRAM_ID, SYSTEM_PROGRAM_ID, TOKEN_2022_PROGRAM_ID, findProgramAddress } from "../solana/pda.ts";
|
|
8
|
+
import { createAssociatedTokenAccountIdempotentInstruction } from "../solana/tx.ts";
|
|
9
|
+
import { FLOOR_AMM_PROGRAM_ID } from "../solana/floor/program.ts";
|
|
10
|
+
import { ATA_CREATE_CU, routeTradeAccountsV2 } from "./route.ts";
|
|
11
|
+
import type { HopQuoteV2, PoolV2, RouteQuoteV2 } from "./route.ts";
|
|
12
|
+
import { buyFromBalanceInstructionV2, buyInstructionV2, openHolderPositionInstruction, sellFromBalanceInstructionV2, sellInstructionV2 } from "./solana.ts";
|
|
13
|
+
|
|
14
|
+
export const MAX_TABLE_ADDRESSES_V2 = 256;
|
|
15
|
+
|
|
16
|
+
export const MAX_EXTEND_ADDRESSES_V2 = 30;
|
|
17
|
+
|
|
18
|
+
const PROBES = ["kVwEj4fW3BriC9M17tRS88VResDomcntxJAgL1kJmDb", "BvhkBZ5kEP1dxJzfprm8kLk9dSgvT8cLziBFTHZef6r7"] as const;
|
|
19
|
+
|
|
20
|
+
function quoteProgramOf(pool: PoolV2, all: readonly PoolV2[]): string {
|
|
21
|
+
if (pool.quoteTokenProgram) return pool.quoteTokenProgram;
|
|
22
|
+
if (all.some((x) => coinKey(x.token) === coinKey(pool.quote))) return TOKEN_2022_PROGRAM_ID;
|
|
23
|
+
throw new RangeError(`pool ${pool.symbol}: quoteTokenProgram is required`);
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
function hopForms(trader: string, pool: PoolV2, all: readonly PoolV2[], programId: string): Instruction[] {
|
|
27
|
+
const qp = quoteProgramOf(pool, all);
|
|
28
|
+
const a = { ...routeTradeAccountsV2(trader, pool, qp, programId), quoteIsLaunch: pool.quoteIsLaunch ?? all.some((x) => coinKey(x.token) === coinKey(pool.quote)), programId };
|
|
29
|
+
return [
|
|
30
|
+
buyInstructionV2({ ...a, amountIn: 1n, minOut: 1n }),
|
|
31
|
+
buyFromBalanceInstructionV2({ ...a, keep: 0n, minOut: 1n }),
|
|
32
|
+
sellInstructionV2({ ...a, tokensIn: 1n, minOut: 1n }),
|
|
33
|
+
sellFromBalanceInstructionV2({ ...a, keep: 0n, minOut: 1n }),
|
|
34
|
+
openHolderPositionInstruction({ owner: trader, launch: a.launch, ownerBase: a.traderBase, programId }),
|
|
35
|
+
createAssociatedTokenAccountIdempotentInstruction({ payer: trader, owner: trader, mint: pool.token, tokenProgram: TOKEN_2022_PROGRAM_ID }),
|
|
36
|
+
createAssociatedTokenAccountIdempotentInstruction({ payer: trader, owner: trader, mint: pool.quote, tokenProgram: qp }),
|
|
37
|
+
];
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
export function routeTableAddressesV2(pools: readonly PoolV2[], programId = FLOOR_AMM_PROGRAM_ID): string[] {
|
|
41
|
+
if (pools.some((p) => p.chain !== "solana")) throw new RangeError("a lookup table is Solana's");
|
|
42
|
+
const seen = PROBES.map((w) => {
|
|
43
|
+
const ixs = pools.flatMap((p) => hopForms(w, p, pools, programId));
|
|
44
|
+
const invoked = new Set(ixs.map((i) => i.programAddress));
|
|
45
|
+
return { order: ixs.flatMap((i) => i.accounts.map((m) => m.address)), invoked };
|
|
46
|
+
});
|
|
47
|
+
const other = new Set(seen[1].order);
|
|
48
|
+
const out: string[] = [];
|
|
49
|
+
const has = new Set<string>();
|
|
50
|
+
for (const x of seen[0].order) {
|
|
51
|
+
if (has.has(x) || !other.has(x) || seen[0].invoked.has(x) || (PROBES as readonly string[]).includes(x)) continue;
|
|
52
|
+
has.add(x);
|
|
53
|
+
out.push(x);
|
|
54
|
+
}
|
|
55
|
+
return out;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
export function createRouteTableInstructionV2(p: { authority: string; payer: string; recentSlot: bigint }): { instruction: Instruction; table: string } {
|
|
59
|
+
if (p.recentSlot < 0n || p.recentSlot > 0xffff_ffff_ffff_ffffn) throw new RangeError("recentSlot: a u64");
|
|
60
|
+
const slot = new Uint8Array(8);
|
|
61
|
+
new DataView(slot.buffer).setBigUint64(0, p.recentSlot, true);
|
|
62
|
+
const [table, bump] = findProgramAddress([addressBytes(p.authority), slot], ADDRESS_LOOKUP_TABLE_PROGRAM_ID);
|
|
63
|
+
const data = concatBytes(Uint8Array.of(0, 0, 0, 0), slot, Uint8Array.of(bump));
|
|
64
|
+
return {
|
|
65
|
+
table,
|
|
66
|
+
instruction: {
|
|
67
|
+
programAddress: ADDRESS_LOOKUP_TABLE_PROGRAM_ID, data,
|
|
68
|
+
accounts: [
|
|
69
|
+
{ address: table, role: AccountRole.WRITABLE }, { address: p.authority, role: AccountRole.READONLY },
|
|
70
|
+
{ address: p.payer, role: AccountRole.WRITABLE_SIGNER }, { address: SYSTEM_PROGRAM_ID, role: AccountRole.READONLY },
|
|
71
|
+
],
|
|
72
|
+
},
|
|
73
|
+
};
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
export function extendRouteTableInstructionsV2(p: { table: string; authority: string; payer: string; addresses: readonly string[] }): Instruction[] {
|
|
77
|
+
if (p.addresses.length === 0 || p.addresses.length > MAX_TABLE_ADDRESSES_V2) throw new RangeError(`addresses: 1 ..= ${MAX_TABLE_ADDRESSES_V2}`);
|
|
78
|
+
const out: Instruction[] = [];
|
|
79
|
+
for (let i = 0; i < p.addresses.length; i += MAX_EXTEND_ADDRESSES_V2) {
|
|
80
|
+
const chunk = p.addresses.slice(i, i + MAX_EXTEND_ADDRESSES_V2);
|
|
81
|
+
const head = new Uint8Array(12);
|
|
82
|
+
const v = new DataView(head.buffer);
|
|
83
|
+
v.setUint32(0, 2, true);
|
|
84
|
+
v.setBigUint64(4, BigInt(chunk.length), true);
|
|
85
|
+
out.push({
|
|
86
|
+
programAddress: ADDRESS_LOOKUP_TABLE_PROGRAM_ID, data: concatBytes(head, ...chunk.map(addressBytes)),
|
|
87
|
+
accounts: [
|
|
88
|
+
{ address: p.table, role: AccountRole.WRITABLE }, { address: p.authority, role: AccountRole.READONLY_SIGNER },
|
|
89
|
+
{ address: p.payer, role: AccountRole.WRITABLE_SIGNER }, { address: SYSTEM_PROGRAM_ID, role: AccountRole.READONLY },
|
|
90
|
+
],
|
|
91
|
+
});
|
|
92
|
+
}
|
|
93
|
+
return out;
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
export const ROUTE_CU_V2 = Object.freeze({
|
|
97
|
+
buy: Object.freeze([[1, 72_930], [10, 126_041], [24, 229_866]] as const),
|
|
98
|
+
sell: Object.freeze([[1, 68_471], [10, 122_930], [24, 216_856]] as const),
|
|
99
|
+
ata: ATA_CREATE_CU,
|
|
100
|
+
});
|
|
101
|
+
|
|
102
|
+
export function hopComputeUnitsV2(side: "buy" | "sell", crossings: number): number | undefined {
|
|
103
|
+
if (!Number.isInteger(crossings) || crossings < 1) return undefined;
|
|
104
|
+
for (const [n, cu] of ROUTE_CU_V2[side]) if (crossings <= n) return cu;
|
|
105
|
+
return undefined;
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
export function routeComputeUnitsV2<L>(q: RouteQuoteV2<L>, read: (hq: HopQuoteV2<L>, i: number) => { crossings: number } | null): (number | undefined)[] {
|
|
109
|
+
return q.hops.map((hq, i) => {
|
|
110
|
+
if (hq.hop.kind === "edge") return undefined;
|
|
111
|
+
const r = read(hq, i);
|
|
112
|
+
return r === null ? undefined : hopComputeUnitsV2(hq.hop.kind, r.crossings);
|
|
113
|
+
});
|
|
114
|
+
}
|