Skip to content

SubStream-Protocol/SubStream-Protocol-Contracts

Repository files navigation

SubStream Protocol: Decentralized Creator Economy

Overview

SubStream is a Pay-As-You-Go subscription protocol. Instead of monthly credit card charges, fans stream tokens to creators second-by-second. If the fan dislikes the content, they can cancel instantly and get their remaining balance back.

Key Logic

  • subscribe: User deposits a buffer (e.g., 50 XLM) and sets a rate.
  • 7-day free trial: Streams accrue zero charges for the first 7 days, then automatically charge at the configured paid rate.
  • collect: Creator triggers the withdrawal of accumulated seconds.
  • cancel: Subscriber stops the stream and refunds unspent tokens (after minimum duration).
  • pause_channel / unpause_channel: Creator can pause their channel to stop charges across all active incoming streams during hiatus.

Sybil Protection

To prevent users from rapidly starting/stopping streams to "scrape" content, the protocol enforces a minimum flow duration of 24 hours. Once a stream is initiated, it cannot be canceled until the minimum duration has elapsed. This protects creators from abuse and ensures meaningful engagement.

  • cancel: Subscriber stops the stream and refunds unspent tokens.
  • subscribe_group: User streams to a group channel with exactly 5 creators and percentage splits that sum to 100.
  • collect_group: Contract automatically splits each collected amount to all 5 creators based on configured percentages.

Network

  • Stellar Testnet

Deployed Contract

  • Network: Stellar Testnet
  • Contract ID: CAOUX2FZ65IDC4F2X7LJJ2SVF23A35CCTZB7KVVN475JCLKTTU4CEY6L

Subscription State Flow

stateDiagram-v2
    [*] --> Trial : subscribe()

    Trial --> Active : trial period ends\n(stream begins)
    Trial --> Expired : cancel() during trial

    Active --> GracePeriod : balance runs low\n(below rate threshold)
    Active --> Expired : cancel()

    GracePeriod --> Active : top_up() refills balance
    GracePeriod --> Expired : balance depleted\nor cancel()

    Expired --> [*]
Loading

Running Tests

To run the contract tests locally:

cargo test

Building

To build the contract for Wasm:

cargo build --target wasm32-unknown-unknown --release

WASM Compression (Recommended for Deployment)

To reduce deployment fees, use the automated WASM compression:

cd contracts/substream_contracts
make build-compressed

Or use the compression script:

./scripts/compress_wasm.sh

The compression system uses wasm-opt to optimize WASM binaries, typically reducing file sizes by 10-30%, which directly lowers deployment costs on Stellar.

See WASM_COMPRESSION.md for detailed documentation.

About

Soroban contracts for creator subscriptions

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors