Skip to content

kshaan-ali/Real-dex

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 

Repository files navigation

RealDex - Decentralized Exchange

A full-stack decentralized exchange built with React, Node.js, TypeScript, and smart contracts on Monad testnet.

🚀 Features

Frontend

  • Real-time Trading Interface - Live orderbook, charts, recent trades
  • Portfolio Management - Deposit/withdraw tokens, view balances
  • Socket.IO Integration - Real-time updates for orders, trades, and balances
  • Responsive Design - Modern UI with TailwindCSS and Radix UI
  • Wallet Integration - Connect with Web3 wallets (EIP-155)

Backend

  • Blockchain Integration - Ethers.js v6 with WebSocketProvider for Monad testnet
  • Event Processing - Real-time subscription to smart contract events
  • Database - MongoDB for normalized data storage
  • REST API - HTTP endpoints for orders, trades, pairs
  • Socket.IO Server - Real-time data streaming to frontend
  • Event Backfill - Automatic backfill of missed events on startup

Smart Contracts

  • Vault - Token deposit/withdrawal management
  • Orderbook - Order matching and trade execution
  • Pair Registry - Trading pair management
  • Fee Manager - Trading fee collection

🏗️ Architecture

┌─────────────────┐    ┌──────────────────┐    ┌─────────────────┐
│   Monad Testnet │◄──►│  Event Processor │◄──►│   MongoDB      │
│   (WebSocket)   │    │                  │    │                 │
└─────────────────┘    └──────────────────┘    └─────────────────┘
                                │
                                ▼
                       ┌──────────────────┐
                       │  Socket.IO Server│◄──► Frontend Clients
                       │  + REST API      │
                       └──────────────────┘

📁 Project Structure

realDex/
├── frontendV2/                # React frontend (current)
│   ├── src/                  # Source code
│   │   ├── components/       # UI components
│   │   ├── pages/            # Route pages
│   │   └── lib/              # Utilities
├── backendV2/                 # Node.js backend (current)
│   ├── index.js              # Main backend server
│   ├── abis/                 # Contract ABIs
│   └── ...                   # Other backend files
├── blockchainv3/              # Smart contracts
│   ├── contracts/            # Solidity contracts
│   ├── scripts/              # Deployment scripts
│   └── deployments.json      # Contract addresses

🛠️ Setup

Prerequisites

  • Node.js 18+
  • npm or pnpm
  • MongoDB instance
  • Monad testnet access

1. Clone and Install

git clone <repository-url>
cd realDex

# Install frontend dependencies
cd frontendV2
npm install

# Install backend dependencies
cd ../backendV2
npm install

# Install smart contract dependencies
cd ../blockchainv3
npm install

2. Configure Environment

Backend Configuration

cd backendV2
cp .env.example .env

Edit .env with your values:

MONGO_URI=mongodb://localhost:27017/orderbook
WS_RPC=wss://testnet-rpc.monad.xyz
ORDERBOOK_ADDR=0x4A8948D81B9e277b0DA9070E6D02816d0E36F18A
PAIRREG_ADDR=0xB1d7C0E3a1278D83a95Ff98e821f73EEe836d666
PRIVATE_KEY=your_private_key

Database Setup

  • Start your MongoDB instance (local or cloud)

3. Start Development

Terminal 1 - Backend

cd backendV2
npm run dev

Terminal 2 - Frontend

cd frontendV2
npm run dev

Terminal 3 - Smart Contracts (Optional)

cd blockchainv3
npm run dev

🌐 Access Points

📊 API Endpoints

REST API

  • GET /api/pairs - Get trading pairs
  • GET /api/orders - Get orders
  • GET /api/trades - Get recent trades

Socket.IO Events

  • orderPlaced - New order created
  • orderMatched - Order matched
  • orderCancelled - Order cancelled
  • pairAdded - New trading pair added

🔧 Development

Frontend

cd frontendV2
npm run dev          # Start development server
npm run build        # Build for production

Backend

cd backendV2
npm run dev          # Start development server
npm run build        # Build for production
npm start            # Start production server

Smart Contracts

cd blockchainv3
npm run compile      # Compile contracts
npm run deploy       # Deploy to testnet
npm run test         # Run tests

🎯 Key Features

Portfolio Management

  • Deposit Tokens - Deposit USDC/WETH to vault for trading
  • Withdraw Tokens - Withdraw available tokens to wallet
  • Balance Tracking - View available and locked balances
  • Real-time Updates - Live balance updates via Socket.IO

Trading Interface

  • Orderbook - Live bid/ask orders with real-time updates
  • Charts - Price and depth charts
  • Trade Form - Place buy/sell orders
  • Recent Trades - Activity feed

🔒 Security

  • Smart Contract Audits - Contracts follow OpenZeppelin standards
  • Access Control - Role-based permissions for critical functions
  • Input Validation - Comprehensive validation on all inputs
  • Error Handling - Graceful error handling throughout

🚀 Deployment

Production Backend

cd backendV2
npm run build
npm start

Production Frontend

cd frontendV2
npm run build
# Deploy dist/ to your hosting provider

📝 Contributing

  1. Fork the repository
  2. Create a feature branch
  3. Make your changes
  4. Add tests if applicable
  5. Submit a pull request

📄 License

MIT License - see LICENSE file for details

🆘 Support

For issues and questions:

  1. Check the documentation
  2. Search existing issues
  3. Create a new issue with detailed information

🔮 Roadmap

  • Price feed integration
  • Advanced order types (limit, stop-loss)
  • Mobile app
  • Multi-chain support
  • Governance token
  • Advanced analytics
  • API rate limiting
  • Caching layer
  • Monitoring and alerting

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors