How do you get the amount of shares issued by a ERC-4626 deposit?

You can call previewDeposits but from what I've read it's not actually guaranteed that the amount of shares issued will be equal to the value returned be previewDeposit.

There doesn't seem to be any other function to query the amount of shares a user owns.

Is it safe to assume the amount of tokens a user will receive is atleast the value returned by previewDeposits?

Hey @jimmylaoo,

There doesn't seem to be any other function to query the amount of shares a user owns.

I'm not sure what this means, the amount of shares owned by the users can be always queried by calling balanceOf on the vault (it inherits from ERC20).

Is it safe to assume the amount of tokens a user will receive is atleast the value returned by previewDeposits ?

TLDR is yes, but within some boundaries.

The long answer is that when a user calls deposit(), the number of shares received will be calculated using previewDeposit, but if you estimate the shares by calling previewDeposit first and then making the actual deposit, there's a chance that the rate is different at the moment of depositing.

The rate difference is not an issue on its own if the vault has enough liquidity so that it becomes expensive to manipulate the rate. A very popular attack vector is an inflation attack, which we do have guidelines for.

If you're fine with a (very) small difference between the estimated shares and the actual shares gotten then it's safe to use previewDeposit (e.g. in a UI). However, if a critical component of your protocol depends on a correct estimation, it wouldn't be safe (e.g. updating an on-chain balance sheet from the estimation).