project screenshot 1
project screenshot 2
project screenshot 3

Limit order hook

A gas-optimized hook for Uniswap v4 that enables limit orders by monitoring price movements between ticks. Place orders at target prices and automatically execute trades when conditions are met. Built with Solady's ERC1155 for token positions.

Limit order hook

Created At

ETHGlobal Bangkok

Project Description

Take Profits Hook for Uniswap v4

Overview

A gas-optimized hook system for Uniswap v4 that enables limit orders by monitoring price movements between ticks. The protocol allows users to place conditional orders that execute automatically when specific price conditions are met, without requiring constant monitoring or active management.

Core Functionality

  • Limit Order Creation: Users can place limit orders at specific tick prices for any Uniswap v4 pool
  • Automated Execution: Orders execute automatically when pool prices cross the specified tick boundaries
  • Position Tokenization: Orders are represented as ERC1155 tokens, enabling composability and transferability
  • Bidirectional Trading: Support for both buying and selling at specified price points
  • Gas Optimization: Built using Solady's ERC1155 implementation for maximum gas efficiency

Technical Architecture

Hook Integration

  • Implements Uniswap v4's hook interface to monitor price changes
  • Uses afterSwap callbacks to check and execute pending orders
  • Maintains order state using efficient storage patterns
  • Validates and processes orders during pool state transitions

Order Management

  1. Order Placement

    • Users specify target tick price and direction (buy/sell)
    • Input tokens are transferred and held by the contract
    • ERC1155 tokens are minted to represent the order position
  2. Order Execution

    • Monitors price movements through tick crossings
    • Automatically executes trades when price conditions are met
    • Settles balances with the Uniswap pool manager
    • Burns position tokens and transfers output tokens to user
  3. Position Management

    • Orders can be cancelled before execution
    • Positions can be transferred between addresses
    • Supports batch operations for gas efficiency

Key Features

Security

  • Fully permissionless execution
  • No privileged roles or admin functions
  • Order validation and bound checking
  • Safe math operations throughout
  • Reentrancy protection

Efficiency

  • Optimized storage layout
  • Minimal state access patterns
  • Batch processing capabilities
  • Gas-efficient token implementation

User Benefits

  • No active monitoring required
  • Guaranteed execution price
  • Composable positions
  • Flexible order management
  • Transparent pricing

Technical Stack

  • Solidity ^0.8.26
  • Uniswap v4 Core & Periphery
  • Solady ERC1155
  • Foundry for testing and deployment

Use Cases

  1. Take Profit Orders

    • Set sell orders above current price
    • Automatically realize gains when targets are hit
    • Multiple orders at different price points
  2. Buy Limit Orders

    • Place buy orders below market price
    • Accumulate positions at desired entry points
    • Dollar-cost averaging strategies
  3. Trading Strategies

    • Range trading implementation
    • Portfolio rebalancing
    • Automated trading systems
  4. Risk Management

    • Stop-loss implementation
    • Position sizing
    • Portfolio protection

Integrations

  • Compatible with all Uniswap v4 pools
  • Integrates with existing DeFi protocols via ERC1155
  • Supports external smart contract interactions
  • Webhook-ready for off-chain monitoring

Future Expansions

  1. Advanced Orders

    • Time-weighted average price (TWAP) orders
    • Good-till-cancelled (GTC) orders
    • Fill-or-kill orders
  2. Analytics

    • Order book visualization
    • Historical execution data
    • Performance metrics
  3. Risk Features

    • Price impact limits
    • Slippage protection
    • Oracle integration

Target Users

  • DeFi traders seeking automation
  • Long-term holders implementing strategies
  • DeFi protocols requiring limit order functionality
  • Market makers and liquidity providers

Differentiators

  1. Gas Efficiency

    • Optimized execution paths
    • Minimal state changes
    • Efficient storage patterns
  2. Reliability

    • Deterministic execution
    • No external dependencies
    • Pure on-chain logic
  3. Flexibility

    • Support for any token pair
    • Customizable price points
    • Transferable positions
  4. Composability

    • ERC1155 standard compliance
    • Hook-based architecture
    • Clean interfaces

This protocol represents a significant advancement in DeFi infrastructure, bringing traditional limit order functionality to Uniswap v4 in a gas-efficient, secure, and user-friendly manner.

How it's Made

Take Profits Hook - Uniswap v4 Limit Orders

Overview

Gas-optimized hook for Uniswap v4 that enables limit orders by monitoring price movements between ticks. Place orders at target prices and automatically execute trades when conditions are met, built with Solady's ERC1155 for efficient position management. Supports both take-profit and stop-loss strategies.

Key Features

  • Automatic Execution: Orders execute when price crosses specified ticks, no monitoring needed
  • Gas Optimized: Leverages Solady's ERC1155 and efficient storage patterns for minimal gas costs
  • Flexible Positions: Orders are tokenized as ERC1155s, enabling transfer and composability
  • Permissionless: No admin controls, fully trustless operation with Uniswap v4 hooks
  • Safe & Secure: Comprehensive testing, no external dependencies, battle-tested components

Technologies Used

Built using Solidity ^0.8.26, Uniswap v4 Hooks, Solady ERC1155, and Foundry for development. Implements gas-efficient storage patterns and optimized execution paths for minimal transaction costs.

Future Development

More optimizations

background image mobile

Join the mailing list

Get the latest news and updates