1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
use borsh::BorshDeserialize;
use solana_client::rpc_client::RpcClient;
use solana_program::pubkey::Pubkey;
use tabled::Tabled;

#[derive(Default, Debug, BorshDeserialize, Tabled)]
pub struct Position {
    pub clmmpool: Pubkey,
    pub position_nft_mint: Pubkey,
    pub liquidity: u128,
    pub tick_lower_index: i32,
    pub tick_upper_index: i32,

    // Q64.64
    pub fee_growth_inside_a: u128,
    pub fee_owed_a: u64,

    // Q64.64
    pub fee_growth_inside_b: u128,
    pub fee_owed_b: u64,

    pub reward_infos: PositionRewarders,
}

#[derive(Copy, Clone, BorshDeserialize, Default, Debug, PartialEq)]
pub struct PositionReward {
    // Q64.64
    pub growth_inside: u128,
    pub amount_owed: u64,
}

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

impl std::fmt::Display for PositionRewarders {
    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
        write!(f, "reserved")
    }
}
impl Position {
    pub fn get_info(rpc_client: &RpcClient, pubkey: &Pubkey) -> Self {
        let data_slice = &rpc_client.get_account_data(pubkey).unwrap()[8..];
        Position::try_from_slice(data_slice).unwrap()
    }
}