Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unnecessary return of default value #75

Open
PaulRBerg opened this issue May 24, 2023 · 1 comment
Open

Unnecessary return of default value #75

PaulRBerg opened this issue May 24, 2023 · 1 comment

Comments

@PaulRBerg
Copy link

PaulRBerg commented May 24, 2023

SafeERC20Namer.tokenDecimals returns zero in case the decimals is not implemented by the provided token address:

https://github.com/yieldprotocol/yield-utils-v2/blob/dbeb85ac94befc477bf8cdff9f178fdf331eb83d/src/token/SafeERC20Namer.sol#L99-102

However, this is not necessary, because "0" is the implicit default value for uint8. You might be able to save a little bit of gas if you refactor the code like this:

- function tokenDecimals(address token) public view returns (uint8) {
+ function tokenDecimals(address token) public view returns (uint8 decimals) {
(bool success, bytes memory data) = token.staticcall(abi.encodeWithSelector(IERC20Metadata.decimals.selector));
- return success && data.length == 32 ? abi.decode(data, (uint8)) : 0;
+ if (success && data.length == 32) {
+     decimals = abi.decode(data, (uint8));
+ }
@PaulRBerg
Copy link
Author

Though, on second thoughts, I am not so sure that this would save gas.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant