Smart Contracts
Backproto is implemented as 22 Solidity smart contracts deployed on Base Sepolia (L2). The core contracts handle capacity-weighted payment routing for AI agents. Additional research modules cover demurrage, Nostr relays, Lightning routing, and cross-domain composition.
Architecture
┌──────────────────────────────┐
│ Platform Layer │
│ UniversalCapacityAdapter │
│ ReputationLedger │
│ CrossProtocolRouter │
└──────┬──────┬──────┬──────────┘
│ │ │
┌───────────────┤ │ ├──────────────────┐
▼ ▼ ▼ ▼ ▼
┌─────────────┐ ┌──────────┐ ┌───────────────┐ ┌────────────────┐
│ Core BPE │ │Demurrage │ │ Nostr Relays │ │ Lightning │
│ 8 contracts│ │2 contracts│ │ 2 contracts │ │ 3 contracts │
└──────┬──────┘ └──────────┘ └───────────────┘ └────────────────┘
│
┌──────┴──────┐
│ V2 Economy │
│ 5 contracts │
└─────────────┘
Core BPE (8 contracts)
The foundational layer: capacity-weighted streaming payment routing for AI agents via Superfluid GDA.
| Contract | Purpose |
|---|---|
CapacityRegistry | Task type + sink registry, commit-reveal capacity signals, EWMA smoothing |
StakeManager | Stake/unstake/slash, concave capacity cap |
BackpressurePool | Superfluid GDA pool with capacity-weighted unit rebalancing |
EscrowBuffer | Overflow buffer when all sinks saturated, FIFO drain |
Pipeline | Multi-stage pipeline composition with upstream congestion propagation |
PricingCurve | EIP-1559-style dynamic fees based on queue length |
CompletionTracker | Statistical capacity verification with auto-slash |
OffchainAggregator | Batched EIP-712 attestation submission (83.5% gas savings) |
Demurrage (2 contracts)
Time-decaying tokens that incentivize circulation over hoarding, layered with velocity tracking.
| Contract | Purpose |
|---|---|
DemurrageToken | ERC-20 Super Token with configurable decay rate per epoch |
VelocityMetrics | Epoch-based monetary velocity and turnover rate tracking |
Nostr Relays (2 contracts)
NIP-compliant relay capacity signaling and economic sustainability for relay operators.
| Contract | Purpose |
|---|---|
RelayCapacityRegistry | Relay registration with EIP-712 signed capacity attestations, EWMA smoothing |
RelayPaymentPool | Anti-spam minimum + BPE-weighted streaming payment distribution |
See also: NIP-XX specification for the full Nostr relay economics protocol.
Lightning (3 contracts)
Channel capacity oracles and cross-protocol routing for Lightning Network integration.
| Contract | Purpose |
|---|---|
LightningCapacityOracle | EWMA-smoothed Lightning node capacity from signed attestation batches |
LightningRoutingPool | BPE pool weighting nodes by capacity/congestion score |
CrossProtocolRouter | Unified routing across Superfluid, Lightning, and on-chain settlement |
Platform (2 contracts)
The composition layer: universal adapter and cross-domain reputation.
| Contract | Purpose |
|---|---|
UniversalCapacityAdapter | Domain adapter registry, normalizes capacity 0–10000, routes to core BPE |
ReputationLedger | Cross-domain portable reputation, 3× negative weight, up to 50% stake discount |
V2 Economy (5 contracts)
Recursive composition, quality-weighted routing, and temporal token mechanics. See EconomyFactory deep dive for template details.
| Contract | Purpose |
|----------|---------||
| EconomyFactory | Deploy a complete BPE economy in one transaction (4 templates: Marketplace, Cooperative, Pipeline, Guild) |
| NestedPool | Hierarchical backpressure pools where sinks can be child economies (max depth 8) |
| QualityOracle | EWMA-smoothed latency, error rate, satisfaction scoring; effective capacity = declared × quality |
| VelocityToken | ERC-20 wrapper with idle-only linear decay, stream-exempt accounts skip decay |
| UrgencyToken | TTL-stamped self-destructing token deposits (min 60s, max 30 days) |
Deployment
Contracts are deployed on Base Sepolia (testnet). Deployment addresses are tracked in contracts/deployments/base-sepolia.json.
Build & Test
cd contracts
forge build
forge test
All 213 tests pass across 21 test suites. The test suite covers:
- Core BPE: capacity registration, EWMA, staking, escrow, pricing, completion tracking
- Demurrage: wrap/unwrap, decay mechanics, epoch advancement, velocity metrics
- Lightning: node registration, EIP-712 batch attestation, EWMA smoothing
- Platform: reputation scoring, cross-domain aggregation, stake discounts
- V2 Economy: factory deployment, nested pool hierarchy, quality scoring, velocity decay, urgency token TTL
- Fork tests against live Superfluid on Base Sepolia
Source
Contract source code is on GitHub.
See also
- TypeScript SDK — type-safe client for all 22 contracts
- EconomyFactory — template deep dive and one-transaction deployment
- Simulation — agent-based validation of BPE theoretical claims
- NIP-XX — Nostr relay economics specification
- Get started — deploy an economy in 5 minutes