Files

134 lines
4.1 KiB
Solidity
Raw Permalink Normal View History

2021-06-09 09:41:32 +08:00
/*
2022-02-17 11:18:10 +08:00
Copyright 2022 DODO ZOO.
2021-06-09 09:41:32 +08:00
SPDX-License-Identifier: Apache-2.0
*/
pragma solidity 0.6.9;
import {SafeMath} from "../../lib/SafeMath.sol";
import {InitializableOwnable} from "../../lib/InitializableOwnable.sol";
contract CustomERC20 is InitializableOwnable {
using SafeMath for uint256;
string public name;
2021-06-28 23:51:34 +08:00
uint8 public decimals;
2021-06-09 09:41:32 +08:00
string public symbol;
uint256 public totalSupply;
uint256 public tradeBurnRatio;
uint256 public tradeFeeRatio;
address public team;
mapping(address => uint256) balances;
mapping(address => mapping(address => uint256)) internal allowed;
event Transfer(address indexed from, address indexed to, uint256 amount);
event Approval(address indexed owner, address indexed spender, uint256 amount);
event ChangeTeam(address oldTeam, address newTeam);
function init(
address _creator,
2022-02-17 11:18:10 +08:00
uint256 _totalSupply,
2021-06-09 09:41:32 +08:00
string memory _name,
string memory _symbol,
2021-06-28 23:51:34 +08:00
uint8 _decimals,
2021-06-09 09:41:32 +08:00
uint256 _tradeBurnRatio,
uint256 _tradeFeeRatio,
2022-02-17 11:18:10 +08:00
address _team
2021-06-09 09:41:32 +08:00
) public {
initOwner(_creator);
name = _name;
symbol = _symbol;
decimals = _decimals;
2022-02-17 11:18:10 +08:00
totalSupply = _totalSupply;
balances[_creator] = _totalSupply;
2021-06-09 09:41:32 +08:00
require(_tradeBurnRatio >= 0 && _tradeBurnRatio <= 5000, "TRADE_BURN_RATIO_INVALID");
require(_tradeFeeRatio >= 0 && _tradeFeeRatio <= 5000, "TRADE_FEE_RATIO_INVALID");
tradeBurnRatio = _tradeBurnRatio;
tradeFeeRatio = _tradeFeeRatio;
team = _team;
2022-02-17 11:18:10 +08:00
emit Transfer(address(0), _creator, _totalSupply);
2021-06-09 09:41:32 +08:00
}
function transfer(address to, uint256 amount) public returns (bool) {
_transfer(msg.sender,to,amount);
return true;
}
function balanceOf(address owner) public view returns (uint256 balance) {
return balances[owner];
}
function transferFrom(
address from,
address to,
uint256 amount
) public returns (bool) {
require(amount <= allowed[from][msg.sender], "ALLOWANCE_NOT_ENOUGH");
_transfer(from,to,amount);
allowed[from][msg.sender] = allowed[from][msg.sender].sub(amount);
return true;
}
function approve(address spender, uint256 amount) public returns (bool) {
allowed[msg.sender][spender] = amount;
emit Approval(msg.sender, spender, amount);
return true;
}
function allowance(address owner, address spender) public view returns (uint256) {
return allowed[owner][spender];
}
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");
require(balances[sender] >= amount, "ERC20: transfer amount exceeds balance");
balances[sender] = balances[sender].sub(amount);
uint256 burnAmount;
uint256 feeAmount;
if(tradeBurnRatio > 0) {
burnAmount = amount.mul(tradeBurnRatio).div(10000);
balances[address(0)] = balances[address(0)].add(burnAmount);
2022-02-21 16:31:27 +08:00
emit Transfer(sender, address(0), burnAmount);
2021-06-09 09:41:32 +08:00
}
if(tradeFeeRatio > 0) {
feeAmount = amount.mul(tradeFeeRatio).div(10000);
balances[team] = balances[team].add(feeAmount);
2022-02-21 16:31:27 +08:00
emit Transfer(sender, team, feeAmount);
2021-06-09 09:41:32 +08:00
}
2022-02-21 16:31:27 +08:00
uint256 receiveAmount = amount.sub(burnAmount).sub(feeAmount);
balances[recipient] = balances[recipient].add(receiveAmount);
2021-06-09 09:41:32 +08:00
2022-02-21 16:31:27 +08:00
emit Transfer(sender, recipient, receiveAmount);
2021-06-09 09:41:32 +08:00
}
2021-07-07 14:26:00 +08:00
//=================== Ownable ======================
2021-06-09 09:41:32 +08:00
function changeTeamAccount(address newTeam) external onlyOwner {
require(tradeFeeRatio > 0, "NOT_TRADE_FEE_TOKEN");
emit ChangeTeam(team,newTeam);
team = newTeam;
}
2022-02-17 11:18:10 +08:00
function abandonOwnership(address zeroAddress) external onlyOwner {
require(zeroAddress == address(0), "NOT_ZERO_ADDRESS");
emit OwnershipTransferred(_OWNER_, address(0));
_OWNER_ = address(0);
}
2021-06-09 09:41:32 +08:00
}