A Uniswap v4 hook that detects trends and makes trend-chasing swaps pay a spread to the LPs
What we have made
Poincaré is a Uniswap v4 hook that turns an ordinary two-asset pool into one that responds to the market. It runs a live WETH/USDC pool on Unichain Sepolia. The hook has a trend detector built on CUSUM, a change-point method introduced by E. S. Page in 1954 and later proved optimal by Lorden and Moustakides. When the detector confirms a real trend from the pool's own price, the hook charges a spread to swaps following that trend and keeps it in the pool for its liquidity providers. If there is no trend, the pool trades like a normal one with a small fee that follows volatility. No oracle, keeper or off-chain service is involved and everything that the pool decides comes from its own price, inside the swap.
We have around the hook built a complete product:
The contracts have went through a scoped review by SFS-Labs and an Olympix pre-audit scan, with entire project being open source under the MIT licence.
Once per block, before the first swap, the hook reads the pool price and computes how far it moved since the last sample. It clips extreme values so one wild block cannot dominate, then feeds the return into two CUSUM statistics, one looks for an up-trend and one for a down-trend. Each statistic adds a block's move only when that move exceeds a small noise allowance, and drains back toward zero when the market chops or reverses. Evidence therefore builds only when the price keeps moving the same way. A trend is declared when a statistic crosses a threshold. That threshold is set from a target false-alarm rate, not from a fixed number of blocks, so the moment it fires depends on the data and cannot be predicted or gamed.
Because volatility alone can make CUSUM's evidence rise, the hook also measures directional efficiency. This is actually the net distance the price travelled divided by the total distance it covered, smoothed over recent blocks. It is close to one in a clean trend and close to zero in back-and-forth noise. The spread engages only when the CUSUM evidence is past its threshold and directional efficiency is above a floor chosen from how noisy that measure is in a market is when there is no trend. A control law then maps the evidence to a spread: zero at the threshold, rising to a hard cap of 5%, limited in how fast it can change from one block to the next, and fading back to zero as the trend ends.
So when a swap arrives, the hook prices it itself on a constant-product curve, instead of letting the pool use its built-in liquidity math. Every swap pays a fee proportional to recent volatility, capped at 0.30%. A swap pushing in the direction of the confirmed trend also pays the spread; a swap going against it does not. The hook returns this result to Uniswap as the swap's final amounts and settles through ERC-6909 claims. It also keeps its own record of every amount it settles, so tokens sent to it from outside cannot distort prices or the detector.
We feel there is a need for this as Liquidity providers are the backbone of every AMM, and they lose money in a way most of them never see. Prices move first on large centralised exchanges and a Uniswap pool keeps quoting the old price until arbitrageurs trade against it to close the gap, and every such trade transfers value from the LPs to the arbitrageur. (loss-versus-rebalancing or LVR). It is worst during trends, when the price keeps moving the same way and arbitrageurs can take the gap again block after block.
A standard pool cannot defend against this, because it charges the same fee to everyone at all times and cannot tell a calm market from a trending one, or a trader bringing the price back from one chasing the move. Raising the fee for everyone drives away the ordinary traders who make providing liquidity worthwhile. Existing fixes either rely on an external price oracle (another trust assumption and point of failure) or use dynamic fees that react to volatility without knowing which direction the risk is coming from. But a pool that can confirm, from its own price and with a known false-alarm rate, that a real trend has started, can then charge only the flow that profits from it.
For liquidity providers, Poincaré targets their biggest loss. During a trend, the swaps that would have taken value from them now pay a spread that stays in the pool and grows every LP's share. In calm markets the pool stays cheap and competitive, so LPs keep earning from normal trading. In a four-year replay of real ETH/USDC prices, with the same price path and order flow for every pool, a $2 million Poincaré position finished about $185,000 ahead of a standard 30 basis point pool. Arbitrageurs took 32% less, and Poincaré stayed ahead in each of the four years separately, through a doubling, a sideways market and a 38% drawdown. This is a simulation with modelled flow rather than live results, but the advantage built up steadily rather than coming from one lucky period.
For traders, the pool is fairer rather than simply more expensive. Anyone trading against the trend, or trading when there is no trend, never pays the spread. Because the Lens quotes exactly what will execute, there are no surprises at execution. PoincareDCA goes further: a regular investor can set up a recurring buy that automatically waits whenever buying would cost the spread and catches up once the trend passes. They get the same total on the same schedule without paying the trend premium.
For builders and the wider ecosystem, Poincaré shows that a pool can manage its own risk using only its own data, with a detector backed by decades of statistics rather than hand-tuned rules. The SDK, API, MCP server and Claude skill make that market signal available to bots, apps and AI agents. They can read whether a trend is under way, quote swaps, and run spread-aware strategies without understanding the maths underneath. Because it is open source under MIT, anyone can study, fork or build on the design.
Written in Solidity and tested with Foundry. Inside it are four small libraries:
On every swap, the hook reads the pool's own price, updates the detector, works out the spread and prices the swap itself. There's no oracle and no keeper. A Lens contract reuses the exact same maths, so quotes match real swaps to the wei. We tuned the parameters with Python back-tests on four years of real ETH/USDC prices.
Tech stack -> Contracts: Solidity, Foundry, Uniswap v4 core and periphery, OpenZeppelin's uniswap-hooks, Solady, and HookMiner (to mine the hook address). -> App: React, Vite, TypeScript, Tailwind, wagmi and RainbowKit. -> Backend: Supabase (Postgres plus edge functions) for the trade history, the HTTP API, a DCA keeper, and a function that checks every database write against the chain before saving it. -> Developer tools: a TypeScript SDK, an MCP server so AI agents can use Poincaré, and a Claude skill. -> Hosting and analytics: Vercel and PostHog. -> Uniswap v4: the custom-curve pattern (beforeSwapReturnDelta) let us replace the pool's pricing entirely while still using v4's settlement and ERC-6909 claims. A pool that reacts to trends wasn't possible before v4 hooks. -> OpenZeppelin's base contracts: they handled the accounting for us, so we could focus on the maths.
Hacky BITS
The detector looks at each block only once, using the reserves from before that block's first swap. A flash trade that's undone in the same block never reaches it.
The hook keeps its own record of its reserves instead of reading its token balances, so tokens sent in from outside can't move prices.
Every block, the hook emits an event with the detector's full state. Our analytics charts are rebuilt from those events, so the page doesn't depend on our own database.
Testnet gas estimates came out wrong for transactions that go through the hook, so the app sets explicit gas limits and approves exact amounts.
There's no swap log to read for a custom-curve pool, so the hook emits its own HookSwap event, and the trade history is built from that.

