Skip to content

Commit

Permalink
feat: move toUserAssetAmount to LSDWrapper
Browse files Browse the repository at this point in the history
  • Loading branch information
johnnyonline committed Sep 25, 2024
1 parent 24b72b5 commit 2de43b7
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 24 deletions.
8 changes: 8 additions & 0 deletions src/interfaces/IWrapper.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
26 changes: 3 additions & 23 deletions src/ynEIGEN/EigenStrategyManager.sol
Original file line number Diff line number Diff line change
Expand Up @@ -343,15 +343,15 @@ 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)))
);

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);
Expand All @@ -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.
Expand Down Expand Up @@ -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)))
);
Expand Down
13 changes: 13 additions & 0 deletions src/ynEIGEN/LSDWrapper.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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
// ============================================================================================
Expand Down
2 changes: 1 addition & 1 deletion src/ynEIGEN/RedemptionAssetsVault.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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!
}

/**
Expand Down

0 comments on commit 2de43b7

Please sign in to comment.