Skip to content

Commit 3adc6d1

Browse files
committed
test: update based on 4x change for calculator
1 parent 116fe5d commit 3adc6d1

File tree

2 files changed

+11
-5
lines changed

2 files changed

+11
-5
lines changed

evm/test/integration/concrete/staking-rewards-calculator/inject-rewards-for-week/injectRewardsForWeek.sol

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@ contract InjectRewardsForWeek_StakingRewardsCalculator_Integration_Test is
99
StakingRewardsCalculator_Integration_Shared_Test
1010
{
1111
uint256 constant STAKE_AMOUNT = 5_000_000 ether;
12-
uint256 constant REWARDS_AMOUNT = 10_000 ether;
13-
uint256 constant EXPECTED_WEEKLY_REWARD = 2816.059 ether;
12+
uint256 constant REWARDS_AMOUNT = 50_000 ether;
13+
uint256 constant EXPECTED_WEEKLY_REWARD = 11_264.236 ether;
1414

1515
uint256 defaultTimestamp;
1616

@@ -210,7 +210,7 @@ contract InjectRewardsForWeek_StakingRewardsCalculator_Integration_Test is
210210
uint256 rewards = _calculateAndInjectRewards(address(walletConnectConfig), timestamp, false, bytes(""));
211211

212212
// Then: Rewards should be around double (more flexibility for the test)
213-
assertApproxEqAbs(rewards, EXPECTED_WEEKLY_REWARD * 2, 1e20, "Rewards should be double for two equal stakers");
213+
assertApproxEqAbs(rewards, EXPECTED_WEEKLY_REWARD * 2, 3e20, "Rewards should be double for two equal stakers");
214214

215215
// And: Should transfer tokens from caller to distributor
216216
assertEq(l2wct.balanceOf(address(stakingRewardDistributor)), rewards, "Distributor should have rewards");

evm/test/invariant/StakingRewardsCalculator.t.sol

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -92,11 +92,15 @@ contract StakingRewardsCalculator_Invariant_Test is Invariant_Test {
9292
}
9393

9494
function invariant_WeeklyRewards_Bounds() public view {
95-
// Weekly rewards should never exceed annual rewards divided by WEEKS_IN_YEAR
95+
// Weekly rewards should never exceed annual rewards
96+
// The calculateWeeklyRewards function uses the formula:
97+
// weeklyRewards = (stakeWeight * 4 * apy) / (PRECISION * 100 * WEEKS_IN_YEAR)
9698
uint256 maxStakeWeight = store.maxRecordedStakeWeight();
9799
if (maxStakeWeight > 0) {
98100
uint256 maxWeeklyRewards = calculator.calculateWeeklyRewards(maxStakeWeight, INTERCEPT);
99-
uint256 maxAnnualRewards = (maxStakeWeight * uint256(INTERCEPT)) / (PRECISION * 100);
101+
102+
// Calculate the annual rewards using the same formula but without dividing by WEEKS_IN_YEAR
103+
uint256 maxAnnualRewards = (maxStakeWeight * 4 * uint256(INTERCEPT)) / (PRECISION * 100);
100104

101105
assertLe(
102106
maxWeeklyRewards * WEEKS_IN_YEAR,
@@ -144,6 +148,8 @@ contract StakingRewardsCalculator_Invariant_Test is Invariant_Test {
144148
uint256 largerRewards = calculator.calculateWeeklyRewards(largerStake, largerApy);
145149

146150
// Calculate the ratio of stakes and APYs
151+
// Note: The multiplication by 4 in calculateWeeklyRewards applies equally to both rewards,
152+
// so it doesn't affect the ratio calculation
147153
uint256 stakeRatio = (largerStake * PRECISION) / smallerStake;
148154
uint256 apyRatio = (uint256(largerApy) * PRECISION) / uint256(smallerApy);
149155

0 commit comments

Comments
 (0)