Skip to content

Change Strategy PDA seed from manager key to index#82

Open
mikemaccana wants to merge 3 commits into
mainfrom
claude/vault-strategy-indexing-jw34h7
Open

Change Strategy PDA seed from manager key to index#82
mikemaccana wants to merge 3 commits into
mainfrom
claude/vault-strategy-indexing-jw34h7

Conversation

@mikemaccana

Copy link
Copy Markdown
Collaborator

Summary

This PR refactors the Strategy account's PDA derivation to use a caller-chosen index instead of the manager's public key. This allows multiple strategies to be created by the same manager and makes strategy addresses deterministic based on a simple counter rather than identity.

Key Changes

  • Strategy PDA seed: Changed from ["strategy", manager_pubkey] to ["strategy", index] where index is a u64 provided during initialization
  • Strategy struct: Added index: u64 field to store the PDA seed for re-derivation in handlers
  • Initialize instruction: Added index parameter to initialize_strategy instruction
  • All handlers updated: Modified collect_fees, deposit, invest, rebalance, withdraw, and add_asset to use strategy.index instead of strategy.manager when constructing signer seeds
  • Tests updated: Updated test setup to use STRATEGY_INDEX constant and pass index to initialization
  • Documentation: Updated VIDEO_SCRIPT.md and README.md to reflect the new seeding scheme

Implementation Details

  • The manager's key is still stored as a field on the Strategy account and used for authorization checks (has_one = manager)
  • The index is converted to little-endian bytes (to_le_bytes()) for use in PDA seed derivation
  • This change enables multiple independent strategies per manager while maintaining deterministic PDA addresses
  • All CPI signer seeds now use the index-based derivation consistently across all instructions

https://claude.ai/code/session_01RajngzX57RGaQx5sKPbysZ

claude added 3 commits June 29, 2026 18:34
The Strategy PDA was derived from seeds "strategy" + manager pubkey. Switch
to a simpler caller-chosen index, e.g. "strategy" + 0, so strategies are
addressed by a counter rather than the manager's key.

- Add `index: u64` to the Strategy account, set at creation and used to
  re-derive the PDA wherever it signs for the vaults and share mint.
- `initialize_strategy` now takes an `index` argument used in the PDA seeds.
- deposit, invest, rebalance, collect_fees, withdraw, add_asset re-derive the
  strategy PDA from the stored index; the manager is still recorded as a field
  and keeps its manager-only powers, it is just no longer part of the address.
- Update tests, README, and the video script to match.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01RajngzX57RGaQx5sKPbysZ
Keep VIDEO_SCRIPT.md as-is on this branch; the index-seed program change
stands on its own. The updated script is delivered separately.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01RajngzX57RGaQx5sKPbysZ
deposit now invests each depositor's USDC into the basket at its target
weights in the same transaction, routing each weight-sized slice through the
registered swap router with the same oracle-computed slippage floor invest
uses. The USDC vault no longer holds idle deposits; only the unallocated
remainder (when the weights sum below 10000) stays as USDC. Its
remaining_accounts are now [asset_config, vault, mint, rate, price_feed] per
asset, plus the router accounts.

Add set_weight, a manager-only instruction that changes an asset's target
weight, including setting it to zero to retire it. The asset's index is
preserved so the contiguous 0..asset_count range the valuation handlers
depend on stays intact; the manager sells the retired asset's holdings out
with rebalance.

Rework the tests around the new behavior: a full-lifecycle test (deposit and
auto-deploy, a price move, a rebalance back to target, a second depositor
priced at the new NAV, a year's fee, in-kind withdrawal), focused per-handler
tests, set_weight retire and rejection paths, and oracle-bounded slippage on
both deposit and invest. Also fixes two InitializeStrategy constructions left
without the index field. 20 tests pass under cargo build-sbf + cargo test.

Update README and CHANGELOG to match.
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