@percolatorct/sdk 1.0.0-beta.15 → 1.0.0-beta.16
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/LICENSE +201 -0
- package/README.md +754 -0
- package/dist/abi/accounts.d.ts +244 -0
- package/dist/abi/encode.d.ts +46 -0
- package/dist/abi/errors.d.ts +45 -0
- package/dist/abi/index.d.ts +4 -0
- package/dist/abi/instructions.d.ts +1102 -0
- package/dist/config/program-ids.d.ts +50 -0
- package/dist/index.d.ts +7 -3455
- package/dist/index.js +1047 -308
- package/dist/index.js.map +1 -1
- package/dist/math/index.d.ts +2 -0
- package/dist/math/trading.d.ts +222 -0
- package/dist/math/warmup.d.ts +105 -0
- package/dist/oracle/price-router.d.ts +38 -0
- package/dist/runtime/index.d.ts +2 -0
- package/dist/runtime/lighthouse.d.ts +170 -0
- package/dist/runtime/tx.d.ts +31 -0
- package/dist/solana/adl.d.ts +305 -0
- package/dist/solana/ata.d.ts +18 -0
- package/dist/solana/dex-oracle.d.ts +49 -0
- package/dist/solana/discovery.d.ts +492 -0
- package/dist/solana/index.d.ts +11 -0
- package/dist/solana/oracle.d.ts +52 -0
- package/dist/solana/pda.d.ts +44 -0
- package/dist/solana/rpc-pool.d.ts +347 -0
- package/dist/solana/slab.d.ts +421 -0
- package/dist/solana/stake.d.ts +216 -0
- package/dist/solana/static-markets.d.ts +86 -0
- package/dist/solana/token-program.d.ts +19 -0
- package/dist/validation.d.ts +70 -0
- package/package.json +11 -5
|
@@ -0,0 +1,421 @@
|
|
|
1
|
+
import { Connection, PublicKey } from "@solana/web3.js";
|
|
2
|
+
/**
|
|
3
|
+
* Full slab layout descriptor. Returned by detectSlabLayout().
|
|
4
|
+
* All engine field offsets are relative to engineOff.
|
|
5
|
+
*/
|
|
6
|
+
export interface SlabLayout {
|
|
7
|
+
version: 0 | 1 | 2;
|
|
8
|
+
headerLen: number;
|
|
9
|
+
configOffset: number;
|
|
10
|
+
configLen: number;
|
|
11
|
+
reservedOff: number;
|
|
12
|
+
engineOff: number;
|
|
13
|
+
accountSize: number;
|
|
14
|
+
maxAccounts: number;
|
|
15
|
+
bitmapWords: number;
|
|
16
|
+
accountsOff: number;
|
|
17
|
+
engineInsuranceOff: number;
|
|
18
|
+
engineParamsOff: number;
|
|
19
|
+
paramsSize: number;
|
|
20
|
+
engineCurrentSlotOff: number;
|
|
21
|
+
engineFundingIndexOff: number;
|
|
22
|
+
engineLastFundingSlotOff: number;
|
|
23
|
+
engineFundingRateBpsOff: number;
|
|
24
|
+
engineMarkPriceOff: number;
|
|
25
|
+
engineLastCrankSlotOff: number;
|
|
26
|
+
engineMaxCrankStalenessOff: number;
|
|
27
|
+
engineTotalOiOff: number;
|
|
28
|
+
engineLongOiOff: number;
|
|
29
|
+
engineShortOiOff: number;
|
|
30
|
+
engineCTotOff: number;
|
|
31
|
+
enginePnlPosTotOff: number;
|
|
32
|
+
engineLiqCursorOff: number;
|
|
33
|
+
engineGcCursorOff: number;
|
|
34
|
+
engineLastSweepStartOff: number;
|
|
35
|
+
engineLastSweepCompleteOff: number;
|
|
36
|
+
engineCrankCursorOff: number;
|
|
37
|
+
engineSweepStartIdxOff: number;
|
|
38
|
+
engineLifetimeLiquidationsOff: number;
|
|
39
|
+
engineLifetimeForceClosesOff: number;
|
|
40
|
+
engineNetLpPosOff: number;
|
|
41
|
+
engineLpSumAbsOff: number;
|
|
42
|
+
engineLpMaxAbsOff: number;
|
|
43
|
+
engineLpMaxAbsSweepOff: number;
|
|
44
|
+
engineEmergencyOiModeOff: number;
|
|
45
|
+
engineEmergencyStartSlotOff: number;
|
|
46
|
+
engineLastBreakerSlotOff: number;
|
|
47
|
+
engineBitmapOff: number;
|
|
48
|
+
postBitmap: number;
|
|
49
|
+
acctOwnerOff: number;
|
|
50
|
+
hasInsuranceIsolation: boolean;
|
|
51
|
+
engineInsuranceIsolatedOff: number;
|
|
52
|
+
engineInsuranceIsolationBpsOff: number;
|
|
53
|
+
}
|
|
54
|
+
export declare const ENGINE_OFF = 600;
|
|
55
|
+
export declare const ENGINE_MARK_PRICE_OFF = 400;
|
|
56
|
+
/**
|
|
57
|
+
* V2 slab tier sizes (small and large) for discovery.
|
|
58
|
+
* V2 uses ENGINE_OFF=600, BITMAP_OFF=432, ACCOUNT_SIZE=248, postBitmap=18.
|
|
59
|
+
* Sizes overlap with V1D (postBitmap=2) — disambiguation requires reading the version field.
|
|
60
|
+
*/
|
|
61
|
+
export declare const SLAB_TIERS_V2: {
|
|
62
|
+
readonly small: {
|
|
63
|
+
readonly maxAccounts: 256;
|
|
64
|
+
readonly dataSize: 65088;
|
|
65
|
+
readonly label: "Small";
|
|
66
|
+
readonly description: "256 slots (V2 BPF intermediate)";
|
|
67
|
+
};
|
|
68
|
+
readonly large: {
|
|
69
|
+
readonly maxAccounts: 4096;
|
|
70
|
+
readonly dataSize: 1025568;
|
|
71
|
+
readonly label: "Large";
|
|
72
|
+
readonly description: "4,096 slots (V2 BPF intermediate)";
|
|
73
|
+
};
|
|
74
|
+
};
|
|
75
|
+
/**
|
|
76
|
+
* V1M slab tier sizes — mainnet-deployed V1 program (ESa89R5).
|
|
77
|
+
* ENGINE_OFF=640, BITMAP_OFF=726, ACCOUNT_SIZE=248, postBitmap=18.
|
|
78
|
+
* Expanded RiskParams (336 bytes) and trade_twap runtime fields.
|
|
79
|
+
* Confirmed by on-chain probing of slab 8NY7rvQ (SOL/USDC Perpetual, 257512 bytes).
|
|
80
|
+
*/
|
|
81
|
+
export declare const SLAB_TIERS_V1M: Record<string, {
|
|
82
|
+
maxAccounts: number;
|
|
83
|
+
dataSize: number;
|
|
84
|
+
label: string;
|
|
85
|
+
description: string;
|
|
86
|
+
}>;
|
|
87
|
+
/**
|
|
88
|
+
* V1M2 slab tier sizes — mainnet program rebuilt from main@4861c56 with 312-byte accounts.
|
|
89
|
+
* ENGINE_OFF=616, BITMAP_OFF=1008 (empirically verified from CCTegYZ...).
|
|
90
|
+
* Engine struct is layout-identical to V_ADL; differs only in engineOff (616 vs 624).
|
|
91
|
+
* Sizes are unique from V_ADL after the bitmap correction: medium=323312 vs V_ADL=323320.
|
|
92
|
+
*/
|
|
93
|
+
export declare const SLAB_TIERS_V1M2: Record<string, {
|
|
94
|
+
maxAccounts: number;
|
|
95
|
+
dataSize: number;
|
|
96
|
+
label: string;
|
|
97
|
+
description: string;
|
|
98
|
+
}>;
|
|
99
|
+
/**
|
|
100
|
+
* V_ADL slab tier sizes — PERC-8270/8271 ADL-upgraded program.
|
|
101
|
+
* ENGINE_OFF=624, BITMAP_OFF=1008, ACCOUNT_SIZE=312, postBitmap=18.
|
|
102
|
+
* New account layout adds ADL tracking fields (+64 bytes/account including alignment padding).
|
|
103
|
+
* BPF SLAB_LEN verified by cargo build-sbf in PERC-8271: large (4096) = 1288320 bytes.
|
|
104
|
+
*/
|
|
105
|
+
export declare const SLAB_TIERS_V_ADL: Record<string, {
|
|
106
|
+
maxAccounts: number;
|
|
107
|
+
dataSize: number;
|
|
108
|
+
label: string;
|
|
109
|
+
description: string;
|
|
110
|
+
}>;
|
|
111
|
+
/**
|
|
112
|
+
* V_SETDEXPOOL slab tier sizes — PERC-SetDexPool security fix.
|
|
113
|
+
* ENGINE_OFF=632, BITMAP_OFF=1008, ACCOUNT_SIZE=312, CONFIG_LEN=528.
|
|
114
|
+
* e.g. large (4096 accts) = 1288336 bytes.
|
|
115
|
+
*/
|
|
116
|
+
export declare const SLAB_TIERS_V_SETDEXPOOL: Record<string, {
|
|
117
|
+
maxAccounts: number;
|
|
118
|
+
dataSize: number;
|
|
119
|
+
label: string;
|
|
120
|
+
description: string;
|
|
121
|
+
}>;
|
|
122
|
+
/**
|
|
123
|
+
* V12_1 slab tier sizes — percolator-core v12.1 merge.
|
|
124
|
+
* ENGINE_OFF=648, BITMAP_OFF=1016, ACCOUNT_SIZE=320.
|
|
125
|
+
* Verified by cargo build-sbf compile-time assertions.
|
|
126
|
+
*/
|
|
127
|
+
export declare const SLAB_TIERS_V12_1: Record<string, {
|
|
128
|
+
maxAccounts: number;
|
|
129
|
+
dataSize: number;
|
|
130
|
+
label: string;
|
|
131
|
+
description: string;
|
|
132
|
+
}>;
|
|
133
|
+
/**
|
|
134
|
+
* V12_15 slab tier sizes — percolator v12.15 (engine+prog sync).
|
|
135
|
+
* ENGINE_OFF=624, BITMAP_OFF=862 (relative), ACCOUNT_SIZE=4400, postBitmap=18.
|
|
136
|
+
* MAX_ACCOUNTS default changed from 4096 to 2048. Verified SLAB_LEN=1,128,448 for small (256).
|
|
137
|
+
* Account layout completely redesigned with reserve cohort arrays.
|
|
138
|
+
*/
|
|
139
|
+
export declare const SLAB_TIERS_V12_15: Record<string, {
|
|
140
|
+
maxAccounts: number;
|
|
141
|
+
dataSize: number;
|
|
142
|
+
label: string;
|
|
143
|
+
description: string;
|
|
144
|
+
}>;
|
|
145
|
+
/**
|
|
146
|
+
* Detect the slab layout version from the raw account data length.
|
|
147
|
+
* Returns the full SlabLayout descriptor, or null if the size is unrecognised.
|
|
148
|
+
* Checks V12_15, V12_1, V_SETDEXPOOL, V1M2, V_ADL, V1M, V0, V1D, V1D-legacy, V1, and V1-legacy sizes.
|
|
149
|
+
*
|
|
150
|
+
* When `data` is provided and the size matches V1D, the version field at offset 8 is read
|
|
151
|
+
* to disambiguate V2 slabs (which produce identical sizes to V1D with postBitmap=2).
|
|
152
|
+
* V2 slabs have version===2 at offset 8 (u32 LE).
|
|
153
|
+
*
|
|
154
|
+
* @param dataLen - The slab account data length in bytes
|
|
155
|
+
* @param data - Optional raw slab data for version-field disambiguation
|
|
156
|
+
*/
|
|
157
|
+
export declare function detectSlabLayout(dataLen: number, data?: Uint8Array): SlabLayout | null;
|
|
158
|
+
/**
|
|
159
|
+
* Legacy detectLayout for backward compat.
|
|
160
|
+
* Returns { bitmapWords, accountsOff, maxAccounts } or null.
|
|
161
|
+
*
|
|
162
|
+
* GH#1238: previously recomputed accountsOff with hardcoded postBitmap=18, which gave a value
|
|
163
|
+
* 16 bytes too large for V1D slabs (which use postBitmap=2). Now delegates directly to the
|
|
164
|
+
* SlabLayout descriptor so each variant uses its own correct accountsOff.
|
|
165
|
+
*/
|
|
166
|
+
export declare function detectLayout(dataLen: number): {
|
|
167
|
+
bitmapWords: number;
|
|
168
|
+
accountsOff: number;
|
|
169
|
+
maxAccounts: number;
|
|
170
|
+
} | null;
|
|
171
|
+
export interface SlabHeader {
|
|
172
|
+
magic: bigint;
|
|
173
|
+
version: number;
|
|
174
|
+
bump: number;
|
|
175
|
+
flags: number;
|
|
176
|
+
resolved: boolean;
|
|
177
|
+
paused: boolean;
|
|
178
|
+
admin: PublicKey;
|
|
179
|
+
nonce: bigint;
|
|
180
|
+
lastThrUpdateSlot: bigint;
|
|
181
|
+
}
|
|
182
|
+
export interface MarketConfig {
|
|
183
|
+
collateralMint: PublicKey;
|
|
184
|
+
vaultPubkey: PublicKey;
|
|
185
|
+
indexFeedId: PublicKey;
|
|
186
|
+
maxStalenessSlots: bigint;
|
|
187
|
+
confFilterBps: number;
|
|
188
|
+
vaultAuthorityBump: number;
|
|
189
|
+
invert: number;
|
|
190
|
+
unitScale: number;
|
|
191
|
+
fundingHorizonSlots: bigint;
|
|
192
|
+
fundingKBps: bigint;
|
|
193
|
+
fundingInvScaleNotionalE6: bigint;
|
|
194
|
+
fundingMaxPremiumBps: bigint;
|
|
195
|
+
fundingMaxBpsPerSlot: bigint;
|
|
196
|
+
/** @deprecated Removed in V12_1 — always 0 */ fundingPremiumWeightBps: bigint;
|
|
197
|
+
/** @deprecated Removed in V12_1 — always 0 */ fundingSettlementIntervalSlots: bigint;
|
|
198
|
+
/** @deprecated Removed in V12_1 — always 0 */ fundingPremiumDampeningE6: bigint;
|
|
199
|
+
/** @deprecated Removed in V12_1 — always 0 */ fundingPremiumMaxBpsPerSlot: bigint;
|
|
200
|
+
threshFloor: bigint;
|
|
201
|
+
threshRiskBps: bigint;
|
|
202
|
+
threshUpdateIntervalSlots: bigint;
|
|
203
|
+
threshStepBps: bigint;
|
|
204
|
+
threshAlphaBps: bigint;
|
|
205
|
+
threshMin: bigint;
|
|
206
|
+
threshMax: bigint;
|
|
207
|
+
threshMinStep: bigint;
|
|
208
|
+
oracleAuthority: PublicKey;
|
|
209
|
+
authorityPriceE6: bigint;
|
|
210
|
+
authorityTimestamp: bigint;
|
|
211
|
+
oraclePriceCapE2bps: bigint;
|
|
212
|
+
lastEffectivePriceE6: bigint;
|
|
213
|
+
oiCapMultiplierBps: bigint;
|
|
214
|
+
maxPnlCap: bigint;
|
|
215
|
+
adaptiveFundingEnabled: boolean;
|
|
216
|
+
adaptiveScaleBps: number;
|
|
217
|
+
adaptiveMaxFundingBps: bigint;
|
|
218
|
+
marketCreatedSlot: bigint;
|
|
219
|
+
oiRampSlots: bigint;
|
|
220
|
+
resolvedSlot: bigint;
|
|
221
|
+
insuranceIsolationBps: number;
|
|
222
|
+
/** PERC-622: Oracle phase (0=Nascent, 1=Growing, 2=Mature) */
|
|
223
|
+
oraclePhase: number;
|
|
224
|
+
/** PERC-622: Cumulative trade volume in e6 format */
|
|
225
|
+
cumulativeVolumeE6: bigint;
|
|
226
|
+
/** PERC-622: Slots elapsed from market creation to Phase 2 entry (u24) */
|
|
227
|
+
phase2DeltaSlots: number;
|
|
228
|
+
/**
|
|
229
|
+
* PERC-SetDexPool: Admin-pinned DEX pool pubkey for HYPERP markets.
|
|
230
|
+
* Null when reading old slabs (pre-SetDexPool configLen < 528) or when
|
|
231
|
+
* SetDexPool has never been called (all-zero pubkey).
|
|
232
|
+
* Non-null means the program will reject any UpdateHyperpMark that passes
|
|
233
|
+
* a different pool account.
|
|
234
|
+
*/
|
|
235
|
+
dexPool: PublicKey | null;
|
|
236
|
+
}
|
|
237
|
+
export interface InsuranceFund {
|
|
238
|
+
balance: bigint;
|
|
239
|
+
feeRevenue: bigint;
|
|
240
|
+
isolatedBalance: bigint;
|
|
241
|
+
isolationBps: number;
|
|
242
|
+
}
|
|
243
|
+
export interface RiskParams {
|
|
244
|
+
/**
|
|
245
|
+
* @deprecated Split into hMin/hMax in v12.15 RiskParams. On V12_15 slabs this field returns
|
|
246
|
+
* hMin for backwards compatibility. On pre-v12.15 slabs hMin/hMax both mirror this value.
|
|
247
|
+
*/
|
|
248
|
+
warmupPeriodSlots: bigint;
|
|
249
|
+
maintenanceMarginBps: bigint;
|
|
250
|
+
initialMarginBps: bigint;
|
|
251
|
+
tradingFeeBps: bigint;
|
|
252
|
+
maxAccounts: bigint;
|
|
253
|
+
newAccountFee: bigint;
|
|
254
|
+
riskReductionThreshold: bigint;
|
|
255
|
+
maintenanceFeePerSlot: bigint;
|
|
256
|
+
maxCrankStalenessSlots: bigint;
|
|
257
|
+
liquidationFeeBps: bigint;
|
|
258
|
+
liquidationFeeCap: bigint;
|
|
259
|
+
liquidationBufferBps: bigint;
|
|
260
|
+
minLiquidationAbs: bigint;
|
|
261
|
+
/** Minimum horizon slots (v12.15+). Replaces warmupPeriodSlots. 0n on pre-v12.15 slabs. */
|
|
262
|
+
hMin: bigint;
|
|
263
|
+
/** Maximum horizon slots (v12.15+). 0n on pre-v12.15 slabs. */
|
|
264
|
+
hMax: bigint;
|
|
265
|
+
}
|
|
266
|
+
export interface EngineState {
|
|
267
|
+
vault: bigint;
|
|
268
|
+
insuranceFund: InsuranceFund;
|
|
269
|
+
currentSlot: bigint;
|
|
270
|
+
fundingIndexQpbE6: bigint;
|
|
271
|
+
lastFundingSlot: bigint;
|
|
272
|
+
/**
|
|
273
|
+
* Funding rate per slot. On pre-v12.15 slabs: i64 in BPS units.
|
|
274
|
+
* On v12.15+ slabs: i128 in e9 units (field renamed `funding_rate_e9` on-chain).
|
|
275
|
+
* Use `fundingRateE9` for v12.15-aware code.
|
|
276
|
+
*/
|
|
277
|
+
fundingRateBpsPerSlotLast: bigint;
|
|
278
|
+
/**
|
|
279
|
+
* Funding rate in e9 units (i128). v12.15+ only.
|
|
280
|
+
* 0n on pre-v12.15 slabs (use `fundingRateBpsPerSlotLast` instead).
|
|
281
|
+
*/
|
|
282
|
+
fundingRateE9: bigint;
|
|
283
|
+
/**
|
|
284
|
+
* Market mode. v12.15+ only.
|
|
285
|
+
* 0 = Live, 1 = Resolved. null on pre-v12.15 slabs.
|
|
286
|
+
*/
|
|
287
|
+
marketMode: 0 | 1 | null;
|
|
288
|
+
lastCrankSlot: bigint;
|
|
289
|
+
maxCrankStalenessSlots: bigint;
|
|
290
|
+
totalOpenInterest: bigint;
|
|
291
|
+
longOi: bigint;
|
|
292
|
+
shortOi: bigint;
|
|
293
|
+
cTot: bigint;
|
|
294
|
+
pnlPosTot: bigint;
|
|
295
|
+
/**
|
|
296
|
+
* Matured (settled) positive PnL total (u128). v12.15+ only.
|
|
297
|
+
* 0n on pre-v12.15 slabs.
|
|
298
|
+
*/
|
|
299
|
+
pnlMaturedPosTot: bigint;
|
|
300
|
+
liqCursor: number;
|
|
301
|
+
gcCursor: number;
|
|
302
|
+
lastSweepStartSlot: bigint;
|
|
303
|
+
lastSweepCompleteSlot: bigint;
|
|
304
|
+
crankCursor: number;
|
|
305
|
+
sweepStartIdx: number;
|
|
306
|
+
lifetimeLiquidations: bigint;
|
|
307
|
+
lifetimeForceCloses: bigint;
|
|
308
|
+
netLpPos: bigint;
|
|
309
|
+
lpSumAbs: bigint;
|
|
310
|
+
lpMaxAbs: bigint;
|
|
311
|
+
lpMaxAbsSweep: bigint;
|
|
312
|
+
emergencyOiMode: boolean;
|
|
313
|
+
emergencyStartSlot: bigint;
|
|
314
|
+
lastBreakerSlot: bigint;
|
|
315
|
+
numUsedAccounts: number;
|
|
316
|
+
nextAccountId: bigint;
|
|
317
|
+
markPriceE6: bigint;
|
|
318
|
+
}
|
|
319
|
+
export declare enum AccountKind {
|
|
320
|
+
User = 0,
|
|
321
|
+
LP = 1
|
|
322
|
+
}
|
|
323
|
+
/** Parsed reserve cohort (64 bytes on-chain). Raw bytes; structure is program-internal. */
|
|
324
|
+
export type ReserveCohortBytes = Uint8Array;
|
|
325
|
+
export interface Account {
|
|
326
|
+
kind: AccountKind;
|
|
327
|
+
accountId: bigint;
|
|
328
|
+
capital: bigint;
|
|
329
|
+
pnl: bigint;
|
|
330
|
+
reservedPnl: bigint;
|
|
331
|
+
/** @deprecated Removed in v12.15. Always 0n on V12_15 slabs. */
|
|
332
|
+
warmupStartedAtSlot: bigint;
|
|
333
|
+
/** @deprecated Removed in v12.15. Always 0n on V12_15 slabs. */
|
|
334
|
+
warmupSlopePerStep: bigint;
|
|
335
|
+
positionSize: bigint;
|
|
336
|
+
/** Entry price in e6 units. Present in V12_15 (offset 120) and V_ADL/V12_1_EP. -1 signals absent. */
|
|
337
|
+
entryPrice: bigint;
|
|
338
|
+
fundingIndex: bigint;
|
|
339
|
+
matcherProgram: PublicKey;
|
|
340
|
+
matcherContext: PublicKey;
|
|
341
|
+
owner: PublicKey;
|
|
342
|
+
feeCredits: bigint;
|
|
343
|
+
/** @deprecated Removed in v12.15. Always 0n on V12_15 slabs. */
|
|
344
|
+
lastFeeSlot: bigint;
|
|
345
|
+
/** Total fees earned over account lifetime (u128). Present from v12.15. 0n on older layouts. */
|
|
346
|
+
feesEarnedTotal: bigint;
|
|
347
|
+
/**
|
|
348
|
+
* Reserve cohorts array (v12.15+). Up to 62 cohorts of 64 bytes each.
|
|
349
|
+
* `null` on pre-v12.15 slabs. Parse the raw bytes according to the on-chain ReserveCohort struct.
|
|
350
|
+
*/
|
|
351
|
+
exactReserveCohorts: ReserveCohortBytes[] | null;
|
|
352
|
+
/** Number of active reserve cohorts (0–62). null on pre-v12.15 slabs. */
|
|
353
|
+
exactCohortCount: number | null;
|
|
354
|
+
/** Overflow (oldest) cohort raw bytes. null on pre-v12.15 slabs or when not present. */
|
|
355
|
+
overflowOlder: ReserveCohortBytes | null;
|
|
356
|
+
/** True if overflowOlder contains valid data. null on pre-v12.15 slabs. */
|
|
357
|
+
overflowOlderPresent: boolean | null;
|
|
358
|
+
/** Overflow (newest) cohort raw bytes. null on pre-v12.15 slabs or when not present. */
|
|
359
|
+
overflowNewest: ReserveCohortBytes | null;
|
|
360
|
+
/** True if overflowNewest contains valid data. null on pre-v12.15 slabs. */
|
|
361
|
+
overflowNewestPresent: boolean | null;
|
|
362
|
+
}
|
|
363
|
+
export declare function fetchSlab(connection: Connection, slabPubkey: PublicKey): Promise<Uint8Array>;
|
|
364
|
+
export declare const RAMP_START_BPS = 1000n;
|
|
365
|
+
export declare const DEFAULT_OI_RAMP_SLOTS = 432000n;
|
|
366
|
+
export declare function computeEffectiveOiCapBps(config: MarketConfig, currentSlot: bigint): bigint;
|
|
367
|
+
export declare function readNonce(data: Uint8Array): bigint;
|
|
368
|
+
export declare function readLastThrUpdateSlot(data: Uint8Array): bigint;
|
|
369
|
+
/**
|
|
370
|
+
* Parse slab header (first 72 bytes — layout-independent).
|
|
371
|
+
*/
|
|
372
|
+
export declare function parseHeader(data: Uint8Array): SlabHeader;
|
|
373
|
+
/**
|
|
374
|
+
* Parse market config. Layout-version aware.
|
|
375
|
+
* For V0 slabs, fields beyond the basic config are read if present in the data,
|
|
376
|
+
* otherwise defaults are returned.
|
|
377
|
+
*
|
|
378
|
+
* @param data - Slab data (may be a partial slice for discovery; pass layoutHint in that case)
|
|
379
|
+
* @param layoutHint - Pre-detected layout to use; if omitted, detected from data.length.
|
|
380
|
+
*/
|
|
381
|
+
export declare function parseConfig(data: Uint8Array, layoutHint?: SlabLayout | null): MarketConfig;
|
|
382
|
+
/**
|
|
383
|
+
* Parse RiskParams from engine data. Layout-version aware.
|
|
384
|
+
* For V0 slabs, extended params (risk_threshold, maintenance_fee, etc.) are
|
|
385
|
+
* not present on-chain, so defaults (0) are returned.
|
|
386
|
+
*
|
|
387
|
+
* @param data - Slab data (may be a partial slice; pass layoutHint in that case)
|
|
388
|
+
* @param layoutHint - Pre-detected layout to use; if omitted, detected from data.length.
|
|
389
|
+
*/
|
|
390
|
+
export declare function parseParams(data: Uint8Array, layoutHint?: SlabLayout | null): RiskParams;
|
|
391
|
+
/**
|
|
392
|
+
* Parse RiskEngine state (excluding accounts array). Layout-version aware.
|
|
393
|
+
*/
|
|
394
|
+
export declare function parseEngine(data: Uint8Array): EngineState;
|
|
395
|
+
/**
|
|
396
|
+
* Read bitmap to get list of used account indices.
|
|
397
|
+
*/
|
|
398
|
+
/**
|
|
399
|
+
* Return all account indices whose bitmap bit is set (i.e. slot is in use).
|
|
400
|
+
* Uses the layout-aware bitmap offset so V1_LEGACY slabs (bitmap at rel+672) are handled correctly.
|
|
401
|
+
*/
|
|
402
|
+
export declare function parseUsedIndices(data: Uint8Array): number[];
|
|
403
|
+
/**
|
|
404
|
+
* Check if a specific account index is used.
|
|
405
|
+
*/
|
|
406
|
+
export declare function isAccountUsed(data: Uint8Array, idx: number): boolean;
|
|
407
|
+
/**
|
|
408
|
+
* Calculate the maximum valid account index for a given slab size.
|
|
409
|
+
*/
|
|
410
|
+
export declare function maxAccountIndex(dataLen: number): number;
|
|
411
|
+
/**
|
|
412
|
+
* Parse a single account by index.
|
|
413
|
+
*/
|
|
414
|
+
export declare function parseAccount(data: Uint8Array, idx: number): Account;
|
|
415
|
+
/**
|
|
416
|
+
* Parse all used accounts.
|
|
417
|
+
*/
|
|
418
|
+
export declare function parseAllAccounts(data: Uint8Array): {
|
|
419
|
+
idx: number;
|
|
420
|
+
account: Account;
|
|
421
|
+
}[];
|
|
@@ -0,0 +1,216 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @module stake
|
|
3
|
+
* Percolator Insurance LP Staking program — instruction encoders, PDA derivation, and account specs.
|
|
4
|
+
*
|
|
5
|
+
* Program: percolator-stake (dcccrypto/percolator-stake)
|
|
6
|
+
* Deployed devnet: 6aJb1F9CDCVWCNYFwj8aQsVb696YnW6J1FznteHq4Q6k
|
|
7
|
+
* Deployed mainnet: (pending deployment — DevOps must set STAKE_PROGRAM_ID env var or deploy and update STAKE_PROGRAM_IDS.mainnet)
|
|
8
|
+
*/
|
|
9
|
+
import { PublicKey } from '@solana/web3.js';
|
|
10
|
+
/** Known stake program addresses per network. */
|
|
11
|
+
export declare const STAKE_PROGRAM_IDS: {
|
|
12
|
+
readonly devnet: "6aJb1F9CDCVWCNYFwj8aQsVb696YnW6J1FznteHq4Q6k";
|
|
13
|
+
readonly mainnet: "DC5fovFQD5SZYsetwvEqd4Wi4PFY1Yfnc669VMe6oa7F";
|
|
14
|
+
};
|
|
15
|
+
/**
|
|
16
|
+
* Resolve the stake program ID for the given network.
|
|
17
|
+
*
|
|
18
|
+
* Priority:
|
|
19
|
+
* 1. STAKE_PROGRAM_ID env var (explicit override — DevOps sets this for mainnet until constant is filled)
|
|
20
|
+
* 2. Network-specific constant from STAKE_PROGRAM_IDS
|
|
21
|
+
*
|
|
22
|
+
* Throws a clear error on mainnet when no address is available so callers
|
|
23
|
+
* surface the gap instead of silently hitting the devnet program.
|
|
24
|
+
*/
|
|
25
|
+
export declare function getStakeProgramId(network?: 'devnet' | 'mainnet'): PublicKey;
|
|
26
|
+
/**
|
|
27
|
+
* Default export — resolves for the current runtime network.
|
|
28
|
+
* Use getStakeProgramId() with an explicit network argument where possible.
|
|
29
|
+
*
|
|
30
|
+
* @deprecated Direct use of STAKE_PROGRAM_ID is being phased out in favour of
|
|
31
|
+
* getStakeProgramId() so mainnet callers get a clear error rather than silently
|
|
32
|
+
* resolving to the devnet address.
|
|
33
|
+
*/
|
|
34
|
+
export declare const STAKE_PROGRAM_ID: PublicKey;
|
|
35
|
+
export declare const STAKE_IX: {
|
|
36
|
+
readonly InitPool: 0;
|
|
37
|
+
readonly Deposit: 1;
|
|
38
|
+
readonly Withdraw: 2;
|
|
39
|
+
readonly FlushToInsurance: 3;
|
|
40
|
+
readonly UpdateConfig: 4;
|
|
41
|
+
readonly TransferAdmin: 5;
|
|
42
|
+
readonly AdminSetOracleAuthority: 6;
|
|
43
|
+
readonly AdminSetRiskThreshold: 7;
|
|
44
|
+
readonly AdminSetMaintenanceFee: 8;
|
|
45
|
+
readonly AdminResolveMarket: 9;
|
|
46
|
+
readonly AdminWithdrawInsurance: 10;
|
|
47
|
+
readonly AdminSetInsurancePolicy: 11;
|
|
48
|
+
/** PERC-272: Accrue trading fees to LP vault */
|
|
49
|
+
readonly AccrueFees: 12;
|
|
50
|
+
/** PERC-272: Init pool in trading LP mode */
|
|
51
|
+
readonly InitTradingPool: 13;
|
|
52
|
+
/** PERC-313: Set HWM config (enable + floor bps) */
|
|
53
|
+
readonly AdminSetHwmConfig: 14;
|
|
54
|
+
/** PERC-303: Enable/configure senior-junior LP tranches */
|
|
55
|
+
readonly AdminSetTrancheConfig: 15;
|
|
56
|
+
/** PERC-303: Deposit into junior (first-loss) tranche */
|
|
57
|
+
readonly DepositJunior: 16;
|
|
58
|
+
};
|
|
59
|
+
/** Derive the stake pool PDA for a given slab (market). */
|
|
60
|
+
export declare function deriveStakePool(slab: PublicKey, programId?: PublicKey): [PublicKey, number];
|
|
61
|
+
/** Derive the vault authority PDA (signs CPI, owns LP mint + vault). */
|
|
62
|
+
export declare function deriveStakeVaultAuth(pool: PublicKey, programId?: PublicKey): [PublicKey, number];
|
|
63
|
+
/** Derive the per-user deposit PDA (tracks cooldown, deposit time). */
|
|
64
|
+
export declare function deriveDepositPda(pool: PublicKey, user: PublicKey, programId?: PublicKey): [PublicKey, number];
|
|
65
|
+
/** Tag 0: InitPool — create stake pool for a slab. */
|
|
66
|
+
export declare function encodeStakeInitPool(cooldownSlots: bigint | number, depositCap: bigint | number): Uint8Array;
|
|
67
|
+
/** Tag 1: Deposit — deposit collateral, receive LP tokens. */
|
|
68
|
+
export declare function encodeStakeDeposit(amount: bigint | number): Uint8Array;
|
|
69
|
+
/** Tag 2: Withdraw — burn LP tokens, receive collateral (subject to cooldown). */
|
|
70
|
+
export declare function encodeStakeWithdraw(lpAmount: bigint | number): Uint8Array;
|
|
71
|
+
/** Tag 3: FlushToInsurance — move collateral from stake vault to wrapper insurance. */
|
|
72
|
+
export declare function encodeStakeFlushToInsurance(amount: bigint | number): Uint8Array;
|
|
73
|
+
/** Tag 4: UpdateConfig — update cooldown and/or deposit cap. */
|
|
74
|
+
export declare function encodeStakeUpdateConfig(newCooldownSlots?: bigint | number, newDepositCap?: bigint | number): Uint8Array;
|
|
75
|
+
/** Tag 5: TransferAdmin — transfer wrapper admin to pool PDA. */
|
|
76
|
+
export declare function encodeStakeTransferAdmin(): Uint8Array;
|
|
77
|
+
/** Tag 6: AdminSetOracleAuthority — forward to wrapper via CPI. */
|
|
78
|
+
export declare function encodeStakeAdminSetOracleAuthority(newAuthority: PublicKey): Uint8Array;
|
|
79
|
+
/** Tag 7: AdminSetRiskThreshold — forward to wrapper via CPI. */
|
|
80
|
+
export declare function encodeStakeAdminSetRiskThreshold(newThreshold: bigint | number): Uint8Array;
|
|
81
|
+
/** Tag 8: AdminSetMaintenanceFee — forward to wrapper via CPI. */
|
|
82
|
+
export declare function encodeStakeAdminSetMaintenanceFee(newFee: bigint | number): Uint8Array;
|
|
83
|
+
/** Tag 9: AdminResolveMarket — forward to wrapper via CPI. */
|
|
84
|
+
export declare function encodeStakeAdminResolveMarket(): Uint8Array;
|
|
85
|
+
/** Tag 10: AdminWithdrawInsurance — withdraw insurance after market resolution. */
|
|
86
|
+
export declare function encodeStakeAdminWithdrawInsurance(amount: bigint | number): Uint8Array;
|
|
87
|
+
/** Tag 12: AccrueFees — permissionless: accrue trading fees to LP vault. */
|
|
88
|
+
export declare function encodeStakeAccrueFees(): Uint8Array;
|
|
89
|
+
/** Tag 13: InitTradingPool — create pool in trading LP mode (pool_mode = 1). */
|
|
90
|
+
export declare function encodeStakeInitTradingPool(cooldownSlots: bigint | number, depositCap: bigint | number): Uint8Array;
|
|
91
|
+
/** Tag 14 (PERC-313): AdminSetHwmConfig — enable HWM protection and set floor BPS. */
|
|
92
|
+
export declare function encodeStakeAdminSetHwmConfig(enabled: boolean, hwmFloorBps: number): Uint8Array;
|
|
93
|
+
/** Tag 15 (PERC-303): AdminSetTrancheConfig — enable senior/junior LP tranches. */
|
|
94
|
+
export declare function encodeStakeAdminSetTrancheConfig(juniorFeeMultBps: number): Uint8Array;
|
|
95
|
+
/** Tag 16 (PERC-303): DepositJunior — deposit into first-loss junior tranche. */
|
|
96
|
+
export declare function encodeStakeDepositJunior(amount: bigint | number): Uint8Array;
|
|
97
|
+
/** Tag 11: AdminSetInsurancePolicy — set withdrawal policy on wrapper. */
|
|
98
|
+
export declare function encodeStakeAdminSetInsurancePolicy(authority: PublicKey, minWithdrawBase: bigint | number, maxWithdrawBps: number, cooldownSlots: bigint | number): Uint8Array;
|
|
99
|
+
/**
|
|
100
|
+
* Decoded StakePool state (352 bytes on-chain).
|
|
101
|
+
* Includes PERC-272 (fee yield), PERC-313 (HWM), and PERC-303 (tranches).
|
|
102
|
+
*/
|
|
103
|
+
export interface StakePoolState {
|
|
104
|
+
isInitialized: boolean;
|
|
105
|
+
bump: number;
|
|
106
|
+
vaultAuthorityBump: number;
|
|
107
|
+
adminTransferred: boolean;
|
|
108
|
+
slab: PublicKey;
|
|
109
|
+
admin: PublicKey;
|
|
110
|
+
collateralMint: PublicKey;
|
|
111
|
+
lpMint: PublicKey;
|
|
112
|
+
vault: PublicKey;
|
|
113
|
+
totalDeposited: bigint;
|
|
114
|
+
totalLpSupply: bigint;
|
|
115
|
+
cooldownSlots: bigint;
|
|
116
|
+
depositCap: bigint;
|
|
117
|
+
totalFlushed: bigint;
|
|
118
|
+
totalReturned: bigint;
|
|
119
|
+
totalWithdrawn: bigint;
|
|
120
|
+
percolatorProgram: PublicKey;
|
|
121
|
+
totalFeesEarned: bigint;
|
|
122
|
+
lastFeeAccrualSlot: bigint;
|
|
123
|
+
lastVaultSnapshot: bigint;
|
|
124
|
+
poolMode: number;
|
|
125
|
+
hwmEnabled: boolean;
|
|
126
|
+
epochHighWaterTvl: bigint;
|
|
127
|
+
hwmFloorBps: number;
|
|
128
|
+
trancheEnabled: boolean;
|
|
129
|
+
juniorBalance: bigint;
|
|
130
|
+
juniorTotalLp: bigint;
|
|
131
|
+
juniorFeeMultBps: number;
|
|
132
|
+
}
|
|
133
|
+
/** Size of StakePool on-chain (bytes). */
|
|
134
|
+
export declare const STAKE_POOL_SIZE = 352;
|
|
135
|
+
/**
|
|
136
|
+
* Decode a StakePool account from raw data buffer. * Uses DataView for all u64/u16 reads — browser-safe.
|
|
137
|
+
*/
|
|
138
|
+
export declare function decodeStakePool(data: Uint8Array): StakePoolState;
|
|
139
|
+
export interface StakeAccounts {
|
|
140
|
+
/** InitPool accounts */
|
|
141
|
+
initPool: {
|
|
142
|
+
admin: PublicKey;
|
|
143
|
+
slab: PublicKey;
|
|
144
|
+
pool: PublicKey;
|
|
145
|
+
lpMint: PublicKey;
|
|
146
|
+
vault: PublicKey;
|
|
147
|
+
vaultAuth: PublicKey;
|
|
148
|
+
collateralMint: PublicKey;
|
|
149
|
+
percolatorProgram: PublicKey;
|
|
150
|
+
};
|
|
151
|
+
/** Deposit accounts */
|
|
152
|
+
deposit: {
|
|
153
|
+
user: PublicKey;
|
|
154
|
+
pool: PublicKey;
|
|
155
|
+
userCollateralAta: PublicKey;
|
|
156
|
+
vault: PublicKey;
|
|
157
|
+
lpMint: PublicKey;
|
|
158
|
+
userLpAta: PublicKey;
|
|
159
|
+
vaultAuth: PublicKey;
|
|
160
|
+
depositPda: PublicKey;
|
|
161
|
+
};
|
|
162
|
+
/** Withdraw accounts */
|
|
163
|
+
withdraw: {
|
|
164
|
+
user: PublicKey;
|
|
165
|
+
pool: PublicKey;
|
|
166
|
+
userLpAta: PublicKey;
|
|
167
|
+
lpMint: PublicKey;
|
|
168
|
+
vault: PublicKey;
|
|
169
|
+
userCollateralAta: PublicKey;
|
|
170
|
+
vaultAuth: PublicKey;
|
|
171
|
+
depositPda: PublicKey;
|
|
172
|
+
};
|
|
173
|
+
/** FlushToInsurance accounts (CPI from stake → percolator) */
|
|
174
|
+
flushToInsurance: {
|
|
175
|
+
caller: PublicKey;
|
|
176
|
+
pool: PublicKey;
|
|
177
|
+
vault: PublicKey;
|
|
178
|
+
vaultAuth: PublicKey;
|
|
179
|
+
slab: PublicKey;
|
|
180
|
+
wrapperVault: PublicKey;
|
|
181
|
+
percolatorProgram: PublicKey;
|
|
182
|
+
};
|
|
183
|
+
}
|
|
184
|
+
/**
|
|
185
|
+
* Build account keys for InitPool instruction.
|
|
186
|
+
* Returns array of {pubkey, isSigner, isWritable} in the order the program expects.
|
|
187
|
+
*/
|
|
188
|
+
export declare function initPoolAccounts(a: StakeAccounts['initPool']): {
|
|
189
|
+
pubkey: PublicKey;
|
|
190
|
+
isSigner: boolean;
|
|
191
|
+
isWritable: boolean;
|
|
192
|
+
}[];
|
|
193
|
+
/**
|
|
194
|
+
* Build account keys for Deposit instruction.
|
|
195
|
+
*/
|
|
196
|
+
export declare function depositAccounts(a: StakeAccounts['deposit']): {
|
|
197
|
+
pubkey: PublicKey;
|
|
198
|
+
isSigner: boolean;
|
|
199
|
+
isWritable: boolean;
|
|
200
|
+
}[];
|
|
201
|
+
/**
|
|
202
|
+
* Build account keys for Withdraw instruction.
|
|
203
|
+
*/
|
|
204
|
+
export declare function withdrawAccounts(a: StakeAccounts['withdraw']): {
|
|
205
|
+
pubkey: PublicKey;
|
|
206
|
+
isSigner: boolean;
|
|
207
|
+
isWritable: boolean;
|
|
208
|
+
}[];
|
|
209
|
+
/**
|
|
210
|
+
* Build account keys for FlushToInsurance instruction.
|
|
211
|
+
*/
|
|
212
|
+
export declare function flushToInsuranceAccounts(a: StakeAccounts['flushToInsurance']): {
|
|
213
|
+
pubkey: PublicKey;
|
|
214
|
+
isSigner: boolean;
|
|
215
|
+
isWritable: boolean;
|
|
216
|
+
}[];
|