Skip to content

Commit

Permalink
refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
yield-farmer-1 committed Feb 15, 2025
1 parent f9a8922 commit d24975f
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 101 deletions.
3 changes: 2 additions & 1 deletion src/StakingNode.sol
Original file line number Diff line number Diff line change
Expand Up @@ -543,7 +543,8 @@ contract StakingNode is IStakingNode, StakingNodeEvents, ReentrancyGuardUpgradea

syncQueuedShares();

delegatedTo = address(0);
IDelegationManager delegationManager = IDelegationManager(address(stakingNodesManager.delegationManager()));
delegatedTo = delegationManager.delegatedTo(address(this));
}

//--------------------------------------------------------------------------------------
Expand Down
2 changes: 1 addition & 1 deletion src/interfaces/IStakingNode.sol
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ interface IStakingNode {

function isSynchronized() external view returns (bool);

function synchronize(uint256 queuedShares, uint32 lastQueuedWithdrawalBlockNumber) external;
function synchronize() external;

function syncQueuedShares() external;

Expand Down
115 changes: 18 additions & 97 deletions test/integration/StakingNode.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -418,7 +418,7 @@ contract StakingNodeDelegation is StakingNodeTestBase {

// Synchronize
vm.prank(actors.admin.STAKING_NODES_DELEGATOR);
stakingNodeInstance.synchronize(32 ether * validatorIndices.length, undelegateBlockNumber);
stakingNodeInstance.synchronize();

// Verify total assets stayed the same
assertEq(yneth.totalAssets(), initialTotalAssets, "Total assets should not change after synchronization");
Expand Down Expand Up @@ -516,7 +516,7 @@ contract StakingNodeDelegation is StakingNodeTestBase {

// Synchronize
vm.prank(actors.admin.STAKING_NODES_DELEGATOR);
stakingNodeInstance.synchronize(32 ether * validatorIndices.length, undelegateBlockNumber);
stakingNodeInstance.synchronize();

// Verify total assets stayed the same
assertEq(yneth.totalAssets(), initialTotalAssets, "Total assets should not change after synchronization");
Expand Down Expand Up @@ -629,7 +629,7 @@ contract StakingNodeDelegation is StakingNodeTestBase {

// Synchronize
vm.prank(actors.admin.STAKING_NODES_DELEGATOR);
stakingNodeInstance.synchronize(32 ether * validatorIndices.length, undelegateBlockNumber);
stakingNodeInstance.synchronize();

// Verify total assets stayed the same
assertEq(yneth.totalAssets(), initialTotalAssets, "Total assets should not change after synchronization");
Expand Down Expand Up @@ -1766,31 +1766,6 @@ contract StakingNodeWithdrawals is StakingNodeTestBase {

}

contract StakingNodeSyncQueuedShares is StakingNodeTestBase {

address user = vm.addr(156_737);

uint256 nodeId;
IStakingNode stakingNodeInstance;

function setUp() public override {
super.setUp();

nodeId = createStakingNodes(1)[0];
stakingNodeInstance = stakingNodesManager.nodes(nodeId);
}

function testSyncQueuedSharesFailWhenNotAdmin() public {
vm.expectRevert();
stakingNodeInstance.syncQueuedShares();
}

function testSyncQueuedSharesSuccessWhenAdmin() public {
vm.prank(actors.admin.STAKING_NODES_DELEGATOR);
stakingNodeInstance.syncQueuedShares();
}
}

contract StakingNodeOperatorSlashing is StakingNodeTestBase {
using stdStorage for StdStorage;
using BytesLib for bytes;
Expand All @@ -1807,6 +1782,8 @@ contract StakingNodeOperatorSlashing is StakingNodeTestBase {
uint256 nodeId;
IStakingNode stakingNodeInstance;
IAllocationManager allocationManager;
uint256 validatorCount = 2;
uint256 totalDepositedAmount;

function setUp() public override {
super.setUp();
Expand Down Expand Up @@ -1870,35 +1847,28 @@ contract StakingNodeOperatorSlashing is StakingNodeTestBase {
allocationManager.registerForOperatorSets(operator1, registerParams);
allocationManager.modifyAllocations(operator1, allocateParams);
vm.stopPrank();
}

function testSlashedOperatorBeforeQueuedWithdrawals() public {
uint256 validatorCount = 2;
uint256 totalDepositedAmount;


{
// Setup
uint256 depositAmount = 32 ether;
totalDepositedAmount = depositAmount * validatorCount;
address user = vm.addr(156_737);
vm.deal(user, 1000 ether);
yneth.depositETH{value: totalDepositedAmount}(user); // Deposit for validators
}

{
// Setup: Create multiple validators and verify withdrawal credentials
uint40[] memory validatorIndices = createValidators(repeat(nodeId, validatorCount), validatorCount);
beaconChain.advanceEpoch_NoRewards();
registerValidators(repeat(nodeId, validatorCount));

beaconChain.advanceEpoch_NoRewards();
yneth.depositETH{value: totalDepositedAmount}(user);

for (uint256 i = 0; i < validatorCount; i++) {
_verifyWithdrawalCredentials(nodeId, validatorIndices[i]);
}
// Create and setup validators
validatorIndices = createValidators(repeat(nodeId, validatorCount), validatorCount);
beaconChain.advanceEpoch_NoRewards();
registerValidators(repeat(nodeId, validatorCount));
beaconChain.advanceEpoch_NoRewards();

beaconChain.advanceEpoch_NoRewards();
for (uint256 i = 0; i < validatorCount; i++) {
_verifyWithdrawalCredentials(nodeId, validatorIndices[i]);
}
beaconChain.advanceEpoch_NoRewards();
}

function testSlashedOperatorBeforeQueuedWithdrawals() public {

// Capture initial state
StateSnapshot memory initialState = takeSnapshot(nodeId);
Expand Down Expand Up @@ -1966,33 +1936,6 @@ contract StakingNodeOperatorSlashing is StakingNodeTestBase {
}

function testSlashedOperatorBetweenQueuedAndCompletedWithdrawals() public {
uint256 validatorCount = 2;
uint256 totalDepositedAmount;

{
// Setup
uint256 depositAmount = 32 ether;
totalDepositedAmount = depositAmount * validatorCount;
address user = vm.addr(156_737);
vm.deal(user, 1000 ether);
yneth.depositETH{value: totalDepositedAmount}(user); // Deposit for validators
}

uint40[] memory validatorIndices;
{
// Setup: Create multiple validators and verify withdrawal credentials
validatorIndices = createValidators(repeat(nodeId, validatorCount), validatorCount);
beaconChain.advanceEpoch_NoRewards();
registerValidators(repeat(nodeId, validatorCount));

beaconChain.advanceEpoch_NoRewards();

for (uint256 i = 0; i < validatorCount; i++) {
_verifyWithdrawalCredentials(nodeId, validatorIndices[i]);
}

beaconChain.advanceEpoch_NoRewards();
}

// Capture initial state
StateSnapshot memory initialState = takeSnapshot(nodeId);
Expand Down Expand Up @@ -2090,28 +2033,6 @@ contract StakingNodeOperatorSlashing is StakingNodeTestBase {
}

function testSlashedOperatorAfterCompletedWithdrawals() public {
uint256 validatorCount = 2;
uint256 totalDepositedAmount;

// Setup initial state
{
uint256 depositAmount = 32 ether;
totalDepositedAmount = depositAmount * validatorCount;
address user = vm.addr(156_737);
vm.deal(user, 1000 ether);
yneth.depositETH{value: totalDepositedAmount}(user);
}

// Create and setup validators
uint40[] memory validatorIndices = createValidators(repeat(nodeId, validatorCount), validatorCount);
beaconChain.advanceEpoch_NoRewards();
registerValidators(repeat(nodeId, validatorCount));
beaconChain.advanceEpoch_NoRewards();

for (uint256 i = 0; i < validatorCount; i++) {
_verifyWithdrawalCredentials(nodeId, validatorIndices[i]);
}
beaconChain.advanceEpoch_NoRewards();

// Capture initial state
StateSnapshot memory initialState = takeSnapshot(nodeId);
Expand Down
4 changes: 2 additions & 2 deletions test/scenarios/fork/ynETH/Delegation.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ contract YnETHDelegationScenarioTest is WithdrawalsScenarioTestBase {

// Call synchronize after verifying not synchronized
vm.prank(actors.admin.STAKING_NODES_DELEGATOR);
stakingNode.synchronize(podSharesBefore, blockNumberBefore);
stakingNode.synchronize();

// Assert staking node balance remains unchanged after synchronization
assertEq(stakingNodeBalanceBefore, stakingNode.getETHBalance(), "Staking node balance should not change after synchronization");
Expand Down Expand Up @@ -124,7 +124,7 @@ contract YnETHDelegationScenarioTest is WithdrawalsScenarioTestBase {
// Call synchronize after verifying synchronized
vm.expectRevert(StakingNode.AlreadySynchronized.selector);
vm.prank(actors.admin.STAKING_NODES_DELEGATOR);
stakingNode.synchronize(podSharesBefore, blockNumberBefore);
stakingNode.synchronize();

// Assert staking node balance remains unchanged after synchronization
assertEq(stakingNodeBalanceBefore, stakingNode.getETHBalance(), "Staking node balance should not change after synchronization");
Expand Down

0 comments on commit d24975f

Please sign in to comment.