# sherlock-audit/2025-05-yearn-ybold architecture

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

- Interactive diagram: https://gitdiagram.com/sherlock-audit/2025-05-yearn-ybold
- Repository: https://github.com/sherlock-audit/2025-05-yearn-ybold

## Overview

##### Project type and purpose
- This is a DeFi on-chain protocol: a Yearn V3 ERC-4626 vault (“yBOLD”) plus companion strategies that interact with Liquity V2 Stability Pools and Auction contracts. It includes profit tracking (Accountant), staking wrapper (Staker), and off-chain keepers to call tend/harvest.

##### File structure
- Top level:
- yv3-liquityv2-sp-strategy/ — core Solidity code, configs, tests
- src/interfaces/ — external protocol and Yearn interface definitions
- src/periphery/ — Accountant.sol, Staker.sol and their Factories
- Strategy.sol + StrategyFactory.sol
- Staker.sol + StakerFactory.sol
- lib/ — vendored Yearn and OpenZeppelin libraries, TokenizedStrategy, VaultV3
- config files: foundry.toml, slither.config.json, .env.example, Makefile
- Factories indicate a dynamic-deployment pattern (StrategyFactory, AccountantFactory, StakerFactory).

##### Key architecture points from README
- yBOLD vault (VaultV3) allocates BOLD into N Strategy instances (each wraps a Liquity Stability Pool + Auction)
- Accountant.sol collects all gains from yBOLD, mints new yBOLD to itself, then distributes to st-yBOLD via Staker.sol
- Off-chain keepers call tend() (to claim collateral & start auctions) and harvest() (to report P/L)
- External integrations: Liquity StabilityPool, AuctionFactory/Auction, price oracles, TroveManager, etc.

##### Main components
a. On-chain contracts:
- yBOLD Vault (ERC-4626, VaultV3)
- Strategy (Strategy.sol) + StrategyFactory
- Accountant (Accountant.sol) + AccountantFactory
- Staker (Staker.sol) + StakerFactory
- External protocol contracts:
– StabilityPool
– Auction / AuctionFactory
– TroveManager, ActivePool, CollateralRegistry, SortedTroves, MultiTroveGetter
– PriceFeed / AggregatorV3Interface
b. Off-chain services:
- Keeper bots (call tend/harvest)
c. External systems:
- Price oracles (e.g., Chainlink)
- Ethereum / L2 networks (Ethereum, Arbitrum, etc.)

##### Relationships & data flows
- User → deposit BOLD → yBOLD Vault → issues yBOLD
- yBOLD Vault ↔ Strategy instances (deposit/withdraw BOLD; report P/L)
- Strategy ↔ StabilityPool (deposit BOLD collateral), Strategy ↔ Auction (auction collateral → BOLD)
- Strategy.report → yBOLD → Accountant
- Accountant.mint yBOLD → to itself → forward to Staker
- User → deposit yBOLD → Staker → earn yield
- Keepers monitor on-chain events → call tend()/harvest() on Strategy

##### Architectural patterns & design principles
- Factory pattern for dynamic contract deployments
- ERC-4626 vault standard for yBOLD & st-yBOLD
- TokenizedStrategy inheritance: reuse Yearn’s base strategy logic
- Separation of concerns: Vault (user shares), Strategy (yield logic), Accountant (fee routing), Staker (yield distribution)
- Off-chain keeper orchestration

##### Essential elements
- Component labels, version references (e.g., VaultV3.vy)
- Arrowheads with action labels (deposit(), tend(), harvest(), process_report())
- Blue = core on-chain contracts
- Green = external protocol contracts
- Orange = off-chain keepers

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% User and Network
    subgraph "User & Network Layer"
        direction TB
        User["User"]
        Ethereum["Ethereum / L2 Networks"]:::external
    end

    %% Core Contracts
    subgraph "Core On-Chain Contracts"
        direction TB
        Vault["yBOLD Vault (VaultV3)"]:::core
        StrategyFactory["StrategyFactory"]:::core
        Strategy["Strategy (Strategy.sol)"]:::core
        AccountantFactory["AccountantFactory"]:::core
        Accountant["Accountant (Accountant.sol)"]:::core
        StakerFactory["StakerFactory"]:::core
        Staker["Staker (Staker.sol)"]:::core
    end

    %% Protocol Integrations
    subgraph "External Protocol Integrations"
        direction TB
        StabilityPool["StabilityPool"]:::external
        Auction["AuctionFactory/Auction"]:::external
        TroveManager["TroveManager & Related"]:::external
        PriceFeed["PriceFeed / AggregatorV3"]:::external
    end

    %% Off-chain Keepers
    subgraph "Off-Chain Keeper Layer"
        direction TB
        Keepers["Keeper Bots (tend/harvest)"]:::offchain
    end

    %% Flows
    User -->|"deposit BOLD"| Vault
    Vault -->|"deploys"| StrategyFactory
    StrategyFactory -->|"create()"| Strategy
    Strategy -->|"depositCollateral() BOLD"| StabilityPool
    Strategy -->|"startAuction()"| Auction
    Strategy -->|"report() P/L"| Accountant
    Accountant -->|"mint() yBOLD"| Staker
    User -->|"deposit yBOLD"| Staker

    Ethereum --- StabilityPool
    Ethereum --- Auction
    Ethereum --- TroveManager
    Ethereum --- PriceFeed

    Keepers -.->|"tend() / harvest() calls"| Strategy

    %% Deploy Factories
    Vault -->|"deploys"| AccountantFactory
    Vault -->|"deploys"| StakerFactory

    %% Click Events
    click Vault "https://github.com/sherlock-audit/2025-05-yearn-ybold/blob/main/yv3-liquityv2-sp-strategy/lib/yearn-vaults-v3/src/VaultV3.sol"
    click Strategy "https://github.com/sherlock-audit/2025-05-yearn-ybold/blob/main/yv3-liquityv2-sp-strategy/src/Strategy.sol"
    click StrategyFactory "https://github.com/sherlock-audit/2025-05-yearn-ybold/blob/main/yv3-liquityv2-sp-strategy/src/StrategyFactory.sol"
    click Accountant "https://github.com/sherlock-audit/2025-05-yearn-ybold/blob/main/yv3-liquityv2-sp-strategy/src/periphery/Accountant.sol"
    click AccountantFactory "https://github.com/sherlock-audit/2025-05-yearn-ybold/blob/main/yv3-liquityv2-sp-strategy/src/periphery/AccountantFactory.sol"
    click Staker "https://github.com/sherlock-audit/2025-05-yearn-ybold/blob/main/yv3-liquityv2-sp-strategy/src/periphery/Staker.sol"
    click StakerFactory "https://github.com/sherlock-audit/2025-05-yearn-ybold/blob/main/yv3-liquityv2-sp-strategy/src/periphery/StakerFactory.sol"
    click Interfaces "https://github.com/sherlock-audit/2025-05-yearn-ybold/tree/main/yv3-liquityv2-sp-strategy/src/interfaces/"

    %% Styles
    classDef core fill:#bbdefb,stroke:#1e88e5,stroke-width:2px
    classDef external fill:#c8e6c9,stroke:#43a047,stroke-width:2px
    classDef offchain fill:#ffe0b2,stroke:#fb8c00,stroke-width:2px
```
