Skip to content

feat: stateless js add pda helpers#1971

Merged
SwenSchaeferjohann merged 7 commits intomainfrom
jorrit/fix-sdk
Oct 8, 2025
Merged

feat: stateless js add pda helpers#1971
SwenSchaeferjohann merged 7 commits intomainfrom
jorrit/fix-sdk

Conversation

@ananas-block
Copy link
Contributor

@ananas-block ananas-block commented Oct 8, 2025

Changes:

  • bumped anchor ts versions to 0.31.1
  • add PackedAccounts to stateless js
  • add v1 and v2 anchor ts client tests to v2 stateless js ci
  • small fixes light-sdk

Summary by CodeRabbit

  • New Features

    • V2 support for creating, updating, and closing compressed accounts; new V2 APIs added to the program IDL.
    • RPC now exposes V2-style address tree info.
    • Utilities to simplify constructing instruction account metas.
  • Improvements

    • Program-test logging now shows V1/V2-aware tree and queue public keys.
  • Tests

    • End-to-end tests for V1 and V2 compressed account lifecycles; TypeScript-based test execution enabled and CI step added.
  • Chores

    • Anchor/tooling versions and workspace config updated; installer versions adjusted; workspace expanded to include SDK tests.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Oct 8, 2025

Walkthrough

Adds 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

Cohort / File(s) Summary
CI: JS V2 tests
.github/workflows/js-v2.yml
Adds step to run sdk-anchor-test TypeScript tests in the stateless-js-v2 job.
JS RPC & TestRpc V2 accessor
js/stateless.js/src/rpc.ts, js/stateless.js/src/test-helpers/test-rpc/test-rpc.ts
Adds getAddressTreeInfoV2() to Rpc and TestRpc, uses batchAddressTree constant; adjusts imports.
JS utils: instruction/meta packing
js/stateless.js/src/utils/index.ts, js/stateless.js/src/utils/instruction.ts
New exports and implementation: PackedAccounts, SystemAccountMetaConfig, and getLightSystemAccountMetas/getLightSystemAccountMetasV2.
Workspace & tooling
pnpm-workspace.yaml, scripts/install.sh, cli/package.json, js/stateless.js/package.json, .gitignore, sdk-tests/sdk-anchor-test/.gitignore
Adds sdk-tests/** to workspace, updates Anchor installer version, adjusts package deps, and tweaks gitignore entries.
Rust: program-test logging (types/decoder/formatter)
sdk-libs/program-test/src/logging/types.rs, .../decoder.rs, .../formatter.rs
Adds pubkey fields to AddressParam, computes/resolves tree/queue pubkeys in decoder, and updates formatter to display V2-aware tree/queue info; adds AssignedIndex usage.
Rust: SDK types — CPI trait & tree_info
sdk-libs/sdk-types/src/cpi_accounts/mod.rs, .../v1.rs, .../v2.rs, sdk-libs/sdk-types/src/instruction/tree_info.rs
Introduces TreeAccounts trait, implements it for V1/V2 CpiAccounts, and makes get_tree_pubkey accept &impl TreeAccounts<T>.
Anchor test program: V2 handlers & features
sdk-tests/sdk-anchor-test/programs/sdk-anchor-test/src/lib.rs, .../Cargo.toml
Adds create_compressed_account_v2, update_compressed_account_v2, close_compressed_account_v2; removes default idl-build feature.
Anchor test package, IDL, and types
sdk-tests/sdk-anchor-test/Anchor.toml, .../package.json, .../tsconfig.json, target/idl/sdk_anchor_test.json, target/types/sdk_anchor_test.ts
Moves program mapping, adds scripts/deps (including workspace @lightprotocol/stateless.js), enables resolveJsonModule, and adds generated IDL + TS types including V2 instructions/types.
Tests: end-to-end V1 and V2
sdk-tests/sdk-anchor-test/tests/test_v1.ts, .../tests/test_v2.ts
Adds E2E tests for compressed account lifecycle (create/update/close) for V1 and V2 using stateless.js RPC, proofs, and remaining account wiring.
Workspace Cargo adjustments
Cargo.toml, anchor-programs/system/Cargo.toml
Removes default idl-build feature from anchor-lang and system program defaults.

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
Loading
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 }
Loading

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~60 minutes

Possibly related PRs

Suggested reviewers

  • sergeytimoshin
  • SwenSchaeferjohann

Poem

Hop hop, I stitch V2 threads with care,
New trees, new trails, fresh bytes in air.
Proofs in my paws, I sign and I send—
Create, update, close—beginning to end.
Carrots compiled, all tests pass by the bend. 🥕✨

Pre-merge checks and finishing touches

✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title Check ✅ Passed The title highlights the addition of PDA helper utilities in the stateless JS module, which is indeed part of the changeset, but it does not convey the broader scope of updates including new RPC methods, test coverage, CI workflow steps, and SDK version bumps.
Docstring Coverage ✅ Passed No functions found in the changes. Docstring coverage check skipped.
✨ Finishing touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch jorrit/fix-sdk

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 7

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between c7227ba and 217564e.

⛔ Files ignored due to path filters (1)
  • pnpm-lock.yaml is 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 TreeAccounts trait 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 TreeAccounts trait 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 TreeAccounts trait 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 v2 CpiAccounts implementations while maintaining the same functionality.

js/stateless.js/src/utils/instruction.ts (3)

5-99: LGTM!

The PackedAccounts class 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 SystemAccountMetaConfig class 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 noopProgram and selfProgram from 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_test to sdk_anchor_test aligns with the package structure. The removal of the [scripts] test entry is appropriate since test orchestration has been moved to package.json (as seen in the new test-ts script).

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 resolveJsonModule enables 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.1 is consistent with the version update in scripts/install.sh, and adding @lightprotocol/stateless.js as 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 prettier is 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.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 2

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between c094fdd and c53986d.

⛔ Files ignored due to path filters (1)
  • pnpm-lock.yaml is 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

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

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

📥 Commits

Reviewing files that changed from the base of the PR and between c53986d and cd3f226.

📒 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...

Copy link
Contributor

@SwenSchaeferjohann SwenSchaeferjohann left a comment

Choose a reason for hiding this comment

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

lgtm

@SwenSchaeferjohann SwenSchaeferjohann merged commit a31725d into main Oct 8, 2025
24 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants