Context
Vault accounting state is split across VaultState (DataKey::State) and legacy scalar keys DataKey::TotalShares, DataKey::TotalAssets, and DataKey::TotalAssets used in deposit/withdraw.
Problem / Gap
deposit updates DataKey::TotalAssets, DataKey::TotalShares, and VaultState fields independently. total_shares() reads from VaultState while some paths read DataKey::TotalShares directly. Divergence risks incorrect share-price math and complicates upgrades.
Proposed approach
- Choose a single source of truth (prefer
VaultState) and deprecate redundant keys with a migration helper in upgrade.rs.
- Add invariant tests asserting
state.total_shares == sum(ShareBalance) and state.total_assets consistency with idle + strategy value.
- Document storage layout changes in
docs/architecture.md.
Files/areas affected
contracts/vault/src/lib.rs
contracts/vault/src/upgrade.rs
contracts/vault/src/test.rs, fuzz_math.rs
Context
Vault accounting state is split across
VaultState(DataKey::State) and legacy scalar keysDataKey::TotalShares,DataKey::TotalAssets, andDataKey::TotalAssetsused indeposit/withdraw.Problem / Gap
depositupdatesDataKey::TotalAssets,DataKey::TotalShares, andVaultStatefields independently.total_shares()reads fromVaultStatewhile some paths readDataKey::TotalSharesdirectly. Divergence risks incorrect share-price math and complicates upgrades.Proposed approach
VaultState) and deprecate redundant keys with a migration helper inupgrade.rs.state.total_shares == sum(ShareBalance)andstate.total_assetsconsistency with idle + strategy value.docs/architecture.md.Files/areas affected
contracts/vault/src/lib.rscontracts/vault/src/upgrade.rscontracts/vault/src/test.rs,fuzz_math.rs