use borsh::BorshSerialize;
use solana_program::{
instruction::{AccountMeta, Instruction},
pubkey::Pubkey,
};
use crate::constants::*;
use crate::pda;
use super::types::*;
#[derive(BorshSerialize, Clone, Debug)]
pub struct BuyExactInArgs {
pub amount_in: u64,
pub minimum_amount_out: u64,
pub share_fee_rate: u64,
}
pub fn buy_exact_in(
payer: &Pubkey,
global_config: &Pubkey,
platform_config: &Pubkey,
pool_state: &Pubkey,
user_base_token: &Pubkey,
user_quote_token: &Pubkey,
base_vault: &Pubkey,
quote_vault: &Pubkey,
base_token_mint: &Pubkey,
quote_token_mint: &Pubkey,
base_token_program: &Pubkey,
amount_in: u64,
minimum_amount_out: u64,
share_fee_rate: u64,
) -> Instruction {
let (authority, _) = pda::get_authority_pda();
let (event_authority, _) = pda::get_event_authority_pda();
let accounts = vec![
AccountMeta::new(*payer, true),
AccountMeta::new_readonly(authority, false),
AccountMeta::new_readonly(*global_config, false),
AccountMeta::new_readonly(*platform_config, false),
AccountMeta::new(*pool_state, false),
AccountMeta::new(*user_base_token, false),
AccountMeta::new(*user_quote_token, false),
AccountMeta::new(*base_vault, false),
AccountMeta::new(*quote_vault, false),
AccountMeta::new_readonly(*base_token_mint, false),
AccountMeta::new_readonly(*quote_token_mint, false),
AccountMeta::new_readonly(*base_token_program, false),
AccountMeta::new_readonly(TOKEN_PROGRAM_ID, false),
AccountMeta::new_readonly(event_authority, false),
AccountMeta::new_readonly(PROGRAM_ID, false),
];
let mut data = discriminators::BUY_EXACT_IN.to_vec();
let args = BuyExactInArgs {
amount_in,
minimum_amount_out,
share_fee_rate,
};
args.serialize(&mut data).unwrap();
Instruction {
program_id: PROGRAM_ID,
accounts,
data,
}
}
#[derive(BorshSerialize, Clone, Debug)]
pub struct BuyExactOutArgs {
pub amount_out: u64,
pub maximum_amount_in: u64,
pub share_fee_rate: u64,
}
pub fn buy_exact_out(
payer: &Pubkey,
global_config: &Pubkey,
platform_config: &Pubkey,
pool_state: &Pubkey,
user_base_token: &Pubkey,
user_quote_token: &Pubkey,
base_vault: &Pubkey,
quote_vault: &Pubkey,
base_token_mint: &Pubkey,
quote_token_mint: &Pubkey,
base_token_program: &Pubkey,
amount_out: u64,
maximum_amount_in: u64,
share_fee_rate: u64,
) -> Instruction {
let (authority, _) = pda::get_authority_pda();
let (event_authority, _) = pda::get_event_authority_pda();
let accounts = vec![
AccountMeta::new(*payer, true),
AccountMeta::new_readonly(authority, false),
AccountMeta::new_readonly(*global_config, false),
AccountMeta::new_readonly(*platform_config, false),
AccountMeta::new(*pool_state, false),
AccountMeta::new(*user_base_token, false),
AccountMeta::new(*user_quote_token, false),
AccountMeta::new(*base_vault, false),
AccountMeta::new(*quote_vault, false),
AccountMeta::new_readonly(*base_token_mint, false),
AccountMeta::new_readonly(*quote_token_mint, false),
AccountMeta::new_readonly(*base_token_program, false),
AccountMeta::new_readonly(TOKEN_PROGRAM_ID, false),
AccountMeta::new_readonly(event_authority, false),
AccountMeta::new_readonly(PROGRAM_ID, false),
];
let mut data = discriminators::BUY_EXACT_OUT.to_vec();
let args = BuyExactOutArgs {
amount_out,
maximum_amount_in,
share_fee_rate,
};
args.serialize(&mut data).unwrap();
Instruction {
program_id: PROGRAM_ID,
accounts,
data,
}
}
#[derive(BorshSerialize, Clone, Debug)]
pub struct SellExactInArgs {
pub amount_in: u64,
pub minimum_amount_out: u64,
pub share_fee_rate: u64,
}
pub fn sell_exact_in(
payer: &Pubkey,
global_config: &Pubkey,
platform_config: &Pubkey,
pool_state: &Pubkey,
user_base_token: &Pubkey,
user_quote_token: &Pubkey,
base_vault: &Pubkey,
quote_vault: &Pubkey,
base_token_mint: &Pubkey,
quote_token_mint: &Pubkey,
base_token_program: &Pubkey,
amount_in: u64,
minimum_amount_out: u64,
share_fee_rate: u64,
) -> Instruction {
let (authority, _) = pda::get_authority_pda();
let (event_authority, _) = pda::get_event_authority_pda();
let accounts = vec![
AccountMeta::new(*payer, true),
AccountMeta::new_readonly(authority, false),
AccountMeta::new_readonly(*global_config, false),
AccountMeta::new_readonly(*platform_config, false),
AccountMeta::new(*pool_state, false),
AccountMeta::new(*user_base_token, false),
AccountMeta::new(*user_quote_token, false),
AccountMeta::new(*base_vault, false),
AccountMeta::new(*quote_vault, false),
AccountMeta::new_readonly(*base_token_mint, false),
AccountMeta::new_readonly(*quote_token_mint, false),
AccountMeta::new_readonly(*base_token_program, false),
AccountMeta::new_readonly(TOKEN_PROGRAM_ID, false),
AccountMeta::new_readonly(event_authority, false),
AccountMeta::new_readonly(PROGRAM_ID, false),
];
let mut data = discriminators::SELL_EXACT_IN.to_vec();
let args = SellExactInArgs {
amount_in,
minimum_amount_out,
share_fee_rate,
};
args.serialize(&mut data).unwrap();
Instruction {
program_id: PROGRAM_ID,
accounts,
data,
}
}
#[derive(BorshSerialize, Clone, Debug)]
pub struct SellExactOutArgs {
pub amount_out: u64,
pub maximum_amount_in: u64,
pub share_fee_rate: u64,
}
pub fn sell_exact_out(
payer: &Pubkey,
global_config: &Pubkey,
platform_config: &Pubkey,
pool_state: &Pubkey,
user_base_token: &Pubkey,
user_quote_token: &Pubkey,
base_vault: &Pubkey,
quote_vault: &Pubkey,
base_token_mint: &Pubkey,
quote_token_mint: &Pubkey,
base_token_program: &Pubkey,
amount_out: u64,
maximum_amount_in: u64,
share_fee_rate: u64,
) -> Instruction {
let (authority, _) = pda::get_authority_pda();
let (event_authority, _) = pda::get_event_authority_pda();
let accounts = vec![
AccountMeta::new(*payer, true),
AccountMeta::new_readonly(authority, false),
AccountMeta::new_readonly(*global_config, false),
AccountMeta::new_readonly(*platform_config, false),
AccountMeta::new(*pool_state, false),
AccountMeta::new(*user_base_token, false),
AccountMeta::new(*user_quote_token, false),
AccountMeta::new(*base_vault, false),
AccountMeta::new(*quote_vault, false),
AccountMeta::new_readonly(*base_token_mint, false),
AccountMeta::new_readonly(*quote_token_mint, false),
AccountMeta::new_readonly(*base_token_program, false),
AccountMeta::new_readonly(TOKEN_PROGRAM_ID, false),
AccountMeta::new_readonly(event_authority, false),
AccountMeta::new_readonly(PROGRAM_ID, false),
];
let mut data = discriminators::SELL_EXACT_OUT.to_vec();
let args = SellExactOutArgs {
amount_out,
maximum_amount_in,
share_fee_rate,
};
args.serialize(&mut data).unwrap();
Instruction {
program_id: PROGRAM_ID,
accounts,
data,
}
}
#[derive(BorshSerialize, Clone, Debug)]
pub struct InitializeArgs {
pub base_mint_param: MintParams,
pub curve_param: CurveParams,
pub vesting_param: VestingParams,
}
pub fn initialize(
payer: &Pubkey,
creator: &Pubkey,
global_config: &Pubkey,
platform_config: &Pubkey,
base_mint: &Pubkey,
quote_mint: &Pubkey,
base_mint_param: MintParams,
curve_param: CurveParams,
vesting_param: VestingParams,
) -> Instruction {
let (authority, _) = pda::get_authority_pda();
let (pool_state, _) = pda::get_pool_state_pda(base_mint, quote_mint);
let (base_vault, _) = pda::get_pool_vault_pda(&pool_state, base_mint);
let (quote_vault, _) = pda::get_pool_vault_pda(&pool_state, quote_mint);
let (metadata_account, _) = pda::get_metadata_address(base_mint);
let (event_authority, _) = pda::get_event_authority_pda();
let accounts = vec![
AccountMeta::new(*payer, true),
AccountMeta::new_readonly(*creator, false),
AccountMeta::new_readonly(*global_config, false),
AccountMeta::new_readonly(*platform_config, false),
AccountMeta::new_readonly(authority, false),
AccountMeta::new(pool_state, false),
AccountMeta::new(*base_mint, true),
AccountMeta::new_readonly(*quote_mint, false),
AccountMeta::new(base_vault, false),
AccountMeta::new(quote_vault, false),
AccountMeta::new(metadata_account, false),
AccountMeta::new_readonly(TOKEN_PROGRAM_ID, false),
AccountMeta::new_readonly(TOKEN_PROGRAM_ID, false),
AccountMeta::new_readonly(METADATA_PROGRAM_ID, false),
AccountMeta::new_readonly(SYSTEM_PROGRAM_ID, false),
AccountMeta::new_readonly(RENT_PROGRAM_ID, false),
AccountMeta::new_readonly(event_authority, false),
AccountMeta::new_readonly(PROGRAM_ID, false),
];
let mut data = discriminators::INITIALIZE.to_vec();
let args = InitializeArgs {
base_mint_param,
curve_param,
vesting_param,
};
args.serialize(&mut data).unwrap();
Instruction {
program_id: PROGRAM_ID,
accounts,
data,
}
}
#[derive(BorshSerialize, Clone, Debug)]
pub struct InitializeV2Args {
pub base_mint_param: MintParams,
pub curve_param: CurveParams,
pub vesting_param: VestingParams,
pub amm_fee_on: AmmCreatorFeeOn,
}
pub fn initialize_v2(
payer: &Pubkey,
creator: &Pubkey,
global_config: &Pubkey,
platform_config: &Pubkey,
base_mint: &Pubkey,
quote_mint: &Pubkey,
base_mint_param: MintParams,
curve_param: CurveParams,
vesting_param: VestingParams,
amm_fee_on: AmmCreatorFeeOn,
) -> Instruction {
let (authority, _) = pda::get_authority_pda();
let (pool_state, _) = pda::get_pool_state_pda(base_mint, quote_mint);
let (base_vault, _) = pda::get_pool_vault_pda(&pool_state, base_mint);
let (quote_vault, _) = pda::get_pool_vault_pda(&pool_state, quote_mint);
let (metadata_account, _) = pda::get_metadata_address(base_mint);
let (event_authority, _) = pda::get_event_authority_pda();
let accounts = vec![
AccountMeta::new(*payer, true),
AccountMeta::new_readonly(*creator, false),
AccountMeta::new_readonly(*global_config, false),
AccountMeta::new_readonly(*platform_config, false),
AccountMeta::new_readonly(authority, false),
AccountMeta::new(pool_state, false),
AccountMeta::new(*base_mint, true),
AccountMeta::new_readonly(*quote_mint, false),
AccountMeta::new(base_vault, false),
AccountMeta::new(quote_vault, false),
AccountMeta::new(metadata_account, false),
AccountMeta::new_readonly(TOKEN_PROGRAM_ID, false),
AccountMeta::new_readonly(TOKEN_PROGRAM_ID, false),
AccountMeta::new_readonly(METADATA_PROGRAM_ID, false),
AccountMeta::new_readonly(SYSTEM_PROGRAM_ID, false),
AccountMeta::new_readonly(RENT_PROGRAM_ID, false),
AccountMeta::new_readonly(event_authority, false),
AccountMeta::new_readonly(PROGRAM_ID, false),
];
let mut data = discriminators::INITIALIZE_V2.to_vec();
let args = InitializeV2Args {
base_mint_param,
curve_param,
vesting_param,
amm_fee_on,
};
args.serialize(&mut data).unwrap();
Instruction {
program_id: PROGRAM_ID,
accounts,
data,
}
}
pub fn claim_creator_fee(
creator: &Pubkey,
quote_mint: &Pubkey,
) -> Instruction {
let (fee_vault_authority, _) = pda::get_creator_fee_vault_authority_pda();
let (creator_fee_vault, _) = pda::get_creator_fee_vault_pda(creator, quote_mint);
let recipient_token_account = pda::get_associated_token_address(creator, quote_mint);
let accounts = vec![
AccountMeta::new(*creator, true),
AccountMeta::new_readonly(fee_vault_authority, false),
AccountMeta::new(creator_fee_vault, false),
AccountMeta::new(recipient_token_account, false),
AccountMeta::new_readonly(*quote_mint, false),
AccountMeta::new_readonly(TOKEN_PROGRAM_ID, false),
AccountMeta::new_readonly(SYSTEM_PROGRAM_ID, false),
AccountMeta::new_readonly(ASSOCIATED_TOKEN_PROGRAM_ID, false),
];
let data = discriminators::CLAIM_CREATOR_FEE.to_vec();
Instruction {
program_id: PROGRAM_ID,
accounts,
data,
}
}
pub fn claim_platform_fee(
platform_fee_wallet: &Pubkey,
pool_state: &Pubkey,
platform_config: &Pubkey,
quote_vault: &Pubkey,
quote_mint: &Pubkey,
) -> Instruction {
let (authority, _) = pda::get_authority_pda();
let recipient_token_account = pda::get_associated_token_address(platform_fee_wallet, quote_mint);
let accounts = vec![
AccountMeta::new(*platform_fee_wallet, true),
AccountMeta::new_readonly(authority, false),
AccountMeta::new(*pool_state, false),
AccountMeta::new_readonly(*platform_config, false),
AccountMeta::new(*quote_vault, false),
AccountMeta::new(recipient_token_account, false),
AccountMeta::new_readonly(*quote_mint, false),
AccountMeta::new_readonly(TOKEN_PROGRAM_ID, false),
AccountMeta::new_readonly(SYSTEM_PROGRAM_ID, false),
AccountMeta::new_readonly(ASSOCIATED_TOKEN_PROGRAM_ID, false),
];
let data = discriminators::CLAIM_PLATFORM_FEE.to_vec();
Instruction {
program_id: PROGRAM_ID,
accounts,
data,
}
}
pub fn claim_platform_fee_from_vault(
platform_fee_wallet: &Pubkey,
platform_config: &Pubkey,
quote_mint: &Pubkey,
) -> Instruction {
let (fee_vault_authority, _) = pda::get_platform_fee_vault_authority_pda();
let (platform_fee_vault, _) = pda::get_platform_fee_vault_pda(platform_config, quote_mint);
let recipient_token_account = pda::get_associated_token_address(platform_fee_wallet, quote_mint);
let accounts = vec![
AccountMeta::new(*platform_fee_wallet, true),
AccountMeta::new_readonly(fee_vault_authority, false),
AccountMeta::new_readonly(*platform_config, false),
AccountMeta::new(platform_fee_vault, false),
AccountMeta::new(recipient_token_account, false),
AccountMeta::new_readonly(*quote_mint, false),
AccountMeta::new_readonly(TOKEN_PROGRAM_ID, false),
AccountMeta::new_readonly(SYSTEM_PROGRAM_ID, false),
AccountMeta::new_readonly(ASSOCIATED_TOKEN_PROGRAM_ID, false),
];
let data = discriminators::CLAIM_PLATFORM_FEE_FROM_VAULT.to_vec();
Instruction {
program_id: PROGRAM_ID,
accounts,
data,
}
}
pub fn collect_fee(
owner: &Pubkey,
pool_state: &Pubkey,
global_config: &Pubkey,
quote_vault: &Pubkey,
quote_mint: &Pubkey,
recipient_token_account: &Pubkey,
) -> Instruction {
let (authority, _) = pda::get_authority_pda();
let accounts = vec![
AccountMeta::new_readonly(*owner, true),
AccountMeta::new_readonly(authority, false),
AccountMeta::new(*pool_state, false),
AccountMeta::new_readonly(*global_config, false),
AccountMeta::new(*quote_vault, false),
AccountMeta::new_readonly(*quote_mint, false),
AccountMeta::new(*recipient_token_account, false),
AccountMeta::new_readonly(TOKEN_PROGRAM_ID, false),
];
let data = discriminators::COLLECT_FEE.to_vec();
Instruction {
program_id: PROGRAM_ID,
accounts,
data,
}
}
pub fn collect_migrate_fee(
owner: &Pubkey,
pool_state: &Pubkey,
global_config: &Pubkey,
quote_vault: &Pubkey,
quote_mint: &Pubkey,
recipient_token_account: &Pubkey,
) -> Instruction {
let (authority, _) = pda::get_authority_pda();
let accounts = vec![
AccountMeta::new_readonly(*owner, true),
AccountMeta::new_readonly(authority, false),
AccountMeta::new(*pool_state, false),
AccountMeta::new_readonly(*global_config, false),
AccountMeta::new(*quote_vault, false),
AccountMeta::new_readonly(*quote_mint, false),
AccountMeta::new(*recipient_token_account, false),
AccountMeta::new_readonly(TOKEN_PROGRAM_ID, false),
];
let data = discriminators::COLLECT_MIGRATE_FEE.to_vec();
Instruction {
program_id: PROGRAM_ID,
accounts,
data,
}
}
#[derive(BorshSerialize, Clone, Debug)]
pub struct CreateVestingAccountArgs {
pub share_amount: u64,
}
pub fn create_vesting_account(
creator: &Pubkey,
beneficiary: &Pubkey,
pool_state: &Pubkey,
share_amount: u64,
) -> Instruction {
let (vesting_record, _) = pda::get_vesting_record_pda(pool_state, beneficiary);
let accounts = vec![
AccountMeta::new(*creator, true),
AccountMeta::new(*beneficiary, false),
AccountMeta::new(*pool_state, false),
AccountMeta::new(vesting_record, false),
AccountMeta::new_readonly(SYSTEM_PROGRAM_ID, false),
];
let mut data = discriminators::CREATE_VESTING_ACCOUNT.to_vec();
let args = CreateVestingAccountArgs { share_amount };
args.serialize(&mut data).unwrap();
Instruction {
program_id: PROGRAM_ID,
accounts,
data,
}
}
pub fn claim_vested_token(
beneficiary: &Pubkey,
pool_state: &Pubkey,
base_vault: &Pubkey,
base_token_mint: &Pubkey,
) -> Instruction {
let (authority, _) = pda::get_authority_pda();
let (vesting_record, _) = pda::get_vesting_record_pda(pool_state, beneficiary);
let user_base_token = pda::get_associated_token_address(beneficiary, base_token_mint);
let accounts = vec![
AccountMeta::new(*beneficiary, true),
AccountMeta::new_readonly(authority, false),
AccountMeta::new(*pool_state, false),
AccountMeta::new(vesting_record, false),
AccountMeta::new(*base_vault, false),
AccountMeta::new(user_base_token, false),
AccountMeta::new_readonly(*base_token_mint, false),
AccountMeta::new_readonly(TOKEN_PROGRAM_ID, false),
AccountMeta::new_readonly(SYSTEM_PROGRAM_ID, false),
AccountMeta::new_readonly(ASSOCIATED_TOKEN_PROGRAM_ID, false),
];
let data = discriminators::CLAIM_VESTED_TOKEN.to_vec();
Instruction {
program_id: PROGRAM_ID,
accounts,
data,
}
}
#[derive(BorshSerialize, Clone, Debug)]
pub struct CreateConfigArgs {
pub curve_type: u8,
pub index: u16,
pub migrate_fee: u64,
pub trade_fee_rate: u64,
}
pub fn create_config(
owner: &Pubkey,
quote_token_mint: &Pubkey,
protocol_fee_owner: &Pubkey,
migrate_fee_owner: &Pubkey,
migrate_to_amm_wallet: &Pubkey,
migrate_to_cpswap_wallet: &Pubkey,
curve_type: u8,
index: u16,
migrate_fee: u64,
trade_fee_rate: u64,
) -> Instruction {
let (global_config, _) = pda::get_global_config_pda(quote_token_mint, curve_type, index);
let accounts = vec![
AccountMeta::new(*owner, true),
AccountMeta::new(global_config, false),
AccountMeta::new_readonly(*quote_token_mint, false),
AccountMeta::new_readonly(*protocol_fee_owner, false),
AccountMeta::new_readonly(*migrate_fee_owner, false),
AccountMeta::new_readonly(*migrate_to_amm_wallet, false),
AccountMeta::new_readonly(*migrate_to_cpswap_wallet, false),
AccountMeta::new_readonly(SYSTEM_PROGRAM_ID, false),
];
let mut data = discriminators::CREATE_CONFIG.to_vec();
let args = CreateConfigArgs {
curve_type,
index,
migrate_fee,
trade_fee_rate,
};
args.serialize(&mut data).unwrap();
Instruction {
program_id: PROGRAM_ID,
accounts,
data,
}
}
#[derive(BorshSerialize, Clone, Debug)]
pub struct UpdateConfigArgs {
pub param: u8,
pub value: u64,
}
pub fn update_config(
owner: &Pubkey,
global_config: &Pubkey,
param: u8,
value: u64,
) -> Instruction {
let accounts = vec![
AccountMeta::new_readonly(*owner, true),
AccountMeta::new(*global_config, false),
];
let mut data = discriminators::UPDATE_CONFIG.to_vec();
let args = UpdateConfigArgs { param, value };
args.serialize(&mut data).unwrap();
Instruction {
program_id: PROGRAM_ID,
accounts,
data,
}
}
#[derive(BorshSerialize, Clone, Debug)]
pub struct CreatePlatformConfigArgs {
pub platform_params: PlatformParams,
}
pub fn create_platform_config(
platform_admin: &Pubkey,
platform_fee_wallet: &Pubkey,
platform_nft_wallet: &Pubkey,
cpswap_config: &Pubkey,
transfer_fee_extension_authority: &Pubkey,
platform_params: PlatformParams,
) -> Instruction {
let (platform_config, _) = pda::get_platform_config_pda(platform_admin);
let accounts = vec![
AccountMeta::new(*platform_admin, true),
AccountMeta::new_readonly(*platform_fee_wallet, false),
AccountMeta::new_readonly(*platform_nft_wallet, false),
AccountMeta::new(platform_config, false),
AccountMeta::new_readonly(*cpswap_config, false),
AccountMeta::new_readonly(SYSTEM_PROGRAM_ID, false),
AccountMeta::new_readonly(*transfer_fee_extension_authority, false),
];
let mut data = discriminators::CREATE_PLATFORM_CONFIG.to_vec();
let args = CreatePlatformConfigArgs { platform_params };
args.serialize(&mut data).unwrap();
Instruction {
program_id: PROGRAM_ID,
accounts,
data,
}
}
#[derive(BorshSerialize, Clone, Debug)]
pub struct UpdatePlatformConfigArgs {
pub param: PlatformConfigParam,
}
pub fn update_platform_config(
platform_admin: &Pubkey,
param: PlatformConfigParam,
) -> Instruction {
let (platform_config, _) = pda::get_platform_config_pda(platform_admin);
let accounts = vec![
AccountMeta::new_readonly(*platform_admin, true),
AccountMeta::new(platform_config, false),
];
let mut data = discriminators::UPDATE_PLATFORM_CONFIG.to_vec();
let args = UpdatePlatformConfigArgs { param };
args.serialize(&mut data).unwrap();
Instruction {
program_id: PROGRAM_ID,
accounts,
data,
}
}
#[derive(BorshSerialize, Clone, Debug)]
pub struct UpdatePlatformCurveParamArgs {
pub index: u8,
pub bonding_curve_param: BondingCurveParam,
}
pub fn update_platform_curve_param(
platform_admin: &Pubkey,
global_config: &Pubkey,
index: u8,
bonding_curve_param: BondingCurveParam,
) -> Instruction {
let (platform_config, _) = pda::get_platform_config_pda(platform_admin);
let accounts = vec![
AccountMeta::new(*platform_admin, true),
AccountMeta::new(platform_config, false),
AccountMeta::new_readonly(*global_config, false),
AccountMeta::new_readonly(SYSTEM_PROGRAM_ID, false),
];
let mut data = discriminators::UPDATE_PLATFORM_CURVE_PARAM.to_vec();
let args = UpdatePlatformCurveParamArgs {
index,
bonding_curve_param,
};
args.serialize(&mut data).unwrap();
Instruction {
program_id: PROGRAM_ID,
accounts,
data,
}
}
#[derive(BorshSerialize, Clone, Debug)]
pub struct RemovePlatformCurveParamArgs {
pub index: u8,
}
pub fn remove_platform_curve_param(
platform_admin: &Pubkey,
index: u8,
) -> Instruction {
let (platform_config, _) = pda::get_platform_config_pda(platform_admin);
let accounts = vec![
AccountMeta::new_readonly(*platform_admin, true),
AccountMeta::new(platform_config, false),
];
let mut data = discriminators::REMOVE_PLATFORM_CURVE_PARAM.to_vec();
let args = RemovePlatformCurveParamArgs { index };
args.serialize(&mut data).unwrap();
Instruction {
program_id: PROGRAM_ID,
accounts,
data,
}
}
pub fn create_buy_instruction(
payer: &Pubkey,
base_mint: &Pubkey,
quote_mint: &Pubkey,
global_config: &Pubkey,
platform_config: &Pubkey,
amount_in: u64,
minimum_amount_out: u64,
share_fee_rate: u64,
is_token_2022: bool,
) -> Instruction {
let (pool_state, _) = pda::get_pool_state_pda(base_mint, quote_mint);
let (base_vault, _) = pda::get_pool_vault_pda(&pool_state, base_mint);
let (quote_vault, _) = pda::get_pool_vault_pda(&pool_state, quote_mint);
let base_token_program = if is_token_2022 {
TOKEN_2022_PROGRAM_ID
} else {
TOKEN_PROGRAM_ID
};
let user_base_token = if is_token_2022 {
pda::get_associated_token_address_2022(payer, base_mint)
} else {
pda::get_associated_token_address(payer, base_mint)
};
let user_quote_token = pda::get_associated_token_address(payer, quote_mint);
buy_exact_in(
payer,
global_config,
platform_config,
&pool_state,
&user_base_token,
&user_quote_token,
&base_vault,
"e_vault,
base_mint,
quote_mint,
&base_token_program,
amount_in,
minimum_amount_out,
share_fee_rate,
)
}
pub fn create_sell_instruction(
payer: &Pubkey,
base_mint: &Pubkey,
quote_mint: &Pubkey,
global_config: &Pubkey,
platform_config: &Pubkey,
amount_in: u64,
minimum_amount_out: u64,
share_fee_rate: u64,
is_token_2022: bool,
) -> Instruction {
let (pool_state, _) = pda::get_pool_state_pda(base_mint, quote_mint);
let (base_vault, _) = pda::get_pool_vault_pda(&pool_state, base_mint);
let (quote_vault, _) = pda::get_pool_vault_pda(&pool_state, quote_mint);
let base_token_program = if is_token_2022 {
TOKEN_2022_PROGRAM_ID
} else {
TOKEN_PROGRAM_ID
};
let user_base_token = if is_token_2022 {
pda::get_associated_token_address_2022(payer, base_mint)
} else {
pda::get_associated_token_address(payer, base_mint)
};
let user_quote_token = pda::get_associated_token_address(payer, quote_mint);
sell_exact_in(
payer,
global_config,
platform_config,
&pool_state,
&user_base_token,
&user_quote_token,
&base_vault,
"e_vault,
base_mint,
quote_mint,
&base_token_program,
amount_in,
minimum_amount_out,
share_fee_rate,
)
}