spherenet-admin 0.3.0

Command-line tool for SphereNet governance and network administration
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
//! CLI command definitions
//!
//! CLAP structs and enums defining the CLI interface.
//!
//! Convention for arg value placeholders: `*_KEYPAIR` = path to a keypair file
//! (signs), `*_PUBKEY` = a public key, `*_CREATE_KEY` = a multisig's create-key
//! (pubkey), `*_SO` = a program `.so` file. This makes `--help`/error output say
//! whether each argument is a keypair or a pubkey.

use crate::cli::output::OutputMode;
use clap::{Parser, Subcommand};

/// Default RPC_URL
pub const RPC_URL: &str = "https://api.test.sphere.net";

/// ASCII banner shown at the top of `--help` — the same Small Slant "SphereNet"
/// art as the read-API banner in `server::run`, tagged `admin`.
pub const BANNER_ART: &str = concat!(
    "\n",
    r"   ____     __               _  __    __
  / __/__  / /  ___ _______ / |/ /__ / /_
 _\ \/ _ \/ _ \/ -_) __/ -_)    / -_) __/
/___/ .__/_//_/\__/_/  \__/_/|_/\__/\__/
   /_/                         a d m i n",
);

#[derive(Parser)]
#[command(name = "spherenet-admin", about = BANNER_ART, version)]
pub struct Cli {
    /// RPC URL to connect to
    #[arg(long, global = true, default_value = RPC_URL, value_name = "URL")]
    pub url: String,

    /// Output format: text (human-readable) or json (machine-readable)
    #[arg(long, global = true, value_enum, default_value_t = OutputMode::Text)]
    pub output: OutputMode,

    #[command(subcommand)]
    pub command: Commands,
}

#[derive(Subcommand)]
pub enum Commands {
    /// Validator whitelist commands
    #[command(name = "vw")]
    ValidatorWhitelist {
        #[command(subcommand)]
        action: ValidatorWhitelistAction,
    },
    /// Program whitelist commands
    #[command(name = "pw")]
    ProgramWhitelist {
        #[command(subcommand)]
        action: ProgramWhitelistAction,
    },
    /// Monetary policy commands
    #[command(name = "mp")]
    MonetaryPolicy {
        #[command(subcommand)]
        action: MonetaryPolicyAction,
    },
    /// Program deployment commands
    Program {
        #[command(subcommand)]
        action: ProgramAction,
    },
    /// Multisig vault management commands
    Multisig {
        #[command(subcommand)]
        action: MultisigAction,
    },
    /// Vote account commands
    Vote {
        #[command(subcommand)]
        action: VoteAction,
    },
    /// Stake account commands
    Stake {
        #[command(subcommand)]
        action: StakeAction,
    },
    /// Show the native (SPHR) balance of an account
    Balance {
        /// Account pubkey
        #[arg(value_name = "PUBKEY")]
        pubkey: String,
    },
    /// Show the current epoch
    Epoch,
    /// Serve command output as a read-only JSON HTTP API
    Server {
        /// Port to listen on
        #[arg(long, default_value = "8080", value_name = "PORT")]
        port: u16,
    },
    /// Request an airdrop for an account
    Airdrop {
        /// Account pubkey to receive the airdrop
        #[arg(long, value_name = "PUBKEY")]
        pubkey: String,
        /// Amount in SPHR to airdrop
        #[arg(long, default_value = "1.0", value_name = "SPHR")]
        amount: f64,
    },
    /// Transfer SPHR from one account to another
    Transfer {
        /// Destination account pubkey (mutually exclusive with --to-multisig)
        #[arg(long, conflicts_with = "to_multisig", value_name = "DESTINATION_PUBKEY")]
        to: Option<String>,
        /// Destination multisig by create-key — funds go to its vault, validated
        /// (mutually exclusive with --to)
        #[arg(long, conflicts_with = "to", value_name = "MULTISIG_CREATE_KEY")]
        to_multisig: Option<String>,
        /// Amount in SPHR to transfer
        #[arg(long, value_name = "SPHR")]
        amount: f64,
        /// Single-sig: path to source keypair (mutually exclusive with --multisig)
        #[arg(long, conflicts_with = "multisig", value_name = "FROM_KEYPAIR")]
        from: Option<String>,
        /// Multi-sig: the multisig's create-key (pubkey) (requires --multisig-authority)
        #[arg(long, requires = "multisig_authority", value_name = "MULTISIG_CREATE_KEY")]
        multisig: Option<String>,
        /// Multi-sig: path to signer keypair that pays for proposal creation
        #[arg(long, requires = "multisig", value_name = "MEMBER_KEYPAIR")]
        multisig_authority: Option<String>,
    },
}

#[derive(Subcommand)]
pub enum ValidatorWhitelistAction {
    /// Show validator whitelist account (authority and entries)
    Show,
    /// Request a validator whitelist entry (step 1 of 2 — creates a Pending
    /// entry the authority must approve). The vote account co-signs to prove
    /// control, so this is single-sig only (multisig cannot co-sign).
    Request {
        /// Path to the validator vote-account keypair (co-signs to prove control)
        #[arg(value_name = "VOTE_ACCOUNT_KEYPAIR")]
        vote_account_keypair: String,
        #[arg(long, value_name = "EPOCH")]
        start_epoch: Option<u64>,
        #[arg(long, value_name = "EPOCH")]
        end_epoch: Option<u64>,
        /// Single-sig: path to authority/payer keypair (mutually exclusive with --multisig)
        #[arg(long = "authority", alias = "auth", conflicts_with = "multisig", value_name = "AUTHORITY_KEYPAIR")]
        authority: Option<String>,
        /// Multi-sig: the multisig's create-key (pubkey) (requires --multisig-authority)
        #[arg(long, requires = "multisig_authority", value_name = "MULTISIG_CREATE_KEY")]
        multisig: Option<String>,
        /// Multi-sig: path to signer keypair that pays for proposal creation
        #[arg(long, requires = "multisig", value_name = "MEMBER_KEYPAIR")]
        multisig_authority: Option<String>,
    },
    /// Approve a pending validator whitelist entry (step 2 of 2 — authority action)
    Approve {
        #[arg(value_name = "VOTE_ACCOUNT_PUBKEY")]
        vote_account: String,
        #[arg(long, value_name = "EPOCH")]
        start_epoch: Option<u64>,
        #[arg(long, value_name = "EPOCH")]
        end_epoch: Option<u64>,
        /// Single-sig: path to authority keypair (mutually exclusive with --multisig)
        #[arg(long = "authority", alias = "auth", conflicts_with = "multisig", value_name = "AUTHORITY_KEYPAIR")]
        authority: Option<String>,
        /// Multi-sig: the multisig's create-key (pubkey) (requires --multisig-authority)
        #[arg(long, requires = "multisig_authority", value_name = "MULTISIG_CREATE_KEY")]
        multisig: Option<String>,
        /// Multi-sig: path to signer keypair that pays for proposal creation
        #[arg(long, requires = "multisig", value_name = "MEMBER_KEYPAIR")]
        multisig_authority: Option<String>,
    },
    /// Reject a pending validator whitelist entry (authority action)
    Reject {
        #[arg(value_name = "VOTE_ACCOUNT_PUBKEY")]
        vote_account: String,
        /// Single-sig: path to authority keypair (mutually exclusive with --multisig)
        #[arg(long = "authority", alias = "auth", conflicts_with = "multisig", value_name = "AUTHORITY_KEYPAIR")]
        authority: Option<String>,
        /// Multi-sig: the multisig's create-key (pubkey) (requires --multisig-authority)
        #[arg(long, requires = "multisig_authority", value_name = "MULTISIG_CREATE_KEY")]
        multisig: Option<String>,
        /// Multi-sig: path to signer keypair that pays for proposal creation
        #[arg(long, requires = "multisig", value_name = "MEMBER_KEYPAIR")]
        multisig_authority: Option<String>,
    },
    /// Remove a validator from the whitelist
    Remove {
        #[arg(value_name = "VOTE_ACCOUNT_PUBKEY")]
        vote_account: String,
        /// Single-sig: path to authority keypair (mutually exclusive with --multisig)
        #[arg(long = "authority", alias = "auth", conflicts_with = "multisig", value_name = "AUTHORITY_KEYPAIR")]
        authority: Option<String>,
        /// Multi-sig: the multisig's create-key (pubkey) (requires --multisig-authority)
        #[arg(long, requires = "multisig_authority", value_name = "MULTISIG_CREATE_KEY")]
        multisig: Option<String>,
        /// Multi-sig: path to signer keypair that pays for proposal creation
        #[arg(long, requires = "multisig", value_name = "MEMBER_KEYPAIR")]
        multisig_authority: Option<String>,
    },
    /// Update a validator's start epoch
    UpdateStartEpoch {
        #[arg(value_name = "VOTE_ACCOUNT_PUBKEY")]
        vote_account: String,
        #[arg(long, value_name = "EPOCH")]
        epoch: u64,
        /// Single-sig: path to authority keypair (mutually exclusive with --multisig)
        #[arg(long = "authority", alias = "auth", conflicts_with = "multisig", value_name = "AUTHORITY_KEYPAIR")]
        authority: Option<String>,
        /// Multi-sig: the multisig's create-key (pubkey) (requires --multisig-authority)
        #[arg(long, requires = "multisig_authority", value_name = "MULTISIG_CREATE_KEY")]
        multisig: Option<String>,
        /// Multi-sig: path to signer keypair that pays for proposal creation
        #[arg(long, requires = "multisig", value_name = "MEMBER_KEYPAIR")]
        multisig_authority: Option<String>,
    },
    /// Update a validator's end epoch
    UpdateEndEpoch {
        #[arg(value_name = "VOTE_ACCOUNT_PUBKEY")]
        vote_account: String,
        #[arg(long, value_name = "EPOCH")]
        epoch: u64,
        /// Single-sig: path to authority keypair (mutually exclusive with --multisig)
        #[arg(long = "authority", alias = "auth", conflicts_with = "multisig", value_name = "AUTHORITY_KEYPAIR")]
        authority: Option<String>,
        /// Multi-sig: the multisig's create-key (pubkey) (requires --multisig-authority)
        #[arg(long, requires = "multisig_authority", value_name = "MULTISIG_CREATE_KEY")]
        multisig: Option<String>,
        /// Multi-sig: path to signer keypair that pays for proposal creation
        #[arg(long, requires = "multisig", value_name = "MEMBER_KEYPAIR")]
        multisig_authority: Option<String>,
    },
    /// Propose a new authority
    ProposeAuthority {
        /// New authority pubkey (mutually exclusive with --new-multisig)
        #[arg(long, conflicts_with = "new_multisig", value_name = "NEW_AUTHORITY_PUBKEY")]
        new_authority: Option<String>,
        /// New authority is a multisig, by create-key — resolves to its vault
        /// (mutually exclusive with --new-authority)
        #[arg(long, conflicts_with = "new_authority", value_name = "NEW_MULTISIG_CREATE_KEY")]
        new_multisig: Option<String>,
        /// Single-sig: path to authority keypair (mutually exclusive with --multisig)
        #[arg(long = "authority", alias = "auth", conflicts_with = "multisig", value_name = "AUTHORITY_KEYPAIR")]
        authority: Option<String>,
        /// Multi-sig: the multisig's create-key (pubkey) (requires --multisig-authority)
        #[arg(long, requires = "multisig_authority", value_name = "MULTISIG_CREATE_KEY")]
        multisig: Option<String>,
        /// Multi-sig: path to signer keypair that pays for proposal creation
        #[arg(long, requires = "multisig", value_name = "MEMBER_KEYPAIR")]
        multisig_authority: Option<String>,
    },
    /// Accept pending authority transfer
    AcceptAuthority {
        /// Single-sig: path to authority keypair (mutually exclusive with --multisig)
        #[arg(long = "authority", alias = "auth", conflicts_with = "multisig", value_name = "AUTHORITY_KEYPAIR")]
        authority: Option<String>,
        /// Multi-sig: the multisig's create-key (pubkey) (requires --multisig-authority)
        #[arg(long, requires = "multisig_authority", value_name = "MULTISIG_CREATE_KEY")]
        multisig: Option<String>,
        /// Multi-sig: path to signer keypair that pays for proposal creation
        #[arg(long, requires = "multisig", value_name = "MEMBER_KEYPAIR")]
        multisig_authority: Option<String>,
    },
    /// Cancel pending authority transfer
    CancelAuthority {
        /// Single-sig: path to authority keypair (mutually exclusive with --multisig)
        #[arg(long = "authority", alias = "auth", conflicts_with = "multisig", value_name = "AUTHORITY_KEYPAIR")]
        authority: Option<String>,
        /// Multi-sig: the multisig's create-key (pubkey) (requires --multisig-authority)
        #[arg(long, requires = "multisig_authority", value_name = "MULTISIG_CREATE_KEY")]
        multisig: Option<String>,
        /// Multi-sig: path to signer keypair that pays for proposal creation
        #[arg(long, requires = "multisig", value_name = "MEMBER_KEYPAIR")]
        multisig_authority: Option<String>,
    },
}

