# aerodrome-finance/contracts architecture

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

- Interactive diagram: https://gitdiagram.com/aerodrome-finance/contracts
- Repository: https://github.com/aerodrome-finance/contracts

## Overview

##### Project Type and Purpose
- This is an on-chain protocol written in Solidity for EVM chains: an AMM (constant-product pools + router), paired with ve-tokenomics (vote-escrow NFTs), emissions distribution (gauges, rewards), and governance (on-chain governors).
- Deployment/testing is done via Foundry and Hardhat scripts; CI is configured through GitHub Actions.

##### File Structure Analysis
- Top-level “contracts/” directory holds all Solidity code organized into subfolders by domain:
- art, factories, gauges, governance, interfaces, libraries, rewards.
- “script/” contains Hardhat deployment scripts and JSON templates for multiple environments (ci, Base, etc.).
- “lib/” has Git-submodule dependencies: OpenZeppelin, ds-test, forge-std, gsn, v3-core.
- Configuration files: hardhat.config.ts, foundry.toml, tsconfig.json, remappings.txt, .env.example.
- “test/” uses Foundry for unit and e2e tests.
- CI workflows in “.github/workflows” automate linting, build, and tests.

##### README Insights
- README organizes contracts into four key layers:
a. AMM (Pool.sol, Router.sol, PoolFees.sol, FactoryRegistry.sol, ProtocolLibrary.sol)
b. Tokenomy (Aero.sol token, VotingEscrow.sol NFT locks, Minter.sol, RewardsDistributor.sol, VeArtProxy.sol, AirdropDistributor.sol)
c. Protocol mechanics (Voter.sol, Gauge.sol, various Reward implementations under contracts/rewards/)
d. Governance (ProtocolGovernor.sol, EpochGovernor.sol)
- Foundry is the default test/deployment framework; Hardhat is used for scripted multi-stage deployments.

