Omniscia Mean Finance Audit
SwapAdapter Code Style Findings
SwapAdapter Code Style Findings
SAR-01C: Loop Iterator Optimizations
Type | Severity | Location |
---|---|---|
Gas Optimization | SwapAdapter.sol:L128, L130 |
Description:
The linked for
loops increment / decrement their iterator "safely" due to Solidity's built - in safe arithmetics(post - 0.8.X
).
Example:
128for (uint256 i; i < _revokeActions.length; i++) {
Recommendation:
We advise the increment / decrement operations to be performed in an unchecked
code block as the last statement within each for
loop to optimize their execution cost.
Alleviation:
All for
loops have been appropriately optimized via the usage of the unchecked
code block for each iterator's increment.
SAR-02C: Potential Function Overlap
Type | Severity | Location |
---|---|---|
Code Style | SwapAdapter.sol:L80-L93, L101-L112 |
Description:
The _sendToRecipient
function's statements are performed by the _sendBalanceOnContractToRecipient
function redundantly.
Example:
74/**75 * @notice Checks if the contract has any balance of the given token, and if it does,76 * it sends it to the given recipient77 * @param _token The token to check78 * @param _recipient The recipient of the token balance79 */80function _sendBalanceOnContractToRecipient(address _token, address _recipient) internal virtual {81 if (_recipient == address(0)) _recipient = msg.sender;82 if (_token == PROTOCOL_TOKEN) {83 uint256 _balance = address(this).balance;84 if (_balance > 0) {85 payable(_recipient).sendValue(_balance);86 }87 } else {88 uint256 _balance = IERC20(_token).balanceOf(address(this));89 if (_balance > 0) {90 IERC20(_token).safeTransfer(_recipient, _balance);91 }92 }93}94
95/**96 * @notice Transfers the given amount of tokens from the contract to the recipient97 * @param _token The token to check98 * @param _amount The amount to send99 * @param _recipient The recipient100 */101function _sendToRecipient(102 address _token,103 uint256 _amount,104 address _recipient105) internal virtual {106 if (_recipient == address(0)) _recipient = msg.sender;107 if (_token == PROTOCOL_TOKEN) {108 payable(_recipient).sendValue(_amount);109 } else {110 IERC20(_token).safeTransfer(_recipient, _amount);111 }112}
Recommendation:
We advise the _sendBalanceOnContractToRecipient
function to in turn invoke the _sendToRecipient
after evaluating the balance that should be transferred and ensuring it is non-zero.
Alleviation:
The _sendToRecipient
function is now invoked in place of the duplicated logic optimizing the codebase's legibility and gas cost.