@floorlaunchpad/sdk 0.1.1 → 0.3.0
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 +84 -0
- package/LICENSE +201 -60
- package/README.md +45 -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 +128 -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 +746 -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 +144 -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/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 +91 -7
- package/dist/indexer/bodies.js +473 -0
- package/dist/indexer/client.js +104 -0
- package/dist/indexer/contract.js +349 -0
- package/dist/indexer/decode.js +97 -0
- package/dist/indexer/partners.js +100 -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 +390 -0
- package/dist/solana/floor/borsh.js +66 -0
- package/dist/solana/floor/create.js +65 -0
- package/dist/solana/floor/events.js +140 -0
- package/dist/solana/floor/genesis.js +91 -0
- package/dist/solana/floor/genesisList.js +68 -0
- package/dist/solana/floor/instructions.js +435 -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/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/frontend.md +29 -0
- package/docs/wallet.md +54 -0
- package/package.json +428 -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 +138 -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 +746 -0
- package/src/config/index.ts +91 -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 +831 -0
- package/src/evm/abi.ts +292 -0
- package/src/evm/balances.ts +26 -0
- package/src/evm/chains.ts +167 -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/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 +91 -6
- package/src/indexer/bodies.ts +528 -0
- package/src/indexer/client.ts +178 -0
- package/src/indexer/contract.ts +410 -0
- package/src/indexer/decode.ts +109 -0
- package/src/indexer/partners.ts +109 -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 +393 -0
- package/src/solana/floor/borsh.ts +66 -0
- package/src/solana/floor/create.ts +89 -0
- package/src/solana/floor/events.ts +147 -0
- package/src/solana/floor/genesis.ts +111 -0
- package/src/solana/floor/genesisList.ts +75 -0
- package/src/solana/floor/instructions.ts +491 -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/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/evm.ts
ADDED
|
@@ -0,0 +1,349 @@
|
|
|
1
|
+
|
|
2
|
+
|
|
3
|
+
import { decodeAbi, encodeAbi, encodeCall, eventTopic, functionSelector, hexToBytes, bytesToHex } from "../evm/abi.ts";
|
|
4
|
+
import { keccak256 } from "../evm/keccak.ts";
|
|
5
|
+
import type { AbiValue } from "../evm/abi.ts";
|
|
6
|
+
import { claimCall } from "../evm/floor/calls.ts";
|
|
7
|
+
import type { EvmCall } from "../evm/floor/calls.ts";
|
|
8
|
+
import { BIDS_MAX, RANGES_MAX, cloneBook, emptyRange } from "../math/v2/book.ts";
|
|
9
|
+
import type { Book, Range } from "../math/v2/book.ts";
|
|
10
|
+
import { buy } from "../math/v2/trade.ts";
|
|
11
|
+
import type { BookBuy } from "../math/v2/trade.ts";
|
|
12
|
+
import type { SplitRow } from "../math/v2/split.ts";
|
|
13
|
+
import type { Supply } from "../math/v2/supply.ts";
|
|
14
|
+
import { evmSignature } from "../generated/index.ts";
|
|
15
|
+
import { CLAIM_BITS, CLAIM_KNOWN_MASKS } from "../generated/index.ts";
|
|
16
|
+
import { EVM_EVENT_SCHEMAS } from "../abi/evm.gen.ts";
|
|
17
|
+
import { V2_EVENT_FIELD_NAMES } from "../abi/evm-event-names.ts";
|
|
18
|
+
|
|
19
|
+
export const CLAIM_HOLDER_EVM = CLAIM_BITS.evm.holder;
|
|
20
|
+
|
|
21
|
+
export const CLAIM_KNOWN_V2_EVM = CLAIM_KNOWN_MASKS.evm.v2;
|
|
22
|
+
|
|
23
|
+
const BOOK_RANGE = "(uint128,uint128,uint64,uint64,uint64,uint128,uint16,uint16,uint8,uint8)";
|
|
24
|
+
|
|
25
|
+
const LAUNCH_BOOK = `(uint128,uint128,uint128,uint128[],uint8,${BOOK_RANGE}[48],uint128,uint64,uint64[],uint128[],uint8,uint8,uint128[],uint128[],uint128,uint64,bool,uint32[5])`;
|
|
26
|
+
|
|
27
|
+
const BUY_OUT = "(uint256,uint256,uint256,uint128,uint8,bool,bool)";
|
|
28
|
+
|
|
29
|
+
export const V2_VIEWS = {
|
|
30
|
+
launchBook: { sig: evmSignature("launchBook"), ret: [LAUNCH_BOOK] },
|
|
31
|
+
launchMilestones: { sig: evmSignature("launchMilestones"), ret: ["(uint128[4],uint128[4])"] },
|
|
32
|
+
|
|
33
|
+
simBuy: { sig: evmSignature("simBuy"), ret: [BUY_OUT] },
|
|
34
|
+
holderPositionOf: { sig: "holderPositionOf(uint256,address)", ret: ["(bool,uint64,uint64,uint128,uint128,bool)"] },
|
|
35
|
+
holderBook: { sig: evmSignature("holderBook"), ret: ["(uint128,uint64,uint64,uint128,uint128)"] },
|
|
36
|
+
circulatingOf: { sig: evmSignature("circulatingOf"), ret: ["uint256", "uint256", "uint256"] },
|
|
37
|
+
|
|
38
|
+
launchState: { sig: evmSignature("launchState"), ret: ["(address,address,address,uint8,uint32,bytes32,bool,uint64,uint64,uint64,uint256,uint256,uint256,uint256,uint256,uint256,uint256,uint256,uint16)"] },
|
|
39
|
+
|
|
40
|
+
bidMoney: { sig: evmSignature("bidMoney"), ret: ["uint256"] },
|
|
41
|
+
|
|
42
|
+
teamShareOf: { sig: evmSignature("teamShareOf"), ret: ["uint256", "uint256", "uint64"] },
|
|
43
|
+
|
|
44
|
+
launchFeeCurve: { sig: evmSignature("launchFeeCurve"), ret: ["(uint32[5],uint128,uint128)"] },
|
|
45
|
+
|
|
46
|
+
teamSlotOf: { sig: evmSignature("teamSlotOf"), ret: ["(uint64[10],uint32[10],uint64[10],address[10],bytes32[10],uint128[10],uint64[10],address[10])"] },
|
|
47
|
+
|
|
48
|
+
pairIdOf: { sig: evmSignature("pairIdOf"), ret: ["bytes32"] },
|
|
49
|
+
|
|
50
|
+
launchOfPair: { sig: evmSignature("launchOfPair"), ret: ["uint256"] },
|
|
51
|
+
} as const;
|
|
52
|
+
|
|
53
|
+
export function evmPairId(floorAmm: string, launchId: bigint): string {
|
|
54
|
+
return bytesToHex(keccak256(encodeAbi(["address", "uint256"], [floorAmm, launchId])));
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
export const V2_TOKEN_VIEWS = {
|
|
58
|
+
|
|
59
|
+
positionOf: { sig: evmSignature("positionOf"), ret: ["uint64", "uint64", "uint128", "bool", "uint128"] },
|
|
60
|
+
|
|
61
|
+
bookState: { sig: evmSignature("bookState"), ret: ["uint128", "uint64", "uint64", "uint128", "uint128"] },
|
|
62
|
+
bookTotals: { sig: evmSignature("bookTotals"), ret: ["uint128", "uint128"] },
|
|
63
|
+
|
|
64
|
+
optedIn: { sig: evmSignature("optedIn"), ret: ["bool"] },
|
|
65
|
+
} as const;
|
|
66
|
+
|
|
67
|
+
export const V2_CALLS = {
|
|
68
|
+
creditBacking: evmSignature("creditBacking"),
|
|
69
|
+
} as const;
|
|
70
|
+
|
|
71
|
+
export const V2_TOKEN_CALLS = {
|
|
72
|
+
optIn: evmSignature("optIn"),
|
|
73
|
+
releaseSkipped: evmSignature("releaseSkipped"),
|
|
74
|
+
} as const;
|
|
75
|
+
|
|
76
|
+
export const V2_DROPPED_EVM = ["setTraderListBps", "TraderListSet", "listBps"] as const;
|
|
77
|
+
|
|
78
|
+
export const V2_PENDING_EVM: Record<string, string> = {
|
|
79
|
+
holderPositionOf: "not built: read the token's `positionOf` + `optedIn` (`readHolderV2`)",
|
|
80
|
+
RowBands: "row error, not decoded yet", RowShares: "row error, not decoded yet", RowLength: "row error, not decoded yet",
|
|
81
|
+
RowVersion: "row error, not decoded yet", RowEdges: "row error, not decoded yet", RowTail: "row error, not decoded yet",
|
|
82
|
+
RowBounds: "row error, not decoded yet", RowFees: "row error, not decoded yet", RowTeam: "row error, not decoded yet",
|
|
83
|
+
RowFlags: "row error, not decoded yet", RowMsClass: "row error, not decoded yet", RowNonCanonical: "row error, not decoded yet",
|
|
84
|
+
};
|
|
85
|
+
|
|
86
|
+
export type { EvmCall } from "../evm/floor/calls.ts";
|
|
87
|
+
const call = (to: string, sig: string, args: AbiValue[], value = 0n): EvmCall => ({ to, data: bytesToHex(encodeCall(sig, args)), value });
|
|
88
|
+
|
|
89
|
+
const NATIVE = "0x0000000000000000000000000000000000000000";
|
|
90
|
+
|
|
91
|
+
export function creditBackingCall(amm: string, launchId: bigint, quote: string, amount: bigint): EvmCall {
|
|
92
|
+
if (amount <= 0n) throw new RangeError("creditBacking: amount must be > 0 (NothingToDo)");
|
|
93
|
+
return call(amm, V2_CALLS.creditBacking, [launchId, amount], quote.toLowerCase() === NATIVE ? amount : 0n);
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
export function claimV2Call(p: { floorAmm: string; wallet: string; types: number; quotes: readonly string[]; launchIds?: readonly bigint[] }): EvmCall {
|
|
97
|
+
if (!Number.isInteger(p.types) || p.types <= 0 || (p.types & ~CLAIM_KNOWN_V2_EVM) !== 0) throw new RangeError("UnknownClaimType: the v2 claim takes bits 1, 2, 4, 8, 64, 128, 256, 512 (16 and 32 are reserved)");
|
|
98
|
+
if ((p.types & CLAIM_HOLDER_EVM) === 0) return claimCall(p);
|
|
99
|
+
if ((p.launchIds ?? []).length === 0) throw new RangeError("bit 512 (holder) claims per launch: name the launchIds");
|
|
100
|
+
if (p.quotes.length === 0) throw new RangeError("bit 512 (holder) pays in each launch's quote: list them in quotes (an unlisted one is skipped)");
|
|
101
|
+
const rest = p.types & ~CLAIM_HOLDER_EVM;
|
|
102
|
+
if (rest !== 0) claimCall({ ...p, types: rest });
|
|
103
|
+
return call(p.floorAmm, evmSignature("claim"), [p.wallet, BigInt(p.types), [...(p.launchIds ?? [])], [...p.quotes]]);
|
|
104
|
+
}
|
|
105
|
+
export const optInCall = (token: string): EvmCall => call(token, V2_TOKEN_CALLS.optIn, []);
|
|
106
|
+
export const releaseSkippedCall = (token: string, a: string): EvmCall => call(token, V2_TOKEN_CALLS.releaseSkipped, [a]);
|
|
107
|
+
|
|
108
|
+
export function viewCall(name: keyof typeof V2_VIEWS, args: AbiValue[]): string {
|
|
109
|
+
return bytesToHex(encodeCall(V2_VIEWS[name].sig, args));
|
|
110
|
+
}
|
|
111
|
+
export function tokenViewCall(name: keyof typeof V2_TOKEN_VIEWS, args: AbiValue[]): string {
|
|
112
|
+
return bytesToHex(encodeCall(V2_TOKEN_VIEWS[name].sig, args));
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
const n = (v: AbiValue): number => Number(v as bigint);
|
|
116
|
+
const big = (v: AbiValue): bigint => v as bigint;
|
|
117
|
+
const bigs = (v: AbiValue): bigint[] => (v as AbiValue[]).map(big);
|
|
118
|
+
const nums = (v: AbiValue): number[] => (v as AbiValue[]).map(n);
|
|
119
|
+
|
|
120
|
+
export interface BookRangeV2 { sqrtA: bigint; sqrtB: bigint; tokens: bigint; askLeft: bigint; back: bigint; place: bigint; thetaBps: number; psiBps: number; kind: number; class: number }
|
|
121
|
+
|
|
122
|
+
export interface LaunchBookV2 {
|
|
123
|
+
sqrtP: bigint; sqrtF: bigint; f: bigint; bandMoney: bigint[]; nRanges: number; ranges: BookRangeV2[];
|
|
124
|
+
sqrtLMax: bigint; floorTokens: bigint; bandTokens: bigint[]; bandEdge: bigint[];
|
|
125
|
+
|
|
126
|
+
nBands: number; nC: number;
|
|
127
|
+
|
|
128
|
+
bandF: bigint[]; bandFClaim: bigint[];
|
|
129
|
+
|
|
130
|
+
ckAtF: bigint; ckFloorTokens: bigint;
|
|
131
|
+
graduated: boolean;
|
|
132
|
+
|
|
133
|
+
feePpm: number[];
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
export interface LaunchMsV2 { booked: bigint[]; paid: bigint[] }
|
|
137
|
+
|
|
138
|
+
export interface SimBuyV2 { tokensOut: bigint; spent: bigint; refund: bigint; sqrtAfter: bigint; steps: number; budgetHit: boolean; graduatedNow: boolean }
|
|
139
|
+
|
|
140
|
+
export interface HolderPosV2 { matured: boolean; amount: bigint; avgTs: bigint; owed: bigint; indexSnap: bigint; skipped: boolean }
|
|
141
|
+
export interface HolderBookV2 { index: bigint; wMatured: bigint; wPending: bigint; carry: bigint; dust: bigint }
|
|
142
|
+
|
|
143
|
+
function one(name: keyof typeof V2_VIEWS, data: string | Uint8Array): AbiValue[] {
|
|
144
|
+
return decodeAbi(V2_VIEWS[name].ret, data);
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
export function decodeLaunchBook(data: string | Uint8Array): LaunchBookV2 {
|
|
148
|
+
const [t] = one("launchBook", data) as AbiValue[][];
|
|
149
|
+
const nR = n(t[4]);
|
|
150
|
+
const ranges = (t[5] as AbiValue[][]).slice(0, nR).map((r) => ({
|
|
151
|
+
sqrtA: big(r[0]), sqrtB: big(r[1]), tokens: big(r[2]), askLeft: big(r[3]), back: big(r[4]), place: big(r[5]),
|
|
152
|
+
thetaBps: n(r[6]), psiBps: n(r[7]), kind: n(r[8]), class: n(r[9]),
|
|
153
|
+
}));
|
|
154
|
+
return {
|
|
155
|
+
sqrtP: big(t[0]), sqrtF: big(t[1]), f: big(t[2]), bandMoney: bigs(t[3]), nRanges: nR, ranges,
|
|
156
|
+
sqrtLMax: big(t[6]), floorTokens: big(t[7]), bandTokens: bigs(t[8]), bandEdge: bigs(t[9]), nBands: n(t[10]), nC: n(t[11]),
|
|
157
|
+
bandF: bigs(t[12]), bandFClaim: bigs(t[13]), ckAtF: big(t[14]), ckFloorTokens: big(t[15]), graduated: t[16] as boolean, feePpm: nums(t[17]),
|
|
158
|
+
};
|
|
159
|
+
}
|
|
160
|
+
export function decodeSimBuy(data: string | Uint8Array): SimBuyV2 {
|
|
161
|
+
const [t] = one("simBuy", data) as AbiValue[][];
|
|
162
|
+
return { tokensOut: big(t[0]), spent: big(t[1]), refund: big(t[2]), sqrtAfter: big(t[3]), steps: n(t[4]), budgetHit: t[5] as boolean, graduatedNow: t[6] as boolean };
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
export function decodeLaunchStateSupply(data: string | Uint8Array): { graduated: boolean; supply: bigint; sOut: bigint } {
|
|
166
|
+
const [t] = one("launchState", data) as AbiValue[][];
|
|
167
|
+
return { graduated: t[6] as boolean, supply: big(t[10]), sOut: big(t[11]) };
|
|
168
|
+
}
|
|
169
|
+
export const decodeBidMoney = (data: string | Uint8Array): bigint => big(one("bidMoney", data)[0]);
|
|
170
|
+
export const decodeOptedIn = (data: string | Uint8Array): boolean => decodeAbi(V2_TOKEN_VIEWS.optedIn.ret, data)[0] as boolean;
|
|
171
|
+
export function decodeLaunchMilestones(data: string | Uint8Array): LaunchMsV2 {
|
|
172
|
+
const [t] = one("launchMilestones", data) as AbiValue[][];
|
|
173
|
+
return { booked: bigs(t[0]), paid: bigs(t[1]) };
|
|
174
|
+
}
|
|
175
|
+
export interface TeamShareV2 { claimable: bigint; boughtOwed: bigint; lastDay: bigint }
|
|
176
|
+
|
|
177
|
+
export interface FeeCurveViewV2 { feeStartPpm: number[]; sqrtFeeA: bigint; sqrtFeeB: bigint }
|
|
178
|
+
export function decodeLaunchFeeCurve(data: string | Uint8Array): FeeCurveViewV2 {
|
|
179
|
+
const [t] = one("launchFeeCurve", data) as AbiValue[][];
|
|
180
|
+
return { feeStartPpm: nums(t[0]), sqrtFeeA: big(t[1]), sqrtFeeB: big(t[2]) };
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
export interface TeamSlotV2 {
|
|
184
|
+
members: string[];
|
|
185
|
+
handles: string[];
|
|
186
|
+
share: bigint[];
|
|
187
|
+
weightPpb: number[];
|
|
188
|
+
teamBuyPart: bigint[];
|
|
189
|
+
slotOwed: bigint[];
|
|
190
|
+
slotBoughtOwed: bigint[];
|
|
191
|
+
|
|
192
|
+
wallets: string[];
|
|
193
|
+
}
|
|
194
|
+
export function decodeTeamSlotOf(data: string | Uint8Array): TeamSlotV2 {
|
|
195
|
+
const [t] = one("teamSlotOf", data) as AbiValue[][];
|
|
196
|
+
const strs = (v: AbiValue): string[] => (v as AbiValue[]).map((x) => x as string);
|
|
197
|
+
return { teamBuyPart: bigs(t[0]), weightPpb: nums(t[1]), share: bigs(t[2]), members: strs(t[3]), handles: strs(t[4]), slotOwed: bigs(t[5]), slotBoughtOwed: bigs(t[6]), wallets: strs(t[7]) };
|
|
198
|
+
}
|
|
199
|
+
export function decodeTeamShareOf(data: string | Uint8Array): TeamShareV2 {
|
|
200
|
+
const [claimable, boughtOwed, lastDay] = one("teamShareOf", data);
|
|
201
|
+
return { claimable: big(claimable), boughtOwed: big(boughtOwed), lastDay: big(lastDay) };
|
|
202
|
+
}
|
|
203
|
+
export function decodeHolderPositionOf(data: string | Uint8Array): HolderPosV2 {
|
|
204
|
+
const [t] = one("holderPositionOf", data) as AbiValue[][];
|
|
205
|
+
return { matured: t[0] as boolean, amount: big(t[1]), avgTs: big(t[2]), owed: big(t[3]), indexSnap: big(t[4]), skipped: t[5] as boolean };
|
|
206
|
+
}
|
|
207
|
+
export function decodeHolderBook(data: string | Uint8Array): HolderBookV2 {
|
|
208
|
+
const [t] = one("holderBook", data) as AbiValue[][];
|
|
209
|
+
return { index: big(t[0]), wMatured: big(t[1]), wPending: big(t[2]), carry: big(t[3]), dust: big(t[4]) };
|
|
210
|
+
}
|
|
211
|
+
export function decodeCirculatingOf(data: string | Uint8Array): { sCirc: bigint; sBelow: bigint; dead: bigint } {
|
|
212
|
+
const [a, b, c] = one("circulatingOf", data);
|
|
213
|
+
return { sCirc: big(a), sBelow: big(b), dead: big(c) };
|
|
214
|
+
}
|
|
215
|
+
export function decodeTokenPosition(data: string | Uint8Array): Omit<HolderPosV2, "skipped"> {
|
|
216
|
+
const [amount, avgTs, owed, matured, indexSnap] = decodeAbi(V2_TOKEN_VIEWS.positionOf.ret, data);
|
|
217
|
+
return { amount: big(amount), avgTs: big(avgTs), owed: big(owed), matured: matured as boolean, indexSnap: big(indexSnap) };
|
|
218
|
+
}
|
|
219
|
+
export function decodeTokenBookState(data: string | Uint8Array): HolderBookV2 {
|
|
220
|
+
const [index, wMatured, wPending, carry, dust] = decodeAbi(V2_TOKEN_VIEWS.bookState.ret, data);
|
|
221
|
+
return { index: big(index), wMatured: big(wMatured), wPending: big(wPending), carry: big(carry), dust: big(dust) };
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
type V2EventName = keyof typeof V2_EVENT_FIELD_NAMES;
|
|
225
|
+
|
|
226
|
+
export const V2_EVENTS = Object.fromEntries(
|
|
227
|
+
(Object.keys(V2_EVENT_FIELD_NAMES) as V2EventName[]).map((n) => {
|
|
228
|
+
const e = EVM_EVENT_SCHEMAS.find((x) => x.name === n);
|
|
229
|
+
if (!e) throw new Error(`no generated schema for ${n}`);
|
|
230
|
+
return [n, { sig: e.signature, indexed: e.params.filter((p) => p.indexed).length, names: V2_EVENT_FIELD_NAMES[n] }];
|
|
231
|
+
}),
|
|
232
|
+
) as { readonly [N in V2EventName]: { readonly sig: string; readonly indexed: number; readonly names: (typeof V2_EVENT_FIELD_NAMES)[N] } };
|
|
233
|
+
|
|
234
|
+
export const V2_EVENTS_ELSEWHERE = [
|
|
235
|
+
"Initialized", "LaunchCreated", "PayoutOwed", "TeamSlotOpened", "Upgraded", "Approval", "Transfer", "EIP712DomainChanged", "Claimed", "ClaimSkipped",
|
|
236
|
+
"HolderWithdrawn", "PlatformWithdrawn", "PayoutClaimed", "PotsSwept", "TeamBuyClaimed", "TeamShareBoughtClaimed", "CreatorBuyUnlocked",
|
|
237
|
+
"TeamSlotMember",
|
|
238
|
+
] as const;
|
|
239
|
+
|
|
240
|
+
let topics: Map<string, keyof typeof V2_EVENTS> | undefined;
|
|
241
|
+
const TOPICS = (): Map<string, keyof typeof V2_EVENTS> =>
|
|
242
|
+
(topics ??= new Map((Object.keys(V2_EVENTS) as (keyof typeof V2_EVENTS)[]).map((k) => [eventTopic(V2_EVENTS[k].sig), k])));
|
|
243
|
+
|
|
244
|
+
export const v2EventTopic = (name: keyof typeof V2_EVENTS): string => eventTopic(V2_EVENTS[name].sig);
|
|
245
|
+
|
|
246
|
+
export function decodeLogV2(log: { topics: readonly string[]; data: string }): { name: string; fields: Record<string, AbiValue> } | null {
|
|
247
|
+
const name = TOPICS().get((log.topics[0] ?? "").toLowerCase());
|
|
248
|
+
if (!name) return null;
|
|
249
|
+
const ev = V2_EVENTS[name];
|
|
250
|
+
const types = ev.sig.slice(ev.sig.indexOf("(") + 1, -1).split(/,(?![^[]*\])/);
|
|
251
|
+
if (log.topics.length !== 1 + ev.indexed) throw new RangeError(`${name}: ${log.topics.length - 1} indexed topics, want ${ev.indexed}`);
|
|
252
|
+
const fields: Record<string, AbiValue> = {};
|
|
253
|
+
for (let i = 0; i < ev.indexed; i++) fields[ev.names[i]] = decodeAbi([types[i]], hexToBytes(log.topics[1 + i]))[0];
|
|
254
|
+
const body = decodeAbi(types.slice(ev.indexed), log.data);
|
|
255
|
+
body.forEach((v, i) => (fields[ev.names[ev.indexed + i]] = v));
|
|
256
|
+
return { name, fields };
|
|
257
|
+
}
|
|
258
|
+
|
|
259
|
+
export const V2_ERRORS_EVM = [
|
|
260
|
+
"RowTooManyRanges", "RowNotFeasible", "NotToken",
|
|
261
|
+
|
|
262
|
+
"NotProgram",
|
|
263
|
+
|
|
264
|
+
"BadMember",
|
|
265
|
+
] as const;
|
|
266
|
+
|
|
267
|
+
export const V2_ERRORS_ARGS_EVM = ["UnknownClaimType(uint256)"] as const;
|
|
268
|
+
let errs: Map<string, string> | undefined;
|
|
269
|
+
|
|
270
|
+
export function decodeErrorV2(data: string): string | null {
|
|
271
|
+
errs ??= new Map([...V2_ERRORS_EVM.map((n) => `${n}()`), ...V2_ERRORS_ARGS_EVM].map((sig) => [bytesToHex(functionSelector(sig)), sig.slice(0, sig.indexOf("("))]));
|
|
272
|
+
return errs.get(data.slice(0, 10).toLowerCase()) ?? null;
|
|
273
|
+
}
|
|
274
|
+
|
|
275
|
+
export function bookFromEvmLaunchBook(view: LaunchBookV2, opts: { msCapPpm?: readonly number[]; curve?: FeeCurveViewV2 } = {}): Book {
|
|
276
|
+
const noRow: SplitRow = { phiBps: 0, ckBps: 0, wcBps: 0, cShareBps: 0, msClass: 0, platformMsBps: 0, floorMsBps: 0 };
|
|
277
|
+
return evmSettleInputsV2(view, noRow, { live: 0n, dead: 0n }, opts.msCapPpm, opts.curve).book;
|
|
278
|
+
}
|
|
279
|
+
|
|
280
|
+
export function evmSettleInputsV2(b: LaunchBookV2, row: SplitRow, sup: Supply, msCapPpm: readonly number[] = [], curve?: FeeCurveViewV2): { book: Book; row: SplitRow; sup: Supply } {
|
|
281
|
+
if (curve && curve.feeStartPpm.length !== 5) throw new RangeError("a fee curve has 5 legs");
|
|
282
|
+
const fits = (xs: readonly (bigint | number)[], what: string): void => {
|
|
283
|
+
for (let i = BIDS_MAX; i < xs.length; i++) if (BigInt(xs[i]) !== 0n) throw new RangeError(`${what}[${i}] is set: the SDK's v2 math carries ${BIDS_MAX} bid segments`);
|
|
284
|
+
};
|
|
285
|
+
if (b.nBands > BIDS_MAX) throw new RangeError(`${b.nBands} bid segments: the SDK's v2 math carries ${BIDS_MAX}`);
|
|
286
|
+
fits(b.bandMoney, "bandMoney");
|
|
287
|
+
fits(b.bandTokens, "bandTokens");
|
|
288
|
+
fits(b.bandF, "bandF");
|
|
289
|
+
fits(b.bandFClaim, "bandFClaim");
|
|
290
|
+
const pad = <T>(xs: readonly T[], len: number, z: T): T[] => Array.from({ length: len }, (_, i) => xs[i] ?? z);
|
|
291
|
+
const ranges: Range[] = Array.from({ length: RANGES_MAX }, (_, i) => (b.ranges[i] ? { ...b.ranges[i], msCapPpm: msCapPpm[i] ?? 0 } : emptyRange()));
|
|
292
|
+
const book: Book = {
|
|
293
|
+
sqrtP: b.sqrtP, sqrtF: b.sqrtF, sqrtLMax: b.sqrtLMax, floor: b.f, floorTokens: b.floorTokens, nBands: b.nBands, nC: b.nC,
|
|
294
|
+
bandEdge: pad(b.bandEdge, BIDS_MAX + 1, 0n).slice(0, BIDS_MAX + 1), bandMoney: pad(b.bandMoney, BIDS_MAX, 0n).slice(0, BIDS_MAX),
|
|
295
|
+
bandTokens: pad(b.bandTokens, BIDS_MAX, 0n).slice(0, BIDS_MAX), bandF: pad(b.bandF, BIDS_MAX, 0n).slice(0, BIDS_MAX),
|
|
296
|
+
bandFClaim: pad(b.bandFClaim, BIDS_MAX, 0n).slice(0, BIDS_MAX), ckAtF: b.ckAtF, ckFloorTokens: b.ckFloorTokens,
|
|
297
|
+
feePpm: [...b.feePpm], graduated: b.graduated,
|
|
298
|
+
|
|
299
|
+
feeStartPpm: curve ? [...curve.feeStartPpm] : [0, 0, 0, 0, 0], sqrtFeeA: curve?.sqrtFeeA ?? 0n, sqrtFeeB: curve?.sqrtFeeB ?? 0n,
|
|
300
|
+
nRanges: b.nRanges, ranges,
|
|
301
|
+
};
|
|
302
|
+
return { book, row: { ...row }, sup: { ...sup } };
|
|
303
|
+
}
|
|
304
|
+
|
|
305
|
+
export function quoteBuyEvmV2(
|
|
306
|
+
v: { book: LaunchBookV2; row: SplitRow; sup: Supply },
|
|
307
|
+
gross: bigint,
|
|
308
|
+
opts: { recipient?: HolderStandingV2; msCapPpm?: readonly number[]; curve?: FeeCurveViewV2 } = {},
|
|
309
|
+
): { buy: BookBuy; after: Book; holder: HolderStandingV2 | null } {
|
|
310
|
+
const { book, row, sup } = evmSettleInputsV2(v.book, v.row, v.sup, opts.msCapPpm, opts.curve);
|
|
311
|
+
const after = cloneBook(book);
|
|
312
|
+
const r = buy(after, row, sup, gross, 0n);
|
|
313
|
+
return { buy: r, after, holder: opts.recipient ?? null };
|
|
314
|
+
}
|
|
315
|
+
|
|
316
|
+
const NEVER_COUNTED = new Set(["0x0000000000000000000000000000000000000000", "0x0000000000000000000000000000000000000001", "0x000000000000000000000000000000000000dead", "0xdead000000000000000042069420694206942069"]);
|
|
317
|
+
|
|
318
|
+
export type HolderWeightV2 = "counted" | "contract-not-opted-in" | "never-counted";
|
|
319
|
+
export interface HolderStandingV2 {
|
|
320
|
+
weight: HolderWeightV2;
|
|
321
|
+
|
|
322
|
+
earns: boolean;
|
|
323
|
+
|
|
324
|
+
note: string | null;
|
|
325
|
+
}
|
|
326
|
+
|
|
327
|
+
export function holderStandingV2(p: { address: string; code: string; optedIn: boolean; program: string }): HolderStandingV2 {
|
|
328
|
+
const a = p.address.toLowerCase();
|
|
329
|
+
if (NEVER_COUNTED.has(a) || a === p.program.toLowerCase()) return { weight: "never-counted", earns: false, note: "This address never holds a holder position." };
|
|
330
|
+
const hasCode = p.code !== "" && p.code !== "0x" && !/^0x0*$/.test(p.code);
|
|
331
|
+
if (hasCode && !p.optedIn) {
|
|
332
|
+
return { weight: "contract-not-opted-in", earns: false, note: "A contract (or a delegated wallet) earns no Holder Fee and no Holder Milestones until it calls the token's optIn() once." };
|
|
333
|
+
}
|
|
334
|
+
return { weight: "counted", earns: true, note: null };
|
|
335
|
+
}
|
|
336
|
+
|
|
337
|
+
export async function readHolderV2(
|
|
338
|
+
rpc: { ethCall: (to: string, data: string) => Promise<string>; getCode: (address: string) => Promise<string> },
|
|
339
|
+
p: { token: string; program: string; address: string },
|
|
340
|
+
): Promise<{ amount: bigint; owed: bigint; indexSnap: bigint; standing: HolderStandingV2; optIn: EvmCall | null }> {
|
|
341
|
+
const [pos, opted, code] = await Promise.all([
|
|
342
|
+
rpc.ethCall(p.token, tokenViewCall("positionOf", [p.address])),
|
|
343
|
+
rpc.ethCall(p.token, tokenViewCall("optedIn", [p.address])),
|
|
344
|
+
rpc.getCode(p.address),
|
|
345
|
+
]);
|
|
346
|
+
const x = decodeTokenPosition(pos);
|
|
347
|
+
const standing = holderStandingV2({ address: p.address, code, optedIn: decodeOptedIn(opted), program: p.program });
|
|
348
|
+
return { amount: x.amount, owed: x.owed, indexSnap: x.indexSnap, standing, optIn: standing.weight === "contract-not-opted-in" ? optInCall(p.token) : null };
|
|
349
|
+
}
|
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
|
|
2
|
+
|
|
3
|
+
import { bytesToHex, decodeAbi, encodeCall } from "../evm/abi.ts";
|
|
4
|
+
import type { AbiValue } from "../evm/abi.ts";
|
|
5
|
+
import { decodeTeamShareOf, decodeTeamSlotOf, viewCall } from "./evm.ts";
|
|
6
|
+
import type { TeamShareV2, TeamSlotV2 } from "./evm.ts";
|
|
7
|
+
import { EVM_TOKEN_SCALE } from "./market-evm.ts";
|
|
8
|
+
import { evmSignature } from "../generated/index.ts";
|
|
9
|
+
|
|
10
|
+
export const LAUNCH_STATE_VIEW_EVM = {
|
|
11
|
+
sig: evmSignature("launchState"),
|
|
12
|
+
ret: ["(address,address,address,uint8,uint32,bytes32,bool,uint64,uint64,uint64,uint256,uint256,uint256,uint256,uint256,uint256,uint256,uint256,uint16)"],
|
|
13
|
+
} as const;
|
|
14
|
+
|
|
15
|
+
export interface LaunchStateEvmV2 {
|
|
16
|
+
token: string; quote: string; creator: string; presetId: number; presetVersion: number; presetHash: string;
|
|
17
|
+
graduated: boolean; createdAt: bigint; createdBlock: bigint; creatorUnlockAt: bigint;
|
|
18
|
+
supply: bigint; sOut: bigint; creatorLocked: bigint; floor: bigint; cushion: bigint; p0X64: bigint; priceX64: bigint; floorX64: bigint;
|
|
19
|
+
slotRateBps: number;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
const KEYS = [
|
|
23
|
+
"token", "quote", "creator", "presetId", "presetVersion", "presetHash", "graduated", "createdAt", "createdBlock",
|
|
24
|
+
"creatorUnlockAt", "supply", "sOut", "creatorLocked", "floor", "cushion", "p0X64", "priceX64", "floorX64", "slotRateBps",
|
|
25
|
+
] as const;
|
|
26
|
+
const NUMBERS = new Set<string>(["presetId", "presetVersion", "slotRateBps"]);
|
|
27
|
+
|
|
28
|
+
export const launchStateCallV2 = (launchId: bigint): string => bytesToHex(encodeCall(LAUNCH_STATE_VIEW_EVM.sig, [launchId]));
|
|
29
|
+
|
|
30
|
+
export function decodeLaunchStateV2(data: string | Uint8Array): LaunchStateEvmV2 {
|
|
31
|
+
const [t] = decodeAbi(LAUNCH_STATE_VIEW_EVM.ret, data) as AbiValue[][];
|
|
32
|
+
const o: Record<string, unknown> = {};
|
|
33
|
+
KEYS.forEach((k, i) => { o[k] = NUMBERS.has(k) ? Number(t[i] as bigint) : t[i]; });
|
|
34
|
+
return o as unknown as LaunchStateEvmV2;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
export type TeamSlotSourceEvmV2 = TeamSlotV2;
|
|
38
|
+
|
|
39
|
+
export interface TeamBuyOwedEvmV2 {
|
|
40
|
+
|
|
41
|
+
locked: bigint;
|
|
42
|
+
unlockAt: bigint;
|
|
43
|
+
|
|
44
|
+
unlocked: boolean;
|
|
45
|
+
|
|
46
|
+
perPlace: bigint[] | null;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
const PLACES = 10;
|
|
50
|
+
const ZERO_ADDRESS = "0x" + "00".repeat(20);
|
|
51
|
+
const ZERO_WORD = "0x" + "00".repeat(32);
|
|
52
|
+
|
|
53
|
+
function checkSource(s: TeamSlotSourceEvmV2): void {
|
|
54
|
+
for (const k of ["members", "handles", "share", "weightPpb", "teamBuyPart", "slotOwed", "slotBoughtOwed", "wallets"] as const) {
|
|
55
|
+
if (s[k].length !== PLACES) throw new RangeError(`TeamSlotSourceEvmV2.${k}: ${PLACES} places, got ${s[k].length}`);
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
export function teamBuyOwedEvmV2(v: LaunchStateEvmV2, opts: { now?: bigint; slot?: TeamSlotSourceEvmV2 } = {}): TeamBuyOwedEvmV2 {
|
|
60
|
+
const now = opts.now ?? BigInt(Math.floor(Date.now() / 1000));
|
|
61
|
+
if (opts.slot) checkSource(opts.slot);
|
|
62
|
+
return {
|
|
63
|
+
locked: v.creatorLocked, unlockAt: v.creatorUnlockAt, unlocked: now >= v.creatorUnlockAt,
|
|
64
|
+
perPlace: opts.slot ? opts.slot.teamBuyPart.map((x) => x * EVM_TOKEN_SCALE) : null,
|
|
65
|
+
};
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
export interface TeamSlotPlaceEvmV2 {
|
|
69
|
+
place: number;
|
|
70
|
+
|
|
71
|
+
wallet: string | null;
|
|
72
|
+
|
|
73
|
+
handle: string | null;
|
|
74
|
+
share: bigint;
|
|
75
|
+
weightPpb: number;
|
|
76
|
+
|
|
77
|
+
active: boolean;
|
|
78
|
+
|
|
79
|
+
teamShareOwed: bigint;
|
|
80
|
+
|
|
81
|
+
boughtOwed: bigint;
|
|
82
|
+
|
|
83
|
+
teamBuyPart: bigint;
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
export interface TeamSlotEvmV2 {
|
|
87
|
+
rateBps: number;
|
|
88
|
+
creator: string;
|
|
89
|
+
teamBuy: TeamBuyOwedEvmV2;
|
|
90
|
+
|
|
91
|
+
wallet: TeamShareV2 | null;
|
|
92
|
+
|
|
93
|
+
places: TeamSlotPlaceEvmV2[];
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
export async function readTeamSlotEvmV2(
|
|
97
|
+
rpc: { ethCall: (to: string, data: string) => Promise<string> },
|
|
98
|
+
p: { amm: string; launchId: bigint; wallet?: string; now?: bigint; slot?: TeamSlotSourceEvmV2 },
|
|
99
|
+
): Promise<TeamSlotEvmV2> {
|
|
100
|
+
const [state, slot, share] = await Promise.all([
|
|
101
|
+
rpc.ethCall(p.amm, launchStateCallV2(p.launchId)),
|
|
102
|
+
p.slot ? Promise.resolve(null) : rpc.ethCall(p.amm, viewCall("teamSlotOf", [p.launchId])),
|
|
103
|
+
p.wallet === undefined ? Promise.resolve(null) : rpc.ethCall(p.amm, viewCall("teamShareOf", [p.launchId, p.wallet])),
|
|
104
|
+
]);
|
|
105
|
+
const v = decodeLaunchStateV2(state);
|
|
106
|
+
const s = p.slot ?? decodeTeamSlotOf(slot!);
|
|
107
|
+
checkSource(s);
|
|
108
|
+
const addr = (x: string): string | null => (x.toLowerCase() === ZERO_ADDRESS ? null : x);
|
|
109
|
+
const places = Array.from({ length: PLACES }, (_, i): TeamSlotPlaceEvmV2 => {
|
|
110
|
+
const w = addr(s.wallets[i]) ?? addr(s.members[i]);
|
|
111
|
+
return {
|
|
112
|
+
place: i, wallet: i === 0 ? w ?? v.creator : w, handle: s.handles[i].toLowerCase() === ZERO_WORD ? null : s.handles[i],
|
|
113
|
+
share: s.share[i], weightPpb: s.weightPpb[i], active: s.share[i] > 0n, teamShareOwed: s.slotOwed[i],
|
|
114
|
+
boughtOwed: s.slotBoughtOwed[i] * EVM_TOKEN_SCALE, teamBuyPart: s.teamBuyPart[i] * EVM_TOKEN_SCALE,
|
|
115
|
+
};
|
|
116
|
+
});
|
|
117
|
+
return {
|
|
118
|
+
rateBps: v.slotRateBps, creator: v.creator, teamBuy: teamBuyOwedEvmV2(v, { now: p.now, slot: s }),
|
|
119
|
+
wallet: share === null ? null : decodeTeamShareOf(share), places,
|
|
120
|
+
};
|
|
121
|
+
}
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
|
|
2
|
+
|
|
3
|
+
import type { AccountMeta, Instruction } from "../solana/instruction.ts";
|
|
4
|
+
import { R, W } from "../solana/instruction.ts";
|
|
5
|
+
import { FLOOR_AMM_PROGRAM_ID, genesisMigrationVaultPda, genesisRaisePda, launchPda } from "../solana/floor/program.ts";
|
|
6
|
+
import * as I from "../solana/floor/instructions.ts";
|
|
7
|
+
import { extraAccountMetasPda, FLOOR_HOOK_PROGRAM_ID, holderBookPda, holderPositionPda } from "./solana.ts";
|
|
8
|
+
import { Writer } from "../solana/floor/borsh.ts";
|
|
9
|
+
|
|
10
|
+
type Hooked = { hookProgramId?: string };
|
|
11
|
+
type Ctx = { programId?: string } & Hooked;
|
|
12
|
+
const pid = (c?: Ctx): string => c?.programId ?? FLOOR_AMM_PROGRAM_ID;
|
|
13
|
+
const hid = (c?: Ctx): string => c?.hookProgramId ?? FLOOR_HOOK_PROGRAM_ID;
|
|
14
|
+
const EVENT_PAIR = 2;
|
|
15
|
+
|
|
16
|
+
function withTail(base: Instruction, tail: AccountMeta[]): Instruction {
|
|
17
|
+
const n = base.accounts.length - EVENT_PAIR;
|
|
18
|
+
return { ...base, accounts: [...base.accounts.slice(0, n), ...tail, ...base.accounts.slice(n)] };
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
const withData = (base: Instruction, more: (w: Writer) => Writer): Instruction => {
|
|
22
|
+
const tail = more(new Writer()).done();
|
|
23
|
+
const data = new Uint8Array(base.data.length + tail.length);
|
|
24
|
+
data.set(base.data, 0);
|
|
25
|
+
data.set(tail, base.data.length);
|
|
26
|
+
return { ...base, data };
|
|
27
|
+
};
|
|
28
|
+
|
|
29
|
+
type Member = { member: string };
|
|
30
|
+
const position = (mint: string, owner: string, c?: Ctx): string => holderPositionPda(launchPda(mint, pid(c))[0], owner, hid(c))[0];
|
|
31
|
+
const book = (mint: string, c?: Ctx): string => holderBookPda(launchPda(mint, pid(c))[0], hid(c))[0];
|
|
32
|
+
|
|
33
|
+
export function openGenesisLaunchInstructionV2(p: Parameters<typeof I.openGenesisLaunchInstruction>[0] & Hooked & Member): Instruction {
|
|
34
|
+
const base = I.openGenesisLaunchInstruction(p);
|
|
35
|
+
const g = pid(p);
|
|
36
|
+
return withData(withTail(base, [
|
|
37
|
+
W(book(p.baseMint, p)), W(extraAccountMetasPda(p.baseMint, hid(p))[0]), R(hid(p)),
|
|
38
|
+
W(position(p.baseMint, p.launch, p)), W(position(p.baseMint, genesisRaisePda(g)[0], p)), W(position(p.baseMint, genesisMigrationVaultPda(g)[0], p)),
|
|
39
|
+
]), (w) => w.pubkey(p.member));
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
export function openGenesisWagmiInstructionV2(p: Parameters<typeof I.openGenesisWagmiInstruction>[0] & Hooked & Member): Instruction {
|
|
43
|
+
const base = I.openGenesisWagmiInstruction(p);
|
|
44
|
+
const g = pid(p);
|
|
45
|
+
return withData(withTail(base, [
|
|
46
|
+
W(book(p.baseMint, p)), W(extraAccountMetasPda(p.baseMint, hid(p))[0]), R(hid(p)),
|
|
47
|
+
W(position(p.baseMint, p.launch, p)), W(position(p.baseMint, genesisRaisePda(g)[0], p)),
|
|
48
|
+
R(extraAccountMetasPda(p.quoteMint, hid(p))[0]), W(book(p.quoteMint, p)),
|
|
49
|
+
W(position(p.quoteMint, genesisMigrationVaultPda(g)[0], p)), W(position(p.quoteMint, p.launch, p)),
|
|
50
|
+
]), (w) => w.pubkey(p.member));
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
export function claimGenesisInstructionV2(p: Parameters<typeof I.claimGenesisInstruction>[0] & Hooked): Instruction {
|
|
54
|
+
const base = I.claimGenesisInstruction(p);
|
|
55
|
+
const g = pid(p);
|
|
56
|
+
return withTail(base, [
|
|
57
|
+
R(extraAccountMetasPda(p.baseMint, hid(p))[0]), R(launchPda(p.baseMint, g)[0]), W(book(p.baseMint, p)),
|
|
58
|
+
W(position(p.baseMint, genesisRaisePda(g)[0], p)), W(position(p.baseMint, p.wallet, p)), R(hid(p)),
|
|
59
|
+
]);
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
export function claimGenesisWagmiInstructionV2(p: Parameters<typeof I.claimGenesisWagmiInstruction>[0] & Hooked): Instruction {
|
|
63
|
+
const base = I.claimGenesisWagmiInstruction(p);
|
|
64
|
+
const g = pid(p);
|
|
65
|
+
return withTail(base, [
|
|
66
|
+
R(extraAccountMetasPda(p.wagmiMint, hid(p))[0]), R(launchPda(p.wagmiMint, g)[0]), W(book(p.wagmiMint, p)),
|
|
67
|
+
W(position(p.wagmiMint, genesisRaisePda(g)[0], p)), W(position(p.wagmiMint, p.wallet, p)),
|
|
68
|
+
R(extraAccountMetasPda(p.floorMint, hid(p))[0]), R(launchPda(p.floorMint, g)[0]), W(book(p.floorMint, p)),
|
|
69
|
+
W(position(p.floorMint, genesisMigrationVaultPda(g)[0], p)), W(position(p.floorMint, p.wallet, p)), R(hid(p)),
|
|
70
|
+
]);
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
export function sweepGenesisWagmiDustInstructionV2(p: Parameters<typeof I.sweepGenesisWagmiDustInstruction>[0] & Hooked): Instruction {
|
|
74
|
+
const base = I.sweepGenesisWagmiDustInstruction(p);
|
|
75
|
+
const g = pid(p);
|
|
76
|
+
return withTail(base, [
|
|
77
|
+
R(extraAccountMetasPda(p.floorMint, hid(p))[0]), R(launchPda(p.floorMint, g)[0]), W(book(p.floorMint, p)),
|
|
78
|
+
W(position(p.floorMint, genesisMigrationVaultPda(g)[0], p)), W(position(p.floorMint, p.launch, p)), R(hid(p)),
|
|
79
|
+
]);
|
|
80
|
+
}
|