Llixiwen621

anchor-029-to-030

Automate 80%+ of the Anchor 0.29 → 0.30 migration for Solana Rust programs. Updates Cargo.toml dependencies, fixes Rust API breaking changes, and migrates TypeScript client code.

Public
2 executions

Run locally

npx codemod anchor-029-to-030

Anchor v0.29 → v0.30 Codemod

Automated migration tool for upgrading Solana Anchor projects from v0.29 to v0.30.
Built with ast-grep (sg/jssg engine) + Codemod workflow.

Submitted to the Boring AI Hackathon on DoraHacks.

Quick Start

bash

Version note: this codemod upgrades on-chain crates to anchor-lang / anchor-spl 0.30.1, which matches the commonly installed anchor-cli 0.30.1 patch line and avoids patch-mismatch warnings.

Migration Coverage

Covers all 23 breaking changes from the official Anchor 0.30.0 changelog (release notes); migrate-cargo.sh pins anchor-lang / anchor-spl 0.30.1 to match common anchor-cli 0.30.1 installs:

Automation Boundary (for evaluation)

LayerWhat it handlesEvaluation claim
Deterministic rules/scriptsWell-scoped mechanical rewrites onlyPrimary automation claim (safety first)
AI stepEdge cases, project-specific cleanup, semantic decisionsCoverage extension, not counted as deterministic fix
Manual follow-upRare repo-specific dependency/build reconciliationExplicitly tracked in validation notes

Current practical claim:

  • Deterministic auto-fix: 6 high-confidence migration classes
  • AI-assisted coverage: 11 classes
  • Reminder/separate handling: 6 classes
  • Overall workflow automation target: 80%+ with deterministic + AI pipeline

Auto-fixed (6 items)

ChangeRule / Script
ctx.bumps.get("x").unwrap().copied()anchor-bumps-option-type.yml
AnchorProvider(conn, wallet, {}) → 2 argsanchor-ts-provider-init.yml
new Program(idl, programId[/PROGRAM_ID][, provider]) migrationanchor-ts-program-id-arg-* (4 scoped Program rules)
anchor-lang = "0.29.x"0.30.1 (optional --with-idl-build)migrate-cargo.sh
anchor-spl = "0.29.x"0.30.1migrate-cargo.sh
Remove idl-parse / seeds features + add overflow-checksmigrate-cargo.sh

Marked for AI review (11 items)

ChangeRule / Handler
anchor_spl::shared_memory removedanchor-remove-shared-memory.yml (TODO)
CLOSED_ACCOUNT_DISCRIMINATOR removedanchor-remove-closed-account-discriminator.yml (warning)
anchor_syn::idlanchor_lang_idl importsanchor-idl-import-path.yml (TODO)
Optional account bump types u8Option<u8>AI step
IDL enums #[non_exhaustive]AI step
accounts() no longer accepts resolvable accountsanchor-ts-auto-accounts-system-program, anchor-ts-auto-accounts-clock, anchor-ts-auto-accounts-rent, anchor-ts-auto-accounts-token-program
camelCase method namesAI step
Remove discriminator functionsAI step
Remove associated / associatedAddress methodsAI step
Remove anchor-deprecated-state featureAI step
anchor-syn features removedAI step

Zero-FP Guardrails

  • Program constructor rewrite is now strictly scoped to explicit programId/PROGRAM_ID forms (2-arg and 3-arg with provider); it does not rewrite arbitrary argument forms.
  • .accounts() migration rules are scoped to explicit .accounts({...}) calls only; non-.accounts() object arguments are ignored.
  • Cargo feature cleanup only edits anchor-lang / anchor-syn dependency lines (no global string replacement across unrelated crates).

CLI reminders (4 items)

ChangeHandler
build-bpfbuild-sbfAI step prompt
idl upgrade closes bufferAI step prompt
Remove --jest optionAI step prompt
Solana upgraded to 1.18.8AI step prompt

Separate codemod (2 items)

ChangeHandler
IDL v0 → v1 schema migrationTracked as separate codemod
anchor-syn idl-parse/seeds removalAI step + Cargo.toml sed (anchor-lang/anchor-syn lines)

Project Structure

text

Testing

Synthetic fixtures

bash

Real-world projects (validated)

ProjectGitDry-runApplyBuildNotes
Anchor official v0.29.0 (framework mono-repo)https://github.com/solana-foundation/anchor/tree/v0.29.0PASSPASSFAILWorkflow works, but this repo is Anchor framework source (not a typical target program repo), so build failures are not used as codemod success criteria.
solana-presale-smart-contracthttps://github.com/rustjesty/solana-presale-smart-contractPASSPASSPASS (anchor build --no-idl)Required post-migration dependency cleanup in target repo: remove hard-pinned legacy deps and align to Anchor 0.30 dependency graph.

Validation date: 2026-05-01 (UTC+8)

Command shape used in both real repos:

bash

Local verification in this repository

Verified in this repo (2026-04-30):

  • npx codemod workflow validate -w workflow.yaml passed
  • npx codemod workflow run -w workflow.yaml -t <fixture> --param target=<fixture> --dry-run passed (ast-grep steps + workflow wiring)
  • sg scan --config sgconfig.yml test-fixtures/old_program.rs matched expected Rust patterns
  • sg scan --config sgconfig.yml test-fixtures/old_program.ts matched expected TypeScript patterns

For reproducible real-repo evidence recording, use local template: REAL_WORLD_VALIDATION_TEMPLATE.md.

Safety vs Coverage Modes

  • Safe mode (default script behavior): prioritizes lower false-positive risk; does not force idl-build.
  • Coverage mode (workflow default): workflow.yaml runs migrate-cargo.sh --with-idl-build to align with Anchor 0.30 breaking requirement around IDL build.

Using the Full Workflow

If you have the Codemod CLI installed:

bash

Notes:

  • YAML ast-grep steps expect config_file to point at rule YAML (each rule has a top-level id). That is what lives under rules/. Do not point config_file at sgconfig.yml (that file uses ruleDirs and will fail Codemod parsing with missing field id).
  • Shell steps (migrate-cargo.sh, cargo fmt) run with the host working directory, not -t. Pass the same Anchor repo path for -t and --param target=... so Cargo steps execute inside the project being migrated.

Hackathon

  • Category: Production-grade Migration Recipes (XL tier)
  • Pre-approved: Anchor v0.29 → v0.30 Rust API changes — Changelog
  • Coverage: 23/23 breaking changes mapped (6 deterministic auto-fix + 11 AI-assisted + 6 reminders/separate handling)
  • False-positive policy: deterministic rules are intentionally narrow; zero-FP target applies to deterministic transforms (AI/manual layer handles ambiguous cases)

Evaluator Notes

  • Deterministic transforms are intentionally conservative to minimize false positives on real repositories.
  • Ambiguous or project-specific migration cases are explicitly delegated to the AI/manual layer instead of risky auto-rewrites.
  • Workflow execution is reproducible on real open-source repos with documented dry-run/apply/build evidence.
  • Safety-first defaults are provided for scripts, while workflow mode enables stronger breaking-change coverage when required.

License

MIT

Ready to contribute?

Build your own codemod and share it with the community.