Skip to content

[2.x] Adapt dynamic-address-resolution to Codama v2 - #1192

Merged
lorisleiva merged 1 commit into
mainfrom
09-29-adapt_dynamic-address-resolution_to_codama_v2
Sep 30, 2026
Merged

lorisleiva merged 1 commit into
mainfrom
09-29-adapt_dynamic-address-resolution_to_codama_v2

Conversation

@lorisleiva

@lorisleiva lorisleiva commented Sep 29, 2026 •

Copy link
Copy Markdown
Member

This PR adapts @codama/dynamic-address-resolution to Codama v2.

  • resolveInstructionAccountAddress takes the path of the instruction account and resolveStandalonePda the path of the PDA, from which links and injected values are resolved.
  • argumentsInput becomes dataInput, using the value format of @codama/dynamic-codecs. dataValueNode defaults and seeds resolve nested paths such as config.owner, using the default value of each field along the path, including parent fields, the same way their codec encodes them.
  • Custom resolvers are removed, following the removal of resolverValueNode. Accounts without default values must be provided.
  • The input transformer and default value encoder are removed in favour of the codecs of @codama/dynamic-codecs, which now accept these inputs. PDA seeds are encoded with their declared type, and missing option seeds encode as None.
  • Supports injectedValueNode, programLinkNode and pdaValueNode.programId defaults, as well as PDAs of other programs.
  • Conditions compare values across representations, e.g. 2 and integerValueNode('2'), and pass when their condition exists when they have no value.
  • Generated types follow the renderers-js conventions: ${Name}InstructionDataArgs, ${Pda}Seeds, and remaining accounts as named account lists in ${Name}Accounts.
  • Renames the DYNAMIC_CLIENT__ARGUMENT_MISSING error to DYNAMIC_CLIENT__DATA_MISSING, adds DYNAMIC_CLIENT__PDA_SEED_MISSING, and deprecates the resolver errors.

@changeset-bot

changeset-bot Bot commented Sep 29, 2026 •

Copy link
Copy Markdown

⚠️ No Changeset found

Latest commit: 9c01248

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

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

@lorisleiva

Copy link
Copy Markdown
Member Author

@trevor-cortex

@trevor-cortex trevor-cortex left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Summary

Adapts @codama/dynamic-address-resolution to the v2 node model. The big structural shift is that callers now pass a NodePath ([root, program, instruction, account] / [root, program, pda]) instead of root + ixNode + ixAccountNode, which lets the package reuse LinkableDictionary, ProvidedScope and resolveTypePath from core rather than hand-rolling link resolution. All the bespoke encoding machinery (codec-input-transformer, default-value-encoder, value-node-value, bytes-encoding, codecs) is deleted in favour of getNodeValueCodecVisitor / getValueNodeVisitor from @codama/dynamic-codecs, and resolverValueNode support goes away with the node. Net −3.3k lines, and the new context.ts + slimmed-down derivePda are much easier to follow than what they replace.

I read every source file and the main test files. The logic checks out: getDataValue correctly gets a structFieldTypeNode back from resolveTypePath (it returns the last node "as addressed"), the ProvidedScope frame ordering in getProvidedScope is parents-first as the class expects, and the WeakMap linkables cache keyed on root is a nice touch. Tests cover the new behaviours well (cross-program PDA links, pdaValueNode.programId from data/accounts, nested data paths, field defaults, injected values, enum/integer condition comparison).

Things to watch

  • Constant programIdValueNode seeds now encode the resolved program address (derivePda L92–94), i.e. the pdaValueNode.programId override when present, not the PDA's defining program. This matches what renderers-js does with its programAddress parameter, so I believe it's the right call — just flagging it as a deliberate semantic since v1 always used the PDA's own program.
  • Condition without value now uses !== undefined && !== null rather than truthiness, so 0, false and '' pass. The description calls this out; just noting it's a behaviour change from v1.
  • @codama/dynamic-client still imports removed symbols (ArgumentsInput, CODAMA_ERROR__DYNAMIC_CLIENT__ARGUMENT_MISSING) and the old resolveInstructionAccountAddress shape. It was already broken by the errors rename before this PR, so I assume it's excluded from CI on this branch and adapted in the next PR of the stack — worth confirming.
  • is-account-auto-resolvable.ts is untouched. accountDataValueNode is now in ACCOUNT_DEFAULT_VALUE_SUPPORTED_NODE_KINDS but throws UNSUPPORTED_NODE, and injectedValueNode only resolves when a parent provides the key — yet codegen still marks both as ? (omittable). Pre-existing for accountBumpValueNode, so fine as a follow-up, but the generated types will over-promise for those three kinds.
  • No changeset. CONTRIBUTING says user-facing changes need one; if the seeded v2 major changeset is meant to cover all adaptation PRs on this branch, ignore this — otherwise the README-level API rename (argumentsInput → dataInput, path, removed exports) probably deserves a line.

Inline comments below are all non-blocking suggestions.

For subsequent reviewers

  • getDataValue in src/resolvers/context.ts is the linchpin for dataValueNode defaults, seeds and conditions — worth a close read of the omitted / default-value fallback ordering.
  • isValueEqual in src/shared/util.ts defines cross-representation equality for conditions; check the enum handling matches whatever shapes getValueNodeVisitor actually emits in @codama/dynamic-codecs.

Comment thread packages/dynamic-address-resolution/src/resolvers/resolve-pda-address.ts Outdated
Comment thread packages/dynamic-address-resolution/src/resolvers/context.ts Outdated
Comment thread packages/dynamic-address-resolution/src/shared/util.ts
@lorisleiva
lorisleiva force-pushed the 09-29-adapt_dynamic-address-resolution_to_codama_v2 branch from bbdd5f5 to 803123b Compare September 29, 2026 13:49

@trevor-cortex trevor-cortex left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Re-review

Re-fetched every changed source file and the affected tests. All six inline points from my first pass have been addressed, and the fixes are clean:

  • null option seeds — derivePda now only treats undefined as missing and, for OPTIONAL_NODE_KINDS, encodes null (i.e. None) instead of throwing PDA_SEED_MISSING. Tests added for optionTypeNode, zeroableOptionTypeNode and remainderOptionTypeNode, matching the T | null the generated ${Pda}Seeds type already advertised.
  • as string cast for pdaValueNode.programId — replaced with a shared toAddressOrThrow helper in shared/address.ts that runs isAddressConvertible and raises UNEXPECTED_ADDRESS_TYPE, and account-default-value.ts now uses the same helper. Nice consolidation.
  • Nested default lookup — getDataValue now walks the path with getStructFieldValue, applying each field's defaultValue along the way (so config.owner reads owner out of config's struct default when config is absent), and respects omitted fields. Docblock explains the behaviour. Test added for the parent-default case.
  • Uint8Array in isValueEqual — explicit branch comparing byte-wise, with tests.
  • getResolutionRefs on unresolvable links — falls back to ix.data itself so hasData/hasRequiredData are still correct; the unresolvable-link test now asserts dataRef is set.
  • Value-less condition on unprovided account — visitAccountValue in condition-node-value.ts now returns undefined when the account is neither provided nor has a default, so ifFalse is reachable; tests cover both branches.

Also new since last pass: isAccountAutoResolvable was updated so accountBumpValueNode, accountDataValueNode and injectedValueNode are no longer treated as auto-resolvable (with tests), so the generated types stop over-promising for those kinds. That closes the follow-up I flagged in the review body.

Nothing new to flag. The remaining open items from the first review (the dynamic-client compile break, changeset coverage) are stack-level and unchanged — still assuming they land in a later PR.

Approving.

