add bot trade

This commit is contained in:
William
2025-01-03 17:06:19 +08:00
parent bec7305f0e
commit 5c0b8c87e2
7 changed files with 19 additions and 15 deletions
+1 -1
View File
@@ -3,7 +3,7 @@ use serde::{Serialize, Deserialize};
#[derive(Debug)]
pub enum DexInstruction {
CreateToken(CreateTokenInfo),
Trade(TradeInfo),
UserTrade(TradeInfo),
BotTrade(TradeInfo),
Other,
}
@@ -4,7 +4,7 @@ use crate::instruction::logs_data::{CreateTokenInfo, TradeInfo};
#[derive(Debug, Clone, Serialize, Deserialize)]
pub enum DexEvent {
NewToken(CreateTokenInfo),
NewTrade(TradeInfo),
NewUserTrade(TradeInfo),
NewBotTrade(TradeInfo),
Error(String),
}
@@ -9,7 +9,7 @@ impl LogFilter {
const PROGRAM_ID: &'static str = "6EF8rrecthR5Dkzon8Nwu78hRvfCKubJ14M5uBEwF6P";
/// Parse transaction logs and return instruction type and data
pub fn parse_instruction(logs: &[String], payer: Option<Pubkey>) -> ClientResult<Vec<DexInstruction>> {
pub fn parse_instruction(logs: &[String], bot_wallet: Option<Pubkey>) -> ClientResult<Vec<DexInstruction>> {
let mut current_instruction = None;
let mut program_data = String::new();
let mut invoke_depth = 0;
@@ -65,14 +65,14 @@ impl LogFilter {
},
"trade" => {
if let Ok(trade_info) = parse_trade_data(&program_data) {
if let Some(payer_pubkey) = payer {
if trade_info.user == payer_pubkey.to_string() {
if let Some(bot_wallet_pubkey) = bot_wallet {
if trade_info.user == bot_wallet_pubkey.to_string() {
instructions.push(DexInstruction::BotTrade(trade_info));
} else {
instructions.push(DexInstruction::Trade(trade_info));
instructions.push(DexInstruction::UserTrade(trade_info));
}
} else {
instructions.push(DexInstruction::Trade(trade_info));
instructions.push(DexInstruction::UserTrade(trade_info));
}
}
},
@@ -34,7 +34,7 @@ pub async fn tokens_subscription<F>(
ws_url: &str,
commitment: CommitmentConfig,
callback: F,
payer: Option<Pubkey>,
bot_wallet: Option<Pubkey>,
) -> Result<SubscriptionHandle, Box<dyn std::error::Error>>
where
F: Fn(DexEvent) + Send + Sync + 'static,
@@ -66,14 +66,14 @@ where
continue;
}
let instructions = LogFilter::parse_instruction(&msg.value.logs, payer).unwrap();
let instructions = LogFilter::parse_instruction(&msg.value.logs, bot_wallet).unwrap();
for instruction in instructions {
match instruction {
DexInstruction::CreateToken(token_info) => {
callback(DexEvent::NewToken(token_info));
}
DexInstruction::Trade(trade_info) => {
callback(DexEvent::NewTrade(trade_info));
DexInstruction::UserTrade(trade_info) => {
callback(DexEvent::NewUserTrade(trade_info));
}
DexInstruction::BotTrade(trade_info) => {
callback(DexEvent::NewBotTrade(trade_info));
+1 -1
View File
@@ -22,7 +22,7 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
DexEvent::NewToken(token_info) => {
println!("Received new token event: {:?}", token_info);
},
DexEvent::NewTrade(trade_info) => {
DexEvent::NewUserTrade(trade_info) => {
println!("Received new trade event: {:?}", trade_info);
},
DexEvent::NewBotTrade(trade_info) => {