10
10
input_parsers:: { keypair_of, pubkey_of} ,
11
11
input_validators:: {
12
12
is_amount, is_keypair, is_keypair_or_ask_keyword, is_parsable, is_pubkey, is_url,
13
- is_valid_percentage,
13
+ is_valid_percentage, is_valid_pubkey ,
14
14
} ,
15
- keypair:: signer_from_path ,
15
+ keypair:: { signer_from_path_with_config , SignerFromPathConfig } ,
16
16
} ,
17
17
solana_client:: rpc_client:: RpcClient ,
18
18
solana_program:: {
@@ -88,12 +88,14 @@ fn get_signer(
88
88
keypair_name : & str ,
89
89
keypair_path : & str ,
90
90
wallet_manager : & mut Option < Arc < RemoteWalletManager > > ,
91
+ signer_from_path_config : SignerFromPathConfig ,
91
92
) -> Box < dyn Signer > {
92
- signer_from_path (
93
+ signer_from_path_with_config (
93
94
matches,
94
95
matches. value_of ( keypair_name) . unwrap_or ( keypair_path) ,
95
96
keypair_name,
96
97
wallet_manager,
98
+ & signer_from_path_config,
97
99
)
98
100
. unwrap_or_else ( |e| {
99
101
eprintln ! ( "error: {}" , e) ;
@@ -596,6 +598,7 @@ fn command_deposit_stake(
596
598
config : & Config ,
597
599
stake_pool_address : & Pubkey ,
598
600
stake : & Pubkey ,
601
+ withdraw_authority : Box < dyn Signer > ,
599
602
pool_token_receiver_account : & Option < Pubkey > ,
600
603
referrer_token_account : & Option < Pubkey > ,
601
604
) -> CommandResult {
@@ -634,7 +637,7 @@ fn command_deposit_stake(
634
637
}
635
638
636
639
let mut instructions: Vec < Instruction > = vec ! [ ] ;
637
- let mut signers = vec ! [ config. fee_payer. as_ref( ) , config . staker . as_ref( ) ] ;
640
+ let mut signers = vec ! [ config. fee_payer. as_ref( ) , withdraw_authority . as_ref( ) ] ;
638
641
639
642
let mut total_rent_free_balances: u64 = 0 ;
640
643
@@ -672,7 +675,7 @@ fn command_deposit_stake(
672
675
& stake_deposit_authority. pubkey ( ) ,
673
676
& pool_withdraw_authority,
674
677
stake,
675
- & config . staker . pubkey ( ) ,
678
+ & withdraw_authority . pubkey ( ) ,
676
679
& validator_stake_account,
677
680
& stake_pool. reserve_stake ,
678
681
& pool_token_receiver_account,
@@ -688,7 +691,7 @@ fn command_deposit_stake(
688
691
& stake_pool. validator_list ,
689
692
& pool_withdraw_authority,
690
693
stake,
691
- & config . staker . pubkey ( ) ,
694
+ & withdraw_authority . pubkey ( ) ,
692
695
& validator_stake_account,
693
696
& stake_pool. reserve_stake ,
694
697
& pool_token_receiver_account,
@@ -1371,8 +1374,8 @@ fn command_withdraw_stake(
1371
1374
fn command_withdraw_sol (
1372
1375
config : & Config ,
1373
1376
stake_pool_address : & Pubkey ,
1374
- sol_receiver : & Option < Pubkey > ,
1375
1377
pool_token_account : & Option < Pubkey > ,
1378
+ sol_receiver : & Pubkey ,
1376
1379
pool_amount : f64 ,
1377
1380
) -> CommandResult {
1378
1381
if !config. no_update {
@@ -1383,7 +1386,6 @@ fn command_withdraw_sol(
1383
1386
let pool_mint = get_token_mint ( & config. rpc_client , & stake_pool. pool_mint ) ?;
1384
1387
let pool_amount = spl_token:: ui_amount_to_amount ( pool_amount, pool_mint. decimals ) ;
1385
1388
1386
- let sol_receiver = sol_receiver. unwrap_or_else ( || config. fee_payer . pubkey ( ) ) ;
1387
1389
let pool_token_account = pool_token_account. unwrap_or ( get_associated_token_address (
1388
1390
& config. token_owner . pubkey ( ) ,
1389
1391
& stake_pool. pool_mint ,
@@ -1450,7 +1452,7 @@ fn command_withdraw_sol(
1450
1452
& user_transfer_authority. pubkey ( ) ,
1451
1453
& pool_token_account,
1452
1454
& stake_pool. reserve_stake ,
1453
- & sol_receiver,
1455
+ sol_receiver,
1454
1456
& stake_pool. manager_fee_account ,
1455
1457
& stake_pool. pool_mint ,
1456
1458
& spl_token:: id ( ) ,
@@ -1464,7 +1466,7 @@ fn command_withdraw_sol(
1464
1466
& user_transfer_authority. pubkey ( ) ,
1465
1467
& pool_token_account,
1466
1468
& stake_pool. reserve_stake ,
1467
- & sol_receiver,
1469
+ sol_receiver,
1468
1470
& stake_pool. manager_fee_account ,
1469
1471
& stake_pool. pool_mint ,
1470
1472
& spl_token:: id ( ) ,
@@ -2011,6 +2013,15 @@ fn main() {
2011
2013
. required ( true )
2012
2014
. help ( "Stake address to join the pool" ) ,
2013
2015
)
2016
+ . arg (
2017
+ Arg :: with_name ( "withdraw_authority" )
2018
+ . long ( "withdraw-authority" )
2019
+ . validator ( is_keypair)
2020
+ . value_name ( "KEYPAIR" )
2021
+ . takes_value ( true )
2022
+ . help ( "Withdraw authority for the stake account to be deposited. \
2023
+ Defaults to the fee payer.") ,
2024
+ )
2014
2025
. arg (
2015
2026
Arg :: with_name ( "token_receiver" )
2016
2027
. long ( "token-receiver" )
@@ -2181,8 +2192,17 @@ fn main() {
2181
2192
. help ( "Stake pool address." ) ,
2182
2193
)
2183
2194
. arg (
2184
- Arg :: with_name ( "amount " )
2195
+ Arg :: with_name ( "sol_receiver " )
2185
2196
. index ( 2 )
2197
+ . validator ( is_valid_pubkey)
2198
+ . value_name ( "SYSTEM_ACCOUNT_ADDRESS_OR_KEYPAIR" )
2199
+ . takes_value ( true )
2200
+ . required ( true )
2201
+ . help ( "System account to receive SOL from the stake pool. Defaults to the payer." ) ,
2202
+ )
2203
+ . arg (
2204
+ Arg :: with_name ( "amount" )
2205
+ . index ( 3 )
2186
2206
. validator ( is_amount)
2187
2207
. value_name ( "AMOUNT" )
2188
2208
. takes_value ( true )
@@ -2197,14 +2217,6 @@ fn main() {
2197
2217
. takes_value ( true )
2198
2218
. help ( "Pool token account to withdraw tokens from. Defaults to the token-owner's associated token account." ) ,
2199
2219
)
2200
- . arg (
2201
- Arg :: with_name ( "sol_receiver" )
2202
- . long ( "sol-receiver" )
2203
- . validator ( is_pubkey)
2204
- . value_name ( "SYSTEM_ACCOUNT_ADDRESS" )
2205
- . takes_value ( true )
2206
- . help ( "System account to receive SOL from the stake pool. Defaults to the payer." ) ,
2207
- )
2208
2220
)
2209
2221
. subcommand ( SubCommand :: with_name ( "set-manager" )
2210
2222
. about ( "Change manager or fee receiver account for the stake pool. Must be signed by the current manager." )
@@ -2373,12 +2385,12 @@ fn main() {
2373
2385
. get_matches ( ) ;
2374
2386
2375
2387
let mut wallet_manager = None ;
2388
+ let cli_config = if let Some ( config_file) = matches. value_of ( "config_file" ) {
2389
+ solana_cli_config:: Config :: load ( config_file) . unwrap_or_default ( )
2390
+ } else {
2391
+ solana_cli_config:: Config :: default ( )
2392
+ } ;
2376
2393
let config = {
2377
- let cli_config = if let Some ( config_file) = matches. value_of ( "config_file" ) {
2378
- solana_cli_config:: Config :: load ( config_file) . unwrap_or_default ( )
2379
- } else {
2380
- solana_cli_config:: Config :: default ( )
2381
- } ;
2382
2394
let json_rpc_url = value_t ! ( matches, "json_rpc_url" , String )
2383
2395
. unwrap_or_else ( |_| cli_config. json_rpc_url . clone ( ) ) ;
2384
2396
@@ -2387,6 +2399,9 @@ fn main() {
2387
2399
"staker" ,
2388
2400
& cli_config. keypair_path ,
2389
2401
& mut wallet_manager,
2402
+ SignerFromPathConfig {
2403
+ allow_null_signer : false ,
2404
+ } ,
2390
2405
) ;
2391
2406
2392
2407
let funding_authority = if matches. is_present ( "funding_authority" ) {
@@ -2395,6 +2410,9 @@ fn main() {
2395
2410
"funding_authority" ,
2396
2411
& cli_config. keypair_path ,
2397
2412
& mut wallet_manager,
2413
+ SignerFromPathConfig {
2414
+ allow_null_signer : false ,
2415
+ } ,
2398
2416
) )
2399
2417
} else {
2400
2418
None
@@ -2404,18 +2422,27 @@ fn main() {
2404
2422
"manager" ,
2405
2423
& cli_config. keypair_path ,
2406
2424
& mut wallet_manager,
2425
+ SignerFromPathConfig {
2426
+ allow_null_signer : false ,
2427
+ } ,
2407
2428
) ;
2408
2429
let token_owner = get_signer (
2409
2430
& matches,
2410
2431
"token_owner" ,
2411
2432
& cli_config. keypair_path ,
2412
2433
& mut wallet_manager,
2434
+ SignerFromPathConfig {
2435
+ allow_null_signer : false ,
2436
+ } ,
2413
2437
) ;
2414
2438
let fee_payer = get_signer (
2415
2439
& matches,
2416
2440
"fee_payer" ,
2417
2441
& cli_config. keypair_path ,
2418
2442
& mut wallet_manager,
2443
+ SignerFromPathConfig {
2444
+ allow_null_signer : false ,
2445
+ } ,
2419
2446
) ;
2420
2447
let verbose = matches. is_present ( "verbose" ) ;
2421
2448
let dry_run = matches. is_present ( "dry_run" ) ;
@@ -2523,10 +2550,20 @@ fn main() {
2523
2550
let stake_account = pubkey_of ( arg_matches, "stake_account" ) . unwrap ( ) ;
2524
2551
let token_receiver: Option < Pubkey > = pubkey_of ( arg_matches, "token_receiver" ) ;
2525
2552
let referrer: Option < Pubkey > = pubkey_of ( arg_matches, "referrer" ) ;
2553
+ let withdraw_authority = get_signer (
2554
+ arg_matches,
2555
+ "withdraw_authority" ,
2556
+ & cli_config. keypair_path ,
2557
+ & mut wallet_manager,
2558
+ SignerFromPathConfig {
2559
+ allow_null_signer : false ,
2560
+ } ,
2561
+ ) ;
2526
2562
command_deposit_stake (
2527
2563
& config,
2528
2564
& stake_pool_address,
2529
2565
& stake_account,
2566
+ withdraw_authority,
2530
2567
& token_receiver,
2531
2568
& referrer,
2532
2569
)
@@ -2577,12 +2614,21 @@ fn main() {
2577
2614
let stake_pool_address = pubkey_of ( arg_matches, "pool" ) . unwrap ( ) ;
2578
2615
let pool_account = pubkey_of ( arg_matches, "pool_account" ) ;
2579
2616
let pool_amount = value_t_or_exit ! ( arg_matches, "amount" , f64 ) ;
2580
- let sol_receiver = pubkey_of ( arg_matches, "sol_receiver" ) ;
2617
+ let sol_receiver = get_signer (
2618
+ arg_matches,
2619
+ "sol_receiver" ,
2620
+ & cli_config. keypair_path ,
2621
+ & mut wallet_manager,
2622
+ SignerFromPathConfig {
2623
+ allow_null_signer : true ,
2624
+ } ,
2625
+ )
2626
+ . pubkey ( ) ;
2581
2627
command_withdraw_sol (
2582
2628
& config,
2583
2629
& stake_pool_address,
2584
- & sol_receiver,
2585
2630
& pool_account,
2631
+ & sol_receiver,
2586
2632
pool_amount,
2587
2633
)
2588
2634
}
0 commit comments