# infinifi-labs/infinifi-protocol architecture

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

- Interactive diagram: https://gitdiagram.com/infinifi-labs/infinifi-protocol
- Repository: https://github.com/infinifi-labs/infinifi-protocol

## Overview

##### Project Type and Purpose
- This project is a blockchain-based decentralized finance (DeFi) protocol primarily implemented in Solidity. It handles the minting and redemption of receipt tokens (like iUSD, iETH) against collateral assets (USDC, ETH) while integrating yield generation, locking mechanisms, and a governance system.
- The README identifies the main features as yield generation via multiple farm integrations, enhanced rewards through token locking, and dynamic governance for farm allocation voting.

##### Core File Structure
- The top-level directories (src, test, lib) indicate that the project is structured around smart contracts with extensive testing (unit and integration) and dependencies (OpenZeppelin, Solmate, Forge-std).
- Under “src” you have dedicated modules that clearly mirror the protocol architecture described in the README: core, gateway, funding, locking, governance, finance, and integrations. Each of these directories contains Solidity contracts representing a distinct part of the protocol.
- The “lib” directory houses external dependencies and libraries that provide well-known frameworks for security, testing, and deployment.

##### Components
- Core Module:
– Include “InfiniFiCore.sol” & “CoreControlled.sol”. Represent this as the central entity handling roles, access control, and permissions that serve as a base for many contracts.

- Gateway Module:

- Funding Module:
– Illustrate components like “MintController.sol”, “RedeemController.sol”, and “RedemptionPool.sol” as responsible for token minting and redemption workflow. Also show the “ReceiptToken.sol” under tokens.

- Locking Module:
– Incorporate “LockingController.sol” and “UnwindingModule.sol” and represent the associated token “LockedPositionToken.sol” (an ERC20 token that symbolizes locked positions).

- Governance Module:
– Include “AllocationVoting.sol”. Indicate how it uses locked tokens (weighted votes) to dynamically decide farm allocations.

- Finance Module:
– Represent “YieldSharing.sol” and “Accounting.sol” for distributing yield and managing protocol accounting/data.

- Integrations Module:
– Show “FarmRegistry.sol” along with movement components (from the “farms/movement/” directory such as “ManualRebalancer.sol”, “AfterMintHook.sol”, “BeforeRedeemHook.sol”). This module connects the protocol to external yield farms (such as Aave and Pendle) and facilitates asset movement or rebalancing.

##### Relationships and Interactions
- Within the Funding module, connect the minting process to the receipt token contract and then route redemption flows through the redemption queue.
- Link the Locking module’s operations with Governance, showing that locked tokens affect voting power.

##### Architectural Patterns and Design Principles
- Use of modular design: each “module” (Core, Gateway, Funding, etc.) encapsulates a distinct aspect of functionality.
- Separation of concerns (for example, minting/redemption logic in the Funding module vs. locking and reward calculations in the Locking module).
- If appropriate, mention that the design fosters upgradeability and testability, as hinted by the presence of extensive testing directories and use of libraries like OpenZeppelin and Solmate.

##### Specific Elements
- Each component should be clearly marked with its name (e.g., “InfiniFiCore”, “MintController”, etc.).
- Optionally, include notes for security features (like role-based access control and emergency/guardian override) that are critical for understanding the design.

## Diagram (Mermaid)

```mermaid
graph TD
    %% Core and Gateway
    subgraph "Core Module – Access & Control"
        C["InfiniFiCore"]:::core
    end

    subgraph "Gateway – User Entry Point"
        G["InfiniFiGatewayV1"]:::gateway
    end

    %% Funding Module
    subgraph "Funding Module – Minting & Redemption"
        M["MintController"]:::funding
        R["RedeemController"]:::funding
        RP["RedemptionPool"]:::funding
        RT["ReceiptToken"]:::funding
    end

    %% Locking Module
    subgraph "Locking Module – Token Locking"
        LC["LockingController"]:::locking
        UM["UnwindingModule"]:::locking
        LT["LockedPositionToken"]:::locking
    end

    %% Governance Module
    subgraph "Governance Module – Voting & Allocation"
        AV["AllocationVoting"]:::governance
    end

    %% Finance Module
    subgraph "Finance Module – Yield Distribution & Accounting"
        YS["YieldSharing"]:::finance
        AC["Accounting"]:::finance
    end

    %% Integrations Module
    subgraph "Integrations Module – External Farm Connectivity"
        FR["FarmRegistry"]:::integrations
        MR["ManualRebalancer"]:::integrations
        AM["AfterMintHook"]:::integrations
        BR["BeforeRedeemHook"]:::integrations
        AAVE["Aave"]:::external
        PENDLE["Pendle"]:::external
    end

    %% Relationships: Core provides access and security to all modules
    C -->|"controls"| G
    C -->|"secures"| M
    C -->|"secures"| LC
    C -->|"secures"| AV
    C -->|"secures"| YS
    C -->|"secures"| FR

    %% Gateway directs user operations to various modules
    G -->|"minting request"| M
    G -->|"redemption request"| R
    G -->|"locking action"| LC
    G -->|"voting request"| AV
    G -->|"yield query"| YS
    G -->|"farm integration"| FR

    %% Funding Module internal flow
    M -->|"issues_token"| RT
    R -->|"redemption_flow"| RP

    %% Locking Module internal flow and governance integration
    LC -->|"lock_tokens"| LT
    LT -->|"voting_power"| AV
    LC --> UM

    %% Finance and Integrations interplay
    YS -->|"yield_dependency"| FR

    %% Integrations Module internal delegation to movement hooks
    FR --> MR
    FR --> AM
    FR --> BR

    %% External farm connections to the Integrations Module
    AAVE -->|"data_feed"| FR
    PENDLE -->|"data_feed"| FR

    %% Styling classes
    class C core
    class G gateway
    class M,R,RP,RT funding
    class LC,UM,LT locking
    class AV governance
    class YS,AC finance
    class FR,MR,AM,BR integrations
    class AAVE,PENDLE external

    %% Click Events
    click C "https://github.com/infinifi-labs/infinifi-protocol/tree/master/src/core"
    click G "https://github.com/infinifi-labs/infinifi-protocol/tree/master/src/gateway"
    click M "https://github.com/infinifi-labs/infinifi-protocol/tree/master/src/funding"
    click R "https://github.com/infinifi-labs/infinifi-protocol/tree/master/src/funding"
    click RP "https://github.com/infinifi-labs/infinifi-protocol/tree/master/src/funding"
    click RT "https://github.com/infinifi-labs/infinifi-protocol/tree/master/src/tokens"
    click LC "https://github.com/infinifi-labs/infinifi-protocol/tree/master/src/locking"
    click UM "https://github.com/infinifi-labs/infinifi-protocol/tree/master/src/locking"
    click LT "https://github.com/infinifi-labs/infinifi-protocol/tree/master/src/tokens"
    click AV "https://github.com/infinifi-labs/infinifi-protocol/tree/master/src/governance"
    click YS "https://github.com/infinifi-labs/infinifi-protocol/tree/master/src/finance"
    click AC "https://github.com/infinifi-labs/infinifi-protocol/tree/master/src/finance"
    click FR "https://github.com/infinifi-labs/infinifi-protocol/tree/master/src/integrations"
    click MR "https://github.com/infinifi-labs/infinifi-protocol/tree/master/src/integrations/farms/movement"
    click AM "https://github.com/infinifi-labs/infinifi-protocol/tree/master/src/integrations/farms/movement"
    click BR "https://github.com/infinifi-labs/infinifi-protocol/tree/master/src/integrations/farms/movement"
```
