Skip to content

A Repo for an Automated Market Maker on the Stacks blockchain built with clarity

Notifications You must be signed in to change notification settings

Cyber-Mitch/stacks-amm

Repository files navigation

Stacks AMM - Decentralized Exchange

System Design Architecture

This project implements a decentralized exchange (DEX) on the Stacks blockchain using Clarity contracts. The system is designed with the following key functionalities:

  • Permissionless Pool Creation: Any user can create a new trading pool for any two SIP-010 tokens by supplying initial liquidity.
  • Liquidity Management: Users can add liquidity to existing pools and remove their liquidity as needed.
  • Token Swapping: Traders can swap between assets in any trading pool.
  • Fee Collection: Swaps incur fees that are redistributed to liquidity providers.
  • Uniqueness of Pools: Prevents creation of duplicate pools for the same token pair.

The contracts handle these operations, while the frontend provides a user-friendly interface for wallet-connected interactions.

How to Run

Prerequisites

  • Node.js (version 18 or higher)
  • Clarinet (for Clarity contract development and testing)
  • A Stacks wallet for interacting with the frontend

Running Tests

The project includes tests for the Clarity contracts using Vitest and Clarinet.

  1. Install dependencies:

    npm install
  2. Run the tests:

    npm test

This will execute the test suite in tests/amm.test.ts using the Vitest environment configured for Clarinet.

Deploying Contracts

  1. Ensure Clarinet is installed and configured.

  2. Deploy to local network for testing:

    clarinet deployments generate --devnet
  3. For testnet deployment, update the contract addresses in frontend/lib/amm.ts and deploy via Clarinet or Stacks CLI.

Starting the Frontend

The frontend is built with Next.js and allows users to interact with the AMM.

  1. Navigate to the frontend directory:

    cd frontend
  2. Install frontend dependencies:

    npm install
  3. Run the development server:

    npm run dev
  4. Open http://localhost:3000 in your browser.

  5. Connect your Stacks wallet to interact with the DEX (swap, add/remove liquidity, create pools).

Additional Notes

  • Ensure the contract address and name in frontend/lib/amm.ts match your deployed contract.
  • For production, update API endpoints and network configurations as needed.
  • The project supports SIP-010 token interactions and uses the Hiro API for fetching pool data.

About

A Repo for an Automated Market Maker on the Stacks blockchain built with clarity

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published