|
| 1 | +// SPDX-License-Identifier: BUSL-1.1 |
| 2 | +pragma solidity ^0.8.12; |
| 3 | + |
| 4 | +import "src/test/integration/IntegrationBase.t.sol"; |
| 5 | +import "src/test/integration/User.t.sol"; |
| 6 | +import "src/test/integration/tests/utils.t.sol"; |
| 7 | + |
| 8 | +contract Integration_Delegate_Deposit_QueueWithdrawal_Complete is IntegrationTestUtils { |
| 9 | + |
| 10 | + function testFuzz_delegate_deposit_queueWithdrawal_completeAsShares(uint24 _random) public { |
| 11 | + // Configure the random parameters for the test |
| 12 | + _configRand({ |
| 13 | + _randomSeed: _random, |
| 14 | + _assetTypes: HOLDS_LST | HOLDS_ETH | HOLDS_ALL, |
| 15 | + _userTypes: DEFAULT | ALT_METHODS |
| 16 | + }); |
| 17 | + |
| 18 | + // Create a staker and an operator with a nonzero balance and corresponding strategies |
| 19 | + (User staker, IStrategy[] memory strategies, uint[] memory tokenBalances) = _newRandomStaker(); |
| 20 | + (User operator, ,) = _newRandomOperator(); |
| 21 | + |
| 22 | + // 1. Delegate to operator |
| 23 | + staker.delegateTo(operator); |
| 24 | + assertDelegationState(staker, operator, strategies, new uint256[](strategies.length)); // Initial shares are zero |
| 25 | + |
| 26 | + // 2. Deposit into strategy |
| 27 | + staker.depositIntoEigenlayer(strategies, tokenBalances); |
| 28 | + uint[] memory shares = _calculateExpectedShares(strategies, tokenBalances); |
| 29 | + |
| 30 | + // Check that the deposit increased operator shares the staker is delegated to |
| 31 | + assertDelegationState(staker, operator, strategies, shares); |
| 32 | + |
| 33 | + // 3. Queue Withdrawal |
| 34 | + IDelegationManager.Withdrawal[] memory withdrawals; |
| 35 | + bytes32[] memory withdrawalRoots; |
| 36 | + (withdrawals, withdrawalRoots) = staker.queueWithdrawals(strategies, shares); |
| 37 | + assertQueuedWithdrawalState(staker, operator, strategies, shares, withdrawals, withdrawalRoots); |
| 38 | + |
| 39 | + // 4. Complete Queued Withdrawal |
| 40 | + cheats.roll(block.number + delegationManager.withdrawalDelayBlocks()); |
| 41 | + for (uint i = 0; i < withdrawals.length; i++) { |
| 42 | + staker.completeQueuedWithdrawal(withdrawals[i], false); // 'false' indicates completion as shares |
| 43 | + assertWithdrawalAsSharesState(staker, withdrawals[i], strategies, shares); |
| 44 | + } |
| 45 | + } |
| 46 | + |
| 47 | + function testFuzz_delegate_deposit_queueWithdrawal_completeAsTokens(uint24 _random) public { |
| 48 | + // Configure the random parameters for the test |
| 49 | + _configRand({ |
| 50 | + _randomSeed: _random, |
| 51 | + _assetTypes: HOLDS_LST | HOLDS_ETH | HOLDS_ALL, |
| 52 | + _userTypes: DEFAULT | ALT_METHODS |
| 53 | + }); |
| 54 | + |
| 55 | + // Create a staker and an operator with a nonzero balance and corresponding strategies |
| 56 | + (User staker, IStrategy[] memory strategies, uint[] memory tokenBalances) = _newRandomStaker(); |
| 57 | + (User operator, ,) = _newRandomOperator(); |
| 58 | + |
| 59 | + // 1. Delegate to operator |
| 60 | + staker.delegateTo(operator); |
| 61 | + assertDelegationState(staker, operator, strategies, new uint256[](strategies.length)); // Initial shares are zero |
| 62 | + |
| 63 | + // 2. Deposit into strategy |
| 64 | + staker.depositIntoEigenlayer(strategies, tokenBalances); |
| 65 | + uint[] memory shares = _calculateExpectedShares(strategies, tokenBalances); |
| 66 | + |
| 67 | + // Check that the deposit increased operator shares the staker is delegated to |
| 68 | + assertDelegationState(staker, operator, strategies, shares); |
| 69 | + |
| 70 | + // 3. Queue Withdrawal |
| 71 | + IDelegationManager.Withdrawal[] memory withdrawals; |
| 72 | + bytes32[] memory withdrawalRoots; |
| 73 | + (withdrawals, withdrawalRoots) = staker.queueWithdrawals(strategies, shares); |
| 74 | + assertQueuedWithdrawalState(staker, operator, strategies, shares, withdrawals, withdrawalRoots); |
| 75 | + |
| 76 | + // 4. Complete Queued Withdrawal |
| 77 | + cheats.roll(block.number + delegationManager.withdrawalDelayBlocks()); |
| 78 | + for (uint i = 0; i < withdrawals.length; i++) { |
| 79 | + IERC20[] memory tokens = staker.completeQueuedWithdrawal(withdrawals[i], true); // Assuming 'true' for tokens |
| 80 | + uint[] memory expectedTokens = _calculateExpectedTokens(strategies, shares); |
| 81 | + assertWithdrawalAsTokensState(staker, withdrawals[i], strategies, shares, tokens, expectedTokens); |
| 82 | + } |
| 83 | + } |
| 84 | +} |
0 commit comments