Skip to content

Marketplace

The SmartPoints marketplace (ADR-088 Layer 5) manages service discovery, retention, metering, and lifecycle for service engagements between Scopes.

Engagement Lifecycle

Every marketplace engagement follows six phases:

text
Discovery --> Negotiation --> Retention --> Engagement --> Completion --> Dissolution
PhaseDescription
DiscoveryConsumer finds services via DHT and reputation
NegotiationParties exchange terms
RetentionQuarx escrowed, service begins
EngagementService operates, usage metered
CompletionArtifacts delivered, escrow released
DissolutionSmartPoint pair destroyed, keys zeroed

Discovery

The spt-discovery crate provides a Kademlia-style DHT for distributed service discovery. Providers publish ServiceRecord entries; consumers search by capability, type, and minimum reputation.

Publishing a Service

rust,ignore
use spt_discovery::{ServiceRecord, ServiceType, ServiceRegistry};

let registry = ServiceRegistry::new();

let mut record = ServiceRecord::new(
    "did:spt:alice".into(),
    ServiceType::CodingAgent("rust-coder".into()),
    vec!["rust".into(), "code-review".into()],
);
record.reputation = 0.9;
registry.register(record)?;

Searching for Services

rust,ignore
use spt_discovery::DiscoveryQuery;

let query = DiscoveryQuery::new()
    .with_capabilities(vec!["rust".into()])
    .with_min_reputation(0.5);

let results = registry.search(&query);
for scored in &results.matches {
    println!("{}: score={}", scored.record.provider_did, scored.score);
}

Reputation

The ReputationTracker computes provider reputation from engagement history. Each completed engagement produces an Engagement record with a satisfaction score. The reputation is a weighted rolling average.

rust,ignore
use spt_discovery::{ReputationTracker, Engagement};

let tracker = ReputationTracker::new();
tracker.record_engagement(Engagement {
    provider_did: "did:spt:alice".into(),
    consumer_did: "did:spt:bob".into(),
    satisfaction: 0.95,
    // ...
})?;

let score = tracker.get_reputation("did:spt:alice")?;

Retention Lifecycle

Once a service is selected, the spt-marketplace crate manages retention through escrow and contract management.

Retention States

text
Proposed --> Active --> Completing --> Completed --> Dissolved
                |
                +--> Disputed
                |
                +--> Breached
StateDescription
ProposedTerms offered, not yet accepted
ActiveEscrow funded, service operating
CompletingFinal delivery in progress
CompletedArtifacts delivered, escrow released
DissolvedSmartPoint pair destroyed
DisputedDisagreement, mediation required
BreachedTerms violated, escrow may be forfeited

Creating a Retention

rust,ignore
use spt_marketplace::{RetentionManager, RetentionTerms};

let manager = RetentionManager::new();

let terms = RetentionTerms {
    provider_did: "did:spt:alice".into(),
    consumer_did: "did:spt:bob".into(),
    service_type: "coding-agent".into(),
    quarx_budget: 1000,
    ttl_seconds: 86400,
    capabilities: vec!["rust".into(), "testing".into()],
};

let contract = manager.propose(terms)?;
let active = manager.activate(&contract.id)?;

Quarx Metering

Quarx is a metering unit, not a currency. There is no trading, no speculation, and no exchange. Quarx tracks resource consumption within retention contracts.

Quarx Ledger

rust,ignore
use spt_marketplace::{QuarxLedger, QuarxTransaction};

let ledger = QuarxLedger::new();

// Fund escrow
ledger.credit("did:spt:bob", 1000)?;

// Meter usage
let meter = QuarxMeter::new(&contract);
meter.record_operation(MeteredOperation {
    operation_type: "inference".into(),
    quarx_cost: 5,
    // ...
})?;

Usage Tracking

The QuarxMeter records each operation with its quarx cost. The UsageSummary provides aggregated metrics for a retention contract.

Circuit Breakers

The CircuitBreaker protects consumers from runaway costs. It monitors spend rate and can suspend a retention if the burn rate exceeds thresholds.

rust,ignore
use spt_marketplace::{CircuitBreaker, SpendTracker};

let tracker = SpendTracker::new(1000); // budget: 1000 quarx
let breaker = CircuitBreaker::new(tracker);

// Check before each operation
if breaker.is_open() {
    // Budget exceeded, circuit is open
    return Err("Budget exhausted");
}

The SpendTracker provides real-time budget monitoring. When spend exceeds the configured threshold (e.g., 90% of budget), the circuit opens and blocks further operations until the contract is renegotiated or the budget is increased.

Dissolution

When a retention completes or is terminated, dissolution ensures clean teardown:

  1. Final usage summary is computed
  2. Escrow is settled (released or forfeited)
  3. Memory sharing policy is enforced (shared artifacts, if any, are transferred)
  4. SmartPoint pair is destroyed
  5. Keys are zeroed via zeroize
  6. A DissolutionReceipt is issued

Key Types

TypeCrateDescription
ServiceRecordspt-discoveryService listing with capabilities
ServiceTypespt-discoveryEnum of service categories
ServiceRegistryspt-discoveryIn-memory registry with search
DiscoveryQueryspt-discoveryQuery builder for service search
DhtNodespt-discoveryKademlia-style DHT node
ReputationTrackerspt-discoveryEngagement-based reputation
RetentionManagerspt-marketplaceRetention lifecycle
RetentionContractspt-marketplaceActive service contract
RetentionTermsspt-marketplaceProposed engagement terms
QuarxLedgerspt-marketplaceQuarx balance tracking
QuarxMeterspt-marketplacePer-operation metering
EscrowManagerspt-marketplaceEscrow creation and settlement
CircuitBreakerspt-marketplaceBudget protection
SpendTrackerspt-marketplaceReal-time spend monitoring
NegotiationProtocolspt-marketplaceTerms exchange protocol
DissolutionReceiptspt-marketplaceTeardown confirmation

Released under the MIT License.