Soroban smart contracts for the Aether-Swap decentralized AMM on Stellar.
Organization: Aether-Swap · Author: Alhaji-naira
This repository houses all on-chain Soroban contracts powering the Aether-Swap AMM protocol:
| Contract | Path | Description |
|---|---|---|
amm_pool |
contracts/amm_pool/src/lib.rs |
Constant-product AMM with LP shares and swaps |
The amm_pool contract implements the constant-product formula x * y = k:
initialize— Deploy a new pool with two token addresses and a fee in basis points (e.g.30= 0.30%)add_liquidity— Deposittoken_a+token_b, receive proportional LP sharesremove_liquidity— Burn LP shares, withdraw proportional reservesswap_exact_tokens_for_tokens— Swap a precise input for the maximum possible outputquote_swap— Read-only price estimation (no state change)get_reserves/get_shares— View current pool state
Aether-Swap-Contracts/
├── Cargo.toml # Workspace root
└── contracts/
└── amm_pool/
├── Cargo.toml
└── src/
└── lib.rs # AMM contract + unit tests
| Tool | Version | Install |
|---|---|---|
| Rust | ≥ 1.78 | curl https://sh.rustup.rs -sSf | sh |
| wasm32 target | — | rustup target add wasm32-unknown-unknown |
| Stellar CLI | ≥ 22.0 | cargo install --locked stellar-cli --features opt |
cd Aether-Swap-Contracts
stellar contract buildThe compiled .wasm binaries land in target/wasm32-unknown-unknown/release/.
cargo testcargo test -- --nocapture# Create a deployer identity
stellar keys generate deployer --network testnet
# Fund via Friendbot
stellar keys fund deployer --network testnet
# Verify balance
stellar account balances --source-account deployer --network testnet# Deploy token A (e.g. XLM-wrapped SAC)
stellar contract deploy \
--wasm target/wasm32-unknown-unknown/release/amm_pool.wasm \
--source deployer \
--network testnet
# ↳ Copy the returned CONTRACT_ID as TOKEN_A_ID
# Deploy token B
stellar contract deploy \
--wasm target/wasm32-unknown-unknown/release/amm_pool.wasm \
--source deployer \
--network testnet
# ↳ Copy the returned CONTRACT_ID as TOKEN_B_IDexport POOL_ID=$(stellar contract deploy \
--wasm target/wasm32-unknown-unknown/release/amm_pool.wasm \
--source deployer \
--network testnet)
echo "Pool deployed at: $POOL_ID"stellar contract invoke \
--id $POOL_ID \
--source deployer \
--network testnet \
-- \
initialize \
--admin $(stellar keys address deployer) \
--token_a $TOKEN_A_ID \
--token_b $TOKEN_B_ID \
--swap_fee_bps 30stellar contract invoke \
--id $POOL_ID \
--source deployer \
--network testnet \
-- \
add_liquidity \
--provider $(stellar keys address deployer) \
--amount_a 1000000000 \
--amount_b 1000000000 \
--min_shares 1stellar contract invoke \
--id $POOL_ID \
--source deployer \
--network testnet \
-- \
swap_exact_tokens_for_tokens \
--trader $(stellar keys address deployer) \
--token_in $TOKEN_A_ID \
--amount_in 10000000 \
--min_amount_out 1The fee is set at pool initialization in basis points (bps):
| Fee BPS | Percentage | Recommended For |
|---|---|---|
| 10 | 0.10% | Stablecoin pairs |
| 30 | 0.30% | Standard pairs |
| 100 | 1.00% | Exotic / low-liq |
- All state-changing functions use
require_auth()for the caller. - Slippage protection is enforced via
min_shares,min_a,min_b, andmin_amount_out. - Reentrancy is not possible in Soroban's execution model.
- Overflow is handled by Rust's default overflow-checks in debug and explicit assertions in release.
MIT © Aether-Swap