Skip to content
Verified contractPartialMIT

MixedBatchTransfer

Address0x3d0f22bf11636cc9cb129e2b261eed35a487455c
Balance

0 ETH

 

Transactions

442,082

 

Compiler

solc 0.8.20

 

Same code

1 more contract

 

Details

Compiler
solc 0.8.20+commit.a1b79de6
Language
solidity
Optimization
No
EVM version
shanghai
License
MIT
Match
Partialcreation code: yes, runtime code: yes
Verified on Sourcify
Created in block
24,650,590
Creation transaction
0x204bceeb33…12571fb8bb

source.sol

// SPDX-License-Identifier: MIT
pragma solidity 0.8.20;

/*

Recreated from the bytecode by Decurity
https://decurity.io
https://x.com/DecurityHQ

*/

interface IERC20 {
    function transfer(address to, uint256 amount) external returns (bool);
    function balanceOf(address account) external view returns (uint256);
}

contract MixedBatchTransfer {
    address public owner;
    uint256 private _status;

    event Deposit(address indexed sender, uint256 amount);
    event TransferFailed(address indexed recipient, uint256 amount);
    event TokenTransfer(address indexed token, address indexed to, uint256 amount);
    event TokenTransferFailed(address indexed token, address indexed to, uint256 amount);
    event BatchTransfer(uint256 total, uint256 count);
    event Withdrawal(address indexed token, uint256 amount);

    modifier onlyOwner() {
        require(msg.sender == owner, "Not owner");
        _;
    }

    modifier nonReentrant() {
        require(_status != 2, "Reentrant call");
        _status = 2;
        _;
        _status = 1;
    }

    constructor() {
        owner = msg.sender;
        _status = 1;
    }

    receive() external payable {
        emit Deposit(msg.sender, msg.value);
    }

    function getBalance() external view returns (uint256) {
        return address(this).balance;
    }

    function batchTransferMixed(
        address[] calldata recipients,
        uint256[] calldata ethAmounts,
        address[] calldata tokens,
        uint256[] calldata tokenAmounts
    ) external payable onlyOwner {
        require(recipients.length > 0, "Empty");
        require(
            recipients.length == ethAmounts.length &&
                recipients.length == tokens.length &&
                recipients.length == tokenAmounts.length,
            "Length mismatch"
        );

        uint256 successCount = 0;
        for (uint256 i = 0; i < recipients.length; i++) {
            require(recipients[i] != address(0), "Zero address");
            bool sent = false;

            if (ethAmounts[i] > 0) {
                (bool s, ) = recipients[i].call{value: ethAmounts[i]}("");
                if (s) {
                    sent = true;
                } else {
                    emit TransferFailed(recipients[i], ethAmounts[i]);
                }
            }

            if (tokenAmounts[i] > 0 && tokens[i] != address(0)) {
                if (_tokenTransfer(tokens[i], recipients[i], tokenAmounts[i])) {
                    emit TokenTransfer(tokens[i], recipients[i], tokenAmounts[i]);
                    sent = true;
                } else {
                    emit TokenTransferFailed(tokens[i], recipients[i], tokenAmounts[i]);
                }
            }

            if (sent) {
                unchecked {
                    successCount++;
                }
            }
        }

        require(successCount > 0, "All failed");
        emit BatchTransfer(successCount, msg.value);
    }

    function withdraw(uint256 amount) external onlyOwner {
        require(amount > 0 && address(this).balance >= amount, "Invalid");
        (bool s, ) = owner.call{value: amount}("");
        require(s, "Failed");
        emit Withdrawal(address(0), amount);
    }

    function getTokenBalance(address token) external view returns (uint256) {
        (bool success, bytes memory data) = token.staticcall(
            abi.encodeWithSelector(0x70a08231, address(this))
        );
        if (success && data.length >= 32) {
            return abi.decode(data, (uint256));
        }
        return 0;
    }

    function withdrawAll(address[] calldata tokens) external onlyOwner nonReentrant {
        uint256 bal = address(this).balance;
        if (bal > 0) {
            (bool s, ) = owner.call{value: bal}("");
            require(s, "ETH transfer failed");
            emit Withdrawal(address(0), bal);
        }

        for (uint256 i = 0; i < tokens.length; i++) {
            (bool success, bytes memory data) = tokens[i].staticcall(
                abi.encodeWithSelector(0x70a08231, address(this))
            );
            if (success && data.length >= 32) {
                uint256 balance = abi.decode(data, (uint256));
                if (balance > 0) {
                    _tokenTransfer(tokens[i], owner, balance);
                    emit Withdrawal(tokens[i], balance);
                }
            }
        }
    }

    function withdrawToken(address token, uint256 amount) external onlyOwner {
        require(amount > 0, "Zero amount");
        require(_tokenTransfer(token, owner, amount), "Transfer failed");
        emit Withdrawal(token, amount);
    }

    function transfer(address, uint256) external payable onlyOwner returns (bool) {
        (address[] memory recipients, uint256[] memory amounts) = abi.decode(
            msg.data[68:],
            (address[], uint256[])
        );
        require(recipients.length > 0, "Empty");
        require(recipients.length == amounts.length, "Length mismatch");

        uint256 total = 0;
        for (uint256 i = 0; i < recipients.length; i++) {
            require(recipients[i] != address(0), "Zero address");
            require(amounts[i] > 0, "Zero amount");
            total += amounts[i];
        }
        require(address(this).balance >= total, "Insufficient balance");

        uint256 successCount = 0;
        uint256 sentTotal = 0;
        for (uint256 i = 0; i < recipients.length; i++) {
            (bool success, ) = recipients[i].call{value: amounts[i]}("");
            if (success) {
                unchecked {
                    successCount++;
                }
                sentTotal += amounts[i];
            } else {
                emit TransferFailed(recipients[i], amounts[i]);
            }
        }
        require(successCount > 0, "All failed");
        emit BatchTransfer(successCount, sentTotal);
        return true;
    }

    function transferOwnership(address newOwner) external onlyOwner {
        require(newOwner != address(0), "Zero address");
        owner = newOwner;
    }

    function _tokenTransfer(address token, address to, uint256 amount) private returns (bool) {
        (bool success, bytes memory data) = token.call(
            abi.encodeWithSelector(0xa9059cbb, to, amount)
        );
        return success && (data.length == 0 || abi.decode(data, (bool)));
    }
}
Compiler settingsShow
{
  "optimizer": {
    "runs": 200,
    "enabled": false
  },
  "evmVersion": "shanghai"
}

Source code and metadata: Sourcify.

The source code belongs to the authors of the contract.