# rckprtr/pumpdotfun-sdk architecture

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

- Interactive diagram: https://gitdiagram.com/rckprtr/pumpdotfun-sdk
- Repository: https://github.com/rckprtr/pumpdotfun-sdk

## Overview

##### Project Type and Purpose
- This is an open-source, TypeScript-based SDK (“PumpDotFunSDK”) for interacting with the Pump.fun decentralized application on the Solana blockchain.
- It is not a full-stack web app; rather it is a client library that developers install via npm to build scripts or integrations that create, buy, sell tokens and subscribe to on-chain events.

##### Top-Level File Structure Insights
- `src/`
- IDL folder and JSON/TS definitions (`src/IDL`) for the PumpFun Anchor program interface.
- Core modules: `pumpfun.ts` (SDK class), `amm.ts` (automated market maker logic), `bondingCurveAccount.ts`, `globalAccount.ts`, `events.ts`, `util.ts`, `types.ts`.
- `example/`
- Usage samples: basic token lifecycle (`example/basic`) and event subscription (`example/events`).
- `__tests__/`
- Unit/browser/test harness showing CJS/ESM compatibility and runtime behavior.
- Build & config files: `package.json`, `rollup.config.js`, `tsconfig*.json`, `.env.example`.

##### Key Components
a. Developer Application Layer
– Example scripts or any consumer code that calls PumpDotFunSDK methods.
b. PumpDotFunSDK Library
– SDK Class (`PumpFunSDK`) orchestrating:
- Transaction builders for createAndBuy, buy, sell
- Event subscription API (`addEventListener`/`removeEventListener`)
- Internal modules (AMM, bonding curve, global account logic)
- Utilities (type conversions, keypair management)
- IDL ingestion for instruction serialization
c. Wallet & Provider Layer
– `AnchorProvider` + `NodeWallet` wrapping a Solana `Connection`
– Environment variables (`.env`, `HELIUS_RPC_URL`) configure the RPC endpoint
d. Solana Network & Program
– JSON-RPC / WebSocket endpoint (Helius or any Solana RPC)
– On-chain Pump.fun Anchor program (handles accounts: globalAccount, bonding curve accounts, token minting)
– SPL Token Program (for minting, transfers)
e. Build & Test Pipeline (auxiliary)
– Rollup bundler outputs ESM/CJS artifacts
– Unit tests run in Node and browser contexts

##### Component Interactions and Data Flow
- The Developer App imports `PumpFunSDK` → instantiates with an `AnchorProvider`.
- SDK uses IDL definitions to construct Anchor instructions (create token, buy, sell).
- Transactions flow: SDK → Provider → RPC endpoint → Solana cluster → Pump.fun program → updates on-chain accounts (globalAccount, bondingCurveAccount, SPL mint, user token accounts).
- Event flow: SDK subscribes via WebSocket RPC or polling → captures on-chain events (createEvent, tradeEvent, completeEvent) → SDK invokes callbacks in Developer App.
- Utility flows: SDK’s `util.ts` and example `util.ts` handle keypair storage, balance queries, and printing.

