# morpho-org/bundler3 architecture

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

- Interactive diagram: https://gitdiagram.com/morpho-org/bundler3
- Repository: https://github.com/morpho-org/bundler3

## Overview

##### Main Components

a) Core Components:
- Bundler3 Contract (Central Component)
- Adapter System
- Protocol Integrations
- External Protocols (Morpho, Aave, Compound, etc.)

b) Supporting Components:
- Testing Infrastructure
- Verification System (Certora)
- Security Measures

##### Special Features to Highlight

Create dedicated sections showing:
- Transient Storage Mechanism
- Reentrance Pattern
- Skip Revert Logic
- Callback Hash Verification

##### Important Details

Annotations showing:
- Call Structure (to, data, value, skipRevert, callbackHash)
- Security Boundaries
- Approval Flows
- Migration Paths

##### Specific Implementation Notes

- Adapter Inheritance Structure
- Migration Flow Patterns
- Protocol-Specific Interactions

##### Technical Specifications

Technical notes regarding:
- Smart Contract Interactions
- Gas Optimization Points
- Security Measures
- Verification Points

##### Version Differentiation

A small section highlighting key differences from Bundler v2:
- Transient Storage Usage
- Separated Approval System
- Adapter Architecture Changes

Remember to emphasize the security aspects, particularly around the authorization flows and callback handling, as these are critical aspects of the system's design.

## Diagram (Mermaid)

```mermaid
flowchart TB
    subgraph Entry["Entry Layer"]
        B3[Bundler3]
        TS[Transient Storage]
        MC[Multicall Interface]
    end

    subgraph Adapters["Adapter Layer"]
        direction TB
        CA[CoreAdapter]
        GA1[GeneralAdapter1]
        EGA1[EthereumGeneralAdapter1]
        PSA[ParaswapAdapter]
        
        subgraph MA["Migration Adapters"]
            direction TB
            M1[Migration1]
            M2[Migration2]
        end
    end

    subgraph Protocols["Protocol Layer"]
        direction TB
        MP[Morpho]
        AV[Aave]
        CP[Compound]
        P2[Permit2]
        OZ[OpenZeppelin]
    end

    subgraph Testing["Testing & Verification"]
        direction TB
        TI[Test Infrastructure]
        VS[Verification System]
        FT[Fork Testing]
        SA[Security Audits]
    end

    subgraph Components["Core Components"]
        direction TB
        LIB[Libraries]
        INT[Interfaces]
        MCK[Mock Contracts]
    end

    %% Relationships
    B3 --> MC
    B3 --> TS
    MC --> CA
    CA --> GA1
    CA --> EGA1
    CA --> PSA
    CA --> MA
    GA1 --> Protocols
    EGA1 --> Protocols
    PSA --> Protocols
    MA --> Protocols

    %% Click Events
    click CA "https://github.com/morpho-org/bundler3/tree/main/src/adapters/"
    click MA "https://github.com/morpho-org/bundler3/tree/main/src/adapters/migration/"
    click VS "https://github.com/morpho-org/bundler3/tree/main/certora/"
    click TI "https://github.com/morpho-org/bundler3/tree/main/test/"
    click MP "https://github.com/morpho-org/bundler3/tree/main/lib/morpho-blue/"
    click P2 "https://github.com/morpho-org/bundler3/tree/main/lib/permit2/"
    click OZ "https://github.com/morpho-org/bundler3/tree/main/lib/openzeppelin-contracts/"
    click SA "https://github.com/morpho-org/bundler3/tree/main/audits/"
    click VS "https://github.com/morpho-org/bundler3/tree/main/certora/specs/"
    click LIB "https://github.com/morpho-org/bundler3/tree/main/src/libraries/"
    click INT "https://github.com/morpho-org/bundler3/tree/main/src/interfaces/"
    click MCK "https://github.com/morpho-org/bundler3/tree/main/src/mocks/"
    click FT "https://github.com/morpho-org/bundler3/tree/main/test/fork/"

    %% Styling
    classDef core fill:#2b6cb0,stroke:#1a365d,color:white
    classDef adapter fill:#2f855a,stroke:#1c4532,color:white
    classDef protocol fill:#718096,stroke:#2d3748,color:white
    classDef testing fill:#c53030,stroke:#742a2a,color:white
    classDef component fill:#6b46c1,stroke:#44337a,color:white

    class B3,TS,MC core
    class CA,GA1,EGA1,PSA,MA adapter
    class MP,AV,CP,P2,OZ protocol
    class TI,VS,FT,SA testing
    class LIB,INT,MCK component
```
