Skip to content

Commit 0ec8778

Browse files
committed
chore: use an existing function to calculate diff or zero if underflow
1 parent 9ac3b07 commit 0ec8778

File tree

1 file changed

+5
-6
lines changed

1 file changed

+5
-6
lines changed

contracts/rewards/RewardsManager.sol

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ pragma abicoder v2;
66
import "@openzeppelin/contracts/math/SafeMath.sol";
77

88
import "../upgrades/GraphUpgradeable.sol";
9+
import "../staking/libs/MathUtils.sol";
910

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

283284
uint256 accRewardsForSubgraph = getAccRewardsForSubgraph(_subgraphDeploymentID);
284-
uint256 newRewardsForSubgraph;
285-
if (accRewardsForSubgraph > subgraph.accRewardsForSubgraphSnapshot) {
286-
newRewardsForSubgraph = accRewardsForSubgraph.sub(
287-
subgraph.accRewardsForSubgraphSnapshot
288-
);
289-
}
285+
uint256 newRewardsForSubgraph = MathUtils.diffOrZero(
286+
accRewardsForSubgraph,
287+
subgraph.accRewardsForSubgraphSnapshot
288+
);
290289

291290
uint256 subgraphAllocatedTokens = staking().getSubgraphAllocatedTokens(
292291
_subgraphDeploymentID

0 commit comments

Comments
 (0)