Skip to content

feat: add idl-history command for extracting historical Anchor IDL versions#1

Open
serejke wants to merge 2 commits into
tryghostxyz:mainfrom
serejke:feature/idl-history-squashed
Open

feat: add idl-history command for extracting historical Anchor IDL versions#1
serejke wants to merge 2 commits into
tryghostxyz:mainfrom
serejke:feature/idl-history-squashed

Conversation

@serejke
Copy link
Copy Markdown

@serejke serejke commented Jan 19, 2026

Summary

  • Add idl-history command to extract and store historical Anchor IDL versions for Solana programs
  • Refactor transaction types with TransactionProvider trait for better abstraction

Key Features

  • IDL Account Discovery: Derive Anchor IDL account addresses using the canonical anchor:idl seed pattern
  • Version Detection: Identify IDL versions through Create and SetBuffer instructions
  • IDL Reconstruction: Reassemble IDL content from Write instruction sequences
  • Buffer Handling: Track SetBuffer instructions and extract buffer addresses
  • Decompression: Handle zlib-compressed IDL data

Usage

./target/release/gg-program-resurrect idl-history --program 6EF8rrecthR5Dkzon8Nwu78hRvfCKubJ14M5uBEwF6P --output ./idl-versions

…rsions

Adds support for fetching and storing historical IDL versions for Solana
programs using Anchor-style IDL accounts.

## Key Features

- **IDL Account Discovery**: Derive Anchor IDL account addresses using the
  canonical `anchor:idl` + program_id seed pattern
- **Version Detection**: Identify IDL versions through Create and SetBuffer
  instructions (intermediate Writes are part of sequences, not versions)
- **IDL Reconstruction**: Reassemble IDL content from Write instruction
  history, handling the append-only write pattern
- **Buffer Handling**: Track SetBuffer instructions and extract buffer
  addresses for buffer-based IDL updates
- **Decompression**: Handle zlib-compressed IDL data with proper header
  parsing (8-byte header: 4-byte length + 4-byte discriminator)
- **Storage**: Save versions as {slot}.json in output directory

## Implementation Details

The extraction algorithm handles two distinct update patterns:

1. **Create Operations**: IDL Writes occur at slots >= create_slot and
   < next_version_slot (Writes come AFTER Create)
2. **SetBuffer Operations**: IDL content is fetched from the buffer account
   set during the transaction

Key correctness fixes included:
- Only Create and SetBuffer mark version boundaries (not Writes)
- Verify instruction variant before extracting buffer addresses
- Use position-based tracking instead of slot-only for proper ordering

## Module Structure

Organized into `src/core/idl/` directory:
- address.rs: IDL account address derivation
- buffer.rs: SetBuffer operation handling
- constants.rs: Header sizes, discriminators, variants
- decompression.rs: Zlib decompression utilities
- events.rs: Event collection and version tracking
- extraction.rs: Main IDL extraction orchestrator
- instruction.rs: Instruction parsing and classification
- types.rs: Type definitions (IdlModificationType, IdlEvent, etc.)
- writes.rs: Write instruction handling and reconstruction

## New Files

- src/commands/idl_history.rs: Command implementation
- src/core/idl/*.rs: IDL extraction logic modules
- docs/ANCHOR_IDL_INTERNALS.md: Technical documentation
…n types

- Add TransactionProvider trait for abstracting transaction fetching
- Rename HeliusTx to ParsedTransaction and HeliusInstruction to ParsedInstruction
- Make transaction_index optional (REST API doesn't provide it)
- Add HeliusTransaction/HeliusInstruction for Helius-specific response parsing
- Update slot-based tracking to position-based (SlotPosition) throughout
- Extract SlotPosition to its own module
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.

1 participant