# enlomy/pumpfun-solana-smart-contract architecture

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

- Interactive diagram: https://gitdiagram.com/enlomy/pumpfun-solana-smart-contract
- Repository: https://github.com/enlomy/pumpfun-solana-smart-contract

## Overview

##### Main Components
- Smart Contract Program: Represent the main on-chain program, “bonding_curve”. Inside this, show the following sub-components:
- State Management: Include a component for state definitions used to store on-chain data (e.g., “state.rs”).
- Error Handling: A dedicated block for “errors.rs” that outlines how errors are managed.

- Deployment & Configuration: Include components for the Anchor configuration (Anchor.toml), migration scripts (migrations/deploy.ts), and Cargo package files. This represents the environment/setup part.

- Testing and Integration: Represent the testing layer (the “tests” directory with TS tests) and package.json/tsconfig.json that facilitate integration testing. This indicates how off-chain tests validate contract functionality.

- Raydium/Meteora Integration: Indicate the CPI (Cross Program Invocation) calls for managing Raydium pools and migration to Meteora.
- On-chain Markets and Token Management: Illustrate external interactions with the OpenBook market and token authority management.

##### Architectural Patterns and Design Principles
- Modularity by displaying each instruction module (i.e., separate functions like “initialize”, “buy”, “sell”, “create_pool”) as distinct yet interconnected parts of the contract.
- Use of configuration and migration management through anchor and scripts.

##### Specific Technologies
- Specify that the smart contract is written in Rust and uses Anchor (as seen by the Anchor.toml file).
- The use of Cargo for Rust dependency management and build scripts should also be noted.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Deployment & Configuration Section
    subgraph "Deployment & Configuration" 
        D1["Anchor.toml"]:::offChain
        D2["Cargo.toml (root)"]:::offChain
        D3["bonding_curve Cargo.toml"]:::offChain
        D4["deploy script"]:::offChain
    end

    %% Smart Contract Program Section (On-Chain)
    subgraph "Smart Contract Program (bonding_curve)" 
        SC["Smart Contract Program (bonding_curve)"]:::onChain

        subgraph "Instructions Modules"
            I1["Initialize Instruction"]:::onChain
            I2["Create Pool Instruction"]:::onChain
            I3["Buy Instruction"]:::onChain
            I4["Sell Instruction"]:::onChain
        end

        S["State Management"]:::onChain
        E["Error Handling"]:::onChain
        U["Utility Functions"]:::onChain
    end

    %% Testing & Integration Section
    subgraph "Testing & Integration" 
        T1["TypeScript Tests"]:::offChain
        T2["tsconfig.json"]:::offChain
        T3["package.json"]:::offChain
    end

    %% External Integrations Section
    subgraph "External Integrations" 
        X1["Raydium/Meteora Integration"]:::integration
        X2["Discord Integration"]:::integration
        X3["On-chain Markets & Token Management"]:::integration
    end

    %% Arrows from Deployment to Smart Contract
    D1 -->|"deploy"| SC
    D2 -->|"deploy"| SC
    D3 -->|"deploy"| SC
    D4 -->|"deploy"| SC

    %% Arrows from Testing to Smart Contract
    T1 -->|"validate"| SC
    T2 -->|"validate"| SC
    T3 -->|"validate"| SC

    %% Arrows from Smart Contract to External Integrations
    SC -->|"CPI/notify"| X1
    SC -->|"CPI/notify"| X2
    SC -->|"CPI/notify"| X3

    %% Internal arrows within Smart Contract
    I1 -->|"triggers"| S
    I1 -->|"checks"| E
    I1 -->|"utilizes"| U

    I2 -->|"triggers"| S
    I2 -->|"checks"| E
    I2 -->|"utilizes"| U

    I3 -->|"triggers"| S
    I3 -->|"checks"| E
    I3 -->|"utilizes"| U

    I4 -->|"triggers"| S
    I4 -->|"checks"| E
    I4 -->|"utilizes"| U

    %% Styles
    classDef onChain fill:#ffd1dc,stroke:#333,stroke-width:2px,color:#000;
    classDef offChain fill:#d0e7ff,stroke:#333,stroke-width:2px,color:#000;
    classDef integration fill:#d0f0c0,stroke:#333,stroke-width:2px,color:#000;

    %% Click Events for Smart Contract Program Components
    click SC "https://github.com/enlomy/pumpfun-solana-smart-contract/tree/main/programs/bonding_curve"
    click I1 "https://github.com/enlomy/pumpfun-solana-smart-contract/blob/main/programs/bonding_curve/src/instructions/initialize.rs"
    click I2 "https://github.com/enlomy/pumpfun-solana-smart-contract/blob/main/programs/bonding_curve/src/instructions/create_pool.rs"
    click I3 "https://github.com/enlomy/pumpfun-solana-smart-contract/blob/main/programs/bonding_curve/src/instructions/buy.rs"
    click I4 "https://github.com/enlomy/pumpfun-solana-smart-contract/blob/main/programs/bonding_curve/src/instructions/sell.rs"
    click S "https://github.com/enlomy/pumpfun-solana-smart-contract/blob/main/programs/bonding_curve/src/state.rs"
    click E "https://github.com/enlomy/pumpfun-solana-smart-contract/blob/main/programs/bonding_curve/src/errors.rs"
    click U "https://github.com/enlomy/pumpfun-solana-smart-contract/blob/main/programs/bonding_curve/src/utils/calc.rs"
    
    click D1 "https://github.com/enlomy/pumpfun-solana-smart-contract/blob/main/Anchor.toml"
    click D2 "https://github.com/enlomy/pumpfun-solana-smart-contract/blob/main/Cargo.toml"
    click D3 "https://github.com/enlomy/pumpfun-solana-smart-contract/blob/main/programs/bonding_curve/Cargo.toml"
    click D4 "https://github.com/enlomy/pumpfun-solana-smart-contract/blob/main/migrations/deploy.ts"
    
    click T1 "https://github.com/enlomy/pumpfun-solana-smart-contract/blob/main/tests/bonding-curve.ts"
    click T2 "https://github.com/enlomy/pumpfun-solana-smart-contract/blob/main/tsconfig.json"
    click T3 "https://github.com/enlomy/pumpfun-solana-smart-contract/blob/main/package.json"
```
