Skip to content

Commit

Permalink
authorized_staker arg is now stake-pool implementation specific
Browse files Browse the repository at this point in the history
  • Loading branch information
mvines committed Apr 29, 2021
1 parent c3d4c6d commit 8c80315
Show file tree
Hide file tree
Showing 5 changed files with 96 additions and 90 deletions.
7 changes: 1 addition & 6 deletions src/generic_stake_pool.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,4 @@
use {
solana_client::rpc_client::RpcClient,
solana_sdk::{pubkey::Pubkey, signature::Keypair},
std::error,
};
use {solana_client::rpc_client::RpcClient, solana_sdk::pubkey::Pubkey, std::error};

#[derive(Debug, PartialEq, Clone, Copy)]
pub enum ValidatorStakeState {
Expand All @@ -25,7 +21,6 @@ pub trait GenericStakePool {
&mut self,
rpc_client: &RpcClient,
dry_run: bool,
authorized_staker: &Keypair,
desired_validator_stake: &[ValidatorStake],
) -> Result<Vec<String>, Box<dyn error::Error>>;
}
16 changes: 10 additions & 6 deletions src/legacy_stake_pool.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ use {
std::{collections::HashSet, error},
};

#[derive(Default)]
pub struct LegacyStakePool {
authorized_staker: Keypair,
baseline_stake_amount: u64,
bonus_stake_amount: u64,
source_stake_address: Pubkey,
Expand All @@ -23,12 +23,14 @@ pub struct LegacyStakePool {

pub fn new(
_rpc_client: &RpcClient,
authorized_staker: Keypair,
baseline_stake_amount: u64,
bonus_stake_amount: u64,
source_stake_address: Pubkey,
validator_list: HashSet<Pubkey>,
) -> Result<LegacyStakePool, Box<dyn error::Error>> {
Ok(LegacyStakePool {
authorized_staker,
baseline_stake_amount,
bonus_stake_amount,
source_stake_address,
Expand All @@ -45,17 +47,19 @@ impl GenericStakePool for LegacyStakePool {
&mut self,
rpc_client: &RpcClient,
dry_run: bool,
authorized_staker: &Keypair,
validator_stake: &[ValidatorStake],
) -> Result<Vec<String>, Box<dyn error::Error>> {
let (init_transactions, update_transactions) =
self.build_transactions(rpc_client, authorized_staker.pubkey(), &validator_stake)?;
let (init_transactions, update_transactions) = self.build_transactions(
rpc_client,
self.authorized_staker.pubkey(),
&validator_stake,
)?;

if !send_and_confirm_transactions(
rpc_client,
dry_run,
init_transactions,
authorized_staker,
&self.authorized_staker,
&mut vec![],
)? {
return Err("Failed to initialize stake pool. Unable to continue".into());
Expand All @@ -69,7 +73,7 @@ impl GenericStakePool for LegacyStakePool {
rpc_client,
dry_run,
update_transactions,
authorized_staker,
&self.authorized_staker,
&mut notifications,
)?;

Expand Down
49 changes: 33 additions & 16 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ use {
commitment_config::CommitmentConfig,
native_token::*,
pubkey::Pubkey,
signature::Keypair,
slot_history::{self, SlotHistory},
sysvar,
},
Expand Down Expand Up @@ -157,7 +156,6 @@ fn release_version_of(matches: &ArgMatches<'_>, name: &str) -> Option<semver::Ve
struct Config {
json_rpc_url: String,
cluster: String,
authorized_staker: Keypair,

dry_run: bool,

Expand Down Expand Up @@ -211,7 +209,6 @@ impl Config {
Self {
json_rpc_url: "https://api.mainnet-beta.solana.com".to_string(),
cluster: "mainnet-beta".to_string(),
authorized_staker: Keypair::new(),
dry_run: true,
quality_block_producer_percentage: 15,
max_poor_block_producer_percentage: 20,
Expand Down Expand Up @@ -443,15 +440,6 @@ fn get_config() -> BoxResult<(Config, RpcClient, Box<dyn GenericStakePool>)> {
destaking those in the list and warning \
any others")
)
.arg(
Arg::with_name("authorized_staker")
.index(1)
.value_name("KEYPAIR")
.validator(is_keypair)
.required(true)
.takes_value(true)
.help("Keypair of the authorized staker")
)
.subcommand(
SubCommand::with_name("legacy").about("Use the legacy staking solution")
.arg(
Expand All @@ -463,6 +451,15 @@ fn get_config() -> BoxResult<(Config, RpcClient, Box<dyn GenericStakePool>)> {
.validator(is_pubkey_or_keypair)
.help("The source stake account for splitting individual validator stake accounts from")
)
.arg(
Arg::with_name("authorized_staker")
.index(2)
.value_name("KEYPAIR")
.validator(is_keypair)
.required(true)
.takes_value(true)
.help("Keypair of the authorized staker")
)
.arg(
Arg::with_name("baseline_stake_amount")
.long("baseline-stake-amount")
Expand Down Expand Up @@ -499,6 +496,15 @@ fn get_config() -> BoxResult<(Config, RpcClient, Box<dyn GenericStakePool>)> {
.validator(is_pubkey_or_keypair)
.help("The reserve stake account used to fund the stake pool")
)
.arg(
Arg::with_name("authorized_staker")
.index(2)
.value_name("KEYPAIR")
.validator(is_keypair)
.required(true)
.takes_value(true)
.help("Keypair of the authorized staker")
)
.arg(
Arg::with_name("min_reserve_stake_balance")
.long("min-reserve-stake-balance")
Expand Down Expand Up @@ -536,6 +542,15 @@ fn get_config() -> BoxResult<(Config, RpcClient, Box<dyn GenericStakePool>)> {
.validator(is_pubkey_or_keypair)
.help("The stake pool address")
)
.arg(
Arg::with_name("authorized_staker")
.index(2)
.value_name("KEYPAIR")
.validator(is_keypair)
.required(true)
.takes_value(true)
.help("Keypair of the authorized staker")
)
.arg(
Arg::with_name("baseline_stake_amount")
.long("baseline-stake-amount")
Expand Down Expand Up @@ -593,12 +608,9 @@ fn get_config() -> BoxResult<(Config, RpcClient, Box<dyn GenericStakePool>)> {
)
.unwrap();

let authorized_staker = keypair_of(&matches, "authorized_staker").unwrap();

let config = Config {
json_rpc_url,
cluster,
authorized_staker,
dry_run,
quality_block_producer_percentage,
max_commission,
Expand All @@ -623,6 +635,7 @@ fn get_config() -> BoxResult<(Config, RpcClient, Box<dyn GenericStakePool>)> {

let stake_pool: Box<dyn GenericStakePool> = match matches.subcommand() {
("legacy", Some(matches)) => {
let authorized_staker = keypair_of(&matches, "authorized_staker").unwrap();
let source_stake_address = pubkey_of(&matches, "source_stake_address").unwrap();
let baseline_stake_amount =
sol_to_lamports(value_t_or_exit!(matches, "baseline_stake_amount", f64));
Expand All @@ -632,13 +645,15 @@ fn get_config() -> BoxResult<(Config, RpcClient, Box<dyn GenericStakePool>)> {

Box::new(legacy_stake_pool::new(
&rpc_client,
authorized_staker,
baseline_stake_amount,
bonus_stake_amount,
source_stake_address,
validator_list,
)?)
}
("stake-pool-v0", Some(matches)) => {
let authorized_staker = keypair_of(&matches, "authorized_staker").unwrap();
let reserve_stake_address = pubkey_of(&matches, "reserve_stake_address").unwrap();
let min_reserve_stake_balance =
sol_to_lamports(value_t_or_exit!(matches, "min_reserve_stake_balance", f64));
Expand All @@ -647,18 +662,21 @@ fn get_config() -> BoxResult<(Config, RpcClient, Box<dyn GenericStakePool>)> {
let validator_list = validator_list_of(matches, config.cluster.as_str());
Box::new(stake_pool_v0::new(
&rpc_client,
authorized_staker,
baseline_stake_amount,
reserve_stake_address,
min_reserve_stake_balance,
validator_list,
)?)
}
("stake-pool", Some(matches)) => {
let authorized_staker = keypair_of(&matches, "authorized_staker").unwrap();
let pool_address = pubkey_of(&matches, "pool_address").unwrap();
let baseline_stake_amount =
sol_to_lamports(value_t_or_exit!(matches, "baseline_stake_amount", f64));
Box::new(stake_pool::new(
&rpc_client,
authorized_staker,
pool_address,
baseline_stake_amount,
)?)
Expand Down Expand Up @@ -1117,7 +1135,6 @@ fn main() -> BoxResult<()> {
notifications.extend(stake_pool.apply(
&rpc_client,
config.dry_run,
&config.authorized_staker,
&desired_validator_stake,
)?);
notifications.push(format!("{} validators processed", validators_processed));
Expand Down
6 changes: 4 additions & 2 deletions src/stake_pool.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#![allow(dead_code)]
use {
crate::generic_stake_pool::*,
log::*,
Expand All @@ -13,19 +14,21 @@ struct ValidatorInfo {
baseline_stake_activation_state: StakeActivationState,
}

#[derive(Debug)]
pub struct SplStakePool {
authorized_staker: Keypair,
baseline_stake_amount: u64,
pool_address: Pubkey,
validator_info: HashMap<Pubkey, ValidatorInfo>,
}

pub fn new(
_rpc_client: &RpcClient,
authorized_staker: Keypair,
pool_address: Pubkey,
baseline_stake_amount: u64,
) -> Result<SplStakePool, Box<dyn error::Error>> {
Ok(SplStakePool {
authorized_staker,
baseline_stake_amount,
pool_address,
validator_info: HashMap::new(),
Expand All @@ -41,7 +44,6 @@ impl GenericStakePool for SplStakePool {
&mut self,
_rpc_client: &RpcClient,
_dry_run: bool,
_authorized_staker: &Keypair,
_desired_validator_stake: &[ValidatorStake],
) -> Result<Vec<String>, Box<dyn error::Error>> {
todo!();
Expand Down
Loading

0 comments on commit 8c80315

Please sign in to comment.