style: run rustfmt

This commit is contained in:
hookenful
2026-03-14 18:16:55 +02:00
parent 0ec826fcbd
commit 2abcf3839e
76 changed files with 1763 additions and 1352 deletions
+1 -1
View File
@@ -1,8 +1,8 @@
use dashmap::DashMap;
use once_cell::sync::Lazy;
use smallvec::SmallVec;
use solana_sdk::instruction::Instruction;
use solana_compute_budget_interface::ComputeBudgetInstruction;
use solana_sdk::instruction::Instruction;
use std::sync::Arc;
/// Cache key containing all parameters for compute budget instructions
+3 -3
View File
@@ -1,12 +1,12 @@
pub mod compute_budget_manager;
pub mod nonce_manager;
pub mod transaction_builder;
pub mod compute_budget_manager;
pub mod utils;
pub mod wsol_manager;
// Re-export commonly used functions
pub use compute_budget_manager::*;
pub use nonce_manager::*;
pub use transaction_builder::*;
pub use compute_budget_manager::*;
pub use utils::*;
pub use wsol_manager::*;
pub use wsol_manager::*;
+3 -2
View File
@@ -15,10 +15,11 @@ pub fn add_nonce_instruction(
durable_nonce: Option<&DurableNonceInfo>,
) -> Result<(), anyhow::Error> {
if let Some(durable_nonce) = durable_nonce {
let nonce_advance_ix = advance_nonce_account(&durable_nonce.nonce_account.unwrap(), &payer.pubkey());
let nonce_advance_ix =
advance_nonce_account(&durable_nonce.nonce_account.unwrap(), &payer.pubkey());
instructions.push(nonce_advance_ix);
}
Ok(())
}
+4 -1
View File
@@ -9,7 +9,10 @@ use std::sync::Arc;
use super::nonce_manager::{add_nonce_instruction, get_transaction_blockhash};
use crate::{
common::{nonce_cache::DurableNonceInfo, SolanaRpcClient},
trading::{MiddlewareManager, core::transaction_pool::{acquire_builder, release_builder}},
trading::{
core::transaction_pool::{acquire_builder, release_builder},
MiddlewareManager,
},
};
/// Convert SOL amount (f64) to lamports without string allocation (hot path).
+1 -8
View File
@@ -40,14 +40,7 @@ pub async fn get_token_balance(
payer: &Pubkey,
mint: &Pubkey,
) -> Result<u64, anyhow::Error> {
get_token_balance_with_options(
rpc,
payer,
mint,
&crate::constants::TOKEN_PROGRAM,
false,
)
.await
get_token_balance_with_options(rpc, payer, mint, &crate::constants::TOKEN_PROGRAM, false).await
}
/// 使用与交易指令一致的 ATA 推导(可选 seed)查询余额;卖出/余额查询应与买入使用同一 ATA 地址。
+11 -21
View File
@@ -1,7 +1,10 @@
use crate::common::{
fast_fn::create_associated_token_account_idempotent_fast,
seed::{
create_associated_token_account_use_seed,
get_associated_token_address_with_program_id_use_seed,
},
spl_token::close_account,
seed::{create_associated_token_account_use_seed, get_associated_token_address_with_program_id_use_seed},
};
use smallvec::SmallVec;
use solana_sdk::{instruction::Instruction, message::AccountMeta, pubkey::Pubkey};
@@ -38,7 +41,7 @@ pub fn handle_wsol(payer: &Pubkey, amount_in: u64) -> SmallVec<[Instruction; 3]>
pub fn close_wsol(payer: &Pubkey) -> Vec<Instruction> {
use std::sync::Arc;
let wsol_token_account =
crate::common::fast_fn::get_associated_token_address_with_program_id_fast(
&payer,
@@ -61,7 +64,7 @@ pub fn close_wsol(payer: &Pubkey) -> Vec<Instruction> {
.unwrap()]
},
);
// 🚀 性能优化:尝试零开销解包 Arc
Arc::try_unwrap(arc_instructions).unwrap_or_else(|arc| (*arc).clone())
}
@@ -109,10 +112,7 @@ pub fn wrap_sol_only(payer: &Pubkey, amount_in: u64) -> SmallVec<[Instruction; 2
///
/// 注意:此函数只生成指令,不检查账户是否存在(需要调用方在发送交易前检查)
/// 如果临时账户已存在,可以安全地跳过创建步骤,直接转账并关闭
pub fn wrap_wsol_to_sol(
payer: &Pubkey,
amount: u64,
) -> Result<Vec<Instruction>, anyhow::Error> {
pub fn wrap_wsol_to_sol(payer: &Pubkey, amount: u64) -> Result<Vec<Instruction>, anyhow::Error> {
let mut instructions = Vec::new();
// 1. 创建 WSOL seed 账户(注意:如果账户已存在会失败)
@@ -151,13 +151,8 @@ pub fn wrap_wsol_to_sol(
instructions.push(transfer_instruction);
// 5. 添加关闭 WSOL seed 账户的指令
let close_instruction = close_account(
&crate::constants::TOKEN_PROGRAM,
&seed_ata_address,
payer,
payer,
&[],
)?;
let close_instruction =
close_account(&crate::constants::TOKEN_PROGRAM, &seed_ata_address, payer, payer, &[])?;
instructions.push(close_instruction);
Ok(instructions)
@@ -197,13 +192,8 @@ pub fn wrap_wsol_to_sol_without_create(
instructions.push(transfer_instruction);
// 4. 添加关闭 WSOL seed 账户的指令
let close_instruction = close_account(
&crate::constants::TOKEN_PROGRAM,
&seed_ata_address,
payer,
payer,
&[],
)?;
let close_instruction =
close_account(&crate::constants::TOKEN_PROGRAM, &seed_ata_address, payer, payer, &[])?;
instructions.push(close_instruction);
Ok(instructions)