-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathERC20MintableCreator.sol
259 lines (216 loc) · 9.51 KB
/
ERC20MintableCreator.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
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
/**
*Submitted for verification at BscScan.com on 2021-11-25
*/
// SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.8.10;
interface tokenRecipient {
function recieveApproval(address _from, uint256 _value, address _token, bytes memory _extradata) external;
}
// a library for performing overflow-safe math, courtesy of DappHub (https://github.com/dapphub/ds-math)
library SafeMath {
function add(uint x, uint y) internal pure returns (uint z) {
require((z = x + y) >= x, 'ds-math-add-overflow');
}
function sub(uint x, uint y) internal pure returns (uint z) {
require((z = x - y) <= x, 'ds-math-sub-underflow');
}
function mul(uint x, uint y) internal pure returns (uint z) {
require(y == 0 || (z = x * y) / y == x, 'ds-math-mul-overflow');
}
}
contract Context {
// Empty internal constructor, to prevent people from mistakenly deploying
// an instance of this contract, which should be used via inheritance.
constructor () { }
// solhint-disable-previous-line no-empty-blocks
function _msgSender() internal view returns (address payable) {
return payable(msg.sender);
}
function _msgData() internal view returns (bytes memory) {
this; // silence state mutability warning without generating bytecode - see https://github.com/ethereum/solidity/issues/2691
return msg.data;
}
}
contract Ownable is Context {
address private _owner;
event OwnershipTransferred(address indexed previousOwner, address indexed newOwner);
/**
* @dev Initializes the contract setting the deployer as the initial owner.
*/
constructor () {
address msgSender = _msgSender();
_owner = msgSender;
emit OwnershipTransferred(address(0), msgSender);
}
/**
* @dev Returns the address of the current owner.
*/
function owner() public view returns (address) {
return _owner;
}
/**
* @dev Throws if called by any account other than the owner.
*/
modifier onlyOwner() {
require(isOwner(), "Ownable: caller is not the owner");
_;
}
/**
* @dev Returns true if the caller is the current owner.
*/
function isOwner() public view returns (bool) {
return _msgSender() == _owner;
}
/**
* @dev Leaves the contract without owner. It will not be possible to call
* `onlyOwner` functions anymore. Can only be called by the current owner.
*
* NOTE: Renouncing ownership will leave the contract without an owner,
* thereby removing any functionality that is only available to the owner.
*/
function renounceOwnership() public onlyOwner {
emit OwnershipTransferred(_owner, address(0));
_owner = address(0);
}
/**
* @dev Transfers ownership of the contract to a new account (`newOwner`).
* Can only be called by the current owner.
*/
function transferOwnership(address newOwner) public onlyOwner {
_transferOwnership(newOwner);
}
/**
* @dev Transfers ownership of the contract to a new account (`newOwner`).
*/
function _transferOwnership(address newOwner) internal {
require(newOwner != address(0), "Ownable: new owner is the zero address");
emit OwnershipTransferred(_owner, newOwner);
_owner = newOwner;
}
}
contract ERC20 is Ownable{
using SafeMath for uint;
string public name;
string public symbol;
uint8 public decimals = 18;
// uint8 public start = 0;
uint256 public currentBlock;
uint256 public nextBlock;
uint256 public totalSupply;
uint256 public maxSupply = 5000000000000000000000000;
bytes32 public DOMAIN_SEPARATOR;
// keccak256("Permit(address owner,address spender,uint256 value,uint256 nonce,uint256 deadline)");
bytes32 public constant PERMIT_TYPEHASH = 0x6e71edae12b1b97f4d1f60370fef10105fa2faae0126114a169c64845d6126c9;
mapping(address => uint) public nonces;
mapping (address => uint256) public balanceOf;
mapping (address => mapping (address => uint256)) public allowance;
event Transfer (address indexed _from, address indexed to, uint256 _value);
event Approval (address indexed _owner, address indexed _spender, uint256 _value);
event Burn (address indexed _from, uint256 _value);
constructor(string memory tokenName, string memory tokenSymbol, address LP_add, address Airdrop_add, address ICO_add,
uint256 LP, uint256 holding, uint256 airdrop, uint256 ICO){
require(LP + holding +airdrop+ICO == 500000, "ICO Coins more than required");
totalSupply = 500000*10**uint256(decimals); //Coin in circulation
balanceOf[msg.sender] = holding*10**uint256(decimals); //Creator holding
balanceOf[LP_add] = LP*10**uint256(decimals); //Used to add LP
balanceOf[Airdrop_add] = airdrop*10**uint256(decimals); //Used to airdrop coins on launch to holders
balanceOf[ICO_add] = ICO*10**uint256(decimals); //Used for ICO
currentBlock = block.number;
nextBlock = currentBlock.add(12960*6);
name = tokenName;
symbol = tokenSymbol;
uint chainId;
assembly {
chainId := chainid()
}
DOMAIN_SEPARATOR = keccak256(
abi.encode(
keccak256('EIP712Domain(string name,string version,uint256 chainId,address verifyingContract)'),
keccak256(bytes(name)),
keccak256(bytes('1')),
chainId,
address(this)
)
);
}
function mint() public onlyOwner {
require(totalSupply < maxSupply, "Maximum Amount of token are in circulation");
require(block.number > nextBlock, "Wait for next release time");
currentBlock = block.number;
nextBlock = currentBlock.add(12960);
balanceOf[msg.sender] = balanceOf[msg.sender].add(150000);
totalSupply = totalSupply.add(150000);
emit Transfer(address(0), msg.sender, 150000);
}
// function mint(
function _transfer(address from, address to, uint value) private {
balanceOf[from] = balanceOf[from].sub(value);
balanceOf[to] = balanceOf[to].add(value);
emit Transfer(from, to, value);
}
function transfer(address to, uint value) external returns (bool) {
_transfer(msg.sender, to, value);
return true;
}
function transferFrom(address _from, address _to, uint256 _value) public returns (bool success){
require(_value <= allowance[_from][msg.sender]);
allowance[_from][msg.sender] -= _value;
_transfer(_from, _to, _value);
return true;
}
function approvalAndCall(address _spender, uint256 _value, bytes memory _extradata) public returns (bool success){
tokenRecipient spender = tokenRecipient(_spender);
if (approve(_spender, _value)){
spender.recieveApproval(msg.sender, _value, address(this), _extradata);
return true;
}
}
function burnFrom(address _from, uint256 _value) public returns (bool success){
require (balanceOf[_from]>= _value);
require(_value <= allowance[_from][msg.sender]);
balanceOf[msg.sender] -=_value;
totalSupply -= _value;
return true;
}
function _burn(address from, uint value) internal {
balanceOf[from] = balanceOf[from].sub(value);
totalSupply = totalSupply.sub(value);
emit Transfer(from, address(0), value);
}
function burn(uint256 _value) public returns (bool success){
require (balanceOf[msg.sender]>= _value);
balanceOf[msg.sender] -=_value;
totalSupply -= _value;
emit Burn(msg.sender, _value);
return true;
}
// function batchTransfer(address[] calldata tokenHolders, uint256[] calldata amounts) external onlyOwner
// {
// require(tokenHolders.length == amounts.length, "Invalid input parameters");
// for(uint256 indx = 0; indx < tokenHolders.length; indx++) {
// require(_transfer(msg.sender, tokenHolders[indx], amounts[indx]), "Unable to transfer token to the account");
// }
// }
function _approve(address owner, address spender, uint value) private {
allowance[owner][spender] = value;
emit Approval(owner, spender, value);
}
function approve(address _spender, uint256 _value) public returns (bool success){
_approve(msg.sender, _spender, _value);
emit Approval(msg.sender, _spender, _value);
return true;
}
function permit(address owner, address spender, uint value, uint deadline, uint8 v, bytes32 r, bytes32 s) external {
require(deadline >= block.timestamp, 'Pancake: EXPIRED');
bytes32 digest = keccak256(
abi.encodePacked(
'\x19\x01',
DOMAIN_SEPARATOR,
keccak256(abi.encode(PERMIT_TYPEHASH, owner, spender, value, nonces[owner]++, deadline))
)
);
address recoveredAddress = ecrecover(digest, v, r, s);
require(recoveredAddress != address(0) && recoveredAddress == owner, 'Pancake: INVALID_SIGNATURE');
_approve(owner, spender, value);
}
}