Repository navigation
[contract] Use one assets base for share pricing and reconcile conversion tests - #1710
Merged
Junirezz merged 1 commit intoOct 26, 2026
Conversation
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.
[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 idlestate.total_assetsrather thantotal_assets(), which includes strategy valuation. As a result:vault/src/test.rs, expectations afterdivest(10)assumed an incorrect asset base.share-price-math/src/fuzz_invariants.rs, the validity filter prematurely returned ontotal_assets == 0 && total_shares > 0, skipping the zero-idle state where idle assets are zero while shares remain outstanding.Solution
total_assets()(idle assets plus strategy value) as the canonical asset base across all conversion and deposit/withdrawal functions.test_vault_with_benji_strategywithdrawal math to reflect proportional share oftotal_assets().is_valid_vault_stateinfuzz_invariants.rsto allow non-negative assets with positive shares so the zero-idle state is exercised.Changes
contracts/vault/src/lib.rs:share_price: Usestotal_assets(env).unwrap_or(state.total_assets)instead ofstate.total_assets.calculate_shares&calculate_assets: Readstotal_assets(env)?and converts against total vault assets.deposit&gasless_deposit: Readstotal_assets(env)?for TVL risk limits,try_assets_to_shares, and effective asset computation for dust sweeping.withdraw&execute_withdrawal: Usestotal_assets(env)?to determineassets_to_return.contracts/vault/src/test.rs:test_vault_with_benji_strategyexpectations where 50 shares withdraw 53 assets out of 106 total assets.test_deposit_mints_at_correct_price_while_strategy_holds_part_of_assets.contracts/share-price-math/src/fuzz_invariants.rs:is_valid_vault_statecondition to(total_shares == 0 && total_assets == 0) || (total_shares > 0 && total_assets >= 0).zero_idle_state_invariant_holds.Testing
share-price-math(cargo test -p share-price-math), passing all 15 tests including the new zero-idle invariant test.Closes #1632