Search projects, hackathons, sponsors and tech

    ← All projects

    OniBlock

    Uniswap v4 hook where an AI prices toxic arbitrage every block, and loses power if it's wrong.

    Demo

    About

    Oniblock is a Uniswap v4 hook that protects liquidity providers from toxic arbitrage without making ordinary traders pay for it. The problem. When ETH moves on Binance, a Uniswap pool's price is briefly stale. Arbitrageurs buy the cheap side and LPs absorb the loss. On Ethereum this adds up to hundreds of millions of dollars in CEX–DEX arbitrage over the past two years. Private mempools protect traders from sandwiches, but they do nothing for LPs, because the arbitrage trade itself is the problem. Fixed fees and fixed thresholds are walls: they either tax everyone or let arbitrage through. How it works. - Every block, an AI decides how sensitive the fee should be. A keeper sends the pool's state to Jev, TypeSafe's typed decision model, and asks two questions in one call: - How likely is it that the next block brings flow that costs LPs money? - What kind is it: CEX–DEX arbitrage, split arbitrage, backrun, JIT liquidity, sandwich, or none? The state it sends is the Binance mid vs the pool price, the arbitrage edge at the base fee, flow imbalance, trade size vs depth, volatility, and recent liquidity churn. The keeper signs the answer with EIP-712 and posts it on-chain. - The contract turns that answer into two bounded knobs. - k, the fee sensitivity, is 0.8 × p × confidence. Only swaps that move the pool toward Binance (the arbitrage direction) pay fee = 0.30% + k × live gap, capped at 1%. Everyone else pays the base fee. - The JIT penalty window runs from 10 to 100 blocks. Liquidity removed inside its window forfeits its fees to the LPs who stayed, and each position is judged by the window in force when it was added. - The AI has power only while it's accurate. A settler grades each prediction against what actually happened: was the trade profitable against Binance at that moment? It posts a Brier score on-chain and to ENS. A model scoring worse than a coin flip is demoted automatically and the pool falls back to base fees. No admin is involved. - ENSv2 is the identity and permission layer. - oniblock.eth has its own registry and subregistries for models and pools. - The keeper and settler are authorised through custom Enhanced Access Control roles on quoter. and settler.oniblock.eth, which the hook checks on every post. Revoking a role is an instant kill switch. - Only the settler may write the calibration.* records on each model's name (Permissioned Resolver per-key rights). - An ENSIP-10 wildcard resolver serves live data from the hook for names that are never registered: jev-v1.live.oniblock.eth returns a model's live scorecard, weth-usdc.live.oniblock.eth returns the pool's current k, JIT window and fees. - The keeper and settler have ENSIP-19 primary names, and the models carry ENSIP-26 agent records. - Every swap emits a receipt with the gap, k, fee, model and signature, so anyone can re-check the pricing.

    How it's made

    Architecture. Four pieces: a Uniswap v4 hook (Solidity, Foundry), a keeper and settler (TypeScript, viem), an ENSv2 setup, and a Next.js app. Everything runs on Ethereum Sepolia against the real v4 PoolManager and the ENSv2 Sepolia contracts. The hook (OniblockHook.sol). - Dynamic fee: beforeSwap returns fee | OVERRIDE_FEE_FLAG. The fee is computed only from on-chain state: the pool price vs the last attested Binance mid, and the attested k. Contracts can't call a model, so the model's opinion is pushed in beforehand as a signed attestation, and beforeSwap only reads it. - Directional: only swaps that move the pool toward the mid pay the gap premium. - Split-arb resistant: a per-block high-water anchor makes a split arbitrage pay the first sub-swap's fee on every part. - Never reverts in the swap path: a stale oracle falls back to a conservative fee, and all data checks happen in the keeper's setAttestation transaction. beforeSwap hands the fee to afterSwap through transient storage, which emits a Receipt event with every input. - JIT: built on OpenZeppelin's LiquidityPenaltyHook, with two changes: - The penalty window is set by the model per block, and each position is judged by the window in force when it was added. - When the last LP exits inside the window we park the penalty as ERC-6909 claims instead of reverting, so withdrawals never brick. - Calibration gate: k comes from the model only while its node is allowlisted and its on-chain Brier score is under 0.25. - Tests: 146 Foundry tests, including fork tests against real ENSv2 bytecode. The AI: our fine-tuned Kev-0.8B. - Why Kev: Kev is an open-weights decision model, a LoRA adapter plus a pointer head on Qwen3.5. You send a state and typed questions, and it returns calibrated probabilities with no generated text. That's fast and cheap enough for a per-block decision, and we can fine-tune it ourselves. - Fallback: a deterministic heuristic, posted under its own ENS model name so Kev is never blamed for it. Keeper and settler. - Keeper: reads the pool, Binance and recent liquidity events, calls Kev, signs an EIP-712 attestation, and posts it first in the block with its own priority fee. It only posts when the new attestation would actually change pricing. - Settler: grades each receipt against the Binance price at that swap's block (was the flow profitable against Binance after the fee?), computes Brier scores, and writes them to the hook and to ENS text records. - Tests: 271 service tests. ENSv2 (partner tech). - Registries: oniblock.eth is registered through the commit-reveal ETHRegistrar, with its own registry and subregistries deployed via VerifiableFactory. - Roles: custom EAC role bits (ROLE_QUOTER, ROLE_SETTLER) on quoter. and settler.oniblock.eth are the hook's permission system, read through our EnsV2RoleOracle. Revoking a role is a kill switch. - Per-key permissions: the PermissionedResolver grants the settler alone the right to write the calibration.* keys. Even the owner can't forge a model's score without a visible grant. - Wildcard resolver: a custom ENSIP-10 resolver on live.oniblock.eth computes records straight from hook storage for names that are never registered: kev-v1.live.oniblock.eth returns Kev's live scorecard. - Primary names and agent records: ENSIP-19 primary names for the keeper and settler wallets, and ENSIP-26 agent-endpoint[web] records on each model name. - Why it matters: ENS makes the AI an accountable identity with a public, tamper-evident scorecard, rather than an address in a config file. The app. Next.js, server-side reads through UniversalResolverV2. - A server-signed Swap button lets anyone trade without a wallet. - Every trade is mirrored onto a plain v4 pool deployed next to ours, so the headline "Oniblock saved LPs" compares identical flow. - Each swap opens a judgement card with the model's verdict, the fee formula, and the ENS role and EIP-712 checks re-verified from calldata.