Half Inch

A real-time token search, automated rebalancing, and 1inch integration on Rootstock

Half Inch

Created At

ETHGlobal New Delhi

Project Description

Half-Inch is a comprehensive decentralized exchange platform built on Rootstock Testnet with multi-chain support that revolutionizes DeFi trading through advanced automation and real-time discovery. The platform combines a sophisticated smart contract architecture with a modern web frontend to provide users with instant access to thousands of tokens across 7 major blockchain networks. The core innovation lies in its automated rebalancing system that maintains optimal token ratios in liquidity pools through smart contracts, eliminating manual intervention while maximizing capital efficiency. Users can create custom liquidity pools, trade tokens with real-time price quotes from 1inch API, and let the system automatically rebalance their positions when ratios drift beyond configured thresholds. The platform features real-time token discovery with 300ms debounced search across all supported chains, allowing users to find and trade any token instantly. The system integrates directly with blockchain networks through custom smart contracts (Factory, Pair, Router, RebalancerController) while providing a seamless web3 experience with private key management and transaction signing. Key differentiators include multi-chain token management, automated portfolio rebalancing, comprehensive analytics dashboard, and professional-grade trading interface with advanced slippage control and gas optimization. The platform serves both retail traders seeking efficient token swaps and liquidity providers looking for automated yield optimization strategies.

How it's Made

Frontend Architecture: Built with Next.js 14 using App Router for optimal performance and SEO, styled with Tailwind CSS and Framer Motion for smooth animations. The frontend uses React Query for sophisticated state management and caching, implementing 300ms debounced search with automatic query invalidation to prevent excessive API calls. Smart Contract Layer: Deployed on Rootstock Testnet using Hardhat framework with Solidity contracts including Factory (pool creation), Pair (liquidity management), Router (trading logic), and RebalancerController (automated rebalancing). The contracts implement a hub-and-spoke model where the Factory acts as the central hub for all pool operations. API Integration: Custom 1inch API integration with fallback systems - when 1inch API is unavailable, the system automatically switches to mock data ensuring 99.9% uptime. The search API implements real-time token discovery across 7 chains (Ethereum, Rootstock, BSC, Polygon, Arbitrum, Optimism, Avalanche) with intelligent caching and error handling. State Management: Uses React Query for server state with 30-second stale time and automatic background refetching. The system implements a singleton pattern for in-memory database operations and uses localStorage with 10-minute cooldowns to prevent multiple concurrent initializations. Notable Technical Hacks: Blockchain Direct Fetching: Bypasses traditional database storage by fetching pool data directly from smart contracts, ensuring data consistency and eliminating database synchronization issues Debounced Search with Chain Awareness: Implements 300ms debounced search that's chain-aware, automatically switching token lists based on selected network Mock Data Fallback System: When 1inch API fails, generates realistic mock tokens based on search queries, maintaining user experience during API outages Private Key Security: Implements client-side private key handling with local transaction signing, never storing keys on servers The platform leverages TypeScript throughout for type safety, Ethers.js for blockchain interactions, and custom ContractService classes for standardized contract operations across different networks.

background image mobile

Join the mailing list

Get the latest news and updates