A Solana-based Automated Market Maker (AMM) built with Anchor.
This project implements a minimal yet robust AMM smart contract on Solana using the Anchor framework. It supports pool creation, liquidity provision, LP token minting, and slippage protection. The codebase is designed for extensibility and security, following best practices for Solana programs.
- Pool Initialization: Create a new AMM pool with two tokens and a configurable fee.
- Liquidity Provision: Deposit tokens to provide liquidity and receive LP tokens.
- Proportional Deposits: Add liquidity in proportion to the pool's reserves.
- Slippage Protection: Prevents deposits if slippage exceeds user-specified limits.
- LP Token Minting: Mints LP tokens to liquidity providers.
- Authority Management: Optional authority for pool upgrades or admin actions.
- Security: All critical accounts are PDAs; robust error handling.
- programs/amm-anchor/: Rust smart contract (Anchor)
src/lib.rs: Program entrypoint and instruction handlerssrc/instructions/: Instruction logic (initialize, deposit)src/state/: Account state definitions (Config)src/error.rs: Custom error codes
- tests/: TypeScript test suite (Mocha/Chai)
amm-anchor.ts: Comprehensive MVP test suite
anchor buildsolana-test-validator --reset &
anchor deployyarn installanchor testThis will:
- Start a local validator
- Build and deploy the program
- Run the comprehensive TypeScript test suite in
tests/amm-anchor.ts
- Pool initialization (basic, duplicate, custom authority)
- Initial and proportional liquidity deposits
- LP token minting and supply checks
- Slippage and error handling
- Edge cases (minimal deposit)
- Security constraints
- Program ID:
2fWakUuDipQDARTFcjbWV2yQgs4RDNZQwMYeZufk43yS - IDL: Generated at
target/idl/amm_anchor.json - Types: Generated at
target/types/amm_anchor.ts - Constants: 6 decimals for all tokens
- Fee: Expressed in basis points (e.g., 300 = 3%)
- No Swap Yet: Swap functionality is not implemented in this MVP
- Add swap instruction for token exchange
- Implement liquidity withdrawal (burn LP tokens)
- Add fee collection and distribution
- Pool lock/unlock controls
Pull requests and issues are welcome! Please ensure new features are covered by tests.
MIT