# cyfrin/2024-12-alchemix architecture

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

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

## Overview

##### Main Components

a) Core Strategy Components:
- StrategyOp.sol (Optimism)
- StrategyMainnet.sol (Ethereum)
- StrategyArb.sol (Arbitrum)

b) External Protocol Integrations:
- Yearn V3 (Base Strategy)
- Alchemix Transmuter
- Velodrome/Uniswap (for token swaps)
- Token Contracts (WETH, alETH)

##### User Deposit Flow
- User → Strategy Contract → Alchemix Transmuter
- Token flow (alETH → yTokens)

##### Keeper Flow
- Keeper → Strategy Contract → Transmuter (claim)
- Strategy → DEX (swap)
- Circular flow of: alETH → WETH → alETH

##### Component Organization

- Blue rectangles: Core strategy contracts
- Green hexagons: External protocols (Yearn, Alchemix)
- Yellow diamonds: Token contracts
- Purple circles: User roles (Keeper, Owner, Manager, Depositor)
- Orange rectangles: DEX components

##### Specific Implementation Details

Create three parallel sections showing implementation across:
- Optimism
- Ethereum Mainnet
- Arbitrum

For each chain, show:
- Strategy contract
- Related interfaces (IAlchemist, ITransmuter, IVeloRouter)
- Chain-specific DEX implementations

##### Additional Elements

- Network boundaries
- Security boundaries

##### Notes Section

A small notes section indicating:
- nSLOC: 253
- Supported tokens
- Key dependencies
- Emergency procedures

## Diagram (Mermaid)

```mermaid
graph TB
    %% Style Definitions
    classDef core fill:#2196F3,stroke:#1565C0,color:white
    classDef external fill:#4CAF50,stroke:#2E7D32,color:white
    classDef token fill:#FFC107,stroke:#FFA000,color:black
    classDef user fill:#9C27B0,stroke:#6A1B9A,color:white
    classDef dex fill:#FF5722,stroke:#D84315,color:white
    classDef interface fill:#78909C,stroke:#546E7A,color:white

    %% User Actors
    User((User)):::user
    Keeper((Keeper)):::user
    Owner((Owner)):::user
    Manager((Manager)):::user

    %% Core Strategy Components
    subgraph Strategies
        StrategyOp[StrategyOp]:::core
        StrategyMainnet[StrategyMainnet]:::core
        StrategyArb[StrategyArb]:::core
    end

    %% External Protocols
    subgraph ExternalProtocols
        YearnV3{{"Yearn V3"}}:::external
        AlchemixTransmuter{{"Alchemix Transmuter"}}:::external
    end

    %% Interfaces
    subgraph Interfaces
        IAlchemist[IAlchemist]:::interface
        ITransmuter[ITransmuter]:::interface
        IVeloRouter[IVeloRouter]:::interface
    end
    click Interfaces "https://github.com/Cyfrin/2024-12-alchemix/tree/main/src/interfaces"

    %% Token Contracts
    WETH[WETH]:::token
    alETH[alETH]:::token

    %% DEX Components
    subgraph DEX
        Velodrome[Velodrome]:::dex
        Uniswap[Uniswap]:::dex
    end

    %% Test Components
    subgraph Testing
        TestSuite[Test Suite]:::interface
        MockContracts[Mock Contracts]:::interface
    end
    click TestSuite "https://github.com/Cyfrin/2024-12-alchemix/tree/main/src/test"
    click MockContracts "https://github.com/Cyfrin/2024-12-alchemix/tree/main/src/mock"

    %% Peripheral Components
    subgraph Periphery
        Utils[Utilities]:::interface
        Security[Security Analysis]:::interface
    end
    click Utils "https://github.com/Cyfrin/2024-12-alchemix/tree/main/src/test/utils"
    click Security "https://github.com/Cyfrin/2024-12-alchemix/blob/main/slither.config.json"

    %% Documentation
    Documentation[Documentation]:::interface
    click Documentation "https://github.com/Cyfrin/2024-12-alchemix/blob/main/AlchemixReadme.md"

    %% CI/CD
    CICD[CI/CD Pipeline]:::interface
    click CICD "https://github.com/Cyfrin/2024-12-alchemix/tree/main/.github/workflows"

    %% Relationships
    User --> Strategies
    Keeper --> |claimAndSwap| Strategies
    Owner --> |management| Strategies
    Manager --> |configuration| Strategies

    Strategies --> IAlchemist
    Strategies --> ITransmuter
    Strategies --> IVeloRouter

    IAlchemist --> AlchemixTransmuter
    ITransmuter --> AlchemixTransmuter
    IVeloRouter --> DEX

    Strategies --> YearnV3
    Strategies --> |deposit| AlchemixTransmuter
    Strategies --> |swap| DEX

    DEX --> WETH
    DEX --> alETH

    %% Legend
    subgraph Legend
        L1[Strategy]:::core
        L2{{"External Protocol"}}:::external
        L3[Token]:::token
        L4((Actor)):::user
        L5[DEX]:::dex
        L6[Interface]:::interface
    end
```
