Skip to content

Create PaymentStream type for usage-based billing #279

@rz1989s

Description

@rz1989s

Context

Part of Phase 10.4: AI Agent Infrastructure (Roadmap)

AI agents need continuous payment streams for usage-based billing.

Description

Create a PaymentStream type for representing continuous, metered payments:

  • Real-time balance updates
  • Rate-based streaming
  • Pause/resume capability
  • Automatic settlement triggers

Example

#[solana]
#[account]
struct AIServiceSubscription {
    subscriber: PublicKey,
    provider: PublicKey,
    stream: PaymentStream,
    total_requests: u64,
}

Type Definition

struct PaymentStream {
    /// Lamports per second (or per unit)
    rate: u64,
    /// Stream start timestamp
    started_at: i64,
    /// Last settlement timestamp
    last_settled_at: i64,
    /// Total settled amount
    total_settled: u64,
    /// Deposited balance
    deposit: u64,
    /// Stream status
    status: StreamStatus,
}

enum StreamStatus {
    Active,
    Paused,
    Depleted,
    Cancelled,
}

Generated Helpers

Rust:

impl PaymentStream {
    pub fn accrued(&self) -> u64;
    pub fn remaining_time(&self) -> i64;
    pub fn settle(&mut self) -> u64;
    pub fn pause(&mut self);
    pub fn resume(&mut self);
}

TypeScript:

class PaymentStream {
    accrued(): bigint;
    remainingTime(): number;
    estimateEndTime(): Date;
    isActive(): boolean;
}

Acceptance Criteria

  • PaymentStream recognized as built-in type
  • StreamStatus enum generated
  • Generates Rust struct with stream methods
  • Generates TypeScript class with real-time helpers
  • Time-based calculations using Solana Clock
  • Unit tests for stream arithmetic
  • Documentation with streaming payment patterns

Metadata

Metadata

Assignees

No one assigned

    Labels

    ai-agentsAI agent infrastructure featuresphase-10.4Phase 10.4: AI Agent Infrastructuretype:featureNew feature or functionality

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions