Skip to content

Instantly share code, notes, and snippets.

@z0r0z
Created December 31, 2021 17:43
Show Gist options
  • Select an option

  • Save z0r0z/eabf7cdbfd54fdc249390137e60fdd87 to your computer and use it in GitHub Desktop.

Select an option

Save z0r0z/eabf7cdbfd54fdc249390137e60fdd87 to your computer and use it in GitHub Desktop.
whitelisted, conditioned, time-restricted
// SPDX-License-Identifier: MIT
pragma solidity 0.8.0;
/// @notice Basic ERC20 implementation.
contract TestERC20 {
string public name;
string public symbol;
uint8 constant public decimals = 18;
uint256 public totalSupply;
uint256 public deadline;
address public owner;
bool public thingHappened;
mapping(address => uint) public balanceOf;
mapping(address => mapping(address => uint)) public allowance;
mapping(address => bool) public whitelisted;
event Transfer(address indexed from, address indexed to, uint amount);
event Approval(address indexed owner, address indexed spender, uint amount);
constructor(string memory _name, string memory _symbol, uint _totalSupply, uint256 _deadline, address account) {
name = _name;
symbol = _symbol;
totalSupply = _totalSupply;
deadline = _deadline;
balanceOf[msg.sender] = _totalSupply;
thingHappened = false;
owner = msg.sender;
whitelisted[account] = true;
emit Transfer(address(0), msg.sender, _totalSupply);
}
modifier TimePassed {
require(block.timestamp > deadline);
_;
}
modifier OnlyOwner {
require(msg.sender == owner);
_;
}
modifier ThingHappened {
require(thingHappened);
_;
}
modifier OnlyWhitelisted(address from, address to) {
require(whitelisted[from] && whitelisted[to]);
_;
}
function approve(address to, uint amount) external TimePassed OnlyWhitelisted(msg.sender, to) ThingHappened returns (bool) {
allowance[msg.sender][to] = amount;
emit Approval(msg.sender, to, amount);
return true;
}
function transfer(address to, uint amount) external TimePassed OnlyWhitelisted(msg.sender, to) ThingHappened returns (bool) {
balanceOf[msg.sender] -= amount;
balanceOf[to] += amount;
emit Transfer(msg.sender, to, amount);
return true;
}
function transferFrom(address from, address to, uint amount) external TimePassed OnlyWhitelisted(from, to) ThingHappened returns (bool) {
if (allowance[from][msg.sender] != type(uint).max)
allowance[from][msg.sender] -= amount;
balanceOf[from] -= amount;
balanceOf[to] += amount;
emit Transfer(from, to, amount);
return true;
}
function addToWhitelist(address account) external OnlyOwner {
whitelisted[account] = true;
}
function addOwner(address account) external OnlyOwner {
owner = account;
}
function sayThingHappened() external OnlyOwner {
thingHappened = true;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment