Skip to content

Commit

Permalink
stake-pool: Remove copied stake program code (mostly) (solana-labs#2526)
Browse files Browse the repository at this point in the history
* stake-pool: Remove (mostly) the copied stake program

* Remove references to stake_program in CLI
  • Loading branch information
joncinque authored Oct 19, 2021
1 parent d6d0b92 commit 1a48523
Show file tree
Hide file tree
Showing 17 changed files with 227 additions and 879 deletions.
9 changes: 3 additions & 6 deletions stake-pool/cli/src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,8 @@ use {
rpc_config::{RpcAccountInfoConfig, RpcProgramAccountsConfig},
rpc_filter::{Memcmp, MemcmpEncodedBytes, RpcFilterType},
},
solana_program::{borsh::try_from_slice_unchecked, program_pack::Pack, pubkey::Pubkey},
spl_stake_pool::{
stake_program,
state::{StakePool, ValidatorList},
},
solana_program::{borsh::try_from_slice_unchecked, program_pack::Pack, pubkey::Pubkey, stake},
spl_stake_pool::state::{StakePool, ValidatorList},
};

type Error = Box<dyn std::error::Error>;
Expand Down Expand Up @@ -70,7 +67,7 @@ pub fn get_token_mint(
pub(crate) fn get_stake_state(
rpc_client: &RpcClient,
stake_address: &Pubkey,
) -> Result<stake_program::StakeState, Error> {
) -> Result<stake::state::StakeState, Error> {
let account_data = rpc_client.get_account_data(stake_address)?;
let stake_state = deserialize(account_data.as_slice())
.map_err(|err| format!("Invalid stake account {}: {}", stake_address, err))?;
Expand Down
14 changes: 7 additions & 7 deletions stake-pool/cli/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ use {
instruction::Instruction,
program_pack::Pack,
pubkey::Pubkey,
stake,
},
solana_remote_wallet::remote_wallet::RemoteWalletManager,
solana_sdk::{
Expand All @@ -36,7 +37,6 @@ use {
self, find_stake_program_address, find_transient_stake_program_address,
find_withdraw_authority_program_address,
instruction::{FundingType, PreferredValidatorType},
stake_program::{self, StakeState},
state::{Fee, FeeType, StakePool, ValidatorList},
MINIMUM_ACTIVE_STAKE,
},
Expand Down Expand Up @@ -168,7 +168,7 @@ fn new_stake_account(
&stake_receiver_pubkey,
lamports,
STAKE_STATE_LEN as u64,
&stake_program::id(),
&stake::program::id(),
),
);

Expand Down Expand Up @@ -241,15 +241,15 @@ fn command_create_pool(
&reserve_keypair.pubkey(),
reserve_stake_balance,
STAKE_STATE_LEN as u64,
&stake_program::id(),
&stake::program::id(),
),
stake_program::initialize(
stake::instruction::initialize(
&reserve_keypair.pubkey(),
&stake_program::Authorized {
&stake::state::Authorized {
staker: withdraw_authority,
withdrawer: withdraw_authority,
},
&stake_program::Lockup::default(),
&stake::state::Lockup::default(),
),
// Account for the stake pool mint
system_instruction::create_account(
Expand Down Expand Up @@ -610,7 +610,7 @@ fn command_deposit_stake(
println!("Depositing stake account {:?}", stake_state);
}
let vote_account = match stake_state {
StakeState::Stake(_, stake) => Ok(stake.delegation.voter_pubkey),
stake::state::StakeState::Stake(_, stake) => Ok(stake.delegation.voter_pubkey),
_ => Err("Wrong stake account state, must be delegated to validator"),
}?;

Expand Down
47 changes: 25 additions & 22 deletions stake-pool/program/src/instruction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,14 @@ use {
crate::{
find_deposit_authority_program_address, find_stake_program_address,
find_transient_stake_program_address, find_withdraw_authority_program_address,
stake_program,
state::{Fee, FeeType, StakePool, ValidatorList},
MAX_VALIDATORS_TO_UPDATE,
},
borsh::{BorshDeserialize, BorshSchema, BorshSerialize},
solana_program::{
instruction::{AccountMeta, Instruction},
pubkey::Pubkey,
system_program, sysvar,
stake, system_program, sysvar,
},
};

Expand Down Expand Up @@ -443,9 +442,9 @@ pub fn add_validator_to_pool(
AccountMeta::new_readonly(sysvar::rent::id(), false),
AccountMeta::new_readonly(sysvar::clock::id(), false),
AccountMeta::new_readonly(sysvar::stake_history::id(), false),
AccountMeta::new_readonly(stake_program::config_id(), false),
AccountMeta::new_readonly(stake::config::id(), false),
AccountMeta::new_readonly(system_program::id(), false),
AccountMeta::new_readonly(stake_program::id(), false),
AccountMeta::new_readonly(stake::program::id(), false),
];
Instruction {
program_id: *program_id,
Expand Down Expand Up @@ -478,7 +477,7 @@ pub fn remove_validator_from_pool(
AccountMeta::new_readonly(*transient_stake_account, false),
AccountMeta::new(*destination_stake_account, false),
AccountMeta::new_readonly(sysvar::clock::id(), false),
AccountMeta::new_readonly(stake_program::id(), false),
AccountMeta::new_readonly(stake::program::id(), false),
];
Instruction {
program_id: *program_id,
Expand Down Expand Up @@ -512,7 +511,7 @@ pub fn decrease_validator_stake(
AccountMeta::new_readonly(sysvar::clock::id(), false),
AccountMeta::new_readonly(sysvar::rent::id(), false),
AccountMeta::new_readonly(system_program::id(), false),
AccountMeta::new_readonly(stake_program::id(), false),
AccountMeta::new_readonly(stake::program::id(), false),
];
Instruction {
program_id: *program_id,
Expand Down Expand Up @@ -551,9 +550,9 @@ pub fn increase_validator_stake(
AccountMeta::new_readonly(sysvar::clock::id(), false),
AccountMeta::new_readonly(sysvar::rent::id(), false),
AccountMeta::new_readonly(sysvar::stake_history::id(), false),
AccountMeta::new_readonly(stake_program::config_id(), false),
AccountMeta::new_readonly(stake::config::id(), false),
AccountMeta::new_readonly(system_program::id(), false),
AccountMeta::new_readonly(stake_program::id(), false),
AccountMeta::new_readonly(stake::program::id(), false),
];
Instruction {
program_id: *program_id,
Expand Down Expand Up @@ -736,7 +735,7 @@ pub fn update_validator_list_balance(
AccountMeta::new(*reserve_stake, false),
AccountMeta::new_readonly(sysvar::clock::id(), false),
AccountMeta::new_readonly(sysvar::stake_history::id(), false),
AccountMeta::new_readonly(stake_program::id(), false),
AccountMeta::new_readonly(stake::program::id(), false),
];
accounts.append(
&mut validator_vote_accounts
Expand Down Expand Up @@ -911,20 +910,22 @@ pub fn deposit_stake(
AccountMeta::new_readonly(sysvar::clock::id(), false),
AccountMeta::new_readonly(sysvar::stake_history::id(), false),
AccountMeta::new_readonly(*token_program_id, false),
AccountMeta::new_readonly(stake_program::id(), false),
AccountMeta::new_readonly(stake::program::id(), false),
];
vec![
stake_program::authorize(
stake::instruction::authorize(
deposit_stake_address,
deposit_stake_withdraw_authority,
&stake_pool_deposit_authority,
stake_program::StakeAuthorize::Staker,
stake::state::StakeAuthorize::Staker,
None,
),
stake_program::authorize(
stake::instruction::authorize(
deposit_stake_address,
deposit_stake_withdraw_authority,
&stake_pool_deposit_authority,
stake_program::StakeAuthorize::Withdrawer,
stake::state::StakeAuthorize::Withdrawer,
None,
),
Instruction {
program_id: *program_id,
Expand Down Expand Up @@ -968,20 +969,22 @@ pub fn deposit_stake_with_authority(
AccountMeta::new_readonly(sysvar::clock::id(), false),
AccountMeta::new_readonly(sysvar::stake_history::id(), false),
AccountMeta::new_readonly(*token_program_id, false),
AccountMeta::new_readonly(stake_program::id(), false),
AccountMeta::new_readonly(stake::program::id(), false),
];
vec![
stake_program::authorize(
stake::instruction::authorize(
deposit_stake_address,
deposit_stake_withdraw_authority,
stake_pool_deposit_authority,
stake_program::StakeAuthorize::Staker,
stake::state::StakeAuthorize::Staker,
None,
),
stake_program::authorize(
stake::instruction::authorize(
deposit_stake_address,
deposit_stake_withdraw_authority,
stake_pool_deposit_authority,
stake_program::StakeAuthorize::Withdrawer,
stake::state::StakeAuthorize::Withdrawer,
None,
),
Instruction {
program_id: *program_id,
Expand Down Expand Up @@ -1094,7 +1097,7 @@ pub fn withdraw_stake(
AccountMeta::new(*pool_mint, false),
AccountMeta::new_readonly(sysvar::clock::id(), false),
AccountMeta::new_readonly(*token_program_id, false),
AccountMeta::new_readonly(stake_program::id(), false),
AccountMeta::new_readonly(stake::program::id(), false),
];
Instruction {
program_id: *program_id,
Expand Down Expand Up @@ -1130,7 +1133,7 @@ pub fn withdraw_sol(
AccountMeta::new(*pool_mint, false),
AccountMeta::new_readonly(sysvar::clock::id(), false),
AccountMeta::new_readonly(sysvar::stake_history::id(), false),
AccountMeta::new_readonly(stake_program::id(), false),
AccountMeta::new_readonly(stake::program::id(), false),
AccountMeta::new_readonly(*token_program_id, false),
];
Instruction {
Expand Down Expand Up @@ -1170,7 +1173,7 @@ pub fn withdraw_sol_with_authority(
AccountMeta::new(*pool_mint, false),
AccountMeta::new_readonly(sysvar::clock::id(), false),
AccountMeta::new_readonly(sysvar::stake_history::id(), false),
AccountMeta::new_readonly(stake_program::id(), false),
AccountMeta::new_readonly(stake::program::id(), false),
AccountMeta::new_readonly(*token_program_id, false),
AccountMeta::new_readonly(*sol_withdraw_authority, true),
];
Expand Down
4 changes: 2 additions & 2 deletions stake-pool/program/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ pub mod entrypoint;
// Export current sdk types for downstream users building with a different sdk version
pub use solana_program;
use {
crate::{stake_program::Meta, state::Fee},
solana_program::{native_token::LAMPORTS_PER_SOL, pubkey::Pubkey},
crate::state::Fee,
solana_program::{native_token::LAMPORTS_PER_SOL, pubkey::Pubkey, stake::state::Meta},
};

/// Seed for deposit authority seed
Expand Down
Loading

0 comments on commit 1a48523

Please sign in to comment.