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

Commit 87b74cf

Browse files
authored
stake-pool: Combine create stake and add validator (#2371)
1 parent 5a4cff0 commit 87b74cf

File tree

14 files changed

+408
-974
lines changed

14 files changed

+408
-974
lines changed

stake-pool/cli/scripts/setup-stake-pool.sh

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -37,15 +37,6 @@ setup_pool () {
3737
--mint-keypair $mint_keyfile
3838
}
3939

40-
create_validator_stakes() {
41-
pool=$1
42-
validator_list=$2
43-
for validator in $(cat $validator_list)
44-
do
45-
$spl_stake_pool create-validator-stake $pool $validator
46-
done
47-
}
48-
4940
add_validator_stakes () {
5041
pool=$1
5142
validator_list=$2
@@ -65,7 +56,5 @@ setup_pool $max_validators $stake_pool_keyfile $mint_keyfile
6556

6657
stake_pool_pubkey=$(solana-keygen pubkey $stake_pool_keyfile)
6758

68-
echo "Creating validator stake accounts"
69-
create_validator_stakes $stake_pool_pubkey $validator_list
7059
echo "Adding validator stake accounts to the pool"
7160
add_validator_stakes $stake_pool_pubkey $validator_list

stake-pool/cli/src/main.rs

Lines changed: 1 addition & 70 deletions
Original file line numberDiff line numberDiff line change
@@ -357,36 +357,6 @@ fn command_create_pool(
357357
Ok(())
358358
}
359359

360-
fn command_vsa_create(
361-
config: &Config,
362-
stake_pool_address: &Pubkey,
363-
vote_account: &Pubkey,
364-
) -> CommandResult {
365-
let (stake_account, _) =
366-
find_stake_program_address(&spl_stake_pool::id(), vote_account, stake_pool_address);
367-
println!(
368-
"Creating stake account {}, delegated to {}",
369-
stake_account, vote_account
370-
);
371-
let transaction = checked_transaction_with_signers(
372-
config,
373-
&[
374-
// Create new validator stake account address
375-
spl_stake_pool::instruction::create_validator_stake_account(
376-
&spl_stake_pool::id(),
377-
stake_pool_address,
378-
&config.staker.pubkey(),
379-
&config.fee_payer.pubkey(),
380-
&stake_account,
381-
vote_account,
382-
),
383-
],
384-
&[config.fee_payer.as_ref(), config.staker.as_ref()],
385-
)?;
386-
send_transaction(config, transaction)?;
387-
Ok(())
388-
}
389-
390360
fn command_vsa_add(
391361
config: &Config,
392362
stake_pool_address: &Pubkey,
@@ -408,20 +378,6 @@ fn command_vsa_add(
408378
return Ok(());
409379
}
410380

411-
let stake_state = get_stake_state(&config.rpc_client, &stake_account_address)?;
412-
if let stake_program::StakeState::Stake(meta, _stake) = stake_state {
413-
if meta.authorized.withdrawer != config.staker.pubkey() {
414-
let error = format!(
415-
"Stake account withdraw authority must be the staker {}, actual {}",
416-
config.staker.pubkey(),
417-
meta.authorized.withdrawer
418-
);
419-
return Err(error.into());
420-
}
421-
} else {
422-
return Err("Stake account is not active.".into());
423-
}
424-
425381
if !config.no_update {
426382
command_update(config, stake_pool_address, false, false)?;
427383
}
@@ -435,6 +391,7 @@ fn command_vsa_add(
435391
&spl_stake_pool::id(),
436392
&stake_pool,
437393
stake_pool_address,
394+
&config.fee_payer.pubkey(),
438395
vote_account,
439396
),
440397
],
@@ -1714,27 +1671,6 @@ fn main() {
17141671
.help("Stake pool reserve keypair [default: new keypair]"),
17151672
)
17161673
)
1717-
.subcommand(SubCommand::with_name("create-validator-stake")
1718-
.about("Create a new stake account to use with the pool. Must be signed by the pool staker.")
1719-
.arg(
1720-
Arg::with_name("pool")
1721-
.index(1)
1722-
.validator(is_pubkey)
1723-
.value_name("POOL_ADDRESS")
1724-
.takes_value(true)
1725-
.required(true)
1726-
.help("Stake pool address"),
1727-
)
1728-
.arg(
1729-
Arg::with_name("vote_account")
1730-
.index(2)
1731-
.validator(is_pubkey)
1732-
.value_name("VOTE_ACCOUNT_ADDRESS")
1733-
.takes_value(true)
1734-
.required(true)
1735-
.help("The validator vote account that this stake will be delegated to"),
1736-
)
1737-
)
17381674
.subcommand(SubCommand::with_name("add-validator")
17391675
.about("Add validator account to the stake pool. Must be signed by the pool staker.")
17401676
.arg(
@@ -2345,11 +2281,6 @@ fn main() {
23452281
reserve_keypair,
23462282
)
23472283
}
2348-
("create-validator-stake", Some(arg_matches)) => {
2349-
let stake_pool_address = pubkey_of(arg_matches, "pool").unwrap();
2350-
let vote_account_address = pubkey_of(arg_matches, "vote_account").unwrap();
2351-
command_vsa_create(&config, &stake_pool_address, &vote_account_address)
2352-
}
23532284
("add-validator", Some(arg_matches)) => {
23542285
let stake_pool_address = pubkey_of(arg_matches, "pool").unwrap();
23552286
let vote_account_address = pubkey_of(arg_matches, "vote_account").unwrap();

stake-pool/program/src/instruction.rs

Lines changed: 24 additions & 83 deletions
Original file line numberDiff line numberDiff line change
@@ -77,42 +77,24 @@ pub enum StakePoolInstruction {
7777
max_validators: u32,
7878
},
7979

80-
/// (Staker only) Creates new program account for accumulating stakes for
81-
/// a particular validator
82-
///
83-
/// 0. `[]` Stake pool account this stake will belong to
84-
/// 1. `[s]` Staker
85-
/// 2. `[ws]` Funding account (must be a system account)
86-
/// 3. `[w]` Stake account to be created
87-
/// 4. `[]` Validator this stake account will vote for
88-
/// 5. `[]` Rent sysvar
89-
/// 6. `[]` Stake History sysvar
90-
/// 7. `[]` Stake Config sysvar
91-
/// 8. `[]` System program
92-
/// 9. `[]` Stake program
93-
CreateValidatorStakeAccount,
94-
9580
/// (Staker only) Adds stake account delegated to validator to the pool's
9681
/// list of managed validators.
9782
///
98-
/// The stake account must have the rent-exempt amount plus at least 1 SOL,
99-
/// and at most 1.001 SOL.
100-
///
101-
/// Once we delegate even 1 SOL, it will accrue rewards one epoch later,
102-
/// so we'll have more than 1 active SOL at this point.
103-
/// At 10% annualized rewards, 1 epoch of 2 days will accrue
104-
/// 0.000547945 SOL, so we check that it is at least 1 SOL, and at most
105-
/// 1.001 SOL.
83+
/// The stake account will have the rent-exempt amount plus 1 SOL.
10684
///
10785
/// 0. `[w]` Stake pool
10886
/// 1. `[s]` Staker
109-
/// 2. `[]` Stake pool withdraw authority
110-
/// 3. `[w]` Validator stake list storage account
111-
/// 4. `[w]` Stake account to add to the pool, its withdraw authority must
112-
/// be set to the staker
113-
/// 5. `[]` Clock sysvar
114-
/// 6. '[]' Sysvar stake history account
115-
/// 7. `[]` Stake program
87+
/// 2. `[ws]` Funding account (must be a system account)
88+
/// 3. `[]` Stake pool withdraw authority
89+
/// 4. `[w]` Validator stake list storage account
90+
/// 5. `[w]` Stake account to add to the pool
91+
/// 6. `[]` Validator this stake account will be delegated to
92+
/// 7. `[]` Rent sysvar
93+
/// 8. `[]` Clock sysvar
94+
/// 9. '[]' Stake history sysvar
95+
/// 10. '[]' Stake config sysvar
96+
/// 11. `[]` System program
97+
/// 12. `[]` Stake program
11698
AddValidatorToPool,
11799

118100
/// (Staker only) Removes validator from the pool
@@ -415,54 +397,30 @@ pub fn initialize(
415397
}
416398
}
417399

418-
/// Creates `CreateValidatorStakeAccount` instruction (create new stake account for the validator)
419-
pub fn create_validator_stake_account(
420-
program_id: &Pubkey,
421-
stake_pool: &Pubkey,
422-
staker: &Pubkey,
423-
funder: &Pubkey,
424-
stake_account: &Pubkey,
425-
validator: &Pubkey,
426-
) -> Instruction {
427-
let accounts = vec![
428-
AccountMeta::new_readonly(*stake_pool, false),
429-
AccountMeta::new_readonly(*staker, true),
430-
AccountMeta::new(*funder, true),
431-
AccountMeta::new(*stake_account, false),
432-
AccountMeta::new_readonly(*validator, false),
433-
AccountMeta::new_readonly(sysvar::rent::id(), false),
434-
AccountMeta::new_readonly(sysvar::clock::id(), false),
435-
AccountMeta::new_readonly(sysvar::stake_history::id(), false),
436-
AccountMeta::new_readonly(stake_program::config_id(), false),
437-
AccountMeta::new_readonly(system_program::id(), false),
438-
AccountMeta::new_readonly(stake_program::id(), false),
439-
];
440-
Instruction {
441-
program_id: *program_id,
442-
accounts,
443-
data: StakePoolInstruction::CreateValidatorStakeAccount
444-
.try_to_vec()
445-
.unwrap(),
446-
}
447-
}
448-
449400
/// Creates `AddValidatorToPool` instruction (add new validator stake account to the pool)
450401
pub fn add_validator_to_pool(
451402
program_id: &Pubkey,
452403
stake_pool: &Pubkey,
453404
staker: &Pubkey,
405+
funder: &Pubkey,
454406
stake_pool_withdraw: &Pubkey,
455407
validator_list: &Pubkey,
456-
stake_account: &Pubkey,
408+
stake: &Pubkey,
409+
validator: &Pubkey,
457410
) -> Instruction {
458411
let accounts = vec![
459412
AccountMeta::new(*stake_pool, false),
460413
AccountMeta::new_readonly(*staker, true),
414+
AccountMeta::new(*funder, true),
461415
AccountMeta::new_readonly(*stake_pool_withdraw, false),
462416
AccountMeta::new(*validator_list, false),
463-
AccountMeta::new(*stake_account, false),
417+
AccountMeta::new(*stake, false),
418+
AccountMeta::new_readonly(*validator, false),
419+
AccountMeta::new_readonly(sysvar::rent::id(), false),
464420
AccountMeta::new_readonly(sysvar::clock::id(), false),
465421
AccountMeta::new_readonly(sysvar::stake_history::id(), false),
422+
AccountMeta::new_readonly(stake_program::config_id(), false),
423+
AccountMeta::new_readonly(system_program::id(), false),
466424
AccountMeta::new_readonly(stake_program::id(), false),
467425
];
468426
Instruction {
@@ -610,32 +568,13 @@ pub fn set_preferred_validator(
610568
}
611569
}
612570

613-
/// Creates `CreateValidatorStakeAccount` instruction with a vote account
614-
pub fn create_validator_stake_account_with_vote(
615-
program_id: &Pubkey,
616-
stake_pool_address: &Pubkey,
617-
staker: &Pubkey,
618-
funder: &Pubkey,
619-
vote_account_address: &Pubkey,
620-
) -> Instruction {
621-
let (stake_account, _) =
622-
find_stake_program_address(program_id, vote_account_address, stake_pool_address);
623-
create_validator_stake_account(
624-
program_id,
625-
stake_pool_address,
626-
staker,
627-
funder,
628-
&stake_account,
629-
vote_account_address,
630-
)
631-
}
632-
633571
/// Create an `AddValidatorToPool` instruction given an existing stake pool and
634572
/// vote account
635573
pub fn add_validator_to_pool_with_vote(
636574
program_id: &Pubkey,
637575
stake_pool: &StakePool,
638576
stake_pool_address: &Pubkey,
577+
funder: &Pubkey,
639578
vote_account_address: &Pubkey,
640579
) -> Instruction {
641580
let pool_withdraw_authority =
@@ -646,9 +585,11 @@ pub fn add_validator_to_pool_with_vote(
646585
program_id,
647586
stake_pool_address,
648587
&stake_pool.staker,
588+
funder,
649589
&pool_withdraw_authority,
650590
&stake_pool.validator_list,
651591
&stake_account_address,
592+
vote_account_address,
652593
)
653594
}
654595

0 commit comments

Comments
 (0)