style: run rustfmt
This commit is contained in:
@@ -29,8 +29,10 @@ impl InstructionBuilder for MeteoraDammV2InstructionBuilder {
|
||||
.downcast_ref::<MeteoraDammV2Params>()
|
||||
.ok_or_else(|| anyhow!("Invalid protocol params for MeteoraDammV2"))?;
|
||||
|
||||
let is_wsol = protocol_params.token_a_mint == crate::constants::WSOL_TOKEN_ACCOUNT || protocol_params.token_b_mint == crate::constants::WSOL_TOKEN_ACCOUNT;
|
||||
let is_usdc = protocol_params.token_a_mint == crate::constants::USDC_TOKEN_ACCOUNT || protocol_params.token_b_mint == crate::constants::USDC_TOKEN_ACCOUNT;
|
||||
let is_wsol = protocol_params.token_a_mint == crate::constants::WSOL_TOKEN_ACCOUNT
|
||||
|| protocol_params.token_b_mint == crate::constants::WSOL_TOKEN_ACCOUNT;
|
||||
let is_usdc = protocol_params.token_a_mint == crate::constants::USDC_TOKEN_ACCOUNT
|
||||
|| protocol_params.token_b_mint == crate::constants::USDC_TOKEN_ACCOUNT;
|
||||
if !is_wsol && !is_usdc {
|
||||
return Err(anyhow!("Pool must contain WSOL or USDC"));
|
||||
}
|
||||
@@ -38,7 +40,8 @@ impl InstructionBuilder for MeteoraDammV2InstructionBuilder {
|
||||
// ========================================
|
||||
// Trade calculation and account address preparation
|
||||
// ========================================
|
||||
let is_a_in = protocol_params.token_a_mint == crate::constants::WSOL_TOKEN_ACCOUNT || protocol_params.token_a_mint == crate::constants::USDC_TOKEN_ACCOUNT;
|
||||
let is_a_in = protocol_params.token_a_mint == crate::constants::WSOL_TOKEN_ACCOUNT
|
||||
|| protocol_params.token_a_mint == crate::constants::USDC_TOKEN_ACCOUNT;
|
||||
let amount_in: u64 = params.input_amount.unwrap_or(0);
|
||||
let minimum_amount_out: u64 = match params.fixed_output_amount {
|
||||
Some(fixed) => fixed,
|
||||
@@ -141,8 +144,10 @@ impl InstructionBuilder for MeteoraDammV2InstructionBuilder {
|
||||
return Err(anyhow!("Token amount is not set"));
|
||||
}
|
||||
|
||||
let is_wsol = protocol_params.token_b_mint == crate::constants::WSOL_TOKEN_ACCOUNT || protocol_params.token_a_mint == crate::constants::WSOL_TOKEN_ACCOUNT;
|
||||
let is_usdc = protocol_params.token_b_mint == crate::constants::USDC_TOKEN_ACCOUNT || protocol_params.token_a_mint == crate::constants::USDC_TOKEN_ACCOUNT;
|
||||
let is_wsol = protocol_params.token_b_mint == crate::constants::WSOL_TOKEN_ACCOUNT
|
||||
|| protocol_params.token_a_mint == crate::constants::WSOL_TOKEN_ACCOUNT;
|
||||
let is_usdc = protocol_params.token_b_mint == crate::constants::USDC_TOKEN_ACCOUNT
|
||||
|| protocol_params.token_a_mint == crate::constants::USDC_TOKEN_ACCOUNT;
|
||||
if !is_wsol && !is_usdc {
|
||||
return Err(anyhow!("Pool must contain WSOL or USDC"));
|
||||
}
|
||||
@@ -150,7 +155,8 @@ impl InstructionBuilder for MeteoraDammV2InstructionBuilder {
|
||||
// ========================================
|
||||
// Trade calculation and account address preparation
|
||||
// ========================================
|
||||
let is_a_in = protocol_params.token_b_mint == crate::constants::WSOL_TOKEN_ACCOUNT || protocol_params.token_b_mint == crate::constants::USDC_TOKEN_ACCOUNT;
|
||||
let is_a_in = protocol_params.token_b_mint == crate::constants::WSOL_TOKEN_ACCOUNT
|
||||
|| protocol_params.token_b_mint == crate::constants::USDC_TOKEN_ACCOUNT;
|
||||
let minimum_amount_out: u64 = match params.fixed_output_amount {
|
||||
Some(fixed) => fixed,
|
||||
None => return Err(anyhow!("fixed_output_amount must be set for MeteoraDammV2 swap")),
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
pub mod bonk;
|
||||
pub mod meteora_damm_v2;
|
||||
pub mod pumpfun;
|
||||
pub mod pumpswap;
|
||||
pub mod bonk;
|
||||
pub mod raydium_cpmm;
|
||||
pub mod raydium_amm_v4;
|
||||
pub mod meteora_damm_v2;
|
||||
pub mod utils;
|
||||
pub mod raydium_cpmm;
|
||||
pub mod utils;
|
||||
|
||||
+21
-27
@@ -10,7 +10,8 @@ use crate::{
|
||||
instruction::utils::pumpfun::{
|
||||
accounts, get_bonding_curve_pda, get_bonding_curve_v2_pda, get_creator,
|
||||
get_mayhem_fee_recipient_meta_random, get_user_volume_accumulator_pda,
|
||||
global_constants::{self}, BUY_DISCRIMINATOR, BUY_EXACT_SOL_IN_DISCRIMINATOR, SELL_DISCRIMINATOR,
|
||||
global_constants::{self},
|
||||
BUY_DISCRIMINATOR, BUY_EXACT_SOL_IN_DISCRIMINATOR, SELL_DISCRIMINATOR,
|
||||
},
|
||||
utils::calc::{
|
||||
common::{calculate_with_slippage_buy, calculate_with_slippage_sell},
|
||||
@@ -64,8 +65,9 @@ impl InstructionBuilder for PumpFunInstructionBuilder {
|
||||
);
|
||||
|
||||
let bonding_curve_addr = if bonding_curve.account == Pubkey::default() {
|
||||
get_bonding_curve_pda(¶ms.output_mint)
|
||||
.ok_or_else(|| anyhow!("bonding_curve PDA derivation failed for mint {}", params.output_mint))?
|
||||
get_bonding_curve_pda(¶ms.output_mint).ok_or_else(|| {
|
||||
anyhow!("bonding_curve PDA derivation failed for mint {}", params.output_mint)
|
||||
})?
|
||||
} else {
|
||||
bonding_curve.account
|
||||
};
|
||||
@@ -147,8 +149,9 @@ impl InstructionBuilder for PumpFunInstructionBuilder {
|
||||
global_constants::FEE_RECIPIENT_META
|
||||
};
|
||||
|
||||
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 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 accounts: Vec<AccountMeta> = vec![
|
||||
global_constants::GLOBAL_ACCOUNT_META,
|
||||
fee_recipient_meta,
|
||||
@@ -169,11 +172,7 @@ impl InstructionBuilder for PumpFunInstructionBuilder {
|
||||
];
|
||||
accounts.push(AccountMeta::new_readonly(bonding_curve_v2, false)); // remainingAccounts: @pump-fun/pump-sdk 要求末尾传 bondingCurveV2Pda(mint),勿删
|
||||
|
||||
instructions.push(Instruction::new_with_bytes(
|
||||
accounts::PUMPFUN,
|
||||
&buy_data,
|
||||
accounts,
|
||||
));
|
||||
instructions.push(Instruction::new_with_bytes(accounts::PUMPFUN, &buy_data, accounts));
|
||||
|
||||
Ok(instructions)
|
||||
}
|
||||
@@ -220,8 +219,9 @@ impl InstructionBuilder for PumpFunInstructionBuilder {
|
||||
};
|
||||
|
||||
let bonding_curve_addr = if bonding_curve.account == Pubkey::default() {
|
||||
get_bonding_curve_pda(¶ms.input_mint)
|
||||
.ok_or_else(|| anyhow!("bonding_curve PDA derivation failed for mint {}", params.input_mint))?
|
||||
get_bonding_curve_pda(¶ms.input_mint).ok_or_else(|| {
|
||||
anyhow!("bonding_curve PDA derivation failed for mint {}", params.input_mint)
|
||||
})?
|
||||
} else {
|
||||
bonding_curve.account
|
||||
};
|
||||
@@ -290,20 +290,18 @@ impl InstructionBuilder for PumpFunInstructionBuilder {
|
||||
|
||||
// Cashback: Bonding Curve Sell expects UserVolumeAccumulator PDA at 0th remaining account (writable)
|
||||
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"))?;
|
||||
let user_volume_accumulator =
|
||||
get_user_volume_accumulator_pda(¶ms.payer.pubkey())
|
||||
.ok_or_else(|| anyhow!("user_volume_accumulator PDA derivation failed"))?;
|
||||
accounts.push(AccountMeta::new(user_volume_accumulator, false));
|
||||
}
|
||||
// remainingAccounts: @pump-fun/pump-sdk sell 要求末尾传 bondingCurveV2Pda(mint)(cashback 时在 user_volume_accumulator 之后),勿删
|
||||
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))?;
|
||||
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)
|
||||
})?;
|
||||
accounts.push(AccountMeta::new_readonly(bonding_curve_v2, false));
|
||||
|
||||
instructions.push(Instruction::new_with_bytes(
|
||||
accounts::PUMPFUN,
|
||||
&sell_data,
|
||||
accounts,
|
||||
));
|
||||
instructions.push(Instruction::new_with_bytes(accounts::PUMPFUN, &sell_data, accounts));
|
||||
|
||||
// Optional: Close token account
|
||||
if protocol_params.close_token_account_when_sell.unwrap_or(false)
|
||||
@@ -327,15 +325,11 @@ pub fn claim_cashback_pumpfun_instruction(payer: &Pubkey) -> Option<Instruction>
|
||||
const CLAIM_CASHBACK_DISCRIMINATOR: [u8; 8] = [37, 58, 35, 126, 190, 53, 228, 197];
|
||||
let user_volume_accumulator = get_user_volume_accumulator_pda(payer)?;
|
||||
let accounts = vec![
|
||||
AccountMeta::new(*payer, true), // user (signer, writable)
|
||||
AccountMeta::new(*payer, true), // user (signer, writable)
|
||||
AccountMeta::new(user_volume_accumulator, false), // user_volume_accumulator (writable, not signer)
|
||||
crate::constants::SYSTEM_PROGRAM_META,
|
||||
accounts::EVENT_AUTHORITY_META,
|
||||
accounts::PUMPFUN_META,
|
||||
];
|
||||
Some(Instruction::new_with_bytes(
|
||||
accounts::PUMPFUN,
|
||||
&CLAIM_CASHBACK_DISCRIMINATOR,
|
||||
accounts,
|
||||
))
|
||||
Some(Instruction::new_with_bytes(accounts::PUMPFUN, &CLAIM_CASHBACK_DISCRIMINATOR, accounts))
|
||||
}
|
||||
|
||||
@@ -225,11 +225,7 @@ impl InstructionBuilder for PumpSwapInstructionBuilder {
|
||||
buf.to_vec()
|
||||
};
|
||||
|
||||
instructions.push(Instruction {
|
||||
program_id: accounts::AMM_PROGRAM,
|
||||
accounts,
|
||||
data,
|
||||
});
|
||||
instructions.push(Instruction { program_id: accounts::AMM_PROGRAM, accounts, data });
|
||||
if close_wsol_ata {
|
||||
// Close wSOL ATA account, reclaim rent
|
||||
instructions.extend(crate::trading::common::close_wsol(¶ms.payer.pubkey()));
|
||||
@@ -462,12 +458,12 @@ pub fn claim_cashback_pumpswap_instruction(
|
||||
// IDL order: user, user_volume_accumulator, quote_mint, quote_token_program,
|
||||
// user_volume_accumulator_wsol_token_account, user_wsol_token_account, system_program, event_authority, program
|
||||
let accounts = vec![
|
||||
AccountMeta::new(*payer, true), // user (signer, writable)
|
||||
AccountMeta::new(user_volume_accumulator, false), // user_volume_accumulator (writable)
|
||||
AccountMeta::new(*payer, true), // user (signer, writable)
|
||||
AccountMeta::new(user_volume_accumulator, false), // user_volume_accumulator (writable)
|
||||
AccountMeta::new_readonly(quote_mint, false),
|
||||
AccountMeta::new_readonly(quote_token_program, false),
|
||||
AccountMeta::new(user_volume_accumulator_wsol_ata, false), // writable
|
||||
AccountMeta::new(user_wsol_ata, false), // writable
|
||||
AccountMeta::new(user_volume_accumulator_wsol_ata, false), // writable
|
||||
AccountMeta::new(user_wsol_ata, false), // writable
|
||||
crate::constants::SYSTEM_PROGRAM_META,
|
||||
accounts::EVENT_AUTHORITY_META,
|
||||
accounts::AMM_PROGRAM_META,
|
||||
|
||||
@@ -44,7 +44,7 @@ impl InstructionBuilder for RaydiumAmmV4InstructionBuilder {
|
||||
// ========================================
|
||||
// Trade calculation and account address preparation
|
||||
// ========================================
|
||||
let is_base_in = protocol_params.coin_mint == crate::constants::WSOL_TOKEN_ACCOUNT
|
||||
let is_base_in = protocol_params.coin_mint == crate::constants::WSOL_TOKEN_ACCOUNT
|
||||
|| protocol_params.coin_mint == crate::constants::USDC_TOKEN_ACCOUNT;
|
||||
let amount_in: u64 = params.input_amount.unwrap_or(0);
|
||||
let swap_result = compute_swap_amount(
|
||||
@@ -62,7 +62,11 @@ impl InstructionBuilder for RaydiumAmmV4InstructionBuilder {
|
||||
let user_source_token_account =
|
||||
crate::common::fast_fn::get_associated_token_address_with_program_id_fast_use_seed(
|
||||
¶ms.payer.pubkey(),
|
||||
if is_wsol { &crate::constants::WSOL_TOKEN_ACCOUNT } else { &crate::constants::USDC_TOKEN_ACCOUNT },
|
||||
if is_wsol {
|
||||
&crate::constants::WSOL_TOKEN_ACCOUNT
|
||||
} else {
|
||||
&crate::constants::USDC_TOKEN_ACCOUNT
|
||||
},
|
||||
&crate::constants::TOKEN_PROGRAM,
|
||||
params.open_seed_optimize,
|
||||
);
|
||||
@@ -187,7 +191,11 @@ impl InstructionBuilder for RaydiumAmmV4InstructionBuilder {
|
||||
let user_destination_token_account =
|
||||
crate::common::fast_fn::get_associated_token_address_with_program_id_fast_use_seed(
|
||||
¶ms.payer.pubkey(),
|
||||
if is_wsol { &crate::constants::WSOL_TOKEN_ACCOUNT } else { &crate::constants::USDC_TOKEN_ACCOUNT },
|
||||
if is_wsol {
|
||||
&crate::constants::WSOL_TOKEN_ACCOUNT
|
||||
} else {
|
||||
&crate::constants::USDC_TOKEN_ACCOUNT
|
||||
},
|
||||
&crate::constants::TOKEN_PROGRAM,
|
||||
params.open_seed_optimize,
|
||||
);
|
||||
|
||||
@@ -61,7 +61,7 @@ impl InstructionBuilder for RaydiumCpmmInstructionBuilder {
|
||||
// ========================================
|
||||
// Trade calculation and account address preparation
|
||||
// ========================================
|
||||
let is_base_in = protocol_params.base_mint == crate::constants::WSOL_TOKEN_ACCOUNT
|
||||
let is_base_in = protocol_params.base_mint == crate::constants::WSOL_TOKEN_ACCOUNT
|
||||
|| protocol_params.base_mint == crate::constants::USDC_TOKEN_ACCOUNT;
|
||||
let mint_token_program = if is_base_in {
|
||||
protocol_params.quote_token_program
|
||||
@@ -84,7 +84,11 @@ impl InstructionBuilder for RaydiumCpmmInstructionBuilder {
|
||||
|
||||
let input_token_account = get_associated_token_address_with_program_id_fast_use_seed(
|
||||
¶ms.payer.pubkey(),
|
||||
if is_wsol { &crate::constants::WSOL_TOKEN_ACCOUNT } else { &crate::constants::USDC_TOKEN_ACCOUNT },
|
||||
if is_wsol {
|
||||
&crate::constants::WSOL_TOKEN_ACCOUNT
|
||||
} else {
|
||||
&crate::constants::USDC_TOKEN_ACCOUNT
|
||||
},
|
||||
&crate::constants::TOKEN_PROGRAM,
|
||||
params.open_seed_optimize,
|
||||
);
|
||||
@@ -97,10 +101,15 @@ impl InstructionBuilder for RaydiumCpmmInstructionBuilder {
|
||||
|
||||
let input_vault_account = get_vault_account(
|
||||
&pool_state,
|
||||
if is_wsol { &crate::constants::WSOL_TOKEN_ACCOUNT } else { &crate::constants::USDC_TOKEN_ACCOUNT },
|
||||
if is_wsol {
|
||||
&crate::constants::WSOL_TOKEN_ACCOUNT
|
||||
} else {
|
||||
&crate::constants::USDC_TOKEN_ACCOUNT
|
||||
},
|
||||
protocol_params,
|
||||
);
|
||||
let output_vault_account = get_vault_account(&pool_state, ¶ms.output_mint, protocol_params);
|
||||
let output_vault_account =
|
||||
get_vault_account(&pool_state, ¶ms.output_mint, protocol_params);
|
||||
|
||||
let observation_state_account = if protocol_params.observation_state == Pubkey::default() {
|
||||
get_observation_state_pda(&pool_state).unwrap()
|
||||
@@ -136,13 +145,17 @@ impl InstructionBuilder for RaydiumCpmmInstructionBuilder {
|
||||
accounts::AUTHORITY_META, // Authority (readonly)
|
||||
AccountMeta::new(protocol_params.amm_config, false), // Amm Config (readonly)
|
||||
AccountMeta::new(pool_state, false), // Pool State
|
||||
AccountMeta::new(input_token_account, false), // Input Token Account
|
||||
AccountMeta::new(output_token_account, false), // Output Token Account
|
||||
AccountMeta::new(input_vault_account, false), // Input Vault Account
|
||||
AccountMeta::new(output_vault_account, false), // Output Vault Account
|
||||
AccountMeta::new(input_token_account, false), // Input Token Account
|
||||
AccountMeta::new(output_token_account, false), // Output Token Account
|
||||
AccountMeta::new(input_vault_account, false), // Input Vault Account
|
||||
AccountMeta::new(output_vault_account, false), // Output Vault Account
|
||||
crate::constants::TOKEN_PROGRAM_META, // Input Token Program (readonly)
|
||||
AccountMeta::new_readonly(mint_token_program, false), // Output Token Program (readonly)
|
||||
if is_wsol { crate::constants::WSOL_TOKEN_ACCOUNT_META } else { crate::constants::USDC_TOKEN_ACCOUNT_META }, // Input token mint (readonly)
|
||||
if is_wsol {
|
||||
crate::constants::WSOL_TOKEN_ACCOUNT_META
|
||||
} else {
|
||||
crate::constants::USDC_TOKEN_ACCOUNT_META
|
||||
}, // Input token mint (readonly)
|
||||
AccountMeta::new_readonly(params.output_mint, false), // Output token mint (readonly)
|
||||
AccountMeta::new(observation_state_account, false), // Observation State Account
|
||||
];
|
||||
@@ -196,7 +209,7 @@ impl InstructionBuilder for RaydiumCpmmInstructionBuilder {
|
||||
|
||||
let is_usdc = protocol_params.base_mint == crate::constants::USDC_TOKEN_ACCOUNT
|
||||
|| protocol_params.quote_mint == crate::constants::USDC_TOKEN_ACCOUNT;
|
||||
|
||||
|
||||
if !is_wsol && !is_usdc {
|
||||
return Err(anyhow!("Pool must contain WSOL or USDC"));
|
||||
}
|
||||
@@ -228,7 +241,11 @@ impl InstructionBuilder for RaydiumCpmmInstructionBuilder {
|
||||
|
||||
let output_token_account = get_associated_token_address_with_program_id_fast_use_seed(
|
||||
¶ms.payer.pubkey(),
|
||||
if is_wsol { &crate::constants::WSOL_TOKEN_ACCOUNT } else { &crate::constants::USDC_TOKEN_ACCOUNT },
|
||||
if is_wsol {
|
||||
&crate::constants::WSOL_TOKEN_ACCOUNT
|
||||
} else {
|
||||
&crate::constants::USDC_TOKEN_ACCOUNT
|
||||
},
|
||||
&crate::constants::TOKEN_PROGRAM,
|
||||
params.open_seed_optimize,
|
||||
);
|
||||
@@ -241,10 +258,15 @@ impl InstructionBuilder for RaydiumCpmmInstructionBuilder {
|
||||
|
||||
let output_vault_account = get_vault_account(
|
||||
&pool_state,
|
||||
if is_wsol { &crate::constants::WSOL_TOKEN_ACCOUNT } else { &crate::constants::USDC_TOKEN_ACCOUNT },
|
||||
if is_wsol {
|
||||
&crate::constants::WSOL_TOKEN_ACCOUNT
|
||||
} else {
|
||||
&crate::constants::USDC_TOKEN_ACCOUNT
|
||||
},
|
||||
protocol_params,
|
||||
);
|
||||
let input_vault_account = get_vault_account(&pool_state, ¶ms.input_mint, protocol_params);
|
||||
let input_vault_account =
|
||||
get_vault_account(&pool_state, ¶ms.input_mint, protocol_params);
|
||||
|
||||
let observation_state_account = if protocol_params.observation_state == Pubkey::default() {
|
||||
get_observation_state_pda(&pool_state).unwrap()
|
||||
@@ -267,14 +289,18 @@ impl InstructionBuilder for RaydiumCpmmInstructionBuilder {
|
||||
accounts::AUTHORITY_META, // Authority (readonly)
|
||||
AccountMeta::new(protocol_params.amm_config, false), // Amm Config (readonly)
|
||||
AccountMeta::new(pool_state, false), // Pool State
|
||||
AccountMeta::new(input_token_account, false), // Input Token Account
|
||||
AccountMeta::new(output_token_account, false), // Output Token Account
|
||||
AccountMeta::new(input_vault_account, false), // Input Vault Account
|
||||
AccountMeta::new(output_vault_account, false), // Output Vault Account
|
||||
AccountMeta::new(input_token_account, false), // Input Token Account
|
||||
AccountMeta::new(output_token_account, false), // Output Token Account
|
||||
AccountMeta::new(input_vault_account, false), // Input Vault Account
|
||||
AccountMeta::new(output_vault_account, false), // Output Vault Account
|
||||
AccountMeta::new_readonly(mint_token_program, false), // Input Token Program (readonly)
|
||||
crate::constants::TOKEN_PROGRAM_META, // Output Token Program (readonly)
|
||||
AccountMeta::new_readonly(params.input_mint, false), // Input token mint (readonly)
|
||||
if is_wsol { crate::constants::WSOL_TOKEN_ACCOUNT_META } else { crate::constants::USDC_TOKEN_ACCOUNT_META }, // Output token mint (readonly)
|
||||
if is_wsol {
|
||||
crate::constants::WSOL_TOKEN_ACCOUNT_META
|
||||
} else {
|
||||
crate::constants::USDC_TOKEN_ACCOUNT_META
|
||||
}, // Output token mint (readonly)
|
||||
AccountMeta::new(observation_state_account, false), // Observation State Account
|
||||
];
|
||||
// Create instruction data
|
||||
|
||||
@@ -1,13 +1,13 @@
|
||||
pub mod bonk;
|
||||
pub mod meteora_damm_v2;
|
||||
pub mod pumpfun;
|
||||
pub mod pumpswap;
|
||||
pub mod raydium_amm_v4;
|
||||
pub mod raydium_cpmm;
|
||||
pub mod meteora_damm_v2;
|
||||
|
||||
// types
|
||||
pub mod bonk_types;
|
||||
pub mod meteora_damm_v2_types;
|
||||
pub mod pumpswap_types;
|
||||
pub mod raydium_amm_v4_types;
|
||||
pub mod raydium_cpmm_types;
|
||||
pub mod meteora_damm_v2_types;
|
||||
@@ -178,11 +178,7 @@ pub fn get_mayhem_fee_recipient_meta_random() -> AccountMeta {
|
||||
let recipient = *global_constants::MAYHEM_FEE_RECIPIENTS
|
||||
.choose(&mut rand::rng())
|
||||
.unwrap_or(&global_constants::MAYHEM_FEE_RECIPIENTS[0]);
|
||||
AccountMeta {
|
||||
pubkey: recipient,
|
||||
is_signer: false,
|
||||
is_writable: true,
|
||||
}
|
||||
AccountMeta { pubkey: recipient, is_signer: false, is_writable: true }
|
||||
}
|
||||
|
||||
pub struct Symbol;
|
||||
|
||||
@@ -169,11 +169,7 @@ pub fn get_mayhem_fee_recipient_random() -> (Pubkey, AccountMeta) {
|
||||
let recipient = *accounts::MAYHEM_FEE_RECIPIENTS
|
||||
.choose(&mut rand::rng())
|
||||
.unwrap_or(&accounts::MAYHEM_FEE_RECIPIENTS[0]);
|
||||
let meta = AccountMeta {
|
||||
pubkey: recipient,
|
||||
is_signer: false,
|
||||
is_writable: false,
|
||||
};
|
||||
let meta = AccountMeta { pubkey: recipient, is_signer: false, is_writable: false };
|
||||
(recipient, meta)
|
||||
}
|
||||
|
||||
@@ -334,7 +330,7 @@ pub async fn find_by_base_mint(
|
||||
if accounts.is_empty() {
|
||||
return Err(anyhow!("No pool found for mint {}", base_mint));
|
||||
}
|
||||
let accounts_count = accounts.len(); // 🔧 保存长度,因为 into_iter() 会消耗 accounts
|
||||
let accounts_count = accounts.len(); // 🔧 保存长度,因为 into_iter() 会消耗 accounts
|
||||
let mut pools: Vec<_> = accounts
|
||||
.into_iter()
|
||||
.filter_map(|(addr, acc)| {
|
||||
@@ -349,7 +345,11 @@ pub async fn find_by_base_mint(
|
||||
|
||||
// 🔧 修复:检查过滤后的 pools 是否为空(accounts 可能不为空但解码全部失败)
|
||||
if pools.is_empty() {
|
||||
return Err(anyhow!("No valid pool decoded for mint {} (found {} accounts but all decode failed)", base_mint, accounts_count));
|
||||
return Err(anyhow!(
|
||||
"No valid pool decoded for mint {} (found {} accounts but all decode failed)",
|
||||
base_mint,
|
||||
accounts_count
|
||||
));
|
||||
}
|
||||
|
||||
pools.sort_by(|a, b| b.1.lp_supply.cmp(&a.1.lp_supply));
|
||||
@@ -386,7 +386,7 @@ pub async fn find_by_quote_mint(
|
||||
if accounts.is_empty() {
|
||||
return Err(anyhow!("No pool found for mint {}", quote_mint));
|
||||
}
|
||||
let accounts_count = accounts.len(); // 🔧 保存长度,因为 into_iter() 会消耗 accounts
|
||||
let accounts_count = accounts.len(); // 🔧 保存长度,因为 into_iter() 会消耗 accounts
|
||||
let mut pools: Vec<_> = accounts
|
||||
.into_iter()
|
||||
.filter_map(|(addr, acc)| {
|
||||
@@ -401,7 +401,11 @@ pub async fn find_by_quote_mint(
|
||||
|
||||
// 🔧 修复:检查过滤后的 pools 是否为空(accounts 可能不为空但解码全部失败)
|
||||
if pools.is_empty() {
|
||||
return Err(anyhow!("No valid pool decoded for quote_mint {} (found {} accounts but all decode failed)", quote_mint, accounts_count));
|
||||
return Err(anyhow!(
|
||||
"No valid pool decoded for quote_mint {} (found {} accounts but all decode failed)",
|
||||
quote_mint,
|
||||
accounts_count
|
||||
));
|
||||
}
|
||||
|
||||
pools.sort_by(|a, b| b.1.lp_supply.cmp(&a.1.lp_supply));
|
||||
|
||||
@@ -135,9 +135,11 @@ pub fn get_vault_account(
|
||||
) -> Pubkey {
|
||||
if protocol_params.base_mint == *token_mint && protocol_params.base_vault != Pubkey::default() {
|
||||
protocol_params.base_vault
|
||||
} else if protocol_params.quote_mint == *token_mint && protocol_params.quote_vault != Pubkey::default() {
|
||||
} else if protocol_params.quote_mint == *token_mint
|
||||
&& protocol_params.quote_vault != Pubkey::default()
|
||||
{
|
||||
protocol_params.quote_vault
|
||||
} else {
|
||||
get_vault_pda(pool_state, token_mint).unwrap()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user