nodeset-org / constellation

GNU General Public License v3.0
5 stars 0 forks source link

`previewDeposit()` and `previewMint()` on vaults return incorrect values when `totalSupply() == 0` and `totalAssets() > 0` #350

Open VVander opened 1 month ago

VVander commented 1 month ago

If there is ETH, WETH, or RPL sent to the OperatorDistributor before any shares are minted, previewMint() and previewDeposit() are broken. This is because we override the totalAssets() function to take into account the OperatorDistributor's assets, but totalSupply() is still 0 when checked in _convertToAssets() or _convertToShares().

Unfortunately, we can't stop users from sending WETH or RPL to the OperatorDistributor contract before shares are minted, so the easiest fix might be to simply use different logic for in the special case where totalSupply() is 0:

Note that this is low priority because they are only preview functions and the rest of the protocol still works effectively in this scenario.

VVander commented 1 month ago

See test-first-mint.ts for tests that should pass if this is fixed (they are currently skipped).