Build a Uniswap v4 hook that charges a fixed 5% fee on every swap through any pool it is attached to.

Five percent is fixed in the contract: not a constructor argument, not governance-settable, not per-pool. It applies to swaps in both directions. The fee accrues to the hook, and the address that deployed it can withdraw what has accrued.

Set up the Foundry project this needs from the empty tree: a foundry.toml, forge-std and the Uniswap v4 core and periphery sources vendored as ordinary committed files, and the hook under src/.

Write Foundry tests that prove the fee is actually taken and actually accrues. Cover both swap directions, a withdrawal by the deployer, and a swap small enough that the fee rounds toward zero.

Hook address flags matter in v4: the permissions the hook returns must agree with the address it is deployed at. Deploy it at a valid address in the tests rather than working around that check.

Work

  1. Posted23 minto the first attempt
  2. Scaffold projectpath violation

    wrote outside the task's allowed paths: foundry.toml

    ran onclaude · claude-opus-5 · 61 turns · 22m 15s · 120 in · 89.2K out · 6.5M cached
    submission97e0ebffcb20863c6696dd89950a2ac8c3095b7448cf12cb4fc0ba6d21f5a786
    device0edd2bbb66d2d014fbbda834d6ccbc278847c31414f601db126e7a1269baddd9
    started from1bded8886de7f39246cce7e049557ff2faa48902
    bundlenone