Aven

Uniswap v4 hook pricing every swap from Hyperliquid's in-block oracle, so LPs stop losing to arbs

Aven

Created At

ETHGlobal Mumbai

Winner of

Uniswap

Uniswap Foundation - Build with Uniswap 3rd place

Project Description

Aven is a Uniswap v4 dynamic-fee hook on HyperEVM that charges each swap a fee based on Hyperliquid's live perp market, read in the same block as the swap.

THE PROBLEM An AMM's price only moves when someone trades against it. When the market moves elsewhere, the pool goes stale, and arbitrageurs buy cheap or sell high against LPs at the same low fee. LPs lose that value (loss-versus-rebalancing, LVR). A fixed fee charges arbitrage and ordinary flow the same. Existing dynamic-fee hooks, such as Uniswap's VolatilePairHook, learn from the pool's own past trades, so they react after the damage is done. Oracle-based designs need a relayer, a keeper or a signer you have to trust.

THE IDEA Aven reads the market's present. HyperEVM gives smart contracts in-block access to Hyperliquid's perp oracle and mark prices through precompiles (0x807, 0x806). HyperCore and HyperEVM share one consensus, so there is no relay, no signer and no cross-chain delay. The fair price is already chain state.

On every swap, AvenHook reads both prices and computes three signals:

  1. Fair-value gap: how far the pool's price is from the oracle, anchored to the top of the block. Charged only when the swap moves the pool toward fair, i.e. when it is arbitrage.
  2. Perp premium: mark vs oracle. Charged when the swap trades with perp-market pressure.
  3. Mark stress: how far the mark has moved from a time-weighted anchor (tau = 60 s). Charged above 50 bp.

fee = clamp(0.05% base + gap term + premium term + stress term, 0.05%, 1%). The fee goes to LPs. Ordinary flow pays 0.05%; an arbitrageur closing a 1.5% gap pays up to 1%. If a price read fails, the swap never reverts: it pays a 0.30% fallback fee. Every input is emitted in a FeeComputed event, so anyone can recompute every fee.

There is no owner, admin key, keeper, proxy, upgrade path or custody. Every config value is immutable. Two anti-gaming rules: a top-of-block gap anchor (splitting an arb into many swaps in one block doesn't lower the fee) and a time-weighted mark anchor (a dust swap can't reset the stress term).

LIVE ON HYPEREVM MAINNET (chain 999) AvenHook 0xfdd13cA6D7FcF4Ca710Bc8C77546592F42CF6080, deployed on Uniswap's own canonical v4 PoolManager. In the first live test, a shock pushed two identical pools about 188 bp off the oracle. The bot's arbitrage paid 9,950 pips (0.995%) on the Aven pool vs 3,000 (0.30%) on the plain control pool, so Aven LPs kept $97.25 more. That fee was recomputed off-chain from the event and matched exactly. Uniswap's own V4Quoter and Universal Router also route through the Aven pool.

REPLAY ON REAL HISTORY We replayed the Oct 29 2026 Binance-halt window (Hyperliquid mainnet data) through four identical pools. LP value vs holding: fixed 0.05% -$318, fixed 0.30% +$7, Aven with a 60 s-delayed price +$114, Aven live +$141. Live beats delayed, so the edge comes from reading the market in-block. On a calm day, Aven roughly matches fixed 0.30% while charging ordinary trades only 0.05%. No parameters were tuned on this data.

THE APP A web app with a trade terminal (market, limit, stop and TP/SL orders on the pools), swap, add liquidity, a live dashboard that shows the fee repricing in the same block as the oracle moves, the replay, an on-chain ledger and portfolio, and in-browser verification of any Aven swap.

Limits: the pools trade open-mint demo tokens (aETH/aUSD), but the prices the hook reads are real Hyperliquid prices. There has been no third-party audit; our internal security review is in docs/SECURITY.md.

How it's Made

Aven has three parts: Solidity contracts, a TypeScript backend and a Next.js frontend, all written during the event in one pnpm monorepo.

