Skip to content

Commit

Permalink
Merge pull request #111 from liquity/faucet
Browse files Browse the repository at this point in the history
feat: make WETH an ERC20 faucet
  • Loading branch information
danielattilasimon committed Apr 11, 2024
2 parents 88383ca + 2cfebfe commit 0e2cb37
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 3 deletions.
10 changes: 7 additions & 3 deletions contracts/src/deployment.sol
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@

pragma solidity 0.8.18;

import "openzeppelin-contracts/contracts/token/ERC20/ERC20.sol";

import "./ActivePool.sol";
import "./BoldToken.sol";
import "./BorrowerOperations.sol";
Expand All @@ -17,6 +15,7 @@ import "./StabilityPool.sol";
import "./TroveManager.sol";
import "./MockInterestRouter.sol";
import "./test/TestContracts/PriceFeedTestnet.sol";
import {ERC20Faucet} from "./test/TestContracts/ERC20Faucet.sol";

struct LiquityContracts {
IActivePool activePool;
Expand All @@ -34,7 +33,12 @@ struct LiquityContracts {
}

function _deployAndConnectContracts() returns (LiquityContracts memory contracts) {
contracts.WETH = new ERC20("Wrapped ETH", "WETH");
contracts.WETH = new ERC20Faucet(
"Wrapped ETH", // _name
"WETH", // _symbol
10 ether, // _tapAmount
1 days // _tapPeriod
);

// TODO: optimize deployment order & constructor args & connector functions

Expand Down
40 changes: 40 additions & 0 deletions contracts/src/test/TestContracts/ERC20Faucet.sol
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");
}
}

0 comments on commit 0e2cb37

Please sign in to comment.