A comprehensive DeFi toolkit for building decentralized finance applications on the Stellar blockchain using Soroban smart contracts.
- 🪙 Token Contracts: Complete ERC-20-like token implementation on Stellar
- 💧 Liquidity Pools: Automated market maker (AMM) liquidity pools
- 💰 Lending & Borrowing: Collateralized lending protocol with liquidations
- 🌾 Yield Farming: Staking and reward distribution mechanisms
- 🌉 Cross-chain Bridges: Asset transfer between different blockchains
- 🏛️ Governance: Decentralized governance and voting systems
- 📊 Analytics: Real-time DeFi protocol analytics and monitoring
- 🛡️ Circuit Breakers: Automatic protection against extreme price volatility
- 🔮 Oracle System: Multi-source price aggregation with deviation detection
- 🛠️ Developer Tools: CLI tools and SDK for easy development
- Rust 1.70.0 or higher
- Stellar CLI tools
- Soroban CLI
cargo install stellar-defi-toolkitgit clone https://github.com/yourusername/stellar-defi-toolkit.git
cd stellar-defi-toolkit
cargo build --releasestellar-defi-cli quote-rate --utilization-bps 8000stellar-defi-cli check-liquidation \
--borrower "GCBORROWER456" \
--debt-asset "USDC" \
--collateral-asset "XLM" \
--debt-price 1000000000000000000 \
--collateral-price 500000000000000000stellar-defi-cli liquidate \
--liquidator "GCLIQUIDATOR123" \
--borrower "GCBORROWER456" \
--debt-asset "USDC" \
--collateral-asset "XLM" \
--repay-amount 1000000000000000000000 \
--debt-price 1000000000000000000 \
--collateral-price 500000000000000000 \
--dry-runFor detailed documentation on liquidation commands, see CLI_LIQUIDATION.md.
stellar-defi-cli deploy-token \
--name "My Token" \
--symbol "MTK" \
--supply 1000000stellar-defi-cli create-pool \
--token-a "TOKEN_A_CONTRACT_ID" \
--token-b "TOKEN_B_CONTRACT_ID"stellar-defi-cli stake \
--contract-id "STAKING_CONTRACT_ID" \
--amount 1000stellar-defi-cli get-info \
--contract-id "CONTRACT_ID"Add this to your Cargo.toml:
[dependencies]
stellar-defi-toolkit = "0.1.0"
tokio = { version = "1.0", features = ["full"] }use stellar_defi_toolkit::{TokenContract, StellarClient};
#[tokio::main]
async fn main() -> anyhow::Result<()> {
let client = StellarClient::new().await?;
let token = TokenContract::new("My Token".to_string(), "MTK".to_string(), 1000000);
let contract_id = token.deploy(&client).await?;
println!("Token deployed with contract ID: {}", contract_id);
Ok(())
}use stellar_defi_toolkit::{LiquidityPoolContract, StellarClient};
#[tokio::main]
async fn main() -> anyhow::Result<()> {
let client = StellarClient::new().await?;
let pool = LiquidityPoolContract::new(
"TOKEN_A_CONTRACT_ID".to_string(),
"TOKEN_B_CONTRACT_ID".to_string()
);
let contract_id = pool.deploy(&client).await?;
println!("Liquidity pool created with contract ID: {}", contract_id);
Ok(())
}use soroban_sdk::{Env, Address};
use stellar_defi_toolkit::StakingContract;
fn main() {
let env = Env::default();
env.mock_all_auths();
let admin = Address::generate(&env);
let user = Address::generate(&env);
// Initialize staking contract
let staking = StakingContractClient::new(&env, &contract_id);
staking.initialize(
&admin,
&staking_token_address,
&reward_token_address,
&17280, // 1 day reward period
);
// Set rewards
staking.notify_reward_amount(&admin, &10_000_000_000);
// User stakes tokens
staking.stake(&user, &1_000_000_000);
// Check earned rewards
let earned = staking.get_earned(&user);
println!("Earned rewards: {}", earned);
// Claim rewards
staking.claim_rewards(&user);
}For more details, see STAKING_README.md and docs/staking_contract.md.
stellar-defi-toolkit/
├── src/
│ ├── main.rs # CLI entry point
│ ├── lib.rs # Library entry point
│ ├── contracts/ # Smart contract implementations
│ │ ├── mod.rs
│ │ ├── token.rs # Token contract
│ │ ├── liquidity_pool.rs # Liquidity pool contract
│ │ ├── staking.rs # Staking contract
│ │ ├── governance.rs # Governance contract
│ │ ├── circuit_breaker.rs # Circuit breaker for volatility protection
│ │ ├── price_oracle.rs # Multi-source price oracle
│ │ └── oracle_manager.rs # Oracle aggregation manager
│ ├── utils/ # Utility functions
│ │ ├── mod.rs
│ │ ├── client.rs # Stellar client
│ │ └── helpers.rs # Helper functions
│ └── types/ # Type definitions
│ ├── mod.rs
│ ├── token.rs
│ └── pool.rs
├── tests/ # Integration tests
├── examples/ # Example usage
│ ├── circuit_breaker_demo.rs # Circuit breaker demonstration
│ └── ...
├── docs/ # Documentation
│ ├── circuit_breaker_guide.md # Circuit breaker guide
│ └── ...
├── Cargo.toml
└── README.md
The toolkit includes a comprehensive circuit breaker system to protect against extreme price volatility:
- Automatic Protection: Halts operations when price changes exceed 10% in a single update
- Consecutive Deviation Detection: Trips after 3 consecutive 5%+ price movements
- Rate Limiting: Enforces 5-minute minimum intervals between price updates
- Per-Asset Control: Independent circuit breaker status for each asset
- Admin Controls: Manual trip, reset, and configuration management
// Circuit breaker automatically checks price volatility
if !price_oracle.is_operational(env.clone(), asset_address.clone()) {
panic!("Circuit breaker tripped - operations halted");
}
// Get price (includes automatic circuit breaker check)
let price = price_oracle.get_price(env, asset_address);| Threshold | Value | Action |
|---|---|---|
| Single Deviation | 10% | Immediate trip |
| Consecutive Deviation | 5% | Count towards trip |
| Consecutive Count | 3 updates | Trip circuit breaker |
| Rate Limit | 5 minutes | Minimum update interval |
| Cooldown | 30 minutes | Time before recovery |
✓ Prevents liquidations during flash crashes
✓ Protects against oracle manipulation
✓ Provides time for admin review during extreme volatility
✓ Reduces systemic risk from cascading failures
✓ Enables safe recovery after market disruptions
See the Circuit Breaker Guide for detailed documentation.
cargo buildcargo testcargo run --example token_deployment
cargo run --example liquidity_pool- Circuit Breaker Guide - Price volatility protection
- Risk Management Framework - Comprehensive risk controls
- Soroban Documentation
- Stellar Documentation
- API Reference
We welcome contributions! Please see our Contributing Guide for details.
- Fork the repository
- Create a feature branch (
git checkout -b feature/amazing-feature) - Commit your changes (
git commit -m 'Add some amazing feature') - Push to the branch (
git push origin feature/amazing-feature) - Open a Pull Request
This project is licensed under either of:
- Apache License, Version 2.0, (LICENSE-APACHE or https://www.apache.org/licenses/LICENSE-2.0)
- MIT license (LICENSE-MIT or https://opensource.org/licenses/MIT)
at your option.
- The Stellar Development Foundation for the amazing Soroban platform
- The Rust community for excellent tooling and ecosystem
- All contributors who help make this project better
- Token contracts with ERC-20-like functionality
- Liquidity pools with AMM functionality
- Staking contracts with time-based reward distribution
- Basic CLI tools for contract deployment
- Comprehensive testing suite
- Yield farming protocols
- Cross-chain bridges
- Governance contracts with voting
- Advanced analytics dashboard
- Web GUI for easy interaction
- Integration with major DEXs
- Oracle integration for price feeds
- Multi-token governance
- Automated strategy execution
- Mobile app support
- Institutional-grade security
- Compliance tools
- Advanced risk management
- White-label solutions
- Enterprise support packages
- Layer 2 scaling solutions
- AI-powered trading strategies
- Social trading features
- NFT integration
- DeFi insurance protocols
- 📧 Email: support@stellar-defi-toolkit.com
- 💬 Discord: Join our community
- 🐦 Twitter: @stellardefi
Built with ❤️ for the Stellar ecosystem