Carbon Framework

repository·main·Indexed 20 days ago

https://github.com/sevenlabs-hq/carbon

A modular Rust framework for building Solana indexers and data pipelines. Carbon enables the ingestion of Solana updates via various datasources—including Jito Shredstream gRPC, StreamMessageDatasource, and RPC-based methods—decoding them into typed Rust structures using program-specific decoders (such as those for Address Lookup Table, Associated Token Account, Heaven, and Meteora vault), and processing the data through custom logic or storage sinks.

Tokens
75.5K
Snippets
238
Records
288
Agent score
70%

What's inside Carbon

  1. Overview of the Carbon Address lookup table program Decoder

    main
    The carbon-address-lookup-table-decoder is a specialized decoder within the Carbon ecosystem designed to decode data from the Address Lookup Table (ALT) program. It allows developers to interpret the structured data associated with address lookup tables, which are used to optimize transaction sizes on Solana by referencing pre-defined lists of addresses.
  2. Use the Carbon Jito Shredstream gRPC Datasource

    main

    The Jito Shredstream gRPC Datasource provides real-time, low-latency access to shreds—fragments of Solana transaction data distributed by validators before they are assembled into full blocks.

    ⚠️ Critical Usage Warning

    Do not use Shredstream for indexing. Shreds are distributed as they are received by the leader and lack transaction status or metadata.

    Recommended alternatives for indexing:

    • block-subscribe datasource
    • block-crawling datasource
  3. Use @sevenlabs-hq/carbon-versions for Carbon Rust crate versions

    main
    The @sevenlabs-hq/carbon-versions package serves as a centralized version registry for all Carbon Rust crate versions. It provides constants that represent the specific versions of all Rust dependencies used throughout the Carbon code generation process. This ensures version consistency across the Carbon ecosystem and allows developers to reference exact dependency versions used in the core logic.
  4. Use StreamMessageDatasource to ingest real-time or batch data

    main

    The StreamMessageDatasource is a generic, extensible datasource for the Carbon indexing framework. It provides an abstract interface to feed a unified stream of account and transaction messages into Carbon, decoupling the framework from specific transport layers like Kafka, PubSub, or Solana Geyser plugins.

    It is designed to consume UnifiedMessage variants, which allow you to mix account updates and transaction updates in a single stream.

    pub enum UnifiedMessage {
        Account(AccountUpdate),
        Transaction(Box<TransactionUpdate>),
    }
  5. Swap datasource variants in Carbon examples

    main

    Some examples include interchangeable upstream sources defined in src/variants.rs. The processor and pipeline wiring remain identical across these variants. To swap the source, you must edit the single line in main.rs that constructs the datasource.

    CrateDefault SourceAlternatives
    yellowstone-grpcYellowstone Geyser gRPCHelius LaserStream gRPC (use replay_enabled for missed-slot replay); Jito Shredstream gRPC (pre-confirmation, no source-side filters)
    transaction-crawler-rpcRPC getSignaturesForAddressHelius GTFA (hosted, with built-in slot/time/status filters)
    gpa-rpcRPC getProgramAccountsHelius gPA v2 (paginated, changed_since_slot for incremental syncs)
  6. How Carbon's pipeline architecture works

    main

    Carbon is a Rust framework for building Solana indexers and data pipelines based on a modular three-part pipeline model:

    1. Datasources: Stream Solana updates (transactions, account updates, deletions, block metadata) into the runtime. You can swap between RPC streams, Geyser streams, or historical/snapshot sources.
    2. Decoders: Transform raw account and transaction data into typed Rust structures. You can use existing decoders for common programs or generate new ones from Anchor or Codama IDLs.
    3. Processors: Handle the decoded output. Processors are used to build real-time indexers, historical backfills, or sinks like Postgres, GraphQL, or analytics engines.

    This modularity allows you to combine different components (e.g., a Helius datasource with a custom decoder and a Postgres processor) to suit your latency and data requirements.

  7. How gPA RPC variants work

    main

    The gpa-rpc example provides two interchangeable datasource variants for fetching and decoding program account states via getProgramAccounts (gPA):

    1. variants::rpc(...): A standard implementation that performs plain getProgramAccounts against any Solana RPC. This is the default variant.
    2. variants::helius_gpa_v2(...): Uses Helius's enhanced gPA endpoint. This variant supports pagination and includes changed_since_slot for performing incremental synchronizations.

    You can switch between these variants by modifying the datasource initialization in main.rs.

    // To use the standard RPC variant
    let datasource = variants::rpc(MARGINFI_PROGRAM_ID);
    
    // To use the Helius enhanced variant
    let datasource = variants::helius_gpa_v2(MARGINFI_PROGRAM_ID);
  8. Limitations of RPC-based GPA

    main
    Using getProgramAccounts via RPC is suitable for small to medium-sized programs. However, for programs with millions of accounts (such as SPL Token), RPC-based GPA is impractical due to rate limits and scale. For large-scale account state snapshots, use the snapshot-validator tool instead.
  9. Configure environment variables for Transaction Crawler RPC

    main

    Before running the example, create a .env file in examples/transaction-crawler-rpc/ and configure the variables based on the variant you intend to use.

    RPC Variant Variables

    • RPC_URL: The Solana RPC HTTP endpoint. Must support getSignaturesForAddress and getTransaction. It is recommended to use a dedicated provider rather than public mainnet to avoid rate limits.
    • UNTIL_SIGNATURE (Optional): A specific signature used to bound the backfill. If not set, the crawler runs until interrupted.

    Helius GTFA Variant Variables

    • HELIUS_RPC_URL: Your Helius RPC URL with the API key embedded (e.g., https://mainnet.helius-rpc.com/?api-key=YOUR_KEY).

    General Variables

    • RUST_LOG: Set to info to see decoded instructions in the output.
    # RPC variant (default)
    RPC_URL=https://api.mainnet-beta.solana.com
    # Optional: stop the backfill once this signature is reached.
    # UNTIL_SIGNATURE=4xK9j8Cxi...c9Pq
    
    # Helius GTFA variant
    # HELIUS_RPC_URL=https://mainnet.helius-rpc.com/?api-key=YOUR_KEY
    
    RUST_LOG=info