Skip to content

Commit

Permalink
chore: use an existing function to calculate diff or zero if underflow
Browse files Browse the repository at this point in the history
  • Loading branch information
abarmat committed Aug 2, 2022
1 parent 9ac3b07 commit 0ec8778
Showing 1 changed file with 5 additions and 6 deletions.
11 changes: 5 additions & 6 deletions contracts/rewards/RewardsManager.sol
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ pragma abicoder v2;
import "@openzeppelin/contracts/math/SafeMath.sol";

import "../upgrades/GraphUpgradeable.sol";
import "../staking/libs/MathUtils.sol";

import "./RewardsManagerStorage.sol";
import "./IRewardsManager.sol";
Expand Down Expand Up @@ -281,12 +282,10 @@ contract RewardsManager is RewardsManagerV3Storage, GraphUpgradeable, IRewardsMa
Subgraph storage subgraph = subgraphs[_subgraphDeploymentID];

uint256 accRewardsForSubgraph = getAccRewardsForSubgraph(_subgraphDeploymentID);
uint256 newRewardsForSubgraph;
if (accRewardsForSubgraph > subgraph.accRewardsForSubgraphSnapshot) {
newRewardsForSubgraph = accRewardsForSubgraph.sub(
subgraph.accRewardsForSubgraphSnapshot
);
}
uint256 newRewardsForSubgraph = MathUtils.diffOrZero(
accRewardsForSubgraph,
subgraph.accRewardsForSubgraphSnapshot
);

uint256 subgraphAllocatedTokens = staking().getSubgraphAllocatedTokens(
_subgraphDeploymentID
Expand Down

0 comments on commit 0ec8778

Please sign in to comment.