Implementation Lab
ERC-4626 Conversion and Rounding Lifecycle
Complete the Vault’s asset-share conversion functions and verify that deposits preserve the existing exchange rate.
What you will practice
Use a
1:1conversion whentotalSupply == 0.Convert assets to shares using
totalSupplyandtotalAssets().Convert shares to assets using
totalAssets()andtotalSupply.Pass the requested
Roundingdirection to_mulDiv.Keep the Vault exchange rate unchanged when a new user deposits.
Preparation and completion
Review the associated Learn before starting. You should understand the relationship between assets, shares, totalAssets(), totalSupply, and ERC-4626 rounding directions.
Completion outcome
By the end of this Lab, you will be able to implement and test proportional asset-share conversion, apply the correct rounding direction, and verify that new deposits do not unfairly change the value owned by existing users.