Skip to content
Verified contractExactMIT

BatchUSDCDistributor

Address0x644445bccd7bd38717f2bfd1fd343c63d473300f
Balance

0 ETH

 

Transactions

372

 

Compiler

solc 0.8.30

 

Same code

Only this contract

 

Details

Compiler
solc 0.8.30+commit.73712a01
Language
solidity
Optimization
No
EVM version
prague
License
MIT
Match
Exactcreation code: yes, runtime code: yes
Verified on Sourcify
Created in block
23,660,826
Creation transaction
0xed416c619d…0afd92ac8a

src/BatchUSDCDistributor.sol

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

interface IERC20 {
    function transferFrom(address sender, address recipient, uint256 amount) external returns (bool);
    function allowance(address owner, address spender) external view returns (uint256);
}

contract BatchUSDCDistributor {
    address public owner;
    IERC20 public immutable usdcToken;

    event BatchTransferComplete(uint256 totalRecipients, uint256 successCount, uint256 failureCount);
    event TransferSuccess(address indexed recipient, uint256 amount, uint256 index);
    event TransferFailure(address indexed recipient, uint256 amount, uint256 index, string reason);

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

    constructor(address _usdcToken) {
        owner = msg.sender;
        usdcToken = IERC20(_usdcToken);
    }

    /**
     * @notice Batch transfer USDC to multiple recipients
     * @param recipients Array of recipient addresses
     * @param amounts Array of amounts (in USDC base units - 6 decimals)
     * @return results Boolean array indicating success/failure for each transfer
     */
    function batchTransfer(
        address[] calldata recipients,
        uint256[] calldata amounts
    ) external returns (bool[] memory results) {
        require(recipients.length == amounts.length, "Array length mismatch");
        require(recipients.length > 0, "Empty arrays");
        require(recipients.length <= 500, "Batch too large"); // Gas limit protection

        results = new bool[](recipients.length);
        uint256 successCount = 0;
        uint256 failureCount = 0;

        for (uint256 i = 0; i < recipients.length; i++) {
            require(recipients[i] != address(0), "Invalid recipient address");
            require(amounts[i] > 0, "Amount must be greater than 0");

            try usdcToken.transferFrom(msg.sender, recipients[i], amounts[i]) returns (bool success) {
                if (success) {
                    results[i] = true;
                    successCount++;
                    emit TransferSuccess(recipients[i], amounts[i], i);
                } else {
                    results[i] = false;
                    failureCount++;
                    emit TransferFailure(recipients[i], amounts[i], i, "Transfer returned false");
                }
            } catch Error(string memory reason) {
                results[i] = false;
                failureCount++;
                emit TransferFailure(recipients[i], amounts[i], i, reason);
            } catch (bytes memory) {
                results[i] = false;
                failureCount++;
                emit TransferFailure(recipients[i], amounts[i], i, "Unknown error");
            }
        }

        emit BatchTransferComplete(recipients.length, successCount, failureCount);

        return results;
    }

    /**
     * @notice Check if sender has sufficient USDC balance and allowance
     * @param sender The address that will send USDC
     * @param totalAmount Total USDC needed for the batch
     */
    function checkSufficientAllowance(address sender, uint256 totalAmount) external view returns (bool) {
        return usdcToken.allowance(sender, address(this)) >= totalAmount;
    }

    /**
     * @notice Calculate total amount needed for a batch
     * @param amounts Array of amounts
     */
    function calculateTotal(uint256[] calldata amounts) external pure returns (uint256) {
        uint256 total = 0;
        for (uint256 i = 0; i < amounts.length; i++) {
            total += amounts[i];
        }
        return total;
    }

    /**
     * @notice Transfer ownership
     */
    function transferOwnership(address newOwner) external onlyOwner {
        require(newOwner != address(0), "Invalid new owner");
        owner = newOwner;
    }
}
Compiler settingsShow
{
  "viaIR": false,
  "metadata": {
    "appendCBOR": true,
    "bytecodeHash": "ipfs",
    "useLiteralContent": false
  },
  "optimizer": {
    "runs": 200,
    "enabled": false
  },
  "evmVersion": "prague",
  "remappings": [
    "forge-std/=lib/forge-std/src/"
  ]
}

Source code and metadata: Sourcify.

The source code belongs to the authors of the contract.