use crate::borsh_ext::BorshSerializeExt;
use borsh::BorshDeserialize;
use borsh::BorshSerialize;
pub struct SwapYieldBearingToStableTokenAmount {
pub user_wallet: solana_program::pubkey::Pubkey,
pub yield_bearing_token_account: solana_program::pubkey::Pubkey,
pub stable_token_account: solana_program::pubkey::Pubkey,
pub yield_bearing_bond_account: solana_program::pubkey::Pubkey,
pub stable_bond_account: solana_program::pubkey::Pubkey,
pub yield_bearing_mint_account: solana_program::pubkey::Pubkey,
pub stable_mint_account: solana_program::pubkey::Pubkey,
pub token2022_program: solana_program::pubkey::Pubkey,
pub associated_token_program: solana_program::pubkey::Pubkey,
pub system_program: solana_program::pubkey::Pubkey,
pub mint_auth_multisig_account: Option<solana_program::pubkey::Pubkey>,
}
impl SwapYieldBearingToStableTokenAmount {
pub fn instruction(
&self,
args: SwapYieldBearingToStableTokenAmountInstructionArgs,
) -> solana_program::instruction::Instruction {
self.instruction_with_remaining_accounts(args, &[])
}
#[allow(clippy::vec_init_then_push)]
pub fn instruction_with_remaining_accounts(
&self,
args: SwapYieldBearingToStableTokenAmountInstructionArgs,
remaining_accounts: &[solana_program::instruction::AccountMeta],
) -> solana_program::instruction::Instruction {
let mut accounts = Vec::with_capacity(11 + remaining_accounts.len());
accounts.push(solana_program::instruction::AccountMeta::new(
self.user_wallet,
true,
));
accounts.push(solana_program::instruction::AccountMeta::new(
self.yield_bearing_token_account,
false,
));
accounts.push(solana_program::instruction::AccountMeta::new(
self.stable_token_account,
false,
));
accounts.push(solana_program::instruction::AccountMeta::new_readonly(
self.yield_bearing_bond_account,
false,
));
accounts.push(solana_program::instruction::AccountMeta::new_readonly(
self.stable_bond_account,
false,
));
accounts.push(solana_program::instruction::AccountMeta::new(
self.yield_bearing_mint_account,
false,
));
accounts.push(solana_program::instruction::AccountMeta::new(
self.stable_mint_account,
false,
));
accounts.push(solana_program::instruction::AccountMeta::new_readonly(
self.token2022_program,
false,
));
accounts.push(solana_program::instruction::AccountMeta::new_readonly(
self.associated_token_program,
false,
));
accounts.push(solana_program::instruction::AccountMeta::new_readonly(
self.system_program,
false,
));
if let Some(mint_auth_multisig_account) = self.mint_auth_multisig_account {
accounts.push(solana_program::instruction::AccountMeta::new_readonly(
mint_auth_multisig_account,
false,
));
} else {
accounts.push(solana_program::instruction::AccountMeta::new_readonly(
crate::STABLEBOND_ID,
false,
));
}
accounts.extend_from_slice(remaining_accounts);
let mut data = SwapYieldBearingToStableTokenAmountInstructionData::new()
.try_to_vec()
.unwrap();
let mut args = args.try_to_vec().unwrap();
data.append(&mut args);
solana_program::instruction::Instruction {
program_id: crate::STABLEBOND_ID,
accounts,
data,
}
}
}
#[derive(BorshDeserialize, BorshSerialize)]
struct SwapYieldBearingToStableTokenAmountInstructionData {
discriminator: u8,
}
impl SwapYieldBearingToStableTokenAmountInstructionData {
fn new() -> Self {
Self { discriminator: 42 }
}
}
#[derive(BorshSerialize, BorshDeserialize, Clone, Debug, Eq, PartialEq)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct SwapYieldBearingToStableTokenAmountInstructionArgs {
pub amount: u64,
}
#[derive(Default)]
pub struct SwapYieldBearingToStableTokenAmountBuilder {
user_wallet: Option<solana_program::pubkey::Pubkey>,
yield_bearing_token_account: Option<solana_program::pubkey::Pubkey>,
stable_token_account: Option<solana_program::pubkey::Pubkey>,
yield_bearing_bond_account: Option<solana_program::pubkey::Pubkey>,
stable_bond_account: Option<solana_program::pubkey::Pubkey>,
yield_bearing_mint_account: Option<solana_program::pubkey::Pubkey>,
stable_mint_account: Option<solana_program::pubkey::Pubkey>,
token2022_program: Option<solana_program::pubkey::Pubkey>,
associated_token_program: Option<solana_program::pubkey::Pubkey>,
system_program: Option<solana_program::pubkey::Pubkey>,
mint_auth_multisig_account: Option<solana_program::pubkey::Pubkey>,
amount: Option<u64>,
__remaining_accounts: Vec<solana_program::instruction::AccountMeta>,
}
impl SwapYieldBearingToStableTokenAmountBuilder {
pub fn new() -> Self {
Self::default()
}
#[inline(always)]
pub fn user_wallet(&mut self, user_wallet: solana_program::pubkey::Pubkey) -> &mut Self {
self.user_wallet = Some(user_wallet);
self
}
#[inline(always)]
pub fn yield_bearing_token_account(
&mut self,
yield_bearing_token_account: solana_program::pubkey::Pubkey,
) -> &mut Self {
self.yield_bearing_token_account = Some(yield_bearing_token_account);
self
}
#[inline(always)]
pub fn stable_token_account(
&mut self,
stable_token_account: solana_program::pubkey::Pubkey,
) -> &mut Self {
self.stable_token_account = Some(stable_token_account);
self
}
#[inline(always)]
pub fn yield_bearing_bond_account(
&mut self,
yield_bearing_bond_account: solana_program::pubkey::Pubkey,
) -> &mut Self {
self.yield_bearing_bond_account = Some(yield_bearing_bond_account);
self
}
#[inline(always)]
pub fn stable_bond_account(
&mut self,
stable_bond_account: solana_program::pubkey::Pubkey,
) -> &mut Self {
self.stable_bond_account = Some(stable_bond_account);
self
}
#[inline(always)]
pub fn yield_bearing_mint_account(
&mut self,
yield_bearing_mint_account: solana_program::pubkey::Pubkey,
) -> &mut Self {
self.yield_bearing_mint_account = Some(yield_bearing_mint_account);
self
}
#[inline(always)]
pub fn stable_mint_account(
&mut self,
stable_mint_account: solana_program::pubkey::Pubkey,
) -> &mut Self {
self.stable_mint_account = Some(stable_mint_account);
self
}
#[inline(always)]
pub fn token2022_program(
&mut self,
token2022_program: solana_program::pubkey::Pubkey,
) -> &mut Self {
self.token2022_program = Some(token2022_program);
self
}
#[inline(always)]
pub fn associated_token_program(
&mut self,
associated_token_program: solana_program::pubkey::Pubkey,
) -> &mut Self {
self.associated_token_program = Some(associated_token_program);
self
}
#[inline(always)]
pub fn system_program(&mut self, system_program: solana_program::pubkey::Pubkey) -> &mut Self {
self.system_program = Some(system_program);
self
}
#[inline(always)]
pub fn mint_auth_multisig_account(
&mut self,
mint_auth_multisig_account: Option<solana_program::pubkey::Pubkey>,
) -> &mut Self {
self.mint_auth_multisig_account = mint_auth_multisig_account;
self
}
#[inline(always)]
pub fn amount(&mut self, amount: u64) -> &mut Self {
self.amount = Some(amount);
self
}
#[inline(always)]
pub fn add_remaining_account(
&mut self,
account: solana_program::instruction::AccountMeta,
) -> &mut Self {
self.__remaining_accounts.push(account);
self
}
#[inline(always)]
pub fn add_remaining_accounts(
&mut self,
accounts: &[solana_program::instruction::AccountMeta],
) -> &mut Self {
self.__remaining_accounts.extend_from_slice(accounts);
self
}
#[allow(clippy::clone_on_copy)]
pub fn instruction(&self) -> solana_program::instruction::Instruction {
let accounts = SwapYieldBearingToStableTokenAmount {
user_wallet: self.user_wallet.expect("user_wallet is not set"),
yield_bearing_token_account: self
.yield_bearing_token_account
.expect("yield_bearing_token_account is not set"),
stable_token_account: self
.stable_token_account
.expect("stable_token_account is not set"),
yield_bearing_bond_account: self
.yield_bearing_bond_account
.expect("yield_bearing_bond_account is not set"),
stable_bond_account: self
.stable_bond_account
.expect("stable_bond_account is not set"),
yield_bearing_mint_account: self
.yield_bearing_mint_account
.expect("yield_bearing_mint_account is not set"),
stable_mint_account: self
.stable_mint_account
.expect("stable_mint_account is not set"),
token2022_program: self
.token2022_program
.expect("token2022_program is not set"),
associated_token_program: self
.associated_token_program
.expect("associated_token_program is not set"),
system_program: self
.system_program
.unwrap_or(solana_program::pubkey!("11111111111111111111111111111111")),
mint_auth_multisig_account: self.mint_auth_multisig_account,
};
let args = SwapYieldBearingToStableTokenAmountInstructionArgs {
amount: self.amount.clone().expect("amount is not set"),
};
accounts.instruction_with_remaining_accounts(args, &self.__remaining_accounts)
}
}
pub struct SwapYieldBearingToStableTokenAmountCpiAccounts<'a, 'b> {
pub user_wallet: &'b solana_program::account_info::AccountInfo<'a>,
pub yield_bearing_token_account: &'b solana_program::account_info::AccountInfo<'a>,
pub stable_token_account: &'b solana_program::account_info::AccountInfo<'a>,
pub yield_bearing_bond_account: &'b solana_program::account_info::AccountInfo<'a>,
pub stable_bond_account: &'b solana_program::account_info::AccountInfo<'a>,
pub yield_bearing_mint_account: &'b solana_program::account_info::AccountInfo<'a>,
pub stable_mint_account: &'b solana_program::account_info::AccountInfo<'a>,
pub token2022_program: &'b solana_program::account_info::AccountInfo<'a>,
pub associated_token_program: &'b solana_program::account_info::AccountInfo<'a>,
pub system_program: &'b solana_program::account_info::AccountInfo<'a>,
pub mint_auth_multisig_account: Option<&'b solana_program::account_info::AccountInfo<'a>>,
}
pub struct SwapYieldBearingToStableTokenAmountCpi<'a, 'b> {
pub __program: &'b solana_program::account_info::AccountInfo<'a>,
pub user_wallet: &'b solana_program::account_info::AccountInfo<'a>,
pub yield_bearing_token_account: &'b solana_program::account_info::AccountInfo<'a>,
pub stable_token_account: &'b solana_program::account_info::AccountInfo<'a>,
pub yield_bearing_bond_account: &'b solana_program::account_info::AccountInfo<'a>,
pub stable_bond_account: &'b solana_program::account_info::AccountInfo<'a>,
pub yield_bearing_mint_account: &'b solana_program::account_info::AccountInfo<'a>,
pub stable_mint_account: &'b solana_program::account_info::AccountInfo<'a>,
pub token2022_program: &'b solana_program::account_info::AccountInfo<'a>,
pub associated_token_program: &'b solana_program::account_info::AccountInfo<'a>,
pub system_program: &'b solana_program::account_info::AccountInfo<'a>,
pub mint_auth_multisig_account: Option<&'b solana_program::account_info::AccountInfo<'a>>,
pub __args: SwapYieldBearingToStableTokenAmountInstructionArgs,
}
impl<'a, 'b> SwapYieldBearingToStableTokenAmountCpi<'a, 'b> {
pub fn new(
program: &'b solana_program::account_info::AccountInfo<'a>,
accounts: SwapYieldBearingToStableTokenAmountCpiAccounts<'a, 'b>,
args: SwapYieldBearingToStableTokenAmountInstructionArgs,
) -> Self {
Self {
__program: program,
user_wallet: accounts.user_wallet,
yield_bearing_token_account: accounts.yield_bearing_token_account,
stable_token_account: accounts.stable_token_account,
yield_bearing_bond_account: accounts.yield_bearing_bond_account,
stable_bond_account: accounts.stable_bond_account,
yield_bearing_mint_account: accounts.yield_bearing_mint_account,
stable_mint_account: accounts.stable_mint_account,
token2022_program: accounts.token2022_program,
associated_token_program: accounts.associated_token_program,
system_program: accounts.system_program,
mint_auth_multisig_account: accounts.mint_auth_multisig_account,
__args: args,
}
}
#[inline(always)]
pub fn invoke(&self) -> solana_program::entrypoint::ProgramResult {
self.invoke_signed_with_remaining_accounts(&[], &[])
}
#[inline(always)]
pub fn invoke_with_remaining_accounts(
&self,
remaining_accounts: &[(
&'b solana_program::account_info::AccountInfo<'a>,
bool,
bool,
)],
) -> solana_program::entrypoint::ProgramResult {
self.invoke_signed_with_remaining_accounts(&[], remaining_accounts)
}
#[inline(always)]
pub fn invoke_signed(
&self,
signers_seeds: &[&[&[u8]]],
) -> solana_program::entrypoint::ProgramResult {
self.invoke_signed_with_remaining_accounts(signers_seeds, &[])
}
#[allow(clippy::clone_on_copy)]
#[allow(clippy::vec_init_then_push)]
pub fn invoke_signed_with_remaining_accounts(
&self,
signers_seeds: &[&[&[u8]]],
remaining_accounts: &[(
&'b solana_program::account_info::AccountInfo<'a>,
bool,
bool,
)],
) -> solana_program::entrypoint::ProgramResult {
let mut accounts = Vec::with_capacity(11 + remaining_accounts.len());
accounts.push(solana_program::instruction::AccountMeta::new(
*self.user_wallet.key,
true,
));
accounts.push(solana_program::instruction::AccountMeta::new(
*self.yield_bearing_token_account.key,
false,
));
accounts.push(solana_program::instruction::AccountMeta::new(
*self.stable_token_account.key,
false,
));
accounts.push(solana_program::instruction::AccountMeta::new_readonly(
*self.yield_bearing_bond_account.key,
false,
));
accounts.push(solana_program::instruction::AccountMeta::new_readonly(
*self.stable_bond_account.key,
false,
));
accounts.push(solana_program::instruction::AccountMeta::new(
*self.yield_bearing_mint_account.key,
false,
));
accounts.push(solana_program::instruction::AccountMeta::new(
*self.stable_mint_account.key,
false,
));
accounts.push(solana_program::instruction::AccountMeta::new_readonly(
*self.token2022_program.key,
false,
));
accounts.push(solana_program::instruction::AccountMeta::new_readonly(
*self.associated_token_program.key,
false,
));
accounts.push(solana_program::instruction::AccountMeta::new_readonly(
*self.system_program.key,
false,
));
if let Some(mint_auth_multisig_account) = self.mint_auth_multisig_account {
accounts.push(solana_program::instruction::AccountMeta::new_readonly(
*mint_auth_multisig_account.key,
false,
));
} else {
accounts.push(solana_program::instruction::AccountMeta::new_readonly(
crate::STABLEBOND_ID,
false,
));
}
remaining_accounts.iter().for_each(|remaining_account| {
accounts.push(solana_program::instruction::AccountMeta {
pubkey: *remaining_account.0.key,
is_signer: remaining_account.1,
is_writable: remaining_account.2,
})
});
let mut data = SwapYieldBearingToStableTokenAmountInstructionData::new()
.try_to_vec()
.unwrap();
let mut args = self.__args.try_to_vec().unwrap();
data.append(&mut args);
let instruction = solana_program::instruction::Instruction {
program_id: crate::STABLEBOND_ID,
accounts,
data,
};
let mut account_infos = Vec::with_capacity(11 + 1 + remaining_accounts.len());
account_infos.push(self.__program.clone());
account_infos.push(self.user_wallet.clone());
account_infos.push(self.yield_bearing_token_account.clone());
account_infos.push(self.stable_token_account.clone());
account_infos.push(self.yield_bearing_bond_account.clone());
account_infos.push(self.stable_bond_account.clone());
account_infos.push(self.yield_bearing_mint_account.clone());
account_infos.push(self.stable_mint_account.clone());
account_infos.push(self.token2022_program.clone());
account_infos.push(self.associated_token_program.clone());
account_infos.push(self.system_program.clone());
if let Some(mint_auth_multisig_account) = self.mint_auth_multisig_account {
account_infos.push(mint_auth_multisig_account.clone());
}
remaining_accounts
.iter()
.for_each(|remaining_account| account_infos.push(remaining_account.0.clone()));
if signers_seeds.is_empty() {
solana_program::program::invoke(&instruction, &account_infos)
} else {
solana_program::program::invoke_signed(&instruction, &account_infos, signers_seeds)
}
}
}
pub struct SwapYieldBearingToStableTokenAmountCpiBuilder<'a, 'b> {
instruction: Box<SwapYieldBearingToStableTokenAmountCpiBuilderInstruction<'a, 'b>>,
}
impl<'a, 'b> SwapYieldBearingToStableTokenAmountCpiBuilder<'a, 'b> {
pub fn new(program: &'b solana_program::account_info::AccountInfo<'a>) -> Self {
let instruction = Box::new(SwapYieldBearingToStableTokenAmountCpiBuilderInstruction {
__program: program,
user_wallet: None,
yield_bearing_token_account: None,
stable_token_account: None,
yield_bearing_bond_account: None,
stable_bond_account: None,
yield_bearing_mint_account: None,
stable_mint_account: None,
token2022_program: None,
associated_token_program: None,
system_program: None,
mint_auth_multisig_account: None,
amount: None,
__remaining_accounts: Vec::new(),
});
Self { instruction }
}
#[inline(always)]
pub fn user_wallet(
&mut self,
user_wallet: &'b solana_program::account_info::AccountInfo<'a>,
) -> &mut Self {
self.instruction.user_wallet = Some(user_wallet);
self
}
#[inline(always)]
pub fn yield_bearing_token_account(
&mut self,
yield_bearing_token_account: &'b solana_program::account_info::AccountInfo<'a>,
) -> &mut Self {
self.instruction.yield_bearing_token_account = Some(yield_bearing_token_account);
self
}
#[inline(always)]
pub fn stable_token_account(
&mut self,
stable_token_account: &'b solana_program::account_info::AccountInfo<'a>,
) -> &mut Self {
self.instruction.stable_token_account = Some(stable_token_account);
self
}
#[inline(always)]
pub fn yield_bearing_bond_account(
&mut self,
yield_bearing_bond_account: &'b solana_program::account_info::AccountInfo<'a>,
) -> &mut Self {
self.instruction.yield_bearing_bond_account = Some(yield_bearing_bond_account);
self
}
#[inline(always)]
pub fn stable_bond_account(
&mut self,
stable_bond_account: &'b solana_program::account_info::AccountInfo<'a>,
) -> &mut Self {
self.instruction.stable_bond_account = Some(stable_bond_account);
self
}
#[inline(always)]
pub fn yield_bearing_mint_account(
&mut self,
yield_bearing_mint_account: &'b solana_program::account_info::AccountInfo<'a>,
) -> &mut Self {
self.instruction.yield_bearing_mint_account = Some(yield_bearing_mint_account);
self
}
#[inline(always)]
pub fn stable_mint_account(
&mut self,
stable_mint_account: &'b solana_program::account_info::AccountInfo<'a>,
) -> &mut Self {
self.instruction.stable_mint_account = Some(stable_mint_account);
self
}
#[inline(always)]
pub fn token2022_program(
&mut self,
token2022_program: &'b solana_program::account_info::AccountInfo<'a>,
) -> &mut Self {
self.instruction.token2022_program = Some(token2022_program);
self
}
#[inline(always)]
pub fn associated_token_program(
&mut self,
associated_token_program: &'b solana_program::account_info::AccountInfo<'a>,
) -> &mut Self {
self.instruction.associated_token_program = Some(associated_token_program);
self
}
#[inline(always)]
pub fn system_program(
&mut self,
system_program: &'b solana_program::account_info::AccountInfo<'a>,
) -> &mut Self {
self.instruction.system_program = Some(system_program);
self
}
#[inline(always)]
pub fn mint_auth_multisig_account(
&mut self,
mint_auth_multisig_account: Option<&'b solana_program::account_info::AccountInfo<'a>>,
) -> &mut Self {
self.instruction.mint_auth_multisig_account = mint_auth_multisig_account;
self
}
#[inline(always)]
pub fn amount(&mut self, amount: u64) -> &mut Self {
self.instruction.amount = Some(amount);
self
}
#[inline(always)]
pub fn add_remaining_account(
&mut self,
account: &'b solana_program::account_info::AccountInfo<'a>,
is_writable: bool,
is_signer: bool,
) -> &mut Self {
self.instruction
.__remaining_accounts
.push((account, is_writable, is_signer));
self
}
#[inline(always)]
pub fn add_remaining_accounts(
&mut self,
accounts: &[(
&'b solana_program::account_info::AccountInfo<'a>,
bool,
bool,
)],
) -> &mut Self {
self.instruction
.__remaining_accounts
.extend_from_slice(accounts);
self
}
#[inline(always)]
pub fn invoke(&self) -> solana_program::entrypoint::ProgramResult {
self.invoke_signed(&[])
}
#[allow(clippy::clone_on_copy)]
#[allow(clippy::vec_init_then_push)]
pub fn invoke_signed(
&self,
signers_seeds: &[&[&[u8]]],
) -> solana_program::entrypoint::ProgramResult {
let args = SwapYieldBearingToStableTokenAmountInstructionArgs {
amount: self.instruction.amount.clone().expect("amount is not set"),
};
let instruction = SwapYieldBearingToStableTokenAmountCpi {
__program: self.instruction.__program,
user_wallet: self
.instruction
.user_wallet
.expect("user_wallet is not set"),
yield_bearing_token_account: self
.instruction
.yield_bearing_token_account
.expect("yield_bearing_token_account is not set"),
stable_token_account: self
.instruction
.stable_token_account
.expect("stable_token_account is not set"),
yield_bearing_bond_account: self
.instruction
.yield_bearing_bond_account
.expect("yield_bearing_bond_account is not set"),
stable_bond_account: self
.instruction
.stable_bond_account
.expect("stable_bond_account is not set"),
yield_bearing_mint_account: self
.instruction
.yield_bearing_mint_account
.expect("yield_bearing_mint_account is not set"),
stable_mint_account: self
.instruction
.stable_mint_account
.expect("stable_mint_account is not set"),
token2022_program: self
.instruction
.token2022_program
.expect("token2022_program is not set"),
associated_token_program: self
.instruction
.associated_token_program
.expect("associated_token_program is not set"),
system_program: self
.instruction
.system_program
.expect("system_program is not set"),
mint_auth_multisig_account: self.instruction.mint_auth_multisig_account,
__args: args,
};
instruction.invoke_signed_with_remaining_accounts(
signers_seeds,
&self.instruction.__remaining_accounts,
)
}
}
struct SwapYieldBearingToStableTokenAmountCpiBuilderInstruction<'a, 'b> {
__program: &'b solana_program::account_info::AccountInfo<'a>,
user_wallet: Option<&'b solana_program::account_info::AccountInfo<'a>>,
yield_bearing_token_account: Option<&'b solana_program::account_info::AccountInfo<'a>>,
stable_token_account: Option<&'b solana_program::account_info::AccountInfo<'a>>,
yield_bearing_bond_account: Option<&'b solana_program::account_info::AccountInfo<'a>>,
stable_bond_account: Option<&'b solana_program::account_info::AccountInfo<'a>>,
yield_bearing_mint_account: Option<&'b solana_program::account_info::AccountInfo<'a>>,
stable_mint_account: Option<&'b solana_program::account_info::AccountInfo<'a>>,
token2022_program: Option<&'b solana_program::account_info::AccountInfo<'a>>,
associated_token_program: Option<&'b solana_program::account_info::AccountInfo<'a>>,
system_program: Option<&'b solana_program::account_info::AccountInfo<'a>>,
mint_auth_multisig_account: Option<&'b solana_program::account_info::AccountInfo<'a>>,
amount: Option<u64>,
__remaining_accounts: Vec<(
&'b solana_program::account_info::AccountInfo<'a>,
bool,
bool,
)>,
}