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

Commit 092432f

Browse files
authored
stake-pool: Separate manager from owner (#1560)
* stake-pool: Separate manager from owner * Add manager pubkey to stake pool * Differentiate manager functions from owner functions * Include a `set_manager` function to be used by the owner * Change the term `owner` to `authority` in the CLI for clarity * Rename manager -> staker and owner -> manager * Split staker, manager, and token owner in CLI * "Do not disturb the boss"
1 parent f309df4 commit 092432f

File tree

14 files changed

+634
-261
lines changed

14 files changed

+634
-261
lines changed

stake-pool/cli/src/main.rs

Lines changed: 154 additions & 51 deletions
Large diffs are not rendered by default.

stake-pool/program/src/error.rs

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,16 +28,16 @@ pub enum StakePoolError {
2828
/// Token account is associated with the wrong mint.
2929
#[error("WrongAccountMint")]
3030
WrongAccountMint,
31-
/// Wrong pool owner account.
32-
#[error("WrongOwner")]
33-
WrongOwner,
31+
/// Wrong pool manager account.
32+
#[error("WrongManager")]
33+
WrongManager,
3434
/// Required signature is missing.
3535
#[error("SignatureMissing")]
3636
SignatureMissing,
3737
/// Invalid validator stake list account.
3838
#[error("InvalidValidatorStakeList")]
3939
InvalidValidatorStakeList,
40-
/// Invalid owner fee account.
40+
/// Invalid manager fee account.
4141
#[error("InvalidFeeAccount")]
4242
InvalidFeeAccount,
4343

@@ -79,6 +79,9 @@ pub enum StakePoolError {
7979
/// The size of the given validator stake list does match the expected amount
8080
#[error("UnexpectedValidatorListAccountSize")]
8181
UnexpectedValidatorListAccountSize,
82+
/// Wrong pool staker account.
83+
#[error("WrongStaker")]
84+
WrongStaker,
8285
}
8386
impl From<StakePoolError> for ProgramError {
8487
fn from(e: StakePoolError) -> Self {

stake-pool/program/src/instruction.rs

Lines changed: 69 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -30,13 +30,14 @@ pub enum StakePoolInstruction {
3030
/// Initializes a new StakePool.
3131
///
3232
/// 0. `[w]` New StakePool to create.
33-
/// 1. `[s]` Owner
34-
/// 2. `[w]` Uninitialized validator stake list storage account
35-
/// 3. `[]` pool token Mint. Must be non zero, owned by withdraw authority.
36-
/// 4. `[]` Pool Account to deposit the generated fee for owner.
37-
/// 5. `[]` Clock sysvar
38-
/// 6. `[]` Rent sysvar
39-
/// 7. `[]` Token program id
33+
/// 1. `[s]` Manager
34+
/// 2. `[]` Staker
35+
/// 3. `[w]` Uninitialized validator stake list storage account
36+
/// 4. `[]` Pool token mint. Must be non zero, owned by withdraw authority.
37+
/// 5. `[]` Pool account to deposit the generated fee for manager.
38+
/// 6. `[]` Clock sysvar
39+
/// 7. `[]` Rent sysvar
40+
/// 8. `[]` Token program id
4041
Initialize {
4142
/// Deposit fee assessed
4243
#[allow(dead_code)] // but it's not
@@ -46,10 +47,11 @@ pub enum StakePoolInstruction {
4647
max_validators: u32,
4748
},
4849

49-
/// Creates new program account for accumulating stakes for a particular validator
50+
/// (Staker only) Creates new program account for accumulating stakes for
51+
/// a particular validator
5052
///
5153
/// 0. `[]` Stake pool account this stake will belong to
52-
/// 1. `[s]` Owner
54+
/// 1. `[s]` Staker
5355
/// 2. `[ws]` Funding account (must be a system account)
5456
/// 3. `[w]` Stake account to be created
5557
/// 4. `[]` Validator this stake account will vote for
@@ -58,11 +60,11 @@ pub enum StakePoolInstruction {
5860
/// 7. `[]` Stake program
5961
CreateValidatorStakeAccount,
6062

61-
/// Adds stake account delegated to validator to the pool's list of
62-
/// managed validators
63+
/// (Staker only) Adds stake account delegated to validator to the pool's
64+
/// list of managed validators
6365
///
6466
/// 0. `[w]` Stake pool
65-
/// 1. `[s]` Owner
67+
/// 1. `[s]` Staker
6668
/// 2. `[]` Stake pool deposit authority
6769
/// 3. `[]` Stake pool withdraw authority
6870
/// 4. `[w]` Validator stake list storage account
@@ -75,10 +77,10 @@ pub enum StakePoolInstruction {
7577
/// 11. `[]` Stake program id,
7678
AddValidatorToPool,
7779

78-
/// Removes validator stake account from the pool
80+
/// (Staker only) Removes validator from the pool
7981
///
8082
/// 0. `[w]` Stake pool
81-
/// 1. `[s]` Owner
83+
/// 1. `[s]` Staker
8284
/// 2. `[]` Stake pool withdraw authority
8385
/// 3. `[]` New withdraw/staker authority to set in the stake account
8486
/// 4. `[w]` Validator stake list storage account
@@ -139,23 +141,31 @@ pub enum StakePoolInstruction {
139141
/// userdata: amount to withdraw
140142
Withdraw(u64),
141143

142-
/// Update owner
144+
/// (Manager only) Update manager
143145
///
144-
/// 0. `[w]` StakePool
145-
/// 1. `[s]` Owner
146-
/// 2. '[]` New owner pubkey
147-
/// 3. '[]` New owner fee account
148-
SetOwner,
146+
/// 0. `[w]` StakePool
147+
/// 1. `[s]` Manager
148+
/// 2. '[]` New manager pubkey
149+
/// 3. '[]` New manager fee account
150+
SetManager,
151+
152+
/// (Manager or staker only) Update staker
153+
///
154+
/// 0. `[w]` StakePool
155+
/// 1. `[s]` Manager or current staker
156+
/// 2. '[]` New staker pubkey
157+
SetStaker,
149158
}
150159

151160
/// Creates an 'initialize' instruction.
152161
pub fn initialize(
153162
program_id: &Pubkey,
154163
stake_pool: &Pubkey,
155-
owner: &Pubkey,
164+
manager: &Pubkey,
165+
staker: &Pubkey,
156166
validator_list: &Pubkey,
157167
pool_mint: &Pubkey,
158-
owner_pool_account: &Pubkey,
168+
manager_pool_account: &Pubkey,
159169
token_program_id: &Pubkey,
160170
fee: Fee,
161171
max_validators: u32,
@@ -167,10 +177,11 @@ pub fn initialize(
167177
let data = init_data.try_to_vec()?;
168178
let accounts = vec![
169179
AccountMeta::new(*stake_pool, true),
170-
AccountMeta::new_readonly(*owner, true),
180+
AccountMeta::new_readonly(*manager, true),
181+
AccountMeta::new_readonly(*staker, false),
171182
AccountMeta::new(*validator_list, false),
172183
AccountMeta::new_readonly(*pool_mint, false),
173-
AccountMeta::new_readonly(*owner_pool_account, false),
184+
AccountMeta::new_readonly(*manager_pool_account, false),
174185
AccountMeta::new_readonly(sysvar::clock::id(), false),
175186
AccountMeta::new_readonly(sysvar::rent::id(), false),
176187
AccountMeta::new_readonly(*token_program_id, false),
@@ -186,14 +197,14 @@ pub fn initialize(
186197
pub fn create_validator_stake_account(
187198
program_id: &Pubkey,
188199
stake_pool: &Pubkey,
189-
owner: &Pubkey,
200+
staker: &Pubkey,
190201
funder: &Pubkey,
191202
stake_account: &Pubkey,
192203
validator: &Pubkey,
193204
) -> Result<Instruction, ProgramError> {
194205
let accounts = vec![
195206
AccountMeta::new_readonly(*stake_pool, false),
196-
AccountMeta::new_readonly(*owner, true),
207+
AccountMeta::new_readonly(*staker, true),
197208
AccountMeta::new(*funder, true),
198209
AccountMeta::new(*stake_account, false),
199210
AccountMeta::new_readonly(*validator, false),
@@ -215,7 +226,7 @@ pub fn create_validator_stake_account(
215226
pub fn add_validator_to_pool(
216227
program_id: &Pubkey,
217228
stake_pool: &Pubkey,
218-
owner: &Pubkey,
229+
staker: &Pubkey,
219230
stake_pool_deposit: &Pubkey,
220231
stake_pool_withdraw: &Pubkey,
221232
validator_list: &Pubkey,
@@ -226,7 +237,7 @@ pub fn add_validator_to_pool(
226237
) -> Result<Instruction, ProgramError> {
227238
let accounts = vec![
228239
AccountMeta::new(*stake_pool, false),
229-
AccountMeta::new_readonly(*owner, true),
240+
AccountMeta::new_readonly(*staker, true),
230241
AccountMeta::new_readonly(*stake_pool_deposit, false),
231242
AccountMeta::new_readonly(*stake_pool_withdraw, false),
232243
AccountMeta::new(*validator_list, false),
@@ -249,7 +260,7 @@ pub fn add_validator_to_pool(
249260
pub fn remove_validator_from_pool(
250261
program_id: &Pubkey,
251262
stake_pool: &Pubkey,
252-
owner: &Pubkey,
263+
staker: &Pubkey,
253264
stake_pool_withdraw: &Pubkey,
254265
new_stake_authority: &Pubkey,
255266
validator_list: &Pubkey,
@@ -260,7 +271,7 @@ pub fn remove_validator_from_pool(
260271
) -> Result<Instruction, ProgramError> {
261272
let accounts = vec![
262273
AccountMeta::new(*stake_pool, false),
263-
AccountMeta::new_readonly(*owner, true),
274+
AccountMeta::new_readonly(*staker, true),
264275
AccountMeta::new_readonly(*stake_pool_withdraw, false),
265276
AccountMeta::new_readonly(*new_stake_authority, false),
266277
AccountMeta::new(*validator_list, false),
@@ -385,23 +396,42 @@ pub fn withdraw(
385396
})
386397
}
387398

388-
/// Creates a 'set owner' instruction.
389-
pub fn set_owner(
399+
/// Creates a 'set manager' instruction.
400+
pub fn set_manager(
401+
program_id: &Pubkey,
402+
stake_pool: &Pubkey,
403+
manager: &Pubkey,
404+
new_manager: &Pubkey,
405+
new_fee_receiver: &Pubkey,
406+
) -> Result<Instruction, ProgramError> {
407+
let accounts = vec![
408+
AccountMeta::new(*stake_pool, false),
409+
AccountMeta::new_readonly(*manager, true),
410+
AccountMeta::new_readonly(*new_manager, false),
411+
AccountMeta::new_readonly(*new_fee_receiver, false),
412+
];
413+
Ok(Instruction {
414+
program_id: *program_id,
415+
accounts,
416+
data: StakePoolInstruction::SetManager.try_to_vec()?,
417+
})
418+
}
419+
420+
/// Creates a 'set staker' instruction.
421+
pub fn set_staker(
390422
program_id: &Pubkey,
391423
stake_pool: &Pubkey,
392-
stake_pool_owner: &Pubkey,
393-
stake_pool_new_owner: &Pubkey,
394-
stake_pool_new_fee_receiver: &Pubkey,
424+
set_staker_authority: &Pubkey,
425+
new_staker: &Pubkey,
395426
) -> Result<Instruction, ProgramError> {
396427
let accounts = vec![
397428
AccountMeta::new(*stake_pool, false),
398-
AccountMeta::new_readonly(*stake_pool_owner, true),
399-
AccountMeta::new_readonly(*stake_pool_new_owner, false),
400-
AccountMeta::new_readonly(*stake_pool_new_fee_receiver, false),
429+
AccountMeta::new_readonly(*set_staker_authority, true),
430+
AccountMeta::new_readonly(*new_staker, false),
401431
];
402432
Ok(Instruction {
403433
program_id: *program_id,
404434
accounts,
405-
data: StakePoolInstruction::SetOwner.try_to_vec()?,
435+
data: StakePoolInstruction::SetStaker.try_to_vec()?,
406436
})
407437
}

0 commit comments

Comments
 (0)