A basic implementation of an Automated Market Maker built on the Sui blockchain using Move programming language. This project demonstrates token creation, liquidity pool management, and token swapping functionality.
- Custom Token Creation: Create and mint USDC and custom tokens
- Liquidity Pool Management: Create pools and add liquidity
- Token Swapping: Swap between USDC and custom tokens using constant product formula
- TypeScript Client: Complete client library for interacting with the contracts
- Local Testing: Full testing suite for local development
sui-amm/
├── move/
│ ├── sources/
│ │ ├── token_a.move # USDC token implementation
│ │ ├── token_b.move # Custom token (MYTOKEN) implementation
│ │ └── token_swap.move # AMM pool and swap logic
│ └── Move.toml
├── ts-tests/
│ ├── src/
│ │ └── index.ts # TypeScript client implementation
│ ├── package.json
│ └── tsconfig.json
└── README.md
- Sui CLI: Install from Sui documentation
- Node.js: Version 16 or higher
- TypeScript: For running the client
- Local Sui Network: For testing
# Start local Sui network
sui start --with-faucet --force-regenesis
# Create a new address (if needed)
sui client new-address ed25519
# Get test SUI tokens
sui client faucet# Navigate to move directory
cd move/
# Build and publish contracts
sui client publish --gas-budget 20000000Save the Package ID and Treasury Cap IDs from the publish output!
# Navigate to typescript client directory
cd ts-tests/
# Install dependencies
npm install
# Update the contract addresses in src/index.ts:
# - PACKAGE_ID: Your published package ID
# - USDC_TREASURY_CAP: USDC treasury cap object ID
# - MYTOKEN_TREASURY_CAP: MYTOKEN treasury cap object ID# Execute the demo script
npm run test
# or
npx && ts-node src/index.ts- Symbol: USDC
- Name: USD Coin
- Decimals: 6
- Features: Mintable with treasury cap
- Symbol: MTK
- Name: My Token
- Decimals: 6
- Features: Mintable with treasury cap
Pool Management:
create_pool(): Initialize a new liquidity pooladd_liquidity(): Add tokens to existing pool
Trading:
swap_usdc_to_mytoken(): Swap USDC for custom tokensswap_mytoken_to_usdc(): Swap custom tokens for USDC
Queries:
get_reserves(): Get current pool reservesget_amount_out(): Calculate swap output amount
The AMM uses the constant product formula: x * y = k
Where:
x= USDC reservey= MYTOKEN reservek= constant product
Swap calculation:
amount_out = (reserve_out * amount_in) / (reserve_in + amount_in)
import { SuiAMMClient } from './src/index';
// Initialize client
const ammClient = new SuiAMMClient();
// Mint tokens
await ammClient.mintUSDC(BigInt(1000 * 1e6)); // 1000 USDC
await ammClient.mintMYTOKEN(BigInt(2000 * 1e6)); // 2000 MYTOKEN
// Create pool
const poolResult = await ammClient.createPool(
BigInt(500 * 1e6), // 500 USDC
BigInt(1000 * 1e6) // 1000 MYTOKEN
);
// Perform swap
await ammClient.swapUSDCToMYTOKEN(poolId, BigInt(100 * 1e6));The project includes a complete testing workflow that:
- Mints tokens for testing
- Creates a liquidity pool with initial reserves
- Performs token swaps and verifies results
- Checks pool state before and after operations