Skip to content

[contract] Use one assets base for share pricing and reconcile conversion tests - #1710

Merged
Junirezz merged 1 commit into
Junirezz:mainfrom
CathyZaks:fix/issue-1632-share-pricing-assets-base
Oct 26, 2026
Merged

Junirezz merged 1 commit into
Junirezz:mainfrom
CathyZaks:fix/issue-1632-share-pricing-assets-base

Conversation

@CathyZaks

Copy link
Copy Markdown
Contributor

[contract] Use one assets base for share pricing and reconcile conversion tests

Problem

Share conversions (share_price, calculate_shares, calculate_assets, deposit, gasless_deposit, withdraw, execute_withdrawal) were reading only idle state.total_assets rather than total_assets(), which includes strategy valuation. As a result:

  • Deposits into a vault after funds were partially deployed to a strategy minted shares at an incorrect, artificially deflated asset base, diluting prior depositors.
  • Share price reporting ignored strategy holdings.
  • In vault/src/test.rs, expectations after divest(10) assumed an incorrect asset base.
  • In share-price-math/src/fuzz_invariants.rs, the validity filter prematurely returned on total_assets == 0 && total_shares > 0, skipping the zero-idle state where idle assets are zero while shares remain outstanding.

Solution

  • Consolidated share pricing and conversions to use total_assets() (idle assets plus strategy value) as the canonical asset base across all conversion and deposit/withdrawal functions.
  • Reconciled test_vault_with_benji_strategy withdrawal math to reflect proportional share of total_assets().
  • Added test verifying deposits mint at the correct price when a strategy holds part of the assets.
  • Narrowed is_valid_vault_state in fuzz_invariants.rs to allow non-negative assets with positive shares so the zero-idle state is exercised.

Changes

  • contracts/vault/src/lib.rs:
    • share_price: Uses total_assets(env).unwrap_or(state.total_assets) instead of state.total_assets.
    • calculate_shares & calculate_assets: Reads total_assets(env)? and converts against total vault assets.
    • deposit & gasless_deposit: Reads total_assets(env)? for TVL risk limits, try_assets_to_shares, and effective asset computation for dust sweeping.
    • withdraw & execute_withdrawal: Uses total_assets(env)? to determine assets_to_return.
  • contracts/vault/src/test.rs:
    • Reconciled test_vault_with_benji_strategy expectations where 50 shares withdraw 53 assets out of 106 total assets.
    • Added test_deposit_mints_at_correct_price_while_strategy_holds_part_of_assets.
  • contracts/share-price-math/src/fuzz_invariants.rs:
    • Narrowed is_valid_vault_state condition to (total_shares == 0 && total_assets == 0) || (total_shares > 0 && total_assets >= 0).
    • Added unit test zero_idle_state_invariant_holds.

Testing

  • Ran unit tests for share-price-math (cargo test -p share-price-math), passing all 15 tests including the new zero-idle invariant test.

Closes #1632

@Junirezz
Junirezz merged commit d3b62c4 into Junirezz:main Oct 26, 2026
20 of 35 checks passed
@CathyZaks
CathyZaks deleted the fix/issue-1632-share-pricing-assets-base branch October 26, 2026 20:22
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.

[contract] Use one assets base for share pricing and reconcile conversion tests

2 participants