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};
/// Set the reward emissions for a reward in a Whirlpool.
/// ### Authority
/// - "reward_authority" - assigned authority by the reward_super_authority for
///   the specified
///
/// reward-index in this Whirlpool
/// ### Parameters
/// - `reward_index` - The reward index (0 <= index <= NUM_REWARDS) that we'd
///   like to modify.
/// - `emissions_per_second_x64` - The amount of rewards emitted in this pool.
///
/// #### Special Errors
/// - `RewardVaultAmountInsufficient` - The amount of rewards in the reward
///   vault cannot emit
///
/// more than a day of desired emissions.
/// - `InvalidTimestamp` - Provided timestamp is not in order with the previous
///   timestamp.
/// - `InvalidRewardIndex` - If the provided reward index doesn't match the
///   lowest uninitialized
///
/// index in this pool, or exceeds NUM_REWARDS, or
/// all reward slots for this pool has been initialized.
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
#[derive(Debug, Clone, borsh::BorshSerialize, borsh::BorshDeserialize, PartialEq)]
pub struct SetRewardEmissions {
    pub reward_index: u8,
    pub emissions_per_second_x64: u128,
}

#[derive(Debug, Clone, PartialEq)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct SetRewardEmissionsInstructionAccounts {
    pub whirlpool: solana_pubkey::Pubkey,
    pub reward_authority: solana_pubkey::Pubkey,
    pub reward_vault: solana_pubkey::Pubkey,
    pub remaining: Vec<solana_instruction::AccountMeta>,
}

impl SetRewardEmissions {
    pub fn decode(data: &[u8]) -> Option<Self> {
        if data.len() < 8 {
            return None;
        }
        let discriminator = &data[0..8];
        if discriminator != [13, 197, 86, 168, 109, 176, 27, 244] {
            return None;
        }

        let mut data_slice = data;

        data_slice = &data_slice[8..];

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

impl ArrangeAccounts for SetRewardEmissions {
    type ArrangedAccounts = SetRewardEmissionsInstructionAccounts;

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

        let whirlpool = next_account(&mut iter)?;
        let reward_authority = next_account(&mut iter)?;
        let reward_vault = next_account(&mut iter)?;

        let remaining = iter.as_slice();

        Some(SetRewardEmissionsInstructionAccounts {
            whirlpool,
            reward_authority,
            reward_vault,
            remaining: remaining.to_vec(),
        })
    }
}