> 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/drawing-flow.md). Agents can also search and read this documentation through its [MCP server](https://docs.tramplin.io/~gitbook/mcp).

# Complete Distribution Flow

This document describes the full lifecycle of a Tramplin distribution round, from snapshot to reward claim. The protocol runs a single distribution type, the **Epoch Distribution** (the `epoch_draw` round onchain), once per Solana epoch on the epoch program `EoB583odi1Nw7RUtd41m8PSm46aDLwPN5sN3fx1TUkRw`. Each round selects 7 recipients through a commit-reveal flow with ORAO VRF randomness, and every recipient is verified onchain against the epoch's snapshot.

The earlier Regular and Big Distributions have ended; see [How the Protocol Works](https://docs.tramplin.io/readme.md) for their history.

## Flow Overview

The Epoch Distribution selects 7 unique recipients. Because verifying 7 Merkle proofs in a single transaction would exceed Solana's compute unit limit, `reveal` only stores the KISS PRNG seed onchain. The dealer then calls `propose_winner` once per recipient.

```mermaid
sequenceDiagram
    participant MS as Team Multisig
    participant TR as Treasury
    participant SW as Stake Watcher
    participant SS as Snapshot Service
    participant MF as Moneyflow
    participant DL as Dealer
    participant SC as Epoch Program
    participant VRF as ORAO VRF
    participant R as Recipient

    Note over SW: New epoch begins
    SW->>SS: Stake account data
    SS->>SS: Build Merkle tree (effective stake)
    SS->>SC: make_snapshot(merkle_root, eligible_stake)
    SS-->>SS: Publish snapshot JSON to R2

    MS->>TR: Transfer validator rewards (once per epoch)
    MF->>TR: Detect reward deposit
    MF->>SC: create_pool + transfer 100% of the deposit to the epoch pool

    Note over DL: Wait for the start hour H
    DL->>DL: Generate secret
    DL->>SC: draw(secret_hash, seed)
    SC->>VRF: Request randomness(seed)

    Note over VRF: VRF fulfillment (~seconds)
    VRF->>SC: Deliver randomness

    DL->>SC: reveal(secret)
    SC->>SC: Verify commitments, store KISS seed

    Note over DL: Off-chain: replay KISS PRNG, find 7 recipients in Merkle tree

    loop 7 times (one per recipient)
        DL->>SC: propose_winner(winner_id, stake_id, stake, withdrawer, proof)
        SC->>SC: Replay KISS PRNG, verify Merkle proof, record recipient
    end

    Note over R: Recipient sees result onchain
    R->>SC: claim(recipient_id, merkle_proof)
    SC->>R: Transfer reward share (61.5% / 18.5% / 6.2% / 6.1% / 3.1% / 3.1% / 1.5%)
```

## Step-by-Step Breakdown

### Step 1: Snapshot

**When:** At the start of each epoch.

**What happens:**

1. **Stake Watcher** queries all active stake accounts delegated to the Tramplin validator using `getProgramAccounts` with filters:
   * `StakeStateV2::Stake` discriminator
   * Voter pubkey matches Tramplin's vote account
2. **Snapshot Service** processes the raw data:
   * Groups stakes by `withdrawer` address
   * Filters out excluded addresses and stakes below the minimum threshold
   * Calculates **Points** (accumulated loyalty + referral bonuses)
   * Computes each participant's weight as effective stake: `stake × min(1 + √(points/stake/K), 5.0)` divided by `lamports_per_share`
3. **Merkle tree construction:**
   * Nodes are sorted by withdrawer address
   * Each node gets a sequential `stake_id` (cumulative weight position)
   * Leaf hash: `keccak256(stake_id || stake || withdrawer)`
   * Tree uses a **leaf prefix** (`0x00`) to prevent second preimage attacks
   * Root and proofs are computed
4. **Publication:**
   * Full snapshot JSON uploaded to Cloudflare R2 at `https://snapshots.tramplin.io/{EPOCH}-epoch-TRAMp1Z9EXyWQQNwNjjoNvVksMUHKioVU7ky61yNsEq.json`
   * `make_snapshot` instruction called onchain, committing:
     * `merkle_root` (32 bytes)
     * `eligible_stake` (total weight across all participants)

### Step 2: Pool Funding

**When:** Once per epoch, after the validator rewards arrive in the treasury.

**What happens:**

1. The team's multisig signers transfer the rewards of the Tramplin validator (vote account `TRAMp1Z9EXyWQQNwNjjoNvVksMUHKioVU7ky61yNsEq`) to the distribution treasury `28YkbWtEqw9TpetsFrmtwa6Xb1WgKAkvaVt7gsgimASg`
2. **Moneyflow Service** detects the deposit to the treasury account via Geyser
3. Moneyflow moves **100%** of the deposit into the reward pool of the current epoch (the `epoch_pool` account of the epoch program):
   * Creates the pool token account onchain via `create_pool`
   * Transfers funds from the treasury to the pool using `transfer_with_seed`

The moment the epoch's pool is first funded (F) determines when the distribution starts (Step 3). A pool that is never funded has no distribution.

### Step 3: Commit Phase (`draw`)

**When:** Once per epoch, at the start hour **H**. The following rules have been in effect since epoch 1070 (28 October 2026); times are Cyprus time (Europe/Nicosia):

* H is the first round hour (HH:00) that is at least 60 minutes after F, not before the start of the epoch, inside the window 11:00-21:00 (both ends included), and at least 60 minutes before the epoch's distribution deadline (the end of the epoch).
* If no hour inside the window fits, the first round hour outside the window that meets the other conditions is used. If no round hour fits at all, the distribution starts immediately.
* **Settling:** if the pool balance changed less than 5 minutes before H, the start waits until the balance has been unchanged for 5 minutes (never later than 60 minutes before the deadline).
* **Safety rule:** if the distribution has not started when 9,000 slots or fewer remain before the deadline (about 32 minutes at the current slot time of about 213 ms), it starts immediately, whatever the window says.

**What happens:**

1. **Dealer** generates a random 32-byte **secret**
2. Computes:
   * `secret_hash = keccak256(secret)` - commitment to the secret
   * `seed = keccak256(merkle_root || secret)` - links the secret to the specific participant set
3. Calls `draw` instruction on the smart contract with:
   * `secret_hash` and `seed`
   * Draw type discriminator
   * Pool bump (PDA derivation)
4. The smart contract:
   * Verifies the caller is the authorized dealer
   * Checks rounds are enabled and the deadline hasn't passed
   * Verifies the pool has sufficient funds
   * Creates the epoch's `epoch_draw` account with stage = `Draw`
   * Closes the pool token account and transfers lamports to the Draw account
   * Calls ORAO VRF to request randomness with the given `seed`
5. All committed values (`secret_hash`, `seed`, `merkle_root`, `eligible_stake`) are now **publicly visible onchain** before randomness is known

### Step 4: VRF Fulfillment

**When:** Shortly after the commit phase (typically seconds).

**What happens:**

1. [ORAO Network](https://orao.network) fulfills the VRF request
2. The randomness (64 bytes) is written to a dedicated Solana account
3. The randomness is **deterministic** given the seed, but **unpredictable** before fulfillment
4. Since the seed depends on `merkle_root + secret`, and the secret was committed before the VRF request, neither the dealer nor the oracle can manipulate the outcome

### Step 5: Reveal and Recipient Selection

**When:** After VRF fulfillment, before the deadline.

**Commitment verification:**

1. **Dealer** calls `reveal` instruction with the original `secret`
2. The smart contract performs **commitment verification**:
   * `keccak256(secret) == secret_hash` ✓ (secret matches the commitment)
   * `keccak256(merkle_root || secret) == seed` ✓ (seed is correctly derived)
3. **Final randomness** is computed:

   ```
   for each byte i:
     final_randomness[i] = VRF_low[i] XOR VRF_high[i] XOR secret[i]
   ```

   This ensures the result depends on **both** the VRF output and the dealer's secret - neither party alone can determine the outcome.

**Recipient selection via `propose_winner`:**

`reveal` does **not** select recipients directly. Instead it:

1. Derives the KISS PRNG seed from the final randomness (`final_randomness[..16] XOR final_randomness[16..]`)
2. Stores the seed in the epoch's `epoch_draw` account
3. Updates the round stage to `Reveal`

The dealer then runs the KISS PRNG **off-chain** to identify the 7 recipients in the Merkle tree, and calls `propose_winner(winner_id, stake_id, stake, withdrawer, proof)` once per recipient. For each call, the smart contract:

* Replays KISS by calling `next_u64()` exactly `winners.len()` times to advance to the current recipient's slot
* Computes the next `winner_id` (with the same collision-and-retry logic the dealer used off-chain)
* Verifies that the supplied `winner_id` matches what KISS produces
* Verifies the Merkle proof against the stored `merkle_root`
* Records the verified recipient onchain, with the reward share that matches its order of selection (61.5% for the first, 18.5% for the second, and so on)

After all 7 `propose_winner` calls succeed, the round transitions to `Completed`.

### Step 6: Claim

**When:** After all 7 `propose_winner` calls (round stage `Completed`).

**What happens:**

1. A selected participant claims on [tramplin.io](https://tramplin.io) (connect wallet, **Claim**), which submits a `claim` transaction with:
   * `recipient_id` - their position in the selection list
   * `stake_id` - their cumulative stake position in the Merkle tree
   * `stake` - their stake/weight amount
   * `proof` - Merkle proof of inclusion
2. The smart contract:
   * Verifies the round is in the correct claimable stage
   * Checks the `recipient_id` exists in the selection list
   * Verifies the Merkle proof: `verify(proof, merkle_root, hash(LEAF_PREFIX || hash(stake_id || stake || withdrawer)))`
   * Confirms the signer is the `withdrawer` for this stake
   * Checks the reward hasn't already been claimed
3. If all checks pass:
   * Reward (in lamports/SOL) is transferred from the Draw account to the recipient
   * The amount equals the recipient's share of the epoch pool (61.5%, 18.5%, 6.2%, 6.1%, 3.1%, 3.1%, or 1.5%)
   * A `Claimed` account is created as a receipt; its rent (about 0.0015 SOL) is paid by the claimer
   * Metrics are updated

For now, epoch rewards are claimed on the website: the Tramplin mobile app does not support claiming them yet.

### Step 7: Withdraw (Rounds That Missed the Deadline)

**When:** After the `draw_deadline` of a round that was not completed in time.

**What happens:**

1. **Dealer** calls `withdraw` for the round
2. The smart contract verifies the deadline has passed and that the round was not completed
3. The round's lamports are transferred to a designated destination
4. Metrics are updated with the withdrawn amount
5. These funds can be re-delegated or recycled into future reward pools

## Timing and Deadlines

| Parameter       | Description                                                                                                                                                             |
| --------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| Epoch length    | 432,000 slots; about 25-26 hours at the current slot time (about 213 ms), which changes over time                                                                       |
| `draw_deadline` | Maximum slot for commit + reveal + the 7 `propose_winner` calls to complete; for the Epoch Distribution, the end of the epoch                                           |
| Start hour H    | First round hour (HH:00, Cyprus time) at least 60 minutes after the pool is first funded, inside 11:00-21:00 when possible, and at least 60 minutes before the deadline |
| Settling        | The start waits until the pool balance has been unchanged for 5 minutes                                                                                                 |
| Safety start    | If the distribution has not started 9,000 slots before the deadline (about 32 minutes), it starts immediately                                                           |

If the dealer misses the `draw_deadline`, the round is skipped for that period - funds remain in the pool and are not lost.
