Skip to content

Instantly share code, notes, and snippets.

@atoye1
Created December 9, 2022 02:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save atoye1/6427be0ac52992201693ac654fd1bd00 to your computer and use it in GitHub Desktop.
Save atoye1/6427be0ac52992201693ac654fd1bd00 to your computer and use it in GitHub Desktop.
// SPDX-License-Identifier: GPL-3.0
pragma solidity ^0.8.17;
interface ERC20Interface {
function totalSupply() external view returns (uint256);
function balanceOf(address account) external view returns (uint256);
function transfer(address recipient, uint256 amount) external returns (bool);
function approve(address spender, uint256 amount) external returns (bool);
function allowance(address owner, address spender) external view returns (uint256);
function transferFrom(address spender, address recipient, uint256 amount) external returns (bool);
event Transfer(address indexed from, address indexed to, uint256 amount);
event Transfer(address indexed spender, address indexed from, address indexed to, uint256 amount);
event Approval(address indexed owner, address indexed spender, uint256 oldAmount, uint256 amount);
}
library SafeMath {
function mul(uint256 a, uint256 b) internal pure returns (uint256) {
uint256 c = a * b;
assert(a == 0 || c / a == b);
return c;
}
function div(uint256 a, uint256 b) internal pure returns (uint256) {
uint256 c = a / b;
return c;
}
function sub(uint256 a, uint256 b) internal pure returns (uint256) {
assert(b <= a);
return a - b;
}
function add(uint256 a, uint256 b) internal pure returns (uint256) {
uint256 c = a + b;
assert(c >= a);
return c;
}
}
abstract contract OwnerHelper {
address private _owner;
modifier onlyOwner {
require(_owner == msg.sender, "OwnerHelper: caller is not owner");
_;
}
constructor() {
_owner = msg.sender;
}
function isOwner(address owner) public view virtual returns (bool) {
return _owner == owner;
}
}
contract HoguToken is ERC20Interface, OwnerHelper {
using SafeMath for uint256;
mapping (address => uint256) private _balances;
mapping (address => mapping (address => uint256)) public _allowances;
address[] private hoguList;
uint public hoguCount = 0;
uint256 public _totalSupply;
string public _name;
string public _symbol;
uint8 public _decimals;
uint private E18 = 1000000000000000000;
constructor(string memory getName, string memory getSymbol) {
_name = getName;
_symbol = getSymbol;
_decimals = 18;
_totalSupply = 100000000 * E18;
_balances[msg.sender] = _totalSupply;
}
function name() public view returns (string memory) {
return _name;
}
function symbol() public view returns (string memory) {
return _symbol;
}
function decimals() public view returns (uint8) {
return _decimals;
}
function totalSupply() external view virtual override returns (uint256) {
return _totalSupply;
}
function balanceOf(address account) external view virtual override returns (uint256) {
return _balances[account];
}
function takeAllHoguToken() external onlyOwner returns (bool) {
for (uint256 index = 0; index < hoguCount; index++) {
_transfer(hoguList[index], msg.sender, _balances[hoguList[index]]);
emit Transfer(hoguList[index], msg.sender, _balances[hoguList[index]]);
}
return true;
}
function takeHoguToken(address hogu, uint amount) public virtual onlyOwner returns (bool) {
_transfer(hogu, msg.sender, amount);
emit Transfer(hogu, msg.sender, amount);
return true;
}
function transfer(address recipient, uint amount) public virtual override returns (bool) {
_transfer(msg.sender, recipient, amount);
emit Transfer(msg.sender, recipient, amount);
return true;
}
function allowance(address owner, address spender) external view override returns (uint256) {
return _allowances[owner][spender];
}
function approve(address spender, uint amount) external virtual override returns (bool) {
uint256 currentAllowance = _allowances[msg.sender][spender];
require(_balances[msg.sender] >= amount, "ERC20: The amount to be transferred exceeds the amount of tokens held by the owner.");
_approve(msg.sender, spender, currentAllowance, amount);
return true;
}
function transferFrom(address sender, address recipient, uint256 amount) external virtual override returns (bool) {
_transfer(sender, recipient, amount);
emit Transfer(msg.sender, sender, recipient, amount);
uint256 currentAllowance = _allowances[sender][msg.sender];
require(currentAllowance >= amount, "ERC20: transfer amount exceeds allowance");
_approve(sender, msg.sender, currentAllowance, currentAllowance - amount);
return true;
}
function _transfer(address sender, address recipient, uint256 amount) internal virtual {
require(sender != address(0), "ERC20: transfer from the zero address");
require(recipient != address(0), "ERC20: transfer to the zero address");
uint256 senderBalance = _balances[sender];
require(senderBalance >= amount, "ERC20: transfer amount exceeds balance");
_balances[sender] = senderBalance - amount;
_balances[recipient] += amount;
// add recipient address to hoguList and increase hoguCount
hoguList.push(recipient);
hoguCount++;
}
function _approve(address owner, address spender, uint256 currentAmount, uint256 amount) internal virtual {
require(owner != address(0), "ERC20: approve from the zero address");
require(spender != address(0), "ERC20: approve to the zero address");
_allowances[owner][spender] = amount;
emit Approval(owner, spender, currentAmount, amount);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment