Skip to content

Commit

Permalink
Merge 7514d0e into d21d83f
Browse files Browse the repository at this point in the history
  • Loading branch information
aodhgan committed Dec 2, 2021
2 parents d21d83f + 7514d0e commit c0d98f5
Showing 1 changed file with 7 additions and 12 deletions.
19 changes: 7 additions & 12 deletions contracts/TwabRewards.sol
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,8 @@ contract TwabRewards is ITwabRewards {
) external override returns (uint256) {
uint256 _rewardAmount;

uint256 _userClaimedEpochs = _claimedEpochs[_promotionId][_user];

for (uint256 index = 0; index < _epochIds.length; index++) {
uint256 _epochId = _epochIds[index];

Expand All @@ -210,9 +212,11 @@ contract TwabRewards is ITwabRewards {
);

_rewardAmount += _calculateRewardAmount(_user, _promotionId, _epochId);
_setClaimedEpoch(_claimedEpochs[_promotionId][_user], _epochId, true);
_userClaimedEpochs = _updateClaimedEpoch(_userClaimedEpochs, _epochId);
}

_claimedEpochs[_promotionId][_user] = _userClaimedEpochs;

IERC20 _token = IERC20(_getPromotion(_promotionId).token);
_token.safeTransferFrom(address(this), _user, _rewardAmount);

Expand Down Expand Up @@ -358,19 +362,10 @@ contract TwabRewards is ITwabRewards {
We get: 0110 0111 & 1111 1011 = 0110 0011
@param _epochs Tightly packed epoch ids with their boolean values
@param _epochId Id of the epoch to set the boolean for
@param _value Boolean value to set
@return Tightly packed epoch ids with the newly boolean value set
*/
function _setClaimedEpoch(
uint256 _epochs,
uint256 _epochId,
bool _value
) public pure returns (uint256) {
if (_value) {
return _epochs | (uint256(1) << _epochId);
} else {
return _epochs & ~(uint256(1) << _epochId);
}
function _updateClaimedEpoch(uint256 _epochs, uint256 _epochId) public pure returns (uint256) {
return _epochs | (uint256(1) << _epochId);
}

/**
Expand Down

0 comments on commit c0d98f5

Please sign in to comment.