TouchStone

Uniswap v4 hook that holds a refundable deposit on informed swaps and settles it on a signed price

TouchStone

Created At

ETHGlobal Mumbai

Project Description

Every automated market maker has a quiet leak: a pool learns the price only from the trades it receives, so after the market moves it keeps quoting the old price until a bot trades against it. The bot keeps the difference and the liquidity providers pay for it. Touchstone is a Uniswap v4 hook that recovers part of that value without changing the price any trader gets.

When a swap looks informed (large, first in its block, part of fast one-sided flow, or moving toward a stale price), the hook takes a small refundable deposit out of the swap's own output, in the same transaction and with a single wallet signature. A few seconds later anyone can settle it with a signed Pyth price. The trade is measured against that price: if its markout beats a margin, part of the excess goes to the liquidity providers and the rest returns to the trader. Benign flow is refunded in full and can earn a rebate.

Around that core sit four markets: clawback on informed trades, a rented arbitrage licence that pays rent to the pool, rebates for benign flow, and quote integrity. For the last one, previewDeposit, a URC-4 indicative quote and a guarded router show the deposit before the user signs and enforce limits inside the transaction.

Backtested on 184,145 real Ethereum USDC/WETH swaps from a held-out window, the trigger flagged the trades carrying 98.9% of toxic markout while asking a deposit on 23.4% of swaps (historical backtest, pre-registered). Seven verified contracts run on Arbitrum Sepolia, with a dashboard that executes a real swap and follows its settlement.

How it's Made

The contracts are Solidity 0.8.26 built with Foundry on Uniswap v4. The hook uses the beforeInitialize, beforeSwap, afterSwap and afterSwapReturnDelta permissions:

  • beforeSwap snapshots price, liquidity and fee.
  • afterSwap derives the notional from the actual currency deltas, evaluates four triggers (first touch per block, directional leaky-bucket flow, drift against a Chainlink reference, closed market) and returns a delta in the unspecified currency.
  • The deposit is minted to the hook as an ERC-6909 claim in the PoolManager, so it is atomic with the swap and needs no second approval.

The hook address is mined with CREATE2 to carry its flag bits, and the deploy script predicts nonces to wire seven contracts in one pass.

Settlement is a separate contract. It verifies one signed Pyth update through the unique-update call and applies a confidence margin. It clips an overshooting swap to its in-the-money leg, so padding cannot dilute the markout. It splits the retained amount into a tip, a rebate pool and LP income that vests over time through a donation. The hook rechecks that the payout conserves the deposit exactly before paying.

Partner technologies:

  • Uniswap v4: PoolManager, StateView and V4Quoter.
  • Pyth: settlement prices.
  • Chainlink: the swap-time reference.
  • Arbitrum: ArbSys supplies L2 block numbers for the first-touch rule.

Notable engineering:

  • The hook is 23,993 bytes against the 24,576-byte limit, because URC-4 quotes are served through its fallback to a lens contract.
  • A tick-walking lens sizes trades across liquidity bands.
  • Transient storage carries first-touch state through a transaction.
  • A Rust simulator replays settlement against contract bytecode.

Off-chain:

  • A TypeScript keeper (viem, zod) fetches Hermes updates and settles records.
  • An indexer with a read-only API and a Discord alert monitor watch the pool.
  • CI runs 254 forge tests, invariant suites, Slither, coverage and gas gates, and dependency audits.
  • The dashboard is Vite, React and viem with a WebGL ray-marched illustration. Its Simulation page calls previewDeposit, signs once, and shows t, the markout and the payout.
  • The research is pre-registered Python with fixed seeds and hashed inputs.

These counts are from my earlier runs: 254 forge tests, a 23,993-byte hook and seven contracts verified on Arbiscan. The 98.9% / 23.4% backtest figu2 results.

background image mobile

Join the mailing list

Get the latest news and updates