-
Notifications
You must be signed in to change notification settings - Fork 6
/
retn-preico.sol
176 lines (146 loc) · 4.57 KB
/
retn-preico.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
pragma solidity ^0.4.16;
/**
* @title SafeMath
* @dev Math operations with safety checks that throw on error
*/
library SafeMath {
function mul(uint256 a, uint256 b) internal constant returns (uint256) {
uint256 c = a * b;
assert(a == 0 || c / a == b);
return c;
}
function add(uint256 a, uint256 b) internal constant returns (uint256) {
uint256 c = a + b;
assert(c >= a);
return c;
}
}
/**
* @title Ownable
* @dev The Ownable contract has an owner address, and provides basic authorization control
* functions, this simplifies the implementation of "user permissions".
*/
contract Ownable {
address public owner;
/**
* @dev The Ownable constructor sets the original `owner` of the contract to the sender
* account.
*/
function Ownable() {
owner = msg.sender;
}
/**
* @dev Throws if called by any account other than the owner.
*/
modifier onlyOwner() {
require(msg.sender == owner);
_;
}
/**
* @dev Allows the current owner to transfer control of the contract to a newOwner.
* @param newOwner The address to transfer ownership to.
*/
function transferOwnership(address newOwner) onlyOwner {
require(newOwner != address(0));
owner = newOwner;
}
}
/**
* @title Token
* @dev API interface for interacting with the WILD Token contract
*/
interface Token {
function transfer(address _to, uint256 _value) returns (bool);
function balanceOf(address _owner) constant returns (uint256 balance);
}
contract Retn8PreIco is Ownable {
using SafeMath for uint256;
Token token;
uint256 public constant START = 1508932800; // 10/25/2017 @ 12:00pm (UTC)
uint256 public constant DAYS = 21;
uint public creationTime;
uint256 public constant initialTokens = 150000000 * 10**18; // Initial number of tokens available
bool public initialized = false;
uint256 public raisedAmount = 0;
event BoughtTokens(address indexed to, uint256 value, uint256 priceValue);
modifier whenSaleIsActive() {
// Check if sale is active
require(isActive());
_;
}
function Retn8PreIco(address _tokenAddr) {
require(_tokenAddr != address(0));
token = Token(_tokenAddr);
}
function initialize() onlyOwner {
require(initialized == false); // Can only be initialized once
require(tokensAvailable() >= initialTokens); // Must have enough tokens allocated
initialized = true;
creationTime = now;
}
function isActive() constant returns (bool) {
return (
initialized == true &&
now >= START && // Must be after the START date
now <= START.add(DAYS * 1 days) && // Must be before the end date
tokensAvailable() > 0 // Tokens should be available
);
}
function goalReached() constant returns (bool) {
return (initialized == true && tokensAvailable() == 0);
}
function () payable {
buyTokens();
}
/**
* @dev function that sells available tokens
*/
function buyTokens() payable whenSaleIsActive {
// Calculate tokens to sell
uint256 weiAmount = msg.value;
uint256 rate = getRate();
uint256 tokens = weiAmount.mul(rate);
require(tokensAvailable() >= tokens);
BoughtTokens(msg.sender, tokens, weiAmount);
// Increment raised amount
raisedAmount = raisedAmount.add(msg.value);
// Send tokens to buyer
token.transfer(msg.sender, tokens);
// Send money to owner
owner.transfer(msg.value);
}
/**
* @dev returns the number of tokens allocated to this contract
*/
function tokensAvailable() constant returns (uint256) {
return token.balanceOf(this);
}
/**
* @dev returns the number of tokens purchased by an address
*/
function tokenbalanceOf(address from) constant returns (uint256) {
return token.balanceOf(from);
}
function drain() onlyOwner {
require(!isActive());
// Transfer tokens back to owner
uint256 balance = token.balanceOf(this);
require(balance > 0);
owner.transfer(this.balance);
token.transfer(owner, balance);
}
/**
* @notice Get bonus rates
*/
function getRate() constant returns(uint) {
if (creationTime + 1 weeks >= now) {
return 1684; //number of tokens in week 1
} else if (creationTime + 2 weeks >= now) {
return 1588; //number of tokens in week 2
} else if (creationTime + 3 weeks >= now) {
return 1504; //number of tokens in week 3
} else {
return 1203;
}
}
}