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.
- Node.js (version 18 or higher)
- Clarinet (for Clarity contract development and testing)
- A Stacks wallet for interacting with the frontend
The project includes tests for the Clarity contracts using Vitest and Clarinet.
-
Install dependencies:
npm install
-
Run the tests:
npm test
This will execute the test suite in tests/amm.test.ts using the Vitest environment configured for Clarinet.
-
Ensure Clarinet is installed and configured.
-
Deploy to local network for testing:
clarinet deployments generate --devnet
-
For testnet deployment, update the contract addresses in
frontend/lib/amm.tsand deploy via Clarinet or Stacks CLI.
The frontend is built with Next.js and allows users to interact with the AMM.
-
Navigate to the
frontenddirectory:cd frontend -
Install frontend dependencies:
npm install
-
Run the development server:
npm run dev
-
Open http://localhost:3000 in your browser.
-
Connect your Stacks wallet to interact with the DEX (swap, add/remove liquidity, create pools).
- Ensure the contract address and name in
frontend/lib/amm.tsmatch 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.