From c490ca3892310bdee3ed2bd71fd8f47349605230 Mon Sep 17 00:00:00 2001 From: 0xtekgrinder <0xtekgrinder@protonmail.com> Date: Wed, 17 Jul 2024 17:39:31 +0200 Subject: [PATCH] feat: ERC4626 take into account totalShares of strategy --- contracts/ERC4626Strategy.sol | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/contracts/ERC4626Strategy.sol b/contracts/ERC4626Strategy.sol index 00f3b8c..4029880 100644 --- a/contracts/ERC4626Strategy.sol +++ b/contracts/ERC4626Strategy.sol @@ -54,7 +54,8 @@ contract ERC4626Strategy is BaseStrategy { * @inheritdoc ERC4626 */ function maxMint(address) public view override returns (uint256) { - return ERC4626(STRATEGY_ASSET).maxMint(address(this)); + // We need to convert the total supply of the strategy asset to the total supply of the strategy + return (ERC4626(STRATEGY_ASSET).maxMint(address(this)) * totalSupply()) / ERC4626(STRATEGY_ASSET).totalSupply(); } /** @@ -72,6 +73,11 @@ contract ERC4626Strategy is BaseStrategy { * @inheritdoc ERC4626 */ function maxRedeem(address owner) public view override returns (uint256) { - return Math.min(balanceOf(owner), ERC4626(STRATEGY_ASSET).maxRedeem(address(this))); + return + Math.min( + balanceOf(owner), + (ERC4626(STRATEGY_ASSET).maxRedeem(address(this)) * totalSupply()) / + ERC4626(STRATEGY_ASSET).totalSupply() + ); } }