Skip to content

andylinee/swapstarter

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

13 Commits
 
 
 
 
 
 
 
 

Repository files navigation

SwapStarter - Learning Blockchain DEX Development

A full-stack decentralized exchange (DEX) built from scratch to learn blockchain development.

🎯 Learning Journey

Phase 1: Wallet Connection ✅

  • Implemented wallet connection with RainbowKit
  • Network switching and balance display
  • Multi-wallet provider support

Phase 2: ERC20 Tokens ✅

  • Created SwapToken (ERC20) with mint/burn
  • Deployed to Sepolia testnet
  • Comprehensive test suite (7 tests)
  • Frontend integration for viewing/transferring

Phase 3: AMM Swap Contract ✅ JUST COMPLETED

  • Implemented constant product formula (x × y = k)
  • Liquidity pool with add/remove functionality
  • Token swaps with slippage protection
  • Deployed with 1000 TKA + 1000 TKB initial liquidity
  • Solved real-world SafeERC20 compatibility issue

📊 Deployed Contracts (Sepolia)

Contract Address Etherscan
Token A (TKA) 0xd4F8...7374 View
Token B (TKB) 0xb8c1...fC6d View
SimpleSwap 0x1286...4706 View

🛠️ Tech Stack

Smart Contracts:

  • Solidity ^0.8.20
  • Foundry (testing & deployment)
  • OpenZeppelin contracts

Frontend:

  • Next.js 14 (App Router)
  • TypeScript
  • wagmi & viem
  • RainbowKit
  • TailwindCSS

🧪 Key Learnings

AMM Mathematics

Constant Product: x × y = k
Example: 1000 TKA × 1000 TKB = 1,000,000
Swap 100 TKB → Get 90.91 TKA
New: 909.09 TKA × 1100 TKB = 1,000,000 ✓

Real-World Issues Solved

  • SafeERC20 Compatibility: Debugged and fixed transfer issues
  • Allowance Management: Proper approve/transferFrom flow
  • Gas Estimation: Understanding transaction costs
  • State Synchronization: Keeping frontend in sync with blockchain

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors