carbon-jupiter-lend-decoder 2.0.0

Jupiter Lend Liquidity Decoder
Documentation
//! This code was AUTOGENERATED using the Codama library.
use {
    crate::types::TransferType,
    carbon_core::{account_utils::next_account, deserialize::ArrangeAccounts},
    solana_pubkey::Pubkey,
};
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
#[derive(Debug, Clone, borsh::BorshSerialize, borsh::BorshDeserialize, PartialEq)]
pub struct Operate {
    pub supply_amount: i128,
    pub borrow_amount: i128,
    pub withdraw_to: Pubkey,
    pub borrow_to: Pubkey,
    pub transfer_type: TransferType,
}

#[derive(Debug, Clone, PartialEq)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct OperateInstructionAccounts {
    pub protocol: solana_pubkey::Pubkey,
    pub liquidity: solana_pubkey::Pubkey,
    pub token_reserve: solana_pubkey::Pubkey,
    pub mint: solana_pubkey::Pubkey,
    pub vault: solana_pubkey::Pubkey,
    pub user_supply_position: Option<solana_pubkey::Pubkey>,
    pub user_borrow_position: Option<solana_pubkey::Pubkey>,
    pub rate_model: solana_pubkey::Pubkey,
    pub withdraw_to_account: Option<solana_pubkey::Pubkey>,
    pub borrow_to_account: Option<solana_pubkey::Pubkey>,
    pub borrow_claim_account: Option<solana_pubkey::Pubkey>,
    pub withdraw_claim_account: Option<solana_pubkey::Pubkey>,
    pub token_program: solana_pubkey::Pubkey,
    pub associated_token_program: solana_pubkey::Pubkey,
    pub remaining: Vec<solana_instruction::AccountMeta>,
}

impl Operate {
    pub fn decode(data: &[u8]) -> Option<Self> {
        if data.len() < 8 {
            return None;
        }
        let discriminator = &data[0..8];
        if discriminator != [217, 106, 208, 99, 116, 151, 42, 135] {
            return None;
        }

        let mut data_slice = data;

        data_slice = &data_slice[8..];

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

impl ArrangeAccounts for Operate {
    type ArrangedAccounts = OperateInstructionAccounts;

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

        let protocol = next_account(&mut iter)?;
        let liquidity = next_account(&mut iter)?;
        let token_reserve = next_account(&mut iter)?;
        let mint = next_account(&mut iter)?;
        let vault = next_account(&mut iter)?;
        let user_supply_position = next_account(&mut iter);
        let user_borrow_position = next_account(&mut iter);
        let rate_model = next_account(&mut iter)?;
        let withdraw_to_account = next_account(&mut iter);
        let borrow_to_account = next_account(&mut iter);
        let borrow_claim_account = next_account(&mut iter);
        let withdraw_claim_account = next_account(&mut iter);
        let token_program = next_account(&mut iter)?;
        let associated_token_program = next_account(&mut iter)?;

        let remaining = iter.as_slice();

        Some(OperateInstructionAccounts {
            protocol,
            liquidity,
            token_reserve,
            mint,
            vault,
            user_supply_position,
            user_borrow_position,
            rate_model,
            withdraw_to_account,
            borrow_to_account,
            borrow_claim_account,
            withdraw_claim_account,
            token_program,
            associated_token_program,
            remaining: remaining.to_vec(),
        })
    }
}