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
46
47
48
49
50
51
52
53
54
55
56
57
58
use borsh::BorshDeserialize;

use colored::Colorize;
use solana_account_decoder::UiAccountEncoding;

use solana_client::rpc_client::RpcClient;
use solana_client::rpc_config::{RpcAccountInfoConfig, RpcProgramAccountsConfig};
use solana_client::rpc_filter::{RpcFilterType};

use tabled::{Alignment, Modify, Panel, Style, Table};
use tabled::object::Segment;
use tabled::style::Color;


use common::command::{ProcessResult};
use common::contract::state::clmmpools::Clmmpool;
use common::program::{SWAP_PROGRAM_ID};


pub fn process_pair_list(rpc_client: &RpcClient) -> ProcessResult {
    let accounts = rpc_client.get_program_accounts_with_config(
        &SWAP_PROGRAM_ID,
        RpcProgramAccountsConfig {
            filters: Some(
                vec![
                    RpcFilterType::DataSize(
                        (Clmmpool::LEN + 8) as u64
                    )
                ]
            ),
            account_config: RpcAccountInfoConfig {
                encoding: Some(UiAccountEncoding::Base64),
                data_slice: None,
                commitment: None,
                min_context_slot: None
            },
            with_context: None
        }
    );

    let mut list = Vec::new();


    for account in accounts.unwrap() {
        let data_slice = &account.1.data[8..];

        list.push(Clmmpool::try_from_slice(data_slice).unwrap().get_ui_info(account.0));
    };

    let color = Color::try_from(" ".cyan().to_string()).unwrap();

    Ok(Table::new(list)
        .with(Style::modern())
        .with(color)
        .with(Panel("Pool List", 0))
        .with(Modify::new(Segment::all()).with(Alignment::center()))
        .to_string())
}