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

# Architecture

Velora is a single Anchor program (`backend`) with no off-chain components in the trust path. All vesting logic, fund custody, and authority checks happen on-chain. The frontend ("Velora") and any integrator client are untrusted — they only build and submit transactions.

## Accounts at a glance

| Account                   | Type                    | Purpose                                                                     |
| ------------------------- | ----------------------- | --------------------------------------------------------------------------- |
| `StreamConfig`            | program PDA             | Stores the full stream definition and progress (`amount_claimed`, `status`) |
| `vault`                   | SPL token account (PDA) | Holds the locked tokens; owned/signed by the program                        |
| `creator_token_account`   | SPL token account       | Source of funds at creation; refund destination on cancel                   |
| `recipient_token_account` | SPL token account       | Destination for withdrawn / vested tokens                                   |

## PDA derivation

Both PDAs are deterministic, so any client can recompute them without an index.

**StreamConfig**

```
seeds = ["stream", creator, recipient, stream_id (u64, little-endian)]
```

The `stream_id` lets one creator/recipient pair have many independent streams.

**Vault**

```
seeds = ["vault", stream_config]
```

The vault is a token account whose authority is itself (the PDA), so only the program — signing with the vault seeds — can move tokens out. See [ADR-001](https://velora-1.gitbook.io/docs/architecture-decisions/001-vault-per-stream.md) for why each stream gets its own vault.

## Token flow

```mermaid
flowchart LR
    CTA["creator_token_account"]
    VAULT(["vault (PDA)"])
    RTA["recipient_token_account"]

    CTA -- "create_stream: total_amount" --> VAULT
    VAULT -- "withdraw: claimable" --> RTA
    VAULT -- "cancel: unlocked − claimed" --> RTA
    VAULT -- "cancel: locked remainder" --> CTA
```

On `create_stream` the creator signs a normal SPL transfer into the vault. On `withdraw` and `cancel`, the program signs transfers *out* of the vault using the vault PDA seeds (`CpiContext::new_with_signer`).

## Vesting math

`compute_unlocked(stream_config, now)` returns how many tokens have unlocked at time `now`, independent of how many have already been claimed. Each instruction then computes `claimable = unlocked - amount_claimed`.

* **Linear:** `total * (now - start) / (end - start)`, clamped to `[0, total]`.
* **Cliff:** `0` before `cliff_timestamp`, `total` at and after it.
* **CliffLinear:** `0` before the cliff; at/after the cliff, `cliff_amount` plus a linear release of `total - cliff_amount` from `cliff_timestamp` to `end`.
* **Milestone:** `0` until `milestone_released` is set, then `total`.

The linear calculation casts to `u128` before multiplying to avoid overflow on large balances — see [ADR-003](https://velora-1.gitbook.io/docs/architecture-decisions/003-onchain-schedule-math.md).

## Authority model

Two independent authority dimensions:

* **Release authority** (`authority_type`: `None` / `SingleKey` / `MultiSig`) — who may call `release_milestone`. `MultiSig` is currently simplified to creator-only (see [Known limitations](#known-limitations)).
* **Cancel authority** (`cancel_authority`: `CreatorOnly` / `Either` / `Neither`) combined with the `is_cancellable` flag — who, if anyone, may call `cancel`.

## Known limitations

* **MultiSig release is not fully implemented.** `AuthorityType::MultiSig` currently authorizes the creator only; a real multi-sig would need a separate approval account. Documented inline in the program.
* **No per-withdrawal receipts.** A `ClaimReceipt` PDA (per-withdrawal audit record) is planned for Phase 3 and noted in the source; today, withdrawal history must be reconstructed from transaction logs.
* **Not audited.** Devnet-only. Do not use with mainnet funds.

## Forward compatibility

`StreamConfig` carries a `reserved: [u8; 30]` padding field and a fixed `milestone_description: [u8; 128]`, so new fields can be added in Phase 3 without a migration that resizes existing accounts.


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://velora-1.gitbook.io/docs/architecture.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
