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
use std::str::FromStr;

use borsh::{BorshDeserialize, BorshSerialize};
use solana_program::instruction::{AccountMeta, Instruction};
use solana_program::pubkey::Pubkey;

use crate::clmmpool::pair::create_tick_array::TickArrayTemplate;
use crate::program::PROGRAM_ID;
use crate::utils::sighash;

#[derive(BorshSerialize, BorshDeserialize, PartialEq, Debug, Clone)]
pub struct CreateTickArrayArgs {
    pub array_index: u16,
}

pub fn new_create_tick_array(
    template: &TickArrayTemplate,
    tick_array_pubkey: Pubkey,
    payer: Pubkey,
) -> Instruction {
    let data = &CreateTickArrayArgs {
        array_index: template.array_index,
    };

    let mut dsa = data.try_to_vec().unwrap();
    let mut distor = sighash::sighash("global", "create_tick_array").to_vec();
    distor.append(&mut dsa);

    Instruction {
        program_id: PROGRAM_ID,
        accounts: vec![
            AccountMeta::new(payer, true),
            AccountMeta::new_readonly(Pubkey::from_str(template.clmmpool.as_str()).unwrap(), false),
            AccountMeta::new(tick_array_pubkey, false),
            AccountMeta::new_readonly(solana_program::system_program::id(), false),
            AccountMeta::new_readonly(solana_program::sysvar::rent::id(), false),
        ],
        data: distor,
    }
}