raydium_cpmm 0.1.11

raydium client
Documentation
//! This code was AUTOGENERATED using the codama library.
//! Please DO NOT EDIT THIS FILE, instead use visitors
//! to add features, then rerun codama to update it.
//!
//! <https://github.com/codama-idl/codama>
//!

use borsh::BorshDeserialize;
use borsh::BorshSerialize;

/// Accounts.
#[derive(Debug)]
pub struct UpdateAmmConfig {
    /// The amm config owner or admin
    pub owner: solana_pubkey::Pubkey,
    /// Amm config account to be changed
    pub amm_config: solana_pubkey::Pubkey,
}

impl UpdateAmmConfig {
    pub fn instruction(
        &self,
        args: UpdateAmmConfigInstructionArgs,
    ) -> solana_instruction::Instruction {
        self.instruction_with_remaining_accounts(args, &[])
    }
    #[allow(clippy::arithmetic_side_effects)]
    #[allow(clippy::vec_init_then_push)]
    pub fn instruction_with_remaining_accounts(
        &self,
        args: UpdateAmmConfigInstructionArgs,
        remaining_accounts: &[solana_instruction::AccountMeta],
    ) -> solana_instruction::Instruction {
        let mut accounts = Vec::with_capacity(2 + remaining_accounts.len());
        accounts.push(solana_instruction::AccountMeta::new_readonly(
            self.owner, true,
        ));
        accounts.push(solana_instruction::AccountMeta::new(self.amm_config, false));
        accounts.extend_from_slice(remaining_accounts);
        let mut data = borsh::to_vec(&UpdateAmmConfigInstructionData::new()).unwrap();
        let mut args = borsh::to_vec(&args).unwrap();
        data.append(&mut args);

        solana_instruction::Instruction {
            program_id: crate::RAYDIUM_CP_SWAP_ID,
            accounts,
            data,
        }
    }
}

#[derive(BorshSerialize, BorshDeserialize, Clone, Debug, Eq, PartialEq)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct UpdateAmmConfigInstructionData {
    discriminator: [u8; 8],
}

impl UpdateAmmConfigInstructionData {
    pub fn new() -> Self {
        Self {
            discriminator: [49, 60, 174, 136, 154, 28, 116, 200],
        }
    }
}

impl Default for UpdateAmmConfigInstructionData {
    fn default() -> Self {
        Self::new()
    }
}

#[derive(BorshSerialize, BorshDeserialize, Clone, Debug, Eq, PartialEq)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct UpdateAmmConfigInstructionArgs {
    pub param: u8,
    pub value: u64,
}

/// Instruction builder for `UpdateAmmConfig`.
///
/// ### Accounts:
///
///   0. `[signer, optional]` owner (default to `GThUX1Atko4tqhN2NaiTazWSeFWMuiUvfFnyJyUghFMJ`)
///   1. `[writable]` amm_config
#[derive(Clone, Debug, Default)]
pub struct UpdateAmmConfigBuilder {
    owner: Option<solana_pubkey::Pubkey>,
    amm_config: Option<solana_pubkey::Pubkey>,
    param: Option<u8>,
    value: Option<u64>,
    __remaining_accounts: Vec<solana_instruction::AccountMeta>,
}

