feat: add idl-history command for extracting historical Anchor IDL versions#1
Open
serejke wants to merge 2 commits into
Open
feat: add idl-history command for extracting historical Anchor IDL versions#1serejke wants to merge 2 commits into
serejke wants to merge 2 commits into
Conversation
…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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
idl-historycommand to extract and store historical Anchor IDL versions for Solana programsTransactionProvidertrait for better abstractionKey Features
anchor:idlseed patternUsage