#[derive(Subcommand)]
pub enum ProgramWhitelistAction {
    /// Show program whitelist account (authority + deployers)
    Show,
    /// Request a deployer whitelist entry (step 1 of 2 — creates a Pending entry
    /// the authority must approve). The deploy authority co-signs to prove
    /// control, so this is single-sig only (multisig cannot co-sign).
    Request {
        /// Path to the deploy-authority keypair (co-signs to prove control)
        #[arg(value_name = "DEPLOY_AUTHORITY_KEYPAIR")]
        deploy_authority_keypair: String,
        /// Single-sig: path to authority/payer keypair (mutually exclusive with --multisig)
        #[arg(long = "authority", alias = "auth", conflicts_with = "multisig", value_name = "AUTHORITY_KEYPAIR")]
        authority: Option<String>,
        /// Multi-sig: the multisig's create-key (pubkey) (requires --multisig-authority)
        #[arg(long, requires = "multisig_authority", value_name = "MULTISIG_CREATE_KEY")]
        multisig: Option<String>,
        /// Multi-sig: path to signer keypair that pays for proposal creation
        #[arg(long, requires = "multisig", value_name = "MEMBER_KEYPAIR")]
        multisig_authority: Option<String>,
    },
    /// Approve a pending deployer whitelist entry (step 2 of 2 — authority action)
    Approve {
        #[arg(value_name = "DEPLOYER_PUBKEY")]
        deploy_authority: String,
        /// Single-sig: path to authority keypair (mutually exclusive with --multisig)
        #[arg(long = "authority", alias = "auth", conflicts_with = "multisig", value_name = "AUTHORITY_KEYPAIR")]
        authority: Option<String>,
        /// Multi-sig: the multisig's create-key (pubkey) (requires --multisig-authority)
        #[arg(long, requires = "multisig_authority", value_name = "MULTISIG_CREATE_KEY")]
        multisig: Option<String>,
        /// Multi-sig: path to signer keypair that pays for proposal creation
        #[arg(long, requires = "multisig", value_name = "MEMBER_KEYPAIR")]
        multisig_authority: Option<String>,
    },
    /// Reject a pending deployer whitelist entry (authority action)
    Reject {
        #[arg(value_name = "DEPLOYER_PUBKEY")]
        deploy_authority: String,
        /// Single-sig: path to authority keypair (mutually exclusive with --multisig)
        #[arg(long = "authority", alias = "auth", conflicts_with = "multisig", value_name = "AUTHORITY_KEYPAIR")]
        authority: Option<String>,
        /// Multi-sig: the multisig's create-key (pubkey) (requires --multisig-authority)
        #[arg(long, requires = "multisig_authority", value_name = "MULTISIG_CREATE_KEY")]
        multisig: Option<String>,
        /// Multi-sig: path to signer keypair that pays for proposal creation
        #[arg(long, requires = "multisig", value_name = "MEMBER_KEYPAIR")]
        multisig_authority: Option<String>,
    },
    /// Remove a deployer authority from the whitelist
    Remove {
        #[arg(value_name = "DEPLOYER_PUBKEY")]
        deploy_authority: String,
        /// Single-sig: path to authority keypair (mutually exclusive with --multisig)
        #[arg(long = "authority", alias = "auth", conflicts_with = "multisig", value_name = "AUTHORITY_KEYPAIR")]
        authority: Option<String>,
        /// Multi-sig: the multisig's create-key (pubkey) (requires --multisig-authority)
        #[arg(long, requires = "multisig_authority", value_name = "MULTISIG_CREATE_KEY")]
        multisig: Option<String>,
        /// Multi-sig: path to signer keypair that pays for proposal creation
        #[arg(long, requires = "multisig", value_name = "MEMBER_KEYPAIR")]
        multisig_authority: Option<String>,
    },
    /// Propose a new authority
    ProposeAuthority {
        /// New authority pubkey (mutually exclusive with --new-multisig)
        #[arg(long, conflicts_with = "new_multisig", value_name = "NEW_AUTHORITY_PUBKEY")]
        new_authority: Option<String>,
        /// New authority is a multisig, by create-key — resolves to its vault
        /// (mutually exclusive with --new-authority)
        #[arg(long, conflicts_with = "new_authority", value_name = "NEW_MULTISIG_CREATE_KEY")]
        new_multisig: Option<String>,
        /// Single-sig: path to authority keypair (mutually exclusive with --multisig)
        #[arg(long = "authority", alias = "auth", conflicts_with = "multisig", value_name = "AUTHORITY_KEYPAIR")]
        authority: Option<String>,
        /// Multi-sig: the multisig's create-key (pubkey) (requires --multisig-authority)
        #[arg(long, requires = "multisig_authority", value_name = "MULTISIG_CREATE_KEY")]
        multisig: Option<String>,
        /// Multi-sig: path to signer keypair that pays for proposal creation
        #[arg(long, requires = "multisig", value_name = "MEMBER_KEYPAIR")]
        multisig_authority: Option<String>,
    },
    /// Accept pending authority transfer
    AcceptAuthority {
        /// Single-sig: path to authority keypair (mutually exclusive with --multisig)
        #[arg(long = "authority", alias = "auth", conflicts_with = "multisig", value_name = "AUTHORITY_KEYPAIR")]
        authority: Option<String>,
        /// Multi-sig: the multisig's create-key (pubkey) (requires --multisig-authority)
        #[arg(long, requires = "multisig_authority", value_name = "MULTISIG_CREATE_KEY")]
        multisig: Option<String>,
        /// Multi-sig: path to signer keypair that pays for proposal creation
        #[arg(long, requires = "multisig", value_name = "MEMBER_KEYPAIR")]
        multisig_authority: Option<String>,
    },
    /// Cancel pending authority transfer
    CancelAuthority {
        /// Single-sig: path to authority keypair (mutually exclusive with --multisig)
        #[arg(long = "authority", alias = "auth", conflicts_with = "multisig", value_name = "AUTHORITY_KEYPAIR")]
        authority: Option<String>,
        /// Multi-sig: the multisig's create-key (pubkey) (requires --multisig-authority)
        #[arg(long, requires = "multisig_authority", value_name = "MULTISIG_CREATE_KEY")]
        multisig: Option<String>,
        /// Multi-sig: path to signer keypair that pays for proposal creation
        #[arg(long, requires = "multisig", value_name = "MEMBER_KEYPAIR")]
        multisig_authority: Option<String>,
    },
}

