diff --git a/src/stake/LayerEdgeStaking.sol b/src/stake/LayerEdgeStaking.sol index a929afd..81336dd 100644 --- a/src/stake/LayerEdgeStaking.sol +++ b/src/stake/LayerEdgeStaking.sol @@ -673,6 +673,7 @@ contract LayerEdgeStaking is function _stake(uint256 amount, address userAddr, bool isNative) internal { require(amount > 0, "Cannot stake zero amount"); + require(nextJoinId <= MAX_USERS, "Max users reached"); UserInfo storage user = users[userAddr]; @@ -892,9 +893,9 @@ contract LayerEdgeStaking is } // Handle case where Tier 2 count stays the same else if (isRemoval) { - _findAndRecordTierChange(new_t1 + new_t2, n); - } else if (!isRemoval) { _findAndRecordTierChange(old_t1 + old_t2, n); + } else if (!isRemoval) { + _findAndRecordTierChange(new_t1 + new_t2, n); } } } diff --git a/test/stake/LayerEdgeStakingTest.t.sol b/test/stake/LayerEdgeStakingTest.t.sol index c4d5f55..0086539 100644 --- a/test/stake/LayerEdgeStakingTest.t.sol +++ b/test/stake/LayerEdgeStakingTest.t.sol @@ -2659,4 +2659,31 @@ contract LayerEdgeStakingTest is Test { ); vm.stopPrank(); } + + function test__checkBoundariesAndRecord_downgradingIssue() public { + for (uint256 i = 1; i <= 15; i++) { + address staker = makeAddr(string(abi.encodePacked("staker", i))); //staker 1 - 15 + vm.prank(admin); + token.transfer(staker, MIN_STAKE); + + vm.startPrank(staker); + token.approve(address(staking), MIN_STAKE); + staking.stake(MIN_STAKE); + vm.stopPrank(); + } + + address staker7 = makeAddr(string(abi.encodePacked("staker", uint256(7)))); + + (, LayerEdgeStaking.Tier expectedTier,,, LayerEdgeStaking.TierEvent[] memory tierHistory) = + staking.getAllInfoOfUser(staker7); + + LayerEdgeStaking.Tier lastUpdateTier = tierHistory[tierHistory.length - 1].to; + + //From audit report: + // expectedTier is the tier calculated from rank using getCurrentTier, while lastUpdateTier is the last update of the tier history which will be used to get the apy for reward cal for the current period + //vm.assertLt(uint(expectedTier), uint(lastUpdateTier)); + + //Fix + assertEq(uint256(expectedTier), uint256(lastUpdateTier)); + } }