feat(pumpfun): bonding curve buy_v2/sell_v2/buy_exact_quote_in_v2 + quote_mint decode
- Switch swap ix assembly to unified v2 account layout (sharing_config, quote ATAs, buyback recipient). - Decode bonding curve account with optional trailing quote_mint; sync idl/pump.json from pump-public-docs. - Legacy buy/buy_exact_sol_in/sell encoders retained for reference. Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
+203
-74
@@ -1,7 +1,10 @@
|
||||
//! Pump.fun bonding-curve swap ix assembly ([`SwapParams`](crate::trading::core::params::SwapParams)).
|
||||
//!
|
||||
//! 组装 **`buy_v2` / `sell_v2` / `buy_exact_quote_in_v2`**([pump-public-docs](https://github.com/pump-fun/pump-public-docs)):
|
||||
//! 链上 `BondingCurve.quote_mint == default` 的 SOL 币对须在指令里传 **wrapped SOL**;报价侧程序 id 与官方 Rust 示例一致用 legacy SPL Token。
|
||||
|
||||
use crate::{
|
||||
common::spl_token::close_account,
|
||||
common::{bonding_curve::BondingCurveAccount, spl_token::close_account},
|
||||
constants::{trade::trade::DEFAULT_SLIPPAGE, TOKEN_PROGRAM_2022},
|
||||
trading::core::{
|
||||
params::{PumpFunParams, SwapParams},
|
||||
@@ -10,14 +13,13 @@ use crate::{
|
||||
};
|
||||
use crate::{
|
||||
instruction::pumpfun_ix_data::{
|
||||
encode_pumpfun_buy_exact_sol_in_ix_data, encode_pumpfun_buy_ix_data,
|
||||
encode_pumpfun_sell_ix_data, TRACK_VOLUME_TRUE,
|
||||
encode_pumpfun_buy_exact_quote_in_v2_ix_data, encode_pumpfun_buy_v2_ix_data,
|
||||
encode_pumpfun_sell_v2_ix_data,
|
||||
},
|
||||
instruction::utils::pumpfun::{
|
||||
accounts, get_bonding_curve_pda, get_bonding_curve_v2_pda,
|
||||
get_protocol_extra_fee_recipient_random, get_user_volume_accumulator_pda,
|
||||
pump_fun_fee_recipient_meta, resolve_creator_vault_for_ix_with_fee_sharing,
|
||||
global_constants::{self},
|
||||
accounts, get_bonding_curve_pda, get_fee_sharing_config_pda, get_user_volume_accumulator_pda,
|
||||
pump_fun_buyback_fee_recipient_meta_random, pump_fun_fee_recipient_meta,
|
||||
resolve_creator_vault_for_ix_with_fee_sharing, global_constants::{self},
|
||||
},
|
||||
utils::calc::{
|
||||
common::{calculate_with_slippage_buy, calculate_with_slippage_sell},
|
||||
@@ -38,6 +40,16 @@ fn effective_pump_mint_token_program(protocol_params: &PumpFunParams) -> Pubkey
|
||||
}
|
||||
}
|
||||
|
||||
#[inline]
|
||||
fn effective_quote_mint_and_token_program(bc: &BondingCurveAccount) -> (Pubkey, Pubkey) {
|
||||
let quote_mint = if bc.quote_mint == Pubkey::default() {
|
||||
crate::constants::WSOL_TOKEN_ACCOUNT
|
||||
} else {
|
||||
bc.quote_mint
|
||||
};
|
||||
(quote_mint, crate::constants::TOKEN_PROGRAM)
|
||||
}
|
||||
|
||||
pub struct PumpFunInstructionBuilder;
|
||||
|
||||
#[async_trait::async_trait]
|
||||
@@ -89,32 +101,84 @@ impl InstructionBuilder for PumpFunInstructionBuilder {
|
||||
})?;
|
||||
|
||||
let is_mayhem_mode = bonding_curve.is_mayhem_mode;
|
||||
let token_program = effective_pump_mint_token_program(protocol_params);
|
||||
let token_program_meta = if token_program == TOKEN_PROGRAM_2022 {
|
||||
let base_token_program = effective_pump_mint_token_program(protocol_params);
|
||||
let base_token_program_meta = if base_token_program == TOKEN_PROGRAM_2022 {
|
||||
crate::constants::TOKEN_PROGRAM_2022_META
|
||||
} else {
|
||||
crate::constants::TOKEN_PROGRAM_META
|
||||
};
|
||||
|
||||
let associated_bonding_curve =
|
||||
let (quote_mint, quote_token_program) = effective_quote_mint_and_token_program(bonding_curve);
|
||||
let quote_token_program_meta = crate::constants::TOKEN_PROGRAM_META;
|
||||
|
||||
let associated_base_bonding_curve =
|
||||
crate::common::fast_fn::get_associated_token_address_with_program_id_fast(
|
||||
&bonding_curve_addr,
|
||||
¶ms.output_mint,
|
||||
&token_program,
|
||||
&base_token_program,
|
||||
);
|
||||
|
||||
let user_token_account =
|
||||
let associated_base_user =
|
||||
crate::common::fast_fn::get_associated_token_address_with_program_id_fast_use_seed(
|
||||
¶ms.payer.pubkey(),
|
||||
¶ms.output_mint,
|
||||
&token_program,
|
||||
&base_token_program,
|
||||
params.open_seed_optimize,
|
||||
);
|
||||
|
||||
let fee_recipient_meta =
|
||||
pump_fun_fee_recipient_meta(protocol_params.fee_recipient, is_mayhem_mode);
|
||||
let fee_recipient_pk = fee_recipient_meta.pubkey;
|
||||
let buyback_fee_recipient_meta = pump_fun_buyback_fee_recipient_meta_random();
|
||||
let buyback_pk = buyback_fee_recipient_meta.pubkey;
|
||||
|
||||
let associated_quote_fee_recipient =
|
||||
crate::common::fast_fn::get_associated_token_address_with_program_id_fast(
|
||||
&fee_recipient_pk,
|
||||
"e_mint,
|
||||
"e_token_program,
|
||||
);
|
||||
let associated_quote_buyback_fee_recipient =
|
||||
crate::common::fast_fn::get_associated_token_address_with_program_id_fast(
|
||||
&buyback_pk,
|
||||
"e_mint,
|
||||
"e_token_program,
|
||||
);
|
||||
let associated_quote_bonding_curve =
|
||||
crate::common::fast_fn::get_associated_token_address_with_program_id_fast(
|
||||
&bonding_curve_addr,
|
||||
"e_mint,
|
||||
"e_token_program,
|
||||
);
|
||||
let associated_quote_user =
|
||||
crate::common::fast_fn::get_associated_token_address_with_program_id_fast_use_seed(
|
||||
¶ms.payer.pubkey(),
|
||||
"e_mint,
|
||||
"e_token_program,
|
||||
params.open_seed_optimize,
|
||||
);
|
||||
let associated_creator_vault =
|
||||
crate::common::fast_fn::get_associated_token_address_with_program_id_fast(
|
||||
&creator_vault_account,
|
||||
"e_mint,
|
||||
"e_token_program,
|
||||
);
|
||||
|
||||
let sharing_config =
|
||||
get_fee_sharing_config_pda(¶ms.output_mint).ok_or_else(|| {
|
||||
anyhow!("sharing_config PDA derivation failed for mint {}", params.output_mint)
|
||||
})?;
|
||||
|
||||
let user_volume_accumulator = get_user_volume_accumulator_pda(¶ms.payer.pubkey())
|
||||
.ok_or_else(|| anyhow!("user_volume_accumulator PDA derivation failed"))?;
|
||||
let associated_user_volume_accumulator =
|
||||
crate::common::fast_fn::get_associated_token_address_with_program_id_fast(
|
||||
&user_volume_accumulator,
|
||||
"e_mint,
|
||||
"e_token_program,
|
||||
);
|
||||
|
||||
let mut instructions = Vec::with_capacity(2);
|
||||
let mut instructions = Vec::with_capacity(4);
|
||||
|
||||
if params.create_output_mint_ata {
|
||||
instructions.extend(
|
||||
@@ -122,52 +186,58 @@ impl InstructionBuilder for PumpFunInstructionBuilder {
|
||||
¶ms.payer.pubkey(),
|
||||
¶ms.payer.pubkey(),
|
||||
¶ms.output_mint,
|
||||
&token_program,
|
||||
&base_token_program,
|
||||
params.open_seed_optimize,
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
instructions.extend(
|
||||
crate::common::fast_fn::create_associated_token_account_idempotent_fast_use_seed(
|
||||
¶ms.payer.pubkey(),
|
||||
¶ms.payer.pubkey(),
|
||||
"e_mint,
|
||||
"e_token_program,
|
||||
params.open_seed_optimize,
|
||||
),
|
||||
);
|
||||
|
||||
let buy_data = if params.use_exact_sol_amount.unwrap_or(true) {
|
||||
let min_tokens_out = calculate_with_slippage_sell(buy_token_amount, slippage_bp);
|
||||
encode_pumpfun_buy_exact_sol_in_ix_data(
|
||||
lamports_in,
|
||||
min_tokens_out,
|
||||
TRACK_VOLUME_TRUE,
|
||||
)
|
||||
encode_pumpfun_buy_exact_quote_in_v2_ix_data(lamports_in, min_tokens_out)
|
||||
} else {
|
||||
encode_pumpfun_buy_ix_data(buy_token_amount, max_sol_cost, TRACK_VOLUME_TRUE)
|
||||
encode_pumpfun_buy_v2_ix_data(buy_token_amount, max_sol_cost)
|
||||
};
|
||||
|
||||
let fee_recipient_meta =
|
||||
pump_fun_fee_recipient_meta(protocol_params.fee_recipient, is_mayhem_mode);
|
||||
|
||||
let bonding_curve_v2 = get_bonding_curve_v2_pda(¶ms.output_mint).ok_or_else(|| {
|
||||
anyhow!("bonding_curve_v2 PDA derivation failed for mint {}", params.output_mint)
|
||||
})?;
|
||||
let mut metas: Vec<AccountMeta> = vec![
|
||||
let metas: Vec<AccountMeta> = vec![
|
||||
global_constants::GLOBAL_ACCOUNT_META,
|
||||
fee_recipient_meta,
|
||||
AccountMeta::new_readonly(params.output_mint, false),
|
||||
AccountMeta::new_readonly(quote_mint, false),
|
||||
base_token_program_meta,
|
||||
quote_token_program_meta,
|
||||
AccountMeta::new_readonly(accounts::ASSOCIATED_TOKEN_PROGRAM, false),
|
||||
fee_recipient_meta,
|
||||
AccountMeta::new(associated_quote_fee_recipient, false),
|
||||
buyback_fee_recipient_meta,
|
||||
AccountMeta::new(associated_quote_buyback_fee_recipient, false),
|
||||
AccountMeta::new(bonding_curve_addr, false),
|
||||
AccountMeta::new(associated_bonding_curve, false),
|
||||
AccountMeta::new(user_token_account, false),
|
||||
AccountMeta::new(associated_base_bonding_curve, false),
|
||||
AccountMeta::new(associated_quote_bonding_curve, false),
|
||||
AccountMeta::new(params.payer.pubkey(), true),
|
||||
crate::constants::SYSTEM_PROGRAM_META,
|
||||
token_program_meta,
|
||||
AccountMeta::new(associated_base_user, false),
|
||||
AccountMeta::new(associated_quote_user, false),
|
||||
AccountMeta::new(creator_vault_account, false),
|
||||
accounts::EVENT_AUTHORITY_META,
|
||||
accounts::PUMPFUN_META,
|
||||
AccountMeta::new(associated_creator_vault, false),
|
||||
AccountMeta::new_readonly(sharing_config, false),
|
||||
accounts::GLOBAL_VOLUME_ACCUMULATOR_META,
|
||||
AccountMeta::new(user_volume_accumulator, false),
|
||||
AccountMeta::new(associated_user_volume_accumulator, false),
|
||||
accounts::FEE_CONFIG_META,
|
||||
accounts::FEE_PROGRAM_META,
|
||||
crate::constants::SYSTEM_PROGRAM_META,
|
||||
accounts::EVENT_AUTHORITY_META,
|
||||
accounts::PUMPFUN_META,
|
||||
];
|
||||
metas.push(AccountMeta::new_readonly(bonding_curve_v2, false));
|
||||
metas.push(AccountMeta::new(
|
||||
get_protocol_extra_fee_recipient_random(),
|
||||
false,
|
||||
));
|
||||
|
||||
instructions.push(Instruction::new_with_bytes(
|
||||
accounts::PUMPFUN,
|
||||
@@ -228,66 +298,125 @@ impl InstructionBuilder for PumpFunInstructionBuilder {
|
||||
})?;
|
||||
|
||||
let is_mayhem_mode = bonding_curve.is_mayhem_mode;
|
||||
let token_program = effective_pump_mint_token_program(protocol_params);
|
||||
let token_program_meta = if token_program == TOKEN_PROGRAM_2022 {
|
||||
let base_token_program = effective_pump_mint_token_program(protocol_params);
|
||||
let base_token_program_meta = if base_token_program == TOKEN_PROGRAM_2022 {
|
||||
crate::constants::TOKEN_PROGRAM_2022_META
|
||||
} else {
|
||||
crate::constants::TOKEN_PROGRAM_META
|
||||
};
|
||||
|
||||
let associated_bonding_curve =
|
||||
let (quote_mint, quote_token_program) = effective_quote_mint_and_token_program(bonding_curve);
|
||||
let quote_token_program_meta = crate::constants::TOKEN_PROGRAM_META;
|
||||
|
||||
let associated_base_bonding_curve =
|
||||
crate::common::fast_fn::get_associated_token_address_with_program_id_fast(
|
||||
&bonding_curve_addr,
|
||||
¶ms.input_mint,
|
||||
&token_program,
|
||||
&base_token_program,
|
||||
);
|
||||
|
||||
let user_token_account =
|
||||
let associated_base_user =
|
||||
crate::common::fast_fn::get_associated_token_address_with_program_id_fast_use_seed(
|
||||
¶ms.payer.pubkey(),
|
||||
¶ms.input_mint,
|
||||
&token_program,
|
||||
&base_token_program,
|
||||
params.open_seed_optimize,
|
||||
);
|
||||
|
||||
let mut instructions = Vec::with_capacity(2);
|
||||
let sell_data = encode_pumpfun_sell_ix_data(token_amount, min_sol_output);
|
||||
let fee_recipient_meta =
|
||||
pump_fun_fee_recipient_meta(protocol_params.fee_recipient, is_mayhem_mode);
|
||||
let fee_recipient_pk = fee_recipient_meta.pubkey;
|
||||
let buyback_fee_recipient_meta = pump_fun_buyback_fee_recipient_meta_random();
|
||||
let buyback_pk = buyback_fee_recipient_meta.pubkey;
|
||||
|
||||
let mut metas: Vec<AccountMeta> = vec![
|
||||
let associated_quote_fee_recipient =
|
||||
crate::common::fast_fn::get_associated_token_address_with_program_id_fast(
|
||||
&fee_recipient_pk,
|
||||
"e_mint,
|
||||
"e_token_program,
|
||||
);
|
||||
let associated_quote_buyback_fee_recipient =
|
||||
crate::common::fast_fn::get_associated_token_address_with_program_id_fast(
|
||||
&buyback_pk,
|
||||
"e_mint,
|
||||
"e_token_program,
|
||||
);
|
||||
let associated_quote_bonding_curve =
|
||||
crate::common::fast_fn::get_associated_token_address_with_program_id_fast(
|
||||
&bonding_curve_addr,
|
||||
"e_mint,
|
||||
"e_token_program,
|
||||
);
|
||||
let associated_quote_user =
|
||||
crate::common::fast_fn::get_associated_token_address_with_program_id_fast_use_seed(
|
||||
¶ms.payer.pubkey(),
|
||||
"e_mint,
|
||||
"e_token_program,
|
||||
params.open_seed_optimize,
|
||||
);
|
||||
let associated_creator_vault =
|
||||
crate::common::fast_fn::get_associated_token_address_with_program_id_fast(
|
||||
&creator_vault_account,
|
||||
"e_mint,
|
||||
"e_token_program,
|
||||
);
|
||||
|
||||
let sharing_config = get_fee_sharing_config_pda(¶ms.input_mint).ok_or_else(|| {
|
||||
anyhow!("sharing_config PDA derivation failed for mint {}", params.input_mint)
|
||||
})?;
|
||||
|
||||
let user_volume_accumulator = get_user_volume_accumulator_pda(¶ms.payer.pubkey())
|
||||
.ok_or_else(|| anyhow!("user_volume_accumulator PDA derivation failed"))?;
|
||||
let associated_user_volume_accumulator =
|
||||
crate::common::fast_fn::get_associated_token_address_with_program_id_fast(
|
||||
&user_volume_accumulator,
|
||||
"e_mint,
|
||||
"e_token_program,
|
||||
);
|
||||
|
||||
let mut instructions = Vec::with_capacity(3);
|
||||
|
||||
instructions.extend(
|
||||
crate::common::fast_fn::create_associated_token_account_idempotent_fast_use_seed(
|
||||
¶ms.payer.pubkey(),
|
||||
¶ms.payer.pubkey(),
|
||||
"e_mint,
|
||||
"e_token_program,
|
||||
params.open_seed_optimize,
|
||||
),
|
||||
);
|
||||
|
||||
let sell_data = encode_pumpfun_sell_v2_ix_data(token_amount, min_sol_output);
|
||||
|
||||
let metas: Vec<AccountMeta> = vec![
|
||||
global_constants::GLOBAL_ACCOUNT_META,
|
||||
fee_recipient_meta,
|
||||
AccountMeta::new_readonly(params.input_mint, false),
|
||||
AccountMeta::new_readonly(quote_mint, false),
|
||||
base_token_program_meta,
|
||||
quote_token_program_meta,
|
||||
AccountMeta::new_readonly(accounts::ASSOCIATED_TOKEN_PROGRAM, false),
|
||||
fee_recipient_meta,
|
||||
AccountMeta::new(associated_quote_fee_recipient, false),
|
||||
buyback_fee_recipient_meta,
|
||||
AccountMeta::new(associated_quote_buyback_fee_recipient, false),
|
||||
AccountMeta::new(bonding_curve_addr, false),
|
||||
AccountMeta::new(associated_bonding_curve, false),
|
||||
AccountMeta::new(user_token_account, false),
|
||||
AccountMeta::new(associated_base_bonding_curve, false),
|
||||
AccountMeta::new(associated_quote_bonding_curve, false),
|
||||
AccountMeta::new(params.payer.pubkey(), true),
|
||||
crate::constants::SYSTEM_PROGRAM_META,
|
||||
AccountMeta::new(associated_base_user, false),
|
||||
AccountMeta::new(associated_quote_user, false),
|
||||
AccountMeta::new(creator_vault_account, false),
|
||||
token_program_meta,
|
||||
accounts::EVENT_AUTHORITY_META,
|
||||
accounts::PUMPFUN_META,
|
||||
AccountMeta::new(associated_creator_vault, false),
|
||||
AccountMeta::new_readonly(sharing_config, false),
|
||||
AccountMeta::new(user_volume_accumulator, false),
|
||||
AccountMeta::new(associated_user_volume_accumulator, false),
|
||||
accounts::FEE_CONFIG_META,
|
||||
accounts::FEE_PROGRAM_META,
|
||||
crate::constants::SYSTEM_PROGRAM_META,
|
||||
accounts::EVENT_AUTHORITY_META,
|
||||
accounts::PUMPFUN_META,
|
||||
];
|
||||
|
||||
if bonding_curve.is_cashback_coin {
|
||||
let user_volume_accumulator =
|
||||
get_user_volume_accumulator_pda(¶ms.payer.pubkey())
|
||||
.ok_or_else(|| anyhow!("user_volume_accumulator PDA derivation failed"))?;
|
||||
metas.push(AccountMeta::new(user_volume_accumulator, false));
|
||||
}
|
||||
|
||||
let bonding_curve_v2 = get_bonding_curve_v2_pda(¶ms.input_mint).ok_or_else(|| {
|
||||
anyhow!("bonding_curve_v2 PDA derivation failed for mint {}", params.input_mint)
|
||||
})?;
|
||||
metas.push(AccountMeta::new_readonly(bonding_curve_v2, false));
|
||||
metas.push(AccountMeta::new(
|
||||
get_protocol_extra_fee_recipient_random(),
|
||||
false,
|
||||
));
|
||||
|
||||
instructions.push(Instruction::new_with_bytes(
|
||||
accounts::PUMPFUN,
|
||||
&sell_data,
|
||||
@@ -298,8 +427,8 @@ impl InstructionBuilder for PumpFunInstructionBuilder {
|
||||
|| params.close_input_mint_ata
|
||||
{
|
||||
instructions.push(close_account(
|
||||
&token_program,
|
||||
&user_token_account,
|
||||
&base_token_program,
|
||||
&associated_base_user,
|
||||
¶ms.payer.pubkey(),
|
||||
¶ms.payer.pubkey(),
|
||||
&[¶ms.payer.pubkey()],
|
||||
|
||||
@@ -1,15 +1,21 @@
|
||||
//! Pump.fun 曲线 `buy` / `buy_exact_sol_in` / `sell` 的 **instruction data** 栈上编码(热路径零堆分配)。
|
||||
//! Pump.fun 曲线 **legacy** `buy` / `buy_exact_sol_in` / `sell` 与 **`buy_v2` / `sell_v2` / `buy_exact_quote_in_v2`**
|
||||
//! 的 instruction data 栈上编码(热路径零堆分配)。
|
||||
//!
|
||||
//! 与 `@pump-fun/pump-sdk` Anchor `coder.instruction.encode` 对齐:`OptionBool` 在 ix 参数中为 **1 字节**。
|
||||
//! Legacy `buy` / `buy_exact_sol_in` 与 `@pump-fun/pump-sdk` 对齐:`OptionBool` 在 ix 参数中为 **1 字节**。
|
||||
//! `*_v2` 指令无 `track_volume` 字节(见 [pump-public-docs](https://github.com/pump-fun/pump-public-docs))。
|
||||
|
||||
use crate::instruction::utils::pumpfun::{
|
||||
BUY_DISCRIMINATOR, BUY_EXACT_SOL_IN_DISCRIMINATOR, SELL_DISCRIMINATOR,
|
||||
BUY_DISCRIMINATOR, BUY_EXACT_QUOTE_IN_V2_DISCRIMINATOR, BUY_EXACT_SOL_IN_DISCRIMINATOR,
|
||||
BUY_V2_DISCRIMINATOR, SELL_DISCRIMINATOR, SELL_V2_DISCRIMINATOR,
|
||||
};
|
||||
|
||||
/// 与官方 `getBuyInstructionInternal` 一致:`track_volume = true`。
|
||||
/// Legacy `buy`:`track_volume = true`(仅 legacy 指令使用)。
|
||||
#[allow(dead_code)]
|
||||
pub const TRACK_VOLUME_TRUE: u8 = 1;
|
||||
|
||||
/// Legacy `buy` ix data(保留供兼容 / 对照 IDL;热路径已改用 [`encode_pumpfun_buy_v2_ix_data`])。
|
||||
#[inline(always)]
|
||||
#[allow(dead_code)]
|
||||
pub fn encode_pumpfun_buy_ix_data(
|
||||
token_amount: u64,
|
||||
max_sol_cost: u64,
|
||||
@@ -24,6 +30,7 @@ pub fn encode_pumpfun_buy_ix_data(
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
#[allow(dead_code)]
|
||||
pub fn encode_pumpfun_buy_exact_sol_in_ix_data(
|
||||
spendable_sol_in: u64,
|
||||
min_tokens_out: u64,
|
||||
@@ -38,6 +45,7 @@ pub fn encode_pumpfun_buy_exact_sol_in_ix_data(
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
#[allow(dead_code)]
|
||||
pub fn encode_pumpfun_sell_ix_data(token_amount: u64, min_sol_output: u64) -> [u8; 24] {
|
||||
let mut d = [0u8; 24];
|
||||
d[..8].copy_from_slice(&SELL_DISCRIMINATOR);
|
||||
@@ -45,3 +53,33 @@ pub fn encode_pumpfun_sell_ix_data(token_amount: u64, min_sol_output: u64) -> [u
|
||||
d[16..24].copy_from_slice(&min_sol_output.to_le_bytes());
|
||||
d
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
pub fn encode_pumpfun_buy_v2_ix_data(amount: u64, max_sol_cost: u64) -> [u8; 24] {
|
||||
let mut d = [0u8; 24];
|
||||
d[..8].copy_from_slice(&BUY_V2_DISCRIMINATOR);
|
||||
d[8..16].copy_from_slice(&amount.to_le_bytes());
|
||||
d[16..24].copy_from_slice(&max_sol_cost.to_le_bytes());
|
||||
d
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
pub fn encode_pumpfun_buy_exact_quote_in_v2_ix_data(
|
||||
spendable_quote_in: u64,
|
||||
min_tokens_out: u64,
|
||||
) -> [u8; 24] {
|
||||
let mut d = [0u8; 24];
|
||||
d[..8].copy_from_slice(&BUY_EXACT_QUOTE_IN_V2_DISCRIMINATOR);
|
||||
d[8..16].copy_from_slice(&spendable_quote_in.to_le_bytes());
|
||||
d[16..24].copy_from_slice(&min_tokens_out.to_le_bytes());
|
||||
d
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
pub fn encode_pumpfun_sell_v2_ix_data(token_amount: u64, min_sol_output: u64) -> [u8; 24] {
|
||||
let mut d = [0u8; 24];
|
||||
d[..8].copy_from_slice(&SELL_V2_DISCRIMINATOR);
|
||||
d[8..16].copy_from_slice(&token_amount.to_le_bytes());
|
||||
d[16..24].copy_from_slice(&min_sol_output.to_le_bytes());
|
||||
d
|
||||
}
|
||||
|
||||
@@ -172,6 +172,13 @@ pub const BUY_DISCRIMINATOR: [u8; 8] = [102, 6, 61, 18, 1, 218, 235, 234];
|
||||
pub const BUY_EXACT_SOL_IN_DISCRIMINATOR: [u8; 8] = [56, 252, 116, 8, 158, 223, 205, 95];
|
||||
pub const SELL_DISCRIMINATOR: [u8; 8] = [51, 230, 133, 164, 1, 127, 131, 173];
|
||||
|
||||
/// `buy_v2` — unified SOL/USDC quote interface ([pump-public-docs](https://github.com/pump-fun/pump-public-docs)).
|
||||
pub const BUY_V2_DISCRIMINATOR: [u8; 8] = [184, 23, 238, 97, 103, 197, 211, 61];
|
||||
/// `sell_v2`
|
||||
pub const SELL_V2_DISCRIMINATOR: [u8; 8] = [93, 246, 130, 60, 231, 233, 64, 178];
|
||||
/// `buy_exact_quote_in_v2` (native SOL spend for SOL-paired coins when `quote_mint` is WSOL)
|
||||
pub const BUY_EXACT_QUOTE_IN_V2_DISCRIMINATOR: [u8; 8] = [194, 171, 28, 70, 104, 77, 91, 47];
|
||||
|
||||
pub const EXTEND_ACCOUNT_DISCRIMINATOR: [u8; 8] = [234, 102, 194, 203, 150, 72, 62, 229];
|
||||
|
||||
pub const SHARING_CONFIG_ACCOUNT_DISCRIMINATOR: [u8; 8] = [216, 74, 9, 0, 56, 140, 93, 75];
|
||||
@@ -278,6 +285,17 @@ pub fn get_protocol_extra_fee_recipient_random() -> Pubkey {
|
||||
.unwrap_or(&global_constants::PROTOCOL_EXTRA_FEE_RECIPIENTS[0])
|
||||
}
|
||||
|
||||
/// Buyback fee recipient (#8 / `buyback_fee_recipient`) — same static pool as protocol extra / pump-public-docs buyback list.
|
||||
#[inline]
|
||||
pub fn pump_fun_buyback_fee_recipient_meta_random() -> AccountMeta {
|
||||
let pubkey = get_protocol_extra_fee_recipient_random();
|
||||
AccountMeta {
|
||||
pubkey,
|
||||
is_signer: false,
|
||||
is_writable: true,
|
||||
}
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn pump_fun_fee_recipient_meta(observed_fee_recipient: Pubkey, is_mayhem_mode: bool) -> AccountMeta {
|
||||
let trust_observation = observed_fee_recipient != Pubkey::default()
|
||||
@@ -516,9 +534,9 @@ pub async fn fetch_bonding_curve_account(
|
||||
return Err(anyhow!("Bonding curve not found"));
|
||||
}
|
||||
|
||||
let bonding_curve =
|
||||
solana_sdk::borsh1::try_from_slice_unchecked::<BondingCurveAccount>(&account.data[8..])
|
||||
.map_err(|e| anyhow::anyhow!("Failed to deserialize bonding curve account: {}", e))?;
|
||||
let mut bonding_curve = BondingCurveAccount::decode_from_chain_account_data(account.data.as_slice())
|
||||
.map_err(|e| anyhow::anyhow!("Failed to decode bonding curve account: {}", e))?;
|
||||
bonding_curve.account = bonding_curve_pda;
|
||||
|
||||
Ok((Arc::new(bonding_curve), bonding_curve_pda))
|
||||
}
|
||||
@@ -540,6 +558,9 @@ mod tests {
|
||||
assert_eq!(BUY_DISCRIMINATOR.len(), 8);
|
||||
assert_eq!(BUY_EXACT_SOL_IN_DISCRIMINATOR.len(), 8);
|
||||
assert_eq!(SELL_DISCRIMINATOR.len(), 8);
|
||||
assert_eq!(BUY_V2_DISCRIMINATOR.len(), 8);
|
||||
assert_eq!(SELL_V2_DISCRIMINATOR.len(), 8);
|
||||
assert_eq!(BUY_EXACT_QUOTE_IN_V2_DISCRIMINATOR.len(), 8);
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
||||
Reference in New Issue
Block a user