pragma solidity ^0.8.0;

interface IERC20 {
    function transfer(address recipient, uint256 amount) external returns (bool);
    function transferFrom(address sender, address recipient, uint256 amount) external returns (bool);
}

contract ERC20MultiSender {
    event Multisend(uint256 total, address tokenAddress);

    function multisend(address _tokenAddress, address[] calldata _recipients, uint256[] calldata _amounts) external {
        require(_recipients.length == _amounts.length, "ERC20MultiSender: Recipients and amounts array lengths must be equal.");

        uint256 total = 0;
        for (uint256 i = 0; i < _recipients.length; i++) {
            total += _amounts[i];
        }

        IERC20 token = IERC20(_tokenAddress);
        require(token.transferFrom(msg.sender, address(this), total), "ERC20MultiSender: Failed to transfer tokens to the contract.");

        for (uint256 i = 0; i < _recipients.length; i++) {
            require(token.transfer(_recipients[i], _amounts[i]), "ERC20MultiSender: Failed to transfer tokens to recipient.");
        }

        emit Multisend(total, _tokenAddress);
    }
}