@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
package/src/v2/claims.ts
ADDED
|
@@ -0,0 +1,288 @@
|
|
|
1
|
+
|
|
2
|
+
|
|
3
|
+
import { addressBytes, base58Encode } from "../codec.ts";
|
|
4
|
+
import { computeUnitLimitInstruction, computeUnitPriceInstruction } from "../solana/instruction.ts";
|
|
5
|
+
import type { Instruction } from "../solana/instruction.ts";
|
|
6
|
+
import { PACKET_DATA_SIZE, compileV0Message, transactionSize } from "../solana/tx.ts";
|
|
7
|
+
import type { LookupTable } from "../solana/tx.ts";
|
|
8
|
+
import { decodeTeamSlot } from "../solana/floor/accounts.ts";
|
|
9
|
+
import { CLAIM_CREATOR, CLAIM_CREATOR_REF, CLAIM_SHARE_BOUGHT, CLAIM_TEAM_BUY, CLAIM_TEAM_SLOT, CLAIM_TRADER_REF } from "../solana/floor/instructions.ts";
|
|
10
|
+
import { FLOOR_AMM_PROGRAM_ID, configPda, refOwedPda, refOwedVault } from "../solana/floor/program.ts";
|
|
11
|
+
import { TOKEN_2022_PROGRAM_ID, TOKEN_PROGRAM_ID, WSOL_MINT, associatedTokenAddress } from "../solana/pda.ts";
|
|
12
|
+
import { CREATOR_BUY_LOCK_SECS, MAX_MEMBERS, splitTeamBuyV2 } from "../math/v2/team.ts";
|
|
13
|
+
import { holderSync, holderTake } from "../math/v2/holders.ts";
|
|
14
|
+
import { FloorMathError } from "../math/index.ts";
|
|
15
|
+
import { decodeHolderBook, decodeHolderPosition, decodeLaunchV2 } from "./layouts.ts";
|
|
16
|
+
import { CLAIM_HOLDER, claimInstructionV2 } from "./solana.ts";
|
|
17
|
+
import type { ClaimLaunchV2, Ctx } from "./solana.ts";
|
|
18
|
+
|
|
19
|
+
export const MAX_TX_ACCOUNT_LOCKS_V2 = 64;
|
|
20
|
+
|
|
21
|
+
export const CLAIM_COMPUTE_UNIT_LIMIT_V2 = 1_400_000;
|
|
22
|
+
|
|
23
|
+
const MEMBER_IN = 2;
|
|
24
|
+
const KIND_WALLET = 0;
|
|
25
|
+
|
|
26
|
+
export function teamBuyDueV2(createdAt: bigint, now: bigint): boolean {
|
|
27
|
+
const c = createdAt < 0n ? 0n : createdAt;
|
|
28
|
+
const due = c + CREATOR_BUY_LOCK_SECS > 0xffff_ffff_ffff_ffffn ? 0xffff_ffff_ffff_ffffn : c + CREATOR_BUY_LOCK_SECS;
|
|
29
|
+
return now >= due;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
export function holderOwedNowV2(p: { positionData: Uint8Array | null; bookData: Uint8Array; balance: bigint }): bigint {
|
|
33
|
+
if (!p.positionData) return 0n;
|
|
34
|
+
const pos = decodeHolderPosition(p.positionData) as any;
|
|
35
|
+
const book = decodeHolderBook(p.bookData) as any;
|
|
36
|
+
if (pos.launch !== book.launch) throw new RangeError("this HolderPosition is not the book's launch");
|
|
37
|
+
const b = { index: book.index as bigint, w: book.w as bigint, carry: book.carry as bigint, bookedTotal: book.bookedTotal as bigint, paidTotal: book.paidTotal as bigint };
|
|
38
|
+
const q = { amount: pos.amount as bigint, owed: pos.owed as bigint, indexSnap: pos.indexSnap as bigint, optedOut: false };
|
|
39
|
+
holderSync(b, q, p.balance);
|
|
40
|
+
return holderTake(b, q);
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
export interface OwedV2 {
|
|
44
|
+
|
|
45
|
+
creator: bigint;
|
|
46
|
+
|
|
47
|
+
creatorRef: bigint;
|
|
48
|
+
|
|
49
|
+
teamSlot: bigint;
|
|
50
|
+
|
|
51
|
+
teamBuy: bigint;
|
|
52
|
+
|
|
53
|
+
shareBought: bigint;
|
|
54
|
+
|
|
55
|
+
holder: bigint;
|
|
56
|
+
}
|
|
57
|
+
export interface LaunchOwedV2 {
|
|
58
|
+
launch: string;
|
|
59
|
+
quoteMint: string;
|
|
60
|
+
quoteTokenProgram: string;
|
|
61
|
+
quoteVault: string;
|
|
62
|
+
baseMint: string;
|
|
63
|
+
tokenVault: string;
|
|
64
|
+
teamSlot: string | null;
|
|
65
|
+
owed: OwedV2;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
export const claimBitsV2 = (o: OwedV2): number =>
|
|
69
|
+
(o.creator > 0n ? CLAIM_CREATOR : 0) | (o.creatorRef > 0n ? CLAIM_CREATOR_REF : 0) | (o.teamSlot > 0n ? CLAIM_TEAM_SLOT : 0) |
|
|
70
|
+
(o.teamBuy > 0n ? CLAIM_TEAM_BUY : 0) | (o.shareBought > 0n ? CLAIM_SHARE_BOUGHT : 0) | (o.holder > 0n ? CLAIM_HOLDER : 0);
|
|
71
|
+
const quoteOf = (o: OwedV2): bigint => o.creator + o.creatorRef + o.teamSlot + o.holder;
|
|
72
|
+
|
|
73
|
+
export function launchOwedV2(p: {
|
|
74
|
+
wallet: string; launch: string; launchData: Uint8Array; teamSlot?: { address: string; data: Uint8Array } | null; now: bigint; holderOwed?: bigint;
|
|
75
|
+
}): LaunchOwedV2 {
|
|
76
|
+
const a = decodeLaunchV2(p.launchData);
|
|
77
|
+
const owed: OwedV2 = { creator: 0n, creatorRef: 0n, teamSlot: 0n, teamBuy: 0n, shareBought: 0n, holder: p.holderOwed ?? 0n };
|
|
78
|
+
const places: boolean[] = Array(MAX_MEMBERS).fill(false);
|
|
79
|
+
if (a.creator === p.wallet) {
|
|
80
|
+
owed.creator = a.creatorOwed;
|
|
81
|
+
places[0] = true;
|
|
82
|
+
}
|
|
83
|
+
(a.creatorRef as string[]).forEach((r, i) => {
|
|
84
|
+
if (r === p.wallet) owed.creatorRef += a.creatorRefOwed[i];
|
|
85
|
+
});
|
|
86
|
+
if (p.teamSlot) {
|
|
87
|
+
const t = decodeTeamSlot(p.teamSlot.data);
|
|
88
|
+
if (t.launch !== p.launch) throw new RangeError("this TeamSlot is not the launch's");
|
|
89
|
+
const k = addressBytes(p.wallet);
|
|
90
|
+
const i = (t.members as any[]).findIndex((m) => m.state === MEMBER_IN && m.kind === KIND_WALLET && (m.key as Uint8Array).every((x, j) => x === k[j]));
|
|
91
|
+
if (i >= 0) {
|
|
92
|
+
owed.teamSlot = a.slotOwed[i];
|
|
93
|
+
places[i] = true;
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
const createdAt = a.createdAt < 0n ? 0n : (a.createdAt as bigint);
|
|
97
|
+
let buy: bigint[] = a.teamBuyOwed.slice();
|
|
98
|
+
const due = teamBuyDueV2(a.createdAt, p.now);
|
|
99
|
+
if (a.creatorLocked > 0n) {
|
|
100
|
+
try {
|
|
101
|
+
const split = splitTeamBuyV2(a.creatorLocked, a.slotWeightPpb, createdAt, p.now);
|
|
102
|
+
buy = buy.map((x, i) => x + split[i]);
|
|
103
|
+
} catch (e) {
|
|
104
|
+
if (!(e instanceof FloorMathError && e.code === "NotDue")) throw e;
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
for (let i = 0; i < MAX_MEMBERS; i++) {
|
|
108
|
+
if (!places[i]) continue;
|
|
109
|
+
if (due) owed.teamBuy += buy[i];
|
|
110
|
+
owed.shareBought += a.slotBoughtOwed[i];
|
|
111
|
+
}
|
|
112
|
+
return {
|
|
113
|
+
launch: p.launch, quoteMint: a.quoteMint, quoteTokenProgram: a.quoteTokenProgram, quoteVault: a.quoteVault, baseMint: a.baseMint,
|
|
114
|
+
tokenVault: a.tokenVault, teamSlot: p.teamSlot?.address ?? null, owed,
|
|
115
|
+
};
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
export interface ClaimTxV2 {
|
|
119
|
+
quoteMint: string;
|
|
120
|
+
instructions: Instruction[];
|
|
121
|
+
message: Uint8Array;
|
|
122
|
+
size: number;
|
|
123
|
+
locks: number;
|
|
124
|
+
launches: string[];
|
|
125
|
+
|
|
126
|
+
refOwed: boolean;
|
|
127
|
+
types: number;
|
|
128
|
+
|
|
129
|
+
unwrap: boolean;
|
|
130
|
+
|
|
131
|
+
amount: bigint;
|
|
132
|
+
|
|
133
|
+
tokens: bigint;
|
|
134
|
+
}
|
|
135
|
+
export interface ClaimPlanV2 {
|
|
136
|
+
transactions: ClaimTxV2[];
|
|
137
|
+
|
|
138
|
+
skipped: string[];
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
function locksOf(payer: string, ixs: Instruction[]): number {
|
|
142
|
+
const s = new Set<string>([payer]);
|
|
143
|
+
for (const ix of ixs) {
|
|
144
|
+
s.add(ix.programAddress);
|
|
145
|
+
for (const a of ix.accounts) s.add(a.address);
|
|
146
|
+
}
|
|
147
|
+
return s.size;
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
export function planClaimAllV2(p: {
|
|
151
|
+
wallet: string;
|
|
152
|
+
sender?: string;
|
|
153
|
+
launches: readonly LaunchOwedV2[];
|
|
154
|
+
|
|
155
|
+
refOwed?: readonly { quoteMint: string; quoteTokenProgram?: string; owed: bigint }[];
|
|
156
|
+
recentBlockhash: string;
|
|
157
|
+
lookupTables?: LookupTable[];
|
|
158
|
+
microLamports?: bigint;
|
|
159
|
+
computeUnitLimit?: number;
|
|
160
|
+
|
|
161
|
+
unwrapSol?: boolean;
|
|
162
|
+
|
|
163
|
+
launchQuotes?: readonly string[];
|
|
164
|
+
} & Ctx): ClaimPlanV2 {
|
|
165
|
+
const sender = p.sender ?? p.wallet;
|
|
166
|
+
const skipped: string[] = [];
|
|
167
|
+
type Group = { tp: string; classes: Map<number, LaunchOwedV2[]>; refs: bigint };
|
|
168
|
+
const byQuote = new Map<string, Group>();
|
|
169
|
+
const group = (q: string, tp: string): Group => {
|
|
170
|
+
let g = byQuote.get(q);
|
|
171
|
+
if (!g) byQuote.set(q, (g = { tp, classes: new Map(), refs: 0n }));
|
|
172
|
+
return g;
|
|
173
|
+
};
|
|
174
|
+
const classOf = (o: OwedV2): number => (o.teamBuy > 0n || o.shareBought > 0n ? 1 : 0) | (o.holder > 0n ? 2 : 0);
|
|
175
|
+
for (const l of p.launches) {
|
|
176
|
+
if (claimBitsV2(l.owed) === 0) {
|
|
177
|
+
skipped.push(l.launch);
|
|
178
|
+
continue;
|
|
179
|
+
}
|
|
180
|
+
const g = group(l.quoteMint, l.quoteTokenProgram);
|
|
181
|
+
const c = classOf(l.owed);
|
|
182
|
+
if (!g.classes.has(c)) g.classes.set(c, []);
|
|
183
|
+
g.classes.get(c)!.push(l);
|
|
184
|
+
}
|
|
185
|
+
for (const r of p.refOwed ?? []) {
|
|
186
|
+
if (r.owed === 0n) {
|
|
187
|
+
skipped.push(`ref_owed:${r.quoteMint}`);
|
|
188
|
+
continue;
|
|
189
|
+
}
|
|
190
|
+
const known = byQuote.get(r.quoteMint);
|
|
191
|
+
if (!known && !r.quoteTokenProgram) throw new RangeError(`the RefOwed in ${r.quoteMint} needs its quote's token program`);
|
|
192
|
+
group(r.quoteMint, known?.tp ?? r.quoteTokenProgram!).refs = r.owed;
|
|
193
|
+
}
|
|
194
|
+
const pid = p.programId ?? FLOOR_AMM_PROGRAM_ID;
|
|
195
|
+
const budget = (): Instruction[] => [computeUnitLimitInstruction(p.computeUnitLimit ?? CLAIM_COMPUTE_UNIT_LIMIT_V2), ...(p.microLamports !== undefined ? [computeUnitPriceInstruction(p.microLamports)] : [])];
|
|
196
|
+
const fits = (t: ClaimTxV2): boolean => t.size <= PACKET_DATA_SIZE && t.locks <= MAX_TX_ACCOUNT_LOCKS_V2;
|
|
197
|
+
const txs: ClaimTxV2[] = [];
|
|
198
|
+
for (const [quoteMint, g] of byQuote) {
|
|
199
|
+
const unwrap = (p.unwrapSol ?? true) && quoteMint === WSOL_MINT && g.tp === TOKEN_PROGRAM_ID;
|
|
200
|
+
const build = (ls: LaunchOwedV2[], refs: bigint): ClaimTxV2 => {
|
|
201
|
+
const types = ls.reduce((a, l) => a | claimBitsV2(l.owed), 0) | (refs > 0n ? CLAIM_TRADER_REF : 0);
|
|
202
|
+
const tok = (types & (CLAIM_TEAM_BUY | CLAIM_SHARE_BOUGHT)) !== 0;
|
|
203
|
+
const ro = refOwedPda(p.wallet, quoteMint, pid)[0];
|
|
204
|
+
const claim = claimInstructionV2({
|
|
205
|
+
sender, wallet: p.wallet, quoteMint, quoteTokenProgram: g.tp, destination: associatedTokenAddress(p.wallet, quoteMint, g.tp),
|
|
206
|
+
config: configPda(pid)[0], refOwed: refs > 0n ? ro : null, refOwedVault: refs > 0n ? refOwedVault(ro, quoteMint, g.tp) : null, types,
|
|
207
|
+
launches: ls.map((l): ClaimLaunchV2 => ({
|
|
208
|
+
launch: l.launch, quoteVault: l.quoteVault, teamSlot: l.teamSlot, baseMint: l.baseMint,
|
|
209
|
+
...(tok ? { teamBuy: { baseMint: l.baseMint, tokenVault: l.tokenVault, walletBase: associatedTokenAddress(p.wallet, l.baseMint, TOKEN_2022_PROGRAM_ID) } } : {}),
|
|
210
|
+
})),
|
|
211
|
+
unwrap, quoteIsLaunch: p.launchQuotes?.includes(quoteMint) ?? false, programId: p.programId, hookProgramId: p.hookProgramId,
|
|
212
|
+
});
|
|
213
|
+
const instructions = [...budget(), claim];
|
|
214
|
+
const message = compileV0Message({ payer: sender, instructions, recentBlockhash: p.recentBlockhash, lookupTables: p.lookupTables });
|
|
215
|
+
return {
|
|
216
|
+
quoteMint, instructions, message, size: transactionSize(message), locks: locksOf(sender, instructions), launches: ls.map((l) => l.launch),
|
|
217
|
+
refOwed: refs > 0n, types, unwrap, amount: ls.reduce((a, l) => a + quoteOf(l.owed), 0n) + refs, tokens: ls.reduce((a, l) => a + l.owed.teamBuy + l.owed.shareBought, 0n),
|
|
218
|
+
};
|
|
219
|
+
};
|
|
220
|
+
const alone = (ls: LaunchOwedV2[], refs: bigint, what: string): ClaimTxV2 => {
|
|
221
|
+
const t = build(ls, refs);
|
|
222
|
+
if (!fits(t)) throw new RangeError(`${what} alone does not fit one transaction`);
|
|
223
|
+
return t;
|
|
224
|
+
};
|
|
225
|
+
let refs = g.refs;
|
|
226
|
+
for (const c of [...g.classes.keys()].sort()) {
|
|
227
|
+
let cur: LaunchOwedV2[] = [];
|
|
228
|
+
let last: ClaimTxV2 | null = null;
|
|
229
|
+
for (const l of g.classes.get(c)!) {
|
|
230
|
+
const t = build([...cur, l], refs);
|
|
231
|
+
if (fits(t)) {
|
|
232
|
+
cur.push(l);
|
|
233
|
+
last = t;
|
|
234
|
+
continue;
|
|
235
|
+
}
|
|
236
|
+
if (cur.length === 0 && refs > 0n) {
|
|
237
|
+
|
|
238
|
+
txs.push(alone([], refs, "the referral claim"));
|
|
239
|
+
refs = 0n;
|
|
240
|
+
} else if (cur.length === 0) throw new RangeError(`launch ${l.launch} alone does not fit one transaction`);
|
|
241
|
+
else {
|
|
242
|
+
txs.push(last!);
|
|
243
|
+
refs = 0n;
|
|
244
|
+
}
|
|
245
|
+
cur = [l];
|
|
246
|
+
last = alone(cur, 0n, `launch ${l.launch}`);
|
|
247
|
+
}
|
|
248
|
+
if (last) {
|
|
249
|
+
txs.push(last);
|
|
250
|
+
refs = 0n;
|
|
251
|
+
}
|
|
252
|
+
}
|
|
253
|
+
if (refs > 0n) txs.push(alone([], refs, "the referral claim"));
|
|
254
|
+
}
|
|
255
|
+
return { transactions: txs, skipped };
|
|
256
|
+
}
|
|
257
|
+
|
|
258
|
+
export interface ClaimLaunchesPerTxV2 {
|
|
259
|
+
|
|
260
|
+
plain: number;
|
|
261
|
+
|
|
262
|
+
tokens: number;
|
|
263
|
+
|
|
264
|
+
holder: number;
|
|
265
|
+
|
|
266
|
+
both: number;
|
|
267
|
+
}
|
|
268
|
+
|
|
269
|
+
export function claimLaunchesPerTxV2(p: { quoteMint?: string; quoteTokenProgram?: string; lookupTables?: LookupTable[]; microLamports?: bigint } & Ctx = {}): ClaimLaunchesPerTxV2 {
|
|
270
|
+
const key = (i: number): string => {
|
|
271
|
+
const b = new Uint8Array(32);
|
|
272
|
+
b[0] = 0xf1;
|
|
273
|
+
b[1] = i & 0xff;
|
|
274
|
+
b[2] = i >> 8;
|
|
275
|
+
return base58Encode(b);
|
|
276
|
+
};
|
|
277
|
+
const quoteMint = p.quoteMint ?? key(0xfff0);
|
|
278
|
+
const quoteTokenProgram = p.quoteTokenProgram ?? TOKEN_PROGRAM_ID;
|
|
279
|
+
const measure = (o: Partial<OwedV2>): number => {
|
|
280
|
+
const launches = Array.from({ length: 64 }, (_, i): LaunchOwedV2 => ({
|
|
281
|
+
launch: key(i), quoteMint, quoteTokenProgram, quoteVault: key(0x100 + i), baseMint: key(0x200 + i), tokenVault: key(0x300 + i), teamSlot: key(0x400 + i),
|
|
282
|
+
owed: { creator: 0n, creatorRef: 0n, teamSlot: 0n, teamBuy: 0n, shareBought: 0n, holder: 0n, ...o },
|
|
283
|
+
}));
|
|
284
|
+
const plan = planClaimAllV2({ wallet: key(0xfff1), launches, recentBlockhash: key(0xfff2), lookupTables: p.lookupTables, microLamports: p.microLamports, programId: p.programId, hookProgramId: p.hookProgramId });
|
|
285
|
+
return plan.transactions[0].launches.length;
|
|
286
|
+
};
|
|
287
|
+
return { plain: measure({ creator: 1n, teamSlot: 1n }), tokens: measure({ creator: 1n, teamBuy: 1n }), holder: measure({ holder: 1n }), both: measure({ teamBuy: 1n, holder: 1n }) };
|
|
288
|
+
}
|
package/src/v2/dead.ts
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
|
|
2
|
+
|
|
3
|
+
export const SOLANA_DEAD_OWNERS: readonly string[] = [
|
|
4
|
+
"1nc1nerator11111111111111111111111111111111",
|
|
5
|
+
"11111111111111111111111111111111",
|
|
6
|
+
];
|
|
7
|
+
|
|
8
|
+
export const EVM_DEAD_ADDRESSES: readonly string[] = [
|
|
9
|
+
"0x0000000000000000000000000000000000000000",
|
|
10
|
+
"0x000000000000000000000000000000000000dead",
|
|
11
|
+
"0x0000000000000000000000000000000000000001",
|
|
12
|
+
"0xdead000000000000000042069420694206942069",
|
|
13
|
+
];
|
|
14
|
+
|
|
15
|
+
export function isSolanaDeadOwner(owner: string): boolean {
|
|
16
|
+
return SOLANA_DEAD_OWNERS.includes(owner);
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export function isEvmDead(address: string): boolean {
|
|
20
|
+
return EVM_DEAD_ADDRESSES.includes(address.toLowerCase());
|
|
21
|
+
}
|
package/src/v2/devbuy.ts
ADDED
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
|
|
2
|
+
|
|
3
|
+
import { base58Encode } from "../codec.ts";
|
|
4
|
+
import { SLOT_ACTIVE } from "../solana/floor/accounts.ts";
|
|
5
|
+
import { TEAM_SLOT_WALLET } from "../solana/floor/instructions.ts";
|
|
6
|
+
import { priceX64 } from "../math/v2/sqrt.ts";
|
|
7
|
+
import { TRADE_KIND_TEAM_BUY, TRADE_KIND_TEAM_SHARE_BUY } from "./events.ts";
|
|
8
|
+
import type { TradeEventV2 } from "./types.ts";
|
|
9
|
+
|
|
10
|
+
export type DevBuyRole = "creator" | "team_member" | "team_share_buy" | "team_buy";
|
|
11
|
+
|
|
12
|
+
export interface DevBuy {
|
|
13
|
+
launch: string;
|
|
14
|
+
trader: string;
|
|
15
|
+
role: DevBuyRole;
|
|
16
|
+
|
|
17
|
+
quoteIn: bigint;
|
|
18
|
+
|
|
19
|
+
tokens: bigint;
|
|
20
|
+
|
|
21
|
+
priceBeforeX64: bigint;
|
|
22
|
+
priceAfterX64: bigint;
|
|
23
|
+
|
|
24
|
+
impactBps: bigint;
|
|
25
|
+
slot: bigint;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
export interface DevTeam {
|
|
29
|
+
creator: string;
|
|
30
|
+
teamSlot?: { members: { key: Uint8Array; kind: number; state: number }[] } | null;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
export function teamSlotWallets(slot: DevTeam["teamSlot"]): string[] {
|
|
34
|
+
return (slot?.members ?? []).filter((m) => m.kind === TEAM_SLOT_WALLET && m.state === SLOT_ACTIVE).map((m) => base58Encode(m.key));
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
export const impactBps = (before: bigint, after: bigint): bigint => (before === 0n ? 0n : ((after - before) * 10_000n) / before);
|
|
38
|
+
|
|
39
|
+
export function devBuyFromTrade(t: TradeEventV2, team: DevTeam, ctx: { teamBuy?: boolean; teamShareBuy?: boolean } = {}): DevBuy | null {
|
|
40
|
+
if (!t.isBuy) return null;
|
|
41
|
+
let role: DevBuyRole | null = null;
|
|
42
|
+
if (t.kind === TRADE_KIND_TEAM_BUY || ctx.teamBuy) role = "team_buy";
|
|
43
|
+
else if (t.kind === TRADE_KIND_TEAM_SHARE_BUY || ctx.teamShareBuy) role = "team_share_buy";
|
|
44
|
+
else if (t.trader === team.creator) role = "creator";
|
|
45
|
+
else if (teamSlotWallets(team.teamSlot).includes(t.trader)) role = "team_member";
|
|
46
|
+
if (role === null) return null;
|
|
47
|
+
const priceBeforeX64 = priceX64(t.sqrtBefore);
|
|
48
|
+
const priceAfterX64 = priceX64(t.sqrtAfter);
|
|
49
|
+
return {
|
|
50
|
+
launch: t.launch, trader: t.trader, role, quoteIn: t.quoteGross - t.refund, tokens: t.tokens, priceBeforeX64, priceAfterX64,
|
|
51
|
+
impactBps: impactBps(priceBeforeX64, priceAfterX64), slot: t.slot,
|
|
52
|
+
};
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
export const devBuyChangeSinceBps = (d: DevBuy, sqrtNow: bigint): bigint => impactBps(d.priceAfterX64, priceX64(sqrtNow));
|
package/src/v2/events.ts
ADDED
|
@@ -0,0 +1,131 @@
|
|
|
1
|
+
|
|
2
|
+
|
|
3
|
+
import { hex } from "../codec.ts";
|
|
4
|
+
import { EVENT_IX_TAG_LE, eventDiscriminator } from "../solana/instruction.ts";
|
|
5
|
+
import { Reader, Writer } from "../solana/floor/borsh.ts";
|
|
6
|
+
|
|
7
|
+
type F = "pubkey" | "bool" | "u8" | "u32" | "u64" | "i64" | "u128" | "u64[4]" | "u64[5]" | "bytes:10" | "bytes:32";
|
|
8
|
+
const S = (...f: [string, F][]): [string, F][] => f;
|
|
9
|
+
|
|
10
|
+
export const EVENTS_V2: Record<string, [string, F][]> = {
|
|
11
|
+
|
|
12
|
+
LaunchCreatedV2: S(["launch", "pubkey"], ["mint", "pubkey"], ["quoteMint", "pubkey"], ["creator", "pubkey"], ["id", "u64"], ["presetId", "u8"], ["presetVersion", "u32"], ["presetHash", "bytes:32"],
|
|
13
|
+
["p0X64", "u128"], ["raise", "u64"], ["windowTokens", "u64"], ["creatorBuyTokens", "u64"], ["createFee", "u64"], ["name", "bytes:32"], ["symbol", "bytes:10"], ["slot", "u64"], ["ts", "i64"],
|
|
14
|
+
["listed", "bool"], ["quoteUsdCentsX64", "u128"], ["nativeCreateFee", "u64"], ["rowVersion", "u8"], ["sqrtP0", "u128"]),
|
|
15
|
+
Trade: S(["launch", "pubkey"], ["trader", "pubkey"], ["isBuy", "bool"], ["quoteGross", "u64"], ["quoteNet", "u64"], ["refund", "u64"], ["tokens", "u64"], ["fees", "u64[5]"], ["traderRef", "u64"], ["fromResale", "u64"], ["fromFirst", "u64"], ["unfilled", "u64"], ["sqrtBefore", "u128"], ["sqrtAfter", "u128"], ["sqrtF", "u128"], ["floor", "u64"], ["cushion", "u64"], ["sCirc", "u64"], ["steps", "u8"], ["budgetHit", "bool"], ["slot", "u64"], ["ts", "i64"],
|
|
16
|
+
|
|
17
|
+
["kind", "u8"],
|
|
18
|
+
|
|
19
|
+
["creatorRef", "u64"],
|
|
20
|
+
|
|
21
|
+
["recipient", "pubkey"],
|
|
22
|
+
|
|
23
|
+
["bidMoney", "u64"], ["msPaid", "u64[4]"]),
|
|
24
|
+
HolderPositionOpened: S(["launch", "pubkey"], ["owner", "pubkey"], ["amount", "u64"]),
|
|
25
|
+
HolderPositionClosed: S(["launch", "pubkey"], ["owner", "pubkey"], ["amount", "u64"], ["paid", "u64"]),
|
|
26
|
+
HolderIndexRolled: S(["launch", "pubkey"], ["index", "u128"], ["wMatured", "u64"], ["wPending", "u64"], ["carry", "u64"]),
|
|
27
|
+
DeadSynced: S(["launch", "pubkey"], ["added", "u64"], ["deadTokens", "u64"], ["sCirc", "u64"]),
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
EVENTS_V2.GenesisRaiseBought = EVENTS_V2.Trade;
|
|
31
|
+
|
|
32
|
+
export const TRADE_KIND_ORDINARY = 0;
|
|
33
|
+
export const TRADE_KIND_TEAM_BUY = 1;
|
|
34
|
+
export const TRADE_KIND_TEAM_SHARE_BUY = 2;
|
|
35
|
+
export const TRADE_KIND_GENESIS_RAISE = 3;
|
|
36
|
+
export const TRADE_KIND_GENESIS_SHARE = 4;
|
|
37
|
+
export const TRADE_KIND_GENESIS_OVERFLOW = 5;
|
|
38
|
+
export const TRADE_KIND_GENESIS_OVERFLOW_SHARE = 6;
|
|
39
|
+
|
|
40
|
+
export const isPersonTradeV2 = (kind: number | undefined): boolean => kind !== TRADE_KIND_GENESIS_RAISE && kind !== TRADE_KIND_GENESIS_OVERFLOW;
|
|
41
|
+
|
|
42
|
+
export const movesBookV2 = (kind: number | undefined): boolean => kind !== TRADE_KIND_GENESIS_SHARE && kind !== TRADE_KIND_GENESIS_OVERFLOW_SHARE;
|
|
43
|
+
|
|
44
|
+
export const FEE_LEGS_V2 = ["backing", "team", "platform", "floor", "holder"] as const;
|
|
45
|
+
export const MS_CLASSES_V2 = ["team", "holder", "platform", "floor"] as const;
|
|
46
|
+
|
|
47
|
+
let disc: Map<string, string> | undefined;
|
|
48
|
+
|
|
49
|
+
const PRE_CUTOVER: [string, string][] = [["TradeV2", "Trade"]];
|
|
50
|
+
const DISC = (): Map<string, string> =>
|
|
51
|
+
(disc ??= new Map([...Object.keys(EVENTS_V2).map((n): [string, string] => [hex(eventDiscriminator(n)), n]), ...PRE_CUTOVER.map(([a, n]): [string, string] => [hex(eventDiscriminator(a)), n])]));
|
|
52
|
+
|
|
53
|
+
function read(r: Reader, t: F): unknown {
|
|
54
|
+
const bm = /^bytes:(\d+)$/.exec(t);
|
|
55
|
+
if (bm) return r.bytes(Number(bm[1]));
|
|
56
|
+
const m = /^u64\[(\d)\]$/.exec(t);
|
|
57
|
+
if (m) return Array.from({ length: Number(m[1]) }, () => r.u64());
|
|
58
|
+
return (r as any)[t]();
|
|
59
|
+
}
|
|
60
|
+
function write(w: Writer, t: F, v: any): void {
|
|
61
|
+
const bm = /^bytes:(\d+)$/.exec(t);
|
|
62
|
+
if (bm) {
|
|
63
|
+
if (v.length !== Number(bm[1])) throw new RangeError(`${t}: ${v.length} bytes`);
|
|
64
|
+
w.bytes(v);
|
|
65
|
+
return;
|
|
66
|
+
}
|
|
67
|
+
const m = /^u64\[(\d)\]$/.exec(t);
|
|
68
|
+
if (m) {
|
|
69
|
+
if (v.length !== Number(m[1])) throw new RangeError(`${t}: ${v.length} values`);
|
|
70
|
+
for (const x of v) w.u64(x);
|
|
71
|
+
} else if (t === "i64") w.uint(BigInt.asUintN(64, v), 8);
|
|
72
|
+
else (w as any)[t](v);
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
export interface FloorEventV2 {
|
|
76
|
+
name: string;
|
|
77
|
+
fields: Record<string, any>;
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
export function decodeEventDataV2(data: Uint8Array): FloorEventV2 | null {
|
|
81
|
+
const name = DISC().get(hex(data.slice(0, 8)));
|
|
82
|
+
if (!name) return null;
|
|
83
|
+
const r = new Reader(data.slice(8));
|
|
84
|
+
const fields: Record<string, any> = {};
|
|
85
|
+
for (const [f, t] of EVENTS_V2[name]) fields[f] = read(r, t);
|
|
86
|
+
if (r.o !== r.b.length) throw new RangeError(`${name}: ${r.b.length} body bytes, the schema reads ${r.o}`);
|
|
87
|
+
return { name, fields };
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
export function encodeEventDataV2(e: FloorEventV2): Uint8Array {
|
|
91
|
+
const w = new Writer().bytes(eventDiscriminator(e.name));
|
|
92
|
+
for (const [f, t] of EVENTS_V2[e.name] ?? []) write(w, t, e.fields[f]);
|
|
93
|
+
return w.done();
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
export function decodeEventCpiV2(ixData: Uint8Array): FloorEventV2 | null {
|
|
97
|
+
if (ixData.length < 16 || hex(ixData.slice(0, 8)) !== hex(EVENT_IX_TAG_LE)) return null;
|
|
98
|
+
return decodeEventDataV2(ixData.slice(8));
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
export interface PlatformWithdrawalV2 {
|
|
102
|
+
launch: string;
|
|
103
|
+
platform: bigint;
|
|
104
|
+
cut: bigint;
|
|
105
|
+
|
|
106
|
+
paid: bigint;
|
|
107
|
+
platformOwedAfter: bigint;
|
|
108
|
+
cutOwedAfter: bigint;
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
export function platformWithdrawalsV2(events: readonly { name: string; fields: Record<string, any> }[]): PlatformWithdrawalV2[] {
|
|
112
|
+
const by = new Map<string, PlatformWithdrawalV2>();
|
|
113
|
+
const row = (launch: string) => {
|
|
114
|
+
let r = by.get(launch);
|
|
115
|
+
if (!r) by.set(launch, (r = { launch, platform: 0n, cut: 0n, paid: 0n, platformOwedAfter: 0n, cutOwedAfter: 0n }));
|
|
116
|
+
return r;
|
|
117
|
+
};
|
|
118
|
+
for (const e of events) {
|
|
119
|
+
if (e.name === "PlatformWithdrawn") {
|
|
120
|
+
const r = row(e.fields.launch);
|
|
121
|
+
r.platform += e.fields.amount;
|
|
122
|
+
r.platformOwedAfter = e.fields.owedAfter;
|
|
123
|
+
} else if (e.name === "CutWithdrawn") {
|
|
124
|
+
const r = row(e.fields.launch);
|
|
125
|
+
r.cut += e.fields.amount;
|
|
126
|
+
r.cutOwedAfter = e.fields.cutOwedAfter;
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
for (const r of by.values()) r.paid = r.platform + r.cut;
|
|
130
|
+
return [...by.values()];
|
|
131
|
+
}
|