A payment stream with support for SPL tokens, prepaid and limited upfront payment, unlimited lifetime, cliffs and cancellations.

Possible states of a stream:

  • Not started
    • Scheduled
    • Cancelled before start
  • Started but not stopped
    • Streaming
    • Paused
  • Stopped
    • Cancelled after start
    • Ended

Hierarchy

  • Stream

Properties

publicKey: PublicKey

Stream public key.

isPrepaid: boolean

If true, the stream is prepaid - all the required amount needs to be deposited on creation. Prepaid streams cannot have unlimited lifetime.

mint: PublicKey

SPL token mint address.

sender: PublicKey

Sender address.

recipient: PublicKey

Recipient address.

createdAt: BN

Time at which the stream was created.

startsAt: BN

Start time of the stream.

INVARIANT: >= createdAt

endsAt: BN

End time of the stream. If the stream is unbounded, this can be 0 to indicate no end time.

INVARIANT: prepaid: >= startsAt INVARIANT: unbounded: == 0 || >= startsAt

initialAmount: BN

Amount available to the recipient once stream starts.

flowInterval: BN

Flow interval is the interval in which flow payments are released.

flowRate: BN

Flow rate is the number of tokens to stream per interval.

isCancelled: boolean

If true, the stream has been cancelled.

isCancelledBeforeStart: boolean

If true, the stream has been cancelled before start.

INVARIANT: !isCancelled => == false

isCancelledBySender: boolean

If true, the stream has been cancelled by the sender.

INVARIANT: !isCancelled || !senderCanCancel => == false

cancelledAt: BN

Time at which the stream was cancelled. If it is > 0, it means the stream has been cancelled and any funds in the escrow account not available to be withdrawn by the recipient have been retrieved.

INVARIANT: cancelledAt > 0 iff isCancelled == true

senderCanCancel: boolean

True if a solvent stream can be cancelled by the sender.

senderCanCancelAt: BN

Time at which the sender is allowed to cancel a solvent stream.

senderCanChangeSender: boolean

True if the sender can change the sender of the stream who will do the upcoming topups.

INVARIANT: prepaid: false

senderCanChangeSenderAt: BN

Time at which the sender is allowed to change the sender.

INVARIANT: prepaid: == 0

isPaused: boolean

If true, the stream is paused.

INVARIANT: prepaid: == false

isPausedBySender: boolean

If true, the stream is paused by sender.

INVARIANT: prepaid: == false INVARIANT: runtime: unbounded: !isPaused || !senderCanPause => == false

senderCanPause: boolean

True if a stream can be paused by the sender.

INVARIANT: prepaid: false

senderCanPauseAt: BN

Time at which the sender is allowed to pause a stream.

INVARIANT: prepaid: == 0

recipientCanResumePauseBySender: boolean

True if a stream can be resumed by the recipient if it was paused by the sender.

INVARIANT: prepaid: false

recipientCanResumePauseBySenderAt: BN

Time at which the recipient is allowed to resume a stream which was paused by the sender.

INVARIANT: prepaid: == 0

anyoneCanWithdrawForRecipient: boolean

True if anyone can withdraw on behalf of the recipient. The amount will go in recipients' account.

anyoneCanWithdrawForRecipientAt: BN

Time at which anyone can withdraw on behalf of the recipient.

lastResumedAt: BN

Time at which the stream was last resumed.

INVARIANT: prepaid: == 0 INVARIANT: unbounded: (== 0 || >= startsAt) && (endsAt == 0 || < endsAt)

accumulatedActiveTime: BN

Total accumulated active (!isPaused) time since startsAt. This does not include (currentTime - lastResumedAt) time if the stream is not paused.

INVARIANT: prepaid: == 0 INVARIANT: unbounded: == 0 || (currentTime > startsAt && == currentTime - startsAt - totalPausedTime)

totalWithdrawnAmount: BN

Total amount withdrawn by the recipient.

INVARIANT: runtime: prepaid: <= amountOwed && <= prepaidAmountNeeded INVARIANT: runtime: unbounded: <= amountOwed && <= totalTopupAmount

lastWithdrawnAt: BN

Last time at which recipient withdrew any amount.

lastWithdrawnAmount: BN

Last amount which recipient withdrew.

totalTopupAmount: BN

