feat: resolve PDA defaults in instruction account builders#93
feat: resolve PDA defaults in instruction account builders#93amilz wants to merge 2 commits intocodama-idl:mainfrom
Conversation
Extract PDA resolution into a dedicated helper function with proper error handling: warn on unresolvable PDA nodes, bail entirely on missing seed values (instead of silently generating incomplete seeds), and propagate circular dependency fallbacks to all affected nodes. Also adds rawName to account-ref seeds so the template avoids fragile string surgery, removes a spurious `use solana_address;` import, and adds tests for programIdValueNode seeds, bytesTypeNode seeds, linked PDAs with variable account seeds, circular dependencies, and optional+PDA default interaction.
When a pdaLinkNode resolves to a PDA, use the corresponding account struct's name for the find_pda() call — since find_pda is generated on account structs, not PDA nodes. Falls back to inline find_program_address when no account references the PDA. Fixes broken codegen when PDA name differs from account name (e.g. "extensions" PDA vs "escrowExtensionsHeader" account) and when a PDA has no corresponding account struct at all.
|
|
I've built something similar on top of v2.0.1 (Solana v3 dependencies aren't currently compatible with my repo) and having #23 as the base. I've integrated your code patterns and bug fixes as well. ioxde/main- 718eedf I haven't had time to work out a proper PR (among other changes) because of the different base / current needs- but wanted to share this if it would help in anyway. |
Summary
.expect()/ manual settingAccountName::find_pda(...)find_program_addressresolveInstructionPdaDefaults()helperBug fixes included
returninsideseeds.forEachonly skipped one seed but registered the PDA with incomplete seeds → wrong address at runtime. Now bails the entire PDA resolution with a warning.find_pda: Used the PDA node name instead of the account struct name. Broke when they differed (e.g.extensionsPDA vsescrowExtensionsHeaderaccount) or when no account existed for the PDA.use solana_address;bare crate import removed.logWarnfor unresolvable PDA nodes and missing seed values.Generated output examples
creates_escrowbuilder —escrowandevent_authorityauto-derive via linkedfind_pda:depositbuilder — mixed resolution: linkedfind_pdafor accounts with structs, inlinefind_program_addressfor cross-program ATAs:Docblock — PDA-defaulted accounts marked optional:
Test plan
dummy,system,memo,anchor)