/** * Shared utilities for funding arbitrage strategies (v1 + v2). * Extracted to keep individual strategy files under size limits. */ import type { StrategyContext } from "../strategy-types.js"; import type { ExchangeAdapter } from "../../exchanges/index.js"; import type { SpotAdapter } from "../../exchanges/spot-interface.js"; export type RateEntry = { rate: number; price: number; sizeDecimals?: number; maxLeverage?: number; fundingHours?: number; }; export type RateMap = Map>; /** Build adapter map from primary adapter + extraAdapters in context state. */ export declare function buildAdapterMap(ctx: StrategyContext): Map; /** Get or create a spot adapter for a given exchange name + perp adapter instance. */ export declare function getSpotAdapter(name: string, adapter: ExchangeAdapter): Promise; /** Transfer USDC from perp to spot account (exchange-specific). */ export declare function transferUsdcToSpot(spotAdapter: SpotAdapter, exchangeName: string, amount: number): Promise; /** Transfer USDC from spot to perp account (exchange-specific). */ export declare function transferUsdcToPerp(spotAdapter: SpotAdapter, exchangeName: string, amount: number): Promise; /** Resolve perp symbol for a given base symbol on an exchange. */ export declare function getPerpSymbol(baseSymbol: string, _exchangeName: string): string; /** Look up rate from ratesByExchange, trying symbol, symbol-PERP, and symbol without -PERP. */ export declare function findRate(ratesByExchange: RateMap, exchange: string, symbol: string): RateEntry | undefined; /** Match a symbol against a target, accounting for -PERP suffix variations. */ export declare function matchSymbol(s: string, target: string): boolean; /** Get a price estimate for a symbol from the perp adapter. */ export declare function getPriceEstimate(perpAdapter: ExchangeAdapter, perpSymbol: string, fallbackSymbol: string): Promise; export interface RecoveredPosition { symbol: string; mode: "spot-perp" | "perp-perp"; longExchange: string; shortExchange: string; size: string; } /** Recover arb positions from exchange state (perp-perp + spot-perp, same + cross exchange). */ export declare function recoverArbPositions(adapters: Map, log: (msg: string) => void): Promise; export interface FundingScore { symbol: string; exchange: string; avgRate: number; consistency: number; annualized: number; payments: number; } /** Returns true if a reduceOnly rejection indicates the position is already gone. */ export declare function isPositionGone(msg: string): boolean; /** Compute funding period in hours from history timestamps. Falls back to static map. */ export declare function computeFundingHoursFromHistory(history: { time: number; }[]): number; /** Score a symbol's funding rate using history. Returns null if insufficient data. */ export declare function scoreFunding(adapter: ExchangeAdapter, symbol: string, exchangeName: string, periods: number, cache?: Map): Promise; /** Fetch funding rates from an exchange adapter. */ export declare function fetchRates(adapter: ExchangeAdapter, exchangeName: string): Promise<{ symbol: string; rate: number; price: number; sizeDecimals?: number; maxLeverage?: number; fundingHours?: number; }[]>;