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 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 crate::command::{CliCommand, CliCommandInfo, CliConfig, CliError, ProcessResult};
use crate::contract::instructions::remove_position::new_remove_position;
use crate::contract::state::position::Position;
use crate::program::get_pubkey_for_program_with_seeds;
use crate::utils::send::send_tx;
pub fn parse_remove_position<'a>(matches: &'a ArgMatches, default_signer: &DefaultSigner, wallet_manager: &mut Option<Arc<RemoteWalletManager>>) -> Result<CliCommandInfo<'a>, CliError> {
let mint = matches.value_of("mint");
Ok(CliCommandInfo {
command: CliCommand::PositionRemove {
mint: Pubkey::from_str(mint.unwrap()).unwrap(),
},
signers: vec![check_and_update_err!(default_signer.signer_from_path(matches, wallet_manager), CliError::RpcRequestError("owner key is invalid".to_string()))?],
})
}
pub fn process_remove_position(
rpc_client: &RpcClient,
config: &CliConfig,
mint: &Pubkey,
) -> ProcessResult {
let (position, _) = get_pubkey_for_program_with_seeds(&[b"position", mint.as_ref()]);
let position_info = Position::get_info(rpc_client, &position);
let position_ata = get_associated_token_address(&config.pubkey().unwrap(), &position_info.position_nft_mint);
let ixs = [new_remove_position(&position, &position_info.position_nft_mint, &position_ata, config.pubkey().unwrap())];
let res = send_tx(rpc_client, config, &ixs)?;
Ok("signers : ".to_owned() + res.to_string().as_str())
}