Omniscia Alliance Block Audit

NonCompoundingRewardsPoolFactory Code Style Findings

NonCompoundingRewardsPoolFactory Code Style Findings

NCP-01C: Data Location Optimization

Description:

The deploy function contains two dynamic array arguments that are stored in memory and is declared as external.

Example:

contracts/V2/factories/NonCompoundingRewardsPoolFactory.sol
47function deploy(
48 address _stakingToken,
49 uint256 _startBlock,
50 uint256 _endBlock,
51 address[] memory _rewardsTokens,
52 uint256[] memory _rewardPerBlock,
53 uint256 _stakeLimit,
54 uint256 _throttleRoundBlocks,
55nt256 _throttleRoundCap
56) external onlyOwner {

Recommendation:

We advise that the data location the arrays are stored in is changed to calldata to optimize the gas cost of the code segments.

Alleviation:

The data location specifiers for the array arguments were properly set to calldata optimizing the gas cost of the function.

NCP-02C: Redundant Validation Loop

Description:

Within Solidity gas costs are of great concern and as such code should be developed as optimal as possible. The linked for loop validates the input _rewardsTokens and _rewardPerBlock prior to their utilization in the ensuing for loop of L111-L122 redundantly so.

Example:

contracts/V2/factories/NonCompoundingRewardsPoolFactory.sol
70for (uint256 i = 0; i < _rewardsTokens.length; i++) {
71 require(
72 _rewardsTokens[i] != address(0),
73 "NonCompoundingRewardsPoolFactory::deploy: Reward token address could not be invalid"
74 );
75 require(
76 _rewardPerBlock[i] != 0,
77 "NonCompoundingRewardsPoolFactory::deploy: Reward per block must be greater than zero"
78 );
79}
80 require(
81 _stakeLimit != 0,
82 "NonCompoundingRewardsPoolFactory::deploy: Stake limit must be more than 0"
83);
84
85require(
86ttleRoundBlocks != 0,
87ompoundingRewardsPoolFactory::deploy: Throttle round blocks must be more than 0"
88
89
90e(
91ttleRoundCap != 0,
92ompoundingRewardsPoolFactory::deploy: Throttle round cap must be more than 0"
93
94
95address rewardPool =
96 address(
97 new NonCompoundingRewardsPool(
98 IERC20Detailed(_stakingToken),
99 _startBlock,
100 _endBlock,
101 _rewardsTokens,
102 _rewardPerBlock,
103 _stakeLimit,
104 _throttleRoundBlocks,
105 _throttleRoundCap,
106 treasury,
107 externalRewardToken
108 )
109 );
110
111for (uint256 i = 0; i < _rewardsTokens.length; i++) {
112 uint256 rewardsAmount =
113 calculateRewardsAmount(
114 _startBlock,
115 _endBlock,
116 _rewardPerBlock[i]
117 );
118 IERC20Detailed(_rewardsTokens[i]).safeTransfer(
119 rewardPool,
120 rewardsAmount
121 );
122}

Recommendation:

We advise that the validation is performed directly on the for loop that utilizes the variables so as to reduce the gas cost involved in utilizing the function.

Alleviation:

The statements of the validation loop were properly relocated to the loop they are actually utilized in.

NCP-03C: Variable Mutability Specifiers

Description:

The linked variable declarations are only assigned to once during the constructor of the contract.

Example:

contracts/V2/factories/NonCompoundingRewardsPoolFactory.sol
18constructor(address _treasury, address _externalRewardToken) public {
19 require(
20 _treasury != address(0),
21 "NonCompoundingRewardsPoolFactory:: Treasury address can't be zero address"
22 );
23
24 require(
25 _externalRewardToken != address(0),
26 "NonCompoundingRewardsPoolFactory:: External reward address can't be zero address"
27 );
28 treasury = _treasury;
29 externalRewardToken = _externalRewardToken;
30}

Recommendation:

As such, they can be set as immutable greatly optimizing the gas cost involved in interacting with them.

Alleviation:

The linked variables were set to immutable greatly optimizing the gas cost of the segments they are utilized in.