diff --git a/src/bot.rs b/src/bot.rs index 171317a..d5c12ac 100644 --- a/src/bot.rs +++ b/src/bot.rs @@ -6,8 +6,11 @@ use helius::Helius; use tokio::sync::{Mutex, watch}; use crate::{ - data::account::{Account, AccountManager}, - data::tradelog::TradeLog, + data::{ + account::{Account, AccountManager}, + tradelog::TradeLog, + }, + launchpad::Executor, strategy::{Strategy, veloc::MomentumVelocityStrategy}, }; @@ -17,7 +20,7 @@ pub struct Bot { pub strategy: Mutex>, - pub executor: Mutex<()>, + pub executor: Mutex, pub trade_log: Mutex>, pub helius: Helius, @@ -41,7 +44,7 @@ impl Bot { strategy: Mutex::new(Box::new(MomentumVelocityStrategy::new())), trade_log: Mutex::new(Vec::new()), - executor: Mutex::new(()), + executor: Mutex::new(Executor::new()), })) } diff --git a/src/launchpad/mod.rs b/src/launchpad/mod.rs new file mode 100644 index 0000000..58faf35 --- /dev/null +++ b/src/launchpad/mod.rs @@ -0,0 +1,67 @@ +mod pump_fun; + +use crate::launchpad::pump_fun::PumpFun; +use rust_decimal::Decimal; +use std::collections::HashMap; + +pub struct Executor { + pub pump_fun: PumpFun, +} + +#[allow(unused_variables)] +#[async_trait::async_trait] +pub trait Launchpad: Send + Sync { + async fn buy( + &mut self, + mint: &str, + amount: Decimal, + priority: Decimal, + slippage: u16, + ) -> anyhow::Result<()>; + + async fn sell( + &mut self, + mint: &str, + amount: u8, + priority: Decimal, + slippage: u16, + ) -> anyhow::Result<()>; + + fn get_positions(&self) -> HashMap; +} + +impl Executor { + pub fn new() -> Self { + Self { + pump_fun: PumpFun::new(), + } + } + + pub async fn buy( + &mut self, + mint: &str, + amount: Decimal, + priority: Decimal, + slippage: u16, + ) -> anyhow::Result<()> { + self.pump_fun.buy(mint, amount, priority, slippage).await + } + + pub async fn sell( + &mut self, + mint: &str, + amount: u8, + priority: Decimal, + slippage: u16, + ) -> anyhow::Result<()> { + self.pump_fun.sell(mint, amount, priority, slippage).await + } + + pub async fn sell_all(&mut self, priority: Decimal, slippage: u16) -> anyhow::Result<()> { + for (mint, _) in self.pump_fun.get_positions() { + self.pump_fun.sell(&mint, 100, priority, slippage).await?; + } + + Ok(()) + } +} diff --git a/src/launchpad/pump_fun.rs b/src/launchpad/pump_fun.rs new file mode 100644 index 0000000..6e19d27 --- /dev/null +++ b/src/launchpad/pump_fun.rs @@ -0,0 +1,45 @@ +use std::collections::HashMap; + +use rust_decimal::Decimal; + +use crate::launchpad::Launchpad; + +pub struct PumpFun { + pub positions: HashMap, +} + +impl PumpFun { + pub fn new() -> Self { + Self { + positions: HashMap::new(), + } + } +} + +#[allow(unused_variables)] +#[async_trait::async_trait] +impl Launchpad for PumpFun { + async fn buy( + &mut self, + mint: &str, + amount: Decimal, + priority: Decimal, + slippage: u16, + ) -> anyhow::Result<()> { + Ok(()) + } + + async fn sell( + &mut self, + mint: &str, + amount: u8, + priority: Decimal, + slippage: u16, + ) -> anyhow::Result<()> { + Ok(()) + } + + fn get_positions<'a>(&'a self) -> HashMap { + self.positions.clone() + } +} diff --git a/src/main.rs b/src/main.rs index a2acef3..f42f639 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,7 +1,7 @@ pub mod bot; pub mod data; pub mod strategy; -// pub mod types; +pub mod launchpad; use std::sync::Arc; diff --git a/src/strategy/veloc.rs b/src/strategy/veloc.rs index fe7f09f..905ddaf 100644 --- a/src/strategy/veloc.rs +++ b/src/strategy/veloc.rs @@ -173,7 +173,7 @@ impl Strategy for MomentumVelocityStrategy { bot.executor .lock() .await - .sell_percent(mint, 100, PRIORITY, SLIPPAGE) + .sell(mint, 100, PRIORITY, SLIPPAGE) .await?; if let Some(mut pos) = self.positions.remove(mint) {