#![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::{program::ID, state::StakeStateV2},
solana_instruction::{AccountMeta, Instruction},
};
#[cfg_attr(
feature = "serde",
derive(serde_derive::Deserialize, serde_derive::Serialize)
)]
#[cfg_attr(feature = "codama", derive(CodamaInstructions))]
#[cfg_attr(feature = "codama", codama(enum_discriminator(size = number(u32))))]
#[cfg_attr(feature = "codama", codama(optional_account_strategy = omitted))]
#[derive(Debug, PartialEq, Eq, Clone)]
pub enum StakeInstruction {
#[cfg_attr(
feature = "codama",
codama(display(
intent = "Initialize stake account",
interpolated_intent = "Initialize stake account ${accounts.stake}"
)),
codama(account(
name = "stake",
writable,
docs = "Uninitialized stake account",
display(label = "Stake Account")
))
)]
Initialize(
#[cfg_attr(feature = "codama", codama(display(flatten = true)))] Authorized,
#[cfg_attr(feature = "codama", codama(display(flatten = true)))] Lockup,
),
#[cfg_attr(
feature = "codama",
codama(display(
intent = "Update stake authority",
interpolated_intent = "Set the ${data.arg1} authority of ${accounts.stake} to ${data.arg0}"
)),
codama(account(
name = "stake",
writable,
docs = "Stake account to be updated",
display(label = "Stake Account")
)),
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(
#[cfg_attr(feature = "codama", codama(display(label = "New Authority")))] Pubkey,
#[cfg_attr(feature = "codama", codama(display(label = "Authority Type")))] StakeAuthorize,
),
#[cfg_attr(
feature = "codama",
codama(display(
intent = "Delegate stake",
interpolated_intent = "Delegate ${accounts.stake} to vote account ${accounts.vote}"
)),
codama(account(
name = "stake",
writable,
docs = "Initialized stake account to be delegated",
display(label = "Stake Account")
)),
codama(account(
name = "vote",
docs = "Vote account to which this stake will be delegated",
display(label = "Vote Account")
)),
codama(account(name = "stake_authority", signer, docs = "Stake authority"))
)]
DelegateStake,
#[cfg_attr(
feature = "codama",
codama(display(
intent = "Split stake",
interpolated_intent = "Split ${data.args} from ${accounts.stake} into ${accounts.splitStake}"
)),
codama(account(
name = "stake",
writable,
docs = "Stake account to be split; must be in the Initialized or Stake state",
display(label = "Stake Account")
)),
codama(account(
name = "split_stake",
writable,
docs = "Uninitialized stake account that will take the split-off amount",
display(label = "New Stake Account")
)),
codama(account(name = "stake_authority", signer, docs = "Stake authority"))
)]
Split(
#[cfg_attr(
feature = "codama",
codama(name = "args"),
codama(display(label = "Amount", amount(decimals = 9, unit = "SOL")))
)]
u64,
),
#[cfg_attr(
feature = "codama",
codama(display(
intent = "Withdraw stake",
interpolated_intent = "Withdraw ${data.args} from ${accounts.stake} to ${accounts.recipient}"
)),
codama(account(
name = "stake",
writable,
docs = "Stake account from which to withdraw",
display(label = "Stake Account")
)),
codama(account(name = "recipient", writable, docs = "Recipient account")),
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"),
codama(display(label = "Amount", amount(decimals = 9, unit = "SOL")))
)]
u64,
),
#[cfg_attr(
feature = "codama",
codama(display(
intent = "Deactivate stake",
interpolated_intent = "Deactivate ${accounts.stake}"
)),
codama(account(
name = "stake",
writable,
docs = "Delegated stake account to be deactivated",
display(label = "Stake Account")
)),
codama(account(name = "stake_authority", signer, docs = "Stake authority"))
)]
Deactivate,
#[cfg_attr(
feature = "codama",
codama(display(
intent = "Set stake lockup",
interpolated_intent = "Update the lockup of ${accounts.stake}"
)),
codama(account(
name = "stake",
writable,
docs = "Initialized stake account",
display(label = "Stake Account")
)),
codama(account(
name = "authority",
signer,
docs = "Lockup authority or withdraw authority"
))
)]
SetLockup(
#[cfg_attr(
feature = "codama",
codama(type = link("lockupParams")),
codama(display(flatten = true))
)]
LockupArgs,
),
#[cfg_attr(
feature = "codama",
codama(display(
intent = "Merge stake accounts",
interpolated_intent = "Merge ${accounts.sourceStake} into ${accounts.destinationStake}"
)),
codama(account(
name = "destination_stake",
writable,
docs = "Destination stake account for the merge",
display(label = "To")
)),
codama(account(
name = "source_stake",
writable,
docs = "Source stake account for to merge. This account will be drained",
display(label = "From")
)),
codama(account(name = "stake_authority", signer, docs = "Stake authority"))
)]
Merge,
#[cfg_attr(
feature = "codama",
codama(display(
intent = "Update stake authority",
interpolated_intent = "Change an authority of ${accounts.stake}"
)),
codama(account(
name = "stake",
writable,
docs = "Stake account to be updated",
display(label = "Stake Account")
)),
codama(account(
name = "base",
signer,
docs = "Base key of stake or withdraw authority",
display(label = "Base Key")
)),
codama(account(
name = "lockup_authority",
optional,
signer,
docs = "Lockup authority, if updating `StakeAuthorize::Withdrawer` before lockup expiration"
))
)]
AuthorizeWithSeed(
#[cfg_attr(
feature = "codama",
codama(type = link("authorizeWithSeedParams")),
codama(display(flatten = true))
)]
AuthorizeWithSeedArgs,
),
#[cfg_attr(
feature = "codama",
codama(display(
intent = "Initialize stake account",
interpolated_intent = "Initialize stake account ${accounts.stake}"
)),
codama(account(
name = "stake",
writable,
docs = "Uninitialized stake account",
display(label = "Stake Account")
)),
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(display(
intent = "Update stake authority",
interpolated_intent = "Set the ${data.stakeAuthorize} authority of ${accounts.stake} to ${accounts.newAuthority}"
)),
codama(account(
name = "stake",
writable,
docs = "Stake account to be updated",
display(label = "Stake Account")
)),
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"),
codama(display(label = "Authority Type"))
)]
StakeAuthorize,
),
#[cfg_attr(
feature = "codama",
codama(display(
intent = "Update stake authority",
interpolated_intent = "Set an authority of ${accounts.stake} to ${accounts.newAuthority}"
)),
codama(account(
name = "stake",
writable,
docs = "Stake account to be updated",
display(label = "Stake Account")
)),
codama(account(
name = "base",
signer,
docs = "Base key of stake or withdraw authority",
display(label = "Base Key")
)),
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(
#[cfg_attr(
feature = "codama",
codama(type = link("authorizeCheckedWithSeedParams")),
codama(display(flatten = true))
)]
AuthorizeCheckedWithSeedArgs,
),
#[cfg_attr(
feature = "codama",
codama(display(
intent = "Set stake lockup",
interpolated_intent = "Update the lockup of ${accounts.stake}"
)),
codama(account(
name = "stake",
writable,
docs = "Initialized stake account",
display(label = "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(
#[cfg_attr(
feature = "codama",
codama(type = link("lockupCheckedParams")),
codama(display(flatten = true))
)]
LockupCheckedArgs,
),
#[cfg_attr(
feature = "codama",
codama(display(intent = "Get minimum stake delegation"))
)]
GetMinimumDelegation,
#[cfg_attr(
feature = "codama",
codama(display(
intent = "Deactivate delinquent stake",
interpolated_intent = "Deactivate delinquent stake ${accounts.stake}"
)),
codama(account(
name = "stake",
writable,
docs = "Delegated stake account",
display(label = "Stake Account")
)),
codama(account(
name = "delinquent_vote",
docs = "Delinquent vote account for the delegated stake account",
display(label = "Delinquent Vote 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",
display(label = "Reference Vote Account")
))
)]
DeactivateDelinquent,
#[deprecated(since = "2.1.0", note = "Redelegate will not be enabled")]
Redelegate,
#[cfg_attr(
feature = "codama",
codama(display(
intent = "Move stake",
interpolated_intent = "Move ${data.args} of active stake from ${accounts.sourceStake} to ${accounts.destinationStake}"
)),
codama(account(
name = "sourceStake",
writable,
docs = "Active source stake account",
display(label = "From")
)),
codama(account(
name = "destinationStake",
writable,
docs = "Active or inactive destination stake account",
display(label = "To")
)),
codama(account(name = "stake_authority", signer, docs = "Stake authority"))
)]
MoveStake(
#[cfg_attr(
feature = "codama",
codama(name = "args"),
codama(display(label = "Amount", amount(decimals = 9, unit = "SOL")))
)]
u64,
),
#[cfg_attr(
feature = "codama",
codama(display(
intent = "Move unstaked SOL",
interpolated_intent = "Move ${data.args} from ${accounts.sourceStake} to ${accounts.destinationStake}"
)),
codama(account(
name = "source_stake",
writable,
docs = "Active or inactive source stake account",
display(label = "From")
)),
codama(account(
name = "destination_stake",
writable,
docs = "Mergeable destination stake account",
display(label = "To")
)),
codama(account(name = "stake_authority", signer, docs = "Stake authority"))
)]
MoveLamports(
#[cfg_attr(
feature = "codama",
codama(name = "args"),
codama(display(label = "Amount", amount(decimals = 9, unit = "SOL")))
)]
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 {
#[cfg_attr(feature = "codama", codama(display(label = "Locked Until")))]
pub unix_timestamp: Option<UnixTimestamp>,
#[cfg_attr(feature = "codama", codama(display(label = "Locked Until Epoch")))]
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 {
#[cfg_attr(feature = "codama", codama(display(label = "Locked Until")))]
pub unix_timestamp: Option<UnixTimestamp>,
#[cfg_attr(feature = "codama", codama(display(label = "Locked Until Epoch")))]
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 {
#[cfg_attr(feature = "codama", codama(display(label = "New Authority")))]
pub new_authorized_pubkey: Pubkey,
#[cfg_attr(feature = "codama", codama(display(label = "Authority Type")))]
pub stake_authorize: StakeAuthorize,
#[cfg_attr(feature = "codama", codama(size_prefix = number(u64)))]
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 {
#[cfg_attr(feature = "codama", codama(display(label = "Authority Type")))]
pub stake_authorize: StakeAuthorize,
#[cfg_attr(feature = "codama", codama(size_prefix = number(u64)))]
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)],
)
}
#[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(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(*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(*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(*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),
];
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(*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(*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(*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(*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(*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)
}