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.

ContractPurpose
CapacityRegistryTask type + sink registry, commit-reveal capacity signals, EWMA smoothing
StakeManagerStake/unstake/slash, concave capacity cap stake/unit\sqrt{\text{stake}/\text{unit}}
BackpressurePoolSuperfluid GDA pool with capacity-weighted unit rebalancing
EscrowBufferOverflow buffer when all sinks saturated, FIFO drain
PipelineMulti-stage pipeline composition with upstream congestion propagation
PricingCurveEIP-1559-style dynamic fees based on queue length
CompletionTrackerStatistical capacity verification with auto-slash
OffchainAggregatorBatched EIP-712 attestation submission (83.5% gas savings)

Demurrage (2 contracts)

Time-decaying tokens that incentivize circulation over hoarding, layered with velocity tracking.

ContractPurpose
DemurrageTokenERC-20 Super Token with configurable decay rate per epoch
VelocityMetricsEpoch-based monetary velocity and turnover rate tracking

Nostr Relays (2 contracts)

NIP-compliant relay capacity signaling and economic sustainability for relay operators.

ContractPurpose
RelayCapacityRegistryRelay registration with EIP-712 signed capacity attestations, EWMA smoothing
RelayPaymentPoolAnti-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.

ContractPurpose
LightningCapacityOracleEWMA-smoothed Lightning node capacity from signed attestation batches
LightningRoutingPoolBPE pool weighting nodes by capacity/congestion score
CrossProtocolRouterUnified routing across Superfluid, Lightning, and on-chain settlement

Platform (2 contracts)

The composition layer: universal adapter and cross-domain reputation.

ContractPurpose
UniversalCapacityAdapterDomain adapter registry, normalizes capacity 0–10000, routes to core BPE
ReputationLedgerCross-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:

Source

Contract source code is on GitHub.


See also