@lorisleiva
lorisleiva force-pushed the 09-29-adapt_dynamic-address-resolution_to_codama_v2 branch from 803123b to f4b10ab Compare September 30, 2026 13:54
@lorisleiva
lorisleiva force-pushed the 09-29-accept_bytes_enum_shorthands_and_struct_defaults_when_encoding_dynamic_codecs branch from 9c91444 to 81bd5ed Compare September 30, 2026 13:54
@lorisleiva
lorisleiva force-pushed the 09-29-adapt_dynamic-address-resolution_to_codama_v2 branch from f4b10ab to ef341d9 Compare September 30, 2026 14:07
@lorisleiva
lorisleiva force-pushed the 09-29-adapt_dynamic-address-resolution_to_codama_v2 branch from cb8dd0b to 45c081b Compare September 30, 2026 14:12
@lorisleiva
lorisleiva force-pushed the 09-29-accept_bytes_enum_shorthands_and_struct_defaults_when_encoding_dynamic_codecs branch from 5acfda4 to 1e5a11f Compare September 30, 2026 14:12
@lorisleiva
lorisleiva force-pushed the 09-29-adapt_dynamic-address-resolution_to_codama_v2 branch from 45c081b to e3bfabb Compare September 30, 2026 14:13
@lorisleiva
lorisleiva force-pushed the 09-29-accept_bytes_enum_shorthands_and_struct_defaults_when_encoding_dynamic_codecs branch from 1e5a11f to 94bf7c5 Compare September 30, 2026 14:13
@lorisleiva
lorisleiva force-pushed the 09-29-adapt_dynamic-address-resolution_to_codama_v2 branch from 45c081b to e3bfabb Compare September 30, 2026 14:13
@lorisleiva
lorisleiva force-pushed the 09-29-accept_bytes_enum_shorthands_and_struct_defaults_when_encoding_dynamic_codecs branch from 1e5a11f to 94bf7c5 Compare September 30, 2026 14:13
@lorisleiva
lorisleiva force-pushed the 09-29-adapt_dynamic-address-resolution_to_codama_v2 branch from e3bfabb to 97d1f4c Compare September 30, 2026 14:14
@lorisleiva
lorisleiva force-pushed the 09-29-accept_bytes_enum_shorthands_and_struct_defaults_when_encoding_dynamic_codecs branch from 94bf7c5 to 59d18a6 Compare September 30, 2026 14:14
@lorisleiva
lorisleiva force-pushed the 09-29-adapt_dynamic-address-resolution_to_codama_v2 branch from 97d1f4c to 9812253 Compare September 30, 2026 14:15
@lorisleiva
lorisleiva force-pushed the 09-29-accept_bytes_enum_shorthands_and_struct_defaults_when_encoding_dynamic_codecs branch from 59d18a6 to 3210487 Compare September 30, 2026 14:15
@lorisleiva
lorisleiva force-pushed the 09-29-adapt_dynamic-address-resolution_to_codama_v2 branch from 9812253 to fcd8c62 Compare September 30, 2026 14:16
@lorisleiva
lorisleiva force-pushed the 09-29-accept_bytes_enum_shorthands_and_struct_defaults_when_encoding_dynamic_codecs branch 2 times, most recently from 9b81b4a to 517ca2f Compare September 30, 2026 14:17
@lorisleiva
lorisleiva force-pushed the 09-29-adapt_dynamic-address-resolution_to_codama_v2 branch from fcd8c62 to 375cb5e Compare September 30, 2026 14:17
@lorisleiva
lorisleiva force-pushed the 09-29-accept_bytes_enum_shorthands_and_struct_defaults_when_encoding_dynamic_codecs branch from 517ca2f to 4043eca Compare September 30, 2026 14:18
@lorisleiva
lorisleiva force-pushed the 09-29-adapt_dynamic-address-resolution_to_codama_v2 branch 2 times, most recently from 36c98ff to af66e5f Compare September 30, 2026 14:18
@lorisleiva
lorisleiva force-pushed the 09-29-accept_bytes_enum_shorthands_and_struct_defaults_when_encoding_dynamic_codecs branch from 4043eca to e540f66 Compare September 30, 2026 14:18
@lorisleiva
lorisleiva force-pushed the 09-29-adapt_dynamic-address-resolution_to_codama_v2 branch from af66e5f to 608b4bd Compare September 30, 2026 14:19
@lorisleiva
lorisleiva force-pushed the 09-29-accept_bytes_enum_shorthands_and_struct_defaults_when_encoding_dynamic_codecs branch from e540f66 to 2fe5e55 Compare September 30, 2026 14:19
@lorisleiva
lorisleiva force-pushed the 09-29-adapt_dynamic-address-resolution_to_codama_v2 branch from 608b4bd to 1ef2655 Compare September 30, 2026 14:20
@lorisleiva
lorisleiva force-pushed the 09-29-accept_bytes_enum_shorthands_and_struct_defaults_when_encoding_dynamic_codecs branch 2 times, most recently from 83e5377 to 6f075e0 Compare September 30, 2026 14:21
@lorisleiva
lorisleiva force-pushed the 09-29-adapt_dynamic-address-resolution_to_codama_v2 branch from 1ef2655 to 9c01248 Compare September 30, 2026 14:21
Base automatically changed from 09-29-accept_bytes_enum_shorthands_and_struct_defaults_when_encoding_dynamic_codecs to main September 30, 2026 14:21
@lorisleiva
lorisleiva force-pushed the 09-29-adapt_dynamic-address-resolution_to_codama_v2 branch from 9c01248 to 4d1c3d7 Compare September 30, 2026 14:21
@lorisleiva
lorisleiva marked this pull request as ready for review September 30, 2026 14:22
@lorisleiva
lorisleiva merged commit 8314b0b into main Sep 30, 2026
0 of 2 checks passed
@lorisleiva
lorisleiva deleted the 09-29-adapt_dynamic-address-resolution_to_codama_v2 branch September 30, 2026 14:22
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