Skip to content

Latest commit

 

History

History
40 lines (29 loc) · 1.63 KB

File metadata and controls

40 lines (29 loc) · 1.63 KB

Constant Product AMM Contract

This repository implements a Constant Product Automated Market Maker (AMM) smart contract for the Solana blockchain using Anchor. The contract allows users to create liquidity pools, deposit tokens, swap between tokens, and withdraw liquidity, following the x*y=k invariant.

Features

  • Initialize Liquidity Pool: Create a new pool with two tokens and initial liquidity.
  • Deposit: Add liquidity to an existing pool and receive LP tokens.
  • Swap: Swap between base and quote tokens with automatic fee deduction.
  • Withdraw: Remove liquidity from the pool and redeem LP tokens for underlying assets.
  • Event Emission: Emits events for pool initialization, deposits, swaps, and withdrawals.

Getting Started

Prerequisites

  • Rust Version: rustc 1.88.0-nightly (3350c1eb3 2025-05-01)
  • Solana CLI Version: solana-cli 2.2.12 (src:0315eb6a; feat:1522022101, client:Agave)
  • Anchor Verison: anchor-cli 0.31.1
  • Node.js Version: v23.11.0

Build and Deploy

  1. Build the Program:
    anchor build
  2. Run Tests
    anchor test

Usage

  • Initialize Pool: Use the initializeLiquidity instruction to create a new pool.
  • Deposit: Use the deposit instruction to add liquidity.
  • Swap: Use the swapBaseIn instruction to swap tokens.
  • Withdraw: Use the withdraw instruction to remove liquidity.

See tests/amm.ts for example usage and integration tests.