/
Sale.sol
141 lines (114 loc) · 4.38 KB
/
Sale.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
pragma solidity ^0.4.21;
import "./Svandis.sol";
contract Sale is Svandis {
address owner;
address withdrawWallet;
uint256 public tier1Rate;
uint256 public tier2Rate;
bool public tiersSet = false;
uint8 public currentTier = 0;
bool private enableSale = true;
uint256 public preSaleRate;
mapping(uint8 => uint256) public tierToRates;
mapping (address => uint256) public companyAllowed;
constructor() public {
owner = msg.sender;
balances[this] = totalSupply;
}
modifier onlyOwner {
require(owner == msg.sender);
_;
}
modifier onlyWithdrawWallet {
require(withdrawWallet == msg.sender);
_;
}
modifier saleOngoing {
require(enableSale == true);
_;
}
function setWithdrawWallet(address _withdrawalAddress) public onlyOwner returns (bool success) {
require (_withdrawalAddress != address(0));
withdrawWallet = _withdrawalAddress;
return true;
}
//Finalize taking tokens
function disableSale() public onlyOwner returns (bool success){
enableSale = false;
return true;
}
function getContractEth() public view onlyOwner returns (uint256 value) {
return address(this).balance;
}
function withdraw(uint256 _amount) public onlyWithdrawWallet returns (bool success){
require(_amount <= address(this).balance);
withdrawWallet.transfer(_amount);
return true;
}
function addToWhitelist(address _whitelisted, uint256 _quantity) public onlyOwner returns (bool success) {
require(_quantity <= balances[this]);
allowed[this][_whitelisted] = _quantity;
return true;
}
function addMultipleToWhitelist(address[] _whitelistedAddresses, uint256[] _quantities) public onlyOwner returns (bool success) {
require(_whitelistedAddresses.length == _quantities.length);
require(_whitelistedAddresses.length <= 100); //Limit set at 100
for(uint i = 0; i < _whitelistedAddresses.length; i++){
addToWhitelist(_whitelistedAddresses[i], _quantities[i]);
}
return true;
}
function addToCompanyWhitelist(address _whitelisted, uint256 _quantity) public onlyOwner returns (bool success) {
require(_quantity < balances[this]);
companyAllowed[_whitelisted] = _quantity;
return true;
}
function removeFromWhitelist(address _whitelisted) public onlyOwner returns (bool success) {
allowed[this][_whitelisted] = 0;
return true;
}
function removeFromCompanyWhitelist(address _whitelisted) public onlyOwner returns (bool success) {
companyAllowed[_whitelisted] = 0;
return true;
}
function checkWhitelisted(address _whitelisted) public view onlyOwner returns (uint256 quantity) {
return allowed[this][_whitelisted];
}
function checkCompanyWhitelisted(address _whitelisted) public view onlyOwner returns (uint256 quantity) {
return companyAllowed[_whitelisted];
}
function setPreSaleRate(uint256 _preSaleRate) public onlyOwner returns (bool success) {
tierToRates[0] = _preSaleRate;
return true;
}
function setTiers(uint256 _tier1Rate, uint256 _tier2Rate) public onlyOwner saleOngoing returns (bool success) {
tiersSet = true;
tierToRates[1] = _tier1Rate;
tierToRates[2] = _tier2Rate;
return true;
}
function switchTiers(uint8 _tier) public onlyOwner returns (bool success) {
require(_tier == 1 || _tier == 2);
require(_tier > currentTier);
currentTier = _tier;
return true;
}
function () public payable {
revert();
}
function buyTokens() public saleOngoing payable {
uint256 quantity = (msg.value * tierToRates[currentTier])/(1 ether);
require(quantity <= allowed[this][msg.sender]);
balances[msg.sender] += quantity;
balances[address(this)] -= quantity;
allowed[this][msg.sender] -= quantity;
withdrawWallet.transfer(msg.value);
emit Transfer(this, msg.sender, quantity);
}
function takeCompanyTokensOwnership() public {
balances[msg.sender] += companyAllowed[msg.sender];
balances[address(this)] -= companyAllowed[msg.sender];
emit Transfer(this, msg.sender, companyAllowed[msg.sender]);
companyAllowed[msg.sender] = 0;
}
}