Skip to content

Commit

Permalink
feat: tests wip
Browse files Browse the repository at this point in the history
  • Loading branch information
johnnyonline committed Nov 1, 2024
1 parent 9e6af0d commit a87e19c
Show file tree
Hide file tree
Showing 2 changed files with 201 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/ynEIGEN/withdrawalsProcessor.sol
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,11 @@ import {ITokenStakingNode} from "../interfaces/ITokenStakingNode.sol";
import {IAssetRegistry} from "../interfaces/IAssetRegistry.sol";
import {IYieldNestStrategyManager} from "../interfaces/IYieldNestStrategyManager.sol";

import "forge-std/console.sol";

/// @dev - there are inefficiencies if stratagies have different withdrawal delays
/// specifically, in `completeQueuedWithdrawals`, we need to wait for the longest withdrawal delay
contract withdrawalsProcessor is Ownable {
contract WithdrawalsProcessor is Ownable {

struct QueuedWithdrawal {
address node;
Expand Down Expand Up @@ -74,6 +75,9 @@ contract withdrawalsProcessor is Ownable {
assetRegistry = IAssetRegistry(_assetRegistry);
ynStrategyManager = IYieldNestStrategyManager(_ynStrategyManager);
delegationManager = IDelegationManager(_delegationManager);

minNodeShares = 1 ether;
minPendingWithdrawalRequestAmount = 0.1 ether;
}

//
Expand Down
196 changes: 196 additions & 0 deletions test/integration/ynEIGEN/Withdrawals.t.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,196 @@
// SPDX-License-Identifier: BSD 3-Clause License
pragma solidity 0.8.24;

import {WithdrawalsProcessor} from "../../../src/ynEIGEN/withdrawalsProcessor.sol";

import {ITokenStakingNode} from "../../../src/interfaces/ITokenStakingNode.sol";

import "./ynEigenIntegrationBaseTest.sol";

contract WithdrawalsTest is ynEigenIntegrationBaseTest {

bool private _setup = true;

address public constant user = address(0x42069);
address public constant owner = address(0x42069420);

ITokenStakingNode public tokenStakingNode;
WithdrawalsProcessor public withdrawalsProcessor;

function setUp() public virtual override {

super.setUp();

// deal assets to user
{
deal({ token: chainAddresses.lsd.WSTETH_ADDRESS, to: user, give: 1000 ether });
deal({ token: chainAddresses.lsd.WOETH_ADDRESS, to: user, give: 1000 ether });
deal({ token: chainAddresses.lsd.SFRXETH_ADDRESS, to: user, give: 1000 ether });
}

// unpause transfers
{
vm.prank(actors.admin.UNPAUSE_ADMIN);
ynEigenToken.unpauseTransfers();
}

// grant burner role
{
vm.startPrank(actors.admin.STAKING_ADMIN);
ynEigenToken.grantRole(ynEigenToken.BURNER_ROLE(), address(withdrawalQueueManager));
vm.stopPrank();
}

// // user depost
// {
// uint256 _amount = 100 ether;

// vm.startPrank(user);

// // deposit wsteth
// {
// IERC20(chainAddresses.lsd.WSTETH_ADDRESS).approve(address(ynEigenToken), _amount);
// ynEigenToken.deposit(IERC20(chainAddresses.lsd.WSTETH_ADDRESS), _amount, user);
// }

// // deposit woeth
// {
// IERC20(chainAddresses.lsd.WOETH_ADDRESS).approve(address(ynEigenToken), _amount);
// ynEigenToken.deposit(IERC20(chainAddresses.lsd.WOETH_ADDRESS), _amount, user);
// }

// // deposit sfrxeth
// {
// IERC20(chainAddresses.lsd.SFRXETH_ADDRESS).approve(address(ynEigenToken), _amount);
// ynEigenToken.deposit(IERC20(chainAddresses.lsd.SFRXETH_ADDRESS), _amount, user);
// }
// vm.stopPrank();
// }

// // request withdrawl
// {
// uint256 _balance = ynEigenToken.balanceOf(user);
// vm.startPrank(user);
// ynEigenToken.approve(address(withdrawalQueueManager), _balance);
// withdrawalQueueManager.requestWithdrawal(_balance);
// vm.stopPrank();
// }

// // top up redemptionAssetsVault
// {
// address _topper = address(0x420420);
// uint256 _amount = 50; // 50 wei
// deal({ token: chainAddresses.lsd.WSTETH_ADDRESS, to: _topper, give: _amount });
// deal({ token: chainAddresses.lsd.WOETH_ADDRESS, to: _topper, give: _amount });
// deal({ token: chainAddresses.lsd.SFRXETH_ADDRESS, to: _topper, give: _amount });
// vm.startPrank(_topper);
// IERC20(chainAddresses.lsd.WSTETH_ADDRESS).approve(address(redemptionAssetsVault), _amount);
// redemptionAssetsVault.deposit(_amount, chainAddresses.lsd.WSTETH_ADDRESS);
// IERC20(chainAddresses.lsd.WOETH_ADDRESS).approve(address(redemptionAssetsVault), _amount);
// redemptionAssetsVault.deposit(_amount, chainAddresses.lsd.WOETH_ADDRESS);
// IERC20(chainAddresses.lsd.SFRXETH_ADDRESS).approve(address(redemptionAssetsVault), _amount);
// redemptionAssetsVault.deposit(_amount, chainAddresses.lsd.SFRXETH_ADDRESS);
// vm.stopPrank();
// }

// deploy withdrawalsProcessor
{
withdrawalsProcessor = new WithdrawalsProcessor(
owner,
address(withdrawalQueueManager),
address(tokenStakingNodesManager),
address(assetRegistry),
address(eigenStrategyManager),
address(eigenLayer.delegationManager)
);
}

// grant withdrawer role to withdrawalsProcessor
{
vm.startPrank(actors.wallets.YNSecurityCouncil);
eigenStrategyManager.grantRole(eigenStrategyManager.STAKING_NODES_WITHDRAWER_ROLE(), address(withdrawalsProcessor));
vm.stopPrank();
}
}

function testSanity() public {
assertTrue(true, "testSanity: E0");
}

//
// queueWithdrawals
//

function testQueueWithdrawalSTETH(uint256 _amount) public {
if (_setup) setup_(_amount);

IStrategy _strategy = IStrategy(chainAddresses.lsdStrategies.STETH_STRATEGY_ADDRESS);
uint256 _shares = _strategy.shares((address(tokenStakingNode)));

uint256 _totalAssetsBefore = ynEigenToken.totalAssets();

// vm.prank(actors.ops.YNEIGEN_WITHDRAWAL_MANAGER);
// tokenStakingNode.queueWithdrawals(_strategy, _shares);
vm.prank(owner);
withdrawalsProcessor.queueWithdrawals();

assertEq(ynEigenToken.totalAssets(), _totalAssetsBefore, "testQueueWithdrawalSTETH: E0");
assertEq(tokenStakingNode.queuedShares(_strategy), _shares, "testQueueWithdrawalSTETH: E1");
}

//
// internal helpers
//

// (1) create token staking node
// (2) user deposit
// (3) stake assets to node
// (4) user request withdrawal
function setup_(uint256 _amount) private {
vm.assume(_amount > 10_000 && _amount < 100 ether);

// create token staking node
{
vm.prank(actors.ops.STAKING_NODE_CREATOR);
tokenStakingNode = tokenStakingNodesManager.createTokenStakingNode();
}

// user deposit

uint256 _len = 3;
uint256[] memory _amounts = new uint256[](_len);
IERC20[] memory _assetsToDeposit = new IERC20[](_len);
{
_assetsToDeposit[0] = IERC20(chainAddresses.lsd.WSTETH_ADDRESS);
_assetsToDeposit[1] = IERC20(chainAddresses.lsd.WOETH_ADDRESS);
_assetsToDeposit[2] = IERC20(chainAddresses.lsd.SFRXETH_ADDRESS);

_amounts[0] = _amount;
_amounts[1] = _amount;
_amounts[2] = _amount;

vm.startPrank(user);
for (uint256 i = 0; i < _len; i++) {
_assetsToDeposit[i].approve(address(ynEigenToken), _amounts[i]);
ynEigenToken.deposit(_assetsToDeposit[i], _amounts[i], user);
}
vm.stopPrank();
}

// stake assets to node
{
vm.startPrank(actors.ops.STRATEGY_CONTROLLER);
eigenStrategyManager.stakeAssetsToNode(tokenStakingNode.nodeId(), _assetsToDeposit, _amounts);
vm.stopPrank();
}

// request withdrawl
{
uint256 _balance = ynEigenToken.balanceOf(user);
vm.startPrank(user);
ynEigenToken.approve(address(withdrawalQueueManager), _balance);
withdrawalQueueManager.requestWithdrawal(_balance);
vm.stopPrank();
}
}
}

0 comments on commit a87e19c

Please sign in to comment.