- Contract name:
- Faucet
- Optimization enabled
- true
- Compiler version
- v0.8.4+commit.c7e474f2
- Optimization runs
- 200
- EVM Version
- default
- Verified at
- 2022-04-22T02:05:44.854695Z
Contract source code
// Sources flattened with hardhat v2.9.3 https://hardhat.org // File @openzeppelin/contracts/utils/Context.sol@v4.5.0 // SPDX-License-Identifier: MIT // OpenZeppelin Contracts v4.4.1 (utils/Context.sol) pragma solidity ^0.8.0; /** * @dev Provides information about the current execution context, including the * sender of the transaction and its data. While these are generally available * via msg.sender and msg.data, they should not be accessed in such a direct * manner, since when dealing with meta-transactions the account sending and * paying for execution may not be the actual sender (as far as an application * is concerned). * * This contract is only required for intermediate, library-like contracts. */ abstract contract Context { function _msgSender() internal view virtual returns (address) { return msg.sender; } function _msgData() internal view virtual returns (bytes calldata) { return msg.data; } } // File @openzeppelin/contracts/access/Ownable.sol@v4.5.0 // OpenZeppelin Contracts v4.4.1 (access/Ownable.sol) pragma solidity ^0.8.0; /** * @dev Contract module which provides a basic access control mechanism, where * there is an account (an owner) that can be granted exclusive access to * specific functions. * * By default, the owner account will be the one that deploys the contract. This * can later be changed with {transferOwnership}. * * This module is used through inheritance. It will make available the modifier * `onlyOwner`, which can be applied to your functions to restrict their use to * the owner. */ abstract contract Ownable is Context { address private _owner; event OwnershipTransferred(address indexed previousOwner, address indexed newOwner); /** * @dev Initializes the contract setting the deployer as the initial owner. */ constructor() { _transferOwnership(_msgSender()); } /** * @dev Returns the address of the current owner. */ function owner() public view virtual returns (address) { return _owner; } /** * @dev Throws if called by any account other than the owner. */ modifier onlyOwner() { require(owner() == _msgSender(), "Ownable: caller is not the owner"); _; } /** * @dev Leaves the contract without owner. It will not be possible to call * `onlyOwner` functions anymore. Can only be called by the current owner. * * NOTE: Renouncing ownership will leave the contract without an owner, * thereby removing any functionality that is only available to the owner. */ function renounceOwnership() public virtual onlyOwner { _transferOwnership(address(0)); } /** * @dev Transfers ownership of the contract to a new account (`newOwner`). * Can only be called by the current owner. */ function transferOwnership(address newOwner) public virtual onlyOwner { require(newOwner != address(0), "Ownable: new owner is the zero address"); _transferOwnership(newOwner); } /** * @dev Transfers ownership of the contract to a new account (`newOwner`). * Internal function without access restriction. */ function _transferOwnership(address newOwner) internal virtual { address oldOwner = _owner; _owner = newOwner; emit OwnershipTransferred(oldOwner, newOwner); } } // File @openzeppelin/contracts/utils/Address.sol@v4.5.0 // OpenZeppelin Contracts (last updated v4.5.0) (utils/Address.sol) pragma solidity ^0.8.1; /** * @dev Collection of functions related to the address type */ library Address { /** * @dev Returns true if `account` is a contract. * * [IMPORTANT] * ==== * It is unsafe to assume that an address for which this function returns * false is an externally-owned account (EOA) and not a contract. * * Among others, `isContract` will return false for the following * types of addresses: * * - an externally-owned account * - a contract in construction * - an address where a contract will be created * - an address where a contract lived, but was destroyed * ==== * * [IMPORTANT] * ==== * You shouldn't rely on `isContract` to protect against flash loan attacks! * * Preventing calls from contracts is highly discouraged. It breaks composability, breaks support for smart wallets * like Gnosis Safe, and does not provide security since it can be circumvented by calling from a contract * constructor. * ==== */ function isContract(address account) internal view returns (bool) { // This method relies on extcodesize/address.code.length, which returns 0 // for contracts in construction, since the code is only stored at the end // of the constructor execution. return account.code.length > 0; } /** * @dev Replacement for Solidity's `transfer`: sends `amount` wei to * `recipient`, forwarding all available gas and reverting on errors. * * https://eips.ethereum.org/EIPS/eip-1884[EIP1884] increases the gas cost * of certain opcodes, possibly making contracts go over the 2300 gas limit * imposed by `transfer`, making them unable to receive funds via * `transfer`. {sendValue} removes this limitation. * * https://diligence.consensys.net/posts/2019/09/stop-using-soliditys-transfer-now/[Learn more]. * * IMPORTANT: because control is transferred to `recipient`, care must be * taken to not create reentrancy vulnerabilities. Consider using * {ReentrancyGuard} or the * https://solidity.readthedocs.io/en/v0.5.11/security-considerations.html#use-the-checks-effects-interactions-pattern[checks-effects-interactions pattern]. */ function sendValue(address payable recipient, uint256 amount) internal { require(address(this).balance >= amount, "Address: insufficient balance"); (bool success, ) = recipient.call{value: amount}(""); require(success, "Address: unable to send value, recipient may have reverted"); } /** * @dev Performs a Solidity function call using a low level `call`. A * plain `call` is an unsafe replacement for a function call: use this * function instead. * * If `target` reverts with a revert reason, it is bubbled up by this * function (like regular Solidity function calls). * * Returns the raw returned data. To convert to the expected return value, * use https://solidity.readthedocs.io/en/latest/units-and-global-variables.html?highlight=abi.decode#abi-encoding-and-decoding-functions[`abi.decode`]. * * Requirements: * * - `target` must be a contract. * - calling `target` with `data` must not revert. * * _Available since v3.1._ */ function functionCall(address target, bytes memory data) internal returns (bytes memory) { return functionCall(target, data, "Address: low-level call failed"); } /** * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], but with * `errorMessage` as a fallback revert reason when `target` reverts. * * _Available since v3.1._ */ function functionCall( address target, bytes memory data, string memory errorMessage ) internal returns (bytes memory) { return functionCallWithValue(target, data, 0, errorMessage); } /** * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], * but also transferring `value` wei to `target`. * * Requirements: * * - the calling contract must have an ETH balance of at least `value`. * - the called Solidity function must be `payable`. * * _Available since v3.1._ */ function functionCallWithValue( address target, bytes memory data, uint256 value ) internal returns (bytes memory) { return functionCallWithValue(target, data, value, "Address: low-level call with value failed"); } /** * @dev Same as {xref-Address-functionCallWithValue-address-bytes-uint256-}[`functionCallWithValue`], but * with `errorMessage` as a fallback revert reason when `target` reverts. * * _Available since v3.1._ */ function functionCallWithValue( address target, bytes memory data, uint256 value, string memory errorMessage ) internal returns (bytes memory) { require(address(this).balance >= value, "Address: insufficient balance for call"); require(isContract(target), "Address: call to non-contract"); (bool success, bytes memory returndata) = target.call{value: value}(data); return verifyCallResult(success, returndata, errorMessage); } /** * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], * but performing a static call. * * _Available since v3.3._ */ function functionStaticCall(address target, bytes memory data) internal view returns (bytes memory) { return functionStaticCall(target, data, "Address: low-level static call failed"); } /** * @dev Same as {xref-Address-functionCall-address-bytes-string-}[`functionCall`], * but performing a static call. * * _Available since v3.3._ */ function functionStaticCall( address target, bytes memory data, string memory errorMessage ) internal view returns (bytes memory) { require(isContract(target), "Address: static call to non-contract"); (bool success, bytes memory returndata) = target.staticcall(data); return verifyCallResult(success, returndata, errorMessage); } /** * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], * but performing a delegate call. * * _Available since v3.4._ */ function functionDelegateCall(address target, bytes memory data) internal returns (bytes memory) { return functionDelegateCall(target, data, "Address: low-level delegate call failed"); } /** * @dev Same as {xref-Address-functionCall-address-bytes-string-}[`functionCall`], * but performing a delegate call. * * _Available since v3.4._ */ function functionDelegateCall( address target, bytes memory data, string memory errorMessage ) internal returns (bytes memory) { require(isContract(target), "Address: delegate call to non-contract"); (bool success, bytes memory returndata) = target.delegatecall(data); return verifyCallResult(success, returndata, errorMessage); } /** * @dev Tool to verifies that a low level call was successful, and revert if it wasn't, either by bubbling the * revert reason using the provided one. * * _Available since v4.3._ */ function verifyCallResult( bool success, bytes memory returndata, string memory errorMessage ) internal pure returns (bytes memory) { if (success) { return returndata; } else { // Look for revert reason and bubble it up if present if (returndata.length > 0) { // The easiest way to bubble the revert reason is using memory via assembly assembly { let returndata_size := mload(returndata) revert(add(32, returndata), returndata_size) } } else { revert(errorMessage); } } } } // File contracts/tools/Faucet.sol pragma solidity 0.8.4; contract Faucet is Ownable { uint256 public constant AIRDROP_AMOUNT = 0.05 ether; uint256 public constant AIRDROP_INTERVAL = 1 days; mapping(address => uint256) public lastClaimed; mapping(address => bool) public executors; // Sends 0.05 ETH to the sender when the faucet has enough funds // Only allows one withdrawal every day function withdraw(address _recipient) external { require(executors[msg.sender], "Only executors"); require( address(this).balance >= AIRDROP_AMOUNT, "This faucet is empty. Please check back later." ); require( lastClaimed[_recipient] <= block.timestamp - AIRDROP_INTERVAL, "You can only withdraw once every day. Please check back later." ); Address.sendValue(payable(_recipient), AIRDROP_AMOUNT); lastClaimed[_recipient] = block.timestamp; emit Withdrawal(_recipient); } // Sending Tokens to this faucet fills it up receive() external payable { emit Deposit(msg.sender, msg.value); } function addExecutor(address _executor) external onlyOwner { executors[_executor] = true; } function removeExecutor(address _executor) external onlyOwner { delete executors[_executor]; } // Destroys this smart contract and sends all remaining funds to the owner function destroy() external onlyOwner { selfdestruct(payable(msg.sender)); } /* ========= EVENTS ========= */ event Withdrawal(address indexed to); event Deposit(address indexed from, uint256 amount); }
Contract ABI
[{"type":"event","name":"Deposit","inputs":[{"type":"address","name":"from","internalType":"address","indexed":true},{"type":"uint256","name":"amount","internalType":"uint256","indexed":false}],"anonymous":false},{"type":"event","name":"OwnershipTransferred","inputs":[{"type":"address","name":"previousOwner","internalType":"address","indexed":true},{"type":"address","name":"newOwner","internalType":"address","indexed":true}],"anonymous":false},{"type":"event","name":"Withdrawal","inputs":[{"type":"address","name":"to","internalType":"address","indexed":true}],"anonymous":false},{"type":"function","stateMutability":"view","outputs":[{"type":"uint256","name":"","internalType":"uint256"}],"name":"AIRDROP_AMOUNT","inputs":[]},{"type":"function","stateMutability":"view","outputs":[{"type":"uint256","name":"","internalType":"uint256"}],"name":"AIRDROP_INTERVAL","inputs":[]},{"type":"function","stateMutability":"nonpayable","outputs":[],"name":"addExecutor","inputs":[{"type":"address","name":"_executor","internalType":"address"}]},{"type":"function","stateMutability":"nonpayable","outputs":[],"name":"destroy","inputs":[]},{"type":"function","stateMutability":"view","outputs":[{"type":"bool","name":"","internalType":"bool"}],"name":"executors","inputs":[{"type":"address","name":"","internalType":"address"}]},{"type":"function","stateMutability":"view","outputs":[{"type":"uint256","name":"","internalType":"uint256"}],"name":"lastClaimed","inputs":[{"type":"address","name":"","internalType":"address"}]},{"type":"function","stateMutability":"view","outputs":[{"type":"address","name":"","internalType":"address"}],"name":"owner","inputs":[]},{"type":"function","stateMutability":"nonpayable","outputs":[],"name":"removeExecutor","inputs":[{"type":"address","name":"_executor","internalType":"address"}]},{"type":"function","stateMutability":"nonpayable","outputs":[],"name":"renounceOwnership","inputs":[]},{"type":"function","stateMutability":"nonpayable","outputs":[],"name":"transferOwnership","inputs":[{"type":"address","name":"newOwner","internalType":"address"}]},{"type":"function","stateMutability":"nonpayable","outputs":[],"name":"withdraw","inputs":[{"type":"address","name":"_recipient","internalType":"address"}]},{"type":"receive","stateMutability":"payable"}]
Deployed ByteCode
0x6080604052600436106100a05760003560e01c8063715018a611610064578063715018a61461019e57806383197ef0146101b35780638da5cb5b146101c85780639ac2a011146101f0578063d29aaa2d14610230578063f2fde38b1461024757600080fd5b8063013eba92146100e15780631f5a0bbe1461012157806324788429146101435780632b5b68721461016357806351cff8d91461017e57600080fd5b366100dc5760405134815233907fe1fffcc4923d04b559f4d29a8bfc6cda04eb5b0d3c460751c2402c5c5cc9109c9060200160405180910390a2005b600080fd5b3480156100ed57600080fd5b5061010e6100fc366004610722565b60016020526000908152604090205481565b6040519081526020015b60405180910390f35b34801561012d57600080fd5b5061014161013c366004610722565b610267565b005b34801561014f57600080fd5b5061014161015e366004610722565b6102be565b34801561016f57600080fd5b5061010e66b1a2bc2ec5000081565b34801561018a57600080fd5b50610141610199366004610722565b610309565b3480156101aa57600080fd5b506101416104b6565b3480156101bf57600080fd5b506101416104ec565b3480156101d457600080fd5b506000546040516001600160a01b039091168152602001610118565b3480156101fc57600080fd5b5061022061020b366004610722565b60026020526000908152604090205460ff1681565b6040519015158152602001610118565b34801561023c57600080fd5b5061010e6201518081565b34801561025357600080fd5b50610141610262366004610722565b610519565b6000546001600160a01b0316331461029a5760405162461bcd60e51b815260040161029190610750565b60405180910390fd5b6001600160a01b03166000908152600260205260409020805460ff19166001179055565b6000546001600160a01b031633146102e85760405162461bcd60e51b815260040161029190610750565b6001600160a01b03166000908152600260205260409020805460ff19169055565b3360009081526002602052604090205460ff166103595760405162461bcd60e51b815260206004820152600e60248201526d4f6e6c79206578656375746f727360901b6044820152606401610291565b66b1a2bc2ec500004710156103c75760405162461bcd60e51b815260206004820152602e60248201527f546869732066617563657420697320656d7074792e20506c656173652063686560448201526d31b5903130b1b5903630ba32b91760911b6064820152608401610291565b6103d46201518042610785565b6001600160a01b03821660009081526001602052604090205411156104615760405162461bcd60e51b815260206004820152603e60248201527f596f752063616e206f6e6c79207769746864726177206f6e636520657665727960448201527f206461792e20506c6561736520636865636b206261636b206c617465722e00006064820152608401610291565b6104728166b1a2bc2ec500006105b4565b6001600160a01b038116600081815260016020526040808220429055517fe19ed71156e31b3c9e18ac7ad8d1b79f0a0feb3be18d23dae612e52040aada4b9190a250565b6000546001600160a01b031633146104e05760405162461bcd60e51b815260040161029190610750565b6104ea60006106d2565b565b6000546001600160a01b031633146105165760405162461bcd60e51b815260040161029190610750565b33ff5b6000546001600160a01b031633146105435760405162461bcd60e51b815260040161029190610750565b6001600160a01b0381166105a85760405162461bcd60e51b815260206004820152602660248201527f4f776e61626c653a206e6577206f776e657220697320746865207a65726f206160448201526564647265737360d01b6064820152608401610291565b6105b1816106d2565b50565b804710156106045760405162461bcd60e51b815260206004820152601d60248201527f416464726573733a20696e73756666696369656e742062616c616e63650000006044820152606401610291565b6000826001600160a01b03168260405160006040518083038185875af1925050503d8060008114610651576040519150601f19603f3d011682016040523d82523d6000602084013e610656565b606091505b50509050806106cd5760405162461bcd60e51b815260206004820152603a60248201527f416464726573733a20756e61626c6520746f2073656e642076616c75652c207260448201527f6563697069656e74206d617920686176652072657665727465640000000000006064820152608401610291565b505050565b600080546001600160a01b038381166001600160a01b0319831681178455604051919092169283917f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e09190a35050565b600060208284031215610733578081fd5b81356001600160a01b0381168114610749578182fd5b9392505050565b6020808252818101527f4f776e61626c653a2063616c6c6572206973206e6f7420746865206f776e6572604082015260600190565b6000828210156107a357634e487b7160e01b81526011600452602481fd5b50039056fea2646970667358221220a08d288b10582eabe7ce59e5e32bb1efd8bd67275bfd761c3e71394aae7b1c8264736f6c63430008040033