Lifecycle Operations
withdraw, topup, transfer, cancel, and update - signatures, params, and constraints.
All lifecycle functions return InstructionResult: { instructions }. Use the same 3-phase pattern as creation.
import { withdraw, topup, transfer, cancel, update } from "@streamflow/stream/solana/api";Operations
withdraw
Withdraw tokens that have vested. Available on any active stream - no creation-time flag required.
async function withdraw(
params: IWithdrawData, // { id: string, amount?: BN }
invoker: Invoker, // must be the stream's recipient
env: Env,
): Promise<InstructionResult>// Withdraw all available tokens (omit amount)
const result = await withdraw({ id: streamId }, recipientInvoker, env);
// Withdraw a specific amount
const result = await withdraw({ id: streamId, amount: new BN(100) }, recipientInvoker, env);Notes:
- For locks: only works after
unlockDatehas passed - The invoker must be the stream's current recipient on-chain
topup
Add tokens to extend a stream's duration. Requires canTopup: true at creation.
async function topup(
params: ITopUpData, // { id: string, amount: BN }
invoker: Invoker, // must be the stream's sender
env: Env & NativeOptions,
): Promise<InstructionResult>const result = await topup(
{ id: streamId, amount: new BN(500) },
senderInvoker,
{ ...env, isNative: false }, // isNative must match the token used at creation
);Notes:
isNativeinenvmust match whether the stream was created with native SOL- Lock streams have
canTopup: falsehardcoded - topup will fail on locks
transfer
Change the stream's recipient to a new wallet. Requires transferableBySender: true at creation.
async function transfer(
params: ITransferData, // { id: string, newRecipient: string }
invoker: Invoker, // must be the stream's sender
env: Env,
): Promise<InstructionResult>const result = await transfer(
{ id: streamId, newRecipient: "NewWalletAddress..." },
senderInvoker,
env,
);transfer() embeds its own ComputeBudgetProgram instruction. Do not pass computeLimit to buildTransaction - it would create a duplicate compute budget instruction.
cancel
Terminate the stream early. Returns unvested tokens to the sender. Requires cancelableBySender: true at creation.
async function cancel(
params: { id: string },
invoker: Invoker, // must be the stream's sender
env: Env,
): Promise<InstructionResult>const result = await cancel({ id: streamId }, senderInvoker, env);Notes:
- Must be the last operation - all other lifecycle operations fail after cancellation
- Lock streams have
cancelableBySender: falsehardcoded
update
Update the stream's release rate and/or permission flags. Requires canUpdateRate: true on the stream.
async function update(
params: IUpdateData, // { id, amountPerPeriod?, enableAutomaticWithdrawal?, withdrawFrequency?: BN, transferableBySender?, transferableByRecipient?, cancelableBySender? }
invoker: Invoker,
env: Env,
): Promise<InstructionResult>const result = await update(
{ id: streamId, amountPerPeriod: new BN(200) },
senderInvoker,
env,
);canUpdateRate is not exposed in ICreateVestingParams. Streams created via createVesting don't support update unless you use SolanaStreamClient.create() directly with canUpdateRate: true.