# cyfrin/2024-12-quantamm architecture

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

- Interactive diagram: https://gitdiagram.com/cyfrin/2024-12-quantamm
- Repository: https://github.com/cyfrin/2024-12-quantamm

## Overview

##### Main Components and Architecture

a) Core Protocol Layer
- QuantAMMWeightedPool (Central component)
- UpdateWeightRunner (Weight management system)
- Rules Engine (Strategy implementation)
- Oracle System

b) Integration Layer
- Balancer V3 Integration
- External Oracle Integration
- Pool Hooks System

c) Infrastructure Layer
- Storage Systems
- Security Controls
- Administrative Systems

##### Component Relationships

a) Primary Flow:
**Traders/LPs -> Balancer V3 Vault -> QuantAMMWeightedPool -> UpdateWeightRunner -> Rules Engine -> Oracles**

b) Secondary Flows:
**UpdateWeightRunner -> QuantAMMStorage**
**Rules -> QuantammBasedRuleHelpers**
**Pool Hooks -> QuantAMMWeightedPool**

##### Detailed Component Breakdown

a) QuantAMMWeightedPool:
- To: Balancer V3 Vault, UpdateWeightRunner
- Interfaces: IQuantAMMWeightedPool
- Weight management, trading functions

b) UpdateWeightRunner:
- To: Rules Engine, Oracles
- Weight calculation flow
- Update intervals

c) Rules Engine:
- Rule types (Momentum, Antimomentum, etc.)
- To: Base rule components
- Strategy calculation flow

d) Oracle System:
- ChainlinkOracle, MultiHopOracle
- To: External price feeds
- Data flow paths

##### Administrative Controls

Show:
- QuantAMM Admin controls
- Pool Owner permissions
- Emergency systems
- Timelock mechanisms

##### Implementation Notes

- Clear separation between Balancer V3 infrastructure and QuantAMM additions
- Strategy execution flow
- Oracle integration points
- Security boundaries between trusted and untrusted components

##### Technical Details

Specific technical implementations:
- Storage packing (9dp resolution)
- Oracle caching system
- Guard rail implementation
- Weight update mechanisms

##### Interaction Flows

Processes:
- LP deposit/withdrawal flow
- Trading flow
- Weight update flow
- Strategy execution flow

Remember to include version information and date, as this is a protocol under active development with multiple audit phases.

## Diagram (Mermaid)

```mermaid
flowchart TB
    subgraph Core["Core Components"]
        direction TB
        QPool[QuantAMMWeightedPool]:::core
        QFactory[QuantAMMWeightedPoolFactory]:::core
        UpdateRunner[UpdateWeightRunner]:::core
        QStorage[QuantAMMStorage]:::core
    end

    subgraph Rules["Rules Engine"]
        direction TB
        BaseRules[Base Rules Framework]:::rules
        SpecRules[Specialized Rules]:::rules
        GuardRails[Guard Rails System]:::rules
    end

    subgraph Oracle["Oracle System"]
        direction TB
        ChainOracle[ChainlinkOracle]:::oracle
        MultiOracle[MultiHopOracle]:::oracle
        LPOracle[LPOracles]:::oracle
    end

    subgraph Integration["Integration Layer"]
        direction TB
        BalancerV3[Balancer V3 Vault]:::integration
        PoolHooks[Pool Hooks System]:::integration
        ExtInterfaces[External Interfaces]:::integration
    end

    %% Core Relationships
    UpdateRunner --> QPool
    QPool --> QStorage
    QFactory --> QPool
    
    %% Oracle Data Flow
    ChainOracle --> UpdateRunner
    MultiOracle --> UpdateRunner
    LPOracle --> UpdateRunner
    
    %% Rules Processing
    UpdateRunner --> BaseRules
    BaseRules --> SpecRules
    SpecRules --> GuardRails
    GuardRails --> QPool
    
    %% Integration Connections
    QPool --> BalancerV3
    QPool --> PoolHooks
    QPool --> ExtInterfaces

    %% Styling
    classDef core fill:#3498db,stroke:#2980b9,color:white
    classDef rules fill:#f1c40f,stroke:#f39c12,color:black
    classDef oracle fill:#2ecc71,stroke:#27ae60,color:white
    classDef integration fill:#9b59b6,stroke:#8e44ad,color:white
    
    %% Click Events
    click QPool "https://github.com/Cyfrin/2024-12-quantamm/tree/main/pkg/pool-quantamm/contracts/"
    click BaseRules "https://github.com/Cyfrin/2024-12-quantamm/tree/main/pkg/pool-quantamm/contracts/rules/base/"
    click SpecRules "https://github.com/Cyfrin/2024-12-quantamm/tree/main/pkg/pool-quantamm/contracts/rules/"
    click PoolHooks "https://github.com/Cyfrin/2024-12-quantamm/tree/main/pkg/pool-hooks/contracts/hooks-quantamm/"
    click ExtInterfaces "https://github.com/Cyfrin/2024-12-quantamm/tree/main/pkg/interfaces/contracts/pool-quantamm/"

    %% Legend
    subgraph Legend
        direction TB
        CoreL[Core Components]:::core
        RulesL[Rules Engine]:::rules
        OracleL[Oracle System]:::oracle
        IntegrationL[Integration Layer]:::integration
    end
```
