eth-faucet

Gas token gifter with controls from time intervals, amounts and access
Info | Log | Files | Refs | README

PeriodSimple.sol (2211B)


      1 pragma solidity >=0.8.0;
      2 
      3 // SPDX-License-Identifier: AGPL-3.0-or-later
      4 
      5 contract PeriodSimple {
      6 
      7 	address public owner;
      8 	address public poker;
      9 	uint256 public period;
     10 	uint256 public balanceThreshold;
     11 	mapping (address => uint256) public lastUsed;
     12 
     13 	event PeriodChange(uint256 _value);
     14 	event BalanceThresholdChange(uint256 _value);
     15 
     16 	// Implements ERC173
     17 	event OwnershipTransferred(address indexed previousOwner, address indexed newOwner); // EIP173
     18 
     19 	constructor() {
     20 		owner = msg.sender;
     21 		poker = owner;
     22 	}
     23 
     24 	function setPeriod(uint256 _period) public {
     25 		require(owner == msg.sender, 'ERR_NOT_OWNER');
     26 		period = _period;
     27 		emit PeriodChange(_period);
     28 	}
     29 
     30 	function setPoker(address _poker) public {
     31 		require(msg.sender == owner);
     32 		poker = _poker;
     33 	}
     34 
     35 	function setBalanceThreshold(uint256 _threshold) public {
     36 		require(msg.sender == owner);
     37 		balanceThreshold = _threshold;
     38 		emit BalanceThresholdChange(_threshold);
     39 	}
     40 
     41 	function next(address _subject) external view returns(uint256) {
     42 		return lastUsed[_subject] + period;
     43 	}
     44 	
     45 	//function check(address _subject) external view returns(bool) {
     46 	function have(address _subject) external view returns(bool) {
     47 		if (balanceThreshold > 0 && _subject.balance >= balanceThreshold) {
     48 			return false;
     49 		}
     50 		if (lastUsed[_subject] == 0) {
     51 			return true;
     52 		}
     53 		return block.timestamp > this.next(_subject);
     54 	}
     55 
     56 	function poke(address _subject) external returns(bool) {
     57 		require(msg.sender == owner || msg.sender == poker, 'ERR_ACCESS');
     58 		if (!this.have(_subject)) {
     59 			return false;
     60 		}
     61 		lastUsed[_subject] = block.timestamp;
     62 		return true;
     63 	}
     64 
     65 	// Implements EIP173
     66 	function transferOwnership(address _newOwner) public returns (bool) {
     67 		address oldOwner;
     68 		require(msg.sender == owner, 'ERR_AXX');
     69 
     70 		oldOwner = owner;
     71 		owner = _newOwner;
     72 
     73 		emit OwnershipTransferred(oldOwner, owner);
     74 		return true;
     75 	}
     76 
     77 	// Implements ERC165
     78 	function supportsInterface(bytes4 _sum) public pure returns (bool) {
     79 		if (_sum == 0x01ffc9a7) { // ERC165
     80 			return true;
     81 		}
     82 		if (_sum == 0x9493f8b2) { // ERC173
     83 			return true;
     84 		}
     85 		if (_sum == 0x3ef25013) { // ACL
     86 			return true;
     87 		}
     88 		if (_sum == 0x242824a9) { // Throttle
     89 			return true;
     90 		}
     91 		return false;
     92 	}
     93 }