IT COSTS MORE GAS TO INITIALIZE VARIABLES WITH THEIR DEFAULT VALUE THAN LETTING THE DEFAULT VALUE BE APPLIED
Example: for (uint256 i = 0; i < numIterations; ++i) { should be replaced with for (uint256 i; i < numIterations; ++i) {
i++ costs more gas than ++i
Example: for (uint256 i; i < numIterations; i++) { should be replaced with for (uint256 i; i < numIterations; ++i) {
AN ARRAY’S LENGTH SHOULD BE CACHED TO SAVE GAS IN FOR-LOOPS
Example: for (uint256 i; i < iterations.length; ++i) { should be replaced with for (uint256 i; i < numIterations; ++i) {
INCREMENTS CAN BE UNCHECKED
Example: for (uint256 i; i < iterations.length; ++i) { should be replaced with for (uint256 i; i < numIterations) {
unchecked {++i; }
nalus
low
Some Gas and QA improvement proposals
QA:
Line too long https://github.com/Merit-Circle/merit-liquidity-mining/blob/ce5feaae19126079d309ac8dd9a81372648437f1/contracts/base/BasePool.sol#L34
Would be informative to have a condition for rewardToken not to be 0. https://github.com/Merit-Circle/merit-liquidity-mining/blob/ce5feaae19126079d309ac8dd9a81372648437f1/contracts/base/BasePool.sol#L110
Remove "hardhat/console.sol" as its only ment for testing
Gas
Use calldata instead of memory in function parameters to reduce gas costs. https://github.com/Merit-Circle/merit-liquidity-mining/blob/ce5feaae19126079d309ac8dd9a81372648437f1/contracts/base/BasePool.sol#L49-L50
Use immutable instead of constants since its more gas efficient. https://github.com/Merit-Circle/merit-liquidity-mining/blob/ce5feaae19126079d309ac8dd9a81372648437f1/contracts/TimeLockPool.sol#L22
Storing private variables is creaper than public ones, so use private wherever possible. https://github.com/Merit-Circle/merit-liquidity-mining/blob/ce5feaae19126079d309ac8dd9a81372648437f1/contracts/base/BasePool.sol#L26-L30
IT COSTS MORE GAS TO INITIALIZE VARIABLES WITH THEIR DEFAULT VALUE THAN LETTING THE DEFAULT VALUE BE APPLIED Example: for (uint256 i = 0; i < numIterations; ++i) { should be replaced with for (uint256 i; i < numIterations; ++i) {
i++ costs more gas than ++i Example: for (uint256 i; i < numIterations; i++) { should be replaced with for (uint256 i; i < numIterations; ++i) {
AN ARRAY’S LENGTH SHOULD BE CACHED TO SAVE GAS IN FOR-LOOPS Example: for (uint256 i; i < iterations.length; ++i) { should be replaced with for (uint256 i; i < numIterations; ++i) {
INCREMENTS CAN BE UNCHECKED Example: for (uint256 i; i < iterations.length; ++i) { should be replaced with for (uint256 i; i < numIterations) { unchecked {++i; }
Deposit is already defined in TimeLockPool, which is imported. https://github.com/Merit-Circle/merit-liquidity-mining/blob/ce5feaae19126079d309ac8dd9a81372648437f1/contracts/View.sol#L10