> ## Documentation Index
> Fetch the complete documentation index at: https://mintlify.com/Ge0frey/nullgraph/llms.txt
> Use this file to discover all available pages before exploring further.

# Program Overview

> Architecture and structure of the NullGraph Solana program

The NullGraph smart contract is a Solana program built with Anchor 0.31.1 that manages the on-chain infrastructure for Null Knowledge Assets (NKAs) and the bounty marketplace.

## Program ID

```rust theme={null}
2u3DXQq9A6UgMryeVSWCNdYLy3Fjh391R5hcfWYkCgZK
```

Declared in `lib.rs:8`:

```rust theme={null}
declare_id!("2u3DXQq9A6UgMryeVSWCNdYLy3Fjh391R5hcfWYkCgZK");
```

## Technology Stack

<ParamField path="Framework" type="Anchor 0.31.1">
  Solana program development framework providing type-safe account validation, PDA derivation, and CPI abstractions
</ParamField>

<ParamField path="Language" type="Rust 2021">
  Systems programming language ensuring memory safety and zero-cost abstractions
</ParamField>

<ParamField path="SPL Token" type="anchor-spl 0.31.1">
  Token interface for USDC transfers via CPI using `transfer_checked` for decimal validation
</ParamField>

## Architecture

The program implements a decentralized bounty marketplace for null scientific results using four core account types:

<Expandable title="ProtocolState (Singleton)">
  Global configuration storing auto-incrementing counters for NKAs and bounties, protocol fee rate, treasury address, and authority. Seeds: `["protocol_state"]`
</Expandable>

<Expandable title="NullResult (Per NKA)">
  Stores complete scientific metadata for each submitted null result including hypothesis, methodology, outcomes, statistical data, and verification status. Seeds: `["null_result", researcher_pubkey, specimen_number_le_bytes]`
</Expandable>

<Expandable title="NullBounty (Per Bounty)">
  Bounty metadata with escrowed USDC in a PDA-controlled vault. Tracks status (Open/Matched/Fulfilled/Closed) and matched submissions. Seeds: `["null_bounty", creator_pubkey, bounty_number_le_bytes]`
</Expandable>

<Expandable title="BountySubmission (Links NKA to Bounty)">
  Junction account linking a researcher's NullResult to a specific bounty. Seeds: `["bounty_submission", bounty_pda_key, null_result_pda_key]`
</Expandable>

## Program Flow

```mermaid theme={null}
graph TD
    A[initialize_protocol] --> B[ProtocolState Created]
    B --> C[submit_null_result]
    C --> D[NullResult PDA]
    B --> E[create_bounty]
    E --> F[NullBounty + Vault]
    F --> G[USDC Escrowed]
    D --> H[submit_to_bounty]
    F --> H
    H --> I[BountySubmission PDA]
    I --> J[approve_bounty_submission]
    J --> K[USDC Payout - Fee]
    J --> L[Treasury Fee]
    I --> M[close_bounty]
    M --> N[USDC Refund]
```

## Security Model

All program operations are protected by Anchor's account validation framework:

* **Signer enforcement**: Every mutation requires the appropriate authority (researcher, bounty creator, or protocol authority)
* **PDA ownership**: All data accounts are program-owned PDAs preventing external modification
* **Status guards**: Instructions validate current account status before state transitions
* **Replay protection**: PDA init constraints prevent duplicate accounts
* **Vault authority**: Token vaults use the vault PDA itself as authority, only accessible via CPI with correct signer seeds
* **Safe arithmetic**: All fee calculations use checked math operations (`checked_mul`, `checked_div`, `checked_sub`)
* **Transfer validation**: `transfer_checked` validates mint address and decimal precision on every USDC transfer

## File Structure

The entire program is contained in a single file:

```
programs/nullgraph/src/lib.rs  (~593 lines)
├── Program Module (lines 14-274)
│   ├── initialize_protocol
│   ├── submit_null_result
│   ├── create_bounty
│   ├── submit_to_bounty
│   ├── approve_bounty_submission
│   └── close_bounty
├── Account Contexts (lines 280-466)
│   ├── InitializeProtocol
│   ├── SubmitNullResult
│   ├── CreateBounty
│   ├── SubmitToBounty
│   ├── ApproveBountySubmission
│   └── CloseBounty
├── Data Accounts (lines 472-526)
│   ├── ProtocolState
│   ├── NullResult
│   ├── NullBounty
│   └── BountySubmission
├── Events (lines 532-573)
│   └── 6 event structs
└── Errors (lines 579-593)
    └── NullGraphError enum
```

## Next Steps

<CardGroup cols={2}>
  <Card title="Accounts" icon="database" href="/program/accounts">
    Explore all account structures and their fields
  </Card>

  <Card title="Instructions" icon="code" href="/program/instructions">
    Learn about all 6 program instructions
  </Card>

  <Card title="Events" icon="bell" href="/program/events">
    Review emitted events for indexing
  </Card>

  <Card title="Errors" icon="triangle-exclamation" href="/program/errors">
    Reference all custom error codes
  </Card>
</CardGroup>
