You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Hi there, here's previewWithdraw as coded in the solmate ERC4626 mixin:
function previewWithdraw(uint256assets) publicviewvirtualreturns (uint256) {
uint256 supply = totalSupply; // Saves an extra SLOAD if totalSupply is non-zero.return supply ==0? assets : assets.mulDivUp(supply, totalAssets());
}
If totalSupply is 0 (meaning no vault shares exist), it returns the assets passed in.
However, here's previewWithdraw as coded in fubuloubo's repo (comparing these two since they're both listed as reference implementations on the official EIP-4626 page):
function previewWithdraw(uint256assets) externalviewreturns (uint256) {
uint256 shares =convertToShares(assets);
if (totalSupply() ==0) return0;
return shares;
}
In this case, if totalSupply() is 0, it returns 0.
How do we reconcile the two? Which is the correct behavior as per the spec? It makes more sense to me to return 0 since the spec says:
MUST return as close to and no fewer than the exact amount of Vault shares that would be burned in a withdraw call in the same transaction
The text was updated successfully, but these errors were encountered:
To reconcile the two you can return 0 instead of assets value if the totalSupply is zero. This behavior may not satisfy the requirement of returning the exact amount of Vault shares that would be burned in a withdraw call.
Hi there, here's
previewWithdraw
as coded in the solmate ERC4626 mixin:If
totalSupply
is 0 (meaning no vault shares exist), it returns theassets
passed in.However, here's
previewWithdraw
as coded in fubuloubo's repo (comparing these two since they're both listed as reference implementations on the official EIP-4626 page):In this case, if
totalSupply()
is 0, it returns 0.How do we reconcile the two? Which is the correct behavior as per the spec? It makes more sense to me to return 0 since the spec says:
The text was updated successfully, but these errors were encountered: