V4HOOKSCUT SHEET DIRECTORY

Index / Stop-loss

pattern · MIT · last updated 2026-08-27

Stop-loss

Tick-walk fill-on-cross stop loss via unlock-wrapped market sells.

First-party rewrite of saucepoint v4-stoploss (MIT). afterInitialize snapshots tickLowerLast. registerStop records size at a trigger tick. afterSwap walks downward crosses and fillStopLoss runs an unlock-wrapped market sell. Uses 14 permission fields and OpenZeppelin BaseHook. Simplified vs original: no ERC1155 receipts. Experimental teaching hook. Listing is not an audit. Forge tests under test/StopLoss.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

afterInitializeafterSwap

Solidity

Excerpt from contracts/StopLoss.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: false,
        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
PropertiesVanilla swap
ChainsEthereum
Docshttps://github.com/saucepoint/v4-stoploss

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.