LimitOrderHook
EthereumHookRegisteredLimitOrderHook is a Uniswap v4 hook on Ethereum by 0xaad81ac687f7f9454901dafe2ef6ebb26c907498. A Uniswap v4 Hook that enables on-chain limit orders on supported liquidity pools. Users can set a target price, and when the pool price reaches the specified price, the Hook automatically executes the order. This enables users to place limit orders directly on Uniswap v4. Brand new: its first pool went live today. Still in use: 8 trades in the last week, and 1 new pool this week.
- Made by
- 0xaad81ac687f7f9454901dafe2ef6ebb26c907498
- Contract name
- LimitOrderHook
How this hook works
Limit ordersThis hook adds limit orders to Uniswap pools: traders can place an order to sell at a chosen price, and the hook fills it automatically when the price gets there. Trading fees earned by orders go to the hook developer's treasury.
Place an order at a price
A trader puts in one token at a price just above or below the current one. Their tokens sit in the pool as a narrow band of liquidity.
The code that does this (placeOrder):function placeOrder(PoolKey calldata key, int24 tick, bool zeroForOne, uint128 liquidity) public virtual { if (liquidity == 0) revert ZeroLiquidity(); _validatePoolKey(key); OrderInfo storage orderInfo; // get the order for the limit order OrderIdLibrary.OrderId orderId = getOrderId(key, tick, zeroForOne); // if the order is not initialized, initialize it if (orderId.equals(ORDER_ID_DEFAULT)) { // initialize the order to the next order unchecked { _setOrderId(key, tick, zeroForOne, orderId = _orderIdNext); // increment the order id _orderIdNext = _orderIdNext.unsafeIncrement(); } // get the order info orderInfo = _orderInfos[orderId]; // set the currency0 and currency1 orderInfo.currency0 = key.currency0; orderInfo.currency1 = key.currency1; } else { // get the order info orderInfo = _orderInfos[orderId]; } // …Filled automatically
After each trade, the hook checks which prices were crossed and closes the orders there, so they are swapped completely and not swapped back.
The code that does this (_afterSwap):function _afterSwap( address, PoolKey calldata key, SwapParams calldata params, BalanceDelta, bytes calldata ) internal virtual override returns (bytes4, int128) { (int24 tickLower, int24 lower, int24 upper) = _getCrossedTicks(key.toId(), key.tickSpacing); if (lower > upper) return (this.afterSwap.selector, 0); // set the last tick lower for the pool _tickLowerLasts[key.toId()] = tickLower; // note that a zeroForOne swap means that the pool is actually gaining token0, so limit // order fills are the opposite of swap fills, hence the inversion below bool zeroForOne = !params.zeroForOne; for (; lower <= upper; lower += key.tickSpacing) { _fillOrder(key, lower, zeroForOne); } return (this.afterSwap.selector, 0); }Cancel or collect
Traders can cancel an open order to get their tokens back, or withdraw the other token once it has filled.
The code that does this (cancelOrder):function cancelOrder(PoolKey calldata key, int24 tickLower, bool zeroForOne, address to) public virtual { _validatePoolKey(key); // get the order OrderIdLibrary.OrderId orderId = getOrderId(key, tickLower, zeroForOne); OrderInfo storage orderInfo = _orderInfos[orderId]; // revert if the order is already filled if (orderInfo.filled) revert Filled(); // get the liquidity added by the msg.sender uint128 liquidity = orderInfo.liquidity[msg.sender]; // revert if the liquidity is 0 if (liquidity == 0) revert ZeroLiquidity(); // delete the liquidity from the order delete orderInfo.liquidity[msg.sender]; // subtract the liquidity from the total liquidity orderInfo.liquidityTotal -= liquidity; // reset orderInfo when remove all liquidity if (orderInfo.liquidityTotal == 0) { _setOrderId(key, tickLower, zeroForOne, ORDER_ID_DEFAULT); orderInfo.currency0Total = 0; orderInfo.currency1Total = 0; } // Unlock the PoolManager and remove the caller's liquidity. // …Order fees go to the treasury
Trading fees that orders earn while waiting are sent to the hook developer's treasury instead of the trader.
The code that does this (_routeFeesToTreasury):function _routeFeesToTreasury( PoolKey memory key, BalanceDelta feesAccrued, bool asClaims ) internal returns (uint256 amount0Fee, uint256 amount1Fee) { int128 fee0 = feesAccrued.amount0(); int128 fee1 = feesAccrued.amount1(); if (fee0 < 0 || fee1 < 0) { revert UnexpectedFeeDelta(); } if (fee0 == 0 && fee1 == 0) { return (0, 0); } if (fee0 > 0) { amount0Fee = uint256(uint128(fee0)); key.currency0.take(poolManager, treasury, amount0Fee, asClaims); } if (fee1 > 0) { amount1Fee = uint256(uint128(fee1)); key.currency1.take(poolManager, treasury, amount1Fee, asClaims); } // …
Who controls it: The treasury is set when the hook is created. There are no admin settings and the code cannot be upgraded.
Based on the hook’s published code.What do these labels mean?
Safety report
Before you build on it. Automated checks, not an audittreasury 0x3abe…058f, and the sale only goes through if that payment does. It takes the payment today: we tried it the way Uniswap makes it. Its code can be replaced, and code that refuses the payment would stop all selling. Our selling test would then fail.What it can do
Its code executes inside each trade in pools that use it.
It runs when a pool is created, often to lock in that pool’s settings.
Hook history
Nothing recorded yet.
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.