Training a cat

The training room replays real swaps through a cat in the browser, with the same formula the hook runs, and searches the parameters. A builder publishes the winner with one transaction.

The swaps

The replay reads every Swap event of the busiest ETH / USDG v4 pool (fee 0.01%) from the PoolManager, either 7 days in a snapshot taken from the chain or the last 90 minutes live. Swaps are folded into 12-second buckets, one Ethereum block each: ETH sold and bought, the closing tick and an impact-weighted size. The hook's roll is replayed at each bucket, so the fee steps exactly as it would have onchain.

Two measures

  • LPs vs 0.30%, same swaps: for each swap, the ETH side times the LP fee minus 0.30%. This is the leaderboard's measure. The volume a 0.30% pool would have had is not modelled, so on its own it rewards the highest fee.
  • Score vs a 0.30% pool: the grid search ranks by this one. Two-way flow in a block stays while the fee is at or under the level you set (0.30% by default) and leaves above it. The one-way flow that moved the price is treated as arbitrage: it trades only the part of the block's move above the fee, and costs LPs half of that part. The score is the LPs' result under that model minus a flat 0.30% pool's result on the same blocks. It is a model, stated here so you can judge it; a calm pool usually scores best near 0.30%, and a cat earns its keep in the volatile blocks.

Grid search

Each kind has a grid (224 to 648 sets). The room replays every set on the same swaps and keeps the ten best by score. Press Use to load one into the form, adjust, and replay again.

AI trainer

With the inference key connected on the server (INFERENCE_API_KEY, INFERENCE_BASE_URL, INFERENCE_MODEL, any OpenAI-compatible chat endpoint), POST /api/train sends the replay summary and every set tried so far to an agent that answers with four new sets and a one-line note, up to six rounds. Each set is scored by the same deterministic replay in your browser. Until the key is set the room shows "AI trainer not connected", cats are trained by grid search and no cat carries an AI label.

Publish and retune

publishCat(uint8 kind, bytes32 params, string name) returns (uint32 catId)
retune(uint32 catId, bytes32 params)        // builder or its trainer
setTrainer(uint32 catId, address trainer)    // builder
setBuilder(uint32 catId, address to)         // builder

Publishing is a storage write in the hook, not a contract deploy. setTrainer lets a second address, for example an agent's wallet, retune the cat; the builder keeps the cut.