Lorenz
Architecture

Architecture Reference

A thorough, code-grounded description of the Lorenz system as it exists today. One chapter per crate, the on-chain program, end-to-end flows, safety invariants, and the roadmap seams.

A thorough, code-grounded description of the Lorenz system as it exists today. Every statement here is meant to be checkable against the source; where a piece is unfinished it is labelled roadmap / seam, never described as working.

Lorenz Protocol is an experimental, unaudited reference architecture for atomic, flash-loan-funded arbitrage on Solana. It does not trade live yet and makes no profitability claims. See the Disclaimer.

How this set relates to the other docs

The root Architecture overview, Invariants, and Security pages are the high-level documents. This architecture reference is the deep reference that expands them:

DocRelationship
Architecture overviewExecutive summary of the two-plane split. Expanded by chapters 01, 04, 05, 08.
InvariantsCanonical list of guarantees. Cross-referenced and explained in chapter 09.
SecurityThreat model + disclosure. Cross-referenced in chapters 06 and 09.

Reading guide

Start at 01 for the mental model, then read by interest:

#ChapterWhat it covers
01System OverviewWhat Lorenz is, the data/control plane model, design principles, status legend
02Crate TopologyWorkspace layout, dependency graph, why the on-chain program is excluded
03Core Domain Modellorenz-core: newtypes, typed config, errors, telemetry records
04Data Planelorenz-amm, lorenz-graph, lorenz-dex, lorenz-stream: detect → size pipeline
05Control Planelorenz-agent: risk manager, tuner, ledger, LLM boundary, orchestrator
06On-chain Programprograms/executor: instructions, accounts, the five on-chain invariants
07Backtesterlorenz-backtest: cost model, replay loop, the runnable binary
08End-to-End FlowsSequence diagrams for detection, backtest, and a (roadmap) live trade
09Safety & InvariantsWhere each guarantee is enforced and how it is verified
10Roadmap & SeamsEvery NotImplemented boundary and what a production build adds
11GlossaryTerms: notional, CPMM/CLMM, Geyser, flash loan, Jito tip, …

The system in one paragraph

A deterministic data plane ingests pool state, models the market as a token graph, detects profitable cycles (negative-cycle Bellman-Ford), and prices them with exact integer AMM math. An off-hot-path control plane consumes telemetry and may only tighten limits; an LLM, if present, can return only one action from a closed, clamped set. The final backstop is a custom on-chain program that refuses to settle any trade that loses money or exceeds its spend cap. Safety is a property of the runtime and the type system, not a promise in a README.

Status legend

Used consistently across all chapters:

  • Implemented + tested: real code with unit/property tests.
  • 🟡 Seam: a typed, documented integration point that compiles and returns an explicit NotImplemented, so the surrounding logic is reviewable.
  • 🔭 Roadmap: described and scoped, not present in code yet.

Conventions

  • File paths are relative to the repository root (lorenz/).
  • Symbols are written as module::Type and map to the crate of the same prefix (risk::RuleBasedRiskManager lives in crates/lorenz-agent/src/risk.rs).
  • "Base units" always means the integer smallest unit of a token (lamports for SOL). No floating-point value ever settles.

On this page