Skip to content

Proposed: PDA generation, compile-time safety, etc#95

Open
ioxde wants to merge 13 commits intocodama-idl:mainfrom
ioxde:solana-v3
Open

Proposed: PDA generation, compile-time safety, etc#95
ioxde wants to merge 13 commits intocodama-idl:mainfrom
ioxde:solana-v3

Conversation

@ioxde
Copy link
Copy Markdown

@ioxde ioxde commented Apr 9, 2026

macalinao and others added 13 commits March 18, 2026 20:08
When an instruction account has a pdaValueNode default (linked or
inline), the builder now auto-derives the address instead of requiring
it to be set explicitly. PDA-defaulted accounts are emitted as
sequential let bindings, topologically sorted by seed dependencies,
so accounts that reference other PDA-defaulted accounts resolve
correctly. Constant seed rendering dispatches by value type: strings
produce b"...", byte arrays &[...], and numbers &Nu64.to_le_bytes().

Bumps @codama/nodes-from-anchor to ^1.4.0 for extractPdasVisitor
support (codama-idl/codama#984).
The generated from_bytes() blindly deserialized without checking that the
discriminator bytes matched, silently accepting wrong account data.
The TryFrom<&AccountInfo> and fetch_* helpers had no owner validation,
and the Anchor AccountDeserialize::try_deserialize defaulted to unchecked
deserialization with no discriminator gate.

- from_bytes() now rejects data with a mismatched discriminator prefix
- TryFrom<&AccountInfo> checks account_info.owner before deserializing
- fetch_all_* and fetch_all_maybe_* check account.owner before deserializing
- TryFrom delegates to from_bytes() instead of duplicating deserialization
- Anchor try_deserialize checks the discriminator before calling unchecked
- Anchor Discriminator trait uses the real constant instead of [0; 8]
…rams

Move required accounts (no defaults, not IDL-optional) and required args
(no defaults, not Option types) from Option fields with setter methods
into mandatory constructor parameters on both Builder and CpiBuilder.
This shifts missing-field errors from runtime .expect() panics to
compile-time type errors.

Accounts with defaults (PDA, publicKey, programId) remain optional with
setters. PDA seed resolution uses direct field access for required fields
instead of .expect(). programIdValueNode accounts unwrap with the
program's own ID as fallback.
@changeset-bot
Copy link
Copy Markdown

changeset-bot bot commented Apr 9, 2026

🦋 Changeset detected

Latest commit: b0994c5

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@codama/renderers-rust Minor

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

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.

2 participants