#[derive(Subcommand)]
pub enum ProgramAction {
    /// Deploy a program to SphereNet
    Deploy {
        /// Path to the program .so file
        #[arg(long, value_name = "PROGRAM_SO")]
        program_so: String,

        /// Path to the program keypair (the program ID is derived from this)
        #[arg(long, value_name = "PROGRAM_KEYPAIR")]
        program_keypair: String,

        /// Path to upgrade authority keypair (must sign deployment)
        #[arg(long, value_name = "UPGRADE_AUTHORITY_KEYPAIR")]
        upgrade_authority: String,

        /// Payer keypair path (defaults to solana config default keypair)
        #[arg(long, value_name = "PAYER_KEYPAIR")]
        payer: String,

        /// Maximum program data length (optional, defaults to program size)
        #[arg(long, value_name = "BYTES")]
        max_data_len: Option<usize>,
    },
    /// Upgrade an existing program on SphereNet
    Upgrade {
        /// Program ID of the existing program to upgrade
        #[arg(long, value_name = "PROGRAM_ID")]
        program_id: String,

        /// Path to the new program .so file
        #[arg(long, value_name = "PROGRAM_SO")]
        program_so: String,

        /// Single-sig: path to upgrade authority keypair (mutually exclusive with --multisig)
        #[arg(long, conflicts_with = "multisig", value_name = "UPGRADE_AUTHORITY_KEYPAIR")]
        upgrade_authority: Option<String>,

        /// Multi-sig: the multisig's create-key (pubkey) (requires --multisig-authority)
        #[arg(long, requires = "multisig_authority", value_name = "MULTISIG_CREATE_KEY")]
        multisig: Option<String>,

        /// Multi-sig: path to signer keypair that pays for proposal creation
        #[arg(long, requires = "multisig", value_name = "MEMBER_KEYPAIR")]
        multisig_authority: Option<String>,

        /// Payer keypair path
        #[arg(long, value_name = "PAYER_KEYPAIR")]
        payer: String,

        /// Spill account (where excess buffer rent is returned, defaults to payer)
        #[arg(long, value_name = "SPILL_PUBKEY")]
        spill: Option<String>,
    },
    /// Extend a program's data account to accommodate larger programs
    Extend {
        /// Program ID of the program to extend
        #[arg(long, value_name = "PROGRAM_ID")]
        program_id: String,

        /// Number of additional bytes to add
        #[arg(long, value_name = "BYTES")]
        bytes: u32,

        /// Single-sig: path to upgrade authority keypair (mutually exclusive with --multisig)
        #[arg(long, conflicts_with = "multisig", value_name = "UPGRADE_AUTHORITY_KEYPAIR")]
        upgrade_authority: Option<String>,

        /// Multi-sig: the multisig's create-key (pubkey) (requires --multisig-authority)
        #[arg(long, requires = "multisig_authority", value_name = "MULTISIG_CREATE_KEY")]
        multisig: Option<String>,

        /// Multi-sig: path to signer keypair that pays for proposal creation
        #[arg(long, requires = "multisig", value_name = "MEMBER_KEYPAIR")]
        multisig_authority: Option<String>,

        /// Payer keypair path
        #[arg(long, value_name = "PAYER_KEYPAIR")]
        payer: String,
    },
    /// Transfer a program's upgrade authority (or renounce it with --final)
    SetUpgradeAuthority {
        /// Program ID whose upgrade authority to transfer
        #[arg(long, value_name = "PROGRAM_ID")]
        program_id: String,

        /// New authority pubkey (mutually exclusive with --new-multisig)
        #[arg(long, conflicts_with = "new_multisig", value_name = "NEW_AUTHORITY_PUBKEY")]
        new_authority: Option<String>,
        /// New authority is a multisig, by create-key — resolves to its vault
        /// (mutually exclusive with --new-authority)
        #[arg(long, conflicts_with = "new_authority", value_name = "NEW_MULTISIG_CREATE_KEY")]
        new_multisig: Option<String>,
        /// Renounce upgradeability — set the authority to none (program becomes
        /// permanently immutable). Mutually exclusive with --new-authority/--new-multisig.
        #[arg(long = "final", conflicts_with_all = ["new_authority", "new_multisig"])]
        make_final: bool,

        /// Single-sig: path to the current upgrade authority keypair (mutually exclusive with --multisig)
        #[arg(long = "authority", alias = "auth", conflicts_with = "multisig", value_name = "AUTHORITY_KEYPAIR")]
        authority: Option<String>,
        /// Multi-sig: the multisig's create-key (pubkey) (requires --multisig-authority)
        #[arg(long, requires = "multisig_authority", value_name = "MULTISIG_CREATE_KEY")]
        multisig: Option<String>,
        /// Multi-sig: path to signer keypair that pays for proposal creation
        #[arg(long, requires = "multisig", value_name = "MEMBER_KEYPAIR")]
        multisig_authority: Option<String>,
    },
}

