import { BN, type IdlTypes } from "@coral-xyz/anchor"; import { type AccountMeta, PublicKey, type TransactionInstruction, type TransactionSignature, type VersionedTransaction } from "@solana/web3.js"; import { PhoenixPolicy } from "../deser/integrationPolicies"; import type { ExtPhoenix } from "../glamExports"; import { PhoenixApiClient, PhoenixSnapshot } from "../utils/phoenixApi"; import { BaseClient, BaseTxBuilder, type ProtocolPolicyClient, type ProtocolPolicyTxBuilder, type TxOptions } from "./base"; export type PhoenixIdlTypes = IdlTypes; export type PhoenixBaseLots = PhoenixIdlTypes["baseLots"]; export type PhoenixCancelUpToInstruction = PhoenixIdlTypes["cancelUpToInstruction"]; export type PhoenixDepositFundsInstruction = PhoenixIdlTypes["depositFundsInstruction"]; export type PhoenixDepositParams = PhoenixIdlTypes["depositParams"]; export type PhoenixOrderFlags = PhoenixIdlTypes["orderFlags"]; export type PhoenixOrderIds = PhoenixIdlTypes["orderIds"]; export type PhoenixOrderPacket = PhoenixIdlTypes["orderPacket"]; export type PhoenixQuoteLots = PhoenixIdlTypes["quoteLots"]; export type PhoenixRegisterTraderParams = PhoenixIdlTypes["registerTraderParams"]; export type PhoenixSelfTradeBehavior = PhoenixIdlTypes["selfTradeBehavior"]; export type PhoenixSide = PhoenixIdlTypes["side"]; export type PhoenixTicks = PhoenixIdlTypes["ticks"]; export type PhoenixWithdrawFundsInstruction = PhoenixIdlTypes["withdrawFundsInstruction"]; export type PhoenixWithdrawParams = PhoenixIdlTypes["withdrawParams"]; export type PhoenixPolicyInput = PhoenixIdlTypes["phoenixPolicy"]; export type PhoenixTraderIndexes = { traderPdaIndex?: number; subaccountIndex?: number; }; export type PhoenixRemainingAccounts = { remainingAccounts: AccountMeta[]; }; export type PhoenixRegisterTraderAccounts = { traderAccount?: PublicKey; logAuthority?: PublicKey; globalConfig?: PublicKey; }; export type PhoenixEmberAccounts = { inputMint: PublicKey; outputMint: PublicKey; inputTokenAccount?: PublicKey; outputTokenAccount?: PublicKey; emberState?: PublicKey; emberVault?: PublicKey; tokenProgram?: PublicKey; }; export declare function getPhoenixTraderPda(authority: PublicKey, traderPdaIndex?: number, subaccountIndex?: number): PublicKey; export declare function getPhoenixSplineCollectionPda(market: PublicKey): PublicKey; export declare function getPhoenixGlobalVaultPda(mint: PublicKey): PublicKey; export declare function getEmberStatePda(): PublicKey; export declare function getEmberVaultPda(): PublicKey; declare class TxBuilder extends BaseTxBuilder implements ProtocolPolicyTxBuilder { getEmberCpiAccounts(accounts: PhoenixEmberAccounts, signer?: PublicKey): { glamState: PublicKey; glamVault: PublicKey; glamSigner: PublicKey; integrationAuthority: PublicKey; cpiProgram: PublicKey; glamProtocolProgram: PublicKey; systemProgram: PublicKey; emberState: PublicKey; inputMint: PublicKey; outputMint: PublicKey; inputTokenAccount: PublicKey; outputTokenAccount: PublicKey; emberVault: PublicKey; tokenProgram: PublicKey; }; /** * Account map shared by every ext_phoenix Phoenix-CPI instruction * (`glam_state`, `glam_vault`, `glam_signer`, integration authority, * `cpi_program=Phoenix`, the GLAM protocol program, system program). */ getPhoenixCpiAccounts(signer?: PublicKey): { glamState: PublicKey; glamVault: PublicKey; glamSigner: PublicKey; integrationAuthority: PublicKey; cpiProgram: PublicKey; glamProtocolProgram: PublicKey; systemProgram: PublicKey; }; registerTraderIx(params: PhoenixRegisterTraderParams, accounts?: PhoenixRegisterTraderAccounts, signer?: PublicKey): Promise; updateTraderStateIx(accounts: PhoenixRemainingAccounts, signer?: PublicKey): Promise; emberDepositIx(params: PhoenixDepositParams, accounts: PhoenixEmberAccounts, signer?: PublicKey): Promise; depositFundsIx(params: PhoenixDepositFundsInstruction, accounts: PhoenixRemainingAccounts, signer?: PublicKey): Promise; emberWithdrawIx(params: PhoenixWithdrawParams, accounts: PhoenixEmberAccounts, signer?: PublicKey): Promise; withdrawFundsIx(params: PhoenixWithdrawFundsInstruction, accounts: PhoenixRemainingAccounts, signer?: PublicKey): Promise; placeLimitOrderIx(packet: PhoenixOrderPacket, accounts: PhoenixRemainingAccounts, signer?: PublicKey): Promise; placeMarketOrderIx(packet: PhoenixOrderPacket, accounts: PhoenixRemainingAccounts, signer?: PublicKey): Promise; cancelAllIx(accounts: PhoenixRemainingAccounts, signer?: PublicKey): Promise; cancelOrdersByIdIx(orderIds: PhoenixOrderIds, accounts: PhoenixRemainingAccounts, signer?: PublicKey): Promise; cancelUpToIx(args: PhoenixCancelUpToInstruction, accounts: PhoenixRemainingAccounts, signer?: PublicKey): Promise; setPolicyIx(policy: PhoenixPolicy, signer?: PublicKey): Promise; setPolicyTx(policy: PhoenixPolicy, txOptions?: TxOptions): Promise; clearPolicyIx(signer?: PublicKey): Promise; clearPolicyTx(txOptions?: TxOptions): Promise; registerTraderTx(params: PhoenixRegisterTraderParams, accounts?: PhoenixRegisterTraderAccounts, txOptions?: TxOptions): Promise; updateTraderStateTx(accounts: PhoenixRemainingAccounts, txOptions?: TxOptions): Promise; /** * Remaining-accounts list for `deposit_funds` — the vault token account * holding the canonical collateral, the trader PDA, Phoenix's global vault * for that mint, the SPL token program, and the trader-index/active-buffer * chunks from the snapshot. */ getDepositRemainingAccounts(snapshot: PhoenixSnapshot, indexes?: PhoenixTraderIndexes): AccountMeta[]; /** * Remaining-accounts list for `withdraw_funds`. Same shape as the deposit * variant plus the perp asset map and the global withdraw queue, which the * withdraw path mutates. */ getWithdrawRemainingAccounts(snapshot: PhoenixSnapshot, indexes?: PhoenixTraderIndexes): AccountMeta[]; deposit(amount: BN, txOptions?: TxOptions): Promise; withdraw(amount: BN, txOptions?: TxOptions): Promise; depositFundsTx(params: PhoenixDepositFundsInstruction, accounts: PhoenixRemainingAccounts, txOptions?: TxOptions): Promise; withdrawFundsTx(params: PhoenixWithdrawFundsInstruction, accounts: PhoenixRemainingAccounts, txOptions?: TxOptions): Promise; placeLimitOrderTx(packet: PhoenixOrderPacket, accounts: PhoenixRemainingAccounts, txOptions?: TxOptions): Promise; placeMarketOrderTx(packet: PhoenixOrderPacket, accounts: PhoenixRemainingAccounts, txOptions?: TxOptions): Promise; cancelAllTx(accounts: PhoenixRemainingAccounts, txOptions?: TxOptions): Promise; cancelOrdersByIdTx(orderIds: PhoenixOrderIds, accounts: PhoenixRemainingAccounts, txOptions?: TxOptions): Promise; cancelUpToTx(args: PhoenixCancelUpToInstruction, accounts: PhoenixRemainingAccounts, txOptions?: TxOptions): Promise; } export declare class PhoenixClient implements ProtocolPolicyClient { readonly base: BaseClient; readonly txBuilder: TxBuilder; readonly phoenixApi: PhoenixApiClient; constructor(base: BaseClient); /** The ext_phoenix program id this client talks to. */ get programId(): PublicKey; /** Bit flag identifying Phoenix inside the GLAM integration ACL bitmask. */ get protocolBitflag(): number; /** PDA the ext_phoenix program signs CPIs with into Phoenix and Ember. */ getIntegrationAuthorityPda(): PublicKey; /** * PDA of a Phoenix trader account owned by the GLAM vault (defaults to the * vault PDA as authority). `traderPdaIndex` selects the parent trader and * `subaccountIndex` selects a child subaccount under that parent. */ getTraderPda(traderPdaIndex?: number, subaccountIndex?: number, authority?: PublicKey): PublicKey; /** PDA of the spline-collection account associated with a Phoenix market. */ getSplineCollectionPda(market: PublicKey): PublicKey; /** PDA of Phoenix's global-vault token account for a given mint. */ getGlobalVaultPda(mint: PublicKey): PublicKey; /** PDA of the Ember exchange-state account that backs Phoenix conversions. */ getEmberStatePda(): PublicKey; /** PDA of Ember's USDC vault that mints/burns canonical collateral. */ getEmberVaultPda(): PublicKey; /** * The three accounts every Phoenix CPI begins with (program, log authority, * global config). `globalConfigWritable` toggles the writable flag on the * global config — set true for instructions that mutate exchange state. */ getPhoenixRemainingPrefix(globalConfigWritable: boolean): AccountMeta[]; /** * Remaining-accounts list for place/cancel/order-book CPIs against a single * Phoenix market. Includes the trader PDA, perp asset map, trader indices, * the market itself, and its spline collection. */ getMarketRemainingAccounts(snapshot: PhoenixSnapshot, market: PublicKey | string, indexes?: PhoenixTraderIndexes): AccountMeta[]; /** * Remaining-accounts list for `update_trader_state` — settles funding for * the trader and may evict it from the active-trader buffer once it no * longer holds resting orders. */ getUpdateTraderStateRemainingAccounts(snapshot: PhoenixSnapshot, indexes?: PhoenixTraderIndexes): AccountMeta[]; /** Fetches the on-chain PhoenixPolicy stored under this vault, if any. */ fetchPolicy(): Promise; /** Writes the PhoenixPolicy (market allowlist, order types, etc.). */ setPolicy(policy: PhoenixPolicy, txOptions?: TxOptions): Promise; /** Deletes the stored PhoenixPolicy. Future Phoenix policy checks fail closed. */ clearPolicy(txOptions?: TxOptions): Promise; /** * Creates a Phoenix trader account for the vault (parent or child subaccount) * sized to hold `maxPositions`. */ registerTrader(params: PhoenixRegisterTraderParams, accounts?: PhoenixRegisterTraderAccounts, txOptions?: TxOptions): Promise; /** * Settles funding for the vault's trader and may evict it from the active * buffer when no resting orders remain. Idempotent housekeeping call. */ updateTraderState(accounts: PhoenixRemainingAccounts, txOptions?: TxOptions): Promise; /** * Full deposit flow in one transaction: converts USDC to canonical * collateral via Ember, then deposits the canonical amount into the vault's * Phoenix trader account. */ deposit(amount: BN | number, txOptions?: TxOptions): Promise; /** * Full withdraw flow in one transaction: withdraws canonical collateral * from Phoenix and converts it back to USDC via Ember. */ withdraw(amount: BN | number, txOptions?: TxOptions): Promise; /** * Phoenix-only `deposit_funds` (no Ember leg) — moves an already-canonical * token balance from the vault's token account into Phoenix. */ depositFunds(params: PhoenixDepositFundsInstruction, accounts: PhoenixRemainingAccounts, txOptions?: TxOptions): Promise; /** * Phoenix-only `withdraw_funds` (no Ember leg) — pulls canonical collateral * out of Phoenix back to the vault's token account. */ withdrawFunds(params: PhoenixWithdrawFundsInstruction, accounts: PhoenixRemainingAccounts, txOptions?: TxOptions): Promise; /** Places a Phoenix limit order against the market in `accounts`. */ placeLimitOrder(packet: PhoenixOrderPacket, accounts: PhoenixRemainingAccounts, txOptions?: TxOptions): Promise; /** Places an immediate-or-cancel market order against the market. */ placeMarketOrder(packet: PhoenixOrderPacket, accounts: PhoenixRemainingAccounts, txOptions?: TxOptions): Promise; /** Cancels all resting orders the vault has on the given market. */ cancelAll(accounts: PhoenixRemainingAccounts, txOptions?: TxOptions): Promise; /** Cancels the specific resting orders identified by `orderIds`. */ cancelOrdersById(orderIds: PhoenixOrderIds, accounts: PhoenixRemainingAccounts, txOptions?: TxOptions): Promise; /** * Cancels up to `num_orders_to_cancel` resting orders on a side, optionally * bounded by a price tick limit. */ cancelUpTo(args: PhoenixCancelUpToInstruction, accounts: PhoenixRemainingAccounts, txOptions?: TxOptions): Promise; } export {};