diff --git a/src/Staking.sol b/src/Staking.sol index 2f608a8..a8e834b 100644 --- a/src/Staking.sol +++ b/src/Staking.sol @@ -286,24 +286,25 @@ contract Staking is ERC20VotesUpgradeable, Ownable2StepUpgradeable { } // Checks below only apply if keyper is still a keyper - // if keyper is not a keyper anymore, anyone can unstake, lock period is + // if keyper is not a keyper anymore, anyone can unstake for them, lock period is // ignored and minStake is not enforced if (keypers[keyper]) { + // Only the keyper can unstake require(msg.sender == keyper, OnlyKeyper()); // If the lock period is less than the global lock period, the stake // must be locked for the lock period if (lockPeriod < keyperStake.lockPeriod) { require( - keyperStake.timestamp + lockPeriod <= block.timestamp, + block.timestamp > keyperStake.timestamp + lockPeriod, StakeIsStillLocked() ); } else { // If the global lock period is greater than the stake lock period, // the stake must be locked for the stake lock period require( - keyperStake.timestamp + keyperStake.lockPeriod <= - block.timestamp, + block.timestamp > + keyperStake.timestamp + keyperStake.lockPeriod, StakeIsStillLocked() ); } diff --git a/test/Staking.t.sol b/test/Staking.t.sol index cba8dae..ad4613c 100644 --- a/test/Staking.t.sol +++ b/test/Staking.t.sol @@ -1132,13 +1132,13 @@ contract Unstake is StakingTest { _mintGovToken(_depositor, _amount); _setKeyper(_depositor, true); - uint256 stakeIndex = _stake(_depositor, _amount); + uint256 stakeId = _stake(_depositor, _amount); _jumpAhead(_jump); vm.prank(_depositor); vm.expectRevert(Staking.StakeIsStillLocked.selector); - staking.unstake(_depositor, stakeIndex, 0); + staking.unstake(_depositor, stakeId, 0); } function testFuzz_RevertIf_StakeIsStillLockedAfterLockPeriodChangedToLessThanCurrent( @@ -1147,7 +1147,7 @@ contract Unstake is StakingTest { uint256 _jump ) public { _amount = _boundToRealisticStake(_amount); - _jump = bound(_jump, vm.getBlockTimestamp(), LOCK_PERIOD); + _jump = bound(_jump, vm.getBlockTimestamp(), LOCK_PERIOD - 1); _mintGovToken(_depositor, _amount); _setKeyper(_depositor, true); @@ -1155,7 +1155,7 @@ contract Unstake is StakingTest { uint256 stakeIndex = _stake(_depositor, _amount); staking.setLockPeriod(_jump); - _jumpAhead(_jump - 1); + _jumpAhead(_jump); vm.prank(_depositor); vm.expectRevert(Staking.StakeIsStillLocked.selector);