Soroban Smart Contracts for Blocksmith-forge AMM Protocol
A decentralized Automated Market Maker (AMM) and token swap protocol built on the Stellar network using Soroban smart contracts.
This repository contains the core smart contracts for the Blocksmith-forge DEX, including:
- AMM Pool Contract: Manages liquidity pools, token swaps, and liquidity provision
- Constant Product Formula: Implements the standard x*y=k AMM formula
- LP Token System: Tracks liquidity provider positions and rewards
The amm_pool contract provides the following functionality:
- Pool Initialization: Create new trading pairs
- Add Liquidity: Deposit tokens to earn LP tokens
- Remove Liquidity: Withdraw tokens by burning LP tokens
- Token Swaps: Exchange tokens with automatic price discovery
- Fee Mechanism: 0.3% trading fee on all swaps
blocksmith-forge-Contracts/
├── Cargo.toml # Workspace configuration
├── README.md # This file
└── contracts/
└── amm_pool/
├── Cargo.toml # Contract dependencies
└── src/
└── lib.rs # Main contract implementation
- Rust 1.75.0 or higher
- Soroban CLI (
cargo install soroban-cli) - Stellar Testnet account (for deployment)
# Clone the repository
git clone https://github.com/blocksmith-forge/blocksmith-forge-Contracts.git
cd blocksmith-forge-Contracts
# Install Soroban CLI
cargo install soroban-cli# Build the contract
cargo build --target wasm32-unknown-unknown --release
# Or use Soroban CLI
soroban contract build# Run unit tests
cargo test
# Run with Soroban testutils
cargo test --features testutils# Start a local standalone network
soroban network standalone
# In a separate terminal, check network status
soroban network status# Set network to local
soroban network use standalone
# Deploy the AMM pool contract
soroban contract deploy \
--wasm target/wasm32-unknown-unknown/release/amm_pool.wasm \
--source alice \
--network standalone# Initialize the pool with token addresses
soroban contract invoke \
--id <CONTRACT_ID> \
--source alice \
--network standalone \
initialize \
--token_a <TOKEN_A_ADDRESS> \
--token_b <TOKEN_B_ADDRESS>soroban contract invoke \
--id <CONTRACT_ID> \
--source alice \
--network standalone \
add_liquidity \
--provider <PROVIDER_ADDRESS> \
--amount_a 1000000 \
--amount_b 1000000soroban contract invoke \
--id <CONTRACT_ID> \
--source alice \
--network standalone \
swap_exact_tokens_for_tokens \
--trader <TRADER_ADDRESS> \
--token_in <TOKEN_IN_ADDRESS> \
--amount_in 100000 \
--amount_out_min 0Initialize a new liquidity pool with two token addresses.
Add liquidity to the pool and receive LP tokens. Returns the amount of LP tokens minted.
Remove liquidity by burning LP tokens. Returns the amounts of token_a and token_b withdrawn.
Swap exact input tokens for output tokens using constant product formula. Returns the amount of output tokens received.
Get current pool information including reserves and LP token supply.
Get the liquidity position for a specific provider.
- All functions require proper authentication
- Slippage protection via
amount_out_minparameter - 0.3% trading fee to prevent sandwich attacks
- LP token burn mechanism ensures proper liquidity tracking
MIT License - see LICENSE file for details
Contributions are welcome! Please read our contributing guidelines before submitting PRs.
- Organization: blocksmith-forge
- Developer: Aesdecodes
- GitHub: https://github.com/blocksmith-forge