# pancakeswap/infinity-core architecture

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

- Interactive diagram: https://gitdiagram.com/pancakeswap/infinity-core
- Repository: https://github.com/pancakeswap/infinity-core

## Overview

##### Project type and purpose
- This is a blockchain-focused smart-contract system (“Infinity Core”) written in Solidity and managed with Foundry (forge), targeting multiple EVM chains (Ethereum, BSC).
- It contains core contracts (vault, pools, fee hooks), utility libraries (math, hooks), interfaces, deployment scripts, and a test suite (Forge and JS).

##### File structure
- Top-level:
– lib/ – external Solidity dependencies (openzeppelin, solmate, pancake-create3-factory, forge-std)
– src/ – project source, subdivided into base, pool-bin, pool-cl modules, libraries, interfaces, types, tests
– script/ – deployment scripts and configurations per network
– test/ & snapshots/ – exhaustive on-chain behavior tests (Forge & JS)
– foundry.toml, package.json, remappings.txt, CI workflows
- Pattern: modular contract design (separate “bin” vs “concentrated liquidity” pools), common libraries (math, hooks), a vault layer.
- Deployment setup uses a Create3 factory pattern (external lib) for deterministic contract addresses.

##### README for additional insights
- Testing via `forge test --isolate`
- Deployment via `forge script … --broadcast` against EVM RPC
- Verification on Etherscan post-deployment
- Configuration driven by JSON files in script/config