#[derive(Subcommand)]
pub enum MultisigAction {
    /// Create a new multisig vault
    Create {
        /// Comma-separated list of member pubkeys
        #[arg(long, value_name = "MEMBER_PUBKEYS")]
        members: String,

        /// Number of approvals required (e.g., 2 for 2-of-3)
        #[arg(long, value_name = "THRESHOLD")]
        threshold: u16,

        /// Path to create-key keypair (unique ID for this multisig; signs creation)
        #[arg(long, value_name = "CREATE_KEY_KEYPAIR")]
        create_key: String,

        /// Path to payer keypair
        #[arg(long, value_name = "PAYER_KEYPAIR")]
        payer: String,

        /// Optional: time lock delay in seconds
        #[arg(long, value_name = "SECONDS")]
        time_lock: Option<u32>,

        /// Optional: description/memo
        #[arg(long, value_name = "MEMO")]
        memo: Option<String>,
    },
    /// Show multisig vault information (fetches on-chain data)
    Show {
        /// The multisig, identified by its create-key (pubkey)
        #[arg(long = "multisig", value_name = "MULTISIG_CREATE_KEY")]
        create_key: String,
    },
    /// Approve a multisig proposal
    Approve {
        /// The multisig, identified by its create-key (pubkey)
        #[arg(long = "multisig", value_name = "MULTISIG_CREATE_KEY")]
        create_key: String,

        /// Transaction index of the proposal to approve
        #[arg(long, value_name = "INDEX")]
        transaction_index: u64,

        /// Path to member keypair who is approving
        #[arg(long, value_name = "MEMBER_KEYPAIR")]
        member: String,
    },
    /// Execute an approved multisig proposal
    Execute {
        /// The multisig, identified by its create-key (pubkey)
        #[arg(long = "multisig", value_name = "MULTISIG_CREATE_KEY")]
        create_key: String,

        /// Transaction index of the proposal to execute
        #[arg(long, value_name = "INDEX")]
        transaction_index: u64,

        /// Path to member keypair who is executing
        #[arg(long, value_name = "MEMBER_KEYPAIR")]
        member: String,
    },
}

