Skip to content

mcmoodoo/LimitCraft

Folders and files

NameName
Last commit message
Last commit date

Latest commit

ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 

Repository files navigation

LimitCraft - Advanced Limit Order Crafting Platform for DeFi

LimitCraft Platform LimitCraft Logo

Craft Your Perfect Trade with Advanced Limit Orders

DeFi Powered by 1inch TypeScript

๐Ÿ† Hackathon Submission

Project: LimitCraft
Tracks:

  1. Extend Limit Order Protocol
  2. Build a full Application using 1inch APIs

Demo: Live Demo Video: LimitCraft Demo Video

Sample transactions(Live Demo Trace):

๐Ÿš€ Overview

LimitCraft revolutionizes DeFi trading by providing an advanced limit order platform that seamlessly integrates with lending protocols. LimitCraft empowers traders to craft sophisticated trading strategies with unprecedented control and efficiency in the DeFi ecosystem.

๐ŸŒŸ Key Innovation: Yield-Generating Limit Orders

Our breakthrough feature allows traders to earn lending yield on their tokens while waiting for limit orders to fill. This solves the opportunity cost problem that has plagued limit order systems since their inception.

๐Ÿ’ก Problem Statement

Traditional limit order systems force traders to choose between:

  • Setting limit orders and having capital sit idle
  • Earning yield in lending protocols but missing trading opportunities

This creates significant opportunity cost and capital inefficiency in DeFi.

๐ŸŽฏ Our Solution

LimitCraft introduces Smart Limit Orders with integrated lending:

  1. Pre-Trade Yield: Automatically deposits order tokens into lending protocols (Aave, Compound)
  2. Seamless Execution: When orders fill, tokens are withdrawn from lending and traded
  3. Post-Trade Yield: Received tokens are automatically re-deposited to continue earning
  4. Zero Friction: All happens in a single transaction with no manual intervention

Example Flow

User has 10,000 USDC earning 5% APY on Aave
     โ†“
Creates limit order: Buy ETH at $2,000
     โ†“
USDC continues earning yield while waiting
     โ†“
Order fills: USDC withdrawn โ†’ ETH purchased โ†’ ETH deposited to Aave
     โ†“
User now earns yield on ETH position

๐Ÿ—๏ธ Technical Architecture

Stack Overview

  • Frontend: React + TypeScript + Vite + TailwindCSS
  • Wallet Integration: RainbowKit + Wagmi v2
  • Backend: Bun + Elysia.js (Ultra-fast TypeScript runtime)
  • Database: PostgreSQL + Drizzle ORM
  • Blockchain: EVM-compatible blockchain support
  • Order Protocol: 1inch Limit Order Protocol v4
  • Smart Contracts: Solidity + Foundry + OpenZeppelin
  • Order Resolution: Custom automated resolver service

System Architecture

โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”     โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”     โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚   React UI      โ”‚โ”€โ”€โ”€โ–ถโ”‚   Elysia API    โ”‚โ”€โ”€โ”€โ–ถโ”‚  PostgreSQL DB  โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜     โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜     โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
         โ”‚                       โ”‚                         โ–ฒ
         โ”‚                       โ”‚                         โ”‚
         โ–ผ                       โ–ผ                         โ”‚
โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”     โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”     โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚  Wagmi  Wallet  โ”‚     โ”‚ Order Resolver  โ”‚โ”€โ”€โ”€โ–ถโ”‚  Order Status   โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜     โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜     โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
         โ”‚                       โ”‚
         โ–ผ                       โ–ผ
โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚        On-Chain Infrastructure                                                              โ”‚
โ”‚  โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”    โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”   โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”    โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”      โ”‚
โ”‚  โ”‚  1inch LOP  โ”‚    โ”‚ LimitCraft Extensions   โ”‚   โ”‚AAVE/Compoundโ”‚    โ”‚Uniswap Permit2โ”‚      โ”‚
โ”‚  โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜    โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜   โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜    โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜      โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜

๐Ÿ› ๏ธ Core Components

1. Order Creation Engine

  • Real-time price feeds from 1inch API
  • Advanced order types (limit, with pre-interaction lending position unwrapping, with post-interaction lending position deposit)

2. Lending Integration Manager

  • Multi-protocol support:
    • Aave
    • Compound (coming soon)

3. Order Matching System

  • Off-chain order book for gas efficiency
  • MEV-resistant order execution
  • Fair ordering with timestamp priority
  • Partial fill support

๐Ÿ”— 1inch API Integration

LimitCraft leverages multiple 1inch API endpoints to provide a seamless trading experience:

Core API Endpoints Used

API Service Endpoint Purpose Implementation
Balance API GET /balance/v1.2/{chainId}/balances/{address} Fetch user token balances Real-time wallet balance display in UI dropdowns
Token API GET /token/v1.4/{chainId}/custom/{tokenAddress} Resolve token metadata Token symbols, names, decimals, logos for all assets
Price API GET /price/v1.1/{chainId}/{tokenAddress} Live market prices Market rate calculations and USD conversions
Price API (Bulk) POST /price/v1.1/{chainId} Multiple token prices Batch price fetching for trading pairs
Limit Order Protocol SDK Smart Contract Integration Order management EIP-712 signatures, extensions, Permit2

Detailed Implementation

