Change Strategy PDA seed from manager key to index#82
Open
mikemaccana wants to merge 3 commits into
Open
Conversation
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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", manager_pubkey]to["strategy", index]where index is a u64 provided during initializationindex: u64field to store the PDA seed for re-derivation in handlersindexparameter toinitialize_strategyinstructioncollect_fees,deposit,invest,rebalance,withdraw, andadd_assetto usestrategy.indexinstead ofstrategy.managerwhen constructing signer seedsSTRATEGY_INDEXconstant and pass index to initializationImplementation Details
has_one = manager)to_le_bytes()) for use in PDA seed derivationhttps://claude.ai/code/session_01RajngzX57RGaQx5sKPbysZ