From 2de43b785a001986a5cc10abb76e0fca2974f70d Mon Sep 17 00:00:00 2001 From: johnnyonline Date: Wed, 25 Sep 2024 23:25:29 +0900 Subject: [PATCH] feat: move toUserAssetAmount to LSDWrapper --- src/interfaces/IWrapper.sol | 8 ++++++++ src/ynEIGEN/EigenStrategyManager.sol | 26 +++----------------------- src/ynEIGEN/LSDWrapper.sol | 13 +++++++++++++ src/ynEIGEN/RedemptionAssetsVault.sol | 2 +- 4 files changed, 25 insertions(+), 24 deletions(-) diff --git a/src/interfaces/IWrapper.sol b/src/interfaces/IWrapper.sol index 232ccb551..025d5ee31 100644 --- a/src/interfaces/IWrapper.sol +++ b/src/interfaces/IWrapper.sol @@ -16,4 +16,12 @@ interface IWrapper { /// @param _token The token to unwrap. /// @return The amount of unwrapped tokens and the unwrapped token. function unwrap(uint256 _amount, IERC20 _token) external returns (uint256, IERC20); + + /// @notice Converts the user's underlying asset amount to the equivalent user asset amount. + /// @dev This function handles the conversion for wrapped staked ETH (wstETH) and wrapped other ETH (woETH), + /// returning the equivalent amount in the respective wrapped token. + /// @param _asset The ERC20 token for which the conversion is being made. + /// @param _userUnderlyingView The amount of the underlying asset. + /// @return The equivalent amount in the user asset denomination. + function toUserAssetAmount(IERC20 _asset, uint256 _userUnderlyingView) external view returns (uint256); } \ No newline at end of file diff --git a/src/ynEIGEN/EigenStrategyManager.sol b/src/ynEIGEN/EigenStrategyManager.sol index ed01a52c3..cc4052a51 100644 --- a/src/ynEIGEN/EigenStrategyManager.sol +++ b/src/ynEIGEN/EigenStrategyManager.sol @@ -343,7 +343,7 @@ contract EigenStrategyManager is for (uint256 i; i < nodesCount; i++ ) { ITokenStakingNode node = nodes[i]; - uint256 strategyBalance = toUserAssetAmount( + uint256 strategyBalance = wrapper.toUserAssetAmount( asset, strategies[asset].userUnderlyingView((address(node))) ); @@ -351,7 +351,7 @@ contract EigenStrategyManager is uint256 strategyWithdrawalQueueBalance; uint256 queuedShares = node.queuedShares(strategies[asset]); if (queuedShares > 0) { - strategyWithdrawalQueueBalance = toUserAssetAmount(asset, strategies[asset].sharesToUnderlyingView(queuedShares)); + strategyWithdrawalQueueBalance = wrapper.toUserAssetAmount(asset, strategies[asset].sharesToUnderlyingView(queuedShares)); } uint256 strategyWithdrawnBalance = node.withdrawn(asset); @@ -361,26 +361,6 @@ contract EigenStrategyManager is } } - /** - * @notice Converts the user's underlying asset amount to the equivalent user asset amount. - * @dev This function handles the conversion for wrapped staked ETH (wstETH) and wrapped other ETH (woETH), - * returning the equivalent amount in the respective wrapped token. - * @param asset The ERC20 token for which the conversion is being made. - * @param userUnderlyingView The amount of the underlying asset. - * @return The equivalent amount in the user asset denomination. - */ - function toUserAssetAmount(IERC20 asset, uint256 userUnderlyingView) public view returns (uint256) { - if (address(asset) == address(wstETH)) { - // Adjust for wstETH using view method, converting stETH to wstETH - return wstETH.getWstETHByStETH(userUnderlyingView); - } - if (address(asset) == address(woETH)) { - // Adjust for woETH using view method, converting oETH to woETH - return woETH.previewDeposit(userUnderlyingView); - } - return userUnderlyingView; - } - /** * @notice Retrieves the total staked balance of a specific asset across all nodes. * @param asset The ERC20 token for which the staked balance is to be retrieved. @@ -422,7 +402,7 @@ contract EigenStrategyManager is ITokenStakingNode node ) internal view returns (uint256 stakedBalance) { - uint256 strategyBalance = toUserAssetAmount( + uint256 strategyBalance = wrapper.toUserAssetAmount( asset, strategies[asset].userUnderlyingView((address(node))) ); diff --git a/src/ynEIGEN/LSDWrapper.sol b/src/ynEIGEN/LSDWrapper.sol index 6a08f50eb..50039bb58 100644 --- a/src/ynEIGEN/LSDWrapper.sol +++ b/src/ynEIGEN/LSDWrapper.sol @@ -70,6 +70,19 @@ contract LSDWrapper is IWrapper, Initializable { } } + /// @inheritdoc IWrapper + function toUserAssetAmount(IERC20 _asset, uint256 _userUnderlyingView) external view returns (uint256) { + if (_asset == wstETH) { + // Adjust for wstETH using view method, converting stETH to wstETH + return IwstETH(address(wstETH)).getWstETHByStETH(_userUnderlyingView); + } + if (_asset == woETH) { + // Adjust for woETH using view method, converting oETH to woETH + return IERC4626(address(woETH)).previewDeposit(_userUnderlyingView); + } + return _userUnderlyingView; + } + // ============================================================================================ // Errors // ============================================================================================ diff --git a/src/ynEIGEN/RedemptionAssetsVault.sol b/src/ynEIGEN/RedemptionAssetsVault.sol index bab5ac024..0d1d78a06 100644 --- a/src/ynEIGEN/RedemptionAssetsVault.sol +++ b/src/ynEIGEN/RedemptionAssetsVault.sol @@ -142,7 +142,7 @@ contract RedemptionAssetsVault is IRedemptionAssetsVault, Initializable, AccessC } } - emit AssetTransferred(ETH_ASSET, msg.sender, to, amount); + emit AssetTransferred(ETH_ASSET, msg.sender, to, amount); // @todo - `amount` here is always 0! } /**