Settlement Engine
On-chain settlement with escrow, micropayment channels, and batch processing
The settlement engine handles all financial finality on the Tenzro Ledger. Immediate settlements for one-off transactions, escrow with proof-based release for complex agreements, and micropayment channels for high-frequency per-token billing.
Key Features
Immediate Settlement
Direct on-chain transfer with receipt generation. Verify sender balance, deduct, credit, collect fees
Escrow Settlements
Lock funds with release conditions: provider signature, ZK proof submission, or time elapsed
Micropayment Channels
Off-chain state channels for per-token billing. Open with escrowed TNZO, stream updates, settle on close
Batch Processing
Atomic multi-settlement operations. All-or-nothing: if any settlement fails, all roll back
Fee Collection
Network fee: 0.5% on all settlements. Fees routed to treasury for distribution to validators and stakers
Proof Verification
ZK and TEE proof verification during settlement. Verify computation was correct before releasing funds
Settlement Architecture
┌─────────────────────────────────────────────────────────┐
│ Settlement Engine │
│ │
│ ┌──────────────┐ ┌──────────────┐ ┌──────────────┐ │
│ │ Immediate │ │ Escrow │ │ Micropayment │ │
│ │ Settlement │ │ Settlement │ │ Channels │ │
│ └──────┬───────┘ └──────┬───────┘ └──────┬───────┘ │
│ │ │ │ │
│ └─────────┬───────┴─────────┬───────┘ │
│ │ │ │
│ ┌──────▼──────┐ ┌──────▼──────┐ │
│ │ Batch │ │ Fee │ │
│ │ Processor │ │ Collector │ │
│ └──────┬──────┘ └──────┬──────┘ │
│ │ │ │
└───────────────────┼─────────────────┼─────────────────┘
│ │
┌──────▼──────┐ ┌──────▼──────┐
│ Storage │ │ Treasury │
│ (RocksDB) │ │ (TNZO) │
└─────────────┘ └─────────────┘Code Examples
Micropayment Channel
use tenzro_settlement::MicropaymentChannelManager;
let manager = MicropaymentChannelManager::new(storage);
// Open channel
let channel = manager.open_channel(
sender,
receiver,
Amount::tnzo(10.0),
Duration::from_secs(3600),
)?;
// Update state (off-chain)
manager.update_state(&channel.id, new_balance, nonce, signature)?;
// Close and settle on-chain
let receipt = manager.close_channel(&channel.id)?;Escrow Settlement
use tenzro_settlement::{SettlementEngine, EscrowCondition};
let engine = SettlementEngine::new(config);
// Create escrow
let escrow = engine.create_escrow(
payer,
payee,
Amount::tnzo(100.0),
vec![
EscrowCondition::ProofSubmission,
EscrowCondition::TimeElapse(Duration::from_secs(86400)),
],
)?;
// Release with proof
engine.release_escrow(&escrow.id, &zk_proof)?;Batch Settlement
use tenzro_settlement::{SettlementEngine, SettlementRequest};
let engine = SettlementEngine::new(config);
// Create multiple settlement requests
let requests = vec![
SettlementRequest::immediate(payer1, payee1, Amount::tnzo(50.0)),
SettlementRequest::immediate(payer2, payee2, Amount::tnzo(75.0)),
SettlementRequest::immediate(payer3, payee3, Amount::tnzo(100.0)),
];
// Process atomically - all succeed or all fail
let receipts = engine.process_batch(requests)?;
// All settlements completed successfully
for receipt in receipts {
println!("Settlement {} completed", receipt.id);
}Fee Calculation
use tenzro_settlement::{SettlementEngine, Amount};
let engine = SettlementEngine::new(config);
// Network fee: 0.5% of settlement amount
let amount = Amount::tnzo(1000.0);
let fee = engine.calculate_fee(&amount);
println!("Settlement amount: {} TNZO", amount);
println!("Network fee: {} TNZO", fee);
println!("Recipient receives: {} TNZO", amount - fee);
// Output:
// Settlement amount: 1000.000000000000000000 TNZO
// Network fee: 5.000000000000000000 TNZO
// Recipient receives: 995.000000000000000000 TNZOSettlement Modes
Immediate Settlement
Direct transfer with instant finality. Ideal for one-time payments, invoice settlements, and simple transfers.
- Balance verification before execution
- Atomic debit and credit operations
- Network fee deduction (0.5%)
- Receipt generation with transaction hash
Escrow Settlement
Conditional release based on proof submission, signatures, or time. Perfect for AI inference payments, staking rewards, and multi-party agreements.
- Funds locked in smart contract escrow
- Multiple release conditions supported
- ZK proof verification before release
- TEE attestation verification
- Time-based automatic release
Micropayment Channels
Off-chain state channels for high-frequency, low-value payments. Essential for per-token AI billing and streaming payments.
- Open channel with initial TNZO deposit
- Off-chain state updates with signatures
- Unlimited updates during channel lifetime
- On-chain settlement only on close
- Dispute resolution for conflicting states
Build with Settlement Engine
Integrate on-chain settlement into your AI applications with escrow protection and micropayment channels.