Created
July 24, 2022 11:46
-
-
Save dobestan/dbf28b6bdb08aab367a74b3ad49b546f to your computer and use it in GitHub Desktop.
Created using remix-ide: Realtime Ethereum Contract Compiler and Runtime. Load this file by pasting this gists URL or ID at https://remix.ethereum.org/#version=soljson-v0.8.7+commit.e28d00a7.js&optimize=false&runs=200&gist=
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
// SPDX-License-Identifier: UNLICENSED | |
pragma solidity >=0.8.0; | |
import "@openzeppelin/contracts/token/ERC20/ERC20.sol"; | |
contract UtilityToken is ERC20 { | |
address public managerAddress; | |
uint internal _totalSupply; | |
mapping(address => uint256) internal _balances; | |
event TransferFee(address indexed from, address indexed to, uint256 value); | |
event Reset(address indexed reseter, uint amount); | |
constructor(uint _initialSupply) ERC20("UtilityToken", "UT") { | |
// Assume that msg.sender is ManagerContract. | |
managerAddress = msg.sender; | |
_mint(managerAddress, _initialSupply); | |
} | |
// .transfer OR ._beforeTokenTransfer | |
// https://docs.openzeppelin.com/contracts/4.x/extending-contracts#using-hooks | |
function _transfer( | |
address from, | |
address to, | |
uint amount | |
) override internal virtual { | |
super._transfer(from, to, amount * 90 / 100); | |
super._transfer(from, managerAddress, amount * 10/100); | |
emit TransferFee(from, managerAddress, amount * 10/100); | |
} | |
// Hard Reset | |
function _beforeReset() internal virtual {} | |
function _afterReset() internal virtual {} | |
function _reset(uint _initialSupply) internal virtual { | |
_beforeReset(); | |
// delete _balances; | |
// emit Reset(msg.sender(), _totalSupply); | |
_totalSupply = 0; | |
_mint(msg.sender, _initialSupply); | |
_afterReset(); | |
// TODO: allowances mapping 도 다 리셋해야 함. | |
} | |
function reset(uint _initialSupply) public virtual returns(bool) { | |
_reset(_initialSupply); | |
return true; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment