@percolatorct/sdk 1.0.0-beta.8 → 2.0.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/README.md CHANGED
@@ -2,7 +2,18 @@
2
2
 
3
3
  TypeScript SDK for building clients, bots, and UIs on top of the [Percolator](https://github.com/dcccrypto/percolator) perpetual futures protocol on Solana.
4
4
 
5
- > **⚠️ BETA** `1.0.0-beta.1`. Security audit (0x-SquidSol) complete. All 709 tests passing. Pending Helius API key + mainnet market deployment before `1.0.0` stable.
5
+ > **EXPERIMENTAL. NOT AUDITED.** `2.0.0`. v12.19 single-target. 792 tests passing. Do NOT use with real funds.
6
+
7
+ ## Target wrapper
8
+
9
+ The SDK targets the percolator v12.19 wrapper (PR #271, branch `sync/v12.19-wrapper`, commit `d760fc4`).
10
+ All encoders emit v12.19 wire format. The dual-target `target: 'v12.17' | 'v12.19'` parameter
11
+ present in 2.0.0-rc.0 has been removed. PERC-628 shared-vault encoders
12
+ (`InitSharedVault`, `AllocateMarket`, `QueueWithdrawalSV`, `ClaimEpochWithdrawal`,
13
+ `AdvanceEpoch`) are unconditionally enabled.
14
+
15
+ Slab parsers retain V12_1 / V12_15 / V12_17 layout descriptors for backward-compatible
16
+ reads of older deployments. V12_19 layout descriptor is added for fresh v12.19 slabs.
6
17
 
7
18
  [![npm](https://img.shields.io/npm/v/@percolator/sdk?color=14F195)](https://www.npmjs.com/package/@percolator/sdk)
8
19
  [![License](https://img.shields.io/badge/license-Apache--2.0-blue)](LICENSE)
@@ -434,8 +445,10 @@ const markets = await discoverMarkets(connection);
434
445
 
435
446
  | Program | Network | Address |
436
447
  |---------|---------|---------|
437
- | Percolator | Mainnet | `GM8zjJ8LTBMv9xEsverh6H6wLyevgMHEJXcEzyY3rY24` |
448
+ | Percolator | Mainnet | `ESa89R5Es3rJ5mnwGybVRG1GrNt9etP11Z5V2QWD4edv` |
438
449
  | Matcher | Mainnet | `DHP6DtwXP1yJsz8YzfoeigRFPB979gzmumkmCxDLSkUX` |
450
+ | Stake | Mainnet | `DC5fovFQD5SZYsetwvEqd4Wi4PFY1Yfnc669VMe6oa7F` |
451
+ | NFT | Mainnet | `FqhKJT9gtScjrmfUuRMjeg7cXNpif1fqsy5Jh65tJmTS` |
439
452
  | Percolator | Devnet | `FxfD37s1AZTeWfFQps9Zpebi2dNQ9QSSDtfMKdbsfKrD` |
440
453
  | Matcher | Devnet | `GTRgyTDfrMvBubALAqtHuQwT8tbGyXid7svXZKtWfC9k` |
441
454
 
@@ -689,19 +702,26 @@ const markets = await getMarketsByAddress(
689
702
  ```bash
690
703
  pnpm install # Install dependencies
691
704
  pnpm build # Build with tsup (outputs to dist/)
692
- pnpm test # Run test suite (vitest)
705
+ pnpm test # Run all 742 tests (vitest)
693
706
  pnpm lint # Type-check (tsc --noEmit)
707
+ pnpm verify-layout # Verify ABI byte offsets against on-chain layout
694
708
  ```
695
709
 
696
710
  ### Testing
697
711
 
698
- Tests cover ABI encoding roundtrips, PDA derivation, slab parsing, validation, and trading math:
712
+ Tests cover ABI encoding roundtrips, PDA derivation, slab parsing, validation, and trading math. 742 tests, 0 failures.
699
713
 
700
714
  ```bash
701
715
  pnpm test # Run all tests
702
716
  pnpm test -- --watch # Watch mode
703
717
  ```
704
718
 
719
+ ### v12.17 Layout Support
720
+
721
+ The SDK supports the v12.17 slab layout natively via `detectSlabLayout()`. The layout detection function inspects account size to select the correct field offsets for header, config, and per-account data.
722
+
723
+ A key fix in this version corrects the SBF byte offsets for `d1`/`d2` delta fields that were misaligned in earlier SDK versions. The `parseAllAccounts()` function applies the correct offsets for both devnet (legacy layout) and mainnet (v12.17 layout) slabs automatically.
724
+
705
725
  ### Publishing
706
726
 
707
727
  ```bash
@@ -17,7 +17,15 @@ export declare const ACCOUNTS_INIT_MARKET: readonly AccountSpec[];
17
17
  */
18
18
  export declare const ACCOUNTS_INIT_USER: readonly AccountSpec[];
19
19
  /**
20
- * InitLP: 5 accounts (clock/oracle removed in commit 410f947)
20
+ * InitLP: 6 accounts
21
+ * Program at percolator.rs:6607 calls expect_len(accounts, 6).
22
+ * The 6th account (accounts[5]) is the clock sysvar — used via Clock::from_account_info.
23
+ * [0] user signer, writable (LP owner; pays fee)
24
+ * [1] slab writable
25
+ * [2] userAta writable (collateral source for fee)
26
+ * [3] vault writable (collateral destination)
27
+ * [4] tokenProgram read-only
28
+ * [5] clock read-only (SYSVAR_CLOCK_PUBKEY)
21
29
  */
22
30
  export declare const ACCOUNTS_INIT_LP: readonly AccountSpec[];
23
31
  /**
@@ -33,7 +41,9 @@ export declare const ACCOUNTS_WITHDRAW_COLLATERAL: readonly AccountSpec[];
33
41
  */
34
42
  export declare const ACCOUNTS_KEEPER_CRANK: readonly AccountSpec[];
35
43
  /**
36
- * TradeNoCpi: 4 accounts (PERC-199: clock sysvar removed — uses Clock::get() syscall)
44
+ * TradeNoCpi: 5 accounts.
45
+ * v12.19 wrapper at src/percolator.rs:8484 calls accounts::expect_len(5).
46
+ * Layout: [user(s+w), lp(s+w), slab(w), clock, oracle].
37
47
  */
38
48
  export declare const ACCOUNTS_TRADE_NOCPI: readonly AccountSpec[];
39
49
  /**
@@ -46,11 +56,13 @@ export declare const ACCOUNTS_LIQUIDATE_AT_ORACLE: readonly AccountSpec[];
46
56
  */
47
57
  export declare const ACCOUNTS_CLOSE_ACCOUNT: readonly AccountSpec[];
48
58
  /**
49
- * TopUpInsurance: 5 accounts
59
+ * TopUpInsurance: 6 accounts.
60
+ * v12.19 wrapper at src/percolator.rs:9256 calls accounts::expect_len(6).
61
+ * Layout: [user(s+w), slab(w), userAta(w), vault(w), tokenProgram, clock].
50
62
  */
51
63
  export declare const ACCOUNTS_TOPUP_INSURANCE: readonly AccountSpec[];
52
64
  /**
53
- * TradeCpi: 7 accounts (PERC-199: clock sysvar removed uses Clock::get() syscall)
65
+ * TradeCpi: 8 accounts (deployed program expects clock sysvar at index 3)
54
66
  */
55
67
  export declare const ACCOUNTS_TRADE_CPI: readonly AccountSpec[];
56
68
  /**
@@ -62,11 +74,32 @@ export declare const ACCOUNTS_SET_RISK_THRESHOLD: readonly AccountSpec[];
62
74
  */
63
75
  export declare const ACCOUNTS_UPDATE_ADMIN: readonly AccountSpec[];
64
76
  /**
65
- * CloseSlab: 2 accounts
77
+ * AcceptAdmin: 2 accounts (tag 82)
78
+ * Second half of two-step admin transfer. The proposed new admin must sign to
79
+ * complete the transfer. Program at percolator.rs:7994 calls expect_len(accounts, 2).
80
+ * [0] pendingAdmin signer, writable (must match config.pending_admin)
81
+ * [1] slab writable
82
+ */
83
+ export declare const ACCOUNTS_ACCEPT_ADMIN: readonly AccountSpec[];
84
+ /**
85
+ * CloseSlab: 6 accounts
86
+ * Drains vault and recovers rent after market is fully resolved and all accounts closed.
87
+ * Program at percolator.rs:8033 calls expect_len(accounts, 6).
88
+ * [0] dest signer, writable (receives rent + drained vault tokens)
89
+ * [1] slab writable
90
+ * [2] vault writable (token account — drained)
91
+ * [3] vaultAuthority read-only (PDA that signs the drain transfer)
92
+ * [4] destAta writable (dest's token ATA receiving drained tokens)
93
+ * [5] tokenProgram read-only
66
94
  */
67
95
  export declare const ACCOUNTS_CLOSE_SLAB: readonly AccountSpec[];
68
96
  /**
69
- * UpdateConfig: 2 accounts
97
+ * UpdateConfig: 3 accounts (canonical) or 4 (with oracle).
98
+ * v12.19 wrapper at src/percolator.rs:9544 accepts either.
99
+ * 3-account form: [admin(s+w), slab(w), clock].
100
+ * 4-account form: [admin(s+w), slab(w), clock, oracle] (used when the wrapper
101
+ * needs to re-read price during config commit). Default to the 3-account form;
102
+ * callers that need oracle re-reads should append the oracle account themselves.
70
103
  */
71
104
  export declare const ACCOUNTS_UPDATE_CONFIG: readonly AccountSpec[];
72
105
  /**
@@ -74,23 +107,15 @@ export declare const ACCOUNTS_UPDATE_CONFIG: readonly AccountSpec[];
74
107
  */
75
108
  export declare const ACCOUNTS_SET_MAINTENANCE_FEE: readonly AccountSpec[];
76
109
  /**
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)
110
+ * SetOraclePriceCap: 3 accounts.
111
+ * v12.19 wrapper at src/percolator.rs:9654 calls accounts::expect_len(3).
112
+ * Layout: [admin(s+w), slab(w), clock].
84
113
  */
85
114
  export declare const ACCOUNTS_SET_ORACLE_PRICE_CAP: readonly AccountSpec[];
86
115
  /**
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)
116
+ * ResolveMarket: 4 accounts.
117
+ * v12.19 wrapper at src/percolator.rs:9748 calls accounts::expect_len(4).
118
+ * Layout: [admin(s+w), slab(w), clock, oracle].
94
119
  */
95
120
  export declare const ACCOUNTS_RESOLVE_MARKET: readonly AccountSpec[];
96
121
  /**
@@ -98,6 +123,15 @@ export declare const ACCOUNTS_RESOLVE_MARKET: readonly AccountSpec[];
98
123
  * Withdraw insurance fund after market resolution (admin only)
99
124
  */
100
125
  export declare const ACCOUNTS_WITHDRAW_INSURANCE: readonly AccountSpec[];
126
+ /**
127
+ * WithdrawInsuranceLimited (tag 23): 7 or 8 accounts.
128
+ * On live markets the 8th oracle account is REQUIRED (upstream 8ce8d54):
129
+ * the handler does a same-instruction accrue_market_to against the fresh
130
+ * oracle price to prevent withdrawals against overstated insurance.
131
+ * On resolved markets the oracle is frozen — 7 accounts suffice.
132
+ */
133
+ export declare const ACCOUNTS_WITHDRAW_INSURANCE_LIMITED_RESOLVED: readonly AccountSpec[];
134
+ export declare const ACCOUNTS_WITHDRAW_INSURANCE_LIMITED_LIVE: readonly AccountSpec[];
101
135
  /**
102
136
  * PauseMarket: 2 accounts
103
137
  */
@@ -106,6 +140,40 @@ export declare const ACCOUNTS_PAUSE_MARKET: readonly AccountSpec[];
106
140
  * UnpauseMarket: 2 accounts
107
141
  */
108
142
  export declare const ACCOUNTS_UNPAUSE_MARKET: readonly AccountSpec[];
143
+ /**
144
+ * ReclaimEmptyAccount (tag 25): 2 accounts. Permissionless.
145
+ * Wrapper: src/percolator.rs:10470.
146
+ */
147
+ export declare const ACCOUNTS_RECLAIM_EMPTY_ACCOUNT: readonly AccountSpec[];
148
+ /**
149
+ * SettleAccount (tag 26): 3 accounts. Permissionless.
150
+ * Wrapper: src/percolator.rs:10503.
151
+ */
152
+ export declare const ACCOUNTS_SETTLE_ACCOUNT: readonly AccountSpec[];
153
+ /**
154
+ * DepositFeeCredits (tag 27): 6 accounts. Owner only.
155
+ * Wrapper: src/percolator.rs:10557. SPL transfer requires userAta + vault writable.
156
+ */
157
+ export declare const ACCOUNTS_DEPOSIT_FEE_CREDITS: readonly AccountSpec[];
158
+ /**
159
+ * ConvertReleasedPnl (tag 28): 4 accounts. Owner only.
160
+ * Wrapper: src/percolator.rs:10636.
161
+ */
162
+ export declare const ACCOUNTS_CONVERT_RELEASED_PNL: readonly AccountSpec[];
163
+ /**
164
+ * SetInsuranceWithdrawPolicy (tag 22): 2 accounts. Admin only.
165
+ * Wrapper: src/percolator.rs:9990.
166
+ */
167
+ export declare const ACCOUNTS_SET_INSURANCE_WITHDRAW_POLICY: readonly AccountSpec[];
168
+ /**
169
+ * UpdateAuthority (tag 83, v12.18.x 4-way split): 3 accounts.
170
+ * Wrapper: src/percolator.rs:6876.
171
+ *
172
+ * Both the current authority and the new authority must sign. For burn
173
+ * (`new_pubkey == default()`) the new account is still passed but does
174
+ * not need to sign per wrapper L7036 region.
175
+ */
176
+ export declare const ACCOUNTS_UPDATE_AUTHORITY: readonly AccountSpec[];
109
177
  /**
110
178
  * Build AccountMeta array from spec and provided pubkeys.
111
179
  *
@@ -117,6 +185,21 @@ export declare const ACCOUNTS_UNPAUSE_MARKET: readonly AccountSpec[];
117
185
  * remember the positional order, and errors clearly on missing names.
118
186
  */
119
187
  export declare function buildAccountMetas(spec: readonly AccountSpec[], keys: PublicKey[] | Record<string, PublicKey>): AccountMeta[];
188
+ /**
189
+ * CreateInsuranceMint: 9 accounts
190
+ * Creates SPL mint PDA for insurance LP tokens. Admin only, once per market.
191
+ */
192
+ export declare const ACCOUNTS_CREATE_INSURANCE_MINT: readonly AccountSpec[];
193
+ /**
194
+ * DepositInsuranceLP: 8 accounts
195
+ * Deposit collateral into insurance fund, receive LP tokens.
196
+ */
197
+ export declare const ACCOUNTS_DEPOSIT_INSURANCE_LP: readonly AccountSpec[];
198
+ /**
199
+ * WithdrawInsuranceLP: 8 accounts
200
+ * Burn LP tokens and withdraw proportional share of insurance fund.
201
+ */
202
+ export declare const ACCOUNTS_WITHDRAW_INSURANCE_LP: readonly AccountSpec[];
120
203
  /**
121
204
  * LpVaultWithdraw: 10 accounts (tag 39, PERC-627 / GH#1926 / PERC-8287)
122
205
  *
@@ -172,6 +255,9 @@ export declare const ACCOUNTS_CANCEL_QUEUED_WITHDRAWAL: readonly AccountSpec[];
172
255
  * pass additional oracle accounts at accounts[4..].
173
256
  */
174
257
  export declare const ACCOUNTS_EXECUTE_ADL: readonly AccountSpec[];
258
+ export declare const ACCOUNTS_RESOLVE_PERMISSIONLESS: readonly AccountSpec[];
259
+ export declare const ACCOUNTS_FORCE_CLOSE_RESOLVED: readonly AccountSpec[];
260
+ export declare const ACCOUNTS_ADMIN_FORCE_CLOSE: readonly AccountSpec[];
175
261
  /**
176
262
  * CloseStaleSlabs: 2 accounts (tag 51)
177
263
  * Admin closes a slab of an invalid/old layout and recovers rent SOL.
@@ -192,16 +278,25 @@ export declare const ACCOUNTS_AUDIT_CRANK: readonly AccountSpec[];
192
278
  * Permissionless — no signer required beyond fee payer.
193
279
  */
194
280
  export declare const ACCOUNTS_ADVANCE_ORACLE_PHASE: readonly AccountSpec[];
195
- /**
196
- * TopUpKeeperFund: 3 accounts
197
- * Permissionless anyone can fund. Transfers lamports directly (no system program).
198
- */
199
- export declare const ACCOUNTS_TOPUP_KEEPER_FUND: readonly AccountSpec[];
281
+ export declare const ACCOUNTS_UPDATE_HYPERP_MARK: readonly AccountSpec[];
282
+ export declare const ACCOUNTS_CREATE_LP_VAULT: readonly AccountSpec[];
283
+ export declare const ACCOUNTS_LP_VAULT_DEPOSIT: readonly AccountSpec[];
284
+ export declare const ACCOUNTS_LP_VAULT_CRANK_FEES: readonly AccountSpec[];
285
+ export declare const ACCOUNTS_CHALLENGE_SETTLEMENT: readonly AccountSpec[];
286
+ export declare const ACCOUNTS_RESOLVE_DISPUTE: readonly AccountSpec[];
287
+ export declare const ACCOUNTS_DEPOSIT_LP_COLLATERAL: readonly AccountSpec[];
288
+ export declare const ACCOUNTS_WITHDRAW_LP_COLLATERAL: readonly AccountSpec[];
289
+ export declare const ACCOUNTS_SET_OFFSET_PAIR: readonly AccountSpec[];
290
+ export declare const ACCOUNTS_ATTEST_CROSS_MARGIN: readonly AccountSpec[];
200
291
  /**
201
292
  * SetOiImbalanceHardBlock: 2 accounts
202
293
  * Sets the OI imbalance hard-block threshold (admin only)
203
294
  */
204
295
  export declare const ACCOUNTS_SET_OI_IMBALANCE_HARD_BLOCK: readonly AccountSpec[];
296
+ export declare const ACCOUNTS_SET_MAX_PNL_CAP: readonly AccountSpec[];
297
+ export declare const ACCOUNTS_SET_OI_CAP_MULTIPLIER: readonly AccountSpec[];
298
+ export declare const ACCOUNTS_SET_DISPUTE_PARAMS: readonly AccountSpec[];
299
+ export declare const ACCOUNTS_SET_LP_COLLATERAL_PARAMS: readonly AccountSpec[];
205
300
  /**
206
301
  * MintPositionNft: 10 accounts
207
302
  * Creates a Token-2022 position NFT for an open position.
@@ -229,11 +324,20 @@ export declare const ACCOUNTS_SET_PENDING_SETTLEMENT: readonly AccountSpec[];
229
324
  * Protected by admin allowlist (GH#1475).
230
325
  */
231
326
  export declare const ACCOUNTS_CLEAR_PENDING_SETTLEMENT: readonly AccountSpec[];
327
+ export declare const ACCOUNTS_TRANSFER_OWNERSHIP_CPI: readonly AccountSpec[];
232
328
  /**
233
329
  * SetWalletCap: 2 accounts
234
330
  * Sets the per-wallet position cap (admin only). capE6=0 disables.
235
331
  */
236
332
  export declare const ACCOUNTS_SET_WALLET_CAP: readonly AccountSpec[];
333
+ export declare const ACCOUNTS_RESCUE_ORPHAN_VAULT: readonly AccountSpec[];
334
+ export declare const ACCOUNTS_CLOSE_ORPHAN_SLAB: readonly AccountSpec[];
335
+ /**
336
+ * SetDexPool: 3 accounts
337
+ * Admin pins the approved DEX pool address for a HYPERP market.
338
+ * After this call, UpdateHyperpMark rejects any pool that does not match.
339
+ */
340
+ export declare const ACCOUNTS_SET_DEX_POOL: readonly AccountSpec[];
237
341
  /**
238
342
  * InitMatcherCtx: 5 accounts
239
343
  * Admin CPI-initializes the matcher context account for an LP slot.
@@ -19,27 +19,16 @@ export declare function getErrorName(code: number): string;
19
19
  * Get actionable hint for error code.
20
20
  */
21
21
  export declare function getErrorHint(code: number): string | undefined;
22
- /**
23
- * Check whether an error code is in the Anchor framework error range
24
- * (used by Lighthouse, not Percolator).
25
- */
26
- export declare function isAnchorErrorCode(code: number): boolean;
27
22
  /**
28
23
  * Parse error from transaction logs.
29
24
  * Looks for "Program ... failed: custom program error: 0x..."
30
25
  *
31
26
  * Hex capture is bounded (1–8 digits) so pathological logs cannot feed unbounded
32
27
  * strings into `parseInt` or produce precision-loss codes above u32.
33
- *
34
- * Distinguishes between:
35
- * - Percolator program errors (codes 0–65): returns Percolator error info
36
- * - Anchor/Lighthouse errors (codes 0x1770–0x1FFF): returns Lighthouse-specific
37
- * name and hint so callers can handle wallet middleware failures
38
28
  */
39
29
  export declare function parseErrorFromLogs(logs: string[]): {
40
30
  code: number;
41
31
  name: string;
42
32
  hint?: string;
43
- source?: "percolator" | "lighthouse" | "unknown";
44
33
  } | null;
45
34
  export {};
@@ -2,3 +2,4 @@ export * from "./encode.js";
2
2
  export * from "./instructions.js";
3
3
  export * from "./accounts.js";
4
4
  export * from "./errors.js";
5
+ export * from "./nft.js";