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

Commit eb1bf2e

Browse files
committed
Code cleanup v0
1 parent 7d4873c commit eb1bf2e

File tree

13 files changed

+267
-260
lines changed

13 files changed

+267
-260
lines changed

stake-pool/cli/src/main.rs

Lines changed: 83 additions & 88 deletions
Large diffs are not rendered by default.

stake-pool/program/src/instruction.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
#![allow(clippy::too_many_arguments)]
44

55
use {
6-
crate::stake,
6+
crate::stake_program,
77
borsh::{BorshDeserialize, BorshSchema, BorshSerialize},
88
solana_program::{
99
instruction::{AccountMeta, Instruction},
@@ -200,9 +200,9 @@ pub fn create_validator_stake_account(
200200
AccountMeta::new_readonly(sysvar::rent::id(), false),
201201
AccountMeta::new_readonly(sysvar::clock::id(), false),
202202
AccountMeta::new_readonly(sysvar::stake_history::id(), false),
203-
AccountMeta::new_readonly(stake::config_id(), false),
203+
AccountMeta::new_readonly(stake_program::config_id(), false),
204204
AccountMeta::new_readonly(system_program::id(), false),
205-
AccountMeta::new_readonly(stake::id(), false),
205+
AccountMeta::new_readonly(stake_program::id(), false),
206206
];
207207
Ok(Instruction {
208208
program_id: *program_id,
@@ -236,7 +236,7 @@ pub fn add_validator_to_pool(
236236
AccountMeta::new_readonly(sysvar::clock::id(), false),
237237
AccountMeta::new_readonly(sysvar::stake_history::id(), false),
238238
AccountMeta::new_readonly(*token_program_id, false),
239-
AccountMeta::new_readonly(stake::id(), false),
239+
AccountMeta::new_readonly(stake_program::id(), false),
240240
];
241241
Ok(Instruction {
242242
program_id: *program_id,
@@ -269,7 +269,7 @@ pub fn remove_validator_from_pool(
269269
AccountMeta::new(*pool_mint, false),
270270
AccountMeta::new_readonly(sysvar::clock::id(), false),
271271
AccountMeta::new_readonly(*token_program_id, false),
272-
AccountMeta::new_readonly(stake::id(), false),
272+
AccountMeta::new_readonly(stake_program::id(), false),
273273
];
274274
Ok(Instruction {
275275
program_id: *program_id,
@@ -342,7 +342,7 @@ pub fn deposit(
342342
AccountMeta::new_readonly(sysvar::clock::id(), false),
343343
AccountMeta::new_readonly(sysvar::stake_history::id(), false),
344344
AccountMeta::new_readonly(*token_program_id, false),
345-
AccountMeta::new_readonly(stake::id(), false),
345+
AccountMeta::new_readonly(stake_program::id(), false),
346346
];
347347
Ok(Instruction {
348348
program_id: *program_id,
@@ -376,7 +376,7 @@ pub fn withdraw(
376376
AccountMeta::new(*pool_mint, false),
377377
AccountMeta::new_readonly(sysvar::clock::id(), false),
378378
AccountMeta::new_readonly(*token_program_id, false),
379-
AccountMeta::new_readonly(stake::id(), false),
379+
AccountMeta::new_readonly(stake_program::id(), false),
380380
];
381381
Ok(Instruction {
382382
program_id: *program_id,

stake-pool/program/src/lib.rs

Lines changed: 42 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,54 @@ pub mod borsh;
66
pub mod error;
77
pub mod instruction;
88
pub mod processor;
9-
pub mod stake;
9+
pub mod stake_program;
1010
pub mod state;
1111

1212
#[cfg(not(feature = "no-entrypoint"))]
1313
pub mod entrypoint;
1414

1515
// Export current sdk types for downstream users building with a different sdk version
1616
pub use solana_program;
17+
use solana_program::{program_error::ProgramError, pubkey::Pubkey};
18+
19+
/// Seed for deposit authority seed
20+
pub const AUTHORITY_DEPOSIT: &[u8] = b"deposit";
21+
22+
/// Seed for withdraw authority seed
23+
pub const AUTHORITY_WITHDRAW: &[u8] = b"withdraw";
24+
25+
/// Calculates the authority address
26+
pub fn create_pool_authority_address(
27+
program_id: &Pubkey,
28+
stake_pool: &Pubkey,
29+
authority: &[u8],
30+
bump_seed: u8,
31+
) -> Result<Pubkey, ProgramError> {
32+
Pubkey::create_program_address(
33+
&[&stake_pool.to_bytes()[..32], authority, &[bump_seed]],
34+
program_id,
35+
)
36+
.map_err(|_| crate::error::StakePoolError::InvalidProgramAddress.into())
37+
}
38+
39+
/// Generates seed bump for stake pool authorities
40+
pub fn find_authority_bump_seed(
41+
program_id: &Pubkey,
42+
stake_pool: &Pubkey,
43+
authority: &[u8],
44+
) -> (Pubkey, u8) {
45+
Pubkey::find_program_address(&[&stake_pool.to_bytes()[..32], authority], program_id)
46+
}
47+
/// Generates stake account address for the validator
48+
pub fn find_stake_address_for_validator(
49+
program_id: &Pubkey,
50+
validator: &Pubkey,
51+
stake_pool: &Pubkey,
52+
) -> (Pubkey, u8) {
53+
Pubkey::find_program_address(
54+
&[&validator.to_bytes()[..32], &stake_pool.to_bytes()[..32]],
55+
program_id,
56+
)
57+
}
1758

1859
solana_program::declare_id!("poo1B9L9nR3CrcaziKVYVpRX6A9Y1LAXYasjjfCbApj");

0 commit comments

Comments
 (0)