# arcadia-finance/arcadia-vaults architecture

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

- Interactive diagram: https://gitdiagram.com/arcadia-finance/arcadia-vaults
- Repository: https://github.com/arcadia-finance/arcadia-vaults

## Overview

##### Main Components

a) Core Vault Components:
- Vault Factory (proxy pattern)
- Vault Logic Contract (upgradeable)
- ERC-721 Token Interface (for vault representation)

b) Pricing Module System:
- Primary Price Feeds
- Derived Price Feeds
- Pricing Module Registry

c) Asset Support Layer:
- ERC20 Handler
- ERC4626 Handler
- Uniswap/Sushiswap V2 LP Handler
- Uniswap V3 LP Handler
- NFT Floor Price Handler
- AAVE aToken Handler

d) External Integrations:
- Price Oracles
- DEX Interfaces (Uniswap, Sushiswap, Curve)
- Lending Protocols (AAVE)
- NFT Marketplaces

**┌─ External Layer ─────────────────────┐**
- Oracles │ DEXes │ Lending │ NFT Markets │
- ┘
- ↕
**┌─ Integration Layer ──────────────────┐**
- Price Feeds │ Protocol Connectors    │
- ┘
- ↕
**┌─ Core Layer ────────────────────────┐**
- Vault Logic │ Factory │ Access Control│
- ┘
- ↕
**┌─ Asset Handler Layer ───────────────┐**
- ERC20 │ ERC4626 │ LP │ NFT │ aToken │
- ┘

##### Important Relationships

a) Deployment Flow:
- User → Vault Factory → Proxy Vault Instance
- Vault Logic Contract ←→ Proxy Vault

b) Asset Management Flow:
- Vault → Asset Handlers → External Protocols
- Price Modules → Oracle/DEX Data → Vault

c) Upgrade Path:
- Governance → New Vault Logic → User Opt-in

##### Implementation Details

- PricingModules directory structure
- Security implementations
- Test infrastructure
- External protocol interfaces

##### Security boundaries

Keep the abstraction level focused on the architectural components while maintaining enough detail to show the sophisticated pricing and asset handling mechanisms that make this project unique.

Remember to indicate the flow of both assets and price data through the system, as these are crucial aspects of the vault's functionality.

## Diagram (Mermaid)

```mermaid
%%{init: {
  'theme': 'base',
  'themeVariables': {
    'primaryColor': '#2b2b2b',
    'primaryTextColor': '#fff',
    'primaryBorderColor': '#7C0000',
    'lineColor': '#F8B229',
    'secondaryColor': '#006100',
    'tertiaryColor': '#0000ff'
  }
}}%%

flowchart TB
    subgraph External["External Layer"]
        Oracles["Price Oracles"]
        DEXes["DEX Protocols"]
        Lending["Lending Protocols"]
        NFTMarkets["NFT Markets"]
    end

    subgraph Integration["Integration Layer"]
        PricingSystem["Pricing Module System"]:::pricing
        ProtocolConnectors["Protocol Interfaces"]:::interfaces
        UniV3Price["Uniswap V3 Price Integration"]:::pricing
    end

    subgraph Core["Core Layer"]
        VaultFactory["Vault Factory"]:::core
        VaultLogic["Vault Logic Contract"]:::core
        AccessControl["Security Controls"]:::security
        UpgradeManager["Upgrade Management"]:::core
    end

    subgraph Handlers["Asset Handler Layer"]
        ERC20Handler["ERC20 Handler"]:::handler
        ERC4626Handler["ERC4626 Handler"]:::handler
        LPHandler["LP Token Handler"]:::handler
        NFTHandler["NFT Floor Price Handler"]:::handler
        aTokenHandler["aToken Handler"]:::handler
    end

    subgraph Infrastructure["Infrastructure Layer"]
        Testing["Testing Infrastructure"]:::infra
        Utils["Utility Functions"]:::infra
        Deploy["Deployment Scripts"]:::infra
    end

    %% Relationships
    External --> Integration
    Integration --> Core
    Core --> Handlers
    Core --> Infrastructure

    %% Click events
    click PricingSystem "https://github.com/arcadia-finance/arcadia-vaults/tree/main/src/PricingModules"
    click UniV3Price "https://github.com/arcadia-finance/arcadia-vaults/tree/main/src/PricingModules/UniswapV3"
    click ProtocolConnectors "https://github.com/arcadia-finance/arcadia-vaults/tree/main/src/interfaces"
    click Handlers "https://github.com/arcadia-finance/arcadia-vaults/tree/main/src/actions"
    click AccessControl "https://github.com/arcadia-finance/arcadia-vaults/tree/main/src/security"
    click Testing "https://github.com/arcadia-finance/arcadia-vaults/tree/main/src/test"
    click Utils "https://github.com/arcadia-finance/arcadia-vaults/tree/main/src/utils"
    click UpgradeManager "https://github.com/arcadia-finance/arcadia-vaults/tree/main/src/test/MerkleTrees"
    click Deploy "https://github.com/arcadia-finance/arcadia-vaults/tree/main/script"

    %% Styling
    classDef core fill:#0000ff,color:#fff
    classDef handler fill:#006100,color:#fff
    classDef pricing fill:#F8B229,color:#000
    classDef security fill:#ff0000,color:#fff
    classDef interfaces fill:#800080,color:#fff
    classDef infra fill:#808080,color:#fff

    %% Legend
    subgraph Legend
        CoreComponent["Core Component"]:::core
        HandlerComponent["Asset Handler"]:::handler
        PricingComponent["Pricing Module"]:::pricing
        SecurityComponent["Security Component"]:::security
        InterfaceComponent["Interface Component"]:::interfaces
        InfraComponent["Infrastructure"]:::infra
    end
```
