Skip to main content

streamflow_sdk/
lib.rs

1#![allow(unexpected_cfgs)]
2pub mod state;
3
4use anchor_lang::prelude::*;
5
6use anchor_spl::{
7    associated_token::AssociatedToken,
8    token::{Mint, Token, TokenAccount},
9};
10
11#[cfg(feature = "devnet")]
12declare_id!("HqDGZjaVRXJ9MGRQEw7qDc2rAr6iH1n1kAQdCZaCMfMZ");
13#[cfg(not(feature = "devnet"))]
14declare_id!("strmRqUCoQUgGUan5YhzUZa6KqdzwX5L6FpUxfmKg5m");
15
16/// Streamflow sdk module defining anchor account structs expected from the Streamflow protocol
17/// as well as anchor cpi module used for invoking Streamflow protocol
18///
19/// ## Usage
20///
21/// Declaring a dependency in program's Cargo.toml
22///
23/// ```toml
24/// streamflow_sdk = {version = "0.7", features = ["cpi"]}
25/// ```
26///
27/// To use protocol on devnet add sdk with `devnet` feature
28///
29/// ```toml
30/// streamflow_sdk = {version = "0.7", features = ["cpi", "devnet"]}
31/// ```
32///
33/// Example anchor program invoking streamflow create instruction
34///
35///
36/// ```rust
37/// use anchor_lang::prelude::*;
38/// use anchor_spl::{
39///     associated_token::AssociatedToken,
40///     token::{Mint, Token, TokenAccount},
41/// };
42///
43/// use streamflow_sdk;
44/// use streamflow_sdk::cpi::accounts::{
45///     Create as CpiCreate,
46///     CreateUnchecked as CpiCreateUnchecked,
47///     CreateUncheckedWithPayer as CpiCreateUncheckedWithPayer,
48///     Update as CpiUpdate,
49///     Withdraw as CpiWithdraw,
50///     Topup as CpiTopup,
51///     Transfer as CpiTransfer,
52///     Cancel as CpiCancel,
53/// };
54///
55/// declare_id!("FGjLaVo5zLGdzCxMo9gu9tXr1kzTToKd8C8K7YS5hNM1");
56///
57/// #[program]
58/// pub mod example_program {
59///     use super::*;
60///
61///     //anchor rpc handlers
62///     pub fn create(
63///         ctx: Context<Create>,
64///         start_time: u64,
65///         net_amount_deposited: u64,
66///         period: u64,
67///         amount_per_period: u64,
68///         cliff: u64,
69///         cliff_amount: u64,
70///         cancelable_by_sender: bool,
71///         cancelable_by_recipient: bool,
72///         automatic_withdrawal: bool,
73///         transferable_by_sender: bool,
74///         transferable_by_recipient: bool,
75///         can_topup: bool,
76///         stream_name: [u8; 64],
77///         withdraw_frequency: u64,
78///         pausable: Option<bool>,
79///         can_update_rate: Option<bool>,
80///     ) -> Result<()> {
81///         msg!("Got create");
82///         // initializing accounts struct for cross-program invoke
83///         let accs = CpiCreate {
84///             sender: ctx.accounts.sender.to_account_info(),
85///             sender_tokens: ctx.accounts.sender_tokens.to_account_info(),
86///             recipient: ctx.accounts.recipient.to_account_info(),
87///             recipient_tokens: ctx.accounts.recipient_tokens.to_account_info(),
88///             metadata: ctx.accounts.metadata.to_account_info(),
89///             escrow_tokens: ctx.accounts.escrow_tokens.to_account_info(),
90///             streamflow_treasury: ctx.accounts.streamflow_treasury.to_account_info(),
91///             streamflow_treasury_tokens: ctx.accounts.streamflow_treasury_tokens.to_account_info(),
92///             withdrawor: ctx.accounts.withdrawor.to_account_info(),
93///             partner: ctx.accounts.partner.to_account_info(),
94///             partner_tokens: ctx.accounts.partner_tokens.to_account_info(),
95///             mint: ctx.accounts.mint.to_account_info(),
96///             fee_oracle: ctx.accounts.fee_oracle.to_account_info(),
97///             rent: ctx.accounts.rent.to_account_info(),
98///             timelock_program: ctx.accounts.streamflow_program.to_account_info(),
99///             token_program: ctx.accounts.token_program.to_account_info(),
100///             associated_token_program: ctx.accounts.associated_token_program.to_account_info(),
101///             system_program: ctx.accounts.system_program.to_account_info(),
102///         };
103///
104///         // initializing anchor CpiContext, can be used in native solana programs as well
105///         // additional reference: https://project-serum.github.io/anchor/tutorials/tutorial-3.html
106///         let cpi_ctx = CpiContext::new(ctx.accounts.streamflow_program.to_account_info(), accs);
107///
108///         // calling cpi method which calls solana_program invoke with serialized instruction data
109///         // fit for streamflow program
110///         streamflow_sdk::cpi::create(
111///             cpi_ctx,
112///             start_time,
113///             net_amount_deposited,
114///             period,
115///             amount_per_period,
116///             cliff,
117///             cliff_amount,
118///             cancelable_by_sender,
119///             cancelable_by_recipient,
120///             automatic_withdrawal,
121///             transferable_by_sender,
122///             transferable_by_recipient,
123///             can_topup,
124///             stream_name,
125///             withdraw_frequency,
126///             pausable,
127///             can_update_rate
128///         )
129///     }
130/// }
131///
132/// #[derive(Accounts)]
133/// pub struct Create<'info> {
134///     #[account(mut)]
135///     pub sender: Signer<'info>,
136///     #[account(
137///         associated_token::mint = mint,
138///         associated_token::authority = sender,
139///     )]
140///     pub sender_tokens: Box<Account<'info, TokenAccount>>,
141///     #[account(mut)]
142///     /// CHECK: Wallet address of the recipient.
143///     pub recipient: UncheckedAccount<'info>,
144///     #[account(
145///         init_if_needed,
146///         payer = sender,
147///         associated_token::mint = mint,
148///         associated_token::authority = recipient,
149///     )]
150///     pub recipient_tokens: Box<Account<'info, TokenAccount>>,
151///     #[account(mut)]
152///     pub metadata: Signer<'info>,
153///     #[account(
154///         mut,
155///         seeds = [b"strm", metadata.key().to_bytes().as_ref()],
156///         bump,
157///         seeds::program = streamflow_program
158///     )]
159///     /// CHECK: The escrow account holding the funds, expects empty (non-initialized) account.
160///     pub escrow_tokens: AccountInfo<'info>,
161///     #[account(mut)]
162///     /// CHECK: Streamflow treasury account.
163///     pub streamflow_treasury: UncheckedAccount<'info>,
164///     #[account(
165///         init_if_needed,
166///         payer = sender,
167///         associated_token::mint = mint,
168///         associated_token::authority = streamflow_treasury,
169///     )]
170///     /// CHECK: Associated token account address of `streamflow_treasury`.
171///     pub streamflow_treasury_tokens: Box<Account<'info, TokenAccount>>,
172///     #[account(mut)]
173///     /// CHECK: Delegate account for automatically withdrawing contracts.
174///     pub withdrawor: UncheckedAccount<'info>,
175///     #[account(mut)]
176///     /// CHECK: Partner treasury account.
177///     pub partner: UncheckedAccount<'info>,
178///     #[account(
179///         init_if_needed,
180///         payer = sender,
181///         associated_token::mint = mint,
182///         associated_token::authority = partner,
183///     )]
184///     pub partner_tokens: Box<Account<'info, TokenAccount>>,
185///     pub mint: Box<Account<'info, Mint>>,
186///     /// CHECK: Internal program that handles fees for specified partners.
187///     pub fee_oracle: UncheckedAccount<'info>,
188///     pub rent: Sysvar<'info, Rent>,
189///     /// CHECK: Streamflow protocol (alias timelock) program account.
190///     pub streamflow_program: UncheckedAccount<'info>,
191///     pub token_program: Program<'info, Token>,
192///     pub associated_token_program: Program<'info, AssociatedToken>,
193///     pub system_program: Program<'info, System>,
194/// }
195/// ```
196
197
198#[program]
199pub mod streamflow_sdk {
200    use super::*;
201
202    /// Create a Stream
203    ///
204    /// # Arguments
205    ///
206    /// * `ctx` - Accounts that will be used on Stream creation
207    /// * `start_time` - Unix Timestamp for Stream start, can be 0 to use current time
208    /// * `net_amount_deposited` - Amount of Tokens to deposit to the Stream
209    /// * `period` - Unlock Period in Seconds, tokens will be unlocked every `period` seconds
210    /// * `amount_per_period` - Unlock Amount, every `period` we unlock `amount_per_period` tokens
211    /// * `cliff` - Unix Timestamp of Cliff (first unlock), can be 0 to use current time or not use at all
212    /// * `cliff_amount` - Cliff Amount of tokens, can 0 to not use Cliff at all
213    /// * `cancelable_by_sender` - Whether Stream can by cancelled by Sender
214    /// * `cancelable_by_recipient` - Whether Stream can be cancelled by Recipient
215    /// * `automatic_withdrawal` - Whether automatic withdrawals are enabled
216    /// * `transferable_by_sender` - Whether Stream can be transferred by Sender
217    /// * `transferable_by_recipient` - Whether Stream can be transferred by Recipient
218    /// * `can_topup` - Whether Stream can be topped up (deposit additional tokens) by Sender
219    /// * `stream_name` - Name of the Stream
220    /// * `withdraw_frequency` - if `automatic_withdrawal` is on, every `withdraw_frequency` seconds **all unlocked** tokens will be sent to the recipient
221    /// * `pausable` - Whether Stream can be paused by Sender
222    /// * `can_update_rate` - Whether Sender can update `amount_per_period` value of the Stream via `update` method
223    #[allow(unused_variables)]
224    pub fn create(
225        ctx: Context<Create>,
226        start_time: u64,
227        net_amount_deposited: u64,
228        period: u64,
229        amount_per_period: u64,
230        cliff: u64,
231        cliff_amount: u64,
232        cancelable_by_sender: bool,
233        cancelable_by_recipient: bool,
234        automatic_withdrawal: bool,
235        transferable_by_sender: bool,
236        transferable_by_recipient: bool,
237        can_topup: bool,
238        stream_name: [u8; 64],
239        withdraw_frequency: u64,
240        pausable: Option<bool>,
241        can_update_rate: Option<bool>,
242    ) -> Result<()> {
243        Ok(())
244    }
245
246    /// Create a Stream with PDA-based metadata (v2)
247    ///
248    /// This is similar to `create` but uses a PDA for the metadata account instead of an
249    /// ephemeral signer keypair. The metadata PDA is derived from:
250    /// `["strm-met", mint, sender, nonce_be_bytes]`
251    ///
252    /// Use `streamflow_sdk::state::derive_metadata` to compute the metadata PDA address.
253    ///
254    /// # Arguments
255    ///
256    /// * `ctx` - Accounts that will be used on Stream creation
257    /// * `start_time` - Unix Timestamp for Stream start, can be 0 to use current time
258    /// * `net_amount_deposited` - Amount of Tokens to deposit to the Stream
259    /// * `period` - Unlock Period in Seconds, tokens will be unlocked every `period` seconds
260    /// * `amount_per_period` - Unlock Amount, every `period` we unlock `amount_per_period` tokens
261    /// * `cliff` - Unix Timestamp of Cliff (first unlock), can be 0 to use current time or not use at all
262    /// * `cliff_amount` - Cliff Amount of tokens, can 0 to not use Cliff at all
263    /// * `cancelable_by_sender` - Whether Stream can by cancelled by Sender
264    /// * `cancelable_by_recipient` - Whether Stream can be cancelled by Recipient
265    /// * `automatic_withdrawal` - Whether automatic withdrawals are enabled
266    /// * `transferable_by_sender` - Whether Stream can be transferred by Sender
267    /// * `transferable_by_recipient` - Whether Stream can be transferred by Recipient
268    /// * `can_topup` - Whether Stream can be topped up (deposit additional tokens) by Sender
269    /// * `stream_name` - Name of the Stream
270    /// * `withdraw_frequency` - if `automatic_withdrawal` is on, every `withdraw_frequency` seconds **all unlocked** tokens will be sent to the recipient
271    /// * `pausable` - Whether Stream can be paused by Sender
272    /// * `can_update_rate` - Whether Sender can update `amount_per_period` value of the Stream via `update` method
273    /// * `nonce` - Nonce used for PDA derivation of the metadata account
274    #[allow(unused_variables)]
275    pub fn create_v2(
276        ctx: Context<Create>,
277        start_time: u64,
278        net_amount_deposited: u64,
279        period: u64,
280        amount_per_period: u64,
281        cliff: u64,
282        cliff_amount: u64,
283        cancelable_by_sender: bool,
284        cancelable_by_recipient: bool,
285        automatic_withdrawal: bool,
286        transferable_by_sender: bool,
287        transferable_by_recipient: bool,
288        can_topup: bool,
289        stream_name: [u8; 64],
290        withdraw_frequency: u64,
291        pausable: bool,
292        can_update_rate: bool,
293        nonce: u32,
294    ) -> Result<()> {
295        Ok(())
296    }
297
298    /// Create a Stream and skip some optional checks
299    ///
300    /// This method creates a stream and omit some of address checks on creation.
301    /// It is not recommended to use this method unless you need create a Stream inside a contract and you don't have space for extra accounts.
302    ///
303    /// # Arguments
304    ///
305    /// * `ctx` - Accounts that will be used on Stream creation, `metadata` account shuold be initialized!
306    /// * `start_time` - Unix Timestamp for Stream start, can be 0 to use current time
307    /// * `net_amount_deposited` - Amount of Tokens to deposit to the Stream
308    /// * `period` - Unlock Period in Seconds, tokens will be unlocked every `period` seconds
309    /// * `amount_per_period` - Unlock Amount, every `period` we unlock `amount_per_period` tokens
310    /// * `cliff` - Unix Timestamp of Cliff (first unlock), can be 0 to use current time or not use at all
311    /// * `cliff_amount` - Cliff Amount of tokens, can 0 to not use Cliff at all
312    /// * `cancelable_by_sender` - Whether Stream can by cancelled by Sender
313    /// * `cancelable_by_recipient` - Whether Stream can be cancelled by Recipient
314    /// * `automatic_withdrawal` - Whether automatic withdrawals are enabled
315    /// * `transferable_by_sender` - Whether Stream can be transferred by Sender
316    /// * `transferable_by_recipient` - Whether Stream can be transferred by Recipient
317    /// * `can_topup` - Whether Stream can be topped up (deposit additional tokens) by Sender
318    /// * `stream_name` - Name of the Stream
319    /// * `withdraw_frequency` - if `automatic_withdrawal` is on, every `withdraw_frequency` seconds **all unlocked** tokens will be sent to the recipient
320    /// * `pausable` - Whether Stream can be paused by Sender
321    /// * `can_update_rate` - Whether Sender can update `amount_per_period` value of the Stream via `update` method
322
323    #[allow(unused_variables)]
324    pub fn create_unchecked(
325        ctx: Context<CreateUnchecked>,
326        start_time: u64,
327        net_amount_deposited: u64,
328        period: u64,
329        amount_per_period: u64,
330        cliff: u64,
331        cliff_amount: u64,
332        cancelable_by_sender: bool,
333        cancelable_by_recipient: bool,
334        automatic_withdrawal: bool,
335        transferable_by_sender: bool,
336        transferable_by_recipient: bool,
337        can_topup: bool,
338        stream_name: [u8; 64],
339        withdraw_frequency: u64,
340        recipient: Pubkey,
341        partner: Pubkey,
342        pausable: bool,
343        can_update_rate: bool,
344    ) -> Result<()> { Ok(()) }
345
346    /// Create a Stream with PDA-based metadata and skip some optional checks (v2)
347    ///
348    /// This is similar to `create_unchecked` but uses a PDA for the metadata account
349    /// instead of requiring a pre-initialized account. The metadata PDA is derived from:
350    /// `["strm-met", mint, sender, nonce_be_bytes]`
351    ///
352    /// Use `streamflow_sdk::state::derive_metadata` to compute the metadata PDA address.
353    ///
354    /// # Arguments
355    ///
356    /// * `ctx` - Accounts that will be used on Stream creation
357    /// * `start_time` - Unix Timestamp for Stream start, can be 0 to use current time
358    /// * `net_amount_deposited` - Amount of Tokens to deposit to the Stream
359    /// * `period` - Unlock Period in Seconds, tokens will be unlocked every `period` seconds
360    /// * `amount_per_period` - Unlock Amount, every `period` we unlock `amount_per_period` tokens
361    /// * `cliff` - Unix Timestamp of Cliff (first unlock), can be 0 to use current time or not use at all
362    /// * `cliff_amount` - Cliff Amount of tokens, can 0 to not use Cliff at all
363    /// * `cancelable_by_sender` - Whether Stream can by cancelled by Sender
364    /// * `cancelable_by_recipient` - Whether Stream can be cancelled by Recipient
365    /// * `automatic_withdrawal` - Whether automatic withdrawals are enabled
366    /// * `transferable_by_sender` - Whether Stream can be transferred by Sender
367    /// * `transferable_by_recipient` - Whether Stream can be transferred by Recipient
368    /// * `can_topup` - Whether Stream can be topped up (deposit additional tokens) by Sender
369    /// * `stream_name` - Name of the Stream
370    /// * `withdraw_frequency` - if `automatic_withdrawal` is on, every `withdraw_frequency` seconds **all unlocked** tokens will be sent to the recipient
371    /// * `recipient` - Pubkey of the Stream recipient
372    /// * `partner` - Pubkey of the partner treasury
373    /// * `pausable` - Whether Stream can be paused by Sender
374    /// * `can_update_rate` - Whether Sender can update `amount_per_period` value of the Stream via `update` method
375    /// * `nonce` - Nonce used for PDA derivation of the metadata account
376    #[allow(unused_variables)]
377    pub fn create_unchecked_v2(
378        ctx: Context<CreateUnchecked>,
379        start_time: u64,
380        net_amount_deposited: u64,
381        period: u64,
382        amount_per_period: u64,
383        cliff: u64,
384        cliff_amount: u64,
385        cancelable_by_sender: bool,
386        cancelable_by_recipient: bool,
387        automatic_withdrawal: bool,
388        transferable_by_sender: bool,
389        transferable_by_recipient: bool,
390        can_topup: bool,
391        stream_name: [u8; 64],
392        withdraw_frequency: u64,
393        recipient: Pubkey,
394        partner: Pubkey,
395        pausable: bool,
396        can_update_rate: bool,
397        nonce: u32,
398    ) -> Result<()> { Ok(()) }
399
400    /// Create a Stream and skip some optional checks
401    ///
402    /// This method creates a stream and omit some of address checks on creation.
403    /// Also on creation `payer` account will be used to initiliaze accounts and pay withdrawal fees.
404    /// It is not recommended to use this method unless you need create a Stream inside a contract and you don't have space for extra accounts
405    /// and `sender` can't pay for fees (for example, if `sender` is your contract).
406    ///
407    /// # Arguments
408    ///
409    /// * `ctx` - Accounts that will be used on Stream creation, `metadata` account shuold be initialized!
410    /// * `start_time` - Unix Timestamp for Stream start, can be 0 to use current time
411    /// * `net_amount_deposited` - Amount of Tokens to deposit to the Stream
412    /// * `period` - Unlock Period in Seconds, tokens will be unlocked every `period` seconds
413    /// * `amount_per_period` - Unlock Amount, every `period` we unlock `amount_per_period` tokens
414    /// * `cliff` - Unix Timestamp of Cliff (first unlock), can be 0 to use current time or not use at all
415    /// * `cliff_amount` - Cliff Amount of tokens, can 0 to not use Cliff at all
416    /// * `cancelable_by_sender` - Whether Stream can by cancelled by Sender
417    /// * `cancelable_by_recipient` - Whether Stream can be cancelled by Recipient
418    /// * `automatic_withdrawal` - Whether automatic withdrawals are enabled
419    /// * `transferable_by_sender` - Whether Stream can be transferred by Sender
420    /// * `transferable_by_recipient` - Whether Stream can be transferred by Recipient
421    /// * `can_topup` - Whether Stream can be topped up (deposit additional tokens) by Sender
422    /// * `stream_name` - Name of the Stream
423    /// * `withdraw_frequency` - if `automatic_withdrawal` is on, every `withdraw_frequency` seconds **all unlocked** tokens will be sent to the recipient
424    /// * `pausable` - Whether Stream can be paused by Sender
425    /// * `can_update_rate` - Whether Sender can update `amount_per_period` value of the Stream via `update` method
426    #[allow(unused_variables)]
427    pub fn create_unchecked_with_payer(
428        ctx: Context<CreateUncheckedWithPayer>,
429        start_time: u64,
430        net_amount_deposited: u64,
431        period: u64,
432        amount_per_period: u64,
433        cliff: u64,
434        cliff_amount: u64,
435        cancelable_by_sender: bool,
436        cancelable_by_recipient: bool,
437        automatic_withdrawal: bool,
438        transferable_by_sender: bool,
439        transferable_by_recipient: bool,
440        can_topup: bool,
441        stream_name: [u8; 64],
442        withdraw_frequency: u64,
443        recipient: Pubkey,
444        partner: Pubkey,
445        pausable: bool,
446        can_update_rate: bool,
447    ) -> Result<()> { Ok(()) }
448
449    /// Create a Stream with PDA-based metadata, skip some optional checks, and use a separate payer (v2)
450    ///
451    /// This is similar to `create_unchecked_with_payer` but uses a PDA for the metadata account
452    /// instead of requiring a pre-initialized account. The metadata PDA is derived from:
453    /// `["strm-met", mint, payer, nonce_be_bytes]`
454    ///
455    /// Use `streamflow_sdk::state::derive_metadata` to compute the metadata PDA address.
456    /// Note: for this instruction, pass the `payer` pubkey (not `sender`) to `derive_metadata`.
457    ///
458    /// # Arguments
459    ///
460    /// * `ctx` - Accounts that will be used on Stream creation
461    /// * `start_time` - Unix Timestamp for Stream start, can be 0 to use current time
462    /// * `net_amount_deposited` - Amount of Tokens to deposit to the Stream
463    /// * `period` - Unlock Period in Seconds, tokens will be unlocked every `period` seconds
464    /// * `amount_per_period` - Unlock Amount, every `period` we unlock `amount_per_period` tokens
465    /// * `cliff` - Unix Timestamp of Cliff (first unlock), can be 0 to use current time or not use at all
466    /// * `cliff_amount` - Cliff Amount of tokens, can 0 to not use Cliff at all
467    /// * `cancelable_by_sender` - Whether Stream can by cancelled by Sender
468    /// * `cancelable_by_recipient` - Whether Stream can be cancelled by Recipient
469    /// * `automatic_withdrawal` - Whether automatic withdrawals are enabled
470    /// * `transferable_by_sender` - Whether Stream can be transferred by Sender
471    /// * `transferable_by_recipient` - Whether Stream can be transferred by Recipient
472    /// * `can_topup` - Whether Stream can be topped up (deposit additional tokens) by Sender
473    /// * `stream_name` - Name of the Stream
474    /// * `withdraw_frequency` - if `automatic_withdrawal` is on, every `withdraw_frequency` seconds **all unlocked** tokens will be sent to the recipient
475    /// * `recipient` - Pubkey of the Stream recipient
476    /// * `partner` - Pubkey of the partner treasury
477    /// * `pausable` - Whether Stream can be paused by Sender
478    /// * `can_update_rate` - Whether Sender can update `amount_per_period` value of the Stream via `update` method
479    /// * `nonce` - Nonce used for PDA derivation of the metadata account
480    #[allow(unused_variables)]
481    pub fn create_unchecked_with_payer_v2(
482        ctx: Context<CreateUncheckedWithPayer>,
483        start_time: u64,
484        net_amount_deposited: u64,
485        period: u64,
486        amount_per_period: u64,
487        cliff: u64,
488        cliff_amount: u64,
489        cancelable_by_sender: bool,
490        cancelable_by_recipient: bool,
491        automatic_withdrawal: bool,
492        transferable_by_sender: bool,
493        transferable_by_recipient: bool,
494        can_topup: bool,
495        stream_name: [u8; 64],
496        withdraw_frequency: u64,
497        recipient: Pubkey,
498        partner: Pubkey,
499        pausable: bool,
500        can_update_rate: bool,
501        nonce: u32,
502    ) -> Result<()> { Ok(()) }
503
504    /// Update a Stream
505    ///
506    /// This method enables automatic withdrawals and/or updates `amount_per_period` in a Stream
507    ///
508    /// # Arguments
509    /// * `ctx` - Accounts that will be used on Stream update
510    /// * `enable_automatic_withdrawal` - Whether to enable automatic withdrawals (can't be disabled)
511    /// * `withdraw_frequency` - Set withdrawal frequency, use it only if `enable_automatic_withdrawal` is set to Some(true)
512    /// * `amount_per_period` - Whether to update Unlock Amount of the Stream, `can_update_rate` should be enabled
513    /// * `transferable_by_sender` - Whether to disable transfer by Sender, only disabling is possible.
514    /// * `transferable_by_recipient` - Whether to enable transfer by Recipient, only enabling is possible.
515    /// * `cancelable_by_sender` - Whether to disable cancel by Sender, only disabling is possible.
516    /// * `stream_name` - New name of the Stream, only the Sender can rename it.
517    #[allow(unused_variables)]
518    pub fn update(
519        ctx: Context<Update>,
520        enable_automatic_withdrawal: Option<bool>,
521        withdraw_frequency: Option<u64>,
522        amount_per_period: Option<u64>,
523        transferable_by_sender: Option<bool>,
524        transferable_by_recipient: Option<bool>,
525        cancelable_by_sender: Option<bool>,
526        stream_name: Option<[u8; 64]>,
527    ) -> Result<()> {
528        Ok(())
529    }
530
531    /// Withdraw tokens from a Stream
532    ///
533    /// This methods withdraws tokens from a Stream, requested amount of tokens will be sent to the Recipient
534    /// If `enable_automatic_withdrawal` is set to false only Recipient can request a Withdrawal
535    ///
536    /// # Arguments
537    /// * `ctx` - Accounts that will be used on Stream withdrawal
538    /// * `amount` - amount to withdraw, should <= unlocked amount. Use `u64::MAX` if you want to withdraw all unlocked amount
539    #[allow(unused_variables)]
540    pub fn withdraw(ctx: Context<Withdraw>, amount: u64) -> Result<()> {
541        Ok(())
542    }
543
544    /// Cancel a Stream
545    ///
546    /// Cancels a stream, withdraws all unlocked amount to Recipient and returns all leftover tokens back to Sender
547    ///
548    /// # Arguments
549    /// * `ctx` - Accounts that will be used on Stream cancellation
550    #[allow(unused_variables)]
551    pub fn cancel(ctx: Context<Cancel>) -> Result<()> {
552        Ok(())
553    }
554
555    /// Pause a Stream
556    ///
557    /// This method pauses a Stream, meaning that no unlocks will be processed, only already unlocked amount can be withdrawn
558    ///
559    /// # Arguments
560    /// * `ctx` - Accounts that will be used on Stream pause
561    #[allow(unused_variables)]
562    pub fn pause(ctx: Context<Pause>) -> Result<()> {
563        Ok(())
564    }
565
566    /// Unpause a Stream
567    ///
568    /// This method unpauses a paused Stream
569    ///
570    /// # Arguments
571    /// * `ctx` - Accounts that will be used on Stream unpause
572    #[allow(unused_variables)]
573    pub fn unpause(ctx: Context<UnPause>) -> Result<()> {
574        Ok(())
575    }
576
577    /// Transfer a Stream
578    ///
579    /// This method transfer Stream to another Recipient, already unlocked amount **won't** be sent to the old Recipient
580    /// Because of that this method can be effectively used when if you chose wrong Recipient on Stream creation
581    ///
582    /// # Arguments
583    /// * `ctx` - Accounts that will be used on Stream transfer
584    #[allow(unused_variables)]
585    pub fn transfer_recipient(ctx: Context<Transfer>) -> Result<()> {
586        Ok(())
587    }
588
589    /// Transfer a Stream Sender
590    ///
591    /// This method transfer Stream Sender to another Wallet.
592    ///
593    /// # Arguments
594    /// * `ctx` - Accounts that will be used on Stream sender transfer
595    #[allow(unused_variables)]
596    pub fn transfer_sender(ctx: Context<TransferSender>) -> Result<()> {
597        Ok(())
598    }
599
600    /// Topup a Stream
601    ///
602    /// This method tops up a Stream **if it's not closed**
603    ///
604    /// # Arguments
605    /// * `ctx` - Accounts that will be used on Stream unpause
606    /// * `amount` - Amount to Topup a Stream with
607    #[allow(unused_variables)]
608    pub fn topup(ctx: Context<Topup>, amount: u64) -> Result<()> {
609        Ok(())
610    }
611}
612
613/// Accounts expected in create and create_v2 instructions
614#[derive(Accounts)]
615pub struct Create<'info> {
616    /// Wallet of the contract creator.
617    #[account(mut)]
618    pub sender: Signer<'info>,
619    /// Associated token account address of `sender`.
620    #[account(mut)]
621    pub sender_tokens: AccountInfo<'info>,
622    /// Wallet address of the recipient.
623    #[account(mut)]
624    pub recipient: AccountInfo<'info>,
625    /// The account holding the contract parameters.
626    /// - create: should be an ephemeral signer;
627    /// - create_v2: a PDA, use `streamflow_sdk::state::derive_metadata` to derive.
628    ///   Derivation path: `["strm-met", mint, sender, nonce_be_bytes]`
629    #[account(mut)]
630    pub metadata: AccountInfo<'info>,
631    /// The escrow account holding the funds.
632    /// Should be a PDA, use `streamflow_sdk::state::find_escrow_account` to derive
633    /// Expects empty (non-initialized) account.
634    #[account(mut)]
635    pub escrow_tokens: AccountInfo<'info>,
636    /// Associated token account address of `recipient`.
637    #[account(mut)]
638    pub recipient_tokens: AccountInfo<'info>,
639    /// Streamflow treasury account.
640    /// Use constant `streamflow_sdk::state::STRM_TREASURY`
641    #[account(mut)]
642    pub streamflow_treasury: AccountInfo<'info>,
643    /// Associated token account address of `streamflow_treasury`.
644    #[account(mut)]
645    pub streamflow_treasury_tokens: AccountInfo<'info>,
646    /// Delegate account for automatically withdrawing contracts.
647    /// Use constant `streamflow_sdk::state::WITHDRAWOR_ADDRESS`
648    #[account(mut)]
649    pub withdrawor: AccountInfo<'info>,
650    /// Partner treasury account. If no partner fees are expected on behalf of the program
651    /// integrating with streamflow, `streamflow_treasury` can be passed in here.
652    #[account(mut)]
653    pub partner: AccountInfo<'info>,
654    /// Associated token account address of `partner`. If no partner fees are expected on behalf of the
655    /// program integrating with streamflow, `streamflow_treasury_tokens` can be passed in here.
656    #[account(mut)]
657    pub partner_tokens: AccountInfo<'info>,
658    /// The SPL token mint account.
659    pub mint: Account<'info, Mint>,
660    /// Internal program that handles fees for specified partners. If no partner fees are expected
661    /// on behalf of the program integrating with streamflow, `streamflow_treasury` can be passed
662    /// in here.
663    /// Use constant `streamflow_sdk::state::FEE_ORACLE_ADDRESS`
664    pub fee_oracle: AccountInfo<'info>,
665    /// The Rent Sysvar account.
666    pub rent: Sysvar<'info, Rent>,
667    /// Streamflow protocol (alias timelock) program account.
668    /// Use `streamflow_sdk:id()`
669    pub timelock_program: AccountInfo<'info>,
670    /// The SPL program needed in case an associated account
671    /// for the new recipient is being created.
672    pub token_program: Program<'info, Token>,
673    /// The Associated Token program needed in case associated
674    /// account for the new recipient is being created.
675    pub associated_token_program: Program<'info, AssociatedToken>,
676    /// The Solana system program needed for account creation.
677    pub system_program: Program<'info, System>,
678}
679
680/// Accounts expected in create_unchecked and create_unchecked_v2 instructions
681#[derive(Accounts)]
682pub struct CreateUnchecked<'info> {
683    /// Wallet of the contract creator.
684    #[account(mut)]
685    pub sender: Signer<'info>,
686    /// Associated token account address of `sender` for `mint`.
687    #[account(mut)]
688    pub sender_tokens: AccountInfo<'info>,
689    /// The account holding the contract parameters.
690    /// - create_unchecked: expects account initialized with `streamflow_sdk::state::METADATA_LEN` bytes length and assigned program ID.
691    /// - create_unchecked_v2: a PDA that will be created, use `streamflow_sdk::state::derive_metadata` to derive.
692    ///   Derivation path: `["strm-met", mint, sender, nonce_be_bytes]`
693    #[account(mut)]
694    pub metadata: AccountInfo<'info>,
695    /// The escrow account holding the funds.
696    /// Should be a PDA, use `streamflow_sdk::state::find_escrow_account` to derive
697    /// Expects empty (non-initialized) account.
698    #[account(mut)]
699    pub escrow_tokens: AccountInfo<'info>,
700    /// Delegate account for automatically withdrawing contracts.
701    /// Use constant `streamflow_sdk::state::WITHDRAWOR_ADDRESS`
702    #[account(mut)]
703    pub withdrawor: AccountInfo<'info>,
704    /// The SPL token mint account.
705    pub mint: Account<'info, Mint>,
706    /// Internal program that handles fees for specified partners. If no partner fees are expected
707    /// on behalf of the program integrating with streamflow, `streamflow_treasury` can be passed
708    /// in here.
709    /// Use constant `streamflow_sdk::state::FEE_ORACLE_ADDRESS`
710    pub fee_oracle: AccountInfo<'info>,
711    /// The Rent Sysvar account.
712    pub rent: Sysvar<'info, Rent>,
713    /// Streamflow protocol (alias timelock) program account.
714    /// Use `streamflow_sdk:id()`
715    pub timelock_program: AccountInfo<'info>,
716    /// The SPL program account.
717    pub token_program: Program<'info, Token>,
718    /// The Solana system program needed for account creation.
719    pub system_program: Program<'info, System>,
720}
721
722/// Accounts expected in create_unchecked_with_payer and create_unchecked_with_payer_v2 instructions
723#[derive(Accounts)]
724pub struct CreateUncheckedWithPayer<'info> {
725    /// Wallet of the payer account to pay for accounts creation
726    #[account(mut)]
727    pub payer: Signer<'info>,
728    /// Wallet of the contract creator.
729    #[account(mut)]
730    pub sender: Signer<'info>,
731    /// Associated token account address of `sender`.
732    #[account(mut)]
733    pub sender_tokens: AccountInfo<'info>,
734    /// The account holding the contract parameters.
735    /// - create_unchecked_with_payer: expects account initialized with 1104 bytes.
736    /// - create_unchecked_with_payer_v2: a PDA that will be created, use `streamflow_sdk::state::derive_metadata` to derive.
737    ///   Derivation path: `["strm-met", mint, payer, nonce_be_bytes]` (note: uses `payer`, not `sender`)
738    #[account(mut)]
739    pub metadata: AccountInfo<'info>,
740    /// The escrow account holding the funds.
741    /// Should be a PDA, use `streamflow_sdk::state::find_escrow_account` to derive
742    /// Expects empty (non-initialized) account.
743    #[account(mut)]
744    pub escrow_tokens: AccountInfo<'info>,
745    /// Delegate account for automatically withdrawing contracts.
746    /// Use constant `streamflow_sdk::state::WITHDRAWOR_ADDRESS`
747    #[account(mut)]
748    pub withdrawor: AccountInfo<'info>,
749    /// The SPL token mint account.
750    pub mint: Account<'info, Mint>,
751    /// Internal program that handles fees for specified partners. If no partner fees are expected
752    /// on behalf of the program integrating with streamflow, `streamflow_treasury` can be passed
753    /// in here.
754    /// Use constant `streamflow_sdk::state::FEE_ORACLE_ADDRESS`
755    pub fee_oracle: AccountInfo<'info>,
756    /// The Rent Sysvar account.
757    pub rent: Sysvar<'info, Rent>,
758    /// Streamflow protocol (alias timelock) program account.
759    /// Use `streamflow_sdk:id()`
760    pub timelock_program: AccountInfo<'info>,
761    /// The SPL program account.
762    pub token_program: Program<'info, Token>,
763    /// The Solana system program needed for account creation.
764    pub system_program: Program<'info, System>,
765}
766
767/// Accounts expected in update instruction
768#[derive(Accounts)]
769pub struct Update<'info> {
770    /// Wallet that initiates contract update.
771    #[account(mut)]
772    pub sender: Signer<'info>,
773    /// The account holding the contract parameters.
774    /// Expects initialized account.
775    #[account(mut)]
776    pub metadata: AccountInfo<'info>,
777    /// Delegate account for automatically withdrawing contracts.
778    /// Use constant `streamflow_sdk::state::WITHDRAWOR_ADDRESS`
779    #[account(mut)]
780    pub withdrawor: AccountInfo<'info>,
781    pub system_program: Program<'info, System>,
782}
783
784/// Accounts expected in pause instruction
785#[derive(Accounts)]
786pub struct Pause<'info> {
787    #[account()]
788    pub sender: Signer<'info>,
789    #[account(mut)]
790    pub metadata: AccountInfo<'info>,
791}
792
793/// Accounts expected in unpause instruction
794#[derive(Accounts)]
795pub struct UnPause<'info> {
796    #[account()]
797    pub sender: Signer<'info>,
798    #[account(mut)]
799    pub metadata: AccountInfo<'info>,
800}
801
802/// Accounts expected in withdraw instruction
803#[derive(Accounts)]
804pub struct Withdraw<'info> {
805    /// Wallet of the contract withdrawor.
806    #[account(mut)]
807    pub authority: Signer<'info>,
808    #[account(mut)]
809    /// Wallet address of the recipient.
810    pub recipient: AccountInfo<'info>,
811    /// Associated token account address of `recipient`.
812    #[account(mut)]
813    pub recipient_tokens: Account<'info, TokenAccount>,
814    /// The account holding the contract parameters.
815    /// Expects initialized account.
816    #[account(mut)]
817    pub metadata: AccountInfo<'info>,
818    /// The escrow account holding the funds.
819    /// Should be a PDA, use `streamflow_sdk::state::find_escrow_account` to derive
820    /// Expects initialized account.
821    #[account(mut)]
822    pub escrow_tokens: Account<'info, TokenAccount>,
823    /// Streamflow treasury account.
824    /// Use constant `streamflow_sdk::state::STRM_TREASURY`
825    #[account(mut)]
826    pub streamflow_treasury: AccountInfo<'info>,
827    /// Associated token account address of `streamflow_treasury`.
828    #[account(mut)]
829    pub streamflow_treasury_tokens: AccountInfo<'info>,
830    /// Partner treasury account. If no partner fees are expected on behalf of the program
831    /// integrating with streamflow, `streamflow_treasury` can be passed in here.
832    /// Must match partner account in contract metadata.
833    #[account(mut)]
834    pub partner: AccountInfo<'info>,
835    /// Associated token account address of `partner`. If no partner fees are expected on behalf of the
836    /// program integrating with streamflow, `streamflow_treasury_tokens` can be passed in here.
837    /// Must match partner token account in contract metadata.
838    #[account(mut)]
839    pub partner_tokens: AccountInfo<'info>,
840    /// The SPL token mint account.
841    #[account(mut)]
842    pub mint: Account<'info, Mint>,
843    /// The SPL program needed in case an associated account
844    /// for the new recipient is being created.
845    pub token_program: Program<'info, Token>,
846}
847
848/// Accounts expected in cancel instruction
849#[derive(Accounts)]
850pub struct Cancel<'info> {
851    /// Wallet that initiates contract cancel.
852    #[account()]
853    pub authority: Signer<'info>,
854    /// Wallet of the contract creator.
855    #[account(mut)]
856    pub sender: AccountInfo<'info>,
857    /// Associated token account address of `sender`.
858    #[account(mut)]
859    pub sender_tokens: Account<'info, TokenAccount>,
860    /// Wallet address of the recipient.
861    #[account(mut)]
862    pub recipient: AccountInfo<'info>,
863    /// Associated token account address of `recipient`.
864    #[account(mut)]
865    pub recipient_tokens: Account<'info, TokenAccount>,
866    /// The account holding the contract parameters.
867    /// Expects initialized account.
868    #[account(mut)]
869    pub metadata: AccountInfo<'info>,
870    /// The escrow account holding the funds.
871    /// Should be a PDA, use `streamflow_sdk::state::find_escrow_account` to derive
872    /// Expects initialized account.
873    #[account(mut)]
874    pub escrow_tokens: Account<'info, TokenAccount>,
875    /// Streamflow treasury account.
876    /// Use constant `streamflow_sdk::state::STRM_TREASURY`
877    #[account(mut)]
878    pub streamflow_treasury: AccountInfo<'info>,
879    /// Associated token account address of `streamflow_treasury`.
880    #[account(mut)]
881    pub streamflow_treasury_tokens: AccountInfo<'info>,
882    /// Partner treasury account. If no partner fees are expected on behalf of the program
883    /// integrating with streamflow, `streamflow_treasury` can be passed in here. Must match partner
884    /// account in contract metadata.
885    #[account(mut)]
886    pub partner: AccountInfo<'info>,
887    /// Associated token account address of `partner`. If no partner fees are expected on behalf of the
888    /// program integrating with streamflow, `streamflow_treasury_tokens` can be passed in here.
889    /// Must match partner token account in contract metadata.
890    #[account(mut)]
891    pub partner_tokens: AccountInfo<'info>,
892    /// The SPL token mint account.
893    #[account(mut)]
894    pub mint: Account<'info, Mint>,
895    /// The SPL program needed in case an associated account
896    /// for the new recipient is being created.
897    pub token_program: Program<'info, Token>,
898}
899
900/// Accounts expected in transfer instruction
901#[derive(Accounts)]
902pub struct Transfer<'info> {
903    /// Wallet that initiates contract transfer.
904    #[account(mut)]
905    pub authority: Signer<'info>,
906    /// Wallet address of the new contract recipient
907    #[account(mut)]
908    pub new_recipient: AccountInfo<'info>,
909    /// Wallet address of the new contract recipient's token account
910    #[account(mut)]
911    pub new_recipient_tokens: AccountInfo<'info>,
912    /// The account holding the contract parameters.
913    /// Expects initialized account.
914    #[account(mut)]
915    pub metadata: AccountInfo<'info>,
916    /// The SPL token mint account.
917    pub mint: Account<'info, Mint>,
918    /// The Rent Sysvar account.
919    pub rent: Sysvar<'info, Rent>,
920    /// The SPL program needed in case an associated account
921    /// for the new recipient is being created.
922    pub token_program: Program<'info, Token>,
923    /// The Associated Token program needed in case associated
924    /// account for the new recipient is being created.
925    pub associated_token_program: Program<'info, AssociatedToken>,
926    /// The Solana system program needed for account creation.
927    pub system_program: Program<'info, System>,
928}
929
930/// Accounts expected in transfer sender instruction
931#[derive(Accounts)]
932pub struct TransferSender<'info> {
933    /// Wallet of the current contract sender.
934    pub sender: Signer<'info>,
935    /// Wallet address of the new contract sender
936    pub new_sender: Signer<'info>,
937    /// Wallet address of the new contract sender's token account
938    pub new_sender_tokens: AccountInfo<'info>,
939    /// The account holding the contract parameters.
940    /// Expects initialized account.
941    #[account(mut)]
942    pub metadata: AccountInfo<'info>,
943    /// The SPL token mint account.
944    pub mint: Account<'info, Mint>,
945    /// The SPL program needed in case an associated account
946    /// for the new sender is being created.
947    pub token_program: Program<'info, Token>,
948}
949
950/// Accounts expected in topup instruction
951#[derive(Accounts)]
952pub struct Topup<'info> {
953    /// Wallet of the contract creator.
954    #[account(mut)]
955    pub sender: Signer<'info>,
956    /// Associated token account address of `sender`.
957    #[account(mut)]
958    pub sender_tokens: AccountInfo<'info>,
959    /// The account holding the contract parameters.
960    /// Expects initialized account.
961    #[account(mut)]
962    pub metadata: AccountInfo<'info>,
963    /// The escrow account holding the funds.
964    /// Should be a PDA, use `streamflow_sdk::state::find_escrow_account` to derive
965    /// Expects initialized account.
966    #[account(mut)]
967    pub escrow_tokens: Account<'info, TokenAccount>,
968    /// Streamflow treasury account.
969    /// Use constant `streamflow_sdk::state::STRM_TREASURY`
970    #[account(mut)]
971    pub streamflow_treasury: AccountInfo<'info>,
972    /// Associated token account address of `streamflow_treasury`.
973    #[account(mut)]
974    pub streamflow_treasury_tokens: AccountInfo<'info>,
975    /// Delegate account for automatically withdrawing contracts.
976    /// Use constant `streamflow_sdk::state::WITHDRAWOR_ADDRESS`
977    #[account(mut)]
978    pub withdrawor: AccountInfo<'info>,
979    /// Partner treasury account. If no partner fees are expected on behalf of the program
980    /// integrating with streamflow, `streamflow_treasury` can be passed in here. Must match partner
981    /// account in contract metadata.
982    #[account(mut)]
983    pub partner: AccountInfo<'info>,
984    /// Associated token account address of `partner`. If no partner fees are expected on behalf of the
985    /// program integrating with streamflow, `streamflow_treasury_tokens` can be passed in here.
986    /// Must match partner token account in contract metadata.
987    #[account(mut)]
988    pub partner_tokens: AccountInfo<'info>,
989    /// The SPL token mint account.
990    pub mint: Account<'info, Mint>,
991    /// The SPL program needed in case an associated account
992    /// for the new recipient is being created.
993    pub token_program: Program<'info, Token>,
994    /// The Solana system program needed for account creation.
995    pub system_program: Program<'info, System>,
996}