Skip to content

Vivkzz/Token-Swap

Repository files navigation

WizzSwap DEX

A decentralized exchange (DEX) built from scratch, implementing core AMM functionality inspired by Uniswap V1 architecture with modern development practices.

🚀 Features

  • 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

🏗️ Architecture

Smart Contracts

  • 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

Frontend

  • Next.js with TypeScript
  • Wagmi for Ethereum interactions
  • RainbowKit for wallet connections
  • Tailwind CSS for styling

🛠️ Getting Started

Prerequisites

  • Node.js 18+
  • Git
  • MetaMask or compatible Web3 wallet

Installation

  1. Clone the repository
git clone <repository-url>
cd wizzswap-dex
  1. Install dependencies
cd dex-frontend
npm install
  1. Environment Setup Create a .env.local file 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
  1. Run the development server
npm run dev

Open http://localhost:3000 to view the application.

Smart Contract Deployment

  1. Install Foundry (for smart contracts)
curl -L https://foundry.paradigm.xyz | bash
foundryup
  1. Deploy contracts
# Deploy to local network or testnet
forge script script/Deploy.s.sol --broadcast --rpc-url <your_rpc_url>

📝 How It Works

Adding Liquidity

  1. Select two tokens (TokenA and TokenB)
  2. Enter amounts for both tokens
  3. Confirm transaction to add liquidity
  4. Receive LP tokens representing your share

Swapping Tokens

  1. Select input token and amount
  2. Choose output token
  3. Review swap rate and fees
  4. Confirm transaction

Removing Liquidity

  1. Select LP tokens to burn
  2. Receive proportional amounts of both underlying tokens

🔧 Technical Details

  • 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

🌐 Supported Networks

  • Ethereum Mainnet
  • Sepolia Testnet
  • (Easily configurable for other EVM chains)

🚧 Limitations

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

🤝 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

📄 License

This project is licensed under the MIT License - see the LICENSE file for details.

🔗 Resources

⚠️ Disclaimer

This project is for educational purposes only. Do not use in production without proper security audits and testing.

About

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors