Soroban smart contracts for automated SLA management and payment processing on the Stellar blockchain
This repository contains the Soroban smart contracts that power NOCIQ's blockchain-based SLA enforcement system. These contracts enable automated penalty/reward calculations and transparent, tamper-proof payment execution based on network outage resolution times.
Parent Project: NOCIQ
Frontend: noc-iq-fe
Backend: noc-iq-be
Calculates penalties and rewards based on Mean Time To Repair (MTTR) and predefined SLA thresholds.
Features:
- Automated penalty calculation for SLA violations
- Reward calculation for early resolution
- Configurable thresholds per severity level
- Admin-controlled configuration updates
- Transparent calculation logic
Manages conditional payment releases with escrow functionality.
Features:
- Lock funds until conditions are met
- Multi-party approval mechanisms
- Automatic release on condition fulfillment
- Refund capability for failed conditions
Handles cost-sharing between multiple network operators for shared infrastructure incidents.
Features:
- Automatic cost splitting based on usage
- Proportional allocation algorithms
- Batch settlement processing
- Audit trail for all distributions
- Language: Rust
- Framework: Soroban SDK
- Blockchain: Stellar Network
- Testing: Rust
cargo test - Deployment: Soroban CLI
# Clone the repository
git clone https://github.com/OpSoll/noc-iq-contracts.git
cd noc-iq-contracts
# Install Soroban CLI
cargo install --locked soroban-cli
# Build all contracts
make build
# Run tests
make testnoc-iq-contracts/
βββ sla_calculator/ # SLA calculation contract
β βββ src/
β β βββ lib.rs # Main contract logic
β β βββ types.rs # Data structures
β β βββ tests.rs # Unit tests
β βββ Cargo.toml
βββ payment_escrow/ # Payment escrow contract
β βββ src/
β β βββ lib.rs
β β βββ tests.rs
β βββ Cargo.toml
βββ multi_party_settlement/ # Multi-party settlement
β βββ src/
β β βββ lib.rs
β β βββ tests.rs
β βββ Cargo.toml
βββ scripts/ # Deployment scripts
β βββ deploy.sh
β βββ initialize.sh
β βββ test-invoke.sh
βββ docs/ # Documentation
β βββ SLA_CALCULATOR.md
β βββ PAYMENT_ESCROW.md
β βββ DEPLOYMENT.md
βββ Makefile # Build automation
βββ Cargo.toml # Workspace configuration
βββ README.md
make buildThis compiles all contracts to WebAssembly (WASM) and places them in target/wasm32-unknown-unknown/release/.
cd sla_calculator
cargo build --target wasm32-unknown-unknown --releasemake optimizeUses wasm-opt to reduce contract size and gas costs.
make testcd sla_calculator
cargo testcargo test -- --nocapturecargo tarpaulin --out Html# Deploy SLA Calculator
soroban contract deploy \
--wasm target/wasm32-unknown-unknown/release/sla_calculator.wasm \
--source-account testnet-deployer \
--network testnet
# Save the contract ID
export SLA_CONTRACT_ID=CCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCsoroban contract invoke \
--id $SLA_CONTRACT_ID \
--source-account testnet-deployer \
--network testnet \
-- initialize \
--admin GXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX \
--usdc_token CBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB \
--pool_address GAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA# Deploy all contracts to testnet
./scripts/deploy.sh testnet
# Initialize contracts
./scripts/initialize.sh testnet
# Test contract invocation
./scripts/test-invoke.sh testnetinitialize(admin: Address, usdc_token: Address, pool_address: Address)
- Initializes the contract with admin and token addresses
- Can only be called once
- Sets default SLA configurations
calculate_sla(outage_id: Symbol, severity: Severity, mttr_minutes: u32) -> SLAResult
- Calculates penalty or reward based on MTTR
- Returns status, amount, and payment type
- Pure function (doesn't modify state)
execute_payment(sla_result: SLAResult, operator_address: Address, noc_team_address: Address) -> PaymentRecord
- Executes payment based on SLA result
- Requires authorization from payer
- Stores payment record on-chain
get_config(severity: Severity) -> SLAConfig
- Retrieves SLA configuration for severity level
- Public read-only function
update_config(severity: Severity, threshold_minutes: u32, penalty_per_minute: i128, reward_base: i128)
- Updates SLA configuration (admin only)
- Requires admin authorization
pub enum Severity {
Critical = 1,
High = 2,
Medium = 3,
Low = 4,
}
pub struct SLAConfig {
pub threshold_minutes: u32,
pub penalty_per_minute: i128,
pub reward_base: i128,
}
pub struct SLAResult {
pub outage_id: Symbol,
pub status: Symbol, // "met" or "violated"
pub mttr_minutes: u32,
pub threshold_minutes: u32,
pub amount: i128, // Negative for penalty, positive for reward
pub payment_type: Symbol, // "reward" or "penalty"
pub rating: Symbol, // "exceptional", "excellent", "good", "poor"
}// Calculate SLA for a critical outage resolved in 25 minutes
let result = client.calculate_sla(
&Symbol::short("OUT001"),
&Severity::Critical,
&25 // MTTR: 25 minutes (threshold is 15 minutes)
);
// Result:
// status: "violated"
// amount: -1000_0000000 (negative = penalty of $1,000)
// payment_type: "penalty"create_escrow(amount: i128, conditions: Vec<Condition>) -> EscrowId
- Creates new escrow with specified conditions
- Locks funds until conditions are met
- Returns unique escrow ID
release_escrow(escrow_id: EscrowId)
- Releases funds when all conditions are satisfied
- Transfers to designated recipient
- Can only be called by authorized parties
refund_escrow(escrow_id: EscrowId)
- Refunds locked funds to sender
- Only possible if conditions failed or timeout reached
- Requires appropriate authorization
create_settlement(incident_id: Symbol, total_cost: i128, parties: Vec<Party>)
- Creates cost-sharing agreement
- Defines proportions for each party
- Validates that proportions sum to 100%
execute_settlement(incident_id: Symbol)
- Executes payments to all parties
- Uses predefined proportions
- Records all transactions
- All contracts should be audited before mainnet deployment
- We recommend using Halborn or Trail of Bits
- Test thoroughly on testnet with real scenarios
- Never commit private keys to repository
- Use hardware wallets for mainnet deployment
- Implement multi-sig for admin functions in production
- Admin functions restricted to designated addresses
- Payment functions require proper authorization
- All sensitive operations emit events for monitoring
- Test each function in isolation
- Cover all edge cases
- Test error conditions
- Test contract interactions
- Verify state changes
- Test against actual Stellar testnet
- Simulate real-world outage scenarios
- Test with various MTTR values
- Verify payment calculations
#[test]
fn test_sla_violation() {
let env = Env::default();
let contract_id = env.register_contract(None, SLAContract);
let client = SLAContractClient::new(&env, &contract_id);
let admin = Address::generate(&env);
let usdc = Address::generate(&env);
let pool = Address::generate(&env);
client.initialize(&admin, &usdc, &pool);
// Critical outage resolved in 25 minutes (threshold: 15)
let result = client.calculate_sla(
&Symbol::short("OUT001"),
&Severity::Critical,
&25
);
assert_eq!(result.status, Symbol::short("violated"));
assert_eq!(result.amount, -1000_0000000); // $1,000 penalty
}- Minimize storage operations
- Use efficient data structures
- Batch operations when possible
- Cache frequently accessed data
| Operation | Gas Cost (XLM) |
|---|---|
| Deploy contract | ~0.1 - 0.5 |
| Initialize | ~0.01 |
| Calculate SLA | ~0.001 |
| Execute payment | ~0.005 |
| Update config | ~0.002 |
Note: Actual costs vary based on network congestion.
We welcome contributions! Please see our Contributing Guide.
- Fork the repository
- Create feature branch:
git checkout -b feature/new-contract - Write tests first
- Implement functionality
- Run tests:
cargo test - Run clippy:
cargo clippy -- -D warnings - Format code:
cargo fmt - Submit pull request
- Follow Rust best practices
- Write comprehensive tests (aim for 100% coverage)
- Document all public functions
- Use descriptive error messages
- Consider gas costs in design
- Emit events for important state changes
This project is licensed under the MIT License - see the LICENSE file for details.
- Built with Soroban SDK
- Powered by Stellar Network
- Inspired by DeFi protocols and traditional SLA contracts
- Issues: GitHub Issues
- Discussions: GitHub Discussions
- Stellar Discord: Join
- Soroban Discord: Join
- SLA Calculator contract
- Comprehensive test suite
- Documentation
- Payment Escrow contract
- Multi-Party Settlement contract
- Security audit
- Mainnet deployment
- Governance features
- Upgrade mechanisms
- Advanced analytics contracts
Made with β€οΈ by the OpSoll Team | Powered by Stellar β
Building on Stellar? Join us in the Stellar Wave Program!