@percolatorct/sdk 1.0.0-beta.3 → 1.0.0-beta.31
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/README.md +13 -4
- package/dist/abi/accounts.d.ts +57 -18
- package/dist/abi/errors.d.ts +0 -11
- package/dist/abi/index.d.ts +1 -0
- package/dist/abi/instructions.d.ts +379 -146
- package/dist/abi/nft.d.ts +134 -0
- package/dist/config/program-ids.d.ts +2 -2
- package/dist/index.js +1531 -604
- package/dist/index.js.map +1 -1
- package/dist/math/trading.d.ts +1 -116
- package/dist/math/warmup.d.ts +0 -50
- package/dist/runtime/lighthouse.d.ts +1 -1
- package/dist/solana/discovery.d.ts +2 -13
- package/dist/solana/oracle.d.ts +2 -10
- package/dist/solana/pda.d.ts +5 -5
- package/dist/solana/slab.d.ts +132 -5
- package/dist/solana/stake.d.ts +27 -2
- package/dist/validation.d.ts +1 -26
- package/package.json +2 -1
package/dist/math/trading.d.ts
CHANGED
|
@@ -10,68 +10,20 @@
|
|
|
10
10
|
*/
|
|
11
11
|
/**
|
|
12
12
|
* Compute mark-to-market PnL for an open position.
|
|
13
|
-
*
|
|
14
|
-
* @param positionSize - Signed position size (positive = long, negative = short).
|
|
15
|
-
* @param entryPrice - Entry price in e6 format (1 USD = 1_000_000).
|
|
16
|
-
* @param oraclePrice - Current oracle price in e6 format.
|
|
17
|
-
* @returns PnL in native token units (positive = profit, negative = loss).
|
|
18
|
-
*
|
|
19
|
-
* @example
|
|
20
|
-
* ```ts
|
|
21
|
-
* // Long 10 SOL at $100, oracle now $110 → profit
|
|
22
|
-
* const pnl = computeMarkPnl(10_000_000n, 100_000_000n, 110_000_000n);
|
|
23
|
-
* ```
|
|
24
13
|
*/
|
|
25
14
|
export declare function computeMarkPnl(positionSize: bigint, entryPrice: bigint, oraclePrice: bigint): bigint;
|
|
26
15
|
/**
|
|
27
16
|
* Compute liquidation price given entry, capital, position and maintenance margin.
|
|
28
17
|
* Uses pure BigInt arithmetic for precision (no Number() truncation).
|
|
29
|
-
*
|
|
30
|
-
* @param entryPrice - Entry price in e6 format.
|
|
31
|
-
* @param capital - Account capital in native token units.
|
|
32
|
-
* @param positionSize - Signed position size (positive = long, negative = short).
|
|
33
|
-
* @param maintenanceMarginBps - Maintenance margin requirement in basis points (e.g. 500n = 5%).
|
|
34
|
-
* @returns Liquidation price in e6 format. Returns 0n for longs that can't be liquidated,
|
|
35
|
-
* or max u64 for shorts with ≥100% maintenance margin.
|
|
36
|
-
*
|
|
37
|
-
* @example
|
|
38
|
-
* ```ts
|
|
39
|
-
* // Long 1 SOL at $100, $10 capital, 5% maintenance margin
|
|
40
|
-
* const liqPrice = computeLiqPrice(100_000_000n, 10_000_000n, 1_000_000n, 500n);
|
|
41
|
-
* ```
|
|
42
18
|
*/
|
|
43
19
|
export declare function computeLiqPrice(entryPrice: bigint, capital: bigint, positionSize: bigint, maintenanceMarginBps: bigint): bigint;
|
|
44
20
|
/**
|
|
45
21
|
* Compute estimated liquidation price BEFORE opening a trade.
|
|
46
22
|
* Accounts for trading fees reducing effective capital.
|
|
47
|
-
*
|
|
48
|
-
* @param oracleE6 - Current oracle price in e6 format (used as entry estimate).
|
|
49
|
-
* @param margin - Deposit margin in native token units.
|
|
50
|
-
* @param posSize - Intended position size (absolute value used internally).
|
|
51
|
-
* @param maintBps - Maintenance margin in basis points.
|
|
52
|
-
* @param feeBps - Trading fee in basis points.
|
|
53
|
-
* @param direction - Trade direction: `"long"` or `"short"`.
|
|
54
|
-
* @returns Estimated liquidation price in e6 format.
|
|
55
|
-
*
|
|
56
|
-
* @example
|
|
57
|
-
* ```ts
|
|
58
|
-
* const liq = computePreTradeLiqPrice(
|
|
59
|
-
* 100_000_000n, 10_000_000n, 1_000_000n, 500n, 30n, "long"
|
|
60
|
-
* );
|
|
61
|
-
* ```
|
|
62
23
|
*/
|
|
63
24
|
export declare function computePreTradeLiqPrice(oracleE6: bigint, margin: bigint, posSize: bigint, maintBps: bigint, feeBps: bigint, direction: "long" | "short"): bigint;
|
|
64
25
|
/**
|
|
65
26
|
* Compute trading fee from notional value and fee rate in bps.
|
|
66
|
-
*
|
|
67
|
-
* @param notional - Trade notional value in native token units.
|
|
68
|
-
* @param tradingFeeBps - Fee rate in basis points (e.g. 30n = 0.30%).
|
|
69
|
-
* @returns Fee amount in native token units.
|
|
70
|
-
*
|
|
71
|
-
* @example
|
|
72
|
-
* ```ts
|
|
73
|
-
* const fee = computeTradingFee(1_000_000_000n, 30n); // 0.30% of 1 SOL
|
|
74
|
-
* ```
|
|
75
27
|
*/
|
|
76
28
|
export declare function computeTradingFee(notional: bigint, tradingFeeBps: bigint): bigint;
|
|
77
29
|
/**
|
|
@@ -137,86 +89,19 @@ export declare function computeFeeSplit(totalFee: bigint, config: FeeSplitConfig
|
|
|
137
89
|
export declare function computePnlPercent(pnlTokens: bigint, capital: bigint): number;
|
|
138
90
|
/**
|
|
139
91
|
* Estimate entry price including fee impact (slippage approximation).
|
|
140
|
-
*
|
|
141
|
-
* @param oracleE6 - Current oracle price in e6 format.
|
|
142
|
-
* @param tradingFeeBps - Trading fee in basis points.
|
|
143
|
-
* @param direction - Trade direction: `"long"` or `"short"`.
|
|
144
|
-
* @returns Estimated entry price in e6 format (higher for longs, lower for shorts).
|
|
145
|
-
*
|
|
146
|
-
* @example
|
|
147
|
-
* ```ts
|
|
148
|
-
* const entry = computeEstimatedEntryPrice(100_000_000n, 30n, "long");
|
|
149
|
-
* // → 100_030_000n (oracle + 0.30% fee impact)
|
|
150
|
-
* ```
|
|
151
92
|
*/
|
|
152
93
|
export declare function computeEstimatedEntryPrice(oracleE6: bigint, tradingFeeBps: bigint, direction: "long" | "short"): bigint;
|
|
153
94
|
/**
|
|
154
95
|
* Convert per-slot funding rate (bps) to annualized percentage.
|
|
155
|
-
*
|
|
156
|
-
* @param fundingRateBpsPerSlot - Funding rate per slot in basis points (i64 from engine state).
|
|
157
|
-
* @returns Annualized funding rate as a percentage (e.g. 12.5 = 12.5% APR).
|
|
158
|
-
* @throws Error if the value exceeds Number.MAX_SAFE_INTEGER.
|
|
159
|
-
*
|
|
160
|
-
* @example
|
|
161
|
-
* ```ts
|
|
162
|
-
* const apr = computeFundingRateAnnualized(1n); // ~78.84% APR
|
|
163
|
-
* ```
|
|
164
96
|
*/
|
|
165
97
|
export declare function computeFundingRateAnnualized(fundingRateBpsPerSlot: bigint): number;
|
|
166
98
|
/**
|
|
167
99
|
* Compute margin required for a given notional and initial margin bps.
|
|
168
|
-
*
|
|
169
|
-
* @param notional - Trade notional value in native token units.
|
|
170
|
-
* @param initialMarginBps - Initial margin requirement in basis points (e.g. 1000n = 10%).
|
|
171
|
-
* @returns Required margin in native token units.
|
|
172
|
-
*
|
|
173
|
-
* @example
|
|
174
|
-
* ```ts
|
|
175
|
-
* const margin = computeRequiredMargin(10_000_000_000n, 1000n); // 10% of notional
|
|
176
|
-
* // → 1_000_000_000n
|
|
177
|
-
* ```
|
|
178
100
|
*/
|
|
179
101
|
export declare function computeRequiredMargin(notional: bigint, initialMarginBps: bigint): bigint;
|
|
180
102
|
/**
|
|
181
103
|
* Compute maximum leverage from initial margin bps.
|
|
182
104
|
*
|
|
183
|
-
*
|
|
184
|
-
* Uses scaled arithmetic to preserve precision for fractional leverage values.
|
|
185
|
-
*
|
|
186
|
-
* @param initialMarginBps - Initial margin requirement in basis points (e.g. 500n = 5% → 20x).
|
|
187
|
-
* @returns Maximum leverage as a number (e.g. 20 for 500 bps, 3.003 for 3333 bps).
|
|
188
|
-
* @throws Error if initialMarginBps is zero (infinite leverage is undefined).
|
|
189
|
-
*
|
|
190
|
-
* @example
|
|
191
|
-
* ```ts
|
|
192
|
-
* const maxLev = computeMaxLeverage(500n); // → 20
|
|
193
|
-
* const maxLev2 = computeMaxLeverage(1000n); // → 10
|
|
194
|
-
* const maxLev3 = computeMaxLeverage(3333n); // → 3.003 (not truncated to 3)
|
|
195
|
-
* ```
|
|
105
|
+
* @throws Error if initialMarginBps is zero (infinite leverage is undefined)
|
|
196
106
|
*/
|
|
197
107
|
export declare function computeMaxLeverage(initialMarginBps: bigint): number;
|
|
198
|
-
/**
|
|
199
|
-
* Compute the maximum amount that can be withdrawn from a position.
|
|
200
|
-
*
|
|
201
|
-
* The withdrawable amount is the capital plus any matured (unreserved) PnL.
|
|
202
|
-
* Reserved PnL is still locked and cannot be withdrawn until the warmup period elapses.
|
|
203
|
-
*
|
|
204
|
-
* Formula: max_withdrawable = capital + max(0, pnl - reserved_pnl)
|
|
205
|
-
*
|
|
206
|
-
* @param capital - Capital allocated to the position (in native token units)
|
|
207
|
-
* @param pnl - Mark-to-market PnL (in native token units, can be negative)
|
|
208
|
-
* @param reservedPnl - PnL that is still locked during warmup (always non-negative)
|
|
209
|
-
* @returns The maximum amount in native units that can be withdrawn without closing the position
|
|
210
|
-
*
|
|
211
|
-
* @example
|
|
212
|
-
* ```ts
|
|
213
|
-
* // Position: 10 SOL capital, +2 SOL mark PnL, 0.5 SOL reserved
|
|
214
|
-
* const max = computeMaxWithdrawable(
|
|
215
|
-
* 10_000_000_000n, // 10 SOL in lamports
|
|
216
|
-
* 2_000_000_000n, // +2 SOL in lamports
|
|
217
|
-
* 500_000_000n // 0.5 SOL reserved in lamports
|
|
218
|
-
* );
|
|
219
|
-
* // Returns: 11_500_000_000n (10 + (2 - 0.5) = 11.5 SOL in lamports)
|
|
220
|
-
* ```
|
|
221
|
-
*/
|
|
222
|
-
export declare function computeMaxWithdrawable(capital: bigint, pnl: bigint, reservedPnl: bigint): bigint;
|
package/dist/math/warmup.d.ts
CHANGED
|
@@ -53,53 +53,3 @@ export declare function computeWarmupLeverageCap(initialMarginBps: bigint, total
|
|
|
53
53
|
* @returns Maximum position size in native units.
|
|
54
54
|
*/
|
|
55
55
|
export declare function computeWarmupMaxPositionSize(initialMarginBps: bigint, totalCapital: bigint, currentSlot: bigint, warmupStartSlot: bigint, warmupPeriodSlots: bigint): bigint;
|
|
56
|
-
/**
|
|
57
|
-
* Warmup progress information for a position.
|
|
58
|
-
*/
|
|
59
|
-
export interface WarmupProgress {
|
|
60
|
-
/** PnL available for withdrawal right now (not locked by warmup). */
|
|
61
|
-
maturedPnl: bigint;
|
|
62
|
-
/** PnL still locked until warmup completes. */
|
|
63
|
-
reservedPnl: bigint;
|
|
64
|
-
/** Progress toward full warmup as a basis point (0–10,000). */
|
|
65
|
-
progressBps: bigint;
|
|
66
|
-
/** Slots remaining until full warmup (0 if fully matured). */
|
|
67
|
-
slotsRemaining: bigint;
|
|
68
|
-
}
|
|
69
|
-
/**
|
|
70
|
-
* Compute PnL warmup progress for a position.
|
|
71
|
-
*
|
|
72
|
-
* During the warmup period, a position's unrealized PnL is linearly released.
|
|
73
|
-
* The portion available for withdrawal grows over time. This utility shows:
|
|
74
|
-
* - How much PnL is currently available (matured)
|
|
75
|
-
* - How much is still locked (reserved)
|
|
76
|
-
* - Progress toward full maturation (as %)
|
|
77
|
-
* - Slots remaining
|
|
78
|
-
*
|
|
79
|
-
* Users can display a progress bar or "unlocks in X slots" message to give
|
|
80
|
-
* transparency into when their PnL becomes withdrawable.
|
|
81
|
-
*
|
|
82
|
-
* @param currentSlot - Current on-chain slot (from engine state).
|
|
83
|
-
* @param warmupStartedAtSlot - Slot when this position's warmup started.
|
|
84
|
-
* @param warmupPeriodSlots - Total warmup duration in slots (from market config).
|
|
85
|
-
* @param pnl - Total realized + unrealized PnL (from account).
|
|
86
|
-
* @param reservedPnl - PnL locked during warmup (from account).
|
|
87
|
-
* @returns WarmupProgress with matured/reserved PnL, progress %, and slots remaining.
|
|
88
|
-
*
|
|
89
|
-
* @example
|
|
90
|
-
* ```ts
|
|
91
|
-
* const progress = computeWarmupProgress(
|
|
92
|
-
* 10000n, // current slot
|
|
93
|
-
* 9000n, // warmup started at slot 9000
|
|
94
|
-
* 2000n, // warmup period = 2000 slots
|
|
95
|
-
* 1000000000n, // pnl = 1 SOL
|
|
96
|
-
* 600000000n // reserved = 0.6 SOL (60% still locked)
|
|
97
|
-
* );
|
|
98
|
-
* // Returns:
|
|
99
|
-
* // maturedPnl: 400000000n (0.4 SOL available)
|
|
100
|
-
* // reservedPnl: 600000000n (0.6 SOL locked)
|
|
101
|
-
* // progressBps: 5000n (50% complete)
|
|
102
|
-
* // slotsRemaining: 1000n (1000 slots until fully mature)
|
|
103
|
-
* ```
|
|
104
|
-
*/
|
|
105
|
-
export declare function computeWarmupProgress(currentSlot: bigint, warmupStartedAtSlot: bigint, warmupPeriodSlots: bigint, pnl: bigint, reservedPnl: bigint): WarmupProgress;
|
|
@@ -55,7 +55,7 @@ export declare const LIGHTHOUSE_CONSTRAINT_ADDRESS = 6400;
|
|
|
55
55
|
* Known Lighthouse/Anchor error codes that may appear in transaction logs.
|
|
56
56
|
* All are in the Anchor error range (0x1770–0x1900+).
|
|
57
57
|
*/
|
|
58
|
-
export declare const LIGHTHOUSE_ERROR_CODES: Set<
|
|
58
|
+
export declare const LIGHTHOUSE_ERROR_CODES: Set<6400 | 6000 | 6001 | 6002 | 6003 | 6016 | 6032 | 6033 | 6034 | 6035 | 6036 | 6037 | 6038 | 6039 | 6040 | 6041 | 6042 | 6043>;
|
|
59
59
|
/**
|
|
60
60
|
* Check if a TransactionInstruction is from the Lighthouse program.
|
|
61
61
|
*
|
|
@@ -36,16 +36,11 @@ export interface DiscoveredMarket {
|
|
|
36
36
|
* in SLAB_TIERS_V0 for discovery of legacy on-chain accounts.
|
|
37
37
|
*/
|
|
38
38
|
/**
|
|
39
|
-
* Default slab tiers for the current mainnet program (v12.
|
|
39
|
+
* Default slab tiers for the current mainnet program (v12.17).
|
|
40
40
|
* These are used by useCreateMarket to allocate slab accounts of the correct size.
|
|
41
|
+
* V12_17: two-bucket warmup, per-side funding, ACCOUNT_SIZE=352 (SBF).
|
|
41
42
|
*/
|
|
42
43
|
export declare const SLAB_TIERS: {
|
|
43
|
-
readonly micro: {
|
|
44
|
-
maxAccounts: number;
|
|
45
|
-
dataSize: number;
|
|
46
|
-
label: string;
|
|
47
|
-
description: string;
|
|
48
|
-
};
|
|
49
44
|
readonly small: {
|
|
50
45
|
maxAccounts: number;
|
|
51
46
|
dataSize: number;
|
|
@@ -166,12 +161,6 @@ export declare const SLAB_TIERS_V1D_LEGACY: {
|
|
|
166
161
|
};
|
|
167
162
|
/** @deprecated Alias — use SLAB_TIERS (already V1) */
|
|
168
163
|
export declare const SLAB_TIERS_V1: {
|
|
169
|
-
readonly micro: {
|
|
170
|
-
maxAccounts: number;
|
|
171
|
-
dataSize: number;
|
|
172
|
-
label: string;
|
|
173
|
-
description: string;
|
|
174
|
-
};
|
|
175
164
|
readonly small: {
|
|
176
165
|
maxAccounts: number;
|
|
177
166
|
dataSize: number;
|
package/dist/solana/oracle.d.ts
CHANGED
|
@@ -16,19 +16,11 @@ declare const CHAINLINK_MIN_SIZE = 224;
|
|
|
16
16
|
declare const MAX_DECIMALS = 18;
|
|
17
17
|
/** Offset of decimals field in Chainlink aggregator account */
|
|
18
18
|
declare const CHAINLINK_DECIMALS_OFFSET = 138;
|
|
19
|
-
/** Offset of updated_at timestamp (i64 LE, Unix seconds) in Chainlink aggregator */
|
|
20
|
-
declare const CHAINLINK_TIMESTAMP_OFFSET = 168;
|
|
21
19
|
/** Offset of latest answer in Chainlink aggregator account */
|
|
22
20
|
declare const CHAINLINK_ANSWER_OFFSET = 216;
|
|
23
21
|
export interface OraclePrice {
|
|
24
22
|
price: bigint;
|
|
25
23
|
decimals: number;
|
|
26
|
-
/** Unix timestamp (seconds) of the last oracle update, if available. */
|
|
27
|
-
updatedAt?: number;
|
|
28
|
-
}
|
|
29
|
-
export interface ParseChainlinkOptions {
|
|
30
|
-
/** Maximum allowed staleness in seconds. If the oracle update is older, an error is thrown. */
|
|
31
|
-
maxStalenessSeconds?: number;
|
|
32
24
|
}
|
|
33
25
|
/**
|
|
34
26
|
* Parse price data from a Chainlink aggregator account buffer.
|
|
@@ -42,11 +34,11 @@ export interface ParseChainlinkOptions {
|
|
|
42
34
|
* @returns Parsed oracle price with decimals
|
|
43
35
|
* @throws if the buffer is invalid or contains unreasonable data
|
|
44
36
|
*/
|
|
45
|
-
export declare function parseChainlinkPrice(data: Uint8Array
|
|
37
|
+
export declare function parseChainlinkPrice(data: Uint8Array): OraclePrice;
|
|
46
38
|
/**
|
|
47
39
|
* Validate that a buffer looks like a valid Chainlink aggregator account.
|
|
48
40
|
* Returns true if the buffer passes all validation checks, false otherwise.
|
|
49
41
|
* Use this for non-throwing validation.
|
|
50
42
|
*/
|
|
51
43
|
export declare function isValidChainlinkOracle(data: Uint8Array): boolean;
|
|
52
|
-
export { CHAINLINK_MIN_SIZE, CHAINLINK_DECIMALS_OFFSET,
|
|
44
|
+
export { CHAINLINK_MIN_SIZE, CHAINLINK_DECIMALS_OFFSET, CHAINLINK_ANSWER_OFFSET, MAX_DECIMALS };
|
package/dist/solana/pda.d.ts
CHANGED
|
@@ -4,16 +4,16 @@ import { PublicKey } from "@solana/web3.js";
|
|
|
4
4
|
* Seeds: ["vault", slab_key]
|
|
5
5
|
*/
|
|
6
6
|
export declare function deriveVaultAuthority(programId: PublicKey, slab: PublicKey): [PublicKey, number];
|
|
7
|
+
/**
|
|
8
|
+
* Derive insurance LP mint PDA.
|
|
9
|
+
* Seeds: ["ins_lp", slab_key]
|
|
10
|
+
*/
|
|
11
|
+
export declare function deriveInsuranceLpMint(programId: PublicKey, slab: PublicKey): [PublicKey, number];
|
|
7
12
|
/**
|
|
8
13
|
* Derive LP PDA for TradeCpi.
|
|
9
14
|
* Seeds: ["lp", slab_key, lp_idx as u16 LE]
|
|
10
15
|
*/
|
|
11
16
|
export declare function deriveLpPda(programId: PublicKey, slab: PublicKey, lpIdx: number): [PublicKey, number];
|
|
12
|
-
/**
|
|
13
|
-
* Derive keeper fund PDA.
|
|
14
|
-
* Seeds: ["keeper_fund", slab_key]
|
|
15
|
-
*/
|
|
16
|
-
export declare function deriveKeeperFund(programId: PublicKey, slab: PublicKey): [PublicKey, number];
|
|
17
17
|
/** PumpSwap AMM program ID. */
|
|
18
18
|
export declare const PUMPSWAP_PROGRAM_ID: PublicKey;
|
|
19
19
|
/** Raydium CLMM (Concentrated Liquidity) program ID. */
|
package/dist/solana/slab.d.ts
CHANGED
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
import { Connection, PublicKey } from "@solana/web3.js";
|
|
2
|
+
/** Slab magic number ("PERCOLAT" as little-endian u64). */
|
|
3
|
+
export declare const SLAB_MAGIC: bigint;
|
|
2
4
|
/**
|
|
3
5
|
* Full slab layout descriptor. Returned by detectSlabLayout().
|
|
4
6
|
* All engine field offsets are relative to engineOff.
|
|
@@ -130,10 +132,35 @@ export declare const SLAB_TIERS_V12_1: Record<string, {
|
|
|
130
132
|
label: string;
|
|
131
133
|
description: string;
|
|
132
134
|
}>;
|
|
135
|
+
/**
|
|
136
|
+
* V12_15 slab tier sizes — percolator v12.15 (engine+prog sync).
|
|
137
|
+
* ENGINE_OFF=624, BITMAP_OFF=862 (relative), ACCOUNT_SIZE=4400, postBitmap=18.
|
|
138
|
+
* MAX_ACCOUNTS default changed from 4096 to 2048. Verified SLAB_LEN=1,128,448 for small (256).
|
|
139
|
+
* Account layout completely redesigned with reserve cohort arrays.
|
|
140
|
+
*/
|
|
141
|
+
export declare const SLAB_TIERS_V12_15: Record<string, {
|
|
142
|
+
maxAccounts: number;
|
|
143
|
+
dataSize: number;
|
|
144
|
+
label: string;
|
|
145
|
+
description: string;
|
|
146
|
+
}>;
|
|
147
|
+
/**
|
|
148
|
+
* V12_17 slab tier sizes — percolator v12.17 (two-bucket warmup, per-side funding).
|
|
149
|
+
* Uses SBF sizes (on-chain layout) for the dataSize values.
|
|
150
|
+
* ENGINE_OFF=504 (SBF), ACCOUNT_SIZE=352 (SBF), BITMAP_OFF=712 (SBF), postBitmap=4.
|
|
151
|
+
* RISK_BUF_LEN=160 appended after engine.
|
|
152
|
+
* Supported tiers: small(256), medium(1024), large(4096).
|
|
153
|
+
*/
|
|
154
|
+
export declare const SLAB_TIERS_V12_17: Record<string, {
|
|
155
|
+
maxAccounts: number;
|
|
156
|
+
dataSize: number;
|
|
157
|
+
label: string;
|
|
158
|
+
description: string;
|
|
159
|
+
}>;
|
|
133
160
|
/**
|
|
134
161
|
* Detect the slab layout version from the raw account data length.
|
|
135
162
|
* Returns the full SlabLayout descriptor, or null if the size is unrecognised.
|
|
136
|
-
* Checks V12_1, V_SETDEXPOOL, V1M2, V_ADL, V1M, V0, V1D, V1D-legacy, V1, and V1-legacy sizes.
|
|
163
|
+
* Checks V12_15, V12_1_EP, V12_1, V_SETDEXPOOL, V1M2, V_ADL, V1M, V0, V1D, V1D-legacy, V1, and V1-legacy sizes.
|
|
137
164
|
*
|
|
138
165
|
* When `data` is provided and the size matches V1D, the version field at offset 8 is read
|
|
139
166
|
* to disambiguate V2 slabs (which produce identical sizes to V1D with postBitmap=2).
|
|
@@ -181,10 +208,10 @@ export interface MarketConfig {
|
|
|
181
208
|
fundingInvScaleNotionalE6: bigint;
|
|
182
209
|
fundingMaxPremiumBps: bigint;
|
|
183
210
|
fundingMaxBpsPerSlot: bigint;
|
|
184
|
-
fundingPremiumWeightBps: bigint;
|
|
185
|
-
fundingSettlementIntervalSlots: bigint;
|
|
186
|
-
fundingPremiumDampeningE6: bigint;
|
|
187
|
-
fundingPremiumMaxBpsPerSlot: bigint;
|
|
211
|
+
/** @deprecated Removed in V12_1 — always 0 */ fundingPremiumWeightBps: bigint;
|
|
212
|
+
/** @deprecated Removed in V12_1 — always 0 */ fundingSettlementIntervalSlots: bigint;
|
|
213
|
+
/** @deprecated Removed in V12_1 — always 0 */ fundingPremiumDampeningE6: bigint;
|
|
214
|
+
/** @deprecated Removed in V12_1 — always 0 */ fundingPremiumMaxBpsPerSlot: bigint;
|
|
188
215
|
threshFloor: bigint;
|
|
189
216
|
threshRiskBps: bigint;
|
|
190
217
|
threshUpdateIntervalSlots: bigint;
|
|
@@ -229,6 +256,10 @@ export interface InsuranceFund {
|
|
|
229
256
|
isolationBps: number;
|
|
230
257
|
}
|
|
231
258
|
export interface RiskParams {
|
|
259
|
+
/**
|
|
260
|
+
* @deprecated Split into hMin/hMax in v12.15 RiskParams. On V12_15 slabs this field returns
|
|
261
|
+
* hMin for backwards compatibility. On pre-v12.15 slabs hMin/hMax both mirror this value.
|
|
262
|
+
*/
|
|
232
263
|
warmupPeriodSlots: bigint;
|
|
233
264
|
maintenanceMarginBps: bigint;
|
|
234
265
|
initialMarginBps: bigint;
|
|
@@ -242,6 +273,18 @@ export interface RiskParams {
|
|
|
242
273
|
liquidationFeeCap: bigint;
|
|
243
274
|
liquidationBufferBps: bigint;
|
|
244
275
|
minLiquidationAbs: bigint;
|
|
276
|
+
/** Minimum initial deposit to open an account (V12_1+ only) */
|
|
277
|
+
minInitialDeposit: bigint;
|
|
278
|
+
/** Minimum nonzero maintenance margin requirement (V12_1+ only) */
|
|
279
|
+
minNonzeroMmReq: bigint;
|
|
280
|
+
/** Minimum nonzero initial margin requirement (V12_1+ only) */
|
|
281
|
+
minNonzeroImReq: bigint;
|
|
282
|
+
/** Insurance fund floor (V12_1+ only) */
|
|
283
|
+
insuranceFloor: bigint;
|
|
284
|
+
/** Minimum horizon slots (v12.15+). Replaces warmupPeriodSlots. 0n on pre-v12.15 slabs. */
|
|
285
|
+
hMin: bigint;
|
|
286
|
+
/** Maximum horizon slots (v12.15+). 0n on pre-v12.15 slabs. */
|
|
287
|
+
hMax: bigint;
|
|
245
288
|
}
|
|
246
289
|
export interface EngineState {
|
|
247
290
|
vault: bigint;
|
|
@@ -249,7 +292,20 @@ export interface EngineState {
|
|
|
249
292
|
currentSlot: bigint;
|
|
250
293
|
fundingIndexQpbE6: bigint;
|
|
251
294
|
lastFundingSlot: bigint;
|
|
295
|
+
/**
|
|
296
|
+
* Funding rate per slot. On pre-v12.15 slabs: i64 in BPS units.
|
|
297
|
+
* On v12.15+ slabs: i128 in e9 units (field renamed `funding_rate_e9` on-chain).
|
|
298
|
+
*/
|
|
252
299
|
fundingRateBpsPerSlotLast: bigint;
|
|
300
|
+
/**
|
|
301
|
+
* Funding rate in e9 units (i128). v12.15+ only.
|
|
302
|
+
* 0n on pre-v12.15 slabs.
|
|
303
|
+
*/
|
|
304
|
+
fundingRateE9: bigint;
|
|
305
|
+
/**
|
|
306
|
+
* Market mode. v12.15+ only. 0 = Live, 1 = Resolved. null on pre-v12.15 slabs.
|
|
307
|
+
*/
|
|
308
|
+
marketMode: 0 | 1 | null;
|
|
253
309
|
lastCrankSlot: bigint;
|
|
254
310
|
maxCrankStalenessSlots: bigint;
|
|
255
311
|
totalOpenInterest: bigint;
|
|
@@ -257,6 +313,10 @@ export interface EngineState {
|
|
|
257
313
|
shortOi: bigint;
|
|
258
314
|
cTot: bigint;
|
|
259
315
|
pnlPosTot: bigint;
|
|
316
|
+
/**
|
|
317
|
+
* Matured (settled) positive PnL total (u128). v12.15+ only. 0n on pre-v12.15 slabs.
|
|
318
|
+
*/
|
|
319
|
+
pnlMaturedPosTot: bigint;
|
|
260
320
|
liqCursor: number;
|
|
261
321
|
gcCursor: number;
|
|
262
322
|
lastSweepStartSlot: bigint;
|
|
@@ -275,27 +335,94 @@ export interface EngineState {
|
|
|
275
335
|
numUsedAccounts: number;
|
|
276
336
|
nextAccountId: bigint;
|
|
277
337
|
markPriceE6: bigint;
|
|
338
|
+
/** last_oracle_price (u64, e6). V12_15+ only. 0n on pre-v12.15. */
|
|
339
|
+
oraclePriceE6: bigint;
|
|
340
|
+
/** Cumulative funding numerator for long side (i128). 0n on pre-v12.17. */
|
|
341
|
+
fLongNum: bigint;
|
|
342
|
+
/** Cumulative funding numerator for short side (i128). 0n on pre-v12.17. */
|
|
343
|
+
fShortNum: bigint;
|
|
344
|
+
/** Count of accounts with negative PnL. 0n on pre-v12.17. */
|
|
345
|
+
negPnlAccountCount: bigint;
|
|
346
|
+
/** Last funding-sample price (u64 e6). 0n on pre-v12.17. */
|
|
347
|
+
fundPxLast: bigint;
|
|
348
|
+
/** Matured positive PnL total (u128). v12.15+ only. 0n on pre-v12.15 slabs. */
|
|
349
|
+
resolvedKLongTerminalDelta: bigint;
|
|
350
|
+
/** Terminal K delta for short side (i128). 0n on pre-v12.17. */
|
|
351
|
+
resolvedKShortTerminalDelta: bigint;
|
|
352
|
+
/** Live oracle price used during resolution (u64 e6). 0n on pre-v12.17. */
|
|
353
|
+
resolvedLivePrice: bigint;
|
|
278
354
|
}
|
|
279
355
|
export declare enum AccountKind {
|
|
280
356
|
User = 0,
|
|
281
357
|
LP = 1
|
|
282
358
|
}
|
|
359
|
+
/** Parsed reserve cohort (64 bytes on-chain). Raw bytes; structure is program-internal. */
|
|
360
|
+
export type ReserveCohortBytes = Uint8Array;
|
|
283
361
|
export interface Account {
|
|
284
362
|
kind: AccountKind;
|
|
285
363
|
accountId: bigint;
|
|
286
364
|
capital: bigint;
|
|
287
365
|
pnl: bigint;
|
|
288
366
|
reservedPnl: bigint;
|
|
367
|
+
/** @deprecated Removed in v12.15. Always 0n on V12_15 slabs. */
|
|
289
368
|
warmupStartedAtSlot: bigint;
|
|
369
|
+
/** @deprecated Removed in v12.15. Always 0n on V12_15 slabs. */
|
|
290
370
|
warmupSlopePerStep: bigint;
|
|
291
371
|
positionSize: bigint;
|
|
372
|
+
/** Entry price in e6 units. Present in V12_15 (offset 120) and V_ADL/V12_1_EP. -1 signals absent. */
|
|
292
373
|
entryPrice: bigint;
|
|
293
374
|
fundingIndex: bigint;
|
|
294
375
|
matcherProgram: PublicKey;
|
|
295
376
|
matcherContext: PublicKey;
|
|
296
377
|
owner: PublicKey;
|
|
297
378
|
feeCredits: bigint;
|
|
379
|
+
/** @deprecated Removed in v12.15. Always 0n on V12_15 slabs. */
|
|
298
380
|
lastFeeSlot: bigint;
|
|
381
|
+
/** Total fees earned over account lifetime (u128). Present from v12.15. 0n on older layouts. */
|
|
382
|
+
feesEarnedTotal: bigint;
|
|
383
|
+
/**
|
|
384
|
+
* Reserve cohorts array (v12.15+). Up to 62 cohorts of 64 bytes each.
|
|
385
|
+
* `null` on pre-v12.15 slabs. Parse the raw bytes according to the on-chain ReserveCohort struct.
|
|
386
|
+
*/
|
|
387
|
+
exactReserveCohorts: ReserveCohortBytes[] | null;
|
|
388
|
+
/** Number of active reserve cohorts (0-62). null on pre-v12.15 slabs. */
|
|
389
|
+
exactCohortCount: number | null;
|
|
390
|
+
/** Overflow (oldest) cohort raw bytes. null on pre-v12.15 slabs or when not present. */
|
|
391
|
+
overflowOlder: ReserveCohortBytes | null;
|
|
392
|
+
/** True if overflowOlder contains valid data. null on pre-v12.15 slabs. */
|
|
393
|
+
overflowOlderPresent: boolean | null;
|
|
394
|
+
/** Overflow (newest) cohort raw bytes. null on pre-v12.15 slabs or when not present. */
|
|
395
|
+
overflowNewest: ReserveCohortBytes | null;
|
|
396
|
+
/** True if overflowNewest contains valid data. null on pre-v12.15 slabs. */
|
|
397
|
+
overflowNewestPresent: boolean | null;
|
|
398
|
+
/** Per-account cumulative funding snapshot (i128). 0n on pre-v12.17 slabs. */
|
|
399
|
+
fSnap: bigint;
|
|
400
|
+
/** ADL A-basis snapshot (u128). 0n on pre-v12.17 slabs. */
|
|
401
|
+
adlABasis: bigint;
|
|
402
|
+
/** ADL K-coefficient snapshot (i128). 0n on pre-v12.17 slabs. */
|
|
403
|
+
adlKSnap: bigint;
|
|
404
|
+
/** ADL epoch snapshot (u64). 0n on pre-v12.17 slabs. */
|
|
405
|
+
adlEpochSnap: bigint;
|
|
406
|
+
/** True if the scheduled warmup bucket is active. null on pre-v12.17. */
|
|
407
|
+
schedPresent: boolean | null;
|
|
408
|
+
/** Remaining unreleased quantity in scheduled bucket. null on pre-v12.17. */
|
|
409
|
+
schedRemainingQ: bigint | null;
|
|
410
|
+
/** Anchor quantity for scheduled bucket. null on pre-v12.17. */
|
|
411
|
+
schedAnchorQ: bigint | null;
|
|
412
|
+
/** Start slot for scheduled bucket. null on pre-v12.17. */
|
|
413
|
+
schedStartSlot: bigint | null;
|
|
414
|
+
/** Warmup horizon for scheduled bucket. null on pre-v12.17. */
|
|
415
|
+
schedHorizon: bigint | null;
|
|
416
|
+
/** Release quantity for scheduled bucket. null on pre-v12.17. */
|
|
417
|
+
schedReleaseQ: bigint | null;
|
|
418
|
+
/** True if the pending warmup bucket is active. null on pre-v12.17. */
|
|
419
|
+
pendingPresent: boolean | null;
|
|
420
|
+
/** Remaining unreleased quantity in pending bucket. null on pre-v12.17. */
|
|
421
|
+
pendingRemainingQ: bigint | null;
|
|
422
|
+
/** Warmup horizon for pending bucket. null on pre-v12.17. */
|
|
423
|
+
pendingHorizon: bigint | null;
|
|
424
|
+
/** Creation slot for pending bucket. null on pre-v12.17. */
|
|
425
|
+
pendingCreatedSlot: bigint | null;
|
|
299
426
|
}
|
|
300
427
|
export declare function fetchSlab(connection: Connection, slabPubkey: PublicKey): Promise<Uint8Array>;
|
|
301
428
|
export declare const RAMP_START_BPS = 1000n;
|
package/dist/solana/stake.d.ts
CHANGED
|
@@ -4,13 +4,13 @@
|
|
|
4
4
|
*
|
|
5
5
|
* Program: percolator-stake (dcccrypto/percolator-stake)
|
|
6
6
|
* Deployed devnet: 6aJb1F9CDCVWCNYFwj8aQsVb696YnW6J1FznteHq4Q6k
|
|
7
|
-
* Deployed mainnet:
|
|
7
|
+
* Deployed mainnet: DC5fovFQD5SZYsetwvEqd4Wi4PFY1Yfnc669VMe6oa7F
|
|
8
8
|
*/
|
|
9
9
|
import { PublicKey } from '@solana/web3.js';
|
|
10
10
|
/** Known stake program addresses per network. Mainnet is empty until deployed. */
|
|
11
11
|
export declare const STAKE_PROGRAM_IDS: {
|
|
12
12
|
readonly devnet: "6aJb1F9CDCVWCNYFwj8aQsVb696YnW6J1FznteHq4Q6k";
|
|
13
|
-
readonly mainnet: "";
|
|
13
|
+
readonly mainnet: "DC5fovFQD5SZYsetwvEqd4Wi4PFY1Yfnc669VMe6oa7F";
|
|
14
14
|
};
|
|
15
15
|
/**
|
|
16
16
|
* Resolve the stake program ID for the given network.
|
|
@@ -136,6 +136,31 @@ export declare const STAKE_POOL_SIZE = 352;
|
|
|
136
136
|
* Decode a StakePool account from raw data buffer. * Uses DataView for all u64/u16 reads — browser-safe.
|
|
137
137
|
*/
|
|
138
138
|
export declare function decodeStakePool(data: Uint8Array): StakePoolState;
|
|
139
|
+
/** Size of StakeDeposit on-chain (bytes). */
|
|
140
|
+
export declare const STAKE_DEPOSIT_SIZE = 152;
|
|
141
|
+
/** Decoded StakeDeposit PDA state. */
|
|
142
|
+
export interface StakeDepositState {
|
|
143
|
+
isInitialized: boolean;
|
|
144
|
+
bump: number;
|
|
145
|
+
pool: PublicKey;
|
|
146
|
+
user: PublicKey;
|
|
147
|
+
lastDepositSlot: bigint;
|
|
148
|
+
lpAmount: bigint;
|
|
149
|
+
}
|
|
150
|
+
/**
|
|
151
|
+
* Decode a StakeDeposit PDA account from raw data.
|
|
152
|
+
*
|
|
153
|
+
* On-chain layout (152 bytes, percolator-stake/src/state.rs):
|
|
154
|
+
* [0] is_initialized u8
|
|
155
|
+
* [1] bump u8
|
|
156
|
+
* [2..8] _padding
|
|
157
|
+
* [8..40] pool [u8; 32]
|
|
158
|
+
* [40..72] user [u8; 32]
|
|
159
|
+
* [72..80] last_deposit_slot u64
|
|
160
|
+
* [80..88] lp_amount u64
|
|
161
|
+
* [88..152] _reserved
|
|
162
|
+
*/
|
|
163
|
+
export declare function decodeDepositPda(data: Uint8Array): StakeDepositState;
|
|
139
164
|
export interface StakeAccounts {
|
|
140
165
|
/** InitPool accounts */
|
|
141
166
|
initPool: {
|
package/dist/validation.d.ts
CHANGED
|
@@ -9,34 +9,14 @@ export declare class ValidationError extends Error {
|
|
|
9
9
|
}
|
|
10
10
|
/**
|
|
11
11
|
* Validate a public key string.
|
|
12
|
-
*
|
|
13
|
-
* @param value - Base58-encoded public key string.
|
|
14
|
-
* @param field - Field name for error messages.
|
|
15
|
-
* @returns Parsed `PublicKey` instance.
|
|
16
|
-
* @throws {@link ValidationError} if the string is not a valid base58 public key.
|
|
17
|
-
*
|
|
18
|
-
* @example
|
|
19
|
-
* ```ts
|
|
20
|
-
* const key = validatePublicKey("11111111111111111111111111111111", "slab");
|
|
21
|
-
* ```
|
|
22
12
|
*/
|
|
23
13
|
export declare function validatePublicKey(value: string, field: string): PublicKey;
|
|
24
14
|
/**
|
|
25
15
|
* Validate a non-negative integer index (u16 range for accounts).
|
|
26
|
-
*
|
|
27
|
-
* @param value - Decimal string representing the index.
|
|
28
|
-
* @param field - Field name for error messages.
|
|
29
|
-
* @returns Parsed integer in `[0, 65535]`.
|
|
30
|
-
* @throws {@link ValidationError} if the value is not a valid u16 integer.
|
|
31
16
|
*/
|
|
32
17
|
export declare function validateIndex(value: string, field: string): number;
|
|
33
18
|
/**
|
|
34
19
|
* Validate a non-negative amount (u64 range).
|
|
35
|
-
*
|
|
36
|
-
* @param value - Decimal string representing the amount.
|
|
37
|
-
* @param field - Field name for error messages.
|
|
38
|
-
* @returns Parsed `bigint` in `[0, 2^64 - 1]`.
|
|
39
|
-
* @throws {@link ValidationError} if the value is negative or exceeds u64 max.
|
|
40
20
|
*/
|
|
41
21
|
export declare function validateAmount(value: string, field: string): bigint;
|
|
42
22
|
/**
|
|
@@ -52,12 +32,7 @@ export declare function validateI64(value: string, field: string): bigint;
|
|
|
52
32
|
*/
|
|
53
33
|
export declare function validateI128(value: string, field: string): bigint;
|
|
54
34
|
/**
|
|
55
|
-
* Validate a basis points value (0
|
|
56
|
-
*
|
|
57
|
-
* @param value - Decimal string representing basis points.
|
|
58
|
-
* @param field - Field name for error messages.
|
|
59
|
-
* @returns Parsed integer in `[0, 10000]`.
|
|
60
|
-
* @throws {@link ValidationError} if the value exceeds 10000.
|
|
35
|
+
* Validate a basis points value (0-10000).
|
|
61
36
|
*/
|
|
62
37
|
export declare function validateBps(value: string, field: string): number;
|
|
63
38
|
/**
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@percolatorct/sdk",
|
|
3
|
-
"version": "1.0.0-beta.
|
|
3
|
+
"version": "1.0.0-beta.31",
|
|
4
4
|
"license": "Apache-2.0",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"engines": {
|
|
@@ -31,6 +31,7 @@
|
|
|
31
31
|
},
|
|
32
32
|
"devDependencies": {
|
|
33
33
|
"@types/node": "^20.17.10",
|
|
34
|
+
"dotenv": "^17.4.1",
|
|
34
35
|
"tsup": "^8.3.5",
|
|
35
36
|
"tsx": "^4.21.0",
|
|
36
37
|
"typescript": "^5.7.2",
|