Refactoring to helius

This commit is contained in:
2026-08-07 09:03:07 +02:00
parent ba2baadd11
commit 6757452264
5 changed files with 77 additions and 421 deletions
Generated
+16 -296
View File
@@ -233,7 +233,7 @@ dependencies = [
"rustc-hash", "rustc-hash",
"rustls", "rustls",
"rustls-pki-types", "rustls-pki-types",
"rustls-platform-verifier 0.6.2", "rustls-platform-verifier",
"slab", "slab",
"thiserror 2.0.19", "thiserror 2.0.19",
"tinyvec", "tinyvec",
@@ -353,29 +353,6 @@ version = "1.5.1"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f2032f911046de80f0a198e0901378627c33f59ea0ac00e363d481118bd70a53" 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]] [[package]]
name = "base16ct" name = "base16ct"
version = "0.2.0" version = "0.2.0"
@@ -681,15 +658,6 @@ dependencies = [
"inout", "inout",
] ]
[[package]]
name = "cmake"
version = "0.1.58"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c0f78a02292a74a88ac736019ab962ece0bc380e3f977bf72e376c5d78ff0678"
dependencies = [
"cc",
]
[[package]] [[package]]
name = "cmov" name = "cmov"
version = "0.5.4" version = "0.5.4"
@@ -761,28 +729,12 @@ version = "0.9.6"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c2459377285ad874054d797f3ccebf984978aa39129f6eafde5cdc8315b612f8" checksum = "c2459377285ad874054d797f3ccebf984978aa39129f6eafde5cdc8315b612f8"
[[package]]
name = "const-oid"
version = "0.10.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a6ef517f0926dd24a1582492c791b6a4818a4d94e789a334894aa15b0d12f55c"
[[package]] [[package]]
name = "constant_time_eq" name = "constant_time_eq"
version = "0.4.2" version = "0.4.2"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3d52eff69cd5e647efe296129160853a42795992097e8af39800e1060caeea9b" 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]] [[package]]
name = "core-foundation" name = "core-foundation"
version = "0.10.1" version = "0.10.1"
@@ -1084,7 +1036,7 @@ version = "0.7.10"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e7c1832837b905bbfb5101e07cc24c8deddf52f93225eee6ead5f4d63d53ddcb" checksum = "e7c1832837b905bbfb5101e07cc24c8deddf52f93225eee6ead5f4d63d53ddcb"
dependencies = [ dependencies = [
"const-oid 0.9.6", "const-oid",
"zeroize", "zeroize",
] ]
@@ -1121,7 +1073,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9ed9a281f7bc9b7576e61468ba615a66a5c8cfdff42420a70aa82701a3b1e292" checksum = "9ed9a281f7bc9b7576e61468ba615a66a5c8cfdff42420a70aa82701a3b1e292"
dependencies = [ dependencies = [
"block-buffer 0.10.4", "block-buffer 0.10.4",
"const-oid 0.9.6", "const-oid",
"crypto-common 0.1.7", "crypto-common 0.1.7",
"subtle", "subtle",
] ]
@@ -1133,7 +1085,6 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f1dd6dbb5841937940781866fa1281a1ff7bd3bf827091440879f9994983d5c2" checksum = "f1dd6dbb5841937940781866fa1281a1ff7bd3bf827091440879f9994983d5c2"
dependencies = [ dependencies = [
"block-buffer 0.12.1", "block-buffer 0.12.1",
"const-oid 0.10.2",
"crypto-common 0.2.2", "crypto-common 0.2.2",
"ctutils", "ctutils",
] ]
@@ -1172,12 +1123,6 @@ dependencies = [
"syn 2.0.119", "syn 2.0.119",
] ]
[[package]]
name = "dunce"
version = "1.0.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "92773504d58c093f6de2459af4af33faa518c13451eb8f2b5698ed3d36e7c813"
[[package]] [[package]]
name = "ecdsa" name = "ecdsa"
version = "0.16.9" version = "0.16.9"
@@ -1260,15 +1205,6 @@ version = "1.0.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "34aa73646ffb006b8f5147f3dc182bd4bcb190227ce861fc4a4844bf8e3cb2c0" 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]] [[package]]
name = "env_filter" name = "env_filter"
version = "2.0.0" version = "2.0.0"
@@ -1453,12 +1389,6 @@ dependencies = [
"percent-encoding", "percent-encoding",
] ]
[[package]]
name = "fs_extra"
version = "1.3.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "42703706b716c37f96a77aea830392ad231f44c9e9a67872fa5548707e11b11c"
[[package]] [[package]]
name = "funty" name = "funty"
version = "2.0.0" version = "2.0.0"
@@ -1652,25 +1582,6 @@ dependencies = [
"subtle", "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]] [[package]]
name = "halfbrown" name = "halfbrown"
version = "0.3.0" version = "0.3.0"
@@ -1736,7 +1647,7 @@ dependencies = [
"once_cell", "once_cell",
"phf", "phf",
"rand 0.9.5", "rand 0.9.5",
"reqwest 0.12.28", "reqwest",
"semver", "semver",
"serde", "serde",
"serde-enum-str", "serde-enum-str",
@@ -1755,7 +1666,7 @@ dependencies = [
"thiserror 2.0.19", "thiserror 2.0.19",
"tokio", "tokio",
"tokio-stream", "tokio-stream",
"tokio-tungstenite 0.28.0", "tokio-tungstenite",
"url", "url",
] ]
@@ -1849,7 +1760,6 @@ dependencies = [
"bytes", "bytes",
"futures-channel", "futures-channel",
"futures-core", "futures-core",
"h2",
"http 1.5.0", "http 1.5.0",
"http-body", "http-body",
"httparse", "httparse",
@@ -1910,11 +1820,9 @@ dependencies = [
"percent-encoding", "percent-encoding",
"pin-project-lite", "pin-project-lite",
"socket2", "socket2",
"system-configuration",
"tokio", "tokio",
"tower-service", "tower-service",
"tracing", "tracing",
"windows-registry",
] ]
[[package]] [[package]]
@@ -2161,36 +2069,6 @@ dependencies = [
"windows-sys 0.45.0", "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]] [[package]]
name = "jni-sys" name = "jni-sys"
version = "0.3.1" version = "0.3.1"
@@ -2356,12 +2234,6 @@ dependencies = [
"zeroize", "zeroize",
] ]
[[package]]
name = "mime"
version = "0.3.17"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6877bb514081ee2a7ff5ef9de3281f14a4dd4bceac4c09388074a6b5df8a139a"
[[package]] [[package]]
name = "minimal-lexical" name = "minimal-lexical"
version = "0.2.1" version = "0.2.1"
@@ -2917,7 +2789,6 @@ version = "0.11.16"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2f4bfc015262b9df63c8845072ce59068853ff5872180c2ce2f13038b970e560" checksum = "2f4bfc015262b9df63c8845072ce59068853ff5872180c2ce2f13038b970e560"
dependencies = [ dependencies = [
"aws-lc-rs",
"bytes", "bytes",
"getrandom 0.4.3", "getrandom 0.4.3",
"lru-slab", "lru-slab",
@@ -3199,46 +3070,6 @@ dependencies = [
"webpki-roots 1.0.9", "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]] [[package]]
name = "reqwest-middleware" name = "reqwest-middleware"
version = "0.4.2" version = "0.4.2"
@@ -3248,7 +3079,7 @@ dependencies = [
"anyhow", "anyhow",
"async-trait", "async-trait",
"http 1.5.0", "http 1.5.0",
"reqwest 0.12.28", "reqwest",
"serde", "serde",
"thiserror 1.0.69", "thiserror 1.0.69",
"tower-service", "tower-service",
@@ -3384,7 +3215,6 @@ version = "0.23.43"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0283386ce02abc0151e1761d08802dfe86c173b0b494af5cbc086574e453da06" checksum = "0283386ce02abc0151e1761d08802dfe86c173b0b494af5cbc086574e453da06"
dependencies = [ dependencies = [
"aws-lc-rs",
"once_cell", "once_cell",
"ring", "ring",
"rustls-pki-types", "rustls-pki-types",
@@ -3421,30 +3251,9 @@ version = "0.6.2"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1d99feebc72bae7ab76ba994bb5e121b8d83d910ca40b36e0921f53becc41784" checksum = "1d99feebc72bae7ab76ba994bb5e121b8d83d910ca40b36e0921f53becc41784"
dependencies = [ dependencies = [
"core-foundation 0.10.1", "core-foundation",
"core-foundation-sys", "core-foundation-sys",
"jni 0.21.1", "jni",
"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",
"log", "log",
"once_cell", "once_cell",
"rustls", "rustls",
@@ -3469,7 +3278,6 @@ version = "0.103.13"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "61c429a8649f110dddef65e2a5ad240f747e85f7758a6bccc7e5777bd33f756e" checksum = "61c429a8649f110dddef65e2a5ad240f747e85f7758a6bccc7e5777bd33f756e"
dependencies = [ dependencies = [
"aws-lc-rs",
"ring", "ring",
"rustls-pki-types", "rustls-pki-types",
"untrusted", "untrusted",
@@ -3538,7 +3346,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b7f4bc775c73d9a02cde8bf7b2ec4c9d12743edf609006c7facc23998404cd1d" checksum = "b7f4bc775c73d9a02cde8bf7b2ec4c9d12743edf609006c7facc23998404cd1d"
dependencies = [ dependencies = [
"bitflags 2.13.1", "bitflags 2.13.1",
"core-foundation 0.10.1", "core-foundation",
"core-foundation-sys", "core-foundation-sys",
"libc", "libc",
"security-framework-sys", "security-framework-sys",
@@ -3697,17 +3505,6 @@ dependencies = [
"digest 0.10.7", "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]] [[package]]
name = "sha2" name = "sha2"
version = "0.10.9" version = "0.10.9"
@@ -3793,16 +3590,6 @@ dependencies = [
"value-trait", "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]] [[package]]
name = "simdutf8" name = "simdutf8"
version = "0.1.5" version = "0.1.5"
@@ -3852,15 +3639,12 @@ dependencies = [
"chrono", "chrono",
"csv", "csv",
"env_logger", "env_logger",
"futures-util",
"helius", "helius",
"log", "log",
"reqwest 0.13.4",
"rust_decimal", "rust_decimal",
"serde", "serde",
"serde_json", "serde_json",
"tokio", "tokio",
"tokio-tungstenite 0.30.0",
] ]
[[package]] [[package]]
@@ -4592,7 +4376,7 @@ dependencies = [
"crossbeam-channel", "crossbeam-channel",
"gethostname", "gethostname",
"log", "log",
"reqwest 0.12.28", "reqwest",
"solana-cluster-type", "solana-cluster-type",
"solana-sha256-hasher", "solana-sha256-hasher",
"solana-time-utils", "solana-time-utils",
@@ -4868,8 +4652,8 @@ dependencies = [
"thiserror 2.0.19", "thiserror 2.0.19",
"tokio", "tokio",
"tokio-stream", "tokio-stream",
"tokio-tungstenite 0.28.0", "tokio-tungstenite",
"tungstenite 0.28.0", "tungstenite",
"url", "url",
] ]
@@ -4958,7 +4742,7 @@ dependencies = [
"futures", "futures",
"indicatif", "indicatif",
"log", "log",
"reqwest 0.12.28", "reqwest",
"reqwest-middleware", "reqwest-middleware",
"semver", "semver",
"serde", "serde",
@@ -4993,7 +4777,7 @@ checksum = "8a81a57ed54176e3aa4bca8e894f9326638a3f6870f79b078d8b3fadda8a4c9b"
dependencies = [ dependencies = [
"anyhow", "anyhow",
"jsonrpc-core", "jsonrpc-core",
"reqwest 0.12.28", "reqwest",
"reqwest-middleware", "reqwest-middleware",
"serde", "serde",
"serde_json", "serde_json",
@@ -6055,27 +5839,6 @@ dependencies = [
"syn 2.0.119", "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]] [[package]]
name = "tap" name = "tap"
version = "1.0.1" version = "1.0.1"
@@ -6263,24 +6026,10 @@ dependencies = [
"tokio", "tokio",
"tokio-native-tls", "tokio-native-tls",
"tokio-rustls", "tokio-rustls",
"tungstenite 0.28.0", "tungstenite",
"webpki-roots 0.26.11", "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]] [[package]]
name = "tokio-util" name = "tokio-util"
version = "0.7.19" version = "0.7.19"
@@ -6291,7 +6040,6 @@ dependencies = [
"futures-core", "futures-core",
"futures-sink", "futures-sink",
"futures-util", "futures-util",
"libc",
"pin-project-lite", "pin-project-lite",
"tokio", "tokio",
] ]
@@ -6417,29 +6165,12 @@ dependencies = [
"rand 0.9.5", "rand 0.9.5",
"rustls", "rustls",
"rustls-pki-types", "rustls-pki-types",
"sha1 0.10.7", "sha1",
"thiserror 2.0.19", "thiserror 2.0.19",
"utf-8", "utf-8",
"webpki-roots 0.26.11", "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]] [[package]]
name = "typenum" name = "typenum"
version = "1.20.1" version = "1.20.1"
@@ -6809,17 +6540,6 @@ version = "0.2.1"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f0805222e57f7521d6a62e36fa9163bc891acd422f971defe97d64e70d0a4fe5" 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]] [[package]]
name = "windows-result" name = "windows-result"
version = "0.4.1" version = "0.4.1"
+1 -4
View File
@@ -4,18 +4,15 @@ version = "0.1.0"
edition = "2024" edition = "2024"
[dependencies] [dependencies]
tokio = { version = "1.53.1", features = ["macros", "rt-multi-thread", "sync", "fs", "io-std"] }
anyhow = "1.0.104" anyhow = "1.0.104"
futures-util = "0.3.33"
serde = { version = "1.0.229", features = ["derive", "serde_derive"] } serde = { version = "1.0.229", features = ["derive", "serde_derive"] }
serde_json = "1.0.151" 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" log = "0.4.33"
env_logger = "0.11.11" env_logger = "0.11.11"
rust_decimal = { version = "1.42.1", features = ["macros"] } rust_decimal = { version = "1.42.1", features = ["macros"] }
reqwest = { version = "0.13.4", features = ["json"] }
async-trait = "0.1.91" async-trait = "0.1.91"
csv = "1.4.0" csv = "1.4.0"
chrono = { version = "0.4.45", features = ["serde"] } chrono = { version = "0.4.45", features = ["serde"] }
+2
View File
@@ -37,6 +37,8 @@ impl AccountManager {
tokio::fs::create_dir_all(path.parent().unwrap()).await?; tokio::fs::create_dir_all(path.parent().unwrap()).await?;
tokio::fs::write(&path, default.to_string()?).await?; tokio::fs::write(&path, default.to_string()?).await?;
println!("Please open {path:?} and edit the data accordingly");
return Ok(default); return Ok(default);
} }
+59 -120
View File
@@ -1,63 +1,27 @@
use std::{collections::HashMap, sync::Arc}; use std::{collections::HashMap, sync::Arc};
use anyhow::Context; use anyhow::Context;
use futures_util::{SinkExt, StreamExt}; use helius::Helius;
use serde_json::json;
use tokio::{ use tokio::sync::{Mutex, watch};
net::TcpStream,
sync::{Mutex, watch},
};
use tokio_tungstenite::{MaybeTlsStream, WebSocketStream, connect_async};
use crate::{ use crate::{
account::AccountManager, account::{Account, AccountManager},
executor::{ExecutorWrapper, pump_fun::PumpDev}, executor::{ExecutorWrapper, pump_fun::PumpDev},
strategy::{Strategy, veloc::MomentumVelocityStrategy}, strategy::{Strategy, veloc::MomentumVelocityStrategy},
tradelog::TradeLog, tradelog::TradeLog,
}; };
pub struct Bot { pub struct Bot {
pub ws: Mutex<WebSocketStream<MaybeTlsStream<TcpStream>>>, pub account_manager: Mutex<AccountManager>,
pub accounts: Mutex<AccountManager>, pub current_account: Mutex<Account>,
pub executor: Mutex<ExecutorWrapper>,
pub strategy: Mutex<Box<dyn Strategy>>, pub strategy: Mutex<Box<dyn Strategy>>,
pub executor: Mutex<ExecutorWrapper>,
pub trade_log: Mutex<Vec<TradeLog>>, pub trade_log: Mutex<Vec<TradeLog>>,
}
impl Bot { pub helius: Helius,
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(())
}
} }
impl Bot { impl Bot {
@@ -71,55 +35,24 @@ impl Bot {
.clone(); .clone();
Ok(Arc::new(Self { 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: Mutex::new(ExecutorWrapper {
executor: Box::new(PumpDev { account }), executor: Box::new(PumpDev {}),
positions: HashMap::new(), 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<Self>) -> 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( pub async fn start(
self: &Arc<Self>, self: &Arc<Self>,
mut shutdown: watch::Receiver<bool>, mut shutdown: watch::Receiver<bool>,
) -> anyhow::Result<()> { ) -> anyhow::Result<()> {
self.initialize_websocket_subscribe().await?;
loop { loop {
tokio::select! { tokio::select! {
_ = shutdown.changed() => { _ = shutdown.changed() => {
@@ -151,44 +84,50 @@ impl Bot {
} }
pub async fn tick(self: &Arc<Self>) -> anyhow::Result<bool> { pub async fn tick(self: &Arc<Self>) -> anyhow::Result<bool> {
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()? { // drop(ws);
if let tokio_tungstenite::tungstenite::Message::Text(text) = msg { // self.strategy
match serde_json::from_str::<crate::types::PumpDevEvent>(&text) { // .lock()
Ok(crate::types::PumpDevEvent::Create(token)) => { // .await
drop(ws); // .on_trade(self.clone(), trade)
// .await?;
self.strategy
.lock()
.await
.on_new_coin(self.clone(), token)
.await?;
}
Ok(crate::types::PumpDevEvent::Trade(trade)) => {
drop(ws);
self.strategy
.lock()
.await
.on_trade(self.clone(), trade)
.await?;
}
Ok(_event) => {
// println!("{:?}", event);
}
Err(err) => {
log::error!("{err}, MSG -> {text}");
}
}
}
Ok(false) Ok(false)
} else {
Ok(true)
} }
} }
impl Bot {
pub async fn subscribe(&self, mint: &str) -> anyhow::Result<()> {
Ok(())
}
pub async fn unsubscribe(&self, mint: &str) -> anyhow::Result<()> {
Ok(())
}
pub async fn refresh_account(self: &Arc<Self>) -> anyhow::Result<()> {
self.strategy
.lock()
.await
.execute_sell_all(self.clone())
.await?;
let accounts = self.account_manager.lock().await;
let account = accounts
.accounts
.get(&accounts.active)
.context("Failed to get account")?
.clone();
*self.current_account.lock().await = account;
Ok(())
}
} }
+2 -4
View File
@@ -1,10 +1,8 @@
use rust_decimal::Decimal; use rust_decimal::Decimal;
use crate::{account::Account, executor::Executor}; use crate::executor::Executor;
pub struct PumpDev { pub struct PumpDev {}
pub account: Account,
}
#[async_trait::async_trait] #[async_trait::async_trait]
impl Executor for PumpDev { impl Executor for PumpDev {