Soroban smart contracts powering Delego β AI-Powered Delegated Commerce on Stellar
This repository contains the trust-critical Soroban smart contracts for the Delego platform. They handle escrow management, spending permissions, and delegation registry operations on the Stellar blockchain β the blockchain layer for secure, trust-minimized agent-mediated commerce.
Delego is split across three repositories:
| Repository | Purpose |
|---|---|
| Delego | Frontend web application |
| Delego-backend | Backend microservices, agents, shared SDK/types |
| Delego-contracts | This repo β Soroban smart contracts |
Delego (web) ββ> Delego-backend (API/gateway) ββ> Soroban RPC ββ> These contracts
- Security First: All contracts undergo rigorous security audits
- Gas Efficiency: Optimized for minimal gas consumption
- Upgradability: Designed with upgrade patterns in mind
- Auditability: Clear, well-documented code
- Test Coverage: Comprehensive test suites (unit + cross-contract integration)
| Contract | Path | Purpose |
|---|---|---|
| Escrow | escrow/ |
Locks funds during purchases, time-locked release, refunds, yield, disputes, multi-admin |
| Permissions | permissions/ |
Delegated spending authority, allowances, per-tx limits, relayed (gasless) spends, multi-owner grants |
| Delegation Registry | delegation_registry/ |
Tracks delegations, expiry, versioned rollback/upgrade |
| Cross-contract tests | tests/ |
End-to-end delegated purchase flows across escrow + permissions |
Each contract is a Cargo workspace member. Unit tests live as #[cfg(test)] modules in */src/test.rs, contract-level integration tests as modules in */src/integration_tests.rs, and cross-contract integration tests in the root tests/ package.
- Rust:
>= 1.70curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh
- WASM target (required to build contract
.wasmartifacts):rustup target add wasm32-unknown-unknown
- Soroban CLI (for deployment and interaction):
cargo install soroban-cli
# Run the full workspace test suite (unit + cross-contract integration)
cargo test --workspace
# Run tests with output
cargo test -- --nocapture
# Run a single test
cargo test test_function_name
# Run tests in release mode
cargo test --releaseThe cross-contract integration tests (tests/cross_contract.rs) exercise a complete delegated purchase: grant permission, fund escrow, spend within limits, and release.
# Build all contracts for the WASM target
cargo build --target wasm32-unknown-unknown --release
# Build a specific contract
cargo build -p delego-escrow --target wasm32-unknown-unknown --releaseBuild artifacts land in target/wasm32-unknown-unknown/release/.
All five contract crates expose the same script set via package.json
(build-wasm, test, lint) and via a root justfile, so
building, testing, and linting any contract is a single command:
# Inside any contract directory
npm run build-wasm # cargo build --target wasm32-unknown-unknown --release
npm test # cargo test
npm run lint # cargo clippy --all-targets -- -D warnings
# Or from the repo root with just installed
just build-wasm
just test
just lintsoroban network add --global futurenet \
--rpc-url https://rpc-futurenet.stellar.org \
--network-passphrase "Test SDF Future Network ; September 2022"
soroban contract deploy \
--wasm target/wasm32-unknown-unknown/release/delego_escrow.wasm \
--source <DEPLOYER_ACCOUNT> \
--network futurenet
export ESCROW_CONTRACT_ID=<CONTRACT_ID>soroban network add --global public \
--rpc-url https://soroban-rpc.stellar.org \
--network-passphrase "Public Global Stellar Network ; September 2015"
soroban contract deploy \
--wasm target/wasm32-unknown-unknown/release/delego_escrow.wasm \
--source <DEPLOYER_ACCOUNT> \
--network public- Contract tests pass
- Code reviewed by team
- Security audit completed
- Gas optimization performed
- Documentation updated
- Deployment script tested
- Rollback plan prepared
- Access Control: Implement proper access control
- Input Validation: Validate all inputs
- Reentrancy Protection: Protect against reentrancy attacks
- Integer Overflow: Use checked arithmetic (
overflow-checks = truein release profile) - Randomness: Use secure randomness sources
- Secret Management: Never store secrets on-chain
All contracts must undergo:
- Internal code review
- External security audit
- Penetration testing
- Bug bounty program
- Architecture notes
- Generate API docs with
cargo doc --open
When contributing to smart contracts:
- Follow Rust best practices
- Write comprehensive tests for every public function
- Document all public functions
- Consider gas efficiency
- Security review required
- Update documentation
See CONTRIBUTING.md for general guidelines.
Build Errors
cargo clean
cargo build --target wasm32-unknown-unknown --releaseTest Failures
cargo test -- --nocapture
cargo test test_function_nameDeployment Issues
soroban network inspect
soroban contract inspect --wasm contract.wasmLast Updated: August 2026