← Back to home

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.

Screenshots

Limit order hook screenshot 1
Limit order hook screenshot 2
Limit order hook screenshot 3

Problem Statement

Take Profits Hook for Uniswap v4OverviewA 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 FunctionalityLimit Order Creation: Users can place limit orders at specific tick prices for any Uniswap v4 poolAutomated Execution: Orders execute automatically when pool prices cross the specified tick boundariesPosition Tokenization: Orders are represented as ERC1155 tokens, enabling composability and transferabilityBidirectional Trading: Support for both buying and selling at specified price pointsGas Optimization: Built using Solady's ERC1155 implementation for maximum gas efficiencyTechnical ArchitectureHook IntegrationImplements Uniswap v4's hook interface to monitor price changesUses afterSwap callbacks to check and execute pending ordersMaintains order state using efficient storage patternsValidates and processes orders during pool state transitionsOrder ManagementOrder PlacementUsers specify target tick price and direction (buy/sell)Input tokens are transferred and held by the contractERC1155 tokens are minted to represent the order positionOrder ExecutionMonitors price movements through tick crossingsAutomatically executes trades when price conditions are metSettles balances with the Uniswap pool managerBurns position tokens and transfers output tokens to userPosition ManagementOrders can be cancelled before executionPositions can be transferred between addressesSupports batch operations for gas efficiencyKey FeaturesSecurityFully permissionless executionNo privileged roles or admin functionsOrder validation and bound checkingSafe math operations throughoutReentrancy protectionEfficiencyOptimized storage layoutMinimal state access patternsBatch processing capabilitiesGas-efficient token implementationUser BenefitsNo active monitoring requiredGuaranteed execution priceComposable positionsFlexible order managementTransparent pricingTechnical StackSolidity ^0.8.26Uniswap v4 Core & PeripherySolady ERC1155Foundry for testing and deploymentUse CasesTake Profit OrdersSet sell orders above current priceAutomatically realize gains when targets are hitMultiple orders at different price pointsBuy Limit OrdersPlace buy orders below market priceAccumulate positions at desired entry pointsDollar-cost averaging strategiesTrading StrategiesRange trading implementationPortfolio rebalancingAutomated trading systemsRisk ManagementStop-loss implementationPosition sizingPortfolio protectionIntegrationsCompatible with all Uniswap v4 poolsIntegrates with existing DeFi protocols via ERC1155Supports external smart contract interactionsWebhook-ready for off-chain monitoringFuture ExpansionsAdvanced OrdersTime-weighted average price (TWAP) ordersGood-till-cancelled (GTC) ordersFill-or-kill ordersAnalyticsOrder book visualizationHistorical execution dataPerformance metricsRisk FeaturesPrice impact limitsSlippage protectionOracle integrationTarget UsersDeFi traders seeking automationLong-term holders implementing strategiesDeFi protocols requiring limit order functionalityMarket makers and liquidity providersDifferentiatorsGas EfficiencyOptimized execution pathsMinimal state changesEfficient storage patternsReliabilityDeterministic executionNo external dependenciesPure on-chain logicFlexibilitySupport for any token pairCustomizable price pointsTransferable positionsComposabilityERC1155 standard complianceHook-based architectureClean interfacesThis 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.

Solution

Take Profits Hook - Uniswap v4 Limit OrdersOverviewGas-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 FeaturesAutomatic Execution: Orders execute when price crosses specified ticks, no monitoring neededGas Optimized: Leverages Solady's ERC1155 and efficient storage patterns for minimal gas costsFlexible Positions: Orders are tokenized as ERC1155s, enabling transfer and composabilityPermissionless: No admin controls, fully trustless operation with Uniswap v4 hooksSafe & Secure: Comprehensive testing, no external dependencies, battle-tested componentsTechnologies UsedBuilt 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 DevelopmentMore optimizations

Hackathon

ETHGlobal Bangkok

2024

Contributors