Skip to content

Commit f2aa2fa

Browse files
committed
fix: gas optimization (OZ N-02)
1 parent 9f9db2e commit f2aa2fa

File tree

1 file changed

+5
-12
lines changed

1 file changed

+5
-12
lines changed

packages/contracts/contracts/rewards/SubgraphAvailabilityManager.sol

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@
22

33
pragma solidity ^0.7.6;
44

5-
import { SafeMathUpgradeable } from "@openzeppelin/contracts-upgradeable/math/SafeMathUpgradeable.sol";
6-
75
import { Governed } from "../governance/Governed.sol";
86
import { IRewardsManager } from "../rewards/IRewardsManager.sol";
97

@@ -17,8 +15,6 @@ import { IRewardsManager } from "../rewards/IRewardsManager.sol";
1715
* Governor can transfer ownership to a new governor.
1816
*/
1917
contract SubgraphAvailabilityManager is Governed {
20-
using SafeMathUpgradeable for uint256;
21-
2218
// -- Immutable --
2319

2420
/// @notice Number of oracles
@@ -106,14 +102,11 @@ contract SubgraphAvailabilityManager is Governed {
106102
) {
107103
require(_governor != address(0), "SAM: governor must be set");
108104
require(_rewardsManager != address(0), "SAM: rewardsManager must be set");
109-
require(
110-
_executionThreshold >= NUM_ORACLES.div(2).add(1),
111-
"SAM: executionThreshold too low"
112-
);
105+
require(_executionThreshold >= (NUM_ORACLES / 2) + 1, "SAM: executionThreshold too low");
113106
require(_executionThreshold <= NUM_ORACLES, "SAM: executionThreshold too high");
114107

115108
// Oracles should not be address zero
116-
for (uint256 i = 0; i < _oracles.length; i++) {
109+
for (uint256 i; i < _oracles.length; i++) {
117110
address oracle = _oracles[i];
118111
require(oracle != address(0), "SAM: oracle cannot be address zero");
119112
oracles[i] = oracle;
@@ -183,7 +176,7 @@ contract SubgraphAvailabilityManager is Governed {
183176
uint256 _oracleIndex
184177
) external onlyOracle(_oracleIndex) {
185178
require(_subgraphDeploymentID.length == _deny.length, "!length");
186-
for (uint256 i = 0; i < _subgraphDeploymentID.length; i++) {
179+
for (uint256 i; i < _subgraphDeploymentID.length; i++) {
187180
_vote(_subgraphDeploymentID[i], _deny[i], _oracleIndex);
188181
}
189182
}
@@ -226,7 +219,7 @@ contract SubgraphAvailabilityManager is Governed {
226219
* @return True if execution threshold is reached
227220
*/
228221
function checkVotes(bytes32 _subgraphDeploymentID, bool _deny) public view returns (bool) {
229-
uint256 votes = 0;
222+
uint256 votes;
230223

231224
// timeframe for a vote to be valid
232225
uint256 voteTimeValidity = block.timestamp - voteTimeLimit;
@@ -236,7 +229,7 @@ contract SubgraphAvailabilityManager is Governed {
236229
? lastDenyVote[currentNonce][_subgraphDeploymentID]
237230
: lastAllowVote[currentNonce][_subgraphDeploymentID];
238231

239-
for (uint256 i = 0; i < NUM_ORACLES; i++) {
232+
for (uint256 i; i < NUM_ORACLES; i++) {
240233
// check if vote is within the vote time limit
241234
if (lastVoteForSubgraph[i] > voteTimeValidity) {
242235
votes++;

0 commit comments

Comments
 (0)