/** * @name perps/phoenix/phoenix-builder-core * @description Shared types and helpers for Phoenix perps instruction builders. * * Provides UnsignedTransactionResult and helpers to convert @ellipsis-labs/rise * instruction objects (InstructionsWithAccountsAndData) into base64-serialized * unsigned @solana/web3.js Transactions. * * @module perps/phoenix/phoenix-builder-core */ import { PublicKey, TransactionInstruction, type Connection } from '@solana/web3.js'; /** Side of a Phoenix order. */ export type PhoenixSide = 'bid' | 'ask'; /** Direction for conditional/trigger orders. */ export type PhoenixDirection = 'greater-than' | 'less-than'; /** Stop loss order kind. */ export type PhoenixStopLossOrderKind = 'ioc' | 'limit'; /** * Result of building an unsigned Phoenix transaction. * Mirrors the Adrena UnsignedTransactionResult pattern. * All builders return this — NO signing happens server-side. */ export interface UnsignedTransactionResult { /** Base64-serialized unsigned transaction. */ transactionBase64: string; /** Transaction encoding. */ encoding: 'base64'; /** Machine-readable approval gate. UIs may show signing controls only when true. */ safeToApprove: true; /** Machine-readable negative approval gate. Successful builder results keep this false. */ approvalBlocked: false; /** Fee payer public key. */ feePayer: string; /** Description of the instructions included. */ instructions: string[]; /** Next tool to call for signing. */ nextTool: 'sap_payments_finalize_transaction'; /** Arguments to pass to the finalize tool. */ finalizeArgs: { transactionBase64: string; submit: boolean; }; /** Builder-side simulation error for this exact unsigned transaction, if any. */ simulationError?: string; /** Program logs captured during the best-effort simulation. */ simulationLogs?: string[]; } /** * Phoenix instruction shape from @ellipsis-labs/rise SDK. * InstructionsWithAccountsAndData has `accounts` (AccountMeta[]) and `data` (Uint8Array). */ interface PhoenixInstruction { readonly accounts: readonly PhoenixAccountMeta[]; readonly data: ReadonlyUint8Array; } /** AccountMeta from @solana/kit — has address, role, isSigner, isWritable. */ interface PhoenixAccountMeta { readonly address: unknown; readonly role: number; readonly isSigner: boolean; readonly isWritable: boolean; } /** ReadonlyUint8Array type from @solana/kit. */ type ReadonlyUint8Array = Uint8Array; /** * Convert a Phoenix SDK instruction (InstructionsWithAccountsAndData) to a * @solana/web3.js TransactionInstruction. * * @param ix — Phoenix instruction with accounts and data. * @param programId — Phoenix program ID. * @returns TransactionInstruction compatible with @solana/web3.js Transaction. */ export declare function phoenixIxToTransactionInstruction(ix: PhoenixInstruction, programId: string): TransactionInstruction; /** * Convert multiple Phoenix SDK instructions to @solana/web3.js TransactionInstructions. * @param ixs — Array of Phoenix instructions. * @param programId — Phoenix program ID. * @returns Array of TransactionInstructions. */ export declare function phoenixIxsToTransactionInstructions(ixs: readonly unknown[], programId: string): TransactionInstruction[]; /** * Serialize an unsigned transaction to base64. * * Fetches a recent blockhash, constructs a Transaction with the given instructions, * optionally simulates it, and returns the base64-serialized unsigned transaction. * * @param connection — Solana RPC connection. * @param feePayer — Fee payer public key. * @param instructions — Array of TransactionInstructions to include. * @param programId — Phoenix program ID (for instruction conversion if needed). * @returns Object with transactionBase64 and optional simulation data. */ export declare function serializeUnsignedPhoenixTx(connection: Connection, feePayer: PublicKey, instructions: TransactionInstruction[]): Promise<{ transactionBase64: string; simulationLogs?: string[]; simulationError?: string; simulationUnitsConsumed?: number; }>; /** * Build a standard UnsignedTransactionResult from a serialized transaction. * * @param transactionBase64 — Base64-serialized unsigned transaction. * @param feePayer — Fee payer public key. * @param instructionNames — List of instruction names for the `instructions` field. * @returns UnsignedTransactionResult. */ export declare function buildPhoenixResult(transactionBase64: string, feePayer: PublicKey, instructionNames: string[], simulation?: { simulationError?: string; simulationLogs?: string[]; }): UnsignedTransactionResult; /** * Convert a Phoenix SDK instruction result (single ix) to an unsigned transaction. * * @param connection — Solana RPC connection. * @param feePayer — Fee payer public key. * @param phoenixIx — Phoenix instruction (InstructionsWithAccountsAndData). * @param programId — Phoenix program ID. * @param instructionName — Name for the instructions field. * @returns UnsignedTransactionResult. */ export declare function buildFromPhoenixIx(connection: Connection, feePayer: PublicKey, phoenixIx: unknown, programId: string, instructionName: string): Promise; /** * Convert multiple Phoenix SDK instructions to an unsigned transaction. * * @param connection — Solana RPC connection. * @param feePayer — Fee payer public key. * @param phoenixIxs — Array of Phoenix instructions. * @param programId — Phoenix program ID. * @param instructionNames — Names for the instructions field. * @returns UnsignedTransactionResult. */ export declare function buildFromPhoenixIxs(connection: Connection, feePayer: PublicKey, phoenixIxs: readonly unknown[], programId: string, instructionNames: string[]): Promise; export {}; //# sourceMappingURL=phoenix-builder-core.d.ts.map