A next-generation decentralized exchange (DEX) built on Stellarβs Soroban smart contracts, designed for capital efficiency, seamless trading, and a smooth user experience.
The project is engineered for performance and clarity, featuring:
- π Capital-Efficient Index Pools
- π Zero-Hop Cross-Pair Routing
- π Multi-Wallet Support
- π Live Market Data & Real-Time Charts
- β‘ Fast, Low-Cost Transactions powered by Stellar
Production-hardened DeFi application with a multi-asset AMM pool, efficient zero-hop gas routing, and live Multiple wallets integration.
ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β FRONTEND (Next.js + React) β
β ββββββββββββ ββββββββββββββββ βββββββββββββ βββββββββββββ β
β β Wallet β β Swap β β Live Chartβ β Token β β
β β Selector β β Interface β β Component β β Modal β β
β ββββββ¬ββββββ ββββββββ¬ββββββββ βββββββ¬ββββββ βββββββ¬ββββββ β
β β β β β β
β ββββββββββββββββ΄ββββββββββββββββ΄βββββββββββββββ β
β β β
β βββββββββββββββββ΄βββββββββββββββββ β
β β Stellar SDK (sorobanRpc) β β
β βββββββββββββββββ¬βββββββββββββββββ β
ββββββββββββββββββββββββββββββββΌββββββββββββββββββββββββββββββββ
β β Soroban RPC
ββββββββββββββββββββββββββββββββΌββββββββββββββββββββββββββββββββ
β SMART CONTRACTS (Soroban) β
β βββββββββββββββββββββββ ββββββββββββββββββββββββ β
β β 3-Asset Index Pool ββββββΊβ External Tokens β β
β β β’ swap_xlm_for_usdc β β β’ XLM SAC Token β β
β β β’ swap_usdc_for_eth ββββββΊβ β’ USDC Testnet β β
β β β’ add_liquidity β β β’ ETH Testnet β β
β β β’ quote_usdc_to_xlm β β β β
β βββββββββββββββββββββββ ββββββββββββββββββββββββ β
β β
β Zero-Hop Routing: USDC -> ETH internally priced via XLM β
ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
graph TD
User([Trader/User])
Admin([Contract Admin])
LP([Liquidity Provider])
subgraph StellSwap 3-Asset Index Pool
XLM[(XLM Reserve)]
USDC[(USDC Reserve)]
ETH[(ETH Reserve)]
Prices[Oracle Rates<br>UsdcRate, EthRate]
S1(swap_xlm_for_usdc)
S2(swap_xlm_for_eth)
S3(swap_usdc_for_eth)
L1(add_liquidity)
L2(remove_liquidity)
Admin1(update_rates)
Admin2(set_paused)
end
User -->|Sends XLM| S1
S1 -->|Uses| Prices
S1 -->|Calculates payout| USDC
USDC -->|Sends USDC| User
User -.->|Sends USDC| S3
S3 -.->|Uses| Prices
S3 -.->|Sends ETH| User
LP ==>|Deposits XLM, USDC, ETH| L1
π₯ Demo Video: Watch on Google Drive
StellSwap AMM Liquidity Pool Contract ID:
CCH3WGMUTBXK573BPC6MSWLQQZ72DYYOQ7ZFEOXJBJROFCTVFCETDQZA
π Verify on Stellar Expert Explorer
Token Contracts:
- XLM SAC Token:
CDLZFC3SYJYDZT7K67VZ75HPJVIEUVNIXF47ZG2FB2RMQQVU2HHGCYSC - USDC Token:
CBAFDW2AC2PSW3MGW5FVZUJSASEHMT7U6HX24XKHQ34GXXFKCGUX2I7Y - ETH Token:
CANGUK3UOKPZOKHTYUYOXJYJRQ5B7YH7ZSKXW6KNCIPOKXXUDNT3RT2V
Example Transaction Hash (Successful Swap Call):
042cab10f52f02a74e361482362ab8ea003f5ce624c965e6b4e073040bc1d0a5
(Swapped 10 XLM for 1.66 USDC) π View Transaction on Stellar Expert Explorer
Sleek, dark-mode terminal swap UI with live charts
Freighter Wallet extension support via stellar-wallets-kit
AMM Smart Contract functions verified
31/31 Rust Smart Contract tests passing.
- Live Market Data β Displays live XLM/USD pricing data using a dynamic Chart.js chart and
get_reservesdata from the contract. - Contract Called from Frontend β The UI directly interacts with the Soroban contract for quotes (
get_rates) and actual swaps. - Transaction Status Visible β Real-time toast notifications guide the user through signing, submission, and confirmation.
- Error Handling β Deep error handling for rejected signatures, insufficient balances, and disconnected wallets.
- ποΈ 3-Asset Index Pool β All three assets (XLM, USDC, ETH) reside within a single liquidity pool, maximizing capital efficiency for LPs.
- β‘ Double Gas Savings (Zero-Hop Routing) β To swap USDC for ETH, you don't need a factory router contract to bridge two separate token pools. The
swap_usdc_for_ethfunction internally prices USDC to XLM, then XLM to ETH natively in a single update, saving double the gas and mitigating multi-hop slippage! - π‘οΈ Oracle Safety β Admin-controlled oracle rates (
UsdcRate,EthRate) peg cross-asset valuations to XLM to prevent extreme price manipulation attacks often seen in standardx*y=kAMMs with low TVL. - β½ Internal State Ledger β To prevent donation attacks and flash-loan exploits, the pool tracks true liquidity strictly through its persistent
DataKey::Reservestates rather than easily-manipulated raw token balances.
- Node.js v18+
- npm
- Freighter Wallet browser extension
- Testnet XLM (Get free XLM)
git clone <your-repo-url>
cd stellswap
# Install frontend UI dependencies
npm installCreate a .env file in the root directory:
NEXT_PUBLIC_CONTRACT_ADDRESS=CCH3WGMUTBXK573BPC6MSWLQQZ72DYYOQ7ZFEOXJBJROFCTVFCETDQZA
NEXT_PUBLIC_ADMIN_PUBKEY=GBV2VSXKD6CY3XNZOVKIWAEXBHYU3XDQWOGOZSFI27SDCA6SGST73ZBQ
NEXT_PUBLIC_USDC_TOKEN_ID=CBAFDW2AC2PSW3MGW5FVZUJSASEHMT7U6HX24XKHQ34GXXFKCGUX2I7Y
NEXT_PUBLIC_ETH_TOKEN_ID=CANGUK3UOKPZOKHTYUYOXJYJRQ5B7YH7ZSKXW6KNCIPOKXXUDNT3RT2Vnpm run dev- Open http://localhost:3000 in your browser. Connect Freighter wallet (set to Testnet) to begin viewing balances, executing swaps, and watching quotes update.
Located in contracts/hello-world/src/lib.rs
| Function | Description |
|---|---|
swap_xlm_for_usdc / swap_xlm_for_eth |
Core swaps directly against the native reserve token |
swap_usdc_for_eth / swap_eth_for_usdc |
The unified cross-pair routing methods that save double gas |
add_liquidity / remove_liquidity |
Access points for adding/removing liquidity to the index pool |
quote_xlm_to_usdc / quote_usdc_to_xlm |
Instant on-chain expected yield mathematical quotes |
update_rates |
Admin-only pricing oracle adjustments |
Zero-Hop Routing Flow (e.g., USDC for ETH):
User calls swap_usdc_for_eth() on Stellswap Contract
β Calculates intermediate XLM value (USDC * usdc_rate)
β Calculates final ETH value (intermediate_xlm / eth_rate)
β Contract transfers USDC from User to Pool
β Contract transfers ETH from Pool to User
β Updates Internal State Ledgers seamlessly
β Emits SWAP event
cd contracts/hello-world
cargo build --target wasm32-unknown-unknown --release
# Deploy (Stellar CLI required)
stellar contract deploy \
--wasm target/wasm32-unknown-unknown/release/hello_world.wasm \
--source YOUR_SECRET_KEY \
--network testnetcd contracts/hello-world && cargo test- Cross-pair zero-hop swaps accuracy (
test_swap_usdc_for_eth_cross_pair) - Slippage protection & minimum output checks (
test_slippage_usdc_for_xlm_panics) - Empty reserve panic protections (
test_swap_fails_on_empty_usdc_reserve) - Liquidity share math and proportion tests (
test_two_providers_lp_balances) - Pause controls and Admin Auth limitations
- β Internal state ledgers to prevent "donation" token-balance manipulation
- β Admin-only oracle pricing to prevent algorithmic flash loan attacks
- β Minimum output slippage guarantees on every swap function
- β Strict zero-amount and disconnected auth validations
- β Pause-state emergency breakers
- β Simulated fee calculations via Soroban RPC
- β Disconnected state handling & button protections
- β
Transaction rejection error catching via
unsignedXdr
MIT License β feel free to use this project as a learning resource!
Built for Stellar Soroban Smart Contract Development Level 4.
Special thanks to the Stellar Development Foundation for providing excellent documentation and tools.
Submission Date: February 2026 Status: Ready









