Index / AutoBurn
pattern · MIT · last updated 2026-08-27
AutoBurn
Burns burnBps of token output on exact-input buys via afterSwapReturnDelta.
First-party teaching hook inspired by Spark Auto Burn. afterInitialize requires native currency0. afterSwap on exact-input buys (zeroForOne, amountSpecified < 0) takes burnBps of token1 output from the swapper via poolManager.take, transfers to DEAD, and returns the same amount as afterSwap return delta. Sells and exact-output swaps skip. Teaches output-side hook accounting without composing extra LP fee. Experimental. Forge tests in test/AutoBurn.t.sol. Listing is not an audit.
Permission bits
These bits must match the deployed address. Confirm on-chain before you route.
afterInitializeafterSwapafterSwapReturnDelta
Solidity
Excerpt from contracts/AutoBurn.sol. Copy the full file to implement this. Not an audit.
// SPDX-License-Identifier: MIT
// v4hooks first-party — excerpt. Full file: source.url
function _afterSwap(address, PoolKey calldata key, SwapParams calldata params, BalanceDelta delta, bytes calldata)
internal
override
returns (bytes4, int128)
{
if (!params.zeroForOne || params.amountSpecified >= 0) return (this.afterSwap.selector, 0);
int128 tokenOut = delta.amount1();
if (tokenOut <= 0) return (this.afterSwap.selector, 0);
uint256 burnAmount = (uint256(int256(tokenOut)) * burnBps) / 10_000;
if (burnAmount == 0) return (this.afterSwap.selector, 0);
key.currency1.take(poolManager, address(this), burnAmount, false);
IERC20(Currency.unwrap(key.currency1)).transfer(DEAD, burnAmount);
return (this.afterSwap.selector, burnAmount.toInt128());
}Spec
| Kind | pattern |
|---|---|
| Status | experimental |
| License | MIT |
| Source | https://github.com/CryptoGnome/v4hooks |
| Categories | Launchpads |
| Properties | Vanilla 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.