use solana_client::rpc_client::RpcClient;
use solana_program::pubkey::Pubkey;
use solana_sdk::signature::{Keypair, Signer};
use spl_associated_token_account::instruction::create_associated_token_account;
use common::command::{CliConfig, ProcessResult};
use common::contract::instructions::farming::quarry_mine::new_rewarder::new_rewarder;
use common::contract::state::farming::mint_wrapper::MintWrapper;
use common::program::MINE_PROGRAM_ID;
use common::utils::send::send_tx;
pub fn process_farming_mine_rewarder_new(
rpc_client: &RpcClient,
config: &CliConfig,
wrapper: Pubkey,
annual_rate: u64,
) -> ProcessResult {
let base = Keypair::new();
let (rewarder, _) = Pubkey::find_program_address(
&[
b"Rewarder",
base.pubkey().as_ref(),
],
&MINE_PROGRAM_ID,
);
let mint_wrapper_info = MintWrapper::get_info(rpc_client, &wrapper);
let mut ixs = Vec::new();
let (claim_fee_token_account, _) = Pubkey::find_program_address(
&[
rewarder.as_ref(),
spl_token::id().as_ref(),
mint_wrapper_info.token_mint.as_ref(),
],
&MINE_PROGRAM_ID,
);
if rpc_client.get_account(&claim_fee_token_account).is_err() {
ixs.push(create_associated_token_account(
&claim_fee_token_account,
&rewarder,
&mint_wrapper_info.token_mint,
&spl_token::id()
));
}
ixs.push(new_rewarder(
base.pubkey(),
config.pubkey().unwrap(),
rewarder,
config.pubkey().unwrap(),
wrapper,
mint_wrapper_info.token_mint,
claim_fee_token_account,
annual_rate,
));
let res = send_tx(rpc_client, config, &ixs)?;
Ok("signers : ".to_owned() + res.to_string().as_str())
}