Omniscia Mean Finance Audit

SwapAdapter Code Style Findings

SwapAdapter Code Style Findings

SAR-01C: Loop Iterator Optimizations

Description:

The linked for loops increment / decrement their iterator "safely" due to Solidity's built - in safe arithmetics(post - 0.8.X).

Example:

solidity/contracts/SwapAdapter.sol
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

Description:

The _sendToRecipient function's statements are performed by the _sendBalanceOnContractToRecipient function redundantly.

Example:

solidity/contracts/SwapAdapter.sol
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 recipient
77 * @param _token The token to check
78 * @param _recipient The recipient of the token balance
79 */
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 recipient
97 * @param _token The token to check
98 * @param _amount The amount to send
99 * @param _recipient The recipient
100 */
101function _sendToRecipient(
102 address _token,
103 uint256 _amount,
104 address _recipient
105) 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.