Skip to content

Commit 617cb44

Browse files
authored
Merge pull request #135 from quicknode/claude/solana-anchor-v1-v2-structure-x62v8i
Keep an Anchor v1 copy of every Anchor example, tested in its own CI job
2 parents ff91375 + b180f24 commit 617cb44

926 files changed

Lines changed: 68169 additions & 17 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.github/workflows/anchor-v1.yml

Lines changed: 387 additions & 0 deletions
Large diffs are not rendered by default.

.github/workflows/anchor.yml

Lines changed: 22 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
name: Anchor
1+
name: Anchor v2
22

33
on:
44
push:
@@ -8,6 +8,16 @@ on:
88
types: [opened, synchronize, reopened]
99
branches:
1010
- main
11+
# These projects have no committed Cargo.lock (.gitignore ignores **/*/Cargo.lock),
12+
# so their transitive dependencies resolve fresh on every run and can break with
13+
# nobody touching the code. Dependabot does not cover them either: it is configured
14+
# for directory "/", which is the root workspace, and the per-project anchor/ workspaces are
15+
# what `anchor build` actually resolves. A weekly
16+
# build catches that drift on a cadence instead of at whatever unrelated pull request
17+
# happens to touch these files next. The analyze step already treats a scheduled run
18+
# as "build everything".
19+
schedule:
20+
- cron: '0 3 * * 1'
1121

