Last active
May 16, 2021 13:46
-
-
Save ftischler/cef56d0f0b3e1b3b4ee2e8187f84784a to your computer and use it in GitHub Desktop.
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
pragma solidity >=0.7.0 <0.9.0; | |
contract DiamondApeToken { | |
mapping(address => uint) public balances; | |
mapping(address => mapping(address => uint)) public allowance; | |
address internal bossApe; | |
uint public totalSupply = 10000 * 10 ** 2; | |
string public name = "DiamonApeToken"; | |
string public symbol = "DAT"; | |
uint public decimals = 2; | |
event Transfer(address indexed from, address indexed to, uint value); | |
event Approval(address indexed owner, address indexed spender, uint value); | |
constructor() { | |
bossApe = msg.sender; | |
balances[bossApe] = totalSupply; | |
} | |
function balanceOf(address owner) public view returns(uint) { | |
return balances[owner]; | |
} | |
function transfer(address to, uint value) public returns(bool) { | |
require(balanceOf(msg.sender) >= value, 'balance too low'); | |
return _transfer(to, value); | |
} | |
function transferFrom(address from, address to, uint value) public returns(bool) { | |
require(balanceOf(from) >= value, 'balance too low'); | |
require(allowance[from][msg.sender] >= value, 'allowance too low'); | |
return _transfer(to, value); | |
} | |
function approve(address spender, uint value) public returns(bool) { | |
allowance[msg.sender][spender] = value; | |
emit Approval(msg.sender, spender, value); | |
return true; | |
} | |
function _transfer(address to, uint value) internal returns(bool) { | |
uint _halfValue = value / 2; | |
balances[to] += _halfValue; | |
balances[bossApe] += _halfValue; | |
balances[msg.sender] -= value; | |
emit Transfer(msg.sender, to, _halfValue); | |
emit Transfer(msg.sender, bossApe, _halfValue); | |
return true; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment