/** * @dev PnL calculation module * @dev Provides functions matching v10 contract implementations */ import { Trade, TradeInfo, LiquidationParams, Fee, GlobalTradeFeeParams, TradeFeesData } from "../types"; import { ComprehensivePnlResult, GetComprehensivePnlContext } from "./types"; import { BorrowingFee } from "../fees/borrowing"; import { ContractsVersion } from "../../contracts/types"; import { UnifiedPairOi } from "src/markets"; /** * @dev Gets trade realized PnL components from TradeFeesData * @dev Mirrors contract's getTradeRealizedPnlCollateral function * @param tradeFeesData Trade fees data containing realized components * @returns Tuple of [realizedPnlCollateral, realizedTradingFeesCollateral, totalRealizedPnlCollateral] */ export declare const getTradeRealizedPnlCollateral: (tradeFeesData: TradeFeesData) => { realizedPnlCollateral: number; realizedTradingFeesCollateral: number; totalRealizedPnlCollateral: number; }; /** * @dev Calculates PnL percentage for a position * @dev Mirrors contract's getPnlPercent function * @param openPrice Trade open price * @param currentPrice Current market price * @param long Whether position is long * @param leverage Position leverage * @returns PnL percentage (e.g., 10 = 10% profit, -50 = 50% loss) */ export declare const getPnlPercent: (openPrice: number, currentPrice: number, long: boolean, leverage: number) => number; /** * @dev Calculates trade value from collateral and PnL * @dev Mirrors contract's getTradeValuePure function * @param collateral Trade collateral amount * @param pnlPercent PnL percentage * @param totalFees Total fees to deduct * @returns Trade value after PnL and fees */ export declare const getTradeValue: (collateral: number, pnlPercent: number, totalFees: number) => number; /** * @dev Comprehensive PnL calculation including all fees * @param trade The trade to calculate PnL for * @param marketPrice Current market price (without price impact) * @param executionPrice Price after all impacts (spread, skew, volume) * @param tradeInfo Trade info with version and timestamps * @param context Context with all fee parameters * @returns Detailed PnL breakdown */ export declare const getComprehensivePnl: (trade: Trade, marketPrice: number, executionPrice: number, tradeInfo: TradeInfo, context: GetComprehensivePnlContext) => ComprehensivePnlResult; /** * @dev Legacy getPnl function for backward compatibility * @deprecated Use getComprehensivePnl for new implementations */ export type GetPnlContext = { currentBlock: number; groups: BorrowingFee.Group[]; pairs: BorrowingFee.Pair[]; collateralPriceUsd: number | undefined; contractsVersion: ContractsVersion | undefined; feeMultiplier: number | undefined; fee: Fee; globalTradeFeeParams: GlobalTradeFeeParams; traderFeeMultiplier?: number; pairOis: UnifiedPairOi[]; }; /** * @dev Legacy PnL calculation function * @deprecated Use getComprehensivePnl for more comprehensive calculations * @param price Current price * @param trade Trade object * @param tradeInfo Trade info (not used in legacy implementation) * @param initialAccFees Initial accumulated fees * @param liquidationParams Liquidation parameters * @param useFees Whether to include fees * @param context Context with fee calculation parameters * @returns [pnlCollateral, pnlPercentage] or undefined if no price */ export declare const getPnl: (price: number | undefined, trade: Trade, _tradeInfo: TradeInfo, initialAccFees: BorrowingFee.InitialAccFees, liquidationParams: LiquidationParams, useFees: boolean, context: GetPnlContext) => number[] | undefined; /** * @dev Calculates the price needed to achieve a target PnL percentage * @param targetPnlPercent The target PnL percentage (e.g., 50 for 50% profit, -25 for 25% loss) * @param trade The trade to calculate for * @param tradeInfo Trade info with timestamps * @param context Context with fee calculation parameters * @param netPnl Whether to include closing fees in the calculation * @returns The price that would result in the target PnL percentage */ export declare const getPriceForTargetPnlPercentage: (targetPnlPercent: number, trade: Trade, tradeInfo: TradeInfo, context: GetComprehensivePnlContext, netPnl?: boolean) => number; export * from "./types"; export * from "./converter"; export * from "./builder";