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

No packages published