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

Commit c0be064

Browse files
authored
stake-pool: Address a few points post-liquid staking (#2252)
1 parent 87d88bd commit c0be064

File tree

10 files changed

+141
-274
lines changed

10 files changed

+141
-274
lines changed

stake-pool/cli/src/main.rs

Lines changed: 34 additions & 77 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ use {
3737
spl_stake_pool::{
3838
self, find_stake_program_address, find_transient_stake_program_address,
3939
find_withdraw_authority_program_address,
40-
instruction::PreferredValidatorType,
40+
instruction::{DepositType, PreferredValidatorType},
4141
stake_program::{self, StakeState},
4242
state::{Fee, FeeType, StakePool, ValidatorList},
4343
},
@@ -1378,7 +1378,7 @@ fn command_set_deposit_authority(
13781378
config: &Config,
13791379
stake_pool_address: &Pubkey,
13801380
new_sol_deposit_authority: Option<Pubkey>,
1381-
for_stake_deposit: bool,
1381+
deposit_type: DepositType,
13821382
) -> CommandResult {
13831383
let mut signers = vec![config.fee_payer.as_ref(), config.manager.as_ref()];
13841384
unique_signers!(signers);
@@ -1389,7 +1389,7 @@ fn command_set_deposit_authority(
13891389
stake_pool_address,
13901390
&config.manager.pubkey(),
13911391
new_sol_deposit_authority.as_ref(),
1392-
for_stake_deposit,
1392+
deposit_type,
13931393
)],
13941394
&signers,
13951395
)?;
@@ -2039,8 +2039,8 @@ fn main() {
20392039
.help("Public key for the new stake pool staker."),
20402040
)
20412041
)
2042-
.subcommand(SubCommand::with_name("set-sol-deposit-authority")
2043-
.about("Change sol deposit authority account for the stake pool. Must be signed by the manager.")
2042+
.subcommand(SubCommand::with_name("set-deposit-authority")
2043+
.about("Change deposit authority account for the stake pool. Must be signed by the manager.")
20442044
.arg(
20452045
Arg::with_name("pool")
20462046
.index(1)
@@ -2051,39 +2051,17 @@ fn main() {
20512051
.help("Stake pool address."),
20522052
)
20532053
.arg(
2054-
Arg::with_name("new_sol_deposit_authority")
2054+
Arg::with_name("deposit_type")
20552055
.index(2)
2056-
.validator(is_pubkey)
2057-
.value_name("ADDRESS")
2058-
.takes_value(true)
2059-
.help("The public key for the new stake pool sol deposit authority."),
2060-
)
2061-
.arg(
2062-
Arg::with_name("unset")
2063-
.long("unset")
2064-
.takes_value(false)
2065-
.help("Unset the sol deposit authority.")
2066-
)
2067-
.group(ArgGroup::with_name("validator")
2068-
.arg("new_sol_deposit_authority")
2069-
.arg("unset")
2070-
.required(true)
2071-
)
2072-
)
2073-
.subcommand(SubCommand::with_name("set-stake-deposit-authority")
2074-
.about("Change stake deposit authority account for the stake pool. Must be signed by the manager.")
2075-
.arg(
2076-
Arg::with_name("pool")
2077-
.index(1)
2078-
.validator(is_pubkey)
2079-
.value_name("POOL_ADDRESS")
2056+
.value_name("DEPOSIT_TYPE")
2057+
.possible_values(&["stake", "sol"]) // DepositType enum
20802058
.takes_value(true)
20812059
.required(true)
2082-
.help("Stake pool address."),
2060+
.help("Deposit type to be updated."),
20832061
)
20842062
.arg(
20852063
Arg::with_name("new_stake_deposit_authority")
2086-
.index(2)
2064+
.index(3)
20872065
.validator(is_pubkey)
20882066
.value_name("ADDRESS_OR_NONE")
20892067
.takes_value(true)
@@ -2115,7 +2093,7 @@ fn main() {
21152093
.arg(Arg::with_name("fee_type")
21162094
.index(2)
21172095
.value_name("FEE_TYPE")
2118-
.possible_values(&["epoch", "stake-deposit", "sol-deposit", "withdrawal"]) // PreferredValidatorType enum
2096+
.possible_values(&["epoch", "stake-deposit", "sol-deposit", "withdrawal"]) // FeeType enum
21192097
.takes_value(true)
21202098
.required(true)
21212099
.help("Fee type to be updated."),
@@ -2139,7 +2117,7 @@ fn main() {
21392117
.help("Fee denominator, fee amount is numerator divided by denominator."),
21402118
)
21412119
)
2142-
.subcommand(SubCommand::with_name("set-stake-referral-fee")
2120+
.subcommand(SubCommand::with_name("set-referral-fee")
21432121
.about("Change the referral fee assessed by the stake pool for stake deposits. Must be signed by the manager.")
21442122
.arg(
21452123
Arg::with_name("pool")
@@ -2150,29 +2128,17 @@ fn main() {
21502128
.required(true)
21512129
.help("Stake pool address."),
21522130
)
2153-
.arg(
2154-
Arg::with_name("fee")
2155-
.index(2)
2156-
.validator(is_valid_percentage)
2157-
.value_name("FEE_PERCENTAGE")
2158-
.takes_value(true)
2159-
.required(true)
2160-
.help("Fee percentage, maximum 100"),
2161-
)
2162-
).subcommand(SubCommand::with_name("set-sol-referral-fee")
2163-
.about("Change the referral fee assessed by the stake pool for SOL deposits. Must be signed by the manager.")
2164-
.arg(
2165-
Arg::with_name("pool")
2166-
.index(1)
2167-
.validator(is_pubkey)
2168-
.value_name("POOL_ADDRESS")
2169-
.takes_value(true)
2170-
.required(true)
2171-
.help("Stake pool address."),
2131+
.arg(Arg::with_name("fee_type")
2132+
.index(2)
2133+
.value_name("FEE_TYPE")
2134+
.possible_values(&["stake", "sol"]) // FeeType enum, kind of
2135+
.takes_value(true)
2136+
.required(true)
2137+
.help("Fee type to be updated."),
21722138
)
21732139
.arg(
21742140
Arg::with_name("fee")
2175-
.index(2)
2141+
.index(3)
21762142
.validator(is_valid_percentage)
21772143
.value_name("FEE_PERCENTAGE")
21782144
.takes_value(true)
@@ -2408,26 +2374,20 @@ fn main() {
24082374
let new_staker = pubkey_of(arg_matches, "new_staker").unwrap();
24092375
command_set_staker(&config, &stake_pool_address, &new_staker)
24102376
}
2411-
("set-stake-deposit-authority", Some(arg_matches)) => {
2377+
("set-deposit-authority", Some(arg_matches)) => {
24122378
let stake_pool_address = pubkey_of(arg_matches, "pool").unwrap();
24132379
let new_stake_deposit_authority = pubkey_of(arg_matches, "new_stake_deposit_authority");
2380+
let deposit_type = match arg_matches.value_of("deposit_type").unwrap() {
2381+
"sol" => DepositType::Sol,
2382+
"stake" => DepositType::Stake,
2383+
_ => unreachable!(),
2384+
};
24142385
let _unset = arg_matches.is_present("unset");
24152386
command_set_deposit_authority(
24162387
&config,
24172388
&stake_pool_address,
24182389
new_stake_deposit_authority,
2419-
true,
2420-
)
2421-
}
2422-
("set-sol-deposit-authority", Some(arg_matches)) => {
2423-
let stake_pool_address = pubkey_of(arg_matches, "pool").unwrap();
2424-
let new_sol_deposit_authority = pubkey_of(arg_matches, "new_sol_deposit_authority");
2425-
let _unset = arg_matches.is_present("unset");
2426-
command_set_deposit_authority(
2427-
&config,
2428-
&stake_pool_address,
2429-
new_sol_deposit_authority,
2430-
false,
2390+
deposit_type,
24312391
)
24322392
}
24332393
("set-fee", Some(arg_matches)) => {
@@ -2452,21 +2412,18 @@ fn main() {
24522412
_ => unreachable!(),
24532413
}
24542414
}
2455-
("set-stake-referral-fee", Some(arg_matches)) => {
2415+
("set-referral-fee", Some(arg_matches)) => {
24562416
let stake_pool_address = pubkey_of(arg_matches, "pool").unwrap();
24572417
let fee = value_t_or_exit!(arg_matches, "fee", u8);
24582418
if fee > 100u8 {
24592419
panic!("Invalid fee {}%. Fee needs to be in range [0-100]", fee);
24602420
}
2461-
command_set_fee(&config, &stake_pool_address, FeeType::StakeReferral(fee))
2462-
}
2463-
("set-sol-referral-fee", Some(arg_matches)) => {
2464-
let stake_pool_address = pubkey_of(arg_matches, "pool").unwrap();
2465-
let fee = value_t_or_exit!(arg_matches, "fee", u8);
2466-
if fee > 100u8 {
2467-
panic!("Invalid fee {}%. Fee needs to be in range [0-100]", fee);
2468-
}
2469-
command_set_fee(&config, &stake_pool_address, FeeType::SolReferral(fee))
2421+
let fee_type = match arg_matches.value_of("fee_type").unwrap() {
2422+
"sol" => FeeType::SolReferral(fee),
2423+
"stake" => FeeType::StakeReferral(fee),
2424+
_ => unreachable!(),
2425+
};
2426+
command_set_fee(&config, &stake_pool_address, fee_type)
24702427
}
24712428
_ => unreachable!(),
24722429
}

stake-pool/program/src/instruction.rs

Lines changed: 7 additions & 119 deletions
Original file line numberDiff line numberDiff line change
@@ -28,14 +28,14 @@ pub enum PreferredValidatorType {
2828
Withdraw,
2929
}
3030

31-
/// Defines which validator vote account is set during the
32-
/// `SetPreferredValidator` instruction
31+
/// Defines which deposit authority to update in the `SetDepositAuthority`
32+
/// instruction
3333
#[repr(C)]
3434
#[derive(Clone, Debug, PartialEq, BorshSerialize, BorshDeserialize, BorshSchema)]
3535
pub enum DepositType {
36-
/// Set preferred validator for deposits
36+
/// Sets the stake deposit authority
3737
Stake,
38-
/// Set preferred validator for withdraws
38+
/// Sets the SOL deposit authority
3939
Sol,
4040
}
4141

@@ -1132,66 +1132,6 @@ pub fn set_fee(
11321132
}
11331133
}
11341134

1135-
/// Creates a 'set fee' instruction for setting the epoch fee
1136-
pub fn set_epoch_fee(
1137-
program_id: &Pubkey,
1138-
stake_pool: &Pubkey,
1139-
manager: &Pubkey,
1140-
fee: Fee,
1141-
) -> Instruction {
1142-
set_fee(program_id, stake_pool, manager, FeeType::Epoch(fee))
1143-
}
1144-
1145-
/// Creates a 'set fee' instruction for setting withdrawal fee
1146-
pub fn set_withdrawal_fee(
1147-
program_id: &Pubkey,
1148-
stake_pool: &Pubkey,
1149-
manager: &Pubkey,
1150-
fee: Fee,
1151-
) -> Instruction {
1152-
set_fee(program_id, stake_pool, manager, FeeType::Withdrawal(fee))
1153-
}
1154-
1155-
/// Creates a 'set fee' instruction for setting SOL deposit fee
1156-
pub fn set_sol_deposit_fee(
1157-
program_id: &Pubkey,
1158-
stake_pool: &Pubkey,
1159-
manager: &Pubkey,
1160-
fee: Fee,
1161-
) -> Instruction {
1162-
set_fee(program_id, stake_pool, manager, FeeType::SolDeposit(fee))
1163-
}
1164-
1165-
/// Creates a 'set fee' instruction for setting stake deposit fee
1166-
pub fn set_stake_deposit_fee(
1167-
program_id: &Pubkey,
1168-
stake_pool: &Pubkey,
1169-
manager: &Pubkey,
1170-
fee: Fee,
1171-
) -> Instruction {
1172-
set_fee(program_id, stake_pool, manager, FeeType::StakeDeposit(fee))
1173-
}
1174-
1175-
/// Creates a 'set fee' instruction for setting SOL referral fee
1176-
pub fn set_sol_referral_fee(
1177-
program_id: &Pubkey,
1178-
stake_pool: &Pubkey,
1179-
manager: &Pubkey,
1180-
fee: u8,
1181-
) -> Instruction {
1182-
set_fee(program_id, stake_pool, manager, FeeType::SolReferral(fee))
1183-
}
1184-
1185-
/// Creates a 'set fee' instruction for setting stake referral fee
1186-
pub fn set_stake_referral_fee(
1187-
program_id: &Pubkey,
1188-
stake_pool: &Pubkey,
1189-
manager: &Pubkey,
1190-
fee: u8,
1191-
) -> Instruction {
1192-
set_fee(program_id, stake_pool, manager, FeeType::StakeReferral(fee))
1193-
}
1194-
11951135
/// Creates a 'set staker' instruction.
11961136
pub fn set_staker(
11971137
program_id: &Pubkey,
@@ -1211,13 +1151,13 @@ pub fn set_staker(
12111151
}
12121152
}
12131153

1214-
/// Creates a 'set sol deposit authority' instruction.
1154+
/// Creates a 'set deposit authority' instruction.
12151155
pub fn set_deposit_authority(
12161156
program_id: &Pubkey,
12171157
stake_pool: &Pubkey,
12181158
manager: &Pubkey,
12191159
new_sol_deposit_authority: Option<&Pubkey>,
1220-
for_stake_deposit: bool,
1160+
deposit_type: DepositType,
12211161
) -> Instruction {
12221162
let mut accounts = vec![
12231163
AccountMeta::new(*stake_pool, false),
@@ -1229,59 +1169,7 @@ pub fn set_deposit_authority(
12291169
Instruction {
12301170
program_id: *program_id,
12311171
accounts,
1232-
data: if for_stake_deposit {
1233-
StakePoolInstruction::SetDepositAuthority(DepositType::Stake)
1234-
.try_to_vec()
1235-
.unwrap()
1236-
} else {
1237-
StakePoolInstruction::SetDepositAuthority(DepositType::Sol)
1238-
.try_to_vec()
1239-
.unwrap()
1240-
},
1241-
}
1242-
}
1243-
1244-
/// Creates a 'set stake deposit authority' instruction.
1245-
pub fn set_stake_deposit_authority(
1246-
program_id: &Pubkey,
1247-
stake_pool: &Pubkey,
1248-
manager: &Pubkey,
1249-
new_stake_deposit_authority: Option<&Pubkey>,
1250-
) -> Instruction {
1251-
let mut accounts = vec![
1252-
AccountMeta::new(*stake_pool, false),
1253-
AccountMeta::new_readonly(*manager, true),
1254-
];
1255-
if let Some(auth) = new_stake_deposit_authority {
1256-
accounts.push(AccountMeta::new_readonly(*auth, false))
1257-
}
1258-
Instruction {
1259-
program_id: *program_id,
1260-
accounts,
1261-
data: StakePoolInstruction::SetDepositAuthority(DepositType::Stake)
1262-
.try_to_vec()
1263-
.unwrap(),
1264-
}
1265-
}
1266-
1267-
/// Creates a 'set stake deposit authority' instruction.
1268-
pub fn set_sol_deposit_authority(
1269-
program_id: &Pubkey,
1270-
stake_pool: &Pubkey,
1271-
manager: &Pubkey,
1272-
new_stake_deposit_authority: Option<&Pubkey>,
1273-
) -> Instruction {
1274-
let mut accounts = vec![
1275-
AccountMeta::new(*stake_pool, false),
1276-
AccountMeta::new_readonly(*manager, true),
1277-
];
1278-
if let Some(auth) = new_stake_deposit_authority {
1279-
accounts.push(AccountMeta::new_readonly(*auth, false))
1280-
}
1281-
Instruction {
1282-
program_id: *program_id,
1283-
accounts,
1284-
data: StakePoolInstruction::SetDepositAuthority(DepositType::Sol)
1172+
data: StakePoolInstruction::SetDepositAuthority(deposit_type)
12851173
.try_to_vec()
12861174
.unwrap(),
12871175
}

0 commit comments

Comments
 (0)