Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,6 @@ target
coverage
*.log
*.sh

# Soroban test runner — auto-generated, never commit
**/test_snapshots/
28 changes: 28 additions & 0 deletions contracts/stream_contract/src/errors.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
use soroban_sdk::contracterror;

/// Exhaustive error surface for `StreamContract`.
///
/// Each variant maps to a unique u32 so that clients and indexers can
/// distinguish failures without parsing error messages.
#[contracterror]
#[derive(Copy, Clone, Debug, Eq, PartialEq)]
pub enum StreamError {
/// Amount is zero, negative, or otherwise out of range.
InvalidAmount = 1,
/// No stream exists for the supplied ID.
StreamNotFound = 2,
/// Caller is not authorised to perform this action on the stream.
Unauthorized = 3,
/// Operation requires an active stream, but the stream is inactive.
StreamInactive = 4,
/// `initialize` has already been called; cannot re-initialize.
AlreadyInitialized = 5,
/// Caller is not the protocol admin.
NotAdmin = 6,
/// Supplied fee rate exceeds the platform maximum (1 000 bps).
InvalidFeeRate = 7,
/// Protocol config has not been initialized yet.
NotInitialized = 8,
/// Duration supplied to `create_stream` is zero.
InvalidDuration = 9,
}
71 changes: 71 additions & 0 deletions contracts/stream_contract/src/events.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
use soroban_sdk::{contracttype, Address};

/// Emitted when a new stream is created.
///
/// Topic: `("stream_created", stream_id)`
#[contracttype]
#[derive(Clone, Debug, Eq, PartialEq)]
pub struct StreamCreatedEvent {
pub stream_id: u64,
pub sender: Address,
pub recipient: Address,
/// Net rate per second after protocol fee deduction.
pub rate_per_second: i128,
pub token_address: Address,
/// Net deposited amount after protocol fee deduction.
pub deposited_amount: i128,
pub start_time: u64,
}

/// Emitted when a sender tops up an active stream.
///
/// Topic: `("stream_topped_up", stream_id)`
#[contracttype]
#[derive(Clone, Debug, Eq, PartialEq)]
pub struct StreamToppedUpEvent {
pub stream_id: u64,
pub sender: Address,
/// Net top-up amount credited to the stream (after protocol fee).
pub amount: i128,
/// Total deposited amount on the stream after this top-up.
pub new_deposited_amount: i128,
}

/// Emitted when the recipient withdraws accrued tokens.
///
/// Topic: `("tokens_withdrawn", stream_id)`
#[contracttype]
#[derive(Clone, Debug, Eq, PartialEq)]
pub struct TokensWithdrawnEvent {
pub stream_id: u64,
pub recipient: Address,
pub amount: i128,
pub timestamp: u64,
}

/// Emitted when a sender cancels an active stream.
///
/// Topic: `("stream_cancelled", stream_id)`
#[contracttype]
#[derive(Clone, Debug, Eq, PartialEq)]
pub struct StreamCancelledEvent {
pub stream_id: u64,
pub sender: Address,
pub recipient: Address,
/// Total amount withdrawn by the recipient up to cancellation.
pub amount_withdrawn: i128,
/// Unspent amount (deposited - withdrawn) returned to sender.
pub refunded_amount: i128,
}

/// Emitted when a protocol fee is collected during create or top-up.
///
/// Topic: `("fee_collected", stream_id)`
#[contracttype]
#[derive(Clone, Debug, Eq, PartialEq)]
pub struct FeeCollectedEvent {
pub stream_id: u64,
pub treasury: Address,
pub fee_amount: i128,
pub token: Address,
}
Loading
Loading