#[cfg(feature = "anchor")]
use anchor_lang::prelude::{AnchorDeserialize, AnchorSerialize};
#[cfg(not(feature = "anchor"))]
use borsh::{BorshDeserialize, BorshSerialize};
pub struct TransferOutOfEscrow {
pub escrow: solana_program::pubkey::Pubkey,
pub metadata: solana_program::pubkey::Pubkey,
pub payer: solana_program::pubkey::Pubkey,
pub attribute_mint: solana_program::pubkey::Pubkey,
pub attribute_src: solana_program::pubkey::Pubkey,
pub attribute_dst: solana_program::pubkey::Pubkey,
pub escrow_mint: solana_program::pubkey::Pubkey,
pub escrow_account: solana_program::pubkey::Pubkey,
pub system_program: solana_program::pubkey::Pubkey,
pub ata_program: solana_program::pubkey::Pubkey,
pub token_program: solana_program::pubkey::Pubkey,
pub sysvar_instructions: solana_program::pubkey::Pubkey,
pub authority: Option<solana_program::pubkey::Pubkey>,
}
impl TransferOutOfEscrow {
pub fn instruction(
&self,
args: TransferOutOfEscrowInstructionArgs,
) -> solana_program::instruction::Instruction {
self.instruction_with_remaining_accounts(args, &[])
}
#[allow(clippy::vec_init_then_push)]
pub fn instruction_with_remaining_accounts(
&self,
args: TransferOutOfEscrowInstructionArgs,
remaining_accounts: &[solana_program::instruction::AccountMeta],
) -> solana_program::instruction::Instruction {
let mut accounts = Vec::with_capacity(13 + remaining_accounts.len());
accounts.push(solana_program::instruction::AccountMeta::new_readonly(
self.escrow,
false,
));
accounts.push(solana_program::instruction::AccountMeta::new(
self.metadata,
false,
));
accounts.push(solana_program::instruction::AccountMeta::new(
self.payer, true,
));
accounts.push(solana_program::instruction::AccountMeta::new_readonly(
self.attribute_mint,
false,
));
accounts.push(solana_program::instruction::AccountMeta::new(
self.attribute_src,
false,
));
accounts.push(solana_program::instruction::AccountMeta::new(
self.attribute_dst,
false,
));
accounts.push(solana_program::instruction::AccountMeta::new_readonly(
self.escrow_mint,
false,
));
accounts.push(solana_program::instruction::AccountMeta::new_readonly(
self.escrow_account,
false,
));
accounts.push(solana_program::instruction::AccountMeta::new_readonly(
self.system_program,
false,
));
accounts.push(solana_program::instruction::AccountMeta::new_readonly(
self.ata_program,
false,
));
accounts.push(solana_program::instruction::AccountMeta::new_readonly(
self.token_program,
false,
));
accounts.push(solana_program::instruction::AccountMeta::new_readonly(
self.sysvar_instructions,
false,
));
if let Some(authority) = self.authority {
accounts.push(solana_program::instruction::AccountMeta::new_readonly(
authority, true,
));
}
accounts.extend_from_slice(remaining_accounts);
let mut data = borsh::to_vec(&(TransferOutOfEscrowInstructionData::new())).unwrap();
let mut args = borsh::to_vec(&args).unwrap();
data.append(&mut args);
solana_program::instruction::Instruction {
program_id: crate::MPL_TOKEN_METADATA_ID,
accounts,
data,
}
}
}
#[cfg_attr(not(feature = "anchor"), derive(BorshSerialize, BorshDeserialize))]
#[cfg_attr(feature = "anchor", derive(AnchorSerialize, AnchorDeserialize))]
pub struct TransferOutOfEscrowInstructionData {
discriminator: u8,
}
impl TransferOutOfEscrowInstructionData {
pub fn new() -> Self {
Self { discriminator: 40 }
}
}
#[cfg_attr(not(feature = "anchor"), derive(BorshSerialize, BorshDeserialize))]
#[cfg_attr(feature = "anchor", derive(AnchorSerialize, AnchorDeserialize))]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
#[derive(Clone, Debug, Eq, PartialEq)]
pub struct TransferOutOfEscrowInstructionArgs {
pub amount: u64,
}
#[derive(Default)]
pub struct TransferOutOfEscrowBuilder {
escrow: Option<solana_program::pubkey::Pubkey>,
metadata: Option<solana_program::pubkey::Pubkey>,
payer: Option<solana_program::pubkey::Pubkey>,
attribute_mint: Option<solana_program::pubkey::Pubkey>,
attribute_src: Option<solana_program::pubkey::Pubkey>,
attribute_dst: Option<solana_program::pubkey::Pubkey>,
escrow_mint: Option<solana_program::pubkey::Pubkey>,
escrow_account: Option<solana_program::pubkey::Pubkey>,
system_program: Option<solana_program::pubkey::Pubkey>,
ata_program: Option<solana_program::pubkey::Pubkey>,
token_program: Option<solana_program::pubkey::Pubkey>,
sysvar_instructions: Option<solana_program::pubkey::Pubkey>,
authority: Option<solana_program::pubkey::Pubkey>,
amount: Option<u64>,
__remaining_accounts: Vec<solana_program::instruction::AccountMeta>,
}
impl TransferOutOfEscrowBuilder {
pub fn new() -> Self {
Self::default()
}
#[inline(always)]
pub fn escrow(&mut self, escrow: solana_program::pubkey::Pubkey) -> &mut Self {
self.escrow = Some(escrow);
self
}
#[inline(always)]
pub fn metadata(&mut self, metadata: solana_program::pubkey::Pubkey) -> &mut Self {
self.metadata = Some(metadata);
self
}
#[inline(always)]
pub fn payer(&mut self, payer: solana_program::pubkey::Pubkey) -> &mut Self {
self.payer = Some(payer);
self
}
#[inline(always)]
pub fn attribute_mint(&mut self, attribute_mint: solana_program::pubkey::Pubkey) -> &mut Self {
self.attribute_mint = Some(attribute_mint);
self
}
#[inline(always)]
pub fn attribute_src(&mut self, attribute_src: solana_program::pubkey::Pubkey) -> &mut Self {
self.attribute_src = Some(attribute_src);
self
}
#[inline(always)]
pub fn attribute_dst(&mut self, attribute_dst: solana_program::pubkey::Pubkey) -> &mut Self {
self.attribute_dst = Some(attribute_dst);
self
}
#[inline(always)]
pub fn escrow_mint(&mut self, escrow_mint: solana_program::pubkey::Pubkey) -> &mut Self {
self.escrow_mint = Some(escrow_mint);
self
}
#[inline(always)]
pub fn escrow_account(&mut self, escrow_account: solana_program::pubkey::Pubkey) -> &mut Self {
self.escrow_account = Some(escrow_account);
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 ata_program(&mut self, ata_program: solana_program::pubkey::Pubkey) -> &mut Self {
self.ata_program = Some(ata_program);
self
}
#[inline(always)]
pub fn token_program(&mut self, token_program: solana_program::pubkey::Pubkey) -> &mut Self {
self.token_program = Some(token_program);
self
}
#[inline(always)]
pub fn sysvar_instructions(
&mut self,
sysvar_instructions: solana_program::pubkey::Pubkey,
) -> &mut Self {
self.sysvar_instructions = Some(sysvar_instructions);
self
}
#[inline(always)]
pub fn authority(&mut self, authority: Option<solana_program::pubkey::Pubkey>) -> &mut Self {
self.authority = authority;
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 = TransferOutOfEscrow {
escrow: self.escrow.expect("escrow is not set"),
metadata: self.metadata.expect("metadata is not set"),
payer: self.payer.expect("payer is not set"),
attribute_mint: self.attribute_mint.expect("attribute_mint is not set"),
attribute_src: self.attribute_src.expect("attribute_src is not set"),
attribute_dst: self.attribute_dst.expect("attribute_dst is not set"),
escrow_mint: self.escrow_mint.expect("escrow_mint is not set"),
escrow_account: self.escrow_account.expect("escrow_account is not set"),
system_program: self
.system_program
.unwrap_or(solana_program::pubkey!("11111111111111111111111111111111")),
ata_program: self.ata_program.unwrap_or(solana_program::pubkey!(
"ATokenGPvbdGVxr1b2hvZbsiqW5xWH25efTNsLJA8knL"
)),
token_program: self.token_program.unwrap_or(solana_program::pubkey!(
"TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA"
)),
sysvar_instructions: self.sysvar_instructions.unwrap_or(solana_program::pubkey!(
"Sysvar1nstructions1111111111111111111111111"
)),
authority: self.authority,
};
let args = TransferOutOfEscrowInstructionArgs {
amount: self.amount.clone().unwrap_or(1),
};
accounts.instruction_with_remaining_accounts(args, &self.__remaining_accounts)
}
}
pub struct TransferOutOfEscrowCpiAccounts<'a, 'b> {
pub escrow: &'b solana_program::account_info::AccountInfo<'a>,
pub metadata: &'b solana_program::account_info::AccountInfo<'a>,
pub payer: &'b solana_program::account_info::AccountInfo<'a>,
pub attribute_mint: &'b solana_program::account_info::AccountInfo<'a>,
pub attribute_src: &'b solana_program::account_info::AccountInfo<'a>,
pub attribute_dst: &'b solana_program::account_info::AccountInfo<'a>,
pub escrow_mint: &'b solana_program::account_info::AccountInfo<'a>,
pub escrow_account: &'b solana_program::account_info::AccountInfo<'a>,
pub system_program: &'b solana_program::account_info::AccountInfo<'a>,
pub ata_program: &'b solana_program::account_info::AccountInfo<'a>,
pub token_program: &'b solana_program::account_info::AccountInfo<'a>,
pub sysvar_instructions: &'b solana_program::account_info::AccountInfo<'a>,
pub authority: Option<&'b solana_program::account_info::AccountInfo<'a>>,
}
pub struct TransferOutOfEscrowCpi<'a, 'b> {
pub __program: &'b solana_program::account_info::AccountInfo<'a>,
pub escrow: &'b solana_program::account_info::AccountInfo<'a>,
pub metadata: &'b solana_program::account_info::AccountInfo<'a>,
pub payer: &'b solana_program::account_info::AccountInfo<'a>,
pub attribute_mint: &'b solana_program::account_info::AccountInfo<'a>,
pub attribute_src: &'b solana_program::account_info::AccountInfo<'a>,
pub attribute_dst: &'b solana_program::account_info::AccountInfo<'a>,
pub escrow_mint: &'b solana_program::account_info::AccountInfo<'a>,
pub escrow_account: &'b solana_program::account_info::AccountInfo<'a>,
pub system_program: &'b solana_program::account_info::AccountInfo<'a>,
pub ata_program: &'b solana_program::account_info::AccountInfo<'a>,
pub token_program: &'b solana_program::account_info::AccountInfo<'a>,
pub sysvar_instructions: &'b solana_program::account_info::AccountInfo<'a>,
pub authority: Option<&'b solana_program::account_info::AccountInfo<'a>>,
pub __args: TransferOutOfEscrowInstructionArgs,
}
impl<'a, 'b> TransferOutOfEscrowCpi<'a, 'b> {
pub fn new(
program: &'b solana_program::account_info::AccountInfo<'a>,
accounts: TransferOutOfEscrowCpiAccounts<'a, 'b>,
args: TransferOutOfEscrowInstructionArgs,
) -> Self {
Self {
__program: program,
escrow: accounts.escrow,
metadata: accounts.metadata,
payer: accounts.payer,
attribute_mint: accounts.attribute_mint,
attribute_src: accounts.attribute_src,
attribute_dst: accounts.attribute_dst,
escrow_mint: accounts.escrow_mint,
escrow_account: accounts.escrow_account,
system_program: accounts.system_program,
ata_program: accounts.ata_program,
token_program: accounts.token_program,
sysvar_instructions: accounts.sysvar_instructions,
authority: accounts.authority,
__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(13 + remaining_accounts.len());
accounts.push(solana_program::instruction::AccountMeta::new_readonly(
*self.escrow.key,
false,
));
accounts.push(solana_program::instruction::AccountMeta::new(
*self.metadata.key,
false,
));
accounts.push(solana_program::instruction::AccountMeta::new(
*self.payer.key,
true,
));
accounts.push(solana_program::instruction::AccountMeta::new_readonly(
*self.attribute_mint.key,
false,
));
accounts.push(solana_program::instruction::AccountMeta::new(
*self.attribute_src.key,
false,
));
accounts.push(solana_program::instruction::AccountMeta::new(
*self.attribute_dst.key,
false,
));
accounts.push(solana_program::instruction::AccountMeta::new_readonly(
*self.escrow_mint.key,
false,
));
accounts.push(solana_program::instruction::AccountMeta::new_readonly(
*self.escrow_account.key,
false,
));
accounts.push(solana_program::instruction::AccountMeta::new_readonly(
*self.system_program.key,
false,
));
accounts.push(solana_program::instruction::AccountMeta::new_readonly(
*self.ata_program.key,
false,
));
accounts.push(solana_program::instruction::AccountMeta::new_readonly(
*self.token_program.key,
false,
));
accounts.push(solana_program::instruction::AccountMeta::new_readonly(
*self.sysvar_instructions.key,
false,
));
if let Some(authority) = self.authority {
accounts.push(solana_program::instruction::AccountMeta::new_readonly(
*authority.key,
true,
));
}
remaining_accounts.iter().for_each(|remaining_account| {
accounts.push(solana_program::instruction::AccountMeta {
pubkey: *remaining_account.0.key,
is_writable: remaining_account.1,
is_signer: remaining_account.2,
})
});
let mut data = borsh::to_vec(&(TransferOutOfEscrowInstructionData::new())).unwrap();
let mut args = borsh::to_vec(&self.__args).unwrap();
data.append(&mut args);
let instruction = solana_program::instruction::Instruction {
program_id: crate::MPL_TOKEN_METADATA_ID,
accounts,
data,
};
let mut account_infos = Vec::with_capacity(13 + 1 + remaining_accounts.len());
account_infos.push(self.__program.clone());
account_infos.push(self.escrow.clone());
account_infos.push(self.metadata.clone());
account_infos.push(self.payer.clone());
account_infos.push(self.attribute_mint.clone());
account_infos.push(self.attribute_src.clone());
account_infos.push(self.attribute_dst.clone());
account_infos.push(self.escrow_mint.clone());
account_infos.push(self.escrow_account.clone());
account_infos.push(self.system_program.clone());
account_infos.push(self.ata_program.clone());
account_infos.push(self.token_program.clone());
account_infos.push(self.sysvar_instructions.clone());
if let Some(authority) = self.authority {
account_infos.push(authority.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 TransferOutOfEscrowCpiBuilder<'a, 'b> {
instruction: Box<TransferOutOfEscrowCpiBuilderInstruction<'a, 'b>>,
}
impl<'a, 'b> TransferOutOfEscrowCpiBuilder<'a, 'b> {
pub fn new(program: &'b solana_program::account_info::AccountInfo<'a>) -> Self {
let instruction = Box::new(TransferOutOfEscrowCpiBuilderInstruction {
__program: program,
escrow: None,
metadata: None,
payer: None,
attribute_mint: None,
attribute_src: None,
attribute_dst: None,
escrow_mint: None,
escrow_account: None,
system_program: None,
ata_program: None,
token_program: None,
sysvar_instructions: None,
authority: None,
amount: None,
__remaining_accounts: Vec::new(),
});
Self { instruction }
}
#[inline(always)]
pub fn escrow(
&mut self,
escrow: &'b solana_program::account_info::AccountInfo<'a>,
) -> &mut Self {
self.instruction.escrow = Some(escrow);
self
}
#[inline(always)]
pub fn metadata(
&mut self,
metadata: &'b solana_program::account_info::AccountInfo<'a>,
) -> &mut Self {
self.instruction.metadata = Some(metadata);
self
}
#[inline(always)]
pub fn payer(&mut self, payer: &'b solana_program::account_info::AccountInfo<'a>) -> &mut Self {
self.instruction.payer = Some(payer);
self
}
#[inline(always)]
pub fn attribute_mint(
&mut self,
attribute_mint: &'b solana_program::account_info::AccountInfo<'a>,
) -> &mut Self {
self.instruction.attribute_mint = Some(attribute_mint);
self
}
#[inline(always)]
pub fn attribute_src(
&mut self,
attribute_src: &'b solana_program::account_info::AccountInfo<'a>,
) -> &mut Self {
self.instruction.attribute_src = Some(attribute_src);
self
}
#[inline(always)]
pub fn attribute_dst(
&mut self,
attribute_dst: &'b solana_program::account_info::AccountInfo<'a>,
) -> &mut Self {
self.instruction.attribute_dst = Some(attribute_dst);
self
}
#[inline(always)]
pub fn escrow_mint(
&mut self,
escrow_mint: &'b solana_program::account_info::AccountInfo<'a>,
) -> &mut Self {
self.instruction.escrow_mint = Some(escrow_mint);
self
}
#[inline(always)]
pub fn escrow_account(
&mut self,
escrow_account: &'b solana_program::account_info::AccountInfo<'a>,
) -> &mut Self {
self.instruction.escrow_account = Some(escrow_account);
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 ata_program(
&mut self,
ata_program: &'b solana_program::account_info::AccountInfo<'a>,
) -> &mut Self {
self.instruction.ata_program = Some(ata_program);
self
}
#[inline(always)]
pub fn token_program(
&mut self,
token_program: &'b solana_program::account_info::AccountInfo<'a>,
) -> &mut Self {
self.instruction.token_program = Some(token_program);
self
}
#[inline(always)]
pub fn sysvar_instructions(
&mut self,
sysvar_instructions: &'b solana_program::account_info::AccountInfo<'a>,
) -> &mut Self {
self.instruction.sysvar_instructions = Some(sysvar_instructions);
self
}
#[inline(always)]
pub fn authority(
&mut self,
authority: Option<&'b solana_program::account_info::AccountInfo<'a>>,
) -> &mut Self {
self.instruction.authority = authority;
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 = TransferOutOfEscrowInstructionArgs {
amount: self.instruction.amount.clone().unwrap_or(1),
};
let instruction = TransferOutOfEscrowCpi {
__program: self.instruction.__program,
escrow: self.instruction.escrow.expect("escrow is not set"),
metadata: self.instruction.metadata.expect("metadata is not set"),
payer: self.instruction.payer.expect("payer is not set"),
attribute_mint: self
.instruction
.attribute_mint
.expect("attribute_mint is not set"),
attribute_src: self
.instruction
.attribute_src
.expect("attribute_src is not set"),
attribute_dst: self
.instruction
.attribute_dst
.expect("attribute_dst is not set"),
escrow_mint: self
.instruction
.escrow_mint
.expect("escrow_mint is not set"),
escrow_account: self
.instruction
.escrow_account
.expect("escrow_account is not set"),
system_program: self
.instruction
.system_program
.expect("system_program is not set"),
ata_program: self
.instruction
.ata_program
.expect("ata_program is not set"),
token_program: self
.instruction
.token_program
.expect("token_program is not set"),
sysvar_instructions: self
.instruction
.sysvar_instructions
.expect("sysvar_instructions is not set"),
authority: self.instruction.authority,
__args: args,
};
instruction.invoke_signed_with_remaining_accounts(
signers_seeds,
&self.instruction.__remaining_accounts,
)
}
}
struct TransferOutOfEscrowCpiBuilderInstruction<'a, 'b> {
__program: &'b solana_program::account_info::AccountInfo<'a>,
escrow: Option<&'b solana_program::account_info::AccountInfo<'a>>,
metadata: Option<&'b solana_program::account_info::AccountInfo<'a>>,
payer: Option<&'b solana_program::account_info::AccountInfo<'a>>,
attribute_mint: Option<&'b solana_program::account_info::AccountInfo<'a>>,
attribute_src: Option<&'b solana_program::account_info::AccountInfo<'a>>,
attribute_dst: Option<&'b solana_program::account_info::AccountInfo<'a>>,
escrow_mint: Option<&'b solana_program::account_info::AccountInfo<'a>>,
escrow_account: Option<&'b solana_program::account_info::AccountInfo<'a>>,
system_program: Option<&'b solana_program::account_info::AccountInfo<'a>>,
ata_program: Option<&'b solana_program::account_info::AccountInfo<'a>>,
token_program: Option<&'b solana_program::account_info::AccountInfo<'a>>,
sysvar_instructions: Option<&'b solana_program::account_info::AccountInfo<'a>>,
authority: Option<&'b solana_program::account_info::AccountInfo<'a>>,
amount: Option<u64>,
__remaining_accounts: Vec<(
&'b solana_program::account_info::AccountInfo<'a>,
bool,
bool,
)>,
}