A decentralized exchange (DEX) built from scratch, implementing core AMM functionality inspired by Uniswap V1 architecture with modern development practices.
- Token Swapping: Swap ERC20 tokens using constant product formula (x*y=k)
- Liquidity Pools: Provide liquidity and earn LP tokens
- Fee Collection: 0.3% trading fees distributed to liquidity providers
- Factory Pattern: Automated pair creation for any ERC20 tokens
- Modern Frontend: Clean React interface with Web3 wallet integration
- Factory.sol: Creates and manages trading pairs
- Router.sol: Handles user interactions and routing
- Pair.sol: Individual AMM pools with swap logic
- LPToken.sol: ERC20 tokens representing liquidity positions
- TokenA.sol & TokenB.sol: Example ERC20 tokens for testing
- Next.js with TypeScript
- Wagmi for Ethereum interactions
- RainbowKit for wallet connections
- Tailwind CSS for styling
- Node.js 18+
- Git
- MetaMask or compatible Web3 wallet
- Clone the repository
git clone <repository-url>
cd wizzswap-dex- Install dependencies
cd dex-frontend
npm install- Environment Setup
Create a
.env.localfile in the frontend directory:
NEXT_PUBLIC_WALLETCONNECT_PROJECT_ID=your_project_id
NEXT_PUBLIC_FACTORY_ADDRESS=deployed_factory_address
NEXT_PUBLIC_ROUTER_ADDRESS=deployed_router_address
NEXT_PUBLIC_TOKEN_A_ADDRESS=token_a_address
NEXT_PUBLIC_TOKEN_B_ADDRESS=token_b_address- Run the development server
npm run devOpen http://localhost:3000 to view the application.
- Install Foundry (for smart contracts)
curl -L https://foundry.paradigm.xyz | bash
foundryup- Deploy contracts
# Deploy to local network or testnet
forge script script/Deploy.s.sol --broadcast --rpc-url <your_rpc_url>- Select two tokens (TokenA and TokenB)
- Enter amounts for both tokens
- Confirm transaction to add liquidity
- Receive LP tokens representing your share
- Select input token and amount
- Choose output token
- Review swap rate and fees
- Confirm transaction
- Select LP tokens to burn
- Receive proportional amounts of both underlying tokens
- AMM Model: Constant Product Market Maker (x*y=k)
- Fee Structure: 0.3% per swap
- Liquidity Formula: √(amount0 × amount1) for initial liquidity
- Slippage: Calculated based on pool reserves and trade size
- Ethereum Mainnet
- Sepolia Testnet
- (Easily configurable for other EVM chains)
This is an educational/demo project. Notable limitations:
- No slippage protection mechanisms
- No price oracles
- Simplified error handling
- No flash loan support
- Basic frontend without advanced trading features
- Fork the repository
- Create a feature branch (
git checkout -b feature/amazing-feature) - Commit your changes (
git commit -m 'Add amazing feature') - Push to the branch (
git push origin feature/amazing-feature) - Open a Pull Request
This project is licensed under the MIT License - see the LICENSE file for details.
This project is for educational purposes only. Do not use in production without proper security audits and testing.