KalmanGuard

Uniswap v4 Hook with Kalman Filter shields LPs from noise, toxic flow & LVR in real-time

KalmanGuard

Created At

HackMoney 2026

Project Description

KalmanGuard is a Sepolia-ready prototype protecting Uniswap v4 liquidity providers by leveraging real-time risk intelligence and on-chain enforcement. Off-chain agents continuously monitor pool signals-which include price movement, regime shifts in volatility, and manipulation/MEV indicators-run a Kalman-filter-based estimation to stabilize noisy data, and output a clear risk score and confidence. That risk state is then pushed onto the chain to a Uniswap v4 Hook contract, which can act based on that state by dynamically changing LP fees and unlocking emergency controls when conditions become unsafe. The system will have a dashboard for live visibility of agent health, alerts, and risk metrics, plus verifiable on-chain proof via transactions/events demonstrating that protection logic is indeed active on Sepolia for LPs and pool operators who want automated and transparent risk management rather than manual monitoring.

This project is based on the concept of a modular framework that comprises the following modules: State Estimation & Prediction: A reliable mathematical model to perform continuous prediction and correction operations to remove market noise and identify relevant data. anticipate price movements.

  • LPV Logic Layer: This consists of an adaptive controller that can modify agent behaviors as well as parameters of hooks such as dynamic fees in real-time depending on their respective variables.
  • Multi-Agent Orchestration: Five specific agents, MEV Detector, Risk Scorer, Price Monitor, Execution, and Cross-Chain, operate in the context of the Kalman filter’s signals.
  • Privacy & Execution: Integration with Flashbots and ZK-proofs to ensure that rebalancing/shielding maneuvers are MEV-resistant and confidential.

By structuring the system into "decoupled parts" of system modeling, state estimation, and rigorous backtesting suites, KalmanGuard ensures that LPs are protected from impermanent loss and toxic flow across multiple chains with institutional-grade mathematical certainty.

How it's Made

I make Kalman‑LP‑Shield by starting with a simple idea of mixing Kalman filtering and LPV control so the system can adapt even when things keeps changing. First, I create a basic model of how the system supposed to behave, then I add the prediction and correction step of a Kalman Filter. After that, I put LPV logic so the filter can react more smartly when parameters shift around. I organize the project in small parts like state estimation, system model, and testing files, so everything stay easy to understand and reuse. At the end, I run some test scripts to see how good the shield handle noise, changes in environment, and different sensor readings. This help me check that everything working fine.

KalmanGuard integrates an innovative Linear Parameter-Varying (LPV) Adaptive Kalman Filter to address impermanent loss and Loss Versus Rebalancing (LVR) issues in decentralized liquidity provision. Unlike traditional AMM strategies, which are typically modeled as static systems, our approach models the liquidity pool as a dynamic stochastic system. In this formulation, the state transition matrices depend on time-varying scheduling parameters ρ(t), which capture evolving market volatility and liquidity depth.

TECHNICAL AND MATHEMATICAL ARCHITECTURE

LPV State-Space Modeling: The liquidity provision environment is formulated in a discrete-time LPV state-space form:

x_{k+1} = A(ρ_k) x_k z_k = H(ρ_k) x_k

Here, x_k represents the vector of latent (unobserved) system states, such as true asset prices and instantaneous variances. The scheduling parameter ρ_k encodes market conditions (e.g., volatility and liquidity depth), allowing smooth interpolation between low- and high-volatility regimes without the need for frequent re-calibration.

Adaptive Estimation (The "Brain"): The core engine operates as a recursive prediction–correction loop:

  1. Time Update (Prediction): The filter computes the a priori state estimate using the LPV system matrix A(ρ_k) and the process noise covariance Q_k. Notably, Q_k is not static; it is adaptively updated via a Maximum Likelihood Estimation (MLE) operator applied over rolling windows of innovation residuals. This enables rapid reaction to sudden market shocks.

  2. Measurement Update (Correction): The predicted state is corrected by fusing on-chain oracle data (e.g., Chainlink) with centralized exchange (CEX) reference prices. The filter computes the optimal Kalman Gain K_k by minimizing the trace of the posterior covariance matrix P_{k|k}, effectively denoising the price signal prior to AMM arbitrage and rebalancing.

Control and Execution (The "Shield"): The posterior error covariance P_k is used as a direct proxy for system risk.

  • If Trace(P_k) > τ, the system flags a regime change.
  • The Agent Controller invokes a Uniswap v4 Hook to dynamically adjust control inputs u_k, such as swap fee tiers or tick spacing.

These actions increase the cost of attack for toxic flow, thereby mitigating LVR and adverse selection.

Validation and Stability: The codebase is modularized around state estimation, system modeling, and comprehensive testing suites. Extensive Monte Carlo simulations stress-test the filter under non-Gaussian noise and jump-diffusion processes commonly observed in crypto markets. These tests validate the BIBO (Bounded-Input Bounded-Output) stability of the LPV controller and ensure robust performance during extreme volatility, network congestion, or oracle failure.

background image mobile

Join the mailing list

Get the latest news and updates