-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathPresaleBonuses.sol
72 lines (57 loc) · 1.98 KB
/
PresaleBonuses.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
pragma solidity ^0.4.18;
import "./math/SafeMath.sol";
import "../lib/ethereum-datetime/contracts/api.sol";
library PresaleBonuses {
using SafeMath for uint;
function presaleBonusApplicator(uint _purchased, address _dateTimeLib)
internal view returns (uint reward)
{
DateTimeAPI dateTime = DateTimeAPI(_dateTimeLib);
uint hour = dateTime.getHour(block.timestamp);
uint day = dateTime.getDay(block.timestamp);
/// First 4 hours bonus
if (day == 2 && hour >= 16 && hour < 20) {
return applyPercentage(_purchased, 70);
}
/// First day bonus
if ((day == 2 && hour >= 20) || (day == 3 && hour < 5)) {
return applyPercentage(_purchased, 50);
}
/// Second day bonus
if ((day == 3 && hour >= 5) || (day == 4 && hour < 5)) {
return applyPercentage(_purchased, 45);
}
/// Days 3 - 20 bonus
if (day < 22) {
uint numDays = day - 3;
if (hour < 5) {
numDays--;
}
return applyPercentage(_purchased, (45 - numDays));
}
/// Fill the gap
if (day == 22 && hour < 5) {
return applyPercentage(_purchased, 27);
}
/// Day 21 bonus
if ((day == 22 && hour >= 5) || (day == 23 && hour < 5)) {
return applyPercentage(_purchased, 25);
}
/// Day 22 bonus
if ((day == 23 && hour >= 5) || (day == 24 && hour < 5)) {
return applyPercentage(_purchased, 20);
}
/// Day 23 bonus
if ((day == 24 && hour >= 5) || (day == 25 && hour < 5)) {
return applyPercentage(_purchased, 15);
}
//else
revert();
}
/// Internal function to apply a specified percentage amount to an integer.
function applyPercentage(uint _base, uint _percentage)
internal pure returns (uint num)
{
num = _base.mul(_percentage).div(100);
}
}