Add defi/vault-strategy anchor program with mock swap router#42
Merged
Conversation
c8c0006 to
18f207f
Compare
…e and rebalancing Adds a new example under defi/vault-strategy/anchor demonstrating a manager-custodial investment vault on Solana. ## What this adds ### vault-strategy program - `initialize_strategy` — creates the Strategy PDA, share mint, and vault ATAs for USDC/TSLAx/NVDAx; registers Pyth price feed pubkeys - `deposit` — accepts USDC, prices shares against Pyth-computed NAV, mints proportional LP shares to the depositor - `invest` — manager-only CPI to the swap router to convert USDC into basket tokens (TSLAx or NVDAx) - `rebalance` — manager-only atomic two-leg CPI: sell one basket token for USDC then buy the other, with slippage protection on both legs - `collect_fees` — permissionless; accrues the annual management fee by minting new shares to the manager (dilution model) - `withdraw` — burns shares, returns proportional in-kind slice of every vault asset (USDC + TSLAx + NVDAx) to the user ### mock-swap-router program (test fixture) - Stores per-asset `usdc_per_token` exchange rates in `AssetRate` PDAs - `swap_usdc_for_asset` — receives USDC, mints basket tokens (used by invest) - `swap_asset_for_usdc` — burns basket tokens, releases USDC (used by rebalance) - `router_authority` PDA holds mint authority for all basket token mints ### Oracle (Pyth) NAV is computed from Pyth `PriceUpdateV2` accounts. Feed pubkeys are stored in the Strategy at creation. Prices older than 60 seconds are rejected. Raw byte offsets are used to read price data, avoiding the borsh 0.10/1.x incompatibility between the Pyth SDK and Anchor 1.0. ### Financial math No floats; u128 intermediates; multiply-before-divide; all arithmetic via checked_* methods; transfer_checked for all token moves. ### Tests (LiteSVM, 8 tests) Covers all instructions including NAV-based deposit pricing, fee accrual via mock clock advancement, in-kind withdrawal, rebalance, and slippage rejection. Mock Pyth PriceUpdateV2 accounts injected directly into LiteSVM. ### Also adds - defi/ workspace members in root Cargo.toml - Vault Strategy entry in root README.md https://claude.ai/code/session_01XUvydGu8rPSbM1AxLJ2GpA
18f207f to
691f96b
Compare
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.
Manager-run investment vault with two programs: vault-strategy (deposits,
share minting, NAV-based pricing, fee accrual, in-kind withdrawals) and
mock-swap-router (test-only fake Jupiter for USDC→asset swaps via CPI).
Includes 7 LiteSVM tests, README, and root workspace/README updates.
https://claude.ai/code/session_01XUvydGu8rPSbM1AxLJ2GpA