Index / Sell guard
pattern · MIT · last updated 2026-08-27
Sell guard
Sell cooldown blocks rapid dumps; repeat sells in a window pay ramp fee.
First-party rewrite inspired by FairTrade (ETHNYC) and SafeSwap. Native-pair dynamic fee pool. beforeSwap enforces cooldownBlocks between sells and ramps fee after repeat sells in windowBlocks. Trader keyed via abi.encode(trader) in hookData. Complements buy-side AntiSnipe. Experimental. Listing is not an audit. Forge tests under test/SellGuard.t.sol.
Permission bits
These bits must match the deployed address. Confirm on-chain before you route.
afterInitializebeforeSwapafterSwap
Solidity
Excerpt from contracts/SellGuard.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
| Kind | pattern |
|---|---|
| Status | experimental |
| License | MIT |
| Source | https://github.com/CryptoGnome/v4hooks |
| Categories | LaunchpadsMEV protection |
| Properties | Dynamic feeCustom swap dataVanilla swap |
| Chains | Ethereum |
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.