@@ -5,14 +5,19 @@ use anchor_lang::prelude::*;
55/* This struct will be used for both registering and updating the state account */
66#[ derive( AnchorSerialize , AnchorDeserialize , Clone ) ]
77pub struct GenericStateInput {
8+ // an account that can update the `output_yield_accounts` and `spend_proportions`
89 pub update_authority : Pubkey ,
10+ // a vector of accounts to which we will send yields to
911 pub output_yield_accounts : Vec < Pubkey > ,
10- pub spend_proportions : Vec < u8 > , // sum to 100
12+ // proportions of sum to send to each of the accounts in `output_yield_accounts` (sum to 100)
13+ pub spend_proportions : Vec < u8 > ,
14+ // minimum threshold of yield in input_yield_account before it is allowed to send funds
1115 pub spend_threshold : u64 ,
1216}
1317
1418#[ account]
1519pub struct State {
20+ // the state account holding all the configs from GenericStateInput and the info of total yields spent
1621 pub sunrise_state : Pubkey ,
1722 pub update_authority : Pubkey ,
1823 pub output_yield_accounts : Vec < Pubkey > ,
@@ -24,6 +29,7 @@ pub struct State {
2429
2530impl State {
2631 pub fn space ( output_yield_account_count : u8 ) -> usize {
32+ // find space needed for state account for current config
2733 32 + 32
2834 + ( 32 * output_yield_account_count as usize )
2935 + 4
@@ -39,6 +45,7 @@ impl State {
3945#[ derive( Accounts ) ]
4046#[ instruction( sunrise_state: Pubkey , state_in: GenericStateInput ) ]
4147pub struct RegisterState < ' info > {
48+ // to be used for registering state account on chain, only need to ever be done once
4249 #[ account( mut ) ]
4350 pub payer : Signer < ' info > ,
4451 #[ account(
@@ -61,11 +68,13 @@ pub struct RegisterState<'info> {
6168#[ derive( Accounts ) ]
6269#[ instruction( state_in: GenericStateInput ) ]
6370pub struct UpdateState < ' info > {
71+ // to be used for updating parameters of state account
6472 #[ account( mut ) ]
6573 pub payer : Signer < ' info > ,
6674 #[ account(
6775 mut ,
6876 constraint = state. update_authority == payer. key( ) @ ErrorCode :: Unauthorized ,
77+ // resize the state account if necessary
6978 realloc = State :: space( state_in. output_yield_accounts. len( ) as u8 ) ,
7079 realloc:: payer = payer,
7180 realloc:: zero = false ,
@@ -77,6 +86,7 @@ pub struct UpdateState<'info> {
7786#[ derive( Accounts ) ]
7887#[ instruction( amount: u64 ) ]
7988pub struct AllocateYield < ' info > {
89+ // to allocate correct yield proportion to various output_yield_accounts
8090 #[ account( mut ) ]
8191 pub payer : Signer < ' info > ,
8292 pub state : Account < ' info , State > ,
0 commit comments