Skip to content

Commit

Permalink
Interface accounts added as read-only, fixed mint authority on deposi…
Browse files Browse the repository at this point in the history
…t, fixed stake pool stake deserializing (solana-labs#702)
  • Loading branch information
ysavchenko authored Oct 23, 2020
1 parent 1f0bf3b commit 100e930
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 22 deletions.
38 changes: 19 additions & 19 deletions stake-pool/program/src/instruction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -179,10 +179,10 @@ pub fn initialize(
let data = init_data.serialize()?;
let accounts = vec![
AccountMeta::new(*stake_pool, true),
AccountMeta::new(*owner, false),
AccountMeta::new(*pool_mint, false),
AccountMeta::new(*owner_pool_account, false),
AccountMeta::new(*token_program_id, false),
AccountMeta::new_readonly(*owner, false),
AccountMeta::new_readonly(*pool_mint, false),
AccountMeta::new_readonly(*owner_pool_account, false),
AccountMeta::new_readonly(*token_program_id, false),
];
Ok(Instruction {
program_id: *program_id,
Expand All @@ -207,13 +207,13 @@ pub fn deposit(
let data = args.serialize()?;
let accounts = vec![
AccountMeta::new(*stake_pool, false),
AccountMeta::new(*stake_pool_deposit, false),
AccountMeta::new(*stake_pool_withdraw, false),
AccountMeta::new_readonly(*stake_pool_deposit, false),
AccountMeta::new_readonly(*stake_pool_withdraw, false),
AccountMeta::new(*stake_to_join, false),
AccountMeta::new(*pool_tokens_to, false),
AccountMeta::new(*pool_fee_to, false),
AccountMeta::new(*pool_mint, false),
AccountMeta::new(*token_program_id, false),
AccountMeta::new_readonly(*token_program_id, false),
];
Ok(Instruction {
program_id: *program_id,
Expand All @@ -239,13 +239,13 @@ pub fn withdraw(
let data = args.serialize()?;
let accounts = vec![
AccountMeta::new(*stake_pool, false),
AccountMeta::new(*stake_pool_withdraw, false),
AccountMeta::new_readonly(*stake_pool_withdraw, false),
AccountMeta::new(*stake_to_split, false),
AccountMeta::new(*stake_to_receive, false),
AccountMeta::new(*user_withdrawer, false),
AccountMeta::new_readonly(*user_withdrawer, false),
AccountMeta::new(*burn_from, true),
AccountMeta::new(*pool_mint, false),
AccountMeta::new(*token_program_id, false),
AccountMeta::new_readonly(*token_program_id, false),
];
Ok(Instruction {
program_id: *program_id,
Expand All @@ -270,12 +270,12 @@ pub fn claim(
let data = args.serialize()?;
let accounts = vec![
AccountMeta::new(*stake_pool, false),
AccountMeta::new(*stake_pool_withdraw, false),
AccountMeta::new_readonly(*stake_pool_withdraw, false),
AccountMeta::new(*stake_to_claim, false),
AccountMeta::new(*user_withdrawer, false),
AccountMeta::new_readonly(*user_withdrawer, false),
AccountMeta::new(*burn_from, true),
AccountMeta::new(*pool_mint, false),
AccountMeta::new(*token_program_id, false),
AccountMeta::new_readonly(*token_program_id, false),
];
Ok(Instruction {
program_id: *program_id,
Expand All @@ -297,10 +297,10 @@ pub fn set_staking_authority(
let data = args.serialize()?;
let accounts = vec![
AccountMeta::new(*stake_pool, false),
AccountMeta::new(*stake_pool_owner, true),
AccountMeta::new(*stake_pool_withdraw, false),
AccountMeta::new_readonly(*stake_pool_owner, true),
AccountMeta::new_readonly(*stake_pool_withdraw, false),
AccountMeta::new(*stake_account_to_update, false),
AccountMeta::new(*stake_account_new_authority, false),
AccountMeta::new_readonly(*stake_account_new_authority, false),
];
Ok(Instruction {
program_id: *program_id,
Expand All @@ -321,9 +321,9 @@ pub fn set_owner(
let data = args.serialize()?;
let accounts = vec![
AccountMeta::new(*stake_pool, false),
AccountMeta::new(*stake_pool_owner, true),
AccountMeta::new(*stake_pool_new_owner, false),
AccountMeta::new(*stake_pool_new_fee_receiver, false),
AccountMeta::new_readonly(*stake_pool_owner, true),
AccountMeta::new_readonly(*stake_pool_new_owner, false),
AccountMeta::new_readonly(*stake_pool_new_fee_receiver, false),
];
Ok(Instruction {
program_id: *program_id,
Expand Down
4 changes: 2 additions & 2 deletions stake-pool/program/src/processor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -275,8 +275,8 @@ impl Processor {
pool_mint_info.clone(),
dest_user_info.clone(),
withdraw_info.clone(),
Self::AUTHORITY_DEPOSIT,
stake_pool.deposit_bump_seed,
Self::AUTHORITY_WITHDRAW,
stake_pool.withdraw_bump_seed,
user_amount,
)?;
let fee_amount = <u64>::try_from(fee_amount).or(Err(Error::CalculationFailure))?;
Expand Down
3 changes: 2 additions & 1 deletion stake-pool/program/src/state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,8 @@ impl State {
Ok(match input[0] {
0 => State::Unallocated,
1 => {
let swap: &StakePool = unpack(&input[1..])?;
// We send whole input here, because unpack skips the first byte
let swap: &StakePool = unpack(&input)?;
State::Init(*swap)
}
_ => return Err(ProgramError::InvalidAccountData),
Expand Down

0 comments on commit 100e930

Please sign in to comment.