Skip to content

SubAccount V2 (3/3): rust-sdk V2 + SDK integration tests - #189

Open
santy311 wants to merge 6 commits into
santhosh/subaccount-v2-programfrom
santhosh/subaccount-v2-sdk
Open

SubAccount V2 (3/3): rust-sdk V2 + SDK integration tests#189
santy311 wants to merge 6 commits into
santhosh/subaccount-v2-programfrom
santhosh/subaccount-v2-sdk

Conversation

@santy311

@santy311 santy311 commented Jul 27, 2026

Copy link
Copy Markdown
Collaborator

Summary

The rust-sdk V2 sub-account API and its SDK-level integration tests. (The interface builders these depend on live in #188.)

rust-sdk

  • types::Permission: five V2 variants (Create + scoped All/Sign/Withdraw/Toggle) with to_client_actions / from_role / to_action_type.
  • ClientRole: four V2 methods (create/sign/withdraw/toggle) with default "unsupported" impls, overridden for Ed25519, Secp256k1, Secp256r1, and the three session variants (which delegate to the Ed25519 builders via the session key). Secp256k1/r1 thread the odometer as the replay counter. ProgramExec uses the default impl.
  • SwigInstructionBuilder + SwigWallet: V2 create/sign/withdraw/toggle, a counter reader, and get_sub_account_v2. Create reads the on-chain counter to derive the next sub-account's PDAs.

tests (rust_sdk_test)

Thirteen SDK integration tests via the SwigWallet API:

  • lifecycle — create/counter, sign + SOL withdraw, Ed25519 token withdraw, toggle kill-switch
  • validation — state account pre-funded but uninitialized, invalid enabled wire byte
  • authorizationAll alone cannot create (default-deny)
  • Secp256k1 / Secp256r1 — k1 sign, and k1 + r1 create followed by token withdraw
  • sessions — Ed25519 session create + SOL withdraw, token withdraw, and toggle

Test

cargo build-sbf --arch v1
cargo test -p swig-sdk --features rust_sdk_test sub_accounts_v2_test   # 13
cargo test -p swig-sdk --features rust_sdk_test                        # 135

Stack

  1. SubAccount V2 (1/3): state-crate data model #187 — state data model (base main)
  2. SubAccount V2 (2/3): program + interface builders + program tests #188 — program + interface builders + program tests (base SubAccount V2 (1/3): state-crate data model #187)
  3. this PR — rust-sdk V2 + SDK integration tests (base SubAccount V2 (2/3): program + interface builders + program tests #188)

🤖 Generated with Claude Code

@santy311

Copy link
Copy Markdown
Collaborator Author

@santy311
santy311 force-pushed the santhosh/subaccount-v2-sdk branch from c5490f1 to 49dcf1d Compare July 27, 2026 15:20
@santy311 santy311 changed the title SubAccount V2 (3/3): rust-sdk + interface + tests SubAccount V2 (3/3): rust-sdk V2 + SDK integration tests Jul 27, 2026
@santy311
santy311 force-pushed the santhosh/subaccount-v2-sdk branch 3 times, most recently from e6364b5 to 3e274d0 Compare July 28, 2026 12:09
@santy311
santy311 force-pushed the santhosh/subaccount-v2-program branch from e67d530 to d794d3c Compare July 29, 2026 11:22
@santy311
santy311 force-pushed the santhosh/subaccount-v2-sdk branch from 3e274d0 to cba2e26 Compare July 29, 2026 12:30

@tracy-codes tracy-codes left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

The "known gaps" part of the PR seems outdated. sub-accounts_v2_test at line 311 and 368 both create and withdraw with Secp256k1/r1. It also says 5 tests but there's 9.

There's no session authority tests, which we need to have for coverage.

Comment thread rust-sdk/src/client_role.rs
@santy311
santy311 force-pushed the santhosh/subaccount-v2-program branch from d794d3c to 5300b41 Compare July 30, 2026 11:55
@santy311
santy311 force-pushed the santhosh/subaccount-v2-sdk branch from cba2e26 to fabbbb2 Compare July 30, 2026 14:16
@santy311
santy311 requested a review from tracy-codes July 30, 2026 14:31
santy311 added 6 commits July 30, 2026 16:45
- `types::Permission`: five V2 variants (Create + scoped All/Sign/Withdraw/
  Toggle) with `to_client_actions` / `from_role` / `to_action_type` mappings.
- `ClientRole`: four V2 methods (create/sign/withdraw/toggle) with default
  "unsupported" impls, overridden for Ed25519, Secp256k1, Secp256r1, and the
  three session variants (which delegate to the Ed25519 builders via the session
  key). Secp256k1/r1 thread the odometer as the replay counter.
- `SwigInstructionBuilder` + `SwigWallet`: V2 create/sign/withdraw/toggle plus a
  counter reader and `get_sub_account_v2`. Create reads the on-chain counter to
  derive the next sub-account's PDAs.
SDK-level tests via the `SwigWallet` API (rust_sdk_test feature), mirroring the
program matrix at the wallet layer:
- create/counter, sign + withdraw, toggle kill-switch, All-default-deny, and a
  Secp256k1 sign path.
- Secp256k1/r1 `create` is deferred — see the note in the test file.
Ed25519SessionClientRole, Secp256k1SessionClientRole and
Secp256r1SessionClientRole implemented create, SOL withdraw and toggle
for V2 sub-accounts but not withdraw_token_from_sub_account_v2_instruction,
so it fell through to the trait default and returned "V2 sub-accounts not
supported for this authority type". Session authorities could move SOL
out of a sub-account but not tokens.

Each delegates to the Ed25519 token-withdraw builder via the session key,
matching how the other three V2 methods on these roles already work.

Add session coverage for V2, which was absent entirely: create plus SOL
withdraw, token withdraw, and the toggle kill-switch. The helper has to
make the session root the fee payer while opening the session, because
create_session signs with the fee payer alone and ignores the acting
authority keypair.
@santy311
santy311 force-pushed the santhosh/subaccount-v2-sdk branch from aa8c526 to dc39326 Compare July 30, 2026 14:46
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