a. On-chain components:
– Vault contract
– Pool-bin contracts (factory, pair, manager, hooks)
– Pool-cl (concentrated liquidity) contracts
– Shared libraries (Math, TickBitmap, BitMath, LiquidityMath, SqrtPriceMath)
– Create3 factory (from pancake-create3-factory lib)
b. Off-chain/development components:
– Foundry (forge) toolchain – compiles & tests contracts
– Deployment scripts (S.sol) reading script/config/*.json
– RPC providers (Ethereum, BSC endpoints)
– Etherscan API (for verification)
– CI pipelines (.github/workflows – lint.yml, test.yml)
c. Relationships & data flow:
– Developer invokes `forge test` -> local EVM simulation -> reads src contracts & libs -> outputs test results & snapshots
– Deployment: script -> Create3 factory -> on-chain contract instantiation -> record addresses
– Verification: on-chain bytecode -> Etherscan API
– CI: commits & PRs trigger workflows -> run linters, tests
d. Architectural patterns:
– Modular multi-pool design (bin vs CL)
– Library-driven Math abstraction
– Create3 pattern for deterministic deployments
– Config-driven scripts for multi-network
e. Technology stack: Solidity, Foundry (forge), Hardhat-like scripts, OpenZeppelin, Solmate, CI (GitHub Actions), Node (yarn)

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% Actor
    Developer["Developer"]:::actor

    %% On-chain Modules
    subgraph "On-chain Modules"
        direction TB
        Vault["Vault Contract"]:::onchain
        click Vault "https://github.com/pancakeswap/infinity-core/blob/main/src/base/Vault.sol"

        subgraph "Pool-bin Module"
            direction TB
            PBFactory["Factory"]:::onchain
            click PBFactory "https://github.com/pancakeswap/infinity-core/tree/main/src/pool-bin/"

            PBInterfaces["Interfaces"]:::onchain
            click PBInterfaces "https://github.com/pancakeswap/infinity-core/tree/main/src/pool-bin/interfaces/"

            PBLibs["Libraries"]:::onchain
            click PBLibs "https://github.com/pancakeswap/infinity-core/tree/main/src/pool-bin/libraries/"

            PBLibMath["Math"]:::onchain
            click PBLibMath "https://github.com/pancakeswap/infinity-core/tree/main/src/pool-bin/libraries/math/"

            PBTypes["Types"]:::onchain
            click PBTypes "https://github.com/pancakeswap/infinity-core/tree/main/src/pool-bin/types/"
        end

        subgraph "Pool-cl Module"
            direction TB
            PCContracts["Contracts"]:::onchain
            click PCContracts "https://github.com/pancakeswap/infinity-core/tree/main/src/pool-cl/"

            PCInterfaces["Interfaces"]:::onchain
            click PCInterfaces "https://github.com/pancakeswap/infinity-core/tree/main/src/pool-cl/interfaces/"

            PCLibs["Libraries"]:::onchain
            click PCLibs "https://github.com/pancakeswap/infinity-core/tree/main/src/pool-cl/libraries/"

            PCLibMath["Math"]:::onchain
            click PCLibMath "https://github.com/pancakeswap/infinity-core/tree/main/src/pool-cl/libraries/math/"

            PCTypes["Types"]:::onchain
            click PCTypes "https://github.com/pancakeswap/infinity-core/tree/main/src/pool-cl/types/"
        end

        subgraph "Shared Components"
            direction TB
            SharedLibs["Math Libraries"]:::onchain
            click SharedLibs "https://github.com/pancakeswap/infinity-core/tree/main/src/libraries/math/"

            SharedInterfaces["Interfaces"]:::onchain
            click SharedInterfaces "https://github.com/pancakeswap/infinity-core/tree/main/src/interfaces/"

            SharedTypes["Types"]:::onchain
            click SharedTypes "https://github.com/pancakeswap/infinity-core/tree/main/src/types/"

        end

        Create3["Create3 Factory"]:::external
        click Create3 "https://github.com/pancakeswap/infinity-core/tree/main/lib/pancake-create3-factory/"

        OZ["OpenZeppelin"]:::external
        click OZ "https://github.com/pancakeswap/infinity-core/tree/main/lib/openzeppelin-contracts/"

        Solmate["Solmate"]:::external
        click Solmate "https://github.com/pancakeswap/infinity-core/tree/main/lib/solmate/"

        ForgeStd["Forge std"]:::external
        click ForgeStd "https://github.com/pancakeswap/infinity-core/tree/main/lib/forge-std/"
    end

    %% Off-chain Tools and Scripts
    subgraph "Off-chain Tools & Scripts"
        direction TB
        Foundry["Foundry (forge)"]:::tooling
        click Foundry "https://github.com/pancakeswap/infinity-core/blob/main/foundry.toml"
        Remappings["Remappings"]:::tooling
        click Remappings "https://github.com/pancakeswap/infinity-core/blob/main/remappings.txt"

        Scripts["Deployment Scripts"]:::tooling
        click Scripts "https://github.com/pancakeswap/infinity-core/tree/main/script/config/"

        ConfigFiles["Config Files"]:::tooling
        click ConfigFiles "https://github.com/pancakeswap/infinity-core/tree/main/script/config/"

        JSscripts["JS Test Scripts"]:::tooling
        click JSscripts "https://github.com/pancakeswap/infinity-core/blob/main/test/js-scripts/getSqrtRatioAtTick.ts"

        Snapshots["Snapshot Files"]:::tooling
        click Snapshots "https://github.com/pancakeswap/infinity-core/tree/main/snapshots/"

        CI_Lint["CI Lint Workflow"]:::tooling
        click CI_Lint "https://github.com/pancakeswap/infinity-core/blob/main/.github/workflows/lint.yml"

        CI_Test["CI Test Workflow"]:::tooling
        click CI_Test "https://github.com/pancakeswap/infinity-core/blob/main/.github/workflows/test.yml"
    end

    %% External Services
    subgraph "External Services"
        direction TB
        RPC["RPC Providers"]:::external
        Etherscan["Etherscan API"]:::external
    end

    %% Relationships
    Developer -->|"forge test"| Foundry
    Foundry -->|"compile & simulate"| Vault
    Foundry -->|"generate"| Snapshots

    Developer -->|"forge script"| Scripts
    Scripts -->|"reads config"| ConfigFiles
    Scripts --> RPC
    RPC -->|"deploy via"| Create3
    Create3 -->|"instantiates"| Vault
    Create3 -->|"instantiates"| PBFactory
    Create3 -->|"instantiates"| PCContracts

    Scripts -->|"verify bytecode"| Etherscan
    Etherscan -->|"verification result"| Developer

    Developer -->|"push commit"| CI_Lint
    CI_Lint --> CI_Test
    CI_Test -->|"runs tests"| Foundry

    %% Styles
    classDef onchain fill:#D6E4FF,stroke:#1E40AF,stroke-width:2px;
    classDef tooling fill:#D1FAE5,stroke:#047857,stroke-width:2px;
    classDef external fill:#FEF3C7,stroke:#B45309,stroke-width:2px;
    classDef actor fill:#FEE2E2,stroke:#991B1B,stroke-width:2px;
```
