use {
solana_account_info::AccountInfo,
solana_clock::Epoch,
solana_program_error::ProgramError,
solana_pubkey::Pubkey,
solana_stake_interface::{
error::StakeError,
state::{Delegation, Stake},
},
};
pub(crate) struct ValidatedDelegatedInfo {
pub stake_amount: u64,
}
pub(crate) fn new_stake(
stake: u64,
voter_pubkey: &Pubkey,
credits_observed: u64,
activation_epoch: Epoch,
) -> Stake {
Stake {
delegation: Delegation::new(voter_pubkey, stake, activation_epoch),
credits_observed,
}
}
pub(crate) fn validate_delegated_amount(
account: &AccountInfo,
rent_exempt_reserve: u64,
) -> Result<ValidatedDelegatedInfo, ProgramError> {
let stake_amount = account.lamports().saturating_sub(rent_exempt_reserve);
if stake_amount < crate::get_minimum_delegation() {
return Err(StakeError::InsufficientDelegation.into());
}
Ok(ValidatedDelegatedInfo { stake_amount })
}