@percolatorct/sdk 0.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +201 -0
- package/README.md +492 -0
- package/dist/abi/accounts.d.ts +257 -0
- package/dist/abi/encode.d.ts +46 -0
- package/dist/abi/errors.d.ts +34 -0
- package/dist/abi/index.d.ts +4 -0
- package/dist/abi/instructions.d.ts +990 -0
- package/dist/config/program-ids.d.ts +50 -0
- package/dist/index.d.ts +7 -0
- package/dist/index.js +4604 -0
- package/dist/index.js.map +1 -0
- package/dist/math/index.d.ts +2 -0
- package/dist/math/trading.d.ts +107 -0
- package/dist/math/warmup.d.ts +55 -0
- package/dist/oracle/price-router.d.ts +38 -0
- package/dist/runtime/index.d.ts +1 -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 +263 -0
- package/dist/solana/index.d.ts +9 -0
- package/dist/solana/oracle.d.ts +44 -0
- package/dist/solana/pda.d.ts +54 -0
- package/dist/solana/slab.d.ts +316 -0
- package/dist/solana/stake.d.ts +216 -0
- package/dist/solana/token-program.d.ts +19 -0
- package/dist/validation.d.ts +45 -0
- package/package.json +45 -0
|
@@ -0,0 +1,257 @@
|
|
|
1
|
+
import { PublicKey, AccountMeta } from "@solana/web3.js";
|
|
2
|
+
/**
|
|
3
|
+
* Account spec for building instruction account metas.
|
|
4
|
+
* Each instruction has a fixed ordering that matches the Rust processor.
|
|
5
|
+
*/
|
|
6
|
+
export interface AccountSpec {
|
|
7
|
+
name: string;
|
|
8
|
+
signer: boolean;
|
|
9
|
+
writable: boolean;
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* InitMarket: 9 accounts (Pyth Pull - feed_id is in instruction data, not as accounts)
|
|
13
|
+
*/
|
|
14
|
+
export declare const ACCOUNTS_INIT_MARKET: readonly AccountSpec[];
|
|
15
|
+
/**
|
|
16
|
+
* InitUser: 5 accounts (clock/oracle removed in commit 410f947)
|
|
17
|
+
*/
|
|
18
|
+
export declare const ACCOUNTS_INIT_USER: readonly AccountSpec[];
|
|
19
|
+
/**
|
|
20
|
+
* InitLP: 5 accounts (clock/oracle removed in commit 410f947)
|
|
21
|
+
*/
|
|
22
|
+
export declare const ACCOUNTS_INIT_LP: readonly AccountSpec[];
|
|
23
|
+
/**
|
|
24
|
+
* DepositCollateral: 6 accounts
|
|
25
|
+
*/
|
|
26
|
+
export declare const ACCOUNTS_DEPOSIT_COLLATERAL: readonly AccountSpec[];
|
|
27
|
+
/**
|
|
28
|
+
* WithdrawCollateral: 8 accounts
|
|
29
|
+
*/
|
|
30
|
+
export declare const ACCOUNTS_WITHDRAW_COLLATERAL: readonly AccountSpec[];
|
|
31
|
+
/**
|
|
32
|
+
* KeeperCrank: 4 accounts
|
|
33
|
+
*/
|
|
34
|
+
export declare const ACCOUNTS_KEEPER_CRANK: readonly AccountSpec[];
|
|
35
|
+
/**
|
|
36
|
+
* TradeNoCpi: 4 accounts (PERC-199: clock sysvar removed — uses Clock::get() syscall)
|
|
37
|
+
*/
|
|
38
|
+
export declare const ACCOUNTS_TRADE_NOCPI: readonly AccountSpec[];
|
|
39
|
+
/**
|
|
40
|
+
* LiquidateAtOracle: 4 accounts
|
|
41
|
+
* Note: account[0] is unused but must be present
|
|
42
|
+
*/
|
|
43
|
+
export declare const ACCOUNTS_LIQUIDATE_AT_ORACLE: readonly AccountSpec[];
|
|
44
|
+
/**
|
|
45
|
+
* CloseAccount: 8 accounts
|
|
46
|
+
*/
|
|
47
|
+
export declare const ACCOUNTS_CLOSE_ACCOUNT: readonly AccountSpec[];
|
|
48
|
+
/**
|
|
49
|
+
* TopUpInsurance: 5 accounts
|
|
50
|
+
*/
|
|
51
|
+
export declare const ACCOUNTS_TOPUP_INSURANCE: readonly AccountSpec[];
|
|
52
|
+
/**
|
|
53
|
+
* TradeCpi: 7 accounts (PERC-199: clock sysvar removed — uses Clock::get() syscall)
|
|
54
|
+
*/
|
|
55
|
+
export declare const ACCOUNTS_TRADE_CPI: readonly AccountSpec[];
|
|
56
|
+
/**
|
|
57
|
+
* SetRiskThreshold: 2 accounts
|
|
58
|
+
*/
|
|
59
|
+
export declare const ACCOUNTS_SET_RISK_THRESHOLD: readonly AccountSpec[];
|
|
60
|
+
/**
|
|
61
|
+
* UpdateAdmin: 2 accounts
|
|
62
|
+
*/
|
|
63
|
+
export declare const ACCOUNTS_UPDATE_ADMIN: readonly AccountSpec[];
|
|
64
|
+
/**
|
|
65
|
+
* CloseSlab: 2 accounts
|
|
66
|
+
*/
|
|
67
|
+
export declare const ACCOUNTS_CLOSE_SLAB: readonly AccountSpec[];
|
|
68
|
+
/**
|
|
69
|
+
* UpdateConfig: 2 accounts
|
|
70
|
+
*/
|
|
71
|
+
export declare const ACCOUNTS_UPDATE_CONFIG: readonly AccountSpec[];
|
|
72
|
+
/**
|
|
73
|
+
* SetMaintenanceFee: 2 accounts
|
|
74
|
+
*/
|
|
75
|
+
export declare const ACCOUNTS_SET_MAINTENANCE_FEE: readonly AccountSpec[];
|
|
76
|
+
/**
|
|
77
|
+
* SetOracleAuthority: 2 accounts
|
|
78
|
+
* Sets the oracle price authority (admin only)
|
|
79
|
+
*/
|
|
80
|
+
export declare const ACCOUNTS_SET_ORACLE_AUTHORITY: readonly AccountSpec[];
|
|
81
|
+
/**
|
|
82
|
+
* SetOraclePriceCap: 2 accounts
|
|
83
|
+
* Set oracle price circuit breaker cap (admin only)
|
|
84
|
+
*/
|
|
85
|
+
export declare const ACCOUNTS_SET_ORACLE_PRICE_CAP: readonly AccountSpec[];
|
|
86
|
+
/**
|
|
87
|
+
* PushOraclePrice: 2 accounts
|
|
88
|
+
* Push oracle price (oracle authority only)
|
|
89
|
+
*/
|
|
90
|
+
export declare const ACCOUNTS_PUSH_ORACLE_PRICE: readonly AccountSpec[];
|
|
91
|
+
/**
|
|
92
|
+
* ResolveMarket: 2 accounts
|
|
93
|
+
* Resolves a binary/premarket (admin only)
|
|
94
|
+
*/
|
|
95
|
+
export declare const ACCOUNTS_RESOLVE_MARKET: readonly AccountSpec[];
|
|
96
|
+
/**
|
|
97
|
+
* WithdrawInsurance: 6 accounts
|
|
98
|
+
* Withdraw insurance fund after market resolution (admin only)
|
|
99
|
+
*/
|
|
100
|
+
export declare const ACCOUNTS_WITHDRAW_INSURANCE: readonly AccountSpec[];
|
|
101
|
+
/**
|
|
102
|
+
* PauseMarket: 2 accounts
|
|
103
|
+
*/
|
|
104
|
+
export declare const ACCOUNTS_PAUSE_MARKET: readonly AccountSpec[];
|
|
105
|
+
/**
|
|
106
|
+
* UnpauseMarket: 2 accounts
|
|
107
|
+
*/
|
|
108
|
+
export declare const ACCOUNTS_UNPAUSE_MARKET: readonly AccountSpec[];
|
|
109
|
+
/**
|
|
110
|
+
* Build AccountMeta array from spec and provided pubkeys.
|
|
111
|
+
*
|
|
112
|
+
* Accepts either:
|
|
113
|
+
* - `PublicKey[]` — ordered array, one entry per spec account (legacy form)
|
|
114
|
+
* - `Record<string, PublicKey>` — named map keyed by account `name` (preferred form)
|
|
115
|
+
*
|
|
116
|
+
* Named-map form resolves accounts by spec name so callers don't have to
|
|
117
|
+
* remember the positional order, and errors clearly on missing names.
|
|
118
|
+
*/
|
|
119
|
+
export declare function buildAccountMetas(spec: readonly AccountSpec[], keys: PublicKey[] | Record<string, PublicKey>): AccountMeta[];
|
|
120
|
+
/**
|
|
121
|
+
* CreateInsuranceMint: 9 accounts
|
|
122
|
+
* Creates SPL mint PDA for insurance LP tokens. Admin only, once per market.
|
|
123
|
+
*/
|
|
124
|
+
export declare const ACCOUNTS_CREATE_INSURANCE_MINT: readonly AccountSpec[];
|
|
125
|
+
/**
|
|
126
|
+
* DepositInsuranceLP: 8 accounts
|
|
127
|
+
* Deposit collateral into insurance fund, receive LP tokens.
|
|
128
|
+
*/
|
|
129
|
+
export declare const ACCOUNTS_DEPOSIT_INSURANCE_LP: readonly AccountSpec[];
|
|
130
|
+
/**
|
|
131
|
+
* WithdrawInsuranceLP: 8 accounts
|
|
132
|
+
* Burn LP tokens and withdraw proportional share of insurance fund.
|
|
133
|
+
*/
|
|
134
|
+
export declare const ACCOUNTS_WITHDRAW_INSURANCE_LP: readonly AccountSpec[];
|
|
135
|
+
/**
|
|
136
|
+
* LpVaultWithdraw: 10 accounts (tag 39, PERC-627 / GH#1926 / PERC-8287)
|
|
137
|
+
*
|
|
138
|
+
* Burn LP vault tokens and withdraw proportional collateral from the LP vault.
|
|
139
|
+
*
|
|
140
|
+
* accounts[9] = creatorLockPda is REQUIRED since percolator-prog PR#170.
|
|
141
|
+
* Non-creator withdrawers must pass the derived PDA key; if no lock exists
|
|
142
|
+
* on-chain the enforcement is a no-op. Omitting it was the bypass vector
|
|
143
|
+
* fixed in GH#1926. Use `deriveCreatorLockPda(programId, slab)` to compute.
|
|
144
|
+
*
|
|
145
|
+
* Accounts:
|
|
146
|
+
* [0] withdrawer signer, read-only
|
|
147
|
+
* [1] slab writable
|
|
148
|
+
* [2] withdrawerAta writable (collateral destination)
|
|
149
|
+
* [3] vault writable (collateral source)
|
|
150
|
+
* [4] tokenProgram read-only
|
|
151
|
+
* [5] lpVaultMint writable (LP tokens burned from here)
|
|
152
|
+
* [6] withdrawerLpAta writable (LP tokens source)
|
|
153
|
+
* [7] vaultAuthority read-only (PDA that signs token transfers)
|
|
154
|
+
* [8] lpVaultState writable
|
|
155
|
+
* [9] creatorLockPda writable (REQUIRED — derived from ["creator_lock", slab])
|
|
156
|
+
*/
|
|
157
|
+
export declare const ACCOUNTS_LP_VAULT_WITHDRAW: readonly AccountSpec[];
|
|
158
|
+
/**
|
|
159
|
+
* FundMarketInsurance: 5 accounts (PERC-306)
|
|
160
|
+
* Fund per-market isolated insurance balance.
|
|
161
|
+
*/
|
|
162
|
+
export declare const ACCOUNTS_FUND_MARKET_INSURANCE: readonly AccountSpec[];
|
|
163
|
+
/**
|
|
164
|
+
* SetInsuranceIsolation: 2 accounts (PERC-306)
|
|
165
|
+
* Set max % of global fund this market can access.
|
|
166
|
+
*/
|
|
167
|
+
export declare const ACCOUNTS_SET_INSURANCE_ISOLATION: readonly AccountSpec[];
|
|
168
|
+
/**
|
|
169
|
+
* QueueWithdrawal: 5 accounts (PERC-309)
|
|
170
|
+
* User queues a large LP withdrawal. Creates withdraw_queue PDA.
|
|
171
|
+
*/
|
|
172
|
+
export declare const ACCOUNTS_QUEUE_WITHDRAWAL: readonly AccountSpec[];
|
|
173
|
+
/**
|
|
174
|
+
* ClaimQueuedWithdrawal: 10 accounts (PERC-309)
|
|
175
|
+
* Burns LP tokens and releases one epoch tranche of SOL.
|
|
176
|
+
*/
|
|
177
|
+
export declare const ACCOUNTS_CLAIM_QUEUED_WITHDRAWAL: readonly AccountSpec[];
|
|
178
|
+
/**
|
|
179
|
+
* CancelQueuedWithdrawal: 3 accounts (PERC-309)
|
|
180
|
+
* Cancels queue, closes withdraw_queue PDA, returns rent to user.
|
|
181
|
+
*/
|
|
182
|
+
export declare const ACCOUNTS_CANCEL_QUEUED_WITHDRAWAL: readonly AccountSpec[];
|
|
183
|
+
/**
|
|
184
|
+
* ExecuteAdl: 4+ accounts (PERC-305, tag 50)
|
|
185
|
+
* Permissionless — surgically close/reduce the most profitable position
|
|
186
|
+
* when pnl_pos_tot > max_pnl_cap. For non-Hyperp markets with backup oracles,
|
|
187
|
+
* pass additional oracle accounts at accounts[4..].
|
|
188
|
+
*/
|
|
189
|
+
export declare const ACCOUNTS_EXECUTE_ADL: readonly AccountSpec[];
|
|
190
|
+
/**
|
|
191
|
+
* CloseStaleSlabs: 2 accounts (tag 51)
|
|
192
|
+
* Admin closes a slab of an invalid/old layout and recovers rent SOL.
|
|
193
|
+
*/
|
|
194
|
+
export declare const ACCOUNTS_CLOSE_STALE_SLABS: readonly AccountSpec[];
|
|
195
|
+
/**
|
|
196
|
+
* ReclaimSlabRent: 2 accounts (tag 52)
|
|
197
|
+
* Reclaim rent from an uninitialised slab. Both dest and slab must sign.
|
|
198
|
+
*/
|
|
199
|
+
export declare const ACCOUNTS_RECLAIM_SLAB_RENT: readonly AccountSpec[];
|
|
200
|
+
/**
|
|
201
|
+
* AuditCrank: 1 account (tag 53)
|
|
202
|
+
* Permissionless. Verifies conservation invariants; pauses market on violation.
|
|
203
|
+
*/
|
|
204
|
+
export declare const ACCOUNTS_AUDIT_CRANK: readonly AccountSpec[];
|
|
205
|
+
/**
|
|
206
|
+
* AdvanceOraclePhase: 1 account
|
|
207
|
+
* Permissionless — no signer required beyond fee payer.
|
|
208
|
+
*/
|
|
209
|
+
export declare const ACCOUNTS_ADVANCE_ORACLE_PHASE: readonly AccountSpec[];
|
|
210
|
+
/**
|
|
211
|
+
* TopUpKeeperFund: 3 accounts
|
|
212
|
+
* Permissionless — anyone can fund. Transfers lamports directly (no system program).
|
|
213
|
+
*/
|
|
214
|
+
export declare const ACCOUNTS_TOPUP_KEEPER_FUND: readonly AccountSpec[];
|
|
215
|
+
/**
|
|
216
|
+
* SetOiImbalanceHardBlock: 2 accounts
|
|
217
|
+
* Sets the OI imbalance hard-block threshold (admin only)
|
|
218
|
+
*/
|
|
219
|
+
export declare const ACCOUNTS_SET_OI_IMBALANCE_HARD_BLOCK: readonly AccountSpec[];
|
|
220
|
+
/**
|
|
221
|
+
* MintPositionNft: 10 accounts
|
|
222
|
+
* Creates a Token-2022 position NFT for an open position.
|
|
223
|
+
*/
|
|
224
|
+
export declare const ACCOUNTS_MINT_POSITION_NFT: readonly AccountSpec[];
|
|
225
|
+
/**
|
|
226
|
+
* TransferPositionOwnership: 8 accounts
|
|
227
|
+
* Transfer position NFT and update on-chain owner. Requires pending_settlement == 0.
|
|
228
|
+
*/
|
|
229
|
+
export declare const ACCOUNTS_TRANSFER_POSITION_OWNERSHIP: readonly AccountSpec[];
|
|
230
|
+
/**
|
|
231
|
+
* BurnPositionNft: 7 accounts
|
|
232
|
+
* Burns NFT and closes PositionNft + mint PDAs after position is closed.
|
|
233
|
+
*/
|
|
234
|
+
export declare const ACCOUNTS_BURN_POSITION_NFT: readonly AccountSpec[];
|
|
235
|
+
/**
|
|
236
|
+
* SetPendingSettlement: 3 accounts
|
|
237
|
+
* Keeper/admin sets pending_settlement flag before funding transfer.
|
|
238
|
+
* Protected by admin allowlist (GH#1475).
|
|
239
|
+
*/
|
|
240
|
+
export declare const ACCOUNTS_SET_PENDING_SETTLEMENT: readonly AccountSpec[];
|
|
241
|
+
/**
|
|
242
|
+
* ClearPendingSettlement: 3 accounts
|
|
243
|
+
* Keeper/admin clears pending_settlement flag after KeeperCrank.
|
|
244
|
+
* Protected by admin allowlist (GH#1475).
|
|
245
|
+
*/
|
|
246
|
+
export declare const ACCOUNTS_CLEAR_PENDING_SETTLEMENT: readonly AccountSpec[];
|
|
247
|
+
/**
|
|
248
|
+
* SetWalletCap: 2 accounts
|
|
249
|
+
* Sets the per-wallet position cap (admin only). capE6=0 disables.
|
|
250
|
+
*/
|
|
251
|
+
export declare const ACCOUNTS_SET_WALLET_CAP: readonly AccountSpec[];
|
|
252
|
+
export declare const WELL_KNOWN: {
|
|
253
|
+
readonly tokenProgram: PublicKey;
|
|
254
|
+
readonly clock: PublicKey;
|
|
255
|
+
readonly rent: PublicKey;
|
|
256
|
+
readonly systemProgram: PublicKey;
|
|
257
|
+
};
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import { PublicKey } from "@solana/web3.js";
|
|
2
|
+
/**
|
|
3
|
+
* Encode u8 (1 byte)
|
|
4
|
+
*/
|
|
5
|
+
export declare function encU8(val: number): Uint8Array;
|
|
6
|
+
/**
|
|
7
|
+
* Encode u16 little-endian (2 bytes)
|
|
8
|
+
*/
|
|
9
|
+
export declare function encU16(val: number): Uint8Array;
|
|
10
|
+
/**
|
|
11
|
+
* Encode u32 little-endian (4 bytes)
|
|
12
|
+
*/
|
|
13
|
+
export declare function encU32(val: number): Uint8Array;
|
|
14
|
+
/**
|
|
15
|
+
* Encode u64 little-endian (8 bytes)
|
|
16
|
+
* Input: bigint or string (decimal)
|
|
17
|
+
*/
|
|
18
|
+
export declare function encU64(val: bigint | string): Uint8Array;
|
|
19
|
+
/**
|
|
20
|
+
* Encode i64 little-endian (8 bytes), two's complement
|
|
21
|
+
* Input: bigint or string (decimal, may be negative)
|
|
22
|
+
*/
|
|
23
|
+
export declare function encI64(val: bigint | string): Uint8Array;
|
|
24
|
+
/**
|
|
25
|
+
* Encode u128 little-endian (16 bytes)
|
|
26
|
+
* Input: bigint or string (decimal)
|
|
27
|
+
*/
|
|
28
|
+
export declare function encU128(val: bigint | string): Uint8Array;
|
|
29
|
+
/**
|
|
30
|
+
* Encode i128 little-endian (16 bytes), two's complement
|
|
31
|
+
* Input: bigint or string (decimal, may be negative)
|
|
32
|
+
*/
|
|
33
|
+
export declare function encI128(val: bigint | string): Uint8Array;
|
|
34
|
+
/**
|
|
35
|
+
* Encode a PublicKey (32 bytes)
|
|
36
|
+
* Input: PublicKey or base58 string
|
|
37
|
+
*/
|
|
38
|
+
export declare function encPubkey(val: PublicKey | string): Uint8Array;
|
|
39
|
+
/**
|
|
40
|
+
* Encode a boolean as u8 (0 = false, 1 = true)
|
|
41
|
+
*/
|
|
42
|
+
export declare function encBool(val: boolean): Uint8Array;
|
|
43
|
+
/**
|
|
44
|
+
* Concatenate multiple Uint8Arrays (replaces Buffer.concat)
|
|
45
|
+
*/
|
|
46
|
+
export declare function concatBytes(...arrays: Uint8Array[]): Uint8Array;
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Percolator program error definitions.
|
|
3
|
+
* Each error includes a name and actionable guidance.
|
|
4
|
+
*/
|
|
5
|
+
interface ErrorInfo {
|
|
6
|
+
name: string;
|
|
7
|
+
hint: string;
|
|
8
|
+
}
|
|
9
|
+
export declare const PERCOLATOR_ERRORS: Record<number, ErrorInfo>;
|
|
10
|
+
/**
|
|
11
|
+
* Decode a custom program error code to its info.
|
|
12
|
+
*/
|
|
13
|
+
export declare function decodeError(code: number): ErrorInfo | undefined;
|
|
14
|
+
/**
|
|
15
|
+
* Get error name from code.
|
|
16
|
+
*/
|
|
17
|
+
export declare function getErrorName(code: number): string;
|
|
18
|
+
/**
|
|
19
|
+
* Get actionable hint for error code.
|
|
20
|
+
*/
|
|
21
|
+
export declare function getErrorHint(code: number): string | undefined;
|
|
22
|
+
/**
|
|
23
|
+
* Parse error from transaction logs.
|
|
24
|
+
* Looks for "Program ... failed: custom program error: 0x..."
|
|
25
|
+
*
|
|
26
|
+
* Hex capture is bounded (1–8 digits) so pathological logs cannot feed unbounded
|
|
27
|
+
* strings into `parseInt` or produce precision-loss codes above u32.
|
|
28
|
+
*/
|
|
29
|
+
export declare function parseErrorFromLogs(logs: string[]): {
|
|
30
|
+
code: number;
|
|
31
|
+
name: string;
|
|
32
|
+
hint?: string;
|
|
33
|
+
} | null;
|
|
34
|
+
export {};
|