3434 sysvar:: stake_history:: StakeHistorySysvar ,
3535 } ,
3636 solana_system_interface:: { instruction as system_instruction, program as system_program} ,
37- solana_sysvar:: SysvarSerialize ,
37+ solana_sysvar:: { Sysvar , SysvarSerialize } ,
3838 solana_vote_interface:: program as vote_program,
3939 spl_token_interface:: { self as spl_token, state:: Mint } ,
4040} ;
@@ -766,8 +766,13 @@ impl Processor {
766766 ) ?;
767767 check_stake_program ( stake_program_info. key ) ?;
768768
769+ // we expect these numbers to be equal but get them separately in case of future changes
770+ let rent = Rent :: get ( ) ?;
771+ let pool_rent_exempt_reserve = rent. minimum_balance ( pool_stake_info. data_len ( ) ) ;
772+ let onramp_rent_exempt_reserve = rent. minimum_balance ( pool_onramp_info. data_len ( ) ) ;
773+
769774 // get main pool account, we require it to be fully active for most operations
770- let ( pool_stake_meta , pool_stake_state) = get_stake_state ( pool_stake_info) ?;
775+ let ( _ , pool_stake_state) = get_stake_state ( pool_stake_info) ?;
771776 let pool_stake_status = pool_stake_state
772777 . delegation
773778 . stake_activating_and_deactivating (
@@ -779,17 +784,16 @@ impl Processor {
779784
780785 // get on-ramp and its status. we have to match because unlike the main account it could be Initialized
781786 // if it doesnt exist, it must first be created with InitializePoolOnRamp
782- let ( option_onramp_status, onramp_deactivation_epoch, onramp_rent_exempt_reserve ) =
787+ let ( option_onramp_status, onramp_deactivation_epoch) =
783788 match try_from_slice_unchecked :: < StakeStateV2 > ( & pool_onramp_info. data . borrow ( ) ) {
784- Ok ( StakeStateV2 :: Initialized ( meta ) ) => ( None , u64:: MAX , meta . rent_exempt_reserve ) ,
785- Ok ( StakeStateV2 :: Stake ( meta , stake, _) ) => (
789+ Ok ( StakeStateV2 :: Initialized ( _ ) ) => ( None , u64:: MAX ) ,
790+ Ok ( StakeStateV2 :: Stake ( _ , stake, _) ) => (
786791 Some ( stake. delegation . stake_activating_and_deactivating (
787792 clock. epoch ,
788793 stake_history,
789794 PERPETUAL_NEW_WARMUP_COOLDOWN_RATE_EPOCH ,
790795 ) ) ,
791796 stake. delegation . deactivation_epoch ,
792- meta. rent_exempt_reserve ,
793797 ) ,
794798 _ => return Err ( SinglePoolError :: OnRampDoesntExist . into ( ) ) ,
795799 } ;
@@ -831,7 +835,7 @@ impl Processor {
831835 let pool_excess_lamports = pool_stake_info
832836 . lamports ( )
833837 . saturating_sub ( pool_stake_state. delegation . stake )
834- . saturating_sub ( pool_stake_meta . rent_exempt_reserve ) ;
838+ . saturating_sub ( pool_rent_exempt_reserve ) ;
835839
836840 // if the on-ramp is fully active, move its stake to the main pool account
837841 if let Some ( ref onramp_status) = option_onramp_status {
@@ -975,17 +979,20 @@ impl Processor {
975979 return Err ( SinglePoolError :: InvalidPoolStakeAccountUsage . into ( ) ) ;
976980 }
977981
982+ let rent = Rent :: get ( ) ?;
983+ let pool_rent_exempt_reserve = rent. minimum_balance ( pool_stake_info. data_len ( ) ) ;
984+
978985 let minimum_pool_balance = minimum_pool_balance ( ) ?;
979986
980- let ( pool_stake_meta , pool_stake_state) = get_stake_state ( pool_stake_info) ?;
987+ let ( _ , pool_stake_state) = get_stake_state ( pool_stake_info) ?;
981988 let pre_pool_stake = pool_stake_state
982989 . delegation
983990 . stake
984991 . saturating_sub ( minimum_pool_balance) ;
985992 let pre_pool_excess_lamports = pool_stake_info
986993 . lamports ( )
987994 . checked_sub ( pool_stake_state. delegation . stake )
988- . and_then ( |amount| amount. checked_sub ( pool_stake_meta . rent_exempt_reserve ) )
995+ . and_then ( |amount| amount. checked_sub ( pool_rent_exempt_reserve ) )
989996 . ok_or ( SinglePoolError :: ArithmeticOverflow ) ?;
990997 msg ! ( "Available stake pre merge {}" , pre_pool_stake) ;
991998
@@ -1013,7 +1020,7 @@ impl Processor {
10131020 stake_history_info. clone ( ) ,
10141021 ) ?;
10151022
1016- let ( pool_stake_meta , pool_stake_state) = get_stake_state ( pool_stake_info) ?;
1023+ let ( _ , pool_stake_state) = get_stake_state ( pool_stake_info) ?;
10171024 let post_pool_stake = pool_stake_state
10181025 . delegation
10191026 . stake
@@ -1030,7 +1037,7 @@ impl Processor {
10301037 // this includes their rent-exempt reserve if the pool is fully active
10311038 let user_excess_lamports = post_pool_lamports
10321039 . checked_sub ( pool_stake_state. delegation . stake )
1033- . and_then ( |amount| amount. checked_sub ( pool_stake_meta . rent_exempt_reserve ) )
1040+ . and_then ( |amount| amount. checked_sub ( pool_rent_exempt_reserve ) )
10341041 . and_then ( |amount| amount. checked_sub ( pre_pool_excess_lamports) )
10351042 . ok_or ( SinglePoolError :: ArithmeticOverflow ) ?;
10361043
0 commit comments