/** * @name perps/phoenix/phoenix-builder-trading * @description Trading instruction builders for Phoenix perps using the rise SDK. * * Uses createPhoenixClient to access client.ixs for building unsigned transactions: * place limit order, place market order, cancel orders by id, cancel all, * place stop loss, cancel stop loss, place position conditional order. * * ALL builders return UnsignedTransactionResult — NO signing happens server-side. * * @module perps/phoenix/phoenix-builder-trading */ import { PublicKey, type Connection } from '@solana/web3.js'; import { SelfTradeBehavior } from '@ellipsis-labs/rise'; import { type PhoenixSide, type PhoenixDirection, type PhoenixStopLossOrderKind, type UnsignedTransactionResult } from './phoenix-builder-core.js'; /** * Builder-fee tiers for the $STEVE holder program (mirrors * steve-website src/lib/steve-token.ts). Standard builder fee is 10 bps; * higher $STEVE holder tiers pay proportionally less down to 5 bps * (Platinum = half the fee = the on-chain "-50%" discount). */ export declare const PHOENIX_BUILDER_FEE_BPS_STANDARD = 10n; export declare const PHOENIX_BUILDER_FEE_BPS_MINIMUM = 5n; /** Resolve the Flight builder fee override (bps) for a $STEVE holder tier. * Returns null when the Flight builder is not configured. */ export declare function resolveBuilderFeeBpsForTier(tierId: string | undefined): bigint | null; /** * Create a Phoenix client with exchange metadata for instruction building. * The client caches exchange metadata (markets, addresses) for PDA resolution. * * When STEVE_BUILDER_AUTHORITY is set, order instructions are routed through * the Phoenix Flight proxy with a builder fee (feeBpsOverride per $STEVE * tier). With no env set the behaviour is identical to before — zero impact * on existing flows. * * @param connection — Solana RPC connection (used for exchange metadata fallback). * @param options — feeBpsOverride: per-order builder fee in bps (null = builder default). * @returns Phoenix client with .ixs builder surface. */ export declare function getPhoenixClient(connection: Connection, options?: { feeBpsOverride?: bigint | null; }): Promise; export interface PhoenixMarketUnits { baseLotsDecimals: number; tickSize: number; } /** Integer-safe base-units → base-lots conversion (avoids float precision loss). */ export declare function baseUnitsToBaseLots(baseUnits: string, units: PhoenixMarketUnits): bigint; /** USD price → price-in-ticks (integer-safe). * priceTicks = priceUsd * 1e6 / (tickSize * 10^baseLotsDecimals). */ export declare function priceUsdToTicks(priceUsd: string, units: PhoenixMarketUnits): bigint; /** * Build a place limit order transaction. * * @param connection — Solana RPC connection. * @param owner — Trader wallet public key (fee payer and signer). * @param symbol — Market symbol (e.g. "SOL-PERP"). * @param side — Order side: 'bid' (buy) or 'ask' (sell). * @param priceInTicks — Price in ticks (bigint). * @param numBaseLots — Size in base lots (bigint). * @param clientOrderId — Client order ID for tracking (bigint). * @param options — Optional: selfTradeBehavior, matchLimit, lastValidSlot, orderFlags (e.g. OrderFlags.ReduceOnly = 128), traderPdaIndex. * @returns UnsignedTransactionResult with base64-serialized unsigned transaction. */ export declare function buildPlaceLimitOrder(connection: Connection, owner: PublicKey, symbol: string, side: PhoenixSide, priceInTicks: bigint, numBaseLots: bigint, clientOrderId: bigint, options?: { selfTradeBehavior?: SelfTradeBehavior; matchLimit?: bigint | null; lastValidSlot?: bigint | null; orderFlags?: number; /** $STEVE holder tier id — drives the Flight builder-fee override. */ holderTierId?: string; traderPdaIndex?: number; traderSubaccountIndex?: number; }): Promise; /** * Build a place market order (IOC) transaction. * * @param connection — Solana RPC connection. * @param owner — Trader wallet public key (fee payer and signer). * @param symbol — Market symbol. * @param side — Order side: 'bid' (buy) or 'ask' (sell). * @param numBaseLots — Size in base lots (bigint). * @param options — Optional: priceInTicks (null = market), numQuoteLots, minBaseLotsToFill, minQuoteLotsToFill, traderPdaIndex. * @returns UnsignedTransactionResult with base64-serialized unsigned transaction. */ export declare function buildPlaceMarketOrder(connection: Connection, owner: PublicKey, symbol: string, side: PhoenixSide, numBaseLots: bigint, options?: { priceInTicks?: bigint | null; numQuoteLots?: bigint | null; minBaseLotsToFill?: bigint; minQuoteLotsToFill?: bigint; clientOrderId?: bigint; orderFlags?: number; /** $STEVE holder tier id — drives the Flight builder-fee override. */ holderTierId?: string; traderPdaIndex?: number; traderSubaccountIndex?: number; }): Promise; /** * Build a cancel orders by ID transaction. * * @param connection — Solana RPC connection. * @param owner — Trader wallet public key. * @param symbol — Market symbol. * @param orders — Array of orders to cancel (priceInTicks + orderSequenceNumber). * @param options — Optional: traderPdaIndex, traderSubaccountIndex. * @returns UnsignedTransactionResult. */ export declare function buildCancelOrdersById(connection: Connection, owner: PublicKey, symbol: string, orders: Array<{ priceInTicks: bigint | number | string; orderSequenceNumber: string | number | bigint; }>, options?: { traderPdaIndex?: number; traderSubaccountIndex?: number; }): Promise; /** * Build a cancel all orders transaction for a market. * * @param connection — Solana RPC connection. * @param owner — Trader wallet public key. * @param symbol — Market symbol. * @param options — Optional: traderPdaIndex, traderSubaccountIndex, positionAuthority. * @returns UnsignedTransactionResult. */ export declare function buildCancelAll(connection: Connection, owner: PublicKey, symbol: string, options?: { traderPdaIndex?: number; traderSubaccountIndex?: number; positionAuthority?: string; }): Promise; /** * Build a place stop loss order transaction. * * @param connection — Solana RPC connection. * @param owner — Trader wallet public key. * @param symbol — Market symbol. * @param triggerPrice — Trigger price in ticks (bigint). * @param tradeSide — Side of the position being protected: 'bid' or 'ask'. * @param executionDirection — Direction: 'greater-than' or 'less-than'. * @param orderKind — Stop loss order kind: 'ioc' or 'limit'. * @param options — Optional: executionPrice, slippageBps, traderPdaIndex. * @returns UnsignedTransactionResult. */ export declare function buildPlaceStopLoss(connection: Connection, owner: PublicKey, symbol: string, triggerPrice: bigint, tradeSide: PhoenixSide, executionDirection: PhoenixDirection, orderKind: PhoenixStopLossOrderKind, options?: { executionPrice?: bigint; slippageBps?: number | null; traderPdaIndex?: number; traderSubaccountIndex?: number; }): Promise; /** * Build a cancel stop loss order transaction. * * @param connection — Solana RPC connection. * @param owner — Trader wallet public key. * @param symbol — Market symbol. * @param executionDirection — Direction: 'greater-than' or 'less-than'. * @param options — Optional: traderPdaIndex, traderSubaccountIndex, funder. * @returns UnsignedTransactionResult. */ export declare function buildCancelStopLoss(connection: Connection, owner: PublicKey, symbol: string, executionDirection: PhoenixDirection, options?: { traderPdaIndex?: number; traderSubaccountIndex?: number; funder?: string; }): Promise; /** * Build a place position conditional order transaction (take-profit / stop-loss * attached to a position rather than a specific resting order). * * @param connection — Solana RPC connection. * @param owner — Trader wallet public key. * @param symbol — Market symbol. * @param options — Conditional order params: greaterTriggerOrder, lessTriggerOrder, sizeBaseLots, sizePercent, traderPdaIndex. * @returns UnsignedTransactionResult. */ export declare function buildPlacePositionConditionalOrder(connection: Connection, owner: PublicKey, symbol: string, options: { greaterTriggerOrder?: { triggerDirection: PhoenixDirection; tradeSide: PhoenixSide; orderKind?: PhoenixStopLossOrderKind; triggerPrice: bigint; executionPrice?: bigint | null; slippageBps?: number | null; } | null; lessTriggerOrder?: { triggerDirection: PhoenixDirection; tradeSide: PhoenixSide; orderKind?: PhoenixStopLossOrderKind; triggerPrice: bigint; executionPrice?: bigint | null; slippageBps?: number | null; } | null; sizeBaseLots?: bigint | null; sizePercent?: number | null; traderPdaIndex?: number; traderSubaccountIndex?: number; }): Promise; //# sourceMappingURL=phoenix-builder-trading.d.ts.map