V4HOOKSCUT SHEET DIRECTORY

Index / FeeRouter

pattern · MIT · last updated 2026-08-27

FeeRouter

afterSwap skims protocolBps of output to an immutable treasury address.

First-party teaching hook for fee collect-and-route on every swap. afterSwap takes protocolBps of the swap output token via take + ERC20 transfer to treasury. Similar shape to referral-fee.yml but fixed recipient instead of hookData referrer. Experimental. Forge tests in test/FeeRouter.t.sol. Listing is not an audit.

Permission bits

These bits must match the deployed address. Confirm on-chain before you route.

Initialize
ba
Liquidity
baba
Swap
ba
Donate
ba
Return delta
baaa

afterSwapafterSwapReturnDelta

Solidity

Excerpt from contracts/FeeRouter.sol. Copy the full file to implement this. Not an audit.

// SPDX-License-Identifier: MIT
function _afterSwap(...) internal override returns (bytes4, int128) {
    uint256 pay = (uint256(int256(out)) * protocolBps) / 10_000;
    outCur.take(poolManager, address(this), pay, false);
    IERC20(Currency.unwrap(outCur)).transfer(treasury, pay);
    return (this.afterSwap.selector, pay.toInt128());
}

Spec

Kindpattern
Statusexperimental
LicenseMIT
Sourcehttps://github.com/CryptoGnome/v4hooks
CategoriesCreator economyDynamic fees
PropertiesVanilla swap
ChainsEthereum

FAQ

Can I paste this into production? The snippet is an excerpt. Use the full file at the source URL, match flags to the address, and treat this page as a map, not a guarantee.

How do I build this safely? Start with secure v4 hooks and the OpenZeppelin hooks guide.