Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: make WETH an ERC20 faucet #111

Merged
merged 1 commit into from
Apr 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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");
}
}