CrossPoolOracleHook

Uniswap v4 hook that uses deep liquidity pools as free, trustless oracles to protect thin pools

CrossPoolOracleHook

Created At

HackMoney 2026

Project Description

CrossPoolOracleHook protects new token pools from price manipulation without expensive external oracles.

The problem: New tokens launching on Uniswap have thin liquidity that's easy to manipulate. Chainlink and Pyth don't list new tokens and cost money to integrate.
The solution: Use Uniswap's own deep liquidity pools (ETH/USDC, ETH/DAI) as trustless price references. When someone swaps on a protected pool, the hook reads reference pool prices in the same transaction and compares price movements. If the protected pool moves significantly more than the reference pools, it's likely manipulation — not market movement.

The hook applies tiered responses:

  • Normal swaps: 0.3% base fee
  • Suspicious swaps (>2% unexplained impact): 1% elevated fee
  • Manipulation attempts (>10% unexplained impact): swap blocked entirely

This is only possible with Uniswap v4's singleton architecture where all pools share one contract and hooks can read any pool's state atomically.

How it's Made

Built with Foundry and Solidity 0.8.26 using OpenZeppelin's uniswap-hooks framework.

The core innovation is cross-pool state reads via v4's StateLibrary.getSlot0() — the hook reads reference pool sqrtPriceX96 values during beforeSwap and compares them to cached values from the previous swap. This lets us distinguish "ETH dropped 5% market-wide" from "someone is manipulating this specific pool"

Price impact estimation uses actual AMM math: newSqrtP = sqrtP * L / (L + amount) for zeroForOne swaps, then calculates the percentage change. We support up to 5 reference pools per protected pool, taking the maximum movement across all references (most generous to the trader).

The hook uses LPFeeLibrary.OVERRIDE_FEE_FLAG to return dynamic fees from beforeSwap based on the "unexplained impact" calculation.

Frontend built with Next.js 14 and wagmi v2. We read pool state directly from PoolManager storage slots via extsload() — computing keccak256(poolId, POOLS_SLOT) for slot0 and adding offset +3 for liquidity. Real-time price impact estimation runs client-side using the same math as the Solidity contract.

Deployed and tested on Sepolia with demo swaps showing base fees, elevated fees, and circuit breaker triggers.

background image mobile

Join the mailing list

Get the latest news and updates