carbon-raydium-launchpad-decoder 2.0.0

Raydium Launchpad Decoder
Documentation
//! This code was AUTOGENERATED using the Codama library.
use carbon_core::{account_utils::next_account, deserialize::ArrangeAccounts};
/// Creates a new configuration
/// # Arguments
/// * `ctx` - The accounts needed by instruction
/// * `curve_type` - The type of bonding curve (0: ConstantProduct)
/// * `index` - The index of config, there may be multiple config with the same
///   curve type.
/// * `trade_fee_rate` - Trade fee rate, must be less than
///   RATE_DENOMINATOR_VALUE
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
#[derive(Debug, Clone, borsh::BorshSerialize, borsh::BorshDeserialize, PartialEq)]
pub struct CreateConfig {
    pub curve_type: u8,
    pub index: u16,
    pub migrate_fee: u64,
    pub trade_fee_rate: u64,
}

#[derive(Debug, Clone, PartialEq)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct CreateConfigInstructionAccounts {
    pub owner: solana_pubkey::Pubkey,
    pub global_config: solana_pubkey::Pubkey,
    pub quote_token_mint: solana_pubkey::Pubkey,
    pub protocol_fee_owner: solana_pubkey::Pubkey,
    pub migrate_fee_owner: solana_pubkey::Pubkey,
    pub migrate_to_amm_wallet: solana_pubkey::Pubkey,
    pub migrate_to_cpswap_wallet: solana_pubkey::Pubkey,
    pub system_program: solana_pubkey::Pubkey,
    pub remaining: Vec<solana_instruction::AccountMeta>,
}

impl CreateConfig {
    pub fn decode(data: &[u8]) -> Option<Self> {
        if data.len() < 8 {
            return None;
        }
        let discriminator = &data[0..8];
        if discriminator != [201, 207, 243, 114, 75, 111, 47, 189] {
            return None;
        }

        let mut data_slice = data;

        data_slice = &data_slice[8..];

        borsh::BorshDeserialize::deserialize(&mut data_slice).ok()
    }
}

impl ArrangeAccounts for CreateConfig {
    type ArrangedAccounts = CreateConfigInstructionAccounts;

    fn arrange_accounts(
        accounts: &[solana_instruction::AccountMeta],
    ) -> Option<Self::ArrangedAccounts> {
        let mut iter = accounts.iter();

        let owner = next_account(&mut iter)?;
        let global_config = next_account(&mut iter)?;
        let quote_token_mint = next_account(&mut iter)?;
        let protocol_fee_owner = next_account(&mut iter)?;
        let migrate_fee_owner = next_account(&mut iter)?;
        let migrate_to_amm_wallet = next_account(&mut iter)?;
        let migrate_to_cpswap_wallet = next_account(&mut iter)?;
        let system_program = next_account(&mut iter)?;

        let remaining = iter.as_slice();

        Some(CreateConfigInstructionAccounts {
            owner,
            global_config,
            quote_token_mint,
            protocol_fee_owner,
            migrate_fee_owner,
            migrate_to_amm_wallet,
            migrate_to_cpswap_wallet,
            system_program,
            remaining: remaining.to_vec(),
        })
    }
}