##### Architectural Patterns and Principles
- Layered modularization: separation between protocol definitions (IDL), core business logic (amm, bonding curve), SDK surface API, and transport layer (AnchorProvider).
- Adapter pattern: AnchorProvider and NodeWallet adapt the raw Solana connection to a familiar interface.
- Event listener registry: decouples SDK internals from application callbacks.
- Build‐time bundling: rollup to target both CommonJS and ESM consumers.
- Configuration isolation: environment variables for RPC, keys stored externally.

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% Developer Application Layer
    subgraph "Developer Application"
        BA["Basic Example"]:::developer
        EV["Event Example"]:::developer
        EU["Example Util"]:::developer
    end

    %% SDK Library
    subgraph "PumpDotFunSDK (Library)"
        entry["index.ts"]:::sdk
        sdkclass["PumpFunSDK"]:::sdk
        subgraph "Core Modules"
            amm["AMM Module"]:::sdk
            bond["BondingCurveAccount"]:::sdk
            glob["GlobalAccount"]:::sdk
            evmod["Events Module"]:::sdk
            util["Util Functions"]:::sdk
            types["Type Definitions"]:::sdk
        end
        subgraph "IDL Schemas"
            idlindex["IDL index.ts"]:::sdk
            idljson["pump-fun.json"]:::sdk
            idlts["pump-fun.ts"]:::sdk
        end
    end

    %% Wallet & Provider
    subgraph "Wallet & Provider"
        env[".env (HELIUS_RPC_URL)"]:::provider
        provider["AnchorProvider / NodeWallet"]:::provider
    end

    %% External Services
    solanaRpc["Solana RPC (Helius)"]:::external
    subgraph "On-chain Programs"
        pumpProg["Pump.fun Anchor Program"]:::external
        spl["SPL Token Program"]:::external
    end

    %% Build & Test Pipeline
    subgraph "Build & Test Pipeline"
        rollup["rollup.config.js"]:::pipeline
        tsconfig["tsconfig*.json"]:::pipeline
        tests["__tests__"]:::pipeline
        pkg["package.json"]:::pipeline
    end

    %% Connections
    BA --> entry
    EV --> entry
    EU --> entry
    tests --> entry

    entry --> sdkclass
    sdkclass --> amm
    sdkclass --> bond
    sdkclass --> glob
    sdkclass --> evmod
    sdkclass --> util
    sdkclass --> types
    sdkclass --> idlindex
    idlindex --> idljson
    idlindex --> idlts

    sdkclass --> provider
    provider --> env
    provider --> solanaRpc
    solanaRpc --> pumpProg
    solanaRpc --> spl
    solanaRpc --> evmod
    pumpProg -->|"events"| evmod

    rollup --> entry
    tsconfig --> entry
    pkg --> entry
    tests --> rollup
    tests --> tsconfig
    tests --> pkg

    %% Click Events
    click BA "https://github.com/rckprtr/pumpdotfun-sdk/blob/main/example/basic/index.ts"
    click EV "https://github.com/rckprtr/pumpdotfun-sdk/blob/main/example/events/index.ts"
    click EU "https://github.com/rckprtr/pumpdotfun-sdk/blob/main/example/util.ts"
    click entry "https://github.com/rckprtr/pumpdotfun-sdk/blob/main/src/index.ts"
    click sdkclass "https://github.com/rckprtr/pumpdotfun-sdk/blob/main/src/pumpfun.ts"
    click amm "https://github.com/rckprtr/pumpdotfun-sdk/blob/main/src/amm.ts"
    click bond "https://github.com/rckprtr/pumpdotfun-sdk/blob/main/src/bondingCurveAccount.ts"
    click glob "https://github.com/rckprtr/pumpdotfun-sdk/blob/main/src/globalAccount.ts"
    click evmod "https://github.com/rckprtr/pumpdotfun-sdk/blob/main/src/events.ts"
    click util "https://github.com/rckprtr/pumpdotfun-sdk/blob/main/src/util.ts"
    click types "https://github.com/rckprtr/pumpdotfun-sdk/blob/main/src/types.ts"
    click idlindex "https://github.com/rckprtr/pumpdotfun-sdk/blob/main/src/IDL/index.ts"
    click idljson "https://github.com/rckprtr/pumpdotfun-sdk/blob/main/src/IDL/pump-fun.json"
    click idlts "https://github.com/rckprtr/pumpdotfun-sdk/blob/main/src/IDL/pump-fun.ts"
    click env "https://github.com/rckprtr/pumpdotfun-sdk/blob/main/.env.example"
    click rollup "https://github.com/rckprtr/pumpdotfun-sdk/blob/main/rollup.config.js"
    click tsconfig "https://github.com/rckprtr/pumpdotfun-sdk/blob/main/tsconfig.json"
    click tests "https://github.com/rckprtr/pumpdotfun-sdk/tree/main/__tests__"
    click pkg "https://github.com/rckprtr/pumpdotfun-sdk/blob/main/package.json"

    %% Styles
    classDef developer fill:#E3F2FD,stroke:#90CAF9,color:#0D47A1
    classDef sdk fill:#E8F5E9,stroke:#A5D6A7,color:#1B5E20
    classDef provider fill:#FFF3E0,stroke:#FFB74D,color:#E65100
    classDef external fill:#FFEBEE,stroke:#EF9A9A,color:#B71C1C
    classDef pipeline fill:#EDE7F6,stroke:#B39DDB,color:#4A148C
```
