TimberlineHook
BaseTimberlineHook is a Uniswap v4 hook on Base. Brand new: its first pool went live today.
- Contract name
- TimberlineHook
How this hook works
Trading taxA trading tax hook. It sets its own trading fee, takes a cut of every trade and limits trading to stop bots.
Sets its own trading fee
Instead of a fixed fee chosen by the pool creator, it decides the fee itself on each trade.
The code that does this (beforeSwap):function beforeSwap(address, PoolKey calldata key, IPoolManager.SwapParams calldata params, bytes calldata) external override onlyPoolManager returns (bytes4, BeforeSwapDelta, uint24) { PoolId id = key.toId(); PoolConfig storage cfg = poolConfigs[id]; if (!cfg.initialized) revert PoolNotRegistered(); PoolRuntime storage rt = poolRuntimes[id]; uint40 nowTs = uint40(block.timestamp); (uint160 spotSqrtPriceX96,,,) = poolManager.getSlot0(id); // Update wall-clock exponential EMA once per distinct timestamp if (nowTs > rt.lastEmaTime && rt.emaSqrtPriceX96 > 0) { uint256 dt = uint256(nowTs - rt.lastEmaTime); if (dt >= EMA_SNAP_SECONDS) { rt.emaSqrtPriceX96 = spotSqrtPriceX96; } else { // Exact rational Pade (1,1) step without intermediate bps quantization uint256 denom = 2 * EMA_TAU_SECONDS + dt; uint256 numNew = 2 * dt; uint256 numOld = 2 * EMA_TAU_SECONDS - dt; rt.emaSqrtPriceX96 = uint160( (uint256(spotSqrtPriceX96) * numNew + uint256(rt.emaSqrtPriceX96) * numOld) / denom ); } rt.lastEmaTime = nowTs; // …Takes a cut of every trade
On top of the normal pool fee, it keeps a share of each trade. The fee builds up in the hook until it is collected.
The code that does this (beforeSwap):function beforeSwap(address, PoolKey calldata key, IPoolManager.SwapParams calldata params, bytes calldata) external override onlyPoolManager returns (bytes4, BeforeSwapDelta, uint24) { PoolId id = key.toId(); PoolConfig storage cfg = poolConfigs[id]; if (!cfg.initialized) revert PoolNotRegistered(); PoolRuntime storage rt = poolRuntimes[id]; uint40 nowTs = uint40(block.timestamp); (uint160 spotSqrtPriceX96,,,) = poolManager.getSlot0(id); // Update wall-clock exponential EMA once per distinct timestamp if (nowTs > rt.lastEmaTime && rt.emaSqrtPriceX96 > 0) { uint256 dt = uint256(nowTs - rt.lastEmaTime); if (dt >= EMA_SNAP_SECONDS) { rt.emaSqrtPriceX96 = spotSqrtPriceX96; } else { // Exact rational Pade (1,1) step without intermediate bps quantization uint256 denom = 2 * EMA_TAU_SECONDS + dt; uint256 numNew = 2 * dt; uint256 numOld = 2 * EMA_TAU_SECONDS - dt; rt.emaSqrtPriceX96 = uint160( (uint256(spotSqrtPriceX96) * numNew + uint256(rt.emaSqrtPriceX96) * numOld) / denom ); } rt.lastEmaTime = nowTs; // …Limits on trading
It limits trading, for example a max buy or wallet size or a wait between trades, to stop bots grabbing the supply before real traders.
The code that does this (beforeAddLiquidity):function beforeAddLiquidity( address, PoolKey calldata key, IPoolManager.ModifyLiquidityParams calldata, bytes calldata ) external override onlyPoolManager returns (bytes4) { PoolId id = key.toId(); PoolConfig storage cfg = poolConfigs[id]; if (!cfg.initialized) revert PoolNotRegistered(); if (!cfg.genesisSeeded) { cfg.genesisSeeded = true; return BaseHook.beforeAddLiquidity.selector; } if (uint40(block.timestamp) < cfg.launchTime + cfg.decayDuration) { revert SniperWindowLiquidityLocked(); } return BaseHook.beforeAddLiquidity.selector; }Rules for adding liquidity
It decides who can add liquidity, or when.
The code that does this (beforeAddLiquidity):function beforeAddLiquidity( address, PoolKey calldata key, IPoolManager.ModifyLiquidityParams calldata, bytes calldata ) external override onlyPoolManager returns (bytes4) { PoolId id = key.toId(); PoolConfig storage cfg = poolConfigs[id]; if (!cfg.initialized) revert PoolNotRegistered(); if (!cfg.genesisSeeded) { cfg.genesisSeeded = true; return BaseHook.beforeAddLiquidity.selector; } if (uint40(block.timestamp) < cfg.launchTime + cfg.decayDuration) { revert SniperWindowLiquidityLocked(); } return BaseHook.beforeAddLiquidity.selector; }Only approved callers create pools
New pools with this hook can only be created by approved callers, for example its own factory or launcher.
The code that does this (beforeInitialize):function beforeInitialize(address sender, PoolKey calldata key, uint160 sqrtPriceX96) external override onlyPoolManager returns (bytes4) { if (sender != FACTORY) revert OnlyFactory(); PoolId id = key.toId(); PoolConfig storage cfg = poolConfigs[id]; if (!cfg.initialized) revert PoolNotRegistered(); uint40 nowTs = uint40(block.timestamp); cfg.launchTime = nowTs; poolRuntimes[id] = PoolRuntime({ activeBlock: uint40(block.number), blockQuoteVolume: 0, emaSqrtPriceX96: sqrtPriceX96, lastEmaTime: nowTs }); return BaseHook.beforeInitialize.selector; }
Who controls it: Nobody. The hook has no admin functions, and the code cannot be changed.
Based on the hook’s published code.What do these labels mean?
Safety report
Before you build on it. Automated checks, not an auditWhat it can do
Its code executes inside each trade in pools that use it.
It can take or add tokens during a swap. Fees, burns and custom curves work this way, and so do scams.
Pools using it let the hook choose the swap fee instead of a fixed tier.
It checks every deposit before it goes in.
It runs when a pool is created, often to lock in that pool’s settings.
Hook history
- Protected the pool 1 time
Counted from what the hook recorded on-chain across all its pools, for every action in its published code, plus token transfers in and out of it.