2024-12-31 16:51:58 +08:00
//! 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.
2024-12-31 17:46:05 +08:00
use serde_json ::Error ;
2025-01-23 17:48:10 +08:00
use solana_client ::{
2024-12-31 17:46:05 +08:00
client_error ::ClientError as SolanaClientError ,
pubsub_client ::PubsubClientError
};
2025-01-09 00:12:43 +08:00
use solana_sdk ::pubkey ::ParsePubkeyError ;
2024-12-31 16:51:58 +08:00
2025-01-25 12:41:21 +08:00
// #[derive(Debug)]
// #[allow(dead_code)]
// pub struct AppError(anyhow::Error);
2025-01-23 21:15:55 +08:00
2025-01-25 12:41:21 +08:00
// impl<E> From<E> for AppError
// where
// E: Into<anyhow::Error>,
// {
// fn from(err: E) -> Self {
// Self(err.into())
// }
// }
2025-01-23 21:15:55 +08:00
2024-12-31 16:51:58 +08:00
#[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 ,
2024-12-31 17:46:05 +08:00
2025-01-08 16:33:43 +08:00
OrderLimitExceeded ,
2025-01-03 19:06:17 +08:00
ExternalService ( String ),
2025-01-07 13:18:31 +08:00
Redis ( String , String ),
2025-01-03 19:06:17 +08:00
2024-12-31 17:46:05 +08:00
Solana ( String , String ),
Parse ( String , String ),
2025-01-09 00:12:43 +08:00
Pubkey ( String , String ),
2025-01-03 14:43:26 +08:00
Jito ( String , String ),
2024-12-31 17:46:05 +08:00
Join ( String ),
Subscribe ( String , String ),
Send ( String , String ),
Other ( String ),
2025-02-01 09:44:15 +08:00
Anyhow ( & 'static str ),
2025-01-03 19:06:17 +08:00
InvalidData ( String ),
PumpFunBuy ( String ),
PumpFunSell ( String ),
2024-12-31 17:46:05 +08:00
Timeout ( String , String ),
Duplicate ( String ),
InvalidEventType ,
ChannelClosed ,
2024-12-31 16:51:58 +08:00
}
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 ),
2025-01-03 19:06:17 +08:00
Self ::ExternalService ( msg ) => write! ( f , "External service error: {}" , msg ),
2024-12-31 16:51:58 +08:00
Self ::RateLimitExceeded => write! ( f , "Rate limit exceeded" ),
2025-01-08 16:33:43 +08:00
Self ::OrderLimitExceeded => write! ( f , "Order limit exceeded" ),
2025-02-01 09:44:15 +08:00
Self ::Anyhow ( msg ) => write! ( f , "Anyhow error: {}" , msg ),
2024-12-31 17:46:05 +08:00
Self ::Solana ( msg , details ) => write! ( f , "Solana error: {}, details: {}" , msg , details ),
Self ::Parse ( msg , details ) => write! ( f , "Parse error: {}, details: {}" , msg , details ),
2025-01-03 14:43:26 +08:00
Self ::Jito ( msg , details ) => write! ( f , "Jito error: {}, details: {}" , msg , details ),
2025-01-07 13:18:31 +08:00
Self ::Redis ( msg , details ) => write! ( f , "Redis error: {}, details: {}" , msg , details ),
2024-12-31 17:46:05 +08:00
Self ::Join ( msg ) => write! ( f , "Task join error: {}" , msg ),
2025-01-09 00:12:43 +08:00
Self ::Pubkey ( msg , details ) => write! ( f , "Pubkey error: {}, details: {}" , msg , details ),
2024-12-31 17:46:05 +08:00
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 ),
2025-01-03 19:06:17 +08:00
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 ),
2024-12-31 17:46:05 +08:00
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" ),
2024-12-31 16:51:58 +08:00
}
}
}
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 ()),
2025-01-03 19:06:17 +08:00
Self ::ExternalService ( _ ) => None ,
2025-01-07 13:18:31 +08:00
Self ::Redis ( _ , _ ) => None ,
2025-01-03 19:06:17 +08:00
Self ::Solana ( _ , _ ) => None ,
Self ::Parse ( _ , _ ) => None ,
Self ::Jito ( _ , _ ) => None ,
Self ::Join ( _ ) => None ,
2025-01-09 00:12:43 +08:00
Self ::Pubkey ( _ , _ ) => None ,
2025-01-03 19:06:17 +08:00
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 ,
2024-12-31 16:51:58 +08:00
_ => None ,
}
}
}
2024-12-31 17:46:05 +08:00
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 (),
)
}
}
2025-01-09 00:12:43 +08:00
impl From < ParsePubkeyError > for ClientError {
fn from ( error : ParsePubkeyError ) -> Self {
ClientError ::Pubkey (
"Pubkey error" . to_string (),
error . to_string (),
)
}
}
2024-12-31 17:46:05 +08:00
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 > ;