Files
sol-trade-sdk/src/common/logs_data.rs
T

88 lines
2.3 KiB
Rust
Raw Normal View History

2025-01-24 14:01:56 +08:00
use borsh::{BorshDeserialize, BorshSerialize};
use solana_sdk::pubkey::Pubkey;
2025-01-25 12:41:21 +08:00
use crate::error::{ClientError, ClientResult};
2025-01-03 00:38:45 +08:00
#[derive(Debug)]
pub enum DexInstruction {
CreateToken(CreateTokenInfo),
2025-01-03 17:06:19 +08:00
UserTrade(TradeInfo),
2025-01-03 17:01:07 +08:00
BotTrade(TradeInfo),
2025-01-03 00:38:45 +08:00
Other,
}
2025-01-24 14:01:56 +08:00
#[derive(Clone, Debug, Default, PartialEq, BorshDeserialize, BorshSerialize)]
2024-12-31 17:46:05 +08:00
pub struct CreateTokenInfo {
pub name: String,
pub symbol: String,
pub uri: String,
2025-01-24 14:01:56 +08:00
pub mint: Pubkey,
pub bonding_curve: Pubkey,
pub user: Pubkey,
2024-12-31 17:46:05 +08:00
}
2025-01-24 14:01:56 +08:00
#[derive(Clone, Debug, Default, PartialEq, BorshDeserialize, BorshSerialize)]
2024-12-31 17:46:05 +08:00
pub struct TradeInfo {
2025-01-24 14:01:56 +08:00
pub mint: Pubkey,
2024-12-31 17:46:05 +08:00
pub sol_amount: u64,
pub token_amount: u64,
pub is_buy: bool,
2025-01-24 14:01:56 +08:00
pub user: Pubkey,
2024-12-31 17:46:05 +08:00
pub timestamp: i64,
pub virtual_sol_reserves: u64,
pub virtual_token_reserves: u64,
pub real_sol_reserves: u64,
pub real_token_reserves: u64,
2025-01-24 14:01:56 +08:00
}
#[derive(Clone, Debug, Default, PartialEq, BorshDeserialize, BorshSerialize)]
pub struct CompleteInfo {
pub user: Pubkey,
pub mint: Pubkey,
pub bonding_curve: Pubkey,
pub timestamp: u64,
}
#[derive(Clone, Debug, Default, PartialEq, BorshDeserialize, BorshSerialize)]
pub struct SwapBaseInLog {
pub log_type: u8,
// input
pub amount_in: u64,
pub minimum_out: u64,
pub direction: u64,
// user info
pub user_source: u64,
// pool info
pub pool_coin: u64,
pub pool_pc: u64,
// calc result
pub out_amount: u64,
}
pub trait EventTrait: Sized + std::fmt::Debug {
2025-01-25 12:41:21 +08:00
fn from_bytes(bytes: &[u8]) -> ClientResult<Self>;
2025-01-24 14:01:56 +08:00
}
impl EventTrait for CreateTokenInfo {
2025-01-25 12:41:21 +08:00
fn from_bytes(bytes: &[u8]) -> ClientResult<Self> {
CreateTokenInfo::try_from_slice(bytes).map_err(|e| ClientError::Other(e.to_string()))
2025-01-24 14:01:56 +08:00
}
}
impl EventTrait for TradeInfo {
2025-01-25 12:41:21 +08:00
fn from_bytes(bytes: &[u8]) -> ClientResult<Self> {
TradeInfo::try_from_slice(bytes).map_err(|e| ClientError::Other(e.to_string()))
2025-01-24 14:01:56 +08:00
}
}
impl EventTrait for CompleteInfo {
2025-01-25 12:41:21 +08:00
fn from_bytes(bytes: &[u8]) -> ClientResult<Self> {
CompleteInfo::try_from_slice(bytes).map_err(|e| ClientError::Other(e.to_string()))
2025-01-24 14:01:56 +08:00
}
}
impl EventTrait for SwapBaseInLog {
2025-01-25 12:41:21 +08:00
fn from_bytes(bytes: &[u8]) -> ClientResult<Self> {
SwapBaseInLog::try_from_slice(bytes).map_err(|e| ClientError::Other(e.to_string()))
2025-01-24 14:01:56 +08:00
}
2024-12-31 17:46:05 +08:00
}