carbon-bonkswap-decoder 2.0.0

Carbon BonkSwap Decoder
Documentation
//! This code was AUTOGENERATED using the Codama library.
use {
    crate::types::Token,
    carbon_core::{account_utils::next_account, deserialize::ArrangeAccounts},
};
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
#[derive(Debug, Clone, borsh::BorshSerialize, borsh::BorshDeserialize, PartialEq)]
pub struct AddSupply {
    pub supply_marco: Token,
    pub supply_project_first: Token,
    pub supply_project_second: Token,
    pub duration: u64,
}

#[derive(Debug, Clone, PartialEq)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct AddSupplyInstructionAccounts {
    pub state: solana_pubkey::Pubkey,
    pub pool: solana_pubkey::Pubkey,
    pub farm: solana_pubkey::Pubkey,
    pub token_x: solana_pubkey::Pubkey,
    pub token_y: solana_pubkey::Pubkey,
    pub token_marco_account: solana_pubkey::Pubkey,
    pub token_project_first_account: solana_pubkey::Pubkey,
    pub token_project_second_account: solana_pubkey::Pubkey,
    pub admin_marco_account: solana_pubkey::Pubkey,
    pub admin_project_first_account: solana_pubkey::Pubkey,
    pub admin_project_second_account: solana_pubkey::Pubkey,
    pub admin: solana_pubkey::Pubkey,
    pub token_program: solana_pubkey::Pubkey,
    pub remaining: Vec<solana_instruction::AccountMeta>,
}

impl AddSupply {
    pub fn decode(data: &[u8]) -> Option<Self> {
        if data.len() < 8 {
            return None;
        }
        let discriminator = &data[0..8];
        if discriminator != [80, 102, 70, 57, 235, 88, 239, 8] {
            return None;
        }

        let mut data_slice = data;

        data_slice = &data_slice[8..];

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

impl ArrangeAccounts for AddSupply {
    type ArrangedAccounts = AddSupplyInstructionAccounts;

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

        let state = next_account(&mut iter)?;
        let pool = next_account(&mut iter)?;
        let farm = next_account(&mut iter)?;
        let token_x = next_account(&mut iter)?;
        let token_y = next_account(&mut iter)?;
        let token_marco_account = next_account(&mut iter)?;
        let token_project_first_account = next_account(&mut iter)?;
        let token_project_second_account = next_account(&mut iter)?;
        let admin_marco_account = next_account(&mut iter)?;
        let admin_project_first_account = next_account(&mut iter)?;
        let admin_project_second_account = next_account(&mut iter)?;
        let admin = next_account(&mut iter)?;
        let token_program = next_account(&mut iter)?;

        let remaining = iter.as_slice();

        Some(AddSupplyInstructionAccounts {
            state,
            pool,
            farm,
            token_x,
            token_y,
            token_marco_account,
            token_project_first_account,
            token_project_second_account,
            admin_marco_account,
            admin_project_first_account,
            admin_project_second_account,
            admin,
            token_program,
            remaining: remaining.to_vec(),
        })
    }
}