# propeller-heads/tycho-simulation architecture

> Architecture diagram of the GitHub repository propeller-heads/tycho-simulation, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-05-21). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/propeller-heads/tycho-simulation
- Repository: https://github.com/propeller-heads/tycho-simulation

## Overview

##### Project type and purpose
- This is an open-source simulation tool (a Rust crate with Python bindings) designed to move slow on-chain computations off chain and simulate token-exchange protocols (Uniswap V2/V3, Balancer V2, Curve, etc.).
- Core logic lives in Rust (src/…), and there is a Python wheel wrapper (tycho_simulation_py/) plus CLI/example entry points (examples/).

##### File structure
- Top level:
- Cargo.toml / src/… → Rust library (“tycho-simulation”)
- examples/quickstart & price_printer → Rust binary examples & simple UIs
- tests/ → integration tests and protocol snapshots
- tycho_simulation_py/ → Python package + Rust/PyO3 shim + Dockerfile
- Key Rust modules:
- evm/ → general EVM simulation engine (decoder, engine_db backends, traces, tycho_models)
- evm/protocol/… → built-in protocol implementations (Uniswap V2–V4, CPMM, Ekubo) & VM-based adapters
- protocol/ → native ProtocolSim trait and state implementations
- utils.rs, serde_helpers.rs → shared utilities
- Build & CI:
- .github/workflows/*.yaml → CI pipelines (lint, tests, release)
- rust-toolchain.toml, clippy.toml, rustfmt.toml → formatting & lint config
- release.config.js → wheel packaging

##### README for insights
- Describes “move on-chain computations off-chain” via a ProtocolSim trait
- Two extension points: native protocols (in src/protocol) and VM protocols (in src/evm/protocol/vm + bytecode assets)
- Quickstart and full docs referenced

## Diagram (Mermaid)

```mermaid
graph TD
    %% API Layer
    subgraph "API Layer"
        direction TB
        CLI_Rust(("CLI Examples")):::api
        Python_Binding(("Python Binding")):::api
    end

    %% Orchestration Layer
    subgraph "Orchestration Layer: Rust Core"
        direction TB
        Core_Lib["tycho-simulation\n(Cargo.toml, src/lib.rs)"]:::core
        Core_Models["models.rs"]:::core
        Core_Utils["utils.rs"]:::core
        Core_Serde["serde_helpers.rs"]:::core
    end

    %% Engine Layer
    subgraph "Engine Layer: EVM Simulation Engine"
        direction TB
        EVM_Mod["mod.rs"]:::engine
        EVM_Decoder["decoder.rs"]:::engine
        EVM_Storage["account_storage.rs"]:::engine
        EVM_Sim["simulation.rs"]:::engine
        EVM_Stream["stream.rs"]:::engine
        EVM_Traces["traces.rs"]:::engine
        EVM_Models["tycho_models.rs"]:::engine

        subgraph "Engine DB Layer"
            direction TB
            DB_Mod["mod.rs"]:::engine
            DB_Interface["engine_db_interface.rs"]:::engine
            DB_SimDB["simulation_db.rs"]:::engine
            DB_TychoDB["tycho_db.rs"]:::engine
        end
    end

    %% Protocol Layer
    subgraph "Protocol Layer"
        direction TB
        subgraph "Native Protocols"
            direction TB
            Prot_Mod["src/protocol/mod.rs"]:::protocol
            Prot_Errors["errors.rs"]:::protocol
            Prot_Models["models.rs"]:::protocol
            Prot_State["state.rs"]:::protocol
        end
        subgraph "EVM Protocols"
            direction TB
            EVM_Prot_Mod["src/evm/protocol/mod.rs"]:::protocol
            CPMM["CPMM Protocol"]:::protocol
            Ekubo["Ekubo Protocol"]:::protocol
            PancakeV2["PancakeSwap V2"]:::protocol
            UniV2["Uniswap V2"]:::protocol
            UniV3["Uniswap V3"]:::protocol
            UniV4["Uniswap V4"]:::protocol
            VM_Prot["VM-based Protocols"]:::protocol
        end
    end

    %% Assets & Tests
    subgraph "Test Harness & Assets"
        direction TB
        Tests["tests/"]:::assets
        AssetsDir["assets/"]:::assets
        PyTests["tycho_simulation_py/python/test/"]:::assets
    end

    %% CI / Release Pipeline
    subgraph "CI / Release Pipeline"
        direction TB
        Workflows[".github/workflows/"]:::ci
        Configs["rust-toolchain.toml\nclippy.toml\nrustfmt.toml"]:::ci
        ReleaseJS["release.config.js"]:::ci
    end

    %% Connections
    CLI_Rust -->|"calls"| Core_Lib
    Python_Binding -->|"FFI calls"| Core_Lib
    Core_Lib -->|"invokes"| EVM_Mod
    EVM_Mod --> EVM_Decoder
    EVM_Mod --> EVM_Sim
    EVM_Sim --> DB_SimDB
    EVM_Sim --> DB_TychoDB
    EVM_Sim --> Prot_Mod
    Prot_Mod --> CPMM
    Prot_Mod --> Ekubo
    Prot_Mod --> PancakeV2
    Prot_Mod --> UniV2
    Prot_Mod --> UniV3
    Prot_Mod --> UniV4
    Prot_Mod --> VM_Prot
    Tests --> CLI_Rust
    Tests --> Python_Binding
    Tests --> AssetsDir
    Core_Lib --> Tests
    Core_Lib --> AssetsDir
    CI --> Core_Lib

    %% Click Events
    click Core_Lib "https://github.com/propeller-heads/tycho-simulation/blob/main/Cargo.toml"
    click Core_Lib "https://github.com/propeller-heads/tycho-simulation/blob/main/src/lib.rs"
    click Core_Models "https://github.com/propeller-heads/tycho-simulation/blob/main/src/models.rs"
    click Core_Utils "https://github.com/propeller-heads/tycho-simulation/blob/main/src/utils.rs"
    click Core_Serde "https://github.com/propeller-heads/tycho-simulation/blob/main/src/serde_helpers.rs"

    click EVM_Mod "https://github.com/propeller-heads/tycho-simulation/blob/main/src/evm/mod.rs"
    click EVM_Decoder "https://github.com/propeller-heads/tycho-simulation/blob/main/src/evm/decoder.rs"
    click EVM_Storage "https://github.com/propeller-heads/tycho-simulation/blob/main/src/evm/account_storage.rs"
    click EVM_Sim "https://github.com/propeller-heads/tycho-simulation/blob/main/src/evm/simulation.rs"
    click EVM_Stream "https://github.com/propeller-heads/tycho-simulation/blob/main/src/evm/stream.rs"
    click EVM_Traces "https://github.com/propeller-heads/tycho-simulation/blob/main/src/evm/traces.rs"
    click EVM_Models "https://github.com/propeller-heads/tycho-simulation/blob/main/src/evm/tycho_models.rs"

    click DB_Mod "https://github.com/propeller-heads/tycho-simulation/blob/main/src/evm/engine_db/mod.rs"
    click DB_Interface "https://github.com/propeller-heads/tycho-simulation/blob/main/src/evm/engine_db/engine_db_interface.rs"
    click DB_SimDB "https://github.com/propeller-heads/tycho-simulation/blob/main/src/evm/engine_db/simulation_db.rs"
    click DB_TychoDB "https://github.com/propeller-heads/tycho-simulation/blob/main/src/evm/engine_db/tycho_db.rs"

    click Prot_Mod "https://github.com/propeller-heads/tycho-simulation/blob/main/src/protocol/mod.rs"
    click Prot_Errors "https://github.com/propeller-heads/tycho-simulation/blob/main/src/protocol/errors.rs"
    click Prot_Models "https://github.com/propeller-heads/tycho-simulation/blob/main/src/protocol/models.rs"
    click Prot_State "https://github.com/propeller-heads/tycho-simulation/blob/main/src/protocol/state.rs"

    click EVM_Prot_Mod "https://github.com/propeller-heads/tycho-simulation/blob/main/src/evm/protocol/mod.rs"
    click CPMM "https://github.com/propeller-heads/tycho-simulation/blob/main/src/evm/protocol/cpmm/protocol.rs"
    click Ekubo "https://github.com/propeller-heads/tycho-simulation/tree/main/src/evm/protocol/ekubo/pool/"
    click PancakeV2 "https://github.com/propeller-heads/tycho-simulation/blob/main/src/evm/protocol/pancakeswap_v2/mod.rs"
    click UniV2 "https://github.com/propeller-heads/tycho-simulation/blob/main/src/evm/protocol/uniswap_v2/mod.rs"
    click UniV3 "https://github.com/propeller-heads/tycho-simulation/blob/main/src/evm/protocol/uniswap_v3/mod.rs"
    click UniV4 "https://github.com/propeller-heads/tycho-simulation/blob/main/src/evm/protocol/uniswap_v4/mod.rs"
    click VM_Prot "https://github.com/propeller-heads/tycho-simulation/blob/main/src/evm/protocol/vm/mod.rs"

    click CLI_Rust "https://github.com/propeller-heads/tycho-simulation/blob/main/examples/quickstart/main.rs"
    click CLI_Rust "https://github.com/propeller-heads/tycho-simulation/blob/main/examples/price_printer/main.rs"
    click Python_Binding "https://github.com/propeller-heads/tycho-simulation/blob/main/tycho_simulation_py/src/lib.rs"

    click Tests "https://github.com/propeller-heads/tycho-simulation/tree/main/tests/"
    click AssetsDir "https://github.com/propeller-heads/tycho-simulation/tree/main/assets/"
    click PyTests "https://github.com/propeller-heads/tycho-simulation/tree/main/tycho_simulation_py/python/test/"

    click Workflows "https://github.com/propeller-heads/tycho-simulation/blob/main/.github/workflows/ci.yaml"
    click Configs "https://github.com/propeller-heads/tycho-simulation/blob/main/rust-toolchain.toml"
    click Configs "https://github.com/propeller-heads/tycho-simulation/blob/main/clippy.toml"
    click Configs "https://github.com/propeller-heads/tycho-simulation/blob/main/rustfmt.toml"
    click ReleaseJS "https://github.com/propeller-heads/tycho-simulation/blob/main/release.config.js"

    %% Styles
    classDef api fill:#F4A261,stroke:#E76F51,color:#000000
    classDef core fill:#2A9D8F,stroke:#264653,color:#ffffff
    classDef engine fill:#264653,stroke:#2A9D8F,color:#ffffff
    classDef protocol fill:#E9C46A,stroke:#F4A261,color:#000000
    classDef assets fill:#A8A8A8,stroke:#333333,color:#000000
    classDef ci fill:#D3D3D3,stroke:#666666,color:#000000
```
