@@ -46,6 +46,26 @@ import {Math} from "../../../utils/math/Math.sol";
46
46
*
47
47
* To learn more, check out our xref:ROOT:erc4626.adoc[ERC-4626 guide].
48
48
* ====
49
+ *
50
+ * [NOTE]
51
+ * ====
52
+ * When overriding this contract, some elements must to be considered:
53
+ *
54
+ * * When overriding the behavior of the deposit or withdraw mechanisms, it is recommended to override the internal
55
+ * functions. Overriding {_deposit} automatically affects both {deposit} and {mint}. Similarly, overriding {_withdraw}
56
+ * automatically affects both {withdraw} and {redeem}. Overall it is not recommended to override the public facing
57
+ * functions since that could lead to inconsistent behaviors between the {deposit} and {mint} or between {withdraw} and
58
+ * {redeem}, which is documented to have lead to loss of funds.
59
+ *
60
+ * * Overrides to the deposit or withdraw mechanism must be reflected in the preview functions as well.
61
+ *
62
+ * * {maxWithdraw} depends on {maxRedeem}. Therefore, overriding {maxRedeem} only is enough. On the other hand,
63
+ * overriding {maxWithdraw} only would have no effect on {maxRedeem}, and could create an inconsistency between the two
64
+ * functions.
65
+ *
66
+ * * If {previewRedeem} is overridden to revert, {maxWithdraw} must be overridden as necessary to ensure it
67
+ * always return successfully.
68
+ * ====
49
69
*/
50
70
abstract contract ERC4626 is ERC20 , IERC4626 {
51
71
using Math for uint256 ;
@@ -142,7 +162,7 @@ abstract contract ERC4626 is ERC20, IERC4626 {
142
162
143
163
/// @inheritdoc IERC4626
144
164
function maxWithdraw (address owner ) public view virtual returns (uint256 ) {
145
- return _convertToAssets ( balanceOf (owner), Math.Rounding.Floor );
165
+ return previewRedeem ( maxRedeem (owner));
146
166
}
147
167
148
168
/// @inheritdoc IERC4626
0 commit comments