Added missing accounts to the interface to call stake account program (#763)
* Interface accounts added as read-only, fixed mint authority on deposit, fixed stake pool stake deserializing * Unit test refactoring, added success tests for deposit, updated stake account program id * Warnings fixed * Removed random key generation, used Pubkey::new_unique instead * Imports optimization * Unit test architecture updated to remove separate invoke_signed declarations * Added missing accounts (sysvar clock and stake account program id) to calls to stake account program * Fixed formatting * Fixed stake pool deposit unit test * Temporarily removed stake-pool cli from main workspace * Fixed warning in token program * Fixed warning in token program v3 * Fixed warnings in token swap program * Fixed warning in token cli * Sysvar and program id params reordered
This commit is contained in:
parent
7aa82424ba
commit
480f6604b7
|
@ -18,6 +18,7 @@ solana-client = "1.4.4"
|
|||
solana-logger = "1.4.4"
|
||||
solana-sdk = "1.4.4"
|
||||
spl-stake-pool = { version = "0.1.0", path="../program", features = [ "exclude_entrypoint" ] }
|
||||
spl-token = { path="../../token/program" }
|
||||
|
||||
[[bin]]
|
||||
name = "spl-stake-pool"
|
||||
|
|
|
@ -6,6 +6,7 @@ use solana_program::instruction::AccountMeta;
|
|||
use solana_program::instruction::Instruction;
|
||||
use solana_program::program_error::ProgramError;
|
||||
use solana_program::pubkey::Pubkey;
|
||||
use solana_program::sysvar;
|
||||
use std::mem::size_of;
|
||||
|
||||
/// Fee rate as a ratio
|
||||
|
@ -50,7 +51,9 @@ pub enum StakePoolInstruction {
|
|||
/// 4. `[w]` User account to receive pool tokens
|
||||
/// 5. `[w]` Account to receive pool fee tokens
|
||||
/// 6. `[w]` Pool token mint account
|
||||
/// 7. `[]` Pool token program id
|
||||
/// 7. '[]' Sysvar clock account (reserved for future use)
|
||||
/// 8. `[]` Pool token program id,
|
||||
/// 9. `[]` Stake program id,
|
||||
Deposit,
|
||||
|
||||
/// Withdraw the token from the pool at the current ratio.
|
||||
|
@ -63,7 +66,9 @@ pub enum StakePoolInstruction {
|
|||
/// 4. `[]` User account to set as a new withdraw authority
|
||||
/// 5. `[w]` User account with pool tokens to burn from
|
||||
/// 6. `[w]` Pool token mint account
|
||||
/// 7. `[]` Pool token program id
|
||||
/// 7. '[]' Sysvar clock account (reserved for future use)
|
||||
/// 8. `[]` Pool token program id
|
||||
/// 9. `[]` Stake program id,
|
||||
/// userdata: amount to withdraw
|
||||
Withdraw(u64),
|
||||
|
||||
|
@ -76,7 +81,9 @@ pub enum StakePoolInstruction {
|
|||
/// 3. `[]` User account to set as a new withdraw authority
|
||||
/// 4. `[w]` User account with pool tokens to burn from
|
||||
/// 5. `[w]` Pool token mint account
|
||||
/// 6. `[]` Pool token program id
|
||||
/// 6. '[]' Sysvar clock account (reserved for future use)
|
||||
/// 7. `[]` Pool token program id
|
||||
/// 8. `[]` Stake program id,
|
||||
Claim,
|
||||
|
||||
/// Update the staking pubkey for a stake
|
||||
|
@ -86,6 +93,8 @@ pub enum StakePoolInstruction {
|
|||
/// 2. `[]` withdraw authority
|
||||
/// 3. `[w]` Stake to update the staking pubkey
|
||||
/// 4. '[]` Staking pubkey.
|
||||
/// 5. '[]' Sysvar clock account (reserved for future use)
|
||||
/// 6. `[]` Stake program id,
|
||||
SetStakingAuthority,
|
||||
|
||||
/// Update owner
|
||||
|
@ -202,6 +211,7 @@ pub fn deposit(
|
|||
pool_fee_to: &Pubkey,
|
||||
pool_mint: &Pubkey,
|
||||
token_program_id: &Pubkey,
|
||||
stake_program_id: &Pubkey,
|
||||
) -> Result<Instruction, ProgramError> {
|
||||
let args = StakePoolInstruction::Deposit;
|
||||
let data = args.serialize()?;
|
||||
|
@ -213,7 +223,9 @@ pub fn deposit(
|
|||
AccountMeta::new(*pool_tokens_to, false),
|
||||
AccountMeta::new(*pool_fee_to, false),
|
||||
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),
|
||||
];
|
||||
Ok(Instruction {
|
||||
program_id: *program_id,
|
||||
|
@ -233,6 +245,7 @@ pub fn withdraw(
|
|||
burn_from: &Pubkey,
|
||||
pool_mint: &Pubkey,
|
||||
token_program_id: &Pubkey,
|
||||
stake_program_id: &Pubkey,
|
||||
amount: u64,
|
||||
) -> Result<Instruction, ProgramError> {
|
||||
let args = StakePoolInstruction::Withdraw(amount);
|
||||
|
@ -245,7 +258,9 @@ pub fn withdraw(
|
|||
AccountMeta::new_readonly(*user_withdrawer, false),
|
||||
AccountMeta::new(*burn_from, true),
|
||||
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),
|
||||
];
|
||||
Ok(Instruction {
|
||||
program_id: *program_id,
|
||||
|
@ -264,6 +279,7 @@ pub fn claim(
|
|||
burn_from: &Pubkey,
|
||||
pool_mint: &Pubkey,
|
||||
token_program_id: &Pubkey,
|
||||
stake_program_id: &Pubkey,
|
||||
amount: u64,
|
||||
) -> Result<Instruction, ProgramError> {
|
||||
let args = StakePoolInstruction::Withdraw(amount);
|
||||
|
@ -275,7 +291,9 @@ pub fn claim(
|
|||
AccountMeta::new_readonly(*user_withdrawer, false),
|
||||
AccountMeta::new(*burn_from, true),
|
||||
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),
|
||||
];
|
||||
Ok(Instruction {
|
||||
program_id: *program_id,
|
||||
|
@ -292,6 +310,7 @@ pub fn set_staking_authority(
|
|||
stake_pool_withdraw: &Pubkey,
|
||||
stake_account_to_update: &Pubkey,
|
||||
stake_account_new_authority: &Pubkey,
|
||||
stake_program_id: &Pubkey,
|
||||
) -> Result<Instruction, ProgramError> {
|
||||
let args = StakePoolInstruction::SetStakingAuthority;
|
||||
let data = args.serialize()?;
|
||||
|
@ -301,6 +320,8 @@ pub fn set_staking_authority(
|
|||
AccountMeta::new_readonly(*stake_pool_withdraw, false),
|
||||
AccountMeta::new(*stake_account_to_update, false),
|
||||
AccountMeta::new_readonly(*stake_account_new_authority, false),
|
||||
AccountMeta::new_readonly(sysvar::clock::id(), false),
|
||||
AccountMeta::new_readonly(*stake_program_id, false),
|
||||
];
|
||||
Ok(Instruction {
|
||||
program_id: *program_id,
|
||||
|
|
|
@ -46,6 +46,7 @@ impl Processor {
|
|||
}
|
||||
|
||||
/// Issue a stake_split instruction.
|
||||
#[allow(clippy::too_many_arguments)]
|
||||
pub fn stake_split<'a>(
|
||||
stake_pool: &Pubkey,
|
||||
stake_account: AccountInfo<'a>,
|
||||
|
@ -54,6 +55,8 @@ impl Processor {
|
|||
bump_seed: u8,
|
||||
amount: u64,
|
||||
split_stake: AccountInfo<'a>,
|
||||
reserved: AccountInfo<'a>,
|
||||
stake_program_info: AccountInfo<'a>,
|
||||
) -> Result<(), ProgramError> {
|
||||
let me_bytes = stake_pool.to_bytes();
|
||||
let authority_signature_seeds = [&me_bytes[..32], authority_type, &[bump_seed]];
|
||||
|
@ -61,10 +64,21 @@ impl Processor {
|
|||
|
||||
let ix = stake::split_only(stake_account.key, authority.key, amount, split_stake.key);
|
||||
|
||||
invoke_signed(&ix, &[stake_account, authority, split_stake], signers)
|
||||
invoke_signed(
|
||||
&ix,
|
||||
&[
|
||||
stake_account,
|
||||
reserved,
|
||||
authority,
|
||||
split_stake,
|
||||
stake_program_info,
|
||||
],
|
||||
signers,
|
||||
)
|
||||
}
|
||||
|
||||
/// Issue a stake_set_owner instruction.
|
||||
#[allow(clippy::too_many_arguments)]
|
||||
pub fn stake_authorize<'a>(
|
||||
stake_pool: &Pubkey,
|
||||
stake_account: AccountInfo<'a>,
|
||||
|
@ -73,6 +87,8 @@ impl Processor {
|
|||
bump_seed: u8,
|
||||
new_staker: &Pubkey,
|
||||
staker_auth: stake::StakeAuthorize,
|
||||
reserved: AccountInfo<'a>,
|
||||
stake_program_info: AccountInfo<'a>,
|
||||
) -> Result<(), ProgramError> {
|
||||
let me_bytes = stake_pool.to_bytes();
|
||||
let authority_signature_seeds = [&me_bytes[..32], authority_type, &[bump_seed]];
|
||||
|
@ -80,7 +96,11 @@ impl Processor {
|
|||
|
||||
let ix = stake::authorize(stake_account.key, authority.key, new_staker, staker_auth);
|
||||
|
||||
invoke_signed(&ix, &[stake_account, authority], signers)
|
||||
invoke_signed(
|
||||
&ix,
|
||||
&[stake_account, reserved, authority, stake_program_info],
|
||||
signers,
|
||||
)
|
||||
}
|
||||
|
||||
/// Issue a spl_token `Burn` instruction.
|
||||
|
@ -205,8 +225,12 @@ impl Processor {
|
|||
let owner_fee_info = next_account_info(account_info_iter)?;
|
||||
// Pool token mint account
|
||||
let pool_mint_info = next_account_info(account_info_iter)?;
|
||||
// (Reserved)
|
||||
let reserved = next_account_info(account_info_iter)?;
|
||||
// Pool token program id
|
||||
let token_program_info = next_account_info(account_info_iter)?;
|
||||
// Stake program id
|
||||
let stake_program_info = next_account_info(account_info_iter)?;
|
||||
|
||||
let mut stake_pool = State::deserialize(&stake_pool_info.data.borrow())?.stake_pool()?;
|
||||
|
||||
|
@ -260,6 +284,8 @@ impl Processor {
|
|||
stake_pool.deposit_bump_seed,
|
||||
withdraw_info.key,
|
||||
stake::StakeAuthorize::Withdrawer,
|
||||
reserved.clone(),
|
||||
stake_program_info.clone(),
|
||||
)?;
|
||||
|
||||
let user_amount = <u64>::try_from(user_amount).or(Err(Error::CalculationFailure))?;
|
||||
|
@ -313,8 +339,12 @@ impl Processor {
|
|||
let burn_from_info = next_account_info(account_info_iter)?;
|
||||
// Pool token mint account
|
||||
let pool_mint_info = next_account_info(account_info_iter)?;
|
||||
// (Reserved)
|
||||
let reserved = next_account_info(account_info_iter)?;
|
||||
// Pool token program id
|
||||
let token_program_info = next_account_info(account_info_iter)?;
|
||||
// Stake program id
|
||||
let stake_program_info = next_account_info(account_info_iter)?;
|
||||
|
||||
let mut stake_pool = State::deserialize(&stake_pool_info.data.borrow())?.stake_pool()?;
|
||||
|
||||
|
@ -345,6 +375,8 @@ impl Processor {
|
|||
stake_pool.withdraw_bump_seed,
|
||||
stake_amount,
|
||||
stake_split_to.clone(),
|
||||
reserved.clone(),
|
||||
stake_program_info.clone(),
|
||||
)?;
|
||||
|
||||
Self::stake_authorize(
|
||||
|
@ -355,6 +387,8 @@ impl Processor {
|
|||
stake_pool.withdraw_bump_seed,
|
||||
user_stake_authority.key,
|
||||
stake::StakeAuthorize::Withdrawer,
|
||||
reserved.clone(),
|
||||
stake_program_info.clone(),
|
||||
)?;
|
||||
|
||||
Self::token_burn(
|
||||
|
@ -388,8 +422,12 @@ impl Processor {
|
|||
let burn_from_info = next_account_info(account_info_iter)?;
|
||||
// Pool token account
|
||||
let pool_mint_info = next_account_info(account_info_iter)?;
|
||||
// (Reserved)
|
||||
let reserved = next_account_info(account_info_iter)?;
|
||||
// Pool token program id
|
||||
let token_program_info = next_account_info(account_info_iter)?;
|
||||
// Stake program id
|
||||
let stake_program_info = next_account_info(account_info_iter)?;
|
||||
|
||||
let mut stake_pool = State::deserialize(&stake_pool_info.data.borrow())?.stake_pool()?;
|
||||
|
||||
|
@ -421,6 +459,8 @@ impl Processor {
|
|||
stake_pool.withdraw_bump_seed,
|
||||
user_stake_authority.key,
|
||||
stake::StakeAuthorize::Withdrawer,
|
||||
reserved.clone(),
|
||||
stake_program_info.clone(),
|
||||
)?;
|
||||
|
||||
Self::token_burn(
|
||||
|
@ -450,6 +490,10 @@ impl Processor {
|
|||
let withdraw_info = next_account_info(account_info_iter)?;
|
||||
let stake_info = next_account_info(account_info_iter)?;
|
||||
let staker_info = next_account_info(account_info_iter)?;
|
||||
// (Reserved)
|
||||
let reserved = next_account_info(account_info_iter)?;
|
||||
// Stake program id
|
||||
let stake_program_info = next_account_info(account_info_iter)?;
|
||||
|
||||
let stake_pool = State::deserialize(&stake_pool_info.data.borrow())?.stake_pool()?;
|
||||
|
||||
|
@ -479,6 +523,8 @@ impl Processor {
|
|||
stake_pool.withdraw_bump_seed,
|
||||
staker_info.key,
|
||||
stake::StakeAuthorize::Staker,
|
||||
reserved.clone(),
|
||||
stake_program_info.clone(),
|
||||
)?;
|
||||
Ok(())
|
||||
}
|
||||
|
@ -918,6 +964,7 @@ mod tests {
|
|||
&pool_info.owner_fee_key,
|
||||
&pool_info.mint_key,
|
||||
&TOKEN_PROGRAM_ID,
|
||||
&stake_program_id(),
|
||||
)
|
||||
.unwrap(),
|
||||
vec![
|
||||
|
@ -929,6 +976,8 @@ mod tests {
|
|||
&mut pool_info.owner_fee_account,
|
||||
&mut pool_info.mint_account,
|
||||
&mut Account::default(),
|
||||
&mut Account::default(),
|
||||
&mut Account::default(),
|
||||
],
|
||||
)
|
||||
.expect("Error on stake pool deposit");
|
||||
|
|
Loading…
Reference in New Issue