Assessment reports>DfynRFQ>Discussion>Gas optimization

Gas optimization in reused operation

In swapTokenToNative() the amounts[1].sub(feeAmount) call is used three times, performing unnecessary function calls and subsequent operations. In such cases, we recommend caching the operation that is to be reused and using the cached value instead.

//...
uint256 amount_after_fee = amounts[1].sub(feeAmount);
IERC20(tokens[1]).safeTransferFrom(custodian, address(this), amount_after_fee);
IWETH(WETH).withdraw(amount_after_fee);
payable(msg.sender).transfer(amount_after_fee);
//...

This issue has been addressed in commit 3be1183.

Zellic © 2024Back to top ↑