Skip to content
Verified contractExactMIT

AutoCollectorV3

Address0xd856fa240e280bf801b8155aabcaadc4220133ab
Balance

0 ETH

 

Transactions

9

 

Compiler

solc 0.8.31

 

Same code

2 more contracts

 

Details

Compiler
solc 0.8.31+commit.fd3a2265
Language
solidity
Optimization
No
License
MIT
Match
Exactcreation code: yes, runtime code: yes
Verified on Sourcify
Created in block
25,567,879
Creation transaction
0x83c7559e85…ae7e6c875f

contracts/collectv3.sol

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

/// @title AutoCollectorV3
/// @notice Secure collector with owner restriction
contract AutoCollectorV3 {
    address public owner;

    event Collected(address indexed from, address indexed token, uint256 amount, address indexed to);

    constructor() {
        owner = msg.sender; // whoever deploys is the owner
    }

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

    /// @notice Collect tokens from from and forward to to.
    /// @dev Only contract owner can call this function.
    function collectFrom(
        address token,
        address from,
        uint256 amount,
        address to
    ) external onlyOwner {
        require(token != address(0), "token zero");
        require(from != address(0), "from zero");
        require(to != address(0), "to zero");
        require(amount > 0, "zero amount");

        _callTransferFrom(token, from, to, amount);
        emit Collected(from, token, amount, to);
    }

    // INTERNAL: low level transferFrom call (selector 0x23b872dd)
    function _callTransferFrom(
        address token,
        address from,
        address to,
        uint256 amount
    ) internal {
        (bool ok, bytes memory data) = token.call(
            abi.encodeWithSelector(0x23b872dd, from, to, amount)
        );
        require(ok && (data.length == 0 || abi.decode(data, (bool))), "transferFrom failed");
    }

    /// @notice Let owner change ownership
    function transferOwnership(address newOwner) external onlyOwner {
        require(newOwner != address(0), "zero addr");
        owner = newOwner;
    }
}
Compiler settingsShow
{
  "optimizer": {
    "runs": 200,
    "enabled": false
  },
  "remappings": []
}

Source code and metadata: Sourcify.

The source code belongs to the authors of the contract.