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

Check if erc20 and zrc20 are token contracts in v2 contracts #239

Open
skosito opened this issue Jul 18, 2024 · 0 comments
Open

Check if erc20 and zrc20 are token contracts in v2 contracts #239

skosito opened this issue Jul 18, 2024 · 0 comments

Comments

@skosito
Copy link
Contributor

skosito commented Jul 18, 2024

          Here we're assuming token is an ERC20 compliant address always. To code this defensively we'd check always if it's a token contract.

Also we need to check if to != address(0).

    function isERC20(address token) internal view returns (bool) {
        return token.code.length > 0 && IERC20(token).totalSupply() > 0;
    }

    function withdrawAndRevert(address token, address to, uint256 amount, bytes calldata data) public nonReentrant {
        require(isERC20(token), "Provided address is not an ERC20 token");
        require(token != address(0), "Provided address is invalid");
        IERC20(token).safeTransfer(address(gateway), amount);

Originally posted by @fbac in #217 (comment)

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