Launchpad

This commit is contained in:
2026-08-07 15:41:56 +02:00
parent 2f084bab24
commit d5c446b779
5 changed files with 121 additions and 6 deletions
+67
View File
@@ -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<String, Decimal>;
}
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(())
}
}
+45
View File
@@ -0,0 +1,45 @@
use std::collections::HashMap;
use rust_decimal::Decimal;
use crate::launchpad::Launchpad;
pub struct PumpFun {
pub positions: HashMap<String, Decimal>,
}
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<String, Decimal> {
self.positions.clone()
}
}