clmm-common 0.1.39

Blockchain, Clmm for Solana
Documentation
use borsh::{BorshDeserialize, BorshSerialize};
use solana_program::instruction::{AccountMeta, Instruction};
use solana_program::pubkey::Pubkey;

use crate::program::SWAP_PROGRAM_ID;
use crate::utils::sighash;

#[derive(BorshSerialize, BorshDeserialize, PartialEq, Debug, Clone)]
pub struct IncreaseLiquidityWithFixedTokenArgs {
    pub token_a: u64,
    pub token_b: u64,
    pub is_a_fixed: bool,
}

pub fn new_increase_liquidity_with_fixed_token(
    clmmpool: &Pubkey,
    position: &Pubkey,
    position_ata: &Pubkey,
    token_a_ata: &Pubkey,
    token_b_ata: &Pubkey,
    token_a_vault: &Pubkey,
    token_b_vault: &Pubkey,
    tick_array_lower: &Pubkey,
    tick_array_upper: &Pubkey,
    tick_array_map: &Pubkey,
    token_a: u64,
    token_b: u64,
    is_a_fixed: bool,
    payer: Pubkey,
) -> Instruction {
    let data = &IncreaseLiquidityWithFixedTokenArgs {
        token_a,
        token_b,
        is_a_fixed,
    };

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

    Instruction {
        program_id: SWAP_PROGRAM_ID,
        accounts: vec![
            AccountMeta::new(payer, true),
            AccountMeta::new(*clmmpool, false),
            AccountMeta::new(*position, false),
            AccountMeta::new_readonly(*position_ata, false),
            AccountMeta::new(*token_a_ata, false),
            AccountMeta::new(*token_b_ata, false),
            AccountMeta::new(*token_a_vault, false),
            AccountMeta::new(*token_b_vault, false),
            AccountMeta::new(*tick_array_lower, false),
            AccountMeta::new(*tick_array_upper, false),
            AccountMeta::new(*tick_array_map, false),
            AccountMeta::new_readonly(spl_token::id(), false),
        ],
        data: distor,
    }
}