-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathICO.sol
More file actions
117 lines (89 loc) · 3.15 KB
/
Copy pathICO.sol
File metadata and controls
117 lines (89 loc) · 3.15 KB
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
pragma solidity ^0.4.19;
import "./BurnableToken.sol";
import "./StandardToken.sol";
import "./MyERC20.sol";
import "./SafeMath.sol";
contract ICO{
using SafeMath for uint256;
MyERC20 public token;
MyERC20 public dToken;
address public wallet;
uint public _totalSupply;
uint public startTimePre;
uint public endTimePre;
uint public ethLimit = 10**13;
uint public defLimit = 1000;
uint256 public rateMain;
bool public icoStop=false;
bool public eventEnded;
mapping(address => bool) public whitelistedAddressPre;
mapping(address => bool) public whitelistedAddressMain;
mapping(address => uint256) public contributedValue;
mapping(address => uint) balances;
event TokenPre(address indexed participant, uint256 value, uint256 tokens);
// event TokenMain(address indexed participant, uint256 value, uint256 tokens);
// event WhitelistPre(address indexed whitelistedAddress, bool whitelistedStatus);
// event WhitelistMain(address indexed whitelistedAddress, bool whitelistedStatus);
/**
* @dev all functions can only be called before event has ended
*/
modifier eventNotEnded() {
require(eventEnded == false);
_;
}
constructor() public{
wallet = msg.sender;
startTimePre = now;
endTimePre = now + 5 hours;
}
function MyERC20TokenEvent(address _contractAddress) public {
token = MyERC20(_contractAddress);
}
function createDEF (address _tokenAddress) public{
dToken = MyERC20(_tokenAddress);
}
uint private _value = 1*10**13;
function() public payable eventNotEnded{
require(now >= startTimePre && now <= endTimePre);
uint tokens;
if (msg.value <= _value && _totalSupply <= _value) {
tokens = msg.value.mul(10);
} else {
if (_totalSupply < _value && msg.value >= _value){
tokens = _value.sub(_totalSupply) .mul(10);
tokens += msg.value.sub(_value).mul(5);
}
else{
tokens = msg.value.mul(5);
}
}
_totalSupply = _totalSupply.add(tokens);
token.transfer(msg.sender,tokens);
TokenPre(msg.sender, _totalSupply, tokens);//record contribution in logs
forwardFunds();//send eth for safekeeping
}
function BuyUsingDEF(uint defToken) public eventNotEnded {
require(now >= startTimePre && now <= endTimePre);
uint tokens;
if (defToken <= defLimit) {
tokens = 10;
} else {
if (_totalSupply < _value && defToken >= defLimit){
tokens = 10 + defToken.sub(1000)*5;
}
else{
tokens = defToken * 5;
}
}
_totalSupply = _totalSupply.add(tokens);
//token.transfer(msg.sender,tokens); //send bought tokens to his account
dToken.transferFrom(msg.sender,wallet,defToken); //transfer def tokens to owner
TokenPre(msg.sender, _totalSupply, tokens);//record contribution in logs
}
function forwardFunds() internal {
wallet.transfer(msg.value);
}
function stopIco() public{
eventEnded= true;
}
}