The DEX Dashboard is a full-stack Web3 monorepo with smart contracts on the backend (Solidity + Foundry) and a React frontend (Next.js 16 + wagmi). It simulates a decentralized exchange where users can mint mock tokens, trade them on a fixed-ratio DEX, and track market data from CoinGecko.
DEX/ βββ contracts/ # Foundry smart contracts β βββ src/ β β βββ MockERC20.sol # ERC20 token (mETH, mBTC, mUSDC) β β βββ Faucet.sol # Time-locked token faucet β β βββ MockDEX.sol # Fixed-ratio DEX with 6 swap paths β βββ test/ # 182+ Solidity tests β β βββ MockERC20.t.sol # 35 tests β β βββ Faucet.t.sol # 51 tests β β βββ MockDEX.t.sol # 96 tests (fuzz + invariant) β β βββ MockDEX.invariant.t.sol # Invariant tests β βββ script/ β β βββ Deploy.s.sol # Deployment script β βββ .env # Sepolia RPC URL + Etherscan API key β βββ foundry.toml # Foundry configuration βββ frontend/ # Next.js 16 application β βββ src/ β β βββ app/ # Pages (Home, Faucet, Swap, Analytics) β β βββ components/ # UI components (shadcn/ui, custom) β β βββ hooks/ # Custom React hooks β β βββ lib/ # Constants, ABIs, utilities β β βββ providers.tsx # Web3 provider β βββ tests/ # Vitest frontend tests βββ docs/ # GitHub Pages documentation β βββ index.html # Documentation home β βββ user-guide/ # User-facing guides β βββ developer-guide/ # Developer-facing guides β βββ qa.html # FAQ page with search β βββ assets/ # CSS, JS βββ scripts/ β βββ update-addresses.sh # Extracts deployed addresses β constants.ts βββ images/ # README screenshots βββ Makefile # Build automation (install, build, test, deploy)
Three contracts are deployed together. The deployment script handles the inter-contract wiring automatically.
βββββββββββββββ βββββββββββββββββββββ β MockERC20 ββββββΆβ Faucet β β (mETH) β β β β β β - mints via β β MockERC20 β β setFaucet() β β (mBTC) β β - 24h cooldown β β β β - 3 tokens β β MockERC20 β βββββββββββββββββββββ β (mUSDC) β β β βββββββββββββββββββββ β ββββββΆβ MockDEX β β β β β β β β - 3 reserves β β β β - 2 swap rates β β β β - 6 swap paths β β β β - SafeERC20 β β β βββββββββββββββββββββ βββββββββββββββ
setFaucet()ethRate=1700, btcRate=40000)
ββββββββββββ Connect Wallet βββββββββββββββ
β User ββββββββββββββββββββββββΆβ MetaMask β
β (Browser)β β (Wallet) β
β βββββββββββββββββββββββββ β
β β Sign Txn / Read βββββββββββββββ
ββββββ¬ββββββ β
β β
β βββββββββββββββββββββββββββββββββββ€
β β wagmi / viem β
β β β
β ββ useAccount() β
β ββ useReadContract() ββββ On-chain reads
β ββ useWriteContract() ββββΆ On-chain writes
β ββ useWaitForTxnReceipt()
β
βΌ
βββββββββββββββββββββββββββββββ
β Next.js 16 Frontend β
β β
β βββββββββββββββββββββββββ β
β β Pages (App Router) β β
β β ββ Home (/) β β
β β ββ Faucet /faucet β β
β β ββ Swap /swap β β
β β ββ Analytics /analytics β
β βββββββββββββββββββββββββ β
β β
β βββββββββββββββββββββββββ β
β β Custom Hooks β β
β β ββ use-dex.ts β β
β β ββ use-faucet.ts β β
β β ββ use-token-balancesβ β
β β ββ use-analytics.ts β β
β β ββ use-market-data.tsββββΆ CoinGecko API
β βββββββββββββββββββββββββ β
βββββββββββββββββββββββββββββββ
useReadContract to fetch on-chain state (balances, reserves, rates, cooldowns)useWriteContract with the encoded function calluseWaitForTransactionReceipt
layout/ components/ hooks/
βββ header.tsx βββ ui/ (13 primitives) βββ use-dex.ts
βββ footer.tsx β βββ button.tsx βββ use-faucet.ts
βββ wallet-button.tsx β βββ card.tsx βββ use-token-balances.ts
β βββ dialog.tsx βββ use-analytics.ts
pages/ β βββ tabs.tsx βββ use-market-data.ts
βββ page.tsx (Home) β βββ ...
βββ faucet/page.tsx βββ home/ lib/
βββ swap/page.tsx β βββ stats-counters.tsx βββ constants.ts
βββ analytics/ β βββ animated-section βββ wagmi.ts
βββ page.tsx βββ faucet/ βββ dex-abi.ts
βββ client.tsx β βββ claim-card.tsx βββ faucet-abi.ts
βββ swap/ βββ utils.ts
β βββ swap-card.tsx βββ market-data.ts
β βββ settings.tsx
βββ analytics/
β βββ stats-cards.tsx
β βββ token-table.tsx
β βββ trade-history.tsx
β βββ portfolio.tsx
βββ charts/
βββ candlestick.tsx
useAccount, useBalance, useChainId)useReadContract / useReadContracts with automatic caching via @tanstack/react-query (10s stale time)useWriteContract + useWaitForTransactionReceipt β auto-invalidates queries on successuseState for form inputs, slippage settings, and UI togglesAnimatedSection wraps content with Intersection Observer fade-in animationsloading, error, empty, and not-deployed statesaria-labels, focus-visible styles, prefers-reduced-motion support| Decision | Rationale |
|---|---|
| Foundry (vs Hardhat) | Native Solidity testing with fuzz/invariant support, fast compilation in Rust, and built-in linting |
| Fixed-ratio DEX (vs AMM) | Educational simplicity β users understand rate-based swaps without AMM complexity (xβ y=k). Rates are owner-set constants. |
| 3-reserve model (vs 2-token pools) | Supports cross-rate swaps (mETHβmBTC) by routing through mUSDC internally, demonstrating a real DeFi pattern |
| wagmi + viem | Modern, type-safe React hooks for wallet connection and contract interaction. Replaces ethers.js v5. |
| shadcn/ui + Tailwind | Accessible, customizable Radix UI primitives that compose well. Full design control without a bloated component library. |
| Raw HTML docs (GitHub Pages) | Zero build step, no framework dependencies. The docs are plain HTML/CSS/JS that deploy instantly via GitHub Pages. |
| --interactives 1 (private key) | Forge prompts for the private key interactively at deploy time. No env vars, no plaintext key files. |
The project has 182+ Solidity tests and frontend unit tests:
See the Testing Guide for complete details.