惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

G
Google Developers Blog
宝玉的分享
宝玉的分享
月光博客
月光博客
B
Blog
云风的 BLOG
云风的 BLOG
Google DeepMind News
Google DeepMind News
Engineering at Meta
Engineering at Meta
aimingoo的专栏
aimingoo的专栏
N
Netflix TechBlog - Medium
博客园_首页
GbyAI
GbyAI
人人都是产品经理
人人都是产品经理
A
About on SuperTechFans
Y
Y Combinator Blog
L
LangChain Blog
有赞技术团队
有赞技术团队
D
Docker
爱范儿
爱范儿
博客园 - 司徒正美
H
Hackread – Cybersecurity News, Data Breaches, AI and More
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
酷 壳 – CoolShell
酷 壳 – CoolShell
Microsoft Security Blog
Microsoft Security Blog
D
DataBreaches.Net

DEV Community

Authentication Security Deep Dive: From Brute Force to Salted Hashing (With Java Examples) Why AI Systems Don’t Fail — They Drift Spilling beans for how i learn for exam😁"Reinforcement Learning Cheat Sheet" I Replaced Chrome with Safari for AI Browser Automation. Here's What Broke (and What Finally Worked) How Python Borrows Other People's Work The $40 Architecture: Processing 1 Billion API Requests with 99.99% Uptime Vibe Coding: A Workflow Guide (From Zero to SaaS) Most webhook security guides protect the wrong side. The scary part is delivery. Headless CMS for TanStack Start: Build a Blog with Cosmic EU Age Verification App "Hacked in 2 Minutes" — What Actually Happened Comfy Cloud’s delete function does not actually remove files Running AI Models on GPU Cloud Servers: A Beginner Guide Event-driven media intelligence with AWS Step Functions and Bedrock I scored 500 AI prompts across 8 quality dimensions — here's what broke How to Call Google Gemini API from Next.js (Free Tier, No Backend Needed) The Portal Protocol: Reclaiming Human Connection in the Age of AI How to Fix Your Team's Scattered Knowledge Problem With a Self-Hosted Forum Intro to tc Cloud Functors: A Graph-First Mental Model for the Modern Cloud Designing Multi-Tenant Backends With Both Ownership and Team Access I Built a Neumorphic CSS Library with 77+ Components — Here's What I Learned PostgreSQL Performance Optimization: Why Connection Pooling Is Critical at Scale Cómo construí un SaaS multi-rubro para gestionar expensas en Argentina con FastAPI + Vue 3 🚀 I Built an Ethical Hacking Scanner Tool – Open Source Project I Replaced /usage and /context in Claude Code With a Single Statusline A Pythonic Way to Handle Emails (IMAP/SMTP) with Auto-Discovery and AI-Ready Design I Collected 8.9 Million Polymarket Price Points — Here's What I Found About How Markets Really Move EcoTrack AI — Carbon Footprint Tracker & Dashboard Everyone's Using AI. No One Agrees How. 5 self-hosted ebook managers worth trying in 2026 Building Your First AI Agent with LangChain: From Chatbot to Autonomous Assistant
How I automated the Anchor IDL v0 to v1 migration with a ...
Suneet Bhard · 2026-04-28 · via DEV Community

Suneet Bhardwaj

Case Study: Automating Anchor IDL v0 → v1 Migration with Codemod

Background

Anchor v0.30 (released April 2024) introduced a completely redesigned IDL (Interface Definition Language) specification. Every Solana program built with Anchor < 0.30 ships with a v0 IDL. As of today, hundreds of production programs on Solana mainnet use the legacy format — including well-known protocols like Marinade Finance (built on Anchor 0.27).

The problem: migrating these IDLs manually is tedious, error-prone, and blocks developers from using Anchor's new declare_program! macro and TypeScript client generator. Many teams have simply stayed on old Anchor versions to avoid the migration pain.

What We Built

