Index / AntiSnipe
pattern · MIT · last updated 2026-08-27
AntiSnipe
Launch guard — max buy (% supply), snipe tax on exact-input buys for N blocks after init.
First-party teaching hook inspired by Spark's Anti-Snipe launchpad block (usespark.fun/builder). afterInitialize records graduationBlock and requires native currency0 + dynamic fee. beforeSwap applies snipeTax via OVERRIDE_FEE_FLAG on exact-input buys while inGuardWindow; after guard, baseLpFee. afterSwap caps token output to maxBuyBps of totalSupply using afterSwapReturnDelta (FullMath.mulDiv avoids supply overflow). Per-swap cap only — not per-wallet. Sells skip tax and cap. Experimental. Forge tests in test/AntiSnipe.t.sol. Listing is not an audit.
Permission bits
These bits must match the deployed address. Confirm on-chain before you route.
afterInitializebeforeSwapafterSwapafterSwapReturnDelta
Solidity
Excerpt from contracts/AntiSnipe.sol. Copy the full file to implement this. Not an audit.
// SPDX-License-Identifier: MIT
// v4hooks first-party — excerpt. Full file: source.url
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: true,
afterAddLiquidityReturnDelta: false,
afterRemoveLiquidityReturnDelta: false
});
}
function _beforeSwap(address, PoolKey calldata key, SwapParams calldata params, bytes calldata)
internal
view
override
returns (bytes4, BeforeSwapDelta, uint24)
{
bool isExactInputBuy = params.zeroForOne && params.amountSpecified < 0;
uint24 fee = feeFor(key.toId(), isExactInputBuy);
return (this.beforeSwap.selector, BeforeSwapDeltaLibrary.ZERO_DELTA, fee | LPFeeLibrary.OVERRIDE_FEE_FLAG);
}Spec
| Kind | pattern |
|---|---|
| Status | experimental |
| License | MIT |
| Source | https://github.com/CryptoGnome/v4hooks |
| Categories | LaunchpadsMEV protectionDynamic fees |
| Properties | Dynamic feeVanilla 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.