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
use std::str::FromStr;
use borsh::{BorshDeserialize, BorshSerialize};
use solana_program::instruction::AccountMeta;
use solana_program::pubkey::Pubkey;
use solana_sdk::instruction::Instruction;
use crate::clmmpool::pair::create_pool::ClmmpoolTemplate;
use crate::program::PROGRAM_ID;
use crate::utils::sighash;
#[derive(BorshSerialize, BorshDeserialize, PartialEq, Debug, Clone)]
pub struct CreateClmmpoolArgs {
pub init_sqrt_price: u128,
}
pub fn new_create_clmmpool(
template: &ClmmpoolTemplate,
clmmpool_pubkey: &Pubkey,
token_a_vault: &Pubkey,
token_b_vault: &Pubkey,
payer: Pubkey,
) -> Instruction {
let data = &CreateClmmpoolArgs {
init_sqrt_price: template.init_sqrt_price,
};
let mut dsa = data.try_to_vec().unwrap();
let mut distor = sighash::sighash("global", "create_clmmpool").to_vec();
distor.append(&mut dsa);
Instruction {
program_id: PROGRAM_ID,
accounts: vec![
AccountMeta::new(payer, true),
AccountMeta::new_readonly(
Pubkey::from_str(template.clmm_config.as_str()).unwrap(),
false,
),
AccountMeta::new_readonly(Pubkey::from_str(template.fee_tier.as_str()).unwrap(), false),
AccountMeta::new(*clmmpool_pubkey, false),
AccountMeta::new_readonly(Pubkey::from_str(template.token_a.as_str()).unwrap(), false),
AccountMeta::new_readonly(Pubkey::from_str(template.token_b.as_str()).unwrap(), false),
AccountMeta::new(*token_a_vault, false),
AccountMeta::new(*token_b_vault, false),
AccountMeta::new_readonly(spl_token::id(), false),
AccountMeta::new_readonly(spl_associated_token_account::id(), false),
AccountMeta::new_readonly(solana_program::system_program::id(), false),
AccountMeta::new_readonly(solana_program::sysvar::rent::id(), false),
],
data: distor,
}
}