AI-powered chunked on chain execution - Break large ETH orders into optimal chunks.
TWAP CHOP is an AI agent that breaks large ETH sell orders into optimal chunks to minimize price impact on Uniswap V3. It uses Chainlink as a trusted price oracle to gate every execution — if Uniswap's spot price diverges from Chainlink's feed by more than 0.5%, the agent waits and retries before touching your funds.
Selling a large amount of ETH in a single Uniswap swap is expensive. A 50 ETH market sell can move the pool price 0.3–0.8%, costing thousands of dollars in slippage compared to what Chainlink says the fair price actually is.
TWAP CHOP solves this with an AI agent loop. When you submit an order, the agent first fetches the Chainlink ETH/USD price — this is the ground truth for what "fair" looks like. It then reads the Uniswap V3 pool state and validates that the two prices agree. If they diverge beyond a threshold (indicating possible manipulation or a stale pool), the agent sleeps and retries rather than executing into bad conditions.
Once prices are aligned, the agent uses Uniswap's QuoterV2 to simulate the full order and measure worst-case price impact. It then binary-searches for the optimal chunk size — the largest amount per trade where price impact stays below your configured threshold. It creates an on-chain order via the TWAPChopVault contract, then executes each chunk one at a time, re-validating prices against Chainlink before every single swap.
At the end, the app shows you three numbers side by side: what Chainlink said the fair price was, what you would have received with a naive single swap, and what TWAP CHOP actually delivered — so you can see exactly how much slippage was saved.
Smart Contracts — Solidity 0.8.24 with Foundry. The TWAPChopVault contract accepts WETH, splits it into N chunks, and executes each through the Uniswap V3 SwapRouter. It uses OpenZeppelin's SafeERC20 forceApprove to handle USDC's non-standard approval behaviour, and emits on-chain events for every chunk so the frontend can display real execution data rather than estimates.
AI Agent — A tool-use loop running Llama 3.3 70B via Groq's free inference API. The agent is given seven tools: fetch Chainlink price, fetch Uniswap pool state, validate price deviation, quote a swap, create an order, execute a chunk, and sleep. It reasons through the execution protocol autonomously — deciding chunk sizes, handling price divergence, and reporting results.
Blockchain Interaction — viem for all Ethereum RPC calls. QuoterV2 is called via simulateContract (required because it's marked nonpayable). Chunk amounts and prices are tracked using BigInt throughout to avoid precision loss.
Backend — Next.js API route that runs the agent and streams every event back to the browser in real time over Server-Sent Events (SSE).
Frontend — Next.js with Tailwind CSS and Recharts. The UI shows a live activity feed of every tool call the agent makes, a table that updates as each chunk executes, and a final bar chart comparing Chainlink's ideal price, the naive
single-swap estimate, and the actual average execution price.
Oracle — Chainlink ETH/USD price feed on Ethereum mainnet. Used as the authoritative price reference that gates every chunk execution.
Execution Venue — Uniswap V3 WETH/USDC 0.05% pool. QuoterV2 for pre-trade simulation, SwapRouter for on-chain execution.
Local Development — Anvil mainnet fork at block 22000000, giving a realistic pool and oracle state without spending real ETH.