A. Main Components
1. Blockchain Layer (EVM)
2. AMM Core
– PoolFactory → Pool instances ↔ PoolFees
– Router for multi-pool swaps
– FactoryRegistry (registers factories: PoolFactory, GaugeFactory, ManagedRewardsFactory, VotingRewardsFactory)
3. Tokenomy Layer
– Aero ERC20 token
– VotingEscrow (veNFT)
– Minter → distributes new tokens to Voter + RewardsDistributor
– RewardsDistributor handles rebases to ve-holders
– AirdropDistributor for initial veNFT airdrops
– VeArtProxy upgradeable NFT metadata
4. Voting & Emissions Layer
– Voter contract reads veNFT locks to assign weights
– GaugeFactory → Gauge instances
– Gauge ↔ Pool LP tokens staked, emits Aero per epoch
– Rewards module: Reward.sol, VotingReward.sol (FeesVotingReward, BribeVotingReward), ManagedReward variants (LockedManagedReward, FreeManagedReward)
5. Governance Layer
– ProtocolGovernor (OpenZeppelin Governor) for protocol-wide parameter changes (e.g., pool/token whitelists, emissions)
– EpochGovernor for emission rate adjustments per epoch
6. Off-chain Tooling
– Hardhat scripts (script/hardhat/*.ts) for deployments and airdrops
– Foundry tests (test/) and utilities (lib/ds-test, forge-std)
– CI pipelines (.github/workflows)
– Configuration (.env, hardhat.config.ts, foundry.toml)

B. Relationships & Data Flow
- User ↔️ Pool via Router for swaps and liquidity operations
- User locks Aero → VotingEscrow → issues veNFT
- User votes by assigning veNFT to Pools/Gauges → Voter records votes each epoch
- Gauge reads votes → distributes emissions in Aero tokens via Reward contracts
- Minter mints new Aero at epoch boundaries → sends to Voter (for gauges) & RewardsDistributor (rebases)
- Governance proposals → ProtocolGovernor/EpochGovernor → update factories, parameters, emission rates

C. Architectural Patterns & Design Principles
- Modular: one contract per responsibility (Factory, Pool, Gauge, Reward, Governor)
- Factory pattern: abstract factories for Pools, Gauges, Rewards, ManagedRewards
- Dependency injection via FactoryRegistry
- Upgradeability: VeArtProxy uses proxy pattern for NFT metadata
- On-chain composition: Complex behaviors built by composing simple, audited OpenZeppelin modules

D. Key Technologies & Frameworks
- Solidity (contracts/)
- OpenZeppelin Governor & ERC20/ERC721 libraries
- Foundry (forge) for testing & building
- Hardhat for scripted deployments
- GitHub Actions for CI
- JSON-based environment templating for multi-env deployments

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% External Actor
    User(("User")):::external

    %% AMM Core
    subgraph "AMM Core"
        direction TB
        PF["PoolFactory"]:::amm
        PoolFees["PoolFees"]:::amm
        Router["Router"]:::amm
        FR["FactoryRegistry"]:::amm
        PL["ProtocolLibrary"]:::amm
    end

    %% Tokenomy Layer
    subgraph "Tokenomy Layer"
        direction TB
        Aero["Aero (ERC20)"]:::token
        VE["VotingEscrow (veNFT)"]:::token
        Minter["Minter"]:::token
        RD["RewardsDistributor"]:::token
        AD["AirdropDistributor"]:::token
        VAP["VeArtProxy"]:::token
    end

    %% Voting & Emissions
    subgraph "Voting & Emissions"
        direction TB
        Voter["Voter"]:::vote
        GF["GaugeFactory"]:::vote
        Gauge["Gauge"]:::vote
        subgraph "Reward Modules"
            direction TB
            Rwd["Reward"]:::vote
            VR["VotingReward"]:::vote
            FVR["FeesVotingReward"]:::vote
            BVR["BribeVotingReward"]:::vote
            LMR["LockedManagedReward"]:::vote
            FMR["FreeManagedReward"]:::vote
        end
    end

    %% Governance Layer
    subgraph "Governance Layer"
        direction TB
        PG["ProtocolGovernor"]:::gov
        EG["EpochGovernor"]:::gov
    end

    %% Off-chain Tooling
    subgraph "Deployment & Testing"
        direction TB
        HH["Hardhat Scripts"]:::offchain
        ET["Env Templates"]:::offchain
        FD["Foundry Tests & Libs"]:::offchain
        CI["CI Workflows"]:::offchain
        CFG["Config Files"]:::offchain
    end

    %% Connections
    User -->|interacts via swap/liquidity| Router
    Router -->|calls| PF
    Router -->|calls| PoolFees
    PF -->|creates pools| PL
    PF -->|registered in| FR
    GF -->|registers in| FR
    GF -->|creates| Gauge
    User -->|locks tokens| VE
    Aero -->|mint tokens| Minter
    Minter -->|sends emissions| Voter
    Minter -->|sends rebases| RD
    VE -->|issues veNFT| Voter
    Voter -->|assigns weights| Gauge
    Gauge -->|distributes via| Rwd
    Rwd --> VR
    Rwd --> FVR
    Rwd --> BVR
    Rwd --> LMR
    Rwd --> FMR
    AD -->|airdrops veNFTs| VE
    VAP -->|provides metadata| VE
    PG -->|governs| FR
    PG -->|governs| PF
    EG -->|adjusts emissions| Minter
    HH -->|deploys| PF
    HH -->|deploys| GF
    HH -->|deploys| PG
    ET -->|templates| HH
    FD -->|tests| PF
    FD -->|tests| GF
    FD -->|tests| VE
    CI -->|runs| FD
    CI -->|runs| HH
    CFG -->|configures| HH
    CFG -->|configures| FD

    %% Click Events
    click PF "https://github.com/aerodrome-finance/contracts/blob/main/contracts/factories/PoolFactory.sol"
    click PoolFees "https://github.com/aerodrome-finance/contracts/blob/main/contracts/factories/PoolFees.sol"
    click Router "https://github.com/aerodrome-finance/contracts/blob/main/contracts/factories/Router.sol"
    click FR "https://github.com/aerodrome-finance/contracts/blob/main/contracts/factories/FactoryRegistry.sol"
    click PL "https://github.com/aerodrome-finance/contracts/blob/main/contracts/libraries/ProtocolLibrary.sol"
    click Aero "https://github.com/aerodrome-finance/contracts/blob/main/contracts/Aero.sol"
    click VE "https://github.com/aerodrome-finance/contracts/blob/main/contracts/VotingEscrow.sol"
    click Minter "https://github.com/aerodrome-finance/contracts/blob/main/contracts/Minter.sol"
    click RD "https://github.com/aerodrome-finance/contracts/blob/main/contracts/RewardsDistributor.sol"
    click AD "https://github.com/aerodrome-finance/contracts/blob/main/contracts/AirdropDistributor.sol"
    click VAP "https://github.com/aerodrome-finance/contracts/blob/main/contracts/art/VeArtProxy.sol"
    click Voter "https://github.com/aerodrome-finance/contracts/blob/main/contracts/gauges/Voter.sol"
    click GF "https://github.com/aerodrome-finance/contracts/blob/main/contracts/gauges/GaugeFactory.sol"
    click Gauge "https://github.com/aerodrome-finance/contracts/blob/main/contracts/gauges/Gauge.sol"
    click Rwd "https://github.com/aerodrome-finance/contracts/blob/main/contracts/rewards/Reward.sol"
    click VR "https://github.com/aerodrome-finance/contracts/blob/main/contracts/rewards/VotingReward.sol"
    click FVR "https://github.com/aerodrome-finance/contracts/blob/main/contracts/rewards/FeesVotingReward.sol"
    click BVR "https://github.com/aerodrome-finance/contracts/blob/main/contracts/rewards/BribeVotingReward.sol"
    click LMR "https://github.com/aerodrome-finance/contracts/blob/main/contracts/rewards/LockedManagedReward.sol"
    click FMR "https://github.com/aerodrome-finance/contracts/blob/main/contracts/rewards/FreeManagedReward.sol"
    click PG "https://github.com/aerodrome-finance/contracts/blob/main/contracts/governance/ProtocolGovernor.sol"
    click EG "https://github.com/aerodrome-finance/contracts/blob/main/contracts/governance/EpochGovernor.sol"
    click HH "https://github.com/aerodrome-finance/contracts/tree/main/script/hardhat/"
    click ET "https://github.com/aerodrome-finance/contracts/tree/main/script/constants/"
    click FD "https://github.com/aerodrome-finance/contracts/tree/main/test/"
    click CI "https://github.com/aerodrome-finance/contracts/tree/main/.github/workflows/"
    click CFG "https://github.com/aerodrome-finance/contracts/blob/main/foundry.toml"

    %% Styles
    classDef amm fill:#E0F3FF,stroke:#2196F3,color:#000
    classDef token fill:#E8F5E9,stroke:#4CAF50,color:#000
    classDef vote fill:#FFF3E0,stroke:#FF9800,color:#000
    classDef gov fill:#F3E5F5,stroke:#9C27B0,color:#000
    classDef offchain fill:#ECEFF1,stroke:#607D8B,color:#000
    classDef external fill:#FFFFFF,stroke:#000000,color:#000,stroke-dasharray: 2 2
```
