diff --git a/Cargo.lock b/Cargo.lock index 7fe6ee8..3a836be 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -233,7 +233,7 @@ dependencies = [ "rustc-hash", "rustls", "rustls-pki-types", - "rustls-platform-verifier 0.6.2", + "rustls-platform-verifier", "slab", "thiserror 2.0.19", "tinyvec", @@ -353,29 +353,6 @@ version = "1.5.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f2032f911046de80f0a198e0901378627c33f59ea0ac00e363d481118bd70a53" -[[package]] -name = "aws-lc-rs" -version = "1.17.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "00bdb5da18dac48ca2cc7cd4a98e533e8635a58e2361d13a1a4ee3888e0d72f1" -dependencies = [ - "aws-lc-sys", - "zeroize", -] - -[[package]] -name = "aws-lc-sys" -version = "0.43.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "43103168cc76fe62678a375e722fc9cb3a0146159ac5828bc4f0dfd755c2224c" -dependencies = [ - "cc", - "cmake", - "dunce", - "fs_extra", - "pkg-config", -] - [[package]] name = "base16ct" version = "0.2.0" @@ -681,15 +658,6 @@ dependencies = [ "inout", ] -[[package]] -name = "cmake" -version = "0.1.58" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c0f78a02292a74a88ac736019ab962ece0bc380e3f977bf72e376c5d78ff0678" -dependencies = [ - "cc", -] - [[package]] name = "cmov" version = "0.5.4" @@ -761,28 +729,12 @@ version = "0.9.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c2459377285ad874054d797f3ccebf984978aa39129f6eafde5cdc8315b612f8" -[[package]] -name = "const-oid" -version = "0.10.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a6ef517f0926dd24a1582492c791b6a4818a4d94e789a334894aa15b0d12f55c" - [[package]] name = "constant_time_eq" version = "0.4.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3d52eff69cd5e647efe296129160853a42795992097e8af39800e1060caeea9b" -[[package]] -name = "core-foundation" -version = "0.9.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "91e195e091a93c46f7102ec7818a2aa394e1e1771c3ab4825963fa03e45afb8f" -dependencies = [ - "core-foundation-sys", - "libc", -] - [[package]] name = "core-foundation" version = "0.10.1" @@ -1084,7 +1036,7 @@ version = "0.7.10" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e7c1832837b905bbfb5101e07cc24c8deddf52f93225eee6ead5f4d63d53ddcb" dependencies = [ - "const-oid 0.9.6", + "const-oid", "zeroize", ] @@ -1121,7 +1073,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9ed9a281f7bc9b7576e61468ba615a66a5c8cfdff42420a70aa82701a3b1e292" dependencies = [ "block-buffer 0.10.4", - "const-oid 0.9.6", + "const-oid", "crypto-common 0.1.7", "subtle", ] @@ -1133,7 +1085,6 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f1dd6dbb5841937940781866fa1281a1ff7bd3bf827091440879f9994983d5c2" dependencies = [ "block-buffer 0.12.1", - "const-oid 0.10.2", "crypto-common 0.2.2", "ctutils", ] @@ -1172,12 +1123,6 @@ dependencies = [ "syn 2.0.119", ] -[[package]] -name = "dunce" -version = "1.0.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "92773504d58c093f6de2459af4af33faa518c13451eb8f2b5698ed3d36e7c813" - [[package]] name = "ecdsa" version = "0.16.9" @@ -1260,15 +1205,6 @@ version = "1.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "34aa73646ffb006b8f5147f3dc182bd4bcb190227ce861fc4a4844bf8e3cb2c0" -[[package]] -name = "encoding_rs" -version = "0.8.35" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "75030f3c4f45dafd7586dd6780965a8c7e8e285a5ecb86713e63a79c5b2766f3" -dependencies = [ - "cfg-if", -] - [[package]] name = "env_filter" version = "2.0.0" @@ -1453,12 +1389,6 @@ dependencies = [ "percent-encoding", ] -[[package]] -name = "fs_extra" -version = "1.3.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "42703706b716c37f96a77aea830392ad231f44c9e9a67872fa5548707e11b11c" - [[package]] name = "funty" version = "2.0.0" @@ -1652,25 +1582,6 @@ dependencies = [ "subtle", ] -[[package]] -name = "h2" -version = "0.4.15" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6cb093c84e8bd9b188d4c4a8cb6579fc016968d14c99882163cd3ff402a4f155" -dependencies = [ - "atomic-waker", - "bytes", - "fnv", - "futures-core", - "futures-sink", - "http 1.5.0", - "indexmap", - "slab", - "tokio", - "tokio-util", - "tracing", -] - [[package]] name = "halfbrown" version = "0.3.0" @@ -1736,7 +1647,7 @@ dependencies = [ "once_cell", "phf", "rand 0.9.5", - "reqwest 0.12.28", + "reqwest", "semver", "serde", "serde-enum-str", @@ -1755,7 +1666,7 @@ dependencies = [ "thiserror 2.0.19", "tokio", "tokio-stream", - "tokio-tungstenite 0.28.0", + "tokio-tungstenite", "url", ] @@ -1849,7 +1760,6 @@ dependencies = [ "bytes", "futures-channel", "futures-core", - "h2", "http 1.5.0", "http-body", "httparse", @@ -1910,11 +1820,9 @@ dependencies = [ "percent-encoding", "pin-project-lite", "socket2", - "system-configuration", "tokio", "tower-service", "tracing", - "windows-registry", ] [[package]] @@ -2161,36 +2069,6 @@ dependencies = [ "windows-sys 0.45.0", ] -[[package]] -name = "jni" -version = "0.22.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5efd9a482cf3a427f00d6b35f14332adc7902ce91efb778580e180ff90fa3498" -dependencies = [ - "cfg-if", - "combine 4.6.7", - "jni-macros", - "jni-sys 0.4.1", - "log", - "simd_cesu8", - "thiserror 2.0.19", - "walkdir", - "windows-link", -] - -[[package]] -name = "jni-macros" -version = "0.22.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a00109accc170f0bdb141fed3e393c565b6f5e072365c3bd58f5b062591560a3" -dependencies = [ - "proc-macro2", - "quote", - "rustc_version", - "simd_cesu8", - "syn 2.0.119", -] - [[package]] name = "jni-sys" version = "0.3.1" @@ -2356,12 +2234,6 @@ dependencies = [ "zeroize", ] -[[package]] -name = "mime" -version = "0.3.17" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6877bb514081ee2a7ff5ef9de3281f14a4dd4bceac4c09388074a6b5df8a139a" - [[package]] name = "minimal-lexical" version = "0.2.1" @@ -2917,7 +2789,6 @@ version = "0.11.16" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "2f4bfc015262b9df63c8845072ce59068853ff5872180c2ce2f13038b970e560" dependencies = [ - "aws-lc-rs", "bytes", "getrandom 0.4.3", "lru-slab", @@ -3199,46 +3070,6 @@ dependencies = [ "webpki-roots 1.0.9", ] -[[package]] -name = "reqwest" -version = "0.13.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "219c5811de6525e5416c7d5d53bb656d3afdbc6c5af816e0802bcfa42dbdc1c3" -dependencies = [ - "base64 0.22.1", - "bytes", - "encoding_rs", - "futures-core", - "h2", - "http 1.5.0", - "http-body", - "http-body-util", - "hyper", - "hyper-rustls", - "hyper-util", - "js-sys", - "log", - "mime", - "percent-encoding", - "pin-project-lite", - "quinn", - "rustls", - "rustls-pki-types", - "rustls-platform-verifier 0.7.0", - "serde", - "serde_json", - "sync_wrapper", - "tokio", - "tokio-rustls", - "tower", - "tower-http", - "tower-service", - "url", - "wasm-bindgen", - "wasm-bindgen-futures", - "web-sys", -] - [[package]] name = "reqwest-middleware" version = "0.4.2" @@ -3248,7 +3079,7 @@ dependencies = [ "anyhow", "async-trait", "http 1.5.0", - "reqwest 0.12.28", + "reqwest", "serde", "thiserror 1.0.69", "tower-service", @@ -3384,7 +3215,6 @@ version = "0.23.43" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0283386ce02abc0151e1761d08802dfe86c173b0b494af5cbc086574e453da06" dependencies = [ - "aws-lc-rs", "once_cell", "ring", "rustls-pki-types", @@ -3421,30 +3251,9 @@ version = "0.6.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1d99feebc72bae7ab76ba994bb5e121b8d83d910ca40b36e0921f53becc41784" dependencies = [ - "core-foundation 0.10.1", + "core-foundation", "core-foundation-sys", - "jni 0.21.1", - "log", - "once_cell", - "rustls", - "rustls-native-certs", - "rustls-platform-verifier-android", - "rustls-webpki", - "security-framework", - "security-framework-sys", - "webpki-root-certs", - "windows-sys 0.61.2", -] - -[[package]] -name = "rustls-platform-verifier" -version = "0.7.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "26d1e2536ce4f35f4846aa13bff16bd0ff40157cdb14cc056c7b14ba41233ba0" -dependencies = [ - "core-foundation 0.10.1", - "core-foundation-sys", - "jni 0.22.4", + "jni", "log", "once_cell", "rustls", @@ -3469,7 +3278,6 @@ version = "0.103.13" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "61c429a8649f110dddef65e2a5ad240f747e85f7758a6bccc7e5777bd33f756e" dependencies = [ - "aws-lc-rs", "ring", "rustls-pki-types", "untrusted", @@ -3538,7 +3346,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b7f4bc775c73d9a02cde8bf7b2ec4c9d12743edf609006c7facc23998404cd1d" dependencies = [ "bitflags 2.13.1", - "core-foundation 0.10.1", + "core-foundation", "core-foundation-sys", "libc", "security-framework-sys", @@ -3697,17 +3505,6 @@ dependencies = [ "digest 0.10.7", ] -[[package]] -name = "sha1" -version = "0.11.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "aacc4cc499359472b4abe1bf11d0b12e688af9a805fa5e3016f9a386dc2d0214" -dependencies = [ - "cfg-if", - "cpufeatures 0.3.0", - "digest 0.11.3", -] - [[package]] name = "sha2" version = "0.10.9" @@ -3793,16 +3590,6 @@ dependencies = [ "value-trait", ] -[[package]] -name = "simd_cesu8" -version = "1.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "11031e251abf8611c80f460e19dbdeb54a66db918e49c65a7065b46ac7aec520" -dependencies = [ - "rustc_version", - "simdutf8", -] - [[package]] name = "simdutf8" version = "0.1.5" @@ -3852,15 +3639,12 @@ dependencies = [ "chrono", "csv", "env_logger", - "futures-util", "helius", "log", - "reqwest 0.13.4", "rust_decimal", "serde", "serde_json", "tokio", - "tokio-tungstenite 0.30.0", ] [[package]] @@ -4592,7 +4376,7 @@ dependencies = [ "crossbeam-channel", "gethostname", "log", - "reqwest 0.12.28", + "reqwest", "solana-cluster-type", "solana-sha256-hasher", "solana-time-utils", @@ -4868,8 +4652,8 @@ dependencies = [ "thiserror 2.0.19", "tokio", "tokio-stream", - "tokio-tungstenite 0.28.0", - "tungstenite 0.28.0", + "tokio-tungstenite", + "tungstenite", "url", ] @@ -4958,7 +4742,7 @@ dependencies = [ "futures", "indicatif", "log", - "reqwest 0.12.28", + "reqwest", "reqwest-middleware", "semver", "serde", @@ -4993,7 +4777,7 @@ checksum = "8a81a57ed54176e3aa4bca8e894f9326638a3f6870f79b078d8b3fadda8a4c9b" dependencies = [ "anyhow", "jsonrpc-core", - "reqwest 0.12.28", + "reqwest", "reqwest-middleware", "serde", "serde_json", @@ -6055,27 +5839,6 @@ dependencies = [ "syn 2.0.119", ] -[[package]] -name = "system-configuration" -version = "0.7.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a13f3d0daba03132c0aa9767f98351b3488edc2c100cda2d2ec2b04f3d8d3c8b" -dependencies = [ - "bitflags 2.13.1", - "core-foundation 0.9.4", - "system-configuration-sys", -] - -[[package]] -name = "system-configuration-sys" -version = "0.6.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8e1d1b10ced5ca923a1fcb8d03e96b8d3268065d724548c0211415ff6ac6bac4" -dependencies = [ - "core-foundation-sys", - "libc", -] - [[package]] name = "tap" version = "1.0.1" @@ -6263,24 +6026,10 @@ dependencies = [ "tokio", "tokio-native-tls", "tokio-rustls", - "tungstenite 0.28.0", + "tungstenite", "webpki-roots 0.26.11", ] -[[package]] -name = "tokio-tungstenite" -version = "0.30.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "17a073bfed563fa236697a068031408a93cd9522e08abf9933ead3e73411bd71" -dependencies = [ - "futures-util", - "log", - "native-tls", - "tokio", - "tokio-native-tls", - "tungstenite 0.30.0", -] - [[package]] name = "tokio-util" version = "0.7.19" @@ -6291,7 +6040,6 @@ dependencies = [ "futures-core", "futures-sink", "futures-util", - "libc", "pin-project-lite", "tokio", ] @@ -6417,29 +6165,12 @@ dependencies = [ "rand 0.9.5", "rustls", "rustls-pki-types", - "sha1 0.10.7", + "sha1", "thiserror 2.0.19", "utf-8", "webpki-roots 0.26.11", ] -[[package]] -name = "tungstenite" -version = "0.30.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e48ac77174b19c110a50ab2128b24215ac9cb40e0e12e093fb602d175c569d22" -dependencies = [ - "bytes", - "data-encoding", - "http 1.5.0", - "httparse", - "log", - "native-tls", - "rand 0.10.2", - "sha1 0.11.0", - "thiserror 2.0.19", -] - [[package]] name = "typenum" version = "1.20.1" @@ -6809,17 +6540,6 @@ version = "0.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f0805222e57f7521d6a62e36fa9163bc891acd422f971defe97d64e70d0a4fe5" -[[package]] -name = "windows-registry" -version = "0.6.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "02752bf7fbdcce7f2a27a742f798510f3e5ad88dbe84871e5168e2120c3d5720" -dependencies = [ - "windows-link", - "windows-result", - "windows-strings", -] - [[package]] name = "windows-result" version = "0.4.1" diff --git a/Cargo.toml b/Cargo.toml index 246397b..6178806 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -4,18 +4,15 @@ version = "0.1.0" edition = "2024" [dependencies] +tokio = { version = "1.53.1", features = ["macros", "rt-multi-thread", "sync", "fs", "io-std"] } anyhow = "1.0.104" -futures-util = "0.3.33" serde = { version = "1.0.229", features = ["derive", "serde_derive"] } serde_json = "1.0.151" -tokio = { version = "1.53.1", features = ["macros", "rt-multi-thread", "sync", "fs", "io-std"] } -tokio-tungstenite = { version = "0.30.0", features = ["native-tls"] } log = "0.4.33" env_logger = "0.11.11" rust_decimal = { version = "1.42.1", features = ["macros"] } -reqwest = { version = "0.13.4", features = ["json"] } async-trait = "0.1.91" csv = "1.4.0" chrono = { version = "0.4.45", features = ["serde"] } diff --git a/src/account.rs b/src/account.rs index 6210ecc..8ab401d 100644 --- a/src/account.rs +++ b/src/account.rs @@ -37,6 +37,8 @@ impl AccountManager { tokio::fs::create_dir_all(path.parent().unwrap()).await?; tokio::fs::write(&path, default.to_string()?).await?; + println!("Please open {path:?} and edit the data accordingly"); + return Ok(default); } diff --git a/src/bot.rs b/src/bot.rs index d75126a..676aa2b 100644 --- a/src/bot.rs +++ b/src/bot.rs @@ -1,63 +1,27 @@ use std::{collections::HashMap, sync::Arc}; use anyhow::Context; -use futures_util::{SinkExt, StreamExt}; -use serde_json::json; -use tokio::{ - net::TcpStream, - sync::{Mutex, watch}, -}; -use tokio_tungstenite::{MaybeTlsStream, WebSocketStream, connect_async}; +use helius::Helius; + +use tokio::sync::{Mutex, watch}; use crate::{ - account::AccountManager, + account::{Account, AccountManager}, executor::{ExecutorWrapper, pump_fun::PumpDev}, strategy::{Strategy, veloc::MomentumVelocityStrategy}, tradelog::TradeLog, }; pub struct Bot { - pub ws: Mutex>>, - pub accounts: Mutex, - pub executor: Mutex, + pub account_manager: Mutex, + pub current_account: Mutex, + pub strategy: Mutex>, + + pub executor: Mutex, pub trade_log: Mutex>, -} -impl Bot { - pub async fn subscribe(&self, mint: &str) -> anyhow::Result<()> { - self.ws - .lock() - .await - .send(tokio_tungstenite::tungstenite::Message::Text( - json!({ - "method": "subscribeTokenTrade", - "keys": [mint] - }) - .to_string() - .into(), - )) - .await?; - - Ok(()) - } - - pub async fn unsubscribe(&self, mint: &str) -> anyhow::Result<()> { - self.ws - .lock() - .await - .send(tokio_tungstenite::tungstenite::Message::Text( - json!({ - "method": "unsubscribeTokenTrade", - "keys": [mint] - }) - .to_string() - .into(), - )) - .await?; - - Ok(()) - } + pub helius: Helius, } impl Bot { @@ -71,55 +35,24 @@ impl Bot { .clone(); Ok(Arc::new(Self { - ws: Mutex::new(connect_async("wss://pumpdev.io/ws").await?.0), + helius: Helius::new_async(&accounts.api_key, helius::types::Cluster::Devnet).await?, + + account_manager: Mutex::new(accounts), + current_account: Mutex::new(account), + strategy: Mutex::new(Box::new(MomentumVelocityStrategy::new())), + + trade_log: Mutex::new(Vec::new()), executor: Mutex::new(ExecutorWrapper { - executor: Box::new(PumpDev { account }), + executor: Box::new(PumpDev {}), positions: HashMap::new(), }), - accounts: Mutex::new(accounts), - strategy: Mutex::new(Box::new(MomentumVelocityStrategy::new())), - trade_log: Mutex::new(Vec::new()), })) } - pub async fn refresh_account(self: &Arc) -> anyhow::Result<()> { - self.strategy - .lock() - .await - .execute_sell_all(self.clone()) - .await?; - - let accounts = self.accounts.lock().await; - - let account = accounts - .accounts - .get(&accounts.active) - .context("Failed to get account")? - .clone(); - - self.executor.lock().await.executor = Box::new(PumpDev { account }); - - Ok(()) - } - - pub async fn initialize_websocket_subscribe(&self) -> anyhow::Result<()> { - self.ws - .lock() - .await - .send(tokio_tungstenite::tungstenite::Message::Text( - json!({ "method": "subscribeNewToken" }).to_string().into(), - )) - .await?; - - Ok(()) - } - pub async fn start( self: &Arc, mut shutdown: watch::Receiver, ) -> anyhow::Result<()> { - self.initialize_websocket_subscribe().await?; - loop { tokio::select! { _ = shutdown.changed() => { @@ -151,44 +84,50 @@ impl Bot { } pub async fn tick(self: &Arc) -> anyhow::Result { - let mut ws = self.ws.lock().await; + // drop(ws); + // self.strategy + // .lock() + // .await + // .on_new_coin(self.clone(), token) + // .await?; - if let Some(msg) = ws.next().await.transpose()? { - if let tokio_tungstenite::tungstenite::Message::Text(text) = msg { - match serde_json::from_str::(&text) { - Ok(crate::types::PumpDevEvent::Create(token)) => { - drop(ws); + // drop(ws); + // self.strategy + // .lock() + // .await + // .on_trade(self.clone(), trade) + // .await?; - self.strategy - .lock() - .await - .on_new_coin(self.clone(), token) - .await?; - } + Ok(false) + } +} - Ok(crate::types::PumpDevEvent::Trade(trade)) => { - drop(ws); +impl Bot { + pub async fn subscribe(&self, mint: &str) -> anyhow::Result<()> { + Ok(()) + } - self.strategy - .lock() - .await - .on_trade(self.clone(), trade) - .await?; - } + pub async fn unsubscribe(&self, mint: &str) -> anyhow::Result<()> { + Ok(()) + } - Ok(_event) => { - // println!("{:?}", event); - } + pub async fn refresh_account(self: &Arc) -> anyhow::Result<()> { + self.strategy + .lock() + .await + .execute_sell_all(self.clone()) + .await?; - Err(err) => { - log::error!("{err}, MSG -> {text}"); - } - } - } + let accounts = self.account_manager.lock().await; - Ok(false) - } else { - Ok(true) - } + let account = accounts + .accounts + .get(&accounts.active) + .context("Failed to get account")? + .clone(); + + *self.current_account.lock().await = account; + + Ok(()) } } diff --git a/src/executor/pump_fun.rs b/src/executor/pump_fun.rs index d29c7eb..d6c091b 100644 --- a/src/executor/pump_fun.rs +++ b/src/executor/pump_fun.rs @@ -1,10 +1,8 @@ use rust_decimal::Decimal; -use crate::{account::Account, executor::Executor}; +use crate::executor::Executor; -pub struct PumpDev { - pub account: Account, -} +pub struct PumpDev {} #[async_trait::async_trait] impl Executor for PumpDev {