Skip to content
This repository was archived by the owner on Mar 11, 2025. It is now read-only.

Commit 480f660

Browse files
authored
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
1 parent 7aa8242 commit 480f660

File tree

3 files changed

+76
-5
lines changed

3 files changed

+76
-5
lines changed

stake-pool/cli/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ solana-client = "1.4.4"
1818
solana-logger = "1.4.4"
1919
solana-sdk = "1.4.4"
2020
spl-stake-pool = { version = "0.1.0", path="../program", features = [ "exclude_entrypoint" ] }
21+
spl-token = { path="../../token/program" }
2122

2223
[[bin]]
2324
name = "spl-stake-pool"

stake-pool/program/src/instruction.rs

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ use solana_program::instruction::AccountMeta;
66
use solana_program::instruction::Instruction;
77
use solana_program::program_error::ProgramError;
88
use solana_program::pubkey::Pubkey;
9+
use solana_program::sysvar;
910
use std::mem::size_of;
1011

1112
/// Fee rate as a ratio
@@ -50,7 +51,9 @@ pub enum StakePoolInstruction {
5051
/// 4. `[w]` User account to receive pool tokens
5152
/// 5. `[w]` Account to receive pool fee tokens
5253
/// 6. `[w]` Pool token mint account
53-
/// 7. `[]` Pool token program id
54+
/// 7. '[]' Sysvar clock account (reserved for future use)
55+
/// 8. `[]` Pool token program id,
56+
/// 9. `[]` Stake program id,
5457
Deposit,
5558

5659
/// Withdraw the token from the pool at the current ratio.
@@ -63,7 +66,9 @@ pub enum StakePoolInstruction {
6366
/// 4. `[]` User account to set as a new withdraw authority
6467
/// 5. `[w]` User account with pool tokens to burn from
6568
/// 6. `[w]` Pool token mint account
66-
/// 7. `[]` Pool token program id
69+
/// 7. '[]' Sysvar clock account (reserved for future use)
70+
/// 8. `[]` Pool token program id
71+
/// 9. `[]` Stake program id,
6772
/// userdata: amount to withdraw
6873
Withdraw(u64),
6974

@@ -76,7 +81,9 @@ pub enum StakePoolInstruction {
7681
/// 3. `[]` User account to set as a new withdraw authority
7782
/// 4. `[w]` User account with pool tokens to burn from
7883
/// 5. `[w]` Pool token mint account
79-
/// 6. `[]` Pool token program id
84+
/// 6. '[]' Sysvar clock account (reserved for future use)
85+
/// 7. `[]` Pool token program id
86+
/// 8. `[]` Stake program id,
8087
Claim,
8188

8289
/// Update the staking pubkey for a stake
@@ -86,6 +93,8 @@ pub enum StakePoolInstruction {
8693
/// 2. `[]` withdraw authority
8794
/// 3. `[w]` Stake to update the staking pubkey
8895
/// 4. '[]` Staking pubkey.
96+
/// 5. '[]' Sysvar clock account (reserved for future use)
97+
/// 6. `[]` Stake program id,
8998
SetStakingAuthority,
9099

91100
/// Update owner
@@ -202,6 +211,7 @@ pub fn deposit(
202211
pool_fee_to: &Pubkey,
203212
pool_mint: &Pubkey,
204213
token_program_id: &Pubkey,
214+
stake_program_id: &Pubkey,
205215
) -> Result<Instruction, ProgramError> {
206216
let args = StakePoolInstruction::Deposit;
207217
let data = args.serialize()?;
@@ -213,7 +223,9 @@ pub fn deposit(
213223
AccountMeta::new(*pool_tokens_to, false),
214224
AccountMeta::new(*pool_fee_to, false),
215225
AccountMeta::new(*pool_mint, false),
226+
AccountMeta::new_readonly(sysvar::clock::id(), false),
216227
AccountMeta::new_readonly(*token_program_id, false),
228+
AccountMeta::new_readonly(*stake_program_id, false),
217229
];
218230
Ok(Instruction {
219231
program_id: *program_id,
@@ -233,6 +245,7 @@ pub fn withdraw(
233245
burn_from: &Pubkey,
234246
pool_mint: &Pubkey,
235247
token_program_id: &Pubkey,
248+
stake_program_id: &Pubkey,
236249
amount: u64,
237250
) -> Result<Instruction, ProgramError> {
238251
let args = StakePoolInstruction::Withdraw(amount);
@@ -245,7 +258,9 @@ pub fn withdraw(
245258
AccountMeta::new_readonly(*user_withdrawer, false),
246259
AccountMeta::new(*burn_from, true),
247260
AccountMeta::new(*pool_mint, false),
261+
AccountMeta::new_readonly(sysvar::clock::id(), false),
248262
AccountMeta::new_readonly(*token_program_id, false),
263+
AccountMeta::new_readonly(*stake_program_id, false),
249264
];
250265
Ok(Instruction {
251266
program_id: *program_id,
@@ -264,6 +279,7 @@ pub fn claim(
264279
burn_from: &Pubkey,
265280
pool_mint: &Pubkey,
266281
token_program_id: &Pubkey,
282+
stake_program_id: &Pubkey,
267283
amount: u64,
268284
) -> Result<Instruction, ProgramError> {
269285
let args = StakePoolInstruction::Withdraw(amount);
@@ -275,7 +291,9 @@ pub fn claim(
275291
AccountMeta::new_readonly(*user_withdrawer, false),
276292
AccountMeta::new(*burn_from, true),
277293
AccountMeta::new(*pool_mint, false),
294+
AccountMeta::new_readonly(sysvar::clock::id(), false),
278295
AccountMeta::new_readonly(*token_program_id, false),
296+
AccountMeta::new_readonly(*stake_program_id, false),
279297
];
280298
Ok(Instruction {
281299
program_id: *program_id,
@@ -292,6 +310,7 @@ pub fn set_staking_authority(
292310
stake_pool_withdraw: &Pubkey,
293311
stake_account_to_update: &Pubkey,
294312
stake_account_new_authority: &Pubkey,
313+
stake_program_id: &Pubkey,
295314
) -> Result<Instruction, ProgramError> {
296315
let args = StakePoolInstruction::SetStakingAuthority;
297316
let data = args.serialize()?;
@@ -301,6 +320,8 @@ pub fn set_staking_authority(
301320
AccountMeta::new_readonly(*stake_pool_withdraw, false),
302321
AccountMeta::new(*stake_account_to_update, false),
303322
AccountMeta::new_readonly(*stake_account_new_authority, false),
323+
AccountMeta::new_readonly(sysvar::clock::id(), false),
324+
AccountMeta::new_readonly(*stake_program_id, false),
304325
];
305326
Ok(Instruction {
306327
program_id: *program_id,

stake-pool/program/src/processor.rs

Lines changed: 51 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ impl Processor {
4646
}
4747

4848
/// Issue a stake_split instruction.
49+
#[allow(clippy::too_many_arguments)]
4950
pub fn stake_split<'a>(
5051
stake_pool: &Pubkey,
5152
stake_account: AccountInfo<'a>,
@@ -54,17 +55,30 @@ impl Processor {
5455
bump_seed: u8,
5556
amount: u64,
5657
split_stake: AccountInfo<'a>,
58+
reserved: AccountInfo<'a>,
59+
stake_program_info: AccountInfo<'a>,
5760
) -> Result<(), ProgramError> {
5861
let me_bytes = stake_pool.to_bytes();
5962
let authority_signature_seeds = [&me_bytes[..32], authority_type, &[bump_seed]];
6063
let signers = &[&authority_signature_seeds[..]];
6164

6265
let ix = stake::split_only(stake_account.key, authority.key, amount, split_stake.key);
6366

64-
invoke_signed(&ix, &[stake_account, authority, split_stake], signers)
67+
invoke_signed(
68+
&ix,
69+
&[
70+
stake_account,
71+
reserved,
72+
authority,
73+
split_stake,
74+
stake_program_info,
75+
],
76+
signers,
77+
)
6578
}
6679

6780
/// Issue a stake_set_owner instruction.
81+
#[allow(clippy::too_many_arguments)]
6882
pub fn stake_authorize<'a>(
6983
stake_pool: &Pubkey,
7084
stake_account: AccountInfo<'a>,
@@ -73,14 +87,20 @@ impl Processor {
7387
bump_seed: u8,
7488
new_staker: &Pubkey,
7589
staker_auth: stake::StakeAuthorize,
90+
reserved: AccountInfo<'a>,
91+
stake_program_info: AccountInfo<'a>,
7692
) -> Result<(), ProgramError> {
7793
let me_bytes = stake_pool.to_bytes();
7894
let authority_signature_seeds = [&me_bytes[..32], authority_type, &[bump_seed]];
7995
let signers = &[&authority_signature_seeds[..]];
8096

8197
let ix = stake::authorize(stake_account.key, authority.key, new_staker, staker_auth);
8298

83-
invoke_signed(&ix, &[stake_account, authority], signers)
99+
invoke_signed(
100+
&ix,
101+
&[stake_account, reserved, authority, stake_program_info],
102+
signers,
103+
)
84104
}
85105

86106
/// Issue a spl_token `Burn` instruction.
@@ -205,8 +225,12 @@ impl Processor {
205225
let owner_fee_info = next_account_info(account_info_iter)?;
206226
// Pool token mint account
207227
let pool_mint_info = next_account_info(account_info_iter)?;
228+
// (Reserved)
229+
let reserved = next_account_info(account_info_iter)?;
208230
// Pool token program id
209231
let token_program_info = next_account_info(account_info_iter)?;
232+
// Stake program id
233+
let stake_program_info = next_account_info(account_info_iter)?;
210234

211235
let mut stake_pool = State::deserialize(&stake_pool_info.data.borrow())?.stake_pool()?;
212236

@@ -260,6 +284,8 @@ impl Processor {
260284
stake_pool.deposit_bump_seed,
261285
withdraw_info.key,
262286
stake::StakeAuthorize::Withdrawer,
287+
reserved.clone(),
288+
stake_program_info.clone(),
263289
)?;
264290

265291
let user_amount = <u64>::try_from(user_amount).or(Err(Error::CalculationFailure))?;
@@ -313,8 +339,12 @@ impl Processor {
313339
let burn_from_info = next_account_info(account_info_iter)?;
314340
// Pool token mint account
315341
let pool_mint_info = next_account_info(account_info_iter)?;
342+
// (Reserved)
343+
let reserved = next_account_info(account_info_iter)?;
316344
// Pool token program id
317345
let token_program_info = next_account_info(account_info_iter)?;
346+
// Stake program id
347+
let stake_program_info = next_account_info(account_info_iter)?;
318348

319349
let mut stake_pool = State::deserialize(&stake_pool_info.data.borrow())?.stake_pool()?;
320350

@@ -345,6 +375,8 @@ impl Processor {
345375
stake_pool.withdraw_bump_seed,
346376
stake_amount,
347377
stake_split_to.clone(),
378+
reserved.clone(),
379+
stake_program_info.clone(),
348380
)?;
349381

350382
Self::stake_authorize(
@@ -355,6 +387,8 @@ impl Processor {
355387
stake_pool.withdraw_bump_seed,
356388
user_stake_authority.key,
357389
stake::StakeAuthorize::Withdrawer,
390+
reserved.clone(),
391+
stake_program_info.clone(),
358392
)?;
359393

360394
Self::token_burn(
@@ -388,8 +422,12 @@ impl Processor {
388422
let burn_from_info = next_account_info(account_info_iter)?;
389423
// Pool token account
390424
let pool_mint_info = next_account_info(account_info_iter)?;
425+
// (Reserved)
426+
let reserved = next_account_info(account_info_iter)?;
391427
// Pool token program id
392428
let token_program_info = next_account_info(account_info_iter)?;
429+
// Stake program id
430+
let stake_program_info = next_account_info(account_info_iter)?;
393431

394432
let mut stake_pool = State::deserialize(&stake_pool_info.data.borrow())?.stake_pool()?;
395433

@@ -421,6 +459,8 @@ impl Processor {
421459
stake_pool.withdraw_bump_seed,
422460
user_stake_authority.key,
423461
stake::StakeAuthorize::Withdrawer,
462+
reserved.clone(),
463+
stake_program_info.clone(),
424464
)?;
425465

426466
Self::token_burn(
@@ -450,6 +490,10 @@ impl Processor {
450490
let withdraw_info = next_account_info(account_info_iter)?;
451491
let stake_info = next_account_info(account_info_iter)?;
452492
let staker_info = next_account_info(account_info_iter)?;
493+
// (Reserved)
494+
let reserved = next_account_info(account_info_iter)?;
495+
// Stake program id
496+
let stake_program_info = next_account_info(account_info_iter)?;
453497

454498
let stake_pool = State::deserialize(&stake_pool_info.data.borrow())?.stake_pool()?;
455499

@@ -479,6 +523,8 @@ impl Processor {
479523
stake_pool.withdraw_bump_seed,
480524
staker_info.key,
481525
stake::StakeAuthorize::Staker,
526+
reserved.clone(),
527+
stake_program_info.clone(),
482528
)?;
483529
Ok(())
484530
}
@@ -918,6 +964,7 @@ mod tests {
918964
&pool_info.owner_fee_key,
919965
&pool_info.mint_key,
920966
&TOKEN_PROGRAM_ID,
967+
&stake_program_id(),
921968
)
922969
.unwrap(),
923970
vec![
@@ -929,6 +976,8 @@ mod tests {
929976
&mut pool_info.owner_fee_account,
930977
&mut pool_info.mint_account,
931978
&mut Account::default(),
979+
&mut Account::default(),
980+
&mut Account::default(),
932981
],
933982
)
934983
.expect("Error on stake pool deposit");

0 commit comments

Comments
 (0)