import { type Static } from "@sinclair/typebox"; import type { ClearingHousePosition } from "./liquidation-watchdog.js"; declare const positionTrackerConfigSchema: import("@sinclair/typebox").TObject<{ sizeChangeEpsilon: import("@sinclair/typebox").TOptional; }>; /** * Scanner config for `position-tracker`. * * @property sizeChangeEpsilon — Absolute threshold below which position size * differences are treated as unchanged. Prevents false INCREASED/DECREASED * deltas caused by IEEE 754 floating-point drift between consecutive MCP * snapshots (e.g. `1.0` → `1.0000000001`). * * Used in two places: * - {@link normalizePositionTrackerPositions}: positions with absolute size * at or below epsilon are discarded (treated as "no position"). * - {@link diffPositionTrackerPositions}: same-key, same-direction positions * whose size difference falls within epsilon are treated as unchanged. * * Default `1e-9` is small enough to suppress float noise without masking * real sub-unit size changes on any major perpetual venue. */ export type PositionTrackerConfig = Static; /** * Supported position delta categories emitted by the position tracker. * * Assumption: * one state transition for one position key maps to exactly one delta type per * run. A flipped position does not also emit increased/decreased in the same * iteration. */ export type PositionTrackerDeltaType = "POSITION_OPENED" | "POSITION_CLOSED" | "POSITION_INCREASED" | "POSITION_DECREASED" | "POSITION_FLIPPED"; /** * Canonical in-memory snapshot for one open strategy position. * * Constraint: * position identity is tracked by the composite `(dex, asset)` pair so the * same base asset can be monitored independently across multiple venues. */ export interface PositionTrackerPositionSnapshot { key: string; asset: string; dex: string; direction: "LONG" | "SHORT"; size: number; entryPrice: number; leverage: number; leverageType: "cross" | "isolated"; margin: number; liquidationPrice: number | null; unrealizedPnl: number; roe: number; } /** * One replay-safe delta between two canonical snapshots of the same position * key. * * `previous` and `current` are both carried so the delta stream can later be * replayed without re-fetching clearing house state. */ export interface PositionTrackerDelta { type: PositionTrackerDeltaType; asset: string; dex: string; positionKey: string; previous: PositionTrackerPositionSnapshot | null; current: PositionTrackerPositionSnapshot | null; sizeDelta: number | null; } /** * Persisted scanner-local state for `position-tracker`. * * Only the latest canonical snapshot is stored here. The historical delta * series lives in persisted scan results. */ export interface PositionTrackerState { iteration: number; lastObservedAt: number; currentPositions: Record; } /** * Normalizes clearing-house positions into a canonical snapshot keyed by * composite `dex:asset` identity. * * Assumptions and constraints: * - empty asset names are ignored * - zero-size and near-zero-size rows are ignored * - duplicate `(dex, asset)` rows are resolved as "last one wins" * - position size is stored as an absolute value; direction is tracked * separately */ export declare function normalizePositionTrackerPositions(positions: readonly ClearingHousePosition[], sizeChangeEpsilon?: number): Record; /** * Compares two canonical snapshot maps and returns the position deltas needed * to move from `previous` to `current`. * * Precedence: * flipped > opened/closed > increased/decreased */ export declare function diffPositionTrackerPositions(previous: Record, current: Record, sizeChangeEpsilon?: number): PositionTrackerDelta[]; /** * Applies one emitted delta to a snapshot map. * * This is primarily intended for tests and future replay support. */ export declare function applyPositionTrackerDelta(snapshot: Record, delta: PositionTrackerDelta): Record; /** * Creates the position-tracker scanner. * * Behavior: * - reads the latest clearing-house snapshot for the registered strategy wallet * - diffs it against the previously persisted canonical snapshot * - persists the new canonical snapshot * - emits one non-actionable signal per detected delta */ export declare function positionTrackerScanner(): import("../index.js").Scanner<{ sizeChangeEpsilon?: number | undefined; }, PositionTrackerState>; export {}; //# sourceMappingURL=position-tracker.d.ts.map