clmm-common 0.1.39

Blockchain, Clmm for Solana
Documentation
use borsh::BorshDeserialize;
use nom::AsBytes;
use solana_client::rpc_client::RpcClient;
use solana_program::pubkey::Pubkey;
use tabled::Tabled;

use crate::program::SWAP_PROGRAM_ID;

use super::config::ClmmConfig;

#[derive(BorshDeserialize, Tabled)]
pub struct FeeTier {
    pub fee_rate: u16,
    pub tick_spacing: u16,
    pub bump: u8,
}

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

    pub fn find_address(tick_spacing: u16) -> Pubkey {
        let clmm_config = ClmmConfig::find_address();
        let (fee_tier_pubkey, _) = Pubkey::find_program_address(
            &[
                b"fee_tier",
                clmm_config.as_ref(),
                tick_spacing.to_le_bytes().as_bytes(),
            ],
            &SWAP_PROGRAM_ID,
        );
        fee_tier_pubkey
    }
}