streamflow_sdk/
lib.rs

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