V4HOOKSCUT SHEET DIRECTORY

Index / Trailing stop

pattern · MIT · last updated 2026-08-27

Trailing stop

Peak-tick trailing stop with trail fee on sells after retrace.

First-party rewrite inspired by Hookathon C1 Trailing Hook. armTrail sets peak tick per trader. afterSwap updates peak on buys; beforeSwap applies TRAIL_FEE when a sell retraces trailDistance ticks from peak. Dynamic fee pool with OVERRIDE_FEE_FLAG. Experimental. 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

afterInitializebeforeSwapafterSwap

Solidity

Excerpt from contracts/TrailingStop.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: true,
        beforeAddLiquidity: false,
        afterAddLiquidity: false,
        beforeRemoveLiquidity: false,
        afterRemoveLiquidity: false,
        beforeSwap: true,
        afterSwap: true,
        beforeDonate: false,
        afterDonate: false,
        beforeSwapReturnDelta: false,
        afterSwapReturnDelta: false,
        afterAddLiquidityReturnDelta: false,
        afterRemoveLiquidityReturnDelta: false
    });
}

Spec

Kindpattern
Statusexperimental
LicenseMIT
Sourcehttps://github.com/CryptoGnome/v4hooks
CategoriesLimit orders
PropertiesDynamic feeCustom swap dataVanilla 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.