#[derive(Subcommand)]
pub enum MonetaryPolicyAction {
    /// Show monetary policy account details
    Show,
    /// Propose a new authority
    ProposeAuthority {
        /// New authority pubkey (mutually exclusive with --new-multisig)
        #[arg(long, conflicts_with = "new_multisig", value_name = "NEW_AUTHORITY_PUBKEY")]
        new_authority: Option<String>,
        /// New authority is a multisig, by create-key — resolves to its vault
        /// (mutually exclusive with --new-authority)
        #[arg(long, conflicts_with = "new_authority", value_name = "NEW_MULTISIG_CREATE_KEY")]
        new_multisig: Option<String>,
        /// Single-sig: path to authority keypair (mutually exclusive with --multisig)
        #[arg(long = "authority", alias = "auth", conflicts_with = "multisig", value_name = "AUTHORITY_KEYPAIR")]
        authority: Option<String>,
        /// Multi-sig: the multisig's create-key (pubkey) (requires --multisig-authority)
        #[arg(long, requires = "multisig_authority", value_name = "MULTISIG_CREATE_KEY")]
        multisig: Option<String>,
        /// Multi-sig: path to signer keypair that pays for proposal creation
        #[arg(long, requires = "multisig", value_name = "MEMBER_KEYPAIR")]
        multisig_authority: Option<String>,
    },
    /// Accept pending authority transfer
    AcceptAuthority {
        /// Single-sig: path to authority keypair (mutually exclusive with --multisig)
        #[arg(long = "authority", alias = "auth", conflicts_with = "multisig", value_name = "AUTHORITY_KEYPAIR")]
        authority: Option<String>,
        /// Multi-sig: the multisig's create-key (pubkey) (requires --multisig-authority)
        #[arg(long, requires = "multisig_authority", value_name = "MULTISIG_CREATE_KEY")]
        multisig: Option<String>,
        /// Multi-sig: path to signer keypair that pays for proposal creation
        #[arg(long, requires = "multisig", value_name = "MEMBER_KEYPAIR")]
        multisig_authority: Option<String>,
    },
    /// Cancel pending authority transfer
    CancelAuthority {
        /// Single-sig: path to authority keypair (mutually exclusive with --multisig)
        #[arg(long = "authority", alias = "auth", conflicts_with = "multisig", value_name = "AUTHORITY_KEYPAIR")]
        authority: Option<String>,
        /// Multi-sig: the multisig's create-key (pubkey) (requires --multisig-authority)
        #[arg(long, requires = "multisig_authority", value_name = "MULTISIG_CREATE_KEY")]
        multisig: Option<String>,
        /// Multi-sig: path to signer keypair that pays for proposal creation
        #[arg(long, requires = "multisig", value_name = "MEMBER_KEYPAIR")]
        multisig_authority: Option<String>,
    },
    /// Update inflation rate (in basis points)
    UpdateInflationRate {
        /// New inflation rate in basis points (0-2000 bips = 0-20%)
        #[arg(value_name = "BIPS")]
        new_rate_bips: u64,
        /// Single-sig: path to authority keypair (mutually exclusive with --multisig)
        #[arg(long = "authority", alias = "auth", conflicts_with = "multisig", value_name = "AUTHORITY_KEYPAIR")]
        authority: Option<String>,
        /// Multi-sig: the multisig's create-key (pubkey) (requires --multisig-authority)
        #[arg(long, requires = "multisig_authority", value_name = "MULTISIG_CREATE_KEY")]
        multisig: Option<String>,
        /// Multi-sig: path to signer keypair that pays for proposal creation
        #[arg(long, requires = "multisig", value_name = "MEMBER_KEYPAIR")]
        multisig_authority: Option<String>,
    },
    /// Update lamports per signature (transaction fee)
    UpdateLamportsPerSignature {
        /// New lamports per signature (1-10,000,000 lamports)
        #[arg(value_name = "LAMPORTS")]
        new_lamports_per_signature: u64,
        /// Single-sig: path to authority keypair (mutually exclusive with --multisig)
        #[arg(long = "authority", alias = "auth", conflicts_with = "multisig", value_name = "AUTHORITY_KEYPAIR")]
        authority: Option<String>,
        /// Multi-sig: the multisig's create-key (pubkey) (requires --multisig-authority)
        #[arg(long, requires = "multisig_authority", value_name = "MULTISIG_CREATE_KEY")]
        multisig: Option<String>,
        /// Multi-sig: path to signer keypair that pays for proposal creation
        #[arg(long, requires = "multisig", value_name = "MEMBER_KEYPAIR")]
        multisig_authority: Option<String>,
    },
    /// Update burn percent
    UpdateBurnPercent {
        /// New burn percent (0-100%)
        #[arg(value_name = "PERCENT")]
        new_percent: u8,
        /// Single-sig: path to authority keypair (mutually exclusive with --multisig)
        #[arg(long = "authority", alias = "auth", conflicts_with = "multisig", value_name = "AUTHORITY_KEYPAIR")]
        authority: Option<String>,
        /// Multi-sig: the multisig's create-key (pubkey) (requires --multisig-authority)
        #[arg(long, requires = "multisig_authority", value_name = "MULTISIG_CREATE_KEY")]
        multisig: Option<String>,
        /// Multi-sig: path to signer keypair that pays for proposal creation
        #[arg(long, requires = "multisig", value_name = "MEMBER_KEYPAIR")]
        multisig_authority: Option<String>,
    },
    /// Update VAT lamports per epoch (Vote Admission Ticket price for Alpenglow voting)
    UpdateVatLamportsPerEpoch {
        /// New VAT lamports per epoch (0-100,000,000,000 lamports)
        #[arg(value_name = "LAMPORTS")]
        new_vat_lamports: u64,
        /// Single-sig: path to authority keypair (mutually exclusive with --multisig)
        #[arg(long = "authority", alias = "auth", conflicts_with = "multisig", value_name = "AUTHORITY_KEYPAIR")]
        authority: Option<String>,
        /// Multi-sig: the multisig's create-key (pubkey) (requires --multisig-authority)
        #[arg(long, requires = "multisig_authority", value_name = "MULTISIG_CREATE_KEY")]
        multisig: Option<String>,
        /// Multi-sig: path to signer keypair that pays for proposal creation
        #[arg(long, requires = "multisig", value_name = "MEMBER_KEYPAIR")]
        multisig_authority: Option<String>,
    },
}

#[derive(Subcommand)]
pub enum VoteAction {
    /// Show a vote account's identity, authorities, commission, and voting state
    Show {
        /// Vote account pubkey
        #[arg(value_name = "VOTE_ACCOUNT_PUBKEY")]
        vote_account: String,
    },
    /// Create and initialize a vote account
    Create {
        /// Path to the new vote account keypair (signs its own creation)
        #[arg(long, value_name = "VOTE_ACCOUNT_KEYPAIR")]
        vote_account: String,
        /// Path to the validator identity (node) keypair (signs initialization)
        #[arg(long, value_name = "IDENTITY_KEYPAIR")]
        identity: String,
        /// Pubkey authorized to submit votes
        #[arg(long, value_name = "AUTHORIZED_VOTER_PUBKEY")]
        authorized_voter: String,
        /// Pubkey authorized to withdraw from the vote account
        #[arg(long, value_name = "AUTHORIZED_WITHDRAWER_PUBKEY")]
        authorized_withdrawer: String,
        /// Inflation-rewards commission percentage (0-100)
        #[arg(long, default_value = "100", value_name = "PERCENT")]
        commission: u8,
        /// Path to keypair that funds the vote account's rent-exempt reserve
        #[arg(long, value_name = "FUNDER_KEYPAIR")]
        from: String,
        /// Path to keypair that pays transaction fees
        #[arg(long, alias = "fee-payer", value_name = "PAYER_KEYPAIR")]
        payer: String,
        /// Create a legacy V1 vote account (no BLS key). Use on networks where
        /// the vote-account-initialize-v2 feature (SIMD-0464) is not yet active.
        #[arg(long)]
        no_bls: bool,
    },
    /// Withdraw lamports from a vote account (signed by the withdraw authority)
    Withdraw {
        /// Vote account pubkey
        #[arg(long, value_name = "VOTE_ACCOUNT_PUBKEY")]
        vote_account: String,
        /// Destination pubkey that receives the withdrawn SPHR
        #[arg(long, value_name = "DESTINATION_PUBKEY")]
        destination: String,
        /// Amount of SPHR to withdraw (mutually exclusive with --all)
        #[arg(long, conflicts_with = "all", value_name = "SPHR")]
        amount: Option<f64>,
        /// Withdraw the entire balance and close the account
        #[arg(long)]
        all: bool,
        /// Path to the withdraw authority keypair; signs the withdrawal
        #[arg(long, value_name = "WITHDRAW_AUTHORITY_KEYPAIR")]
        withdraw_authority: String,
        /// Path to keypair that pays transaction fees
        #[arg(long, alias = "fee-payer", value_name = "PAYER_KEYPAIR")]
        payer: String,
    },
}

#[derive(Subcommand)]
pub enum StakeAction {
    /// Show a stake account's authorities, lockup, and delegation state
    Show {
        /// Stake account pubkey
        #[arg(value_name = "STAKE_ACCOUNT_PUBKEY")]
        stake_account: String,
    },
    /// Create and initialize a stake account (does not delegate)
    Create {
        /// Path to the new stake account keypair (signs its own creation)
        #[arg(long, value_name = "STAKE_ACCOUNT_KEYPAIR")]
        stake_account: String,
        /// Amount of SPHR to deposit (total; delegatable = amount − rent reserve)
        #[arg(long, value_name = "SPHR")]
        amount: f64,
        /// Pubkey set as the stake authority (staker)
        #[arg(long, value_name = "STAKE_AUTHORITY_PUBKEY")]
        stake_authority: String,
        /// Pubkey set as the withdraw authority
        #[arg(long, value_name = "WITHDRAW_AUTHORITY_PUBKEY")]
        withdraw_authority: String,
        /// Path to keypair that funds the deposited SPHR
        #[arg(long, value_name = "FUNDER_KEYPAIR")]
        from: String,
        /// Path to keypair that pays transaction fees
        #[arg(long, alias = "fee-payer", value_name = "PAYER_KEYPAIR")]
        payer: String,
    },
    /// Delegate an existing stake account to a vote account
    Delegate {
        /// Stake account pubkey (must be initialized, not already delegated)
        #[arg(long, value_name = "STAKE_ACCOUNT_PUBKEY")]
        stake_account: String,
        /// Vote account pubkey to delegate to (must be whitelisted)
        #[arg(long, value_name = "VOTE_ACCOUNT_PUBKEY")]
        vote_account: String,
        /// Path to the stake authority (staker) keypair; signs the delegation
        #[arg(long, value_name = "STAKE_AUTHORITY_KEYPAIR")]
        stake_authority: String,
        /// Path to keypair that pays transaction fees
        #[arg(long, alias = "fee-payer", value_name = "PAYER_KEYPAIR")]
        payer: String,
    },
    /// Deactivate a delegated stake account (begins cooldown)
    Deactivate {
        /// Stake account pubkey (must be delegated)
        #[arg(long, value_name = "STAKE_ACCOUNT_PUBKEY")]
        stake_account: String,
        /// Path to the stake authority (staker) keypair; signs the deactivation
        #[arg(long, value_name = "STAKE_AUTHORITY_KEYPAIR")]
        stake_authority: String,
        /// Path to keypair that pays transaction fees
        #[arg(long, alias = "fee-payer", value_name = "PAYER_KEYPAIR")]
        payer: String,
    },
    /// Withdraw lamports from a stake account (use --all to drain & close)
    Withdraw {
        /// Stake account pubkey
        #[arg(long, value_name = "STAKE_ACCOUNT_PUBKEY")]
        stake_account: String,
        /// Destination pubkey that receives the withdrawn SPHR
        #[arg(long, value_name = "DESTINATION_PUBKEY")]
        destination: String,
        /// Amount of SPHR to withdraw (mutually exclusive with --all)
        #[arg(long, conflicts_with = "all", value_name = "SPHR")]
        amount: Option<f64>,
        /// Withdraw the entire balance and close the account
        #[arg(long)]
        all: bool,
        /// Path to the withdraw authority keypair; signs the withdrawal
        #[arg(long, value_name = "WITHDRAW_AUTHORITY_KEYPAIR")]
        withdraw_authority: String,
        /// Path to keypair that pays transaction fees
        #[arg(long, alias = "fee-payer", value_name = "PAYER_KEYPAIR")]
        payer: String,
    },
}