Autonomous agent that rebalances Uniswap v4 LP positions to maximize fees and minimize risk.
This project is an autonomous liquidity management agent built on Uniswap v4 that helps LPs maximize returns while reducing risk. The agent continuously monitors LP positions across multiple v4 pools, tracking key performance metrics such as fee APY, impermanent loss, price range utilization, volatility, and liquidity competition. Using these signals, it makes deterministic, transparent decisions to rebalance positions by adjusting price ranges, migrating liquidity between pools, or reallocating capital when better opportunities exist.
By leveraging Uniswap v4’s singleton architecture and flash accounting, the agent can rebalance liquidity across multiple pools atomically and with significantly lower gas costs than traditional approaches. Optional v4 hooks are used to observe swaps and liquidity changes, enabling real-time performance tracking and onchain transparency without embedding complex strategy logic onchain. LPs can choose different risk profiles (conservative, balanced, aggressive), while all rebalancing actions are logged onchain with clear reasoning, making the system efficient, composable, and trust-minimized.
This project is built as a hybrid onchain/offchain system designed to showcase Uniswap v4’s new primitives while keeping strategy logic flexible and gas-efficient.
Onchain, we use Uniswap v4 hooks and the PoolManager singleton to observe swaps, liquidity changes, and fee generation across multiple pools. A custom hook contract tracks LP position updates and pool-level performance signals, while rebalancing execution uses v4’s flash accounting to atomically remove liquidity from underperforming pools and redeploy it into better opportunities in a single transaction with minimal token transfers and gas overhead. All actions are guarded by strict authorization, slippage limits, and safety checks to ensure LP funds are never moved without consent.
Offchain, a Chainlink CRE-powered agent acts as the decision engine. It continuously analyzes indexed onchain data to compute fee APY, impermanent loss, volatility, price-range utilization, and gas-adjusted expected returns. The agent selects optimal rebalancing actions based on LP risk profiles and only triggers execution when the projected improvement outweighs costs. Envio is used to index Uniswap v4 events and hook emissions in real time, enabling fast and reliable analytics without expensive onchain reads. Gemini is integrated to provide secure offchain computation and orchestration for the agent, improving reliability and separation between execution and strategy logic.
A notable “hacky” optimization is the use of v4’s singleton + flash accounting to rebalance liquidity across multiple pools in one atomic transaction, something that would normally require multiple approvals, swaps, and transactions in earlier Uniswap versions. This design dramatically reduces gas, improves capital efficiency, and makes true portfolio-level LP management possible onchain.

