@percolatorct/sdk 1.0.0-beta.13 → 1.0.0-beta.14
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/dist/index.d.ts +3459 -7
- package/dist/index.js +305 -837
- package/dist/index.js.map +1 -1
- package/package.json +5 -11
- package/LICENSE +0 -201
- package/README.md +0 -754
- package/dist/abi/accounts.d.ts +0 -249
- package/dist/abi/encode.d.ts +0 -46
- package/dist/abi/errors.d.ts +0 -45
- package/dist/abi/index.d.ts +0 -4
- package/dist/abi/instructions.d.ts +0 -1111
- package/dist/config/program-ids.d.ts +0 -50
- package/dist/math/index.d.ts +0 -2
- package/dist/math/trading.d.ts +0 -222
- package/dist/math/warmup.d.ts +0 -105
- package/dist/oracle/price-router.d.ts +0 -38
- package/dist/runtime/index.d.ts +0 -2
- package/dist/runtime/lighthouse.d.ts +0 -170
- package/dist/runtime/tx.d.ts +0 -31
- package/dist/solana/adl.d.ts +0 -305
- package/dist/solana/ata.d.ts +0 -18
- package/dist/solana/dex-oracle.d.ts +0 -49
- package/dist/solana/discovery.d.ts +0 -492
- package/dist/solana/index.d.ts +0 -11
- package/dist/solana/oracle.d.ts +0 -52
- package/dist/solana/pda.d.ts +0 -49
- package/dist/solana/rpc-pool.d.ts +0 -347
- package/dist/solana/slab.d.ts +0 -358
- package/dist/solana/stake.d.ts +0 -216
- package/dist/solana/static-markets.d.ts +0 -86
- package/dist/solana/token-program.d.ts +0 -19
- package/dist/validation.d.ts +0 -70
|
@@ -1,492 +0,0 @@
|
|
|
1
|
-
import { Connection, PublicKey } from "@solana/web3.js";
|
|
2
|
-
import { type SlabHeader, type MarketConfig, type EngineState, type RiskParams } from "./slab.js";
|
|
3
|
-
import { type StaticMarketEntry } from "./static-markets.js";
|
|
4
|
-
import { type Network } from "../config/program-ids.js";
|
|
5
|
-
/**
|
|
6
|
-
* A discovered Percolator market from on-chain program accounts.
|
|
7
|
-
*/
|
|
8
|
-
export interface DiscoveredMarket {
|
|
9
|
-
slabAddress: PublicKey;
|
|
10
|
-
/** The program that owns this slab account */
|
|
11
|
-
programId: PublicKey;
|
|
12
|
-
header: SlabHeader;
|
|
13
|
-
config: MarketConfig;
|
|
14
|
-
engine: EngineState;
|
|
15
|
-
params: RiskParams;
|
|
16
|
-
}
|
|
17
|
-
/**
|
|
18
|
-
* Slab tier definitions — V1 layout (all tiers upgraded as of 2026-03-13).
|
|
19
|
-
* IMPORTANT: dataSize must match the compiled program's SLAB_LEN for that MAX_ACCOUNTS.
|
|
20
|
-
* The on-chain program has a hardcoded SLAB_LEN — slab account data.len() must equal it exactly.
|
|
21
|
-
*
|
|
22
|
-
* Layout: HEADER(104) + CONFIG(536) + RiskEngine(variable by tier)
|
|
23
|
-
* ENGINE_OFF = 640 (HEADER=104 + CONFIG=536, padded to 8-byte align on SBF)
|
|
24
|
-
* RiskEngine = fixed(656) + bitmap(BW*8) + post_bitmap(18) + next_free(N*2) + pad + accounts(N*248)
|
|
25
|
-
*
|
|
26
|
-
* Values are empirically verified against on-chain initialized accounts (GH #1109):
|
|
27
|
-
* small = 65,352 (256-acct program, verified on-chain post-V1 upgrade)
|
|
28
|
-
* medium = 257,448 (1024-acct program g9msRSV3, verified on-chain)
|
|
29
|
-
* large = 1,025,832 (4096-acct program FxfD37s1, pre-PERC-118, matches slabDataSizeV1(4096) formula)
|
|
30
|
-
*
|
|
31
|
-
* NOTE: small program (FwfBKZXb) redeployed with --features small,devnet (2026-03-13).
|
|
32
|
-
* Large program FxfD37s1 is pre-PERC-118 — SLAB_LEN=1,025,832, matching formula.
|
|
33
|
-
* See GH #1109, GH #1112.
|
|
34
|
-
*
|
|
35
|
-
* History: Small was V0 (62_808) until 2026-03-13 program upgrade. V0 values preserved
|
|
36
|
-
* in SLAB_TIERS_V0 for discovery of legacy on-chain accounts.
|
|
37
|
-
*/
|
|
38
|
-
/**
|
|
39
|
-
* Default slab tiers for the current mainnet program (v12.1).
|
|
40
|
-
* These are used by useCreateMarket to allocate slab accounts of the correct size.
|
|
41
|
-
*/
|
|
42
|
-
export declare const SLAB_TIERS: {
|
|
43
|
-
readonly micro: {
|
|
44
|
-
maxAccounts: number;
|
|
45
|
-
dataSize: number;
|
|
46
|
-
label: string;
|
|
47
|
-
description: string;
|
|
48
|
-
};
|
|
49
|
-
readonly small: {
|
|
50
|
-
maxAccounts: number;
|
|
51
|
-
dataSize: number;
|
|
52
|
-
label: string;
|
|
53
|
-
description: string;
|
|
54
|
-
};
|
|
55
|
-
readonly medium: {
|
|
56
|
-
maxAccounts: number;
|
|
57
|
-
dataSize: number;
|
|
58
|
-
label: string;
|
|
59
|
-
description: string;
|
|
60
|
-
};
|
|
61
|
-
readonly large: {
|
|
62
|
-
maxAccounts: number;
|
|
63
|
-
dataSize: number;
|
|
64
|
-
label: string;
|
|
65
|
-
description: string;
|
|
66
|
-
};
|
|
67
|
-
};
|
|
68
|
-
/** @deprecated V0 slab sizes — kept for backward compatibility with old on-chain slabs */
|
|
69
|
-
export declare const SLAB_TIERS_V0: {
|
|
70
|
-
readonly small: {
|
|
71
|
-
readonly maxAccounts: 256;
|
|
72
|
-
readonly dataSize: 62808;
|
|
73
|
-
readonly label: "Small";
|
|
74
|
-
readonly description: "256 slots · ~0.44 SOL";
|
|
75
|
-
};
|
|
76
|
-
readonly medium: {
|
|
77
|
-
readonly maxAccounts: 1024;
|
|
78
|
-
readonly dataSize: 248760;
|
|
79
|
-
readonly label: "Medium";
|
|
80
|
-
readonly description: "1,024 slots · ~1.73 SOL";
|
|
81
|
-
};
|
|
82
|
-
readonly large: {
|
|
83
|
-
readonly maxAccounts: 4096;
|
|
84
|
-
readonly dataSize: 992568;
|
|
85
|
-
readonly label: "Large";
|
|
86
|
-
readonly description: "4,096 slots · ~6.90 SOL";
|
|
87
|
-
};
|
|
88
|
-
};
|
|
89
|
-
/**
|
|
90
|
-
* V1D slab sizes — actually-deployed devnet V1 program (ENGINE_OFF=424, BITMAP_OFF=624).
|
|
91
|
-
* PR #1200 added V1D layout detection in slab.ts but discovery.ts ALL_TIERS was missing
|
|
92
|
-
* these sizes, causing V1D slabs to fall through to the memcmp fallback with wrong dataSize
|
|
93
|
-
* hints → detectSlabLayout returning null → parse failure (GH#1205).
|
|
94
|
-
*
|
|
95
|
-
* Sizes computed via computeSlabSize(ENGINE_OFF=424, BITMAP_OFF=624, ACCOUNT_SIZE=248, N, postBitmap=2):
|
|
96
|
-
* The V1D deployed program uses postBitmap=2 (free_head u16 only — no num_used/pad/next_account_id).
|
|
97
|
-
* This is 16 bytes smaller per tier than the SDK default (postBitmap=18). GH#1234.
|
|
98
|
-
* micro = 17,064 (64 slots)
|
|
99
|
-
* small = 65,088 (256 slots)
|
|
100
|
-
* medium = 257,184 (1,024 slots)
|
|
101
|
-
* large = 1,025,568 (4,096 slots)
|
|
102
|
-
*/
|
|
103
|
-
export declare const SLAB_TIERS_V1D: {
|
|
104
|
-
readonly micro: {
|
|
105
|
-
readonly maxAccounts: 64;
|
|
106
|
-
readonly dataSize: 17064;
|
|
107
|
-
readonly label: "Micro";
|
|
108
|
-
readonly description: "64 slots (V1D devnet)";
|
|
109
|
-
};
|
|
110
|
-
readonly small: {
|
|
111
|
-
readonly maxAccounts: 256;
|
|
112
|
-
readonly dataSize: 65088;
|
|
113
|
-
readonly label: "Small";
|
|
114
|
-
readonly description: "256 slots (V1D devnet)";
|
|
115
|
-
};
|
|
116
|
-
readonly medium: {
|
|
117
|
-
readonly maxAccounts: 1024;
|
|
118
|
-
readonly dataSize: 257184;
|
|
119
|
-
readonly label: "Medium";
|
|
120
|
-
readonly description: "1,024 slots (V1D devnet)";
|
|
121
|
-
};
|
|
122
|
-
readonly large: {
|
|
123
|
-
readonly maxAccounts: 4096;
|
|
124
|
-
readonly dataSize: 1025568;
|
|
125
|
-
readonly label: "Large";
|
|
126
|
-
readonly description: "4,096 slots (V1D devnet)";
|
|
127
|
-
};
|
|
128
|
-
};
|
|
129
|
-
/**
|
|
130
|
-
* V1D legacy slab sizes — on-chain V1D slabs created before GH#1234 when the SDK assumed
|
|
131
|
-
* postBitmap=18. These are 16 bytes larger per tier than SLAB_TIERS_V1D.
|
|
132
|
-
* PR #1236 fixed postBitmap for new slabs (→2) but caused slab 6ZytbpV4 (65104 bytes,
|
|
133
|
-
* top active market ~$15k 24h vol) to be unrecognized → "Failed to load market". GH#1237.
|
|
134
|
-
*
|
|
135
|
-
* Sizes computed via computeSlabSize(ENGINE_OFF=424, BITMAP_OFF=624, ACCOUNT_SIZE=248, N, postBitmap=18):
|
|
136
|
-
* micro = 17,080 (64 slots)
|
|
137
|
-
* small = 65,104 (256 slots) ← slab 6ZytbpV4 TEST/USD
|
|
138
|
-
* medium = 257,200 (1,024 slots)
|
|
139
|
-
* large = 1,025,584 (4,096 slots)
|
|
140
|
-
*/
|
|
141
|
-
export declare const SLAB_TIERS_V1D_LEGACY: {
|
|
142
|
-
readonly micro: {
|
|
143
|
-
readonly maxAccounts: 64;
|
|
144
|
-
readonly dataSize: 17080;
|
|
145
|
-
readonly label: "Micro";
|
|
146
|
-
readonly description: "64 slots (V1D legacy, postBitmap=18)";
|
|
147
|
-
};
|
|
148
|
-
readonly small: {
|
|
149
|
-
readonly maxAccounts: 256;
|
|
150
|
-
readonly dataSize: 65104;
|
|
151
|
-
readonly label: "Small";
|
|
152
|
-
readonly description: "256 slots (V1D legacy, postBitmap=18)";
|
|
153
|
-
};
|
|
154
|
-
readonly medium: {
|
|
155
|
-
readonly maxAccounts: 1024;
|
|
156
|
-
readonly dataSize: 257200;
|
|
157
|
-
readonly label: "Medium";
|
|
158
|
-
readonly description: "1,024 slots (V1D legacy, postBitmap=18)";
|
|
159
|
-
};
|
|
160
|
-
readonly large: {
|
|
161
|
-
readonly maxAccounts: 4096;
|
|
162
|
-
readonly dataSize: 1025584;
|
|
163
|
-
readonly label: "Large";
|
|
164
|
-
readonly description: "4,096 slots (V1D legacy, postBitmap=18)";
|
|
165
|
-
};
|
|
166
|
-
};
|
|
167
|
-
/** @deprecated Alias — use SLAB_TIERS (already V1) */
|
|
168
|
-
export declare const SLAB_TIERS_V1: {
|
|
169
|
-
readonly micro: {
|
|
170
|
-
maxAccounts: number;
|
|
171
|
-
dataSize: number;
|
|
172
|
-
label: string;
|
|
173
|
-
description: string;
|
|
174
|
-
};
|
|
175
|
-
readonly small: {
|
|
176
|
-
maxAccounts: number;
|
|
177
|
-
dataSize: number;
|
|
178
|
-
label: string;
|
|
179
|
-
description: string;
|
|
180
|
-
};
|
|
181
|
-
readonly medium: {
|
|
182
|
-
maxAccounts: number;
|
|
183
|
-
dataSize: number;
|
|
184
|
-
label: string;
|
|
185
|
-
description: string;
|
|
186
|
-
};
|
|
187
|
-
readonly large: {
|
|
188
|
-
maxAccounts: number;
|
|
189
|
-
dataSize: number;
|
|
190
|
-
label: string;
|
|
191
|
-
description: string;
|
|
192
|
-
};
|
|
193
|
-
};
|
|
194
|
-
/**
|
|
195
|
-
* V_ADL slab tier sizes — PERC-8270/8271 ADL-upgraded program.
|
|
196
|
-
* ENGINE_OFF=624, BITMAP_OFF=1006, ACCOUNT_SIZE=312, postBitmap=18.
|
|
197
|
-
* New account layout adds ADL tracking fields (+64 bytes/account).
|
|
198
|
-
* BPF SLAB_LEN verified by cargo build-sbf in PERC-8271: large (4096) = 1288304 bytes.
|
|
199
|
-
*/
|
|
200
|
-
export declare const SLAB_TIERS_V_ADL_DISCOVERY: Record<string, {
|
|
201
|
-
maxAccounts: number;
|
|
202
|
-
dataSize: number;
|
|
203
|
-
label: string;
|
|
204
|
-
description: string;
|
|
205
|
-
}>;
|
|
206
|
-
export type SlabTierKey = keyof typeof SLAB_TIERS;
|
|
207
|
-
/** Calculate slab data size for arbitrary account count.
|
|
208
|
-
*
|
|
209
|
-
* Layout (SBF, u128 align = 8):
|
|
210
|
-
* HEADER(104) + CONFIG(536) → ENGINE_OFF = 640
|
|
211
|
-
* RiskEngine fixed scalars: 656 bytes (PERC-299: +24 emergency OI, +32 long/short OI)
|
|
212
|
-
* + bitmap: ceil(N/64)*8
|
|
213
|
-
* + num_used_accounts(u16) + pad(6) + next_account_id(u64) + free_head(u16) = 18
|
|
214
|
-
* + next_free: N*2
|
|
215
|
-
* + pad to 8-byte alignment for Account array
|
|
216
|
-
* + accounts: N*248
|
|
217
|
-
*
|
|
218
|
-
* Must match the on-chain program's SLAB_LEN exactly.
|
|
219
|
-
*/
|
|
220
|
-
export declare function slabDataSize(maxAccounts: number): number;
|
|
221
|
-
/**
|
|
222
|
-
* Calculate slab data size for V1 layout (ENGINE_OFF=640).
|
|
223
|
-
*
|
|
224
|
-
* NOTE: This formula is accurate for small (256) and medium (1024) tiers but
|
|
225
|
-
* underestimates large (4096) by 16 bytes — likely due to a padding/alignment
|
|
226
|
-
* difference at high account counts or a post-PERC-118 struct addition in the
|
|
227
|
-
* deployed binary. Always prefer the hardcoded SLAB_TIERS values (empirically
|
|
228
|
-
* verified on-chain) over this formula for production use.
|
|
229
|
-
*/
|
|
230
|
-
export declare function slabDataSizeV1(maxAccounts: number): number;
|
|
231
|
-
/**
|
|
232
|
-
* Validate that a slab data size matches one of the known tier sizes.
|
|
233
|
-
* Use this to catch tier↔program mismatches early (PERC-277).
|
|
234
|
-
*
|
|
235
|
-
* @param dataSize - The expected slab data size (from SLAB_TIERS[tier].dataSize)
|
|
236
|
-
* @param programSlabLen - The program's compiled SLAB_LEN (from on-chain error logs or program introspection)
|
|
237
|
-
* @returns true if sizes match, false if there's a mismatch
|
|
238
|
-
*/
|
|
239
|
-
export declare function validateSlabTierMatch(dataSize: number, programSlabLen: number): boolean;
|
|
240
|
-
/** Options for `discoverMarkets`. */
|
|
241
|
-
export interface DiscoverMarketsOptions {
|
|
242
|
-
/**
|
|
243
|
-
* Run tier queries sequentially with per-tier retry on HTTP 429 instead of
|
|
244
|
-
* firing all in parallel. Reduces RPC rate-limit pressure at the cost of
|
|
245
|
-
* slightly slower discovery (~14 round-trips instead of 1 concurrent batch).
|
|
246
|
-
* Default: false (preserves original parallel behaviour).
|
|
247
|
-
*
|
|
248
|
-
* PERC-1650: keeper uses this flag to avoid 429 storms on its fallback RPC
|
|
249
|
-
* (Helius starter tier). Pass `sequential: true` from CrankService.discover().
|
|
250
|
-
*/
|
|
251
|
-
sequential?: boolean;
|
|
252
|
-
/**
|
|
253
|
-
* Delay in ms between sequential tier queries (only used when sequential=true).
|
|
254
|
-
* Default: 200 ms.
|
|
255
|
-
*/
|
|
256
|
-
interTierDelayMs?: number;
|
|
257
|
-
/**
|
|
258
|
-
* Per-tier retry backoff delays on 429 (ms). Jitter of up to +25% is applied.
|
|
259
|
-
* Only used when sequential=true. Default: [1_000, 3_000, 9_000, 27_000].
|
|
260
|
-
*/
|
|
261
|
-
rateLimitBackoffMs?: number[];
|
|
262
|
-
/**
|
|
263
|
-
* In parallel mode (the default), cap how many tier RPC requests are in-flight
|
|
264
|
-
* at once to avoid accidental RPC storms from client code.
|
|
265
|
-
*
|
|
266
|
-
* Default: 6
|
|
267
|
-
*/
|
|
268
|
-
maxParallelTiers?: number;
|
|
269
|
-
/**
|
|
270
|
-
* Hard cap on how many tier dataSize queries are attempted.
|
|
271
|
-
* Default: all known tiers.
|
|
272
|
-
*/
|
|
273
|
-
maxTierQueries?: number;
|
|
274
|
-
/**
|
|
275
|
-
* Base URL of the Percolator REST API (e.g. `"https://percolatorlaunch.com/api"`).
|
|
276
|
-
*
|
|
277
|
-
* When set, `discoverMarkets` will fall back to the REST API's `GET /markets`
|
|
278
|
-
* endpoint if `getProgramAccounts` fails or returns 0 results (common on public
|
|
279
|
-
* mainnet RPCs that reject `getProgramAccounts`).
|
|
280
|
-
*
|
|
281
|
-
* The API returns slab addresses which are then fetched on-chain via
|
|
282
|
-
* `getMarketsByAddress` (uses `getMultipleAccounts`, works on all RPCs).
|
|
283
|
-
*
|
|
284
|
-
* GH#59 / PERC-8424: Unblocks mainnet users without a Helius API key.
|
|
285
|
-
*
|
|
286
|
-
* @example
|
|
287
|
-
* ```ts
|
|
288
|
-
* const markets = await discoverMarkets(connection, programId, {
|
|
289
|
-
* apiBaseUrl: "https://percolatorlaunch.com/api",
|
|
290
|
-
* });
|
|
291
|
-
* ```
|
|
292
|
-
*/
|
|
293
|
-
apiBaseUrl?: string;
|
|
294
|
-
/**
|
|
295
|
-
* Timeout in ms for the API fallback HTTP request.
|
|
296
|
-
* Only used when `apiBaseUrl` is set.
|
|
297
|
-
* Default: 10_000 (10 seconds).
|
|
298
|
-
*/
|
|
299
|
-
apiTimeoutMs?: number;
|
|
300
|
-
/**
|
|
301
|
-
* Network hint for tier-3 static bundle fallback (`"mainnet"` or `"devnet"`).
|
|
302
|
-
*
|
|
303
|
-
* When both `getProgramAccounts` (tier 1) and the REST API (tier 2) fail,
|
|
304
|
-
* `discoverMarkets` will fall back to a bundled static list of known slab
|
|
305
|
-
* addresses for the specified network. The addresses are fetched on-chain
|
|
306
|
-
* via `getMarketsByAddress` (`getMultipleAccounts` — works on all RPCs).
|
|
307
|
-
*
|
|
308
|
-
* If not set, tier-3 fallback is disabled.
|
|
309
|
-
*
|
|
310
|
-
* The static list can be extended at runtime via `registerStaticMarkets()`.
|
|
311
|
-
*
|
|
312
|
-
* @see {@link registerStaticMarkets} to add addresses at runtime
|
|
313
|
-
* @see {@link getStaticMarkets} to inspect the current static list
|
|
314
|
-
*
|
|
315
|
-
* @example
|
|
316
|
-
* ```ts
|
|
317
|
-
* const markets = await discoverMarkets(connection, programId, {
|
|
318
|
-
* apiBaseUrl: "https://percolatorlaunch.com/api",
|
|
319
|
-
* network: "mainnet", // enables tier-3 static fallback
|
|
320
|
-
* });
|
|
321
|
-
* ```
|
|
322
|
-
*/
|
|
323
|
-
network?: Network;
|
|
324
|
-
}
|
|
325
|
-
/**
|
|
326
|
-
* Discover all Percolator markets owned by the given program.
|
|
327
|
-
* Uses getProgramAccounts with dataSize filter + dataSlice to download only ~1400 bytes per slab.
|
|
328
|
-
*
|
|
329
|
-
* @param options.sequential - Run tier queries sequentially with 429 retry (PERC-1650).
|
|
330
|
-
*/
|
|
331
|
-
export declare function discoverMarkets(connection: Connection, programId: PublicKey, options?: DiscoverMarketsOptions): Promise<DiscoveredMarket[]>;
|
|
332
|
-
/**
|
|
333
|
-
* Options for `getMarketsByAddress`.
|
|
334
|
-
*/
|
|
335
|
-
export interface GetMarketsByAddressOptions {
|
|
336
|
-
/**
|
|
337
|
-
* Maximum number of addresses per `getMultipleAccounts` RPC call.
|
|
338
|
-
* Solana limits a single call to 100 accounts; callers may lower this
|
|
339
|
-
* to reduce per-request payload size or avoid 429s.
|
|
340
|
-
*
|
|
341
|
-
* Default: 100 (Solana maximum).
|
|
342
|
-
*/
|
|
343
|
-
batchSize?: number;
|
|
344
|
-
/**
|
|
345
|
-
* Delay in ms between batches when the address list exceeds `batchSize`.
|
|
346
|
-
* Helps avoid rate-limiting on public RPCs.
|
|
347
|
-
*
|
|
348
|
-
* Default: 0 (no delay).
|
|
349
|
-
*/
|
|
350
|
-
interBatchDelayMs?: number;
|
|
351
|
-
}
|
|
352
|
-
/**
|
|
353
|
-
* Fetch and parse Percolator markets by their known slab addresses.
|
|
354
|
-
*
|
|
355
|
-
* Unlike `discoverMarkets()` — which uses `getProgramAccounts` and is blocked
|
|
356
|
-
* on public mainnet RPCs — this function uses `getMultipleAccounts`, which works
|
|
357
|
-
* on any RPC endpoint (including `api.mainnet-beta.solana.com`).
|
|
358
|
-
*
|
|
359
|
-
* Callers must already know the market slab addresses (e.g. from an indexer,
|
|
360
|
-
* a hardcoded registry, or a previous `discoverMarkets` call on a permissive RPC).
|
|
361
|
-
*
|
|
362
|
-
* @param connection - Solana RPC connection
|
|
363
|
-
* @param programId - The Percolator program that owns these slabs
|
|
364
|
-
* @param addresses - Array of slab account public keys to fetch
|
|
365
|
-
* @param options - Optional batching/delay configuration
|
|
366
|
-
* @returns Parsed markets for all valid slab accounts; invalid/missing accounts are silently skipped.
|
|
367
|
-
*
|
|
368
|
-
* @example
|
|
369
|
-
* ```ts
|
|
370
|
-
* import { getMarketsByAddress, getProgramId } from "@percolator/sdk";
|
|
371
|
-
* import { Connection, PublicKey } from "@solana/web3.js";
|
|
372
|
-
*
|
|
373
|
-
* const connection = new Connection("https://api.mainnet-beta.solana.com");
|
|
374
|
-
* const programId = getProgramId("mainnet");
|
|
375
|
-
* const slabs = [
|
|
376
|
-
* new PublicKey("So11111111111111111111111111111111111111112"),
|
|
377
|
-
* // ... more known slab addresses
|
|
378
|
-
* ];
|
|
379
|
-
*
|
|
380
|
-
* const markets = await getMarketsByAddress(connection, programId, slabs);
|
|
381
|
-
* console.log(`Found ${markets.length} markets`);
|
|
382
|
-
* ```
|
|
383
|
-
*/
|
|
384
|
-
export declare function getMarketsByAddress(connection: Connection, programId: PublicKey, addresses: PublicKey[], options?: GetMarketsByAddressOptions): Promise<DiscoveredMarket[]>;
|
|
385
|
-
/**
|
|
386
|
-
* Shape of a single market entry returned by the Percolator REST API
|
|
387
|
-
* (`GET /markets`). Only the fields needed for discovery are typed here;
|
|
388
|
-
* the full API response may contain additional statistics fields.
|
|
389
|
-
*/
|
|
390
|
-
export interface ApiMarketEntry {
|
|
391
|
-
slab_address: string;
|
|
392
|
-
symbol?: string;
|
|
393
|
-
name?: string;
|
|
394
|
-
decimals?: number;
|
|
395
|
-
status?: string;
|
|
396
|
-
[key: string]: unknown;
|
|
397
|
-
}
|
|
398
|
-
/** Options for {@link discoverMarketsViaApi}. */
|
|
399
|
-
export interface DiscoverMarketsViaApiOptions {
|
|
400
|
-
/**
|
|
401
|
-
* Timeout in ms for the HTTP request to the REST API.
|
|
402
|
-
* Default: 10_000 (10 seconds).
|
|
403
|
-
*/
|
|
404
|
-
timeoutMs?: number;
|
|
405
|
-
/**
|
|
406
|
-
* Options forwarded to {@link getMarketsByAddress} for the on-chain fetch
|
|
407
|
-
* step (batch size, inter-batch delay).
|
|
408
|
-
*/
|
|
409
|
-
onChainOptions?: GetMarketsByAddressOptions;
|
|
410
|
-
}
|
|
411
|
-
/**
|
|
412
|
-
* Discover Percolator markets by first querying the REST API for slab addresses,
|
|
413
|
-
* then fetching full on-chain data via `getMarketsByAddress` (which uses
|
|
414
|
-
* `getMultipleAccounts` — works on all RPCs including public mainnet nodes).
|
|
415
|
-
*
|
|
416
|
-
* This is the recommended discovery path for mainnet users who do not have a
|
|
417
|
-
* Helius API key, since `getProgramAccounts` is rejected by public RPCs.
|
|
418
|
-
*
|
|
419
|
-
* The REST API acts as an address directory only — all market data is verified
|
|
420
|
-
* on-chain via `getMarketsByAddress`, so the caller gets the same
|
|
421
|
-
* `DiscoveredMarket[]` result as `discoverMarkets()`.
|
|
422
|
-
*
|
|
423
|
-
* @param connection - Solana RPC connection (any endpoint, including public)
|
|
424
|
-
* @param programId - The Percolator program that owns the slabs
|
|
425
|
-
* @param apiBaseUrl - Base URL of the Percolator REST API
|
|
426
|
-
* (e.g. `"https://percolatorlaunch.com/api"`)
|
|
427
|
-
* @param options - Optional timeout and on-chain fetch configuration
|
|
428
|
-
* @returns Parsed markets for all valid slab accounts discovered via the API
|
|
429
|
-
*
|
|
430
|
-
* @example
|
|
431
|
-
* ```ts
|
|
432
|
-
* import { discoverMarketsViaApi, getProgramId } from "@percolator/sdk";
|
|
433
|
-
* import { Connection } from "@solana/web3.js";
|
|
434
|
-
*
|
|
435
|
-
* const connection = new Connection("https://api.mainnet-beta.solana.com");
|
|
436
|
-
* const programId = getProgramId("mainnet");
|
|
437
|
-
* const markets = await discoverMarketsViaApi(
|
|
438
|
-
* connection,
|
|
439
|
-
* programId,
|
|
440
|
-
* "https://percolatorlaunch.com/api",
|
|
441
|
-
* );
|
|
442
|
-
* console.log(`Discovered ${markets.length} markets via API fallback`);
|
|
443
|
-
* ```
|
|
444
|
-
*/
|
|
445
|
-
export declare function discoverMarketsViaApi(connection: Connection, programId: PublicKey, apiBaseUrl: string, options?: DiscoverMarketsViaApiOptions): Promise<DiscoveredMarket[]>;
|
|
446
|
-
/** Options for {@link discoverMarketsViaStaticBundle}. */
|
|
447
|
-
export interface DiscoverMarketsViaStaticBundleOptions {
|
|
448
|
-
/**
|
|
449
|
-
* Options forwarded to {@link getMarketsByAddress} for the on-chain fetch
|
|
450
|
-
* step (batch size, inter-batch delay).
|
|
451
|
-
*/
|
|
452
|
-
onChainOptions?: GetMarketsByAddressOptions;
|
|
453
|
-
}
|
|
454
|
-
/**
|
|
455
|
-
* Discover Percolator markets from a static list of known slab addresses.
|
|
456
|
-
*
|
|
457
|
-
* This is the tier-3 (last-resort) fallback for `discoverMarkets()`. It uses
|
|
458
|
-
* a bundled list of known slab addresses and fetches their full account data
|
|
459
|
-
* on-chain via `getMarketsByAddress` (`getMultipleAccounts` — works on all RPCs).
|
|
460
|
-
*
|
|
461
|
-
* The static list acts as an address directory only — all market data is verified
|
|
462
|
-
* on-chain, so stale entries are silently skipped (the account won't have valid
|
|
463
|
-
* magic bytes or will have been closed).
|
|
464
|
-
*
|
|
465
|
-
* @param connection - Solana RPC connection (any endpoint)
|
|
466
|
-
* @param programId - The Percolator program that owns the slabs
|
|
467
|
-
* @param entries - Static market entries (typically from {@link getStaticMarkets})
|
|
468
|
-
* @param options - Optional on-chain fetch configuration
|
|
469
|
-
* @returns Parsed markets for all valid slab accounts; stale/missing entries are skipped.
|
|
470
|
-
*
|
|
471
|
-
* @example
|
|
472
|
-
* ```ts
|
|
473
|
-
* import {
|
|
474
|
-
* discoverMarketsViaStaticBundle,
|
|
475
|
-
* getStaticMarkets,
|
|
476
|
-
* getProgramId,
|
|
477
|
-
* } from "@percolator/sdk";
|
|
478
|
-
* import { Connection } from "@solana/web3.js";
|
|
479
|
-
*
|
|
480
|
-
* const connection = new Connection("https://api.mainnet-beta.solana.com");
|
|
481
|
-
* const programId = getProgramId("mainnet");
|
|
482
|
-
* const entries = getStaticMarkets("mainnet");
|
|
483
|
-
*
|
|
484
|
-
* const markets = await discoverMarketsViaStaticBundle(
|
|
485
|
-
* connection,
|
|
486
|
-
* programId,
|
|
487
|
-
* entries,
|
|
488
|
-
* );
|
|
489
|
-
* console.log(`Recovered ${markets.length} markets from static bundle`);
|
|
490
|
-
* ```
|
|
491
|
-
*/
|
|
492
|
-
export declare function discoverMarketsViaStaticBundle(connection: Connection, programId: PublicKey, entries: StaticMarketEntry[], options?: DiscoverMarketsViaStaticBundleOptions): Promise<DiscoveredMarket[]>;
|
package/dist/solana/index.d.ts
DELETED
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
export * from "./slab.js";
|
|
2
|
-
export * from "./pda.js";
|
|
3
|
-
export * from "./ata.js";
|
|
4
|
-
export * from "./discovery.js";
|
|
5
|
-
export * from "./static-markets.js";
|
|
6
|
-
export * from "./dex-oracle.js";
|
|
7
|
-
export * from "./oracle.js";
|
|
8
|
-
export * from "./token-program.js";
|
|
9
|
-
export * from "./stake.js";
|
|
10
|
-
export * from "./adl.js";
|
|
11
|
-
export * from "./rpc-pool.js";
|
package/dist/solana/oracle.d.ts
DELETED
|
@@ -1,52 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Oracle account parsing utilities.
|
|
3
|
-
*
|
|
4
|
-
* Chainlink aggregator layout on Solana (from Toly's percolator-cli):
|
|
5
|
-
* offset 138: decimals (u8)
|
|
6
|
-
* offset 216: latest answer (i64 LE)
|
|
7
|
-
*
|
|
8
|
-
* Minimum account size: 224 bytes (offset 216 + 8 bytes for i64).
|
|
9
|
-
*
|
|
10
|
-
* These utilities validate oracle data BEFORE parsing to prevent silent
|
|
11
|
-
* propagation of stale or malformed Chainlink data as price.
|
|
12
|
-
*/
|
|
13
|
-
/** Minimum buffer size to read Chainlink price data */
|
|
14
|
-
declare const CHAINLINK_MIN_SIZE = 224;
|
|
15
|
-
/** Maximum reasonable decimals for a price feed */
|
|
16
|
-
declare const MAX_DECIMALS = 18;
|
|
17
|
-
/** Offset of decimals field in Chainlink aggregator account */
|
|
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
|
-
/** Offset of latest answer in Chainlink aggregator account */
|
|
22
|
-
declare const CHAINLINK_ANSWER_OFFSET = 216;
|
|
23
|
-
export interface OraclePrice {
|
|
24
|
-
price: bigint;
|
|
25
|
-
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
|
-
}
|
|
33
|
-
/**
|
|
34
|
-
* Parse price data from a Chainlink aggregator account buffer.
|
|
35
|
-
*
|
|
36
|
-
* Validates:
|
|
37
|
-
* - Buffer is large enough to contain the required fields (≥ 224 bytes)
|
|
38
|
-
* - Decimals are in a reasonable range (0-18)
|
|
39
|
-
* - Price is positive (non-zero)
|
|
40
|
-
*
|
|
41
|
-
* @param data - Raw account data from Chainlink aggregator
|
|
42
|
-
* @returns Parsed oracle price with decimals
|
|
43
|
-
* @throws if the buffer is invalid or contains unreasonable data
|
|
44
|
-
*/
|
|
45
|
-
export declare function parseChainlinkPrice(data: Uint8Array, options?: ParseChainlinkOptions): OraclePrice;
|
|
46
|
-
/**
|
|
47
|
-
* Validate that a buffer looks like a valid Chainlink aggregator account.
|
|
48
|
-
* Returns true if the buffer passes all validation checks, false otherwise.
|
|
49
|
-
* Use this for non-throwing validation.
|
|
50
|
-
*/
|
|
51
|
-
export declare function isValidChainlinkOracle(data: Uint8Array): boolean;
|
|
52
|
-
export { CHAINLINK_MIN_SIZE, CHAINLINK_DECIMALS_OFFSET, CHAINLINK_TIMESTAMP_OFFSET, CHAINLINK_ANSWER_OFFSET, MAX_DECIMALS };
|
package/dist/solana/pda.d.ts
DELETED
|
@@ -1,49 +0,0 @@
|
|
|
1
|
-
import { PublicKey } from "@solana/web3.js";
|
|
2
|
-
/**
|
|
3
|
-
* Derive vault authority PDA.
|
|
4
|
-
* Seeds: ["vault", slab_key]
|
|
5
|
-
*/
|
|
6
|
-
export declare function deriveVaultAuthority(programId: PublicKey, slab: PublicKey): [PublicKey, number];
|
|
7
|
-
/**
|
|
8
|
-
* Derive LP PDA for TradeCpi.
|
|
9
|
-
* Seeds: ["lp", slab_key, lp_idx as u16 LE]
|
|
10
|
-
*/
|
|
11
|
-
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
|
-
/** PumpSwap AMM program ID. */
|
|
18
|
-
export declare const PUMPSWAP_PROGRAM_ID: PublicKey;
|
|
19
|
-
/** Raydium CLMM (Concentrated Liquidity) program ID. */
|
|
20
|
-
export declare const RAYDIUM_CLMM_PROGRAM_ID: PublicKey;
|
|
21
|
-
/** Meteora DLMM (Dynamic Liquidity Market Maker) program ID. */
|
|
22
|
-
export declare const METEORA_DLMM_PROGRAM_ID: PublicKey;
|
|
23
|
-
/** Pyth Push Oracle program on mainnet. */
|
|
24
|
-
export declare const PYTH_PUSH_ORACLE_PROGRAM_ID: PublicKey;
|
|
25
|
-
/**
|
|
26
|
-
* Seed used to derive the creator lock PDA.
|
|
27
|
-
* Matches `creator_lock::CREATOR_LOCK_SEED` in percolator-prog.
|
|
28
|
-
*/
|
|
29
|
-
export declare const CREATOR_LOCK_SEED = "creator_lock";
|
|
30
|
-
/**
|
|
31
|
-
* Derive the creator lock PDA for a given slab.
|
|
32
|
-
* Seeds: ["creator_lock", slab_key]
|
|
33
|
-
*
|
|
34
|
-
* This PDA is required as accounts[9] in every LpVaultWithdraw instruction
|
|
35
|
-
* since percolator-prog PR#170 (GH#1926 / PERC-8287).
|
|
36
|
-
* Non-creator withdrawers must pass this key; if no lock exists on-chain the
|
|
37
|
-
* enforcement is a no-op. The SDK must ALWAYS include it — passing it is mandatory.
|
|
38
|
-
*
|
|
39
|
-
* @param programId - The percolator program ID.
|
|
40
|
-
* @param slab - The slab (market) public key.
|
|
41
|
-
* @returns [pda, bump]
|
|
42
|
-
*
|
|
43
|
-
* @example
|
|
44
|
-
* ```ts
|
|
45
|
-
* const [creatorLockPda] = deriveCreatorLockPda(PROGRAM_ID, slabKey);
|
|
46
|
-
* ```
|
|
47
|
-
*/
|
|
48
|
-
export declare function deriveCreatorLockPda(programId: PublicKey, slab: PublicKey): [PublicKey, number];
|
|
49
|
-
export declare function derivePythPushOraclePDA(feedIdHex: string): [PublicKey, number];
|