# dangerousfood/ethstrategy architecture

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

- Interactive diagram: https://gitdiagram.com/dangerousfood/ethstrategy
- Repository: https://github.com/dangerousfood/ethstrategy

## Overview

##### Project Type and Purpose
- EtherStrategy is a blockchain-based, onchain tokenized protocol operating on Ethereum. It manages an ETH pool and issues $ETHXR tokens to represent a share in the growing ETH pool.
- Its primary functions include managing a deposit pool of ETH, raising funds through convertible bonds (using USDC), issuing new tokens through ATM offerings, and handling NAV options through onchain governance.
- Think of it as a decentralized, onchain version of MicroStrategy, but with transparent and governed mechanisms.

##### Analyzing the File Structure
- Top-level directories include:
- src: Likely contains the Solidity smart contract source files that implement the core protocol logic (e.g., deposit pool, bond conversion, token issuance, governance).
- test: Contains tests for smart contracts, ensuring the correctness of protocol logic.
- lib: Contains important dependencies and libraries like OpenZeppelin contracts, Forge Standard Library (forge-std), Solady, and a custom TReentrancyGuard. These support secure contract development.
- script & ts-scripts: These directories host deployment and auxiliary scripts (the ts-scripts directory indicates TypeScript-based tools for signing whitelist data and verifying contracts, while the script directory likely offers forge/solidity-based deployment or operation scripts).
- Additional files such as foundry.toml, package.json, and deploy.config.json indicate a build and deployment system using Foundry and pnpm, aligning with modern Solidity development practices.

##### Architectural Insights from the README
- The README details multiple interactable protocol elements: deposit pool, convertible bonds, ATM offerings, NAV options, and onchain governance.
- It describes key flows like:
- Deposits from initial funders, resulting in $ETHXR token issuance.
- The mechanics behind buying bonds with USDC that convert to tokens or get redeemed.
- Issuance of new tokens when market conditions meet ATM offering criteria.
- Governance mechanisms (voting, rage quit, transfer pausing) for protocol control.
- These insights help identify the main components and interactions within the protocol.

a. Main Components:
- User Interface/Interaction Layer: This isn’t explicitly described in the file tree but could be integrated through web3 frontends interfacing with contracts.
- Smart Contract Layer (Core Protocol):
- Deposit Pool: Manages ETH deposited by early backers.
- Convertible Bonds Module: Handles bond issuance, conversion to $ETHXR tokens, and redemption in USDC.
- ATM Offering Module: Manages token issuance when $ETHXR trades at a premium.
- NAV Options Module: Governs minting of tokens based on net asset value.
- Governance Module: Manages proposals, votes, token transfer restrictions, and rage quit functionality.
- External Services/Dependencies:
- External Tokens: USDC for bonds and ETH.
- Libraries: OpenZeppelin contracts, forge-std, and other security libraries used as dependencies.
- Supporting Scripts:
- Deployment Scripts: Scripts in “script” and “ts-scripts” directories for contract deployment and verification.
- Testing & CI/CD: GitHub workflow files (.github/workflows) ensure continuous testing and integration.

b. Relationships and Data Flow:
- Users or offchain services interact with the protocol’s smart contracts via transactions:
- Deposits result in issuance of $ETHXR tokens.
- Bonds are purchased with USDC, which then trigger ETH acquisitions to grow the pool.
- ATM offerings and NAV options are triggered based on token market price relative to the pool’s net asset value.
- Governance decisions can pause token transfers or trigger a “rage quit” flow.
- From User → Deposit Pool (ETH deposit)
- From Bond Buyers → Convertible Bonds Module (USDC in, bonds out)
- Bonds Module → ETH Pool (using USDC to purchase ETH)
- ATM Offering Module → New token issuance → ETH Pool replenishment
- Governance Module → Various protocol actions (pausing, execution delay, rage quit)
- Interactions between these modules with clear labels.

c. Architectural Patterns and Design Principles:
- Modularity: Each protocol function (deposit, bonds, ATM, NAV options, governance) is implemented as a distinct module within the smart contracts.
- Onchain Transparency: All actions (deposits, conversions, governance votes) are executed by smart contracts, enhancing auditability.
- Secure Contract Development: Usage of libraries like OpenZeppelin and custom reentrancy guards emphasizes security best practices.
- CI/CD Integration: The presence of GitHub workflows and testing scripts underlines a disciplined deployment and testing lifecycle.

