-
Notifications
You must be signed in to change notification settings - Fork 0
/
ERC20-TKN.sol
88 lines (73 loc) · 2.97 KB
/
ERC20-TKN.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
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.24;
import "@openzeppelin/contracts/token/ERC20/ERC20.sol";
import "@openzeppelin/contracts/token/ERC20/extensions/ERC20Burnable.sol";
import "@openzeppelin/contracts/token/ERC20/extensions/ERC20Permit.sol";
import "@openzeppelin/contracts/access/Ownable.sol";
library SafeMath {
function add(uint256 a, uint256 b) internal pure returns (uint256) {
uint256 c = a + b;
require(c >= a, "SafeMath: addition overflow");
return c;
}
function sub(uint256 a, uint256 b) internal pure returns (uint256) {
return sub(a, b, "SafeMath: subtraction overflow");
}
function sub(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) {
require(b <= a, errorMessage);
uint256 c = a - b;
return c;
}
function mul(uint256 a, uint256 b) internal pure returns (uint256) {
if (a == 0) {
return 0;
}
uint256 c = a * b;
require(c / a == b, "SafeMath: multiplication overflow");
return c;
}
function div(uint256 a, uint256 b) internal pure returns (uint256) {
return div(a, b, "SafeMath: division by zero");
}
function div(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) {
require(b > 0, errorMessage);
uint256 c = a / b;
return c;
}
}
contract ATOKEN is ERC20, ERC20Burnable, ERC20Permit, Ownable {
using SafeMath for uint256;
mapping(address => bool) public claimed;
mapping (address => mapping (address => uint256)) private _allowances;
uint256 initialSupply = 100000000;
constructor()
ERC20("ATOKEN", "TKN")
ERC20Permit("ATOKEN")
Ownable(msg.sender)
{
_mint(address(this), initialSupply * (10 ** uint256(decimals())));
}
function claim(address to, uint256 amount) public onlyOwner {
require(!claimed[to], "You have already claimed your tokens");
require(to != address(0), "ERC20: transfer to the zero address");
require(balanceOf(address(this)) >= amount, "Don't have enough TKN");
claimed[to] = true;
_transfer(address(this), to, amount);
}
function transfer(address to, uint256 amount) public override returns (bool) {
_transfer(_msgSender(), to, amount);
return true;
}
function allowance(address owner, address spender) public view override returns (uint256) {
return _allowances[owner][spender];
}
function approve(address spender, uint256 amount) public override returns (bool) {
_approve(_msgSender(), spender, amount);
return true;
}
function transferFrom(address sender, address recipient, uint256 amount) public onlyOwner override returns (bool) {
_transfer(sender, recipient, amount);
_approve(sender, _msgSender(), _allowances[sender][_msgSender()].sub(amount, "ERC20: transfer amount exceeds allowance"));
return true;
}
}