From 8fd50af83383727384e25e9f1ab0178b3be29771 Mon Sep 17 00:00:00 2001 From: arcantheon Date: Wed, 19 Jun 2024 19:42:11 +0530 Subject: [PATCH 1/2] perf(Reward rate calculation): Fixed precision loss --- contracts/rewarder/Rewarder.sol | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/contracts/rewarder/Rewarder.sol b/contracts/rewarder/Rewarder.sol index 8aeda817..caef18e6 100644 --- a/contracts/rewarder/Rewarder.sol +++ b/contracts/rewarder/Rewarder.sol @@ -283,9 +283,8 @@ contract Rewarder is Ownable, Initializable, ReentrancyGuard { } // Getting reward token price to calculate rewards emission. priceData = _getPrice(REWARD_TOKEN, oracle); - rewardRate = ( - (((farmRewardConfig.apr * totalValue) / (APR_PRECISION * DENOMINATOR)) / ONE_YEAR) * priceData.precision - ) / priceData.price; + rewardRate = (farmRewardConfig.apr * totalValue * priceData.precision) + / (APR_PRECISION * DENOMINATOR * ONE_YEAR * priceData.price); if (rewardRate > farmRewardConfig.maxRewardRate) { rewardRate = farmRewardConfig.maxRewardRate; } From fa731945c810030284957f8514e249701fa9b69b Mon Sep 17 00:00:00 2001 From: arcantheon Date: Thu, 20 Jun 2024 19:40:03 +0530 Subject: [PATCH 2/2] Added formula in comment for rewardRate calculation --- contracts/rewarder/Rewarder.sol | 2 ++ 1 file changed, 2 insertions(+) diff --git a/contracts/rewarder/Rewarder.sol b/contracts/rewarder/Rewarder.sol index caef18e6..3321053b 100644 --- a/contracts/rewarder/Rewarder.sol +++ b/contracts/rewarder/Rewarder.sol @@ -283,6 +283,8 @@ contract Rewarder is Ownable, Initializable, ReentrancyGuard { } // Getting reward token price to calculate rewards emission. priceData = _getPrice(REWARD_TOKEN, oracle); + // rewardValuePerSecond = (APR * totalValue / 100) / 365 days. + // rewardRate = rewardValuePerSecond * pricePrecision / price. rewardRate = (farmRewardConfig.apr * totalValue * priceData.precision) / (APR_PRECISION * DENOMINATOR * ONE_YEAR * priceData.price); if (rewardRate > farmRewardConfig.maxRewardRate) {