-
Notifications
You must be signed in to change notification settings - Fork 6
/
LemonICO.sol
105 lines (85 loc) · 3.02 KB
/
LemonICO.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
pragma solidity >=0.4.22 <0.6.2;
contract ERC20Basic {
function totalSupply() public view returns (uint256);
function tokenBalance(address who) public view returns (uint256);
function transfer(address to, uint256 value) internal returns (bool);
event Transfer(address indexed from, address indexed to, uint256 value);
}
contract LemonToken is ERC20Basic {
address payable owner;
string public name;
string public symbol;
uint public decimals;
uint256 public initialSupply;
uint256 tokenSupply;
mapping (address => uint) balances;
constructor() public {
owner = msg.sender;
name = "LemonToken";
symbol = "LMN";
decimals = 18;
initialSupply = 1000000;
tokenSupply = initialSupply;
balances[owner] = tokenSupply;
}
function totalSupply() public view returns (uint256 tokens) {
return balances[owner];
}
function tokenBalance(address _owner) public view returns (uint256 LMNtokens) {
return balances[_owner];
}
function transfer(address to, uint256 value) internal returns (bool success) {
balances[owner] = tokenSupply;
if (balances[owner] >= value && value > 0) {
balances[owner] -= value;
balances[to] += value;
emit Transfer(owner, to, value);
return true;
} else { return false; }
}
}
contract LemonCrowdsale is LemonToken {
uint startTime;
uint endTime;
uint rateOfTokensToGivePerEth;
address payable walletToStoreTheEthers;
uint lemonTokens;
mapping (address => uint) contribution;
constructor() public payable {
walletToStoreTheEthers = msg.sender;
startTime = now + 2 minutes;
endTime = startTime + 5 minutes;
rateOfTokensToGivePerEth = 10;
contribution[msg.sender] = 0;
}
modifier hasBegun() {
require(startTime <= now, "ICO Launch has not begun");
_;
}
modifier timedICO() {
require(!hasEnded(), "Crowdsale has ended!");
_;
}
modifier nonOwner() {
require(walletToStoreTheEthers != msg.sender, "Contract Owner cannot partake in ICO");
_;
}
function hasEnded() public view returns (bool icoEnded) {
return endTime <= now;
}
function ownerBalance() public view returns (uint weiProfits) {
require(walletToStoreTheEthers == msg.sender, "Only Contract Owner is authorized");
return contribution[msg.sender];
}
function contributions() public view nonOwner returns (uint weiContributions) {
return contribution[msg.sender];
}
function buyLemonTokens() public payable hasBegun timedICO nonOwner {
lemonTokens = rateOfTokensToGivePerEth * (msg.value / 1 ether);
require(msg.value > 0, "Cannot buy ZERO tokens");
contribution[walletToStoreTheEthers] += msg.value;
contribution[msg.sender] += msg.value;
LemonToken.transfer(msg.sender, lemonTokens);
walletToStoreTheEthers.transfer(msg.value);
}
}