Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions .github/workflows/anchor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -205,25 +205,25 @@ jobs:
path: |
~/.cargo/bin/anchor
# Pinned to match the anchor-lang/anchor-spl crate version the programs depend on.
key: anchor-cli-crates-io-${{ runner.os }}-2.0.0-rc.2
- name: Install Anchor 2.0.0-rc.2
key: anchor-cli-crates-io-${{ runner.os }}-2.0.0-rc.4
- name: Install Anchor 2.0.0-rc.4
run: |
export PATH="$HOME/.cargo/bin:$PATH"
# `anchor --version` can emit more than one line; read the first line only so
# a multi-line value never reaches downstream parsing.
current="$(anchor --version 2>/dev/null | head -n1 | awk '{print $2}' || true)"
if [ "$current" != "2.0.0-rc.2" ]; then
if [ "$current" != "2.0.0-rc.4" ]; then
# Install the CLI from crates.io rather than through avm. avm has no
# prebuilt binary for this pre-release (a plain `avm install` 404s), and
# its --from-source path builds the CLI from the git tag, which is not
# the same code as the published anchor-lang 2.0.0-rc.2 the programs
# the same code as the published anchor-lang 2.0.0-rc.4 the programs
# compile against: `anchor idl build` then emits a shim referencing
# `anchor_lang::IdlBuild`, which that crate does not have, and writes
# IDL JSON the parser rejects with "missing field `variants`".
# Installing the CLI from crates.io keeps it and the library on one
# published release. --locked builds it against its own published
# lockfile so the result does not drift with the registry.
cargo install anchor-cli --version 2.0.0-rc.2 --locked --force
cargo install anchor-cli --version 2.0.0-rc.4 --locked --force
fi
echo "$HOME/.cargo/bin" >> "$GITHUB_PATH"
- name: Install Surfpool
Expand Down
56 changes: 56 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,62 @@ All notable changes to this repository are documented here.

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

## [2026-11-14] - Anchor v2 examples on Anchor 2.0.0-rc.4

Anchor 2.0.0-rc.3 replaced v2's duplicate mutable account check with the borrows each
account wrapper takes on account data, removed the `unsafe(dup)` constraint, and made
`Context::remaining_accounts()` infallible. 2.0.0-rc.4's changelog lists only TypeScript
client changes, but it also ships anchor#5185, which takes heap-allocated types out of
v2's public API: `Box` accounts are gone, CPI account lists and `declare_program!`
instruction data go in fixed-capacity buffers the caller sizes, and onchain CPIs take a
`CpiInstruction` rather than a `solana_instruction::Instruction`. anchor#4891 also drops
`Interface`'s lifetime parameter.

### Changed

- All 56 Anchor v2 examples move `anchor-lang` and `anchor-spl` from `2.0.0-rc.2` to
`2.0.0-rc.4`, and `anchor-v2-testing` from revision `a2066021` to `2cdb58ba`, the
commit the `v2.0.0-rc.4` tag points at. `wincode` stays on 0.6, which rc.4 also uses.
- The Anchor v2 workflow installs and caches `anchor-cli 2.0.0-rc.4`. Every Anchor v2
README, `CONTRIBUTING.md`, the root `README.md` and `docs/anchor-v2-migration.md` name
rc.4.
- `token-minter`'s and `transfer-tokens`' `mint`, and `transfer-switch`'s
`configure_admin`, mark the fields that may name the same account `#[account(mut)]`
instead of `#[account(unsafe(dup))]`. `Signer`, `SystemAccount` and `UncheckedAccount`
take no borrow on account data, so they may alias with no constraint.
- The eleven calls to `remaining_accounts()` in `cnft-burn`, `cnft-vault`, `cutils`,
`lending`, `managed-fund`, `order-book` and `transfer-fee` drop the `?`. The method
returns `&[AccountView]`; `transfer-fee`'s `harvest` copies it with `.to_vec()` to
build `CpiHandleMut`s, which take `&mut AccountView`.
- The 245 `Box<...>` account fields across nine finance examples, `transfer-cost` and
`allow-block-list-token` are unboxed, and the comments and `order-book` README notes
that explained the boxing are removed. No Anchor v2 example exceeds the 4 KB stack
frame unboxed. The three `**context.accounts.x = ...` assignments become `*...`.
- The 81 `Interface<'static, TokenInterface>` fields are `Interface<TokenInterface>`.
- All 176 `CpiContext::new` and `CpiContext::new_with_signer` calls name their account
capacity, `CpiContext::<_, N>`, with `N` the number of accounts in the CPI's accounts
struct.
- `transfer-fee`'s `harvest` takes at most `MAX_HARVEST_SOURCES` (16) token accounts and
sizes its `CpiContext` for the mint plus that many; more fail with the new
`TooManyHarvestSources` error, which `test_transfer_fee_full_flow` checks.
- `cross-program-invocation`'s `hand` passes `switch_power` the `FixedVec` instruction-data
buffer the generated CPI function takes onchain, and refuses a `name` over
`MAX_NAME_LEN` (32) bytes with the new `NameTooLong` error.
`test_pull_lever_name_length_limit` tests a 32-byte and a 33-byte name.
- `cnft-burn`, `cnft-vault` and `cutils` build their Bubblegum and account-compression
CPIs as a local `OwnedInstruction`, which implements `CpiInstruction`.
- `order-book`'s `place_order` calls `BorshAccount::load_mut` without `unsafe`; the
method is safe in rc.4.
- `escrow`'s `test_make_offer_rejects_same_mint` and `options`'
`test_writer_cannot_buy_their_own_option` expect `AccountBorrowFailed`, the error a
mutable account in two slots now fails with.
- `docs/anchor-v2-migration.md` replaces "Duplicate Mutable Accounts Are Rejected" with
"Duplicate Accounts Fail Through Borrows", and covers unboxed accounts, `CpiContext`
capacities, `declare_program!` data buffers, `OwnedInstruction` and the safe
`load_mut`.
- `basics/transaction-v1/anchor/README.md` states that `@anchor-lang/core` 2.0.0-rc.4
needs `@solana/kit` 8.5 or later and builds v1 transaction messages by default.

## [2026-11-07] - Transfer Hook - Whitelist becomes Transfer Hook - Allow List, with no size limit

The whitelist example kept every allowed address in one account, capped at eleven,
Expand Down
4 changes: 2 additions & 2 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ See [CHANGELOG.md](./CHANGELOG.md) for release history. This file had no changel
- Each example lives at `category/example-name/<framework>/`, e.g. `basics/counter/anchor/`.
- Supported frameworks: `anchor`, `anchor-v1`, `quasar`, `pinocchio`, `native`, `asm`. Use the existing layout as a reference.
- `anchor-v1/` is Anchor v1 (1.2.1), the current stable Anchor. `anchor/` is the same example
on Anchor v2 (2.0.0-rc.2), the release candidate for the next major version, and is where new
on Anchor v2 (2.0.0-rc.4), the release candidate for the next major version, and is where new
Anchor work starts; the v1 copy tracks its v2 counterpart. A change to what an example does (a new handler, a new check, a
fix, a renamed field) goes into both copies, in the same pull request where practical, so a
v1 reader gets the same program and the same tests. The copies differ only where the Anchor
Expand All @@ -33,7 +33,7 @@ See [CHANGELOG.md](./CHANGELOG.md) for release history. This file had no changel

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

- **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.2 --locked`.
- **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.4 --locked`.
- **Anchor v1** (in `anchor-v1/`): the same `anchor test`, with the v1 CLI: `avm install 1.2.1 && avm use 1.2.1`. Selecting the wrong CLI is the usual cause of a confusing build failure in these directories.
Both Anchor copies' tests send v1 transactions (4,096 bytes, resource limits in the message)
through `solana-kite`: 0.6 for Anchor v1, 0.7 for Anchor v2. Its senders take a last `compute_unit_limit: Option<u32>`: pass `None` and kite
Expand Down
15 changes: 8 additions & 7 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ _The largest actively maintained set of Solana programs ('smart contracts') on t
Each example is available in one or more of the following frameworks:

