@@ -1079,21 +1079,15 @@ struct WithdrawAccount {
10791079fn sorted_accounts < F > (
10801080 validator_list : & ValidatorList ,
10811081 stake_pool : & StakePool ,
1082- get_pubkey : F ,
1082+ get_info : F ,
10831083) -> Vec < ( Pubkey , u64 , Option < Pubkey > ) >
10841084where
1085- F : Fn ( & ValidatorStakeInfo ) -> Pubkey ,
1085+ F : Fn ( & ValidatorStakeInfo ) -> ( Pubkey , u64 , Option < Pubkey > ) ,
10861086{
10871087 let mut result: Vec < ( Pubkey , u64 , Option < Pubkey > ) > = validator_list
10881088 . validators
10891089 . iter ( )
1090- . map ( |validator| {
1091- (
1092- get_pubkey ( validator) ,
1093- validator. active_stake_lamports ,
1094- Some ( validator. vote_account_address ) ,
1095- )
1096- } )
1090+ . map ( get_info)
10971091 . collect :: < Vec < _ > > ( ) ;
10981092
10991093 result. sort_by ( |left, right| {
@@ -1114,12 +1108,12 @@ fn prepare_withdraw_accounts(
11141108 stake_pool : & StakePool ,
11151109 pool_amount : u64 ,
11161110 stake_pool_address : & Pubkey ,
1111+ skip_fee : bool ,
11171112) -> Result < Vec < WithdrawAccount > , Error > {
11181113 let min_balance = rpc_client
11191114 . get_minimum_balance_for_rent_exemption ( STAKE_STATE_LEN ) ?
11201115 . saturating_add ( MINIMUM_ACTIVE_STAKE ) ;
11211116 let pool_mint = get_token_mint ( rpc_client, & stake_pool. pool_mint ) ?;
1122-
11231117 let validator_list: ValidatorList = get_validator_list ( rpc_client, & stake_pool. validator_list ) ?;
11241118
11251119 let mut accounts: Vec < ( Pubkey , u64 , Option < Pubkey > ) > = Vec :: new ( ) ;
@@ -1134,7 +1128,11 @@ fn prepare_withdraw_accounts(
11341128 stake_pool_address,
11351129 ) ;
11361130
1137- stake_account_address
1131+ (
1132+ stake_account_address,
1133+ validator. active_stake_lamports ,
1134+ Some ( validator. vote_account_address ) ,
1135+ )
11381136 } ,
11391137 ) ) ;
11401138
@@ -1149,7 +1147,11 @@ fn prepare_withdraw_accounts(
11491147 validator. transient_seed_suffix_start ,
11501148 ) ;
11511149
1152- transient_stake_account_address
1150+ (
1151+ transient_stake_account_address,
1152+ validator. transient_stake_lamports ,
1153+ Some ( validator. vote_account_address ) ,
1154+ )
11531155 } ,
11541156 ) ) ;
11551157
@@ -1161,15 +1163,26 @@ fn prepare_withdraw_accounts(
11611163 let mut withdraw_from: Vec < WithdrawAccount > = vec ! [ ] ;
11621164 let mut remaining_amount = pool_amount;
11631165
1166+ let fee = stake_pool. stake_withdrawal_fee ;
1167+ let inverse_fee = Fee {
1168+ numerator : fee. denominator - fee. numerator ,
1169+ denominator : fee. denominator ,
1170+ } ;
1171+
11641172 // Go through available accounts and withdraw from largest to smallest
11651173 for ( stake_address, lamports, vote_address_opt) in accounts {
11661174 if lamports <= min_balance {
11671175 continue ;
11681176 }
11691177
1170- let available_for_withdrawal = stake_pool
1171- . calc_lamports_withdraw_amount ( lamports. saturating_sub ( min_balance) )
1172- . unwrap ( ) ;
1178+ let available_for_withdrawal_wo_fee =
1179+ stake_pool. calc_pool_tokens_for_deposit ( lamports) . unwrap ( ) ;
1180+
1181+ let available_for_withdrawal = if skip_fee {
1182+ available_for_withdrawal_wo_fee
1183+ } else {
1184+ available_for_withdrawal_wo_fee * inverse_fee. denominator / inverse_fee. numerator
1185+ } ;
11731186
11741187 let pool_amount = u64:: min ( available_for_withdrawal, remaining_amount) ;
11751188
@@ -1283,6 +1296,7 @@ fn command_withdraw_stake(
12831296 & stake_pool,
12841297 pool_amount,
12851298 stake_pool_address,
1299+ stake_pool. manager_fee_account == pool_token_account,
12861300 ) ?
12871301 } ;
12881302
0 commit comments