d. Relevant Technologies:
- Solidity & Foundry (with foundry.toml and forge commands) are used for contract development and testing.
- pnpm is used for package management.
- Libraries: OpenZeppelin, Forge Standard Library (forge-std), Solady.
- TypeScript scripts in ts-scripts suggest integration for offchain operations like signing and verifying contracts.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% User Interaction Layer
    subgraph "User Interaction"
        U["User/Wallet"]:::external
    end

    %% Smart Contract Layer
    subgraph "Smart Contract Layer"
        DP["Deposit Pool Contract"]:::contract
        CB["Convertible Bonds Contract"]:::contract
        AO["ATM Offering Contract"]:::contract
        NO["NAV Options Contract"]:::contract
        GM["Governance Contract"]:::contract
    end

    %% External Services
    subgraph "External Services"
        ET["External Tokens (USDC/ETH)"]:::external
        EL["External Libraries & Dependencies"]:::dependency
    end

    %% Deployment & Testing Infrastructure
    subgraph "Deployment & Testing"
        DS["Deployment Scripts (Forge)"]:::infra
        TS["Deployment Scripts (TS)"]:::infra
        TCI["Testing & CI/CD"]:::infra
        CIW["CI/CD Workflows"]:::infra
    end

    %% Connections from User
    U -->|"deposit"| DP
    U -->|"buy_bonds"| CB
    U -->|"trigger_offering"| AO
    U -->|"governance_action"| GM

    %% Inter-contract Interactions
    CB -->|"convert_bonds"| DP
    AO -->|"replenish_pool"| DP
    GM -->|"control_actions"| DP
    GM -->|"control_actions"| CB
    GM -->|"control_actions"| AO
    GM -->|"control_actions"| NO

    %% Dependencies to External Libraries
    DP -->|"uses"| EL
    CB -->|"uses"| EL
    AO -->|"uses"| EL
    NO -->|"uses"| EL
    GM -->|"uses"| EL

    %% External Tokens funding Convertible Bonds
    ET -->|"funds_purchase"| CB

    %% Deployment flows
    DS -->|"deploys_contract"| DP
    DS -->|"deploys_contract"| CB
    DS -->|"deploys_contract"| AO
    DS -->|"deploys_contract"| NO
    DS -->|"deploys_contract"| GM

    TS -->|"assists_deployment"| DP
    TS -->|"assists_deployment"| CB
    TS -->|"assists_deployment"| AO
    TS -->|"assists_deployment"| NO
    TS -->|"assists_deployment"| GM

    %% Testing flows
    TCI -->|"tests_contract"| DP
    TCI -->|"tests_contract"| CB
    TCI -->|"tests_contract"| AO
    TCI -->|"tests_contract"| NO
    TCI -->|"tests_contract"| GM
    TCI -->|"integrates_with"| CIW

    %% Click Events for Component Mapping
    click DP "https://github.com/dangerousfood/ethstrategy/tree/master/src"
    click CB "https://github.com/dangerousfood/ethstrategy/tree/master/src"
    click AO "https://github.com/dangerousfood/ethstrategy/tree/master/src"
    click NO "https://github.com/dangerousfood/ethstrategy/tree/master/src"
    click GM "https://github.com/dangerousfood/ethstrategy/tree/master/src"
    click EL "https://github.com/dangerousfood/ethstrategy/tree/master/lib"
    click DS "https://github.com/dangerousfood/ethstrategy/tree/master/script"
    click TS "https://github.com/dangerousfood/ethstrategy/tree/master/ts-scripts"
    click TCI "https://github.com/dangerousfood/ethstrategy/tree/master/test"
    click CIW "https://github.com/dangerousfood/ethstrategy/tree/master/.github/workflows"

    %% Styles
    classDef contract fill:#ADD8E6,stroke:#00008B,stroke-width:2px;
    classDef external fill:#90EE90,stroke:#006400,stroke-width:2px;
    classDef infra fill:#FFDAB9,stroke:#FF8C00,stroke-width:2px;
    classDef dependency fill:#FFB6C1,stroke:#FF69B4,stroke-width:2px;
```
