Skip to content

CtpN3m01/SimpleDEX

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 
 
 

Repository files navigation

SimpleDEX – Decentralized Token Exchange

SimpleDEX is a minimal decentralized exchange (DEX) built on the Sepolia testnet. It allows users to swap between two ERC-20 tokens — TokenA and TokenB — using an automated market maker (AMM) model based on the constant product formula:

(x + Δx) * (y - Δy) = x * y

📦 Deployed Contracts

Contract Address
TokenA 0x729448733C94495Da1C2e350a6621ff9FC3B1672
TokenB 0xF890dcAD1a702f74eD80F138Ddd12fac4cE51fEE
SimpleDEX 0xBc469da34FE5B238D55e3c9BA3a2d0fF17a59Ac6

⚙️ Features

  • ✅ Add liquidity (only owner)
  • 🔁 Swap TokenA ↔ TokenB (any user)
  • 💧 Remove liquidity (only owner)
  • 📈 Get token price based on current pool reserves

📚 Smart Contracts Overview

TokenA.sol & TokenB.sol

  • Standard ERC-20 tokens implemented with OpenZeppelin.
  • 18 decimals, mintable in constructor.

SimpleDEX.sol

  • Contains the liquidity pool for TokenA and TokenB.
  • Uses the constant product formula (x * y = k).
  • Key functions:
    • addLiquidity(uint256 amountA, uint256 amountB)
    • swapAforB(uint256 amountAIn)
    • swapBforA(uint256 amountBIn)
    • removeLiquidity(uint256 amountA, uint256 amountB)
    • getPrice(address _token)

🧪 How to Test on Remix

  1. Connect to the Sepolia testnet using MetaMask.
  2. Deploy or import the contracts using the provided addresses.
  3. Interact with the contracts using Remix’s interface:
    • Use approve() on TokenA/TokenB before calling swap or addLiquidity.
    • Use swapAforB() or swapBforA() to perform token swaps.
    • Use getPrice() to check the exchange rate.

👨‍💻 Owner Permissions

Only the owner (contract deployer) can:

  • Add or remove liquidity.
  • Control initial balances and token supply.

🧠 Learning Objectives

This project was built to understand and apply:

  • Decentralized finance (DeFi) primitives
  • ERC-20 token standards
  • AMM logic (constant product formula)
  • Solidity contract interactions
  • Manual deployment and testing with Remix on the Sepolia Ethereum testnet

📜 License

MIT License

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors