Skip to content

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 

Repository files navigation

Aether-Swap Contracts 🦀

Soroban smart contracts for the Aether-Swap decentralized AMM on Stellar.

Organization: Aether-Swap · Author: Alhaji-naira


Overview

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

AMM Design

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 — Deposit token_a + token_b, receive proportional LP shares
  • remove_liquidity — Burn LP shares, withdraw proportional reserves
  • swap_exact_tokens_for_tokens — Swap a precise input for the maximum possible output
  • quote_swap — Read-only price estimation (no state change)
  • get_reserves / get_shares — View current pool state

Workspace Structure

Aether-Swap-Contracts/
├── Cargo.toml                   # Workspace root
└── contracts/
    └── amm_pool/
        ├── Cargo.toml
        └── src/
            └── lib.rs           # AMM contract + unit tests

Prerequisites

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

Local Development

1. Build all contracts

cd Aether-Swap-Contracts
stellar contract build

The compiled .wasm binaries land in target/wasm32-unknown-unknown/release/.

2. Run unit tests

cargo test

3. Run tests with verbose output

cargo test -- --nocapture

Testnet Deployment

Step 1 — Configure Stellar CLI and fund identity

# 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

Step 2 — Deploy two mock tokens (for testing)

# 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_ID

Step 3 — Deploy the AMM Pool

export POOL_ID=$(stellar contract deploy \
  --wasm target/wasm32-unknown-unknown/release/amm_pool.wasm \
  --source deployer \
  --network testnet)

echo "Pool deployed at: $POOL_ID"

Step 4 — Initialize the Pool

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 30

Step 5 — Add Initial Liquidity

stellar contract invoke \
  --id $POOL_ID \
  --source deployer \
  --network testnet \
  -- \
  add_liquidity \
  --provider $(stellar keys address deployer) \
  --amount_a 1000000000 \
  --amount_b 1000000000 \
  --min_shares 1

Step 6 — Perform a Swap

stellar 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 1

Fee Model

The 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

Security Notes

  • All state-changing functions use require_auth() for the caller.
  • Slippage protection is enforced via min_shares, min_a, min_b, and min_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.

License

MIT © Aether-Swap

About

Core Soroban smart contracts powering the Aether-Swap Automated Market Maker (AMM), managing on-chain liquidity pools, token swaps, and fee distribution logic on the Stellar network.

Resources

Stars

Watchers

Forks

Releases

Packages

Contributors

Languages