crema-cli 0.1.0

Blockchain, Crema for Solana
Documentation
use borsh::BorshDeserialize;
use solana_client::rpc_client::RpcClient;
use solana_sdk::pubkey::Pubkey;
use tabled::Tabled;

use crate::program::PROGRAM_ID;

#[derive(BorshDeserialize, Tabled)]
pub struct Clmmpool {
    /// clmm_config
    pub clmm_config: Pubkey,
    /// The pool token a mint address.
    pub token_a: Pubkey,
    /// The pool token b mint address.
    pub token_b: Pubkey,

    /// The vault for hold clmmpool's token a.
    pub token_a_vault: Pubkey,
    /// The vault for hold clmmpool's token b.
    pub token_b_vault: Pubkey,

    /// The tick spacing.
    pub tick_spacing: u16,

    pub tick_spacing_seed: u16,

    /// The numerator of fee rate, the denominator is 1_000_000.
    pub fee_rate: u16,
    /// The numerator of protocol fee rate, the denominator is 1_000_0.

    /// Protocol fee amount = fee_amount * protocol_fee_rate.
    pub protocol_fee_rate: u16,

    /// The liquidity of current tick index.
    pub liquidity: u128,

    /// The current sqrt price, Q64.64 and MAX/MIN is Q32.64.
    pub current_sqrt_price: u128,
    /// The current tick index.
    pub current_tick_index: i32,

    /// The fee growth a as Q64.64.
    pub fee_growth_global_a: u128,
    /// The fee growth b as Q64.64.
    pub fee_growth_global_b: u128,

    /// The amounts of token a owed to protocol.
    pub fee_protocol_token_a: u64,
    /// The amounts of token b owed to protocol.
    pub fee_protocol_token_b: u64,

    /// The bump
    pub bump: u8,

    pub reward_infos: Rewarders,
    pub reward_last_updated_time: u64, // 8
}

#[derive(Copy, Clone, BorshDeserialize, Default, Debug, PartialEq)]
pub struct Rewarder {
    pub mint_wrapper: Pubkey,
    pub minter: Pubkey,
    /// Reward token mint.
    pub mint: Pubkey,
    /// Authority account that has permission to initialize the reward and set emissions.
    pub authority: Pubkey,
    /// Q64.64 number that indicates how many tokens per second are earned per unit of liquidity.
    pub emissions_per_second: u128,
    /// Q64.64 number that tracks the total tokens earned per unit of liquidity since the reward
    /// emissions were turned on.
    pub growth_global: u128,
}

impl Rewarder {
    pub const LEN: usize = 32 + 32 + 32 + 32 + 16 + 16;
}

#[derive(Copy, Clone, BorshDeserialize, Default, Debug, PartialEq)]
pub struct Rewarders([Rewarder; 3]);

impl std::fmt::Display for Rewarders {
    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
        write!(f, "reserved")
    }
}

impl Clmmpool {
    pub const REWARD_NUM: usize = 3;
    pub const LEN: usize =
        5 * 32 + 4 * 2 + 2 * 16 + 4 + 2 * 16 + 2 * 8 + 1 + Clmmpool::REWARD_NUM * Rewarder::LEN + 8;

    pub fn get_info(rpc_client: &RpcClient, pubkey: &Pubkey) -> Self {
        let data_slice = &rpc_client.get_account_data(pubkey).unwrap()[8..];
        Clmmpool::try_from_slice(data_slice).unwrap()
    }

    pub fn get_tick_map_address(pool: &Pubkey) -> Pubkey {
        let (expect_address, _) =
            Pubkey::find_program_address(&[b"tick_array_map", pool.as_ref()], &PROGRAM_ID);
        expect_address
    }
}