carbon-orca-whirlpool-decoder 1.0.0

Orca Whirlpool Decoder
Documentation
//! This code was AUTOGENERATED using the Codama library.
use carbon_core::{account_utils::next_account, deserialize::ArrangeAccounts};
/// Initializes a Whirlpool account.
/// This instruction works with both Token and Token-2022.
/// Fee rate is set to the default values on the config and supplied fee_tier.
/// ### Parameters
/// - `bumps` - The bump value when deriving the PDA of the Whirlpool address.
/// - `tick_spacing` - The desired tick spacing for this pool.
/// - `initial_sqrt_price` - The desired initial sqrt-price for this pool
///
/// #### Special Errors
/// `InvalidTokenMintOrder` - The order of mints have to be ordered by
/// `SqrtPriceOutOfBounds` - provided initial_sqrt_price is not between 2^-64 to
/// 2^64
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
#[derive(Debug, Clone, borsh::BorshSerialize, borsh::BorshDeserialize, PartialEq)]
pub struct InitializePoolV2 {
    pub tick_spacing: u16,
    pub initial_sqrt_price: u128,
}

#[derive(Debug, Clone, PartialEq)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct InitializePoolV2InstructionAccounts {
    pub whirlpools_config: solana_pubkey::Pubkey,
    pub token_mint_a: solana_pubkey::Pubkey,
    pub token_mint_b: solana_pubkey::Pubkey,
    pub token_badge_a: solana_pubkey::Pubkey,
    pub token_badge_b: solana_pubkey::Pubkey,
    pub funder: solana_pubkey::Pubkey,
    pub whirlpool: solana_pubkey::Pubkey,
    pub token_vault_a: solana_pubkey::Pubkey,
    pub token_vault_b: solana_pubkey::Pubkey,
    pub fee_tier: solana_pubkey::Pubkey,
    pub token_program_a: solana_pubkey::Pubkey,
    pub token_program_b: solana_pubkey::Pubkey,
    pub system_program: solana_pubkey::Pubkey,
    pub rent: solana_pubkey::Pubkey,
    pub remaining: Vec<solana_instruction::AccountMeta>,
}

impl InitializePoolV2 {
    pub fn decode(data: &[u8]) -> Option<Self> {
        if data.len() < 8 {
            return None;
        }
        let discriminator = &data[0..8];
        if discriminator != [207, 45, 87, 242, 27, 63, 204, 67] {
            return None;
        }

        let mut data_slice = data;

        data_slice = &data_slice[8..];

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

impl ArrangeAccounts for InitializePoolV2 {
    type ArrangedAccounts = InitializePoolV2InstructionAccounts;

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

        let whirlpools_config = next_account(&mut iter)?;
        let token_mint_a = next_account(&mut iter)?;
        let token_mint_b = next_account(&mut iter)?;
        let token_badge_a = next_account(&mut iter)?;
        let token_badge_b = next_account(&mut iter)?;
        let funder = next_account(&mut iter)?;
        let whirlpool = next_account(&mut iter)?;
        let token_vault_a = next_account(&mut iter)?;
        let token_vault_b = next_account(&mut iter)?;
        let fee_tier = next_account(&mut iter)?;
        let token_program_a = next_account(&mut iter)?;
        let token_program_b = next_account(&mut iter)?;
        let system_program = next_account(&mut iter)?;
        let rent = next_account(&mut iter)?;

        let remaining = iter.as_slice();

        Some(InitializePoolV2InstructionAccounts {
            whirlpools_config,
            token_mint_a,
            token_mint_b,
            token_badge_a,
            token_badge_b,
            funder,
            whirlpool,
            token_vault_a,
            token_vault_b,
            fee_tier,
            token_program_a,
            token_program_b,
            system_program,
            rent,
            remaining: remaining.to_vec(),
        })
    }
}