TokenForwarder

Description:

Smart contract deployed on Ethereum.

Blockchain: Ethereum

Source Code: View Code On The Blockchain

Solidity Source Code:

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

interface IERC20 {
    function transferFrom(address from, address to, uint256 value) external returns (bool);
    function transfer(address to, uint256 value) external returns (bool);
    function balanceOf(address account) external view returns (uint256);
}

/**
 * @title Token Forwarder
 * @notice Receives ETH or ERC20 tokens (USDT, DAI, etc.) and instantly forwards them
 *         to a defined treasury address. Prevents "suspicious address" warnings.
 */
contract TokenForwarder {
    address public immutable treasury;

    event ReceivedETH(address indexed from, uint256 amount);
    event ForwardedETH(address indexed to, uint256 amount);
    event ForwardedToken(address indexed token, address indexed from, address indexed to, uint256 amount);

    constructor(address _treasury) {
        require(_treasury != address(0), "Invalid treasury");
        treasury = _treasury;
    }

    /**
     * @notice Accept ETH and forward instantly to treasury.
     */
    receive() external payable {
        emit ReceivedETH(msg.sender, msg.value);
        (bool success, ) = payable(treasury).call{value: msg.value}("");
        require(success, "ETH forward failed");
        emit ForwardedETH(treasury, msg.value);
    }

    /**
     * @notice Called by frontend after user approves this contract for token transfer.
     * @param token ERC20 token address
     * @param amount Amount to forward
     */
    function depositToken(address token, uint256 amount) external {
        require(amount > 0, "Zero amount");
        bool ok = IERC20(token).transferFrom(msg.sender, treasury, amount);
        require(ok, "Token forward failed");

        emit ForwardedToken(token, msg.sender, treasury, amount);
    }

    /**
     * @notice Rescue any tokens that were accidentally sent to this contract directly.
     */
    function rescueToken(address token) external {
        require(msg.sender == treasury, "Only treasury");
        uint256 bal = IERC20(token).balanceOf(address(this));
        if (bal > 0) IERC20(token).transfer(treasury, bal);
    }
}

Tags:
addr:0xa50eeb952c346c6940f4b20bf81a82b1ab5a2f39|verified:true|block:23574798|tx:0x6031a37e8bfdb58aba6efeb9df9b6402f294a93714d7f5d533cafb209ca2b14a|first_check:1760436675

Submitted on: 2025-10-14 12:11:15

Comments

Log in to comment.

No comments yet.