Created
March 8, 2022 13:28
-
-
Save cakoyo/724ab9f18e3abb9746e71c117e999494 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
pragma solidity ^0.8.12; | |
interface IERC20 { | |
function balanceOf(address account) external view returns (uint256); | |
function totalSupply() external view returns (uint256); | |
function transferFrom( | |
address from, | |
address to, | |
uint256 amount | |
) external returns (bool); | |
} | |
contract ERC20ConsistentTest { | |
function balanceOf(address erc20, address account) external view returns (bool success, uint256 balance) { | |
if (isContract(erc20)) { | |
success = true; | |
balance = IERC20(erc20).balanceOf(account); | |
} | |
} | |
function balanceOfUnchecked(address erc20, address account) external view returns (uint256) { | |
return IERC20(erc20).balanceOf(account); | |
} | |
function isContract(address erc20) public view returns (bool) { | |
uint256 size; | |
assembly { size := extcodesize(erc20) } | |
return size > 0; | |
} | |
function isContractCode(address erc20) public view returns (bool) { | |
return erc20.code.length > 0; | |
} | |
function totalSupply(address erc20) external view returns (uint256) { | |
return IERC20(erc20).totalSupply(); | |
} | |
function transferFrom(address erc20, address account) external returns (bool success) { | |
require(IERC20(erc20).transferFrom(account, address(this), 1e18), "transferFrom failed"); | |
return true; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment