A decentralized Automated Market Maker built on Solana using the Anchor framework. It implements the constant product formula (x * y = k) to allow users to swap between two tokens without an order book or centralized counterparty.
- Creates a liquidity pool for any two SPL token pairs
- Allows liquidity providers to deposit tokens and receive LP tokens representing their share
- Allows users to swap one token for another with price determined by the pool ratio
- Allows liquidity providers to withdraw their share by burning LP tokens
programs/amm/src/
├── lib.rs — program entry point, instruction routing
├── instructions/
│ ├── initialize.rs — creates the pool and mints LP token
│ ├── deposit.rs — adds liquidity, mints LP tokens to provider
│ ├── withdraw.rs — burns LP tokens, returns underlying assets
│ └── swap.rs — executes token swap using constant product formula
└── state/
└── config.rs — pool config account storing token mints and fees
- Rust
- Solana CLI
- Anchor CLI
- Node.js (v18 or above)
- Yarn
cd AMM
yarn install
anchor build
anchor testMake sure your Solana CLI is set to localnet:
solana config set --url localhostStart a local validator if not already running:
solana-test-validator