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 /// Transfer a Stream Sender
425 ///
426 /// This method transfer Stream Sender to another Wallet.
427 ///
428 /// # Arguments
429 /// * `ctx` - Accounts that will be used on Stream sender transfer
430 #[allow(unused_variables)]
431 pub fn transfer_sender(ctx: Context<TransferSender>) -> Result<()> {
432 Ok(())
433 }
434
435 /// Topup a Stream
436 ///
437 /// This method tops up a Stream **if it's not closed**
438 ///
439 /// # Arguments
440 /// * `ctx` - Accounts that will be used on Stream unpause
441 /// * `amount` - Amount to Topup a Stream with
442 #[allow(unused_variables)]
443 pub fn topup(ctx: Context<Topup>, amount: u64) -> Result<()> {
444 Ok(())
445 }
446}
447
448/// Accounts expected in create instruction
449#[derive(Accounts)]
450pub struct Create<'info> {
451 /// Wallet of the contract creator.
452 #[account(mut)]
453 pub sender: Signer<'info>,
454 /// Associated token account address of `sender`.
455 #[account(mut)]
456 pub sender_tokens: AccountInfo<'info>,
457 /// Wallet address of the recipient.
458 #[account(mut)]
459 pub recipient: AccountInfo<'info>,
460 /// The account holding the contract parameters.
461 /// Expects empty (non-initialized) account that should also be a signer.
462 #[account(mut, signer)]
463 pub metadata: AccountInfo<'info>,
464 /// The escrow account holding the funds.
465 /// Should be a PDA, use `streamflow_sdk::state::find_escrow_account` to derive
466 /// Expects empty (non-initialized) account.
467 #[account(mut)]
468 pub escrow_tokens: AccountInfo<'info>,
469 /// Associated token account address of `recipient`.
470 #[account(mut)]
471 pub recipient_tokens: AccountInfo<'info>,
472 /// Streamflow treasury account.
473 /// Use constant `streamflow_sdk::state::STRM_TREASURY`
474 #[account(mut)]
475 pub streamflow_treasury: AccountInfo<'info>,
476 /// Associated token account address of `streamflow_treasury`.
477 #[account(mut)]
478 pub streamflow_treasury_tokens: AccountInfo<'info>,
479 /// Delegate account for automatically withdrawing contracts.
480 /// Use constant `streamflow_sdk::state::WITHDRAWOR_ADDRESS`
481 #[account(mut)]
482 pub withdrawor: AccountInfo<'info>,
483 /// Partner treasury account. If no partner fees are expected on behalf of the program
484 /// integrating with streamflow, `streamflow_treasury` can be passed in here.
485 #[account(mut)]
486 pub partner: AccountInfo<'info>,
487 /// Associated token account address of `partner`. If no partner fees are expected on behalf of the
488 /// program integrating with streamflow, `streamflow_treasury_tokens` can be passed in here.
489 #[account(mut)]
490 pub partner_tokens: AccountInfo<'info>,
491 /// The SPL token mint account.
492 pub mint: Account<'info, Mint>,
493 /// Internal program that handles fees for specified partners. If no partner fees are expected
494 /// on behalf of the program integrating with streamflow, `streamflow_treasury` can be passed
495 /// in here.
496 /// Use constant `streamflow_sdk::state::FEE_ORACLE_ADDRESS`
497 pub fee_oracle: AccountInfo<'info>,
498 /// The Rent Sysvar account.
499 pub rent: Sysvar<'info, Rent>,
500 /// Streamflow protocol (alias timelock) program account.
501 /// Use `streamflow_sdk:id()`
502 pub timelock_program: AccountInfo<'info>,
503 /// The SPL program needed in case an associated account
504 /// for the new recipient is being created.
505 pub token_program: Program<'info, Token>,
506 /// The Associated Token program needed in case associated
507 /// account for the new recipient is being created.
508 pub associated_token_program: Program<'info, AssociatedToken>,
509 /// The Solana system program needed for account creation.
510 pub system_program: Program<'info, System>,
511}
512
513/// Accounts expected in create_unchecked instruction
514#[derive(Accounts)]
515pub struct CreateUnchecked<'info> {
516 /// Wallet of the contract creator.
517 #[account(mut)]
518 pub sender: Signer<'info>,
519 /// Associated token account address of `sender` for `mint`.
520 #[account(mut)]
521 pub sender_tokens: AccountInfo<'info>,
522 /// The account holding the contract parameters.
523 /// Expects account initialized with `streamflow_sdk::state::METADATA_LEN` bytes length and assigned program ID.
524 #[account(mut)]
525 pub metadata: AccountInfo<'info>,
526 /// The escrow account holding the funds.
527 /// Should be a PDA, use `streamflow_sdk::state::find_escrow_account` to derive
528 /// Expects empty (non-initialized) account.
529 #[account(mut)]
530 pub escrow_tokens: AccountInfo<'info>,
531 /// Delegate account for automatically withdrawing contracts.
532 /// Use constant `streamflow_sdk::state::WITHDRAWOR_ADDRESS`
533 #[account(mut)]
534 pub withdrawor: AccountInfo<'info>,
535 /// The SPL token mint account.
536 pub mint: Account<'info, Mint>,
537 /// Internal program that handles fees for specified partners. If no partner fees are expected
538 /// on behalf of the program integrating with streamflow, `streamflow_treasury` can be passed
539 /// in here.
540 /// Use constant `streamflow_sdk::state::FEE_ORACLE_ADDRESS`
541 pub fee_oracle: AccountInfo<'info>,
542 /// The Rent Sysvar account.
543 pub rent: Sysvar<'info, Rent>,
544 /// Streamflow protocol (alias timelock) program account.
545 /// Use `streamflow_sdk:id()`
546 pub timelock_program: AccountInfo<'info>,
547 /// The SPL program account.
548 pub token_program: Program<'info, Token>,
549 /// The Solana system program needed for account creation.
550 pub system_program: Program<'info, System>,
551}
552
553/// Accounts expected in create_unchecked instruction
554#[derive(Accounts)]
555pub struct CreateUncheckedWithPayer<'info> {
556 /// Wallet of the payer account to pay for accounts creation
557 #[account(mut)]
558 pub payer: Signer<'info>,
559 /// Wallet of the contract creator.
560 #[account(mut)]
561 pub sender: Signer<'info>,
562 /// Associated token account address of `sender`.
563 #[account(mut)]
564 pub sender_tokens: AccountInfo<'info>,
565 /// The account holding the contract parameters.
566 /// Expects account initialized with 1104 bytes.
567 #[account(mut)]
568 pub metadata: AccountInfo<'info>,
569 /// The escrow account holding the funds.
570 /// Should be a PDA, use `streamflow_sdk::state::find_escrow_account` to derive
571 /// Expects empty (non-initialized) account.
572 #[account(mut)]
573 pub escrow_tokens: AccountInfo<'info>,
574 /// Delegate account for automatically withdrawing contracts.
575 /// Use constant `streamflow_sdk::state::WITHDRAWOR_ADDRESS`
576 #[account(mut)]
577 pub withdrawor: AccountInfo<'info>,
578 /// The SPL token mint account.
579 pub mint: Account<'info, Mint>,
580 /// Internal program that handles fees for specified partners. If no partner fees are expected
581 /// on behalf of the program integrating with streamflow, `streamflow_treasury` can be passed
582 /// in here.
583 /// Use constant `streamflow_sdk::state::FEE_ORACLE_ADDRESS`
584 pub fee_oracle: AccountInfo<'info>,
585 /// The Rent Sysvar account.
586 pub rent: Sysvar<'info, Rent>,
587 /// Streamflow protocol (alias timelock) program account.
588 /// Use `streamflow_sdk:id()`
589 pub timelock_program: AccountInfo<'info>,
590 /// The SPL program account.
591 pub token_program: Program<'info, Token>,
592 /// The Solana system program needed for account creation.
593 pub system_program: Program<'info, System>,
594}
595
596/// Accounts expected in update instruction
597#[derive(Accounts)]
598pub struct Update<'info> {
599 /// Wallet that initiates contract update.
600 #[account(mut)]
601 pub sender: Signer<'info>,
602 /// The account holding the contract parameters.
603 /// Expects initialized account.
604 #[account(mut)]
605 pub metadata: AccountInfo<'info>,
606 /// Delegate account for automatically withdrawing contracts.
607 /// Use constant `streamflow_sdk::state::WITHDRAWOR_ADDRESS`
608 #[account(mut)]
609 pub withdrawor: AccountInfo<'info>,
610 pub system_program: Program<'info, System>,
611}
612
613/// Accounts expected in pause instruction
614#[derive(Accounts)]
615pub struct Pause<'info> {
616 #[account()]
617 pub sender: Signer<'info>,
618 #[account(mut)]
619 pub metadata: AccountInfo<'info>,
620}
621
622/// Accounts expected in unpause instruction
623#[derive(Accounts)]
624pub struct UnPause<'info> {
625 #[account()]
626 pub sender: Signer<'info>,
627 #[account(mut)]
628 pub metadata: AccountInfo<'info>,
629}
630
631/// Accounts expected in withdraw instruction
632#[derive(Accounts)]
633pub struct Withdraw<'info> {
634 /// Wallet of the contract withdrawor.
635 #[account()]
636 pub authority: Signer<'info>,
637 #[account(mut)]
638 /// Wallet address of the recipient.
639 pub recipient: AccountInfo<'info>,
640 /// Associated token account address of `recipient`.
641 #[account(mut)]
642 pub recipient_tokens: Account<'info, TokenAccount>,
643 /// The account holding the contract parameters.
644 /// Expects initialized account.
645 #[account(mut)]
646 pub metadata: AccountInfo<'info>,
647 /// The escrow account holding the funds.
648 /// Should be a PDA, use `streamflow_sdk::state::find_escrow_account` to derive
649 /// Expects initialized account.
650 #[account(mut)]
651 pub escrow_tokens: Account<'info, TokenAccount>,
652 /// Streamflow treasury account.
653 /// Use constant `streamflow_sdk::state::STRM_TREASURY`
654 #[account(mut)]
655 pub streamflow_treasury: AccountInfo<'info>,
656 /// Associated token account address of `streamflow_treasury`.
657 #[account(mut)]
658 pub streamflow_treasury_tokens: AccountInfo<'info>,
659 /// Partner treasury account. If no partner fees are expected on behalf of the program
660 /// integrating with streamflow, `streamflow_treasury` can be passed in here.
661 /// Must match partner account in contract metadata.
662 #[account(mut)]
663 pub partner: AccountInfo<'info>,
664 /// Associated token account address of `partner`. If no partner fees are expected on behalf of the
665 /// program integrating with streamflow, `streamflow_treasury_tokens` can be passed in here.
666 /// Must match partner token account in contract metadata.
667 #[account(mut)]
668 pub partner_tokens: AccountInfo<'info>,
669 /// The SPL token mint account.
670 #[account(mut)]
671 pub mint: Account<'info, Mint>,
672 /// The SPL program needed in case an associated account
673 /// for the new recipient is being created.
674 pub token_program: Program<'info, Token>,
675}
676
677/// Accounts expected in cancel instruction
678#[derive(Accounts)]
679pub struct Cancel<'info> {
680 /// Wallet that initiates contract cancel.
681 #[account()]
682 pub authority: Signer<'info>,
683 /// Wallet of the contract creator.
684 #[account(mut)]
685 pub sender: AccountInfo<'info>,
686 /// Associated token account address of `sender`.
687 #[account(mut)]
688 pub sender_tokens: Account<'info, TokenAccount>,
689 /// Wallet address of the recipient.
690 #[account(mut)]
691 pub recipient: AccountInfo<'info>,
692 /// Associated token account address of `recipient`.
693 #[account(mut)]
694 pub recipient_tokens: Account<'info, TokenAccount>,
695 /// The account holding the contract parameters.
696 /// Expects initialized account.
697 #[account(mut)]
698 pub metadata: AccountInfo<'info>,
699 /// The escrow account holding the funds.
700 /// Should be a PDA, use `streamflow_sdk::state::find_escrow_account` to derive
701 /// Expects initialized account.
702 #[account(mut)]
703 pub escrow_tokens: Account<'info, TokenAccount>,
704 /// Streamflow treasury account.
705 /// Use constant `streamflow_sdk::state::STRM_TREASURY`
706 #[account(mut)]
707 pub streamflow_treasury: AccountInfo<'info>,
708 /// Associated token account address of `streamflow_treasury`.
709 #[account(mut)]
710 pub streamflow_treasury_tokens: AccountInfo<'info>,
711 /// Partner treasury account. If no partner fees are expected on behalf of the program
712 /// integrating with streamflow, `streamflow_treasury` can be passed in here. Must match partner
713 /// account in contract metadata.
714 #[account(mut)]
715 pub partner: AccountInfo<'info>,
716 /// Associated token account address of `partner`. If no partner fees are expected on behalf of the
717 /// program integrating with streamflow, `streamflow_treasury_tokens` can be passed in here.
718 /// Must match partner token account in contract metadata.
719 #[account(mut)]
720 pub partner_tokens: AccountInfo<'info>,
721 /// The SPL token mint account.
722 #[account(mut)]
723 pub mint: Account<'info, Mint>,
724 /// The SPL program needed in case an associated account
725 /// for the new recipient is being created.
726 pub token_program: Program<'info, Token>,
727}
728
729/// Accounts expected in transfer instruction
730#[derive(Accounts)]
731pub struct Transfer<'info> {
732 /// Wallet that initiates contract transfer.
733 #[account(mut)]
734 pub authority: Signer<'info>,
735 /// Wallet address of the new contract recipient
736 #[account(mut)]
737 pub new_recipient: AccountInfo<'info>,
738 /// Wallet address of the new contract recipient's token account
739 #[account(mut)]
740 pub new_recipient_tokens: AccountInfo<'info>,
741 /// The account holding the contract parameters.
742 /// Expects initialized account.
743 #[account(mut)]
744 pub metadata: AccountInfo<'info>,
745 /// The SPL token mint account.
746 pub mint: Account<'info, Mint>,
747 /// The Rent Sysvar account.
748 pub rent: Sysvar<'info, Rent>,
749 /// The SPL program needed in case an associated account
750 /// for the new recipient is being created.
751 pub token_program: Program<'info, Token>,
752 /// The Associated Token program needed in case associated
753 /// account for the new recipient is being created.
754 pub associated_token_program: Program<'info, AssociatedToken>,
755 /// The Solana system program needed for account creation.
756 pub system_program: Program<'info, System>,
757}
758
759/// Accounts expected in transfer sender instruction
760#[derive(Accounts)]
761pub struct TransferSender<'info> {
762 /// Wallet of the current contract sender.
763 pub sender: Signer<'info>,
764 /// Wallet address of the new contract sender
765 pub new_sender: Signer<'info>,
766 /// Wallet address of the new contract sender's token account
767 pub new_sender_tokens: AccountInfo<'info>,
768 /// The account holding the contract parameters.
769 /// Expects initialized account.
770 #[account(mut)]
771 pub metadata: AccountInfo<'info>,
772 /// The SPL token mint account.
773 pub mint: Account<'info, Mint>,
774 /// The SPL program needed in case an associated account
775 /// for the new sender is being created.
776 pub token_program: Program<'info, Token>,
777}
778
779/// Accounts expected in topup instruction
780#[derive(Accounts)]
781pub struct Topup<'info> {
782 /// Wallet of the contract creator.
783 #[account(mut)]
784 pub sender: Signer<'info>,
785 /// Associated token account address of `sender`.
786 #[account(mut)]
787 pub sender_tokens: AccountInfo<'info>,
788 /// The account holding the contract parameters.
789 /// Expects initialized account.
790 #[account(mut)]
791 pub metadata: AccountInfo<'info>,
792 /// The escrow account holding the funds.
793 /// Should be a PDA, use `streamflow_sdk::state::find_escrow_account` to derive
794 /// Expects initialized account.
795 #[account(mut)]
796 pub escrow_tokens: Account<'info, TokenAccount>,
797 /// Streamflow treasury account.
798 /// Use constant `streamflow_sdk::state::STRM_TREASURY`
799 #[account(mut)]
800 pub streamflow_treasury: AccountInfo<'info>,
801 /// Associated token account address of `streamflow_treasury`.
802 #[account(mut)]
803 pub streamflow_treasury_tokens: AccountInfo<'info>,
804 /// Delegate account for automatically withdrawing contracts.
805 /// Use constant `streamflow_sdk::state::WITHDRAWOR_ADDRESS`
806 #[account(mut)]
807 pub withdrawor: AccountInfo<'info>,
808 /// Partner treasury account. If no partner fees are expected on behalf of the program
809 /// integrating with streamflow, `streamflow_treasury` can be passed in here. Must match partner
810 /// account in contract metadata.
811 #[account(mut)]
812 pub partner: AccountInfo<'info>,
813 /// Associated token account address of `partner`. If no partner fees are expected on behalf of the
814 /// program integrating with streamflow, `streamflow_treasury_tokens` can be passed in here.
815 /// Must match partner token account in contract metadata.
816 #[account(mut)]
817 pub partner_tokens: AccountInfo<'info>,
818 /// The SPL token mint account.
819 pub mint: Account<'info, Mint>,
820 /// The SPL program needed in case an associated account
821 /// for the new recipient is being created.
822 pub token_program: Program<'info, Token>,
823 /// The Solana system program needed for account creation.
824 pub system_program: Program<'info, System>,
825}