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:1 conversion when totalSupply == 0.

  • Convert assets to shares using totalSupply and totalAssets().

  • Convert shares to assets using totalAssets() and totalSupply.

  • Pass the requested Rounding direction 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.