Skip to content

Men6d656e/DEX

Repository files navigation

🚀 DEX Dashboard

A full-stack educational Web3 platform — mint mock tokens, swap them on a simulated DEX, and track live market analytics.

Solidity Next.js Foundry TypeScript License

📸 Screenshots✨ Features🛠️ Tech Stack🚀 Quick Start🏛️ Structure🧪 Testing


📸 Screenshots

Home Page Analytics Page
🏠 Home Dashboard 📊 Analytics & Charts
Faucet Page Swap Page
💰 Token Faucet 🔄 Swap Interface

✨ Features

💰 Faucet

Mint mETH, mBTC, and mUSDC mock tokens with a 24-hour cooldown per token per wallet. Track your lifetime claims, remaining cooldown timers, and token statistics — all on-chain.

🔄 Swap

Trade mock tokens with 6 swap paths powered by a fixed-ratio pricing engine:

Pair Direction
mETH ↔ mUSDC Direct swap via ratio
mBTC ↔ mUSDC Direct swap via ratio
mETH ↔ mBTC Cross-rate derivation through mUSDC

Includes slippage protection (set your minimum output), reserve tracking, and approval management.

📊 Analytics

  • Market Stats — 24h volume, total trades, active users, TVL (powered by CoinGecko API)
  • Candlestick Charts — Real-time price action for ETH, BTC, and combined overview
  • Token Statistics — Price, 24h change, market cap, and volume per token
  • Trade History — Recent swaps with timestamps, amounts, and participants
  • Portfolio Overview — Token balances, USD values, allocation breakdown

🔌 Wallet Integration

Connect any wallet via wagmi + viem. View your address, connected status, and token balances across pages.

🏠 Landing Page

Animated hero section with CTA buttons, live stats counters (total mints, swaps, users, TVL), feature cards with gradient icons, and tech stack badges.


🛠️ Tech Stack

Layer Technology
Smart Contracts Foundry + OpenZeppelin
Language (Contracts) Solidity ^0.8.27
Frontend Next.js 16 (App Router, static generation)
Language (Frontend) TypeScript (strict mode)
UI Library shadcn/ui + Tailwind CSS v4
Charts Recharts
Wallet wagmi + viem
Icons Lucide
Market Data CoinGecko API (Free Tier)
Testing Foundry (forged), Vitest, Testing Library
Automation Makefile

Smart Contracts

Contract Description
MockERC20 ERC20 token with faucet-restricted minting. Deployed as mETH, mBTC, mUSDC.
Faucet Time-locked faucet — claim 10 tokens per 24 hours per token.
MockDEX Fixed-ratio DEX with 6 swap paths, slippage protection, and reserve tracking.

All contracts inherit from OpenZeppelin (Ownable, ERC20, SafeERC20) for battle-tested security.


🚀 Quick Start

Prerequisites

1. Clone & Install

git clone https://github.com/Men6d656e/DEX.git
cd DEX
make install

2. Build Contracts

make build-contracts

3. Run Contract Tests

make test-contracts

4. Start Local Node & Deploy

# Terminal 1: Start Anvil
make anvil

# Terminal 2: Deploy contracts
make deploy-anvil

5. Configure Environment (Optional)

For live CoinGecko market data, create frontend/.env.local:

NEXT_PUBLIC_COINGECKO_API_KEY=your_api_key_here

Get a free API key

6. Start Frontend

make dev
# Or step by step: make install-frontend && make dev-frontend

Open http://localhost:3000 in your browser.

7. Deploy & Auto-Update Addresses

make deploy-anvil
# Builds → deploys to Anvil → prompts for private key → auto-captures addresses

For Sepolia testnet:

# First, configure contracts/.env:
#   cp contracts/.env.example contracts/.env
#   Edit with your RPC URL and Etherscan API key

make deploy-sepolia
# Builds → deploys to Sepolia → verifies on Etherscan → auto-captures addresses

8. Production Build

make prod

🏛️ Project Structure

