Skip to content

tenrikut/Q3-25-Anchor-Amm

Repository files navigation

AMM Anchor

A Solana-based Automated Market Maker (AMM) built with Anchor.

🚀 Overview

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.


✨ Features

  • 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.

🏗️ Architecture

  • programs/amm-anchor/: Rust smart contract (Anchor)
    • src/lib.rs: Program entrypoint and instruction handlers
    • src/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

⚙️ Build & Deploy

Prerequisites

Build the Program

anchor build

Deploy to Local Validator

solana-test-validator --reset &
anchor deploy

🧪 Running the Test Suite

Install Dependencies

yarn install

Run Tests

anchor test

This will:

  • Start a local validator
  • Build and deploy the program
  • Run the comprehensive TypeScript test suite in tests/amm-anchor.ts

What the Tests Cover

  • 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

📚 Developer Notes

  • 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

🛠️ Extending the AMM

  • Add swap instruction for token exchange
  • Implement liquidity withdrawal (burn LP tokens)
  • Add fee collection and distribution
  • Pool lock/unlock controls

🤝 Contributing

Pull requests and issues are welcome! Please ensure new features are covered by tests.


📄 License

MIT

About

A Solana-based Automated Market Maker (AMM) built with Anchor.

Resources

Stars

Watchers

Forks

Releases

Packages

Contributors

Languages