-
Notifications
You must be signed in to change notification settings - Fork 36
/
token-com-import.sol
100 lines (80 loc) · 3.01 KB
/
token-com-import.sol
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
/*
SPDX-License-Identifier: CC-BY-4.0
(c) Desenvolvido por Jeff Prestes
This work is licensed under a Creative Commons Attribution 4.0 International License.
*/
pragma solidity 0.8.4;
import './lib-interface-erc20.sol';
import "./lib-support-contract.sol";
/// @title ERC-20 Token template
contract TicketERC20 is IERC20, Sale {
string private myName;
string private mySymbol;
uint256 private myTotalSupply;
uint256 public decimals;
mapping (address=>uint256) balances;
mapping (address=>mapping (address=>uint256)) ownerAllowances;
constructor() {
myName = "Ficha de Chocolate";
mySymbol = "CHOCO1";
decimals = 2;
_mint(msg.sender, (46 * (10 ** decimals)));
changeTokenBasePrice(100 gwei);
}
function name() public view returns(string memory) {
return myName;
}
function symbol() public view returns(string memory) {
return mySymbol;
}
function totalSupply() public override view returns(uint256) {
return myTotalSupply;
}
function balanceOf(address tokenOwner) public override view returns(uint256) {
return balances[tokenOwner];
}
function allowance(address tokenOwner, address spender) public override view returns(uint256) {
return ownerAllowances[tokenOwner][spender];
}
function transfer(address to, uint256 amount) public override hasEnoughBalance(msg.sender, amount) tokenAmountValid(amount) returns(bool) {
balances[msg.sender] = balances[msg.sender] - amount;
balances[to] = balances[to] + amount;
emit Transfer(msg.sender, to, amount);
return true;
}
function approve(address spender, uint limit) public override returns(bool) {
ownerAllowances[msg.sender][spender] = limit;
emit Approval(msg.sender, spender, limit);
return true;
}
function transferFrom(address from, address to, uint256 amount) public override
hasEnoughBalance(from, amount) isAllowed(msg.sender, from, amount) tokenAmountValid(amount)
returns(bool) {
balances[from] = balances[from] - amount;
balances[to] += amount;
ownerAllowances[from][msg.sender] = amount;
emit Transfer(from, to, amount);
return true;
}
function _mint(address account, uint256 amount) internal virtual {
require(account != address(0), "ERC20: mint to the zero address");
myTotalSupply = myTotalSupply + amount;
balances[account] = balances[account] + amount;
emit Transfer(address(0), account, amount);
}
modifier hasEnoughBalance(address owner, uint amount) {
uint balance;
balance = balances[owner];
require (balance >= amount);
_;
}
modifier isAllowed(address spender, address tokenOwner, uint amount) {
require (amount <= ownerAllowances[tokenOwner][spender]);
_;
}
modifier tokenAmountValid(uint256 amount) {
require(amount > 0);
require(amount <= myTotalSupply);
_;
}
}