feat: stateless js add pda helpers#1971
Conversation
WalkthroughAdds V2 address-tree support across JS and Rust, new instruction/meta utilities, a TreeAccounts CPI trait, program-test logging V2 fields/formatting, Anchor test program V2 handlers and TS tests, workspace/tooling updates (Anchor 0.31.1), and a CI step to run the sdk-anchor-test TypeScript tests. Changes
Sequence Diagram(s)sequenceDiagram
autonumber
participant Test as Test (TS)
participant Rpc as Rpc (stateless.js)
participant Prog as Anchor Program
participant Chain as Solana
rect rgba(230,245,255,0.6)
note over Test,Rpc: V2 Create compressed account
Test->>Rpc: getAddressTreeInfoV2()
Rpc-->>Test: TreeInfoV2 (tree pubkey, type)
Test->>Chain: Fetch proofs/state tree info
Test->>Prog: invoke create_compressed_account_v2 (CPI + remaining accounts)
Prog->>Chain: Write compressed account (V2)
Chain-->>Test: Confirmation
end
sequenceDiagram
autonumber
participant Test as Test (TS)
participant Rpc as Rpc/TestRpc
participant C as Constants
Test->>Rpc: getAddressTreeInfoV2()
Rpc->>C: batchAddressTree
C-->>Rpc: PublicKey
Rpc-->>Test: { tree: batchAddressTree, queue: undefined, treeType: AddressV2, nextTreeInfo: null }
Estimated code review effort🎯 4 (Complex) | ⏱️ ~60 minutes Possibly related PRs
Suggested reviewers
Poem
Pre-merge checks and finishing touches✅ Passed checks (3 passed)
✨ Finishing touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
3cc29e0 to
0ee3438
Compare
0ee3438 to
217564e
Compare
There was a problem hiding this comment.
Actionable comments posted: 7
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
⛔ Files ignored due to path filters (1)
pnpm-lock.yamlis excluded by!**/pnpm-lock.yaml
📒 Files selected for processing (21)
.github/workflows/js-v2.yml(1 hunks)js/stateless.js/src/rpc.ts(2 hunks)js/stateless.js/src/test-helpers/test-rpc/test-rpc.ts(2 hunks)js/stateless.js/src/utils/index.ts(1 hunks)js/stateless.js/src/utils/instruction.ts(1 hunks)pnpm-workspace.yaml(1 hunks)scripts/install.sh(1 hunks)sdk-libs/program-test/src/logging/decoder.rs(6 hunks)sdk-libs/program-test/src/logging/formatter.rs(2 hunks)sdk-libs/program-test/src/logging/types.rs(1 hunks)sdk-libs/sdk-types/src/cpi_accounts/mod.rs(1 hunks)sdk-libs/sdk-types/src/cpi_accounts/v1.rs(2 hunks)sdk-libs/sdk-types/src/cpi_accounts/v2.rs(2 hunks)sdk-libs/sdk-types/src/instruction/tree_info.rs(2 hunks)sdk-tests/sdk-anchor-test/Anchor.toml(1 hunks)sdk-tests/sdk-anchor-test/package.json(1 hunks)sdk-tests/sdk-anchor-test/programs/sdk-anchor-test/Cargo.toml(1 hunks)sdk-tests/sdk-anchor-test/programs/sdk-anchor-test/src/lib.rs(1 hunks)sdk-tests/sdk-anchor-test/tests/test_v1.ts(1 hunks)sdk-tests/sdk-anchor-test/tests/test_v2.ts(1 hunks)sdk-tests/sdk-anchor-test/tsconfig.json(1 hunks)
🧰 Additional context used
🧬 Code graph analysis (9)
js/stateless.js/src/utils/instruction.ts (1)
js/stateless.js/src/constants.ts (2)
defaultStaticAccountsStruct(95-105)noopProgram(74-74)
sdk-libs/sdk-types/src/cpi_accounts/mod.rs (2)
sdk-libs/sdk-types/src/cpi_accounts/v1.rs (2)
get_tree_account_info(241-248)get_tree_account_info(262-264)sdk-libs/sdk-types/src/cpi_accounts/v2.rs (2)
get_tree_account_info(189-196)get_tree_account_info(229-231)
sdk-tests/sdk-anchor-test/programs/sdk-anchor-test/src/lib.rs (2)
js/stateless.js/src/state/types.ts (1)
ValidityProof(397-410)js/stateless.js/src/state/compressed-account.ts (2)
PackedAddressTreeInfo(146-159)CompressedAccountMeta(165-182)
js/stateless.js/src/rpc.ts (2)
js/stateless.js/src/state/types.ts (1)
TreeInfo(77-99)js/stateless.js/src/constants.ts (1)
batchAddressTree(304-304)
sdk-libs/sdk-types/src/cpi_accounts/v1.rs (2)
sdk-libs/sdk-types/src/cpi_accounts/mod.rs (1)
get_tree_account_info(13-13)sdk-libs/sdk-types/src/cpi_accounts/v2.rs (2)
get_tree_account_info(189-196)get_tree_account_info(229-231)
sdk-libs/sdk-types/src/cpi_accounts/v2.rs (2)
sdk-libs/sdk-types/src/cpi_accounts/mod.rs (1)
get_tree_account_info(13-13)sdk-libs/sdk-types/src/cpi_accounts/v1.rs (2)
get_tree_account_info(241-248)get_tree_account_info(262-264)
sdk-tests/sdk-anchor-test/tests/test_v1.ts (7)
js/stateless.js/src/rpc.ts (2)
createRpc(233-266)Rpc(615-1956)js/stateless.js/src/utils/sleep.ts (1)
sleep(2-4)js/stateless.js/src/constants.ts (3)
defaultTestStateTreeAccounts(236-244)addressTree(274-274)addressQueue(275-275)js/stateless.js/src/utils/address.ts (2)
deriveAddressSeed(11-18)deriveAddress(29-46)js/stateless.js/src/state/bn.ts (1)
bn(3-12)js/stateless.js/src/utils/instruction.ts (2)
SystemAccountMetaConfig(101-129)PackedAccounts(5-99)js/stateless.js/src/state/compressed-account.ts (1)
CompressedAccountWithMerkleContext(14-17)
js/stateless.js/src/test-helpers/test-rpc/test-rpc.ts (2)
js/stateless.js/src/state/types.ts (1)
TreeInfo(77-99)js/stateless.js/src/constants.ts (1)
batchAddressTree(304-304)
sdk-tests/sdk-anchor-test/tests/test_v2.ts (6)
js/stateless.js/src/rpc.ts (2)
createRpc(233-266)Rpc(615-1956)js/stateless.js/src/utils/sleep.ts (1)
sleep(2-4)js/stateless.js/src/utils/address.ts (2)
deriveAddressSeedV2(48-54)deriveAddressV2(64-82)js/stateless.js/src/state/bn.ts (1)
bn(3-12)js/stateless.js/src/utils/instruction.ts (2)
SystemAccountMetaConfig(101-129)PackedAccounts(5-99)js/stateless.js/src/state/compressed-account.ts (1)
CompressedAccountWithMerkleContext(14-17)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (13)
- GitHub Check: lint
- GitHub Check: cli-v1
- GitHub Check: cli-v2
- GitHub Check: stateless-js-v2
- GitHub Check: Forester e2e test
- GitHub Check: Test program-libs-fast
- GitHub Check: stateless-js-v1
- GitHub Check: Test batched-merkle-tree-simulate
- GitHub Check: Test concurrent-merkle-tree
- GitHub Check: Test program-libs-slow
- GitHub Check: system-programs (sdk-anchor-test-program, ["cargo-test-sbf -p sdk-anchor-test", "cargo-test-sbf -...
- GitHub Check: system-programs (sdk-libs, light-sdk-macros light-sdk light-program-test light-client batched-mer...
- GitHub Check: system-programs (sdk-test-program, ["cargo-test-sbf -p sdk-native-test", "cargo-test-sbf -p sdk-v...
🔇 Additional comments (19)
sdk-libs/sdk-types/src/cpi_accounts/v1.rs (1)
261-265: LGTM! Clean trait implementation.The
TreeAccountstrait implementation correctly delegates to the existing inherent method, enabling trait-based polymorphism while preserving the original API.sdk-libs/sdk-types/src/cpi_accounts/v2.rs (1)
228-232: LGTM! Consistent trait implementation.The
TreeAccountstrait implementation mirrors the v1 approach, ensuring consistent behavior across versions.sdk-libs/sdk-types/src/cpi_accounts/mod.rs (1)
11-14: LGTM! Well-designed trait abstraction.The
TreeAccountstrait provides a clean interface for accessing tree account information, enabling polymorphism across v1 and v2 implementations.sdk-libs/sdk-types/src/instruction/tree_info.rs (1)
61-68: LGTM! Effective generalization.The function signature now accepts
impl TreeAccounts<T>, making it compatible with both v1 and v2CpiAccountsimplementations while maintaining the same functionality.js/stateless.js/src/utils/instruction.ts (3)
5-99: LGTM!The
PackedAccountsclass provides a clean builder pattern for managing account metas with proper deduplication and index tracking. The separation between pre-accounts, system accounts, and packed accounts is well-structured.
101-129: LGTM!The
SystemAccountMetaConfigclass uses a clean factory pattern with static constructors, making the API clear and preventing misuse through the private constructor.
197-256: LGTM!The V2 implementation correctly removes the
noopProgramandselfProgramfrom the account list compared to V1, aligning with the V2 protocol changes. The function properly handles optional accounts and avoids the hardcoding issue present in the V1 version.sdk-tests/sdk-anchor-test/Anchor.toml (1)
11-13: LGTM!The program name update from
sdk_testtosdk_anchor_testaligns with the package structure. The removal of the[scripts]test entry is appropriate since test orchestration has been moved topackage.json(as seen in the newtest-tsscript).pnpm-workspace.yaml (1)
8-8: LGTM!Adding
sdk-tests/**to the workspace enables proper monorepo management and aligns with the new test infrastructure being added in this PR.js/stateless.js/src/utils/index.ts (1)
6-6: LGTM!The barrel export properly exposes the new instruction utilities (
PackedAccounts,SystemAccountMetaConfig, and helper functions) added in this PR.sdk-tests/sdk-anchor-test/tsconfig.json (1)
8-9: LGTM!Adding
resolveJsonModuleenables importing JSON files in TypeScript, which is useful for test fixtures and configuration data in the test suite.sdk-tests/sdk-anchor-test/package.json (3)
3-6: LGTM!The new lint scripts and updated test-ts workflow properly integrate TypeScript testing with the local validator setup. The inline validator command ensures the test environment is correctly initialized.
9-10: LGTM!The Anchor upgrade to
^0.31.1is consistent with the version update inscripts/install.sh, and adding@lightprotocol/stateless.jsas a workspace dependency enables the new V2 test functionality.
14-21: LGTM!The dev dependency updates align with the Anchor 0.31.1 upgrade and modern TypeScript testing requirements. Note that
prettieris pinned at^2.6.2, which may be intentional for compatibility—ensure this version meets your formatting needs.sdk-libs/program-test/src/logging/decoder.rs (5)
252-267: LGTM!The address parameter enrichment correctly resolves both tree and queue pubkeys and populates the new fields consistently with the instruction structure.
406-421: LGTM!The implementation mirrors the Invoke instruction parser correctly, maintaining consistency across instruction types.
555-590: LGTM!The implementation correctly handles both new address parameters and readonly addresses:
- New address params resolve both tree and queue pubkeys with appropriate assignment variants
- Readonly addresses correctly omit queue pubkeys as they don't require queue operations
719-754: LGTM!The address parameter handling is consistent with the readonly instruction parser. The intentional difference in tree context availability between input accounts (lines 771-774, no tree context) and output accounts (lines 795-797, tree context available) correctly reflects the CompressedAccountInfo structure.
15-52: Verify resolve_tree_and_queue_pubkeys account offset assumption
Ensure that for all Invoke/InvokeCpi variants, the merkle tree and nullifier queue accounts are positioned exactly two slots after the system program; adjust the helper if the actual instruction layouts differ.
There was a problem hiding this comment.
Actionable comments posted: 2
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
⛔ Files ignored due to path filters (1)
pnpm-lock.yamlis excluded by!**/pnpm-lock.yaml
📒 Files selected for processing (2)
cli/package.json(1 hunks)js/stateless.js/package.json(1 hunks)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (13)
- GitHub Check: stateless-js-v2
- GitHub Check: system-programs (sdk-anchor-test-program, ["cargo-test-sbf -p sdk-anchor-test", "cargo-test-sbf -...
- GitHub Check: system-programs (sdk-libs, light-sdk-macros light-sdk light-program-test light-client batched-mer...
- GitHub Check: system-programs (sdk-test-program, ["cargo-test-sbf -p sdk-native-test", "cargo-test-sbf -p sdk-v...
- GitHub Check: Test batched-merkle-tree-simulate
- GitHub Check: Test concurrent-merkle-tree
- GitHub Check: Test program-libs-slow
- GitHub Check: Test program-libs-fast
- GitHub Check: cli-v2
- GitHub Check: Forester e2e test
- GitHub Check: cli-v1
- GitHub Check: stateless-js-v1
- GitHub Check: lint
There was a problem hiding this comment.
Actionable comments posted: 0
🧹 Nitpick comments (1)
.github/workflows/js-v2.yml (1)
88-94: Use pnpm consistently; avoid mixing npm and pnpm.Other steps use pnpm/nx. Running npm here can create a package-lock and inconsistent installs. Use pnpm to run the test script.
- name: Run sdk-anchor-test TypeScript tests with V2 run: | source ./scripts/devenv.sh npx nx build @lightprotocol/sdk-anchor-test cd sdk-tests/sdk-anchor-test - npm run test-ts + pnpm run test-ts
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (2)
.github/workflows/js-v2.yml(1 hunks)sdk-tests/sdk-anchor-test/package.json(1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
- sdk-tests/sdk-anchor-test/package.json
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (13)
- GitHub Check: stateless-js-v1
- GitHub Check: Forester e2e test
- GitHub Check: cli-v1
- GitHub Check: stateless-js-v2
- GitHub Check: cli-v2
- GitHub Check: Test program-libs-fast
- GitHub Check: Test batched-merkle-tree-simulate
- GitHub Check: Test program-libs-slow
- GitHub Check: Test concurrent-merkle-tree
- GitHub Check: lint
- GitHub Check: system-programs (sdk-anchor-test-program, ["cargo-test-sbf -p sdk-anchor-test", "cargo-test-sbf -...
- GitHub Check: system-programs (sdk-test-program, ["cargo-test-sbf -p sdk-native-test", "cargo-test-sbf -p sdk-v...
- GitHub Check: system-programs (sdk-libs, light-sdk-macros light-sdk light-program-test light-client batched-mer...
Changes:
Summary by CodeRabbit
New Features
Improvements
Tests
Chores