impl UpdateAmmConfigBuilder {
    pub fn new() -> Self {
        Self::default()
    }
    /// `[optional account, default to 'GThUX1Atko4tqhN2NaiTazWSeFWMuiUvfFnyJyUghFMJ']`
    /// The amm config owner or admin
    #[inline(always)]
    pub fn owner(&mut self, owner: solana_pubkey::Pubkey) -> &mut Self {
        self.owner = Some(owner);
        self
    }
    /// Amm config account to be changed
    #[inline(always)]
    pub fn amm_config(&mut self, amm_config: solana_pubkey::Pubkey) -> &mut Self {
        self.amm_config = Some(amm_config);
        self
    }
    #[inline(always)]
    pub fn param(&mut self, param: u8) -> &mut Self {
        self.param = Some(param);
        self
    }
    #[inline(always)]
    pub fn value(&mut self, value: u64) -> &mut Self {
        self.value = Some(value);
        self
    }
    /// Add an additional account to the instruction.
    #[inline(always)]
    pub fn add_remaining_account(&mut self, account: solana_instruction::AccountMeta) -> &mut Self {
        self.__remaining_accounts.push(account);
        self
    }
    /// Add additional accounts to the instruction.
    #[inline(always)]
    pub fn add_remaining_accounts(
        &mut self,
        accounts: &[solana_instruction::AccountMeta],
    ) -> &mut Self {
        self.__remaining_accounts.extend_from_slice(accounts);
        self
    }
    #[allow(clippy::clone_on_copy)]
    pub fn instruction(&self) -> solana_instruction::Instruction {
        let accounts = UpdateAmmConfig {
            owner: self.owner.unwrap_or(solana_pubkey::pubkey!(
                "GThUX1Atko4tqhN2NaiTazWSeFWMuiUvfFnyJyUghFMJ"
            )),
            amm_config: self.amm_config.expect("amm_config is not set"),
        };
        let args = UpdateAmmConfigInstructionArgs {
            param: self.param.clone().expect("param is not set"),
            value: self.value.clone().expect("value is not set"),
        };

        accounts.instruction_with_remaining_accounts(args, &self.__remaining_accounts)
    }
}

/// `update_amm_config` CPI accounts.
pub struct UpdateAmmConfigCpiAccounts<'a, 'b> {
    /// The amm config owner or admin
    pub owner: &'b solana_account_info::AccountInfo<'a>,
    /// Amm config account to be changed
    pub amm_config: &'b solana_account_info::AccountInfo<'a>,
}

/// `update_amm_config` CPI instruction.
pub struct UpdateAmmConfigCpi<'a, 'b> {
    /// The program to invoke.
    pub __program: &'b solana_account_info::AccountInfo<'a>,
    /// The amm config owner or admin
    pub owner: &'b solana_account_info::AccountInfo<'a>,
    /// Amm config account to be changed
    pub amm_config: &'b solana_account_info::AccountInfo<'a>,
    /// The arguments for the instruction.
    pub __args: UpdateAmmConfigInstructionArgs,
}

impl<'a, 'b> UpdateAmmConfigCpi<'a, 'b> {
    pub fn new(
        program: &'b solana_account_info::AccountInfo<'a>,
        accounts: UpdateAmmConfigCpiAccounts<'a, 'b>,
        args: UpdateAmmConfigInstructionArgs,
    ) -> Self {
        Self {
            __program: program,
            owner: accounts.owner,
            amm_config: accounts.amm_config,
            __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_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::arithmetic_side_effects)]
    #[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_account_info::AccountInfo<'a>, bool, bool)],
    ) -> solana_program_entrypoint::ProgramResult {
        let mut accounts = Vec::with_capacity(2 + remaining_accounts.len());
        accounts.push(solana_instruction::AccountMeta::new_readonly(
            *self.owner.key,
            true,
        ));
        accounts.push(solana_instruction::AccountMeta::new(
            *self.amm_config.key,
            false,
        ));
        remaining_accounts.iter().for_each(|remaining_account| {
            accounts.push(solana_instruction::AccountMeta {
                pubkey: *remaining_account.0.key,
                is_signer: remaining_account.1,
                is_writable: remaining_account.2,
            })
        });
        let mut data = borsh::to_vec(&UpdateAmmConfigInstructionData::new()).unwrap();
        let mut args = borsh::to_vec(&self.__args).unwrap();
        data.append(&mut args);

        let instruction = solana_instruction::Instruction {
            program_id: crate::RAYDIUM_CP_SWAP_ID,
            accounts,
            data,
        };
        let mut account_infos = Vec::with_capacity(3 + remaining_accounts.len());
        account_infos.push(self.__program.clone());
        account_infos.push(self.owner.clone());
        account_infos.push(self.amm_config.clone());
        remaining_accounts
            .iter()
            .for_each(|remaining_account| account_infos.push(remaining_account.0.clone()));

        if signers_seeds.is_empty() {
            solana_cpi::invoke(&instruction, &account_infos)
        } else {
            solana_cpi::invoke_signed(&instruction, &account_infos, signers_seeds)
        }
    }
}

