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
59
60
61
62
63
64
65
66
67
68
69
use std::sync::Arc;
use clap::ArgMatches;
use colored::Colorize;
use solana_clap_utils::keypair::DefaultSigner;
use solana_client::rpc_client::RpcClient;
use solana_remote_wallet::remote_wallet::RemoteWalletManager;
use solana_sdk::pubkey::Pubkey;
use tabled::{Alignment, Modify, Panel, Rotate, Style, Table, Tabled};
use tabled::object::Segment;
use tabled::style::Color;
use crate::check_and_update_err;
use crate::command::{CliCommand, CliCommandInfo, CliError, ProcessResult};
use crate::contract::state::clmmpools::Clmmpool;
pub fn parse_tick_map_info<'a>(
matches: &ArgMatches,
default_signer: &DefaultSigner,
wallet_manager: &mut Option<Arc<RemoteWalletManager>>,
) -> Result<CliCommandInfo<'a>, CliError> {
let pool = matches.value_of("pool");
let array_index = matches.value_of("array_index");
Ok(CliCommandInfo {
command: CliCommand::TickMapInfo {
pool: pool.unwrap().parse::<Pubkey>().unwrap(),
array_index: array_index.unwrap().parse::<u16>().unwrap(),
},
signers: vec![check_and_update_err!(
default_signer.signer_from_path(matches, wallet_manager),
CliError::RpcRequestError("owner key is invalid".to_string())
)?],
})
}
#[derive(Debug, Tabled)]
pub struct TickMap {
pre: String,
current: String,
post: String,
}
pub fn process_tick_map_info(
rpc_client: &RpcClient,
array_index: u16,
pool: &Pubkey,
) -> ProcessResult {
let tick_map_address = Clmmpool::get_tick_map_address(pool);
let data = rpc_client.get_account_data(&tick_map_address).unwrap();
let word: usize = array_index as usize / 8 + 8 as usize;
let map = TickMap {
pre: format!("{:08b}", data[word - 1]),
current: format!("{:08b}", data[word]),
post: format!("{:08b}", data[word + 1]),
};
println!("word_index: {}", array_index / 8);
println!("word_bit: {}", array_index % 8);
let color = Color::try_from(" ".cyan().to_string()).unwrap();
Ok(Table::new(vec![map])
.with(Rotate::Bottom)
.with(Rotate::Right)
.with(Style::modern())
.with(color)
.with(Panel("Tick Map Info", 0))
.with(Modify::new(Segment::all()).with(Alignment::center()))
.to_string())
}