# tokemak/v2-core-pub architecture

> Architecture diagram of the GitHub repository tokemak/v2-core-pub, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2024-12-28). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/tokemak/v2-core-pub
- Repository: https://github.com/tokemak/v2-core-pub

## Overview

##### Main System Components

a) Core Protocol Components:
- Vault System (/src/vault)
- Strategy Layer (/src/strategy)
- Liquidation System (/src/liquidation)
- Oracle System (/src/oracles)
- Stats System (/src/stats)

b) Integration Layer:
- Destinations & Adapters (/src/destinations)
- Swapper System (/src/swapper)
- External Protocols Integration (/src/external)

c) Security & Access Control:
- Access Control System (/src/access)
- Security Features (/src/security)

##### Component Relationships

- Blue: Data flow
- Green: Token flow
- Red: Control flow

##### Detailed Component Breakdown

For each major component, create a sub-section showing:

a) Vault System:
- Core Vault contracts
- Fee management system
- Integration with external protocols

b) Strategy Layer:
- Strategy hooks
- Strategy libraries
- Execution flow

c) Oracle System:
- Price feed providers
- Oracle aggregation logic
- External oracle integrations (Chainlink, etc.)

##### Cross-Chain Architecture

A section showing:
- Message Proxy system (/src/messageProxy)
- Receiving Router (/src/receivingRouter)
- CCIP integration (/src/external/chainlink/ccip)

##### Integration Points

Connections to external protocols:
- Curve
- Balancer
- Uniswap
- Various LST protocols (Lido, RocketPool, etc.)

##### Technical Details

Annotations for:
- Key interfaces (/src/interfaces)
- Security boundaries
- Access control points
- Cross-chain communication paths

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% Styles and classes
    classDef core fill:#e1f5fe,stroke:#01579b
    classDef integration fill:#f3e5f5,stroke:#4a148c
    classDef security fill:#ffebee,stroke:#b71c1c
    classDef external fill:#f1f8e9,stroke:#33691e
    classDef crosschain fill:#fff3e0,stroke:#e65100

    %% Legend
    subgraph Legend
        L1[Core Components]:::core
        L2[Integration Layer]:::integration
        L3[Security Layer]:::security
        L4[External Protocols]:::external
        L5[Cross-Chain]:::crosschain
    end

    %% Core Protocol Components
    subgraph CoreProtocol
        Vault[Vault System]:::core
        Strategy[Strategy Layer]:::core
        Liquidation[Liquidation System]:::core
        Oracle[Oracle System]:::core
        Stats[Stats System]:::core

        %% Vault Components
        subgraph VaultSystem
            VaultCore[Core Vault]:::core
            VaultFees[Fee Management]:::core
            VaultLibs[Vault Libraries]:::core
        end

        %% Strategy Components
        subgraph StrategySystem
            StrategyHooks[Strategy Hooks]:::core
            StrategyLibs[Strategy Libraries]:::core
        end

        %% Oracle Components
        subgraph OracleSystem
            OracleProviders[Price Feed Providers]:::core
            OracleAggregator[Oracle Aggregation]:::core
        end

        %% Stats Components
        subgraph StatsSystem
            StatsCalc[Stats Calculators]:::core
            Rewarder[Rewarder System]:::core
        end
    end

    %% Integration Layer
    subgraph IntegrationLayer
        Destinations[Destinations & Adapters]:::integration
        Swapper[Swapper System]:::integration
        ExternalInt[External Protocol Integration]:::integration
    end

    %% Security Layer
    subgraph SecurityLayer
        Access[Access Control System]:::security
        Security[Security Features]:::security
    end

    %% Cross-Chain Components
    subgraph CrossChain
        MessageProxy[Message Proxy]:::crosschain
        ReceivingRouter[Receiving Router]:::crosschain
        CCIP[CCIP Integration]:::crosschain
    end

    %% External Protocols
    subgraph ExternalProtocols
        Curve[Curve]:::external
        Balancer[Balancer]:::external
        Uniswap[Uniswap]:::external
        LST[LST Protocols]:::external
    end

    %% Relationships
    Vault --> VaultSystem
    Strategy --> StrategySystem
    Oracle --> OracleSystem
    Stats --> StatsSystem

    VaultCore --> Access
    StrategyHooks --> VaultCore
    OracleProviders --> ExternalInt
    Destinations --> ExternalProtocols
    Swapper --> ExternalProtocols
    MessageProxy --> CCIP
    ReceivingRouter --> MessageProxy

    %% Click events
    click Vault "https://github.com/Tokemak/v2-core-pub/tree/main//src/vault"
    click Strategy "https://github.com/Tokemak/v2-core-pub/tree/main//src/strategy"
    click Liquidation "https://github.com/Tokemak/v2-core-pub/tree/main//src/liquidation"
    click Oracle "https://github.com/Tokemak/v2-core-pub/tree/main//src/oracles"
    click Stats "https://github.com/Tokemak/v2-core-pub/tree/main//src/stats"
    click Destinations "https://github.com/Tokemak/v2-core-pub/tree/main//src/destinations/adapters"
    click Swapper "https://github.com/Tokemak/v2-core-pub/tree/main//src/swapper"
    click ExternalInt "https://github.com/Tokemak/v2-core-pub/tree/main//src/external"
    click Access "https://github.com/Tokemak/v2-core-pub/tree/main//src/access"
    click Security "https://github.com/Tokemak/v2-core-pub/tree/main//src/security"
    click MessageProxy "https://github.com/Tokemak/v2-core-pub/tree/main//src/messageProxy"
    click ReceivingRouter "https://github.com/Tokemak/v2-core-pub/tree/main//src/receivingRouter"
    click CCIP "https://github.com/Tokemak/v2-core-pub/tree/main//src/external/chainlink/ccip"
    click Rewarder "https://github.com/Tokemak/v2-core-pub/tree/main//src/rewarders"
    click StatsCalc "https://github.com/Tokemak/v2-core-pub/tree/main//src/stats/calculators"
    click StrategyHooks "https://github.com/Tokemak/v2-core-pub/tree/main//src/strategy/hooks"
    click StrategyLibs "https://github.com/Tokemak/v2-core-pub/tree/main//src/strategy/libs"
    click OracleProviders "https://github.com/Tokemak/v2-core-pub/tree/main//src/oracles/providers"
    click VaultFees "https://github.com/Tokemak/v2-core-pub/tree/main//src/vault/fees"
    click VaultLibs "https://github.com/Tokemak/v2-core-pub/tree/main//src/vault/libs"
```
