> For the complete documentation index, see [llms.txt](https://docs.tramplin.io/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.tramplin.io/system-architecture.md). Agents can also search and read this documentation through its [MCP server](https://docs.tramplin.io/~gitbook/mcp).

# System Architecture

The Tramplin protocol consists of an **onchain smart contract** (the epoch program, a Solana program) and **five offchain services** that automate the distribution lifecycle. The smart contract holds the reward pools and enforces the rules - offchain services can only call contract instructions, they cannot bypass the onchain logic.

The protocol runs a single distribution type, the **Epoch Distribution**, once per Solana epoch. The earlier Regular and Big Distributions ran on a previous program, which still holds their claimable rewards (see [Programs](#programs)).

## Architecture Overview

```mermaid
graph TB
    subgraph Solana Blockchain
        SC[Epoch Program<br/>EoB583od...]
        ORAO[ORAO VRF Oracle]
        SA[Stake Accounts]
        TR[Distribution Treasury<br/>28YkbWtE...]
        LP[Earlier Main Program<br/>3NJyzGWj...<br/>claimable Regular/Big rewards]
    end

    MS[Team Multisig Signers]

    subgraph Off-chain Services
        SW[Stake Watcher]
        SS[Snapshot Service]
        MF[Moneyflow Service]
        DL[Dealer Service]
        IS[Info Service]
    end

    subgraph Public
        R2[Cloudflare R2<br/>snapshots.tramplin.io]
        FE[Frontend / API]
    end

    SA -->|reads stake data| SW
    SW -->|epoch events| SS
    SS -->|make_snapshot| SC
    SS -->|publishes JSON| R2
    MS -->|validator rewards, once per epoch| TR
    TR -->|deposit detected| MF
    MF -->|create_pool + transfer 100%| SC
    DL -->|draw + reveal + propose_winner| SC
    DL -->|VRF request| ORAO
    ORAO -->|randomness| SC
    SC -->|on-chain events| IS
    IS -->|serves data| FE
```

## Smart Contract (Distribution Program)

The onchain program is the heart of the protocol. Written in Rust using the [Pinocchio](https://github.com/febo/pinocchio) framework for maximum compute efficiency.

### Programs

| Program                  | Address                                        | Role                                                                                                    |
| ------------------------ | ---------------------------------------------- | ------------------------------------------------------------------------------------------------------- |
| **Epoch program**        | `EoB583odi1Nw7RUtd41m8PSm46aDLwPN5sN3fx1TUkRw` | Runs the Epoch Distribution and holds the epoch reward pools                                            |
| **Earlier main program** | `3NJyzGWjSHP4hZvsqakodi7jAtbufwd52vn1ek6EzQ35` | Ran the Regular and Big Distributions (both ended in October 2026); still holds their claimable rewards |

Related accounts:

| Account                    | Address                                        | Purpose                                                                        |
| -------------------------- | ---------------------------------------------- | ------------------------------------------------------------------------------ |
| **Validator vote account** | `TRAMp1Z9EXyWQQNwNjjoNvVksMUHKioVU7ky61yNsEq`  | The Tramplin validator; its rewards fund the distribution                      |
| **Distribution treasury**  | `28YkbWtEqw9TpetsFrmtwa6Xb1WgKAkvaVt7gsgimASg` | Receives the validator rewards once per epoch from the team's multisig signers |

The account and instruction tables below describe the epoch program.

### Onchain Accounts

| Account          | Address Derivation                            | Purpose                                                                                                  |
| ---------------- | --------------------------------------------- | -------------------------------------------------------------------------------------------------------- |
| **Config**       | `PDA(["config"])`                             | Protocol configuration: admin, operator, dealer keys, deadlines, intervals                               |
| **Participants** | `PDA(["participants"])`                       | Merkle root and eligible stake of the current epoch snapshot                                             |
| **Draw**         | `PDA(["epoch_draw", epoch])`                  | Round state: reward fund, the 7 recipients, VRF seed, stage                                              |
| **Pool**         | `PDA(["epoch_pool", epoch])`                  | Token account holding the reward pool of a specific epoch                                                |
| **Metrics**      | `PDA(["metrics"])`                            | Cumulative stats: total distributed, claimed, withdrawn                                                  |
| **Claimed**      | `PDA(["claimed", kind, epoch, recipient_id])` | Receipt proving a recipient has claimed their reward; its rent (about 0.0015 SOL) is paid by the claimer |

### Instructions

| Instruction      | Caller    | Description                                                                               |
| ---------------- | --------- | ----------------------------------------------------------------------------------------- |
| `initialize`     | deployer  | Creates Config, Participants, and Metrics accounts                                        |
| `update_config`  | admin     | Updates protocol parameters                                                               |
| `set_status`     | admin     | Enables/disables distribution rounds                                                      |
| `make_snapshot`  | operator  | Publishes new Merkle root and eligible stake                                              |
| `create_pool`    | anyone    | Creates the reward pool for a specific epoch                                              |
| `draw`           | dealer    | Commits secret\_hash and seed, requests VRF                                               |
| `reveal`         | dealer    | Verifies the commitment, combines the VRF output with the secret and stores the KISS seed |
| `propose_winner` | dealer    | Replays KISS PRNG, verifies one Merkle proof, records one of the 7 recipients             |
| `claim`          | recipient | Claims reward with Merkle proof and creates the `Claimed` receipt                         |
| `withdraw`       | dealer    | Recovers the funds of a round that was not completed before its `draw_deadline`           |

### Role Separation

The contract enforces strict role separation:

* **Admin** - can change protocol parameters and enable/disable rounds
* **Operator** - can publish snapshots (Merkle roots). Cannot initiate rounds or claim.
* **Dealer** - can conduct distribution rounds (draw/reveal/propose\_winner) and withdraw the funds of rounds that missed their deadline. Cannot change config or snapshots.

No single key can perform all operations. This separation ensures that even if one key is compromised, the attacker cannot fully manipulate the protocol.

## Off-chain Services

### Stake Watcher

**Purpose:** Monitors the Solana validator's stake accounts.

* Subscribes to epoch changes via Geyser (Solana's real-time data streaming)
* Takes a raw snapshot of all active stake accounts using `getProgramAccounts`
* Filters by activation epoch and minimum stake threshold
* Groups stakes by `withdrawer` address (one entry per delegator)

### Snapshot Service

**Purpose:** Builds Merkle trees and publishes verifiable snapshots.

* Receives stake data from Stake Watcher
* Calculates **Points** (loyalty + referral bonuses) and **effective stakes**
* Computes each participant's selection weight: linear, based on effective stake (`effective_stake / lamports_per_share`)
* Builds Merkle trees where each leaf is `hash(stake_id, stake, withdrawer)`
* Publishes the full snapshot JSON to **Cloudflare R2** at `https://snapshots.tramplin.io/{EPOCH}-epoch-TRAMp1Z9EXyWQQNwNjjoNvVksMUHKioVU7ky61yNsEq.json`
* Calls `make_snapshot` on the smart contract to commit the Merkle root onchain, once at the start of each epoch

**Snapshot format (published JSON):**

```json
{
  "config": { "vote_account": "...", "lamports_per_share": 1000000000 },
  "context": { "epoch": 883, "slot": 388625456 },
  "stakes": { "wallet_address": 5000000000, ... },
  "shares": { "wallet_address": 5, ... },
  "merkle_tree": {
    "merkle_root": "...",
    "tree_nodes": [
      { "stake_id": 0, "stake": 5000000000, "withdrawer": "...", "proof": ["..."] }
    ]
  }
}
```

Anyone can download a snapshot from `snapshots.tramplin.io` and independently verify:

* Their inclusion in the participant set
* The correctness of the Merkle root
* That the Merkle root matches what was published onchain

### Moneyflow Service (Reward Distributor)

**Purpose:** Moves validator rewards into the epoch reward pool.

* Monitors the treasury account (`28YkbWtEqw9TpetsFrmtwa6Xb1WgKAkvaVt7gsgimASg`) via Geyser for incoming deposits; the validator rewards are transferred there once per epoch by the team's multisig signers
* Moves **100%** of each deposit into the reward pool of the current epoch
* Creates the pool token account onchain (`create_pool`)
* Tracks transaction confirmations and retries failed sends

### Dealer Service

**Purpose:** Conducts the distribution rounds - the most critical off-chain component.

* Starts each epoch's round at the start hour derived from the moment the epoch's pool was first funded: the first round hour (Cyprus time) at least 60 minutes after funding, inside 11:00-21:00 when possible, and at least 60 minutes before the end of the epoch, with a forced start when 9,000 slots or fewer remain (full rules in [Complete Distribution Flow](https://docs.tramplin.io/drawing-flow.md))
* For each round:
  1. Generates a cryptographic **secret**
  2. Computes `secret_hash = keccak256(secret)` and `seed = keccak256(merkle_root || secret)`
  3. Calls `draw(secret_hash, seed)` - committing to the secret before randomness is known
  4. Waits for **ORAO VRF** to fulfill the randomness request
  5. Calls `reveal(secret)` - the contract verifies the commitment, combines VRF with the secret, and stores the KISS seed
  6. Calls `propose_winner` once per recipient (7 calls total) to select 7 unique recipients weighted by effective stake; the contract verifies each one against the snapshot's Merkle root. The multi-step pattern works around Solana compute unit limits.
* Monitors for config updates via Geyser

### Info Service

**Purpose:** Provides an API layer for the frontend.

* Subscribes to all contract transactions via Geyser
* Stores transaction history for state-changing operations
* Serves data via a web API for the user-facing application
