@percolatorct/sdk 1.0.0-beta.3 → 1.0.0-beta.31

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -2,7 +2,7 @@
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
+ > **EXPERIMENTALNOT AUDITED.** `1.0.0-beta.31`. 742 tests passing. Do NOT use with real funds.
6
6
 
7
7
  [![npm](https://img.shields.io/npm/v/@percolator/sdk?color=14F195)](https://www.npmjs.com/package/@percolator/sdk)
8
8
  [![License](https://img.shields.io/badge/license-Apache--2.0-blue)](LICENSE)
@@ -434,8 +434,10 @@ const markets = await discoverMarkets(connection);
434
434
 
435
435
  | Program | Network | Address |
436
436
  |---------|---------|---------|
437
- | Percolator | Mainnet | `GM8zjJ8LTBMv9xEsverh6H6wLyevgMHEJXcEzyY3rY24` |
437
+ | Percolator | Mainnet | `ESa89R5Es3rJ5mnwGybVRG1GrNt9etP11Z5V2QWD4edv` |
438
438
  | Matcher | Mainnet | `DHP6DtwXP1yJsz8YzfoeigRFPB979gzmumkmCxDLSkUX` |
439
+ | Stake | Mainnet | `DC5fovFQD5SZYsetwvEqd4Wi4PFY1Yfnc669VMe6oa7F` |
440
+ | NFT | Mainnet | `FqhKJT9gtScjrmfUuRMjeg7cXNpif1fqsy5Jh65tJmTS` |
439
441
  | Percolator | Devnet | `FxfD37s1AZTeWfFQps9Zpebi2dNQ9QSSDtfMKdbsfKrD` |
440
442
  | Matcher | Devnet | `GTRgyTDfrMvBubALAqtHuQwT8tbGyXid7svXZKtWfC9k` |
441
443
 
@@ -689,19 +691,26 @@ const markets = await getMarketsByAddress(
689
691
  ```bash
690
692
  pnpm install # Install dependencies
691
693
  pnpm build # Build with tsup (outputs to dist/)
692
- pnpm test # Run test suite (vitest)
694
+ pnpm test # Run all 742 tests (vitest)
693
695
  pnpm lint # Type-check (tsc --noEmit)
696
+ pnpm verify-layout # Verify ABI byte offsets against on-chain layout
694
697
  ```
695
698
 
696
699
  ### Testing
697
700
 
698
- Tests cover ABI encoding roundtrips, PDA derivation, slab parsing, validation, and trading math:
701
+ Tests cover ABI encoding roundtrips, PDA derivation, slab parsing, validation, and trading math. 742 tests, 0 failures.
699
702
 
700
703
  ```bash
701
704
  pnpm test # Run all tests
702
705
  pnpm test -- --watch # Watch mode
703
706
  ```
704
707
 
708
+ ### v12.17 Layout Support
709
+
710
+ 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.
711
+
712
+ 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.
713
+
705
714
  ### Publishing
706
715
 
707
716
  ```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
  /**
@@ -50,7 +58,7 @@ export declare const ACCOUNTS_CLOSE_ACCOUNT: readonly AccountSpec[];
50
58
  */
51
59
  export declare const ACCOUNTS_TOPUP_INSURANCE: readonly AccountSpec[];
52
60
  /**
53
- * TradeCpi: 7 accounts (PERC-199: clock sysvar removed uses Clock::get() syscall)
61
+ * TradeCpi: 8 accounts (deployed program expects clock sysvar at index 3)
54
62
  */
55
63
  export declare const ACCOUNTS_TRADE_CPI: readonly AccountSpec[];
56
64
  /**
@@ -62,7 +70,23 @@ export declare const ACCOUNTS_SET_RISK_THRESHOLD: readonly AccountSpec[];
62
70
  */
63
71
  export declare const ACCOUNTS_UPDATE_ADMIN: readonly AccountSpec[];
64
72
  /**
65
- * CloseSlab: 2 accounts
73
+ * AcceptAdmin: 2 accounts (tag 82)
74
+ * Second half of two-step admin transfer. The proposed new admin must sign to
75
+ * complete the transfer. Program at percolator.rs:7994 calls expect_len(accounts, 2).
76
+ * [0] pendingAdmin signer, writable (must match config.pending_admin)
77
+ * [1] slab writable
78
+ */
79
+ export declare const ACCOUNTS_ACCEPT_ADMIN: readonly AccountSpec[];
80
+ /**
81
+ * CloseSlab: 6 accounts
82
+ * Drains vault and recovers rent after market is fully resolved and all accounts closed.
83
+ * Program at percolator.rs:8033 calls expect_len(accounts, 6).
84
+ * [0] dest signer, writable (receives rent + drained vault tokens)
85
+ * [1] slab writable
86
+ * [2] vault writable (token account — drained)
87
+ * [3] vaultAuthority read-only (PDA that signs the drain transfer)
88
+ * [4] destAta writable (dest's token ATA receiving drained tokens)
89
+ * [5] tokenProgram read-only
66
90
  */
67
91
  export declare const ACCOUNTS_CLOSE_SLAB: readonly AccountSpec[];
68
92
  /**
@@ -73,21 +97,11 @@ export declare const ACCOUNTS_UPDATE_CONFIG: readonly AccountSpec[];
73
97
  * SetMaintenanceFee: 2 accounts
74
98
  */
75
99
  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
100
  /**
82
101
  * SetOraclePriceCap: 2 accounts
83
102
  * Set oracle price circuit breaker cap (admin only)
84
103
  */
85
104
  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
105
  /**
92
106
  * ResolveMarket: 2 accounts
93
107
  * Resolves a binary/premarket (admin only)
@@ -98,6 +112,15 @@ export declare const ACCOUNTS_RESOLVE_MARKET: readonly AccountSpec[];
98
112
  * Withdraw insurance fund after market resolution (admin only)
99
113
  */
100
114
  export declare const ACCOUNTS_WITHDRAW_INSURANCE: readonly AccountSpec[];
115
+ /**
116
+ * WithdrawInsuranceLimited (tag 23): 7 or 8 accounts.
117
+ * On live markets the 8th oracle account is REQUIRED (upstream 8ce8d54):
118
+ * the handler does a same-instruction accrue_market_to against the fresh
119
+ * oracle price to prevent withdrawals against overstated insurance.
120
+ * On resolved markets the oracle is frozen — 7 accounts suffice.
121
+ */
122
+ export declare const ACCOUNTS_WITHDRAW_INSURANCE_LIMITED_RESOLVED: readonly AccountSpec[];
123
+ export declare const ACCOUNTS_WITHDRAW_INSURANCE_LIMITED_LIVE: readonly AccountSpec[];
101
124
  /**
102
125
  * PauseMarket: 2 accounts
103
126
  */
@@ -117,6 +140,21 @@ export declare const ACCOUNTS_UNPAUSE_MARKET: readonly AccountSpec[];
117
140
  * remember the positional order, and errors clearly on missing names.
118
141
  */
119
142
  export declare function buildAccountMetas(spec: readonly AccountSpec[], keys: PublicKey[] | Record<string, PublicKey>): AccountMeta[];
143
+ /**
144
+ * CreateInsuranceMint: 9 accounts
145
+ * Creates SPL mint PDA for insurance LP tokens. Admin only, once per market.
146
+ */
147
+ export declare const ACCOUNTS_CREATE_INSURANCE_MINT: readonly AccountSpec[];
148
+ /**
149
+ * DepositInsuranceLP: 8 accounts
150
+ * Deposit collateral into insurance fund, receive LP tokens.
151
+ */
152
+ export declare const ACCOUNTS_DEPOSIT_INSURANCE_LP: readonly AccountSpec[];
153
+ /**
154
+ * WithdrawInsuranceLP: 8 accounts
155
+ * Burn LP tokens and withdraw proportional share of insurance fund.
156
+ */
157
+ export declare const ACCOUNTS_WITHDRAW_INSURANCE_LP: readonly AccountSpec[];
120
158
  /**
121
159
  * LpVaultWithdraw: 10 accounts (tag 39, PERC-627 / GH#1926 / PERC-8287)
122
160
  *
@@ -192,11 +230,6 @@ export declare const ACCOUNTS_AUDIT_CRANK: readonly AccountSpec[];
192
230
  * Permissionless — no signer required beyond fee payer.
193
231
  */
194
232
  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[];
200
233
  /**
201
234
  * SetOiImbalanceHardBlock: 2 accounts
202
235
  * Sets the OI imbalance hard-block threshold (admin only)
@@ -234,6 +267,12 @@ export declare const ACCOUNTS_CLEAR_PENDING_SETTLEMENT: readonly AccountSpec[];
234
267
  * Sets the per-wallet position cap (admin only). capE6=0 disables.
235
268
  */
236
269
  export declare const ACCOUNTS_SET_WALLET_CAP: readonly AccountSpec[];
270
+ /**
271
+ * SetDexPool: 3 accounts
272
+ * Admin pins the approved DEX pool address for a HYPERP market.
273
+ * After this call, UpdateHyperpMark rejects any pool that does not match.
274
+ */
275
+ export declare const ACCOUNTS_SET_DEX_POOL: readonly AccountSpec[];
237
276
  /**
238
277
  * InitMatcherCtx: 5 accounts
239
278
  * 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";