-
Notifications
You must be signed in to change notification settings - Fork 0
/
RVL.sol
280 lines (239 loc) · 9.68 KB
/
RVL.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
pragma solidity ^0.4.11;
library SafeMath {
function mul(uint256 a, uint256 b) internal pure returns (uint256) {
uint256 c = a * b;
assert(a == 0 || c / a == b);
return c;
}
function div(uint256 a, uint256 b) internal pure returns (uint256) {
assert(b > 0); // Solidity automatically throws when dividing by 0
uint256 c = a / b;
assert(a == b * c + a % b); // There is no case in which this doesn't hold
return c;
}
function sub(uint256 a, uint256 b) internal pure returns (uint256) {
assert(b <= a);
return a - b;
}
function add(uint256 a, uint256 b) internal pure returns (uint256) {
uint256 c = a + b;
assert(c >= a);
return c;
}
}
contract Ownable {
address public owner;
event OwnershipTransferred(address indexed previousOwner, address indexed newOwner);
/**
* @dev The Ownable constructor sets the original `owner` of the contract to the sender
* account.
*/
function Ownable() public {
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 public {
require(newOwner != address(0));
OwnershipTransferred(owner, newOwner);
owner = newOwner;
}
}
/**
* @title ERC20Basic
* @dev Simpler version of ERC20 interface
* @dev see https://github.com/ethereum/EIPs/issues/179
*/
contract ERC20Basic {
uint256 public totalSupply;
function balanceOf(address who) constant public returns (uint256);
function transfer(address to, uint256 value) public returns (bool);
event Transfer(address indexed from, address indexed to, uint256 value);
}
/**
* @title Basic token
* @dev Basic version of StandardToken, with no allowances.
*/
contract BasicToken is ERC20Basic {
using SafeMath for uint256;
mapping(address => uint256) tokenBalances;
/**
* @dev transfer token for a specified address
* @param _to The address to transfer to.
* @param _value The amount to be transferred.
*/
function transfer(address _to, uint256 _value) public returns (bool) {
require(tokenBalances[msg.sender]>=_value);
tokenBalances[msg.sender] = tokenBalances[msg.sender].sub(_value);
tokenBalances[_to] = tokenBalances[_to].add(_value);
Transfer(msg.sender, _to, _value);
return true;
}
/**
* @dev Gets the balance of the specified address.
* @param _owner The address to query the the balance of.
* @return An uint256 representing the amount owned by the passed address.
*/
function balanceOf(address _owner) constant public returns (uint256 balance) {
return tokenBalances[_owner];
}
}
contract RevolutionCoin is BasicToken,Ownable {
using SafeMath for uint256;
string public constant name = "R-evolutioncoin";
string public constant symbol = "RVL";
uint256 public constant decimals = 18;
uint256 public preIcoBuyPrice = 222222222222222; // per token the price is 2.2222*10^-4 eth, this price is equivalent in wei
uint256 public IcoPrice = 1000000000000000;
uint256 public bonusPhase1 = 30;
uint256 public bonusPhase2 = 20;
uint256 public bonusPhase3 = 10;
uint256 public TOKENS_SOLD;
address public ethStore = 0xDd64EF0c8a41d8a17F09ce2279D79b3397184A10;
uint256 public constant INITIAL_SUPPLY = 100000000;
event Debug(string message, address addr, uint256 number);
event log(string message, uint256 number);
/**
* @dev Contructor that gives msg.sender all of existing tokens.
*/
//TODO: Change the name of the constructor
function RevolutionCoin() public {
owner = ethStore;
totalSupply = INITIAL_SUPPLY;
tokenBalances[ethStore] = INITIAL_SUPPLY * (10 ** uint256(decimals)); //Since we divided the token into 10^18 parts
TOKENS_SOLD = 0;
}
// fallback function can be used to buy tokens
function () public payable {
// require(msg.sender != owner); //owner should not be buying any tokens
buy(msg.sender);
}
function calculateTokens(uint amt) internal returns (uint tokensYouCanGive, uint returnAmount) {
uint bonus = 0;
uint tokensRequired = 0;
uint tokensWithoutBonus = 0;
uint priceCharged = 0;
//pre-ico phase
if (TOKENS_SOLD <4500000)
{
tokensRequired = amt.div(preIcoBuyPrice);
if (tokensRequired + TOKENS_SOLD > 4500000)
{
tokensYouCanGive = 4500000 - TOKENS_SOLD;
returnAmount = tokensRequired - tokensYouCanGive;
returnAmount = returnAmount.mul(preIcoBuyPrice);
log("Tokens being bought exceed the limit of pre-ico. Returning remaining amount",returnAmount);
}
else
{
tokensYouCanGive = tokensRequired;
returnAmount = 0;
}
require (tokensYouCanGive + TOKENS_SOLD <= 4500000);
}
//ico phase 1 with 30% bonus
else if (TOKENS_SOLD >=4500000 && TOKENS_SOLD <24000000)
{
tokensRequired = amt.div(IcoPrice);
bonus = tokensRequired.mul(bonusPhase1);
bonus = bonus.div(100);
tokensRequired = tokensRequired.add(bonus);
if (tokensRequired + TOKENS_SOLD > 24000000)
{
tokensYouCanGive = 24000000 - TOKENS_SOLD;
tokensWithoutBonus = tokensYouCanGive.mul(10);
tokensWithoutBonus = tokensWithoutBonus.div(13);
priceCharged = tokensWithoutBonus.mul(IcoPrice);
returnAmount = amt - priceCharged;
log("Tokens being bought exceed the limit of ico phase 1. Returning remaining amount",returnAmount);
}
else
{
tokensYouCanGive = tokensRequired;
returnAmount = 0;
}
require (tokensYouCanGive + TOKENS_SOLD <= 24000000);
}
//ico phase 2 with 20% bonus
if (TOKENS_SOLD >=24000000 && TOKENS_SOLD <42000000)
{
tokensRequired = amt.div(IcoPrice);
bonus = tokensRequired.mul(bonusPhase2);
bonus = bonus.div(100);
tokensRequired = tokensRequired.add(bonus);
if (tokensRequired + TOKENS_SOLD > 42000000)
{
tokensYouCanGive = 42000000 - TOKENS_SOLD;
tokensWithoutBonus = tokensYouCanGive.mul(10);
tokensWithoutBonus = tokensWithoutBonus.div(13);
priceCharged = tokensWithoutBonus.mul(IcoPrice);
returnAmount = amt - priceCharged;
log("Tokens being bought exceed the limit of ico phase 2. Returning remaining amount",returnAmount);
}
else
{
tokensYouCanGive = tokensRequired;
returnAmount = 0;
}
require (tokensYouCanGive + TOKENS_SOLD <= 42000000);
}
//ico phase 3 with 10% bonus
if (TOKENS_SOLD >=42000000 && TOKENS_SOLD <58500000)
{
tokensRequired = amt.div(IcoPrice);
bonus = tokensRequired.mul(bonusPhase3);
bonus = bonus.div(100);
tokensRequired = tokensRequired.add(bonus);
if (tokensRequired + TOKENS_SOLD > 58500000)
{
tokensYouCanGive = 58500000 - TOKENS_SOLD;
tokensWithoutBonus = tokensYouCanGive.mul(10);
tokensWithoutBonus = tokensWithoutBonus.div(13);
priceCharged = tokensWithoutBonus.mul(IcoPrice);
returnAmount = amt - priceCharged;
log("Tokens being bought exceed the limit of ico phase 3. Returning remaining amount",returnAmount);
}
else
{
tokensYouCanGive = tokensRequired;
returnAmount = 0;
}
require (tokensYouCanGive + TOKENS_SOLD <= 58500000);
}
if (TOKENS_SOLD == 58500000)
{
log("ICO has ended. All tokens sold.", 58500000);
tokensYouCanGive = 0;
returnAmount = amt;
}
require(TOKENS_SOLD <=58500000);
}
function buy(address beneficiary) payable public returns (uint tokens) {
uint paymentToGiveBack = 0;
(tokens,paymentToGiveBack) = calculateTokens(msg.value);
TOKENS_SOLD += tokens;
tokens = tokens * (10 ** uint256(decimals));
require(tokenBalances[owner] >= tokens); // checks if it has enough to sell
tokenBalances[beneficiary] = tokenBalances[beneficiary].add(tokens); // adds the amount to buyer's balance
tokenBalances[owner] = tokenBalances[owner].sub(tokens); // subtracts amount from seller's balance
Transfer(owner, beneficiary, tokens); // execute an event reflecting the change
if (paymentToGiveBack >0)
{
beneficiary.transfer(paymentToGiveBack);
}
ethStore.transfer(msg.value - paymentToGiveBack); //send the eth to the address where eth should be collected
return tokens; // ends function and returns
}
function getTokenBalance(address yourAddress) constant public returns (uint256 balance) {
return tokenBalances[yourAddress].div (10**decimals); // show token balance in full tokens not part
}
}