feat: atas & other well known programs#83
Closed
amilz wants to merge 2 commits intocodama-idl:mainfrom
Closed
Conversation
Add SetWellKnownProgramsVisitor that scans the final RootNode for
ProgramLinkNode references in instruction default values and auto-injects
matching well-known programs (associatedToken, system, token, token2022,
memo) into additional_programs. Runs by default in DefaultPlugin — no
extra configuration needed.
Add ata() shorthand syntax for associated token PDA default values:
ata(account("owner"), account("tokenProgram"), account("mint"))
which expands to the equivalent PdaValueNode with fixed seed names.
Move SetWellKnownProgramsVisitor tests from inline #[cfg(test)] to tests/set_well_known_programs_visitor.rs to match the existing pattern where all visitor tests live in the tests/ directory.
Contributor
Author
|
replaced with #84 |
Member
|
@amilz I can find some time next week to create that |
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.
SetWellKnownProgramsVisitorruns automatically inDefaultPlugin.on_root_node_set()afterCombineModulesVisitor. Scans the finalRootNodeforProgramLinkNodereferences in instruction default values and injects matching well-known programs intoadditional_programsif not already present. Zero config — no extra plugin, no boilerplate struct.ata()shorthand directive: Simple handler for associated token PDA default values. Takes 3 positional seed values and hardcodes the fixed seed names (owner,tokenProgram,mint) and program link automatically.associatedToken,system,token,token2022,memo— with addresses and PDAs. Easy to extend.Before / After
The
pda(...)syntax still works if you need full control:Design decisions
DefaultPluginrather than a standalone plugin since ATA is ubiquitous in Solana programs — adding a separateadd_plugin()call for something almost everyone needs would defeat the zero-config goal.ata()takes positional seed values (not named seeds) — the seed names are alwaysowner/tokenProgram/mintfor an ATA, so the shorthand hardcodes them.CombineModulesVisitorso it sees the fully assembled tree. It only injects programs that are (a) referenced and (b) not already present.ata()— if you need a custom ATA-like program, usepda()directly. Keeps the shorthand opinionated and simple (I've never once seen anyone override ATA program).default_value = program("system")etc. — if aProgramLinkNodereference exists but the program isn't in the tree, the visitor injects it with the correct address.Test plan
cargo test -p codama-korok-visitors— 15 integration tests intests/set_well_known_programs_visitor.rs(injection of each program, deduplication, unknown refs ignored, sub-instruction traversal, multiple programs, argument/extra_argument collection, additional programs)cargo test -p codama-attributes— 8 inline unit tests for ata parser (positional seeds, different account names, argument seeds, mixed types, error cases)cargo test -p codama-korok-plugins— plugin integrationassociatedTokenprogramLMK what you think @lorisleiva