-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This will let us print free WETH for manual testing & demos.
- Loading branch information
1 parent
88383ca
commit 2cfebfe
Showing
2 changed files
with
47 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
// SPDX-License-Identifier: GPL-3.0 | ||
pragma solidity 0.8.18; | ||
|
||
import "openzeppelin-contracts/contracts/token/ERC20/ERC20.sol"; | ||
import "openzeppelin-contracts/contracts/access/Ownable.sol"; | ||
|
||
contract ERC20Faucet is ERC20, Ownable { | ||
uint256 public immutable tapAmount; | ||
uint256 public immutable tapPeriod; | ||
|
||
mapping(address => uint256) public lastTapped; | ||
|
||
constructor(string memory _name, string memory _symbol, uint256 _tapAmount, uint256 _tapPeriod) | ||
ERC20(_name, _symbol) | ||
{ | ||
tapAmount = _tapAmount; | ||
tapPeriod = _tapPeriod; | ||
} | ||
|
||
function mint(address _to, uint256 _amount) external onlyOwner { | ||
_mint(_to, _amount); | ||
} | ||
|
||
function tapTo(address receiver) public { | ||
uint256 timeNow = _requireNotRecentlyTapped(receiver); | ||
|
||
_mint(receiver, tapAmount); | ||
lastTapped[receiver] = timeNow; | ||
} | ||
|
||
function tap() external { | ||
tapTo(msg.sender); | ||
} | ||
|
||
function _requireNotRecentlyTapped(address receiver) internal view returns (uint256 timeNow) { | ||
timeNow = block.timestamp; | ||
|
||
require(timeNow >= lastTapped[receiver] + tapPeriod, "ERC20Faucet: must wait before tapping again"); | ||
} | ||
} |