CONTRACTS (Solidity 0.8.26, Foundry)

  • AvenFairValue is a pure fee library; AvenHook is the Uniswap v4 hook. It is built on OpenZeppelin's uniswap-hooks BaseHook and implements Uniswap's IDynamicFeeHook, so anything that quotes Uniswap's dynamic-fee hooks can quote Aven.
  • Permissions are beforeInitialize + beforeSwap only, so the hook address's low 14 bits must be 0x2080. We mined the address with v4-periphery's HookMiner through the CREATE2 deployer.
  • Every beforeSwap return sets the override-fee flag (0x400000), the fallback included. A v4 dynamic pool's stored LP fee is 0, so one missing flag would mean free swaps. It has a dedicated test, an invariant and a mutation check.
  • Precompile reads are hand-written staticcalls that never revert, forward exactly 30,000 gas and copy at most 32 bytes. hyper-evm-lib's PrecompileLib reverts on failure, so it is only used in tests. Reads can revert, return 0 bytes, return words wider than uint64 or burn all forwarded gas; each case has a test and falls back to a 0.30% fee instead of reverting the swap.
  • beforeInitialize rejects any pool that isn't the configured pair with a dynamic fee, so the hook can't be attached to a pair it would misprice.
  • Hook overhead is about 47k gas per swap; runtime size is 9.3 KB.

PROOFS

  • forge: 90 tests passing, covering unit, fuzz (1,000 runs), v4 integration in both token orders, nine named attack tests (split swaps, dust swaps, sandwich back leg, gas burn, preview == charged, and more), and invariants I1-I10 over random swaps, price moves and read failures.
  • Mutation testing: we broke the code on purpose (no override flag, top-of-block reset every swap, anchor moving on a failed read) and confirmed the matching tests went red.
  • Differential proof: the same fee math is ported to TypeScript with BigInt, integer-only. Solidity and TypeScript agree on 10,000 / 10,000 fee vectors and 2,000 / 2,000 anchor vectors, bit for bit.
  • Verifier: pnpm verify <tx> rebuilds the inputs from the FeeComputed event, recomputes the fee, and checks it against the event (check A) and the PoolManager's own Swap fee (check B).
  • Load tests: 2,318 swaps over 250 blocks with broken reads gave 0 reverts. They also found 4 real bugs, each fixed with a regression test: viem's ~4 s block-number cache, viem's 4 s receipt polling, a stampeding per-block cache, and gas estimates that missed the more expensive first-swap-of-block path.

BACKEND (TypeScript, Node, viem, zod, Hono, vitest)

  • @aven/core: the fee port, ABIs, pool math and the verifier.
  • Arena: an arbitrage bot service over HTTP + Server-Sent Events. It runs against two identical pools, Aven and a plain 0.30% control pool. An admin "shock" pushes both off fair value, then the bot simulates and sends only profitable arbs and verifies every trade. It has a nonce manager, gas-price caps, auto-pause on low balance and rate limits, plus a bulk mode that runs repeated shocks.
  • Replay engine: Hyperliquid mainnet candles and funding replayed through four pools in a Foundry test. A seeded retail agent sends the same trades to every pool.

FRONTEND (Next.js 16, React 19, Tailwind 4, viem, Privy, TradingView lightweight-charts, GSAP + three.js) Trade terminal, swap, liquidity, live dashboard, replay and docs. Fees are re-verified in the browser with @aven/core, and the chain is the database: history and portfolios are rebuilt from logs and receipts, with no DB. A client-side RPC load balancer spreads reads over 7 public HyperEVM endpoints, with failover, per-endpoint budgets and Multicall3, to stay under the public 100 requests/min limits.

PARTNER TECH

  • Uniswap v4: the PoolManager, hooks, the dynamic-fee override and IDynamicFeeHook. We deployed on Uniswap's own canonical PoolManager on HyperEVM, not a fork, and showed that Uniswap's V4Quoter and Universal Router route through the Aven pool.
  • Hyperliquid / HyperEVM: the read precompiles are what make the idea possible. The oracle and mark in the same block as the swap, with no oracle network in between. We also used Hyperliquid's info API for replay data and the live order book.

HACKY / NOTABLE

  • Testnet was a dead end. Testnet HYPE needs a mainnet deposit, and deploying our own PoolManager would have needed big blocks, so we went straight to mainnet on Uniswap's PoolManager, capping every tx at 2 gwei. The whole deploy cost about 0.001 HYPE; the first live test cost 0.000083 HYPE.
  • forge's script simulation can't see HyperCore precompiles on a live chain (it reads 0 bytes), so our deploy would have failed on mainnet. Our internal review caught it, and the scripts now read prices through vm.rpc("eth_call").
  • To prove Universal Router compatibility without spending funds, we simulated swaps with eth_call state overrides (fake ERC20 + Permit2 allowances).
background image mobile

Join the mailing list

Get the latest news and updates

Aven | ETHGlobal