Skip to content

Commit 6159dba

Browse files
authored
program: remove default deposit helpers (#632)
1 parent f63b6b0 commit 6159dba

13 files changed

Lines changed: 26 additions & 584 deletions

File tree

clients/cli/src/cli.rs

Lines changed: 4 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -76,22 +76,14 @@ pub enum Command {
7676
Manage(ManageCli),
7777

7878
/// Deposit delegated stake into a pool in exchange for pool tokens, closing
79-
/// out the original stake account. Provide either a stake account
80-
/// address, or a pool or vote account address along with the
81-
/// --default-stake-account flag to use an account created with
82-
/// create-stake.
79+
/// out the original stake account. Pool address is inferred from stake account.
8380
Deposit(DepositCli),
8481

8582
/// Withdraw stake into a new stake account, burning tokens in exchange.
8683
/// Provide either pool or vote account address, plus either an amount of
8784
/// tokens to burn or the ALL keyword to burn all.
8885
Withdraw(WithdrawCli),
8986

90-
/// WARNING: This command is DEPRECATED and will be removed in a future release.
91-
/// Create and delegate a new stake account to a given validator, using a
92-
/// default address linked to the intended depository pool
93-
CreateDefaultStake(CreateStakeCli),
94-
9587
/// Display info for one or all single-validator stake pool(s)
9688
Display(DisplayCli),
9789
}
@@ -158,31 +150,18 @@ pub struct ReplenishCli {
158150
}
159151

160152
#[derive(Clone, Debug, Args)]
161-
#[clap(group(ArgGroup::new("stake-source").required(true).args(&["stake-account-address", "default-stake-account"])))]
162153
#[clap(group(pool_source_group().required(false)))]
163154
pub struct DepositCli {
164155
/// The stake account to deposit from. Must be in the same activation state
165156
/// as the pool's stake account
166157
#[clap(value_parser = |p: &str| parse_address(p, "stake_account_address"))]
167-
pub stake_account_address: Option<Pubkey>,
168-
169-
/// WARNING: This flag is DEPRECATED and will be removed in a future release.
170-
/// Instead of using a stake account by address, use the user's default
171-
/// account for a specified pool
172-
#[clap(
173-
short,
174-
long,
175-
conflicts_with = "stake-account-address",
176-
requires = "pool-source"
177-
)]
178-
pub default_stake_account: bool,
158+
pub stake_account_address: Pubkey,
179159

180-
/// The pool to deposit into. Optional when stake account is provided
160+
/// The pool to deposit into. Optional for validation
181161
#[clap(short, long = "pool", value_parser = |p: &str| parse_address(p, "pool_address"))]
182162
pub pool_address: Option<Pubkey>,
183163

184-
/// The vote account corresponding to the pool to deposit into. Optional
185-
/// when stake account or pool is provided
164+
/// The vote account corresponding to the pool to deposit into. Optional for validation
186165
#[clap(long = "vote-account", value_parser = |p: &str| parse_address(p, "vote_account_address"))]
187166
pub vote_account_address: Option<Pubkey>,
188167

clients/cli/src/config.rs

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -22,15 +22,6 @@ pub fn println_display(config: &Config, message: String) {
2222
}
2323
}
2424