DEX/
├── contracts/                    # Foundry smart contracts
│   ├── src/
│   │   ├── MockERC20.sol         # Mock tokens (mETH, mBTC, mUSDC)
│   │   ├── Faucet.sol            # Time-locked token faucet
│   │   └── MockDEX.sol           # Fixed-ratio DEX with 6 swap paths
│   ├── test/                     # Solidity tests (182+ tests)
│   ├── script/
│   │   └── Deploy.s.sol          # Deployment script
│   └── foundry.toml              # Foundry configuration
├── frontend/                     # Next.js 16 application
│   ├── src/
│   │   ├── app/
│   │   │   ├── page.tsx          # Home / Landing page
│   │   │   ├── faucet/           # Token faucet page
│   │   │   ├── swap/             # Token swap page
│   │   │   └── analytics/        # Market analytics page
│   │   ├── components/
│   │   │   ├── ui/               # shadcn/ui primitives (13 components)
│   │   │   ├── home/             # Landing page components
│   │   │   ├── swap/             # Swap panel components
│   │   │   ├── faucet/           # Faucet claim & analytics
│   │   │   ├── analytics/        # Charts, stats, portfolio
│   │   │   └── layout/           # Header, navigation
│   │   ├── hooks/                # Custom React hooks
│   │   ├── lib/                  # Utilities, constants, ABI types
│   │   └── providers.tsx         # Web3 provider setup
│   └── package.json
├── images/                       # Screenshots for README
├── docs/                         # GitHub Pages documentation
├── scripts/                      # Utility scripts
│   └── update-addresses.sh       # Auto-capture deployed contract addresses
├── Makefile                      # Automation (install, build, test, deploy)
└── README.md                     # This file

🧪 Testing

make test              # Run all tests (contracts + frontend)
make test-contracts    # Run only Foundry tests (182+ tests)
make test-frontend     # Run only frontend tests
make coverage          # Generate Foundry coverage report

The Solidity test suite includes:

  • 35 tests for MockERC20 (minting, faucet, ownership, ERC20 standards)
  • 51 tests for Faucet (claims, cooldowns, edge cases, ownership)
  • 96 tests for MockDEX (swaps, liquidity, cross-rate ETH↔BTC, fuzz tests, invariant tests)

16 fuzz functions × 256 runs each + 4 invariant tests × 256 runs × 15 depth.

Documentation

User and developer documentation is available via GitHub Pages:


🔧 Makefile Commands

Command Description
make install Install all dependencies (forge + npm)
make build Build contracts + frontend
make test Run all tests
make anvil Start local Anvil node (port 8545)
make deploy-anvil Deploy to Anvil + auto-update frontend addresses
make deploy-sepolia Deploy to Sepolia testnet + verify on Etherscan + auto-update
make update-addresses Re-capture addresses from broadcast JSON
make dev Install frontend deps + start dev server (localhost:3000)
make dev-frontend Start frontend dev server (localhost:3000)
make prod Build + serve production
make prod-frontend Serve production build
make generate-abi Generate type-safe wagmi hooks from ABIs
make coverage Generate coverage report
make clean Clean all artifacts
make fmt Format Solidity + TypeScript
make docs Serve docs locally (port 3001)

📄 License

MIT — see LICENSE for details.


🤝 Contributing

  1. Fork the repository
  2. Create a feature branch (git checkout -b feature/amazing-feature)
  3. Commit your changes (git commit -m 'Add amazing feature')
  4. Push to the branch (git push origin feature/amazing-feature)
  5. Open a Pull Request

Built with ❤️ for learning decentralized finance.

About

A full-stack educational Web3 platform for learning DeFi through hands-on interaction. Mint mock ERC20 tokens on a simulated DEX, execute swaps with fixed-ratio pricing, and track live market analytics via CoinGecko — all without risking real funds. Built with Solidity (Foundry), Next.js 16, wagmi, and shadcn/ui. Deployed to Sepolia testnet.

Topics

Resources

License

Stars

0 stars

Watchers

0 watching

Forks

Releases

No releases published

Packages

 
 
 

Contributors