AsyncSwap
BaseAsyncSwap is a Uniswap v4 hook on Base. Brand new: its first pool went live today.
- Contract name
- AsyncSwap
How this hook works
Trading taxA trading tax hook. It sets its own trading fee, takes a cut of every trade and pays extra to liquidity providers.
Sets its own trading fee
It sets the pool’s trading fee itself instead of using a fixed one.
The code that does this (swapAgainstPool):function _swapAgainstPool( IPoolManager manager, PoolKey calldata key, bool zeroForOne, uint256 amountIn, address hook, uint160 sqrtPriceLimitX96 ) private returns (uint256 swapped, uint256 amountOut, int24 tickBefore) { if (manager.getLiquidity(key.toId()) == 0) revert NoActiveLiquidity(); Currency input = zeroForOne ? key.currency0 : key.currency1; input.settle(manager, hook, amountIn, true); uint24 previousFee; (, tickBefore,, previousFee) = manager.getSlot0(key.toId()); manager.updateDynamicLPFee(key, POOL_LIQUIDITY_FILL_FEE); BalanceDelta delta = manager.swap( key, SwapParams( zeroForOne, -amountIn.toInt256(), // A limit (the best book level) stops the swap there. sqrtPriceLimitX96 != 0 ? sqrtPriceLimitX96 : zeroForOne ? TickMath.MIN_SQRT_PRICE + 1 : TickMath.MAX_SQRT_PRICE - 1 ), "" ); manager.updateDynamicLPFee(key, previousFee); // A fill that runs out of in-range liquidity leaves the pool where no liquidity is active, and the // check above would then refuse every later fill: refuse this one instead, so the order uses the book. if (manager.getLiquidity(key.toId()) == 0) revert NoActiveLiquidity(); // …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 sender, PoolKey calldata key, SwapParams calldata params, bytes calldata hookParams) internal override returns (bytes4, BeforeSwapDelta, uint24) { if (params.amountSpecified > 0) revert ExactInputOnly(); PoolId poolId = key.toId(); uint256 amountTaken = uint256(-params.amountSpecified); UserParams memory hookData = abi.decode(hookParams, (UserParams)); // Only the Router opens orders: it settles the input and hands the order to `matchNewOrder` in the same // unlock, which clears the pending-match id. Then bind the declared executor to the actual swap caller so // nobody can open orders attributed to a maker through an executor they do not control. if (sender != router) revert NotTrustedRouter(); if (sender != hookData.executor) revert AsyncFiller.NotAuthorizedExecutor(); Currency specified = params.zeroForOne ? key.currency0 : key.currency1; // Escrow the entire deposit; fees are earned only on successful fill. specified.take(poolManager, address(this), amountTaken, true); _createOrder(key, params.zeroForOne, amountTaken, hookData); if (specified == key.currency0) { emit HookSwap(PoolId.unwrap(poolId), sender, amountTaken.toInt128(), 0, 0, 0); } else { emit HookSwap(PoolId.unwrap(poolId), sender, 0, amountTaken.toInt128(), 0, 0); } BeforeSwapDelta beforeSwapDelta = toBeforeSwapDelta(int128(-params.amountSpecified), 0); return (BaseHook.beforeSwap.selector, beforeSwapDelta, 0); // …Pays extra to liquidity providers
It sends extra rewards straight into the pool for liquidity providers.
The code that does this (pay):function _pay(AsyncFiller.State storage self, PoolKey calldata key, bytes32 id, Currency output, uint256 fee) private { IPoolManager manager = self.poolManager; uint256 toLps = manager.getLiquidity(key.toId()) == 0 ? 0 : fee / 2; if (toLps != 0) { bool zero = output == key.currency0; manager.donate(key, zero ? toLps : 0, zero ? 0 : toLps, ""); } manager.mint(self.feeVault, output.toId(), fee - toLps); emit DynamicFeeCharged(key.toId(), id, output, toLps, fee - toLps, self.refTick); }Trades on its own
It makes trades itself, for example to convert the fees it collected.
The code that does this (swapAgainstPool):function _swapAgainstPool( IPoolManager manager, PoolKey calldata key, bool zeroForOne, uint256 amountIn, address hook, uint160 sqrtPriceLimitX96 ) private returns (uint256 swapped, uint256 amountOut, int24 tickBefore) { if (manager.getLiquidity(key.toId()) == 0) revert NoActiveLiquidity(); Currency input = zeroForOne ? key.currency0 : key.currency1; input.settle(manager, hook, amountIn, true); uint24 previousFee; (, tickBefore,, previousFee) = manager.getSlot0(key.toId()); manager.updateDynamicLPFee(key, POOL_LIQUIDITY_FILL_FEE); BalanceDelta delta = manager.swap( key, SwapParams( zeroForOne, -amountIn.toInt256(), // A limit (the best book level) stops the swap there. sqrtPriceLimitX96 != 0 ? sqrtPriceLimitX96 : zeroForOne ? TickMath.MIN_SQRT_PRICE + 1 : TickMath.MAX_SQRT_PRICE - 1 ), "" ); manager.updateDynamicLPFee(key, previousFee); // A fill that runs out of in-range liquidity leaves the pool where no liquidity is active, and the // check above would then refuse every later fill: refuse this one instead, so the order uses the book. if (manager.getLiquidity(key.toId()) == 0) revert NoActiveLiquidity(); // …Needs a signed approval
Some actions need a message signed by an approved address.
The code that does this (verify):function _verify(address maker, bytes32 structHash, uint256 nonce, uint256 deadline, bytes calldata signature) private { if (block.timestamp > deadline) revert SignatureExpired(); _useNonce(maker, nonce); if (!SignatureChecker.isValidSignatureNow(maker, _hashTypedDataV4(structHash), signature)) { revert InvalidSignature(); } }Runs an auction
People bid, for example for the right to trade first or for launch tokens.
The code that does this (executeOrder):function executeOrder(AsyncOrder calldata order, bytes calldata data) external { address filler = abi.decode(data, (address)); bytes32 id = order.orderId(); // Native-output settlement may only consume ETH that the filler deposited // in this tx (via the Router's pre-unlock forward). Stranded balance is // not drawable. Decrement the per-tx ledger to amountOutMin's worth. Currency output = order.zeroForOne ? order.key.currency1 : order.key.currency0; if (output.isAddressZero()) { uint256 pending; assembly ("memory-safe") { pending := tload(PENDING_NATIVE_DEPOSIT_SLOT) } (, uint256 amountOutMin) = (this.asyncOrderInfo(order.key.toId(), id)); amountOutMin += calculatePoolFee(order.key.fee, amountOutMin); if (pending < amountOutMin) revert UnaccountedNativeOutput(); assembly ("memory-safe") { tstore(PENDING_NATIVE_DEPOSIT_SLOT, sub(pending, amountOutMin)) } } AsyncFiller.State storage state = asyncOrders[order.key.toId()]; // A plain fill cannot skip a live auction premium; flash fills pay it through the Router. DutchAuction.requireNoPremium(state, auctions, id); uint256 fee = calculatePoolFee(order.key.fee, state.orders[id].amountOutMin); AsyncMatching.fill( state, priceBooks[order.key.toId()], AsyncMatching.FillParams({ order: order, id: id, hook: address(this), executor: msg.sender, // …
Who controls it: The hook developer can withdraw funds held by the hook. 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 auditmatchNewOrder topUpPriorityFeematchNewOrderflashFillmatchNewOrderWhat 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
Nothing found yet. Still reading this hook’s older history.
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. Still reading older history, so totals will grow.