@@ -395,7 +395,9 @@ fn command_vsa_remove(
395
395
396
396
// Calculate amount of tokens to burn
397
397
let stake_account = config. rpc_client . get_account ( & stake) ?;
398
- let tokens_to_burn = stake_amount_to_pool_tokens ( & pool_data, stake_account. lamports ) ;
398
+ let tokens_to_burn = pool_data
399
+ . calc_pool_withdraw_amount ( stake_account. lamports )
400
+ . unwrap ( ) ;
399
401
400
402
// Check balance and mint
401
403
let account_data = config. rpc_client . get_account_data ( & burn_from) ?;
@@ -736,22 +738,6 @@ fn command_update(config: &Config, pool: &Pubkey) -> CommandResult {
736
738
}
737
739
}
738
740
739
- fn stake_amount_to_pool_tokens ( pool_data : & StakePool , amount : u64 ) -> u64 {
740
- ( amount as u128 )
741
- . checked_mul ( pool_data. pool_total as u128 )
742
- . unwrap ( )
743
- . checked_div ( pool_data. stake_total as u128 )
744
- . unwrap ( ) as u64
745
- }
746
-
747
- fn pool_tokens_to_stake_amount ( pool_data : & StakePool , tokens : u64 ) -> u64 {
748
- ( tokens as u128 )
749
- . checked_mul ( pool_data. stake_total as u128 )
750
- . unwrap ( )
751
- . checked_div ( pool_data. pool_total as u128 )
752
- . unwrap ( ) as u64
753
- }
754
-
755
741
#[ derive( PartialEq , Debug ) ]
756
742
struct WithdrawAccount {
757
743
pubkey : Pubkey ,
@@ -859,7 +845,7 @@ fn command_withdraw(
859
845
}
860
846
861
847
// Convert pool tokens amount to lamports
862
- let sol_withdraw_amount = pool_tokens_to_stake_amount ( & pool_data, amount) ;
848
+ let sol_withdraw_amount = pool_data. calc_lamports_amount ( amount) . unwrap ( ) ;
863
849
864
850
// Get the list of accounts to withdraw from
865
851
let withdraw_from: Vec < WithdrawAccount > =
@@ -870,8 +856,6 @@ fn command_withdraw(
870
856
let mut signers = vec ! [ config. fee_payer. as_ref( ) , config. owner. as_ref( ) ] ;
871
857
let stake_receiver_account = Keypair :: new ( ) ; // Will be added to signers if creating new account
872
858
873
- let mut total_rent_free_balances: u64 = 0 ;
874
-
875
859
instructions. push (
876
860
// Approve spending token
877
861
approve_token (
@@ -887,12 +871,19 @@ fn command_withdraw(
887
871
// Use separate mutable variable because withdraw might create a new account
888
872
let mut stake_receiver: Option < Pubkey > = * stake_receiver_param;
889
873
874
+ let mut total_rent_free_balances = 0 ;
875
+
890
876
// Go through prepared accounts and withdraw/claim them
891
877
for withdraw_stake in withdraw_from {
878
+ let withdraw_amount = pool_data
879
+ . calc_pool_withdraw_amount ( withdraw_stake. amount )
880
+ . unwrap ( )
881
+ + 1 ;
892
882
println ! (
893
- "Withdrawing from account {}, amount {} SOL" ,
883
+ "Withdrawing from account {}, amount {} SOL, {} pool tokens " ,
894
884
withdraw_stake. pubkey,
895
- lamports_to_sol( withdraw_stake. amount)
885
+ lamports_to_sol( withdraw_stake. amount) ,
886
+ lamports_to_sol( withdraw_amount) ,
896
887
) ;
897
888
898
889
if stake_receiver. is_none ( ) {
@@ -936,7 +927,7 @@ fn command_withdraw(
936
927
& pool_data. pool_mint ,
937
928
& spl_token:: id ( ) ,
938
929
& stake_program_id ( ) ,
939
- withdraw_stake . amount ,
930
+ withdraw_amount ,
940
931
) ?) ;
941
932
}
942
933
0 commit comments