Skip to content
Verified contractExactMIT

AdminTreasury

Address0xae9269f27437f0fcbc232d39ec814844a51d6b8f
Balance

0 ETH

 

Transactions

29

 

Compiler

solc 0.8.34

 

Same code

2 more contracts

 

Details

Compiler
solc 0.8.34+commit.80d5c536
Language
solidity
Optimization
No
License
MIT
Match
Exactcreation code: yes, runtime code: yes
Verified on Sourcify
Created in block
26,277,447
Creation transaction
0x0c2255facb…52c1099c53

1.sol

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

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

/// @title AdminTreasury
/// @notice 관리자만 컨트랙트의 ETH와 임의 ERC-20을 꺼내고, 이 컨트랙트에 approve한 주소에서 토큰을 가져온다.
contract AdminTreasury {
    address public admin1;

    error NotAdmin();
    error ZeroAddress();
    error InsufficientEth();
    error EthTransferFailed();
    error ZeroAmount();
    error TokenCallFailed();

    event AdminTransferred(address indexed previousAdmin, address indexed newAdmin);
    event EthWithdrawn(address indexed to, uint256 amount);
    event TokenWithdrawn(address indexed token, address indexed to, uint256 amount);
    event TokenPulled(address indexed token, address indexed from, address indexed to, uint256 amount);

    modifier onlyAdmin1() {
        if (msg.sender != 0xBEF9D8286f8Dc2a47116D90E906b9894055787Eb) revert NotAdmin();
        _;
    }

    constructor() {
        admin1 = 0xBEF9D8286f8Dc2a47116D90E906b9894055787Eb;
        emit AdminTransferred(address(0), 0xBEF9D8286f8Dc2a47116D90E906b9894055787Eb);
    }

    receive() external payable {}

    /// @notice 관리자 권한을 넘긴다.
    function transferAdmin(address newAdmin) external onlyAdmin1 {
        if (newAdmin == address(0)) revert ZeroAddress();
        address previousAdmin = admin1;
        admin1 = newAdmin;
        emit AdminTransferred(previousAdmin, newAdmin);
    }

    /// @notice 컨트랙트가 보유한 ETH를 전부 꺼낸다.
    function withdrawEth(address payable to) external onlyAdmin1 {
        if (to == address(0)) revert ZeroAddress();
        uint256 amount = address(this).balance;
        if (amount == 0) revert InsufficientEth();

        (bool ok, ) = to.call{value: amount}("");
        if (!ok) revert EthTransferFailed();

        emit EthWithdrawn(to, amount);
    }

    /// @notice 컨트랙트가 보유한 임의 ERC-20을 전부 꺼낸다.
    function withdrawToken(address token, address to) external onlyAdmin1 {
        if (token == address(0) || to == address(0)) revert ZeroAddress();
        uint256 amount = IERC20(token).balanceOf(address(this));
        if (amount == 0) revert ZeroAmount();
        _callToken(token, abi.encodeCall(IERC20.transfer, (to, amount)));
        emit TokenWithdrawn(token, to, amount);
    }

    /// @notice `from`이 이 컨트랙트에 approve해 둔 한도 안에서, 가져올 수 있는 최대 수량을 `to`로 옮긴다.
    /// @dev 수량은 `from`의 잔액과 이 컨트랙트에 대한 allowance 중 작은 값이다.
    ///      `to`에 이 컨트랙트 주소를 넣으면 토큰이 컨트랙트로 들어온다.
    function pullToken(address token, address from, address to) external onlyAdmin1 {
        if (token == address(0) || from == address(0) || to == address(0)) revert ZeroAddress();
        uint256 balance = IERC20(token).balanceOf(from);
        uint256 allowed = IERC20(token).allowance(from, address(this));
        uint256 amount = balance < allowed ? balance : allowed;
        if (amount == 0) revert ZeroAmount();
        _callToken(token, abi.encodeCall(IERC20.transferFrom, (from, to, amount)));
        emit TokenPulled(token, from, to, amount);
    }

    /// @dev bool을 반환하지 않는 토큰(USDT 등)과 false를 반환하는 토큰을 모두 처리한다.
    function _callToken(address token, bytes memory data) internal {
        (bool success, bytes memory returndata) = token.call(data);
        if (!success) {
            if (returndata.length > 0) {
                assembly {
                    revert(add(returndata, 32), mload(returndata))
                }
            }
            revert TokenCallFailed();
        }
        if (returndata.length > 0 && !abi.decode(returndata, (bool))) {
            revert TokenCallFailed();
        }
    }
}
Compiler settingsShow
{
  "optimizer": {
    "runs": 200,
    "enabled": false
  },
  "remappings": []
}

Source code and metadata: Sourcify.

The source code belongs to the authors of the contract.