#![allow(deprecated)]
#[cfg(feature = "codama")]
use codama_macros::{CodamaInstructions, CodamaType};
use {
crate::state::{Authorized, Lockup, StakeAuthorize},
solana_clock::{Epoch, UnixTimestamp},
solana_pubkey::Pubkey,
};
#[cfg(feature = "bincode")]
use {
crate::{config, program::ID, state::StakeStateV2},
solana_instruction::{AccountMeta, Instruction},
};
#[cfg(feature = "bincode")]
const CLOCK_ID: Pubkey = Pubkey::from_str_const("SysvarC1ock11111111111111111111111111111111");
#[cfg(feature = "bincode")]
const RENT_ID: Pubkey = Pubkey::from_str_const("SysvarRent111111111111111111111111111111111");
#[cfg(feature = "bincode")]
const STAKE_HISTORY_ID: Pubkey =
Pubkey::from_str_const("SysvarStakeHistory1111111111111111111111111");
#[cfg_attr(
feature = "serde",
derive(serde_derive::Deserialize, serde_derive::Serialize)
)]
#[cfg_attr(feature = "codama", derive(CodamaInstructions))]
#[derive(Debug, PartialEq, Eq, Clone)]
pub enum StakeInstruction {
#[cfg_attr(
feature = "codama",
codama(account(name = "stake", writable, docs = "Uninitialized stake account")),
codama(account(name = "rent_sysvar", docs = "Rent sysvar", default_value = sysvar("rent")))
)]
Initialize(Authorized, Lockup),
#[cfg_attr(
feature = "codama",
codama(account(name = "stake", writable, docs = "Stake account to be updated")),
codama(account(name = "clock_sysvar", docs = "Clock sysvar", default_value = sysvar("clock"))),
codama(account(name = "authority", signer, docs = "The stake or withdraw authority")),
codama(account(
name = "lockup_authority",
optional,
signer,
docs = "Lockup authority, if updating `StakeAuthorize::Withdrawer` before lockup expiration"
))
)]
Authorize(Pubkey, StakeAuthorize),
#[cfg_attr(
feature = "codama",
codama(account(
name = "stake",
writable,
docs = "Initialized stake account to be delegated"
)),
codama(account(
name = "vote",
docs = "Vote account to which this stake will be delegated"
)),
codama(account(name = "clock_sysvar", docs = "Clock sysvar", default_value = sysvar("clock"))),
codama(account(
name = "stake_history",
docs = "Stake history sysvar that carries stake warmup/cooldown history",
default_value = sysvar("stake_history")
)),
codama(account(name = "unused", docs = "Unused account, formerly the stake config")),
codama(account(name = "stake_authority", signer, docs = "Stake authority"))
)]
DelegateStake,
#[cfg_attr(
feature = "codama",
codama(account(
name = "stake",
writable,
docs = "Stake account to be split; must be in the Initialized or Stake state"
)),
codama(account(
name = "split_stake",
writable,
docs = "Uninitialized stake account that will take the split-off amount"
)),
codama(account(name = "stake_authority", signer, docs = "Stake authority"))
)]
Split(#[cfg_attr(feature = "codama", codama(name = "args"))] u64),
#[cfg_attr(
feature = "codama",
codama(account(
name = "stake",
writable,
docs = "Stake account from which to withdraw"
)),
codama(account(name = "recipient", writable, docs = "Recipient account")),
codama(account(name = "clock_sysvar", docs = "Clock sysvar", default_value = sysvar("clock"))),
codama(account(
name = "stake_history",
docs = "Stake history sysvar that carries stake warmup/cooldown history",
default_value = sysvar("stake_history")
)),
codama(account(name = "withdraw_authority", signer, docs = "Withdraw authority")),
codama(account(
name = "lockup_authority",
optional,
signer,
docs = "Lockup authority, if before lockup expiration"
))
)]
Withdraw(#[cfg_attr(feature = "codama", codama(name = "args"))] u64),
#[cfg_attr(
feature = "codama",
codama(account(
name = "stake",
writable,
docs = "Delegated stake account to be deactivated"
)),
codama(account(name = "clock_sysvar", docs = "Clock sysvar", default_value = sysvar("clock"))),
codama(account(name = "stake_authority", signer, docs = "Stake authority"))
)]
Deactivate,
#[cfg_attr(
feature = "codama",
codama(account(name = "stake", writable, docs = "Initialized stake account")),
codama(account(
name = "authority",
signer,
docs = "Lockup authority or withdraw authority"
))
)]
SetLockup(LockupArgs),
#[cfg_attr(
feature = "codama",
codama(account(
name = "destination_stake",
writable,
docs = "Destination stake account for the merge"
)),
codama(account(
name = "source_stake",
writable,
docs = "Source stake account for to merge. This account will be drained"
)),
codama(account(name = "clock_sysvar", docs = "Clock sysvar", default_value = sysvar("clock"))),
codama(account(
name = "stake_history",
docs = "Stake history sysvar that carries stake warmup/cooldown history",
default_value = sysvar("stake_history")
)),
codama(account(name = "stake_authority", signer, docs = "Stake authority"))
)]
Merge,
#[cfg_attr(
feature = "codama",
codama(account(name = "stake", writable, docs = "Stake account to be updated")),
codama(account(
name = "base",
signer,
docs = "Base key of stake or withdraw authority"
)),
codama(account(name = "clock_sysvar", docs = "Clock sysvar", default_value = sysvar("clock"))),
codama(account(
name = "lockup_authority",
optional,
signer,
docs = "Lockup authority, if updating `StakeAuthorize::Withdrawer` before lockup expiration"
))
)]
AuthorizeWithSeed(AuthorizeWithSeedArgs),
#[cfg_attr(
feature = "codama",
codama(account(name = "stake", writable, docs = "Uninitialized stake account")),
codama(account(name = "rent_sysvar", docs = "Rent sysvar", default_value = sysvar("rent"))),
codama(account(name = "stake_authority", docs = "The stake authority")),
codama(account(name = "withdraw_authority", signer, docs = "The withdraw authority"))
)]
InitializeChecked,
#[cfg_attr(
feature = "codama",
codama(account(name = "stake", writable, docs = "Stake account to be updated")),
codama(account(name = "clock_sysvar", docs = "Clock sysvar", default_value = sysvar("clock"))),
codama(account(name = "authority", signer, docs = "The stake or withdraw authority")),
codama(account(
name = "new_authority",
signer,
docs = "The new stake or withdraw authority"
)),
codama(account(
name = "lockup_authority",
optional,
signer,
docs = "Lockup authority, if updating `StakeAuthorize::Withdrawer` before lockup expiration"
))
)]
AuthorizeChecked(
#[cfg_attr(feature = "codama", codama(name = "stakeAuthorize"))] StakeAuthorize,
),
#[cfg_attr(
feature = "codama",
codama(account(name = "stake", writable, docs = "Stake account to be updated")),
codama(account(
name = "base",
signer,
docs = "Base key of stake or withdraw authority"
)),
codama(account(name = "clock_sysvar", docs = "Clock sysvar", default_value = sysvar("clock"))),
codama(account(
name = "new_authority",
signer,
docs = "The new stake or withdraw authority"
)),
codama(account(
name = "lockup_authority",
optional,
signer,
docs = "Lockup authority, if updating `StakeAuthorize::Withdrawer` before lockup expiration"
))
)]
AuthorizeCheckedWithSeed(AuthorizeCheckedWithSeedArgs),
#[cfg_attr(
feature = "codama",
codama(account(name = "stake", writable, docs = "Initialized stake account")),
codama(account(
name = "authority",
signer,
docs = "Lockup authority or withdraw authority"
)),
codama(account(
name = "new_authority",
optional,
signer,
docs = "New lockup authority"
))
)]
SetLockupChecked(LockupCheckedArgs),
GetMinimumDelegation,
#[cfg_attr(
feature = "codama",
codama(account(name = "stake", writable, docs = "Delegated stake account")),
codama(account(
name = "delinquent_vote",
docs = "Delinquent vote account for the delegated stake account"
)),
codama(account(
name = "reference_vote",
docs = "Reference vote account that has voted at least once in the last `MINIMUM_DELINQUENT_EPOCHS_FOR_DEACTIVATION` epochs"
))
)]
DeactivateDelinquent,
#[deprecated(since = "2.1.0", note = "Redelegate will not be enabled")]
Redelegate,
#[cfg_attr(
feature = "codama",
codama(account(name = "sourceStake", writable, docs = "Active source stake account")),
codama(account(
name = "destinationStake",
writable,
docs = "Active or inactive destination stake account"
)),
codama(account(name = "stake_authority", signer, docs = "Stake authority"))
)]
MoveStake(#[cfg_attr(feature = "codama", codama(name = "args"))] u64),
#[cfg_attr(
feature = "codama",
codama(account(
name = "source_stake",
writable,
docs = "Active or inactive source stake account"
)),
codama(account(
name = "destination_stake",
writable,
docs = "Mergeable destination stake account"
)),
codama(account(name = "stake_authority", signer, docs = "Stake authority"))
)]
MoveLamports(#[cfg_attr(feature = "codama", codama(name = "args"))] u64),
}
#[cfg_attr(feature = "codama", derive(CodamaType), codama(name = "lockupParams"))]
#[derive(Default, Debug, PartialEq, Eq, Clone, Copy)]
#[cfg_attr(
feature = "serde",
derive(serde_derive::Deserialize, serde_derive::Serialize)
)]
pub struct LockupArgs {
pub unix_timestamp: Option<UnixTimestamp>,
pub epoch: Option<Epoch>,
pub custodian: Option<Pubkey>,
}
#[cfg_attr(
feature = "codama",
derive(CodamaType),
codama(name = "lockupCheckedParams")
)]
#[derive(Default, Debug, PartialEq, Eq, Clone, Copy)]
#[cfg_attr(
feature = "serde",
derive(serde_derive::Deserialize, serde_derive::Serialize)
)]
pub struct LockupCheckedArgs {
pub unix_timestamp: Option<UnixTimestamp>,
pub epoch: Option<Epoch>,
}
#[cfg_attr(
feature = "codama",
derive(CodamaType),
codama(name = "authorizeWithSeedParams")
)]
#[derive(Debug, PartialEq, Eq, Clone)]
#[cfg_attr(
feature = "serde",
derive(serde_derive::Deserialize, serde_derive::Serialize)
)]
pub struct AuthorizeWithSeedArgs {
pub new_authorized_pubkey: Pubkey,
pub stake_authorize: StakeAuthorize,
pub authority_seed: String,
pub authority_owner: Pubkey,
}
#[cfg_attr(
feature = "codama",
derive(CodamaType),
codama(name = "authorizeCheckedWithSeedParams")
)]
#[derive(Debug, PartialEq, Eq, Clone)]
#[cfg_attr(
feature = "serde",
derive(serde_derive::Deserialize, serde_derive::Serialize)
)]
pub struct AuthorizeCheckedWithSeedArgs {
pub stake_authorize: StakeAuthorize,
pub authority_seed: String,
pub authority_owner: Pubkey,
}
#[cfg(feature = "bincode")]
pub fn initialize(stake_pubkey: &Pubkey, authorized: &Authorized, lockup: &Lockup) -> Instruction {
Instruction::new_with_bincode(
ID,
&StakeInstruction::Initialize(*authorized, *lockup),
vec![
AccountMeta::new(*stake_pubkey, false),
AccountMeta::new_readonly(RENT_ID, false),
],
)
}
#[cfg(feature = "bincode")]
pub fn initialize_checked(stake_pubkey: &Pubkey, authorized: &Authorized) -> Instruction {
Instruction::new_with_bincode(
ID,
&StakeInstruction::InitializeChecked,
vec![
AccountMeta::new(*stake_pubkey, false),
AccountMeta::new_readonly(RENT_ID, false),
AccountMeta::new_readonly(authorized.staker, false),
AccountMeta::new_readonly(authorized.withdrawer, true),
],
)
}
#[cfg(feature = "bincode")]
pub fn create_account_with_seed(
from_pubkey: &Pubkey,
stake_pubkey: &Pubkey,
base: &Pubkey,
seed: &str,
authorized: &Authorized,
lockup: &Lockup,
lamports: u64,
) -> Vec<Instruction> {
vec![
solana_system_interface::instruction::create_account_with_seed(
from_pubkey,
stake_pubkey,
base,
seed,
lamports,
StakeStateV2::size_of() as u64,
&ID,
),
initialize(stake_pubkey, authorized, lockup),
]
}
#[cfg(feature = "bincode")]
pub fn create_account(
from_pubkey: &Pubkey,
stake_pubkey: &Pubkey,
authorized: &Authorized,
lockup: &Lockup,
lamports: u64,
) -> Vec<Instruction> {
vec![
solana_system_interface::instruction::create_account(
from_pubkey,
stake_pubkey,
lamports,
StakeStateV2::size_of() as u64,
&ID,
),
initialize(stake_pubkey, authorized, lockup),
]
}
#[cfg(feature = "bincode")]
pub fn create_account_with_seed_checked(
from_pubkey: &Pubkey,
stake_pubkey: &Pubkey,
base: &Pubkey,
seed: &str,
authorized: &Authorized,
lamports: u64,
) -> Vec<Instruction> {
vec![
solana_system_interface::instruction::create_account_with_seed(
from_pubkey,
stake_pubkey,
base,
seed,
lamports,
StakeStateV2::size_of() as u64,
&ID,
),
initialize_checked(stake_pubkey, authorized),
]
}
#[cfg(feature = "bincode")]
pub fn create_account_checked(
from_pubkey: &Pubkey,
stake_pubkey: &Pubkey,
authorized: &Authorized,
lamports: u64,
) -> Vec<Instruction> {
vec![
solana_system_interface::instruction::create_account(
from_pubkey,
stake_pubkey,
lamports,
StakeStateV2::size_of() as u64,
&ID,
),
initialize_checked(stake_pubkey, authorized),
]
}
#[cfg(feature = "bincode")]
fn _split(
stake_pubkey: &Pubkey,
authorized_pubkey: &Pubkey,
lamports: u64,
split_stake_pubkey: &Pubkey,
) -> Instruction {
let account_metas = vec![
AccountMeta::new(*stake_pubkey, false),
AccountMeta::new(*split_stake_pubkey, false),
AccountMeta::new_readonly(*authorized_pubkey, true),
];
Instruction::new_with_bincode(ID, &StakeInstruction::Split(lamports), account_metas)
}
#[cfg(feature = "bincode")]
pub fn split(
stake_pubkey: &Pubkey,
authorized_pubkey: &Pubkey,
lamports: u64,
split_stake_pubkey: &Pubkey,
) -> Vec<Instruction> {
vec![
solana_system_interface::instruction::allocate(
split_stake_pubkey,
StakeStateV2::size_of() as u64,
),
solana_system_interface::instruction::assign(split_stake_pubkey, &ID),
_split(
stake_pubkey,
authorized_pubkey,
lamports,
split_stake_pubkey,
),
]
}
#[cfg(feature = "bincode")]
pub fn split_with_seed(
stake_pubkey: &Pubkey,
authorized_pubkey: &Pubkey,
lamports: u64,
split_stake_pubkey: &Pubkey, base: &Pubkey, seed: &str, ) -> Vec<Instruction> {
vec![
solana_system_interface::instruction::allocate_with_seed(
split_stake_pubkey,
base,
seed,
StakeStateV2::size_of() as u64,
&ID,
),
_split(
stake_pubkey,
authorized_pubkey,
lamports,
split_stake_pubkey,
),
]
}
#[cfg(feature = "bincode")]
pub fn merge(
destination_stake_pubkey: &Pubkey,
source_stake_pubkey: &Pubkey,
authorized_pubkey: &Pubkey,
) -> Vec<Instruction> {
let account_metas = vec![
AccountMeta::new(*destination_stake_pubkey, false),
AccountMeta::new(*source_stake_pubkey, false),
AccountMeta::new_readonly(CLOCK_ID, false),
AccountMeta::new_readonly(STAKE_HISTORY_ID, false),
AccountMeta::new_readonly(*authorized_pubkey, true),
];
vec![Instruction::new_with_bincode(
ID,
&StakeInstruction::Merge,
account_metas,
)]
}
#[cfg(feature = "bincode")]
pub fn create_account_and_delegate_stake(
from_pubkey: &Pubkey,
stake_pubkey: &Pubkey,
vote_pubkey: &Pubkey,
authorized: &Authorized,
lockup: &Lockup,
lamports: u64,
) -> Vec<Instruction> {
let mut instructions = create_account(from_pubkey, stake_pubkey, authorized, lockup, lamports);
instructions.push(delegate_stake(
stake_pubkey,
&authorized.staker,
vote_pubkey,
));
instructions
}
#[cfg(feature = "bincode")]
#[allow(clippy::too_many_arguments)]
pub fn create_account_with_seed_and_delegate_stake(
from_pubkey: &Pubkey,
stake_pubkey: &Pubkey,
base: &Pubkey,
seed: &str,
vote_pubkey: &Pubkey,
authorized: &Authorized,
lockup: &Lockup,
lamports: u64,
) -> Vec<Instruction> {
let mut instructions = create_account_with_seed(
from_pubkey,
stake_pubkey,
base,
seed,
authorized,
lockup,
lamports,
);
instructions.push(delegate_stake(
stake_pubkey,
&authorized.staker,
vote_pubkey,
));
instructions
}
#[cfg(feature = "bincode")]
pub fn authorize(
stake_pubkey: &Pubkey,
authorized_pubkey: &Pubkey,
new_authorized_pubkey: &Pubkey,
stake_authorize: StakeAuthorize,
custodian_pubkey: Option<&Pubkey>,
) -> Instruction {
let mut account_metas = vec![
AccountMeta::new(*stake_pubkey, false),
AccountMeta::new_readonly(CLOCK_ID, false),
AccountMeta::new_readonly(*authorized_pubkey, true),
];
if let Some(custodian_pubkey) = custodian_pubkey {
account_metas.push(AccountMeta::new_readonly(*custodian_pubkey, true));
}
Instruction::new_with_bincode(
ID,
&StakeInstruction::Authorize(*new_authorized_pubkey, stake_authorize),
account_metas,
)
}
#[cfg(feature = "bincode")]
pub fn authorize_checked(
stake_pubkey: &Pubkey,
authorized_pubkey: &Pubkey,
new_authorized_pubkey: &Pubkey,
stake_authorize: StakeAuthorize,
custodian_pubkey: Option<&Pubkey>,
) -> Instruction {
let mut account_metas = vec![
AccountMeta::new(*stake_pubkey, false),
AccountMeta::new_readonly(CLOCK_ID, false),
AccountMeta::new_readonly(*authorized_pubkey, true),
AccountMeta::new_readonly(*new_authorized_pubkey, true),
];
if let Some(custodian_pubkey) = custodian_pubkey {
account_metas.push(AccountMeta::new_readonly(*custodian_pubkey, true));
}
Instruction::new_with_bincode(
ID,
&StakeInstruction::AuthorizeChecked(stake_authorize),
account_metas,
)
}
#[cfg(feature = "bincode")]
pub fn authorize_with_seed(
stake_pubkey: &Pubkey,
authority_base: &Pubkey,
authority_seed: String,
authority_owner: &Pubkey,
new_authorized_pubkey: &Pubkey,
stake_authorize: StakeAuthorize,
custodian_pubkey: Option<&Pubkey>,
) -> Instruction {
let mut account_metas = vec![
AccountMeta::new(*stake_pubkey, false),
AccountMeta::new_readonly(*authority_base, true),
AccountMeta::new_readonly(CLOCK_ID, false),
];
if let Some(custodian_pubkey) = custodian_pubkey {
account_metas.push(AccountMeta::new_readonly(*custodian_pubkey, true));
}
let args = AuthorizeWithSeedArgs {
new_authorized_pubkey: *new_authorized_pubkey,
stake_authorize,
authority_seed,
authority_owner: *authority_owner,
};
Instruction::new_with_bincode(
ID,
&StakeInstruction::AuthorizeWithSeed(args),
account_metas,
)
}
#[cfg(feature = "bincode")]
pub fn authorize_checked_with_seed(
stake_pubkey: &Pubkey,
authority_base: &Pubkey,
authority_seed: String,
authority_owner: &Pubkey,
new_authorized_pubkey: &Pubkey,
stake_authorize: StakeAuthorize,
custodian_pubkey: Option<&Pubkey>,
) -> Instruction {
let mut account_metas = vec![
AccountMeta::new(*stake_pubkey, false),
AccountMeta::new_readonly(*authority_base, true),
AccountMeta::new_readonly(CLOCK_ID, false),
AccountMeta::new_readonly(*new_authorized_pubkey, true),
];
if let Some(custodian_pubkey) = custodian_pubkey {
account_metas.push(AccountMeta::new_readonly(*custodian_pubkey, true));
}
let args = AuthorizeCheckedWithSeedArgs {
stake_authorize,
authority_seed,
authority_owner: *authority_owner,
};
Instruction::new_with_bincode(
ID,
&StakeInstruction::AuthorizeCheckedWithSeed(args),
account_metas,
)
}
#[cfg(feature = "bincode")]
pub fn delegate_stake(
stake_pubkey: &Pubkey,
authorized_pubkey: &Pubkey,
vote_pubkey: &Pubkey,
) -> Instruction {
let account_metas = vec![
AccountMeta::new(*stake_pubkey, false),
AccountMeta::new_readonly(*vote_pubkey, false),
AccountMeta::new_readonly(CLOCK_ID, false),
AccountMeta::new_readonly(STAKE_HISTORY_ID, false),
AccountMeta::new_readonly(config::ID, false),
AccountMeta::new_readonly(*authorized_pubkey, true),
];
Instruction::new_with_bincode(ID, &StakeInstruction::DelegateStake, account_metas)
}
#[cfg(feature = "bincode")]
pub fn withdraw(
stake_pubkey: &Pubkey,
withdrawer_pubkey: &Pubkey,
to_pubkey: &Pubkey,
lamports: u64,
custodian_pubkey: Option<&Pubkey>,
) -> Instruction {
let mut account_metas = vec![
AccountMeta::new(*stake_pubkey, false),
AccountMeta::new(*to_pubkey, false),
AccountMeta::new_readonly(CLOCK_ID, false),
AccountMeta::new_readonly(STAKE_HISTORY_ID, false),
AccountMeta::new_readonly(*withdrawer_pubkey, true),
];
if let Some(custodian_pubkey) = custodian_pubkey {
account_metas.push(AccountMeta::new_readonly(*custodian_pubkey, true));
}
Instruction::new_with_bincode(ID, &StakeInstruction::Withdraw(lamports), account_metas)
}
#[cfg(feature = "bincode")]
pub fn deactivate_stake(stake_pubkey: &Pubkey, authorized_pubkey: &Pubkey) -> Instruction {
let account_metas = vec![
AccountMeta::new(*stake_pubkey, false),
AccountMeta::new_readonly(CLOCK_ID, false),
AccountMeta::new_readonly(*authorized_pubkey, true),
];
Instruction::new_with_bincode(ID, &StakeInstruction::Deactivate, account_metas)
}
#[cfg(feature = "bincode")]
pub fn set_lockup(
stake_pubkey: &Pubkey,
lockup: &LockupArgs,
custodian_pubkey: &Pubkey,
) -> Instruction {
let account_metas = vec![
AccountMeta::new(*stake_pubkey, false),
AccountMeta::new_readonly(*custodian_pubkey, true),
];
Instruction::new_with_bincode(ID, &StakeInstruction::SetLockup(*lockup), account_metas)
}
#[cfg(feature = "bincode")]
pub fn set_lockup_checked(
stake_pubkey: &Pubkey,
lockup: &LockupArgs,
custodian_pubkey: &Pubkey,
) -> Instruction {
let mut account_metas = vec![
AccountMeta::new(*stake_pubkey, false),
AccountMeta::new_readonly(*custodian_pubkey, true),
];
let lockup_checked = LockupCheckedArgs {
unix_timestamp: lockup.unix_timestamp,
epoch: lockup.epoch,
};
if let Some(new_custodian) = lockup.custodian {
account_metas.push(AccountMeta::new_readonly(new_custodian, true));
}
Instruction::new_with_bincode(
ID,
&StakeInstruction::SetLockupChecked(lockup_checked),
account_metas,
)
}
#[cfg(feature = "bincode")]
pub fn get_minimum_delegation() -> Instruction {
Instruction::new_with_bincode(ID, &StakeInstruction::GetMinimumDelegation, Vec::default())
}
#[cfg(feature = "bincode")]
pub fn deactivate_delinquent_stake(
stake_account: &Pubkey,
delinquent_vote_account: &Pubkey,
reference_vote_account: &Pubkey,
) -> Instruction {
let account_metas = vec![
AccountMeta::new(*stake_account, false),
AccountMeta::new_readonly(*delinquent_vote_account, false),
AccountMeta::new_readonly(*reference_vote_account, false),
];
Instruction::new_with_bincode(ID, &StakeInstruction::DeactivateDelinquent, account_metas)
}
#[cfg(feature = "bincode")]
fn _redelegate(
stake_pubkey: &Pubkey,
authorized_pubkey: &Pubkey,
vote_pubkey: &Pubkey,
uninitialized_stake_pubkey: &Pubkey,
) -> Instruction {
let account_metas = vec![
AccountMeta::new(*stake_pubkey, false),
AccountMeta::new(*uninitialized_stake_pubkey, false),
AccountMeta::new_readonly(*vote_pubkey, false),
AccountMeta::new_readonly(config::ID, false),
AccountMeta::new_readonly(*authorized_pubkey, true),
];
Instruction::new_with_bincode(ID, &StakeInstruction::Redelegate, account_metas)
}
#[cfg(feature = "bincode")]
#[deprecated(since = "2.1.0", note = "Redelegate will not be enabled")]
pub fn redelegate(
stake_pubkey: &Pubkey,
authorized_pubkey: &Pubkey,
vote_pubkey: &Pubkey,
uninitialized_stake_pubkey: &Pubkey,
) -> Vec<Instruction> {
vec![
solana_system_interface::instruction::allocate(
uninitialized_stake_pubkey,
StakeStateV2::size_of() as u64,
),
solana_system_interface::instruction::assign(uninitialized_stake_pubkey, &ID),
_redelegate(
stake_pubkey,
authorized_pubkey,
vote_pubkey,
uninitialized_stake_pubkey,
),
]
}
#[cfg(feature = "bincode")]
#[deprecated(since = "2.1.0", note = "Redelegate will not be enabled")]
pub fn redelegate_with_seed(
stake_pubkey: &Pubkey,
authorized_pubkey: &Pubkey,
vote_pubkey: &Pubkey,
uninitialized_stake_pubkey: &Pubkey, base: &Pubkey, seed: &str, ) -> Vec<Instruction> {
vec![
solana_system_interface::instruction::allocate_with_seed(
uninitialized_stake_pubkey,
base,
seed,
StakeStateV2::size_of() as u64,
&ID,
),
_redelegate(
stake_pubkey,
authorized_pubkey,
vote_pubkey,
uninitialized_stake_pubkey,
),
]
}
#[cfg(feature = "bincode")]
pub fn move_stake(
source_stake_pubkey: &Pubkey,
destination_stake_pubkey: &Pubkey,
authorized_pubkey: &Pubkey,
lamports: u64,
) -> Instruction {
let account_metas = vec![
AccountMeta::new(*source_stake_pubkey, false),
AccountMeta::new(*destination_stake_pubkey, false),
AccountMeta::new_readonly(*authorized_pubkey, true),
];
Instruction::new_with_bincode(ID, &StakeInstruction::MoveStake(lamports), account_metas)
}
#[cfg(feature = "bincode")]
pub fn move_lamports(
source_stake_pubkey: &Pubkey,
destination_stake_pubkey: &Pubkey,
authorized_pubkey: &Pubkey,
lamports: u64,
) -> Instruction {
let account_metas = vec![
AccountMeta::new(*source_stake_pubkey, false),
AccountMeta::new(*destination_stake_pubkey, false),
AccountMeta::new_readonly(*authorized_pubkey, true),
];
Instruction::new_with_bincode(ID, &StakeInstruction::MoveLamports(lamports), account_metas)
}
#[cfg(feature = "bincode")]
#[cfg(test)]
mod tests {
use super::*;
#[allow(deprecated)]
#[test]
fn test_constants() {
assert_eq!(CLOCK_ID, solana_sdk_ids::sysvar::clock::ID);
assert_eq!(STAKE_HISTORY_ID, solana_sdk_ids::sysvar::stake_history::ID);
assert_eq!(RENT_ID, solana_sdk_ids::sysvar::rent::ID);
}
}