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
use std::str::FromStr;
use std::sync::Arc;
use clap::ArgMatches;
use solana_clap_utils::keypair::DefaultSigner;
use solana_client::rpc_client::RpcClient;
use solana_program::pubkey::Pubkey;
use solana_remote_wallet::remote_wallet::RemoteWalletManager;
use spl_associated_token_account::get_associated_token_address;
use crate::check_and_update_err;
use common::command::{CliCommand, CliCommandInfo, CliConfig, CliError, ProcessResult};
use common::contract::instructions::collect_protocol_fee::new_collect_protocol_fee;
use common::contract::state::clmmpools::Clmmpool;
use common::utils::send::send_tx;
pub fn parse_collect_protocol_fee<'a>(matches: &'a ArgMatches, default_signer: Box<DefaultSigner>, mut wallet_manager: Box<Option<Arc<RemoteWalletManager>>>) -> Result<CliCommandInfo, CliError> {
let clmmpool = matches.value_of("clmmpool");
Ok(CliCommandInfo {
command: Box::new(CliCommand::PairCollectProtocolFee {
clmmpool: Pubkey::from_str(clmmpool.unwrap()).unwrap(),
}),
signers: vec![check_and_update_err!(default_signer.signer_from_path(matches, wallet_manager.as_mut()), CliError::RpcRequestError("owner key is invalid".to_string()))?],
})
}
pub fn process_collect_protocol_fee(
rpc_client: &RpcClient,
config: &CliConfig,
clmmpool: &Pubkey,
) -> ProcessResult {
let clmmpool_info = Clmmpool::get_info(rpc_client, clmmpool);
let token_a_ata = get_associated_token_address(&config.pubkey().unwrap(), &clmmpool_info.token_a);
let token_b_ata = get_associated_token_address(&config.pubkey().unwrap(), &clmmpool_info.token_b);
let ixs = [
new_collect_protocol_fee(
&clmmpool_info.clmm_config,
clmmpool,
&token_a_ata,
&token_b_ata,
&clmmpool_info.token_a_vault,
&clmmpool_info.token_b_vault,
config.pubkey().unwrap(),
)
];
let res = send_tx(rpc_client, config, &ixs)?;
Ok("signers : ".to_owned() + res.to_string().as_str())
}