update dir

This commit is contained in:
wood
2025-07-10 02:53:01 +08:00
parent 794207b6c2
commit f1649ac933
11 changed files with 12 additions and 227 deletions
-14
View File
@@ -1,14 +0,0 @@
//! Accounts for the Pump.fun Solana Program
//!
//! This module contains the definitions for the accounts used by the Pump.fun program.
//!
//! # Accounts
//!
//! - `BondingCurve`: Represents a bonding curve account.
//! - `Global`: Represents the global configuration account.
mod bonding_curve;
mod global;
pub use bonding_curve::*;
pub use global::*;
+2
View File
@@ -4,5 +4,7 @@ pub mod tip_cache;
pub mod types;
pub mod address_lookup_cache;
pub mod subscription_handle;
pub mod bonding_curve;
pub mod global;
pub use types::*;
-197
View File
@@ -1,197 +0,0 @@
//! Error types for the Pump.fun SDK.
//!
//! This module defines the `ClientError` enum, which encompasses various error types that can occur when interacting with the Pump.fun program.
//! It includes specific error cases for bonding curve operations, metadata uploads, Solana client errors, and more.
//!
//! The `ClientError` enum provides a comprehensive set of error types to help developers handle and debug issues that may arise during interactions with the Pump.fun program.
//!
//! # Error Types
//!
//! - `BondingCurveNotFound`: The bonding curve account was not found.
//! - `BondingCurveError`: An error occurred while interacting with the bonding curve.
//! - `BorshError`: An error occurred while serializing or deserializing data using Borsh.
//! - `SolanaClientError`: An error occurred while interacting with the Solana RPC client.
//! - `UploadMetadataError`: An error occurred while uploading metadata to IPFS.
//! - `InvalidInput`: Invalid input parameters were provided.
//! - `InsufficientFunds`: Insufficient funds for a transaction.
//! - `SimulationError`: Transaction simulation failed.
//! - `RateLimitExceeded`: Rate limit exceeded.
use serde_json::Error;
use solana_client::{
client_error::ClientError as SolanaClientError,
pubsub_client::PubsubClientError
};
use solana_sdk::pubkey::ParsePubkeyError;
// #[derive(Debug)]
// #[allow(dead_code)]
// pub struct AppError(anyhow::Error);
// impl<E> From<E> for AppError
// where
// E: Into<anyhow::Error>,
// {
// fn from(err: E) -> Self {
// Self(err.into())
// }
// }
#[derive(Debug)]
pub enum ClientError {
/// Bonding curve account was not found
BondingCurveNotFound,
/// Error related to bonding curve operations
BondingCurveError(&'static str),
/// Error deserializing data using Borsh
BorshError(std::io::Error),
/// Error from Solana RPC client
SolanaClientError(solana_client::client_error::ClientError),
/// Error uploading metadata
UploadMetadataError(Box<dyn std::error::Error>),
/// Invalid input parameters
InvalidInput(&'static str),
/// Insufficient funds for transaction
InsufficientFunds,
/// Transaction simulation failed
SimulationError(String),
/// Rate limit exceeded
RateLimitExceeded,
OrderLimitExceeded,
ExternalService(String),
Redis(String, String),
Solana(String, String),
Parse(String, String),
Pubkey(String, String),
Jito(String, String),
Join(String),
Subscribe(String, String),
Send(String, String),
Other(String),
Anyhow(&'static str),
InvalidData(String),
PumpFunBuy(String),
PumpFunSell(String),
Timeout(String, String),
Duplicate(String),
InvalidEventType,
ChannelClosed,
}
impl std::fmt::Display for ClientError {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self {
Self::BondingCurveNotFound => write!(f, "Bonding curve not found"),
Self::BondingCurveError(msg) => write!(f, "Bonding curve error: {}", msg),
Self::BorshError(err) => write!(f, "Borsh serialization error: {}", err),
Self::SolanaClientError(err) => write!(f, "Solana client error: {}", err),
Self::UploadMetadataError(err) => write!(f, "Metadata upload error: {}", err),
Self::InvalidInput(msg) => write!(f, "Invalid input: {}", msg),
Self::InsufficientFunds => write!(f, "Insufficient funds for transaction"),
Self::SimulationError(msg) => write!(f, "Transaction simulation failed: {}", msg),
Self::ExternalService(msg) => write!(f, "External service error: {}", msg),
Self::RateLimitExceeded => write!(f, "Rate limit exceeded"),
Self::OrderLimitExceeded => write!(f, "Order limit exceeded"),
Self::Anyhow(msg) => write!(f, "Anyhow error: {}", msg),
Self::Solana(msg, details) => write!(f, "Solana error: {}, details: {}", msg, details),
Self::Parse(msg, details) => write!(f, "Parse error: {}, details: {}", msg, details),
Self::Jito(msg, details) => write!(f, "Jito error: {}, details: {}", msg, details),
Self::Redis(msg, details) => write!(f, "Redis error: {}, details: {}", msg, details),
Self::Join(msg) => write!(f, "Task join error: {}", msg),
Self::Pubkey(msg, details) => write!(f, "Pubkey error: {}, details: {}", msg, details),
Self::Subscribe(msg, details) => write!(f, "Subscribe error: {}, details: {}", msg, details),
Self::Send(msg, details) => write!(f, "Send error: {}, details: {}", msg, details),
Self::Other(msg) => write!(f, "Other error: {}", msg),
Self::PumpFunBuy(msg) => write!(f, "PumpFun buy error: {}", msg),
Self::PumpFunSell(msg) => write!(f, "PumpFun sell error: {}", msg),
Self::InvalidData(msg) => write!(f, "Invalid data: {}", msg),
Self::Timeout(msg, details) => write!(f, "Operation timed out: {}, details: {}", msg, details),
Self::Duplicate(msg) => write!(f, "Duplicate event: {}", msg),
Self::InvalidEventType => write!(f, "Invalid event type"),
Self::ChannelClosed => write!(f, "Channel closed"),
}
}
}
impl std::error::Error for ClientError {
fn source(&self) -> Option<&(dyn std::error::Error + 'static)> {
match self {
Self::BorshError(err) => Some(err),
Self::SolanaClientError(err) => Some(err),
Self::UploadMetadataError(err) => Some(err.as_ref()),
Self::ExternalService(_) => None,
Self::Redis(_, _) => None,
Self::Solana(_, _) => None,
Self::Parse(_, _) => None,
Self::Jito(_, _) => None,
Self::Join(_) => None,
Self::Pubkey(_, _) => None,
Self::Subscribe(_, _) => None,
Self::Send(_, _) => None,
Self::Other(_) => None,
Self::PumpFunBuy(_) => None,
Self::PumpFunSell(_) => None,
Self::Timeout(_, _) => None,
Self::Duplicate(_) => None,
Self::InvalidEventType => None,
Self::ChannelClosed => None,
_ => None,
}
}
}
impl From<SolanaClientError> for ClientError {
fn from(error: SolanaClientError) -> Self {
ClientError::Solana(
"Solana client error".to_string(),
error.to_string(),
)
}
}
impl From<PubsubClientError> for ClientError {
fn from(error: PubsubClientError) -> Self {
ClientError::Solana(
"PubSub client error".to_string(),
error.to_string(),
)
}
}
impl From<ParsePubkeyError> for ClientError {
fn from(error: ParsePubkeyError) -> Self {
ClientError::Pubkey(
"Pubkey error".to_string(),
error.to_string(),
)
}
}
impl From<Error> for ClientError {
fn from(err: Error) -> Self {
ClientError::Parse(
"JSON serialization error".to_string(),
err.to_string()
)
}
}
pub type ClientResult<T> = Result<T, ClientError>;
-1
View File
@@ -9,7 +9,6 @@ use std::collections::HashMap;
use std::fmt::Debug;
use crate::{
error,
event_parser::{common::{utils::*, EventMetadata, EventType, ProtocolType}, protocols::{pumpfun::{PumpFunCreateTokenEvent, PumpFunTradeEvent}, bonk::{BonkPoolCreateEvent, BonkTradeEvent}}},
};
-3
View File
@@ -1,7 +1,5 @@
pub mod accounts;
pub mod common;
pub mod constants;
pub mod error;
pub mod event_parser;
pub mod grpc;
pub mod instruction;
@@ -22,7 +20,6 @@ use swqos::SwqosClient;
use common::{PriorityFee, SolanaRpcClient, TradeConfig};
use accounts::BondingCurveAccount;
use constants::trade_platform::{PUMPFUN, PUMPFUN_SWAP, BONK};
use constants::trade_type::{COPY_BUY, SNIPER_BUY};
+1 -2
View File
@@ -1,8 +1,7 @@
use std::{str::FromStr, sync::Arc};
use sol_trade_sdk::{
accounts::BondingCurveAccount,
common::{AnyResult, PriorityFee, TradeConfig},
common::{bonding_curve::BondingCurveAccount, AnyResult, PriorityFee, TradeConfig},
constants::{pumpfun::global_constants::TOKEN_TOTAL_SUPPLY, trade_type},
event_parser::{
protocols::{
+1 -1
View File
@@ -5,7 +5,7 @@ use std::sync::Arc;
use super::traits::ProtocolParams;
use crate::common::{PriorityFee, SolanaRpcClient};
use crate::swqos::SwqosClient;
use crate::accounts::BondingCurveAccount;
use crate::common::bonding_curve::BondingCurveAccount;
/// 通用买入参数
#[derive(Clone)]
+1 -2
View File
@@ -1,6 +1,5 @@
use crate::accounts::BondingCurveAccount;
use crate::{
common::{PriorityFee, SolanaRpcClient},
common::{bonding_curve::BondingCurveAccount, PriorityFee, SolanaRpcClient},
swqos::SwqosClient,
trading::{core::params::PumpFunParams, factory::Protocol, BuyParams, TradeFactory},
};
+7 -7
View File
@@ -8,10 +8,10 @@ use solana_sdk::{
};
use spl_associated_token_account::get_associated_token_address;
use pumpfun_program::accounts::BondingCurveAccount as PumpfunBondingCurveAccount;
use crate::{accounts::{self, BondingCurveAccount}, common::{PriorityFee, SolanaRpcClient}, constants::{self, pumpfun::{self, global_constants::{CREATOR_FEE, FEE_BASIS_POINTS}, trade::DEFAULT_SLIPPAGE}}, event_parser::protocols::pumpfun::PumpFunTradeEvent};
use crate::{common::{bonding_curve::BondingCurveAccount, global::GlobalAccount, PriorityFee, SolanaRpcClient}, constants::{self, pumpfun::{self, global_constants::{CREATOR_FEE, FEE_BASIS_POINTS}, trade::DEFAULT_SLIPPAGE}}, event_parser::protocols::pumpfun::PumpFunTradeEvent};
lazy_static::lazy_static! {
static ref ACCOUNT_CACHE: RwLock<HashMap<Pubkey, Arc<accounts::GlobalAccount>>> = RwLock::new(HashMap::new());
static ref ACCOUNT_CACHE: RwLock<HashMap<Pubkey, Arc<GlobalAccount>>> = RwLock::new(HashMap::new());
}
pub async fn transfer_sol(rpc: &SolanaRpcClient, payer: &Keypair, receive_wallet: &Pubkey, amount: u64) -> Result<(), anyhow::Error> {
@@ -185,13 +185,13 @@ pub fn get_metadata_pda(mint: &Pubkey) -> Pubkey {
}
#[inline]
pub async fn get_global_account(/*rpc: &SolanaRpcClient*/) -> Result<Arc<accounts::GlobalAccount>, anyhow::Error> {
pub async fn get_global_account(/*rpc: &SolanaRpcClient*/) -> Result<Arc<GlobalAccount>, anyhow::Error> {
// let global = constants::global_constants::GLOBAL_ACCOUNT;
// if let Some(account) = ACCOUNT_CACHE.read().await.get(&global) {
// return Ok(account.clone());
// }
let global_account = accounts::GlobalAccount::new();
let global_account = GlobalAccount::new();
// let account = rpc.get_account(&global).await?;
// let global_account = bincode::deserialize::<accounts::GlobalAccount>(&account.data)?;
@@ -202,7 +202,7 @@ pub async fn get_global_account(/*rpc: &SolanaRpcClient*/) -> Result<Arc<account
}
#[inline]
pub async fn get_initial_buy_price(global_account: &Arc<accounts::GlobalAccount>, amount_sol: u64) -> Result<u64, anyhow::Error> {
pub async fn get_initial_buy_price(global_account: &Arc<GlobalAccount>, amount_sol: u64) -> Result<u64, anyhow::Error> {
let buy_amount = global_account.get_initial_buy_price(amount_sol);
Ok(buy_amount)
}
@@ -211,7 +211,7 @@ pub async fn get_initial_buy_price(global_account: &Arc<accounts::GlobalAccount>
pub async fn get_bonding_curve_account(
rpc: &SolanaRpcClient,
mint: &Pubkey,
) -> Result<(Arc<accounts::BondingCurveAccount>, Pubkey), anyhow::Error> {
) -> Result<(Arc<BondingCurveAccount>, Pubkey), anyhow::Error> {
let bonding_curve_pda = get_bonding_curve_pda(mint)
.ok_or(anyhow!("Bonding curve not found"))?;
@@ -220,7 +220,7 @@ pub async fn get_bonding_curve_account(
return Err(anyhow!("Bonding curve not found"));
}
let bonding_curve = Arc::new(bincode::deserialize::<accounts::BondingCurveAccount>(&account.data)?);
let bonding_curve = Arc::new(bincode::deserialize::<BondingCurveAccount>(&account.data)?);
Ok((bonding_curve, bonding_curve_pda))
}