Estimate ERC-4626 vault shares for a deposit

A depositor entering a token amount needs an estimate in vault shares. An idealized conversion can omit fees that the deposit actually charges.

Compare conversion and preview at one block

In a hypothetical vault, convertToShares(1000) returns 500 share units while previewDeposit(1000) returns 495. Treat 495 as the fee-aware preview for that state. Keep both arguments and results in their respective smallest units.

convertToShares(1000) → 500
previewDeposit(1000)  → 495

Read asset() to identify the deposit token. Fetch its decimals for displaying the input and the vault share decimals for displaying the output. The two tokens may use different precisions.

Check limits independently

A successful preview does not establish that the receiver can deposit that amount. Query maxDeposit(receiver) and check the payer’s allowance separately. A change in vault state before execution can also change the actual share count. eips.ethereum.org EIP-4626