Description:
Smart contract deployed on Ethereum with Factory features.
Blockchain: Ethereum
Source Code: View Code On The Blockchain
Solidity Source Code:
{{
"language": "Solidity",
"sources": {
"src/BatchUSDCDistributor.sol": {
"content": "// 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;
}
}
"
}
},
"settings": {
"remappings": [
"forge-std/=lib/forge-std/src/"
],
"optimizer": {
"enabled": false,
"runs": 200
},
"metadata": {
"useLiteralContent": false,
"bytecodeHash": "ipfs",
"appendCBOR": true
},
"outputSelection": {
"*": {
"*": [
"evm.bytecode",
"evm.deployedBytecode",
"devdoc",
"userdoc",
"metadata",
"abi"
]
}
},
"evmVersion": "prague",
"viaIR": false
}
}}
Submitted on: 2025-10-26 12:43:41
Comments
Log in to comment.
No comments yet.