Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Audit preview/yneigen withdrawals #170

Draft
wants to merge 27 commits into
base: danoctavian/sc-1162/implement-generalized-withdrawal-queue-manager
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
2fe35e6
feat: logic wip
johnnyonline Sep 9, 2024
47a5837
pre-redesign
johnnyonline Sep 10, 2024
9843a92
feat: new design layout wip
johnnyonline Sep 13, 2024
812a0a1
feat: tests wip
johnnyonline Sep 14, 2024
8958973
feat: tests wip
johnnyonline Sep 14, 2024
48f6183
feat: tests wip
johnnyonline Sep 15, 2024
4d1049c
feat: tests wip
johnnyonline Sep 15, 2024
c594ec4
feat: pre req withdrawal tests
johnnyonline Sep 16, 2024
9aefcf8
feat: pre precision fix
johnnyonline Sep 16, 2024
a724e59
feat: setup tests wip
johnnyonline Sep 17, 2024
2f54591
fix: tests
johnnyonline Sep 17, 2024
7b35647
fix: https://github.com/yieldnest/yieldnest-protocol/pull/164#discuss…
johnnyonline Sep 19, 2024
92540f4
fix: move withdraw logic to strategy manager
johnnyonline Sep 19, 2024
4731a19
chore: remove comments
johnnyonline Sep 19, 2024
02260f0
chore: remove redundant deps
johnnyonline Sep 19, 2024
cc5c202
feat: refactor token wrapping
johnnyonline Sep 23, 2024
fc6afc0
fix: ci
johnnyonline Sep 24, 2024
a9ff9bc
chore: remove console.log
johnnyonline Sep 24, 2024
24b72b5
chore: add curly brackets
johnnyonline Sep 24, 2024
2de43b7
feat: move toUserAssetAmount to LSDWrapper
johnnyonline Sep 25, 2024
9895e89
fix: event
johnnyonline Sep 25, 2024
6e73ce7
chore: add natspec
johnnyonline Sep 25, 2024
8ba709a
feat: optimize getStakedAssetsBalances
johnnyonline Sep 26, 2024
2ae7917
feat: bundle call
johnnyonline Sep 26, 2024
be925af
feat: optimize gas on getStakedAssetsBalances()
johnnyonline Sep 27, 2024
471afc7
feat: optimize gas on getStakedAssetsBalances() with solady
johnnyonline Sep 27, 2024
2918a37
feat: remove from inner loop poc - costs more gas
johnnyonline Sep 27, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gas-snapshot
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
ynLSDeDepositAdapterTest:testTotalAssetsGas() (gas: 760757)
ynLSDeWithdrawalsTest:testTotalAssetsGas() (gas: 760757)
5 changes: 4 additions & 1 deletion .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,7 @@
[submodule "lib/eigenlayer-contracts"]
path = lib/eigenlayer-contracts
url = https://github.com/layr-labs/eigenlayer-contracts
commit = bda003385c5fec59e35196dc14d01f17d1eb7001
commit = bda003385c5fec59e35196dc14d01f17d1eb7001
[submodule "lib/solady"]
path = lib/solady
url = https://github.com/Vectorized/solady
1 change: 1 addition & 0 deletions lib/solady
Submodule solady added at e0ef35
2 changes: 2 additions & 0 deletions src/interfaces/IAssetRegistry.sol
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,13 @@ interface IAssetRegistry {
AssetStatus status;
}

function getAssets() external view returns (IERC20[] memory);
function assetData(IERC20 asset) external view returns (AssetData memory);
function addAsset(IERC20 asset) external;
function disableAsset(IERC20 asset) external;
function deleteAsset(IERC20 asset) external;
function totalAssets() external view returns (uint256);
function convertToUnitOfAccount(IERC20 asset, uint256 amount) external view returns (uint256);
function convertFromUnitOfAccount(IERC20 asset, uint256 amount) external view returns (uint256);
function assetIsSupported(IERC20 asset) external view returns (bool);
}
5 changes: 4 additions & 1 deletion src/interfaces/IEigenStrategyManager.sol
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ import {IStrategy} from "lib/eigenlayer-contracts/src/contracts/interfaces/IStra
import {IERC20} from "lib/openzeppelin-contracts/contracts/token/ERC20/IERC20.sol";
import {IwstETH} from "src/external/lido/IwstETH.sol";
import {IERC4626} from "@openzeppelin/contracts/interfaces/IERC4626.sol";

import {IynEigen} from "src/interfaces/IynEigen.sol";
import {ITokenStakingNodesManager} from "src/interfaces/ITokenStakingNodesManager.sol";

interface IEigenStrategyManager {

Expand All @@ -21,4 +22,6 @@ interface IEigenStrategyManager {
function woETH() external view returns (IERC4626);
function oETH() external view returns (IERC20);
function stETH() external view returns (IERC20);
function ynEigen() external view returns (IynEigen);
function tokenStakingNodesManager() external view returns (ITokenStakingNodesManager);
}
10 changes: 10 additions & 0 deletions src/interfaces/ITokenStakingNode.sol
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import {IERC20} from "lib/openzeppelin-contracts/contracts/token/ERC20/IERC20.so
import {ISignatureUtils} from "lib/eigenlayer-contracts/src/contracts/interfaces/ISignatureUtils.sol";
import {ITokenStakingNodesManager} from "src/interfaces/ITokenStakingNodesManager.sol";
import {IStrategy} from "lib/eigenlayer-contracts/src/contracts/interfaces/IStrategy.sol";
import {IDelegationManager} from "lib/eigenlayer-contracts/src/contracts/interfaces/IDelegationManager.sol";

interface ITokenStakingNode {

Expand Down Expand Up @@ -37,4 +38,13 @@ interface ITokenStakingNode {
) external;

function undelegate() external;

function getQueuedSharesAndWithdrawn(IStrategy _strategy, IERC20 _asset) external view returns (uint256, uint256);
function queueWithdrawals(IStrategy _strategy, uint256 _shares) external returns (bytes32[] memory _fullWithdrawalRoots);
function completeQueuedWithdrawals(uint256 _nonce, uint32 _startBlock, uint256 _shares, IStrategy _strategy, uint256[] memory _middlewareTimesIndexes) external;

function deallocateTokens(IERC20 _token, uint256 _amount) external;

function queuedShares(IStrategy _strategy) external view returns (uint256);
function withdrawn(IERC20 _token) external view returns (uint256);
}
2 changes: 2 additions & 0 deletions src/interfaces/ITokenStakingNodesManager.sol
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,6 @@ interface ITokenStakingNodesManager {
function hasYieldNestStrategyManagerRole(address) external view returns (bool);

function getNodeById(uint256 nodeId) external view returns (ITokenStakingNode);

function yieldNestStrategyManager() external view returns (address);
}
27 changes: 27 additions & 0 deletions src/interfaces/IWrapper.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
// SPDX-License-Identifier: BSD 3-Clause License
pragma solidity ^0.8.24;

import {IERC20} from "lib/openzeppelin-contracts/contracts/token/ERC20/IERC20.sol";

interface IWrapper {

/// @notice Wraps the given amount of the given token.
/// @param _amount The amount to wrap.
/// @param _token The token to wrap.
/// @return The amount of wrapped tokens and the wrapped token.
function wrap(uint256 _amount, IERC20 _token) external returns (uint256, IERC20);

/// @notice Unwraps the given amount of the given token.
/// @param _amount The amount to unwrap.
/// @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);
}
19 changes: 19 additions & 0 deletions src/interfaces/IYieldNestStrategyManager.sol
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,23 @@
pragma solidity ^0.8.24;

import {IERC20} from "lib/openzeppelin-contracts/contracts/token/ERC20/IERC20.sol";
import {ITokenStakingNodesManager} from "src/interfaces/ITokenStakingNodesManager.sol";
import {IRedemptionAssetsVault} from "src/interfaces/IRedemptionAssetsVault.sol";

interface IRedemptionAssetsVaultExt is IRedemptionAssetsVault {
function deposit(uint256 amount, address asset) external;
function balances(address asset) external view returns (uint256 amount);
}

interface IYieldNestStrategyManager {

struct WithdrawalAction {
uint256 nodeId;
uint256 amountToReinvest;
uint256 amountToQueue;
address asset;
}

function getStakedAssetsBalances(
IERC20[] calldata assets
) external view returns (uint256[] memory stakedBalances);
Expand All @@ -13,4 +27,9 @@ interface IYieldNestStrategyManager {

function supportsAsset(IERC20 asset) external view returns (bool);

function tokenStakingNodesManager() external view returns (ITokenStakingNodesManager);

function processPrincipalWithdrawals(WithdrawalAction[] calldata _actions) external;

function redemptionAssetsVault() external view returns (IRedemptionAssetsVaultExt);
}
9 changes: 9 additions & 0 deletions src/interfaces/IynEigen.sol
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,20 @@ interface IynEigen is IERC20 {

function previewDeposit(IERC20 asset, uint256 amount) external view returns (uint256);

function burn(uint256 amount) external;

function previewRedeem(IERC20 asset, uint256 shares) external view returns (uint256 assets);
function previewRedeem(uint256 shares) external view returns (uint256);

function convertToAssets(IERC20 asset, uint256 shares) external view returns (uint256);

function retrieveAssets(
IERC20[] calldata assetsToRetrieve,
uint256[] calldata amounts
) external;

function processWithdrawn(uint256 _amount, address _asset) external;

function assetBalances(IERC20[] calldata assetsArray) external view returns (uint256[] memory balances);
function assetBalance(IERC20 asset) external view returns (uint256 balance);

Expand Down
12 changes: 11 additions & 1 deletion src/ynEIGEN/AssetRegistry.sol
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import {IRateProvider} from "src/interfaces/IRateProvider.sol";
import {IAssetRegistry} from "src/interfaces/IAssetRegistry.sol";
import "lib/openzeppelin-contracts-upgradeable/contracts/access/AccessControlUpgradeable.sol";
import {IYieldNestStrategyManager} from "src/interfaces/IYieldNestStrategyManager.sol";

import {IRedemptionAssetsVaultExt} from "src/interfaces/IYieldNestStrategyManager.sol";

interface IAssetRegistryEvents {
event AssetAdded(address indexed asset);
Expand Down Expand Up @@ -286,8 +286,10 @@ interface IAssetRegistryEvents {
revert LengthMismatch(assetsCount, stakedAssetBalances.length);
}

IRedemptionAssetsVaultExt redemptionAssetsVault = strategyManager.redemptionAssetsVault();
for (uint256 i = 0; i < assetsCount; i++) {
assetBalances[i] += stakedAssetBalances[i];
if (address(redemptionAssetsVault) != address(0)) assetBalances[i] += redemptionAssetsVault.balances(address(assets[i]));
}
}

Expand Down Expand Up @@ -315,6 +317,14 @@ interface IAssetRegistryEvents {
: assetRate * amount / 1e18;
}

function convertFromUnitOfAccount(IERC20 asset, uint256 amount) public view returns (uint256) {
uint256 assetRate = rateProvider.rate(address(asset));
uint8 assetDecimals = IERC20Metadata(address(asset)).decimals();
return assetDecimals != 18
? amount * (10 ** assetDecimals) / assetRate
: amount * 1e18 / assetRate;
}

//--------------------------------------------------------------------------------------
//---------------------------------- PAUSING -----------------------------------------
//--------------------------------------------------------------------------------------
Expand Down
Loading
Loading