//! This code was AUTOGENERATED using the Codama library.
use solana_pubkey::Pubkey;

#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
#[derive(Debug, Clone, borsh::BorshSerialize, borsh::BorshDeserialize, PartialEq)]
pub struct ProtocolPositionState {
    /// Bump to identify PDA
    pub bump: u8,
    /// The ID of the pool with which this token is connected
    pub pool_id: Pubkey,
    /// The lower bound tick of the position
    pub tick_lower_index: i32,
    /// The upper bound tick of the position
    pub tick_upper_index: i32,
    /// The amount of liquidity owned by this position
    pub liquidity: u128,
    /// The token_0 fee growth per unit of liquidity as of the last update to
    /// liquidity or fees owed
    pub fee_growth_inside0_last_x64: u128,
    /// The token_1 fee growth per unit of liquidity as of the last update to
    /// liquidity or fees owed
    pub fee_growth_inside1_last_x64: u128,
    /// The fees owed to the position owner in token_0
    pub token_fees_owed0: u64,
    /// The fees owed to the position owner in token_1
    pub token_fees_owed1: u64,
    /// The reward growth per unit of liquidity as of the last update to
    /// liquidity
    pub reward_growth_inside: [u128; 3],
    pub recent_epoch: u64,
    pub padding: [u64; 7],
}

impl ProtocolPositionState {
    pub fn decode(data: &[u8]) -> Option<Self> {
        if data.len() < 8 {
            return None;
        }
        let discriminator = &data[0..8];
        if discriminator != [100, 226, 145, 99, 146, 218, 160, 106] {
            return None;
        }

        let mut data_slice = data;

        data_slice = &data_slice[8..];

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