-
Notifications
You must be signed in to change notification settings - Fork 3
/
Ucift.sol
372 lines (312 loc) · 11.6 KB
/
Ucift.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
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
pragma solidity ^0.4.23;
contract Ucift {
//Supply definition
string public name;
string public symbol;
uint256 public ownerSupply;
uint256 public icoSupply;
uint256 public poolSupply;
uint256 public totalSupply;
uint256 _poolSupply = 200000000e18;
uint256 _saleSupply = 100000000e18;
uint256 _reserveSupply = 100000000e18;
uint256 public constant decimals = 18;
uint256 _totalSupply = _poolSupply + _saleSupply + _reserveSupply;
uint256 countOnPool = 0;
//Token
string _tokenName = "Universal Crypto Investment Fund";
string _symbol = "UCIFT";
address public owner;
uint256 public price = 1 trx;
uint256 public saleDate = 1563164918;
uint256 public escrow = 0;
//Addresses
address public marketing;
address public development;
//Mappings
mapping(address => uint256) public balanceOf;
mapping(uint256 => mapping(uint256 => Investor[])) public staking;
mapping(uint256 => Referral) public referral;
mapping(uint256 => mapping(uint256 => Request[])) public request;
//Events
event Transfer(address _from, address _to, uint256 _value);
//Helper
uint256 exists;
uint256 public staked;
uint256 requestExists;
uint256 count = 0;
uint256 public requestCount = 0;
//Struct
struct Investor{
address person;
uint256 timestamp;
uint256 amount;
uint256 amountCredited;
bool onPool;
uint256 referralCode;
uint256 referred;
}
struct Referral {
uint256 id;
address person;
}
struct Request {
address person;
uint256 amount;
bool processed;
}
//Modifiers
modifier onlyOwner(){
require(msg.sender == owner);
_;
}
modifier Allowed(){
require(now >= saleDate);
require(now <= (saleDate + 7776000)); //90 days
_;
}
modifier buyBackAllowed(){
require(now >= (saleDate + 7776000));
_;
}
constructor() public {
owner = msg.sender;
count++;
referral[count] = Referral(count, msg.sender);
name = _tokenName;
symbol = _symbol;
ownerSupply = _reserveSupply;
poolSupply = _poolSupply;
icoSupply = _saleSupply;
totalSupply = _totalSupply;
balanceOf[owner] = _reserveSupply;
marketing = owner;
development = owner;
}
function changeOwner(address _new) public onlyOwner{
owner = _new;
}
function setMarketingAddress(address _new) public onlyOwner{
marketing = _new;
}
function setDevelopmentAddress(address _new) public onlyOwner{
development = _new;
}
function moveIcoToPool() public onlyOwner{
require(now >= (saleDate + 7776000));
if(icoSupply > 0){
poolSupply += icoSupply;
icoSupply = 0;
}
}
function buyToken(uint256 _amount) public payable Allowed{
uint256 amount = _amount*10**decimals;
require(amount <= icoSupply);
require(msg.value >= price);
uint256 result = _amount * price;
require(msg.value == result);
balanceOf[msg.sender] += amount;
icoSupply -= amount;
owner.transfer(result);
}
function _transfer(address _from, address _to, uint _value) internal {
require(_to != 0);
require(balanceOf[_from] >= _value);
require(balanceOf[_to] + _value >= balanceOf[_to]);
uint256 previousBalances = balanceOf[_from] + balanceOf[_to];
balanceOf[_from] -= _value;
balanceOf[_to] += _value;
emit Transfer(_from, _to, _value);
assert(balanceOf[_from] + balanceOf[_to] == previousBalances);
}
function transfer(address _to, uint256 _value) public returns (bool success){
_transfer(msg.sender, _to, _value);
return true;
}
function isOnPool(address _person) internal returns(bool) {
for(uint256 i = 0; i < staking[1][1].length; i++){
if(staking[1][1][i].person == _person) {
exists = i;
return true;
}
}
return false;
}
function isRequest(address _person) internal returns(bool){
_person = msg.sender;
for(uint256 i=0; i < request[1][1].length; i++){
if(request[1][1][i].person == _person){
requestExists = i;
return true;
}
}
return false;
}
function viewRequests() public view returns(address){
for(uint256 i = 0; i < request[1][1].length; i++){
if(request[1][1][i].processed == false ){
request[1][1][i].person;
}
}
}
function createReferral(address _person) internal {
count += 1;
referral[count] = Referral(count, _person);
}
function viewReferralCode() public view returns(uint256){
for(uint256 i = 1; i <= count; i++){
if(referral[i].person == msg.sender){
return referral[i].id;
}
}
revert();
}
function invest(uint256 _amount, uint256 _id) public {
uint256 amount = _amount*10**decimals;
require(amount >= 1);
require(msg.sender != 0);
require(balanceOf[msg.sender] >= (amount));
uint256 _timestamp = now;
address _person = msg.sender;
bool _onPool = true;
uint256 onePercent = (amount)/ 100; // 1%
uint256 investor = (amount * 96) / 100; //96% Investor
require(investor <= poolSupply);
if(isOnPool(msg.sender) == false && (msg.sender != owner)){
require(_id > 0 && _id <= count);
createReferral(msg.sender); //Creates referral code;
staking[1][1].push(Investor(_person, _timestamp, amount, investor, _onPool, count, _id));
balanceOf[msg.sender] -= amount;
balanceOf[referral[_id].person] += onePercent;//Referral %
balanceOf[marketing] += onePercent; //Marketing %
balanceOf[development] += onePercent; //Devs %
poolSupply += onePercent; //Pool %
poolSupply -= investor; // Algorithm
//balanceOf[msg.sender] += investor;
}
else if(msg.sender == owner && isOnPool(msg.sender) == false){
staking[1][1].push(Investor(_person, _timestamp, amount, investor, _onPool, 1, 0));
balanceOf[msg.sender] -= amount;
poolSupply += onePercent; //As Owner has no referral, pool should have +1%
balanceOf[marketing] += onePercent;
balanceOf[development] += onePercent;
poolSupply += onePercent; //Respective pool %
poolSupply -= investor; //Algorithm
//balanceOf[msg.sender] += investor;
}
else if(msg.sender == owner && isOnPool(msg.sender) == true){
balanceOf[msg.sender] -= amount;
poolSupply += onePercent; //As Owner has no referral, pool should have +1%
balanceOf[marketing] += onePercent;
balanceOf[development] += onePercent;
poolSupply += onePercent; //Respective pool %
poolSupply -= investor;
//balanceOf[msg.sender] += investor;
staking[1][1][exists].amount += amount;
staking[1][1][exists].amountCredited += investor;
staking[1][1][exists].onPool = true;
}
else if(isOnPool(msg.sender) == true && (msg.sender) != owner){
balanceOf[msg.sender] -= amount;
balanceOf[marketing] += onePercent;
balanceOf[development] += onePercent;
uint256 ref = staking[1][1][exists].referred;
balanceOf[referral[ref].person] += onePercent;
poolSupply += onePercent;
poolSupply -= investor;
//balanceOf[msg.sender] += investor;
staking[1][1][exists].onPool = true;
staking[1][1][exists].amount += amount;
staking[1][1][exists].amountCredited += investor;
}
}
function withdraw() public {
require(isOnPool(msg.sender) == true);
require(staking[1][1][exists].onPool == true);
uint256 amountInvested = staking[1][1][exists].amount;
uint256 credited = (amountInvested *96) / 100;
uint256 c = now - staking[1][1][exists].timestamp;
uint256 d = c * amountInvested;
require(d / c == amountInvested);
uint256 stakedOne = (((d/100)/86400)); // 1% daily
require(stakedOne >= 1e18);
staking[1][1][exists].onPool = false;
assert(staking[1][1][exists].timestamp <= now);
balanceOf[msg.sender] += stakedOne;
balanceOf[msg.sender] += staking[1][1][exists].amountCredited;
staking[1][1][exists].amount = 0;
poolSupply += credited;
poolSupply -= stakedOne;
}
function viewStake() public returns(uint256){
require(isOnPool(msg.sender) == true);
require(staking[1][1][exists].onPool == true);
uint256 amountInvested = staking[1][1][exists].amount;
uint256 c = now - staking[1][1][exists].timestamp;
uint256 d = c * amountInvested;
require(d / c == amountInvested);
staked = ((d /100)/86400);
return staked;
}
function withdrawStake() public returns(uint256){
require(isOnPool(msg.sender) == true);
require(staking[1][1][exists].onPool == true);
uint256 amountInvested = staking[1][1][exists].amount;
uint256 c = now - staking[1][1][exists].timestamp;
uint256 d = c * amountInvested;
require(d / c == amountInvested);
uint256 stakedOne = ((d /100)/86400);
require(stakedOne >= 1e18);
uint256 totalStake = stakedOne;
balanceOf[msg.sender] += totalStake;
poolSupply -= totalStake;
staking[1][1][exists].timestamp = now;
return totalStake;
}
function requestBuyBack(uint256 _amount) public buyBackAllowed {
uint256 amount = _amount*10**decimals;
require(balanceOf[msg.sender] >= amount);
require(isOnPool(msg.sender) == true);
if(isRequest(msg.sender) == false){
balanceOf[msg.sender] -= amount;
escrow += amount;
requestCount += 1;
request[1][1].push(Request(msg.sender, _amount, false));
}
else {
balanceOf[msg.sender] -= amount;
escrow += amount;
request[1][1][requestExists].amount += _amount;
request[1][1][requestExists].processed = false;
}
}
function cancelBuyBack() public buyBackAllowed {
require(isOnPool(msg.sender) == true);
require(isRequest(msg.sender) == true);
uint256 _amount = request[1][1][requestExists].amount;
require(escrow >= _amount);
escrow -= _amount;
balanceOf[msg.sender] += _amount;
request[1][1][requestExists].processed = true;
request[1][1][requestExists].amount = 0;
}
function processRequest(uint256 _id, uint256 amount) public payable onlyOwner{
require(request[1][1][_id].processed == false);
require(isOnPool(request[1][1][_id].person) == true);
require(msg.value == (amount * price));
uint256 onePercent = (msg.value)/ 100; // 1%
uint256 investor = (msg.value * 96) / 100; //96% Investor
address person = request[1][1][_id].person;
address referred = referral[staking[1][1][_id].referred].person;
uint256 fromEscrow = amount*10**decimals;
development.transfer(onePercent);
marketing.transfer(onePercent);
referred.transfer(onePercent);
person.transfer(investor);
require(fromEscrow <= escrow);
escrow -= fromEscrow;
poolSupply += fromEscrow;
request[1][1][_id].processed = true;
request[1][1][_id].amount = 0;
}
}