Skip to main content
The Stream Contract is the heart of Aven. It is the only contract that holds funds. Every employer deposit, every work-session verification, every approval decision, and every payment release passes through it. The contract independently enforces the payment formula — neither the dashboard nor the verifier service can bypass the on-chain checks.

Purpose

When an employer creates a stream, the contract immediately transfers the full deposit into its own escrow. From that point, funds can only leave the contract in two ways:
  • Payment to the recipient — after a verified withdrawal is approved (or auto-released after the deadline).
  • Refund to the sender — when a stream is cancelled and no funds are reserved for outstanding withdrawals.
The contract recomputes every payment amount itself using rate_per_second × active_duration_seconds. Workers never submit their own payment figure; the contract enforces it.

Data Structures

The primary record stored for every stream. Read it with get_stream(stream_id).
Created by verify_work (or request_withdrawal in legacy mode). Each record represents one work session payment.
The lifecycle of a single withdrawal request.
The lifecycle state of a stream.

Public Entrypoints

create_stream

Creates a new payment stream and transfers the full deposit into escrow.
Address
required
The employer’s Stellar address. Must authorize this transaction. Must differ from recipient.
Address
required
The worker’s Stellar address who will receive payments.
i128
required
Payment rate in Stellar 7-decimal fixed-point per second. For example, 1_0000000 = 1 XLM/s. Must be greater than 0.
Address
required
Stellar asset contract address. Use the XLM SAC address or the testnet USDC contract.
i128
required
Total escrow amount in 7-decimal fixed-point. Must be at least rate_per_second × 5 × duration_ledgers.
u32
required
Scheduled stream length in ledgers (approximately 5 seconds per ledger). Must be greater than 0.
u32
Legacy parameter. Pass 0 — the contract ignores this value in work-session mode.
u32
Legacy parameter. Pass 0 — the contract ignores this value in work-session mode.
u32
required
Number of ledgers the employer has to approve or dispute after verify_work is called. After this deadline the worker can call withdraw_approved without explicit employer action. Must be greater than 0.
Category
required
One of Freelance, Salary, Bounty, Grant, AgentTask, or Subscription. Affects reputation scoring weights.
String
required
Human-readable stream name. Maximum 80 UTF-8 bytes.

verify_work

Called exclusively by the Aven verifier service. Reserves funds for one completed work session and creates a WithdrawalRecord in Pending status.
You do not call verify_work directly. It is signed by the Aven verifier service after the CLI submits a work-session report. The contract independently recalculates rate_per_second × active_duration_seconds and rejects the call if the reported amount does not match.

request_withdrawal

Legacy direct-request path. Disabled whenever the verifier is configured.
If a verifier is set on the stream contract, calling request_withdrawal returns Error 32: VerificationRequired. All active Aven deployments use the verifier. This entrypoint exists for compatibility with older integrations.

approve_withdrawal

Called by the employer to approve a Pending withdrawal.
The sender must be the stream’s original employer address and must authorize the transaction. Moves the WithdrawalRecord status from Pending → Approved.

dispute_withdrawal

Called by the employer to dispute a Pending withdrawal.
Moves the status to Disputed and releases the reserved amount back to unreserved escrow so future sessions can use it. Cannot be called on an already-approved or withdrawn record.

withdraw_approved

Called by the recipient to transfer an approved (or auto-released) payment.
Returns the amount transferred. Also triggers mint_attestation on the Attestation Contract. If this payment completes the stream (total_withdrawn == total_deposited), a second StreamCompletion attestation is minted for reputation scoring. Auto-release applies when the current ledger is at or past deadline_ledger and the record is still in Pending status — the employer did not act within the timeout window.

Stream Lifecycle Management

All three require the caller to be the stream’s sender and to authorize the transaction.
  • pause_stream — moves an Active stream to Paused. Records the current ledger so paused time can be tracked. New work sessions cannot be verified on a paused stream.
  • resume_stream — moves a Paused stream back to Active. Accumulates the paused duration.
  • cancel_stream — cancels an Active or Paused stream. Returns all unreserved escrow to the sender. Fails with Error 36: OutstandingWithdrawals if any funds are currently reserved for pending withdrawals — resolve those first.

Read-Only Queries


Contract Events

The Stream Contract emits the following events. You can subscribe to them via the Stellar Horizon events API or the stellar-sdk event stream.

Error Codes

The following errors are returned as Soroban contract errors. The numeric code is embedded in the transaction result.