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);
}
}
Submitted on: 2025-10-14 12:11:15
Comments
Log in to comment.
No comments yet.