@floorlaunchpad/sdk 0.6.0 → 0.8.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 +279 -0
- package/README.md +12 -1
- package/dist/abi/evm-event-names.js +7 -0
- package/dist/abi/evm.gen.js +81 -2
- package/dist/abi/functions.gen.js +135 -1
- package/dist/abi/solana.gen.js +64 -0
- package/dist/client/solana/index.js +25 -6
- package/dist/config/generated.js +803 -26374
- package/dist/errors.js +21 -2
- package/dist/events/types.gen.js +1 -1
- package/dist/evm/chains.js +80 -0
- package/dist/evm/floor/abi.gen.js +115 -0
- package/dist/evm/floor/calls.js +5 -0
- package/dist/evm/squid.js +21 -5
- package/dist/evm/venues.js +302 -0
- package/dist/generated/interface.gen.js +93 -44
- package/dist/index.js +7 -0
- package/dist/indexer/bodies.js +288 -5
- package/dist/indexer/client.js +17 -1
- package/dist/indexer/contract.js +141 -15
- package/dist/indexer/paths.js +80 -7
- package/dist/indexer/read.js +25 -3
- package/dist/indexer/stream.js +2 -2
- package/dist/math/v2/book.js +24 -7
- package/dist/math/v2/create.js +1 -1
- package/dist/math/v2/escrow.js +205 -0
- package/dist/math/v2/fees.js +30 -4
- package/dist/math/v2/milestones.js +1 -1
- package/dist/math/v2/office.js +110 -0
- package/dist/math/v2/receipt.js +3 -3
- package/dist/math/v2/relay.js +263 -96
- package/dist/math/v2/rows.js +17 -0
- package/dist/math/v2/team.js +42 -1
- package/dist/math/v2/trade.js +3 -1
- package/dist/reprice.js +88 -0
- package/dist/route/quote.js +16 -0
- package/dist/scaledUi.js +113 -0
- package/dist/solana/floor/accounts.js +38 -5
- package/dist/solana/floor/events.js +62 -1
- package/dist/solana/floor/instructions.js +39 -1
- package/dist/solana/floor/program.js +3 -0
- package/dist/stockRefresh.js +99 -0
- package/dist/ton/consts.generated.js +2 -2
- package/dist/ton/gas.js +3 -3
- package/dist/v2/claims.js +28 -5
- package/dist/v2/devbuy.js +28 -3
- package/dist/v2/events.js +2 -0
- package/dist/v2/evm.js +183 -5
- package/dist/v2/layouts.js +102 -2
- package/dist/v2/office-events.js +127 -0
- package/dist/v2/office-evm.js +68 -0
- package/dist/v2/office-read.js +182 -0
- package/dist/v2/office-solana.js +134 -0
- package/dist/v2/office-trade.js +73 -0
- package/dist/v2/route-alt.js +1 -0
- package/dist/v2/route.js +1 -1
- package/dist/v2/solana.js +224 -5
- package/dist/v2/solanaSettle.js +2 -0
- package/dist/v2/tx/evm.js +66 -2
- package/dist/v2/tx/solana.js +3 -3
- package/dist/v2/types.js +4 -0
- package/docs/aggregator.md +19 -0
- package/docs/cursor-pages.md +9 -3
- package/docs/ton.md +1 -1
- package/examples/floor-line.html +1 -1
- package/package.json +26 -1
- package/src/abi/evm-event-names.ts +7 -0
- package/src/abi/evm.gen.ts +81 -2
- package/src/abi/functions.gen.ts +135 -1
- package/src/abi/solana.gen.ts +64 -0
- package/src/client/solana/index.ts +25 -6
- package/src/config/generated.ts +803 -26374
- package/src/errors.ts +21 -2
- package/src/events/types.gen.ts +458 -1
- package/src/evm/chains.ts +89 -0
- package/src/evm/floor/abi.gen.ts +115 -0
- package/src/evm/floor/calls.ts +5 -0
- package/src/evm/squid.ts +22 -6
- package/src/evm/venues.ts +340 -0
- package/src/generated/interface.gen.ts +93 -44
- package/src/index.ts +7 -0
- package/src/indexer/bodies.ts +308 -5
- package/src/indexer/client.ts +31 -4
- package/src/indexer/contract.ts +148 -17
- package/src/indexer/paths.ts +139 -7
- package/src/indexer/read.ts +27 -5
- package/src/indexer/stream.ts +4 -4
- package/src/math/v2/book.ts +23 -7
- package/src/math/v2/create.ts +1 -1
- package/src/math/v2/escrow.ts +213 -0
- package/src/math/v2/fees.ts +30 -4
- package/src/math/v2/milestones.ts +1 -1
- package/src/math/v2/office.ts +114 -0
- package/src/math/v2/receipt.ts +7 -3
- package/src/math/v2/relay.ts +269 -96
- package/src/math/v2/rows.ts +17 -0
- package/src/math/v2/team.ts +42 -1
- package/src/math/v2/trade.ts +3 -1
- package/src/reprice.ts +121 -0
- package/src/route/quote.ts +16 -0
- package/src/scaledUi.ts +123 -0
- package/src/solana/floor/accounts.ts +38 -5
- package/src/solana/floor/events.ts +63 -2
- package/src/solana/floor/instructions.ts +39 -1
- package/src/solana/floor/program.ts +3 -0
- package/src/stockRefresh.ts +131 -0
- package/src/ton/consts.generated.ts +2 -2
- package/src/ton/gas.ts +3 -3
- package/src/v2/claims.ts +34 -5
- package/src/v2/devbuy.ts +38 -3
- package/src/v2/events.ts +3 -1
- package/src/v2/evm.ts +209 -5
- package/src/v2/layouts.ts +102 -2
- package/src/v2/office-events.ts +133 -0
- package/src/v2/office-evm.ts +76 -0
- package/src/v2/office-read.ts +264 -0
- package/src/v2/office-solana.ts +159 -0
- package/src/v2/office-trade.ts +96 -0
- package/src/v2/route-alt.ts +1 -0
- package/src/v2/route.ts +1 -1
- package/src/v2/solana.ts +235 -5
- package/src/v2/solanaSettle.ts +2 -0
- package/src/v2/tx/evm.ts +66 -2
- package/src/v2/tx/solana.ts +5 -3
- package/src/v2/types.ts +76 -1
package/dist/v2/claims.js
CHANGED
|
@@ -9,11 +9,11 @@ import { decodeTeamSlot } from "../solana/floor/accounts.js";
|
|
|
9
9
|
import { CLAIM_CREATOR, CLAIM_CREATOR_REF, CLAIM_SHARE_BOUGHT, CLAIM_TEAM_BUY, CLAIM_TEAM_SLOT, CLAIM_TRADER_REF } from "../solana/floor/instructions.js";
|
|
10
10
|
import { FLOOR_AMM_PROGRAM_ID, configPda, refOwedPda, refOwedVault } from "../solana/floor/program.js";
|
|
11
11
|
import { TOKEN_2022_PROGRAM_ID, TOKEN_PROGRAM_ID, WSOL_MINT, associatedTokenAddress } from "../solana/pda.js";
|
|
12
|
-
import { CREATOR_BUY_LOCK_SECS, MAX_MEMBERS, splitTeamBuyV2 } from "../math/v2/team.js";
|
|
12
|
+
import { CREATOR_BUY_LOCK_SECS, MAX_MEMBERS, seatNet, splitTeamBuyV2 } from "../math/v2/team.js";
|
|
13
13
|
import { holderSync, holderTake } from "../math/v2/holders.js";
|
|
14
14
|
import { FloorMathError } from "../math/index.js";
|
|
15
|
-
import { decodeHolderBook, decodeHolderPosition, decodeLaunchV2 } from "./layouts.js";
|
|
16
|
-
import { CLAIM_HOLDER, claimInstructionV2 } from "./solana.js";
|
|
15
|
+
import { decodeAccountV2, decodeHolderBook, decodeHolderPosition, decodeLaunchV2 } from "./layouts.js";
|
|
16
|
+
import { CLAIM_HOLDER, claimInstructionV2, seatAgencyPda } from "./solana.js";
|
|
17
17
|
|
|
18
18
|
export const MAX_TX_ACCOUNT_LOCKS_V2 = 64;
|
|
19
19
|
|
|
@@ -39,6 +39,21 @@ export function holderOwedNowV2(p
|
|
|
39
39
|
return holderTake(b, q);
|
|
40
40
|
}
|
|
41
41
|
|
|
42
|
+
export function seatAgencyOf(p ) {
|
|
43
|
+
const t = decodeTeamSlot(p.teamSlotData);
|
|
44
|
+
if (t.launch !== p.launch) throw new RangeError("this TeamSlot is not the launch's");
|
|
45
|
+
const k = addressBytes(p.wallet);
|
|
46
|
+
const mine = (m ) => m.state === MEMBER_IN && m.kind === KIND_WALLET && (m.key ).every((x, j) => x === k[j]);
|
|
47
|
+
|
|
48
|
+
if (!(t.members ).some((m) => mine(m) && m.agencyBps > 0)) return null;
|
|
49
|
+
const index = (t.members ).findIndex(mine);
|
|
50
|
+
const address = seatAgencyPda(p.launch, index, p.programId ?? FLOOR_AMM_PROGRAM_ID)[0];
|
|
51
|
+
if (!p.seatAgencyData) return { index, address, agency: null };
|
|
52
|
+
const a = decodeAccountV2("SeatAgency", p.seatAgencyData);
|
|
53
|
+
if (a.launch !== p.launch || a.index !== index) throw new RangeError(`this SeatAgency is not seat ${index}'s of the launch (${address})`);
|
|
54
|
+
return { index, address, agency: a.agency };
|
|
55
|
+
}
|
|
56
|
+
|
|
42
57
|
export const claimBitsV2 = (o ) =>
|
|
43
58
|
(o.creator > 0n ? CLAIM_CREATOR : 0) | (o.creatorRef > 0n ? CLAIM_CREATOR_REF : 0) | (o.teamSlot > 0n ? CLAIM_TEAM_SLOT : 0) |
|
|
44
59
|
(o.teamBuy > 0n ? CLAIM_TEAM_BUY : 0) | (o.shareBought > 0n ? CLAIM_SHARE_BOUGHT : 0) | (o.holder > 0n ? CLAIM_HOLDER : 0);
|
|
@@ -63,7 +78,9 @@ export function launchOwedV2(p
|
|
|
63
78
|
const k = addressBytes(p.wallet);
|
|
64
79
|
const i = (t.members ).findIndex((m) => m.state === MEMBER_IN && m.kind === KIND_WALLET && (m.key ).every((x, j) => x === k[j]));
|
|
65
80
|
if (i >= 0) {
|
|
66
|
-
|
|
81
|
+
|
|
82
|
+
const m = (t.members )[i];
|
|
83
|
+
owed.teamSlot = seatNet(a.slotOwed[i], m.dealFeeBps ?? 0, m.agencyBps ?? 0);
|
|
67
84
|
places[i] = true;
|
|
68
85
|
}
|
|
69
86
|
}
|
|
@@ -83,9 +100,11 @@ export function launchOwedV2(p
|
|
|
83
100
|
if (due) owed.teamBuy += buy[i];
|
|
84
101
|
owed.shareBought += a.slotBoughtOwed[i];
|
|
85
102
|
}
|
|
103
|
+
const sa = p.teamSlot ? seatAgencyOf({ wallet: p.wallet, launch: p.launch, teamSlotData: p.teamSlot.data, seatAgencyData: p.seatAgency, programId: p.programId }) : null;
|
|
86
104
|
return {
|
|
87
105
|
launch: p.launch, quoteMint: a.quoteMint, quoteTokenProgram: a.quoteTokenProgram, quoteVault: a.quoteVault, baseMint: a.baseMint,
|
|
88
106
|
tokenVault: a.tokenVault, teamSlot: p.teamSlot?.address ?? null, owed,
|
|
107
|
+
...(sa ? (sa.agency ? { seatAgency: { index: sa.index, agency: sa.agency } } : { seatAgencyMissing: sa.address }) : {}),
|
|
89
108
|
};
|
|
90
109
|
}
|
|
91
110
|
|
|
@@ -141,12 +160,16 @@ export function planClaimAllV2(p
|
|
|
141
160
|
const build = (ls , refs ) => {
|
|
142
161
|
const types = ls.reduce((a, l) => a | claimBitsV2(l.owed), 0) | (refs > 0n ? CLAIM_TRADER_REF : 0);
|
|
143
162
|
const tok = (types & (CLAIM_TEAM_BUY | CLAIM_SHARE_BOUGHT)) !== 0;
|
|
163
|
+
if ((types & CLAIM_TEAM_SLOT) !== 0) {
|
|
164
|
+
const miss = ls.find((l) => l.seatAgencyMissing);
|
|
165
|
+
if (miss) throw new RangeError(`launch ${miss.launch}: the wallet's seat carries an agency: read its SeatAgency ${miss.seatAgencyMissing} into launchOwedV2`);
|
|
166
|
+
}
|
|
144
167
|
const ro = refOwedPda(p.wallet, quoteMint, pid)[0];
|
|
145
168
|
const claim = claimInstructionV2({
|
|
146
169
|
sender, wallet: p.wallet, quoteMint, quoteTokenProgram: g.tp, destination: associatedTokenAddress(p.wallet, quoteMint, g.tp),
|
|
147
170
|
config: configPda(pid)[0], refOwed: refs > 0n ? ro : null, refOwedVault: refs > 0n ? refOwedVault(ro, quoteMint, g.tp) : null, types,
|
|
148
171
|
launches: ls.map((l) => ({
|
|
149
|
-
launch: l.launch, quoteVault: l.quoteVault, teamSlot: l.teamSlot, baseMint: l.baseMint,
|
|
172
|
+
launch: l.launch, quoteVault: l.quoteVault, teamSlot: l.teamSlot, baseMint: l.baseMint, ...(l.seatAgency ? { seatAgency: l.seatAgency } : {}),
|
|
150
173
|
...(tok ? { teamBuy: { baseMint: l.baseMint, tokenVault: l.tokenVault, walletBase: associatedTokenAddress(p.wallet, l.baseMint, TOKEN_2022_PROGRAM_ID) } } : {}),
|
|
151
174
|
})),
|
|
152
175
|
unwrap, quoteIsLaunch: p.launchQuotes?.includes(quoteMint) ?? false, programId: p.programId, hookProgramId: p.hookProgramId,
|
package/dist/v2/devbuy.js
CHANGED
|
@@ -16,12 +16,34 @@ export function teamSlotWallets(slot ) {
|
|
|
16
16
|
return (slot?.members ?? []).filter((m) => m.kind === TEAM_SLOT_WALLET && m.state === SLOT_ACTIVE).map((m) => base58Encode(m.key));
|
|
17
17
|
}
|
|
18
18
|
|
|
19
|
+
export function ownProofOf(tradeLogIndex , proofs ) {
|
|
20
|
+
let own = null;
|
|
21
|
+
for (const p of proofs) if (p.logIndex > tradeLogIndex && (own === null || p.logIndex < own.logIndex)) own = p;
|
|
22
|
+
return own;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
export function routedPerson(
|
|
26
|
+
t ,
|
|
27
|
+
own ,
|
|
28
|
+
same = (a, b) => a === b,
|
|
29
|
+
) {
|
|
30
|
+
if (own === null) return t.trader;
|
|
31
|
+
if (own.name !== "Zapped" && own.launch !== t.launch) {
|
|
32
|
+
if (t.recipient !== undefined && same(t.recipient, own.emitter) && same(t.trader, own.sender) && !same(t.trader, own.emitter)) return own.emitter;
|
|
33
|
+
return t.trader;
|
|
34
|
+
}
|
|
35
|
+
if (!same(own.emitter, t.trader)) return t.trader;
|
|
36
|
+
if (t.isBuy && own.name !== "Sold" && t.recipient !== undefined && same(t.recipient, own.to) && same(own.sender, own.to)) return own.sender;
|
|
37
|
+
if (!t.isBuy && own.name === "Sold" && t.recipient !== undefined && same(t.recipient, t.trader)) return own.sender;
|
|
38
|
+
return t.trader;
|
|
39
|
+
}
|
|
40
|
+
|
|
19
41
|
export const impactBps = (before , after ) => (before === 0n ? 0n : ((after - before) * 10_000n) / before);
|
|
20
42
|
|
|
21
|
-
export function devBuyFromTrade(t , team , ctx
|
|
43
|
+
export function devBuyFromTrade(t , team , ctx = {}) {
|
|
22
44
|
if (!t.isBuy) return null;
|
|
23
45
|
|
|
24
|
-
const person = ctx.buyer ?? t.trader;
|
|
46
|
+
const person = ctx.buyer ?? (ctx.own === undefined ? t.trader : routedPerson(t, ctx.own, ctx.same));
|
|
25
47
|
let role = null;
|
|
26
48
|
if (t.kind === TRADE_KIND_TEAM_BUY || ctx.teamBuy) role = "team_buy";
|
|
27
49
|
else if (t.kind === TRADE_KIND_TEAM_SHARE_BUY || ctx.teamShareBuy) role = "team_share_buy";
|
|
@@ -42,9 +64,12 @@ export function memberSoldFromTrade(
|
|
|
42
64
|
t ,
|
|
43
65
|
seats ,
|
|
44
66
|
same = (a, b) => a === b,
|
|
67
|
+
own ,
|
|
45
68
|
) {
|
|
46
69
|
if (t.isBuy) return null;
|
|
47
|
-
|
|
70
|
+
|
|
71
|
+
const seller = own === undefined ? t.trader : routedPerson({ ...t, isBuy: false }, own, same);
|
|
72
|
+
for (const who of t.recipient === undefined ? [seller] : [seller, t.recipient]) {
|
|
48
73
|
const held = seats.filter((s) => same(s.wallet, who));
|
|
49
74
|
if (held.length === 0) continue;
|
|
50
75
|
const seat = held.reduce((lo, s) => (s.place < lo.place ? s : lo));
|
package/dist/v2/events.js
CHANGED
|
@@ -24,6 +24,8 @@ export const EVENTS_V2 = {
|
|
|
24
24
|
HolderPositionClosed: S(["launch", "pubkey"], ["owner", "pubkey"], ["amount", "u64"], ["paid", "u64"]),
|
|
25
25
|
HolderIndexRolled: S(["launch", "pubkey"], ["index", "u128"], ["wMatured", "u64"], ["wPending", "u64"], ["carry", "u64"]),
|
|
26
26
|
DeadSynced: S(["launch", "pubkey"], ["added", "u64"], ["deadTokens", "u64"], ["sCirc", "u64"]),
|
|
27
|
+
|
|
28
|
+
RefSlices: S(["launch", "pubkey"], ["trader", "pubkey"], ["traderParts", "u64[3]"], ["creatorParts", "u64[3]"], ["og", "u8"]),
|
|
27
29
|
};
|
|
28
30
|
|
|
29
31
|
EVENTS_V2.GenesisRaiseBought = EVENTS_V2.Trade;
|
package/dist/v2/evm.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
|
|
2
2
|
|
|
3
|
-
import { decodeAbi, encodeAbi, encodeCall, eventTopic, functionSelector, hexToBytes, bytesToHex } from "../evm/abi.js";
|
|
3
|
+
import { checksumAddress, decodeAbi, encodeAbi, encodeCall, eventTopic, functionSelector, hexToBytes, bytesToHex } from "../evm/abi.js";
|
|
4
4
|
import { keccak256 } from "../evm/keccak.js";
|
|
5
5
|
|
|
6
6
|
import { claimCall } from "../evm/floor/calls.js";
|
|
@@ -11,6 +11,8 @@ import { buy } from "../math/v2/trade.js";
|
|
|
11
11
|
|
|
12
12
|
import { evmSignature } from "../generated/index.js";
|
|
13
13
|
import { CLAIM_BITS, CLAIM_KNOWN_MASKS } from "../generated/index.js";
|
|
14
|
+
import { slotMemberKeyEvm } from "./tx/evm.js";
|
|
15
|
+
|
|
14
16
|
import { EVM_EVENT_SCHEMAS } from "../abi/evm.gen.js";
|
|
15
17
|
import { V2_EVENT_FIELD_NAMES } from "../abi/evm-event-names.js";
|
|
16
18
|
|
|
@@ -20,7 +22,7 @@ export const CLAIM_KNOWN_V2_EVM = CLAIM_KNOWN_MASKS.evm.v2;
|
|
|
20
22
|
|
|
21
23
|
const BOOK_RANGE = "(uint128,uint128,uint64,uint64,uint64,uint128,uint16,uint16,uint8,uint8)";
|
|
22
24
|
|
|
23
|
-
const LAUNCH_BOOK = `(uint128,uint128,uint128,uint128[],uint8,${BOOK_RANGE}[48],uint128,uint64,uint64[],uint128[],uint8,uint8,uint128[],uint128[],uint128,uint64,bool,uint32[5],uint128,uint64,bool)`;
|
|
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],uint128,uint64,bool,uint32)`;
|
|
24
26
|
|
|
25
27
|
const BUY_OUT = "(uint256,uint256,uint256,uint128,uint8,bool,bool)";
|
|
26
28
|
|
|
@@ -64,6 +66,8 @@ export const V2_TOKEN_VIEWS = {
|
|
|
64
66
|
|
|
65
67
|
export const V2_CALLS = {
|
|
66
68
|
creditBacking: evmSignature("creditBacking"),
|
|
69
|
+
|
|
70
|
+
creditPlatform: evmSignature("creditPlatform"),
|
|
67
71
|
} ;
|
|
68
72
|
|
|
69
73
|
export const V2_TOKEN_CALLS = {
|
|
@@ -90,6 +94,17 @@ export function creditBackingCall(amm , launchId , quote ,
|
|
|
90
94
|
return call(amm, V2_CALLS.creditBacking, [launchId, amount], quote.toLowerCase() === NATIVE ? amount : 0n);
|
|
91
95
|
}
|
|
92
96
|
|
|
97
|
+
export function creditPlatformCall(amm , launchId , quote , amount , memo = new Uint8Array(32)) {
|
|
98
|
+
if (amount <= 0n) throw new RangeError("creditPlatform: amount must be > 0 (NothingToDo)");
|
|
99
|
+
if (memo.length !== 32) throw new RangeError("creditPlatform: the memo is 32 bytes");
|
|
100
|
+
return call(amm, V2_CALLS.creditPlatform, [launchId, amount, memo], quote.toLowerCase() === NATIVE ? amount : 0n);
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
export function setDealFeeCapCall(amm , capBps ) {
|
|
104
|
+
if (!Number.isInteger(capBps) || capBps < 0 || capBps > 5000) throw new RangeError("setDealFeeCap: capBps in 0..=5000");
|
|
105
|
+
return call(amm, evmSignature("setDealFeeCap"), [BigInt(capBps)]);
|
|
106
|
+
}
|
|
107
|
+
|
|
93
108
|
export function claimV2Call(p ) {
|
|
94
109
|
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)");
|
|
95
110
|
if ((p.types & CLAIM_HOLDER_EVM) === 0) return claimCall(p);
|
|
@@ -119,7 +134,14 @@ function one(name , data )
|
|
|
119
134
|
}
|
|
120
135
|
|
|
121
136
|
export function decodeLaunchBook(data ) {
|
|
122
|
-
|
|
137
|
+
|
|
138
|
+
const [t] = (() => {
|
|
139
|
+
try {
|
|
140
|
+
return one("launchBook", data) ;
|
|
141
|
+
} catch {
|
|
142
|
+
return decodeAbi([LAUNCH_BOOK.replace(/,uint32\)$/, ")")], data) ;
|
|
143
|
+
}
|
|
144
|
+
})();
|
|
123
145
|
const nR = n(t[4]);
|
|
124
146
|
const ranges = (t[5] ).slice(0, nR).map((r) => ({
|
|
125
147
|
sqrtA: big(r[0]), sqrtB: big(r[1]), tokens: big(r[2]), askLeft: big(r[3]), back: big(r[4]), place: big(r[5]),
|
|
@@ -130,6 +152,7 @@ export function decodeLaunchBook(data ) {
|
|
|
130
152
|
sqrtLMax: big(t[6]), floorTokens: big(t[7]), bandTokens: bigs(t[8]), bandEdge: bigs(t[9]), nBands: n(t[10]), nC: n(t[11]),
|
|
131
153
|
bandF: bigs(t[12]), bandFClaim: bigs(t[13]), ckAtF: big(t[14]), ckFloorTokens: big(t[15]), graduated: t[16] , feePpm: nums(t[17]),
|
|
132
154
|
kAtF: big(t[18]), kFloorTokens: big(t[19]), kpot: t[20] ,
|
|
155
|
+
...(t.length > 21 && n(t[21]) !== 0 && { kKept: n(t[21]) }),
|
|
133
156
|
};
|
|
134
157
|
}
|
|
135
158
|
export function decodeSimBuy(data ) {
|
|
@@ -193,8 +216,16 @@ export const V2_EVENTS = Object.fromEntries(
|
|
|
193
216
|
|
|
194
217
|
export const V2_EVENTS_ELSEWHERE = [
|
|
195
218
|
"Initialized", "LaunchCreated", "PayoutOwed", "TeamSlotOpened", "Upgraded", "Approval", "Transfer", "EIP712DomainChanged", "Claimed", "ClaimSkipped",
|
|
196
|
-
"HolderWithdrawn", "PlatformWithdrawn", "PayoutClaimed", "PotsSwept", "TeamBuyClaimed", "TeamShareBoughtClaimed", "CreatorBuyUnlocked",
|
|
219
|
+
"HolderWithdrawn", "PlatformWithdrawn", "PayoutClaimed", "PotsSwept", "BookRelayed" , "TeamBuyClaimed", "TeamShareBoughtClaimed", "CreatorBuyUnlocked",
|
|
197
220
|
"TeamSlotMember",
|
|
221
|
+
"DealFeePaid", "PlatformCredited", "TeamSlotDealFee",
|
|
222
|
+
"DealEscrowOpened", "DealEscrowArmed", "DealEscrowReleased", "DealEscrowRefunded", "DealEscrowCancelAgreed", "DealEscrowCancelled",
|
|
223
|
+
"DealEscrowTermsV3", "DealEscrowSplit", "DealEscrowProofSubmitted", "DealEscrowProofObjected",
|
|
224
|
+
"TeamSlotAgency", "TeamSlotAgencyPaid",
|
|
225
|
+
|
|
226
|
+
"ConfigWritten", "HandleBound", "HandleOwedMoved", "MetadataBaseSet", "NativeCreateFeeSet", "PriceUpdaterSet", "QuoteCapSet",
|
|
227
|
+
"QuoteWritten", "TraderRefCleared", "TraderRefOpened", "TreasurySet",
|
|
228
|
+
"DealFeeCapSet",
|
|
198
229
|
] ;
|
|
199
230
|
|
|
200
231
|
let topics ;
|
|
@@ -222,6 +253,8 @@ export const V2_ERRORS_EVM = [
|
|
|
222
253
|
"NotProgram",
|
|
223
254
|
|
|
224
255
|
"BadMember",
|
|
256
|
+
|
|
257
|
+
"OgFull", "OgAlreadySet",
|
|
225
258
|
] ;
|
|
226
259
|
|
|
227
260
|
export const V2_ERRORS_ARGS_EVM = ["UnknownClaimType(uint256)"] ;
|
|
@@ -254,7 +287,7 @@ export function evmSettleInputsV2(b , row , sup , m
|
|
|
254
287
|
bandEdge: pad(b.bandEdge, BIDS_MAX + 1, 0n).slice(0, BIDS_MAX + 1), bandMoney: pad(b.bandMoney, BIDS_MAX, 0n).slice(0, BIDS_MAX),
|
|
255
288
|
bandTokens: pad(b.bandTokens, BIDS_MAX, 0n).slice(0, BIDS_MAX), bandF: pad(b.bandF, BIDS_MAX, 0n).slice(0, BIDS_MAX),
|
|
256
289
|
bandFClaim: pad(b.bandFClaim, BIDS_MAX, 0n).slice(0, BIDS_MAX), ckAtF: b.ckAtF, ckFloorTokens: b.ckFloorTokens,
|
|
257
|
-
kpot: b.kpot, kAtF: b.kAtF, kFloorTokens: b.kFloorTokens,
|
|
290
|
+
kpot: b.kpot, kAtF: b.kAtF, kFloorTokens: b.kFloorTokens, ...(b.kKept ? { kKept: b.kKept } : {}),
|
|
258
291
|
feePpm: [...b.feePpm], graduated: b.graduated,
|
|
259
292
|
|
|
260
293
|
feeStartPpm: curve ? [...curve.feeStartPpm] : [0, 0, 0, 0, 0], sqrtFeeA: curve?.sqrtFeeA ?? 0n, sqrtFeeB: curve?.sqrtFeeB ?? 0n,
|
|
@@ -299,3 +332,148 @@ export async function readHolderV2(
|
|
|
299
332
|
const standing = holderStandingV2({ address: p.address, code, optedIn: decodeOptedIn(opted), program: p.program });
|
|
300
333
|
return { amount: x.amount, owed: x.owed, indexSnap: x.indexSnap, standing, optIn: standing.weight === "contract-not-opted-in" ? optInCall(p.token) : null };
|
|
301
334
|
}
|
|
335
|
+
|
|
336
|
+
export const DEAL_V3_STEP = { mcap: 0, volume: 1, upfront: 2 } ;
|
|
337
|
+
|
|
338
|
+
export const DEAL_V3_PROOF = { none: 0, waiting: 1, submitted: 2, objected: 3, resubmitted: 4 } ;
|
|
339
|
+
export const DEAL_AGENCY_BPS_MAX = 3_000;
|
|
340
|
+
export const DEAL_PROOF_WINDOW_SECS = 86_400n;
|
|
341
|
+
|
|
342
|
+
const DEAL_TERMS_V3 = "(uint8[],uint256[],uint256[],uint8,address,uint16,int64)";
|
|
343
|
+
export const DEAL_V3_CALLS = {
|
|
344
|
+
dealEscrowOpenV3: `dealEscrowOpenV3(uint256,address,bytes32,bool,${DEAL_TERMS_V3})`,
|
|
345
|
+
dealEscrowArmV3: "dealEscrowArmV3(bytes32,uint8)",
|
|
346
|
+
dealEscrowReleaseV3: "dealEscrowReleaseV3(bytes32,uint8)",
|
|
347
|
+
dealEscrowSubmitProof: "dealEscrowSubmitProof(bytes32,uint8,bytes32)",
|
|
348
|
+
dealEscrowObject: "dealEscrowObject(bytes32,uint8)",
|
|
349
|
+
teamSlotAddDealV3: "teamSlotAddDealV3(uint256,bytes32,uint8,uint256,uint16,address,uint16)",
|
|
350
|
+
} ;
|
|
351
|
+
export const DEAL_V3_VIEWS = {
|
|
352
|
+
refVolume: { sig: "refVolume(uint256,address)", ret: ["uint256"] },
|
|
353
|
+
teamSlotAgencyOf: { sig: "teamSlotAgencyOf(uint256,uint8)", ret: ["address", "uint16"] },
|
|
354
|
+
dealEscrowV3Of: {
|
|
355
|
+
sig: "dealEscrowV3Of(bytes32)",
|
|
356
|
+
ret: ["(uint8,uint8[8],uint8[8],int64[8],bytes32[8],address,uint16,uint256,uint256)"],
|
|
357
|
+
},
|
|
358
|
+
} ;
|
|
359
|
+
|
|
360
|
+
const stepOk = (name , step ) => {
|
|
361
|
+
if (!Number.isInteger(step) || step < 0 || step > 7) throw new RangeError(`${name}: step in 0..8 (DealEscrowSteps)`);
|
|
362
|
+
return BigInt(step);
|
|
363
|
+
};
|
|
364
|
+
|
|
365
|
+
export function dealEscrowOpenV3Call(p ) {
|
|
366
|
+
const t = p.terms;
|
|
367
|
+
const n = t.kinds.length;
|
|
368
|
+
if (n < 1 || n > 8 || t.targets.length !== n || t.amounts.length !== n) throw new RangeError("dealEscrowOpenV3: 1..=8 steps, one target and amount each (DealEscrowSteps)");
|
|
369
|
+
if (!Number.isInteger(t.proofMask) || t.proofMask < 0 || t.proofMask >> n !== 0) throw new RangeError("dealEscrowOpenV3: proofMask bits only below n (DealEscrowSteps)");
|
|
370
|
+
if (t.kinds.some((k) => k !== 0 && k !== 1 && k !== 2)) throw new RangeError("dealEscrowOpenV3: kinds are 0 (market cap), 1 (volume), 2 (up front)");
|
|
371
|
+
const hasAgency = t.agency.toLowerCase() !== NATIVE;
|
|
372
|
+
if (hasAgency !== (t.agencyBps !== 0) || t.agencyBps < 0 || t.agencyBps > DEAL_AGENCY_BPS_MAX) throw new RangeError("dealEscrowOpenV3: an agency needs 1..=3000 bps, none needs 0 (DealEscrowAgency)");
|
|
373
|
+
if (p.ref32.length !== 32) throw new RangeError("dealEscrowOpenV3: ref32 is 32 bytes");
|
|
374
|
+
const total = t.amounts.reduce((a, b) => a + b, 0n);
|
|
375
|
+
const value = !p.assetIsToken && p.quote.toLowerCase() === NATIVE ? total : 0n;
|
|
376
|
+
const terms = [t.kinds.map(BigInt), [...t.targets], [...t.amounts], BigInt(t.proofMask), t.agency, BigInt(t.agencyBps), t.expiry];
|
|
377
|
+
return call(p.floorAmm, DEAL_V3_CALLS.dealEscrowOpenV3, [p.launchId, p.kol, p.ref32, p.assetIsToken, terms], value);
|
|
378
|
+
}
|
|
379
|
+
|
|
380
|
+
export const dealEscrowArmV3Call = (floorAmm , escrow , step ) =>
|
|
381
|
+
call(floorAmm, DEAL_V3_CALLS.dealEscrowArmV3, [hexToBytes(escrow), stepOk("dealEscrowArmV3", step)]);
|
|
382
|
+
|
|
383
|
+
export const dealEscrowReleaseV3Call = (floorAmm , escrow , step ) =>
|
|
384
|
+
call(floorAmm, DEAL_V3_CALLS.dealEscrowReleaseV3, [hexToBytes(escrow), stepOk("dealEscrowReleaseV3", step)]);
|
|
385
|
+
|
|
386
|
+
export function dealEscrowSubmitProofCall(floorAmm , escrow , step , proofHash ) {
|
|
387
|
+
if (proofHash.length !== 32) throw new RangeError("dealEscrowSubmitProof: the hash is 32 bytes");
|
|
388
|
+
return call(floorAmm, DEAL_V3_CALLS.dealEscrowSubmitProof, [hexToBytes(escrow), stepOk("dealEscrowSubmitProof", step), proofHash]);
|
|
389
|
+
}
|
|
390
|
+
|
|
391
|
+
export const dealEscrowObjectCall = (floorAmm , escrow , step ) =>
|
|
392
|
+
call(floorAmm, DEAL_V3_CALLS.dealEscrowObject, [hexToBytes(escrow), stepOk("dealEscrowObject", step)]);
|
|
393
|
+
|
|
394
|
+
export function teamSlotAddDealV3Call(p ) {
|
|
395
|
+
if (p.shares <= 0n) throw new RangeError("teamSlotAddDealV3: shares > 0 (NothingToDo)");
|
|
396
|
+
if (!Number.isInteger(p.dealFeeBps) || p.dealFeeBps < 0 || p.dealFeeBps > 0xffff) throw new RangeError("teamSlotAddDealV3: dealFeeBps is a uint16");
|
|
397
|
+
const hasAgency = p.agency.toLowerCase() !== NATIVE;
|
|
398
|
+
if (!Number.isInteger(p.agencyBps) || hasAgency !== (p.agencyBps !== 0) || p.agencyBps < 0 || p.agencyBps > DEAL_AGENCY_BPS_MAX) {
|
|
399
|
+
throw new RangeError("teamSlotAddDealV3: an agency needs 1..=3000 bps, none needs 0 (DealEscrowAgency)");
|
|
400
|
+
}
|
|
401
|
+
const { key, kind } = slotMemberKeyEvm(p.member);
|
|
402
|
+
return call(p.floorAmm, DEAL_V3_CALLS.teamSlotAddDealV3, [p.launchId, hexToBytes(key), BigInt(kind), p.shares, BigInt(p.dealFeeBps), p.agency, BigInt(p.agencyBps)]);
|
|
403
|
+
}
|
|
404
|
+
|
|
405
|
+
export const teamSlotAgencyOfData = (launchId , place ) => {
|
|
406
|
+
if (!Number.isInteger(place) || place < 0 || place > 9) throw new RangeError("teamSlotAgencyOf: place in 0..10 (BadArgument)");
|
|
407
|
+
return bytesToHex(encodeCall(DEAL_V3_VIEWS.teamSlotAgencyOf.sig, [launchId, BigInt(place)]));
|
|
408
|
+
};
|
|
409
|
+
export function decodeTeamSlotAgencyOf(data ) {
|
|
410
|
+
const [a, bps] = decodeAbi(DEAL_V3_VIEWS.teamSlotAgencyOf.ret, data) ;
|
|
411
|
+
return a.toLowerCase() === NATIVE && bps === 0n ? null : { agency: checksumAddress(a), agencyBps: Number(bps) };
|
|
412
|
+
}
|
|
413
|
+
|
|
414
|
+
export const refVolumeData = (launchId , referrer ) => bytesToHex(encodeCall(DEAL_V3_VIEWS.refVolume.sig, [launchId, referrer]));
|
|
415
|
+
export const dealEscrowV3OfData = (escrow ) => bytesToHex(encodeCall(DEAL_V3_VIEWS.dealEscrowV3Of.sig, [hexToBytes(escrow)]));
|
|
416
|
+
export const decodeRefVolume = (data ) => decodeAbi(DEAL_V3_VIEWS.refVolume.ret, data)[0] ;
|
|
417
|
+
|
|
418
|
+
export function decodeDealEscrowV3Of(data ) {
|
|
419
|
+
const v = decodeAbi(DEAL_V3_VIEWS.dealEscrowV3Of.ret, data)[0] ;
|
|
420
|
+
const nums = (x ) => (x ).map(Number);
|
|
421
|
+
return {
|
|
422
|
+
version: Number(v[0]),
|
|
423
|
+
kinds: nums(v[1]),
|
|
424
|
+
proof: nums(v[2]),
|
|
425
|
+
proofEnds: v[3] ,
|
|
426
|
+
proofHash: (v[4] ).map((b) => (typeof b === "string" ? b : bytesToHex(b))),
|
|
427
|
+
agency: checksumAddress(v[5] ),
|
|
428
|
+
agencyBps: Number(v[6]),
|
|
429
|
+
volAtLock: v[7] ,
|
|
430
|
+
volumeNow: v[8] ,
|
|
431
|
+
};
|
|
432
|
+
}
|
|
433
|
+
|
|
434
|
+
export const DEAL_V3_EVENTS = {
|
|
435
|
+
DealEscrowTermsV3: {
|
|
436
|
+
sig: "DealEscrowTermsV3(uint256,bytes32,bytes32,uint8[],uint8,address,uint16,uint256)",
|
|
437
|
+
indexed: ["launchId", "escrow"],
|
|
438
|
+
names: ["launchId", "escrow", "ref32", "kinds", "proofMask", "agency", "agencyBps", "volAtLock"],
|
|
439
|
+
},
|
|
440
|
+
DealEscrowSplit: {
|
|
441
|
+
sig: "DealEscrowSplit(uint256,bytes32,bytes32,uint8,uint8,address,uint256,address,uint256,address[3],uint256[3],uint256)",
|
|
442
|
+
indexed: ["launchId", "escrow", "kol"],
|
|
443
|
+
names: ["launchId", "escrow", "ref32", "step", "kind", "kol", "kolPart", "agency", "agencyPart", "tiers", "refs", "feeRest"],
|
|
444
|
+
},
|
|
445
|
+
DealEscrowProofSubmitted: {
|
|
446
|
+
sig: "DealEscrowProofSubmitted(uint256,bytes32,bytes32,uint8,bytes32,uint8,int64)",
|
|
447
|
+
indexed: ["launchId", "escrow"],
|
|
448
|
+
names: ["launchId", "escrow", "ref32", "step", "proofHash", "state", "windowEnds"],
|
|
449
|
+
},
|
|
450
|
+
DealEscrowProofObjected: {
|
|
451
|
+
sig: "DealEscrowProofObjected(uint256,bytes32,bytes32,uint8)",
|
|
452
|
+
indexed: ["launchId", "escrow"],
|
|
453
|
+
names: ["launchId", "escrow", "ref32", "step"],
|
|
454
|
+
},
|
|
455
|
+
} ;
|
|
456
|
+
|
|
457
|
+
let dealTopics ;
|
|
458
|
+
const DEAL_TOPICS = () =>
|
|
459
|
+
(dealTopics ??= new Map((Object.keys(DEAL_V3_EVENTS) ).map((k) => [eventTopic(DEAL_V3_EVENTS[k].sig), k])));
|
|
460
|
+
export const dealV3EventTopic = (name ) => eventTopic(DEAL_V3_EVENTS[name].sig);
|
|
461
|
+
|
|
462
|
+
export function decodeDealV3Log(log ) {
|
|
463
|
+
const name = DEAL_TOPICS().get((log.topics[0] ?? "").toLowerCase());
|
|
464
|
+
if (!name) return null;
|
|
465
|
+
const ev = DEAL_V3_EVENTS[name];
|
|
466
|
+
const types = ev.sig.slice(ev.sig.indexOf("(") + 1, -1).split(",");
|
|
467
|
+
const idx = new Set (ev.indexed);
|
|
468
|
+
if (log.topics.length !== 1 + idx.size) throw new RangeError(`${name}: ${log.topics.length - 1} indexed topics, want ${idx.size}`);
|
|
469
|
+
const fields = {};
|
|
470
|
+
let t = 1;
|
|
471
|
+
const bodyTypes = [];
|
|
472
|
+
const bodyNames = [];
|
|
473
|
+
ev.names.forEach((n, i) => {
|
|
474
|
+
if (idx.has(n)) fields[n] = decodeAbi([types[i]], hexToBytes(log.topics[t++]))[0];
|
|
475
|
+
else (bodyTypes.push(types[i]), bodyNames.push(n));
|
|
476
|
+
});
|
|
477
|
+
decodeAbi(bodyTypes, log.data).forEach((v, i) => (fields[bodyNames[i]] = v));
|
|
478
|
+
return { name, fields };
|
|
479
|
+
}
|
package/dist/v2/layouts.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
|
|
2
2
|
|
|
3
|
-
import { hex } from "../codec.js";
|
|
3
|
+
import { base58Encode, hex } from "../codec.js";
|
|
4
4
|
import { accountDiscriminator } from "../solana/instruction.js";
|
|
5
5
|
import { AccountDecodeError, decodeStruct, encodeStruct, layoutSize } from "../solana/floor/accounts.js";
|
|
6
6
|
|
|
@@ -134,7 +134,9 @@ export const LAUNCH_V2 = [
|
|
|
134
134
|
["k_at_f", "u64"],
|
|
135
135
|
["k_floor_tokens", "u64"],
|
|
136
136
|
["kpot", "u8"],
|
|
137
|
-
|
|
137
|
+
|
|
138
|
+
["k_kept", "bytes:3"],
|
|
139
|
+
["creator_ref_og_until", "u32[3]"],
|
|
138
140
|
];
|
|
139
141
|
|
|
140
142
|
export const HOLDER_POSITION = [
|
|
@@ -177,6 +179,85 @@ export const DEAD_MARK = [
|
|
|
177
179
|
["counted", "u64"],
|
|
178
180
|
];
|
|
179
181
|
|
|
182
|
+
export const DEAL_ESCROW = [
|
|
183
|
+
["version", "u8"],
|
|
184
|
+
["bump", "u8"],
|
|
185
|
+
["n", "u8"],
|
|
186
|
+
["kind", "u8"],
|
|
187
|
+
["released", "u8"],
|
|
188
|
+
["refunded", "u8"],
|
|
189
|
+
["decimals", "u8"],
|
|
190
|
+
["pad_fee_bps", "u8"],
|
|
191
|
+
["fee_bps", "u16"],
|
|
192
|
+
["cancel", "u8"],
|
|
193
|
+
["pad_expiry", "bytes:5"],
|
|
194
|
+
["expiry", "i64"],
|
|
195
|
+
["opened_at", "i64"],
|
|
196
|
+
["launch", "pubkey"],
|
|
197
|
+
["launcher", "pubkey"],
|
|
198
|
+
["kol", "pubkey"],
|
|
199
|
+
["asset_mint", "pubkey"],
|
|
200
|
+
["asset_token_program", "pubkey"],
|
|
201
|
+
["vault", "pubkey"],
|
|
202
|
+
["ref32", "bytes:32"],
|
|
203
|
+
["targets", "u128l[8]"],
|
|
204
|
+
["amounts", "u64[8]"],
|
|
205
|
+
["armed_at", "i64[8]"],
|
|
206
|
+
["armed_slot", "u64[8]"],
|
|
207
|
+
|
|
208
|
+
["agency", "pubkey"],
|
|
209
|
+
["vol_at_lock", "u128l"],
|
|
210
|
+
["proof_ends", "i64[8]"],
|
|
211
|
+
["proof_hash", "bytes:32[8]"],
|
|
212
|
+
["kinds", "u8[8]"],
|
|
213
|
+
["proof", "u8[8]"],
|
|
214
|
+
["agency_bps", "u16"],
|
|
215
|
+
|
|
216
|
+
["vol_src", "u8"],
|
|
217
|
+
|
|
218
|
+
["pad_size", "bytes:13"],
|
|
219
|
+
];
|
|
220
|
+
|
|
221
|
+
export const DEAL_ESCROW_SIZE = 976;
|
|
222
|
+
|
|
223
|
+
export const DEAL_ESCROW_V3_VERSION = 3;
|
|
224
|
+
|
|
225
|
+
export const REF_VOLUME = [
|
|
226
|
+
["launch", "pubkey"],
|
|
227
|
+
["referrer", "pubkey"],
|
|
228
|
+
["volume", "u128l"],
|
|
229
|
+
["bump", "u8"],
|
|
230
|
+
["pad_size", "bytes:15"],
|
|
231
|
+
];
|
|
232
|
+
export const REF_VOLUME_SIZE = 96;
|
|
233
|
+
|
|
234
|
+
export const SEAT_AGENCY_LAYOUT = [
|
|
235
|
+
["launch", "pubkey"],
|
|
236
|
+
["agency", "pubkey"],
|
|
237
|
+
["agency_bps", "u16"],
|
|
238
|
+
["index", "u8"],
|
|
239
|
+
["bump", "u8"],
|
|
240
|
+
["pad_size", "bytes:4"],
|
|
241
|
+
];
|
|
242
|
+
export const SEAT_AGENCY_SIZE = 72;
|
|
243
|
+
|
|
244
|
+
export const REF_VOLUME_ENTRY = [
|
|
245
|
+
["referrer", "pubkey"],
|
|
246
|
+
["volume", "u128l"],
|
|
247
|
+
];
|
|
248
|
+
export const REF_VOLUME_BOOK = [
|
|
249
|
+
["launch", "pubkey"],
|
|
250
|
+
["len", "u8"],
|
|
251
|
+
["bump", "u8"],
|
|
252
|
+
["pad_entries", "bytes:14"],
|
|
253
|
+
["entries", "bytes:1536"],
|
|
254
|
+
];
|
|
255
|
+
export const REF_VOLUME_BOOK_SIZE = 1584;
|
|
256
|
+
export const REF_VOLUME_BOOK_CAP = 32;
|
|
257
|
+
|
|
258
|
+
export const VOL_SRC_REF_VOLUME = 0;
|
|
259
|
+
export const VOL_SRC_BOOK = 1;
|
|
260
|
+
|
|
180
261
|
export const LOTS_MAX = 16;
|
|
181
262
|
export const MEMBERS_MAX = 10;
|
|
182
263
|
|
|
@@ -188,6 +269,10 @@ export const LAYOUTS_V2 = {
|
|
|
188
269
|
HolderPosition: HOLDER_POSITION,
|
|
189
270
|
HolderBook: HOLDER_BOOK,
|
|
190
271
|
DeadMark: DEAD_MARK,
|
|
272
|
+
DealEscrow: DEAL_ESCROW,
|
|
273
|
+
RefVolume: REF_VOLUME,
|
|
274
|
+
RefVolumeBook: REF_VOLUME_BOOK,
|
|
275
|
+
SeatAgency: SEAT_AGENCY_LAYOUT,
|
|
191
276
|
} ;
|
|
192
277
|
|
|
193
278
|
export function decodeAccountV2(name , data ) {
|
|
@@ -219,3 +304,18 @@ export const decodePresetRowV2 = (d ) => decodeAccountV2("PresetRowV2
|
|
|
219
304
|
export const decodeHolderPosition = (d ) => decodeAccountV2("HolderPosition", d);
|
|
220
305
|
export const decodeHolderBook = (d ) => decodeAccountV2("HolderBook", d);
|
|
221
306
|
export const decodeDeadMark = (d ) => decodeAccountV2("DeadMark", d);
|
|
307
|
+
|
|
308
|
+
export const decodeDealEscrow = (d ) => decodeAccountV2("DealEscrow", d);
|
|
309
|
+
|
|
310
|
+
export const decodeRefVolume = (d ) => decodeAccountV2("RefVolume", d);
|
|
311
|
+
|
|
312
|
+
export function refVolumeBookEntries(book ) {
|
|
313
|
+
const out = [];
|
|
314
|
+
for (let i = 0; i < Math.min(book.len, REF_VOLUME_BOOK_CAP); i++) {
|
|
315
|
+
const e = book.entries.subarray(48 * i, 48 * i + 48);
|
|
316
|
+
let v = 0n;
|
|
317
|
+
for (let j = 47; j >= 32; j--) v = (v << 8n) | BigInt(e[j]);
|
|
318
|
+
out.push({ referrer: base58Encode(e.subarray(0, 32)), volume: v });
|
|
319
|
+
}
|
|
320
|
+
return out;
|
|
321
|
+
}
|
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
|
|
2
|
+
|
|
3
|
+
import { hex } from "../codec.js";
|
|
4
|
+
import { EVENT_IX_TAG_LE, eventDiscriminator } from "../solana/instruction.js";
|
|
5
|
+
import { Reader, Writer } from "../solana/floor/borsh.js";
|
|
6
|
+
import { base58Encode } from "../codec.js";
|
|
7
|
+
import { decodeAbi, eventTopic, hexToBytes } from "../evm/abi.js";
|
|
8
|
+
|
|
9
|
+
const S = (...f ) => f;
|
|
10
|
+
|
|
11
|
+
export const OFFICE_EVENTS = {
|
|
12
|
+
OfficeOpened: S(["officeId", "id"], ["controller", "addr"], ["quote", "addr"]),
|
|
13
|
+
OfficeMemberAdded: S(["officeId", "id"], ["member", "addr"]),
|
|
14
|
+
OfficeMemberLeft: S(["officeId", "id"], ["member", "addr"], ["byController", "bool"], ["units", "amt"], ["cashOut", "amt64"], ["launches", "launches"], ["tokensOut", "toksV"]),
|
|
15
|
+
OfficeDeposit: S(["officeId", "id"], ["member", "addr"], ["amount", "amt64"], ["units", "amt"], ["valueBefore", "amt"], ["unitsTotal", "amt"]),
|
|
16
|
+
OfficeShareSet: S(["officeId", "id"], ["member", "addr"], ["shareBps", "u16"], ["shareSum", "u16"]),
|
|
17
|
+
OfficeBuy: S(["officeId", "id"], ["buyer", "addr"], ["launch", "launch"], ["gross", "amt64"], ["tokens", "tok"], ["refund", "amt64"]),
|
|
18
|
+
OfficeSell: S(["officeId", "id"], ["seller", "addr"], ["buyer", "addr"], ["launch", "launch"], ["tokens", "tok"], ["out", "amt64"], ["unfilled", "tok"]),
|
|
19
|
+
OfficeControllerProposed: S(["officeId", "id"], ["member", "addr"]),
|
|
20
|
+
OfficeControllerSet: S(["officeId", "id"], ["controller", "addr"]),
|
|
21
|
+
OfficeMergeProposed: S(["officeId", "id"], ["other", "id"], ["newController", "addr"]),
|
|
22
|
+
OfficeMergeCancelled: S(["officeId", "id"]),
|
|
23
|
+
OfficeMerged: S(["officeId", "id"], ["other", "id"], ["newController", "addr"], ["unitsFrom", "amt"], ["unitsTo", "amt"], ["valueFrom", "amt"], ["valueTo", "amt"]),
|
|
24
|
+
|
|
25
|
+
OfficeMergeStarted: S(["officeId", "id"], ["other", "id"], ["newController", "addr"], ["unitsFrom", "amt"], ["valueFrom", "amt"], ["valueTo", "amt"], ["members", "u16"]),
|
|
26
|
+
|
|
27
|
+
OfficeMergeStep: S(["officeId", "id"], ["other", "id"], ["moved", "u16"], ["left", "u16"], ["unitsTo", "amt"]),
|
|
28
|
+
|
|
29
|
+
OfficePayoutOwed: S(["officeId", "id"], ["member", "addr"], ["amount", "amt64"]),
|
|
30
|
+
};
|
|
31
|
+
export const OFFICE_EVENT_NAMES = Object.keys(OFFICE_EVENTS);
|
|
32
|
+
|
|
33
|
+
export const OFFICE_UNFILLED_LEN = 6;
|
|
34
|
+
|
|
35
|
+
function solRead(r , k ) {
|
|
36
|
+
switch (k) {
|
|
37
|
+
case "id": return hex(r.bytes(32));
|
|
38
|
+
case "addr":
|
|
39
|
+
case "launch": return base58Encode(r.bytes(32));
|
|
40
|
+
case "bool": return r.bool();
|
|
41
|
+
case "u16": return r.u16();
|
|
42
|
+
case "amt": return r.u128();
|
|
43
|
+
case "amt64": return r.u64();
|
|
44
|
+
case "tok": return r.u64();
|
|
45
|
+
case "toks": return Array.from({ length: OFFICE_UNFILLED_LEN }, () => r.u64());
|
|
46
|
+
case "launches": return Array.from({ length: r.u32() }, () => base58Encode(r.bytes(32)));
|
|
47
|
+
case "toksV": return Array.from({ length: r.u32() }, () => r.u64());
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
function solWrite(w , k , v ) {
|
|
51
|
+
switch (k) {
|
|
52
|
+
case "id": w.bytes(hexToBytes(v)); break;
|
|
53
|
+
case "addr":
|
|
54
|
+
case "launch": w.pubkey(v); break;
|
|
55
|
+
case "bool": w.bool(v); break;
|
|
56
|
+
case "u16": w.u16(v); break;
|
|
57
|
+
case "amt": w.u128(v); break;
|
|
58
|
+
case "amt64": w.u64(v); break;
|
|
59
|
+
case "tok": w.u64(v); break;
|
|
60
|
+
case "toks":
|
|
61
|
+
if (v.length !== OFFICE_UNFILLED_LEN) throw new RangeError(`tokensUnfilled: ${OFFICE_UNFILLED_LEN} values`);
|
|
62
|
+
for (const x of v) w.u64(x);
|
|
63
|
+
break;
|
|
64
|
+
case "launches": w.u32(v.length); for (const x of v) w.pubkey(x); break;
|
|
65
|
+
case "toksV": w.u32(v.length); for (const x of v) w.u64(x); break;
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
let disc ;
|
|
70
|
+
const DISC = () => (disc ??= new Map(OFFICE_EVENT_NAMES.map((n) => [hex(eventDiscriminator(n)), n])));
|
|
71
|
+
|
|
72
|
+
export function decodeOfficeEventData(data ) {
|
|
73
|
+
const name = DISC().get(hex(data.slice(0, 8)));
|
|
74
|
+
if (!name) return null;
|
|
75
|
+
const r = new Reader(data.slice(8));
|
|
76
|
+
const fields = {};
|
|
77
|
+
for (const [f, k] of OFFICE_EVENTS[name]) fields[f] = solRead(r, k);
|
|
78
|
+
if (r.o !== r.b.length) throw new RangeError(`${name}: ${r.b.length} body bytes, the schema reads ${r.o}`);
|
|
79
|
+
return { name, fields };
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
export function encodeOfficeEventData(e ) {
|
|
83
|
+
const w = new Writer().bytes(eventDiscriminator(e.name));
|
|
84
|
+
for (const [f, k] of OFFICE_EVENTS[e.name] ?? []) solWrite(w, k, e.fields[f]);
|
|
85
|
+
return w.done();
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
export function decodeOfficeEventCpi(ixData ) {
|
|
89
|
+
if (ixData.length < 16 || hex(ixData.slice(0, 8)) !== hex(EVENT_IX_TAG_LE)) return null;
|
|
90
|
+
return decodeOfficeEventData(ixData.slice(8));
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
const EVM_TYPE = { id: "bytes32", addr: "address", launch: "uint256", bool: "bool", u16: "uint16", amt: "uint256", amt64: "uint256", tok: "uint256", toks: "uint256[]", launches: "uint256[]", toksV: "uint256[]" };
|
|
94
|
+
|
|
95
|
+
export const officeEventSignature = (name ) => `${name}(${OFFICE_EVENTS[name].map(([, k]) => EVM_TYPE[k]).join(",")})`;
|
|
96
|
+
|
|
97
|
+
export const OFFICE_LOG_TOPICS = new Map(OFFICE_EVENT_NAMES.map((n) => [eventTopic(officeEventSignature(n)), n]));
|
|
98
|
+
|
|
99
|
+
const EVM_INDEXED = {
|
|
100
|
+
OfficeOpened: ["officeId", "controller"], OfficeMemberAdded: ["officeId", "member"], OfficeMemberLeft: ["officeId", "member"],
|
|
101
|
+
OfficeDeposit: ["officeId", "member"], OfficeShareSet: ["officeId", "member"], OfficeBuy: ["officeId", "buyer", "launch"],
|
|
102
|
+
OfficeSell: ["officeId", "seller", "launch"], OfficeControllerProposed: ["officeId", "member"], OfficeControllerSet: ["officeId", "controller"],
|
|
103
|
+
OfficeMergeProposed: ["officeId", "other"], OfficeMergeCancelled: ["officeId"], OfficeMerged: ["officeId", "other"], OfficeMergeStarted: ["officeId", "other"], OfficeMergeStep: ["officeId", "other"], OfficePayoutOwed: ["officeId", "member"],
|
|
104
|
+
};
|
|
105
|
+
const topicWord = (t , k ) => {
|
|
106
|
+
const h = t.toLowerCase();
|
|
107
|
+
return k === "addr" ? "0x" + h.slice(-40) : k === "launch" ? String(BigInt(h)) : h;
|
|
108
|
+
};
|
|
109
|
+
|
|
110
|
+
export function decodeOfficeLog(log ) {
|
|
111
|
+
const name = OFFICE_LOG_TOPICS.get(log.topics[0]?.toLowerCase() ?? "");
|
|
112
|
+
if (!name) return null;
|
|
113
|
+
const spec = OFFICE_EVENTS[name];
|
|
114
|
+
const n = log.topics.length - 1;
|
|
115
|
+
const table = EVM_INDEXED[name] ?? [];
|
|
116
|
+
const idx = n === table.length ? table : spec.slice(0, n).map(([f]) => f);
|
|
117
|
+
const dataSpec = spec.filter(([f]) => !idx.includes(f));
|
|
118
|
+
const vals = dataSpec.length === 0 ? [] : decodeAbi(dataSpec.map(([, k]) => EVM_TYPE[k]), log.data);
|
|
119
|
+
const fields = {};
|
|
120
|
+
let ti = 1;
|
|
121
|
+
for (const [f, k] of spec.filter(([f]) => idx.includes(f))) fields[f] = topicWord(log.topics[ti++], k);
|
|
122
|
+
dataSpec.forEach(([f, k], i) => {
|
|
123
|
+
const v = vals[i];
|
|
124
|
+
fields[f] = k === "launch" ? String(v) : k === "launches" ? (v ).map(String) : k === "id" || k === "addr" ? String(v).toLowerCase() : v;
|
|
125
|
+
});
|
|
126
|
+
return { name, fields };
|
|
127
|
+
}
|