From 42aeead6b4e97663c8941ea5761b03b56eaa4be0 Mon Sep 17 00:00:00 2001 From: Michael Vines Date: Wed, 30 Sep 2020 20:17:29 -0700 Subject: [PATCH] Add inflation subcommand --- cli/src/cli.rs | 12 +++++- cli/src/feature.rs | 5 +-- cli/src/inflation.rs | 89 ++++++++++++++++++++++++++++++++++++++++++++ cli/src/lib.rs | 1 + 4 files changed, 102 insertions(+), 5 deletions(-) create mode 100644 cli/src/inflation.rs diff --git a/cli/src/cli.rs b/cli/src/cli.rs index d1c0ff24f3..ef37b9964e 100644 --- a/cli/src/cli.rs +++ b/cli/src/cli.rs @@ -1,6 +1,6 @@ use crate::{ - checks::*, cluster_query::*, feature::*, nonce::*, spend_utils::*, stake::*, validator_info::*, - vote::*, + checks::*, cluster_query::*, feature::*, inflation::*, nonce::*, spend_utils::*, stake::*, + validator_info::*, vote::*, }; use clap::{value_t_or_exit, App, AppSettings, Arg, ArgMatches, SubCommand}; use log::*; @@ -93,6 +93,7 @@ pub enum CliCommand { program_id: Pubkey, }, Feature(FeatureCliCommand), + Inflation(InflationCliCommand), Fees, FirstAvailableBlock, GetBlock { @@ -557,6 +558,9 @@ pub fn parse_command( ("epoch", Some(matches)) => parse_get_epoch(matches), ("slot", Some(matches)) => parse_get_slot(matches), ("block-height", Some(matches)) => parse_get_block_height(matches), + ("inflation", Some(matches)) => { + parse_inflation_subcommand(matches, default_signer, wallet_manager) + } ("largest-accounts", Some(matches)) => parse_largest_accounts(matches), ("supply", Some(matches)) => parse_supply(matches), ("total-supply", Some(matches)) => parse_total_supply(matches), @@ -1365,6 +1369,9 @@ pub fn process_command(config: &CliConfig) -> ProcessResult { process_largest_accounts(&rpc_client, config, filter.clone()) } CliCommand::GetTransactionCount => process_get_transaction_count(&rpc_client, config), + CliCommand::Inflation(inflation_subcommand) => { + process_inflation_subcommand(&rpc_client, config, inflation_subcommand) + } CliCommand::LeaderSchedule => process_leader_schedule(&rpc_client), CliCommand::LiveSlots => process_live_slots(&config.websocket_url), CliCommand::Ping { @@ -1968,6 +1975,7 @@ pub fn app<'ab, 'v>(name: &str, about: &'ab str, version: &'v str) -> App<'ab, ' ) .cluster_query_subcommands() .feature_subcommands() + .inflation_subcommands() .nonce_subcommands() .stake_subcommands() .subcommand( diff --git a/cli/src/feature.rs b/cli/src/feature.rs index b8a3a59769..527360aa0e 100644 --- a/cli/src/feature.rs +++ b/cli/src/feature.rs @@ -19,7 +19,6 @@ use solana_sdk::{ use std::{collections::HashMap, fmt, sync::Arc}; #[derive(Debug, PartialEq)] -#[allow(clippy::large_enum_variant)] pub enum FeatureCliCommand { Status { features: Vec }, Activate { feature: Pubkey }, @@ -242,7 +241,7 @@ fn feature_activation_allowed(rpc_client: &RpcClient) -> Result Result Self; +} + +impl InflationSubCommands for App<'_, '_> { + fn inflation_subcommands(self) -> Self { + self.subcommand(SubCommand::with_name("inflation").about("Show inflation information")) + } +} + +pub fn parse_inflation_subcommand( + _matches: &ArgMatches<'_>, + _default_signer: &DefaultSigner, + _wallet_manager: &mut Option>, +) -> Result { + Ok(CliCommandInfo { + command: CliCommand::Inflation(InflationCliCommand::Show), + signers: vec![], + }) +} + +pub fn process_inflation_subcommand( + rpc_client: &RpcClient, + _config: &CliConfig, + inflation_subcommand: &InflationCliCommand, +) -> ProcessResult { + assert_eq!(*inflation_subcommand, InflationCliCommand::Show); + + let governor = rpc_client.get_inflation_governor()?; + let current_inflation_rate = rpc_client.get_inflation_rate()?; + + println!("{}", style("Inflation Governor:").bold()); + if (governor.initial - governor.terminal).abs() < f64::EPSILON { + println!( + "Fixed APR: {:>5.2}%", + governor.terminal * 100. + ); + } else { + println!("Initial APR: {:>5.2}%", governor.initial * 100.); + println!( + "Terminal APR: {:>5.2}%", + governor.terminal * 100. + ); + println!("Rate reduction per year: {:>5.2}%", governor.taper * 100.); + } + if governor.foundation_term > 0. { + println!("Foundation percentage: {:>5.2}%", governor.foundation); + println!( + "Foundation term: {:.1} years", + governor.foundation_term + ); + } + + println!( + "\n{}", + style(format!( + "Inflation for Epoch {}:", + current_inflation_rate.epoch + )) + .bold() + ); + println!( + "Total APR: {:>5.2}%", + current_inflation_rate.total * 100. + ); + println!( + "Staking APR: {:>5.2}%", + current_inflation_rate.validator * 100. + ); + println!( + "Foundation APR: {:>5.2}%", + current_inflation_rate.foundation * 100. + ); + + Ok("".to_string()) +} diff --git a/cli/src/lib.rs b/cli/src/lib.rs index 30f36b999a..c2816dfc6a 100644 --- a/cli/src/lib.rs +++ b/cli/src/lib.rs @@ -24,6 +24,7 @@ pub mod checks; pub mod cli; pub mod cluster_query; pub mod feature; +pub mod inflation; pub mod nonce; pub mod spend_utils; pub mod stake;