Skip to content

Bring the Anchor v1 copies in line with v2 where the Anchor version allows - #163

Merged
mikemaccana merged 3 commits into
mainfrom
claude/kind-pasteur-2sw8p5
Sep 23, 2026
Merged

mikemaccana merged 3 commits into
mainfrom
claude/kind-pasteur-2sw8p5

Conversation

@mikemaccana

Copy link
Copy Markdown
Collaborator

Summary

CONTRIBUTING.md now says the anchor-v1/ copies differ from their v2 counterparts only where the Anchor version forces it (#156). This PR applies that rule to one known case, the interest-bearing helper, and to everything a scan of all v1/v2 pairs turned up.

Changes

Interest-bearing (first commit). v2 split check_mint_data into check_rate_authority, which takes the parsed InterestBearingConfig. v2 needed that because of its exclusive borrows (44f7c35); only the parsing route is forced. The v1 copy now has the same helper, name and signature, and its handlers parse the extension with anchor-spl's get_mint_extension_data.

Drift scan fixes (second commit).

  • Transfer-hook counter and account-data-as-seed (a real bug). The v1 copies still had the bug v2 fixed in 14847e8. The hook added one to the stored count, logged it, and dropped it, because counter_account wasn't mut. The count read one after every transfer. This ports the fix:
    • the mut constraint and the write-back
    • a new CounterOverflow error for the checked add, which previously reused AmountTooBig
    • a test assertion that reads the stored count after the hooked transfer
  • Account field visibility. Fields that v2 declares pub are now pub in the v1 copies of account-data, checking-accounts, program-derived-addresses, rent, transfer-sol and nft-operations. The other v1 examples already did this.
  • Order book. OrderTreeRoot derives Default as in v2, replacing a hand-written impl that clippy flagged as derivable.

How the scan worked

  1. For every anchor/ + anchor-v1/ pair, I compared the sets of function names, #[error_code] variants, pub fields, constants and seed strings in the program source, plus the test names.
  2. I listed every non-merge commit since July that changed a v2 program's source without touching its v1 copy. Then I checked the behavior-changing ones against v1: vault-strategy's allocation, MAX_ASSETS and ApprovedAsset, lending's index names, and nft-minter's update_authority_is_signer, plus the handler-adding commits. All of these were already in v1 or expressed through v1's own API.

The remaining differences are all forced by the Anchor version; the root changelog lists them:

  • v2's transfer-hook entrypoint fallback
  • a local session-token reader replacing the v1-only session-keys crate
  • the last_restart_slot syscall wrapper (v1 does the same check through the sysvar)
  • the wincode span in rent
  • zero-copy padding
  • the Pyth account traits
  • the betting market's borrow-release helper
  • v2's borrow-model fixes (44f7c35, eff9f03, 16d30e4)

Verification

  • Every touched v1 copy and its tests compile with no errors.
  • Clippy warning counts match main in each copy. The order book goes from 10 to 9, because the flagged impl is gone.
  • Not run locally: the LiteSVM suites, which need the SBF build. This PR's Anchor v1 CI job runs them.

🤖 Generated with Claude Code

https://claude.ai/code/session_01F8Wo5zNLqZ2NQqSjGD7WpK


Generated by Claude Code

…helper

v2 split check_mint_data into check_rate_authority, which takes the parsed
InterestBearingConfig, because v2's exclusive borrows made the old
read-the-account helper need unsafe. Only that parsing route is forced by the
Anchor version. The v1 copy now has the same helper, name and signature, and
its handlers parse the extension with anchor-spl's get_mint_extension_data.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01F8Wo5zNLqZ2NQqSjGD7WpK
A scan of every anchor/anchor-v1 pair (function names, error variants,
account fields, constants, seeds) and of every v2 program commit since July
that left its v1 copy untouched found:

- transfer-hook counter and account-data-as-seed: port 14847e8. The hook
  dropped the incremented count because counter_account was not mut, so it
  read one after every transfer. Write it back, add CounterOverflow for the
  checked add, and assert the stored count in the tests.
- account fields v2 declares pub are pub in the v1 copies of account-data,
  checking-accounts, program-derived-addresses, rent, transfer-sol and
  nft-operations.
- order-book: derive Default on OrderTreeRoot like v2, dropping the
  hand-written impl.

The remaining differences are forced by the Anchor version and are listed in
the changelog.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01F8Wo5zNLqZ2NQqSjGD7WpK
Keeps both 2026-09-23 changelog entries.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01F8Wo5zNLqZ2NQqSjGD7WpK
@mikemaccana
mikemaccana merged commit 8e95f8e into main Sep 23, 2026
35 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants