@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.
@@ -1,1111 +0,0 @@
1
- import { PublicKey } from "@solana/web3.js";
2
- /**
3
- * Oracle price constraints.
4
- * Maximum oracle price that can be pushed to the on-chain oracle authority.
5
- */
6
- export declare const MAX_ORACLE_PRICE = 1000000000000n;
7
- /**
8
- * Instruction tags - exact match to Rust ix::Instruction::decode
9
- */
10
- export declare const IX_TAG: {
11
- readonly InitMarket: 0;
12
- readonly InitUser: 1;
13
- readonly InitLP: 2;
14
- readonly DepositCollateral: 3;
15
- readonly WithdrawCollateral: 4;
16
- readonly KeeperCrank: 5;
17
- readonly TradeNoCpi: 6;
18
- readonly LiquidateAtOracle: 7;
19
- readonly CloseAccount: 8;
20
- readonly TopUpInsurance: 9;
21
- readonly TradeCpi: 10;
22
- readonly SetRiskThreshold: 11;
23
- readonly UpdateAdmin: 12;
24
- readonly CloseSlab: 13;
25
- readonly UpdateConfig: 14;
26
- readonly SetMaintenanceFee: 15;
27
- readonly SetOracleAuthority: 16;
28
- readonly PushOraclePrice: 17;
29
- readonly SetOraclePriceCap: 18;
30
- readonly ResolveMarket: 19;
31
- readonly WithdrawInsurance: 20;
32
- readonly AdminForceClose: 21;
33
- readonly SetInsuranceWithdrawPolicy: 22;
34
- /** @deprecated Use SetInsuranceWithdrawPolicy */ readonly UpdateRiskParams: 22;
35
- readonly WithdrawInsuranceLimited: 23;
36
- /** @deprecated Use WithdrawInsuranceLimited */ readonly RenounceAdmin: 23;
37
- readonly QueryLpFees: 24;
38
- readonly ReclaimEmptyAccount: 25;
39
- readonly SettleAccount: 26;
40
- readonly DepositFeeCredits: 27;
41
- /** @deprecated No on-chain PauseMarket instruction */ readonly PauseMarket: 27;
42
- readonly ConvertReleasedPnl: 28;
43
- /** @deprecated No on-chain UnpauseMarket instruction */ readonly UnpauseMarket: 28;
44
- readonly ResolvePermissionless: 29;
45
- /** @deprecated Use ResolvePermissionless */ readonly AcceptAdmin: 29;
46
- readonly ForceCloseResolved: 30;
47
- readonly SetPythOracle: 32;
48
- readonly UpdateMarkPrice: 33;
49
- readonly UpdateHyperpMark: 34;
50
- readonly TradeCpiV2: 35;
51
- readonly UnresolveMarket: 36;
52
- readonly CreateLpVault: 37;
53
- readonly LpVaultDeposit: 38;
54
- readonly LpVaultWithdraw: 39;
55
- readonly LpVaultCrankFees: 40;
56
- /** PERC-306: Fund per-market isolated insurance balance */
57
- readonly FundMarketInsurance: 41;
58
- /** PERC-306: Set insurance isolation BPS for a market */
59
- readonly SetInsuranceIsolation: 42;
60
- /** PERC-314: Challenge settlement price during dispute window */
61
- readonly ChallengeSettlement: 43;
62
- /** PERC-314: Resolve dispute (admin adjudication) */
63
- readonly ResolveDispute: 44;
64
- /** PERC-315: Deposit LP vault tokens as perp collateral */
65
- readonly DepositLpCollateral: 45;
66
- /** PERC-315: Withdraw LP collateral (position must be closed) */
67
- readonly WithdrawLpCollateral: 46;
68
- /** PERC-309: Queue a large LP withdrawal (user; creates withdraw_queue PDA). */
69
- readonly QueueWithdrawal: 47;
70
- /** PERC-309: Claim one epoch tranche from a queued LP withdrawal (user). */
71
- readonly ClaimQueuedWithdrawal: 48;
72
- /** PERC-309: Cancel a queued withdrawal, refund remaining LP tokens (user). */
73
- readonly CancelQueuedWithdrawal: 49;
74
- /** PERC-305: Auto-deleverage — surgically close profitable positions when PnL cap is exceeded (permissionless). */
75
- readonly ExecuteAdl: 50;
76
- /** Close a stale slab of an invalid/old layout and recover rent SOL (admin only). */
77
- readonly CloseStaleSlabs: 51;
78
- /** Reclaim rent from an uninitialised slab whose market creation failed mid-flow. Slab must sign. */
79
- readonly ReclaimSlabRent: 52;
80
- /** Permissionless on-chain audit crank: verifies conservation invariants and pauses market on violation. */
81
- readonly AuditCrank: 53;
82
- /** Cross-Market Portfolio Margining: SetOffsetPair */
83
- readonly SetOffsetPair: 54;
84
- /** Cross-Market Portfolio Margining: AttestCrossMargin */
85
- readonly AttestCrossMargin: 55;
86
- /** PERC-622: Advance oracle phase (permissionless crank) */
87
- readonly AdvanceOraclePhase: 56;
88
- /** PERC-623: Top up a market's keeper fund (permissionless) */
89
- readonly TopUpKeeperFund: 57;
90
- /** PERC-629: Slash a market creator's deposit (permissionless) */
91
- readonly SlashCreationDeposit: 58;
92
- /** PERC-628: Initialize the global shared vault (admin) */
93
- readonly InitSharedVault: 59;
94
- /** PERC-628: Allocate virtual liquidity to a market (admin) */
95
- readonly AllocateMarket: 60;
96
- /** PERC-628: Queue a withdrawal for the current epoch */
97
- readonly QueueWithdrawalSV: 61;
98
- /** PERC-628: Claim a queued withdrawal after epoch elapses */
99
- readonly ClaimEpochWithdrawal: 62;
100
- /** PERC-628: Advance the shared vault epoch (permissionless crank) */
101
- readonly AdvanceEpoch: 63;
102
- /** PERC-608: Mint a Position NFT for a user's open position. */
103
- readonly MintPositionNft: 64;
104
- /** PERC-608: Transfer position ownership via the NFT (keeper-gated). */
105
- readonly TransferPositionOwnership: 65;
106
- /** PERC-608: Burn the Position NFT when a position is closed. */
107
- readonly BurnPositionNft: 66;
108
- /** PERC-608: Keeper sets pending_settlement flag before a funding transfer. */
109
- readonly SetPendingSettlement: 67;
110
- /** PERC-608: Keeper clears pending_settlement flag after KeeperCrank. */
111
- readonly ClearPendingSettlement: 68;
112
- /** PERC-608: Internal CPI call from percolator-nft TransferHook to update on-chain owner. */
113
- readonly TransferOwnershipCpi: 69;
114
- /** PERC-8111: Set per-wallet position cap (admin only, cap_e6=0 disables). */
115
- readonly SetWalletCap: 70;
116
- /** PERC-8110: Set OI imbalance hard-block threshold (admin only). */
117
- readonly SetOiImbalanceHardBlock: 71;
118
- /** PERC-8270: Rescue orphan vault — recover tokens from a closed market's vault (admin). */
119
- readonly RescueOrphanVault: 72;
120
- /** PERC-8270: Close orphan slab — reclaim rent from a slab whose market closed unexpectedly (admin). */
121
- readonly CloseOrphanSlab: 73;
122
- /** PERC-SetDexPool: Pin admin-approved DEX pool address for a HYPERP market (admin). */
123
- readonly SetDexPool: 74;
124
- /** CPI to the matcher program to initialize a matcher context account for an LP slot. Admin-only. */
125
- readonly InitMatcherCtx: 75;
126
- };
127
- /**
128
- * InitMarket instruction data (256 bytes total)
129
- * Layout: tag(1) + admin(32) + mint(32) + indexFeedId(32) +
130
- * maxStaleSecs(8) + confFilter(2) + invert(1) + unitScale(4) +
131
- * RiskParams(144)
132
- *
133
- * Note: indexFeedId is the Pyth Pull feed ID (32 bytes hex), NOT an oracle pubkey.
134
- * The program validates PriceUpdateV2 accounts against this feed ID at runtime.
135
- */
136
- export interface InitMarketArgs {
137
- admin: PublicKey | string;
138
- collateralMint: PublicKey | string;
139
- indexFeedId: string;
140
- maxStalenessSecs: bigint | string;
141
- confFilterBps: number;
142
- invert: number;
143
- unitScale: number;
144
- initialMarkPriceE6: bigint | string;
145
- maxMaintenanceFeePerSlot?: bigint | string;
146
- maxInsuranceFloor?: bigint | string;
147
- minOraclePriceCap?: bigint | string;
148
- warmupPeriodSlots: bigint | string;
149
- maintenanceMarginBps: bigint | string;
150
- initialMarginBps: bigint | string;
151
- tradingFeeBps: bigint | string;
152
- maxAccounts: bigint | string;
153
- newAccountFee: bigint | string;
154
- riskReductionThreshold: bigint | string;
155
- maintenanceFeePerSlot: bigint | string;
156
- maxCrankStalenessSlots: bigint | string;
157
- liquidationFeeBps: bigint | string;
158
- liquidationFeeCap: bigint | string;
159
- liquidationBufferBps: bigint | string;
160
- minLiquidationAbs: bigint | string;
161
- minInitialDeposit: bigint | string;
162
- minNonzeroMmReq: bigint | string;
163
- minNonzeroImReq: bigint | string;
164
- }
165
- export declare function encodeInitMarket(args: InitMarketArgs): Uint8Array;
166
- /**
167
- * InitUser instruction data (9 bytes)
168
- */
169
- export interface InitUserArgs {
170
- feePayment: bigint | string;
171
- }
172
- export declare function encodeInitUser(args: InitUserArgs): Uint8Array;
173
- /**
174
- * InitLP instruction data (73 bytes)
175
- */
176
- export interface InitLPArgs {
177
- matcherProgram: PublicKey | string;
178
- matcherContext: PublicKey | string;
179
- feePayment: bigint | string;
180
- }
181
- export declare function encodeInitLP(args: InitLPArgs): Uint8Array;
182
- /**
183
- * DepositCollateral instruction data (11 bytes)
184
- */
185
- export interface DepositCollateralArgs {
186
- userIdx: number;
187
- amount: bigint | string;
188
- }
189
- export declare function encodeDepositCollateral(args: DepositCollateralArgs): Uint8Array;
190
- /**
191
- * WithdrawCollateral instruction data (11 bytes)
192
- */
193
- export interface WithdrawCollateralArgs {
194
- userIdx: number;
195
- amount: bigint | string;
196
- }
197
- export declare function encodeWithdrawCollateral(args: WithdrawCollateralArgs): Uint8Array;
198
- /**
199
- * KeeperCrank instruction data (4 bytes)
200
- * Funding rate is computed on-chain from LP inventory.
201
- */
202
- export interface KeeperCrankArgs {
203
- callerIdx: number;
204
- allowPanic: boolean;
205
- }
206
- export declare function encodeKeeperCrank(args: KeeperCrankArgs): Uint8Array;
207
- /**
208
- * TradeNoCpi instruction data (21 bytes)
209
- */
210
- export interface TradeNoCpiArgs {
211
- lpIdx: number;
212
- userIdx: number;
213
- size: bigint | string;
214
- }
215
- export declare function encodeTradeNoCpi(args: TradeNoCpiArgs): Uint8Array;
216
- /**
217
- * LiquidateAtOracle instruction data (3 bytes)
218
- */
219
- export interface LiquidateAtOracleArgs {
220
- targetIdx: number;
221
- }
222
- export declare function encodeLiquidateAtOracle(args: LiquidateAtOracleArgs): Uint8Array;
223
- /**
224
- * CloseAccount instruction data (3 bytes)
225
- */
226
- export interface CloseAccountArgs {
227
- userIdx: number;
228
- }
229
- export declare function encodeCloseAccount(args: CloseAccountArgs): Uint8Array;
230
- /**
231
- * TopUpInsurance instruction data (9 bytes)
232
- */
233
- export interface TopUpInsuranceArgs {
234
- amount: bigint | string;
235
- }
236
- export declare function encodeTopUpInsurance(args: TopUpInsuranceArgs): Uint8Array;
237
- /**
238
- * TradeCpi instruction data (21 bytes)
239
- */
240
- export interface TradeCpiArgs {
241
- lpIdx: number;
242
- userIdx: number;
243
- size: bigint | string;
244
- }
245
- export declare function encodeTradeCpi(args: TradeCpiArgs): Uint8Array;
246
- /**
247
- * TradeCpiV2 instruction data (22 bytes) — PERC-154 optimized trade CPI.
248
- *
249
- * Same as TradeCpi but includes a caller-provided PDA bump byte.
250
- * Uses create_program_address instead of find_program_address,
251
- * saving ~1500 CU per trade. The bump should be obtained once via
252
- * deriveLpPda() and cached for the lifetime of the market.
253
- */
254
- export interface TradeCpiV2Args {
255
- lpIdx: number;
256
- userIdx: number;
257
- size: bigint | string;
258
- bump: number;
259
- }
260
- export declare function encodeTradeCpiV2(args: TradeCpiV2Args): Uint8Array;
261
- /**
262
- * SetRiskThreshold instruction data (17 bytes)
263
- */
264
- export interface SetRiskThresholdArgs {
265
- newThreshold: bigint | string;
266
- }
267
- export declare function encodeSetRiskThreshold(args: SetRiskThresholdArgs): Uint8Array;
268
- /**
269
- * UpdateAdmin instruction data (33 bytes)
270
- */
271
- export interface UpdateAdminArgs {
272
- newAdmin: PublicKey | string;
273
- }
274
- export declare function encodeUpdateAdmin(args: UpdateAdminArgs): Uint8Array;
275
- /**
276
- * CloseSlab instruction data (1 byte)
277
- */
278
- export declare function encodeCloseSlab(): Uint8Array;
279
- /**
280
- * UpdateConfig instruction data
281
- * Updates funding and threshold parameters at runtime (admin only)
282
- */
283
- export interface UpdateConfigArgs {
284
- fundingHorizonSlots: bigint | string;
285
- fundingKBps: bigint | string;
286
- fundingInvScaleNotionalE6: bigint | string;
287
- fundingMaxPremiumBps: bigint | string;
288
- fundingMaxBpsPerSlot: bigint | string;
289
- threshFloor: bigint | string;
290
- threshRiskBps: bigint | string;
291
- threshUpdateIntervalSlots: bigint | string;
292
- threshStepBps: bigint | string;
293
- threshAlphaBps: bigint | string;
294
- threshMin: bigint | string;
295
- threshMax: bigint | string;
296
- threshMinStep: bigint | string;
297
- }
298
- export declare function encodeUpdateConfig(args: UpdateConfigArgs): Uint8Array;
299
- /**
300
- * SetMaintenanceFee instruction data (17 bytes)
301
- */
302
- export interface SetMaintenanceFeeArgs {
303
- newFee: bigint | string;
304
- }
305
- export declare function encodeSetMaintenanceFee(args: SetMaintenanceFeeArgs): Uint8Array;
306
- /**
307
- * SetOracleAuthority instruction data (33 bytes)
308
- * Sets the oracle price authority. Pass zero pubkey to disable and require Pyth/Chainlink.
309
- */
310
- export interface SetOracleAuthorityArgs {
311
- newAuthority: PublicKey | string;
312
- }
313
- export declare function encodeSetOracleAuthority(args: SetOracleAuthorityArgs): Uint8Array;
314
- /**
315
- * PushOraclePrice instruction data (17 bytes)
316
- * Push a new oracle price (oracle authority only).
317
- * The price should be in e6 format and already include any inversion/scaling.
318
- */
319
- export interface PushOraclePriceArgs {
320
- priceE6: bigint | string;
321
- timestamp: bigint | string;
322
- }
323
- /**
324
- * Encode PushOraclePrice instruction data with validation.
325
- *
326
- * Validates oracle price constraints:
327
- * - Price cannot be zero (division by zero in on-chain engine)
328
- * - Price cannot exceed MAX_ORACLE_PRICE (prevents overflow in price math)
329
- *
330
- * @param args - PushOraclePrice arguments
331
- * @returns Encoded instruction data (17 bytes)
332
- * @throws Error if price is 0 or exceeds MAX_ORACLE_PRICE
333
- */
334
- export declare function encodePushOraclePrice(args: PushOraclePriceArgs): Uint8Array;
335
- /**
336
- * SetOraclePriceCap instruction data (9 bytes)
337
- * Set oracle price circuit breaker cap (admin only).
338
- *
339
- * max_change_e2bps: maximum oracle price movement per slot in 0.01 bps units.
340
- * 1_000_000 = 100% max move per slot.
341
- *
342
- * ⚠️ PERC-8191 (PR#150): cap=0 is NO LONGER accepted for admin-oracle markets.
343
- * - Hyperp markets: rejected if cap < DEFAULT_HYPERP_PRICE_CAP_E2BPS (1000).
344
- * - Admin-oracle markets: rejected if cap == 0 (circuit breaker bypass prevention).
345
- * - Pyth-pinned markets: immune (oracle_authority zeroed), any value accepted.
346
- *
347
- * Use a non-zero cap for all admin-oracle and Hyperp markets.
348
- */
349
- export interface SetOraclePriceCapArgs {
350
- maxChangeE2bps: bigint | string;
351
- }
352
- export declare function encodeSetOraclePriceCap(args: SetOraclePriceCapArgs): Uint8Array;
353
- /**
354
- * ResolveMarket instruction data (1 byte)
355
- * Resolves a binary/premarket - sets RESOLVED flag, positions force-closed via crank.
356
- * Requires admin oracle price (authority_price_e6) to be set first.
357
- */
358
- export declare function encodeResolveMarket(): Uint8Array;
359
- /**
360
- * WithdrawInsurance instruction data (1 byte)
361
- * Withdraw insurance fund to admin (requires RESOLVED and all positions closed).
362
- */
363
- export declare function encodeWithdrawInsurance(): Uint8Array;
364
- /**
365
- * AdminForceClose instruction data (3 bytes)
366
- * Force-close any position at oracle price (admin only, skips margin checks).
367
- */
368
- export interface AdminForceCloseArgs {
369
- targetIdx: number;
370
- }
371
- export declare function encodeAdminForceClose(args: AdminForceCloseArgs): Uint8Array;
372
- /**
373
- * UpdateRiskParams instruction data (17 or 25 bytes)
374
- * Update initial and maintenance margin BPS (admin only).
375
- *
376
- * R2-S13: The Rust program uses `data.len() >= 25` to detect the optional
377
- * tradingFeeBps field, so variable-length encoding is safe. When tradingFeeBps
378
- * is omitted, the data is 17 bytes (tag + 2×u64). When included, 25 bytes.
379
- */
380
- export interface UpdateRiskParamsArgs {
381
- initialMarginBps: bigint | string;
382
- maintenanceMarginBps: bigint | string;
383
- tradingFeeBps?: bigint | string;
384
- }
385
- export declare function encodeUpdateRiskParams(args: UpdateRiskParamsArgs): Uint8Array;
386
- /**
387
- * On-chain confirmation code for RenounceAdmin (must match program constant).
388
- * ASCII "RENOUNCE" as u64 LE = 0x52454E4F554E4345.
389
- */
390
- export declare const RENOUNCE_ADMIN_CONFIRMATION = 5928230587143701317n;
391
- /**
392
- * On-chain confirmation code for UnresolveMarket (must match program constant).
393
- */
394
- export declare const UNRESOLVE_CONFIRMATION = 16045690984503054900n;
395
- /**
396
- * RenounceAdmin instruction data (9 bytes)
397
- * Irreversibly set admin to all zeros. After this, all admin-only instructions fail.
398
- *
399
- * Requires the confirmation code 0x52454E4F554E4345 ("RENOUNCE" as u64 LE)
400
- * to prevent accidental invocation.
401
- */
402
- export declare function encodeRenounceAdmin(): Uint8Array;
403
- /**
404
- * LpVaultWithdraw (Tag 39, PERC-627 / GH#1926 / PERC-8287) — burn LP vault tokens and
405
- * withdraw proportional collateral.
406
- *
407
- * **BREAKING (PR#170):** accounts[9] = creatorLockPda is now REQUIRED.
408
- * Always include `deriveCreatorLockPda(programId, slab)` at position 9.
409
- * Non-creator withdrawers pass the derived PDA; if no lock exists on-chain
410
- * the check is a no-op. Omitting this account causes `ExpectLenFailed` on-chain.
411
- *
412
- * Instruction data: tag(1) + lp_amount(8) = 9 bytes
413
- *
414
- * Accounts (use ACCOUNTS_LP_VAULT_WITHDRAW):
415
- * [0] withdrawer signer
416
- * [1] slab writable
417
- * [2] withdrawerAta writable
418
- * [3] vault writable
419
- * [4] tokenProgram
420
- * [5] lpVaultMint writable
421
- * [6] withdrawerLpAta writable
422
- * [7] vaultAuthority
423
- * [8] lpVaultState writable
424
- * [9] creatorLockPda writable ← derive with deriveCreatorLockPda(programId, slab)
425
- *
426
- * @param lpAmount - Amount of LP vault tokens to burn.
427
- *
428
- * @example
429
- * ```ts
430
- * import { encodeLpVaultWithdraw, ACCOUNTS_LP_VAULT_WITHDRAW, buildAccountMetas } from "@percolator/sdk";
431
- * import { deriveCreatorLockPda, deriveVaultAuthority } from "@percolator/sdk";
432
- *
433
- * const [creatorLockPda] = deriveCreatorLockPda(PROGRAM_ID, slabKey);
434
- * const [vaultAuthority] = deriveVaultAuthority(PROGRAM_ID, slabKey);
435
- *
436
- * const data = encodeLpVaultWithdraw({ lpAmount: 1_000_000_000n });
437
- * const keys = buildAccountMetas(ACCOUNTS_LP_VAULT_WITHDRAW, {
438
- * withdrawer, slab: slabKey, withdrawerAta, vault, tokenProgram: TOKEN_PROGRAM_ID,
439
- * lpVaultMint, withdrawerLpAta, vaultAuthority, lpVaultState, creatorLockPda,
440
- * });
441
- * ```
442
- */
443
- export interface LpVaultWithdrawArgs {
444
- /** Amount of LP vault tokens to burn. */
445
- lpAmount: bigint | string;
446
- }
447
- export declare function encodeLpVaultWithdraw(args: LpVaultWithdrawArgs): Uint8Array;
448
- /**
449
- * PauseMarket instruction data (1 byte)
450
- * Pauses the market — disables trading, deposits, and withdrawals.
451
- */
452
- export declare function encodePauseMarket(): Uint8Array;
453
- /**
454
- * UnpauseMarket instruction data (1 byte)
455
- * Unpauses the market — re-enables trading, deposits, and withdrawals.
456
- */
457
- export declare function encodeUnpauseMarket(): Uint8Array;
458
- /**
459
- * SetPythOracle (Tag 32) — switch a market to Pyth-pinned mode.
460
- *
461
- * After this instruction:
462
- * - oracle_authority is cleared → PushOraclePrice is disabled
463
- * - index_feed_id is set to feed_id → validated on every price read
464
- * - max_staleness_secs and conf_filter_bps are updated
465
- * - All price reads go directly to read_pyth_price_e6() with on-chain
466
- * staleness + confidence + feed-ID validation (no silent fallback)
467
- *
468
- * Instruction data: tag(1) + feed_id(32) + max_staleness_secs(8) + conf_filter_bps(2) = 43 bytes
469
- *
470
- * Accounts:
471
- * 0. [signer, writable] Admin
472
- * 1. [writable] Slab
473
- */
474
- export interface SetPythOracleArgs {
475
- /** 32-byte Pyth feed ID. All zeros is invalid (reserved for Hyperp mode). */
476
- feedId: Uint8Array;
477
- /** Maximum age of Pyth price in seconds before OracleStale is returned. Must be > 0. */
478
- maxStalenessSecs: bigint;
479
- /** Max confidence/price ratio in bps (0 = no confidence check). */
480
- confFilterBps: number;
481
- }
482
- export declare function encodeSetPythOracle(args: SetPythOracleArgs): Uint8Array;
483
- /**
484
- * Derive the expected Pyth PriceUpdateV2 account address for a given feed ID.
485
- * Uses PDA seeds: [shard_id(2), feed_id(32)] under the Pyth Receiver program.
486
- *
487
- * @param feedId 32-byte Pyth feed ID
488
- * @param shardId Shard index (default 0 for mainnet/devnet)
489
- */
490
- export declare const PYTH_RECEIVER_PROGRAM_ID = "rec5EKMGg6MxZYaMdyBfgwp4d5rB9T1VQH5pJv5LtFJ";
491
- export declare function derivePythPriceUpdateAccount(feedId: Uint8Array, shardId?: number): Promise<string>;
492
- /**
493
- * UpdateMarkPrice (Tag 33) — permissionless EMA mark price crank.
494
- *
495
- * Reads the current oracle price on-chain, applies 8-hour EMA smoothing
496
- * with circuit breaker, and writes result to authority_price_e6.
497
- *
498
- * Instruction data: 1 byte (tag only — all params read from on-chain state)
499
- *
500
- * Accounts:
501
- * 0. [writable] Slab
502
- * 1. [] Oracle account (Pyth PriceUpdateV2 / Chainlink / DEX AMM)
503
- * 2. [] Clock sysvar (SysvarC1ock11111111111111111111111111111111)
504
- * 3..N [] Remaining accounts (PumpSwap vaults, etc. if needed)
505
- */
506
- export declare function encodeUpdateMarkPrice(): Uint8Array;
507
- /**
508
- * Mark price EMA parameters (must match program/src/percolator.rs constants).
509
- */
510
- export declare const MARK_PRICE_EMA_WINDOW_SLOTS = 72000n;
511
- export declare const MARK_PRICE_EMA_ALPHA_E6: bigint;
512
- /**
513
- * Compute the next EMA mark price step (TypeScript mirror of the on-chain function).
514
- */
515
- export declare function computeEmaMarkPrice(markPrevE6: bigint, oracleE6: bigint, dtSlots: bigint, alphaE6?: bigint, capE2bps?: bigint): bigint;
516
- /**
517
- * UpdateHyperpMark (Tag 34) — permissionless Hyperp EMA oracle crank.
518
- *
519
- * Reads the spot price from a PumpSwap, Raydium CLMM, or Meteora DLMM pool,
520
- * applies 8-hour EMA smoothing with circuit breaker, and writes the new mark
521
- * to authority_price_e6 on the slab.
522
- *
523
- * This is the core mechanism for permissionless token markets — no Pyth or
524
- * Chainlink feed is needed. The DEX AMM IS the oracle.
525
- *
526
- * Instruction data: 1 byte (tag only)
527
- *
528
- * Accounts:
529
- * 0. [writable] Slab
530
- * 1. [] DEX pool account (PumpSwap / Raydium CLMM / Meteora DLMM)
531
- * 2. [] Clock sysvar (SysvarC1ock11111111111111111111111111111111)
532
- * 3..N [] Remaining accounts (e.g. PumpSwap vault0 + vault1)
533
- */
534
- export declare function encodeUpdateHyperpMark(): Uint8Array;
535
- /**
536
- * Fund per-market isolated insurance balance.
537
- * Accounts: [admin(signer,writable), slab(writable), admin_ata(writable), vault(writable), token_program]
538
- */
539
- export declare function encodeFundMarketInsurance(args: {
540
- amount: bigint;
541
- }): Uint8Array;
542
- /**
543
- * Set insurance isolation BPS for a market.
544
- * Accounts: [admin(signer), slab(writable)]
545
- */
546
- export declare function encodeSetInsuranceIsolation(args: {
547
- bps: number;
548
- }): Uint8Array;
549
- /**
550
- * QueueWithdrawal (Tag 47, PERC-309) — queue a large LP withdrawal.
551
- *
552
- * Creates a withdraw_queue PDA. The LP tokens are claimed in epoch tranches
553
- * via ClaimQueuedWithdrawal. Call CancelQueuedWithdrawal to abort.
554
- *
555
- * Accounts: [user(signer,writable), slab(writable), lpVaultState, withdrawQueue(writable), systemProgram]
556
- *
557
- * @param lpAmount - Amount of LP tokens to queue for withdrawal.
558
- *
559
- * @example
560
- * ```ts
561
- * const data = encodeQueueWithdrawal({ lpAmount: 1_000_000_000n });
562
- * ```
563
- */
564
- export declare function encodeQueueWithdrawal(args: {
565
- lpAmount: bigint | string;
566
- }): Uint8Array;
567
- /**
568
- * ClaimQueuedWithdrawal (Tag 48, PERC-309) — claim one epoch tranche from a queued withdrawal.
569
- *
570
- * Burns LP tokens and releases one tranche of SOL to the user.
571
- * Call once per epoch until epochs_remaining == 0.
572
- *
573
- * Accounts: [user(signer,writable), slab(writable), withdrawQueue(writable),
574
- * lpVaultMint(writable), userLpAta(writable), vault(writable),
575
- * userAta(writable), vaultAuthority, tokenProgram, lpVaultState(writable)]
576
- */
577
- export declare function encodeClaimQueuedWithdrawal(): Uint8Array;
578
- /**
579
- * CancelQueuedWithdrawal (Tag 49, PERC-309) — cancel a queued withdrawal, refund remaining LP.
580
- *
581
- * Closes the withdraw_queue PDA and returns its rent lamports to the user.
582
- * The queued LP amount that was not yet claimed is NOT refunded — it is burned.
583
- * Use only to abandon a partial withdrawal.
584
- *
585
- * Accounts: [user(signer,writable), slab, withdrawQueue(writable)]
586
- */
587
- export declare function encodeCancelQueuedWithdrawal(): Uint8Array;
588
- /**
589
- * ExecuteAdl (Tag 50, PERC-305) — auto-deleverage the most profitable position.
590
- *
591
- * Permissionless. Surgically closes or reduces `targetIdx` position when
592
- * `pnl_pos_tot > max_pnl_cap` on the market. The caller receives no reward —
593
- * the incentive is unblocking the market for normal trading.
594
- *
595
- * Requires `UpdateRiskParams.max_pnl_cap > 0` on the market.
596
- *
597
- * Accounts: [caller(signer), slab(writable), clock, oracle, ...backupOracles?]
598
- *
599
- * @param targetIdx - Account index of the position to deleverage.
600
- *
601
- * @example
602
- * ```ts
603
- * const data = encodeExecuteAdl({ targetIdx: 5 });
604
- * ```
605
- */
606
- export interface ExecuteAdlArgs {
607
- targetIdx: number;
608
- }
609
- export declare function encodeExecuteAdl(args: ExecuteAdlArgs): Uint8Array;
610
- /**
611
- * CloseStaleSlabs (Tag 51) — close a slab of an invalid/old layout and recover rent SOL.
612
- *
613
- * Admin only. Skips slab_guard; validates header magic + admin authority instead.
614
- * Use for slabs created by old program layouts (e.g. pre-PERC-120 devnet deploys)
615
- * whose size does not match any current valid tier.
616
- *
617
- * Accounts: [dest(signer,writable), slab(writable)]
618
- */
619
- export declare function encodeCloseStaleSlabs(): Uint8Array;
620
- /**
621
- * ReclaimSlabRent (Tag 52) — reclaim rent from an uninitialised slab.
622
- *
623
- * For use when market creation failed mid-flow (slab funded but InitMarket not called).
624
- * The slab account must sign (proves the caller holds the slab keypair).
625
- * Cannot close an initialised slab (magic == PERCOLAT) — use CloseSlab (tag 13).
626
- *
627
- * Accounts: [dest(signer,writable), slab(signer,writable)]
628
- */
629
- export declare function encodeReclaimSlabRent(): Uint8Array;
630
- /**
631
- * AuditCrank (Tag 53) — verify conservation invariants on-chain (permissionless).
632
- *
633
- * Walks all accounts and verifies: capital sum, pnl_pos_tot, total_oi, LP consistency,
634
- * and solvency. Sets FLAG_PAUSED on violation (with a 150-slot cooldown guard to
635
- * prevent DoS from transient failures).
636
- *
637
- * Accounts: [slab(writable)]
638
- *
639
- * @example
640
- * ```ts
641
- * const data = encodeAuditCrank();
642
- * ```
643
- */
644
- export declare function encodeAuditCrank(): Uint8Array;
645
- /**
646
- * Parsed vAMM matcher parameters (from on-chain matcher context account)
647
- */
648
- export interface VammMatcherParams {
649
- mode: number;
650
- tradingFeeBps: number;
651
- baseSpreadBps: number;
652
- maxTotalBps: number;
653
- impactKBps: number;
654
- liquidityNotionalE6: bigint;
655
- }
656
- /** Magic bytes identifying a vAMM matcher context: "PERCMATC" as u64 LE */
657
- export declare const VAMM_MAGIC = 5784119745439683651n;
658
- /** Offset into matcher context where vAMM params start */
659
- export declare const CTX_VAMM_OFFSET = 64;
660
- /**
661
- * Compute execution price for a given LP quote.
662
- * For buys (isLong=true): price above oracle.
663
- * For sells (isLong=false): price below oracle.
664
- */
665
- export declare function computeVammQuote(params: VammMatcherParams, oraclePriceE6: bigint, tradeSize: bigint, isLong: boolean): bigint;
666
- /**
667
- * AdvanceOraclePhase (Tag 56) — permissionless oracle phase advancement.
668
- *
669
- * Checks if a market should transition from Phase 0→1→2 based on
670
- * time elapsed and cumulative volume. Anyone can call this.
671
- *
672
- * Instruction data: 1 byte (tag only)
673
- *
674
- * Accounts:
675
- * 0. [writable] Slab
676
- */
677
- export declare function encodeAdvanceOraclePhase(): Uint8Array;
678
- /** Oracle phase constants matching on-chain values */
679
- export declare const ORACLE_PHASE_NASCENT = 0;
680
- export declare const ORACLE_PHASE_GROWING = 1;
681
- export declare const ORACLE_PHASE_MATURE = 2;
682
- /** Phase transition thresholds (must match program constants) */
683
- export declare const PHASE1_MIN_SLOTS = 648000n;
684
- export declare const PHASE1_VOLUME_MIN_SLOTS = 36000n;
685
- export declare const PHASE2_VOLUME_THRESHOLD = 100000000000n;
686
- export declare const PHASE2_MATURITY_SLOTS = 3024000n;
687
- /**
688
- * Check if an oracle phase transition is due (TypeScript mirror of on-chain logic).
689
- *
690
- * @returns [newPhase, shouldTransition]
691
- */
692
- export declare function checkPhaseTransition(currentSlot: bigint, marketCreatedSlot: bigint, oraclePhase: number, cumulativeVolumeE6: bigint, phase2DeltaSlots: number, hasMatureOracle: boolean): [number, boolean];
693
- /**
694
- * TopUpKeeperFund (Tag 57) — permissionless keeper fund top-up.
695
- *
696
- * Instruction data: tag(1) + amount(8) = 9 bytes
697
- *
698
- * Accounts:
699
- * 0. [signer, writable] Funder
700
- * 1. [writable] Slab
701
- * 2. [writable] Keeper fund PDA
702
- * 3. [] System program
703
- */
704
- export interface TopUpKeeperFundArgs {
705
- amount: bigint | string;
706
- }
707
- export declare function encodeTopUpKeeperFund(args: TopUpKeeperFundArgs): Uint8Array;
708
- /**
709
- * SlashCreationDeposit (Tag 58) — permissionless: slash a market creator's deposit
710
- * after the spam grace period has elapsed (PERC-629).
711
- *
712
- * **WARNING**: Tag 58 is reserved in tags.rs but has NO instruction decoder or
713
- * handler in the on-chain program. Sending this instruction will fail with
714
- * `InvalidInstructionData`. Do not use until the on-chain handler is deployed.
715
- *
716
- * Instruction data: 1 byte (tag only)
717
- *
718
- * Accounts:
719
- * 0. [signer] Caller (anyone)
720
- * 1. [] Slab
721
- * 2. [writable] Creator history PDA
722
- * 3. [writable] Insurance vault
723
- * 4. [writable] Treasury
724
- * 5. [] System program
725
- *
726
- * @deprecated Not yet implemented on-chain — will fail with InvalidInstructionData.
727
- */
728
- export declare function encodeSlashCreationDeposit(): Uint8Array;
729
- /**
730
- * InitSharedVault (Tag 59) — admin: create the global shared vault PDA (PERC-628).
731
- *
732
- * Instruction data: tag(1) + epochDurationSlots(8) + maxMarketExposureBps(2) = 11 bytes
733
- *
734
- * Accounts:
735
- * 0. [signer] Admin
736
- * 1. [writable] Shared vault PDA
737
- * 2. [] System program
738
- */
739
- export interface InitSharedVaultArgs {
740
- epochDurationSlots: bigint | string;
741
- maxMarketExposureBps: number;
742
- }
743
- export declare function encodeInitSharedVault(args: InitSharedVaultArgs): Uint8Array;
744
- /**
745
- * AllocateMarket (Tag 60) — admin: allocate virtual liquidity from the shared vault
746
- * to a market (PERC-628).
747
- *
748
- * Instruction data: tag(1) + amount(16) = 17 bytes
749
- *
750
- * Accounts:
751
- * 0. [signer] Admin
752
- * 1. [] Slab
753
- * 2. [writable] Shared vault PDA
754
- * 3. [writable] Market alloc PDA
755
- * 4. [] System program
756
- */
757
- export interface AllocateMarketArgs {
758
- amount: bigint | string;
759
- }
760
- export declare function encodeAllocateMarket(args: AllocateMarketArgs): Uint8Array;
761
- /**
762
- * QueueWithdrawalSV (Tag 61) — user: queue a withdrawal request for the current
763
- * epoch (PERC-628). Tokens are locked until the epoch elapses.
764
- *
765
- * Instruction data: tag(1) + lpAmount(8) = 9 bytes
766
- *
767
- * Accounts:
768
- * 0. [signer] User
769
- * 1. [writable] Shared vault PDA
770
- * 2. [writable] Withdraw request PDA
771
- * 3. [] System program
772
- */
773
- export interface QueueWithdrawalSVArgs {
774
- lpAmount: bigint | string;
775
- }
776
- export declare function encodeQueueWithdrawalSV(args: QueueWithdrawalSVArgs): Uint8Array;
777
- /**
778
- * ClaimEpochWithdrawal (Tag 62) — user: claim a queued withdrawal after the epoch
779
- * has elapsed (PERC-628). Receives pro-rata collateral from the vault.
780
- *
781
- * Instruction data: 1 byte (tag only)
782
- *
783
- * Accounts:
784
- * 0. [signer] User
785
- * 1. [writable] Shared vault PDA
786
- * 2. [writable] Withdraw request PDA
787
- * 3. [] Slab
788
- * 4. [writable] Vault
789
- * 5. [writable] User ATA
790
- * 6. [] Vault authority
791
- * 7. [] Token program
792
- */
793
- export declare function encodeClaimEpochWithdrawal(): Uint8Array;
794
- /**
795
- * AdvanceEpoch (Tag 63) — permissionless crank: move the shared vault to the next
796
- * epoch once `epoch_duration_slots` have elapsed (PERC-628).
797
- *
798
- * Instruction data: 1 byte (tag only)
799
- *
800
- * Accounts:
801
- * 0. [signer] Caller (anyone)
802
- * 1. [writable] Shared vault PDA
803
- */
804
- export declare function encodeAdvanceEpoch(): Uint8Array;
805
- /**
806
- * SetOiImbalanceHardBlock (Tag 71, PERC-8110) — set OI imbalance hard-block threshold (admin only).
807
- *
808
- * When `|long_oi − short_oi| / total_oi * 10_000 >= threshold_bps`, any new trade that would
809
- * *increase* the imbalance is rejected with `OiImbalanceHardBlock` (error code 59).
810
- *
811
- * - `threshold_bps = 0`: hard block disabled.
812
- * - `threshold_bps = 8_000`: block trades that push skew above 80%.
813
- * - `threshold_bps = 10_000`: never allow >100% skew (always blocks one side when oi > 0).
814
- *
815
- * Instruction data layout: tag(1) + threshold_bps(2) = 3 bytes
816
- *
817
- * Accounts:
818
- * 0. [signer] admin
819
- * 1. [writable] slab
820
- *
821
- * @example
822
- * ```ts
823
- * const ix = new TransactionInstruction({
824
- * programId: PROGRAM_ID,
825
- * keys: buildAccountMetas(ACCOUNTS_SET_OI_IMBALANCE_HARD_BLOCK, { admin, slab }),
826
- * data: Buffer.from(encodeSetOiImbalanceHardBlock({ thresholdBps: 8_000 })),
827
- * });
828
- * ```
829
- */
830
- export declare function encodeSetOiImbalanceHardBlock(args: {
831
- thresholdBps: number;
832
- }): Uint8Array;
833
- /**
834
- * MintPositionNft (Tag 64, PERC-608) — mint a Token-2022 NFT representing a position.
835
- *
836
- * Creates a PositionNft PDA + Token-2022 mint with metadata, then mints 1 NFT to the
837
- * position owner's ATA. The NFT represents ownership of `user_idx` in the slab.
838
- *
839
- * Instruction data layout: tag(1) + user_idx(2) = 3 bytes
840
- *
841
- * Accounts:
842
- * 0. [signer, writable] payer
843
- * 1. [writable] slab
844
- * 2. [writable] position_nft PDA (created — seeds: ["position_nft", slab, user_idx])
845
- * 3. [writable] nft_mint PDA (created)
846
- * 4. [writable] owner_ata (Token-2022 ATA for owner)
847
- * 5. [signer] owner (must match engine account owner)
848
- * 6. [] vault_authority PDA
849
- * 7. [] token_2022_program
850
- * 8. [] system_program
851
- * 9. [] rent sysvar
852
- *
853
- * @example
854
- * ```ts
855
- * const ix = new TransactionInstruction({
856
- * programId: PROGRAM_ID,
857
- * keys: buildAccountMetas(ACCOUNTS_MINT_POSITION_NFT, [payer, slab, nftPda, nftMint, ownerAta, owner, vaultAuth, TOKEN_2022_PROGRAM_ID, SystemProgram.programId, SYSVAR_RENT_PUBKEY]),
858
- * data: Buffer.from(encodeMintPositionNft({ userIdx: 5 })),
859
- * });
860
- * ```
861
- */
862
- export interface MintPositionNftArgs {
863
- userIdx: number;
864
- }
865
- export declare function encodeMintPositionNft(args: MintPositionNftArgs): Uint8Array;
866
- /**
867
- * TransferPositionOwnership (Tag 65, PERC-608) — transfer an open position to a new owner.
868
- *
869
- * Transfers the Token-2022 NFT from current owner to new owner and updates the on-chain
870
- * engine account's owner field. Requires `pending_settlement == 0`.
871
- *
872
- * Instruction data layout: tag(1) + user_idx(2) = 3 bytes
873
- *
874
- * Accounts:
875
- * 0. [signer, writable] current_owner
876
- * 1. [writable] slab
877
- * 2. [writable] position_nft PDA
878
- * 3. [writable] nft_mint PDA
879
- * 4. [writable] current_owner_ata (source Token-2022 ATA)
880
- * 5. [writable] new_owner_ata (destination Token-2022 ATA)
881
- * 6. [] new_owner
882
- * 7. [] token_2022_program
883
- */
884
- export interface TransferPositionOwnershipArgs {
885
- userIdx: number;
886
- }
887
- export declare function encodeTransferPositionOwnership(args: TransferPositionOwnershipArgs): Uint8Array;
888
- /**
889
- * BurnPositionNft (Tag 66, PERC-608) — burn the Position NFT when a position is closed.
890
- *
891
- * Burns the NFT, closes the PositionNft PDA and the mint PDA, returning rent to the owner.
892
- * Can only be called after the position is fully closed (size == 0).
893
- *
894
- * Instruction data layout: tag(1) + user_idx(2) = 3 bytes
895
- *
896
- * Accounts:
897
- * 0. [signer, writable] owner
898
- * 1. [writable] slab
899
- * 2. [writable] position_nft PDA (closed — rent to owner)
900
- * 3. [writable] nft_mint PDA (closed via Token-2022 close_account)
901
- * 4. [writable] owner_ata (Token-2022 ATA, balance burned)
902
- * 5. [] vault_authority PDA
903
- * 6. [] token_2022_program
904
- */
905
- export interface BurnPositionNftArgs {
906
- userIdx: number;
907
- }
908
- export declare function encodeBurnPositionNft(args: BurnPositionNftArgs): Uint8Array;
909
- /**
910
- * SetPendingSettlement (Tag 67, PERC-608) — keeper sets the pending_settlement flag.
911
- *
912
- * Called by the keeper/admin before performing a funding settlement transfer.
913
- * Blocks NFT transfers until ClearPendingSettlement is called.
914
- * Admin-only (protected by GH#1475 keeper allowlist guard).
915
- *
916
- * Instruction data layout: tag(1) + user_idx(2) = 3 bytes
917
- *
918
- * Accounts:
919
- * 0. [signer] keeper / admin
920
- * 1. [] slab (read — for PDA verification + admin check)
921
- * 2. [writable] position_nft PDA
922
- */
923
- export interface SetPendingSettlementArgs {
924
- userIdx: number;
925
- }
926
- export declare function encodeSetPendingSettlement(args: SetPendingSettlementArgs): Uint8Array;
927
- /**
928
- * ClearPendingSettlement (Tag 68, PERC-608) — keeper clears the pending_settlement flag.
929
- *
930
- * Called by the keeper/admin after KeeperCrank has run and funding is settled.
931
- * Admin-only (protected by GH#1475 keeper allowlist guard).
932
- *
933
- * Instruction data layout: tag(1) + user_idx(2) = 3 bytes
934
- *
935
- * Accounts:
936
- * 0. [signer] keeper / admin
937
- * 1. [] slab (read — for PDA verification + admin check)
938
- * 2. [writable] position_nft PDA
939
- */
940
- export interface ClearPendingSettlementArgs {
941
- userIdx: number;
942
- }
943
- export declare function encodeClearPendingSettlement(args: ClearPendingSettlementArgs): Uint8Array;
944
- /**
945
- * TransferOwnershipCpi (Tag 69, PERC-608) — internal CPI target for percolator-nft TransferHook.
946
- *
947
- * Called by the Token-2022 TransferHook on the percolator-nft program during an NFT transfer.
948
- * Updates the engine account's owner field to the new_owner public key.
949
- * NOT intended for direct external use — always called via Token-2022 CPI.
950
- *
951
- * Instruction data layout: tag(1) + user_idx(2) + new_owner(32) = 35 bytes
952
- *
953
- * Accounts:
954
- * 0. [signer] nft TransferHook program (CPI caller)
955
- * 1. [writable] slab
956
- * (remaining accounts per Token-2022 ExtraAccountMeta spec)
957
- */
958
- export interface TransferOwnershipCpiArgs {
959
- userIdx: number;
960
- newOwner: PublicKey | string;
961
- }
962
- export declare function encodeTransferOwnershipCpi(args: TransferOwnershipCpiArgs): Uint8Array;
963
- /**
964
- * SetWalletCap (Tag 70, PERC-8111) — set the per-wallet position cap (admin only).
965
- *
966
- * Limits the maximum absolute position size any single wallet may hold on this market.
967
- * Enforced on every trade (TradeNoCpi + TradeCpi) after execute_trade.
968
- *
969
- * - `capE6 = 0`: disable per-wallet cap (no limit, default).
970
- * - `capE6 > 0`: max |position_size| in e6 units ($1 = 1_000_000).
971
- * Phase 1 launch value: 1_000_000_000n ($1,000).
972
- *
973
- * When a trade would breach the cap, the on-chain error `WalletPositionCapExceeded`
974
- * (error code 58) is returned.
975
- *
976
- * Instruction data layout: tag(1) + cap_e6(8) = 9 bytes
977
- *
978
- * Accounts:
979
- * 0. [signer] admin
980
- * 1. [writable] slab
981
- *
982
- * @example
983
- * ```ts
984
- * // Set $1K per-wallet cap
985
- * const ix = new TransactionInstruction({
986
- * programId: PROGRAM_ID,
987
- * keys: buildAccountMetas(ACCOUNTS_SET_WALLET_CAP, [admin, slab]),
988
- * data: Buffer.from(encodeSetWalletCap({ capE6: 1_000_000_000n })),
989
- * });
990
- *
991
- * // Disable cap
992
- * const disableIx = new TransactionInstruction({
993
- * programId: PROGRAM_ID,
994
- * keys: buildAccountMetas(ACCOUNTS_SET_WALLET_CAP, [admin, slab]),
995
- * data: Buffer.from(encodeSetWalletCap({ capE6: 0n })),
996
- * });
997
- * ```
998
- */
999
- export interface SetWalletCapArgs {
1000
- /** Max position size in e6 units. 0 = disabled. $1 = 1_000_000n, $1K = 1_000_000_000n. */
1001
- capE6: bigint | string;
1002
- }
1003
- export declare function encodeSetWalletCap(args: SetWalletCapArgs): Uint8Array;
1004
- /**
1005
- * InitMatcherCtx (Tag 75) — admin initializes the matcher context account for an LP slot.
1006
- *
1007
- * The matcher program (DHP6DtwXP1yJsz8YzfoeigRFPB979gzmumkmCxDLSkUX) requires its context
1008
- * account to be initialized before TradeCpi can work. Only the percolator program can sign
1009
- * as the LP PDA via invoke_signed, so this instruction acts as the trusted initializer.
1010
- *
1011
- * Instruction data layout: tag(1) + lp_idx(2) + kind(1) + trading_fee_bps(4) +
1012
- * base_spread_bps(4) + max_total_bps(4) + impact_k_bps(4) +
1013
- * liquidity_notional_e6(16) + max_fill_abs(16) + max_inventory_abs(16) +
1014
- * fee_to_insurance_bps(2) + skew_spread_mult_bps(2) = 72 bytes
1015
- *
1016
- * Accounts:
1017
- * 0. [signer] admin
1018
- * 1. [] slab (program-owned; used to verify admin + LP slot)
1019
- * 2. [writable] matcherCtx (must match LP's stored matcher_context)
1020
- * 3. [] matcherProg (executable; must match LP's stored matcher_program)
1021
- * 4. [] lpPda (PDA ["lp", slab, lp_idx]; required by CPI as signer)
1022
- */
1023
- export interface InitMatcherCtxArgs {
1024
- /** LP account index in the engine (0-based). */
1025
- lpIdx: number;
1026
- /** Matcher kind: 0=Passive, 1=vAMM. */
1027
- kind: number;
1028
- /** Base trading fee in bps (e.g. 30 = 0.30%). */
1029
- tradingFeeBps: number;
1030
- /** Base spread in bps. */
1031
- baseSpreadBps: number;
1032
- /** Max total spread in bps. */
1033
- maxTotalBps: number;
1034
- /** vAMM impact constant in bps (0 for passive matchers). */
1035
- impactKBps: number;
1036
- /** Liquidity notional in e6 units (0 for passive matchers). */
1037
- liquidityNotionalE6: bigint | string;
1038
- /** Max single fill size in absolute units (u128::MAX = no limit). */
1039
- maxFillAbs: bigint | string;
1040
- /** Max inventory size in absolute units (u128::MAX = no limit). */
1041
- maxInventoryAbs: bigint | string;
1042
- /** Fraction of fees routed to insurance fund in bps. */
1043
- feeToInsuranceBps: number;
1044
- /** Skew spread multiplier in bps (0 = disabled). */
1045
- skewSpreadMultBps: number;
1046
- }
1047
- export declare function encodeInitMatcherCtx(args: InitMatcherCtxArgs): Uint8Array;
1048
- /** SetInsuranceWithdrawPolicy (tag 22): authority + min_withdraw_base + max_withdraw_bps + cooldown_slots */
1049
- export interface SetInsuranceWithdrawPolicyArgs {
1050
- authority: PublicKey | string;
1051
- minWithdrawBase: bigint | string;
1052
- maxWithdrawBps: number;
1053
- cooldownSlots: bigint | string;
1054
- }
1055
- export declare function encodeSetInsuranceWithdrawPolicy(args: SetInsuranceWithdrawPolicyArgs): Uint8Array;
1056
- /** WithdrawInsuranceLimited (tag 23): amount */
1057
- export declare function encodeWithdrawInsuranceLimited(args: {
1058
- amount: bigint | string;
1059
- }): Uint8Array;
1060
- /** ResolvePermissionless (tag 29): no args */
1061
- export declare function encodeResolvePermissionless(): Uint8Array;
1062
- /** ForceCloseResolved (tag 30): user_idx */
1063
- export declare function encodeForceCloseResolved(args: {
1064
- userIdx: number;
1065
- }): Uint8Array;
1066
- /** CreateLpVault (tag 37): fee_share_bps + util_curve_enabled */
1067
- export declare function encodeCreateLpVault(args: {
1068
- feeShareBps: bigint | string;
1069
- utilCurveEnabled?: boolean;
1070
- }): Uint8Array;
1071
- /** LpVaultDeposit (tag 38): amount */
1072
- export declare function encodeLpVaultDeposit(args: {
1073
- amount: bigint | string;
1074
- }): Uint8Array;
1075
- /** LpVaultCrankFees (tag 40): no args */
1076
- export declare function encodeLpVaultCrankFees(): Uint8Array;
1077
- /** ChallengeSettlement (tag 43): proposed_price_e6 */
1078
- export declare function encodeChallengeSettlement(args: {
1079
- proposedPriceE6: bigint | string;
1080
- }): Uint8Array;
1081
- /** ResolveDispute (tag 44): accept (0 = reject, 1 = accept) */
1082
- export declare function encodeResolveDispute(args: {
1083
- accept: number;
1084
- }): Uint8Array;
1085
- /** DepositLpCollateral (tag 45): user_idx + lp_amount */
1086
- export declare function encodeDepositLpCollateral(args: {
1087
- userIdx: number;
1088
- lpAmount: bigint | string;
1089
- }): Uint8Array;
1090
- /** WithdrawLpCollateral (tag 46): user_idx + lp_amount */
1091
- export declare function encodeWithdrawLpCollateral(args: {
1092
- userIdx: number;
1093
- lpAmount: bigint | string;
1094
- }): Uint8Array;
1095
- /** SetOffsetPair (tag 54): offset_bps */
1096
- export declare function encodeSetOffsetPair(args: {
1097
- offsetBps: number;
1098
- }): Uint8Array;
1099
- /** AttestCrossMargin (tag 55): user_idx_a + user_idx_b */
1100
- export declare function encodeAttestCrossMargin(args: {
1101
- userIdxA: number;
1102
- userIdxB: number;
1103
- }): Uint8Array;
1104
- /** RescueOrphanVault (tag 72): no args */
1105
- export declare function encodeRescueOrphanVault(): Uint8Array;
1106
- /** CloseOrphanSlab (tag 73): no args */
1107
- export declare function encodeCloseOrphanSlab(): Uint8Array;
1108
- /** SetDexPool (tag 74): pool pubkey */
1109
- export declare function encodeSetDexPool(args: {
1110
- pool: PublicKey | string;
1111
- }): Uint8Array;