-
Notifications
You must be signed in to change notification settings - Fork 97
/
Copy path0x7b1309c1522afd4e66c31e1e6d0ec1319e1eba5e-BLN-Bulleon.sol
353 lines (287 loc) · 11.9 KB
/
0x7b1309c1522afd4e66c31e1e6d0ec1319e1eba5e-BLN-Bulleon.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
pragma solidity ^0.4.18;
// © Bulleon. All Rights Reserved
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 div(uint256 a, uint256 b) internal constant 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 constant returns (uint256) {
assert(b <= a);
return a - b;
}
function add(uint256 a, uint256 b) internal constant returns (uint256) {
uint256 c = a + b;
assert(c >= a);
return c;
}
}
contract owned {
address public owner;
address public newOwner;
function owned() payable {
owner = msg.sender;
}
modifier onlyOwner {
require(owner == msg.sender);
_;
}
function changeOwner(address _owner) onlyOwner public {
require(_owner != 0);
newOwner = _owner;
}
function confirmOwner() public {
require(newOwner == msg.sender);
owner = newOwner;
delete newOwner;
}
}
contract StandardToken {
using SafeMath for uint256;
mapping (address => mapping (address => uint256)) allowed;
mapping(address => uint256) balances;
uint256 public totalSupply;
event Transfer(address indexed from, address indexed to, uint256 value);
event Approval(address indexed owner, address indexed spender, uint256 value);
/**
* @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(_to != address(0));
// SafeMath.sub will throw if there is not enough balance.
balances[msg.sender] = balances[msg.sender].sub(_value);
balances[_to] = balances[_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) public constant returns (uint256 balance) {
return balances[_owner];
}
/**
* @dev Transfer tokens from one address to another
* @param _from address The address which you want to send tokens from
* @param _to address The address which you want to transfer to
* @param _value uint256 the amount of tokens to be transferred
*/
function transferFrom(address _from, address _to, uint256 _value) public returns (bool) {
require(_to != address(0));
var _allowance = allowed[_from][msg.sender];
// Check is not needed because sub(_allowance, _value) will already throw if this condition is not met
// require (_value <= _allowance);
balances[_from] = balances[_from].sub(_value);
balances[_to] = balances[_to].add(_value);
allowed[_from][msg.sender] = _allowance.sub(_value);
Transfer(_from, _to, _value);
return true;
}
/**
* @dev Approve the passed address to spend the specified amount of tokens on behalf of msg.sender.
* @param _spender The address which will spend the funds.
* @param _value The amount of tokens to be spent.
*/
function approve(address _spender, uint256 _value) public returns (bool) {
// To change the approve amount you first have to reduce the addresses`
// allowance to zero by calling `approve(_spender, 0)` if it is not
// already 0 to mitigate the race condition described here:
// https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729
require((_value == 0) || (allowed[msg.sender][_spender] == 0));
allowed[msg.sender][_spender] = _value;
Approval(msg.sender, _spender, _value);
return true;
}
/**
* @dev Function to check the amount of tokens that an owner allowed to a spender.
* @param _owner address The address which owns the funds.
* @param _spender address The address which will spend the funds.
* @return A uint256 specifying the amount of tokens still available for the spender.
*/
function allowance(address _owner, address _spender) public constant returns (uint256 remaining) {
return allowed[_owner][_spender];
}
/**
* approve should be called when allowed[_spender] == 0. To increment
* allowed value is better to use this function to avoid 2 calls (and wait until
* the first transaction is mined)
* From MonolithDAO Token.sol
*/
function increaseApproval (address _spender, uint _addedValue) public
returns (bool success) {
allowed[msg.sender][_spender] = allowed[msg.sender][_spender].add(_addedValue);
Approval(msg.sender, _spender, allowed[msg.sender][_spender]);
return true;
}
function decreaseApproval (address _spender, uint _subtractedValue) public
returns (bool success) {
uint oldValue = allowed[msg.sender][_spender];
if (_subtractedValue > oldValue) {
allowed[msg.sender][_spender] = 0;
} else {
allowed[msg.sender][_spender] = oldValue.sub(_subtractedValue);
}
Approval(msg.sender, _spender, allowed[msg.sender][_spender]);
return true;
}
}
contract BulleonICO is owned {
using SafeMath for uint256;
string public version = "1.0";
address private WITHDRAW_WALLET;
uint256 public totalSold = 0;
uint256 public soldOnStage = 0;
uint8 public currentStage = 0;
Bulleon public rewardToken;
uint256[] tokensRate = [1000,800,600,400,200,100,75,50,25,10,5,1];
uint256[] tokensCap = [760000,760000,760000,760000,760000,760000,760000,760000,760000,760000,760000,760000];
mapping(address=>uint256) investments;
uint256 LIMIT_ON_BENEFICIARY = 1000 * 1 ether;
function investmentsOf(address beneficiary) public constant returns(uint256) {
return investments[beneficiary];
}
function availableOnStage() public constant returns(uint256) {
return tokensCap[currentStage].mul(1 ether).sub(soldOnStage);
}
function createTokenContract() internal returns (Bulleon) {
return new Bulleon();
}
function currentStageTokensCap() public constant returns(uint256) {
return tokensCap[currentStage];
}
function currentStageTokensRate() public constant returns(uint256) {
return tokensRate[currentStage];
}
function BulleonICO() payable owned() {
owner = msg.sender;
WITHDRAW_WALLET = msg.sender;
rewardToken = createTokenContract();
}
function () payable {
buyTokens(msg.sender);
}
function buyTokens(address beneficiary) payable {
bool canBuy = investmentsOf(beneficiary) < LIMIT_ON_BENEFICIARY;
bool validPurchase = beneficiary != 0x0 && msg.value != 0;
uint256 currentTokensAmount = availableTokens();
require(canBuy && validPurchase && currentTokensAmount > 0);
uint256 boughtTokens;
uint256 refundAmount = 0;
uint256[2] memory tokensAndRefund = calcMultiStage();
boughtTokens = tokensAndRefund[0];
refundAmount = tokensAndRefund[1];
require(boughtTokens < currentTokensAmount);
totalSold = totalSold.add(boughtTokens);
investments[beneficiary] = investments[beneficiary].add(boughtTokens);
if( soldOnStage >= tokensCap[currentStage].mul(1 ether)) {
toNextStage();
}
rewardToken.transfer(beneficiary,boughtTokens);
if (refundAmount > 0)
refundMoney(refundAmount);
withdrawFunds(this.balance);
}
function forceWithdraw() onlyOwner {
withdrawFunds(this.balance);
}
function calcMultiStage() internal returns(uint256[2]) {
uint256 stageBoughtTokens;
uint256 undistributedAmount = msg.value;
uint256 _boughtTokens = 0;
uint256 undistributedTokens = availableTokens();
while(undistributedAmount > 0 && undistributedTokens > 0) {
bool needNextStage = false;
stageBoughtTokens = getTokensAmount(undistributedAmount);
if(totalInvestments(_boughtTokens.add(stageBoughtTokens)) > LIMIT_ON_BENEFICIARY){
stageBoughtTokens = LIMIT_ON_BENEFICIARY.sub(_boughtTokens);
undistributedTokens = stageBoughtTokens;
}
if (stageBoughtTokens > availableOnStage()) {
stageBoughtTokens = availableOnStage();
needNextStage = true;
}
_boughtTokens = _boughtTokens.add(stageBoughtTokens);
undistributedTokens = undistributedTokens.sub(stageBoughtTokens);
undistributedAmount = undistributedAmount.sub(getTokensCost(stageBoughtTokens));
soldOnStage = soldOnStage.add(stageBoughtTokens);
if (needNextStage)
toNextStage();
}
return [_boughtTokens,undistributedAmount];
}
function setWithdrawWallet(address addressToWithdraw) public onlyOwner {
require(addressToWithdraw != 0x0);
WITHDRAW_WALLET = addressToWithdraw;
}
function totalInvestments(uint additionalAmount) internal returns (uint256) {
return investmentsOf(msg.sender).add(additionalAmount);
}
function refundMoney(uint256 refundAmount) internal {
msg.sender.transfer(refundAmount);
}
function burnTokens(uint256 amount) public onlyOwner {
rewardToken.burn(amount);
}
function getTokensCost(uint256 _tokensAmount) internal constant returns(uint256) {
return _tokensAmount.div(tokensRate[currentStage]);
}
function getTokensAmount(uint256 _amountInWei) internal constant returns(uint256) {
return _amountInWei.mul(tokensRate[currentStage]);
}
function toNextStage() internal {
if(currentStage < tokensRate.length && currentStage < tokensCap.length){
currentStage++;
soldOnStage = 0;
}
}
function availableTokens() public constant returns(uint256) {
return rewardToken.balanceOf(address(this));
}
function withdrawFunds(uint256 amount) internal {
WITHDRAW_WALLET.transfer(amount);
}
}
contract Bulleon is StandardToken {
event Burn(address indexed burner, uint256 value);
string public constant name = "Bulleon";
string public constant symbol = "BLN";
uint8 public constant decimals = 18;
string public version = "1.0";
uint256 public totalSupply = 9500000 * 1 ether;
mapping(address=>uint256) premineOf;
address[] private premineWallets = [
0xdAB26a04594Ca4EDB276672BE0A0F697e5a24aFb,
0xA75E62874Cb25D53e563A269DF4b52d5A28e7A8e,
0x6Ff480a30D037B774c6aba935468fa5560d769a4
];
function Bulleon() public {
balances[msg.sender] = totalSupply;
premineOf[premineWallets[0]] = 95000 * 1 ether;
premineOf[premineWallets[1]] = 95000 * 1 ether;
premineOf[premineWallets[2]] = 190000 * 1 ether;
for(uint i = 0; i<premineWallets.length;i++) {
transfer(premineWallets[i],premineOf[premineWallets[i]]);
}
}
/**
* @dev Burns a specific amount of tokens.
* @param _value The amount of token to be burned.
*/
function burn(uint256 _value) public {
require(_value > 0);
address burner = msg.sender;
balances[burner] = balances[burner].sub(_value);
totalSupply = totalSupply.sub(_value);
Burn(burner, _value);
}
}