Omniscia Moby Audit
RewardRouterV2 Code Style Findings
RewardRouterV2 Code Style Findings
RRV-01C: Redundant Code Repetitions
Type | Severity | Location |
---|---|---|
Gas Optimization | RewardRouterV2.sol:L64-L73, L85-L92, L97-L103, L112-L116 |
Description:
The referenced code blocks will be repeated across RewardRouterV2::mintAndStakeOlp
& RewardRouterV2::mintAndStakeOlpETH
as well as RewardRouterV2::unstakeAndRedeemOlp
& RewardRouterV2::unstakeAndRedeemOlpETH
respectively.
Example:
contracts/staking/RewardRouterV2.sol
60// when buying olp with token other than ETH61function mintAndStakeOlp(address _token, uint256 _amount, uint256 _minUsdg, uint256 _minOlp) external nonReentrant returns (uint256) {62 require(_amount > 0, "RewardRouter: invalid _amount");63
64 // send token to Olp Manager and olp to account65 address account = msg.sender;66 uint256 olpAmount = IOlpManager(olpManager).addLiquidityForAccount(account, account, _token, _amount, _minUsdg, _minOlp);67 68 // stake fOLP and sOLP in order69 IRewardTracker(feeOlpTracker).stakeForAccount(account, account, olp, olpAmount);70
71 emit StakeOlp(account, olpAmount);72
73 return olpAmount;74}75
76// when buying olp with ETH77function mintAndStakeOlpETH(uint256 _minUsdg, uint256 _minOlp) external payable nonReentrant returns (uint256) {78 require(msg.value > 0, "RewardRouter: invalid msg.value");79
80 // convert ETH to WETH81 // get approval from Olp Manager82 IWETH(weth).deposit{value: msg.value}();83 IERC20(weth).approve(olpManager, msg.value);84
85 address account = msg.sender;86 uint256 olpAmount = IOlpManager(olpManager).addLiquidityForAccount(address(this), account, weth, msg.value, _minUsdg, _minOlp);87
88 IRewardTracker(feeOlpTracker).stakeForAccount(account, account, olp, olpAmount);89
90 emit StakeOlp(account, olpAmount);91
92 return olpAmount;93}
Recommendation:
We advise them to be relocated to internal
functions that are underscore-prefixed (_
), greatly optimizing the code's bytecode size as well as legibility.
Alleviation (a8720219a6a97e10b8d9c6a70c6345747f0fdcb3):
The referenced functions have been refactored as advised, greatly easing their maintainability as well as bytecode size.