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

6 stars 4 forks source link

Gas Optimizations #115

Open code423n4 opened 2 years ago

code423n4 commented 2 years ago

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

Code could be reorganized to reuse the same check and be more readable:

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

Fixed in previous commit.

H3xept commented 2 years ago

Duplicate of #39