Description:
Smart contract deployed on Ethereum with Factory features.
Blockchain: Ethereum
Source Code: View Code On The Blockchain
Solidity Source Code:
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
interface IERC20 {
function transfer(address to, uint256 value) external returns (bool);
function transferFrom(address from, address to, uint256 value) external returns (bool);
}
interface IWETH is IERC20 {
function withdraw(uint256 wad) external;
}
contract UnwrapAndForward {
/// @notice Canonical WETH for this deployment
IWETH public immutable WETH;
/// @notice Owner with admin/rescue privileges
address public owner;
modifier onlyOwner() {
require(msg.sender == owner, "not owner");
_;
}
constructor(address weth, address initialOwner) {
require(weth != address(0), "weth=0");
require(initialOwner != address(0), "owner=0");
WETH = IWETH(weth);
owner = initialOwner;
}
// unwrap WETH then forward ETH to recipient
function unwrapAndSend(uint256 amount, address payable recipient) external {
require(recipient != address(0), "recipient=0");
// pull WETH from caller (caller must approve first)
bool ok = WETH.transferFrom(msg.sender, address(this), amount);
require(ok, "transferFrom failed");
// convert WETH -> ETH (ETH will be in this contract)
WETH.withdraw(amount);
// forward ETH to recipient (use call and check)
(bool sent, ) = recipient.call{value: amount}("");
require(sent, "ETH send failed");
}
// receive ETH from WETH.withdraw
receive() external payable {}
// ============ onlyOwner administrative ============
/// @notice Change contract owner
function transferOwnership(address newOwner) external onlyOwner {
require(newOwner != address(0), "newOwner=0");
owner = newOwner;
}
/// @notice Rescue stuck ETH
function rescueETH(address payable to, uint256 amount) external onlyOwner {
(bool ok, ) = to.call{value: amount}("");
require(ok, "ETH rescue failed");
}
/// @notice Rescue stuck ERC20 tokens (including WETH if ever held)
function rescueERC20(address token, address to, uint256 amount) external onlyOwner {
bool ok = IERC20(token).transfer(to, amount);
require(ok, "ERC20 rescue failed");
}
}
Submitted on: 2025-10-16 15:46:57
Comments
Log in to comment.
No comments yet.