Autonomous on-chain limit orders using Uniswap v4 Hooks. No keepers, no bots—just smart contracts.
This project demonstrates how to implement self-executing limit orders directly on-chain using Uniswap v4's Hook architecture. Orders automatically execute when the target price is reached.
📖 Full technical breakdown: Read the Medium article
- ✅ Create limit orders with custom price targets
- ✅ Automatic execution when tick threshold is met
- ✅ Double-execution prevention
- ✅ Multiple orders per pool support
- ✅ Dynamic fee adjustment example
- Solidity ^0.8.24
- Foundry for testing and deployment
- Uniswap v4 Core for pool management
- Foundry
- Git
# Clone the repository
git clone https://github.com/zacksfF/v4-limit-order-hooks.git
cd v4-limit-order-hooks
# Install dependencies
forge install
# Build the project
forge buildforge test -vvvExpected output:
Ran 5 tests for test/LimitOrderHook.t.sol:LimitOrderHookTest
[PASS] testAlreadyExecutedOrderDoesNotDoubleExecute() (gas: 184660)
[PASS] testEdgeCases() (gas: 428904)
[PASS] testMultipleOrdersInOnePool() (gas: 310838)
[PASS] testPriceNotReachedYet() (gas: 178390)
[PASS] testSingleOrderExec() (gas: 181284)
Suite result: ok. 5 passed; 0 failed; 0 skipped
- Create Order: User specifies token pair, amount, and target tick
- Monitor: Hook listens to all swaps in the pool via
afterSwap() - Execute: When
currentTick >= targetTick, order is marked executed - Prevent Doubles: Executed flag prevents re-execution
See the Medium article for detailed implementation breakdown.
This is a research prototype for educational purposes. It is NOT production-ready and has not been audited. Do not use with real funds.
Missing features:
- Actual swap execution
- Fund custody mechanism
- Order cancellation
- Gas optimization
- Security audit
MIT
PRs welcome! Feel free to fork, experiment, and submit improvements.
Questions? Reach out on Medium or open an issue.
Built with ⚡ on Uniswap v4