V4HOOKSCUT SHEET DIRECTORY

Index / Referral fee

pattern · MIT · last updated 2026-08-27

Referral fee

abi.encode(referrer) in hookData pays refBps of swap output to the referrer.

First-party rewrite inspired by mergd/ref-fee-hook (MIT). afterSwapReturnDelta takes refBps of output token and transfers to the referrer decoded from hookData. Zero referrer skips the skim. Experimental referral split pattern. Listing is not an audit. Forge tests under test/ReferralFee.t.sol.

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/ReferralFee.sol. Copy the full file to implement this. Not an audit.

function getHookPermissions() public pure override returns (Hooks.Permissions memory) {
    return Hooks.Permissions({
        beforeInitialize: false,
        afterInitialize: false,
        beforeAddLiquidity: false,
        afterAddLiquidity: false,
        beforeRemoveLiquidity: false,
        afterRemoveLiquidity: false,
        beforeSwap: false,
        afterSwap: true,
        beforeDonate: false,
        afterDonate: false,
        beforeSwapReturnDelta: false,
        afterSwapReturnDelta: true,
        afterAddLiquidityReturnDelta: false,
        afterRemoveLiquidityReturnDelta: false
    });
}

Spec

Kindpattern
Statusexperimental
LicenseMIT
Sourcehttps://github.com/CryptoGnome/v4hooks
CategoriesCreator economy
PropertiesCustom swap dataVanilla swap
ChainsEthereum
Docshttps://github.com/mergd/ref-fee-hook

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.