Description:
Smart contract deployed on Ethereum with Factory features.
Blockchain: Ethereum
Source Code: View Code On The Blockchain
Solidity Source Code:
{{
"language": "Solidity",
"sources": {
"WETH_ETH_Briber.sol": {
"content": "// SPDX-License-Identifier: MIT\r
pragma solidity ^0.8.19;\r
\r
interface IWETH {\r
function deposit() external payable;\r
function withdraw(uint256 wad) external;\r
function transfer(address to, uint256 value) external returns (bool);\r
function balanceOf(address who) external view returns (uint256);\r
}\r
\r
interface IERC20 {\r
function transfer(address to, uint256 amount) external returns (bool);\r
function balanceOf(address who) external view returns (uint256);\r
}\r
\r
contract WETH_ETH_Briber {\r
// immutable owner, set once at deploy\r
address public immutable OWNER;\r
IWETH public immutable WETH;\r
\r
// simple reentrancy guard\r
bool private _locked;\r
modifier nonReentrant() {\r
require(!_locked, "REENTRANCY");\r
_locked = true;\r
_;\r
_locked = false;\r
}\r
\r
modifier onlyOwner() {\r
require(msg.sender == OWNER, "NOT_OWNER");\r
_;\r
}\r
\r
event WETHUnwrapped(uint256 wethAmount);\r
event BribePaid(uint256 ethAmount);\r
event ETHWithdrawn(address to, uint256 amount);\r
event ERC20Withdrawn(address token, address to, uint256 amount);\r
event ReceivedETH(address from, uint256 amount);\r
\r
constructor(address wethAddress, address owner_) {\r
require(wethAddress != address(0), "ZERO_WETH");\r
require(owner_ != address(0), "ZERO_OWNER");\r
WETH = IWETH(wethAddress);\r
OWNER = owner_;\r
}\r
\r
// ========== Deposits ==========\r
// contract can receive native ETH\r
receive() external payable {\r
emit ReceivedETH(msg.sender, msg.value);\r
}\r
\r
fallback() external payable {\r
if (msg.value > 0) emit ReceivedETH(msg.sender, msg.value);\r
}\r
\r
// EOAs can also deposit WETH by calling WETH.transfer(contract, amount) externally.\r
\r
// ========== Bribe functions ==========\r
/**\r
* @notice Unwrap WETH -> ETH and pay block proposer (validator).\r
* @param wethAmount amount of WETH to withdraw (in wei)\r
* @param bribeAmount amount of ETH to send to block.coinbase (<= wethAmount)\r
*\r
* Flow:\r
* - require contract has >= wethAmount WETH\r
* - call WETH.withdraw(wethAmount) -> contract receives wethAmount ETH\r
* - send bribeAmount ETH to block.coinbase\r
* - leftover ETH (if any) remains on contract (owner can withdraw later)\r
*/\r
function unwrapAndBribe(uint256 wethAmount, uint256 bribeAmount)\r
external\r
onlyOwner\r
nonReentrant\r
{\r
require(wethAmount >= bribeAmount, "weth < bribe");\r
\r
uint256 wbal = WETH.balanceOf(address(this));\r
require(wbal >= wethAmount, "INSUFFICIENT_WETH");\r
\r
// unwrap\r
WETH.withdraw(wethAmount);\r
emit WETHUnwrapped(wethAmount);\r
\r
// pay bribe\r
require(address(this).balance >= bribeAmount, "INSUFFICIENT_ETH_AFTER_UNWRAP");\r
(bool ok, ) = payable(block.coinbase).call{value: bribeAmount}("");\r
require(ok, "BRIBE_FAILED");\r
emit BribePaid(bribeAmount);\r
}\r
\r
/**\r
* @notice Pay bribe from already-present ETH on contract (no unwrap).\r
* @param bribeAmount amount of ETH to send to block.coinbase\r
*/\r
function payBribeFromETH(uint256 bribeAmount) external onlyOwner nonReentrant {\r
require(address(this).balance >= bribeAmount, "INSUFFICIENT_ETH");\r
(bool ok, ) = payable(block.coinbase).call{value: bribeAmount}("");\r
require(ok, "BRIBE_FAILED");\r
emit BribePaid(bribeAmount);\r
}\r
\r
// ========== Withdrawals (owner only) ==========\r
// withdraw native ETH to owner or any address\r
function withdrawETH(address payable to, uint256 amount) external onlyOwner nonReentrant {\r
require(to != address(0), "ZERO_TO");\r
require(address(this).balance >= amount, "INSUFFICIENT_ETH");\r
(bool ok, ) = to.call{value: amount}("");\r
require(ok, "WITHDRAW_FAILED");\r
emit ETHWithdrawn(to, amount);\r
}\r
\r
// withdraw any ERC20 (WETH included) to owner\r
function withdrawERC20(address token, address to, uint256 amount) external onlyOwner nonReentrant {\r
require(to != address(0), "ZERO_TO");\r
require(IERC20(token).transfer(to, amount), "ERC20_TRANSFER_FAILED");\r
emit ERC20Withdrawn(token, to, amount);\r
}\r
\r
// view helpers (optional)\r
function wethBalance() external view returns (uint256) {\r
return WETH.balanceOf(address(this));\r
}\r
\r
function ethBalance() external view returns (uint256) {\r
return address(this).balance;\r
}\r
}\r
"
}
},
"settings": {
"optimizer": {
"enabled": true,
"runs": 200
},
"outputSelection": {
"*": {
"*": [
"evm.bytecode",
"evm.deployedBytecode",
"devdoc",
"userdoc",
"metadata",
"abi"
]
}
},
"remappings": []
}
}}
Submitted on: 2025-10-28 18:34:42
Comments
Log in to comment.
No comments yet.