1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
//! # hft-core
//!
//! **LLM-driven high-frequency trading platform on Solana**, built on
//! [Rig (ARC)](https://rig.rs) - the Rust Inference Gateway.
//!
//! Combines agentic LLM pipelines with on-chain `DeFi` execution on Solana,
//! enabling statefully supervised, multi-step agent workflows with full PEV
//! loop governance.
//!
//! > **mAI (π§ )** Β· Technology Lead: Murtaza Ali Imtiaz (July 2019 β present)
//!
//! ## Architecture
//!
//! ```text
//! ββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
//! β hft-core β
//! ββββββββββββ¬βββββββββββ¬ββββββββββββ¬ββββββββββ¬βββββββββββ€
//! β pev β sor β onchain β avm β config β
//! β Plan β β Smart β Jupiter β AVM β Env β
//! β Executeββ Order β swap + β bench- β loader β
//! β Verify β Routing β Signer β mark β β
//! ββββββββββββ΄βββββββββββ΄ββββββββββββ΄ββββββββββ΄βββββββββββ
//! ```
//!
//! ## Full pipeline
//!
//! 1. **PEV loop** ([`pev`]) - Haiku decomposes the trade into four [`pev::types::TradeTask`]
//! objects; Sonnet executes each one using tool calls; Haiku verifies the output (pass β₯ 0.80).
//! Up to two retries on failure.
//! 2. **SOR** ([`sor`]) - Raydium, Orca, and Serum are queried concurrently; the lowest
//! cost-adjusted venue wins.
//! 3. **On-chain** ([`onchain`]) - Jupiter swap is simulated (dry-run by default) inside an
//! isolated [`onchain::signer::LocalSolanaSigner`] context.
//! 4. **AVM audit** ([`avm`]) - Reactor GUI audit log records state-before, execution details, and
//! state-after for every swap.
//!
//! ## Quick start
//!
//! ```text
//! cp .env.example .env # set ANTHROPIC_API_KEY (optional - stub mode works without it)
//! cargo run --release -- --mode full --pair SOL/USDC --amount 1.0
//! ```
//!
//! ## Offline / stub mode
//!
//! All subsystems work without an `ANTHROPIC_API_KEY`. When a key is absent
//! (or `--skip-llm` is passed), every PEV phase substitutes a deterministic
//! offline stub:
//!
//! ```text
//! SKIP_LLM=1 cargo run --release -- --mode full
//! ```
//!
//! ## Feature flags
//!
//! This crate has no optional feature flags. All subsystems are always compiled.
//!
//! ## Crate status
//!
//! The venue adapters (`raydium.rs`, `orca.rs`, `serum.rs`) and the balance
//! query helpers (`balance.rs`, `types.rs` in `onchain`) are documented stubs
//! awaiting real SDK integration. The PEV loop, SOR router, `SignerContext`,
//! Jupiter dry-run simulation, and AVM benchmark are fully implemented.