-
Notifications
You must be signed in to change notification settings - Fork 0
/
ICO.sol
108 lines (79 loc) · 3.06 KB
/
ICO.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
//SPDX-License-Identifier: GPL-3.0
pragma solidity >=0.5.0 <0.9.0;
import "./ERC20.sol";
contract CryptosICO is Cryptos {
address public admin;
address payable public deposit;
uint tokenPrice = 0.001 ether;
uint public hardCap = 300 ether;
uint public raisedAmount;
uint public saleStart = block.timestamp;
uint public saleEnd = block.timestamp + 604800;
uint public tokenTradeStart = saleEnd + 604800;
uint public maxInvestment = 5 ether;
uint public minInvestment = 0.1 ether;
enum State{beforeStart, running, afterEnd, halted}
State public icoState;
event Invest(address investor, uint value, uint tokens);
constructor(address payable _deposit){
admin = msg.sender;
deposit = _deposit;
icoState = State.beforeStart;
}
modifier onlyAdmin(){
require(msg.sender == admin);
_;
}
function changeDepsoitAddress(address payable _newDeposit) public onlyAdmin{
deposit = _newDeposit;
}
function halt() public onlyAdmin{
icoState = State.halted;
}
function resume() public onlyAdmin{
icoState = State.running;
}
function getCurrentState() public view returns(State) {
if(icoState == State.halted){
return State.halted;
}else if (block.timestamp < saleStart){
return State.beforeStart;
}else if (block.timestamp >= saleStart && block.timestamp <= saleEnd){
return State.running;
}else
return State.afterEnd;
}
function invest() payable public returns(bool){
icoState = getCurrentState();
require(icoState == State.running);
require(msg.value >= minInvestment && msg.value <= maxInvestment);
raisedAmount += msg.value;
require(raisedAmount <= hardCap);
uint tokens = msg.value / tokenPrice;
balances[msg.sender] += tokens;
balances[founder] -= tokens;
deposit.transfer(msg.value);
emit Invest(msg.sender, msg.value, tokens);
return true;
}
receive () payable external{
invest();
}
function transfer(address to, uint tokens) public override returns (bool success){
require(block.timestamp > tokenTradeStart); // the token will be transferable only after tokenTradeStart
// calling the transfer function of the base contract
super.transfer(to, tokens); // same as Cryptos.transfer(to, tokens);
return true;
}
function transferFrom(address from, address to, uint tokens) public override returns (bool success){
require(block.timestamp > tokenTradeStart); // the token will be transferable only after tokenTradeStart
Cryptos.transferFrom(from, to, tokens); // same as super.transferFrom(to, tokens);
return true;
}
function burn() public returns(bool){
icoState = getCurrentState();
require(icoState == State.afterEnd);
balances[founder] = 0;
return true;
}
}