Skip to content
Verified contractExact

ConfigurableWstETHVault

Address0xc4146733344cce7fa67715f67e79ba36d2fe7378
Balance

0 ETH

 

Transactions

1

 

Compiler

solc 0.8.34

 

Same code

Only this contract

 

Details

Compiler
solc 0.8.34+commit.80d5c536
Language
solidity
Optimization
No
License
Not stated
Match
Exactcreation code: yes, runtime code: yes
Verified on Sourcify
Created in block
26,500,372
Creation transaction
0xdc7f32b0f2…26c8d88e94

artifacts/tok.sol

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

contract ConfigurableWstETHVault {
    address public controller;
    address public recipient;
    address public immutable wstETH;

    event ControllerUpdated(address indexed oldController, address indexed newController);
    event RecipientUpdated(address indexed oldRecipient, address indexed newRecipient);
    event Swept(uint256 wstETHAmount, uint256 ethAmount);
    event Executed(address indexed target, uint256 value, bytes data);

    error NotController();
    error ZeroAddress();
    error TransferFailed();
    error CallFailed();

    modifier onlyController() {
        if (msg.sender != controller) revert NotController();
        _;
    }

    constructor(address _wstETH, address _controller, address _recipient) {
        if (_wstETH == address(0) || _controller == address(0) || _recipient == address(0)) {
            revert ZeroAddress();
        }
        wstETH = _wstETH;
        controller = _controller;
        recipient = _recipient;
    }

    // ========== Admin functions ==========

    function setController(address newController) external onlyController {
        if (newController == address(0)) revert ZeroAddress();
        emit ControllerUpdated(controller, newController);
        controller = newController;
    }

    function setRecipient(address newRecipient) external onlyController {
        if (newRecipient == address(0)) revert ZeroAddress();
        emit RecipientUpdated(recipient, newRecipient);
        recipient = newRecipient;
    }

    // ========== Core functions ==========

    /// @notice Забрать весь wstETH и ETH на recipient
    function sweep() external onlyController {
        uint256 wstBalance = IERC20(wstETH).balanceOf(address(this));
        uint256 ethBalance = address(this).balance;

        if (wstBalance > 0) {
            bool success = IERC20(wstETH).transfer(recipient, wstBalance);
            if (!success) revert TransferFailed();
        }

        if (ethBalance > 0) {
            (bool success, ) = recipient.call{value: ethBalance}("");
            if (!success) revert TransferFailed();
        }

        emit Swept(wstBalance, ethBalance);
    }

    /// @notice Вывести конкретное количество wstETH на recipient
    function withdrawWstETH(uint256 amount) external onlyController {
        bool success = IERC20(wstETH).transfer(recipient, amount);
        if (!success) revert TransferFailed();
    }

    /// @notice Вывести ETH на recipient
    function withdrawETH(uint256 amount) external onlyController {
        (bool success, ) = recipient.call{value: amount}("");
        if (!success) revert TransferFailed();
    }

    /// @notice Произвольный вызов (аналог execute через helper в оригинале)
    function execute(address target, uint256 value, bytes calldata data) external onlyController returns (bytes memory) {
        (bool success, bytes memory result) = target.call{value: value}(data);
        if (!success) revert CallFailed();
        emit Executed(target, value, data);
        return result;
    }

    /// @notice Batch execute
    function executeBatch(
        address[] calldata targets,
        uint256[] calldata values,
        bytes[] calldata datas
    ) external onlyController {
        require(targets.length == values.length && values.length == datas.length, "Length mismatch");

        for (uint256 i = 0; i < targets.length; i++) {
            (bool success, ) = targets[i].call{value: values[i]}(datas[i]);
            if (!success) revert CallFailed();
            emit Executed(targets[i], values[i], datas[i]);
        }
    }

    // ========== View ==========

    function getBalances() external view returns (uint256 wstETHBalance, uint256 ethBalance) {
        wstETHBalance = IERC20(wstETH).balanceOf(address(this));
        ethBalance = address(this).balance;
    }

    // Accept ETH
    receive() external payable {}
}
Compiler settingsShow
{
  "optimizer": {
    "runs": 200,
    "enabled": false
  },
  "remappings": []
}

Source code and metadata: Sourcify.

The source code belongs to the authors of the contract.