25-
pub fn eprintln_display(config: &Config, message: String) {
26-
match config.output_format {
27-
OutputFormat::Display | OutputFormat::DisplayVerbose => {
28-
eprintln!("{}", message);
29-
}
30-
_ => {}
31-
}
32-
}
33-
3425
pub struct Config {
3526
pub rpc_client: Arc<RpcClient>,
3627
pub program_client: Arc<dyn ProgramClient<ProgramRpcClientSendTransaction>>,

clients/cli/src/main.rs

Lines changed: 5 additions & 108 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,6 @@ use {
2727
std::{rc::Rc, sync::Arc},
2828
};
2929

30-
#[allow(deprecated)]
31-
use spl_single_pool::find_default_deposit_account_address;
32-
3330
mod config;
3431
use config::*;
3532

@@ -93,9 +90,6 @@ impl Command {
9390
Command::Withdraw(command_config) => {
9491
command_withdraw(config, command_config, matches, wallet_manager).await
9592
}
96-
Command::CreateDefaultStake(command_config) => {
97-
command_create_stake(config, command_config).await
98-
}
9993
Command::Display(command_config) => command_display(config, command_config).await,
10094
}
10195
}
@@ -218,6 +212,7 @@ async fn command_deposit(
218212
) -> CommandResult {
219213
let payer = config.fee_payer()?;
220214
let owner = config.default_signer()?;
215+
let stake_account_address = command_config.stake_account_address;
221216
let stake_authority = command_config
222217
.stake_withdraw_authority
223218
.and_then(|source| {
@@ -232,34 +227,16 @@ async fn command_deposit(
232227

233228
let current_epoch = config.rpc_client.get_epoch_info().await?.epoch;
234229

235-
// the cli invocation for this is conceptually simple, but a bit tricky
236-
// the user can provide pool or vote and let the cli infer the stake account
237-
// address but they can also provide pool or vote with the stake account, as
238-
// a safety check first we want to get the pool address if they provided a
239-
// pool or vote address
230+
// we originally accepted this because there was the notion of a "canonical"
231+
// stake account keyed off each wallet/pool combination. now we just derive
232+
// the pool address from the stake account delegation, but we still allow
233+
// the pool or vote address to be supplied for optional validation
240234
let provided_pool_address = command_config.pool_address.or_else(|| {
241235
command_config
242236
.vote_account_address
243237
.map(|address| find_pool_address(&spl_single_pool::id(), &address))
244238
});
245239

246-
// from there we can determine the stake account address
247-
let stake_account_address = if let Some(stake_account_address) =
248-
command_config.stake_account_address
249-
{
250-
stake_account_address
251-
} else if let Some(pool_address) = provided_pool_address {
252-
assert!(command_config.default_stake_account);
253-
eprintln_display(
254-
config,
255-
"WARNING: This flag is DEPRECATED and will be removed in a future release.".to_string(),
256-
);
257-
#[allow(deprecated)]
258-
find_default_deposit_account_address(&pool_address, &stake_authority.pubkey())
259-
} else {
260-
unreachable!()
261-
};
262-
263240
// now we validate the stake account and definitively resolve the pool address
264241
let (pool_address, user_stake_active) = if let Some((meta, stake)) =
265242
quarantine::get_stake_info(config, &stake_account_address).await?
@@ -694,86 +671,6 @@ async fn command_update_metadata(
694671
))
695672
}
696673

697-
// create default stake account
698-
async fn command_create_stake(config: &Config, command_config: CreateStakeCli) -> CommandResult {
699-
eprintln_display(
700-
config,
701-
"WARNING: This command is DEPRECATED and will be removed in a future release.".to_string(),
702-
);
703-
704-
let payer = config.fee_payer()?;
705-
let owner = config.default_signer()?;
706-
let stake_authority_address = command_config
707-
.stake_authority_address
708-
.unwrap_or_else(|| owner.pubkey());
709-
710-
let pool_address = pool_address_from_args(
711-
command_config.pool_address,
712-
command_config.vote_account_address,
713-
);
714-
715-
#[allow(deprecated)]
716-
let stake_account_address =
717-
find_default_deposit_account_address(&pool_address, &stake_authority_address);
718-
719-
println_display(
720-
config,
721-
format!("Creating default stake account for pool {}\n", pool_address),
722-
);
723-
724-
let vote_account_address = if let Some(vote_account_address) =
725-
command_config.vote_account_address
726-
{
727-
vote_account_address
728-
} else if let Ok(vote_account_address) = get_vote_address_from_pool(config, pool_address).await
729-
{
730-
vote_account_address
731-
} else {
732-
return Err(format!(
733-
"Cannot determine vote account address from provided pool address {}",
734-
pool_address,
735-
)
736-
.into());
737-
};
738-
739-
if command_config.vote_account_address.is_some()
740-
&& pool_is_initialized(config, pool_address).await.is_err()
741-
{
742-
eprintln_display(
743-
config,
744-
format!("warning: Pool {} has not been initialized", pool_address),
745-
);
746-
}
747-
748-
#[allow(deprecated)]
749-
let instructions = spl_single_pool::instruction::create_and_delegate_user_stake(
750-
&spl_single_pool::id(),
751-
&vote_account_address,
752-
&stake_authority_address,
753-
&quarantine::get_rent(config).await?,
754-
command_config.lamports,
755-
);
756-
757-
let transaction = Transaction::new_signed_with_payer(
758-
&instructions,
759-
Some(&payer.pubkey()),
760-
&vec![payer],
761-
config.program_client.get_latest_blockhash().await?,
762-
);
763-
764-
let signature = process_transaction(config, transaction).await?;
765-
766-
Ok(format_output(
767-
config,
768-
"CreateDefaultStake".to_string(),
769-
CreateStakeOutput {
770-
pool_address,
771-
stake_account_address,
772-
signature,
773-
},
774-
))
775-
}
776-
777674
// display stake pool(s)
778675
async fn command_display(config: &Config, command_config: DisplayCli) -> CommandResult {
779676
let minimum_pool_balance = quarantine::get_minimum_pool_balance(config).await?;

clients/cli/src/output.rs

Lines changed: 0 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -291,37 +291,3 @@ impl Display for WithdrawOutput {
291291
Ok(())
292292
}
293293
}
294-
295-
#[serde_as]
296-
#[derive(Debug, Serialize, Deserialize)]
297-
#[serde(rename_all = "camelCase")]
298-
pub struct CreateStakeOutput {
299-
#[serde_as(as = "DisplayFromStr")]
300-
pub pool_address: Pubkey,
301-
#[serde_as(as = "DisplayFromStr")]
302-
pub stake_account_address: Pubkey,
303-
#[serde_as(as = "Option<DisplayFromStr>")]
304-
pub signature: Option<Signature>,
305-
}
306-
307-
impl QuietDisplay for CreateStakeOutput {}
308-
impl VerboseDisplay for CreateStakeOutput {}
309-
310-
impl Display for CreateStakeOutput {
311-
fn fmt(&self, f: &mut Formatter<'_>) -> Result {
312-
writeln!(f)?;
313-
writeln_name_value(f, "Pool address:", &self.pool_address.to_string())?;
314-
writeln_name_value(
315-
f,
316-
"Stake account address:",
317-
&self.stake_account_address.to_string(),
318-
)?;
319-
320-
if let Some(signature) = self.signature {
321-
writeln!(f)?;
322-
writeln_name_value(f, "Signature:", &signature.to_string())?;
323-
}
324-
325-
Ok(())
326-
}
327-
}

clients/cli/tests/test.rs

Lines changed: 9 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -291,52 +291,27 @@ async fn replenish_pool(raise_minimum_delegation: bool) {
291291
assert!(status.success());
292292
}
293293

294-
#[test_case(false, false; "one_lamp::normal_stake")]
295-
#[test_case(true, false; "one_sol::normal_stake")]
296-
#[test_case(false, true; "one_lamp::default_stake")]
297-
#[test_case(true, true; "one_sol::default_stake")]
294+
#[test_case(false; "one_lamp")]
295+
#[test_case(true; "one_sol")]
298296
#[tokio::test(flavor = "multi_thread", worker_threads = 2)]
299297
#[serial]
300-
async fn deposit(raise_minimum_delegation: bool, use_default: bool) {
298+
async fn deposit(raise_minimum_delegation: bool) {
301299
let env = setup(raise_minimum_delegation, true).await;
302300

303-
let stake_account = if use_default {
304-
let status = Command::new(SVSP_CLI)
305-
.args([
306-
"create-default-stake",
307-
"-C",
308-
&env.config_file_path,
309-
"--vote-account",
310-
&env.vote_account.to_string(),
311-
&LAMPORTS_PER_SOL.to_string(),
312-
])
313-
.status()
314-
.unwrap();
315-
assert!(status.success());
316-
317-
Pubkey::default()
318-
} else {
319-
create_and_delegate_stake_account(&env.rpc_client, &env.payer, &env.vote_account).await
320-
};
301+
let stake_account =
302+
create_and_delegate_stake_account(&env.rpc_client, &env.payer, &env.vote_account).await;
321303

322304
wait_for_next_epoch(&env.rpc_client).await;
323305

324-
let mut args = vec![
306+
let args = vec![
325307
"deposit".to_string(),
326308
"-C".to_string(),
327309
env.config_file_path,
310+
stake_account.to_string(),
311+
"--vote-account".to_string(),
312+
env.vote_account.to_string(),
328313
];
329314

330-
if use_default {
331-
args.extend([
332-
"--vote-account".to_string(),
333-
env.vote_account.to_string(),
334-
"--default-stake-account".to_string(),
335-
]);
336-
} else {
337-
args.push(stake_account.to_string());
338-
};
339-
340315
let status = Command::new(SVSP_CLI).args(&args).status().unwrap();
341316
assert!(status.success());
342317
}

clients/js-legacy/src/addresses.ts

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ import {
99
findPoolStakeAuthorityAddress as findStakeAuthorityModern,
1010
findPoolMintAuthorityAddress as findMintAuthorityModern,
1111
findPoolMplAuthorityAddress as findMplAuthorityModern,
12-
findDefaultDepositAccountAddress as findDefaultDepositModern,
1312
} from '@solana/spl-single-pool';
1413

1514
export async function findPoolAddress(programId: PublicKey, voteAccountAddress: PublicKey) {
@@ -65,16 +64,3 @@ export async function findPoolMplAuthorityAddress(programId: PublicKey, poolAddr
6564
),
6665
);
6766
}
68-
69-
/** @deprecated */
70-
export async function findDefaultDepositAccountAddress(
71-
poolAddress: PublicKey,
72-
userWallet: PublicKey,
73-
) {
74-
return new PublicKey(
75-
await findDefaultDepositModern(
76-
poolAddress.toBase58() as PoolAddress,
77-
userWallet.toBase58() as Address,
78-
),
79-
);
80-
}

clients/js-legacy/src/transactions.ts

Lines changed: 1 addition & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,7 @@ interface DepositParams {
99
connection: Connection;
1010
pool: PublicKey;
1111
userWallet: PublicKey;
12-
userStakeAccount?: PublicKey;
13-
depositFromDefaultAccount?: boolean;
12+
userStakeAccount: PublicKey;
1413
userTokenAccount?: PublicKey;
1514
userLamportAccount?: PublicKey;
1615
userWithdrawAuthority?: PublicKey;
@@ -106,20 +105,4 @@ export class SinglePoolProgram {
106105

107106
return modernTransactionToLegacy(modernTransaction);
108107
}
109-
110-
static async createAndDelegateUserStake(
111-
connection: Connection,
112-
voteAccount: PublicKey,
113-
userWallet: PublicKey,
114-
stakeAmount: number | bigint,
115-
) {
116-
const modernTransaction = await PoolProgramModern.createAndDelegateUserStake(
117-
rpc(connection),
118-
voteAccount.toBase58() as VoteAccountAddress,
119-
userWallet.toBase58() as Address,
120-
BigInt(stakeAmount),
121-
);
122-
123-
return modernTransactionToLegacy(modernTransaction);
124-
}
125108
}

0 commit comments

Comments
 (0)