Commit 691f96b
committed
Add defi/vault-strategy: manager-run investment vault with Pyth oracle 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_01XUvydGu8rPSbM1AxLJ2GpA1 parent 5540080 commit 691f96b
33 files changed
Lines changed: 3028 additions & 0 deletions
File tree
- defi/vault-strategy/anchor
- programs
- mock-swap-router
- src
- instructions
- state
- vault-strategy
- src
- instructions
- state
- tests
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
48 | 48 | | |
49 | 49 | | |
50 | 50 | | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
51 | 55 | | |
52 | 56 | | |
53 | 57 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
41 | 41 | | |
42 | 42 | | |
43 | 43 | | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
44 | 50 | | |
45 | 51 | | |
46 | 52 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
0 commit comments