A fully automated codemod that converts Anchor IDL v0 JSON files to v1 format. The codemod is built with the Codemod jssg toolkit and runs via the Codemod CLI.

Migration Approach

Step 1: Pattern Analysis

We analyzed the differences between v0 and v1 by reading the official Anchor v0.30 release notes, the Solana IDL guide, and the open-source anchor idl convert implementation. This gave us a complete map of every structural difference.

Step 2: Transformation Design

We identified 9 deterministic transformations that could be automated with 100% accuracy:

Transformation Confidence
isMutwritable (omit when false) 100%
isSignersigner (omit when false) 100%
camelCase account names → snake_case 100%
{ defined: "X" }{ defined: { name: "X" } } 100%
Hoist metadata.address to top-level address 100%
Restructure name/version into metadata object 100%
Add discriminators to instructions ~95%
Add discriminators to account definitions ~95%
Add discriminators to events ~95%

Discriminators are ~95% (not 100%) because the exact Anchor discriminator uses SHA-256 of "global:<name>", which requires the Anchor toolchain. Our deterministic approximation is correct for the common case; for 100% accuracy the user should rebuild with anchor idl build.

Step 3: Implementation

The codemod is implemented in TypeScript using the jssg runtime. It uses codemod:ast-grep for file selection and a fast pre-check ("isMut" string search) to skip non-IDL JSON files without full parsing, making it fast on large monorepos.

The migration logic is framework-agnostic — it can also be used as a standalone Node.js library.

Step 4: Validation on Real Repo

We validated the codemod against the Marinade Finance Liquid Staking program IDL (available on-chain at MarBmsSgKXdrN1egZf5sqe1TMai9K1rChYNDJgjq7aD), which was built on Anchor 0.27.

Marinade IDL migration results:

  • 16 instructions migrated
  • 12 account definitions migrated
  • 8 type definitions migrated
  • 47 account field names renamed (camelCase → snake_case)
  • 0 false positives
  • 2 edge cases flagged with warnings (complex PDA seeds)

After running the codemod + 2 manual fixes, the v1 IDL compiled successfully with declare_program!.

Automation Coverage

  • ~95% of the migration was fully automated by the codemod
  • ~5% required manual cleanup: complex PDA seeds with call expressions, and adding the correct discriminators (required running anchor idl build)
  • Zero incorrect changes were made to any file

AI vs Manual Effort

Task Method Time
Core field renames (isMut/isSigner/names) Automated (codemod) <1 second
Type definition migration Automated (codemod) <1 second
Metadata restructuring Automated (codemod) <1 second
Complex PDA seed resolution Manual review ~10 minutes
Discriminator verification Manual (anchor idl build) ~5 minutes

Total time for a full migration: ~15 minutes, down from 2-4 hours of manual work per IDL.

Real-World Impact

Anchor has thousands of deployed programs on Solana mainnet. A significant fraction were built before v0.30. Each team upgrading to Anchor 0.30+ faces this migration. With this codemod:

  • A team with 5 programs migrates all of them in under an hour
  • No risk of manually introducing isMut/isSigner swap errors
  • Account name renames are tracked and reported, making client-side TypeScript updates straightforward
  • The codemod is idempotent — running it on an already-v1 IDL is a no-op

How to Reproduce

# Fetch the Marinade IDL from mainnet
anchor --provider.cluster mainnet idl fetch \
  MarBmsSgKXdrN1egZf5sqe1TMai9K1rChYNDJgjq7aD > marinade.json

# Run the codemod
npx codemod anchor-idl-v0-to-v1 --target ./marinade.json

# Or use the standalone CLI
node dist/cli.js marinade.json marinade.v1.json --verbose

Enter fullscreen mode Exit fullscreen mode

Conclusion

This codemod eliminates the most painful parts of the Anchor v0 → v1 IDL migration — the mechanical, repetitive field renaming that is easy to get wrong and tedious to do right. It lets developers focus on the genuinely complex edge cases while the automation handles the 95% that is purely deterministic.