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    #[allow(unused_variables)]
517    pub fn update(
518        ctx: Context<Update>,
519        enable_automatic_withdrawal: Option<bool>,
520        withdraw_frequency: Option<u64>,
521        amount_per_period: Option<u64>,
522        transferable_by_sender: Option<bool>,
523        transferable_by_recipient: Option<bool>,
524        cancelable_by_sender: Option<bool>,
525    ) -> Result<()> {
526        Ok(())
527    }
528
529    /// Withdraw tokens from a Stream
530    ///
531    /// This methods withdraws tokens from a Stream, requested amount of tokens will be sent to the Recipient
532    /// If `enable_automatic_withdrawal` is set to false only Recipient can request a Withdrawal
533    ///
534    /// # Arguments
535    /// * `ctx` - Accounts that will be used on Stream withdrawal
536    /// * `amount` - amount to withdraw, should <= unlocked amount. Use `u64::MAX` if you want to withdraw all unlocked amount
537    #[allow(unused_variables)]
538    pub fn withdraw(ctx: Context<Withdraw>, amount: u64) -> Result<()> {
539        Ok(())
540    }
541
542    /// Cancel a Stream
543    ///
544    /// Cancels a stream, withdraws all unlocked amount to Recipient and returns all leftover tokens back to Sender
545    ///
546    /// # Arguments
547    /// * `ctx` - Accounts that will be used on Stream cancellation
548    #[allow(unused_variables)]
549    pub fn cancel(ctx: Context<Cancel>) -> Result<()> {
550        Ok(())
551    }
552
553    /// Pause a Stream
554    ///
555    /// This method pauses a Stream, meaning that no unlocks will be processed, only already unlocked amount can be withdrawn
556    ///
557    /// # Arguments
558    /// * `ctx` - Accounts that will be used on Stream pause
559    #[allow(unused_variables)]
560    pub fn pause(ctx: Context<Pause>) -> Result<()> {
561        Ok(())
562    }
563
564    /// Unpause a Stream
565    ///
566    /// This method unpauses a paused Stream
567    ///
568    /// # Arguments
569    /// * `ctx` - Accounts that will be used on Stream unpause
570    #[allow(unused_variables)]
571    pub fn unpause(ctx: Context<UnPause>) -> Result<()> {
572        Ok(())
573    }
574
575    /// Transfer a Stream
576    ///
577    /// This method transfer Stream to another Recipient, already unlocked amount **won't** be sent to the old Recipient
578    /// Because of that this method can be effectively used when if you chose wrong Recipient on Stream creation
579    ///
580    /// # Arguments
581    /// * `ctx` - Accounts that will be used on Stream transfer
582    #[allow(unused_variables)]
583    pub fn transfer_recipient(ctx: Context<Transfer>) -> Result<()> {
584        Ok(())
585    }
586
587    /// Transfer a Stream Sender
588    ///
589    /// This method transfer Stream Sender to another Wallet.
590    ///
591    /// # Arguments
592    /// * `ctx` - Accounts that will be used on Stream sender transfer
593    #[allow(unused_variables)]
594    pub fn transfer_sender(ctx: Context<TransferSender>) -> Result<()> {
595        Ok(())
596    }
597
598    /// Topup a Stream
599    ///
600    /// This method tops up a Stream **if it's not closed**
601    ///
602    /// # Arguments
603    /// * `ctx` - Accounts that will be used on Stream unpause
604    /// * `amount` - Amount to Topup a Stream with
605    #[allow(unused_variables)]
606    pub fn topup(ctx: Context<Topup>, amount: u64) -> Result<()> {
607        Ok(())
608    }
609}
610
611/// Accounts expected in create and create_v2 instructions
612#[derive(Accounts)]
613pub struct Create<'info> {
614    /// Wallet of the contract creator.
615    #[account(mut)]
616    pub sender: Signer<'info>,
617    /// Associated token account address of `sender`.
618    #[account(mut)]
619    pub sender_tokens: AccountInfo<'info>,
620    /// Wallet address of the recipient.
621    #[account(mut)]
622    pub recipient: AccountInfo<'info>,
623    /// The account holding the contract parameters.
624    /// - create: should be an ephemeral signer;
625    /// - create_v2: a PDA, use `streamflow_sdk::state::derive_metadata` to derive.
626    ///   Derivation path: `["strm-met", mint, sender, nonce_be_bytes]`
627    #[account(mut)]
628    pub metadata: AccountInfo<'info>,
629    /// The escrow account holding the funds.
630    /// Should be a PDA, use `streamflow_sdk::state::find_escrow_account` to derive
631    /// Expects empty (non-initialized) account.
632    #[account(mut)]
633    pub escrow_tokens: AccountInfo<'info>,
634    /// Associated token account address of `recipient`.
635    #[account(mut)]
636    pub recipient_tokens: AccountInfo<'info>,
637    /// Streamflow treasury account.
638    /// Use constant `streamflow_sdk::state::STRM_TREASURY`
639    #[account(mut)]
640    pub streamflow_treasury: AccountInfo<'info>,
641    /// Associated token account address of `streamflow_treasury`.
642    #[account(mut)]
643    pub streamflow_treasury_tokens: AccountInfo<'info>,
644    /// Delegate account for automatically withdrawing contracts.
645    /// Use constant `streamflow_sdk::state::WITHDRAWOR_ADDRESS`
646    #[account(mut)]
647    pub withdrawor: AccountInfo<'info>,
648    /// Partner treasury account. If no partner fees are expected on behalf of the program
649    /// integrating with streamflow, `streamflow_treasury` can be passed in here.
650    #[account(mut)]
651    pub partner: AccountInfo<'info>,
652    /// Associated token account address of `partner`. If no partner fees are expected on behalf of the
653    /// program integrating with streamflow, `streamflow_treasury_tokens` can be passed in here.
654    #[account(mut)]
655    pub partner_tokens: AccountInfo<'info>,
656    /// The SPL token mint account.
657    pub mint: Account<'info, Mint>,
658    /// Internal program that handles fees for specified partners. If no partner fees are expected
659    /// on behalf of the program integrating with streamflow, `streamflow_treasury` can be passed
660    /// in here.
661    /// Use constant `streamflow_sdk::state::FEE_ORACLE_ADDRESS`
662    pub fee_oracle: AccountInfo<'info>,
663    /// The Rent Sysvar account.
664    pub rent: Sysvar<'info, Rent>,
665    /// Streamflow protocol (alias timelock) program account.
666    /// Use `streamflow_sdk:id()`
667    pub timelock_program: AccountInfo<'info>,
668    /// The SPL program needed in case an associated account
669    /// for the new recipient is being created.
670    pub token_program: Program<'info, Token>,
671    /// The Associated Token program needed in case associated
672    /// account for the new recipient is being created.
673    pub associated_token_program: Program<'info, AssociatedToken>,
674    /// The Solana system program needed for account creation.
675    pub system_program: Program<'info, System>,
676}
677
678/// Accounts expected in create_unchecked and create_unchecked_v2 instructions
679#[derive(Accounts)]
680pub struct CreateUnchecked<'info> {
681    /// Wallet of the contract creator.
682    #[account(mut)]
683    pub sender: Signer<'info>,
684    /// Associated token account address of `sender` for `mint`.
685    #[account(mut)]
686    pub sender_tokens: AccountInfo<'info>,
687    /// The account holding the contract parameters.
688    /// - create_unchecked: expects account initialized with `streamflow_sdk::state::METADATA_LEN` bytes length and assigned program ID.
689    /// - create_unchecked_v2: a PDA that will be created, use `streamflow_sdk::state::derive_metadata` to derive.
690    ///   Derivation path: `["strm-met", mint, sender, nonce_be_bytes]`
691    #[account(mut)]
692    pub metadata: AccountInfo<'info>,
693    /// The escrow account holding the funds.
694    /// Should be a PDA, use `streamflow_sdk::state::find_escrow_account` to derive
695    /// Expects empty (non-initialized) account.
696    #[account(mut)]
697    pub escrow_tokens: AccountInfo<'info>,
698    /// Delegate account for automatically withdrawing contracts.
699    /// Use constant `streamflow_sdk::state::WITHDRAWOR_ADDRESS`
700    #[account(mut)]
701    pub withdrawor: AccountInfo<'info>,
702    /// The SPL token mint account.
703    pub mint: Account<'info, Mint>,
704    /// Internal program that handles fees for specified partners. If no partner fees are expected
705    /// on behalf of the program integrating with streamflow, `streamflow_treasury` can be passed
706    /// in here.
707    /// Use constant `streamflow_sdk::state::FEE_ORACLE_ADDRESS`
708    pub fee_oracle: AccountInfo<'info>,
709    /// The Rent Sysvar account.
710    pub rent: Sysvar<'info, Rent>,
711    /// Streamflow protocol (alias timelock) program account.
712    /// Use `streamflow_sdk:id()`
713    pub timelock_program: AccountInfo<'info>,
714    /// The SPL program account.
715    pub token_program: Program<'info, Token>,
716    /// The Solana system program needed for account creation.
717    pub system_program: Program<'info, System>,
718}
719
720/// Accounts expected in create_unchecked_with_payer and create_unchecked_with_payer_v2 instructions
721#[derive(Accounts)]
722pub struct CreateUncheckedWithPayer<'info> {
723    /// Wallet of the payer account to pay for accounts creation
724    #[account(mut)]
725    pub payer: Signer<'info>,
726    /// Wallet of the contract creator.
727    #[account(mut)]
728    pub sender: Signer<'info>,
729    /// Associated token account address of `sender`.
730    #[account(mut)]
731    pub sender_tokens: AccountInfo<'info>,
732    /// The account holding the contract parameters.
733    /// - create_unchecked_with_payer: expects account initialized with 1104 bytes.
734    /// - create_unchecked_with_payer_v2: a PDA that will be created, use `streamflow_sdk::state::derive_metadata` to derive.
735    ///   Derivation path: `["strm-met", mint, payer, nonce_be_bytes]` (note: uses `payer`, not `sender`)
736    #[account(mut)]
737    pub metadata: AccountInfo<'info>,
738    /// The escrow account holding the funds.
739    /// Should be a PDA, use `streamflow_sdk::state::find_escrow_account` to derive
740    /// Expects empty (non-initialized) account.
741    #[account(mut)]
742    pub escrow_tokens: AccountInfo<'info>,
743    /// Delegate account for automatically withdrawing contracts.
744    /// Use constant `streamflow_sdk::state::WITHDRAWOR_ADDRESS`
745    #[account(mut)]
746    pub withdrawor: AccountInfo<'info>,
747    /// The SPL token mint account.
748    pub mint: Account<'info, Mint>,
749    /// Internal program that handles fees for specified partners. If no partner fees are expected
750    /// on behalf of the program integrating with streamflow, `streamflow_treasury` can be passed
751    /// in here.
752    /// Use constant `streamflow_sdk::state::FEE_ORACLE_ADDRESS`
753    pub fee_oracle: AccountInfo<'info>,
754    /// The Rent Sysvar account.
755    pub rent: Sysvar<'info, Rent>,
756    /// Streamflow protocol (alias timelock) program account.
757    /// Use `streamflow_sdk:id()`
758    pub timelock_program: AccountInfo<'info>,
759    /// The SPL program account.
760    pub token_program: Program<'info, Token>,
761    /// The Solana system program needed for account creation.
762    pub system_program: Program<'info, System>,
763}
764
765/// Accounts expected in update instruction
766#[derive(Accounts)]
767pub struct Update<'info> {
768    /// Wallet that initiates contract update.
769    #[account(mut)]
770    pub sender: Signer<'info>,
771    /// The account holding the contract parameters.
772    /// Expects initialized account.
773    #[account(mut)]
774    pub metadata: AccountInfo<'info>,
775    /// Delegate account for automatically withdrawing contracts.
776    /// Use constant `streamflow_sdk::state::WITHDRAWOR_ADDRESS`
777    #[account(mut)]
778    pub withdrawor: AccountInfo<'info>,
779    pub system_program: Program<'info, System>,
780}
781
782/// Accounts expected in pause instruction
783#[derive(Accounts)]
784pub struct Pause<'info> {
785    #[account()]
786    pub sender: Signer<'info>,
787    #[account(mut)]
788    pub metadata: AccountInfo<'info>,
789}
790
791/// Accounts expected in unpause instruction
792#[derive(Accounts)]
793pub struct UnPause<'info> {
794    #[account()]
795    pub sender: Signer<'info>,
796    #[account(mut)]
797    pub metadata: AccountInfo<'info>,
798}
799
800/// Accounts expected in withdraw instruction
801#[derive(Accounts)]
802pub struct Withdraw<'info> {
803    /// Wallet of the contract withdrawor.
804    #[account()]
805    pub authority: Signer<'info>,
806    #[account(mut)]
807    /// Wallet address of the recipient.
808    pub recipient: AccountInfo<'info>,
809    /// Associated token account address of `recipient`.
810    #[account(mut)]
811    pub recipient_tokens: Account<'info, TokenAccount>,
812    /// The account holding the contract parameters.
813    /// Expects initialized account.
814    #[account(mut)]
815    pub metadata: AccountInfo<'info>,
816    /// The escrow account holding the funds.
817    /// Should be a PDA, use `streamflow_sdk::state::find_escrow_account` to derive
818    /// Expects initialized account.
819    #[account(mut)]
820    pub escrow_tokens: Account<'info, TokenAccount>,
821    /// Streamflow treasury account.
822    /// Use constant `streamflow_sdk::state::STRM_TREASURY`
823    #[account(mut)]
824    pub streamflow_treasury: AccountInfo<'info>,
825    /// Associated token account address of `streamflow_treasury`.
826    #[account(mut)]
827    pub streamflow_treasury_tokens: AccountInfo<'info>,
828    /// Partner treasury account. If no partner fees are expected on behalf of the program
829    /// integrating with streamflow, `streamflow_treasury` can be passed in here.
830    /// Must match partner account in contract metadata.
831    #[account(mut)]
832    pub partner: AccountInfo<'info>,
833    /// Associated token account address of `partner`. If no partner fees are expected on behalf of the
834    /// program integrating with streamflow, `streamflow_treasury_tokens` can be passed in here.
835    /// Must match partner token account in contract metadata.
836    #[account(mut)]
837    pub partner_tokens: AccountInfo<'info>,
838    /// The SPL token mint account.
839    #[account(mut)]
840    pub mint: Account<'info, Mint>,
841    /// The SPL program needed in case an associated account
842    /// for the new recipient is being created.
843    pub token_program: Program<'info, Token>,
844}
845
846/// Accounts expected in cancel instruction
847#[derive(Accounts)]
848pub struct Cancel<'info> {
849    /// Wallet that initiates contract cancel.
850    #[account()]
851    pub authority: Signer<'info>,
852    /// Wallet of the contract creator.
853    #[account(mut)]
854    pub sender: AccountInfo<'info>,
855    /// Associated token account address of `sender`.
856    #[account(mut)]
857    pub sender_tokens: Account<'info, TokenAccount>,
858    /// Wallet address of the recipient.
859    #[account(mut)]
860    pub recipient: AccountInfo<'info>,
861    /// Associated token account address of `recipient`.
862    #[account(mut)]
863    pub recipient_tokens: Account<'info, TokenAccount>,
864    /// The account holding the contract parameters.
865    /// Expects initialized account.
866    #[account(mut)]
867    pub metadata: AccountInfo<'info>,
868    /// The escrow account holding the funds.
869    /// Should be a PDA, use `streamflow_sdk::state::find_escrow_account` to derive
870    /// Expects initialized account.
871    #[account(mut)]
872    pub escrow_tokens: Account<'info, TokenAccount>,
873    /// Streamflow treasury account.
874    /// Use constant `streamflow_sdk::state::STRM_TREASURY`
875    #[account(mut)]
876    pub streamflow_treasury: AccountInfo<'info>,
877    /// Associated token account address of `streamflow_treasury`.
878    #[account(mut)]
879    pub streamflow_treasury_tokens: AccountInfo<'info>,
880    /// Partner treasury account. If no partner fees are expected on behalf of the program
881    /// integrating with streamflow, `streamflow_treasury` can be passed in here. Must match partner
882    /// account in contract metadata.
883    #[account(mut)]
884    pub partner: AccountInfo<'info>,
885    /// Associated token account address of `partner`. If no partner fees are expected on behalf of the
886    /// program integrating with streamflow, `streamflow_treasury_tokens` can be passed in here.
887    /// Must match partner token account in contract metadata.
888    #[account(mut)]
889    pub partner_tokens: AccountInfo<'info>,
890    /// The SPL token mint account.
891    #[account(mut)]
892    pub mint: Account<'info, Mint>,
893    /// The SPL program needed in case an associated account
894    /// for the new recipient is being created.
895    pub token_program: Program<'info, Token>,
896}
897
898/// Accounts expected in transfer instruction
899#[derive(Accounts)]
900pub struct Transfer<'info> {
901    /// Wallet that initiates contract transfer.
902    #[account(mut)]
903    pub authority: Signer<'info>,
904    /// Wallet address of the new contract recipient
905    #[account(mut)]
906    pub new_recipient: AccountInfo<'info>,
907    /// Wallet address of the new contract recipient's token account
908    #[account(mut)]
909    pub new_recipient_tokens: AccountInfo<'info>,
910    /// The account holding the contract parameters.
911    /// Expects initialized account.
912    #[account(mut)]
913    pub metadata: AccountInfo<'info>,
914    /// The SPL token mint account.
915    pub mint: Account<'info, Mint>,
916    /// The Rent Sysvar account.
917    pub rent: Sysvar<'info, Rent>,
918    /// The SPL program needed in case an associated account
919    /// for the new recipient is being created.
920    pub token_program: Program<'info, Token>,
921    /// The Associated Token program needed in case associated
922    /// account for the new recipient is being created.
923    pub associated_token_program: Program<'info, AssociatedToken>,
924    /// The Solana system program needed for account creation.
925    pub system_program: Program<'info, System>,
926}
927
928/// Accounts expected in transfer sender instruction
929#[derive(Accounts)]
930pub struct TransferSender<'info> {
931    /// Wallet of the current contract sender.
932    pub sender: Signer<'info>,
933    /// Wallet address of the new contract sender
934    pub new_sender: Signer<'info>,
935    /// Wallet address of the new contract sender's token account
936    pub new_sender_tokens: AccountInfo<'info>,
937    /// The account holding the contract parameters.
938    /// Expects initialized account.
939    #[account(mut)]
940    pub metadata: AccountInfo<'info>,
941    /// The SPL token mint account.
942    pub mint: Account<'info, Mint>,
943    /// The SPL program needed in case an associated account
944    /// for the new sender is being created.
945    pub token_program: Program<'info, Token>,
946}
947
948/// Accounts expected in topup instruction
949#[derive(Accounts)]
950pub struct Topup<'info> {
951    /// Wallet of the contract creator.
952    #[account(mut)]
953    pub sender: Signer<'info>,
954    /// Associated token account address of `sender`.
955    #[account(mut)]
956    pub sender_tokens: AccountInfo<'info>,
957    /// The account holding the contract parameters.
958    /// Expects initialized account.
959    #[account(mut)]
960    pub metadata: AccountInfo<'info>,
961    /// The escrow account holding the funds.
962    /// Should be a PDA, use `streamflow_sdk::state::find_escrow_account` to derive
963    /// Expects initialized account.
964    #[account(mut)]
965    pub escrow_tokens: Account<'info, TokenAccount>,
966    /// Streamflow treasury account.
967    /// Use constant `streamflow_sdk::state::STRM_TREASURY`
968    #[account(mut)]
969    pub streamflow_treasury: AccountInfo<'info>,
970    /// Associated token account address of `streamflow_treasury`.
971    #[account(mut)]
972    pub streamflow_treasury_tokens: AccountInfo<'info>,
973    /// Delegate account for automatically withdrawing contracts.
974    /// Use constant `streamflow_sdk::state::WITHDRAWOR_ADDRESS`
975    #[account(mut)]
976    pub withdrawor: AccountInfo<'info>,
977    /// Partner treasury account. If no partner fees are expected on behalf of the program
978    /// integrating with streamflow, `streamflow_treasury` can be passed in here. Must match partner
979    /// account in contract metadata.
980    #[account(mut)]
981    pub partner: AccountInfo<'info>,
982    /// Associated token account address of `partner`. If no partner fees are expected on behalf of the
983    /// program integrating with streamflow, `streamflow_treasury_tokens` can be passed in here.
984    /// Must match partner token account in contract metadata.
985    #[account(mut)]
986    pub partner_tokens: AccountInfo<'info>,
987    /// The SPL token mint account.
988    pub mint: Account<'info, Mint>,
989    /// The SPL program needed in case an associated account
990    /// for the new recipient is being created.
991    pub token_program: Program<'info, Token>,
992    /// The Solana system program needed for account creation.
993    pub system_program: Program<'info, System>,
994}