-
Notifications
You must be signed in to change notification settings - Fork 30
/
Copy pathrouleth.sol
1056 lines (957 loc) · 34.7 KB
/
rouleth.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
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
// , ; , .-'"""'-. , ; ,
// \\|/ .' '. \|//
// \-;-/ () () \-;-/
// // ; ; \\
// //__; :. .; ;__\\
// `-----\'.'-.....-'.'/-----'
// '.'.-.-,_.'.'
// '( (..-'
// '-'
// ROULETH
//
// Play the Roulette on ethereum blockchain !
// (or become a member of Rouleth's Decentralized Organisation and contribute to the bankroll.)
//
//
//
// check latest contract address version on the current website interface
// V 2
//
//
//
contract Rouleth
{
//Game and Global Variables, Structure of gambles
address developer;
uint8 blockDelay; //nb of blocks to wait before spin
uint8 blockExpiration; //nb of blocks before bet expiration (due to hash storage limits)
uint256 maxGamble; //max gamble value manually set by config
uint256 minGamble; //min gamble value manually set by config
uint maxBetsPerBlock; //limits the number of bets per blocks to prevent miner cheating
uint nbBetsCurrentBlock; //counts the nb of bets in the block
uint casinoStatisticalLimit; //ratio payroll and max win
//Current gamble value possibly lower than limit auto
uint256 currentMaxGamble;
//Gambles
enum BetTypes{number, color, parity, dozen, column, lowhigh}
struct Gamble
{
address player;
bool spinned; //Was the rouleth spinned ?
bool win;
//Possible bet types
BetTypes betType;
uint8 input; //stores number, color, dozen or oddeven
uint256 wager;
uint256 blockNumber; //block of bet
uint256 blockSpinned; //block of spin
uint8 wheelResult;
}
Gamble[] private gambles;
uint totalGambles;
//Tracking progress of players
mapping (address=>uint) gambleIndex; //current gamble index of the player
//records current status of player
enum Status {waitingForBet, waitingForSpin} mapping (address=>Status) playerStatus;
//**********************************************
// Management & Config FUNCTIONS //
//**********************************************
function Rouleth() private //creation settings
{
developer = msg.sender;
blockDelay=1; //indicates which block after bet will be used for RNG
blockExpiration=200; //delay after which gamble expires
minGamble=50 finney; //configurable min bet
maxGamble=500 finney; //configurable max bet
maxBetsPerBlock=5; // limit of bets per block, to prevent multiple bets per miners
casinoStatisticalLimit=100; //we are targeting at least 400
}
modifier onlyDeveloper()
{
if (msg.sender!=developer) throw;
_
}
function changeDeveloper_only_Dev(address new_dev)
noEthSent
onlyDeveloper
{
developer=new_dev;
}
//Prevents accidental sending of Eth when you shouldn't
modifier noEthSent()
{
if (msg.value>0)
{
throw;
}
_
}
//Activate, Deactivate Betting
enum States{active, inactive} States private contract_state;
function disableBetting_only_Dev()
noEthSent
onlyDeveloper
{
contract_state=States.inactive;
}
function enableBetting_only_Dev()
noEthSent
onlyDeveloper
{
contract_state=States.active;
}
modifier onlyActive()
{
if (contract_state==States.inactive) throw;
_
}
//Change some settings within safety bounds
function changeSettings_only_Dev(uint newCasinoStatLimit, uint newMaxBetsBlock, uint256 newMinGamble, uint256 newMaxGamble, uint16 newMaxInvestor, uint256 newMinInvestment,uint256 newMaxInvestment, uint256 newLockPeriod, uint8 newBlockDelay, uint8 newBlockExpiration)
noEthSent
onlyDeveloper
{
// changes the statistical multiplier that guarantees the long run casino survival
if (newCasinoStatLimit<100) throw;
casinoStatisticalLimit=newCasinoStatLimit;
//Max number of bets per block to prevent miner cheating
maxBetsPerBlock=newMaxBetsBlock;
//MAX BET : limited by payroll/(casinoStatisticalLimit*35)
if (newMaxGamble<newMinGamble) throw;
else { maxGamble=newMaxGamble; }
//Min Bet
if (newMinGamble<0) throw;
else { minGamble=newMinGamble; }
//MAX NB of DAO members (can only increase (within bounds) or stay equal)
//this number of members can only increase after 25k spins on Rouleth
//refuse change of max number of members if less than 25k spins played
if (newMaxInvestor!=setting_maxInvestors && gambles.length<25000) throw;
if ( newMaxInvestor<setting_maxInvestors
|| newMaxInvestor>investors.length) throw;
else { setting_maxInvestors=newMaxInvestor;}
//computes the results of the vote of the VIP members, fees to apply to new members
computeResultVoteExtraInvestFeesRate();
if (newMaxInvestment<newMinInvestment) throw;
//MIN INVEST :
setting_minInvestment=newMinInvestment;
//MAX INVEST :
setting_maxInvestment=newMaxInvestment;
//Invest LOCK PERIOD
//1 year max
//can also serve as a failsafe to shutdown withdraws for a period
if (setting_lockPeriod>360 days) throw;
setting_lockPeriod=newLockPeriod;
//Delay before spin :
blockDelay=newBlockDelay;
if (newBlockExpiration<blockDelay+20) throw;
blockExpiration=newBlockExpiration;
updateMaxBet();
}
//**********************************************
// Nicknames FUNCTIONS //
//**********************************************
//User set nickname
mapping (address => string) nicknames;
function setNickname(string name)
noEthSent
{
if (bytes(name).length >= 2 && bytes(name).length <= 30)
nicknames[msg.sender] = name;
}
function getNickname(address _address) constant returns(string _name) {
_name = nicknames[_address];
}
//**********************************************
// BETTING FUNCTIONS //
//**********************************************
//***//basic betting without Mist or contract call
//activates when the player only sends eth to the contract
//without specifying any type of bet.
function ()
{
//defaut bet : bet on red
betOnColor(true,false);
}
//Admin function that
//recalculates max bet
//updated after each bet and change of bankroll
function updateMaxBet() private
{
//check that setting is still within safety bounds
if (payroll/(casinoStatisticalLimit*35) > maxGamble)
{
currentMaxGamble=maxGamble;
}
else
{
currentMaxGamble = payroll/(casinoStatisticalLimit*35);
}
}
//***//Guarantees that gamble is under max bet and above min.
// returns bet value
function checkBetValue() private returns(uint256 playerBetValue)
{
if (msg.value < minGamble) throw;
if (msg.value > currentMaxGamble) //if above max, send difference back
{
playerBetValue=currentMaxGamble;
}
else
{ playerBetValue=msg.value; }
return;
}
//check number of bets in block (to prevent miner cheating)
modifier checkNbBetsCurrentBlock()
{
if (gambles.length!=0 && block.number==gambles[gambles.length-1].blockNumber) nbBetsCurrentBlock+=1;
else nbBetsCurrentBlock=0;
if (nbBetsCurrentBlock>=maxBetsPerBlock) throw;
_
}
//Function record bet called by all others betting functions
function placeBet(BetTypes betType_, uint8 input_) private
{
// Before we record, we may have to spin the past bet if the croupier bot
// is down for some reason or if the player played again too quickly.
// This would fail though if the player tries too play to quickly (in consecutive block).
// gambles should be spaced by at least a block
// the croupier bot should spin within 2 blocks (~30 secs) after your bet.
// if the bet expires it is added to casino profit, otherwise it would be a way to cheat
if (playerStatus[msg.sender]!=Status.waitingForBet)
{
SpinTheWheel(msg.sender);
}
//Once this is done, we can record the new bet
playerStatus[msg.sender]=Status.waitingForSpin;
gambleIndex[msg.sender]=gambles.length;
totalGambles++;
//adapts wager to casino limits
uint256 betValue = checkBetValue();
gambles.push(Gamble(msg.sender, false, false, betType_, input_, betValue, block.number, 0, 37)); //37 indicates not spinned yet
//refund excess bet (at last step vs re-entry)
if (betValue<msg.value)
{
if (msg.sender.send(msg.value-betValue)==false) throw;
}
}
//***//bet on Number
function betOnNumber(uint8 numberChosen)
onlyActive
checkNbBetsCurrentBlock
{
//check that number chosen is valid and records bet
if (numberChosen>36) throw;
placeBet(BetTypes.number, numberChosen);
}
//***// function betOnColor
//bet type : color
//input : 0 for red
//input : 1 for black
function betOnColor(bool Red, bool Black)
onlyActive
checkNbBetsCurrentBlock
{
uint8 count;
uint8 input;
if (Red)
{
count+=1;
input=0;
}
if (Black)
{
count+=1;
input=1;
}
if (count!=1) throw;
placeBet(BetTypes.color, input);
}
//***// function betOnLow_High
//bet type : lowhigh
//input : 0 for low
//input : 1 for low
function betOnLowHigh(bool Low, bool High)
onlyActive
checkNbBetsCurrentBlock
{
uint8 count;
uint8 input;
if (Low)
{
count+=1;
input=0;
}
if (High)
{
count+=1;
input=1;
}
if (count!=1) throw;
placeBet(BetTypes.lowhigh, input);
}
//***// function betOnOddEven
//bet type : parity
//input : 0 for even
//input : 1 for odd
function betOnOddEven(bool Odd, bool Even)
onlyActive
checkNbBetsCurrentBlock
{
uint8 count;
uint8 input;
if (Even)
{
count+=1;
input=0;
}
if (Odd)
{
count+=1;
input=1;
}
if (count!=1) throw;
placeBet(BetTypes.parity, input);
}
//***// function betOnDozen
// //bet type : dozen
// //input : 0 for first dozen
// //input : 1 for second dozen
// //input : 2 for third dozen
function betOnDozen(bool First, bool Second, bool Third)
{
betOnColumnOrDozen(First,Second,Third, BetTypes.dozen);
}
// //***// function betOnColumn
// //bet type : column
// //input : 0 for first column
// //input : 1 for second column
// //input : 2 for third column
function betOnColumn(bool First, bool Second, bool Third)
{
betOnColumnOrDozen(First, Second, Third, BetTypes.column);
}
function betOnColumnOrDozen(bool First, bool Second, bool Third, BetTypes bet) private
onlyActive
checkNbBetsCurrentBlock
{
uint8 count;
uint8 input;
if (First)
{
count+=1;
input=0;
}
if (Second)
{
count+=1;
input=1;
}
if (Third)
{
count+=1;
input=2;
}
if (count!=1) throw;
placeBet(bet, input);
}
//**********************************************
// Spin The Wheel & Check Result FUNCTIONS//
//**********************************************
event Win(address player, uint8 result, uint value_won, bytes32 bHash, bytes32 sha3Player, uint gambleId);
event Loss(address player, uint8 result, uint value_loss, bytes32 bHash, bytes32 sha3Player, uint gambleId);
//***//function to spin callable
// no eth allowed
function spinTheWheel(address spin_for_player)
noEthSent
{
SpinTheWheel(spin_for_player);
}
function SpinTheWheel(address playerSpinned) private
{
if (playerSpinned==0)
{
playerSpinned=msg.sender; //if no index spins for the sender
}
//check that player has to spin
if (playerStatus[playerSpinned]!=Status.waitingForSpin) throw;
//redundent double check : check that gamble has not been spinned already
if (gambles[gambleIndex[playerSpinned]].spinned==true) throw;
//check that the player waited for the delay before spin
//and also that the bet is not expired
uint playerblock = gambles[gambleIndex[playerSpinned]].blockNumber;
//too early to spin
if (block.number<=playerblock+blockDelay) throw;
//too late, bet expired, player lost
else if (block.number>playerblock+blockExpiration) solveBet(playerSpinned, 255, false, 1, 0, 0) ;
//spin !
else
{
uint8 wheelResult;
//Spin the wheel,
bytes32 blockHash= block.blockhash(playerblock+blockDelay);
//security check that the Hash is not empty
if (blockHash==0) throw;
// generate the hash for RNG from the blockHash and the player's address
bytes32 shaPlayer = sha3(playerSpinned, blockHash);
// get the final wheel result
wheelResult = uint8(uint256(shaPlayer)%37);
//check result against bet and pay if win
checkBetResult(wheelResult, playerSpinned, blockHash, shaPlayer);
}
}
//CHECK BETS FUNCTIONS private
function checkBetResult(uint8 result, address player, bytes32 blockHash, bytes32 shaPlayer) private
{
BetTypes betType=gambles[gambleIndex[player]].betType;
//bet on Number
if (betType==BetTypes.number) checkBetNumber(result, player, blockHash, shaPlayer);
else if (betType==BetTypes.parity) checkBetParity(result, player, blockHash, shaPlayer);
else if (betType==BetTypes.color) checkBetColor(result, player, blockHash, shaPlayer);
else if (betType==BetTypes.lowhigh) checkBetLowhigh(result, player, blockHash, shaPlayer);
else if (betType==BetTypes.dozen) checkBetDozen(result, player, blockHash, shaPlayer);
else if (betType==BetTypes.column) checkBetColumn(result, player, blockHash, shaPlayer);
updateMaxBet(); //at the end, update the Max possible bet
}
// function solve Bet once result is determined : sends to winner, adds loss to profit
function solveBet(address player, uint8 result, bool win, uint8 multiplier, bytes32 blockHash, bytes32 shaPlayer) private
{
//Update status and record spinned
playerStatus[player]=Status.waitingForBet;
gambles[gambleIndex[player]].wheelResult=result;
gambles[gambleIndex[player]].spinned=true;
gambles[gambleIndex[player]].blockSpinned=block.number;
uint bet_v = gambles[gambleIndex[player]].wager;
if (win)
{
gambles[gambleIndex[player]].win=true;
uint win_v = (multiplier-1)*bet_v;
lossSinceChange+=win_v;
Win(player, result, win_v, blockHash, shaPlayer, gambleIndex[player]);
//send win!
//safe send vs potential callstack overflowed spins
if (player.send(win_v+bet_v)==false) throw;
}
else
{
Loss(player, result, bet_v-1, blockHash, shaPlayer, gambleIndex[player]);
profitSinceChange+=bet_v-1;
//send 1 wei to confirm spin if loss
if (player.send(1)==false) throw;
}
}
// checkbeton number(input)
// bet type : number
// input : chosen number
function checkBetNumber(uint8 result, address player, bytes32 blockHash, bytes32 shaPlayer) private
{
bool win;
//win
if (result==gambles[gambleIndex[player]].input)
{
win=true;
}
solveBet(player, result,win,36, blockHash, shaPlayer);
}
// checkbet on oddeven
// bet type : parity
// input : 0 for even, 1 for odd
function checkBetParity(uint8 result, address player, bytes32 blockHash, bytes32 shaPlayer) private
{
bool win;
//win
if (result%2==gambles[gambleIndex[player]].input && result!=0)
{
win=true;
}
solveBet(player,result,win,2, blockHash, shaPlayer);
}
// checkbet on lowhigh
// bet type : lowhigh
// input : 0 low, 1 high
function checkBetLowhigh(uint8 result, address player, bytes32 blockHash, bytes32 shaPlayer) private
{
bool win;
//win
if (result!=0 && ( (result<19 && gambles[gambleIndex[player]].input==0)
|| (result>18 && gambles[gambleIndex[player]].input==1)
) )
{
win=true;
}
solveBet(player,result,win,2, blockHash, shaPlayer);
}
// checkbet on color
// bet type : color
// input : 0 red, 1 black
uint[18] red_list=[1,3,5,7,9,12,14,16,18,19,21,23,25,27,30,32,34,36];
function checkBetColor(uint8 result, address player, bytes32 blockHash, bytes32 shaPlayer) private
{
bool red;
//check if red
for (uint8 k; k<18; k++)
{
if (red_list[k]==result)
{
red=true;
break;
}
}
bool win;
//win
if ( result!=0
&& ( (gambles[gambleIndex[player]].input==0 && red)
|| ( gambles[gambleIndex[player]].input==1 && !red) ) )
{
win=true;
}
solveBet(player,result,win,2, blockHash, shaPlayer);
}
// checkbet on dozen
// bet type : dozen
// input : 0 first, 1 second, 2 third
function checkBetDozen(uint8 result, address player, bytes32 blockHash, bytes32 shaPlayer) private
{
bool win;
//win on first dozen
if ( result!=0 &&
( (result<13 && gambles[gambleIndex[player]].input==0)
||
(result>12 && result<25 && gambles[gambleIndex[player]].input==1)
||
(result>24 && gambles[gambleIndex[player]].input==2) ) )
{
win=true;
}
solveBet(player,result,win,3, blockHash, shaPlayer);
}
// checkbet on column
// bet type : column
// input : 0 first, 1 second, 2 third
function checkBetColumn(uint8 result, address player, bytes32 blockHash, bytes32 shaPlayer) private
{
bool win;
//win
if ( result!=0
&& ( (gambles[gambleIndex[player]].input==0 && result%3==1)
|| ( gambles[gambleIndex[player]].input==1 && result%3==2)
|| ( gambles[gambleIndex[player]].input==2 && result%3==0) ) )
{
win=true;
}
solveBet(player,result,win,3, blockHash, shaPlayer);
}
//D.A.O. FUNCTIONS
//total casino payroll
uint256 payroll;
//Profit Loss since last investor change
uint256 profitSinceChange;
uint256 lossSinceChange;
//DAO members struct array (hard capped to 777 members (77 VIP + 700 extra members) )
struct Investor
{
address investor;
uint256 time;
}
Investor[777] private investors; //array of 777 elements (max Rouleth's members nb.)
uint16 setting_maxInvestors = 77; //Initially restricted to 77 VIP Members
//Balances of the DAO members
mapping (address=>uint256) balance;
//lockPeriod
//minimum membership time
uint256 setting_lockPeriod=30 days ;
uint256 setting_minInvestment=100 ether; //min amount to send when using "invest()"
uint256 setting_maxInvestment=200 ether; //max amount to send when using "invest()"
event newInvest(address player, uint invest_v, uint net_invest_v);
//Become a DAO member.
function invest()
{
// update balances before altering the shares
updateBalances();
uint256 netInvest;
uint excess;
// reset the open position counter to values out of bounds
// =999 if full
uint16 openPosition=999;
bool alreadyInvestor;
// loop over array to find if already member,
// and record a potential openPosition
for (uint16 k = 0; k<setting_maxInvestors; k++)
{
// captures an index of an open position
if (investors[k].investor==0) openPosition=k;
// captures if already a member
else if (investors[k].investor==msg.sender)
{
alreadyInvestor=true;
break;
}
}
//new Member
if (!alreadyInvestor)
{
// check that more than min is sent (variable setting)
if (msg.value<setting_minInvestment) throw;
// check that less than max is sent (variable setting)
// otherwise refund
if (msg.value>setting_maxInvestment)
{
excess=msg.value-setting_maxInvestment;
netInvest=setting_maxInvestment;
}
else
{
netInvest=msg.value;
}
//members can't become a VIP member after the initial period
if (setting_maxInvestors >77 && openPosition<77) throw;
//case : array not full, record new member
else if (openPosition!=999) investors[openPosition]=Investor(msg.sender, now);
//case : array full
else
{
throw;
}
}
//already a member
else
{
netInvest=msg.value;
//is already above the max balance allowed or is sending
// too much refuse additional invest
if (balance[msg.sender]+msg.value>setting_maxInvestment)
{
throw;
}
// this additionnal amount should be of at least 1/5 of "setting_minInvestment" (vs spam)
if (msg.value<setting_minInvestment/5) throw;
}
// add to balance of member and to bankroll
// 10% of initial 77 VIP members investment is allocated to
// game developement provider chosen by Rouleth DAO
// 90% to bankroll
//share that will be allocated to game dev
uint256 developmentAllocation;
developmentAllocation=10*netInvest/100;
netInvest-=developmentAllocation;
//send game development allocation to Rouleth DAO or tech provider
if (developer.send(developmentAllocation)==false) throw;
// Apply extra entry fee once casino has been opened to extra members
// that fee will be shared between the VIP members and represents the increment of
// market value of their shares in Rouleth to outsiders
// warning if a VIP adds to its initial invest after the casino has been opened to
// extra members he will pay have to pay this fee.
if (setting_maxInvestors>77)
{
// % of extra member's investment that rewards VIP funders
// Starts at 100%
// is set by a vote and computed when settings are changed
// to allow more investors
uint256 entryExtraCost=voted_extraInvestFeesRate*netInvest/100;
// add to VIP profit (to be shared by later call by dev.)
profitVIP += entryExtraCost;
netInvest-=entryExtraCost;
}
newInvest(msg.sender, msg.value, netInvest);//event log
balance[msg.sender]+=netInvest; //add to balance
payroll+=netInvest; //add to bankroll
updateMaxBet();
//refund potential excess
if (excess>0)
{
if (msg.sender.send(excess)==false) throw;
}
}
//Allows to transfer your DAO account to another address
//target should not be currently a DAO member of rouleth
//enter twice the address to make sure you make no mistake.
//this can't be reversed if you don't own the target account
function transferInvestorAccount(address newInvestorAccountOwner, address newInvestorAccountOwner_confirm)
noEthSent
{
if (newInvestorAccountOwner!=newInvestorAccountOwner_confirm) throw;
if (newInvestorAccountOwner==0) throw;
//retrieve investor ID
uint16 investorID=999;
for (uint16 k = 0; k<setting_maxInvestors; k++)
{
//new address cant be of a current investor
if (investors[k].investor==newInvestorAccountOwner) throw;
//retrieve investor id
if (investors[k].investor==msg.sender)
{
investorID=k;
}
}
if (investorID==999) throw; //stop if not a member
else
//accept and execute change of address
//votes on entryFeesRate are not transfered
//new address should vote again
{
balance[newInvestorAccountOwner]=balance[msg.sender];
balance[msg.sender]=0;
investors[investorID].investor=newInvestorAccountOwner;
}
}
//***// Withdraw function (only after lockPeriod)
// input : amount to withdraw in Wei (leave empty for full withdraw)
// if your withdraw brings your balance under the min required,
// your balance is fully withdrawn
event withdraw(address player, uint withdraw_v);
function withdrawInvestment(uint256 amountToWithdrawInWei)
noEthSent
{
//vs spam withdraw min 1/10 of min
if (amountToWithdrawInWei!=0 && amountToWithdrawInWei<setting_minInvestment/10) throw;
//before withdraw, update balances with the Profit and Loss sinceChange
updateBalances();
//check that amount requested is authorized
if (amountToWithdrawInWei>balance[msg.sender]) throw;
//retrieve member ID
uint16 investorID=999;
for (uint16 k = 0; k<setting_maxInvestors; k++)
{
if (investors[k].investor==msg.sender)
{
investorID=k;
break;
}
}
if (investorID==999) throw; //stop if not a member
//check if investment lock period is over
if (investors[investorID].time+setting_lockPeriod>now) throw;
//if balance left after withdraw is still above min accept partial withdraw
if (balance[msg.sender]-amountToWithdrawInWei>=setting_minInvestment && amountToWithdrawInWei!=0)
{
balance[msg.sender]-=amountToWithdrawInWei;
payroll-=amountToWithdrawInWei;
//send amount to investor (with security if transaction fails)
if (msg.sender.send(amountToWithdrawInWei)==false) throw;
withdraw(msg.sender, amountToWithdrawInWei);
}
else
//if amountToWithdraw=0 : user wants full withdraw
//if balance after withdraw is < min invest, withdraw all and delete member
{
//send amount to member (with security if transaction fails)
uint256 fullAmount=balance[msg.sender];
payroll-=fullAmount;
balance[msg.sender]=0;
//delete member
delete investors[investorID];
if (msg.sender.send(fullAmount)==false) throw;
withdraw(msg.sender, fullAmount);
}
updateMaxBet();
}
//***// updates balances with Profit Losses when there is a withdraw/deposit
// can be called by dev for accounting when there are no more changes
function manualUpdateBalances_only_Dev()
noEthSent
onlyDeveloper
{
updateBalances();
}
function updateBalances() private
{
//split Profits
uint256 profitToSplit;
uint256 lossToSplit;
if (profitSinceChange==0 && lossSinceChange==0)
{ return; }
else
{
// Case : Global profit (more win than losses)
// 20% fees for game development on global profit (if profit>loss)
if (profitSinceChange>lossSinceChange)
{
profitToSplit=profitSinceChange-lossSinceChange;
uint256 developerFees=profitToSplit*20/100;
profitToSplit-=developerFees;
if (developer.send(developerFees)==false) throw;
}
else
{
lossToSplit=lossSinceChange-profitSinceChange;
}
//share the loss and profits between all DAO members
//(proportionnaly. to each one's balance)
uint totalShared;
for (uint16 k=0; k<setting_maxInvestors; k++)
{
address inv=investors[k].investor;
if (inv==0) continue;
else
{
if (profitToSplit!=0)
{
uint profitShare=(profitToSplit*balance[inv])/payroll;
balance[inv]+=profitShare;
totalShared+=profitShare;
}
else if (lossToSplit!=0)
{
uint lossShare=(lossToSplit*balance[inv])/payroll;
balance[inv]-=lossShare;
totalShared+=lossShare;
}
}
}
// update bankroll
// and handle potential very small left overs from integer div.
if (profitToSplit !=0)
{
payroll+=profitToSplit;
balance[developer]+=profitToSplit-totalShared;
}
else if (lossToSplit !=0)
{
payroll-=lossToSplit;
balance[developer]-=lossToSplit-totalShared;
}
profitSinceChange=0; //reset Profit;
lossSinceChange=0; //reset Loss ;
}
}
//VIP Voting on Extra Invest Fees Rate
//mapping records 100 - vote
mapping (address=>uint) hundredminus_extraInvestFeesRate;
// max fee is 99%
// a fee of 100% indicates that the VIP has never voted.
function voteOnNewEntryFees_only_VIP(uint8 extraInvestFeesRate_0_to_99)
noEthSent
{
if (extraInvestFeesRate_0_to_99<1 || extraInvestFeesRate_0_to_99>99) throw;
hundredminus_extraInvestFeesRate[msg.sender]=100-extraInvestFeesRate_0_to_99;
}
uint256 payrollVIP;
uint256 voted_extraInvestFeesRate;
function computeResultVoteExtraInvestFeesRate() private
{
payrollVIP=0;
voted_extraInvestFeesRate=0;
//compute total payroll of the VIPs
//compute vote results among VIPs
for (uint8 k=0; k<77; k++)
{
if (investors[k].investor==0) continue;
else
{
//don't count vote if the VIP never voted
if (hundredminus_extraInvestFeesRate[investors[k].investor]==0) continue;
else
{
payrollVIP+=balance[investors[k].investor];
voted_extraInvestFeesRate+=hundredminus_extraInvestFeesRate[investors[k].investor]*balance[investors[k].investor];
}
}
}
//compute final result
if (payrollVIP!=0)
{
voted_extraInvestFeesRate=100-voted_extraInvestFeesRate/payrollVIP;
}
}
//Split the profits of the VIP members on extra members' contribution
uint profitVIP;
function splitProfitVIP_only_Dev()
noEthSent
onlyDeveloper
{
payrollVIP=0;
//compute total payroll of the VIPs
for (uint8 k=0; k<77; k++)
{
if (investors[k].investor==0) continue;
else
{
payrollVIP+=balance[investors[k].investor];
}
}
//split the profits of the VIP members on extra member's contribution
uint totalSplit;
for (uint8 i=0; i<77; i++)
{
if (investors[i].investor==0) continue;
else
{
uint toSplit=balance[investors[i].investor]*profitVIP/payrollVIP;
balance[investors[i].investor]+=toSplit;
totalSplit+=toSplit;
}
}
//take care of Integer Div remainders, and add to bankroll
balance[developer]+=profitVIP-totalSplit;
payroll+=profitVIP;
//reset var profitVIP
profitVIP=0;
}
//INFORMATION FUNCTIONS
function checkProfitLossSinceInvestorChange() constant returns(uint profit_since_update_balances, uint loss_since_update_balances, uint profit_VIP_since_update_balances)
{
profit_since_update_balances=profitSinceChange;
loss_since_update_balances=lossSinceChange;
profit_VIP_since_update_balances=profitVIP;
return;
}
function checkInvestorBalance(address investor) constant returns(uint balanceInWei)
{
balanceInWei=balance[investor];
return;
}
function getInvestorList(uint index) constant returns(address investor, uint endLockPeriod)
{
investor=investors[index].investor;
endLockPeriod=investors[index].time+setting_lockPeriod;
return;
}
function investmentEntryInfos() constant returns(uint current_max_nb_of_investors, uint investLockPeriod, uint voted_Fees_Rate_on_extra_investments)
{