@@ -39,7 +39,6 @@ use spl_stake_pool::{
39
39
stake:: StakeAuthorize ,
40
40
stake:: StakeState ,
41
41
state:: StakePool ,
42
- state:: State as PoolState ,
43
42
state:: ValidatorStakeList ,
44
43
} ;
45
44
use spl_token:: {
@@ -148,7 +147,7 @@ fn command_create_pool(config: &Config, fee: PoolFee) -> CommandResult {
148
147
. get_minimum_balance_for_rent_exemption ( TokenAccount :: LEN ) ?;
149
148
let pool_account_balance = config
150
149
. rpc_client
151
- . get_minimum_balance_for_rent_exemption ( PoolState :: LEN ) ?;
150
+ . get_minimum_balance_for_rent_exemption ( StakePool :: LEN ) ?;
152
151
let validator_stake_list_balance = config
153
152
. rpc_client
154
153
. get_minimum_balance_for_rent_exemption ( ValidatorStakeList :: LEN ) ?;
@@ -193,7 +192,7 @@ fn command_create_pool(config: &Config, fee: PoolFee) -> CommandResult {
193
192
& config. fee_payer . pubkey ( ) ,
194
193
& pool_account. pubkey ( ) ,
195
194
pool_account_balance,
196
- PoolState :: LEN as u64 ,
195
+ StakePool :: LEN as u64 ,
197
196
& spl_stake_pool:: id ( ) ,
198
197
) ,
199
198
// Validator stake account list storage
@@ -245,6 +244,7 @@ fn command_create_pool(config: &Config, fee: PoolFee) -> CommandResult {
245
244
& validator_stake_list,
246
245
& mint_account,
247
246
& pool_fee_account,
247
+ config. owner. as_ref( ) ,
248
248
] ;
249
249
unique_signers ! ( signers) ;
250
250
transaction. sign ( & signers, recent_blockhash) ;
@@ -289,10 +289,7 @@ fn command_vsa_add(
289
289
) -> CommandResult {
290
290
// Get stake pool state
291
291
let pool_data = config. rpc_client . get_account_data ( & pool) ?;
292
- let pool_data: StakePool = PoolState :: deserialize ( pool_data. as_slice ( ) )
293
- . unwrap ( )
294
- . stake_pool ( )
295
- . unwrap ( ) ;
292
+ let pool_data: StakePool = StakePool :: deserialize ( pool_data. as_slice ( ) ) . unwrap ( ) ;
296
293
297
294
let mut total_rent_free_balances: u64 = 0 ;
298
295
@@ -383,10 +380,7 @@ fn command_vsa_remove(
383
380
) -> CommandResult {
384
381
// Get stake pool state
385
382
let pool_data = config. rpc_client . get_account_data ( & pool) ?;
386
- let pool_data: StakePool = PoolState :: deserialize ( pool_data. as_slice ( ) )
387
- . unwrap ( )
388
- . stake_pool ( )
389
- . unwrap ( ) ;
383
+ let pool_data: StakePool = StakePool :: deserialize ( pool_data. as_slice ( ) ) . unwrap ( ) ;
390
384
391
385
let pool_withdraw_authority: Pubkey = PoolProcessor :: authority_id (
392
386
& spl_stake_pool:: id ( ) ,
@@ -512,10 +506,7 @@ fn command_deposit(
512
506
) -> CommandResult {
513
507
// Get stake pool state
514
508
let pool_data = config. rpc_client . get_account_data ( & pool) ?;
515
- let pool_data: StakePool = PoolState :: deserialize ( pool_data. as_slice ( ) )
516
- . unwrap ( )
517
- . stake_pool ( )
518
- . unwrap ( ) ;
509
+ let pool_data: StakePool = StakePool :: deserialize ( pool_data. as_slice ( ) ) . unwrap ( ) ;
519
510
520
511
// Get stake account data
521
512
let stake_data = config. rpc_client . get_account_data ( & stake) ?;
@@ -624,10 +615,7 @@ fn command_deposit(
624
615
fn command_list ( config : & Config , pool : & Pubkey ) -> CommandResult {
625
616
// Get stake pool state
626
617
let pool_data = config. rpc_client . get_account_data ( & pool) ?;
627
- let pool_data: StakePool = PoolState :: deserialize ( pool_data. as_slice ( ) )
628
- . unwrap ( )
629
- . stake_pool ( )
630
- . unwrap ( ) ;
618
+ let pool_data: StakePool = StakePool :: deserialize ( pool_data. as_slice ( ) ) . unwrap ( ) ;
631
619
632
620
let pool_withdraw_authority: Pubkey = PoolProcessor :: authority_id (
633
621
& spl_stake_pool:: id ( ) ,
@@ -657,10 +645,7 @@ fn command_list(config: &Config, pool: &Pubkey) -> CommandResult {
657
645
fn command_update ( config : & Config , pool : & Pubkey ) -> CommandResult {
658
646
// Get stake pool state
659
647
let pool_data = config. rpc_client . get_account_data ( & pool) ?;
660
- let pool_data: StakePool = PoolState :: deserialize ( pool_data. as_slice ( ) )
661
- . unwrap ( )
662
- . stake_pool ( )
663
- . unwrap ( ) ;
648
+ let pool_data: StakePool = StakePool :: deserialize ( pool_data. as_slice ( ) ) . unwrap ( ) ;
664
649
let validator_stake_list_data = config
665
650
. rpc_client
666
651
. get_account_data ( & pool_data. validator_stake_list ) ?;
@@ -804,10 +789,7 @@ fn command_withdraw(
804
789
) -> CommandResult {
805
790
// Get stake pool state
806
791
let pool_data = config. rpc_client . get_account_data ( & pool) ?;
807
- let pool_data: StakePool = PoolState :: deserialize ( pool_data. as_slice ( ) )
808
- . unwrap ( )
809
- . stake_pool ( )
810
- . unwrap ( ) ;
792
+ let pool_data: StakePool = StakePool :: deserialize ( pool_data. as_slice ( ) ) . unwrap ( ) ;
811
793
812
794
let pool_withdraw_authority: Pubkey = PoolProcessor :: authority_id (
813
795
& spl_stake_pool:: id ( ) ,
@@ -827,19 +809,21 @@ fn command_withdraw(
827
809
}
828
810
829
811
// Check burn_from balance
830
- let max_withdraw_amount = pool_tokens_to_stake_amount ( & pool_data, account_data. amount ) ;
831
- if max_withdraw_amount < amount {
812
+ if account_data. amount < amount {
832
813
return Err ( format ! (
833
- "Not enough token balance to withdraw {} SOL .\n Maximum withdraw amount is {} SOL ." ,
814
+ "Not enough token balance to withdraw {} pool tokens .\n Maximum withdraw amount is {} pool tokens ." ,
834
815
lamports_to_sol( amount) ,
835
- lamports_to_sol( max_withdraw_amount )
816
+ lamports_to_sol( account_data . amount )
836
817
)
837
818
. into ( ) ) ;
838
819
}
839
820
821
+ // Convert pool tokens amount to lamports
822
+ let sol_withdraw_amount = pool_tokens_to_stake_amount ( & pool_data, amount) ;
823
+
840
824
// Get the list of accounts to withdraw from
841
825
let withdraw_from: Vec < WithdrawAccount > =
842
- prepare_withdraw_accounts ( config, & pool_withdraw_authority, amount ) ?;
826
+ prepare_withdraw_accounts ( config, & pool_withdraw_authority, sol_withdraw_amount ) ?;
843
827
844
828
// Construct transaction to withdraw from withdraw_from account list
845
829
let mut instructions: Vec < Instruction > = vec ! [ ] ;
@@ -848,9 +832,6 @@ fn command_withdraw(
848
832
849
833
let mut total_rent_free_balances: u64 = 0 ;
850
834
851
- // Calculate amount of tokens to burn
852
- let tokens_to_burn = stake_amount_to_pool_tokens ( & pool_data, amount) ;
853
-
854
835
instructions. push (
855
836
// Approve spending token
856
837
approve_token (
@@ -859,7 +840,7 @@ fn command_withdraw(
859
840
& pool_withdraw_authority,
860
841
& config. owner . pubkey ( ) ,
861
842
& [ ] ,
862
- tokens_to_burn ,
843
+ amount ,
863
844
) ?,
864
845
) ;
865
846
@@ -940,10 +921,7 @@ fn command_set_staking_auth(
940
921
new_staker : & Pubkey ,
941
922
) -> CommandResult {
942
923
let pool_data = config. rpc_client . get_account_data ( & pool) ?;
943
- let pool_data: StakePool = PoolState :: deserialize ( pool_data. as_slice ( ) )
944
- . unwrap ( )
945
- . stake_pool ( )
946
- . unwrap ( ) ;
924
+ let pool_data: StakePool = StakePool :: deserialize ( pool_data. as_slice ( ) ) . unwrap ( ) ;
947
925
948
926
let pool_withdraw_authority: Pubkey = PoolProcessor :: authority_id (
949
927
& spl_stake_pool:: id ( ) ,
@@ -981,10 +959,7 @@ fn command_set_owner(
981
959
new_fee_receiver : & Option < Pubkey > ,
982
960
) -> CommandResult {
983
961
let pool_data = config. rpc_client . get_account_data ( & pool) ?;
984
- let pool_data: StakePool = PoolState :: deserialize ( pool_data. as_slice ( ) )
985
- . unwrap ( )
986
- . stake_pool ( )
987
- . unwrap ( ) ;
962
+ let pool_data: StakePool = StakePool :: deserialize ( pool_data. as_slice ( ) ) . unwrap ( ) ;
988
963
989
964
// If new accounts are missing in the arguments use the old ones
990
965
let new_owner: Pubkey = match new_owner {
@@ -1264,7 +1239,7 @@ fn main() {
1264
1239
. value_name ( "AMOUNT" )
1265
1240
. takes_value ( true )
1266
1241
. required ( true )
1267
- . help ( "Amount in SOL to withdraw from the pool ." ) ,
1242
+ . help ( "Amount of pool tokens to burn and get rewards ." ) ,
1268
1243
)
1269
1244
. arg (
1270
1245
Arg :: with_name ( "burn_from" )
@@ -1444,6 +1419,7 @@ fn main() {
1444
1419
( "withdraw" , Some ( arg_matches) ) => {
1445
1420
let pool_account: Pubkey = pubkey_of ( arg_matches, "pool" ) . unwrap ( ) ;
1446
1421
let burn_from: Pubkey = pubkey_of ( arg_matches, "burn_from" ) . unwrap ( ) ;
1422
+ // convert from float to int, using sol_to_lamports because they have the same precision as SOL
1447
1423
let amount: u64 = sol_to_lamports ( value_t_or_exit ! ( arg_matches, "amount" , f64 ) ) ;
1448
1424
let stake_receiver: Option < Pubkey > = pubkey_of ( arg_matches, "stake_receiver" ) ;
1449
1425
command_withdraw ( & config, & pool_account, amount, & burn_from, & stake_receiver)
0 commit comments