Skip to content

Commit

Permalink
Fixes: L2Reward.extendDuration for expired locking positions (#110)
Browse files Browse the repository at this point in the history
* fixes: L2Reward.extendDuration for expired locking positions
Considers today as the expiry date for an expired locking position.

* adds assertions to test and updated L2Reward._extendDuration as per feedback

* Refactors L2Reward.extendDuration
  • Loading branch information
has5aan authored May 7, 2024
1 parent 7821959 commit 93ea20e
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 7 deletions.
6 changes: 3 additions & 3 deletions src/L2/L2Reward.sol
Original file line number Diff line number Diff line change
Expand Up @@ -406,15 +406,15 @@ contract L2Reward is Initializable, Ownable2StepUpgradeable, UUPSUpgradeable, IS
// locking period has not finished
if (lockingPosition.expDate > todayDay()) {
dailyUnlockedAmounts[lockingPosition.expDate] -= lockingPosition.amount;
dailyUnlockedAmounts[lockingPosition.expDate + durationExtension] += lockingPosition.amount;
}
// locking period has expired, re-lock amount
// locking period has expired, re-lock amount and assume that expiry date is today
else {
dailyUnlockedAmounts[todayDay() + durationExtension] += lockingPosition.amount;
totalAmountLocked += lockingPosition.amount;
pendingUnlockAmount += lockingPosition.amount;
totalWeight += lockingPosition.amount * OFFSET;
}

dailyUnlockedAmounts[lockingPosition.expDate + durationExtension] += lockingPosition.amount;
}
}

Expand Down
26 changes: 22 additions & 4 deletions test/L2/L2Reward.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -1292,21 +1292,39 @@ contract L2RewardTest is Test {
extensions[0].durationExtension = 50;
// For expired positions, amount is effectively re-locked for the extended duration.
uint256 weightIncrease = (amount * extensions[0].durationExtension) + (amount * l2Reward.OFFSET());
balance = l2LiskToken.balanceOf(staker);

uint256 expectedReward = 11.9 * 10 ** 18;

vm.startPrank(staker);
then_eventRewardsClaimedIsEmitted(extensions[0].lockID, expectedReward);
l2Reward.extendDuration(extensions);
vm.stopPrank();

assertEq(l2LiskToken.balanceOf(staker), balance + expectedReward);
assertEq(l2LiskToken.balanceOf(staker), balance + expectedReward - amount);
assertEq(l2Reward.totalWeight(), weightIncrease);

assertEq(l2Reward.totalAmountLocked(), amount);
assertEq(l2Reward.pendingUnlockAmount(), amount);
assertEq(l2Reward.dailyUnlockedAmounts(deploymentDate + duration + extensions[0].durationExtension), amount);

// today is assumed to be the expiry date
assertEq(l2Reward.dailyUnlockedAmounts(l2Reward.todayDay() + extensions[0].durationExtension), amount);

skip(60 days);

uint256[] memory lockIDs = new uint256[](1);
lockIDs[0] = extensions[0].lockID;

uint256 expectedRewardAfterExtension = 5 * 10 ** 18;
// staker claims rewards, after expiry date
then_eventRewardsClaimedIsEmitted(lockIDs[0], expectedRewardAfterExtension);
vm.prank(staker);
l2Reward.claimRewards(lockIDs);

// staker unlocks rewards
then_eventRewardsClaimedIsEmitted(lockIDs[0], 0);
vm.prank(staker);
l2Reward.deletePositions(lockIDs);

assertEq(l2LiskToken.balanceOf(staker), balance + expectedReward + expectedRewardAfterExtension);
}

function test_extendDuration_updatesGlobalsAndClaimRewardsForPausedPositions() public {
Expand Down

0 comments on commit 93ea20e

Please sign in to comment.