# naddotfun/contracts architecture

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

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

## Overview

##### Project Type & Purpose
- The project is a smart contract system written in Solidity (using Foundry for development) that creates and manages bonding curve-based tokens.
- Its purpose is to enable token creation, buying, and selling using bonding curves combined with automated market makers. It supports both native and wrapped tokens and integrates with external decentralized exchanges (e.g., Uniswap).

##### File Structure
- The top-level directories (src, test, and .github) show that the project separates its smart contract source code, its test suites, and even its CI/CD workflows.
- Within src, key folders include:
- abis: Contains JSON representations of contract interfaces (e.g., IBondingCurve, ICore, IToken, etc.), which indicate external interaction points.
- errors and interfaces: Centralize error handling and define contract interfaces, ensuring modularity and upgradability.
- uniswap: Contains libraries and interfaces hinting at integrations with Uniswap DEX functionality.
- utils: Provides helper functions and libraries (such as mathematical helpers or security utilities).

##### Readme Insights
- The README details the system’s main contracts: Core.sol, BondingCurve.sol, BondingCurveFactory.sol, WNative.sol, FeeVault.sol, Token.sol, MintParty.sol, and MintPartyFactory.sol.
- It clearly describes a layered architecture where the core contract coordinates operations, factories deploy contracts, and utility contracts support calculations and error handling.
- The README also discusses how token creation, buying/selling (with slippage protection), fee collection, and liquidity management take place.

a. Main Components:
- Core Contracts:
- Core.sol: Acts as the central coordinator.
- BondingCurve.sol: Contains the core bonding curve logic and liquidity management.
- BondingCurveFactory.sol: Deploys new bonding curve contracts and maintains a registry.
- WNative.sol: Provides the wrapped native token functionality.
- Supporting Contracts:
- FeeVault.sol: Manages fee collection and distribution.
- Token.sol: Implements ERC20 tokens representing the created coins.
- MintParty.sol and MintPartyFactory.sol: Manage group token minting.
- Utility & Interface Components:
- Utility Libraries (within src/utils) for mathematical operations and security.
- Interfaces & Errors that define and standardize inter-contract communications.
- External Dependencies & Integrations:
- Uniswap DEX integration (see the src/uniswap directory) for liquidity and price discovery.
- CPMM DEX (mentioned in the README) that interacts with the bonding curve operations.

b. Relationships and Data Flow:
- From Core.sol, indicate that a call is made to BondingCurveFactory.sol, which then deploys a new BondingCurve.sol instance.
- Data flows from Core.sol to:
- FeeVault.sol for fee collection,
- WNative.sol for handling wrapped tokens,
- Token.sol for deploying new ERC20 tokens.
- Interactions where Traders interact with Core.sol to buy or sell tokens, which in turn route through bonding curve calculations (via BondingCurve.sol) and require slippage protection.
- That Utility functions and Interfaces are used as supporting blocks that “feed into” these main contracts.

c. Architectural Patterns & Design Principles:
- A modular approach is employed, with each smart contract having a well-defined responsibility.
- Use of factory patterns (e.g., BondingCurveFactory and MintPartyFactory) to standardize the creation of contracts.
- Clearly separate business logic (Core) from utility/helper functions (Utils, Libraries).
- Emphasis on clear error management (Errors folder) and strict interface definitions to facilitate upgradeability.

d. Relevant Technologies & Frameworks:
- Solidity and Foundry as the core development framework.
- Integration with JavaScript tools for deployment and testing (package.json, package-lock.json).
- CI/CD setup via GitHub Actions (in the .github/workflows directory).
- Standard technologies from the blockchain ecosystem like ERC20, ERC4626 interfaces, and Uniswap libraries.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% User Interaction
    subgraph "User Interaction"
        Creator("Creator"):::user
        Trader("Trader"):::user
    end

    %% Core Contracts
    subgraph "Core Contracts"
        Core("Core.sol"):::contract
        Curve("BondingCurve.sol"):::contract
    end

    %% Factory Contracts
    subgraph "Factory Contracts"
        BCFactory("BondingCurveFactory.sol"):::factory
        MPFactory("MintPartyFactory.sol"):::factory
    end

    %% Token & Fee Management
    subgraph "Token & Fee Management"
        WNative("WNative.sol"):::contract
        FeeVault("FeeVault.sol"):::contract
        Token("Token.sol"):::contract
        MintParty("MintParty.sol"):::contract
    end

    %% Utilities & Interfaces
    subgraph "Utilities & Interfaces"
        Interfaces("Interfaces & Errors"):::utils
        Utils("Utility Libraries"):::utils
    end

    %% External Integrations
    subgraph "External Integrations"
        Uniswap("Uniswap DEX"):::external
        CPMM("CPMM DEX"):::external
    end

    %% Connections between User and Core
    Creator -->|"createCurve"| Core
    Trader  -->|"buy/sell"| Core

    %% Core interactions with factories and utilities
    Core -->|"deploys"| BCFactory
    Core -->|"initiates"| MPFactory
    Core -->|"calls"| FeeVault
    Core -->|"handles"| WNative
    Core -->|"deploys"| Token
    Core -->|"utilizes"| Interfaces
    Core -->|"uses"| Utils

    %% Factory deployment flow
    BCFactory -->|"creates"| Curve
    MPFactory -->|"deploys"| MintParty

    %% Interaction between traders and bonding curve
    Trader -->|"triggers exchange"| Curve

    %% External liquidity and DEX integration
    Curve -->|"liquidity info"| Uniswap
    Core -->|"price discovery"| Uniswap
    Uniswap -->|"market data"| CPMM

    %% Click Events
    click Core "https://github.com/naddotfun/contracts/blob/main/src/Core.sol"
    click Curve "https://github.com/naddotfun/contracts/blob/main/src/BondingCurve.sol"
    click BCFactory "https://github.com/naddotfun/contracts/blob/main/src/BondingCurveFactory.sol"
    click WNative "https://github.com/naddotfun/contracts/blob/main/src/WNative.sol"
    click FeeVault "https://github.com/naddotfun/contracts/blob/main/src/FeeVault.sol"
    click Token "https://github.com/naddotfun/contracts/blob/main/src/Token.sol"
    click MintParty "https://github.com/naddotfun/contracts/blob/main/src/MintParty.sol"
    click MPFactory "https://github.com/naddotfun/contracts/blob/main/src/MintPartyFactory.sol"
    click Interfaces "https://github.com/naddotfun/contracts/tree/main/src/interfaces"
    click Utils "https://github.com/naddotfun/contracts/tree/main/src/utils"
    click Uniswap "https://github.com/naddotfun/contracts/tree/main/src/uniswap"

    %% Styles
    classDef user fill:#add8e6,stroke:#0000ff,stroke-width:2px;
    classDef contract fill:#d0f0c0,stroke:#228B22,stroke-width:2px;
    classDef factory fill:#fffacd,stroke:#ffa500,stroke-width:2px;
    classDef utils fill:#e6e6fa,stroke:#800080,stroke-width:2px;
    classDef external fill:#ffb6c1,stroke:#ff0000,stroke-width:2px;
```
