Description:
Smart contract deployed on Ethereum with Factory features.
Blockchain: Ethereum
Source Code: View Code On The Blockchain
Solidity Source Code:
{{
"language": "Solidity",
"sources": {
"AutoDistributor_ETH_USDT_v1/AutoDistributor_ETH_USDT_v1/contracts/AutoDistributor_ETH_USDT.sol": {
"content": "// SPDX-License-Identifier: MIT
pragma solidity ^0.8.20;
/// @title AutoDistributor for ETH and USDT (ERC-20)
/// @notice Auto-distributes incoming ETH immediately; holds USDT until distributeUSDT() is called.
/// @dev Percentages use basis points with two decimals (10000 = 100.00%). Example: 0.5% = 50.
interface IERC20 {
function transfer(address recipient, uint256 amount) external returns (bool);
function balanceOf(address account) external view returns (uint256);
}
contract AutoDistributor_ETH_USDT {
// --- Ownership ---
address public owner;
event OwnerTransferred(address indexed previousOwner, address indexed newOwner);
modifier onlyOwner() {
require(msg.sender == owner, "Not authorized");
_;
}
// --- Reentrancy Guard (minimal) ---
uint256 private _guard;
modifier nonReentrant() {
require(_guard == 0, "Reentrancy");
_guard = 1;
_;
_guard = 0;
}
// --- Token ---
IERC20 public usdtToken;
event USDTAddressUpdated(address indexed newUSDT);
struct Receiver {
address wallet;
uint256 bps; // basis points *with two decimals*, 10000 = 100.00%
}
Receiver[] public receivers;
uint256 public constant TOTAL_BPS = 10000; // 100.00%
// --- Events ---
event ETHDistributed(uint256 amount);
event USDTDistributed(uint256 amount);
constructor(address _usdtAddress) {
owner = msg.sender;
emit OwnerTransferred(address(0), owner);
usdtToken = IERC20(_usdtAddress);
emit USDTAddressUpdated(_usdtAddress);
// Initialize receivers (sum = 10000 bps = 100%)
receivers.push(Receiver(0x23CEC6907b83Ce0893538229A279548cc6C2068C, 500)); // 5%
receivers.push(Receiver(0xa0ceFa3E958101C43f8de6f4562AC61D82305aA5, 1500)); // 15%
receivers.push(Receiver(0xEB97020acd5307438CD638892Be1D3516587Bbe3, 1250)); // 12.5%
receivers.push(Receiver(0x867419B9a18de0640e6bb022e03280C3c5f21902, 300)); // 3%
receivers.push(Receiver(0xB161072cd7E0dad66464D23263126F2F2271eb55, 50)); // 0.5%
receivers.push(Receiver(0x59df45c858dC7831B69f90692B950E0dbc092ddd, 50)); // 0.5%
receivers.push(Receiver(0x96e95BA6896E2A50FaF44D3A0a05817e8079318A, 50)); // 0.5%
receivers.push(Receiver(0x9C8fDC36335dcc56BD0e07B3FDD8f9A21Def8087, 300)); // 3%
receivers.push(Receiver(0x4e5787dF300Af3A879c30003fF04345d63f15651, 1000)); // 10%
receivers.push(Receiver(0xCAB5Ea022e285e1d0e839ED02FAcCc6489eE0BB2, 5000)); // 50%
}
// --- Fallback to auto-distribute ETH ---
receive() external payable {
_distributeETH(msg.value);
}
// Allow manual ETH distribution of an arbitrary amount already held by contract
function distributeETHHeld() external nonReentrant {
uint256 amount = address(this).balance;
require(amount > 0, "No ETH");
_distributeETH(amount);
}
// Internal ETH distribution using call, reverting on any failed leg
function _distributeETH(uint256 amount) internal nonReentrant {
require(amount > 0, "Zero");
uint256 sentTotal = 0;
uint256 len = receivers.length;
for (uint256 i = 0; i < len; i++) {
uint256 share = (amount * receivers[i].bps) / TOTAL_BPS;
sentTotal += share;
(bool ok, ) = payable(receivers[i].wallet).call{value: share}("");
require(ok, "ETH transfer failed");
}
// Handle rounding dust (if any) by sending to last receiver
uint256 dust = amount - sentTotal;
if (dust > 0) {
(bool ok2, ) = payable(receivers[len - 1].wallet).call{value: dust}("");
require(ok2, "Dust transfer failed");
}
emit ETHDistributed(amount);
}
// --- USDT distribution (pull-then-push) ---
/// @notice Distributes the contract's USDT balance to receivers by bps.
/// @dev ERC-20 tokens cannot auto-trigger on receipt, so this must be called.
function distributeUSDT() external nonReentrant {
uint256 balance = usdtToken.balanceOf(address(this));
require(balance > 0, "No USDT to distribute");
uint256 sentTotal = 0;
uint256 len = receivers.length;
for (uint256 i = 0; i < len; i++) {
uint256 share = (balance * receivers[i].bps) / TOTAL_BPS;
sentTotal += share;
require(usdtToken.transfer(receivers[i].wallet, share), "USDT transfer failed");
}
// Send any rounding dust to last receiver
uint256 dust = balance - sentTotal;
if (dust > 0) {
require(usdtToken.transfer(receivers[len - 1].wallet, dust), "USDT dust transfer failed");
}
emit USDTDistributed(balance);
}
// --- Admin utilities ---
function updateUSDTAddress(address _newUSDT) external onlyOwner {
usdtToken = IERC20(_newUSDT);
emit USDTAddressUpdated(_newUSDT);
}
function transferOwnership(address newOwner) external onlyOwner {
require(newOwner != address(0), "Zero address");
emit OwnerTransferred(owner, newOwner);
owner = newOwner;
}
// Rescue functions
function withdrawETH() external onlyOwner nonReentrant {
uint256 bal = address(this).balance;
(bool ok, ) = payable(owner).call{value: bal}("");
require(ok, "Withdraw failed");
}
function withdrawUSDT() external onlyOwner nonReentrant {
uint256 bal = usdtToken.balanceOf(address(this));
require(usdtToken.transfer(owner, bal), "Withdraw USDT failed");
}
// View helpers
function receiversCount() external view returns (uint256) {
return receivers.length;
}
}
"
}
},
"settings": {
"optimizer": {
"enabled": true,
"runs": 200
},
"outputSelection": {
"*": {
"*": [
"evm.bytecode",
"evm.deployedBytecode",
"devdoc",
"userdoc",
"metadata",
"abi"
]
}
},
"remappings": []
}
}}
Submitted on: 2025-11-06 21:05:58
Comments
Log in to comment.
No comments yet.