A decentralized exchange platform with automated market making, multi-hop routing, and real-time price feeds powered by Chainlink oracles.
SimpleDEX is a fully on-chain decentralized exchange (DEX) that enables permissionless token swaps through liquidity pools. Built on Ethereum with a modern Next.js frontend, it provides a complete DeFi trading experience with intelligent routing, live price data, and seamless liquidity provision.
- Multi-Hop Routing: Automatically finds the best path for trades, even through intermediate tokens
- Direct & Indirect Pairs: Seamlessly swap between any supported tokens
- Price Impact Display: See how your trade affects pool prices
- Slippage Protection: Built-in 5% slippage tolerance to protect against frontrunning
- Real-time Quotes: Live swap calculations as you type
- Add/Remove Liquidity: Become a liquidity provider and earn trading fees
- LP Position Tracking: Monitor all your liquidity positions in one place
- Pool Share Display: View your percentage ownership of each pool
- Automatic Ratio Calculation: Smart input fields auto-calculate proportional amounts
- LP Token Management: Mint and burn LP tokens representing your pool share
- Chainlink Price Feeds: Real-time USD prices for all major assets
- CoinGecko Integration: 1-hour and 24-hour price change tracking
- Industry-Standard APR: Realistic mock APR/APY for liquidity pools
- Market Price Display: Live token prices updated every 15 seconds
- Pool Analytics: Real-time reserve information and exchange rates
Support for 7 major tokens across 10+ trading pairs:
- Stablecoins: mUSDC, mUSDT, mDAI
- Wrapped Assets: mWETH, mWBTC
- DeFi Tokens: mLINK, mUNI
- Swap History: Complete record of all your trades
- Timestamped Transactions: Track when each swap occurred
- Transaction Links: Direct links to blockchain explorers
- Token Icons: Visual representation of all assets
- Dark Theme: Beautiful silver/blue gradient design
- Responsive Layout: Works seamlessly on desktop and mobile
- Wallet Integration: RainbowKit-powered wallet connection
- Real-time Updates: Auto-refreshing balances and prices
- Toast Notifications: Transaction status updates with detailed feedback
- Connect Wallet: Link your Web3 wallet (MetaMask, Rainbow, etc.)
- Get Test Tokens: Use the faucet to claim free tokens for testing
- Swap Tokens:
- Select input/output tokens
- Enter amount
- Review route and price impact
- Approve tokens (first time only)
- Execute swap
- Provide Liquidity:
- Choose a token pair
- Enter amounts for both tokens
- Approve tokens
- Add liquidity and receive LP tokens
- Track Positions: Monitor your LP positions and swap history
- Remove Liquidity: Burn LP tokens to reclaim your share plus fees
simpleDex/
βββ contracts/ # Smart contracts (Solidity + Foundry)
β βββ src/
β β βββ DEXFactory.sol # Pair creation factory
β β βββ DEXRouter.sol # Swap & liquidity router
β β βββ DEXPair.sol # Liquidity pool (AMM)
β β βββ PriceOracle.sol # Chainlink price aggregator
β β βββ TokenFaucet.sol # Test token distribution
β β βββ MockERC20.sol # Mock token implementation
β βββ script/ # Deployment & setup scripts
β βββ test/ # Contract test suite
β βββ startup.sh # One-command deployment
β βββ Makefile # Build & deploy commands
β
βββ dex-frontend/ # Next.js frontend (TypeScript)
βββ src/app/
β βββ components/ # React components
β β βββ SwapInterface.tsx
β β βββ LiquidityInterface.tsx
β β βββ Market.tsx
β β βββ LPPositions.tsx
β β βββ SwapHistory.tsx
β β βββ PoolInfo.tsx
β β βββ RouteDisplay.tsx
β β βββ TokenSelector.tsx
β βββ config/ # Token & network configs
β βββ hooks/ # React hooks
β βββ utils/ # Helper functions
β βββ page.tsx # Main app page
βββ public/ # Token icons & assets
| Contract | Address |
|---|---|
| DEXFactory | 0x5FbDB2315678afecb367f032d93F642f64180aa3 |
| DEXRouter | 0xe7f1725E7734CE288F8367e1Bb143E90bb3F0512 |
| PriceOracle | 0x9fE46736679d2D9a65F0992F2272dE9f3c7fa6e0 |
| TokenFaucet | 0xCf7Ed3AccA5a467e9e704C703E8D87F634fB0Fc9 |
| Token | Symbol | Address |
|---|---|---|
| USD Coin | mUSDC | 0x70e0bA845a1A0F2DA3359C97E0285013525FFC49 |
| Tether USD | mUSDT | 0x4826533B4897376654Bb4d4AD88B7faFD0C98528 |
| Dai Stablecoin | mDAI | 0x99bbA657f2BbC93c02D617f8bA121cB8Fc104Acf |
| Wrapped Ether | mWETH | 0x0E801D84Fa97b50751Dbf25036d067dCf18858bF |
| Wrapped Bitcoin | mWBTC | 0x8f86403A4DE0BB5791fa46B8e795C547942fE4Cf |
| Chainlink | mLINK | 0x9d4454B023096f34B160D6B654540c56A1F81688 |
| Uniswap | mUNI | 0x5eb3Bc0a489C5A8288765d2336659EbCA68FCd00 |
- BTC/USD: Real-time Bitcoin pricing
- ETH/USD: Real-time Ethereum pricing
- USDC/USD: Stablecoin peg monitoring
- LINK/USD: Chainlink token pricing
- UNI/USD: Uniswap token pricing (fallback)
Terminal 1 - Start local blockchain:
cd contracts
anvilTerminal 2 - Deploy contracts & setup pools:
cd contracts
make startupThis single command:
- β Deploys all core contracts (Factory, Router, Oracle, Faucet)
- β Deploys 7 mock tokens with price feeds
- β Creates 10+ trading pairs
- β Seeds initial liquidity across all pairs
- β Executes test swaps to verify functionality
Terminal 3 - Launch frontend:
cd dex-frontend
npm install
npm run devVisit http://localhost:3000 π
- Connect your wallet to the app
- Navigate to the "Faucet" tab
- Click "Claim Tokens" to receive:
- 10,000 mUSDC
- 10,000 mUSDT
- 10,000 mDAI
- 5 mWETH
- 0.5 mWBTC
- 100 mLINK
- 100 mUNI
# Complete setup (recommended)
make startup # Deploy everything + create pairs + add liquidity
# Individual deployment steps
make deploy-anvil # Deploy core contracts only
make deploy-tokens # Deploy mock tokens
make create-pairs # Create trading pairs
make add-liquidity # Add initial liquidity
make random-swaps # Execute test swaps
# Testing & verification
make test # Run test suite
make test-gas # Run tests with gas report
forge coverage # Check test coverage
# Build & clean
make build # Compile contracts
make clean # Remove artifacts
make format # Format Solidity codenpm run dev # Start development server
npm run build # Build for production
npm run start # Start production server
npm run lint # Run ESLintSimpleDEX supports 10+ active trading pairs:
- mWETH/mUSDC
- mWETH/mUSDT
- mWETH/mDAI
- mWBTC/mWETH
- mWBTC/mUSDC
- mUSDC/mUSDT
- mUSDC/mDAI
- mUSDT/mDAI
- mLINK/mUSDC
- mUNI/mUSDC
Multi-hop routing enables swaps between any two tokens, even without direct pairs.
- Solidity 0.8.20 - Contract language
- Foundry - Development framework
- OpenZeppelin - Security-audited contract libraries
- Chainlink - Decentralized price oracles
- Next.js 14 - React framework with App Router
- TypeScript - Type-safe development
- Tailwind CSS - Utility-first styling
- Wagmi - React hooks for Ethereum
- Viem - TypeScript Ethereum library
- RainbowKit - Wallet connection UI
- Ethers.js v6 - Blockchain interactions
- Anvil - Local Ethereum node (development)
- Sepolia - Ethereum testnet (deployment ready)
SimpleDEX uses the proven x Γ y = k formula:
- Ensures liquidity at all price levels
- Price determined by pool ratio
- Minimal price impact for balanced trades
- Resistant to manipulation
When no direct pair exists between tokens A and C:
- Algorithm searches for intermediate token B
- Calculates optimal path: A β B β C
- Compares gas cost vs. price improvement
- Executes multi-hop swap in single transaction
- Visual route display shows full swap path
- Chainlink Aggregators: Fetch real-world asset prices
- Fallback Mechanisms: Default prices for tokens without feeds
- Update Intervals: 15-second refresh for live data
- CoinGecko API: Historical price change tracking
β
Slippage Protection: 5-10% tolerance prevents sandwich attacks
β
Deadline Checks: Time-bound transactions expire if not mined
β
ReentrancyGuard: Prevents reentrancy attacks on critical functions
β
Token Sorting: Deterministic pair addresses (CREATE2-compatible)
β
Minimum Liquidity Lock: 1000 wei locked forever to prevent division by zero
β
Approval Required: Two-step token approval flow
β
Input Validation: Comprehensive checks on all user inputs
β
Safe Math: Solidity 0.8.x built-in overflow protection
- Token balances refresh after every transaction
- Pool reserves update on new blocks
- Price feeds poll every 15 seconds
- Swap history updates instantly
- Automatically detects direct vs. multi-hop routes
- Displays full swap path with token icons
- Shows hop count and intermediate tokens
- Optimizes for best execution price
- View all active positions in one dashboard
- Track pool share percentage
- Monitor pooled token amounts
- Calculate total position value in USD
- One-click liquidity removal
- Deploy to Sepolia testnet
- Implement concentrated liquidity (v3 style)
- Add token whitelisting for permissionless listings
- Integrate real Chainlink oracles on testnet
- Add limit orders via keeper network
- Implement flash swaps
- Add governance token ($SDEX)
- Launch mainnet version
cd contracts
forge test -vvvforge coveragemake test-gasContributions are welcome! Please feel free to submit a Pull Request.
- Fork the repository
- Create your feature branch (
git checkout -b feature/AmazingFeature) - Commit your changes (
git commit -m 'Add some AmazingFeature') - Push to the branch (
git push origin feature/AmazingFeature) - Open a Pull Request
MIT License - see LICENSE for details
- Inspired by Uniswap V2
- Built with Foundry by Paradigm
- UI components from shadcn/ui
- Price data from Chainlink & CoinGecko
Built with β€οΈ by the SimpleDEX team