Skip to content

Commit

Permalink
Merge pull request #20 from Canto-Network/claim-rewards-fix
Browse files Browse the repository at this point in the history
refactor: replace revert with if check
  • Loading branch information
tkkwon1998 authored Oct 16, 2023
2 parents be6ae23 + 670908d commit 0e86bd1
Showing 1 changed file with 10 additions and 12 deletions.
22 changes: 10 additions & 12 deletions contracts/mixins/LiquidityMining.sol
Original file line number Diff line number Diff line change
Expand Up @@ -201,20 +201,18 @@ contract LiquidityMining is PositionRegistrar {
for (uint256 i; i < weeksToClaim.length; ++i) {
uint32 week = weeksToClaim[i];
require(week + WEEK < block.timestamp, "Week not over yet");
require(
!concLiquidityRewardsClaimed_[poolIdx][posKey][week],
"Already claimed"
);
uint256 overallInRangeLiquidity = timeWeightedWeeklyGlobalConcLiquidity_[poolIdx][week];
if (overallInRangeLiquidity > 0) {
uint256 inRangeLiquidityOfPosition;
for (int24 j = lowerTick + 100; j <= upperTick - 100; ++j) {
inRangeLiquidityOfPosition += timeWeightedWeeklyPositionInRangeConcLiquidity_[poolIdx][posKey][week][j];
if (!concLiquidityRewardsClaimed_[poolIdx][posKey][week]) {
uint256 overallInRangeLiquidity = timeWeightedWeeklyGlobalConcLiquidity_[poolIdx][week];
if (overallInRangeLiquidity > 0) {
uint256 inRangeLiquidityOfPosition;
for (int24 j = lowerTick + 100; j <= upperTick - 100; ++j) {
inRangeLiquidityOfPosition += timeWeightedWeeklyPositionInRangeConcLiquidity_[poolIdx][posKey][week][j];
}
// Percentage of this weeks overall in range liquidity that was provided by the user times the overall weekly rewards
rewardsToSend += inRangeLiquidityOfPosition * concRewardPerWeek_[poolIdx][week] / overallInRangeLiquidity;
}
// Percentage of this weeks overall in range liquidity that was provided by the user times the overall weekly rewards
rewardsToSend += inRangeLiquidityOfPosition * concRewardPerWeek_[poolIdx][week] / overallInRangeLiquidity;
concLiquidityRewardsClaimed_[poolIdx][posKey][week] = true;
}
concLiquidityRewardsClaimed_[poolIdx][posKey][week] = true;
}
if (rewardsToSend > 0) {
(bool sent, ) = owner.call{value: rewardsToSend}("");
Expand Down

0 comments on commit 0e86bd1

Please sign in to comment.