streamflow_sdk/state.rs
1use anchor_lang::prelude::*;
2
3/// Streamflow Treasury address, by default receives 0.25% of tokens deposited
4pub const STRM_TREASURY: &str = "5SEpbdjFK5FxwTvfsGMXVQTD2v4M2c5tyRTxhdsPkgDw";
5/// Streamflow Withdrawor address, this account will process withdrawals
6pub const WITHDRAWOR_ADDRESS: &str = "wdrwhnCv4pzW8beKsbPa4S2UDZrXenjg16KJdKSpb5u";
7/// Address of Fee Oracle that stores information about fees for speficic partners
8pub const FEE_ORACLE_ADDRESS: &str = "B743wFVk2pCYhV91cn287e1xY7f1vt4gdY48hhNiuQmT";
9
10/// Prefix used to derive Escrow account address
11pub const ESCROW_SEED_PREFIX: &[u8] = b"strm";
12/// Size of Stream metadata
13pub const METADATA_LEN: usize = 1104;
14
15/// You can also use id that sdk exposes like so streamflow_sdk::id()
16pub const STREAMFLOW_PROGRAM_ID: &str = "strmRqUCoQUgGUan5YhzUZa6KqdzwX5L6FpUxfmKg5m";
17pub const STREAMFLOW_DEVNET_PROGRAM_ID: &str = "HqDGZjaVRXJ9MGRQEw7qDc2rAr6iH1n1kAQdCZaCMfMZ";
18
19pub fn find_escrow_account(seed: &[u8], pid: &Pubkey) -> (Pubkey, u8) {
20 Pubkey::find_program_address(&[ESCROW_SEED_PREFIX, seed], pid)
21}
22
23/// The struct containing parameters for initializing a stream
24#[derive(AnchorSerialize, AnchorDeserialize, Clone, Debug)]
25#[repr(C)]
26pub struct CreateParams {
27 /// Timestamp when the tokens start vesting
28 pub start_time: u64,
29 /// Deposited amount of tokens
30 pub net_amount_deposited: u64,
31 /// Time step (period) in seconds per which the vesting/release occurs
32 pub period: u64,
33 /// Amount released per period. Combined with `period`, we get a release rate.
34 pub amount_per_period: u64,
35 /// Vesting contract "cliff" timestamp
36 pub cliff: u64,
37 /// Amount unlocked at the "cliff" timestamp
38 pub cliff_amount: u64,
39 /// Whether a stream can be canceled by a sender
40 pub cancelable_by_sender: bool,
41 /// Whether a stream can be canceled by a recipient
42 pub cancelable_by_recipient: bool,
43 /// Whether a 3rd party can initiate withdraw in the name of recipient
44 pub automatic_withdrawal: bool,
45 /// Whether the sender can transfer the stream
46 pub transferable_by_sender: bool,
47 /// Whether the recipient can transfer the stream
48 pub transferable_by_recipient: bool,
49 /// Whether topup is enabled
50 pub can_topup: bool,
51 /// The name of this stream
52 pub stream_name: [u8; 64],
53 /// Withdraw frequency
54 pub withdraw_frequency: u64,
55 /// used as padding len in serialization in old streams, added for backwards compatibility
56 pub ghost: u32,
57 /// Whether the contract can be paused
58 pub pausable: bool,
59 /// Whether the contract can update release amount
60 pub can_update_rate: bool,
61}
62
63/// Struct that represents Stream Contract stored on chain, this account **DOES NOT** have a discriminator.
64///
65/// May be read like so
66///
67/// ```rust
68/// let stream_metadata: Contract = match try_from_slice_unchecked(&stream_data) {
69/// Ok(v) => v,
70/// Err(_) => return err!(ErrorCode::InvalidStreamMetadata),
71/// };
72/// ```
73#[derive(AnchorSerialize, AnchorDeserialize, Clone, Debug)]
74#[repr(C)]
75pub struct Contract {
76 /// Magic bytes
77 pub magic: u64,
78 /// Version of the program
79 pub version: u8,
80 /// Timestamp when stream was created
81 pub created_at: u64,
82 /// Amount of funds withdrawn
83 pub amount_withdrawn: u64,
84 /// Timestamp when stream was canceled (if canceled)
85 pub canceled_at: u64,
86 /// Timestamp at which stream can be safely canceled by a 3rd party
87 /// (Stream is either fully vested or there isn't enough capital to
88 /// keep it active)
89 pub end_time: u64,
90 /// Timestamp of the last withdrawal
91 pub last_withdrawn_at: u64,
92 /// Pubkey of the stream initializer
93 pub sender: Pubkey,
94 /// Pubkey of the stream initializer's token account
95 pub sender_tokens: Pubkey,
96 /// Pubkey of the stream recipient
97 pub recipient: Pubkey,
98 /// Pubkey of the stream recipient's token account
99 pub recipient_tokens: Pubkey,
100 /// Pubkey of the token mint
101 pub mint: Pubkey,
102 /// Escrow account holding the locked tokens for recipient
103 pub escrow_tokens: Pubkey,
104 /// Streamflow treasury authority
105 pub streamflow_treasury: Pubkey,
106 /// Escrow account holding the locked tokens for Streamflow (fee account)
107 pub streamflow_treasury_tokens: Pubkey,
108 /// The total fee amount for streamflow
109 pub streamflow_fee_total: u64,
110 /// The withdrawn fee amount for streamflow
111 pub streamflow_fee_withdrawn: u64,
112 /// Fee percentage for Streamflow
113 pub streamflow_fee_percent: f32,
114 /// Streamflow partner authority
115 pub partner: Pubkey,
116 /// Escrow account holding the locked tokens for Streamflow partner (fee account)
117 pub partner_tokens: Pubkey,
118 /// The total fee amount for the partner
119 pub partner_fee_total: u64,
120 /// The withdrawn fee amount for the partner
121 pub partner_fee_withdrawn: u64,
122 /// Fee percentage for partner
123 pub partner_fee_percent: f32,
124 /// The stream instruction
125 pub ix: CreateParams,
126 /// Padding for `ix: CreateParams` to allow for future upgrades.
127 pub ix_padding: Vec<u8>,
128 /// Stream is closed
129 pub closed: bool,
130 /// time of the current pause. 0 signifies unpaused state
131 pub current_pause_start: u64,
132 /// total time the contract was paused for
133 pub pause_cumulative: u64,
134 /// timestamp of last rate change for this stream.
135 /// Rate can be changed with `update` instruction
136 pub last_rate_change_time: u64,
137 /// Accumulated unlocked tokens before last rate change (excluding cliff_amount)
138 pub funds_unlocked_at_last_rate_change: u64,
139}