Use a staticcall to fetch ERC20.decimals in ERC4626 (#3943)

Co-authored-by: Francisco <frangio.1@gmail.com>
(cherry picked from commit 6b17b33430)
Signed-off-by: Hadrien Croubois <hadrien.croubois@gmail.com>
This commit is contained in:
Hadrien Croubois
2023-01-12 16:33:15 +01:00
parent 873a01b220
commit cd50a86a90
2 changed files with 6 additions and 2 deletions

View File

@ -45,8 +45,8 @@ abstract contract ERC4626 is ERC20, IERC4626 {
/**
* @dev Attempts to fetch the asset decimals. A return value of false indicates that the attempt failed in some way.
*/
function _tryGetAssetDecimals(IERC20 asset_) private returns (bool, uint8) {
(bool success, bytes memory encodedDecimals) = address(asset_).call(
function _tryGetAssetDecimals(IERC20 asset_) private view returns (bool, uint8) {
(bool success, bytes memory encodedDecimals) = address(asset_).staticcall(
abi.encodeWithSelector(IERC20Metadata.decimals.selector)
);
if (success && encodedDecimals.length >= 32) {