near_cli_rs/commands/staking/delegate/
mod.rs1use strum::{EnumDiscriminants, EnumIter, EnumMessage};
2
3mod deposit_and_stake;
4mod stake;
5mod stake_all;
6mod unstake;
7mod unstake_all;
8pub mod view_balance;
9mod withdraw;
10mod withdraw_all;
11
12#[derive(Debug, Clone, interactive_clap::InteractiveClap)]
13#[interactive_clap(input_context = crate::GlobalContext)]
14#[interactive_clap(output_context = StakeDelegationContext)]
15pub struct StakeDelegation {
16 #[interactive_clap(skip_default_input_arg)]
17 account_id: crate::types::account_id::AccountId,
19 #[interactive_clap(subcommand)]
20 delegate_stake_command: StakeDelegationCommand,
21}
22
23#[derive(Debug, Clone)]
24pub struct StakeDelegationContext {
25 global_context: crate::GlobalContext,
26 account_id: near_primitives::types::AccountId,
27}
28
29impl StakeDelegationContext {
30 pub fn from_previous_context(
31 previous_context: crate::GlobalContext,
32 scope: &<StakeDelegation as interactive_clap::ToInteractiveClapContextScope>::InteractiveClapContextScope,
33 ) -> color_eyre::eyre::Result<Self> {
34 Ok(Self {
35 global_context: previous_context,
36 account_id: scope.account_id.clone().into(),
37 })
38 }
39}
40
41impl StakeDelegation {
42 pub fn input_account_id(
43 context: &crate::GlobalContext,
44 ) -> color_eyre::eyre::Result<Option<crate::types::account_id::AccountId>> {
45 crate::common::input_non_signer_account_id_from_used_account_list(
46 &context.config.credentials_home_dir,
47 "Enter the account that you want to manage delegated stake for:",
48 )
49 }
50}
51
52#[derive(Debug, EnumDiscriminants, Clone, interactive_clap::InteractiveClap)]
53#[interactive_clap(context = StakeDelegationContext)]
54#[strum_discriminants(derive(EnumMessage, EnumIter))]
55#[non_exhaustive]
56pub enum StakeDelegationCommand {
58 #[strum_discriminants(strum(
59 message = "view-balance - View the delegated stake balance for a given account"
60 ))]
61 ViewBalance(self::view_balance::ViewBalance),
63 #[strum_discriminants(strum(
64 message = "deposit-and-stake - Delegate NEAR tokens to a validator's staking pool"
65 ))]
66 DepositAndStake(self::deposit_and_stake::DepositAndStake),
68 #[strum_discriminants(strum(
69 message = "stake - Delegate a certain amount of previously deposited or unstaked NEAR tokens to a validator's staking pool"
70 ))]
71 Stake(self::stake::Stake),
73 #[strum_discriminants(strum(
74 message = "stake-all - Delegate all previously deposited or unstaked NEAR tokens to a validator's staking pool"
75 ))]
76 StakeAll(self::stake_all::StakeAll),
78 #[strum_discriminants(strum(
79 message = "unstake - Unstake a certain amount of delegated NEAR tokens from a validator's staking pool"
80 ))]
81 Unstake(self::unstake::Unstake),
83 #[strum_discriminants(strum(
84 message = "unstake-all - Unstake all delegated NEAR tokens from a validator's staking pool"
85 ))]
86 UnstakeAll(self::unstake_all::UnstakeAll),
88 #[strum_discriminants(strum(
89 message = "withdraw - Withdraw a certain amount of unstaked NEAR tokens from a validator's staking pool"
90 ))]
91 Withdraw(self::withdraw::Withdraw),
93 #[strum_discriminants(strum(
94 message = "withdraw-all - Withdraw all unstaked NEAR tokens from a validator's staking pool"
95 ))]
96 WithdrawAll(self::withdraw_all::WithdrawAll),
98}