use borsh::{BorshDeserialize, BorshSerialize};
use solana_program::instruction::{AccountMeta, Instruction};
use solana_program::pubkey::Pubkey;
use crate::program::{POSITION_NFT_UPDATE_AUTHORITY, PROGRAM_ID};
use crate::utils::sighash;
#[derive(BorshSerialize, BorshDeserialize, PartialEq, Debug, Clone)]
pub struct OpenPositionArgs {
pub tick_lower_index: i32,
pub tick_upper_index: i32,
}
pub fn new_open_position(
clmmpool: &Pubkey,
position: &Pubkey,
position_nft_mint: &Pubkey,
position_metadata_account: &Pubkey,
position_ata: &Pubkey,
tick_lower_index: &i32,
tick_upper_index: &i32,
payer: Pubkey,
) -> Instruction {
let data = &OpenPositionArgs {
tick_lower_index: *tick_lower_index,
tick_upper_index: *tick_upper_index,
};
let mut dsa = data.try_to_vec().unwrap();
let mut distor = sighash::sighash("global", "open_position").to_vec();
distor.append(&mut dsa);
Instruction {
program_id: PROGRAM_ID,
accounts: vec![
AccountMeta::new(payer, true),
AccountMeta::new(*clmmpool, false),
AccountMeta::new(*position, false),
AccountMeta::new(*position_nft_mint, true),
AccountMeta::new(*position_metadata_account, false),
AccountMeta::new_readonly(*POSITION_NFT_UPDATE_AUTHORITY, false),
AccountMeta::new(*position_ata, false),
AccountMeta::new_readonly(spl_token::id(), false),
AccountMeta::new_readonly(spl_associated_token_account::id(), false),
AccountMeta::new_readonly(mpl_token_metadata::id(), false),
AccountMeta::new_readonly(solana_program::system_program::id(), false),
AccountMeta::new_readonly(solana_program::sysvar::rent::id(), false),
],
data: distor,
}
}