DEMO VIDEO for EigenGames submission: Google Drive.
A decentralized peer-to-peer orderbook system built with EigenLayer's AVS (Autonomous Verifiable Service) using Othentic and Uniswap V4 Hook integration, enabling better execution prices by routing trades between the orderbook and AMMs.
To quickly see how it comes together check out our Architecture Diagram, Placing Order Flow, and Uniswap Hook Flow.
The reason that TradFi (the largest industry in the world by far) operates on order books rather than AMMs is because they're better. They're more capital-efficient for market makers, provide better prices for traders, and are resistant to AMM flaws like impermanent loss. However, AMMs are the norm on-chain due to the computational intensiveness of running order books, which would cost a fortune in gas fees or just be plain impossible at scale on many chains.
Fortunately, EigenLayer's AVS tech allows you to run computation off-chain and verify its validity through a network of validator nodes, reaching consensus and trustlessly triggering a transaction on-chain with the result of the computation. A perfect use case is order books.
SwapBook is an order book that runs on an AVS and with on-chain settlement. The secret sauce? We use Uniswap V4 hooks to loop into AMMs. When you go to swap on a pool using our hook, before the swap goes through, if you can get a better price on the order book than you can through the pool, our hook reroutes your order to trade with the P2P oroder book instead of the AMM, getting you better prices with lower fees.
This project implements a decentralized orderbook system that processes orders off-chain while settling trades on-chain. It leverages EigenLayer's AVS infrastructure for secure off-chain computation and integrates with Uniswap V4 Hooks to offer improved trading between the orderbook and AMMs.
Key features:
- Decentralized Orderbook: Maintains order books for token pairs
- Off-chain Computation: Processes orders through an AVS network
- On-chain Settlement: Securely settles trades on-chain
- Uniswap V4 Hook Integration: Route AMM swaps to the orderbook when better prices are available
Architecture (see diagram here)
Filling an order through Uniswap:

The system consists of several interconnected services:
- Orderbook Service: Maintains the order book state, matching engine, and order processing logic
- Execution Service: Verifies user signatures, validates actions, and triggers AVS tasks
- Validation Service: Validates task execution from the Execution Service
- Smart Contract: Handles on-chain settlement and escrow management
- Frontend Service: User interface for interacting with the system
- Othentic AVS Infrastructure: Othentics's infrastructure for secure off-chain computation
When a user places an order through the P2P order book:
- The request is sent to the Execution Service
- The Execution Service verifies the signature and order validity
- The Execution Service submits the order to the Orderbook Service
- The Execution Service triggers a task in the AVS
- Attester nodes validate the task through the Validation Service
- Valid tasks are executed on-chain through the smart contract
When a user triggers a swap with a hook-enabled Uniswap V4 pool:
- The hook catches the order before the swap executes and checks for better pricing in the P2P order book
- The hook uses this as a market order to directly fill the best priced limit order in the P2P order book
- Node.js (>= v22.6.0)
- Docker
- Foundry
-
Clone the repository:
git clone https://github.com/joyhuang9473/swapbook.git cd swapbook -
Install dependencies:
# Install Othentic CLI (for AVS) npm i -g @othentic/othentic-cli -
Create a
.envfile in the root directory using.env.exampleas a template:cp .env.example .env
-
Update the
.envfile with your specific configuration values:- Private keys for operators
- RPC URLs
- Contract addresses
- Other required parameters
Deploy the P2POrderBookAvsHook contract (if not already deployed):
cd contracts/
forge install
forge script script/P2POrderBookAvsHookDeploy.s.sol:P2POrderBookAvsHookDeploy \
--rpc-url $L2_RPC \
--private-key $PRIVATE_KEY \
--broadcast -vvvv \
--verify \
--etherscan-api-key $L2_ETHERSCAN_API_KEY \
--chain $L2_CHAIN \
--verifier-url $L2_VERIFIER_URL \
--sig="run(address,address)" \
$ATTESTATION_CENTER_ADDRESS $POOL_MANAGER_ADDRESSStart all services using Docker Compose:
docker-compose up --buildThis will launch:
- Orderbook Service
- Execution Service
- Validation Service
- Frontend Service
- AVS Infrastructure (Aggregator and Attesters)
- Monitoring tools (Prometheus and Grafana)
- Access the frontend at
http://localhost:8080(or other port if specified in logs) - Connect your wallet
- Place, cancel or fill orders through the interface, or manage your escrow account
For development information, see each service's README for specific instructions:
The system includes Prometheus and Grafana for monitoring:
- Prometheus:
http://localhost:9090 - Grafana:
http://localhost:3000(default credentials: admin/admin)
