Soroban smart contracts for the MentorMinds Stellar platform, providing secure escrow and payment functionality on the Stellar blockchain.
This repository contains the Soroban smart contracts that power the MentorMinds platform:
- Escrow Contract: Secure payment escrow for mentoring sessions
- Multi-Sig Wallet: Multi-signature wallet for platform administration
- Payment Router: Automated payment distribution and fee collection
- Rust 1.70+ with wasm32 target
- Soroban CLI (latest version)
- Stellar Account (testnet for development)
- Node.js 18+ (for testing scripts)
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh
rustup target add wasm32-unknown-unknowncargo install --locked soroban-clisoroban config network add testnet \
--rpc-url https://soroban-testnet.stellar.org:443 \
--network-passphrase "Test SDF Network ; September 2015"soroban config identity generate defaultsoroban config identity address default
# Use the Stellar Laboratory to fund your testnet account
# https://laboratory.stellar.org/#account-creator?network=testmentorminds-contracts/
βββ escrow/ # Escrow smart contract
β βββ src/
β β βββ lib.rs # Main contract code
β βββ Cargo.toml
β βββ README.md
βββ multisig/ # Multi-signature wallet
β βββ src/
β β βββ lib.rs
β βββ Cargo.toml
β βββ README.md
βββ payment-router/ # Payment distribution
β βββ src/
β β βββ lib.rs
β βββ Cargo.toml
β βββ README.md
βββ scripts/ # Deployment and testing scripts
β βββ deploy.sh
β βββ test.sh
β βββ invoke.sh
βββ tests/ # Integration tests
βββ README.md
Manages secure payment escrow for mentoring sessions.
Features:
- Lock funds until session completion
- Automatic release on confirmation
- Dispute resolution mechanism
- Time-based auto-release
- Refund support for cancellations
Functions:
create_escrow(mentor, learner, amount, session_id)release_funds(escrow_id)dispute(escrow_id, reason)resolve_dispute(escrow_id, decision)refund(escrow_id)
Multi-signature wallet for platform administration.
Features:
- Configurable signers and threshold
- Transaction proposal and approval
- Time-lock for delayed execution
- Emergency recovery procedures
Functions:
add_signer(address, weight)remove_signer(address)propose_transaction(to, amount, data)approve_transaction(tx_id)execute_transaction(tx_id)
Automated payment distribution and fee collection.
Features:
- Automatic fee calculation
- Multi-recipient payments
- Asset conversion support
- Payment batching
Functions:
route_payment(from, to, amount, fee_percentage)batch_payments(payments[])calculate_fees(amount)
./scripts/build-all.shcd escrow
cargo build --target wasm32-unknown-unknown --releasesoroban contract optimize --wasm target/wasm32-unknown-unknown/release/escrow.wasm# Deploy escrow contract
cd escrow
soroban contract deploy \
--wasm target/wasm32-unknown-unknown/release/escrow.wasm \
--source default \
--network testnet
# Save contract ID
export ESCROW_CONTRACT_ID=<contract-id>soroban contract invoke \
--id $ESCROW_CONTRACT_ID \
--source default \
--network testnet \
-- initialize \
--admin <admin-address> \
--platform_fee 5cd escrow
cargo test./scripts/test-integration.sh# Create escrow
soroban contract invoke \
--id $ESCROW_CONTRACT_ID \
--source default \
--network testnet \
-- create_escrow \
--mentor <mentor-address> \
--learner <learner-address> \
--amount 100 \
--session_id "session-123"- Write Contract: Implement contract logic in Rust
- Test Locally: Run unit tests with
cargo test - Build: Compile to WASM with
cargo build - Optimize: Optimize WASM size
- Deploy to Testnet: Deploy and test on testnet
- Integration Test: Test with backend API
- Audit: Security audit before mainnet
- Deploy to Mainnet: Final deployment
- Access Control: Proper authorization checks
- Reentrancy Protection: Guard against reentrancy attacks
- Integer Overflow: Use checked arithmetic
- Input Validation: Validate all inputs
- Emergency Pause: Implement pause mechanism
- Upgrade Path: Plan for contract upgrades
MentorMinds contracts use a formal state machine methodology to ensure secure and predictable state transitions.
- Explicit States: All possible contract states are defined as
contracttypeenums. - Valid Transitions: Only pre-defined transitions between states are permitted.
- Shared Trait: The
StateMachinetrait incontracts/sharedenforces a consistentis_valid_transitionmethod across all contracts. - Exhaustive Testing: State machine transitions are verified by exhaustive tests in
tests/state_machine_tests.rs, covering every possible (from, to) state pair.
impl StateMachine for EscrowStatus {
fn is_valid_transition(env: &Env, from: &Self, to: &Self) -> bool {
match (from, to) {
(EscrowStatus::Active, EscrowStatus::Released) => true,
(EscrowStatus::Active, EscrowStatus::Disputed) => true,
// ... other valid transitions
_ => false,
}
}
}For detailed specifications and diagrams, see docs/state-machines.md.
- Build the new version to WASM
cd escrow cargo build --target wasm32-unknown-unknown --release - Upload the new WASM artifact
soroban contract upload \ --source default \ --network testnet \ --wasm target/wasm32-unknown-unknown/release/escrow.wasm
- Invoke the contractβs admin-only upgrade entrypoint to switch code at the same contract ID
- Use the on-chain upgrade mechanism recommended in Sorobanβs guide
- Do not call initialize again; the initialization guard prevents re-initialization
- Verify existing escrows remain readable and new fields default correctly
dispute_reasondefaults to emptyresolved_atdefaults to0auto_release_delayuses the configured stored value or the 72h default
- Validate new functions on old records
- Call
dispute,resolve_dispute, andtry_auto_releaseon pre-upgrade escrows
- Call
Reference: Upgrading Wasm bytecode for a deployed contract (Stellar Docs)
- Minimize storage operations
- Use efficient data structures
- Batch operations when possible
- Optimize WASM size
- Cache frequently accessed data
soroban contract invoke \
--id $ESCROW_CONTRACT_ID \
--network testnet \
-- get_balancesoroban events --id $ESCROW_CONTRACT_ID --network testnet- Project setup
- Escrow contract implementation
- Multi-sig wallet implementation
- Payment router implementation
- Unit tests
- Integration tests
- Security audit
- Testnet deployment
- Mainnet deployment
- Fork the repository
- Create a feature branch
- Write tests for new features
- Ensure all tests pass
- Submit a pull request
MIT License - see LICENSE file for details
For issues and questions:
- Create an issue on GitHub
- Join Stellar Discord
- Check Soroban documentation
Status: π‘ In Development
Built with Rust and Soroban for the Stellar blockchain