Skip to content

Add defi/vault-strategy anchor program with mock swap router#42

Merged
mikemaccana merged 1 commit into
mainfrom
claude/upbeat-ride-7YCIz
Jun 2, 2026
Merged

Add defi/vault-strategy anchor program with mock swap router#42
mikemaccana merged 1 commit into
mainfrom
claude/upbeat-ride-7YCIz

Conversation

@mikemaccana

Copy link
Copy Markdown
Collaborator

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

@mikemaccana mikemaccana force-pushed the claude/upbeat-ride-7YCIz branch 2 times, most recently from c8c0006 to 18f207f Compare June 1, 2026 16:03
…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
@mikemaccana mikemaccana force-pushed the claude/upbeat-ride-7YCIz branch from 18f207f to 691f96b Compare June 2, 2026 17:30
@mikemaccana mikemaccana merged commit ef0b504 into main Jun 2, 2026
18 checks passed
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