@@ -162,7 +162,7 @@ contract Hyperstaker is AccessControlUpgradeable, PausableUpgradeable, UUPSUpgra
162162 address staker = stakes[_hypercertId].staker;
163163 require (staker == msg .sender , NotStakerOfHypercert (staker));
164164 require (! isRoundClaimed (_hypercertId, _roundId), AlreadyClaimed ());
165- uint256 reward = calculateReward (_hypercertId, _roundId);
165+ uint256 reward = _calculateReward (_hypercertId, _roundId);
166166 require (reward != 0 , NoRewardAvailable ());
167167
168168 _setRoundClaimed (_hypercertId, _roundId);
@@ -184,14 +184,10 @@ contract Hyperstaker is AccessControlUpgradeable, PausableUpgradeable, UUPSUpgra
184184 /// @param _roundId id of the round to calculate the reward for
185185 /// @return amount of the reward eligable for the staked Hypercert for the given round
186186 function calculateReward (uint256 _hypercertId , uint256 _roundId ) public view returns (uint256 ) {
187- Round memory round = rounds[_roundId];
188- require (round.endTime != 0 , RoundNotSet ());
189- uint256 stakeStartTime = stakes[_hypercertId].stakingStartTime;
190- require (stakeStartTime != 0 , NotStaked ());
191- stakeStartTime = stakeStartTime < round.startTime ? round.startTime : stakeStartTime;
192- uint256 stakeDuration = stakeStartTime > round.endTime ? 0 : round.endTime - stakeStartTime;
193- return
194- round.totalRewards * hypercertMinter.unitsOf (_hypercertId) * stakeDuration / (totalUnits * round.duration);
187+ if (isRoundClaimed (_hypercertId, _roundId)) {
188+ return 0 ;
189+ }
190+ return _calculateReward (_hypercertId, _roundId);
195191 }
196192
197193 /// @notice Check if a staked Hypercert had already claimed a reward for a given round
@@ -218,6 +214,21 @@ contract Hyperstaker is AccessControlUpgradeable, PausableUpgradeable, UUPSUpgra
218214
219215 // INTERNAL FUNCTIONS
220216
217+ /// @notice Calculate the reward for a staked Hypercert for a given round
218+ /// @param _hypercertId id of the Hypercert to calculate the reward for
219+ /// @param _roundId id of the round to calculate the reward for
220+ /// @return amount of the reward eligable for the staked Hypercert for the given round
221+ function _calculateReward (uint256 _hypercertId , uint256 _roundId ) internal view returns (uint256 ) {
222+ Round memory round = rounds[_roundId];
223+ require (round.endTime != 0 , RoundNotSet ());
224+ uint256 stakeStartTime = stakes[_hypercertId].stakingStartTime;
225+ require (stakeStartTime != 0 , NotStaked ());
226+ stakeStartTime = stakeStartTime < round.startTime ? round.startTime : stakeStartTime;
227+ uint256 stakeDuration = stakeStartTime > round.endTime ? 0 : round.endTime - stakeStartTime;
228+ return
229+ round.totalRewards * hypercertMinter.unitsOf (_hypercertId) * stakeDuration / (totalUnits * round.duration);
230+ }
231+
221232 /// @notice Get the hypercert type id for a given hypercert id
222233 /// @param _hypercertId id of the Hypercert to get the type id for
223234 /// @return hypercert type id for the given hypercert id
0 commit comments