/// Instruction builder for `UpdateAmmConfig` via CPI.
///
/// ### Accounts:
///
///   0. `[signer]` owner
///   1. `[writable]` amm_config
#[derive(Clone, Debug)]
pub struct UpdateAmmConfigCpiBuilder<'a, 'b> {
    instruction: Box<UpdateAmmConfigCpiBuilderInstruction<'a, 'b>>,
}

impl<'a, 'b> UpdateAmmConfigCpiBuilder<'a, 'b> {
    pub fn new(program: &'b solana_account_info::AccountInfo<'a>) -> Self {
        let instruction = Box::new(UpdateAmmConfigCpiBuilderInstruction {
            __program: program,
            owner: None,
            amm_config: None,
            param: None,
            value: None,
            __remaining_accounts: Vec::new(),
        });
        Self { instruction }
    }
    /// The amm config owner or admin
    #[inline(always)]
    pub fn owner(&mut self, owner: &'b solana_account_info::AccountInfo<'a>) -> &mut Self {
        self.instruction.owner = Some(owner);
        self
    }
    /// Amm config account to be changed
    #[inline(always)]
    pub fn amm_config(
        &mut self,
        amm_config: &'b solana_account_info::AccountInfo<'a>,
    ) -> &mut Self {
        self.instruction.amm_config = Some(amm_config);
        self
    }
    #[inline(always)]
    pub fn param(&mut self, param: u8) -> &mut Self {
        self.instruction.param = Some(param);
        self
    }
    #[inline(always)]
    pub fn value(&mut self, value: u64) -> &mut Self {
        self.instruction.value = Some(value);
        self
    }
    /// Add an additional account to the instruction.
    #[inline(always)]
    pub fn add_remaining_account(
        &mut self,
        account: &'b solana_account_info::AccountInfo<'a>,
        is_writable: bool,
        is_signer: bool,
    ) -> &mut Self {
        self.instruction
            .__remaining_accounts
            .push((account, is_writable, is_signer));
        self
    }
    /// Add additional accounts to the instruction.
    ///
    /// Each account is represented by a tuple of the `AccountInfo`, a `bool` indicating whether the account is writable or not,
    /// and a `bool` indicating whether the account is a signer or not.
    #[inline(always)]
    pub fn add_remaining_accounts(
        &mut self,
        accounts: &[(&'b solana_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 = UpdateAmmConfigInstructionArgs {
            param: self.instruction.param.clone().expect("param is not set"),
            value: self.instruction.value.clone().expect("value is not set"),
        };
        let instruction = UpdateAmmConfigCpi {
            __program: self.instruction.__program,

            owner: self.instruction.owner.expect("owner is not set"),

            amm_config: self.instruction.amm_config.expect("amm_config is not set"),
            __args: args,
        };
        instruction.invoke_signed_with_remaining_accounts(
            signers_seeds,
            &self.instruction.__remaining_accounts,
        )
    }
}

#[derive(Clone, Debug)]
struct UpdateAmmConfigCpiBuilderInstruction<'a, 'b> {
    __program: &'b solana_account_info::AccountInfo<'a>,
    owner: Option<&'b solana_account_info::AccountInfo<'a>>,
    amm_config: Option<&'b solana_account_info::AccountInfo<'a>>,
    param: Option<u8>,
    value: Option<u64>,
    /// Additional instruction accounts `(AccountInfo, is_writable, is_signer)`.
    __remaining_accounts: Vec<(&'b solana_account_info::AccountInfo<'a>, bool, bool)>,
}