Code cleanup v0

This commit is contained in:
Michael Vines 2021-03-31 10:04:41 -07:00
parent 7d4873c617
commit eb1bf2eb44
13 changed files with 267 additions and 260 deletions

View File

@ -15,6 +15,7 @@ use {
keypair::signer_from_path,
},
solana_client::{
client_error::ClientError,
rpc_client::RpcClient,
rpc_config::{RpcAccountInfoConfig, RpcProgramAccountsConfig},
rpc_filter::{Memcmp, MemcmpEncodedBytes, RpcFilterType},
@ -24,7 +25,6 @@ use {
borsh::get_packed_len, instruction::Instruction, program_pack::Pack, pubkey::Pubkey,
},
solana_sdk::{
account::Account,
commitment_config::CommitmentConfig,
native_token::{self, Sol},
signature::{Keypair, Signer},
@ -33,18 +33,15 @@ use {
},
spl_stake_pool::{
borsh::{get_instance_packed_len, try_from_slice_unchecked},
create_pool_authority_address, find_authority_bump_seed, find_stake_address_for_validator,
instruction::{
add_validator_to_pool, create_validator_stake_account, deposit,
initialize as initialize_pool, remove_validator_from_pool, set_owner,
update_stake_pool_balance, update_validator_list_balance, withdraw, Fee as PoolFee,
},
processor::Processor as PoolProcessor,
stake::authorize as authorize_stake,
stake::id as stake_program_id,
stake::StakeAuthorize,
stake::StakeState,
state::StakePool,
state::ValidatorList,
stake_program::{self, StakeAuthorize, StakeState},
state::{StakePool, ValidatorList},
AUTHORITY_DEPOSIT, AUTHORITY_WITHDRAW,
},
spl_token::{
self, instruction::approve as approve_token, instruction::initialize_account,
@ -94,16 +91,17 @@ fn check_fee_payer_balance(config: &Config, required_balance: u64) -> Result<(),
}
}
fn get_authority_accounts(rpc_client: &RpcClient, authority: &Pubkey) -> Vec<(Pubkey, Account)> {
fn get_stake_accounts_by_withdrawer(
rpc_client: &RpcClient,
withdrawer: &Pubkey,
) -> Result<Vec<(Pubkey, u64, StakeState)>, ClientError> {
rpc_client
.get_program_accounts_with_config(
&stake_program_id(),
&stake_program::id(),
RpcProgramAccountsConfig {
filters: Some(vec![RpcFilterType::Memcmp(Memcmp {
offset: 44, // 44 is Withdrawer authority offset in stake account stake
bytes: MemcmpEncodedBytes::Binary(
bs58::encode(authority.to_bytes()).into_string(),
),
bytes: MemcmpEncodedBytes::Binary(format!("{}", withdrawer)),
encoding: None,
})]),
account_config: RpcAccountInfoConfig {
@ -112,7 +110,20 @@ fn get_authority_accounts(rpc_client: &RpcClient, authority: &Pubkey) -> Vec<(Pu
},
},
)
.unwrap()
.map(|accounts| {
accounts
.into_iter()
.filter_map(
|(address, account)| match deserialize(account.data.as_slice()) {
Ok(stake_state) => Some((address, account.lamports, stake_state)),
Err(err) => {
eprintln!("Invalid stake account data for {}: {}", address, err);
None
}
},
)
.collect()
})
}
fn send_transaction(
@ -168,10 +179,10 @@ fn command_create_pool(config: &Config, fee: PoolFee, max_validators: u32) -> Co
let default_decimals = native_mint::DECIMALS;
// Calculate withdraw authority used for minting pool tokens
let (withdraw_authority, _) = PoolProcessor::find_authority_bump_seed(
let (withdraw_authority, _) = find_authority_bump_seed(
&spl_stake_pool::id(),
&pool_account.pubkey(),
PoolProcessor::AUTHORITY_WITHDRAW,
AUTHORITY_WITHDRAW,
);
if config.verbose {
@ -263,11 +274,8 @@ fn command_create_pool(config: &Config, fee: PoolFee, max_validators: u32) -> Co
}
fn command_vsa_create(config: &Config, pool: &Pubkey, vote_account: &Pubkey) -> CommandResult {
let (stake_account, _) = PoolProcessor::find_stake_address_for_validator(
&spl_stake_pool::id(),
&vote_account,
&pool,
);
let (stake_account, _) =
find_stake_address_for_validator(&spl_stake_pool::id(), &vote_account, &pool);
println!("Creating stake account {}", stake_account);
@ -335,31 +343,31 @@ fn command_vsa_add(
)?;
// Calculate Deposit and Withdraw stake pool authorities
let pool_deposit_authority: Pubkey = PoolProcessor::authority_id(
let pool_deposit_authority: Pubkey = create_pool_authority_address(
&spl_stake_pool::id(),
pool,
PoolProcessor::AUTHORITY_DEPOSIT,
AUTHORITY_DEPOSIT,
pool_data.deposit_bump_seed,
)
.unwrap();
let pool_withdraw_authority: Pubkey = PoolProcessor::authority_id(
let pool_withdraw_authority: Pubkey = create_pool_authority_address(
&spl_stake_pool::id(),
pool,
PoolProcessor::AUTHORITY_WITHDRAW,
AUTHORITY_WITHDRAW,
pool_data.withdraw_bump_seed,
)
.unwrap();
instructions.extend(vec![
// Set Withdrawer on stake account to Deposit authority of the stake pool
authorize_stake(
stake_program::authorize(
&stake,
&config.owner.pubkey(),
&pool_deposit_authority,
StakeAuthorize::Withdrawer,
),
// Set Staker on stake account to Deposit authority of the stake pool
authorize_stake(
stake_program::authorize(
&stake,
&config.owner.pubkey(),
&pool_deposit_authority,
@ -409,10 +417,10 @@ fn command_vsa_remove(
let pool_data = config.rpc_client.get_account_data(&pool)?;
let pool_data: StakePool = StakePool::try_from_slice(pool_data.as_slice()).unwrap();
let pool_withdraw_authority: Pubkey = PoolProcessor::authority_id(
let pool_withdraw_authority: Pubkey = create_pool_authority_address(
&spl_stake_pool::id(),
pool,
PoolProcessor::AUTHORITY_WITHDRAW,
AUTHORITY_WITHDRAW,
pool_data.withdraw_bump_seed,
)
.unwrap();
@ -567,7 +575,7 @@ fn command_deposit(
// Calculate validator stake account address linked to the pool
let (validator_stake_account, _) =
PoolProcessor::find_stake_address_for_validator(&spl_stake_pool::id(), &vote_account, pool);
find_stake_address_for_validator(&spl_stake_pool::id(), &vote_account, pool);
let validator_stake_data = config
.rpc_client
.get_account_data(&validator_stake_account)?;
@ -600,31 +608,31 @@ fn command_deposit(
)?;
// Calculate Deposit and Withdraw stake pool authorities
let pool_deposit_authority: Pubkey = PoolProcessor::authority_id(
let pool_deposit_authority: Pubkey = create_pool_authority_address(
&spl_stake_pool::id(),
pool,
PoolProcessor::AUTHORITY_DEPOSIT,
AUTHORITY_DEPOSIT,
pool_data.deposit_bump_seed,
)
.unwrap();
let pool_withdraw_authority: Pubkey = PoolProcessor::authority_id(
let pool_withdraw_authority: Pubkey = create_pool_authority_address(
&spl_stake_pool::id(),
pool,
PoolProcessor::AUTHORITY_WITHDRAW,
AUTHORITY_WITHDRAW,
pool_data.withdraw_bump_seed,
)
.unwrap();
instructions.extend(vec![
// Set Withdrawer on stake account to Deposit authority of the stake pool
authorize_stake(
stake_program::authorize(
&stake,
&config.owner.pubkey(),
&pool_deposit_authority,
StakeAuthorize::Withdrawer,
),
// Set Staker on stake account to Deposit authority of the stake pool
authorize_stake(
stake_program::authorize(
&stake,
&config.owner.pubkey(),
&pool_deposit_authority,
@ -663,14 +671,22 @@ fn command_deposit(
fn command_list(config: &Config, pool: &Pubkey) -> CommandResult {
// Get stake pool state
let pool_data = config.rpc_client.get_account_data(&pool)?;
let pool_data = StakePool::try_from_slice(pool_data.as_slice()).unwrap();
let pool_data = StakePool::try_from_slice(pool_data.as_slice())
.map_err(|err| format!("Invalid pool {}: {}", pool, err))?;
if config.verbose {
let validator_list = config
.rpc_client
.get_account_data(&pool_data.validator_list)?;
let validator_list_data =
try_from_slice_unchecked::<ValidatorList>(&validator_list.as_slice())?;
let validator_list_data = try_from_slice_unchecked::<ValidatorList>(
&validator_list.as_slice(),
)
.map_err(|err| {
format!(
"Invalid validator list{}: {}",
pool_data.validator_list, err
)
})?;
println!("Current validator list");
for validator in validator_list_data.validators {
println!(
@ -680,31 +696,27 @@ fn command_list(config: &Config, pool: &Pubkey) -> CommandResult {
}
}
let pool_withdraw_authority: Pubkey = PoolProcessor::authority_id(
let pool_withdraw_authority: Pubkey = create_pool_authority_address(
&spl_stake_pool::id(),
pool,
PoolProcessor::AUTHORITY_WITHDRAW,
AUTHORITY_WITHDRAW,
pool_data.withdraw_bump_seed,
)
.unwrap();
let accounts = get_authority_accounts(&config.rpc_client, &pool_withdraw_authority);
let accounts = get_stake_accounts_by_withdrawer(&config.rpc_client, &pool_withdraw_authority)?;
if accounts.is_empty() {
return Err("No accounts found.".to_string().into());
}
let mut total_balance: u64 = 0;
for (pubkey, account) in accounts {
let stake_data: StakeState =
deserialize(account.data.as_slice()).or(Err("Invalid stake account data"))?;
let balance = account.lamports;
total_balance += balance;
for (pubkey, lamports, stake_state) in accounts {
total_balance += lamports;
println!(
"Stake Account: {}\tVote Account: {}\t{}",
pubkey,
stake_data.delegation().unwrap().voter_pubkey,
Sol(balance)
stake_state.delegation().expect("delegation").voter_pubkey,
Sol(lamports)
);
}
println!("Total: {}", Sol(total_balance));
@ -731,7 +743,7 @@ fn command_update(config: &Config, pool: &Pubkey) -> CommandResult {
if item.last_update_epoch >= epoch_info.epoch {
None
} else {
let (stake_account, _) = PoolProcessor::find_stake_address_for_validator(
let (stake_account, _) = find_stake_address_for_validator(
&spl_stake_pool::id(),
&item.validator_account,
&pool,
@ -775,8 +787,7 @@ fn command_update(config: &Config, pool: &Pubkey) -> CommandResult {
#[derive(PartialEq, Debug)]
struct WithdrawAccount {
pubkey: Pubkey,
account: Account,
address: Pubkey,
pool_amount: u64,
}
@ -786,53 +797,37 @@ fn prepare_withdraw_accounts(
pool_withdraw_authority: &Pubkey,
pool_amount: u64,
) -> Result<Vec<WithdrawAccount>, Error> {
let mut accounts = get_authority_accounts(rpc_client, &pool_withdraw_authority);
let mut accounts = get_stake_accounts_by_withdrawer(rpc_client, &pool_withdraw_authority)?;
if accounts.is_empty() {
return Err("No accounts found.".to_string().into());
}
let min_balance = rpc_client.get_minimum_balance_for_rent_exemption(STAKE_STATE_LEN)? + 1;
let pool_mint_data = rpc_client.get_account_data(&stake_pool.pool_mint)?;
let pool_mint = TokenMint::unpack_from_slice(pool_mint_data.as_slice()).unwrap();
pick_withdraw_accounts(
&mut accounts,
stake_pool,
&pool_mint,
pool_amount,
min_balance,
)
}
fn pick_withdraw_accounts(
accounts: &mut Vec<(Pubkey, Account)>,
stake_pool: &StakePool,
pool_mint: &TokenMint,
pool_amount: u64,
min_balance: u64,
) -> Result<Vec<WithdrawAccount>, Error> {
// Sort from highest to lowest balance
accounts.sort_by(|a, b| b.1.lamports.cmp(&a.1.lamports));
accounts.sort_by(|a, b| b.1.cmp(&a.1));
// Prepare the list of accounts to withdraw from
let mut withdraw_from: Vec<WithdrawAccount> = vec![];
let mut remaining_amount = pool_amount;
// Go through available accounts and withdraw from largest to smallest
for (pubkey, account) in accounts {
if account.lamports <= min_balance {
for (address, lamports, _) in accounts {
if lamports <= min_balance {
continue;
}
let available_for_withdrawal = stake_pool
.calc_lamports_withdraw_amount(account.lamports - *MIN_STAKE_BALANCE)
.calc_lamports_withdraw_amount(lamports - *MIN_STAKE_BALANCE)
.unwrap();
let withdraw_amount = u64::min(available_for_withdrawal, remaining_amount);
let pool_amount = u64::min(available_for_withdrawal, remaining_amount);
// Those accounts will be withdrawn completely with `claim` instruction
withdraw_from.push(WithdrawAccount {
pubkey: *pubkey,
account: account.clone(),
pool_amount: withdraw_amount,
address,
pool_amount,
});
remaining_amount -= withdraw_amount;
remaining_amount -= pool_amount;
if remaining_amount == 0 {
break;
@ -870,10 +865,10 @@ fn command_withdraw(
let pool_mint = TokenMint::unpack_from_slice(pool_mint_data.as_slice()).unwrap();
let pool_amount = spl_token::ui_amount_to_amount(pool_amount, pool_mint.decimals);
let pool_withdraw_authority: Pubkey = PoolProcessor::authority_id(
let pool_withdraw_authority: Pubkey = create_pool_authority_address(
&spl_stake_pool::id(),
pool,
PoolProcessor::AUTHORITY_WITHDRAW,
AUTHORITY_WITHDRAW,
pool_data.withdraw_bump_seed,
)
.unwrap();
@ -898,7 +893,7 @@ fn command_withdraw(
}
// Get the list of accounts to withdraw from
let withdraw_accounts: Vec<WithdrawAccount> = prepare_withdraw_accounts(
let withdraw_accounts = prepare_withdraw_accounts(
&config.rpc_client,
&pool_data,
&pool_withdraw_authority,
@ -928,17 +923,17 @@ fn command_withdraw(
let mut total_rent_free_balances = 0;
// Go through prepared accounts and withdraw/claim them
for withdraw_stake in withdraw_accounts {
for withdraw_account in withdraw_accounts {
// Convert pool tokens amount to lamports
let sol_withdraw_amount = pool_data
.calc_lamports_withdraw_amount(withdraw_stake.pool_amount)
.calc_lamports_withdraw_amount(withdraw_account.pool_amount)
.unwrap();
println!(
"Withdrawing from account {}, amount {}, {} pool tokens",
withdraw_stake.pubkey,
withdraw_account.address,
Sol(sol_withdraw_amount),
spl_token::amount_to_ui_amount(withdraw_stake.pool_amount, pool_mint.decimals),
spl_token::amount_to_ui_amount(withdraw_account.pool_amount, pool_mint.decimals),
);
if stake_receiver.is_none() {
@ -959,7 +954,7 @@ fn command_withdraw(
&stake_receiver_account.pubkey(),
stake_receiver_account_balance,
STAKE_STATE_LEN as u64,
&stake_program_id(),
&stake_program::id(),
),
);
@ -975,13 +970,13 @@ fn command_withdraw(
&pool,
&pool_data.validator_list,
&pool_withdraw_authority,
&withdraw_stake.pubkey,
&withdraw_account.address,
&stake_receiver.unwrap(), // Cannot be none at this point
&config.owner.pubkey(),
&withdraw_from,
&pool_data.pool_mint,
&spl_token::id(),
withdraw_stake.pool_amount,
withdraw_account.pool_amount,
)?);
}

View File

@ -3,7 +3,7 @@
#![allow(clippy::too_many_arguments)]
use {
crate::stake,
crate::stake_program,
borsh::{BorshDeserialize, BorshSchema, BorshSerialize},
solana_program::{
instruction::{AccountMeta, Instruction},
@ -200,9 +200,9 @@ pub fn create_validator_stake_account(
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::config_id(), false),
AccountMeta::new_readonly(stake_program::config_id(), false),
AccountMeta::new_readonly(system_program::id(), false),
AccountMeta::new_readonly(stake::id(), false),
AccountMeta::new_readonly(stake_program::id(), false),
];
Ok(Instruction {
program_id: *program_id,
@ -236,7 +236,7 @@ pub fn add_validator_to_pool(
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::id(), false),
AccountMeta::new_readonly(stake_program::id(), false),
];
Ok(Instruction {
program_id: *program_id,
@ -269,7 +269,7 @@ pub fn remove_validator_from_pool(
AccountMeta::new(*pool_mint, false),
AccountMeta::new_readonly(sysvar::clock::id(), false),
AccountMeta::new_readonly(*token_program_id, false),
AccountMeta::new_readonly(stake::id(), false),
AccountMeta::new_readonly(stake_program::id(), false),
];
Ok(Instruction {
program_id: *program_id,
@ -342,7 +342,7 @@ pub fn deposit(
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::id(), false),
AccountMeta::new_readonly(stake_program::id(), false),
];
Ok(Instruction {
program_id: *program_id,
@ -376,7 +376,7 @@ pub fn withdraw(
AccountMeta::new(*pool_mint, false),
AccountMeta::new_readonly(sysvar::clock::id(), false),
AccountMeta::new_readonly(*token_program_id, false),
AccountMeta::new_readonly(stake::id(), false),
AccountMeta::new_readonly(stake_program::id(), false),
];
Ok(Instruction {
program_id: *program_id,

View File

@ -6,7 +6,7 @@ pub mod borsh;
pub mod error;
pub mod instruction;
pub mod processor;
pub mod stake;
pub mod stake_program;
pub mod state;
#[cfg(not(feature = "no-entrypoint"))]
@ -14,5 +14,46 @@ pub mod entrypoint;
// Export current sdk types for downstream users building with a different sdk version
pub use solana_program;
use solana_program::{program_error::ProgramError, pubkey::Pubkey};
/// Seed for deposit authority seed
pub const AUTHORITY_DEPOSIT: &[u8] = b"deposit";
/// Seed for withdraw authority seed
pub const AUTHORITY_WITHDRAW: &[u8] = b"withdraw";
/// Calculates the authority address
pub fn create_pool_authority_address(
program_id: &Pubkey,
stake_pool: &Pubkey,
authority: &[u8],
bump_seed: u8,
) -> Result<Pubkey, ProgramError> {
Pubkey::create_program_address(
&[&stake_pool.to_bytes()[..32], authority, &[bump_seed]],
program_id,
)
.map_err(|_| crate::error::StakePoolError::InvalidProgramAddress.into())
}
/// Generates seed bump for stake pool authorities
pub fn find_authority_bump_seed(
program_id: &Pubkey,
stake_pool: &Pubkey,
authority: &[u8],
) -> (Pubkey, u8) {
Pubkey::find_program_address(&[&stake_pool.to_bytes()[..32], authority], program_id)
}
/// Generates stake account address for the validator
pub fn find_stake_address_for_validator(
program_id: &Pubkey,
validator: &Pubkey,
stake_pool: &Pubkey,
) -> (Pubkey, u8) {
Pubkey::find_program_address(
&[&validator.to_bytes()[..32], &stake_pool.to_bytes()[..32]],
program_id,
)
}
solana_program::declare_id!("poo1B9L9nR3CrcaziKVYVpRX6A9Y1LAXYasjjfCbApj");

View File

@ -3,10 +3,13 @@
use {
crate::{
borsh::try_from_slice_unchecked,
create_pool_authority_address,
error::StakePoolError,
find_authority_bump_seed, find_stake_address_for_validator,
instruction::{Fee, StakePoolInstruction},
stake,
stake_program,
state::{AccountType, StakePool, ValidatorList, ValidatorStakeInfo},
AUTHORITY_DEPOSIT, AUTHORITY_WITHDRAW,
},
bincode::deserialize,
borsh::{BorshDeserialize, BorshSerialize},
@ -35,53 +38,16 @@ use {
/// Program state handler.
pub struct Processor {}
impl Processor {
/// Suffix for deposit authority seed
pub const AUTHORITY_DEPOSIT: &'static [u8] = b"deposit";
/// Suffix for withdraw authority seed
pub const AUTHORITY_WITHDRAW: &'static [u8] = b"withdraw";
/// Calculates the authority id by generating a program address.
pub fn authority_id(
program_id: &Pubkey,
stake_pool: &Pubkey,
authority_type: &[u8],
bump_seed: u8,
) -> Result<Pubkey, ProgramError> {
Pubkey::create_program_address(
&[&stake_pool.to_bytes()[..32], authority_type, &[bump_seed]],
program_id,
)
.map_err(|_| StakePoolError::InvalidProgramAddress.into())
}
/// Generates seed bump for stake pool authorities
pub fn find_authority_bump_seed(
program_id: &Pubkey,
stake_pool: &Pubkey,
authority_type: &[u8],
) -> (Pubkey, u8) {
Pubkey::find_program_address(&[&stake_pool.to_bytes()[..32], authority_type], program_id)
}
/// Generates stake account address for the validator
pub fn find_stake_address_for_validator(
program_id: &Pubkey,
validator: &Pubkey,
stake_pool: &Pubkey,
) -> (Pubkey, u8) {
Pubkey::find_program_address(
&[&validator.to_bytes()[..32], &stake_pool.to_bytes()[..32]],
program_id,
)
}
/// Checks withdraw or deposit authority
pub fn check_authority(
authority_to_check: &Pubkey,
program_id: &Pubkey,
stake_pool_key: &Pubkey,
authority_type: &[u8],
authority: &[u8],
bump_seed: u8,
) -> Result<(), ProgramError> {
if *authority_to_check
!= Self::authority_id(program_id, stake_pool_key, authority_type, bump_seed)?
!= create_pool_authority_address(program_id, stake_pool_key, authority, bump_seed)?
{
return Err(StakePoolError::InvalidProgramAddress.into());
}
@ -90,10 +56,10 @@ impl Processor {
/// Returns validator address for a particular stake account
pub fn get_validator(stake_account_info: &AccountInfo) -> Result<Pubkey, ProgramError> {
let stake_state: stake::StakeState = deserialize(&stake_account_info.data.borrow())
let stake_state: stake_program::StakeState = deserialize(&stake_account_info.data.borrow())
.or(Err(ProgramError::InvalidAccountData))?;
match stake_state {
stake::StakeState::Stake(_, stake) => Ok(stake.delegation.voter_pubkey),
stake_program::StakeState::Stake(_, stake) => Ok(stake.delegation.voter_pubkey),
_ => Err(StakePoolError::WrongStakeState.into()),
}
}
@ -106,11 +72,8 @@ impl Processor {
stake_account_info: &AccountInfo,
) -> bool {
// Check stake account address validity
let (stake_address, _) = Self::find_stake_address_for_validator(
&program_id,
&validator_account,
&stake_pool_info.key,
);
let (stake_address, _) =
find_stake_address_for_validator(&program_id, &validator_account, &stake_pool_info.key);
stake_address == *stake_account_info.key
}
@ -147,7 +110,8 @@ impl Processor {
let authority_signature_seeds = [&me_bytes[..32], authority_type, &[bump_seed]];
let signers = &[&authority_signature_seeds[..]];
let ix = stake::split_only(stake_account.key, authority.key, amount, split_stake.key);
let ix =
stake_program::split_only(stake_account.key, authority.key, amount, split_stake.key);
invoke_signed(&ix, &[stake_account, split_stake, authority], signers)
}
@ -169,7 +133,7 @@ impl Processor {
let authority_signature_seeds = [&me_bytes[..32], authority_type, &[bump_seed]];
let signers = &[&authority_signature_seeds[..]];
let ix = stake::merge(merge_with.key, stake_account.key, authority.key);
let ix = stake_program::merge(merge_with.key, stake_account.key, authority.key);
invoke_signed(
&ix,
@ -194,7 +158,7 @@ impl Processor {
authority_type: &[u8],
bump_seed: u8,
new_staker: &Pubkey,
staker_auth: stake::StakeAuthorize,
staker_auth: stake_program::StakeAuthorize,
reserved: AccountInfo<'a>,
stake_program_info: AccountInfo<'a>,
) -> Result<(), ProgramError> {
@ -202,7 +166,8 @@ impl Processor {
let authority_signature_seeds = [&me_bytes[..32], authority_type, &[bump_seed]];
let signers = &[&authority_signature_seeds[..]];
let ix = stake::authorize(stake_account.key, authority.key, new_staker, staker_auth);
let ix =
stake_program::authorize(stake_account.key, authority.key, new_staker, staker_auth);
invoke_signed(
&ix,
@ -357,16 +322,10 @@ impl Processor {
return Err(StakePoolError::WrongAccountMint.into());
}
let (_, deposit_bump_seed) = Self::find_authority_bump_seed(
program_id,
stake_pool_info.key,
Self::AUTHORITY_DEPOSIT,
);
let (withdraw_authority_key, withdraw_bump_seed) = Self::find_authority_bump_seed(
program_id,
stake_pool_info.key,
Self::AUTHORITY_WITHDRAW,
);
let (_, deposit_bump_seed) =
find_authority_bump_seed(program_id, stake_pool_info.key, AUTHORITY_DEPOSIT);
let (withdraw_authority_key, withdraw_bump_seed) =
find_authority_bump_seed(program_id, stake_pool_info.key, AUTHORITY_WITHDRAW);
let pool_mint = Mint::unpack_from_slice(&pool_mint_info.data.borrow())?;
@ -439,12 +398,12 @@ impl Processor {
if *system_program_info.key != solana_program::system_program::id() {
return Err(ProgramError::IncorrectProgramId);
}
if *stake_program_info.key != stake::id() {
if *stake_program_info.key != stake_program::id() {
return Err(ProgramError::IncorrectProgramId);
}
// Check stake account address validity
let (stake_address, bump_seed) = Self::find_stake_address_for_validator(
let (stake_address, bump_seed) = find_stake_address_for_validator(
&program_id,
&validator_info.key,
&stake_pool_info.key,
@ -460,8 +419,8 @@ impl Processor {
];
// Fund the stake account with 1 SOL + rent-exempt balance
let required_lamports =
sol_to_lamports(1.0) + rent.minimum_balance(std::mem::size_of::<stake::StakeState>());
let required_lamports = sol_to_lamports(1.0)
+ rent.minimum_balance(std::mem::size_of::<stake_program::StakeState>());
// Create new stake account
invoke_signed(
@ -469,21 +428,21 @@ impl Processor {
&funder_info.key,
&stake_account_info.key,
required_lamports,
std::mem::size_of::<stake::StakeState>() as u64,
&stake::id(),
std::mem::size_of::<stake_program::StakeState>() as u64,
&stake_program::id(),
),
&[funder_info.clone(), stake_account_info.clone()],
&[&stake_account_signer_seeds],
)?;
invoke(
&stake::initialize(
&stake_program::initialize(
&stake_account_info.key,
&stake::Authorized {
&stake_program::Authorized {
staker: *owner_info.key,
withdrawer: *owner_info.key,
},
&stake::Lockup::default(),
&stake_program::Lockup::default(),
),
&[
stake_account_info.clone(),
@ -493,7 +452,7 @@ impl Processor {
)?;
invoke(
&stake::delegate_stake(
&stake_program::delegate_stake(
&stake_account_info.key,
&owner_info.key,
&validator_info.key,
@ -543,7 +502,7 @@ impl Processor {
let stake_program_info = next_account_info(account_info_iter)?;
// Check program ids
if *stake_program_info.key != stake::id() {
if *stake_program_info.key != stake_program::id() {
return Err(ProgramError::IncorrectProgramId);
}
@ -596,14 +555,14 @@ impl Processor {
// Update Withdrawer and Staker authority to the program withdraw authority
for authority in &[
stake::StakeAuthorize::Withdrawer,
stake::StakeAuthorize::Staker,
stake_program::StakeAuthorize::Withdrawer,
stake_program::StakeAuthorize::Staker,
] {
Self::stake_authorize(
stake_pool_info.key,
stake_account_info.clone(),
deposit_info.clone(),
Self::AUTHORITY_DEPOSIT,
AUTHORITY_DEPOSIT,
stake_pool.deposit_bump_seed,
withdraw_info.key,
*authority,
@ -623,7 +582,7 @@ impl Processor {
pool_mint_info.clone(),
dest_user_info.clone(),
withdraw_info.clone(),
Self::AUTHORITY_WITHDRAW,
AUTHORITY_WITHDRAW,
stake_pool.withdraw_bump_seed,
token_amount,
)?;
@ -679,7 +638,7 @@ impl Processor {
let stake_program_info = next_account_info(account_info_iter)?;
// Check program ids
if *stake_program_info.key != stake::id() {
if *stake_program_info.key != stake_program::id() {
return Err(ProgramError::IncorrectProgramId);
}
@ -728,14 +687,14 @@ impl Processor {
// Update Withdrawer and Staker authority to the provided authority
for authority in &[
stake::StakeAuthorize::Withdrawer,
stake::StakeAuthorize::Staker,
stake_program::StakeAuthorize::Withdrawer,
stake_program::StakeAuthorize::Staker,
] {
Self::stake_authorize(
stake_pool_info.key,
stake_account_info.clone(),
withdraw_info.clone(),
Self::AUTHORITY_WITHDRAW,
AUTHORITY_WITHDRAW,
stake_pool.withdraw_bump_seed,
new_stake_authority_info.key,
*authority,
@ -755,7 +714,7 @@ impl Processor {
burn_from_info.clone(),
pool_mint_info.clone(),
withdraw_info.clone(),
Self::AUTHORITY_WITHDRAW,
AUTHORITY_WITHDRAW,
stake_pool.withdraw_bump_seed,
token_amount,
)?;
@ -886,7 +845,7 @@ impl Processor {
//#[cfg(not(feature = "test-bpf"))]
// This check is commented to make tests run without special command line arguments
/*{
let stake_acc_state: stake::StakeState =
let stake_acc_state: stake_program::StakeState =
deserialize(&stake_info.data.borrow()).unwrap();
let delegation = stake_acc_state.delegation();
if let Some(delegation) = delegation {
@ -938,7 +897,7 @@ impl Processor {
let stake_program_info = next_account_info(account_info_iter)?;
// Check program ids
if *stake_program_info.key != stake::id() {
if *stake_program_info.key != stake_program::id() {
return Err(ProgramError::IncorrectProgramId);
}
@ -1002,10 +961,10 @@ impl Processor {
stake_pool_info.key,
stake_info.clone(),
deposit_info.clone(),
Self::AUTHORITY_DEPOSIT,
AUTHORITY_DEPOSIT,
stake_pool.deposit_bump_seed,
withdraw_info.key,
stake::StakeAuthorize::Withdrawer,
stake_program::StakeAuthorize::Withdrawer,
clock_info.clone(),
stake_program_info.clone(),
)?;
@ -1014,10 +973,10 @@ impl Processor {
stake_pool_info.key,
stake_info.clone(),
deposit_info.clone(),
Self::AUTHORITY_DEPOSIT,
AUTHORITY_DEPOSIT,
stake_pool.deposit_bump_seed,
withdraw_info.key,
stake::StakeAuthorize::Staker,
stake_program::StakeAuthorize::Staker,
clock_info.clone(),
stake_program_info.clone(),
)?;
@ -1026,7 +985,7 @@ impl Processor {
stake_pool_info.key,
stake_info.clone(),
withdraw_info.clone(),
Self::AUTHORITY_WITHDRAW,
AUTHORITY_WITHDRAW,
stake_pool.withdraw_bump_seed,
validator_stake_account_info.clone(),
clock_info.clone(),
@ -1040,7 +999,7 @@ impl Processor {
pool_mint_info.clone(),
dest_user_info.clone(),
withdraw_info.clone(),
Self::AUTHORITY_WITHDRAW,
AUTHORITY_WITHDRAW,
stake_pool.withdraw_bump_seed,
user_amount,
)?;
@ -1051,7 +1010,7 @@ impl Processor {
pool_mint_info.clone(),
owner_fee_info.clone(),
withdraw_info.clone(),
Self::AUTHORITY_WITHDRAW,
AUTHORITY_WITHDRAW,
stake_pool.withdraw_bump_seed,
fee_amount,
)?;
@ -1097,7 +1056,7 @@ impl Processor {
let stake_program_info = next_account_info(account_info_iter)?;
// Check program ids
if *stake_program_info.key != stake::id() {
if *stake_program_info.key != stake_program::id() {
return Err(ProgramError::IncorrectProgramId);
}
@ -1145,7 +1104,7 @@ impl Processor {
stake_pool_info.key,
stake_split_from.clone(),
withdraw_info.clone(),
Self::AUTHORITY_WITHDRAW,
AUTHORITY_WITHDRAW,
stake_pool.withdraw_bump_seed,
stake_amount,
stake_split_to.clone(),
@ -1155,10 +1114,10 @@ impl Processor {
stake_pool_info.key,
stake_split_to.clone(),
withdraw_info.clone(),
Self::AUTHORITY_WITHDRAW,
AUTHORITY_WITHDRAW,
stake_pool.withdraw_bump_seed,
user_stake_authority.key,
stake::StakeAuthorize::Withdrawer,
stake_program::StakeAuthorize::Withdrawer,
clock_info.clone(),
stake_program_info.clone(),
)?;
@ -1167,10 +1126,10 @@ impl Processor {
stake_pool_info.key,
stake_split_to.clone(),
withdraw_info.clone(),
Self::AUTHORITY_WITHDRAW,
AUTHORITY_WITHDRAW,
stake_pool.withdraw_bump_seed,
user_stake_authority.key,
stake::StakeAuthorize::Staker,
stake_program::StakeAuthorize::Staker,
clock_info.clone(),
stake_program_info.clone(),
)?;
@ -1181,7 +1140,7 @@ impl Processor {
burn_from_info.clone(),
pool_mint_info.clone(),
withdraw_info.clone(),
Self::AUTHORITY_WITHDRAW,
AUTHORITY_WITHDRAW,
stake_pool.withdraw_bump_seed,
pool_amount,
)?;

View File

@ -110,7 +110,7 @@ impl StakePool {
authority_to_check,
program_id,
stake_pool_key,
Processor::AUTHORITY_WITHDRAW,
crate::AUTHORITY_WITHDRAW,
self.withdraw_bump_seed,
)
}
@ -125,7 +125,7 @@ impl StakePool {
authority_to_check,
program_id,
stake_pool_key,
Processor::AUTHORITY_DEPOSIT,
crate::AUTHORITY_DEPOSIT,
self.deposit_bump_seed,
)
}

View File

@ -18,7 +18,9 @@ use {
transaction::TransactionError,
transport::TransportError,
},
spl_stake_pool::{borsh::try_from_slice_unchecked, error, id, instruction, stake, state},
spl_stake_pool::{
borsh::try_from_slice_unchecked, error, id, instruction, stake_program, state,
},
spl_token::error as token_error,
};
@ -61,10 +63,10 @@ async fn test_stake_pool_deposit() {
let user = Keypair::new();
// make stake account
let user_stake = Keypair::new();
let lockup = stake::Lockup::default();
let lockup = stake_program::Lockup::default();
let stake_authority = Keypair::new();
let authorized = stake::Authorized {
let authorized = stake_program::Authorized {
staker: stake_authority.pubkey(),
withdrawer: stake_authority.pubkey(),
};
@ -104,7 +106,7 @@ async fn test_stake_pool_deposit() {
&user_stake.pubkey(),
&stake_authority,
&stake_pool_accounts.deposit_authority,
stake::StakeAuthorize::Withdrawer,
stake_program::StakeAuthorize::Withdrawer,
)
.await;
authorize_stake_account(
@ -114,7 +116,7 @@ async fn test_stake_pool_deposit() {
&user_stake.pubkey(),
&stake_authority,
&stake_pool_accounts.deposit_authority,
stake::StakeAuthorize::Staker,
stake_program::StakeAuthorize::Staker,
)
.await;
@ -295,8 +297,8 @@ async fn test_stake_pool_deposit_with_wrong_pool_fee_account() {
let user = Keypair::new();
// make stake account
let user_stake = Keypair::new();
let lockup = stake::Lockup::default();
let authorized = stake::Authorized {
let lockup = stake_program::Lockup::default();
let authorized = stake_program::Authorized {
staker: stake_pool_accounts.deposit_authority,
withdrawer: stake_pool_accounts.deposit_authority,
};
@ -359,8 +361,8 @@ async fn test_stake_pool_deposit_with_wrong_token_program_id() {
let user = Keypair::new();
// make stake account
let user_stake = Keypair::new();
let lockup = stake::Lockup::default();
let authorized = stake::Authorized {
let lockup = stake_program::Lockup::default();
let authorized = stake_program::Authorized {
staker: stake_pool_accounts.deposit_authority,
withdrawer: stake_pool_accounts.deposit_authority,
};
@ -434,8 +436,8 @@ async fn test_stake_pool_deposit_with_wrong_validator_list_account() {
let user = Keypair::new();
// make stake account
let user_stake = Keypair::new();
let lockup = stake::Lockup::default();
let authorized = stake::Authorized {
let lockup = stake_program::Lockup::default();
let authorized = stake_program::Authorized {
staker: stake_pool_accounts.deposit_authority,
withdrawer: stake_pool_accounts.deposit_authority,
};
@ -527,8 +529,8 @@ async fn test_stake_pool_deposit_to_unknown_validator() {
// make stake account
let user_stake = Keypair::new();
let lockup = stake::Lockup::default();
let authorized = stake::Authorized {
let lockup = stake_program::Lockup::default();
let authorized = stake_program::Authorized {
staker: stake_pool_accounts.deposit_authority,
withdrawer: stake_pool_accounts.deposit_authority,
};
@ -582,8 +584,8 @@ async fn test_stake_pool_deposit_with_wrong_deposit_authority() {
let user = Keypair::new();
// make stake account
let user_stake = Keypair::new();
let lockup = stake::Lockup::default();
let authorized = stake::Authorized {
let lockup = stake_program::Lockup::default();
let authorized = stake_program::Authorized {
staker: stake_pool_accounts.deposit_authority,
withdrawer: stake_pool_accounts.deposit_authority,
};
@ -650,8 +652,8 @@ async fn test_stake_pool_deposit_with_wrong_withdraw_authority() {
let user = Keypair::new();
// make stake account
let user_stake = Keypair::new();
let lockup = stake::Lockup::default();
let authorized = stake::Authorized {
let lockup = stake_program::Lockup::default();
let authorized = stake_program::Authorized {
staker: stake_pool_accounts.deposit_authority,
withdrawer: stake_pool_accounts.deposit_authority,
};
@ -713,8 +715,8 @@ async fn test_stake_pool_deposit_with_wrong_set_deposit_authority() {
let user = Keypair::new();
// make stake account
let user_stake = Keypair::new();
let lockup = stake::Lockup::default();
let authorized = stake::Authorized {
let lockup = stake_program::Lockup::default();
let authorized = stake_program::Authorized {
staker: Keypair::new().pubkey(),
withdrawer: stake_pool_accounts.deposit_authority,
};
@ -770,8 +772,8 @@ async fn test_stake_pool_deposit_with_wrong_mint_for_receiver_acc() {
// make stake account
let user_stake = Keypair::new();
let lockup = stake::Lockup::default();
let authorized = stake::Authorized {
let lockup = stake_program::Lockup::default();
let authorized = stake_program::Authorized {
staker: stake_pool_accounts.deposit_authority,
withdrawer: stake_pool_accounts.deposit_authority,
};

View File

@ -12,7 +12,10 @@ use {
transport::TransportError,
},
solana_vote_program::{self, vote_state::VoteState},
spl_stake_pool::{borsh::get_instance_packed_len, id, instruction, processor, stake, state},
spl_stake_pool::{
borsh::get_instance_packed_len, find_stake_address_for_validator, id, instruction,
processor, stake_program, state,
},
};
pub const TEST_STAKE_AMOUNT: u64 = 100;
@ -247,15 +250,15 @@ pub async fn create_independent_stake_account(
payer: &Keypair,
recent_blockhash: &Hash,
stake: &Keypair,
authorized: &stake::Authorized,
lockup: &stake::Lockup,
authorized: &stake_program::Authorized,
lockup: &stake_program::Lockup,
) -> u64 {
let rent = banks_client.get_rent().await.unwrap();
let lamports =
rent.minimum_balance(std::mem::size_of::<stake::StakeState>()) + TEST_STAKE_AMOUNT;
rent.minimum_balance(std::mem::size_of::<stake_program::StakeState>()) + TEST_STAKE_AMOUNT;
let mut transaction = Transaction::new_with_payer(
&stake::create_account(
&stake_program::create_account(
&payer.pubkey(),
&stake.pubkey(),
authorized,
@ -277,15 +280,15 @@ pub async fn create_blank_stake_account(
stake: &Keypair,
) -> u64 {
let rent = banks_client.get_rent().await.unwrap();
let lamports = rent.minimum_balance(std::mem::size_of::<stake::StakeState>()) + 1;
let lamports = rent.minimum_balance(std::mem::size_of::<stake_program::StakeState>()) + 1;
let mut transaction = Transaction::new_with_payer(
&[system_instruction::create_account(
&payer.pubkey(),
&stake.pubkey(),
lamports,
std::mem::size_of::<stake::StakeState>() as u64,
&stake::id(),
std::mem::size_of::<stake_program::StakeState>() as u64,
&stake_program::id(),
)],
Some(&payer.pubkey()),
);
@ -332,7 +335,11 @@ pub async fn delegate_stake_account(
vote: &Pubkey,
) {
let mut transaction = Transaction::new_with_payer(
&[stake::delegate_stake(&stake, &authorized.pubkey(), &vote)],
&[stake_program::delegate_stake(
&stake,
&authorized.pubkey(),
&vote,
)],
Some(&payer.pubkey()),
);
transaction.sign(&[payer, authorized], *recent_blockhash);
@ -346,10 +353,10 @@ pub async fn authorize_stake_account(
stake: &Pubkey,
authorized: &Keypair,
new_authorized: &Pubkey,
stake_authorize: stake::StakeAuthorize,
stake_authorize: stake_program::StakeAuthorize,
) {
let mut transaction = Transaction::new_with_payer(
&[stake::authorize(
&[stake_program::authorize(
&stake,
&authorized.pubkey(),
&new_authorized,
@ -371,11 +378,8 @@ pub struct ValidatorStakeAccount {
impl ValidatorStakeAccount {
pub fn new_with_target_authority(authority: &Pubkey, stake_pool: &Pubkey) -> Self {
let validator = Keypair::new();
let (stake_account, _) = processor::Processor::find_stake_address_for_validator(
&id(),
&validator.pubkey(),
stake_pool,
);
let (stake_account, _) =
find_stake_address_for_validator(&id(), &validator.pubkey(), stake_pool);
ValidatorStakeAccount {
stake_account,
target_authority: *authority,
@ -411,7 +415,7 @@ impl ValidatorStakeAccount {
&self.stake_account,
&owner,
&self.target_authority,
stake::StakeAuthorize::Staker,
stake_program::StakeAuthorize::Staker,
)
.await;
@ -422,7 +426,7 @@ impl ValidatorStakeAccount {
&self.stake_account,
&owner,
&self.target_authority,
stake::StakeAuthorize::Withdrawer,
stake_program::StakeAuthorize::Withdrawer,
)
.await;
}
@ -700,8 +704,8 @@ pub async fn simple_deposit(
let user = Keypair::new();
// make stake account
let user_stake = Keypair::new();
let lockup = stake::Lockup::default();
let authorized = stake::Authorized {
let lockup = stake_program::Lockup::default();
let authorized = stake_program::Authorized {
staker: stake_pool_accounts.deposit_authority,
withdrawer: stake_pool_accounts.deposit_authority,
};

View File

@ -8,7 +8,7 @@ use {
solana_program::{native_token, pubkey::Pubkey},
solana_program_test::*,
solana_sdk::signature::Signer,
spl_stake_pool::{borsh::try_from_slice_unchecked, stake, state},
spl_stake_pool::{borsh::try_from_slice_unchecked, stake_program, state},
};
async fn get_list_sum(banks_client: &mut BanksClient, validator_list_key: &Pubkey) -> u64 {
@ -66,7 +66,7 @@ async fn test_update_validator_list_balance() {
}
let rent = banks_client.get_rent().await.unwrap();
let stake_rent = rent.minimum_balance(std::mem::size_of::<stake::StakeState>())
let stake_rent = rent.minimum_balance(std::mem::size_of::<stake_program::StakeState>())
+ native_token::sol_to_lamports(1.0);
// Check current balance in the list

View File

@ -18,7 +18,9 @@ use {
transaction::{Transaction, TransactionError},
transport::TransportError,
},
spl_stake_pool::{borsh::try_from_slice_unchecked, error, id, instruction, stake, state},
spl_stake_pool::{
borsh::try_from_slice_unchecked, error, id, instruction, stake_program, state,
},
};
async fn setup() -> (
@ -136,9 +138,9 @@ async fn test_add_validator_to_pool() {
// Check of stake account authority has changed
let stake = get_account(&mut banks_client, &user_stake.stake_account).await;
let stake_state = deserialize::<stake::StakeState>(&stake.data).unwrap();
let stake_state = deserialize::<stake_program::StakeState>(&stake.data).unwrap();
match stake_state {
stake::StakeState::Stake(meta, _) => {
stake_program::StakeState::Stake(meta, _) => {
assert_eq!(
&meta.authorized.staker,
&stake_pool_accounts.withdraw_authority
@ -174,7 +176,7 @@ async fn test_add_validator_to_pool_with_wrong_token_program_id() {
&user_stake.stake_account,
&user_pool_account.pubkey(),
&stake_pool_accounts.pool_mint.pubkey(),
&stake::id(),
&stake_program::id(),
)
.unwrap()],
Some(&payer.pubkey()),
@ -407,7 +409,7 @@ async fn test_not_owner_try_to_add_validator_to_pool_without_signature() {
AccountMeta::new_readonly(sysvar::clock::id(), false),
AccountMeta::new_readonly(sysvar::stake_history::id(), false),
AccountMeta::new_readonly(spl_token::id(), false),
AccountMeta::new_readonly(stake::id(), false),
AccountMeta::new_readonly(stake_program::id(), false),
];
let instruction = Instruction {
program_id: id(),

View File

@ -18,7 +18,7 @@ use {
transaction::TransactionError,
transport::TransportError,
},
spl_stake_pool::{error, id, instruction, processor, stake},
spl_stake_pool::{error, find_stake_address_for_validator, id, instruction, stake_program},
};
#[tokio::test]
@ -33,7 +33,7 @@ async fn success_create_validator_stake_account() {
let validator = Keypair::new();
create_vote(&mut banks_client, &payer, &recent_blockhash, &validator).await;
let (stake_account, _) = processor::Processor::find_stake_address_for_validator(
let (stake_account, _) = find_stake_address_for_validator(
&id(),
&validator.pubkey(),
&stake_pool_accounts.stake_pool.pubkey(),
@ -56,9 +56,9 @@ async fn success_create_validator_stake_account() {
// Check authorities
let stake = get_account(&mut banks_client, &stake_account).await;
let stake_state = deserialize::<stake::StakeState>(&stake.data).unwrap();
let stake_state = deserialize::<stake_program::StakeState>(&stake.data).unwrap();
match stake_state {
stake::StakeState::Stake(meta, stake) => {
stake_program::StakeState::Stake(meta, stake) => {
assert_eq!(&meta.authorized.staker, &stake_pool_accounts.owner.pubkey());
assert_eq!(
&meta.authorized.withdrawer,
@ -81,7 +81,7 @@ async fn fail_create_validator_stake_account_on_non_vote_account() {
let validator = Pubkey::new_unique();
let (stake_account, _) = processor::Processor::find_stake_address_for_validator(
let (stake_account, _) = find_stake_address_for_validator(
&id(),
&validator,
&stake_pool_accounts.stake_pool.pubkey(),
@ -124,7 +124,7 @@ async fn fail_create_validator_stake_account_with_wrong_system_program() {
let validator = Pubkey::new_unique();
let (stake_account, _) = processor::Processor::find_stake_address_for_validator(
let (stake_account, _) = find_stake_address_for_validator(
&id(),
&validator,
&stake_pool_accounts.stake_pool.pubkey(),
@ -139,9 +139,9 @@ async fn fail_create_validator_stake_account_with_wrong_system_program() {
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::config_id(), false),
AccountMeta::new_readonly(stake_program::config_id(), false),
AccountMeta::new_readonly(wrong_system_program, false),
AccountMeta::new_readonly(stake::id(), false),
AccountMeta::new_readonly(stake_program::id(), false),
];
let instruction = Instruction {
program_id: id(),
@ -177,7 +177,7 @@ async fn fail_create_validator_stake_account_with_wrong_stake_program() {
let validator = Pubkey::new_unique();
let (stake_account, _) = processor::Processor::find_stake_address_for_validator(
let (stake_account, _) = find_stake_address_for_validator(
&id(),
&validator,
&stake_pool_accounts.stake_pool.pubkey(),
@ -192,7 +192,7 @@ async fn fail_create_validator_stake_account_with_wrong_stake_program() {
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::config_id(), false),
AccountMeta::new_readonly(stake_program::config_id(), false),
AccountMeta::new_readonly(system_program::id(), false),
AccountMeta::new_readonly(wrong_stake_program, false),
];

View File

@ -18,7 +18,9 @@ use {
transaction::{Transaction, TransactionError},
transport::TransportError,
},
spl_stake_pool::{borsh::try_from_slice_unchecked, error, id, instruction, stake, state},
spl_stake_pool::{
borsh::try_from_slice_unchecked, error, id, instruction, stake_program, state,
},
};
async fn setup() -> (
@ -147,9 +149,9 @@ async fn test_remove_validator_from_pool() {
// Check of stake account authority has changed
let stake = get_account(&mut banks_client, &user_stake.stake_account).await;
let stake_state = deserialize::<stake::StakeState>(&stake.data).unwrap();
let stake_state = deserialize::<stake_program::StakeState>(&stake.data).unwrap();
match stake_state {
stake::StakeState::Stake(meta, _) => {
stake_program::StakeState::Stake(meta, _) => {
assert_eq!(&meta.authorized.staker, &new_authority);
assert_eq!(&meta.authorized.withdrawer, &new_authority);
}
@ -498,7 +500,7 @@ async fn test_not_owner_try_to_remove_validator_from_pool_without_signature() {
AccountMeta::new(stake_pool_accounts.pool_mint.pubkey(), false),
AccountMeta::new_readonly(sysvar::clock::id(), false),
AccountMeta::new_readonly(spl_token::id(), false),
AccountMeta::new_readonly(stake::id(), false),
AccountMeta::new_readonly(stake_program::id(), false),
];
let instruction = Instruction {
program_id: id(),

View File

@ -17,7 +17,9 @@ use {
transaction::{Transaction, TransactionError},
transport::TransportError,
},
spl_stake_pool::{borsh::try_from_slice_unchecked, error, id, instruction, stake, state},
spl_stake_pool::{
borsh::try_from_slice_unchecked, error, id, instruction, stake_program, state,
},
spl_token::error::TokenError,
};
@ -439,8 +441,8 @@ async fn test_stake_pool_withdraw_from_unknown_validator() {
let user = Keypair::new();
// make stake account
let user_stake = Keypair::new();
let lockup = stake::Lockup::default();
let authorized = stake::Authorized {
let lockup = stake_program::Lockup::default();
let authorized = stake_program::Authorized {
staker: stake_pool_accounts.deposit_authority,
withdrawer: stake_pool_accounts.deposit_authority,
};