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
use solana_client::rpc_client::RpcClient;
use solana_program::pubkey::Pubkey;

use spl_associated_token_account::get_associated_token_address;

use common::command::{CliConfig, ProcessResult};
use common::contract::instructions::collect_partner_fee::new_collect_partner_fee;
use common::contract::state::clmmpools::Clmmpool;
use common::utils::send::send_tx;

pub fn process(
    rpc_client: &RpcClient,
    config: &CliConfig,
    partner: &Pubkey,
    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 token_a_partner_fee_vault = get_associated_token_address(&partner, &clmmpool_info.token_a);
    let token_b_partner_fee_vault = get_associated_token_address(&partner, &clmmpool_info.token_b);

    let ixs = [new_collect_partner_fee(
        partner,
        clmmpool,
        &token_a_ata,
        &token_b_ata,
        &token_a_partner_fee_vault,
        &token_b_partner_fee_vault,
        config.pubkey().unwrap(),
    )];

    let res = send_tx(rpc_client, config, &ixs)?;

    Ok("signers : ".to_owned() + res.to_string().as_str())
}