# yearn/yearn-vaults-v3 architecture

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

- Interactive diagram: https://gitdiagram.com/yearn/yearn-vaults-v3
- Repository: https://github.com/yearn/yearn-vaults-v3

## Overview

##### Main Components

a) Core Smart Contracts Layer:
- VaultFactory Contract
- VaultV3 Contract (ERC4626 compliant)
- Tokenized Strategy Contract (external dependency)

b) Peripheral Components:
- Accountant Contracts
- Limit Module
- Fee Management System

c) Testing Infrastructure:
- Unit Tests
- E2E Tests
- Mock Contracts

##### Key Relationships to Highlight

a) Factory → Vault Relationship:
- VaultFactory as the deployment mechanism for VaultV3 instances
- Protocol fee configuration flow

b) Vault → Strategy Interaction:
- Deposit/Withdrawal flows
- Profit reporting mechanism
- Debt management
- Emergency shutdown paths

c) Access Control Structure:
- Role-based access system
- Permission hierarchy

**[Core Infrastructure]**
**┌─────────────────────┐**
- VaultFactory     │──────┐
- ┘      │
- ↓
**┌─────────────────────┐    ┌─────────────────┐**
- Tokenized Strategy  │←───│    VaultV3      │
- ┘    └─────────────────┘

##### Important Architectural Elements

a) Protocol Features:
- ERC4626 compliance
- Multi-strategy support
- Profit unlocking mechanism
- Debt management system
- Emergency shutdown capability

b) Security Patterns:
- Role-based access control
- Emergency shutdown procedures
- Fee management system

##### Technical Implementation Details

- External interfaces (ERC4626, ERC20)
- Integration points with external protocols
- State variables and their flow

How the testing infrastructure validates:
- E2E flows
- Unit test coverage
- Mock contract interaction patterns

Remember to:
- Use consistent styling for similar components
- Version information (V3)
- Relevant audit reference points

## Diagram (Mermaid)

```mermaid
flowchart TB
    subgraph Core["Core Smart Contracts"]
        VF["VaultFactory"]
        VV3["VaultV3\nERC4626 Compliant"]
        TS["Tokenized Strategy"]
    end

    subgraph Periphery["Peripheral Components"]
        AC["Accountant"]
        LM["Limit Module"]
        FM["Fee Management"]
    end

    subgraph Testing["Testing Infrastructure"]
        E2E["E2E Tests"]
        UT["Unit Tests"]
        MC["Mock Contracts"]
    end

    subgraph Functions["Key Functional Components"]
        DM["Debt Management"]
        ES["Emergency Shutdown"]
        PU["Profit Unlocking"]
        RBAC["Role-Based Access"]
        SM["Strategy Management"]
        PF["Protocol Fees"]
    end

    %% Core relationships
    VF -->|Deploys| VV3
    VV3 <-->|Interacts| TS
    
    %% Peripheral interactions
    VV3 <--->|Accounting| AC
    VV3 <--->|Limits| LM
    VV3 <--->|Fees| FM
    
    %% Functional flows
    VV3 --- DM
    VV3 --- ES
    VV3 --- PU
    VV3 --- RBAC
    VV3 --- SM
    VV3 --- PF

    %% Testing relationships
    E2E -.->|Validates| VV3
    UT -.->|Tests| VV3
    MC -.->|Mocks| VV3

    classDef default fill:#f9f9f9,stroke:#333,stroke-width:2px
    classDef core fill:#e1f5fe,stroke:#0277bd
    classDef periphery fill:#f3e5f5,stroke:#7b1fa2
    classDef testing fill:#fff3e0,stroke:#ef6c00
    classDef function fill:#e8f5e9,stroke:#2e7d32

    class VF,VV3,TS core
    class AC,LM,FM periphery
    class E2E,UT,MC testing
    class DM,ES,PU,RBAC,SM,PF function

    click VF "https://github.com/yearn/yearn-vaults-v3/blob/master/contracts/VaultFactory.vy"
    click VV3 "https://github.com/yearn/yearn-vaults-v3/blob/master/contracts/VaultV3.vy"
    click TS "https://github.com/yearn/yearn-vaults-v3/tree/master/lib/tokenized-strategy"
    click AC "https://github.com/yearn/yearn-vaults-v3/blob/master/contracts/test/mocks/periphery/Accountant.vy"
    click LM "https://github.com/yearn/yearn-vaults-v3/blob/master/contracts/test/mocks/periphery/LimitModule.vy"
    click FM "https://github.com/yearn/yearn-vaults-v3/blob/master/tests/unit/periphery/test_fee_manager.py"
    click E2E "https://github.com/yearn/yearn-vaults-v3/tree/master/tests/e2e"
    click UT "https://github.com/yearn/yearn-vaults-v3/tree/master/tests/unit"
    click MC "https://github.com/yearn/yearn-vaults-v3/tree/master/contracts/test/mocks"
    click DM "https://github.com/yearn/yearn-vaults-v3/blob/master/tests/unit/vault/test_debt_management.py"
    click ES "https://github.com/yearn/yearn-vaults-v3/blob/master/tests/unit/vault/test_emergency_shutdown.py"
    click PU "https://github.com/yearn/yearn-vaults-v3/blob/master/tests/unit/vault/test_profit_unlocking.py"
    click RBAC "https://github.com/yearn/yearn-vaults-v3/blob/master/tests/unit/vault/test_role_base_access.py"
    click SM "https://github.com/yearn/yearn-vaults-v3/blob/master/tests/unit/vault/test_strategy_management.py"
    click PF "https://github.com/yearn/yearn-vaults-v3/blob/master/tests/unit/vault/test_protocol_fees.py"
```
