{"id":49600860,"url":"https://github.com/milerius/mantis","last_synced_at":"2026-05-04T09:10:12.166Z","repository":{"id":347026484,"uuid":"1191471111","full_name":"Milerius/Mantis","owner":"Milerius","description":"A modular, no_std-first Rust foundation for low-latency trading systems — fixed-point arithmetic, typed event transport, lock-free queues, verified with Miri \u0026 Kani","archived":false,"fork":false,"pushed_at":"2026-04-11T08:30:07.000Z","size":1424548,"stargazers_count":8,"open_issues_count":1,"forks_count":2,"subscribers_count":0,"default_branch":"main","last_synced_at":"2026-04-11T09:23:59.806Z","etag":null,"topics":["financial","hft","lock-free","low-latency","no-std","ring-buffer","rust","spsc"],"latest_commit_sha":null,"homepage":null,"language":"Rust","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Milerius.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":"SECURITY.md","support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2026-03-25T09:24:21.000Z","updated_at":"2026-04-11T09:10:36.000Z","dependencies_parsed_at":null,"dependency_job_id":null,"html_url":"https://github.com/Milerius/Mantis","commit_stats":null,"previous_names":["milerius/mantis"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/Milerius/Mantis","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Milerius%2FMantis","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Milerius%2FMantis/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Milerius%2FMantis/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Milerius%2FMantis/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Milerius","download_url":"https://codeload.github.com/Milerius/Mantis/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Milerius%2FMantis/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":32600982,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-05-03T22:12:39.696Z","status":"online","status_checked_at":"2026-05-04T02:00:06.625Z","response_time":58,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["financial","hft","lock-free","low-latency","no-std","ring-buffer","rust","spsc"],"created_at":"2026-05-04T09:10:11.313Z","updated_at":"2026-05-04T09:10:12.151Z","avatar_url":"https://github.com/Milerius.png","language":"Rust","funding_links":[],"categories":[],"sub_categories":[],"readme":"\u003cp align=\"center\"\u003e\n  \u003cimg src=\"assets/banner.png\" alt=\"Mantis — Financial Low-Latency HFT Library in Rust\" width=\"600\"\u003e\n\u003c/p\u003e\n\n\u003ch1 align=\"center\"\u003e\n  \u003cimg src=\"assets/logo.png\" alt=\"Mantis logo\" width=\"40\" valign=\"middle\"\u003e\n  Mantis\n\u003c/h1\u003e\n\n\u003cp align=\"center\"\u003e\n  A modular, \u003ccode\u003eno_std\u003c/code\u003e-first Rust foundation for low-latency financial systems\u003cbr\u003e\n  across centralized and decentralized markets.\n\u003c/p\u003e\n\n\u003cp align=\"center\"\u003e\n  \u003ca href=\"https://github.com/Milerius/Mantis/actions/workflows/ci.yml\"\u003e\u003cimg src=\"https://img.shields.io/github/actions/workflow/status/Milerius/Mantis/ci.yml?style=flat-square\u0026logo=github\u0026label=CI\" alt=\"CI\"\u003e\u003c/a\u003e\n  \u003ca href=\"https://codecov.io/gh/Milerius/Mantis\"\u003e\u003cimg src=\"https://img.shields.io/codecov/c/github/Milerius/Mantis?style=flat-square\u0026logo=codecov\u0026label=coverage\" alt=\"Coverage\"\u003e\u003c/a\u003e\n  \u003ca href=\"https://github.com/Milerius/Mantis/actions/workflows/nightly.yml\"\u003e\u003cimg src=\"https://img.shields.io/github/actions/workflow/status/Milerius/Mantis/nightly.yml?style=flat-square\u0026logo=github\u0026label=nightly\" alt=\"Nightly\"\u003e\u003c/a\u003e\n  \u003cimg src=\"https://img.shields.io/badge/rust-nightly-93450a?style=flat-square\u0026logo=rust\" alt=\"Rust Nightly\"\u003e\n  \u003cimg src=\"https://img.shields.io/badge/no__std-first-orange?style=flat-square\" alt=\"no_std\"\u003e\n  \u003ca href=\"LICENSE\"\u003e\u003cimg src=\"https://img.shields.io/badge/license-Apache--2.0-blue?style=flat-square\" alt=\"License\"\u003e\u003c/a\u003e\n\u003c/p\u003e\n\n\u003cp align=\"center\"\u003e\n  \u003ca href=\"https://codecov.io/gh/Milerius/Mantis\"\u003e\u003cimg src=\"https://img.shields.io/codecov/c/github/Milerius/Mantis?style=for-the-badge\u0026label=coverage\" alt=\"Coverage\"\u003e\u003c/a\u003e\n  \u003ca href=\"https://github.com/Milerius/Mantis/actions/workflows/nightly.yml\"\u003e\u003cimg src=\"https://img.shields.io/github/actions/workflow/status/Milerius/Mantis/nightly.yml?style=for-the-badge\u0026label=miri%20%2B%20kani\" alt=\"Miri + Kani\"\u003e\u003c/a\u003e\n\u003c/p\u003e\n\n\u003cp align=\"center\"\u003e\n  \u003cb\u003e42ns market state engine · 130ns cross-core SPSC · Zero allocation on hot path · Miri + Kani verified\u003c/b\u003e\n\u003c/p\u003e\n\n---\n\n## Why Mantis?\n\n| | Mantis | Typical HFT Software | Top-Tier (FPGA) |\n|---|---|---|---|\n| **Event processing** | **42ns** p50 | 1-10µs | \u003c100ns |\n| **SPSC ring (cross-core)** | **130ns** (472 cycles) | 200-500ns | N/A |\n| **Memory allocation** | **Zero** on hot path | Minimal | Fixed in fabric |\n| **Verification** | Miri + Kani + Fuzz + Bolero | Unit tests | Hardware proofs |\n| **Replay** | **Deterministic** | Best-effort | Hard |\n| **`no_std`** | All core crates | Rarely | N/A |\n\nInspired by Optiver/LMAX-class software systems. SPSC latency measured on isolated cores (AMD Ryzen 7 PRO 8700GE, `isolcpus`, `rdtsc`).\nSee [`benchmarks/RESULTS.md`](benchmarks/RESULTS.md) for full methodology and comparison with C++ rigtorp.\n\n---\n\n## Architecture\n\n```\n                    ┌─────────────────────────────┐\n                    │      Trading Application     │\n                    └──────────────┬───────────────┘\n                                   │\n              ┌────────────────────┼────────────────────┐\n              │                    │                     │\n     ┌────────▼────────┐ ┌────────▼────────┐  ┌────────▼────────┐\n     │ mantis-strategy  │ │  mantis-queue   │  │ mantis-market-  │\n     │                  │ │                 │  │ state           │\n     │  Strategy trait  │ │  SPSC ring buf  │  │  ArrayBook      │\n     │  Position, PnL   │ │  lock-free I/O  │  │  Engine, BBO    │\n     │  QueueEstimator  │ │  130ns x-core   │  │  42ns/event     │\n     │  OrderTracker    │ └────────┬────────┘  └────────┬────────┘\n     └────────┬─────────┘          │                    │\n              │           ┌────────▼────────┐  ┌────────▼────────┐\n              │           │  mantis-events  │  │  mantis-types   │\n              ├──────────►│  HotEvent 64B   │  │  Ticks · Lots   │\n              │           │  1 cache line   │  │  SignedLots      │\n              │           └────────┬────────┘  │  InstrumentId    │\n              │                    │           └────────┬────────┘\n              │           ┌────────▼────────┐  ┌────────▼────────┐\n              │           │  mantis-fixed   │  │ mantis-platform │\n              └──────────►│  FixedI64\u003cD\u003e    │  │  CachePadded    │\n                          │  1.10ns mul     │  │  CT types, SIMD │\n                          └─────────────────┘  │  cycle counters │\n                                               └─────────────────┘\n```\n\n\u003cdetails\u003e\n\u003csummary\u003e\u003cb\u003eData Flow — Hot Path\u003c/b\u003e\u003c/summary\u003e\n\n```\nFeed Handler → [SPSC Ring] → Market State Engine → Strategy.on_event() → [SPSC Ring] → Execution\n                                    ↓\n                             Books · BBO · Micro Price\n                             Queue Position · Take Rate\n                             Fill Probability · Exposure\n```\n\nEach strategy is a self-contained state machine. Same code path live and replay.\nFeed the same event tape → get identical order intents.\n\n\u003c/details\u003e\n\n---\n\n## Highlights\n\n⚡ **42ns market state engine** — single-core event processing, no locks, no allocation on hot path\n\n🏎️ **130ns cross-core SPSC** — measured on isolated cores with `rdtsc`, beating C++ rigtorp on same hardware\n\n🔒 **Zero-alloc hot path** — fixed-size arrays, `repr(C)` types, `no_std` everywhere\n\n🧪 **Formally verified** — Miri (zero UB), Kani (bounded model checking), Bolero (property tests), fuzz targets\n\n🔄 **Deterministic replay** — event-driven strategy trait: same tape = same intents\n\n📊 **Live POC** — Nim prototype with FTXUI terminal dashboard capturing Polymarket + Binance in real-time\n\n🏗️ **14 modular crates** — compose what you need, leave the rest\n\n📈 **L2 queue position model** — probabilistic fill estimation using `PowerProbQueueFunc`\n\n---\n\n## Crates\n\n| Crate | Purpose | `no_std` | Tests |\n|---|---|---|---:|\n| [`mantis-strategy`](crates/strategy/) | Strategy trait, Position, OrderTracker, QueueEstimator, RiskLimits | yes | 38 |\n| [`mantis-market-state`](crates/market-state/) | Market-state engine: `ArrayBook`, `MarketStateEngine`, TopOfBook | yes | 17 |\n| [`mantis-events`](crates/events/) | Hot event language: 64B `HotEvent` envelope for SPSC transport | yes | 62 |\n| [`mantis-queue`](crates/queue/) | Lock-free SPSC ring buffer with modular strategies | yes | 31 |\n| [`mantis-types`](crates/types/) | Domain types: `Ticks`, `Lots`, `SignedLots`, `Side`, `InstrumentId` | yes | 98 |\n| [`mantis-fixed`](crates/fixed/) | `FixedI64\u003cD\u003e` compile-time fixed-point decimal engine | yes | 110 |\n| [`mantis-platform`](crates/platform/) | Platform abstractions: cache padding, CT types, cycle counters, SIMD | yes | 164 |\n| [`mantis-seqlock`](crates/seqlock/) | Lock-free sequence lock primitive | yes | 1 |\n| [`mantis-core`](crates/core/) | Strategy traits (`IndexStrategy`, `PushPolicy`, `Instrumentation`) | yes | 1 |\n| [`mantis-registry`](crates/registry/) | Instrument registry with venue bindings | yes | — |\n| [`mantis-transport`](crates/transport/) | WebSocket feed handlers (Polymarket, Binance) | no | — |\n| [`mantis-bench`](crates/bench/) | Criterion benchmarks + platform cycle counters + JSON reports | no | 11 |\n| [`mantis-layout`](crates/layout/) | Struct layout and cache-line inspector | no | 6 |\n| [`mantis-verify`](crates/verify/) | Kani proofs, Bolero property tests, differential testing | no | 13 |\n\n---\n\n## Benchmarks\n\n### SPSC Ring — Two-Thread Cross-Core Latency\n\nMeasured on AMD Ryzen 7 PRO 8700GE with `isolcpus`, `rdtsc`, `chrt -f 99`.\n48-byte messages, capacity 1024, 1M operations per run.\n\n| Queue | Language | Mean (TSC cycles) | Stability |\n|-------|----------|---:|---:|\n| **Mantis `SpscRingFast`** | Rust | **472** | +/-8 |\n| Mantis `SpscRing` | Rust | 554 | +/-14 |\n| Mantis `SpscRingCopy` | Rust | 552 | +/-11 |\n| rigtorp `SPSCQueue` | C++ | 510 best, 1315 median | +/-400 |\n| rtrb | Rust | 1090 best, 2345 median | +/-750 |\n\nAt 3.65 GHz TSC, 472 cycles = **129 ns** per cross-core message handoff.\n\nSee [`benchmarks/RESULTS.md`](benchmarks/RESULTS.md) for full methodology, hardware configuration, and reproduction steps.\n\n### Fixed-Point Math\n\n| Operation | Mantis | `fixed` crate | `rust_decimal` |\n|---|---:|---:|---:|\n| mul | **1.10 ns** | 1.20 ns | -- |\n| add | **0.28 ns** | -- | 1.12 ns (4x slower) |\n\nRun benchmarks:\n```bash\n# Fixed-point\ncargo +nightly bench --bench fixed\n\n# SPSC (requires isolated cores on Linux)\ncd benchmarks/rust\nRUSTFLAGS='-C target-cpu=native' cargo +nightly build --release\nchrt -f 99 taskset -c 2,3 ./target/release/mantis-spsc-bench \\\n    --producer-core 2 --consumer-core 3 --messages 1000000 --runs 10\n```\n\n---\n\n## Quick Start\n\n```bash\n# Build everything\ncargo +nightly build --features alloc,std\n\n# Run tests\ncargo +nightly test --features alloc,std\n\n# Check coverage\ncargo +nightly llvm-cov --all-features\n\n# Inspect struct layouts\ncargo run -p mantis-layout\n\n# Run fixed-point benchmarks\ncargo +nightly bench --bench fixed\n```\n\n---\n\n\u003cdetails\u003e\n\u003csummary\u003e\u003ch2\u003e🧪 Verification Strategy\u003c/h2\u003e\u003c/summary\u003e\n\n| Tool | What It Catches | Scope |\n|---|---|---|\n| **Miri** | Undefined behavior, data races, use-after-free | All `no_std` crates on every PR |\n| **Kani** | Arithmetic overflow, out-of-bounds, invariant violations | 4 bounded model checking proofs |\n| **Bolero** | Edge cases via property-based + fuzz testing | 10+ property tests |\n| **Fuzz** | Crash bugs in parsing + serialization | 2 fuzz targets (fixed-point) |\n| **Differential** | Portable vs platform-specific divergence | 3 cross-variant comparisons |\n| **Careful** | Additional UB detection beyond Miri | Full workspace |\n\nEvery PR runs: fmt → clippy → test → no_std test → Miri → coverage → deny → doc build.\n\nNightly runs add: mutant testing, extended Miri, full coverage, ASM inspection, Kani proofs, fuzz.\n\n\u003c/details\u003e\n\n\u003cdetails\u003e\n\u003csummary\u003e\u003ch2\u003e🎯 Strategy Design\u003c/h2\u003e\u003c/summary\u003e\n\n```rust\nuse mantis_strategy::{Strategy, OrderIntent, MAX_INTENTS_PER_TICK};\nuse mantis_events::HotEvent;\n\nstruct MyStrategy { /* own state, own engine, own position */ }\n\nimpl Strategy for MyStrategy {\n    const STRATEGY_ID: u8 = 0;\n    const NAME: \u0026'static str = \"my-strategy\";\n\n    fn on_event(\n        \u0026mut self,\n        event: \u0026HotEvent,\n        intents: \u0026mut [OrderIntent; MAX_INTENTS_PER_TICK],\n    ) -\u003e usize {\n        // Process event, update internal state, emit order intents\n        0\n    }\n}\n```\n\n**Key properties:**\n- No generics on the trait — implementation details stay inside the strategy\n- Associated consts (`STRATEGY_ID`, `NAME`) — zero runtime overhead\n- Enum dispatch in bot binary — no vtable, no heap, fully inlined\n- Each strategy owns its own `MarketStateEngine` — no shared mutable state\n- Replay: feed the same event tape → get identical intents\n\n\u003c/details\u003e\n\n\u003cdetails\u003e\n\u003csummary\u003e\u003ch2\u003e📊 Live POC — Polymarket + Binance\u003c/h2\u003e\u003c/summary\u003e\n\nA working Nim prototype (`polymarket-bot-poc/`) captures Polymarket prediction markets + Binance reference feeds with an FTXUI terminal dashboard.\n\n**Features:**\n- Multi-market: BTC, SOL, ETH up-or-down 5m markets\n- 6-thread architecture: ingest(2) + engine + telemetry + dashboard + main\n- FTXUI 3-column trading terminal with Canvas charts\n- Depth ladders (UP/DOWN PM books + Binance depth20 L2)\n- Probability history, latency histogram, event rate sparkline\n- Queue gauges, feed status, trade tape, market tab switching\n- Binary mmap tape output with zstd compression\n- Engine latency: p50=42ns, p99=1-5µs\n- CPU: ~9% with yield-on-idle\n\nSee [`polymarket-bot-poc/README.md`](polymarket-bot-poc/README.md) for build instructions.\n\n\u003c/details\u003e\n\n\u003cdetails\u003e\n\u003csummary\u003e\u003ch2\u003e🏛️ Design Principles\u003c/h2\u003e\u003c/summary\u003e\n\n1. **Correctness first** — Kani proofs, Miri, differential tests\n2. **Safety** — all unsafe isolated in `raw` modules with `// SAFETY:` comments\n3. **Performance** — benchmarked, layout-inspected, ASM-verified\n4. **`no_std` first** — no heap in hot paths, `alloc` optional\n5. **Replay-friendly** — every component is a deterministic state machine\n6. **Venue-agnostic** — no prediction market concepts in core SDK\n\nSee [CLAUDE.md](CLAUDE.md) for the full development guide.\n\n\u003c/details\u003e\n\n\u003cdetails\u003e\n\u003csummary\u003e\u003ch2\u003e📋 Project Status\u003c/h2\u003e\u003c/summary\u003e\n\nSee [docs/PROGRESS.md](docs/PROGRESS.md) for detailed tracking.\n\n**Phase 1 — Completed:**\n- SPSC ring buffer with strategy pattern\n- Benchmark harness (RDTSC, kperf, criterion)\n- Platform abstractions (CT types, SIMD, cache padding)\n- Fixed-point decimal engine\n- 64B HotEvent model (8 variants)\n- Sequence lock\n- Market state engine (ArrayBook, BBO tracking)\n- Strategy runtime (trait, position, queue estimator, risk)\n\n**In Progress (by collaborators):**\n- Instrument registry with venue bindings\n- WebSocket transport (Polymarket, Binance)\n\n**Next:**\n- Execution engine (order management, signing, fill routing)\n- Risk management (per-strategy + global wallet)\n- Capture/replay framework\n- `mantis-prediction` crate (binary outcome positions)\n\n\u003c/details\u003e\n\n---\n\n## License\n\nApache-2.0\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmilerius%2Fmantis","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmilerius%2Fmantis","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmilerius%2Fmantis/lists"}