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

Commit 1a48523

Browse files
authored
stake-pool: Remove copied stake program code (mostly) (#2526)
* stake-pool: Remove (mostly) the copied stake program * Remove references to stake_program in CLI
1 parent d6d0b92 commit 1a48523

17 files changed

+227
-879
lines changed

stake-pool/cli/src/client.rs

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,8 @@ use {
77
rpc_config::{RpcAccountInfoConfig, RpcProgramAccountsConfig},
88
rpc_filter::{Memcmp, MemcmpEncodedBytes, RpcFilterType},
99
},
10-
solana_program::{borsh::try_from_slice_unchecked, program_pack::Pack, pubkey::Pubkey},
11-
spl_stake_pool::{
12-
stake_program,
13-
state::{StakePool, ValidatorList},
14-
},
10+
solana_program::{borsh::try_from_slice_unchecked, program_pack::Pack, pubkey::Pubkey, stake},
11+
spl_stake_pool::state::{StakePool, ValidatorList},
1512
};
1613

1714
type Error = Box<dyn std::error::Error>;
@@ -70,7 +67,7 @@ pub fn get_token_mint(
7067
pub(crate) fn get_stake_state(
7168
rpc_client: &RpcClient,
7269
stake_address: &Pubkey,
73-
) -> Result<stake_program::StakeState, Error> {
70+
) -> Result<stake::state::StakeState, Error> {
7471
let account_data = rpc_client.get_account_data(stake_address)?;
7572
let stake_state = deserialize(account_data.as_slice())
7673
.map_err(|err| format!("Invalid stake account {}: {}", stake_address, err))?;

stake-pool/cli/src/main.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ use {
2020
instruction::Instruction,
2121
program_pack::Pack,
2222
pubkey::Pubkey,
23+
stake,
2324
},
2425
solana_remote_wallet::remote_wallet::RemoteWalletManager,
2526
solana_sdk::{
@@ -36,7 +37,6 @@ use {
3637
self, find_stake_program_address, find_transient_stake_program_address,
3738
find_withdraw_authority_program_address,
3839
instruction::{FundingType, PreferredValidatorType},
39-
stake_program::{self, StakeState},
4040
state::{Fee, FeeType, StakePool, ValidatorList},
4141
MINIMUM_ACTIVE_STAKE,
4242
},
@@ -168,7 +168,7 @@ fn new_stake_account(
168168
&stake_receiver_pubkey,
169169
lamports,
170170
STAKE_STATE_LEN as u64,
171-
&stake_program::id(),
171+
&stake::program::id(),
172172
),
173173
);
174174

@@ -241,15 +241,15 @@ fn command_create_pool(
241241
&reserve_keypair.pubkey(),
242242
reserve_stake_balance,
243243
STAKE_STATE_LEN as u64,
244-
&stake_program::id(),
244+
&stake::program::id(),
245245
),
246-
stake_program::initialize(
246+
stake::instruction::initialize(
247247
&reserve_keypair.pubkey(),
248-
&stake_program::Authorized {
248+
&stake::state::Authorized {
249249
staker: withdraw_authority,
250250
withdrawer: withdraw_authority,
251251
},
252-
&stake_program::Lockup::default(),
252+
&stake::state::Lockup::default(),
253253
),
254254
// Account for the stake pool mint
255255
system_instruction::create_account(
@@ -610,7 +610,7 @@ fn command_deposit_stake(
610610
println!("Depositing stake account {:?}", stake_state);
611611
}
612612
let vote_account = match stake_state {
613-
StakeState::Stake(_, stake) => Ok(stake.delegation.voter_pubkey),
613+
stake::state::StakeState::Stake(_, stake) => Ok(stake.delegation.voter_pubkey),
614614
_ => Err("Wrong stake account state, must be delegated to validator"),
615615
}?;
616616

stake-pool/program/src/instruction.rs

Lines changed: 25 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,14 @@ use {
55
crate::{
66
find_deposit_authority_program_address, find_stake_program_address,
77
find_transient_stake_program_address, find_withdraw_authority_program_address,
8-
stake_program,
98
state::{Fee, FeeType, StakePool, ValidatorList},
109
MAX_VALIDATORS_TO_UPDATE,
1110
},
1211
borsh::{BorshDeserialize, BorshSchema, BorshSerialize},
1312
solana_program::{
1413
instruction::{AccountMeta, Instruction},
1514
pubkey::Pubkey,
16-
system_program, sysvar,
15+
stake, system_program, sysvar,
1716
},
1817
};
1918

@@ -443,9 +442,9 @@ pub fn add_validator_to_pool(
443442
AccountMeta::new_readonly(sysvar::rent::id(), false),
444443
AccountMeta::new_readonly(sysvar::clock::id(), false),
445444
AccountMeta::new_readonly(sysvar::stake_history::id(), false),
446-
AccountMeta::new_readonly(stake_program::config_id(), false),
445+
AccountMeta::new_readonly(stake::config::id(), false),
447446
AccountMeta::new_readonly(system_program::id(), false),
448-
AccountMeta::new_readonly(stake_program::id(), false),
447+
AccountMeta::new_readonly(stake::program::id(), false),
449448
];
450449
Instruction {
451450
program_id: *program_id,
@@ -478,7 +477,7 @@ pub fn remove_validator_from_pool(
478477
AccountMeta::new_readonly(*transient_stake_account, false),
479478
AccountMeta::new(*destination_stake_account, false),
480479
AccountMeta::new_readonly(sysvar::clock::id(), false),
481-
AccountMeta::new_readonly(stake_program::id(), false),
480+
AccountMeta::new_readonly(stake::program::id(), false),
482481
];
483482
Instruction {
484483
program_id: *program_id,
@@ -512,7 +511,7 @@ pub fn decrease_validator_stake(
512511
AccountMeta::new_readonly(sysvar::clock::id(), false),
513512
AccountMeta::new_readonly(sysvar::rent::id(), false),
514513
AccountMeta::new_readonly(system_program::id(), false),
515-
AccountMeta::new_readonly(stake_program::id(), false),
514+
AccountMeta::new_readonly(stake::program::id(), false),
516515
];
517516
Instruction {
518517
program_id: *program_id,
@@ -551,9 +550,9 @@ pub fn increase_validator_stake(
551550
AccountMeta::new_readonly(sysvar::clock::id(), false),
552551
AccountMeta::new_readonly(sysvar::rent::id(), false),
553552
AccountMeta::new_readonly(sysvar::stake_history::id(), false),
554-
AccountMeta::new_readonly(stake_program::config_id(), false),
553+
AccountMeta::new_readonly(stake::config::id(), false),
555554
AccountMeta::new_readonly(system_program::id(), false),
556-
AccountMeta::new_readonly(stake_program::id(), false),
555+
AccountMeta::new_readonly(stake::program::id(), false),
557556
];
558557
Instruction {
559558
program_id: *program_id,
@@ -736,7 +735,7 @@ pub fn update_validator_list_balance(
736735
AccountMeta::new(*reserve_stake, false),
737736
AccountMeta::new_readonly(sysvar::clock::id(), false),
738737
AccountMeta::new_readonly(sysvar::stake_history::id(), false),
739-
AccountMeta::new_readonly(stake_program::id(), false),
738+
AccountMeta::new_readonly(stake::program::id(), false),
740739
];
741740
accounts.append(
742741
&mut validator_vote_accounts
@@ -911,20 +910,22 @@ pub fn deposit_stake(
911910
AccountMeta::new_readonly(sysvar::clock::id(), false),
912911
AccountMeta::new_readonly(sysvar::stake_history::id(), false),
913912
AccountMeta::new_readonly(*token_program_id, false),
914-
AccountMeta::new_readonly(stake_program::id(), false),
913+
AccountMeta::new_readonly(stake::program::id(), false),
915914
];
916915
vec![
917-
stake_program::authorize(
916+
stake::instruction::authorize(
918917
deposit_stake_address,
919918
deposit_stake_withdraw_authority,
920919
&stake_pool_deposit_authority,
921-
stake_program::StakeAuthorize::Staker,
920+
stake::state::StakeAuthorize::Staker,
921+
None,
922922
),
923-
stake_program::authorize(
923+
stake::instruction::authorize(
924924
deposit_stake_address,
925925
deposit_stake_withdraw_authority,
926926
&stake_pool_deposit_authority,
927-
stake_program::StakeAuthorize::Withdrawer,
927+
stake::state::StakeAuthorize::Withdrawer,
928+
None,
928929
),
929930
Instruction {
930931
program_id: *program_id,
@@ -968,20 +969,22 @@ pub fn deposit_stake_with_authority(
968969
AccountMeta::new_readonly(sysvar::clock::id(), false),
969970
AccountMeta::new_readonly(sysvar::stake_history::id(), false),
970971
AccountMeta::new_readonly(*token_program_id, false),
971-
AccountMeta::new_readonly(stake_program::id(), false),
972+
AccountMeta::new_readonly(stake::program::id(), false),
972973
];
973974
vec![
974-
stake_program::authorize(
975+
stake::instruction::authorize(
975976
deposit_stake_address,
976977
deposit_stake_withdraw_authority,
977978
stake_pool_deposit_authority,
978-
stake_program::StakeAuthorize::Staker,
979+
stake::state::StakeAuthorize::Staker,
980+
None,
979981
),
980-
stake_program::authorize(
982+
stake::instruction::authorize(
981983
deposit_stake_address,
982984
deposit_stake_withdraw_authority,
983985
stake_pool_deposit_authority,
984-
stake_program::StakeAuthorize::Withdrawer,
986+
stake::state::StakeAuthorize::Withdrawer,
987+
None,
985988
),
986989
Instruction {
987990
program_id: *program_id,
@@ -1094,7 +1097,7 @@ pub fn withdraw_stake(
10941097
AccountMeta::new(*pool_mint, false),
10951098
AccountMeta::new_readonly(sysvar::clock::id(), false),
10961099
AccountMeta::new_readonly(*token_program_id, false),
1097-
AccountMeta::new_readonly(stake_program::id(), false),
1100+
AccountMeta::new_readonly(stake::program::id(), false),
10981101
];
10991102
Instruction {
11001103
program_id: *program_id,
@@ -1130,7 +1133,7 @@ pub fn withdraw_sol(
11301133
AccountMeta::new(*pool_mint, false),
11311134
AccountMeta::new_readonly(sysvar::clock::id(), false),
11321135
AccountMeta::new_readonly(sysvar::stake_history::id(), false),
1133-
AccountMeta::new_readonly(stake_program::id(), false),
1136+
AccountMeta::new_readonly(stake::program::id(), false),
11341137
AccountMeta::new_readonly(*token_program_id, false),
11351138
];
11361139
Instruction {
@@ -1170,7 +1173,7 @@ pub fn withdraw_sol_with_authority(
11701173
AccountMeta::new(*pool_mint, false),
11711174
AccountMeta::new_readonly(sysvar::clock::id(), false),
11721175
AccountMeta::new_readonly(sysvar::stake_history::id(), false),
1173-
AccountMeta::new_readonly(stake_program::id(), false),
1176+
AccountMeta::new_readonly(stake::program::id(), false),
11741177
AccountMeta::new_readonly(*token_program_id, false),
11751178
AccountMeta::new_readonly(*sol_withdraw_authority, true),
11761179
];

stake-pool/program/src/lib.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@ pub mod entrypoint;
1515
// Export current sdk types for downstream users building with a different sdk version
1616
pub use solana_program;
1717
use {
18-
crate::{stake_program::Meta, state::Fee},
19-
solana_program::{native_token::LAMPORTS_PER_SOL, pubkey::Pubkey},
18+
crate::state::Fee,
19+
solana_program::{native_token::LAMPORTS_PER_SOL, pubkey::Pubkey, stake::state::Meta},
2020
};
2121

2222
/// Seed for deposit authority seed

0 commit comments

Comments
 (0)