/** * @dev Cumulative volume price impact calculations * @dev Mirrors contract's getTradeCumulVolPriceImpactP functionality */ import { PairDepthBands, DepthBandsMapping } from "./types"; import { LiquidationParams, OiWindows, OiWindowsSettings, PairFactor, UserPriceImpact } from "../../types"; import { ContractsVersion } from "../../../contracts/types"; export type CumulVolContext = { isOpen?: boolean; isPnlPositive?: boolean; createdBlock?: number; liquidationParams?: LiquidationParams | undefined; currentBlock?: number | undefined; contractsVersion?: ContractsVersion | undefined; protectionCloseFactorWhitelist?: boolean; oiWindowsSettings?: OiWindowsSettings | undefined; oiWindows?: OiWindows | undefined; pairDepthBands?: PairDepthBands | undefined; depthBandsMapping?: DepthBandsMapping | undefined; userPriceImpact?: UserPriceImpact | undefined; collateralPriceUsd?: number; } & Partial; /** * @dev Gets the protection close factor with user multiplier * @param context Cumulative volume context * @returns Protection close factor (1 = 100%) */ export declare const getProtectionCloseFactor: (context: CumulVolContext | undefined) => number; /** * @dev Checks if protection close factor is active * @param context Cumulative volume context * @returns True if protection close factor should be applied */ export declare const isProtectionCloseFactorActive: (context: CumulVolContext | undefined) => boolean | undefined; /** * @dev Gets the cumulative factor for price impact calculation * @param context Cumulative volume context * @returns Cumulative factor (default 1) */ export declare const getCumulativeFactor: (context: CumulVolContext | undefined) => number; /** * @dev Gets the legacy factor for v9.2 compatibility * @param context Cumulative volume context * @returns 1 for pre-v9.2, 2 for v9.2+ */ export declare const getLegacyFactor: (context: CumulVolContext | undefined) => number; /** * @dev Calculates cumulative volume price impact percentage * @dev Mirrors contract's getTradeCumulVolPriceImpactP function * @param trader Trader address * @param pairIndex Trading pair index * @param long True for long, false for short * @param tradeOpenInterestUsd Position size in USD * @param isPnlPositive Whether PnL is positive (only relevant when closing) * @param open True for opening, false for closing * @param lastPosIncreaseBlock Last block when position was increased (only relevant when closing) * @param context Additional context with depths, OI data, and factors * @returns Cumulative volume price impact percentage (not including spread) */ export declare const getTradeCumulVolPriceImpactP: (_trader: string, _pairIndex: number, long: boolean, tradeOpenInterestUsd: number, isPnlPositive: boolean, open: boolean, lastPosIncreaseBlock: number, context: CumulVolContext) => number; /** * @dev Gets the fixed spread percentage with direction * @dev Mirrors contract's getFixedSpreadP function * @param spreadP Total spread percentage (includes base + user spread) * @param long True for long position * @param open True for opening, false for closing * @returns Signed spread percentage (positive or negative based on direction) */ export declare const getFixedSpreadP: (spreadP: number, long: boolean, open: boolean) => number; /** * @dev Gets the base spread percentage * @param pairSpreadP Pair spread percentage * @param isLiquidation True if liquidation * @param liquidationParams Liquidation parameters * @param userPriceImpact User-specific price impact settings * @returns Base spread percentage * @todo Review if this function still makes sense or should use getFixedSpreadP pattern * Currently it may double-count user fixed spread if pairSpreadP already includes it */ export declare const getSpreadP: (pairSpreadP: number | undefined, isLiquidation?: boolean | undefined, liquidationParams?: LiquidationParams | undefined, userPriceImpact?: UserPriceImpact | undefined) => number; /** * @dev Gets spread with cumulative volume price impact * @dev This combines base spread + cumulative volume impact * @param pairSpreadP Base pair spread percentage * @param buy True for long, false for short * @param collateral Collateral amount * @param leverage Position leverage * @param oiWindowsSettings OI windows configuration * @param oiWindows Current OI windows data * @param context Additional context for the calculation * @returns Total spread + cumulative volume price impact percentage */ export declare const getSpreadWithCumulVolPriceImpactP: (pairSpreadP: number, buy: boolean, collateral: number, leverage: number, context: CumulVolContext) => number; /** * @dev Convenience function for calculating cumulative volume price impact * @dev Uses collateral and leverage instead of USD position size * @param buy True for long, false for short * @param collateral Collateral amount * @param leverage Position leverage * @param open True for opening, false for closing * @param context Full context including depths, OI data, and collateral price * @returns Cumulative volume price impact percentage */ export declare const getCumulVolPriceImpact: (buy: boolean, collateral: number, leverage: number, open: boolean, context: CumulVolContext & { collateralPriceUsd: number; }) => number; export declare const getSpreadWithPriceImpactP: (pairSpreadP: number, buy: boolean, collateral: number, leverage: number, context: CumulVolContext) => number; export { convertOiWindowsSettings, convertOiWindow, convertOiWindows, convertOiWindowsSettingsArray, } from "./converter"; export { buildCumulVolContext } from "./builder";