Skip to content

sevryn-labs/encrypted-orderbook

Repository files navigation

🔒 Confidential Order Book

A fully functional confidential limit order book dApp using Fhenix FHE technology with a stunning, production-ready frontend.


📦 Overview

Backend (Smart Contracts)

  • ConfidentialOrderBook.sol - Full FHE implementation
    • Order placement with encrypted prices & quantities
    • FHE-based order matching (no plaintext comparisons)
    • Trade execution with encrypted values
    • Secure decryption flow for participants only
  • Comprehensive Test Suite - 18/18 tests passing covering placement, matching, cancellation, and decryption flow.

Frontend (Next.js App)

  • Beautiful, Premium UI with:
    • 🌙 Dark mode with gradient backgrounds
    • ✨ Glassmorphism effects
    • 🎭 Smooth Framer Motion animations
    • 📱 Fully responsive design
  • Complete Trading Interface:
    • Wallet connection (wagmi + viem)
    • Order placement form (Buy/Sell)
    • Real-time order book display
    • Trade history panel
    • My Orders management

🎯 Key Features

Privacy Guarantees

Feature Status Description
Encrypted Prices Stored as euint32 on-chain
Encrypted Quantities Stored as euint32 on-chain
Private Matching Uses FHE.gte(), FHE.select()
Participant-Only Decryption Only buyer/seller can decrypt
MEV Protection No front-running possible

📁 Project Structure

cofhe-hardhat-starter/
├── contracts/
│   ├── ConfidentialOrderbook.sol    # Main contract
│   └── Counter.sol                  # Reference example
│
├── test/
│   ├── ConfidentialOrderBook.test.ts # 18 tests passing
│   └── Counter.test.ts
│
├── frontend/
│   ├── app/                         # Next.js App Router root
│   ├── components/                  # Trading UI components
│   └── lib/                         # ABIs, Web3 setup
│
└── IMPLEMENTATION_SUMMARY.md        # Deep-dive technical docs

🚀 How to Run

1. Smart Contracts

# Install dependencies
pnpm install

# Compile contracts
npx hardhat compile

# Run tests
npx hardhat test

# Deploy to local network
npx hardhat run scripts/deploy.ts --network localhost

2. Frontend

# Navigate to frontend
cd frontend

# Install dependencies
pnpm install

# Start dev server
pnpm dev

Frontend will run at: http://localhost:3000


🔐 Security Architecture

Contract Level

// All comparisons in encrypted space
ebool canMatch = FHE.gte(buyPrice, sellPrice);

// Conditional logic without if statements
euint32 result = FHE.select(condition, valueIfTrue, valueIfFalse);

// Access control enforced
FHE.allowThis();      // Contract access
FHE.allowSender();    // User access
FHE.allow(value, participant);  // Specific access

Privacy Model

Data Visibility Notes
Order Prices Encrypted euint32 on-chain
Order Quantities Encrypted euint32 on-chain
Order Side Public BUY or SELL
Trader Address Public Wallet address
Trade Match Public Event emitted
Trade Price Encrypted Only participants decrypt
Trade Quantity Encrypted Only participants decrypt

🎯 What Makes This Special

1. True Privacy

  • On-chain order book with fully encrypted orders
  • No MEV, no front-running, no strategy leakage
  • Matching happens entirely in encrypted space using FHE

2. Production-Ready

  • Comprehensive test coverage
  • Clean, well-documented code
  • Error handling and edge cases covered

3. Beautiful UX

  • Premium dark mode design
  • Smooth animations throughout
  • Intuitive trading interface
  • Real-time updates

🔮 Future Enhancements

  • Enhanced Privacy: Full cofhejs integration for encryption, embedded decryption UI for trade participants, encrypted order book depth visualization.
  • Advanced Trading: Market orders, stop-loss orders, price charts.
  • DeFi Integration: Liquidity pools, cross-chain bridging.

📚 Documentation Reference

Document Purpose
IMPLEMENTATION_SUMMARY.md Technical architecture, FHE operations used & API reference
frontend/README.md Frontend setup & usage guide
PROJECT_COMPLETE.md Origin delivery summary & milestones

Built with ❤️ using Fhenix Protocol & CoFHE Framework

Releases

No releases published

Packages

 
 
 

Contributors