An implementation of a decentralized Automated Market Maker (AMM) — enabling users to swap tokens, add/remove liquidity, and manage pool configurations without centralized intermediaries.
The AMM follows a modular pool-based architecture.
Each liquidity pool maintains independent state variables that define its behavior and health:
- Token X & Y Balances – Current reserves in the pool
- LP Token Supply – Tracks liquidity provider shares
- Fee Rate – Defines swap fees applied per trade
- Lock Status – Controls whether trading or liquidity actions are allowed
The system supports three main user operations and one admin operation:
- Swap Tokens – Users send token X, receive calculated amount of token Y based on pool ratio.
- Add Liquidity – Users deposit token pairs (X & Y) to mint LP tokens representing their share.
- Remove Liquidity – LP tokens are burned to withdraw the user’s proportional share of X & Y.
- Lock / Unlock Pool – Admin authority can pause or resume trading and liquidity operations to ensure security or during upgrades.
All actions update the AMM Pool State, maintaining balance consistency across:
- Token X Balance
- Token Y Balance
- LP Token Supply
- Fee Rate
- Lock Status
- Smart contract logic handles state updates, fee accounting, and liquidity math.
- Ensures atomic operations to prevent inconsistencies during high-frequency transactions.
- Includes role-based access control for pool administration.
- Designed for modularity — easily extendable to multi-token pools or advanced bonding curves.
Resources:
