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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
use solana_client::rpc_client::RpcClient;
use solana_program::instruction::Instruction;
use solana_program::pubkey::Pubkey;
use spl_associated_token_account::get_associated_token_address;
use common::command::{CliConfig, Parse, ProcessResult};
use common::contract::instructions::create_clmmpools::new_create_clmmpool;
use common::contract::instructions::create_tick_array_map::new_create_tick_array_map;
use common::contract::state::fee_tier::FeeTier;
use common::program::SWAP_PROGRAM_ID;
use common::utils::send::send_tx;
pub fn process_create_pool(
rpc_client: &RpcClient,
config: &CliConfig,
) -> ProcessResult {
let clmm_config = Parse::new("clmm_config address", true).to_pubkey()?;
let fee_tier = Parse::new("fee_tier address", true).to_pubkey()?;
let token_a = Parse::new("token_a mint address", true).to_pubkey()?;
let token_b = Parse::new("token_b mint address", true).to_pubkey()?;
let init_sqrt_price = Parse::new("init_sqrt_price", true).to_u128()?;
Parse::confirm()?;
let fee_tier_info = FeeTier::get_info(
rpc_client,
&fee_tier,
);
let (clmmpool_pubkey, _) = Pubkey::find_program_address(
&[
b"clmmpool",
clmm_config.as_ref(),
token_a.as_ref(),
token_b.as_ref(),
fee_tier_info.tick_spacing.to_le_bytes().as_ref(),
],
&SWAP_PROGRAM_ID,
);
let token_a_vault = get_associated_token_address(
&clmmpool_pubkey,
&token_a,
);
let token_b_vault = get_associated_token_address(
&clmmpool_pubkey,
&token_b,
);
let mut ixs: Vec<Instruction> = Vec::new();
ixs.push(new_create_clmmpool(
clmm_config,
fee_tier,
token_a,
token_b,
init_sqrt_price,
clmmpool_pubkey,
token_a_vault,
token_b_vault,
config.pubkey().unwrap(),
));
let (tick_array_map_pubkey, _) = Pubkey::find_program_address(
&[b"tick_array_map", clmmpool_pubkey.as_ref()],
&SWAP_PROGRAM_ID,
);
ixs.push(new_create_tick_array_map(
clmmpool_pubkey,
tick_array_map_pubkey,
config.pubkey().unwrap(),
));
let res = send_tx(rpc_client, config, &ixs)?;
println!("pool key: {}", clmmpool_pubkey.to_string());
Ok("signers : ".to_owned() + res.to_string().as_str())
}