Why does `mint` in ERC4626 call `_deposit` function?

In the OZ implementation of EIP-4626, the mint function calls _deposit function to move assets to the vault and then mints the corresponding shares of tokens. My thought was mint function just calls _mint function to mint shares for some reasons like gifting, rebasing, and etc. But now, the mint function seems to require depositing assets. Although it's a virtual public function and can be overriden, I'm just wondering what the reationale is behind it and if it's better to simply call _mint function by default. Thanks.

1 Like


The deposit function does more than calling _mint. Just calling _mint directly would remove an important part of the process: the transfer of the underlying tokens from the caller to the vault, which is what funds the vault. Without funding the vault with an underlying asset for each mint, it would unbalance the ratio between available assets and available shares, and modify how many shares can be minted by transferring x amount of assets, causing inflation.


Hey @JulissaDantes , thanks for your explanations. Now I see the difference between mint and deposit. The former requires the number of shares as the input and the later requires the amount of assets. Under the hood, they both call _depositFor with the calculated input variables. I got this.

Somehow, I was thinking about letting another part of the dapp take care of the depositing and this vault is only taking care of the shares. Then, I guess another mint public function can be created to overload mint with certain modifiers.

Okay, I think I've got this through. Many thanks.

1 Like