feat(dynamic-client): extract dynamic-address-resolution#996
Conversation
* feat: extract dynamic-address-resolution * feat: add dynamic-address-resolution to dynamic-client - Cleaned dynamic-client from dynamic-address-resolution files - Hook dynamic-address-resolution, fix imports * chore: re-build custom idls * fix: cleanup * feat: export DEFAULT_VALUE_ENCODER_SUPPORTED_NODE_KINDS from dynamic-address-resolution * fix: types import * fix: async describe * fix: cleanup
🦋 Changeset detectedLatest commit: 5d6add5 The changes in this PR will be included in the next version bump. This PR includes changesets to release 2 packages
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 |
trevor-cortex
left a comment
There was a problem hiding this comment.
Summary
Extracts address resolution out of @codama/dynamic-client into a new @codama/dynamic-address-resolution package, with the dynamic-client code now consuming it. Most of the diff is renames (packages/dynamic-client/... → packages/dynamic-address-resolution/...) with import path updates, a few function/type renames (isConvertibleAddress → isAddressConvertible, createInputValueTransformer → createCodecInputTransformer, deriveStandalonePDA → resolveStandalonePda), and the introduction of generics (TAccounts, TArgs, TResolvers) across the resolution pipeline so generated client types can flow through.
New public surface is curated in src/index.ts: resolveInstructionAccountAddress, resolveStandalonePda, two visitor factories, and a small set of address helpers. Package config mirrors the existing dynamic-* packages (tsup, multi-target exports, sideEffects: false, treeshakability test, workspace deps).
Overall the move is mechanical and clean. A few things worth a closer look below.
Things to watch
-
deriveStandalonePDA→resolveStandalonePdais a rename that isn't called out. The PR description only lists theisConvertibleAddressandcreateInputValueTransformerrenames, butderiveStandalonePDAis also renamed. If@codama/dynamic-clientpreviously re-exportedderiveStandalonePDAfrom its public API, this is a breaking change there and thepatchbump ondynamic-clientin.changeset/neat-badgers-heal.mdwould be wrong (should beminorpre-1.0, ormajorif you've passed 1.0). Worth double-checking whether anything outside this repo was importing the old name. -
resolvePDAAddressdropped the= {}defaults foraccountsInput/argumentsInput. Previously the function defaulted these to{}; now they propagate through asundefinedfrom the newBaseResolutionContexttyping. Most downstream lookups use?.[name]so this is safe, but it's a behavioural change worth confirming is intentional — particularly anywhere the values are spread or iterated rather than indexed. -
Per-package memoized codecs.
src/shared/codecs.tskeeps its own module-level cache, which is now distinct from any equivalent cache indynamic-codecs/dynamic-client. Apps loading multiple of these packages will end up with one codec instance per package. Almost certainly fine, just noting it. -
src/index.tsexportsDEFAULT_VALUE_ENCODER_SUPPORTED_NODE_KINDSin addition to the two visitor factories, but the PR description's "Public API" block omits it. Either trim the export or update the description — small thing but the README under "Types" doesn't list it either.
Notes for reviewers
- The generic plumbing is consistent across all resolvers and visitors. The contravariance escape hatch in
shared/types.ts(ResolverFnInputusingResolverFn<any, any>) is the right move and the comment explains why. - The auto-resolution truth table in
resolve-instruction-account-address.tsis excellent — I traced each row against thecanAutoResolvelogic and it matches. resolveAccountAddressnow derivesaccountAddressInputfromaccountsInput?.[ixAccountNode.name]instead of receiving it as a parameter; behaviour is preserved because the only caller passing an external value (resolveAccountValueNodeAddress) was already looking up by the same name.- Lots of test files moved; new tests added for
resolveInstructionAccountAddress,resolveConditional,codecs,types, andutil. Good coverage on the new public function.
Description
This PR [1] extracts Account address resolution functionality from
dynamic-clientintodynamic-address-resolutionpackage (including standalone PDA resolution). Packagedynamic-clientwas cleaned and now usesdynamic-address-resolution.Change
dynamic-address-resolutioncontains full functionality of Address resolution for the given Instruction's Account. ExportsresolveStandalonePda,resolveInstructionAccountAddressand address helpers.utilfiles andtestsdisplayed as new are not new.dynamic-client.Minor
isConvertibleAddress->isAddressConvertible,createInputValueTransformer->createCodecInputTransformer.Public API:
dynamic-address-resolution
dynamic-client
Unchanged
Notes
This is 1st out of 4 forthcoming dependent PRs. In the next we will do more in terms of spliting:
Extract dynamic-instructions - it will contain functionality for building Solana kit Instruction and AccountMeta. Uses dynamic-address-resolution.
Split type generations between dynamic-address-resolution, dynamic-instructions, dynamic-client packages.
Refactor constant pda seeds resolution.