@@ -465,6 +465,7 @@ impl Processor {
465
465
stake_pool. check_authority_deposit ( deposit_info. key , program_id, stake_pool_info. key ) ?;
466
466
467
467
stake_pool. check_staker ( staker_info) ?;
468
+ stake_pool. check_mint ( pool_mint_info) ?;
468
469
469
470
if stake_pool. last_update_epoch < clock. epoch {
470
471
return Err ( StakePoolError :: StakeListAndPoolOutOfDate . into ( ) ) ;
@@ -473,9 +474,6 @@ impl Processor {
473
474
if stake_pool. token_program_id != * token_program_info. key {
474
475
return Err ( ProgramError :: IncorrectProgramId ) ;
475
476
}
476
- if stake_pool. pool_mint != * pool_mint_info. key {
477
- return Err ( StakePoolError :: WrongPoolMint . into ( ) ) ;
478
- }
479
477
480
478
if * validator_list_info. key != stake_pool. validator_list {
481
479
return Err ( StakePoolError :: InvalidValidatorStakeList . into ( ) ) ;
@@ -586,9 +584,7 @@ impl Processor {
586
584
if stake_pool. token_program_id != * token_program_info. key {
587
585
return Err ( ProgramError :: IncorrectProgramId ) ;
588
586
}
589
- if stake_pool. pool_mint != * pool_mint_info. key {
590
- return Err ( StakePoolError :: WrongPoolMint . into ( ) ) ;
591
- }
587
+ stake_pool. check_mint ( pool_mint_info) ?;
592
588
593
589
if * validator_list_info. key != stake_pool. validator_list {
594
590
return Err ( StakePoolError :: InvalidValidatorStakeList . into ( ) ) ;
@@ -703,31 +699,44 @@ impl Processor {
703
699
704
700
/// Processes `UpdateStakePoolBalance` instruction.
705
701
fn process_update_stake_pool_balance (
706
- _program_id : & Pubkey ,
702
+ program_id : & Pubkey ,
707
703
accounts : & [ AccountInfo ] ,
708
704
) -> ProgramResult {
709
705
let account_info_iter = & mut accounts. iter ( ) ;
710
706
let stake_pool_info = next_account_info ( account_info_iter) ?;
711
707
let validator_list_info = next_account_info ( account_info_iter) ?;
708
+ let withdraw_info = next_account_info ( account_info_iter) ?;
709
+ let manager_fee_info = next_account_info ( account_info_iter) ?;
710
+ let pool_mint_info = next_account_info ( account_info_iter) ?;
712
711
let clock_info = next_account_info ( account_info_iter) ?;
713
712
let clock = & Clock :: from_account_info ( clock_info) ?;
713
+ let token_program_info = next_account_info ( account_info_iter) ?;
714
714
715
715
let mut stake_pool = StakePool :: try_from_slice ( & stake_pool_info. data . borrow ( ) ) ?;
716
716
if !stake_pool. is_valid ( ) {
717
717
return Err ( StakePoolError :: InvalidState . into ( ) ) ;
718
718
}
719
+ stake_pool. check_mint ( pool_mint_info) ?;
720
+ stake_pool. check_authority_withdraw ( withdraw_info. key , program_id, stake_pool_info. key ) ?;
721
+ if stake_pool. manager_fee_account != * manager_fee_info. key {
722
+ return Err ( StakePoolError :: InvalidFeeAccount . into ( ) ) ;
723
+ }
719
724
720
725
if * validator_list_info. key != stake_pool. validator_list {
721
726
return Err ( StakePoolError :: InvalidValidatorStakeList . into ( ) ) ;
722
727
}
728
+ if stake_pool. token_program_id != * token_program_info. key {
729
+ return Err ( ProgramError :: IncorrectProgramId ) ;
730
+ }
723
731
724
732
let validator_list =
725
733
try_from_slice_unchecked :: < ValidatorList > ( & validator_list_info. data . borrow ( ) ) ?;
726
734
if !validator_list. is_valid ( ) {
727
735
return Err ( StakePoolError :: InvalidState . into ( ) ) ;
728
736
}
729
737
730
- let mut total_stake_lamports: u64 = 0 ;
738
+ let previous_lamports = stake_pool. total_stake_lamports ;
739
+ let mut total_stake_lamports = 0 ;
731
740
for validator_stake_record in validator_list. validators {
732
741
if validator_stake_record. last_update_epoch < clock. epoch {
733
742
return Err ( StakePoolError :: StakeListOutOfDate . into ( ) ) ;
@@ -736,6 +745,29 @@ impl Processor {
736
745
}
737
746
738
747
stake_pool. total_stake_lamports = total_stake_lamports;
748
+
749
+ let reward_lamports = total_stake_lamports. saturating_sub ( previous_lamports) ;
750
+ let fee = stake_pool
751
+ . calc_fee_amount ( reward_lamports)
752
+ . ok_or ( StakePoolError :: CalculationFailure ) ?;
753
+
754
+ if fee > 0 {
755
+ Self :: token_mint_to (
756
+ stake_pool_info. key ,
757
+ token_program_info. clone ( ) ,
758
+ pool_mint_info. clone ( ) ,
759
+ manager_fee_info. clone ( ) ,
760
+ withdraw_info. clone ( ) ,
761
+ AUTHORITY_WITHDRAW ,
762
+ stake_pool. withdraw_bump_seed ,
763
+ fee,
764
+ ) ?;
765
+
766
+ stake_pool. pool_token_supply = stake_pool
767
+ . pool_token_supply
768
+ . checked_add ( fee)
769
+ . ok_or ( StakePoolError :: CalculationFailure ) ?;
770
+ }
739
771
stake_pool. last_update_epoch = clock. epoch ;
740
772
stake_pool. serialize ( & mut * stake_pool_info. data . borrow_mut ( ) ) ?;
741
773
@@ -782,7 +814,6 @@ impl Processor {
782
814
let stake_info = next_account_info ( account_info_iter) ?;
783
815
let validator_stake_account_info = next_account_info ( account_info_iter) ?;
784
816
let dest_user_info = next_account_info ( account_info_iter) ?;
785
- let manager_fee_info = next_account_info ( account_info_iter) ?;
786
817
let pool_mint_info = next_account_info ( account_info_iter) ?;
787
818
let clock_info = next_account_info ( account_info_iter) ?;
788
819
let clock = & Clock :: from_account_info ( clock_info) ?;
@@ -804,10 +835,8 @@ impl Processor {
804
835
805
836
stake_pool. check_authority_withdraw ( withdraw_info. key , program_id, stake_pool_info. key ) ?;
806
837
stake_pool. check_authority_deposit ( deposit_info. key , program_id, stake_pool_info. key ) ?;
838
+ stake_pool. check_mint ( pool_mint_info) ?;
807
839
808
- if stake_pool. manager_fee_account != * manager_fee_info. key {
809
- return Err ( StakePoolError :: InvalidFeeAccount . into ( ) ) ;
810
- }
811
840
if stake_pool. token_program_id != * token_program_info. key {
812
841
return Err ( ProgramError :: IncorrectProgramId ) ;
813
842
}
@@ -838,14 +867,6 @@ impl Processor {
838
867
. calc_pool_tokens_for_deposit ( stake_lamports)
839
868
. ok_or ( StakePoolError :: CalculationFailure ) ?;
840
869
841
- let fee_pool_tokens = stake_pool
842
- . calc_fee_amount ( new_pool_tokens)
843
- . ok_or ( StakePoolError :: CalculationFailure ) ?;
844
-
845
- let user_pool_tokens = new_pool_tokens
846
- . checked_sub ( fee_pool_tokens)
847
- . ok_or ( StakePoolError :: CalculationFailure ) ?;
848
-
849
870
Self :: stake_authorize (
850
871
stake_pool_info. key ,
851
872
stake_info. clone ( ) ,
@@ -890,19 +911,9 @@ impl Processor {
890
911
withdraw_info. clone ( ) ,
891
912
AUTHORITY_WITHDRAW ,
892
913
stake_pool. withdraw_bump_seed ,
893
- user_pool_tokens ,
914
+ new_pool_tokens ,
894
915
) ?;
895
916
896
- Self :: token_mint_to (
897
- stake_pool_info. key ,
898
- token_program_info. clone ( ) ,
899
- pool_mint_info. clone ( ) ,
900
- manager_fee_info. clone ( ) ,
901
- withdraw_info. clone ( ) ,
902
- AUTHORITY_WITHDRAW ,
903
- stake_pool. withdraw_bump_seed ,
904
- fee_pool_tokens,
905
- ) ?;
906
917
stake_pool. pool_token_supply += new_pool_tokens;
907
918
stake_pool. total_stake_lamports += stake_lamports;
908
919
stake_pool. serialize ( & mut * stake_pool_info. data . borrow_mut ( ) ) ?;
@@ -943,6 +954,7 @@ impl Processor {
943
954
}
944
955
945
956
stake_pool. check_authority_withdraw ( withdraw_info. key , program_id, stake_pool_info. key ) ?;
957
+ stake_pool. check_mint ( pool_mint_info) ?;
946
958
947
959
if stake_pool. token_program_id != * token_program_info. key {
948
960
return Err ( ProgramError :: IncorrectProgramId ) ;
0 commit comments