# metatheory-dev/presale-smartcontracts architecture

> Architecture diagram of the GitHub repository metatheory-dev/presale-smartcontracts, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-11-11). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/metatheory-dev/presale-smartcontracts
- Repository: https://github.com/metatheory-dev/presale-smartcontracts

## Overview

This Anchor program manages an SPL-token presale: an administrator configures and funds a sale, buyers purchase during its configured window, and users or the administrator claim or withdraw assets. The tree contains two parallel Rust source trees; the graph shows the `programs/palm-presale` implementation, with the root `palm-presale` tree as its duplicate. README-described allocation tickets are not represented as a separate stage because the sampled code does not establish their implementation. Edges are limited to documented dispatches and source-index or excerpt evidence.

Main entry points: [`programs/palm-presale/src/lib.rs`](https://github.com/metatheory-dev/presale-smartcontracts/blob/master/programs/palm-presale/src/lib.rs) (Anchor program), [`programs/palm-presale/src/state/presale_info.rs`](https://github.com/metatheory-dev/presale-smartcontracts/blob/master/programs/palm-presale/src/state/presale_info.rs) (Sale account), [`programs/palm-presale/src/instructions/buy_token.rs`](https://github.com/metatheory-dev/presale-smartcontracts/blob/master/programs/palm-presale/src/instructions/buy_token.rs) (Buy tokens), [`programs/palm-presale/src/instructions/deposit_token.rs`](https://github.com/metatheory-dev/presale-smartcontracts/blob/master/programs/palm-presale/src/instructions/deposit_token.rs) (Fund inventory)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_entry["Program entry"]
  node_program["Anchor program<br/>[lib.rs]"]
  node_rootcopy["Mirrored Rust implementation"]
end

subgraph group_sale["Sale management"]
  node_create["Create presale<br/>[create_presale.rs]"]
  node_update["Update presale<br/>[update_presale.rs]"]
  node_start["Start presale<br/>[start_presale.rs]"]
  node_deposit["Fund inventory<br/>[deposit_token.rs]"]
end

subgraph group_purchase["Purchasing"]
  node_buy["Buy tokens<br/>[buy_token.rs]"]
end

subgraph group_settlement["Settlement"]
  node_claim["Claim tokens<br/>[claim_token.rs]"]
  node_withdrawsol["Withdraw SOL<br/>[withdraw_sol.rs]"]
  node_withdrawtoken["Withdraw tokens<br/>[withdraw_token.rs]"]
end

subgraph group_state["On-chain state"]
  node_presale[("Sale account<br/>[presale_info.rs]")]
  node_user[("Buyer account<br/>[user_info.rs]")]
end

node_admin(("Administrator"))
node_buyer(("Buyer"))
node_spl{{"Solana token and system programs"}}
node_vault[("Presale vault")]

node_admin -->|"invokes"| node_program
node_buyer -->|"invokes"| node_program
node_program -->|"dispatches"| node_create
node_program -->|"dispatches"| node_update
node_program -->|"dispatches"| node_start
node_program -->|"dispatches"| node_deposit
node_program -->|"dispatches"| node_buy
node_program -->|"dispatches"| node_claim
node_program -->|"dispatches"| node_withdrawsol
node_program -->|"dispatches"| node_withdrawtoken
node_create -->|"initializes"| node_presale
node_update -->|"updates"| node_presale
node_start -->|"updates"| node_presale
node_deposit -->|"updates inventory"| node_presale
node_deposit -->|"transfers tokens"| node_spl
node_deposit -->|"funds rent"| node_vault
node_buy -->|"checks and updates"| node_presale
node_buy -->|"records purchase"| node_user
node_buy -->|"transfers SOL"| node_vault
node_buy -->|"calls system transfer"| node_spl
node_claim -->|"reads sale state"| node_presale
node_claim -->|"reads buyer state"| node_user
node_claim -->|"transfers tokens"| node_spl
node_withdrawsol -->|"reads sale state"| node_presale
node_withdrawsol -->|"withdraws SOL"| node_vault
node_withdrawsol -->|"calls system transfer"| node_spl
node_withdrawtoken -->|"reads sale state"| node_presale
node_withdrawtoken -->|"transfers tokens"| node_spl

click node_program "https://github.com/metatheory-dev/presale-smartcontracts/blob/master/programs/palm-presale/src/lib.rs"
click node_create "https://github.com/metatheory-dev/presale-smartcontracts/blob/master/programs/palm-presale/src/instructions/create_presale.rs"
click node_update "https://github.com/metatheory-dev/presale-smartcontracts/blob/master/programs/palm-presale/src/instructions/update_presale.rs"
click node_start "https://github.com/metatheory-dev/presale-smartcontracts/blob/master/programs/palm-presale/src/instructions/start_presale.rs"
click node_deposit "https://github.com/metatheory-dev/presale-smartcontracts/blob/master/programs/palm-presale/src/instructions/deposit_token.rs"
click node_buy "https://github.com/metatheory-dev/presale-smartcontracts/blob/master/programs/palm-presale/src/instructions/buy_token.rs"
click node_claim "https://github.com/metatheory-dev/presale-smartcontracts/blob/master/programs/palm-presale/src/instructions/claim_token.rs"
click node_withdrawsol "https://github.com/metatheory-dev/presale-smartcontracts/blob/master/programs/palm-presale/src/instructions/withdraw_sol.rs"
click node_withdrawtoken "https://github.com/metatheory-dev/presale-smartcontracts/blob/master/programs/palm-presale/src/instructions/withdraw_token.rs"
click node_presale "https://github.com/metatheory-dev/presale-smartcontracts/blob/master/programs/palm-presale/src/state/presale_info.rs"
click node_user "https://github.com/metatheory-dev/presale-smartcontracts/blob/master/programs/palm-presale/src/state/user_info.rs"
click node_rootcopy "https://github.com/metatheory-dev/presale-smartcontracts/tree/master/palm-presale/src"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_program,node_rootcopy toneBlue
class node_create,node_update,node_start,node_deposit,node_vault toneAmber
class node_buy toneMint
class node_claim,node_withdrawsol,node_withdrawtoken toneRose
class node_presale,node_user,node_admin,node_buyer,node_spl toneIndigo
```

## Components

### Program entry

- [Anchor program](https://github.com/metatheory-dev/presale-smartcontracts/blob/master/programs/palm-presale/src/lib.rs): `programs/palm-presale/src/lib.rs`
- [Mirrored Rust implementation](https://github.com/metatheory-dev/presale-smartcontracts/tree/master/palm-presale/src): `palm-presale/src`

### Sale management

- [Create presale](https://github.com/metatheory-dev/presale-smartcontracts/blob/master/programs/palm-presale/src/instructions/create_presale.rs): `programs/palm-presale/src/instructions/create_presale.rs`
- [Update presale](https://github.com/metatheory-dev/presale-smartcontracts/blob/master/programs/palm-presale/src/instructions/update_presale.rs): `programs/palm-presale/src/instructions/update_presale.rs`
- [Start presale](https://github.com/metatheory-dev/presale-smartcontracts/blob/master/programs/palm-presale/src/instructions/start_presale.rs): `programs/palm-presale/src/instructions/start_presale.rs`
- [Fund inventory](https://github.com/metatheory-dev/presale-smartcontracts/blob/master/programs/palm-presale/src/instructions/deposit_token.rs): `programs/palm-presale/src/instructions/deposit_token.rs`

### Purchasing

- [Buy tokens](https://github.com/metatheory-dev/presale-smartcontracts/blob/master/programs/palm-presale/src/instructions/buy_token.rs): `programs/palm-presale/src/instructions/buy_token.rs`

### Settlement

- [Claim tokens](https://github.com/metatheory-dev/presale-smartcontracts/blob/master/programs/palm-presale/src/instructions/claim_token.rs): `programs/palm-presale/src/instructions/claim_token.rs`
- [Withdraw SOL](https://github.com/metatheory-dev/presale-smartcontracts/blob/master/programs/palm-presale/src/instructions/withdraw_sol.rs): `programs/palm-presale/src/instructions/withdraw_sol.rs`
- [Withdraw tokens](https://github.com/metatheory-dev/presale-smartcontracts/blob/master/programs/palm-presale/src/instructions/withdraw_token.rs): `programs/palm-presale/src/instructions/withdraw_token.rs`

### On-chain state

- [Sale account](https://github.com/metatheory-dev/presale-smartcontracts/blob/master/programs/palm-presale/src/state/presale_info.rs): `programs/palm-presale/src/state/presale_info.rs`
- [Buyer account](https://github.com/metatheory-dev/presale-smartcontracts/blob/master/programs/palm-presale/src/state/user_info.rs): `programs/palm-presale/src/state/user_info.rs`

### Other components

- **Administrator**
- **Buyer**
- **Solana token and system programs**
- **Presale vault**

## Connections

- Administrator → Anchor program: invokes (evidence: `README.md`)
- Buyer → Anchor program: invokes (evidence: `README.md`)
- Anchor program → Create presale: dispatches (evidence: `programs/palm-presale/src/lib.rs`)
- Anchor program → Update presale: dispatches (evidence: `programs/palm-presale/src/lib.rs`)
- Anchor program → Start presale: dispatches (evidence: `programs/palm-presale/src/lib.rs`)
- Anchor program → Fund inventory: dispatches (evidence: `programs/palm-presale/src/lib.rs`)
- Anchor program → Buy tokens: dispatches (evidence: `programs/palm-presale/src/lib.rs`)
- Anchor program → Claim tokens: dispatches (evidence: `programs/palm-presale/src/lib.rs`)
- Anchor program → Withdraw SOL: dispatches (evidence: `programs/palm-presale/src/lib.rs`)
- Anchor program → Withdraw tokens: dispatches (evidence: `programs/palm-presale/src/lib.rs`)
- Create presale → Sale account: initializes (evidence: `programs/palm-presale/src/instructions/create_presale.rs`)
- Update presale → Sale account: updates (evidence: `programs/palm-presale/src/instructions/update_presale.rs`)
- Start presale → Sale account: updates (evidence: `programs/palm-presale/src/instructions/start_presale.rs`)
- Fund inventory → Sale account: updates inventory (evidence: `programs/palm-presale/src/instructions/deposit_token.rs`)
- Fund inventory → Solana token and system programs: transfers tokens (evidence: `programs/palm-presale/src/instructions/deposit_token.rs`)
- Fund inventory → Presale vault: funds rent (evidence: `programs/palm-presale/src/instructions/deposit_token.rs`)
- Buy tokens → Sale account: checks and updates (evidence: `programs/palm-presale/src/instructions/buy_token.rs`)
- Buy tokens → Buyer account: records purchase (evidence: `programs/palm-presale/src/instructions/buy_token.rs`)
- Buy tokens → Presale vault: transfers SOL (evidence: `programs/palm-presale/src/instructions/buy_token.rs`)
- Buy tokens → Solana token and system programs: calls system transfer (evidence: `programs/palm-presale/src/instructions/buy_token.rs`)
- Claim tokens → Sale account: reads sale state (evidence: `programs/palm-presale/src/instructions/claim_token.rs`)
- Claim tokens → Buyer account: reads buyer state (evidence: `programs/palm-presale/src/instructions/claim_token.rs`)
- Claim tokens → Solana token and system programs: transfers tokens (evidence: `programs/palm-presale/src/instructions/claim_token.rs`)
- Withdraw SOL → Sale account: reads sale state (evidence: `programs/palm-presale/src/instructions/withdraw_sol.rs`)
- Withdraw SOL → Presale vault: withdraws SOL (evidence: `programs/palm-presale/src/instructions/withdraw_sol.rs`)
- Withdraw SOL → Solana token and system programs: calls system transfer (evidence: `programs/palm-presale/src/instructions/withdraw_sol.rs`)
- Withdraw tokens → Sale account: reads sale state (evidence: `programs/palm-presale/src/instructions/withdraw_token.rs`)
- Withdraw tokens → Solana token and system programs: transfers tokens (evidence: `programs/palm-presale/src/instructions/withdraw_token.rs`)
