@@ -1079,21 +1079,15 @@ struct WithdrawAccount {
1079
1079
fn sorted_accounts < F > (
1080
1080
validator_list : & ValidatorList ,
1081
1081
stake_pool : & StakePool ,
1082
- get_pubkey : F ,
1082
+ get_info : F ,
1083
1083
) -> Vec < ( Pubkey , u64 , Option < Pubkey > ) >
1084
1084
where
1085
- F : Fn ( & ValidatorStakeInfo ) -> Pubkey ,
1085
+ F : Fn ( & ValidatorStakeInfo ) -> ( Pubkey , u64 , Option < Pubkey > ) ,
1086
1086
{
1087
1087
let mut result: Vec < ( Pubkey , u64 , Option < Pubkey > ) > = validator_list
1088
1088
. validators
1089
1089
. 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)
1097
1091
. collect :: < Vec < _ > > ( ) ;
1098
1092
1099
1093
result. sort_by ( |left, right| {
@@ -1114,12 +1108,12 @@ fn prepare_withdraw_accounts(
1114
1108
stake_pool : & StakePool ,
1115
1109
pool_amount : u64 ,
1116
1110
stake_pool_address : & Pubkey ,
1111
+ skip_fee : bool ,
1117
1112
) -> Result < Vec < WithdrawAccount > , Error > {
1118
1113
let min_balance = rpc_client
1119
1114
. get_minimum_balance_for_rent_exemption ( STAKE_STATE_LEN ) ?
1120
1115
. saturating_add ( MINIMUM_ACTIVE_STAKE ) ;
1121
1116
let pool_mint = get_token_mint ( rpc_client, & stake_pool. pool_mint ) ?;
1122
-
1123
1117
let validator_list: ValidatorList = get_validator_list ( rpc_client, & stake_pool. validator_list ) ?;
1124
1118
1125
1119
let mut accounts: Vec < ( Pubkey , u64 , Option < Pubkey > ) > = Vec :: new ( ) ;
@@ -1134,7 +1128,11 @@ fn prepare_withdraw_accounts(
1134
1128
stake_pool_address,
1135
1129
) ;
1136
1130
1137
- stake_account_address
1131
+ (
1132
+ stake_account_address,
1133
+ validator. active_stake_lamports ,
1134
+ Some ( validator. vote_account_address ) ,
1135
+ )
1138
1136
} ,
1139
1137
) ) ;
1140
1138
@@ -1149,7 +1147,11 @@ fn prepare_withdraw_accounts(
1149
1147
validator. transient_seed_suffix_start ,
1150
1148
) ;
1151
1149
1152
- transient_stake_account_address
1150
+ (
1151
+ transient_stake_account_address,
1152
+ validator. transient_stake_lamports ,
1153
+ Some ( validator. vote_account_address ) ,
1154
+ )
1153
1155
} ,
1154
1156
) ) ;
1155
1157
@@ -1161,15 +1163,26 @@ fn prepare_withdraw_accounts(
1161
1163
let mut withdraw_from: Vec < WithdrawAccount > = vec ! [ ] ;
1162
1164
let mut remaining_amount = pool_amount;
1163
1165
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
+
1164
1172
// Go through available accounts and withdraw from largest to smallest
1165
1173
for ( stake_address, lamports, vote_address_opt) in accounts {
1166
1174
if lamports <= min_balance {
1167
1175
continue ;
1168
1176
}
1169
1177
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
+ } ;
1173
1186
1174
1187
let pool_amount = u64:: min ( available_for_withdrawal, remaining_amount) ;
1175
1188
@@ -1283,6 +1296,7 @@ fn command_withdraw_stake(
1283
1296
& stake_pool,
1284
1297
pool_amount,
1285
1298
stake_pool_address,
1299
+ stake_pool. manager_fee_account == pool_token_account,
1286
1300
) ?
1287
1301
} ;
1288
1302
0 commit comments