Balance API (https://api.1inch.dev/balance/v1.2/{chainId}/balances/{address})

// Fetches all token balances for a wallet address
const balancesResponse = await fetch(balancesUrl, {
  headers: {
    Authorization: `Bearer ${oneInchApiKey}`,
    accept: "application/json",
  },
});
  • Filters tokens with non-zero balances
  • Displays available amounts in order creation form
  • Sorts tokens by balance value for better UX

Token Details API (https://api.1inch.dev/token/v1.4/{chainId}/custom/{tokenAddress})

// Fetches metadata for each token with balances
const detailsResponse = await fetch(detailsUrl, {
  headers: {
    Authorization: `Bearer ${oneInchApiKey}`,
    accept: "application/json",
  },
});
  • Resolves token symbols, names, decimals, and logos
  • Validates token addresses for order creation
  • Handles edge cases (e.g., USDC_1 โ†’ USDC symbol fix)

Price API (https://api.1inch.dev/price/v1.1/{chainId}/{tokenAddress}?currency=USD)

// Single token price (GET)
const response = await fetch(
  `https://api.1inch.dev/price/v1.1/${chainId}/${tokenAddress}?currency=USD`,
);

// Multiple token prices (POST)
const response = await fetch(`https://api.1inch.dev/price/v1.1/${chainId}`, {
  method: "POST",
  body: JSON.stringify({
    tokens: tokenAddresses,
    currency: "USD",
  }),
});
  • Powers market rate spectrum slider in order creation
  • Calculates USD values for portfolio display
  • Implements fallback from GET to POST for reliability

Backend Proxy Architecture

  • All 1inch API calls are proxied through our Elysia.js backend
  • Secure API key management with Bearer authentication
  • Rate limiting and error handling for production reliability
  • Fallback mechanisms (1inch โ†’ Moralis for token data)

Internal API Endpoints

Our backend exposes these endpoints that utilize 1inch APIs:

Endpoint 1inch API Used Description
GET /api/v1/tokens/{address}?chainId={id} Balance + Token APIs Combined token balances and metadata
GET /api/v1/prices?token1={addr}&token2={addr} Price API Trading pair price data
POST /api/v1/orders LOP SDK Order creation and storage

This architecture ensures secure, efficient access to 1inch services while maintaining optimal performance for our users.

๐Ÿš€ Quick Start

Prerequisites

  • Bun 1.0+
  • PostgreSQL 15+
  • wallet
  • Maker token balances

Installation

# Clone the repository
git clone https://github.com/yourusername/limitcraft.git
cd limitcraft

# Install dependencies
bun install

# Initialize submodules (for smart contracts)
git submodule update --init --recursive

# Set up the database
bun run db:setup

# Start all services
bun run dev:all

Environment Configuration

Create .env files in each service directory:

# API (.env)
DATABASE_URL=postgresql://postgres:postgres@localhost:5432/limitcraft-db
API_PORT=3001

# Resolver (.env)
PRIVATE_KEY=your_private_key_here
ONEINCH_API_KEY=your_1inch_api_key
RPC_URL=your_preferred_chain_rpc_url

# UI (.env)
VITE_API_URL=http://localhost:3001
VITE_WALLETCONNECT_PROJECT_ID=your_walletconnect_id

๐Ÿ” Security Features

  • Non-custodial architecture - users retain full control

๐ŸŽฎ How to Use

  1. Connect Wallet: Link your MetaMask to LimitCraft
  2. Select Trading Pair: Choose from 100+ token pairs
  3. Set Order Parameters:
    • Order type (limit/)
    • Price levels
    • Amount to trade
    • Enable lending integration
    • Choose and configure TWAP
  4. Review & Sign: Check gas costs and sign transaction
  5. Monitor Orders: Track status in real-time dashboard
  6. Claim Rewards: Withdraw accumulated yield anytime

๐Ÿ—๏ธ Smart Contract Architecture

Core Contracts

OrderManager.sol        // Main order lifecycle management
LendingIntegration.sol  // Aave/Compound protocol interactions
OrderResolver.sol       // Automated execution logic
PriceOracle.sol        // Chainlink price feed integration
EmergencyPause.sol     // Circuit breaker mechanism

Key Features

  • EIP-712 typed signatures for orders
  • Permit2 integration for gasless approvals
  • Comprehensive event logging for indexing

๐Ÿ“ˆ Hackathon Achievements

Technical Innovation

  • โœ… First platform to integrate lending yields with limit orders
  • โœ… Sub-second order matching algorithm
  • โœ… Cross-protocol yield optimization engine

User Experience

  • โœ… One-click order creation with lending
  • โœ… Real-time portfolio analytics
  • โœ… Mobile-responsive design
  • โœ… Intuitive order management interface

Scalability

  • โœ… Horizontal scaling architecture
  • โœ… Production deployment almost ready

๐Ÿ—บ๏ธ Future Roadmap

Phase 1

  • Enhanced DeFi protocol integrations
  • Advanced charting with TradingView
  • Mobile application (iOS/Android)
  • Limit order NFTs for composability

Phase 2

  • DAO governance implementation
  • Protocol revenue sharing mechanism
  • Institutional API access
  • Advanced order types (TWAPs, Icebergs)

Phase 3

  • Perpetual futures integration
  • Options trading support
  • Social trading features
  • AI-powered trade suggestions

๐Ÿ‘ฅ Team

  • Lead Developer: Junta Okuda - Smart Contract Architect
  • Lead Developer: Rashid Mak - Smart Contract Engineer

๐Ÿ™ Acknowledgments

  • 1inch Protocol team for the limit order framework
  • The broader DeFi ecosystem
  • Aave and Compound for lending integrations
  • The DeFi community for invaluable feedback

๐Ÿ“œ License

This project is licensed under the MIT License - see LICENSE for details.


๐Ÿ† Built with passion for the future of DeFi trading

LimitCraft - Where Limit Orders Meet Lending Yields

About

LimitCraft - Advanced Limit Order Crafting Platform

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 2

  •  
  •