BuildapireferencegeneratedIStreamingPaymentAdapter

IStreamingPaymentAdapter

Source: https://github.com/tangle-network/tnt-core/blob/main/src/interfaces/IStreamingPaymentAdapter.sol

IStreamingPaymentAdapter

Common interface for streaming payment adapters (Superfluid, Sablier, etc.)

Adapters implement this interface to provide streaming payment capabilities to Tangle services without tight coupling to specific protocols.

Functions

createStream

function createStream(uint64 serviceId, address token, uint256 totalAmount, uint64 durationSeconds, uint64 cliffSeconds) external payable returns (uint256 streamId)

Create a streaming payment for a service

Parameters
NameTypeDescription
serviceIduint64The Tangle service ID
tokenaddressThe ERC-20 token to stream (address(0) for native)
totalAmountuint256Total amount to stream
durationSecondsuint64Stream duration in seconds
cliffSecondsuint64Optional cliff period (0 for no cliff)
Return Values
NameTypeDescription
streamIduint256The created stream ID

updateStreamRate

function updateStreamRate(uint256 streamId, uint256 newRatePerSecond) external

Update the rate of an existing stream

Parameters
NameTypeDescription
streamIduint256The stream ID to update
newRatePerSeconduint256New streaming rate

cancelStream

function cancelStream(uint256 streamId) external returns (uint256 refundedAmount)

Cancel a stream and refund remaining balance

Parameters
NameTypeDescription
streamIduint256The stream ID to cancel
Return Values
NameTypeDescription
refundedAmountuint256Amount refunded to the payer

withdrawFromStream

function withdrawFromStream(uint256 streamId) external returns (uint256 withdrawnAmount)

Withdraw available funds from a stream

Parameters
NameTypeDescription
streamIduint256The stream ID
Return Values
NameTypeDescription
withdrawnAmountuint256Amount withdrawn

settleAndDistribute

function settleAndDistribute(uint256 streamId) external

Settle a stream’s accumulated funds and distribute to operators

This triggers distribution through Tangle’s payment system

Parameters
NameTypeDescription
streamIduint256The stream ID to settle

getWithdrawableAmount

function getWithdrawableAmount(uint256 streamId) external view returns (uint256 amount)

Get the current withdrawable amount for a stream

Parameters
NameTypeDescription
streamIduint256The stream ID
Return Values
NameTypeDescription
amountuint256Amount available to withdraw

getStreamRate

function getStreamRate(uint256 streamId) external view returns (uint256 ratePerSecond)

Get the current streaming rate

Parameters
NameTypeDescription
streamIduint256The stream ID
Return Values
NameTypeDescription
ratePerSeconduint256Tokens per second being streamed

getStreamInfo

function getStreamInfo(uint256 streamId) external view returns (uint64 serviceId, address payer, address token, uint256 totalAmount, uint256 withdrawnAmount, uint256 startTime, uint256 endTime, uint256 cliffTime, bool active)

Get full stream information

Parameters
NameTypeDescription
streamIduint256The stream ID
Return Values
NameTypeDescription
serviceIduint64Associated Tangle service
payeraddressAddress funding the stream
tokenaddressToken being streamed
totalAmountuint256Total stream amount
withdrawnAmountuint256Amount already withdrawn
startTimeuint256Stream start timestamp
endTimeuint256Stream end timestamp
cliffTimeuint256Cliff timestamp (0 if no cliff)
activeboolWhether stream is active

getStreamServiceId

function getStreamServiceId(uint256 streamId) external view returns (uint64 serviceId)

Get the service ID associated with a stream

Parameters
NameTypeDescription
streamIduint256The stream ID
Return Values
NameTypeDescription
serviceIduint64The Tangle service ID

getServiceStreams

function getServiceStreams(uint64 serviceId) external view returns (uint256[] streamIds)

Get all active streams for a service

Parameters
NameTypeDescription
serviceIduint64The Tangle service ID
Return Values
NameTypeDescription
streamIdsuint256[]Array of active stream IDs

getAccruedAmount

function getAccruedAmount(uint256 streamId) external view returns (uint256 accruedAmount)

Calculate real-time accrued amount (not yet settled)

Parameters
NameTypeDescription
streamIduint256The stream ID
Return Values
NameTypeDescription
accruedAmountuint256Amount accrued since last settlement

protocolName

function protocolName() external view returns (string name)

Get the name of the underlying protocol

Return Values
NameTypeDescription
namestringProtocol name (e.g., “Superfluid”, “Sablier”)

isTokenSupported

function isTokenSupported(address token) external view returns (bool supported)

Check if a token is supported for streaming

Parameters
NameTypeDescription
tokenaddressThe token address
Return Values
NameTypeDescription
supportedboolTrue if token can be streamed

Events

StreamCreated

event StreamCreated(uint64 serviceId, uint256 streamId, address payer, address token, uint256 ratePerSecond, uint256 totalAmount)

Emitted when a stream is created for a service

StreamUpdated

event StreamUpdated(uint64 serviceId, uint256 streamId, uint256 newRatePerSecond)

Emitted when a stream is updated

StreamCancelled

event StreamCancelled(uint64 serviceId, uint256 streamId, uint256 refundedAmount)

Emitted when a stream is cancelled

StreamWithdrawn

event StreamWithdrawn(uint64 serviceId, uint256 streamId, uint256 amount, address recipient)

Emitted when funds are withdrawn from a stream

StreamSettled

event StreamSettled(uint64 serviceId, uint256 streamId, uint256 amount)

Emitted when a stream is settled and distributed