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

use solana_sdk::signature::{Keypair, Signer};
use spl_associated_token_account::get_associated_token_address;

use common::command::{CliConfig, ProcessResult};
use common::contract::instructions::open_position::new_open_position;
use common::program::SWAP_PROGRAM_ID;
use common::utils::send::send_tx;

pub fn process(
    rpc_client: &RpcClient,
    config: &mut CliConfig,
    clmmpool: &Pubkey,
    tick_lower_index: &i32,
    tick_upper_index: &i32,
) -> ProcessResult {
    let position_nft_mint = Keypair::new();
    let position_nft_mint_pubkey = position_nft_mint.pubkey();
    let position_metadata_account =
        mpl_token_metadata::pda::find_metadata_account(&position_nft_mint_pubkey);
    let edition = mpl_token_metadata::pda::find_master_edition_account(&position_nft_mint_pubkey);

    let position_ata =
        get_associated_token_address(&config.pubkey().unwrap(), &position_nft_mint_pubkey);

    config.signers.push(Box::new(position_nft_mint));

    let (position_pubkey, _) = Pubkey::find_program_address(
        &[b"position", position_nft_mint_pubkey.as_ref()],
        &SWAP_PROGRAM_ID,
    );

    let ixs = [new_open_position(
        rpc_client,
        clmmpool,
        &position_pubkey,
        &position_nft_mint_pubkey,
        &position_metadata_account.0,
        &edition.0,
        &position_ata,
        tick_lower_index,
        tick_upper_index,
        config.pubkey().unwrap(),
    )];

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

    println!(
        "position nft mint key: {}",
        position_nft_mint_pubkey.to_string()
    );
    println!("position key: {}", position_pubkey.to_string());

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