Smart contracts for the KosmosShop decentralized multi-vendor e-commerce marketplace built with Soroban on the Stellar blockchain.
Kosmos Contracts implement the core logic for shops, products, orders, escrow, and paymentsβensuring trustless, transparent transactions between buyers and sellers.
- Shop Contract - Seller shop creation and management
- Product Contract - Product listing and inventory
- Order Contract - Order creation and tracking
- Escrow Contract - Secure fund holding and release
- Marketplace Contract - Platform governance and fees
- Reputation Contract - Seller and product ratings
- Multi-token Support - XLM, USDC, and other Stellar assets
- Dispute Resolution - Built-in conflict resolution
- Gas Optimized - Efficient contract execution
- Upgrade Mechanism - Safe contract updates
- Language: Rust
- Platform: Stellar Soroban (Smart Contract Platform)
- Framework: Soroban SDK
- Testing: Rust test framework + Soroban testing utilities
- Package Manager: Cargo
- Blockchain: Stellar Testnet / Mainnet
- Rust >= 1.73.0
- Soroban CLI latest version
- Stellar SDK for Rust
- Docker (optional, for consistent environment)
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh
source $HOME/.cargo/env
rustup updatecargo install --locked soroban-cligit clone https://github.com/yourusername/kosmos-contracts.git
cd kosmos-contractssoroban contract buildCompiled WASM files in target/wasm32-unknown-unknown/release/
kosmos-contracts/
βββ contracts/
β βββ marketplace/ # Platform governance
β β βββ src/
β β β βββ lib.rs
β β β βββ contract.rs
β β β βββ error.rs
β β βββ Cargo.toml
β βββ shop/ # Shop management
β β βββ src/
β β β βββ lib.rs
β β β βββ contract.rs
β β β βββ error.rs
β β βββ Cargo.toml
β βββ product/ # Product listings
β β βββ src/
β β β βββ lib.rs
β β β βββ contract.rs
β β β βββ error.rs
β β βββ Cargo.toml
β βββ order/ # Order processing
β β βββ src/
β β β βββ lib.rs
β β β βββ contract.rs
β β β βββ error.rs
β β βββ Cargo.toml
β βββ escrow/ # Escrow management
β β βββ src/
β β β βββ lib.rs
β β β βββ contract.rs
β β β βββ token.rs
β β β βββ error.rs
β β βββ Cargo.toml
β βββ reputation/ # Ratings & reviews
β βββ src/
β β βββ lib.rs
β β βββ contract.rs
β β βββ error.rs
β βββ Cargo.toml
βββ Cargo.toml # Workspace config
βββ Cargo.lock
βββ README.md
Purpose: Platform governance, fees, and settings
Responsibilities:
- Initialize the marketplace with admin settings
- Manage platform fee percentages
- Handle fee withdrawals to platform wallet
- Register and manage admin addresses
- Track platform-wide statistics
Purpose: Seller shop management
Responsibilities:
- Create new shops with seller information
- Update shop details (name, description, branding)
- Retrieve shop information and metadata
- Toggle shop active/inactive status
- List all shops owned by a seller
- Manage shop followers and reputation
Purpose: Product listings and inventory
Responsibilities:
- Create products with details and pricing
- Update product information and pricing
- Manage product inventory and stock levels
- Delete products from listings
- Retrieve product details by ID
- List products by shop
- Track product categories and tags
Purpose: Order creation and tracking
Responsibilities:
- Create new orders with buyer and shop details
- Track order status through lifecycle
- Store order items and quantities
- Confirm delivery status
- List orders by buyer
- List orders by shop
- Track order timestamps and metadata
Purpose: Secure fund holding and release
Responsibilities:
- Hold buyer funds securely during transactions
- Release funds to seller upon delivery confirmation
- Process refunds back to buyer if needed
- Freeze funds during dispute periods
- Track escrow status for each order
- Support multiple token types (XLM, USDC, etc.)
- Maintain transparent escrow balance records
Purpose: Seller and product ratings
Responsibilities:
- Store product reviews with ratings and comments
- Store seller reviews and ratings
- Retrieve reviews for products
- Retrieve reviews for sellers
- Calculate seller reputation scores
- Track review authors and timestamps
- Manage review visibility and moderation
# Run all tests
cargo test --release
# Run specific contract tests
cargo test -p escrow-contract --release
# Run with Soroban testing
soroban contract test --release
# Coverage report
cargo tarpaulin --releaseTest suite covers functionality, edge cases, and security validation for all contracts.
Set environment variables for your target network:
# For testnet
export SOROBAN_RPC_URL=https://soroban-testnet.stellar.org
export SOROBAN_NETWORK_PASSPHRASE="Test SDF Network ; September 2015"
# For mainnet
export SOROBAN_RPC_URL=https://soroban-mainnet.stellar.org
export SOROBAN_NETWORK_PASSPHRASE="Public Global Stellar Network ; September 2015"Generate a keypair for contract deployment:
soroban keys generate deployerFund the account from the Stellar faucet (testnet only) or transfer funds from an existing account.
Build all contracts:
soroban contract buildDeploy each contract to the network using the Soroban CLI.
After deploying the marketplace contract, initialize it with admin settings and platform parameters.
Deploy shop, product, order, escrow, and reputation contracts in the order specified in the deployment guide.
A deployment script is provided to automate the process of building and deploying all contracts to testnet or mainnet.
After deployment, store contract addresses in your backend environment variables for blockchain interactions.
Before mainnet deployment:
- Internal Review - Code walkthrough and security checklist
- External Audit - Professional security firm conducts full contract audit
- Bug Bounty - Launch bug bounty program for community review
Contracts include upgrade mechanisms that:
- Require admin authorization
- Preserve state during upgrades
- Allow safe migration of data
- Include fallback options for rollback
- Deploy new contract version to testnet
- Run migration function to transfer state
- Validate all data transferred correctly
- Test thoroughly on testnet
- Deploy to mainnet in controlled manner
- Minimize state writes per transaction
- Use efficient data structures
- Batch operations when possible
- Cache frequently accessed data
- Optimize contract method signatures
Gas usage for common operations is documented to help understand cost implications of different flows.
UnauthorizedCaller- Caller lacks required permissionsInvalidShopId- Referenced shop doesn't existInvalidProductId- Referenced product doesn't existInvalidOrderId- Referenced order doesn't existInsufficientFunds- Not enough funds for operationProductOutOfStock- Product inventory exhaustedOrderAlreadyFulfilled- Can't modify completed orderDisputeInProgress- Can't take action during disputeInvalidAmount- Amount doesn't meet requirementsContractError- General contract execution error
All operations return detailed error messages for debugging and user feedback.
- Fork repository
- Create feature branch for your changes
- Test thoroughly with the Rust test suite
- Ensure code passes all security checks
- Commit with clear, descriptive messages
- Push to your fork and open a Pull Request
MIT License - see LICENSE file for details
For issues and questions:
- Open GitHub issue
- Check Stellar documentation: https://developers.stellar.org/docs
- Kosmos API - NestJS backend
- Kosmos Frontend - Next.js frontend