- [⚓ Anchor v1](https://www.anchor-lang.com/) - the most popular framework for Solana development, in its current major version. Lives in `anchor-v1/`. Install with `avm install 1.2.1 && avm use 1.2.1`, build with `anchor build`, test with `anchor test`.
- [⚓ Anchor v2](https://www.anchor-lang.com/) - the next major version of Anchor, a ground-up rewrite that is not yet released. Lives in `anchor/`, alongside the v1 copy of the same example, and builds on the release candidate: install with `cargo install anchor-cli --version 2.0.0-rc.2 --locked`, then the same `anchor build` / `anchor test`.
- [⚓ Anchor v2](https://www.anchor-lang.com/) - the next major version of Anchor, a ground-up rewrite that is not yet released. Lives in `anchor/`, alongside the v1 copy of the same example, and builds on the release candidate: install with `cargo install anchor-cli --version 2.0.0-rc.4 --locked`, then the same `anchor build` / `anchor test`.
- [💫 Quasar](https://quasar-lang.com/docs) - a newer, more performant framework with Anchor-compatible ergonomics. Build with `quasar build`, test with `quasar test`.
- [🤥 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`.
- [🦀 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`.
Expand Down
2 changes: 1 addition & 1 deletion basics/account-data/anchor/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

> [!NOTE]
> This is the **Anchor v2** copy of this example. Every `anchor` command on this page
> needs the v2 CLI: `cargo install anchor-cli --version 2.0.0-rc.2 --locked` (avm has
> needs the v2 CLI: `cargo install anchor-cli --version 2.0.0-rc.4 --locked` (avm has
> no prebuilt binary for this pre-release). The Anchor v1 version of this example is in
> [`../anchor-v1`](../anchor-v1/).

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ custom-panic = []
profile = ["anchor-v2-testing/profile"]

[dependencies]
anchor-lang = "2.0.0-rc.2"
anchor-lang = "2.0.0-rc.4"
# The `#[program]` macro expands to `wincode` paths for instruction-data
# (de)serialization, so the crate has to be a direct dependency.
wincode = { version = "0.6", features = ["derive"] }
Expand All @@ -42,7 +42,7 @@ wincode = { version = "0.6", features = ["derive"] }
# development happens, so a later revision can carry breakage as easily as
# fixes. When `anchor-v2-testing` reaches crates.io, drop the git source for
# an ordinary version.
anchor-v2-testing = { git = "https://github.com/otter-sec/anchor.git", rev = "a20660219882af5f199d56ea3f9326f387f89d8b" }
anchor-v2-testing = { git = "https://github.com/otter-sec/anchor.git", rev = "2cdb58ba8fd9139942ffe235ed5c5c01072138b8" }
# LiteSVM 0.18.1 asks for the Agave crates with `^4.3` ranges but does not
# compile against Agave 4.4.0. These two hold the Agave crates at 4.3; the rest
# follow, because Agave pins its own crates to one another exactly. Remove both
Expand Down
2 changes: 1 addition & 1 deletion basics/checking-accounts/anchor/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

> [!NOTE]
> This is the **Anchor v2** copy of this example. Every `anchor` command on this page
> needs the v2 CLI: `cargo install anchor-cli --version 2.0.0-rc.2 --locked` (avm has
> needs the v2 CLI: `cargo install anchor-cli --version 2.0.0-rc.4 --locked` (avm has
> no prebuilt binary for this pre-release). The Anchor v1 version of this example is in
> [`../anchor-v1`](../anchor-v1/).

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ custom-panic = []
profile = ["anchor-v2-testing/profile"]

[dependencies]
anchor-lang = "2.0.0-rc.2"
anchor-lang = "2.0.0-rc.4"
# The `#[program]` macro expands to `wincode` paths for instruction-data
# (de)serialization, so the crate has to be a direct dependency.
wincode = { version = "0.6", features = ["derive"] }
Expand All @@ -42,7 +42,7 @@ wincode = { version = "0.6", features = ["derive"] }
# development happens, so a later revision can carry breakage as easily as
# fixes. When `anchor-v2-testing` reaches crates.io, drop the git source for
# an ordinary version.
anchor-v2-testing = { git = "https://github.com/otter-sec/anchor.git", rev = "a20660219882af5f199d56ea3f9326f387f89d8b" }
anchor-v2-testing = { git = "https://github.com/otter-sec/anchor.git", rev = "2cdb58ba8fd9139942ffe235ed5c5c01072138b8" }
# LiteSVM 0.18.1 asks for the Agave crates with `^4.3` ranges but does not
# compile against Agave 4.4.0. These two hold the Agave crates at 4.3; the rest
# follow, because Agave pins its own crates to one another exactly. Remove both
Expand Down
2 changes: 1 addition & 1 deletion basics/close-account/anchor/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

> [!NOTE]
> This is the **Anchor v2** copy of this example. Every `anchor` command on this page
> needs the v2 CLI: `cargo install anchor-cli --version 2.0.0-rc.2 --locked` (avm has
> needs the v2 CLI: `cargo install anchor-cli --version 2.0.0-rc.4 --locked` (avm has
> no prebuilt binary for this pre-release). The Anchor v1 version of this example is in
> [`../anchor-v1`](../anchor-v1/).

Expand Down
4 changes: 2 additions & 2 deletions basics/close-account/anchor/programs/close-account/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ custom-panic = []
profile = ["anchor-v2-testing/profile"]

[dependencies]
anchor-lang = "2.0.0-rc.2"
anchor-lang = "2.0.0-rc.4"
# The `#[program]` macro expands to `wincode` paths for instruction-data
# (de)serialization, so the crate has to be a direct dependency.
wincode = { version = "0.6", features = ["derive"] }
Expand All @@ -42,7 +42,7 @@ wincode = { version = "0.6", features = ["derive"] }
# development happens, so a later revision can carry breakage as easily as
# fixes. When `anchor-v2-testing` reaches crates.io, drop the git source for
# an ordinary version.
anchor-v2-testing = { git = "https://github.com/otter-sec/anchor.git", rev = "a20660219882af5f199d56ea3f9326f387f89d8b" }
anchor-v2-testing = { git = "https://github.com/otter-sec/anchor.git", rev = "2cdb58ba8fd9139942ffe235ed5c5c01072138b8" }
# LiteSVM 0.18.1 asks for the Agave crates with `^4.3` ranges but does not
# compile against Agave 4.4.0. These two hold the Agave crates at 4.3; the rest
# follow, because Agave pins its own crates to one another exactly. Remove both
Expand Down
2 changes: 1 addition & 1 deletion basics/counter/anchor/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

> [!NOTE]
> This is the **Anchor v2** copy of this example. Every `anchor` command on this page
> needs the v2 CLI: `cargo install anchor-cli --version 2.0.0-rc.2 --locked` (avm has
> needs the v2 CLI: `cargo install anchor-cli --version 2.0.0-rc.4 --locked` (avm has
> no prebuilt binary for this pre-release). The Anchor v1 version of this example is in
> [`../anchor-v1`](../anchor-v1/).

Expand Down
4 changes: 2 additions & 2 deletions basics/counter/anchor/programs/counter_anchor/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ custom-heap = []
custom-panic = []

[dependencies]
anchor-lang = "2.0.0-rc.2"
anchor-lang = "2.0.0-rc.4"
# The `#[program]` macro expands to `wincode` paths for instruction-data
# (de)serialization, so the crate has to be a direct dependency.
wincode = { version = "0.6", features = ["derive"] }
Expand All @@ -42,7 +42,7 @@ wincode = { version = "0.6", features = ["derive"] }
# development happens, so a later revision can carry breakage as easily as
# fixes. When `anchor-v2-testing` reaches crates.io, drop the git source for
# an ordinary version.
anchor-v2-testing = { git = "https://github.com/otter-sec/anchor.git", rev = "a20660219882af5f199d56ea3f9326f387f89d8b" }
anchor-v2-testing = { git = "https://github.com/otter-sec/anchor.git", rev = "2cdb58ba8fd9139942ffe235ed5c5c01072138b8" }
# LiteSVM 0.18.1 asks for the Agave crates with `^4.3` ranges but does not
# compile against Agave 4.4.0. These two hold the Agave crates at 4.3; the rest
# follow, because Agave pins its own crates to one another exactly. Remove both
Expand Down
2 changes: 1 addition & 1 deletion basics/create-account/anchor/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

> [!NOTE]
> This is the **Anchor v2** copy of this example. Every `anchor` command on this page
> needs the v2 CLI: `cargo install anchor-cli --version 2.0.0-rc.2 --locked` (avm has
> needs the v2 CLI: `cargo install anchor-cli --version 2.0.0-rc.4 --locked` (avm has
> no prebuilt binary for this pre-release). The Anchor v1 version of this example is in
> [`../anchor-v1`](../anchor-v1/).

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ custom-panic = []
profile = ["anchor-v2-testing/profile"]

[dependencies]
anchor-lang = "2.0.0-rc.2"
anchor-lang = "2.0.0-rc.4"
# The `#[program]` macro expands to `wincode` paths for instruction-data
# (de)serialization, so the crate has to be a direct dependency.
wincode = { version = "0.6", features = ["derive"] }
Expand All @@ -42,7 +42,7 @@ wincode = { version = "0.6", features = ["derive"] }
# development happens, so a later revision can carry breakage as easily as
# fixes. When `anchor-v2-testing` reaches crates.io, drop the git source for
# an ordinary version.
anchor-v2-testing = { git = "https://github.com/otter-sec/anchor.git", rev = "a20660219882af5f199d56ea3f9326f387f89d8b" }
anchor-v2-testing = { git = "https://github.com/otter-sec/anchor.git", rev = "2cdb58ba8fd9139942ffe235ed5c5c01072138b8" }
# LiteSVM 0.18.1 asks for the Agave crates with `^4.3` ranges but does not
# compile against Agave 4.4.0. These two hold the Agave crates at 4.3; the rest
# follow, because Agave pins its own crates to one another exactly. Remove both
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ pub mod create_system_account {
let lamports = Rent::get()?.try_minimum_balance(0)?;

create_account(
CpiContext::new(
CpiContext::<_, 2>::new(
context.accounts.system_program.address(),
CreateAccount {
from: context.accounts.payer.cpi_handle_mut(), // From pubkey
Expand Down
3 changes: 2 additions & 1 deletion basics/cross-program-invocation/anchor/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

> [!NOTE]
> This is the **Anchor v2** copy of this example. Every `anchor` command on this page
> needs the v2 CLI: `cargo install anchor-cli --version 2.0.0-rc.2 --locked` (avm has
> needs the v2 CLI: `cargo install anchor-cli --version 2.0.0-rc.4 --locked` (avm has
> no prebuilt binary for this pre-release). The Anchor v1 version of this example is in
> [`../anchor-v1`](../anchor-v1/).

Expand All @@ -14,6 +14,7 @@ See also: [Cross Program Invocation overview](../README.md) and the [repository

- Cross-program invocation (CPI)
- Composing multiple programs in one transaction
- `declare_program!` CPI functions write the instruction data into a fixed-capacity buffer the caller supplies onchain. `pull_lever` sizes its buffer for a name of up to `MAX_NAME_LEN` (32) bytes and refuses a longer one with `NameTooLong`.

## Setup

Expand Down
Loading
Loading