diff --git a/cli/src/stake.rs b/cli/src/stake.rs index 6d3f2916a6..6db8fad633 100644 --- a/cli/src/stake.rs +++ b/cli/src/stake.rs @@ -1002,6 +1002,7 @@ pub fn process_withdraw_stake( &withdraw_authority.pubkey(), destination_account_pubkey, lamports, + None, )]; let fee_payer = config.signers[fee_payer]; diff --git a/programs/stake/src/stake_instruction.rs b/programs/stake/src/stake_instruction.rs index a87ec591cc..86952a8568 100644 --- a/programs/stake/src/stake_instruction.rs +++ b/programs/stake/src/stake_instruction.rs @@ -327,8 +327,9 @@ pub fn withdraw( withdrawer_pubkey: &Pubkey, to_pubkey: &Pubkey, lamports: u64, + custodian_pubkey: Option<&Pubkey>, ) -> Instruction { - let account_metas = vec![ + let mut account_metas = vec![ AccountMeta::new(*stake_pubkey, false), AccountMeta::new(*to_pubkey, false), AccountMeta::new_readonly(sysvar::clock::id(), false), @@ -336,24 +337,9 @@ pub fn withdraw( ] .with_signer(withdrawer_pubkey); - Instruction::new(id(), &StakeInstruction::Withdraw(lamports), account_metas) -} - -pub fn withdraw_early( - stake_pubkey: &Pubkey, - withdrawer_pubkey: &Pubkey, - to_pubkey: &Pubkey, - lamports: u64, - custodian_pubkey: &Pubkey, -) -> Instruction { - let account_metas = vec![ - AccountMeta::new(*stake_pubkey, false), - AccountMeta::new(*to_pubkey, false), - AccountMeta::new_readonly(sysvar::clock::id(), false), - AccountMeta::new_readonly(sysvar::stake_history::id(), false), - ] - .with_signer(withdrawer_pubkey) - .with_signer(custodian_pubkey); + if let Some(custodian_pubkey) = custodian_pubkey { + account_metas = account_metas.with_signer(custodian_pubkey) + } Instruction::new(id(), &StakeInstruction::Withdraw(lamports), account_metas) } @@ -537,7 +523,8 @@ mod tests { &Pubkey::default(), &Pubkey::default(), &Pubkey::new_rand(), - 100 + 100, + None, )), Err(InstructionError::InvalidAccountData), ); diff --git a/runtime/tests/stake.rs b/runtime/tests/stake.rs index 00366aeb38..bb71fd198a 100644 --- a/runtime/tests/stake.rs +++ b/runtime/tests/stake.rs @@ -224,6 +224,7 @@ fn test_stake_account_lifetime() { &stake_pubkey, &Pubkey::new_rand(), 1, + None, )], Some(&mint_pubkey), ); @@ -318,6 +319,7 @@ fn test_stake_account_lifetime() { &stake_pubkey, &Pubkey::new_rand(), lamports / 2 - split_staked + 1, + None, )], Some(&mint_pubkey), ); @@ -339,6 +341,7 @@ fn test_stake_account_lifetime() { &stake_pubkey, &Pubkey::new_rand(), lamports / 2, + None, )], Some(&mint_pubkey), ); @@ -354,6 +357,7 @@ fn test_stake_account_lifetime() { &stake_pubkey, &Pubkey::new_rand(), lamports / 2 - split_staked, + None, )], Some(&mint_pubkey), ); @@ -378,6 +382,7 @@ fn test_stake_account_lifetime() { &stake_pubkey, &Pubkey::new_rand(), split_staked, + None, )], Some(&mint_pubkey), ); diff --git a/stake-monitor/src/lib.rs b/stake-monitor/src/lib.rs index cd6dbdd4d3..a932ba39a5 100644 --- a/stake-monitor/src/lib.rs +++ b/stake-monitor/src/lib.rs @@ -450,6 +450,7 @@ mod test { &stake3_keypair.pubkey(), &payer.pubkey(), one_sol, + None, )], Some(&payer.pubkey()), ),