1222
concurrency:
1323
group: ${{ github.workflow }}-${{ github.ref }}
@@ -50,11 +60,15 @@ jobs:
5060
ignore_pattern=$(grep -v '^#' .github/.ghaignore | grep -v '^$' | tr '\n' '|' | sed 's/|$//')
5161
echo "Ignore pattern: $ignore_pattern"
5262
53-
# Single source of truth for "what is a framework project": a directory
63+
# Single source of truth for "what is an Anchor v2 project": a directory
5464
# whose name is exactly "anchor". `find -type d -name anchor` gives us
5565
# that by construction — no substring matching, no path-segment trickery,
5666
# so siblings like "anchor-example/" or nested files such as
5767
# "anchor-example/app/pages/api/foo.ts" can never enter the build list.
68+
# It is also what keeps the two Anchor workflows disjoint: the Anchor v1
69+
# projects live in "anchor-v1" directories, built by
70+
# .github/workflows/anchor-v1.yml, and an exact-name match on "anchor"
71+
# never sees them.
5872
function get_projects() {
5973
# An empty .ghaignore makes ignore_pattern empty, and `grep -vE ""`
6074
# matches everything, silently emptying the project list - only
@@ -173,11 +187,11 @@ jobs:
173187
# runs `anchor --version | awk '{print $2}'` and writes the result straight to
174188
# $GITHUB_OUTPUT. `anchor --version` now prints more than one line, so the value
175189
# becomes multi-line and the step dies with "Invalid format", aborting the whole
176-
# job before any project is built. These steps install the same toolchain (Solana
177-
# via the Anza installer, Anchor via avm) and read the version from the first line
178-
# only. The other workflows that use setup-anchor (native, quasar, pinocchio,
179-
# solana-asm) hit the same latent bug once their matrices run; migrate them the
180-
# same way once this is confirmed green.
190+
# job before any project is built. These steps install the toolchain directly
191+
# (Solana via the Anza installer, the Anchor CLI from crates.io) and read the
192+
# version from the first line only. The other workflows that use setup-anchor
193+
# (native, quasar, pinocchio, solana-asm) hit the same latent bug once their
194+
# matrices run; migrate them the same way once this is confirmed green.
181195
- uses: actions/setup-node@v4
182196
with:
183197
node-version: lts/*
@@ -378,7 +392,7 @@ jobs:
378392
- uses: actions/checkout@v5
379393
- name: Create job summary
380394
run: |
381-
echo "## Anchor Workflow Summary" >> $GITHUB_STEP_SUMMARY
395+
echo "## Anchor v2 Workflow Summary" >> $GITHUB_STEP_SUMMARY
382396
echo "- Total projects: ${{ needs.changes.outputs.total_projects }}" >> $GITHUB_STEP_SUMMARY
383397
384398
# List all processed projects

CHANGELOG.md

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,59 @@ All notable changes to this repository are documented here.
44

55
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/).
66

7+
## [2026-08-21] - Anchor v1 kept alongside Anchor v2
8+
9+
Anchor v1 is expected to stay on long-term support, and many deployed programs
10+
will stay with it. Both versions of every Anchor example now ship, each built and
11+
tested by its own CI job.
12+
13+
### Added
14+
15+
- Every one of the 55 Anchor examples gains a sibling `anchor-v1/` directory
16+
holding the example exactly as it stood before the v2 port, restored from
17+
`94abbea`, the last commit on `main` before that merge. 864 files. The 17
18+
third-party `.so` test fixtures are byte-identical to the ones already tracked
19+
under `anchor/`, so git stores one copy and the tree grows by ~2.3 MB of text.
20+
- `.github/workflows/anchor-v1.yml` builds and tests them on Anchor 1.1.2,
21+
installed through avm. It is the workflow as it stood at `94abbea`, with
22+
project discovery changed to `find -type d -name "anchor-v1"`. The v2-only IDL
23+
workaround (`anchor#4947`, enum variants) is not carried over: that bug does not
24+
exist in 1.1.2, so v1 builds generate IDLs normally.
25+
26+
### Changed
27+
28+
- The `Anchor` workflow is now `Anchor v2`, so the two checks read as a pair. Its
29+
filename, triggers and `find -type d -name "anchor"` discovery are unchanged.
30+
Both workflows match a directory name exactly, so neither can ever see the
31+
other's projects.
32+
- Both Anchor workflows install the CLI from crates.io (`cargo install anchor-cli
33+
--version <v> --locked`). The v1 job started out installing avm from the tip of
34+
anchor's `main` branch, which meant what CI installed drifted with whatever landed
35+
there; 1.1.2 is an ordinary published release, so it comes from the registry like
36+
2.0.0-rc.1 does.
37+
- Both Anchor workflows now run weekly (v2 Mondays 03:00 UTC, v1 05:00 UTC). The
38+
analyze step has always treated a scheduled run as "build everything", but nothing
39+
declared a schedule, so that path had never executed. It is worth having because no
40+
Anchor project commits a `Cargo.lock` and Dependabot only covers the root workspace,
41+
so dependency drift in either tree is otherwise invisible until an unrelated pull
42+
request happens to touch it.
43+
- The two workflows no longer report colliding check names. Both declared jobs called
44+
`changes`, `summary` and `build-and-test-group-N`; the v1 job names are now
45+
`changes (Anchor v1)`, `anchor-v1-group-N` and `summary (Anchor v1)`.
46+
- Every Anchor example README now names the CLI its commands need, on both sides:
47+
`anchor/` pages say Anchor v2 and `anchor-v1/` pages say Anchor v1. A bare
48+
`anchor build` was unambiguous while the repository had one Anchor and is not
49+
any more. `README.md` and `CONTRIBUTING.md`, which sit above both, show both.
50+
51+
### Note
52+
53+
- The `anchor-v1/` crates are not members of the root Cargo workspace and cannot
54+
be: they carry the same package names as their `anchor/` siblings. `cargo fmt`
55+
and `cargo clippy` therefore do not see them, and the Anchor v1 workflow is what
56+
keeps them honest. They also have no committed `Cargo.lock` (`.gitignore` ignores
57+
`**/*/Cargo.lock`), so their transitive dependencies resolve fresh on each run and
58+
can break without anyone touching the directory.
59+
760
## [2026-08-16] - Every Anchor example on Anchor v2.0.0-rc.1
861

962
All 55 Anchor examples build and pass their tests on 2.0.0-rc.1 (304 tests),

CONTRIBUTING.md

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,10 @@ See [CHANGELOG.md](./CHANGELOG.md) for release history. This file had no changel
1212
## Project structure
1313

1414
- Each example lives at `category/example-name/<framework>/`, e.g. `basics/counter/anchor/`.
15-
- Supported frameworks: `anchor`, `quasar`, `pinocchio`, `native`, `asm`. Use the existing layout as a reference.
15+
- Supported frameworks: `anchor`, `anchor-v1`, `quasar`, `pinocchio`, `native`, `asm`. Use the existing layout as a reference.
16+
- `anchor/` is Anchor v2 (2.0.0-rc.1) and is where new Anchor work goes. `anchor-v1/` is the
17+
same example on Anchor v1 (1.1.2), kept for the v1 LTS line: it is a frozen snapshot and
18+
changes only to keep the v1 build green, not to gain new features.
1619
- Anchor and Quasar programs usually keep Rust tests under `programs/<name>/tests/`.
1720
- Native and Pinocchio tests are Rust + LiteSVM, kept under `program/tests/`.
1821

@@ -25,7 +28,8 @@ See [CHANGELOG.md](./CHANGELOG.md) for release history. This file had no changel
2528

2629
Run an example's tests with the command for its framework, from the framework directory (e.g. `basics/counter/anchor/`):
2730

28-
- **Anchor:** `anchor test` (runs `cargo test`, per the `[scripts]` table in `Anchor.toml`).
31+
- **Anchor v2** (in `anchor/`): `anchor test` (runs `cargo test`, per the `[scripts]` table in `Anchor.toml`), with the v2 CLI: `cargo install anchor-cli --version 2.0.0-rc.1 --locked`.
32+
- **Anchor v1** (in `anchor-v1/`): the same `anchor test`, with the v1 CLI: `avm install 1.1.2 && avm use 1.1.2`. Selecting the wrong CLI is the usual cause of a confusing build failure in these directories.
2933
- **Quasar:** `quasar test`.
3034
- **Native / Pinocchio:** `cargo test --manifest-path=./program/Cargo.toml` (build first with `cargo build-sbf --manifest-path=./program/Cargo.toml`).
3135

Cargo.toml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,15 @@
33
# `anchor/Cargo.toml` workspace. `anchor build` uses the project workspace; this
44
# one is what the repository-wide `cargo fmt` and `cargo clippy` jobs see, and
55
# they only ever look at members. A crate missing here is a crate CI never lints.
6+
#
7+
# The `anchor-v1/` crates are deliberately absent, and must stay absent. Each is a
8+
# copy of its `anchor/` sibling carrying the same `[package] name`, and one
9+
# workspace cannot hold two packages called the same thing - adding them fails with
10+
# "two packages named `favorites` in this workspace". They do not need an `exclude`
11+
# entry either: nothing here depends on them by path, and each `anchor-v1/Cargo.toml`
12+
# declares its own `[workspace]`, so `anchor build` inside one resolves there. The
13+
# cost is that `cargo fmt` and `cargo clippy` never see them; the Anchor v1 workflow
14+
# compiles and tests them instead.
615
members = [
716
#basics
817
"basics/account-data/native/program",

README.md

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,14 @@
44

55
_Solana program examples ('smart contracts') in Anchor, Quasar, Pinocchio, native Rust, and sBPF assembly. Focused on financial software ('DeFi'), plus the basics, tokens, Token Extensions, state compression, and more._
66

7-
Working, tested, up-to-date examples of common Solana programs (what other chains call smart contracts), maintained by [Quicknode](https://www.quicknode.com/chains/solana). Current as of August 2026 (see [CHANGELOG.md](./CHANGELOG.md)): every example builds and passes CI on **Anchor 2.0.0-rc.1**, the current multi-file program layout (one file per instruction handler, account type, etc), and [LiteSVM](https://github.com/LiteSVM/litesvm) tests rather than the older `solana-test-validator` / web3.js stack.
7+
Working, tested, up-to-date examples of common Solana programs (what other chains call smart contracts), maintained by [Quicknode](https://www.quicknode.com/chains/solana). Current as of August 2026 (see [CHANGELOG.md](./CHANGELOG.md)): every example builds and passes CI on **Anchor 2.0.0-rc.1**, the current multi-file program layout (one file per instruction handler, account type, etc), and [LiteSVM](https://github.com/LiteSVM/litesvm) tests rather than the older `solana-test-validator` / web3.js stack. Every Anchor example also keeps its last **Anchor 1.1.2** version in a sibling `anchor-v1/` directory, built and tested by its own CI job, for programs staying on the Anchor v1 LTS line.
88

9-
[![Anchor](../../actions/workflows/anchor.yml/badge.svg)](../../actions/workflows/anchor.yml) [![Quasar](../../actions/workflows/quasar.yml/badge.svg)](../../actions/workflows/quasar.yml) [![Pinocchio](../../actions/workflows/pinocchio.yml/badge.svg)](../../actions/workflows/pinocchio.yml) [![Native](../../actions/workflows/native.yml/badge.svg)](../../actions/workflows/native.yml) [![ASM](../../actions/workflows/solana-asm.yml/badge.svg)](../../actions/workflows/solana-asm.yml)
9+
[![Anchor v2](../../actions/workflows/anchor.yml/badge.svg)](../../actions/workflows/anchor.yml) [![Anchor v1](../../actions/workflows/anchor-v1.yml/badge.svg)](../../actions/workflows/anchor-v1.yml) [![Quasar](../../actions/workflows/quasar.yml/badge.svg)](../../actions/workflows/quasar.yml) [![Pinocchio](../../actions/workflows/pinocchio.yml/badge.svg)](../../actions/workflows/pinocchio.yml) [![Native](../../actions/workflows/native.yml/badge.svg)](../../actions/workflows/native.yml) [![ASM](../../actions/workflows/solana-asm.yml/badge.svg)](../../actions/workflows/solana-asm.yml)
1010

1111
Each example is available in one or more of the following frameworks:
1212

13-
- [⚓ Anchor](https://www.anchor-lang.com/) - the most popular framework for Solana development. Build with `anchor build`, test with `anchor test`.
13+
- [⚓ Anchor v2](https://www.anchor-lang.com/) - the most popular framework for Solana development, in its current major version. Lives in `anchor/`. Install with `cargo install anchor-cli --version 2.0.0-rc.1 --locked`, build with `anchor build`, test with `anchor test`.
14+
- [⚓ Anchor v1](https://www.anchor-lang.com/) - the previous major version, on long-term support and still what many deployed programs use. Lives in `anchor-v1/`, alongside the v2 copy of the same example. Install with `avm install 1.1.2 && avm use 1.1.2`, then the same `anchor build` / `anchor test`.
1415
- [💫 Quasar](https://quasar-lang.com/docs) - a newer, more performant framework with Anchor-compatible ergonomics. Build with `quasar build`, test with `quasar test`.
1516
- [🤥 Pinocchio](https://github.com/anza-xyz/pinocchio) - a zero-copy, zero-allocation library for Solana programs. Build with `cargo build-sbf --manifest-path=./program/Cargo.toml`, test with `cargo test --manifest-path=./program/Cargo.toml`.
1617
- [🦀 Native Rust](https://docs.anza.xyz/) - vanilla Rust using Solana's native crates. Build with `cargo build-sbf --manifest-path=./program/Cargo.toml`, test with `cargo test --manifest-path=./program/Cargo.toml`.
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
[toolchain]
2+
# Match the repo package manager (pnpm-lock.yaml at root); avoids Anchor's yarn default.
3+
package_manager = "pnpm"
4+
solana_version = "3.1.8"
5+
6+
[features]
7+
seeds = false
8+
skip-lint = false
9+
10+
[programs.localnet]
11+
account_data_anchor_program = "GpVcgWdgVErgLqsn8VYUch6EqDerMgNqoLSmGyKrd6MR"
12+
13+
[provider]
14+
cluster = "Localnet"
15+
wallet = "~/.config/solana/id.json"
16+
17+
[scripts]
18+
test = "cargo test"
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# Changelog
2+
3+
## 2026-07-07
4+
5+
Added this changelog. Changes prior to this date were tracked in git history only.
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
[workspace]
2+
members = [
3+
"programs/*"
4+
]
5+
resolver = "2"
6+
7+
[profile.release]
8+
overflow-checks = true
9+
lto = "fat"
10+
codegen-units = 1
11+
[profile.release.build-override]
12+
opt-level = 3
13+
incremental = false
14+
codegen-units = 1
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
# Account Data (Anchor)
2+
3+
> [!NOTE]
4+
> This is the **Anchor v1** copy of this example, kept for programs staying on the
5+
> Anchor v1 LTS line. Every `anchor` command on this page needs the v1 CLI:
6+
> `avm install 1.1.2 && avm use 1.1.2`. The Anchor v2 version of this example is in
7+
> [`../anchor`](../anchor/).
8+
9+
Store and retrieve arbitrary data in a Solana [account](https://solana.com/docs/terminology#account) owned by this [program](https://solana.com/docs/terminology#program).
10+
11+
See also: the [repository catalog](../../../README.md).
12+
13+
## Major concepts
14+
15+
- Account ownership and lamport rent
16+
- Serializing and deserializing account data
17+
18+
## Setup
19+
20+
From this directory (`basics/account-data/anchor/`):
21+
22+
```bash
23+
anchor build
24+
```
25+
26+
Prerequisites: [Agave](https://docs.anza.xyz/) CLI (version in `Anchor.toml` `[toolchain]`), [Anchor](https://www.anchor-lang.com/docs).
27+
28+
## Testing
29+
30+
Tests run in-process with [LiteSVM](https://www.anchor-lang.com/docs/testing/litesvm). No local validator.
31+
32+
```bash
33+
anchor test
34+
```
35+
36+
This runs `cargo test` as configured in `Anchor.toml`. Tests call instruction handlers and check onchain state.
37+
38+
## Usage
39+
40+
Read the program `programs/` source and `Anchor.toml` for deployed program IDs. For deployment, use `anchor build && anchor deploy` against your target cluster.

0 commit comments

Comments
 (0)