/** * @name perps/phoenix/phoenix-backing-engine * @description Perp-backing keeper engine (PerpsPad model, Phoenix venue). * * Pure state machine `evaluateBackingTick` decides the next action for a * token's backing position from (policy, position, collateral, now). * 100% testable without chain access. The thin executor in the backing-tick * route translates decisions into the existing Phoenix builders * (buildRegisterTrader, buildDeposit, buildPlaceMarketOrder, * getTraderStateSnapshot). * * Policy model (mirrors perpspad.fun/whitepaper §6-8, adapted to our 70/30): * - open: collateral >= OPEN_THRESHOLD_USD ($20) and no position * - top-up: position open and collateral >= top-up step ($20 increments) * - take-profit: floating PnL >= takeProfitPct of collateral (realize partial) * - re-open: after liquidation, cooldown 6h/12h/24h and leverage ×0.6 * (min 3x) — mirrors PerpsPad §8 * - none: otherwise * * @module perps/phoenix/phoenix-backing-engine */ export interface BackingPolicy { /** Phoenix market symbol (e.g. SOL, BTC, TSLA). */ underlying: string; /** Integer 1-10. */ leverage: number; direction: 'long' | 'short'; status: 'pending-keeper' | 'active' | 'paused'; } export interface BackingPosition { /** Position exists (has been opened at least once). */ exists: boolean; /** Current collateral in USDC (human units). */ collateralUsdc: number; /** Floating (unrealized) PnL in USDC. */ pnlUsdc: number; /** Current notional exposure in USDC. */ notionalUsdc: number; /** Current effective leverage (0 if no position). */ leverage: number; /** Liquidation occurred at this instant (epoch ms), or null. */ lastLiquidationAt: number | null; /** Consecutive liquidation count (drives cooldown + de-leverage steps). */ liquidationCount: number; } export interface BackingDecision { action: 'none' | 'open' | 'top-up' | 'take-profit' | 're-open'; /** Reason — surfaced in keeper logs and the token page. */ reason: string; /** USDC amount for the action (open/top-up: collateral to deploy; TP: notional to close). */ amountUsdc: number; /** Leverage for the action (re-open may de-lever). */ leverage: number; direction: 'long' | 'short'; underlying: string; } /** Tunables — defaults mirror PerpsPad §6-8. */ export interface BackingEngineConfig { /** Collateral needed before the first open. */ openThresholdUsdc: number; /** Collateral per top-up. */ topUpStepUsdc: number; /** Floating PnL (fraction of collateral) that triggers a partial TP. */ takeProfitPct: number; /** Fraction of the position closed on TP. */ takeProfitCloseFraction: number; /** Liquidation cooldowns, in ms, indexed by (consecutive count - 1). */ liquidationCooldownsMs: number[]; /** Leverage multiplier applied per re-open after liquidation. */ liquidationLeverageStep: number; /** Minimum leverage after de-leveraging. */ minLeverage: number; /** Hard floor on deployed collateral per action (dust guard). */ minActionUsdc: number; } export declare const DEFAULT_BACKING_ENGINE_CONFIG: BackingEngineConfig; /** * Decide the next backing action. PURE — no chain, no clock, no side effects. * `now` is epoch ms (injected for testability). */ export declare function evaluateBackingTick(policy: BackingPolicy, position: BackingPosition, availableCollateralUsdc: number, now: number, config?: BackingEngineConfig): BackingDecision; //# sourceMappingURL=phoenix-backing-engine.d.ts.map