code-423n4 / 2022-03-lifinance-findings

6 stars 4 forks source link

Gas Optimizations #77

Open code423n4 opened 2 years ago

code423n4 commented 2 years ago

Repeated if conditions

Same conditions repeated in separate ifs, can be reduced to nested ifs, saving a repeated clause.

https://github.com/code-423n4/2022-03-lifinance/blob/699c2305fcfb6fe8862b75b26d1d8a2f46a551e6/src/Libraries/LibSwap.sol#L33-L39

Update code:

if (!LibAsset.isNativeAsset(fromAssetId)) {
    if (LibAsset.getOwnBalance(fromAssetId) < fromAmount) {
        LibAsset.transferFromERC20(fromAssetId, msg.sender, address(this), fromAmount);
    }
    LibAsset.approveERC20(IERC20(fromAssetId), _swapData.approveTo, fromAmount);
}
H3xept commented 2 years ago

Tackled in previous commit.

H3xept commented 2 years ago

Duplicate of #39