Total topup amount added for the stream.

INVARIANT: prepaid: == totalPrepaidAmount INVARIANT: unbounded: >= initialAmount + streamingAmountOwed

lastTopupAt: BN

Last time at which sender topped up the stream.

lastTopupAmount: BN

Last topup amount.

depositNeeded: BN

Total deposit amount needed for the non-prepaid stream. These are needed in case the sender does not topup the stream in time and the amount owed becomes > total topup amount. When that happens, anyone can cancel the stream. The deposit amount will be distributed as a reward to whoever finds the insolvency and cancels the stream.

INVARIANT: prepaid: == 0 INVARIANT: unbounded: == DEPOSIT_AMOUNT_PERIOD_IN_SECS of streaming payments

seed: BN

Seed of the stream PDA. It's upto the client how they choose the seed. Each tuple (seed, mint, name) corresponds to a unique stream.

bump: number

The PDA bump.

name: string

Name of the stream. Should be unique for a particular set of (seed, mint).

INVARIANT: Length <= 100 unicode chars or 400 bytes

Methods

  • Comparison function for Stream objects by the created at time.

    Parameters

    • a: Stream

      The first Stream object

    • b: Stream

      The second Stream object

    Returns number

    -1 if a < b, 0 if a == b or 1 if a > b

  • Get the current Solana on-chain time in seconds. If there is an issue fetching the time, undefined is returned.

    Returns Promise<undefined | BN>

    The current Solana on-chain time in seconds or undefined if there was an issue

  • Get the current Solana on-chain time in seconds. If there is an issue fetching the time, an error is thrown.

    Returns Promise<BN>

    The current Solana on-chain time in seconds

    Throws

    An error is thrown if there is an issue fetching the time

  • Get the stream public key.

    Returns [PublicKey, number]

    The stream public key

  • Refresh the stream.

    Returns Promise<Stream>

    The refreshed stream

    Throws

    An error is thrown if there is a Solana RPC issue

  • Check is the client wallet address is the sender of this stream.

    Returns boolean

    true if the client wallet address is the sender of this stream, false otherwise

  • Check is the client wallet address is the recipient of this stream.

    Returns boolean

    true if the client wallet address is the recipient of this stream, false otherwise

  • Check is the stream has non-zero flow payments. Flow payments refers to payments without the initial amount.

    Returns boolean

    true if the stream has flow payments, false otherwise

  • Get the time at which the stream will stop or has already stopped.

    Returns BN

    The time at which the stream will stop or has already stopped in seconds as BN

  • Check is the stream has stopped at the given on-chain time.

    Parameters

    • at: BN

      The on-chain time

    Returns boolean

    true if the stream has stopped, false otherwise

  • Get the status of the stream at the given on-chain time.

    Parameters

    • at: BN

      The on-chain time

    Returns StreamStatus

    The status of the stream

  • Get the maximum acceptable topup amount at the given on-chain time.

    Parameters

    • at: BN

      The on-chain time

    Returns {
        noLimit: boolean;
        maxAcceptableTopupAmount: BN;
    }

    The maximum acceptable topup amount. If there is no maximum, the noLimit property is true

    • noLimit: boolean
    • maxAcceptableTopupAmount: BN
  • Get the total amount owed to the recipient at the given on-chain time. This includes any amount the recipient has already withdrawn. That need be subtracted to get the amount the recipient is eligible to withdraw. See totalWithdrawnAmount for more details.

    Parameters

    • at: BN

      The on-chain time

    Returns BN

    The total amount owed to the recipient at the given on-chain time

  • Get the total amount available to withdraw to the recipient at the given on-chain time.

    Parameters

    • at: BN

      The on-chain time

    Returns BN

    The total amount available to withdraw to the recipient at the given on-chain time

  • Check is the stream is solvent at the given on-chain time.

    Parameters

    • at: BN

      The on-chain time

    Returns boolean

    true if the stream is solvent, false otherwise

  • Validate if the stream can be cancelled at the given on-chain time.

    Conditions when validation fails:

    • Stream has already been cancelled
    • Stream has already ended
    • Stream is solvent and
      • Wallet doesn't belong to the sender or the recipient of the stream
      • Wallet belongs to the sender of the stream and the sender of the stream isn't allowed to cancel

    Parameters

    • at: BN

      The on-chain time

    Returns void

    Throws

    An error is thrown if the stream cannot be cancelled

  • Cancel the stream and validate at the given on-chain time.

    Parameters

    • at: BN

      The on-chain time

    Returns Promise<void>

    Throws

    An error is thrown if the stream cannot be cancelled or a user wallet wasn't provided to the Superstream client or there is a Solana RPC issue

  • Validate if the stream can be withdrawn from for excess sender topup at the given on-chain time.

    Conditions when validation fails:

    • Stream has already been cancelled
    • Stream has not yet ended
    • Stream is insolvent
    • Amount owed to the recipient is more than the total topup amount plus the deposit

    Parameters

    • at: BN

      The on-chain time

    Returns void

    Throws

    An error is thrown if the stream cannot be withdrawn from for excess sender topup

  • Withdraw excess sender topup from the non-prepaid stream and validate at the given on-chain time.

    Parameters

    • at: BN

      The on-chain time

    Returns Promise<void>

    Throws

    An error is thrown if the stream cannot be withdrawn from for excess sender topup or a user wallet wasn't provided to the Superstream client or there is a Solana RPC issue

  • Validate if the non-prepaid stream can be topped up at the given on-chain time.

    Conditions when validation fails:

    • Stream has already ended
    • Stream is prepaid
    • Stream doesn't have any flow payments (payments apart from the initial amount)
    • Topup amount is <= 0
    • Topup amount is > maximum acceptable topup amount

    Parameters

    • at: BN

      The on-chain time

    • Optional topupAmount: BN

      The topup amount

    Returns void

    Throws

    An error is thrown if the stream cannot be topped up

  • Topup the non-prepaid stream and validate at the given on-chain time.

    Parameters

    • at: BN

      The on-chain time

    • topupAmount: BN

      The topup amount

    Returns Promise<void>

    Throws

    An error is thrown if the stream cannot be topped up or a user wallet wasn't provided to the Superstream client or there is a Solana RPC issue

  • Validate if the non-prepaid stream's sender can be changed at the given on-chain time.

    Conditions when validation fails:

    • Stream has already ended
    • Stream is prepaid
    • Wallet doesn't belong to the sender of the stream
    • Sender of the stream is not allowed to change the sender
    • New sender === web3.PublicKey.default
    • New sender === this stream's current sender

    Parameters

    • at: BN

      The on-chain time

    • Optional newSender: PublicKey

      The new sender

    Returns void

    Throws

    An error is thrown if the stream's sender cannot be changed

  • Change the sender of the non-prepaid stream and validate at the given on-chain time. The new sender should not be === web3.PublicKey.default or === this stream's current sender

    Parameters

    • at: BN

      The on-chain time

    • newSender: PublicKey

      The new sender. The new sender should not be === web3.PublicKey.default or === this stream's current sender

    Returns Promise<void>

    Throws

    An error is thrown if the stream's sender cannot be changed or a user wallet wasn't provided to the Superstream client or there is a Solana RPC issue

  • Validate if the stream's recipient funds can be withdrawn at the given on-chain time.

    Conditions when validation fails:

    • Amount owed to the recipient is less than or equal to the total withdrawn amount
    • Total withdrawn amount is greater than or equal to the total topup amount plus the total deposit
    • Wallet doesn't belong to the recipient of the stream and
      • Anyone cannot withdraw on behalf of the recipient

    Parameters

    • at: BN

      The on-chain time

    Returns void

    Throws

    An error is thrown if the stream's recipient funds cannot be withdrawn

  • Withdraw recipient funds from the stream and validate at the given on-chain time.

    Parameters

    • at: BN

      The on-chain time

    Returns Promise<void>

    Throws

    An error is thrown if the stream's recipient funds cannot be withdrawn or a user wallet wasn't provided to the Superstream client or there is a Solana RPC issue

  • Validate if the stream's recipient funds can be withdrawn and the recipient can be changed at the given on-chain time.

    Conditions when validation fails:

    • validateWithdraw fails
    • Wallet doesn't belong to the recipient of the stream
    • New recipient === this stream's current recipient

    Parameters

    • at: BN

      The on-chain time

    • Optional newRecipient: PublicKey

      The new recipient

    Returns void

    Throws

    An error is thrown if the stream's recipient funds cannot be withdrawn or the recipient cannot be changed

  • Withdraw recipient funds from the stream and change the recipient of the stream and validate at the given on-chain time. If the new recipient === web3.PublicKey.default, the recipient is not changed. The new recipient should not be === this stream's current recipient.

    Parameters

    • at: BN

      The on-chain time

    • newRecipient: PublicKey

      The new recipient. If the new recipient === web3.PublicKey.default, the recipient is not changed. The new recipient should not be === this stream's current recipient

    Returns Promise<void>

    Throws

    An error is thrown if the stream's recipient funds cannot be withdrawn or the recipient cannot be changed or a user wallet wasn't provided to the Superstream client or there is a Solana RPC issue

  • Validate if the stream can be paused at the given on-chain time.

    Conditions when validation fails:

    • Stream is prepaid
    • Stream has already stopped
    • Stream is already paused
    • Stream doesn't have any flow payments (payments apart from the initial amount)
    • Wallet doesn't belong to the sender or the recipient of the stream
    • Wallet belongs to the sender of the stream and
      • Sender of the stream isn't allowed to pause

    Parameters

    • at: BN

      The on-chain time

    Returns void

    Throws

    An error is thrown if the stream cannot be paused

  • Pause the non-prepaid stream and validate at the given on-chain time.

    Parameters

    • at: BN

      The on-chain time

    Returns Promise<void>

    Throws

    An error is thrown if the stream cannot be paused or a user wallet wasn't provided to the Superstream client or there is a Solana RPC issue

  • Validate if the stream can be resumed at the given on-chain time.

    Conditions when validation fails:

    • Stream is prepaid
    • Stream has already stopped
    • Stream is not already paused
    • Wallet doesn't belong to the sender or the recipient of the stream
    • Wallet belongs to the recipient of the stream and
      • Stream is paused by the sender of the stream and
        • Recipient of the stream isn't allowed to resume a stream paused by the sender of the stream

    Parameters

    • at: BN

      The on-chain time

    Returns void

    Throws

    An error is thrown if the stream cannot be resumed

  • Resume the non-prepaid stream and validate at the given on-chain time.

    Parameters

    • at: BN

      The on-chain time

    Returns Promise<void>

    Throws

    An error is thrown if the stream cannot be resumed or a user wallet wasn't provided to the Superstream client or there is a Solana RPC issue

  • Get or create an associated token account for the stream's mint for the given owner.

    Parameters

    • owner: PublicKey

      The public key of the owner for which an associated token account is needed

    Returns Promise<PublicKey>

    The public key of the associated token account fetched or created

    Throws

    An error is thrown if there is a Solana RPC issue

  • Get or create an associated token account for the stream's mint for the signer.

    Returns Promise<PublicKey>

    The public key of the associated token account fetched or created

    Throws

    An error is thrown if there is a Solana RPC issue

  • Get or create an associated token account for the stream's mint for the stream sender.

    Returns Promise<PublicKey>

    The public key of the associated token account fetched or created

    Throws

    An error is thrown if there is a Solana RPC issue

  • Get or create an associated token account for the stream's mint for the stream recipient.

    Returns Promise<PublicKey>

    The public key of the associated token account fetched or created

    Throws

    An error is thrown if there is a Solana RPC issue

  • Get the associated token account for the stream's mint for the given owner. If an associated token account doesn't exist, an error is thrown.

    Parameters

    • owner: PublicKey

      The public key of the owner for which the associated token account is needed

    Returns Promise<PublicKey>

    The public key of the associated token account

    Throws

    An error is thrown an associated token account doesn't exist or there is a Solana RPC issue

  • Get the associated token account for the stream's mint for the stream sender. If an associated token account doesn't exist, an error is thrown.

    Returns Promise<PublicKey>

    The public key of the associated token account

    Throws

    An error is thrown an associated token account doesn't exist or there is a Solana RPC issue

  • Get the associated token account for the stream's mint for the stream recipient. If an associated token account doesn't exist, an error is thrown.

    Returns Promise<PublicKey>

    The public key of the associated token account

    Throws

    An error is thrown an associated token account doesn't exist or there is a Solana RPC issue

Generated using TypeDoc