Upload 491 files
Browse filesThis view is limited to 50 files because it contains too many changes. See raw diff
- output.csv +779 -0
- smart_contract_dataset/block number dependency/0.sol +169 -0
- smart_contract_dataset/block number dependency/1017.sol +625 -0
- smart_contract_dataset/block number dependency/103.sol +247 -0
- smart_contract_dataset/block number dependency/1034.sol +258 -0
- smart_contract_dataset/block number dependency/1044.sol +255 -0
- smart_contract_dataset/block number dependency/1052.sol +625 -0
- smart_contract_dataset/block number dependency/1056.sol +619 -0
- smart_contract_dataset/block number dependency/1096.sol +621 -0
- smart_contract_dataset/block number dependency/1101.sol +626 -0
- smart_contract_dataset/block number dependency/112.sol +253 -0
- smart_contract_dataset/block number dependency/1121.sol +222 -0
- smart_contract_dataset/block number dependency/1149.sol +403 -0
- smart_contract_dataset/block number dependency/1165.sol +222 -0
- smart_contract_dataset/block number dependency/129.sol +222 -0
- smart_contract_dataset/block number dependency/1297.sol +136 -0
- smart_contract_dataset/block number dependency/1345.sol +458 -0
- smart_contract_dataset/block number dependency/135.sol +1130 -0
- smart_contract_dataset/block number dependency/136.sol +1130 -0
- smart_contract_dataset/block number dependency/137.sol +1130 -0
- smart_contract_dataset/block number dependency/138.sol +222 -0
- smart_contract_dataset/block number dependency/1406.sol +247 -0
- smart_contract_dataset/block number dependency/1472.sol +472 -0
- smart_contract_dataset/block number dependency/1482.sol +222 -0
- smart_contract_dataset/block number dependency/1546.sol +472 -0
- smart_contract_dataset/block number dependency/1567.sol +395 -0
- smart_contract_dataset/block number dependency/164.sol +167 -0
- smart_contract_dataset/block number dependency/1673.sol +466 -0
- smart_contract_dataset/block number dependency/1698.sol +247 -0
- smart_contract_dataset/block number dependency/1714.sol +403 -0
- smart_contract_dataset/block number dependency/173.sol +247 -0
- smart_contract_dataset/block number dependency/1761.sol +490 -0
- smart_contract_dataset/block number dependency/1791.sol +222 -0
- smart_contract_dataset/block number dependency/1986.sol +1250 -0
- smart_contract_dataset/block number dependency/2003.sol +383 -0
- smart_contract_dataset/block number dependency/2110.sol +395 -0
- smart_contract_dataset/block number dependency/215.sol +1133 -0
- smart_contract_dataset/block number dependency/216.sol +1133 -0
- smart_contract_dataset/block number dependency/217.sol +1133 -0
- smart_contract_dataset/block number dependency/220.sol +222 -0
- smart_contract_dataset/block number dependency/2295.sol +269 -0
- smart_contract_dataset/block number dependency/2296.sol +247 -0
- smart_contract_dataset/block number dependency/238.sol +183 -0
- smart_contract_dataset/block number dependency/246.sol +1532 -0
- smart_contract_dataset/block number dependency/2584.sol +402 -0
- smart_contract_dataset/block number dependency/2587.sol +402 -0
- smart_contract_dataset/block number dependency/2589.sol +398 -0
- smart_contract_dataset/block number dependency/2593.sol +397 -0
- smart_contract_dataset/block number dependency/2619.sol +250 -0
- smart_contract_dataset/block number dependency/2632.sol +247 -0
output.csv
ADDED
|
@@ -0,0 +1,779 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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_type
|
| 2 |
+
0,15,NXX,1,timestamp dependency
|
| 3 |
+
1,124,TTPresale,1,timestamp dependency
|
| 4 |
+
2,176,IcoRocketFuel,1,timestamp dependency
|
| 5 |
+
3,188,Duang8,1,timestamp dependency
|
| 6 |
+
4,237,braggerContract,1,timestamp dependency
|
| 7 |
+
5,292,CrowdsaleExt,1,timestamp dependency
|
| 8 |
+
6,295,CrowdsaleExt,1,timestamp dependency
|
| 9 |
+
7,347,CrowdsaleWPTByRounds,1,timestamp dependency
|
| 10 |
+
8,361,FreezableToken,1,timestamp dependency
|
| 11 |
+
9,361,FreezableMintableToken,1,timestamp dependency
|
| 12 |
+
10,399,Saturn,1,timestamp dependency
|
| 13 |
+
11,419,SnooKarma,1,timestamp dependency
|
| 14 |
+
12,428,F3DPLUS,1,timestamp dependency
|
| 15 |
+
13,496,TokenSale,1,timestamp dependency
|
| 16 |
+
14,518,SCardLong,1,timestamp dependency
|
| 17 |
+
15,578,ERC20Like,1,timestamp dependency
|
| 18 |
+
16,613,SnooKarma,1,timestamp dependency
|
| 19 |
+
17,649,DVPlock,1,timestamp dependency
|
| 20 |
+
18,665,TwoYearDreamTokensVesting,1,timestamp dependency
|
| 21 |
+
19,738,Token,1,timestamp dependency
|
| 22 |
+
20,739,Crowdsale,1,timestamp dependency
|
| 23 |
+
21,837,Controller,1,timestamp dependency
|
| 24 |
+
22,883,RakuRakuEth,1,timestamp dependency
|
| 25 |
+
23,1051,LimitCollectCoin,1,timestamp dependency
|
| 26 |
+
24,1182,BitSongCrowdsale,1,timestamp dependency
|
| 27 |
+
25,1256,Betting,1,timestamp dependency
|
| 28 |
+
26,1318,WorkIt,1,timestamp dependency
|
| 29 |
+
27,1667,JobsBounty,1,timestamp dependency
|
| 30 |
+
28,1671,TokenSale,1,timestamp dependency
|
| 31 |
+
29,1704,ExternalView,1,timestamp dependency
|
| 32 |
+
30,1704,WinnerWinner,1,timestamp dependency
|
| 33 |
+
31,1826,JobsBounty,1,timestamp dependency
|
| 34 |
+
32,2315,ETHERlemon,1,timestamp dependency
|
| 35 |
+
33,2389,ERC20Like,1,timestamp dependency
|
| 36 |
+
34,2391,FsTKColdWallet,1,timestamp dependency
|
| 37 |
+
35,2641,CrowdsaleExt,1,timestamp dependency
|
| 38 |
+
36,2641,UpgradeableToken,1,timestamp dependency
|
| 39 |
+
37,2646,CrowdsaleExt,1,timestamp dependency
|
| 40 |
+
38,2688,F3d,1,timestamp dependency
|
| 41 |
+
39,2711,ExhibationLinkingCoin,1,timestamp dependency
|
| 42 |
+
40,2736,DisbursementHandler,1,timestamp dependency
|
| 43 |
+
41,2736,TimedStateMachine,1,timestamp dependency
|
| 44 |
+
42,2797,TimedCrowdsale,1,timestamp dependency
|
| 45 |
+
43,2814,TokenSale,1,timestamp dependency
|
| 46 |
+
44,2861,TokenVesting,1,timestamp dependency
|
| 47 |
+
45,2948,BGAudit,1,timestamp dependency
|
| 48 |
+
46,3100,CardsRaffle,1,timestamp dependency
|
| 49 |
+
47,3125,NekoToken,1,timestamp dependency
|
| 50 |
+
48,3185,StarmidFreezeTokens,1,timestamp dependency
|
| 51 |
+
49,3240,TokenTimelock,1,timestamp dependency
|
| 52 |
+
50,3240,TokenVesting,1,timestamp dependency
|
| 53 |
+
51,3271,hodlEthereum,1,timestamp dependency
|
| 54 |
+
52,6053,TimedCrowdsale,1,timestamp dependency
|
| 55 |
+
53,6054,TimedCrowdsale,1,timestamp dependency
|
| 56 |
+
54,6059,TimedCrowdsale,1,timestamp dependency
|
| 57 |
+
55,6065,TokenTimelock,1,timestamp dependency
|
| 58 |
+
56,6065,TokenVesting,1,timestamp dependency
|
| 59 |
+
57,6149,JadeCoin,1,timestamp dependency
|
| 60 |
+
58,6272,JadeCoin,1,timestamp dependency
|
| 61 |
+
59,6297,TimedCrowdsale,1,timestamp dependency
|
| 62 |
+
60,6297,JcnxxxCrowdsale,1,timestamp dependency
|
| 63 |
+
61,6322,TokenTimelock,1,timestamp dependency
|
| 64 |
+
62,6348,DutchAuction,1,timestamp dependency
|
| 65 |
+
63,6369,LemoCoin,1,timestamp dependency
|
| 66 |
+
64,6370,AMTTimelockedToken,1,timestamp dependency
|
| 67 |
+
65,6396,SparksterToken,1,timestamp dependency
|
| 68 |
+
66,6403,CrowdsaleExt,1,timestamp dependency
|
| 69 |
+
67,6404,CrowdsaleExt,1,timestamp dependency
|
| 70 |
+
68,6472,SparksterToken,1,timestamp dependency
|
| 71 |
+
69,6534,XTVToken,1,timestamp dependency
|
| 72 |
+
70,6578,CryptualProjectToken,1,timestamp dependency
|
| 73 |
+
71,6586,TokenTimelockController,1,timestamp dependency
|
| 74 |
+
72,6592,SparksterToken,1,timestamp dependency
|
| 75 |
+
73,6596,FreezableToken,1,timestamp dependency
|
| 76 |
+
74,6604,TimedCrowdsale,1,timestamp dependency
|
| 77 |
+
75,6604,VreoTokenSale,1,timestamp dependency
|
| 78 |
+
76,6663,TokenTimelockController,1,timestamp dependency
|
| 79 |
+
77,6747,CrowdsaleBase,1,timestamp dependency
|
| 80 |
+
78,6753,CrowdsaleBase,1,timestamp dependency
|
| 81 |
+
79,6798,CrowdsaleBase,1,timestamp dependency
|
| 82 |
+
80,6806,CrowdsaleBase,1,timestamp dependency
|
| 83 |
+
81,6811,XTVToken,1,timestamp dependency
|
| 84 |
+
82,6822,Lockable,1,timestamp dependency
|
| 85 |
+
83,6833,MOEToken,1,timestamp dependency
|
| 86 |
+
84,6844,XTVToken,1,timestamp dependency
|
| 87 |
+
85,6846,FoMo3Dlong,1,timestamp dependency
|
| 88 |
+
86,6915,TimedCrowdsale,1,timestamp dependency
|
| 89 |
+
87,6933,AnythingAppTokenPreSale,1,timestamp dependency
|
| 90 |
+
88,7012,TokenVesting,1,timestamp dependency
|
| 91 |
+
89,7044,BaseICO,1,timestamp dependency
|
| 92 |
+
90,7044,IonChainICO,1,timestamp dependency
|
| 93 |
+
91,7046,Crowdsale,1,timestamp dependency
|
| 94 |
+
92,7046,TokenVesting,1,timestamp dependency
|
| 95 |
+
93,7046,GambioVesting,1,timestamp dependency
|
| 96 |
+
94,7046,GambioCrowdsale,1,timestamp dependency
|
| 97 |
+
95,7086,TokenTimelockController,1,timestamp dependency
|
| 98 |
+
96,7134,FENIX,1,timestamp dependency
|
| 99 |
+
97,7334,TimedCrowdsale,1,timestamp dependency
|
| 100 |
+
98,7338,EtheremonRankBattle,1,timestamp dependency
|
| 101 |
+
99,7419,SponsoredItemGooRaffle,1,timestamp dependency
|
| 102 |
+
100,7440,FreezableToken,1,timestamp dependency
|
| 103 |
+
101,7441,Crowdsale,1,timestamp dependency
|
| 104 |
+
102,7441,MainCrowdsale,1,timestamp dependency
|
| 105 |
+
103,7441,TemplateCrowdsale,1,timestamp dependency
|
| 106 |
+
104,7464,TimedCrowdsale,1,timestamp dependency
|
| 107 |
+
105,7464,GrapevineCrowdsale,1,timestamp dependency
|
| 108 |
+
106,7466,TokenTimelockController,1,timestamp dependency
|
| 109 |
+
107,7511,R1Exchange,1,timestamp dependency
|
| 110 |
+
108,7512,CrowdsaleExt,1,timestamp dependency
|
| 111 |
+
109,7515,CrowdsaleExt,1,timestamp dependency
|
| 112 |
+
110,7519,BSPMintable,1,timestamp dependency
|
| 113 |
+
111,7521,BSPVesting,1,timestamp dependency
|
| 114 |
+
112,7570,GStarCrowdsale,1,timestamp dependency
|
| 115 |
+
113,7627,NanoLoanEngine,1,timestamp dependency
|
| 116 |
+
114,7724,CTCLock,1,timestamp dependency
|
| 117 |
+
115,7736,CTCVesting,1,timestamp dependency
|
| 118 |
+
116,7753,BVesting,1,timestamp dependency
|
| 119 |
+
117,7775,TokenVesting,1,timestamp dependency
|
| 120 |
+
118,7803,TimedCrowdsale,1,timestamp dependency
|
| 121 |
+
119,7803,CareerChainPrivateSale,1,timestamp dependency
|
| 122 |
+
120,8025,ESSENTIA_PE,1,timestamp dependency
|
| 123 |
+
121,8099,tipbot,1,timestamp dependency
|
| 124 |
+
122,8233,CrowdsaleExt,1,timestamp dependency
|
| 125 |
+
123,8254,StakeDice,1,timestamp dependency
|
| 126 |
+
124,8305,GigToken,1,timestamp dependency
|
| 127 |
+
125,8305,CrowdSale,1,timestamp dependency
|
| 128 |
+
126,8306,CrowdSale,1,timestamp dependency
|
| 129 |
+
127,8314,Vault,1,timestamp dependency
|
| 130 |
+
128,8320,ESSENTIA_PE,1,timestamp dependency
|
| 131 |
+
129,8436,ESSENTIA_PE,1,timestamp dependency
|
| 132 |
+
130,8470,StakeDice,1,timestamp dependency
|
| 133 |
+
131,8505,TokenVesting,1,timestamp dependency
|
| 134 |
+
132,8555,FreezableToken,1,timestamp dependency
|
| 135 |
+
133,8555,FreezableMintableToken,1,timestamp dependency
|
| 136 |
+
134,8555,MainToken,1,timestamp dependency
|
| 137 |
+
135,8556,Crowdsale,1,timestamp dependency
|
| 138 |
+
136,8556,FreezableToken,1,timestamp dependency
|
| 139 |
+
137,8556,TemplateCrowdsale,1,timestamp dependency
|
| 140 |
+
138,8596,CrowdsaleExt,1,timestamp dependency
|
| 141 |
+
139,8606,YunMint,1,timestamp dependency
|
| 142 |
+
140,8612,TokenVesting,1,timestamp dependency
|
| 143 |
+
141,8614,CoinSparrow,1,timestamp dependency
|
| 144 |
+
142,8615,TokenVesting,1,timestamp dependency
|
| 145 |
+
143,8636,TokenVesting,1,timestamp dependency
|
| 146 |
+
144,8636,VariableRateTokenVesting,1,timestamp dependency
|
| 147 |
+
145,8647,StreamityEscrow,1,timestamp dependency
|
| 148 |
+
146,8750,LemurTokenSale,1,timestamp dependency
|
| 149 |
+
147,8766,ESSENTIA_PE,1,timestamp dependency
|
| 150 |
+
148,8826,TokenOffering,1,timestamp dependency
|
| 151 |
+
149,8851,mameCoin,1,timestamp dependency
|
| 152 |
+
150,8926,DreamTeamToken,1,timestamp dependency
|
| 153 |
+
151,8939,StreamityEscrow,1,timestamp dependency
|
| 154 |
+
152,9208,Crowdsale,1,timestamp dependency
|
| 155 |
+
153,9210,Crowdsale,1,timestamp dependency
|
| 156 |
+
154,9221,EtherBet,1,timestamp dependency
|
| 157 |
+
155,9224,TokenTimelock,1,timestamp dependency
|
| 158 |
+
156,9230,Tokenlock,1,timestamp dependency
|
| 159 |
+
157,9242,EthTeamContract,1,timestamp dependency
|
| 160 |
+
158,9300,TimedCrowdsale,1,timestamp dependency
|
| 161 |
+
159,9300,EoptCrowdsale,1,timestamp dependency
|
| 162 |
+
160,9309,CrowdsaleExt,1,timestamp dependency
|
| 163 |
+
161,9310,CrowdsaleExt,1,timestamp dependency
|
| 164 |
+
162,9322,Cryphos,1,timestamp dependency
|
| 165 |
+
163,9329,FreezableToken,1,timestamp dependency
|
| 166 |
+
164,9333,CrowdsaleExt,1,timestamp dependency
|
| 167 |
+
165,9334,CrowdsaleExt,1,timestamp dependency
|
| 168 |
+
166,9358,SecurityController,1,timestamp dependency
|
| 169 |
+
167,9359,SecurityController,1,timestamp dependency
|
| 170 |
+
168,9378,PGOMonthlyPresaleVault,1,timestamp dependency
|
| 171 |
+
169,9379,PGOVault,1,timestamp dependency
|
| 172 |
+
170,9379,PGOMonthlyInternalVault,1,timestamp dependency
|
| 173 |
+
171,9379,PGOMonthlyPresaleVault,1,timestamp dependency
|
| 174 |
+
172,9379,GotCrowdSale,1,timestamp dependency
|
| 175 |
+
173,9474,WaltonTokenLocker,1,timestamp dependency
|
| 176 |
+
174,9476,WaltonTokenLocker,1,timestamp dependency
|
| 177 |
+
175,9499,WaltonTokenLocker,1,timestamp dependency
|
| 178 |
+
176,9500,WaltonTokenLocker,1,timestamp dependency
|
| 179 |
+
177,9502,FreezableToken,1,timestamp dependency
|
| 180 |
+
178,9505,WaltonTokenLocker,1,timestamp dependency
|
| 181 |
+
179,9521,WaltonTokenLocker,1,timestamp dependency
|
| 182 |
+
180,9531,CryptualProjectToken,1,timestamp dependency
|
| 183 |
+
181,9560,dappVolumeAd,1,timestamp dependency
|
| 184 |
+
182,9654,SimpleBet,1,timestamp dependency
|
| 185 |
+
183,9759,FreezableToken,1,timestamp dependency
|
| 186 |
+
184,9779,CrowdsaleExt,1,timestamp dependency
|
| 187 |
+
185,9780,CrowdsaleExt,1,timestamp dependency
|
| 188 |
+
186,9802,CrowdsaleExt,1,timestamp dependency
|
| 189 |
+
187,9803,CrowdsaleExt,1,timestamp dependency
|
| 190 |
+
188,9805,CrowdsaleExt,1,timestamp dependency
|
| 191 |
+
189,9806,CrowdsaleExt,1,timestamp dependency
|
| 192 |
+
190,9820,CrowdsaleRC,1,timestamp dependency
|
| 193 |
+
191,9830,SpaceWar,1,timestamp dependency
|
| 194 |
+
192,9843,Frozenable,1,timestamp dependency
|
| 195 |
+
193,9843,Releaseable,1,timestamp dependency
|
| 196 |
+
194,9850,PLCRVoting,1,timestamp dependency
|
| 197 |
+
195,9850,Parameterizer,1,timestamp dependency
|
| 198 |
+
196,9851,PLCRVoting,1,timestamp dependency
|
| 199 |
+
197,9851,Parameterizer,1,timestamp dependency
|
| 200 |
+
198,9858,CrowdsaleExt,1,timestamp dependency
|
| 201 |
+
199,9859,CrowdsaleExt,1,timestamp dependency
|
| 202 |
+
200,9889,SecurityController,1,timestamp dependency
|
| 203 |
+
201,9890,CrowdsaleExt,1,timestamp dependency
|
| 204 |
+
202,9892,CrowdsaleExt,1,timestamp dependency
|
| 205 |
+
203,9918,GENEOSSale,1,timestamp dependency
|
| 206 |
+
204,9978,EthTeamContract,1,timestamp dependency
|
| 207 |
+
205,9987,DQCoin,1,timestamp dependency
|
| 208 |
+
206,9994,BaseGameLogic,1,timestamp dependency
|
| 209 |
+
207,9998,EthTeamContract,1,timestamp dependency
|
| 210 |
+
208,10022,CrowdsaleExt,1,timestamp dependency
|
| 211 |
+
209,10023,CrowdsaleExt,1,timestamp dependency
|
| 212 |
+
210,10024,CrowdsaleExt,1,timestamp dependency
|
| 213 |
+
211,10025,CrowdsaleExt,1,timestamp dependency
|
| 214 |
+
212,10129,CrowdsaleBase,1,timestamp dependency
|
| 215 |
+
213,10129,KYCPresale,1,timestamp dependency
|
| 216 |
+
214,10131,ICO,1,timestamp dependency
|
| 217 |
+
215,10131,Tokens,1,timestamp dependency
|
| 218 |
+
216,10133,Tokens,1,timestamp dependency
|
| 219 |
+
217,10146,KOIOSTokenSale,1,timestamp dependency
|
| 220 |
+
218,10146,KOIOSTokenPreSale,1,timestamp dependency
|
| 221 |
+
219,10159,XPAAssets,1,timestamp dependency
|
| 222 |
+
220,10186,FreezableToken,1,timestamp dependency
|
| 223 |
+
221,10189,TokenTimelock,1,timestamp dependency
|
| 224 |
+
222,10189,TokenVesting,1,timestamp dependency
|
| 225 |
+
223,10250,CrowdsaleExt,1,timestamp dependency
|
| 226 |
+
224,10253,CrowdsaleExt,1,timestamp dependency
|
| 227 |
+
225,10369,MuskTokenVault,1,timestamp dependency
|
| 228 |
+
226,10431,EthTeamContract,1,timestamp dependency
|
| 229 |
+
227,10547,ATTRToken,1,timestamp dependency
|
| 230 |
+
228,10551,CrowdsaleExt,1,timestamp dependency
|
| 231 |
+
229,10552,CrowdsaleExt,1,timestamp dependency
|
| 232 |
+
230,10559,Crowdsale,1,timestamp dependency
|
| 233 |
+
231,10559,TokenTimelock,1,timestamp dependency
|
| 234 |
+
232,10560,Crowdsale,1,timestamp dependency
|
| 235 |
+
233,10560,TokenTimelock,1,timestamp dependency
|
| 236 |
+
234,10736,LescovexERC20,1,timestamp dependency
|
| 237 |
+
235,10755,Crowdsale,1,timestamp dependency
|
| 238 |
+
236,10755,FreezableToken,1,timestamp dependency
|
| 239 |
+
237,10758,FreezableToken,1,timestamp dependency
|
| 240 |
+
238,10763,Frozenable,1,timestamp dependency
|
| 241 |
+
239,10798,TokenTimelock,1,timestamp dependency
|
| 242 |
+
240,10803,AnythingAppTokenPreSale,1,timestamp dependency
|
| 243 |
+
241,10807,CrowdsaleExt,1,timestamp dependency
|
| 244 |
+
242,10808,CrowdsaleExt,1,timestamp dependency
|
| 245 |
+
243,10826,AnythingAppTokenPreSale,1,timestamp dependency
|
| 246 |
+
244,10833,AnythingAppTokenPreSale,1,timestamp dependency
|
| 247 |
+
245,10855,TokenLock,1,timestamp dependency
|
| 248 |
+
246,10915,DiceRoll,1,timestamp dependency
|
| 249 |
+
247,10931,CrowdsaleBase,1,timestamp dependency
|
| 250 |
+
248,11021,PAIStandardToken,1,timestamp dependency
|
| 251 |
+
249,11063,TimedCrowdsale,1,timestamp dependency
|
| 252 |
+
250,11064,ANSAToken,1,timestamp dependency
|
| 253 |
+
251,11069,Deposit,1,timestamp dependency
|
| 254 |
+
252,11069,Redeem,1,timestamp dependency
|
| 255 |
+
253,11182,CrowdsaleExt,1,timestamp dependency
|
| 256 |
+
254,11183,FractionalERC20Ext,1,timestamp dependency
|
| 257 |
+
255,11190,TimedCrowdsale,1,timestamp dependency
|
| 258 |
+
256,11191,DiceForSlice,1,timestamp dependency
|
| 259 |
+
257,11205,TimedCrowdsale,1,timestamp dependency
|
| 260 |
+
258,11207,ANDToken,1,timestamp dependency
|
| 261 |
+
259,11223,MCoinDistribution,1,timestamp dependency
|
| 262 |
+
260,11236,EDiamondToken,1,timestamp dependency
|
| 263 |
+
261,11237,TimedCrowdsale,1,timestamp dependency
|
| 264 |
+
262,11237,T2TCrowdsale,1,timestamp dependency
|
| 265 |
+
263,11243,EmontFrenzy,1,timestamp dependency
|
| 266 |
+
264,11257,TTGOracle,1,timestamp dependency
|
| 267 |
+
265,11323,TUINETWORK,1,timestamp dependency
|
| 268 |
+
266,11328,BWService,1,timestamp dependency
|
| 269 |
+
267,11328,BW,1,timestamp dependency
|
| 270 |
+
268,11329,BWService,1,timestamp dependency
|
| 271 |
+
269,11330,BWService,1,timestamp dependency
|
| 272 |
+
270,11339,CrowdsaleExt,1,timestamp dependency
|
| 273 |
+
271,11340,CrowdsaleExt,1,timestamp dependency
|
| 274 |
+
272,11373,TimedCrowdsale,1,timestamp dependency
|
| 275 |
+
273,11374,DAVToken,1,timestamp dependency
|
| 276 |
+
274,11407,Validation,1,timestamp dependency
|
| 277 |
+
275,11415,CrowdsaleExt,1,timestamp dependency
|
| 278 |
+
276,11416,CrowdsaleExt,1,timestamp dependency
|
| 279 |
+
277,11418,CrowdsaleExt,1,timestamp dependency
|
| 280 |
+
278,11419,CrowdsaleExt,1,timestamp dependency
|
| 281 |
+
279,11447,TimedCrowdsale,1,timestamp dependency
|
| 282 |
+
280,11448,SuperCountriesEth,1,timestamp dependency
|
| 283 |
+
281,11457,BCVTokenVault,1,timestamp dependency
|
| 284 |
+
282,11526,Escrow,1,timestamp dependency
|
| 285 |
+
283,11566,Variation,1,timestamp dependency
|
| 286 |
+
284,11568,SetLottery,1,timestamp dependency
|
| 287 |
+
285,11569,CrowdsaleTokenExt,1,timestamp dependency
|
| 288 |
+
286,11640,CrowdsaleExt,1,timestamp dependency
|
| 289 |
+
287,11642,CrowdsaleExt,1,timestamp dependency
|
| 290 |
+
288,11684,CrowdsaleExt,1,timestamp dependency
|
| 291 |
+
289,11685,CrowdsaleExt,1,timestamp dependency
|
| 292 |
+
290,11711,Escrow,1,timestamp dependency
|
| 293 |
+
291,11716,TimedCrowdsale,1,timestamp dependency
|
| 294 |
+
292,11727,FreezableToken,1,timestamp dependency
|
| 295 |
+
293,11751,TokenVesting,1,timestamp dependency
|
| 296 |
+
294,11765,FreezableToken,1,timestamp dependency
|
| 297 |
+
295,11766,FreezableToken,1,timestamp dependency
|
| 298 |
+
296,11775,CrowdsaleBase,1,timestamp dependency
|
| 299 |
+
297,11776,CrowdsaleBase,1,timestamp dependency
|
| 300 |
+
298,11777,AllocatedCappedCrowdsale,1,timestamp dependency
|
| 301 |
+
299,11778,LockToken,1,timestamp dependency
|
| 302 |
+
300,11779,CrowdsaleBase,1,timestamp dependency
|
| 303 |
+
301,11780,CrowdsaleBase,1,timestamp dependency
|
| 304 |
+
302,11786,TokenVesting,1,timestamp dependency
|
| 305 |
+
303,11798,CopaDelCrypto,1,timestamp dependency
|
| 306 |
+
304,11804,TokenVesting,1,timestamp dependency
|
| 307 |
+
305,0,BREBuy,1,block number dependency
|
| 308 |
+
306,42,PoP,1,block number dependency
|
| 309 |
+
307,57,ForeignBridgeErcToErc,1,block number dependency
|
| 310 |
+
308,58,MiniMeToken,1,block number dependency
|
| 311 |
+
309,58,AywakeToken,1,block number dependency
|
| 312 |
+
310,103,EBLLToken,1,block number dependency
|
| 313 |
+
311,106,SPMTToken,1,block number dependency
|
| 314 |
+
312,112,ZeroGoldPOWMining,1,block number dependency
|
| 315 |
+
313,129,DelayedClaimable,1,block number dependency
|
| 316 |
+
314,135,HorseyToken,1,block number dependency
|
| 317 |
+
315,136,HorseyToken,1,block number dependency
|
| 318 |
+
316,137,HorseyToken,1,block number dependency
|
| 319 |
+
317,138,DelayedClaimable,1,block number dependency
|
| 320 |
+
318,164,BREBuy,1,block number dependency
|
| 321 |
+
319,173,EBBToken,1,block number dependency
|
| 322 |
+
320,196,DelayedClaimable,1,block number dependency
|
| 323 |
+
321,215,HorseyToken,1,block number dependency
|
| 324 |
+
322,216,HorseyToken,1,block number dependency
|
| 325 |
+
323,217,HorseyToken,1,block number dependency
|
| 326 |
+
324,220,DelayedClaimable,1,block number dependency
|
| 327 |
+
325,238,DEJToken,1,block number dependency
|
| 328 |
+
326,246,Pinakion,1,block number dependency
|
| 329 |
+
327,246,BlockHashRNGFallback,1,block number dependency
|
| 330 |
+
328,277,Random,1,block number dependency
|
| 331 |
+
329,313,Ethnamed,1,block number dependency
|
| 332 |
+
330,399,Saturn,1,block number dependency
|
| 333 |
+
331,413,StandardToken,1,block number dependency
|
| 334 |
+
332,413,CryptoCongress,1,block number dependency
|
| 335 |
+
333,415,Pinakion,1,block number dependency
|
| 336 |
+
334,415,BlockHashRNGFallback,1,block number dependency
|
| 337 |
+
335,436,DelayedClaimable,1,block number dependency
|
| 338 |
+
336,441,QCOToken,1,block number dependency
|
| 339 |
+
337,584,ULCToken,1,block number dependency
|
| 340 |
+
338,639,HorseyToken,1,block number dependency
|
| 341 |
+
339,642,DelayedClaimable,1,block number dependency
|
| 342 |
+
340,652,LighthouseLib,1,block number dependency
|
| 343 |
+
341,652,RobotLiabilityLib,1,block number dependency
|
| 344 |
+
342,654,HorseyToken,1,block number dependency
|
| 345 |
+
343,655,HorseyToken,1,block number dependency
|
| 346 |
+
344,661,DelayedClaimable,1,block number dependency
|
| 347 |
+
345,672,Game,1,block number dependency
|
| 348 |
+
346,677,BREBuy_ERC20,1,block number dependency
|
| 349 |
+
347,681,ULChain,1,block number dependency
|
| 350 |
+
348,705,DelayedClaimable,1,block number dependency
|
| 351 |
+
349,710,HorseyToken,1,block number dependency
|
| 352 |
+
350,712,HorseyToken,1,block number dependency
|
| 353 |
+
351,713,HorseyToken,1,block number dependency
|
| 354 |
+
352,749,Lockable,1,block number dependency
|
| 355 |
+
353,753,LighthouseLib,1,block number dependency
|
| 356 |
+
354,753,RobotLiabilityLib,1,block number dependency
|
| 357 |
+
355,759,DelayedClaimable,1,block number dependency
|
| 358 |
+
356,762,Crowdsale,1,block number dependency
|
| 359 |
+
357,765,TravelHelperToken,1,block number dependency
|
| 360 |
+
358,810,DelayedClaimable,1,block number dependency
|
| 361 |
+
359,931,DelayedClaimable,1,block number dependency
|
| 362 |
+
360,970,OATToken,1,block number dependency
|
| 363 |
+
361,980,HKHCToken,1,block number dependency
|
| 364 |
+
362,1017,Zlots,1,block number dependency
|
| 365 |
+
363,1034,PoCGame,1,block number dependency
|
| 366 |
+
364,1044,PoCGame,1,block number dependency
|
| 367 |
+
365,1052,Zlots,1,block number dependency
|
| 368 |
+
366,1056,Zlots,1,block number dependency
|
| 369 |
+
367,1096,Zlots,1,block number dependency
|
| 370 |
+
368,1101,Zlots,1,block number dependency
|
| 371 |
+
369,1121,DelayedClaimable,1,block number dependency
|
| 372 |
+
370,1149,Zethroll,1,block number dependency
|
| 373 |
+
371,1165,DelayedClaimable,1,block number dependency
|
| 374 |
+
372,1297,BREBuy,1,block number dependency
|
| 375 |
+
373,1345,Zethroll,1,block number dependency
|
| 376 |
+
374,1376,Win20ETH,1,block number dependency
|
| 377 |
+
375,1406,EVTCTLToken,1,block number dependency
|
| 378 |
+
376,1472,Zlots,1,block number dependency
|
| 379 |
+
377,1482,DelayedClaimable,1,block number dependency
|
| 380 |
+
378,1546,Zlots,1,block number dependency
|
| 381 |
+
379,1567,GuessEth,1,block number dependency
|
| 382 |
+
380,1673,Zlots,1,block number dependency
|
| 383 |
+
381,1678,DelayedClaimable,1,block number dependency
|
| 384 |
+
382,1698,EVTCToken,1,block number dependency
|
| 385 |
+
383,1714,Zethroll,1,block number dependency
|
| 386 |
+
384,1761,Zlots,1,block number dependency
|
| 387 |
+
385,1791,DelayedClaimable,1,block number dependency
|
| 388 |
+
386,1986,PoP,1,block number dependency
|
| 389 |
+
387,2003,Zlots,1,block number dependency
|
| 390 |
+
388,2110,GuessEth,1,block number dependency
|
| 391 |
+
389,2295,WrapperLock,1,block number dependency
|
| 392 |
+
390,2296,WrapperLockEth,1,block number dependency
|
| 393 |
+
391,2584,Zethroll,1,block number dependency
|
| 394 |
+
392,2587,Zethroll,1,block number dependency
|
| 395 |
+
393,2589,Zethroll,1,block number dependency
|
| 396 |
+
394,2593,Zethroll,1,block number dependency
|
| 397 |
+
395,2619,UnityToken,1,block number dependency
|
| 398 |
+
396,2632,AntiFakeLabelToken,1,block number dependency
|
| 399 |
+
397,2633,Zethroll,1,block number dependency
|
| 400 |
+
398,2638,Zethroll,1,block number dependency
|
| 401 |
+
399,2644,POOHMO,1,block number dependency
|
| 402 |
+
400,2658,Zethroll,1,block number dependency
|
| 403 |
+
401,2670,TwentyDollars,1,block number dependency
|
| 404 |
+
402,2734,DivMultisigHackable,1,block number dependency
|
| 405 |
+
403,2805,AZExchange,1,block number dependency
|
| 406 |
+
404,2825,KickTheCoin,1,block number dependency
|
| 407 |
+
405,2963,IMDEXDexchange,1,block number dependency
|
| 408 |
+
406,2977,LedToken,1,block number dependency
|
| 409 |
+
407,2978,LedToken,1,block number dependency
|
| 410 |
+
408,2990,MerkleMine,1,block number dependency
|
| 411 |
+
409,2990,MultiMerkleMine,1,block number dependency
|
| 412 |
+
410,2991,PlayCoinKey,1,block number dependency
|
| 413 |
+
411,3060,TokenLock,1,block number dependency
|
| 414 |
+
412,3062,TokenLock,1,block number dependency
|
| 415 |
+
413,3105,ShintakuToken,1,block number dependency
|
| 416 |
+
414,3123,IcoLib,1,block number dependency
|
| 417 |
+
415,3132,PresalePool,1,block number dependency
|
| 418 |
+
416,3201,AuctionPack,1,block number dependency
|
| 419 |
+
417,3240,NokuCustomERC20,1,block number dependency
|
| 420 |
+
418,3284,MiniMeToken,1,block number dependency
|
| 421 |
+
419,3290,MiniMeToken,1,block number dependency
|
| 422 |
+
420,3291,MiniMeToken,1,block number dependency
|
| 423 |
+
421,3311,nDEX,1,block number dependency
|
| 424 |
+
422,3337,PolarisDEX,1,block number dependency
|
| 425 |
+
423,3386,ContractForDifference,1,block number dependency
|
| 426 |
+
424,3574,BitDex,1,block number dependency
|
| 427 |
+
425,3689,EthertoteToken,1,block number dependency
|
| 428 |
+
426,3704,KickTheCoin,1,block number dependency
|
| 429 |
+
427,3708,WithdrawFromKickTheCoin,1,block number dependency
|
| 430 |
+
428,3711,KickTheCoin,1,block number dependency
|
| 431 |
+
429,3828,LavaWallet,1,block number dependency
|
| 432 |
+
430,3955,DelayedClaimable,1,block number dependency
|
| 433 |
+
431,3970,XinXianToken,1,block number dependency
|
| 434 |
+
432,3971,IcoLib,1,block number dependency
|
| 435 |
+
433,510,AbstractStorage,1,dangerous delegatecall
|
| 436 |
+
434,2004,Proxy,1,dangerous delegatecall
|
| 437 |
+
435,3721,Proxy,1,dangerous delegatecall
|
| 438 |
+
436,3721,DutchExchangeProxy,1,dangerous delegatecall
|
| 439 |
+
437,5321,Proxy,1,dangerous delegatecall
|
| 440 |
+
438,5321,DutchExchangeProxy,1,dangerous delegatecall
|
| 441 |
+
439,5349,Proxy,1,dangerous delegatecall
|
| 442 |
+
440,5349,DutchExchangeProxy,1,dangerous delegatecall
|
| 443 |
+
441,5901,Proxy,1,dangerous delegatecall
|
| 444 |
+
442,5901,DutchExchangeProxy,1,dangerous delegatecall
|
| 445 |
+
443,6043,VersionedToken,1,dangerous delegatecall
|
| 446 |
+
444,6043,SPFCToken,1,dangerous delegatecall
|
| 447 |
+
445,7129,Proxy,1,dangerous delegatecall
|
| 448 |
+
446,7129,DutchExchangeProxy,1,dangerous delegatecall
|
| 449 |
+
447,7493,Proxy,1,dangerous delegatecall
|
| 450 |
+
448,7494,Proxy,1,dangerous delegatecall
|
| 451 |
+
449,7494,DutchExchangeProxy,1,dangerous delegatecall
|
| 452 |
+
450,7628,Registry,1,dangerous delegatecall
|
| 453 |
+
451,11089,Proxy,1,dangerous delegatecall
|
| 454 |
+
452,11089,DutchExchangeProxy,1,dangerous delegatecall
|
| 455 |
+
453,12692,main,1,dangerous delegatecall
|
| 456 |
+
454,13000,EllipseMarketMaker,1,dangerous delegatecall
|
| 457 |
+
455,20625,VersionedToken,1,dangerous delegatecall
|
| 458 |
+
456,20625,ELTToken,1,dangerous delegatecall
|
| 459 |
+
457,20740,Proxy,1,dangerous delegatecall
|
| 460 |
+
458,20740,KnowledgeProxy,1,dangerous delegatecall
|
| 461 |
+
459,21312,Proxy,1,dangerous delegatecall
|
| 462 |
+
460,21312,DutchExchangeProxy,1,dangerous delegatecall
|
| 463 |
+
461,21313,Proxy,1,dangerous delegatecall
|
| 464 |
+
462,21313,DutchExchangeProxy,1,dangerous delegatecall
|
| 465 |
+
463,21314,Proxy,1,dangerous delegatecall
|
| 466 |
+
464,21314,DutchExchangeProxy,1,dangerous delegatecall
|
| 467 |
+
465,22229,MultiSigStub,1,dangerous delegatecall
|
| 468 |
+
466,22344,Proxy,1,dangerous delegatecall
|
| 469 |
+
467,22344,DutchExchangeProxy,1,dangerous delegatecall
|
| 470 |
+
468,22345,Proxy,1,dangerous delegatecall
|
| 471 |
+
469,22345,DutchExchangeProxy,1,dangerous delegatecall
|
| 472 |
+
470,22943,Ohni,1,dangerous delegatecall
|
| 473 |
+
471,23604,token,1,dangerous delegatecall
|
| 474 |
+
472,25217,Standard223Receiver,1,dangerous delegatecall
|
| 475 |
+
473,25217,EllipseMarketMaker,1,dangerous delegatecall
|
| 476 |
+
474,25219,Standard223Receiver,1,dangerous delegatecall
|
| 477 |
+
475,26431,Proxy,1,dangerous delegatecall
|
| 478 |
+
476,26431,DutchExchangeProxy,1,dangerous delegatecall
|
| 479 |
+
477,27767,RiskSharingToken,1,dangerous delegatecall
|
| 480 |
+
478,29219,SimpleDispatcher,1,dangerous delegatecall
|
| 481 |
+
479,29219,PersonalCrowdsaleProxyDispatcher,1,dangerous delegatecall
|
| 482 |
+
480,29717,UserWallet,1,dangerous delegatecall
|
| 483 |
+
481,29999,Proxy,1,dangerous delegatecall
|
| 484 |
+
482,29999,DutchExchangeProxy,1,dangerous delegatecall
|
| 485 |
+
483,30357,testBank,1,dangerous delegatecall
|
| 486 |
+
484,30358,debugContract,1,dangerous delegatecall
|
| 487 |
+
485,30679,MultiSigStub,1,dangerous delegatecall
|
| 488 |
+
486,30692,firstTest,1,dangerous delegatecall
|
| 489 |
+
487,33425,AdminInterface,1,dangerous delegatecall
|
| 490 |
+
488,33567,Proxy,1,dangerous delegatecall
|
| 491 |
+
489,33567,DutchExchangeProxy,1,dangerous delegatecall
|
| 492 |
+
490,33727,Dispatcher,1,dangerous delegatecall
|
| 493 |
+
491,33741,EDProxy,1,dangerous delegatecall
|
| 494 |
+
492,33799,caller,1,dangerous delegatecall
|
| 495 |
+
493,34410,Router,1,dangerous delegatecall
|
| 496 |
+
494,34483,Conductor,1,dangerous delegatecall
|
| 497 |
+
495,38293,Proxy,1,dangerous delegatecall
|
| 498 |
+
496,38293,DutchExchangeProxy,1,dangerous delegatecall
|
| 499 |
+
497,38370,Proxy,1,dangerous delegatecall
|
| 500 |
+
498,38370,DutchExchangeProxy,1,dangerous delegatecall
|
| 501 |
+
499,43210,Proxy,1,dangerous delegatecall
|
| 502 |
+
500,43210,DutchExchangeProxy,1,dangerous delegatecall
|
| 503 |
+
501,44311,DelegateCaller,1,dangerous delegatecall
|
| 504 |
+
502,44417,InstaAccount,1,dangerous delegatecall
|
| 505 |
+
503,44418,InstaAccountV2,1,dangerous delegatecall
|
| 506 |
+
504,47235,Proxy,1,dangerous delegatecall
|
| 507 |
+
505,47235,DutchExchangeProxy,1,dangerous delegatecall
|
| 508 |
+
506,47236,Proxy,1,dangerous delegatecall
|
| 509 |
+
507,47236,DutchExchangeProxy,1,dangerous delegatecall
|
| 510 |
+
508,20189,Withdrawals,1,unchecked external call
|
| 511 |
+
509,22074,SIMPLE_PIGGY_BANK,1,unchecked external call
|
| 512 |
+
510,22675,Withdrawable,1,unchecked external call
|
| 513 |
+
511,31497,MultiplicatorX4,1,unchecked external call
|
| 514 |
+
512,33447,OrganizeFunds,1,unchecked external call
|
| 515 |
+
513,33464,Vault,1,unchecked external call
|
| 516 |
+
514,33512,MultiplicatorX3,1,unchecked external call
|
| 517 |
+
515,35078,minter,1,unchecked external call
|
| 518 |
+
516,35421,DSBaseActor,1,unchecked external call
|
| 519 |
+
517,35904,Withdrawals,1,unchecked external call
|
| 520 |
+
518,35970,EnjinBuyer,1,unchecked external call
|
| 521 |
+
519,36334,RequestSale,1,unchecked external call
|
| 522 |
+
520,37707,BountyHunt,1,unchecked external call
|
| 523 |
+
521,39268,TownCrier,1,unchecked external call
|
| 524 |
+
522,40120,Withdrawals,1,unchecked external call
|
| 525 |
+
523,40123,Withdrawals,1,unchecked external call
|
| 526 |
+
524,40124,Withdrawals,1,unchecked external call
|
| 527 |
+
525,40127,Withdrawals,1,unchecked external call
|
| 528 |
+
526,40129,Withdrawals,1,unchecked external call
|
| 529 |
+
527,40250,Withdrawals,1,unchecked external call
|
| 530 |
+
528,40256,Withdrawals,1,unchecked external call
|
| 531 |
+
529,40259,Withdrawals,1,unchecked external call
|
| 532 |
+
530,40267,Withdrawals,1,unchecked external call
|
| 533 |
+
531,40290,Withdrawals,1,unchecked external call
|
| 534 |
+
532,40301,Withdrawals,1,unchecked external call
|
| 535 |
+
533,40304,Withdrawals,1,unchecked external call
|
| 536 |
+
534,40307,Withdrawals,1,unchecked external call
|
| 537 |
+
535,40310,Withdrawals,1,unchecked external call
|
| 538 |
+
536,40315,Withdrawals,1,unchecked external call
|
| 539 |
+
537,40345,Withdrawals,1,unchecked external call
|
| 540 |
+
538,40346,Withdrawals,1,unchecked external call
|
| 541 |
+
539,40347,Withdrawals,1,unchecked external call
|
| 542 |
+
540,40348,Withdrawals,1,unchecked external call
|
| 543 |
+
541,40349,Withdrawals,1,unchecked external call
|
| 544 |
+
542,40368,Withdrawals,1,unchecked external call
|
| 545 |
+
543,40370,Withdrawals,1,unchecked external call
|
| 546 |
+
544,40372,Withdrawals,1,unchecked external call
|
| 547 |
+
545,40374,Withdrawals,1,unchecked external call
|
| 548 |
+
546,40375,Withdrawals,1,unchecked external call
|
| 549 |
+
547,40406,Dice,1,unchecked external call
|
| 550 |
+
548,40407,Dice,1,unchecked external call
|
| 551 |
+
549,40408,Dice,1,unchecked external call
|
| 552 |
+
550,40432,Withdrawals,1,unchecked external call
|
| 553 |
+
551,40435,Withdrawals,1,unchecked external call
|
| 554 |
+
552,40437,Withdrawals,1,unchecked external call
|
| 555 |
+
553,40452,Withdrawals,1,unchecked external call
|
| 556 |
+
554,40454,Withdrawals,1,unchecked external call
|
| 557 |
+
555,40458,Dice,1,unchecked external call
|
| 558 |
+
556,40459,Dice,1,unchecked external call
|
| 559 |
+
557,40460,Dice,1,unchecked external call
|
| 560 |
+
558,40461,Dice,1,unchecked external call
|
| 561 |
+
559,40462,Dice,1,unchecked external call
|
| 562 |
+
560,40481,KissBTC,1,unchecked external call
|
| 563 |
+
561,40500,MICRODAO,1,unchecked external call
|
| 564 |
+
562,40511,Withdrawals,1,unchecked external call
|
| 565 |
+
563,40513,Withdrawals,1,unchecked external call
|
| 566 |
+
564,40521,Withdrawals,1,unchecked external call
|
| 567 |
+
565,40524,Withdrawals,1,unchecked external call
|
| 568 |
+
566,40527,Withdrawals,1,unchecked external call
|
| 569 |
+
567,40623,Withdrawals,1,unchecked external call
|
| 570 |
+
568,40634,Withdrawals,1,unchecked external call
|
| 571 |
+
569,40640,Withdrawals,1,unchecked external call
|
| 572 |
+
570,40654,Withdrawals,1,unchecked external call
|
| 573 |
+
571,40655,Withdrawals,1,unchecked external call
|
| 574 |
+
572,40733,Attack,1,unchecked external call
|
| 575 |
+
573,43091,Withdrawals,1,unchecked external call
|
| 576 |
+
574,43100,Withdrawals,1,unchecked external call
|
| 577 |
+
575,43101,Withdrawals,1,unchecked external call
|
| 578 |
+
576,43121,Withdrawals,1,unchecked external call
|
| 579 |
+
577,43123,Withdrawals,1,unchecked external call
|
| 580 |
+
578,43330,Withdrawals,1,unchecked external call
|
| 581 |
+
579,43334,Withdrawals,1,unchecked external call
|
| 582 |
+
580,43369,Withdrawals,1,unchecked external call
|
| 583 |
+
581,43379,Withdrawals,1,unchecked external call
|
| 584 |
+
582,43387,Withdrawals,1,unchecked external call
|
| 585 |
+
583,43590,Withdrawals,1,unchecked external call
|
| 586 |
+
584,43593,Withdrawals,1,unchecked external call
|
| 587 |
+
585,43595,Withdrawals,1,unchecked external call
|
| 588 |
+
586,43747,Withdrawals,1,unchecked external call
|
| 589 |
+
587,43750,Withdrawals,1,unchecked external call
|
| 590 |
+
588,43752,Withdrawals,1,unchecked external call
|
| 591 |
+
589,43757,Withdrawals,1,unchecked external call
|
| 592 |
+
590,43769,Withdrawals,1,unchecked external call
|
| 593 |
+
591,44156,LoanTokenSettings,1,unchecked external call
|
| 594 |
+
592,44340,Withdrawals,1,unchecked external call
|
| 595 |
+
593,44341,Withdrawals,1,unchecked external call
|
| 596 |
+
594,44342,Withdrawals,1,unchecked external call
|
| 597 |
+
595,44343,Withdrawals,1,unchecked external call
|
| 598 |
+
596,44344,Withdrawals,1,unchecked external call
|
| 599 |
+
597,44432,HeadTail,1,unchecked external call
|
| 600 |
+
598,44548,Withdrawals,1,unchecked external call
|
| 601 |
+
599,44555,Withdrawals,1,unchecked external call
|
| 602 |
+
600,44576,Withdrawals,1,unchecked external call
|
| 603 |
+
601,44577,Withdrawals,1,unchecked external call
|
| 604 |
+
602,44579,Withdrawals,1,unchecked external call
|
| 605 |
+
603,44810,Withdrawals,1,unchecked external call
|
| 606 |
+
604,44812,Withdrawals,1,unchecked external call
|
| 607 |
+
605,44813,Withdrawals,1,unchecked external call
|
| 608 |
+
606,44815,Withdrawals,1,unchecked external call
|
| 609 |
+
607,44821,Withdrawals,1,unchecked external call
|
| 610 |
+
608,44850,DAO,1,unchecked external call
|
| 611 |
+
609,44994,BaseWallet,1,unchecked external call
|
| 612 |
+
610,44998,Withdrawals,1,unchecked external call
|
| 613 |
+
611,45000,Withdrawals,1,unchecked external call
|
| 614 |
+
612,45011,Withdrawals,1,unchecked external call
|
| 615 |
+
613,45013,Withdrawals,1,unchecked external call
|
| 616 |
+
614,45020,Withdrawals,1,unchecked external call
|
| 617 |
+
615,45030,FakeWallet,1,unchecked external call
|
| 618 |
+
616,45052,KyberNetworkTest,1,unchecked external call
|
| 619 |
+
617,60,MultiBuyer,1,reentrancy
|
| 620 |
+
618,80,MultiBuyer,1,reentrancy
|
| 621 |
+
619,81,MultiBuyer,1,reentrancy
|
| 622 |
+
620,92,MultiBuyer,1,reentrancy
|
| 623 |
+
621,95,MultiBuyer,1,reentrancy
|
| 624 |
+
622,165,MultiBuyer,1,reentrancy
|
| 625 |
+
623,168,MultiBuyer,1,reentrancy
|
| 626 |
+
624,180,MultiBuyer,1,reentrancy
|
| 627 |
+
625,187,MultiBuyer,1,reentrancy
|
| 628 |
+
626,241,MultiBuyer,1,reentrancy
|
| 629 |
+
627,245,MultiBuyer,1,reentrancy
|
| 630 |
+
628,268,MultiBuyer,1,reentrancy
|
| 631 |
+
629,332,MultiBuyer,1,reentrancy
|
| 632 |
+
630,336,MultiBuyer,1,reentrancy
|
| 633 |
+
631,420,MultiBuyer,1,reentrancy
|
| 634 |
+
632,425,MultiBuyer,1,reentrancy
|
| 635 |
+
633,470,MultiBuyer,1,reentrancy
|
| 636 |
+
634,475,MultiBuyer,1,reentrancy
|
| 637 |
+
635,520,MultiBuyer,1,reentrancy
|
| 638 |
+
636,523,MultiBuyer,1,reentrancy
|
| 639 |
+
637,601,MultiBuyer,1,reentrancy
|
| 640 |
+
638,609,MultiBuyer,1,reentrancy
|
| 641 |
+
639,668,MultiBuyer,1,reentrancy
|
| 642 |
+
640,670,MultiBuyer,1,reentrancy
|
| 643 |
+
641,678,MultiBuyer,1,reentrancy
|
| 644 |
+
642,717,MultiBuyer,1,reentrancy
|
| 645 |
+
643,721,MultiBuyer,1,reentrancy
|
| 646 |
+
644,754,MultiBuyer,1,reentrancy
|
| 647 |
+
645,760,MultiBuyer,1,reentrancy
|
| 648 |
+
646,798,MultiBuyer,1,reentrancy
|
| 649 |
+
647,801,MultiBuyer,1,reentrancy
|
| 650 |
+
648,870,MultiBuyer,1,reentrancy
|
| 651 |
+
649,871,MultiBuyer,1,reentrancy
|
| 652 |
+
650,930,MultiBuyer,1,reentrancy
|
| 653 |
+
651,934,MultiBuyer,1,reentrancy
|
| 654 |
+
652,989,MultiBuyer,1,reentrancy
|
| 655 |
+
653,990,MultiBuyer,1,reentrancy
|
| 656 |
+
654,1011,MultiBuyer,1,reentrancy
|
| 657 |
+
655,1021,MultiBuyer,1,reentrancy
|
| 658 |
+
656,1023,MultiBuyer,1,reentrancy
|
| 659 |
+
657,1030,MultiBuyer,1,reentrancy
|
| 660 |
+
658,1076,MultiBuyer,1,reentrancy
|
| 661 |
+
659,1078,MultiBuyer,1,reentrancy
|
| 662 |
+
660,1155,ZethrBankroll,1,reentrancy
|
| 663 |
+
661,1421,MultiBuyer,1,reentrancy
|
| 664 |
+
662,1423,MultiBuyer,1,reentrancy
|
| 665 |
+
663,1427,MultiBuyer,1,reentrancy
|
| 666 |
+
664,1489,MultiBuyer,1,reentrancy
|
| 667 |
+
665,1491,MultiBuyer,1,reentrancy
|
| 668 |
+
666,1498,MultiBuyer,1,reentrancy
|
| 669 |
+
667,1600,MultiBuyer,1,reentrancy
|
| 670 |
+
668,1611,MultiBuyer,1,reentrancy
|
| 671 |
+
669,1620,MultiBuyer,1,reentrancy
|
| 672 |
+
670,1634,MultiBuyer,1,reentrancy
|
| 673 |
+
671,20780,MultiBuyer,1,reentrancy
|
| 674 |
+
672,20810,MultiBuyer,1,reentrancy
|
| 675 |
+
673,20815,MultiBuyer,1,reentrancy
|
| 676 |
+
674,20821,MultiBuyer,1,reentrancy
|
| 677 |
+
675,21071,MultiBuyer,1,reentrancy
|
| 678 |
+
676,21080,MultiBuyer,1,reentrancy
|
| 679 |
+
677,21082,MultiBuyer,1,reentrancy
|
| 680 |
+
678,21084,MultiBuyer,1,reentrancy
|
| 681 |
+
679,21390,Accrual_account,1,reentrancy
|
| 682 |
+
680,21391,MultiSigWallet,1,reentrancy
|
| 683 |
+
681,21391,MultiSigWalletWithDailyLimit,1,reentrancy
|
| 684 |
+
682,21700,MultiBuyer,1,reentrancy
|
| 685 |
+
683,21703,MultiBuyer,1,reentrancy
|
| 686 |
+
684,21741,MultiBuyer,1,reentrancy
|
| 687 |
+
685,21750,MultiBuyer,1,reentrancy
|
| 688 |
+
686,21755,COIN_BOX,1,reentrancy
|
| 689 |
+
687,22074,SIMPLE_PIGGY_BANK,1,reentrancy
|
| 690 |
+
688,22478,MultiBuyer,1,reentrancy
|
| 691 |
+
689,22480,MultiBuyer,1,reentrancy
|
| 692 |
+
690,22485,MultiBuyer,1,reentrancy
|
| 693 |
+
691,22500,MultiBuyer,1,reentrancy
|
| 694 |
+
692,22810,MultiBuyer,1,reentrancy
|
| 695 |
+
693,22813,MultiBuyer,1,reentrancy
|
| 696 |
+
694,22823,MultiBuyer,1,reentrancy
|
| 697 |
+
695,22854,MultiBuyer,1,reentrancy
|
| 698 |
+
696,24456,ETH_VAULT,1,reentrancy
|
| 699 |
+
697,24501,MultiBuyer,1,reentrancy
|
| 700 |
+
698,24507,MultiBuyer,1,reentrancy
|
| 701 |
+
699,24517,MultiBuyer,1,reentrancy
|
| 702 |
+
700,24520,MultiBuyer,1,reentrancy
|
| 703 |
+
701,31620,MultiBuyer,1,reentrancy
|
| 704 |
+
702,31624,MultiBuyer,1,reentrancy
|
| 705 |
+
703,31627,MultiBuyer,1,reentrancy
|
| 706 |
+
704,31632,MultiBuyer,1,reentrancy
|
| 707 |
+
705,31890,MultiBuyer,1,reentrancy
|
| 708 |
+
706,31893,MultiBuyer,1,reentrancy
|
| 709 |
+
707,31895,MultiBuyer,1,reentrancy
|
| 710 |
+
708,31900,MultiBuyer,1,reentrancy
|
| 711 |
+
709,32090,MultiBuyer,1,reentrancy
|
| 712 |
+
710,32091,MultiBuyer,1,reentrancy
|
| 713 |
+
711,32095,MultiBuyer,1,reentrancy
|
| 714 |
+
712,32100,MultiBuyer,1,reentrancy
|
| 715 |
+
713,32470,MultiBuyer,1,reentrancy
|
| 716 |
+
714,32474,MultiBuyer,1,reentrancy
|
| 717 |
+
715,32480,MultiBuyer,1,reentrancy
|
| 718 |
+
716,32481,MultiBuyer,1,reentrancy
|
| 719 |
+
717,32700,MultiBuyer,1,reentrancy
|
| 720 |
+
718,32701,MultiBuyer,1,reentrancy
|
| 721 |
+
719,32710,MultiBuyer,1,reentrancy
|
| 722 |
+
720,32715,MultiBuyer,1,reentrancy
|
| 723 |
+
721,33907,MultiBuyer,1,reentrancy
|
| 724 |
+
722,33910,MultiBuyer,1,reentrancy
|
| 725 |
+
723,33912,MultiBuyer,1,reentrancy
|
| 726 |
+
724,33991,MultiBuyer,1,reentrancy
|
| 727 |
+
725,33995,MultiBuyer,1,reentrancy
|
| 728 |
+
726,33998,MultiBuyer,1,reentrancy
|
| 729 |
+
727,34000,MultiBuyer,1,reentrancy
|
| 730 |
+
728,34090,MultiBuyer,1,reentrancy
|
| 731 |
+
729,34092,MultiBuyer,1,reentrancy
|
| 732 |
+
730,34095,MultiBuyer,1,reentrancy
|
| 733 |
+
731,34098,MultiBuyer,1,reentrancy
|
| 734 |
+
732,34328,MultiBuyer,1,reentrancy
|
| 735 |
+
733,34330,MultiBuyer,1,reentrancy
|
| 736 |
+
734,34331,MultiBuyer,1,reentrancy
|
| 737 |
+
735,34334,MultiBuyer,1,reentrancy
|
| 738 |
+
736,9,WWW,1,integer overflow
|
| 739 |
+
737,33,AbcdEfg,1,integer overflow
|
| 740 |
+
738,34,GlobalGoldCashToken,1,integer overflow
|
| 741 |
+
739,35,BEECASHBACKHOME,1,integer overflow
|
| 742 |
+
740,117,ExShellToken,1,integer overflow
|
| 743 |
+
741,118,ExShellToken,1,integer overflow
|
| 744 |
+
742,126,TestCoin,1,integer overflow
|
| 745 |
+
743,130,ExShellToken,1,integer overflow
|
| 746 |
+
744,143,ExShellToken,1,integer overflow
|
| 747 |
+
745,169,ExShellToken,1,integer overflow
|
| 748 |
+
746,241,ExShellToken,1,integer overflow
|
| 749 |
+
747,258,CRYPTOHEDGECoin,1,integer overflow
|
| 750 |
+
748,339,ExShellToken,1,integer overflow
|
| 751 |
+
749,364,ATM,1,integer overflow
|
| 752 |
+
750,370,Purox,1,integer overflow
|
| 753 |
+
751,372,MntToken,1,integer overflow
|
| 754 |
+
752,375,ExShellToken,1,integer overflow
|
| 755 |
+
753,385,HelpingBlocksContract,1,integer overflow
|
| 756 |
+
754,394,ExShellToken,1,integer overflow
|
| 757 |
+
755,465,ExShellToken,1,integer overflow
|
| 758 |
+
756,520,HeavenlyHoundCoin,1,integer overflow
|
| 759 |
+
757,544,HNContract,1,integer overflow
|
| 760 |
+
758,566,CYFToken,1,integer overflow
|
| 761 |
+
759,607,ExShellToken,1,integer overflow
|
| 762 |
+
760,633,StandardToken,1,integer overflow
|
| 763 |
+
761,633,NABC,1,integer overflow
|
| 764 |
+
762,640,ExShellToken,1,integer overflow
|
| 765 |
+
763,655,ExShellToken,1,integer overflow
|
| 766 |
+
764,688,QPay,1,integer overflow
|
| 767 |
+
765,847,ExShellToken,1,integer overflow
|
| 768 |
+
766,944,VXR,1,integer overflow
|
| 769 |
+
767,977,WBET,1,integer overflow
|
| 770 |
+
768,980,ExShellToken,1,integer overflow
|
| 771 |
+
769,1675,ExShellToken,1,integer overflow
|
| 772 |
+
770,1690,ExShellToken,1,integer overflow
|
| 773 |
+
771,1711,ExShellToken,1,integer overflow
|
| 774 |
+
772,1720,ExShellToken,1,integer overflow
|
| 775 |
+
773,1735,ExShellToken,1,integer overflow
|
| 776 |
+
774,1808,ZXCToken,1,integer overflow
|
| 777 |
+
775,1822,CoinByInsomnia,1,integer overflow
|
| 778 |
+
776,1896,SAFCOIN,1,integer overflow
|
| 779 |
+
777,1955,BBBToken,1,integer overflow
|
smart_contract_dataset/block number dependency/0.sol
ADDED
|
@@ -0,0 +1,169 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
pragma solidity ^0.4.24;
|
| 2 |
+
contract BREBuy {
|
| 3 |
+
|
| 4 |
+
struct ContractParam {
|
| 5 |
+
uint32 totalSize ;
|
| 6 |
+
uint256 singlePrice;
|
| 7 |
+
uint8 pumpRate;
|
| 8 |
+
bool hasChange;
|
| 9 |
+
}
|
| 10 |
+
|
| 11 |
+
address owner = 0x0;
|
| 12 |
+
uint32 gameIndex = 0;
|
| 13 |
+
uint256 totalPrice= 0;
|
| 14 |
+
bool isLock = false;
|
| 15 |
+
ContractParam public setConfig;
|
| 16 |
+
ContractParam public curConfig;
|
| 17 |
+
|
| 18 |
+
address[] public addressArray = new address[](0);
|
| 19 |
+
|
| 20 |
+
event openLockEvent();
|
| 21 |
+
event addPlayerEvent(uint32 gameIndex,address player);
|
| 22 |
+
event gameOverEvent(uint32 gameIndex,uint32 totalSize,uint256 singlePrice,uint8 pumpRate,address winAddr,uint overTime);
|
| 23 |
+
event stopGameEvent(uint totalBalace,uint totalSize,uint price);
|
| 24 |
+
|
| 25 |
+
|
| 26 |
+
constructor ( uint32 _totalSize,
|
| 27 |
+
uint256 _singlePrice
|
| 28 |
+
) public {
|
| 29 |
+
owner = msg.sender;
|
| 30 |
+
setConfig = ContractParam(_totalSize,_singlePrice * 1 finney ,5,false);
|
| 31 |
+
curConfig = ContractParam(_totalSize,_singlePrice * 1 finney ,5,false);
|
| 32 |
+
startNewGame();
|
| 33 |
+
}
|
| 34 |
+
|
| 35 |
+
modifier onlyOwner {
|
| 36 |
+
require(msg.sender == owner,"only owner can call this function");
|
| 37 |
+
_;
|
| 38 |
+
}
|
| 39 |
+
|
| 40 |
+
modifier notLock {
|
| 41 |
+
require(isLock == false,"contract current is lock status");
|
| 42 |
+
_;
|
| 43 |
+
}
|
| 44 |
+
|
| 45 |
+
function isNotContract(address addr) private view returns (bool) {
|
| 46 |
+
uint size;
|
| 47 |
+
assembly { size := extcodesize(addr) }
|
| 48 |
+
return size <= 0;
|
| 49 |
+
}
|
| 50 |
+
|
| 51 |
+
function updateLock(bool b) onlyOwner public {
|
| 52 |
+
|
| 53 |
+
require(isLock != b," updateLock new status == old status");
|
| 54 |
+
|
| 55 |
+
isLock = b;
|
| 56 |
+
|
| 57 |
+
if(isLock) {
|
| 58 |
+
stopGame();
|
| 59 |
+
}else{
|
| 60 |
+
startNewGame();
|
| 61 |
+
emit openLockEvent();
|
| 62 |
+
}
|
| 63 |
+
}
|
| 64 |
+
|
| 65 |
+
function stopGame() onlyOwner private {
|
| 66 |
+
|
| 67 |
+
if(addressArray.length <= 0) {
|
| 68 |
+
return;
|
| 69 |
+
}
|
| 70 |
+
uint totalBalace = address(this).balance;
|
| 71 |
+
uint price = totalBalace / addressArray.length;
|
| 72 |
+
for(uint i = 0; i < addressArray.length; i++) {
|
| 73 |
+
address curPlayer = addressArray[i];
|
| 74 |
+
curPlayer.transfer(price);
|
| 75 |
+
}
|
| 76 |
+
emit stopGameEvent(totalBalace,addressArray.length,price);
|
| 77 |
+
addressArray.length=0;
|
| 78 |
+
}
|
| 79 |
+
|
| 80 |
+
function transferOwnership(address newOwner) onlyOwner public {
|
| 81 |
+
if (newOwner != address(0)) {
|
| 82 |
+
owner = newOwner;
|
| 83 |
+
}
|
| 84 |
+
}
|
| 85 |
+
|
| 86 |
+
function changeConfig( uint32 _totalSize,uint256 _singlePrice,uint8 _pumpRate) onlyOwner public payable {
|
| 87 |
+
|
| 88 |
+
curConfig.hasChange = true;
|
| 89 |
+
if(setConfig.totalSize != _totalSize) {
|
| 90 |
+
setConfig.totalSize = _totalSize;
|
| 91 |
+
}
|
| 92 |
+
if(setConfig.pumpRate != _pumpRate){
|
| 93 |
+
setConfig.pumpRate = _pumpRate;
|
| 94 |
+
}
|
| 95 |
+
if(setConfig.singlePrice != _singlePrice * 1 finney){
|
| 96 |
+
setConfig.singlePrice = _singlePrice * 1 finney;
|
| 97 |
+
}
|
| 98 |
+
}
|
| 99 |
+
|
| 100 |
+
function startNewGame() private {
|
| 101 |
+
|
| 102 |
+
gameIndex++;
|
| 103 |
+
if(curConfig.hasChange) {
|
| 104 |
+
if(curConfig.totalSize != setConfig.totalSize) {
|
| 105 |
+
curConfig.totalSize = setConfig.totalSize;
|
| 106 |
+
}
|
| 107 |
+
if(curConfig.singlePrice != setConfig.singlePrice){
|
| 108 |
+
curConfig.singlePrice = setConfig.singlePrice;
|
| 109 |
+
}
|
| 110 |
+
if( curConfig.pumpRate != setConfig.pumpRate) {
|
| 111 |
+
curConfig.pumpRate = setConfig.pumpRate;
|
| 112 |
+
}
|
| 113 |
+
curConfig.hasChange = false;
|
| 114 |
+
}
|
| 115 |
+
addressArray.length=0;
|
| 116 |
+
}
|
| 117 |
+
|
| 118 |
+
function getGameInfo() public view returns (uint256,uint32,uint256,uint8,address[],uint256,bool) {
|
| 119 |
+
return (gameIndex,
|
| 120 |
+
curConfig.totalSize,
|
| 121 |
+
curConfig.singlePrice,
|
| 122 |
+
curConfig.pumpRate,
|
| 123 |
+
addressArray,
|
| 124 |
+
totalPrice,
|
| 125 |
+
isLock);
|
| 126 |
+
}
|
| 127 |
+
|
| 128 |
+
function gameResult() private {
|
| 129 |
+
|
| 130 |
+
uint index = getRamdon();
|
| 131 |
+
address lastAddress = addressArray[index];
|
| 132 |
+
uint totalBalace = address(this).balance;
|
| 133 |
+
uint giveToOwn = totalBalace * curConfig.pumpRate / 100;
|
| 134 |
+
uint giveToActor = totalBalace - giveToOwn;
|
| 135 |
+
owner.transfer(giveToOwn);
|
| 136 |
+
lastAddress.transfer(giveToActor);
|
| 137 |
+
emit gameOverEvent(
|
| 138 |
+
gameIndex,
|
| 139 |
+
curConfig.totalSize,
|
| 140 |
+
curConfig.singlePrice,
|
| 141 |
+
curConfig.pumpRate,
|
| 142 |
+
lastAddress,
|
| 143 |
+
now);
|
| 144 |
+
}
|
| 145 |
+
|
| 146 |
+
function getRamdon() private view returns (uint) {
|
| 147 |
+
bytes32 ramdon = keccak256(abi.encodePacked(ramdon,now,blockhash(block.number-1)));
|
| 148 |
+
for(uint i = 0; i < addressArray.length; i++) {
|
| 149 |
+
ramdon = keccak256(abi.encodePacked(ramdon,now, addressArray[i]));
|
| 150 |
+
}
|
| 151 |
+
uint index = uint(ramdon) % addressArray.length;
|
| 152 |
+
return index;
|
| 153 |
+
}
|
| 154 |
+
|
| 155 |
+
function() notLock payable public{
|
| 156 |
+
|
| 157 |
+
require(msg.sender == tx.origin, "msg.sender must equipt tx.origin");
|
| 158 |
+
require(isNotContract(msg.sender),"msg.sender not is Contract");
|
| 159 |
+
require(msg.value == curConfig.singlePrice,"msg.value error");
|
| 160 |
+
totalPrice = totalPrice + msg.value;
|
| 161 |
+
addressArray.push(msg.sender);
|
| 162 |
+
|
| 163 |
+
emit addPlayerEvent(gameIndex,msg.sender);
|
| 164 |
+
if(addressArray.length >= curConfig.totalSize) {
|
| 165 |
+
gameResult();
|
| 166 |
+
startNewGame();
|
| 167 |
+
}
|
| 168 |
+
}
|
| 169 |
+
}
|
smart_contract_dataset/block number dependency/1017.sol
ADDED
|
@@ -0,0 +1,625 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
pragma solidity ^0.4.24;
|
| 2 |
+
|
| 3 |
+
|
| 4 |
+
|
| 5 |
+
|
| 6 |
+
contract ZethrTokenBankroll{
|
| 7 |
+
|
| 8 |
+
function gameRequestTokens(address target, uint tokens) public;
|
| 9 |
+
function gameTokenAmount(address what) public returns (uint);
|
| 10 |
+
}
|
| 11 |
+
|
| 12 |
+
|
| 13 |
+
contract ZethrMainBankroll{
|
| 14 |
+
function gameGetTokenBankrollList() public view returns (address[7]);
|
| 15 |
+
}
|
| 16 |
+
|
| 17 |
+
|
| 18 |
+
contract ZethrInterface{
|
| 19 |
+
function withdraw() public;
|
| 20 |
+
}
|
| 21 |
+
|
| 22 |
+
|
| 23 |
+
library ZethrTierLibrary{
|
| 24 |
+
|
| 25 |
+
function getTier(uint divRate) internal pure returns (uint){
|
| 26 |
+
|
| 27 |
+
|
| 28 |
+
|
| 29 |
+
|
| 30 |
+
|
| 31 |
+
uint actualDiv = divRate;
|
| 32 |
+
if (actualDiv >= 30){
|
| 33 |
+
return 6;
|
| 34 |
+
} else if (actualDiv >= 25){
|
| 35 |
+
return 5;
|
| 36 |
+
} else if (actualDiv >= 20){
|
| 37 |
+
return 4;
|
| 38 |
+
} else if (actualDiv >= 15){
|
| 39 |
+
return 3;
|
| 40 |
+
} else if (actualDiv >= 10){
|
| 41 |
+
return 2;
|
| 42 |
+
} else if (actualDiv >= 5){
|
| 43 |
+
return 1;
|
| 44 |
+
} else if (actualDiv >= 2){
|
| 45 |
+
return 0;
|
| 46 |
+
} else{
|
| 47 |
+
|
| 48 |
+
revert();
|
| 49 |
+
}
|
| 50 |
+
}
|
| 51 |
+
}
|
| 52 |
+
|
| 53 |
+
|
| 54 |
+
contract ZlotsJackpotHoldingContract {
|
| 55 |
+
function payOutWinner(address winner) public;
|
| 56 |
+
function getJackpot() public view returns (uint);
|
| 57 |
+
}
|
| 58 |
+
|
| 59 |
+
|
| 60 |
+
contract ZethrBankrollBridge {
|
| 61 |
+
|
| 62 |
+
ZethrInterface Zethr;
|
| 63 |
+
|
| 64 |
+
|
| 65 |
+
|
| 66 |
+
|
| 67 |
+
|
| 68 |
+
address[7] UsedBankrollAddresses;
|
| 69 |
+
|
| 70 |
+
|
| 71 |
+
mapping(address => bool) ValidBankrollAddress;
|
| 72 |
+
|
| 73 |
+
|
| 74 |
+
function setupBankrollInterface(address ZethrMainBankrollAddress) internal {
|
| 75 |
+
|
| 76 |
+
|
| 77 |
+
Zethr = ZethrInterface(0xD48B633045af65fF636F3c6edd744748351E020D);
|
| 78 |
+
|
| 79 |
+
|
| 80 |
+
UsedBankrollAddresses = ZethrMainBankroll(ZethrMainBankrollAddress).gameGetTokenBankrollList();
|
| 81 |
+
for(uint i=0; i<7; i++){
|
| 82 |
+
ValidBankrollAddress[UsedBankrollAddresses[i]] = true;
|
| 83 |
+
}
|
| 84 |
+
}
|
| 85 |
+
|
| 86 |
+
|
| 87 |
+
modifier fromBankroll(){
|
| 88 |
+
require(ValidBankrollAddress[msg.sender], "msg.sender should be a valid bankroll");
|
| 89 |
+
_;
|
| 90 |
+
}
|
| 91 |
+
|
| 92 |
+
|
| 93 |
+
|
| 94 |
+
function RequestBankrollPayment(address to, uint tokens, uint tier) internal {
|
| 95 |
+
address tokenBankrollAddress = UsedBankrollAddresses[tier];
|
| 96 |
+
ZethrTokenBankroll(tokenBankrollAddress).gameRequestTokens(to, tokens);
|
| 97 |
+
}
|
| 98 |
+
|
| 99 |
+
function getZethrTokenBankroll(uint divRate) public constant returns (ZethrTokenBankroll){
|
| 100 |
+
return ZethrTokenBankroll(UsedBankrollAddresses[ZethrTierLibrary.getTier(divRate)]);
|
| 101 |
+
}
|
| 102 |
+
}
|
| 103 |
+
|
| 104 |
+
|
| 105 |
+
contract ZethrShell is ZethrBankrollBridge {
|
| 106 |
+
|
| 107 |
+
|
| 108 |
+
function WithdrawToBankroll() public {
|
| 109 |
+
address(UsedBankrollAddresses[0]).transfer(address(this).balance);
|
| 110 |
+
}
|
| 111 |
+
|
| 112 |
+
|
| 113 |
+
function WithdrawAndTransferToBankroll() public {
|
| 114 |
+
Zethr.withdraw();
|
| 115 |
+
WithdrawToBankroll();
|
| 116 |
+
}
|
| 117 |
+
}
|
| 118 |
+
|
| 119 |
+
|
| 120 |
+
|
| 121 |
+
contract Zlots is ZethrShell {
|
| 122 |
+
using SafeMath for uint;
|
| 123 |
+
|
| 124 |
+
|
| 125 |
+
|
| 126 |
+
|
| 127 |
+
event HouseRetrievedTake(
|
| 128 |
+
uint timeTaken,
|
| 129 |
+
uint tokensWithdrawn
|
| 130 |
+
);
|
| 131 |
+
|
| 132 |
+
|
| 133 |
+
event TokensWagered(
|
| 134 |
+
address _wagerer,
|
| 135 |
+
uint _wagered
|
| 136 |
+
);
|
| 137 |
+
|
| 138 |
+
event LogResult(
|
| 139 |
+
address _wagerer,
|
| 140 |
+
uint _result,
|
| 141 |
+
uint _profit,
|
| 142 |
+
uint _wagered,
|
| 143 |
+
uint _category,
|
| 144 |
+
bool _win
|
| 145 |
+
);
|
| 146 |
+
|
| 147 |
+
|
| 148 |
+
event Loss(address _wagerer, uint _block);
|
| 149 |
+
event ThreeMoonJackpot(address _wagerer, uint _block);
|
| 150 |
+
event TwoMoonPrize(address _wagerer, uint _block);
|
| 151 |
+
event ZTHPrize(address _wagerer, uint _block);
|
| 152 |
+
event ThreeZSymbols(address _wagerer, uint _block);
|
| 153 |
+
event ThreeTSymbols(address _wagerer, uint _block);
|
| 154 |
+
event ThreeHSymbols(address _wagerer, uint _block);
|
| 155 |
+
event ThreeEtherIcons(address _wagerer, uint _block);
|
| 156 |
+
event ThreePurplePyramids(address _wagerer, uint _block);
|
| 157 |
+
event ThreeGoldPyramids(address _wagerer, uint _block);
|
| 158 |
+
event ThreeRockets(address _wagerer, uint _block);
|
| 159 |
+
event OneMoonPrize(address _wagerer, uint _block);
|
| 160 |
+
event OneOfEachPyramidPrize(address _wagerer, uint _block);
|
| 161 |
+
event TwoZSymbols(address _wagerer, uint _block);
|
| 162 |
+
event TwoTSymbols(address _wagerer, uint _block);
|
| 163 |
+
event TwoHSymbols(address _wagerer, uint _block);
|
| 164 |
+
event TwoEtherIcons(address _wagerer, uint _block);
|
| 165 |
+
event TwoPurplePyramids(address _wagerer, uint _block);
|
| 166 |
+
event TwoGoldPyramids(address _wagerer, uint _block);
|
| 167 |
+
event TwoRockets(address _wagerer, uint _block);
|
| 168 |
+
event SpinConcluded(address _wagerer, uint _block);
|
| 169 |
+
|
| 170 |
+
|
| 171 |
+
|
| 172 |
+
|
| 173 |
+
|
| 174 |
+
modifier betIsValid(uint _betSize, uint divRate) {
|
| 175 |
+
require(_betSize.mul(50) <= getMaxProfit(divRate));
|
| 176 |
+
_;
|
| 177 |
+
}
|
| 178 |
+
|
| 179 |
+
|
| 180 |
+
modifier gameIsActive {
|
| 181 |
+
require(gamePaused == false);
|
| 182 |
+
_;
|
| 183 |
+
}
|
| 184 |
+
|
| 185 |
+
|
| 186 |
+
modifier onlyOwner {
|
| 187 |
+
require(msg.sender == owner);
|
| 188 |
+
_;
|
| 189 |
+
}
|
| 190 |
+
|
| 191 |
+
|
| 192 |
+
modifier onlyBankroll {
|
| 193 |
+
require(msg.sender == bankroll);
|
| 194 |
+
_;
|
| 195 |
+
}
|
| 196 |
+
|
| 197 |
+
|
| 198 |
+
modifier onlyOwnerOrBankroll {
|
| 199 |
+
require(msg.sender == owner || msg.sender == bankroll);
|
| 200 |
+
_;
|
| 201 |
+
}
|
| 202 |
+
|
| 203 |
+
|
| 204 |
+
|
| 205 |
+
|
| 206 |
+
uint constant public maxProfitDivisor = 1000000;
|
| 207 |
+
uint constant public houseEdgeDivisor = 1000;
|
| 208 |
+
mapping (uint => uint) public maxProfit;
|
| 209 |
+
uint public maxProfitAsPercentOfHouse;
|
| 210 |
+
uint public minBet = 1e18;
|
| 211 |
+
address public zlotsJackpot;
|
| 212 |
+
address private owner;
|
| 213 |
+
address private bankroll;
|
| 214 |
+
bool gamePaused;
|
| 215 |
+
|
| 216 |
+
|
| 217 |
+
uint public totalSpins;
|
| 218 |
+
uint public totalZTHWagered;
|
| 219 |
+
mapping (uint => uint) public contractBalance;
|
| 220 |
+
|
| 221 |
+
|
| 222 |
+
bool public gameActive;
|
| 223 |
+
|
| 224 |
+
address private ZTHTKNADDR;
|
| 225 |
+
address private ZTHBANKROLL;
|
| 226 |
+
|
| 227 |
+
|
| 228 |
+
|
| 229 |
+
|
| 230 |
+
constructor(address BankrollAddress) public {
|
| 231 |
+
|
| 232 |
+
setupBankrollInterface(BankrollAddress);
|
| 233 |
+
|
| 234 |
+
|
| 235 |
+
owner = msg.sender;
|
| 236 |
+
|
| 237 |
+
|
| 238 |
+
ownerSetMaxProfitAsPercentOfHouse(50000);
|
| 239 |
+
|
| 240 |
+
|
| 241 |
+
bankroll = ZTHBANKROLL;
|
| 242 |
+
gameActive = true;
|
| 243 |
+
|
| 244 |
+
|
| 245 |
+
ownerSetMinBet(1e18);
|
| 246 |
+
}
|
| 247 |
+
|
| 248 |
+
|
| 249 |
+
function() public payable { }
|
| 250 |
+
|
| 251 |
+
|
| 252 |
+
struct TKN { address sender; uint value; }
|
| 253 |
+
function execute(address _from, uint _value, uint divRate, bytes ) public fromBankroll returns (bool){
|
| 254 |
+
TKN memory _tkn;
|
| 255 |
+
_tkn.sender = _from;
|
| 256 |
+
_tkn.value = _value;
|
| 257 |
+
_spinTokens(_tkn, divRate);
|
| 258 |
+
return true;
|
| 259 |
+
}
|
| 260 |
+
|
| 261 |
+
struct playerSpin {
|
| 262 |
+
uint200 tokenValue;
|
| 263 |
+
uint48 blockn;
|
| 264 |
+
uint8 tier;
|
| 265 |
+
uint divRate;
|
| 266 |
+
}
|
| 267 |
+
|
| 268 |
+
|
| 269 |
+
mapping(address => playerSpin) public playerSpins;
|
| 270 |
+
|
| 271 |
+
|
| 272 |
+
function _spinTokens(TKN _tkn, uint divRate)
|
| 273 |
+
private
|
| 274 |
+
betIsValid(_tkn.value, divRate)
|
| 275 |
+
{
|
| 276 |
+
|
| 277 |
+
require(gameActive);
|
| 278 |
+
require(block.number <= ((2 ** 48) - 1));
|
| 279 |
+
|
| 280 |
+
address _customerAddress = _tkn.sender;
|
| 281 |
+
uint _wagered = _tkn.value;
|
| 282 |
+
|
| 283 |
+
playerSpin memory spin = playerSpins[_tkn.sender];
|
| 284 |
+
|
| 285 |
+
|
| 286 |
+
|
| 287 |
+
|
| 288 |
+
addContractBalance(divRate, _wagered);
|
| 289 |
+
|
| 290 |
+
|
| 291 |
+
require(block.number != spin.blockn);
|
| 292 |
+
|
| 293 |
+
|
| 294 |
+
if (spin.blockn != 0) {
|
| 295 |
+
_finishSpin(_tkn.sender);
|
| 296 |
+
}
|
| 297 |
+
|
| 298 |
+
|
| 299 |
+
spin.blockn = uint48(block.number);
|
| 300 |
+
spin.tokenValue = uint200(_wagered);
|
| 301 |
+
spin.tier = uint8(ZethrTierLibrary.getTier(divRate));
|
| 302 |
+
spin.divRate = divRate;
|
| 303 |
+
|
| 304 |
+
|
| 305 |
+
playerSpins[_tkn.sender] = spin;
|
| 306 |
+
|
| 307 |
+
|
| 308 |
+
totalSpins += 1;
|
| 309 |
+
|
| 310 |
+
|
| 311 |
+
totalZTHWagered += _wagered;
|
| 312 |
+
|
| 313 |
+
emit TokensWagered(_customerAddress, _wagered);
|
| 314 |
+
}
|
| 315 |
+
|
| 316 |
+
|
| 317 |
+
function finishSpin() public
|
| 318 |
+
gameIsActive
|
| 319 |
+
returns (uint)
|
| 320 |
+
{
|
| 321 |
+
return _finishSpin(msg.sender);
|
| 322 |
+
}
|
| 323 |
+
|
| 324 |
+
|
| 325 |
+
function _finishSpin(address target)
|
| 326 |
+
private returns (uint)
|
| 327 |
+
{
|
| 328 |
+
playerSpin memory spin = playerSpins[target];
|
| 329 |
+
|
| 330 |
+
require(spin.tokenValue > 0);
|
| 331 |
+
require(spin.blockn != block.number);
|
| 332 |
+
|
| 333 |
+
uint profit = 0;
|
| 334 |
+
uint category = 0;
|
| 335 |
+
uint playerDivrate = spin.divRate;
|
| 336 |
+
|
| 337 |
+
|
| 338 |
+
|
| 339 |
+
uint result;
|
| 340 |
+
if (block.number - spin.blockn > 255) {
|
| 341 |
+
result = 1000000;
|
| 342 |
+
} else {
|
| 343 |
+
|
| 344 |
+
|
| 345 |
+
|
| 346 |
+
result = random(1000000, spin.blockn, target) + 1;
|
| 347 |
+
}
|
| 348 |
+
|
| 349 |
+
if (result > 506856) {
|
| 350 |
+
|
| 351 |
+
|
| 352 |
+
|
| 353 |
+
|
| 354 |
+
RequestBankrollPayment(zlotsJackpot, spin.tokenValue / 100, tier);
|
| 355 |
+
|
| 356 |
+
|
| 357 |
+
playerSpins[target] = playerSpin(uint200(0), uint48(0), uint8(0), uint(0));
|
| 358 |
+
|
| 359 |
+
emit Loss(target, spin.blockn);
|
| 360 |
+
emit LogResult(target, result, profit, spin.tokenValue, category, false);
|
| 361 |
+
} else if (result < 2) {
|
| 362 |
+
|
| 363 |
+
|
| 364 |
+
|
| 365 |
+
profit = ZlotsJackpotHoldingContract(zlotsJackpot).getJackpot();
|
| 366 |
+
category = 1;
|
| 367 |
+
|
| 368 |
+
|
| 369 |
+
emit ThreeMoonJackpot(target, spin.blockn);
|
| 370 |
+
emit LogResult(target, result, profit, spin.tokenValue, category, true);
|
| 371 |
+
|
| 372 |
+
|
| 373 |
+
uint8 tier = spin.tier;
|
| 374 |
+
|
| 375 |
+
|
| 376 |
+
playerSpins[target] = playerSpin(uint200(0), uint48(0), uint8(0), uint(0));
|
| 377 |
+
|
| 378 |
+
|
| 379 |
+
ZlotsJackpotHoldingContract(zlotsJackpot).payOutWinner(target);
|
| 380 |
+
} else {
|
| 381 |
+
if (result < 299) {
|
| 382 |
+
|
| 383 |
+
profit = SafeMath.mul(spin.tokenValue, 50);
|
| 384 |
+
category = 2;
|
| 385 |
+
emit TwoMoonPrize(target, spin.blockn);
|
| 386 |
+
} else if (result < 3128) {
|
| 387 |
+
|
| 388 |
+
profit = SafeMath.mul(spin.tokenValue, 20);
|
| 389 |
+
category = 3;
|
| 390 |
+
emit ZTHPrize(target, spin.blockn);
|
| 391 |
+
} else if (result < 16961) {
|
| 392 |
+
|
| 393 |
+
profit = SafeMath.div(SafeMath.mul(spin.tokenValue, 30), 10);
|
| 394 |
+
category = 4;
|
| 395 |
+
emit ThreeZSymbols(target, spin.blockn);
|
| 396 |
+
} else if (result < 30794) {
|
| 397 |
+
|
| 398 |
+
profit = SafeMath.div(SafeMath.mul(spin.tokenValue, 30), 10);
|
| 399 |
+
category = 5;
|
| 400 |
+
emit ThreeTSymbols(target, spin.blockn);
|
| 401 |
+
} else if (result < 44627) {
|
| 402 |
+
|
| 403 |
+
profit = SafeMath.div(SafeMath.mul(spin.tokenValue, 30), 10);
|
| 404 |
+
category = 6;
|
| 405 |
+
emit ThreeHSymbols(target, spin.blockn);
|
| 406 |
+
} else if (result < 46627) {
|
| 407 |
+
|
| 408 |
+
profit = SafeMath.mul(spin.tokenValue, 11);
|
| 409 |
+
category = 7;
|
| 410 |
+
emit ThreeEtherIcons(target, spin.blockn);
|
| 411 |
+
} else if (result < 49127) {
|
| 412 |
+
|
| 413 |
+
profit = SafeMath.div(SafeMath.mul(spin.tokenValue, 75), 10);
|
| 414 |
+
category = 8;
|
| 415 |
+
emit ThreePurplePyramids(target, spin.blockn);
|
| 416 |
+
} else if (result < 51627) {
|
| 417 |
+
|
| 418 |
+
profit = SafeMath.mul(spin.tokenValue, 9);
|
| 419 |
+
category = 9;
|
| 420 |
+
emit ThreeGoldPyramids(target, spin.blockn);
|
| 421 |
+
} else if (result < 53127) {
|
| 422 |
+
|
| 423 |
+
profit = SafeMath.mul(spin.tokenValue, 13);
|
| 424 |
+
category = 10;
|
| 425 |
+
emit ThreeRockets(target, spin.blockn);
|
| 426 |
+
} else if (result < 82530) {
|
| 427 |
+
|
| 428 |
+
profit = SafeMath.div(SafeMath.mul(spin.tokenValue, 25),10);
|
| 429 |
+
category = 11;
|
| 430 |
+
emit OneMoonPrize(target, spin.blockn);
|
| 431 |
+
} else if (result < 150423) {
|
| 432 |
+
|
| 433 |
+
profit = SafeMath.div(SafeMath.mul(spin.tokenValue, 15),10);
|
| 434 |
+
category = 12;
|
| 435 |
+
emit OneOfEachPyramidPrize(target, spin.blockn);
|
| 436 |
+
} else if (result < 203888) {
|
| 437 |
+
|
| 438 |
+
profit = spin.tokenValue;
|
| 439 |
+
category = 13;
|
| 440 |
+
emit TwoZSymbols(target, spin.blockn);
|
| 441 |
+
} else if (result < 257353) {
|
| 442 |
+
|
| 443 |
+
profit = spin.tokenValue;
|
| 444 |
+
category = 14;
|
| 445 |
+
emit TwoTSymbols(target, spin.blockn);
|
| 446 |
+
} else if (result < 310818) {
|
| 447 |
+
|
| 448 |
+
profit = spin.tokenValue;
|
| 449 |
+
category = 15;
|
| 450 |
+
emit TwoHSymbols(target, spin.blockn);
|
| 451 |
+
} else if (result < 364283) {
|
| 452 |
+
|
| 453 |
+
profit = SafeMath.mul(spin.tokenValue, 2);
|
| 454 |
+
category = 16;
|
| 455 |
+
emit TwoEtherIcons(target, spin.blockn);
|
| 456 |
+
} else if (result < 417748) {
|
| 457 |
+
|
| 458 |
+
profit = SafeMath.div(SafeMath.mul(spin.tokenValue, 125), 100);
|
| 459 |
+
category = 17;
|
| 460 |
+
emit TwoPurplePyramids(target, spin.blockn);
|
| 461 |
+
} else if (result < 471213) {
|
| 462 |
+
|
| 463 |
+
profit = SafeMath.div(SafeMath.mul(spin.tokenValue, 133), 100);
|
| 464 |
+
category = 18;
|
| 465 |
+
emit TwoGoldPyramids(target, spin.blockn);
|
| 466 |
+
} else {
|
| 467 |
+
|
| 468 |
+
profit = SafeMath.div(SafeMath.mul(spin.tokenValue, 25), 10);
|
| 469 |
+
category = 19;
|
| 470 |
+
emit TwoRockets(target, spin.blockn);
|
| 471 |
+
}
|
| 472 |
+
|
| 473 |
+
|
| 474 |
+
subContractBalance(playerDivrate, profit);
|
| 475 |
+
|
| 476 |
+
emit LogResult(target, result, profit, spin.tokenValue, category, true);
|
| 477 |
+
tier = spin.tier;
|
| 478 |
+
playerSpins[target] = playerSpin(uint200(0), uint48(0), uint8(0), uint(0));
|
| 479 |
+
RequestBankrollPayment(target, profit, tier);
|
| 480 |
+
}
|
| 481 |
+
|
| 482 |
+
emit SpinConcluded(target, spin.blockn);
|
| 483 |
+
return result;
|
| 484 |
+
}
|
| 485 |
+
|
| 486 |
+
|
| 487 |
+
|
| 488 |
+
function maxRandom(uint blockn, address entropy) private view returns (uint256 randomNumber) {
|
| 489 |
+
return uint256(keccak256(
|
| 490 |
+
abi.encodePacked(
|
| 491 |
+
|
| 492 |
+
blockhash(blockn),
|
| 493 |
+
entropy)
|
| 494 |
+
));
|
| 495 |
+
}
|
| 496 |
+
|
| 497 |
+
|
| 498 |
+
function random(uint256 upper, uint256 blockn, address entropy) internal view returns (uint256 randomNumber) {
|
| 499 |
+
return maxRandom(blockn, entropy) % upper;
|
| 500 |
+
}
|
| 501 |
+
|
| 502 |
+
|
| 503 |
+
function setMaxProfit(uint divRate) internal {
|
| 504 |
+
maxProfit[divRate] = (contractBalance[divRate] * maxProfitAsPercentOfHouse) / maxProfitDivisor;
|
| 505 |
+
}
|
| 506 |
+
|
| 507 |
+
|
| 508 |
+
function getMaxProfit(uint divRate) public view returns (uint) {
|
| 509 |
+
return (contractBalance[divRate] * maxProfitAsPercentOfHouse) / maxProfitDivisor;
|
| 510 |
+
}
|
| 511 |
+
|
| 512 |
+
|
| 513 |
+
function subContractBalance(uint divRate, uint sub) internal {
|
| 514 |
+
contractBalance[divRate] = contractBalance[divRate].sub(sub);
|
| 515 |
+
}
|
| 516 |
+
|
| 517 |
+
|
| 518 |
+
function addContractBalance(uint divRate, uint add) internal {
|
| 519 |
+
contractBalance[divRate] = contractBalance[divRate].add(add);
|
| 520 |
+
}
|
| 521 |
+
|
| 522 |
+
|
| 523 |
+
|
| 524 |
+
|
| 525 |
+
function bankrollExternalUpdateTokens(uint divRate, uint newBalance)
|
| 526 |
+
public
|
| 527 |
+
fromBankroll
|
| 528 |
+
{
|
| 529 |
+
contractBalance[divRate] = newBalance;
|
| 530 |
+
setMaxProfit(divRate);
|
| 531 |
+
}
|
| 532 |
+
|
| 533 |
+
|
| 534 |
+
|
| 535 |
+
function ownerSetMaxProfitAsPercentOfHouse(uint newMaxProfitAsPercent) public
|
| 536 |
+
onlyOwner
|
| 537 |
+
{
|
| 538 |
+
|
| 539 |
+
require(newMaxProfitAsPercent <= 500000);
|
| 540 |
+
maxProfitAsPercentOfHouse = newMaxProfitAsPercent;
|
| 541 |
+
setMaxProfit(2);
|
| 542 |
+
setMaxProfit(5);
|
| 543 |
+
setMaxProfit(10);
|
| 544 |
+
setMaxProfit(15);
|
| 545 |
+
setMaxProfit(20);
|
| 546 |
+
setMaxProfit(25);
|
| 547 |
+
setMaxProfit(33);
|
| 548 |
+
}
|
| 549 |
+
|
| 550 |
+
|
| 551 |
+
function ownerSetMinBet(uint newMinimumBet) public
|
| 552 |
+
onlyOwner
|
| 553 |
+
{
|
| 554 |
+
minBet = newMinimumBet;
|
| 555 |
+
}
|
| 556 |
+
|
| 557 |
+
|
| 558 |
+
function ownerSetZlotsAddress(address zlotsAddress) public
|
| 559 |
+
onlyOwner
|
| 560 |
+
{
|
| 561 |
+
zlotsJackpot = zlotsAddress;
|
| 562 |
+
}
|
| 563 |
+
|
| 564 |
+
|
| 565 |
+
function pauseGame() public onlyOwnerOrBankroll {
|
| 566 |
+
gameActive = false;
|
| 567 |
+
}
|
| 568 |
+
|
| 569 |
+
|
| 570 |
+
function resumeGame() public onlyOwnerOrBankroll {
|
| 571 |
+
gameActive = true;
|
| 572 |
+
}
|
| 573 |
+
|
| 574 |
+
|
| 575 |
+
function changeOwner(address _newOwner) public onlyOwnerOrBankroll {
|
| 576 |
+
owner = _newOwner;
|
| 577 |
+
}
|
| 578 |
+
|
| 579 |
+
|
| 580 |
+
function changeBankroll(address _newBankroll) public onlyOwnerOrBankroll {
|
| 581 |
+
bankroll = _newBankroll;
|
| 582 |
+
}
|
| 583 |
+
|
| 584 |
+
|
| 585 |
+
function _zthToken(address _tokenContract) private view returns (bool) {
|
| 586 |
+
return _tokenContract == ZTHTKNADDR;
|
| 587 |
+
}
|
| 588 |
+
}
|
| 589 |
+
|
| 590 |
+
|
| 591 |
+
|
| 592 |
+
|
| 593 |
+
library SafeMath {
|
| 594 |
+
|
| 595 |
+
|
| 596 |
+
function mul(uint a, uint b) internal pure returns (uint) {
|
| 597 |
+
if (a == 0) {
|
| 598 |
+
return 0;
|
| 599 |
+
}
|
| 600 |
+
uint c = a * b;
|
| 601 |
+
assert(c / a == b);
|
| 602 |
+
return c;
|
| 603 |
+
}
|
| 604 |
+
|
| 605 |
+
|
| 606 |
+
function div(uint a, uint b) internal pure returns (uint) {
|
| 607 |
+
|
| 608 |
+
uint c = a / b;
|
| 609 |
+
|
| 610 |
+
return c;
|
| 611 |
+
}
|
| 612 |
+
|
| 613 |
+
|
| 614 |
+
function sub(uint a, uint b) internal pure returns (uint) {
|
| 615 |
+
assert(b <= a);
|
| 616 |
+
return a - b;
|
| 617 |
+
}
|
| 618 |
+
|
| 619 |
+
|
| 620 |
+
function add(uint a, uint b) internal pure returns (uint) {
|
| 621 |
+
uint c = a + b;
|
| 622 |
+
assert(c >= a);
|
| 623 |
+
return c;
|
| 624 |
+
}
|
| 625 |
+
}
|
smart_contract_dataset/block number dependency/103.sol
ADDED
|
@@ -0,0 +1,247 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
pragma solidity ^0.4.24;
|
| 2 |
+
|
| 3 |
+
contract IMigrationContract {
|
| 4 |
+
function migrate(address addr, uint256 nas) returns (bool success);
|
| 5 |
+
}
|
| 6 |
+
|
| 7 |
+
|
| 8 |
+
contract SafeMath {
|
| 9 |
+
|
| 10 |
+
|
| 11 |
+
function safeAdd(uint256 x, uint256 y) internal returns(uint256) {
|
| 12 |
+
uint256 z = x + y;
|
| 13 |
+
assert((z >= x) && (z >= y));
|
| 14 |
+
return z;
|
| 15 |
+
}
|
| 16 |
+
|
| 17 |
+
function safeSubtract(uint256 x, uint256 y) internal returns(uint256) {
|
| 18 |
+
assert(x >= y);
|
| 19 |
+
uint256 z = x - y;
|
| 20 |
+
return z;
|
| 21 |
+
}
|
| 22 |
+
|
| 23 |
+
function safeMult(uint256 x, uint256 y) internal returns(uint256) {
|
| 24 |
+
uint256 z = x * y;
|
| 25 |
+
assert((x == 0)||(z/x == y));
|
| 26 |
+
return z;
|
| 27 |
+
}
|
| 28 |
+
|
| 29 |
+
}
|
| 30 |
+
|
| 31 |
+
contract Token {
|
| 32 |
+
uint256 public totalSupply;
|
| 33 |
+
function balanceOf(address _owner) constant returns (uint256 balance);
|
| 34 |
+
function transfer(address _to, uint256 _value) returns (bool success);
|
| 35 |
+
function transferFrom(address _from, address _to, uint256 _value) returns (bool success);
|
| 36 |
+
function approve(address _spender, uint256 _value) returns (bool success);
|
| 37 |
+
function allowance(address _owner, address _spender) constant returns (uint256 remaining);
|
| 38 |
+
event Transfer(address indexed _from, address indexed _to, uint256 _value);
|
| 39 |
+
event Approval(address indexed _owner, address indexed _spender, uint256 _value);
|
| 40 |
+
}
|
| 41 |
+
|
| 42 |
+
|
| 43 |
+
|
| 44 |
+
contract StandardToken is Token {
|
| 45 |
+
|
| 46 |
+
function transfer(address _to, uint256 _value) returns (bool success) {
|
| 47 |
+
if (balances[msg.sender] >= _value && _value > 0) {
|
| 48 |
+
balances[msg.sender] -= _value;
|
| 49 |
+
balances[_to] += _value;
|
| 50 |
+
Transfer(msg.sender, _to, _value);
|
| 51 |
+
return true;
|
| 52 |
+
} else {
|
| 53 |
+
return false;
|
| 54 |
+
}
|
| 55 |
+
}
|
| 56 |
+
|
| 57 |
+
function transferFrom(address _from, address _to, uint256 _value) returns (bool success) {
|
| 58 |
+
if (balances[_from] >= _value && allowed[_from][msg.sender] >= _value && _value > 0) {
|
| 59 |
+
balances[_to] += _value;
|
| 60 |
+
balances[_from] -= _value;
|
| 61 |
+
allowed[_from][msg.sender] -= _value;
|
| 62 |
+
Transfer(_from, _to, _value);
|
| 63 |
+
return true;
|
| 64 |
+
} else {
|
| 65 |
+
return false;
|
| 66 |
+
}
|
| 67 |
+
}
|
| 68 |
+
|
| 69 |
+
function balanceOf(address _owner) constant returns (uint256 balance) {
|
| 70 |
+
return balances[_owner];
|
| 71 |
+
}
|
| 72 |
+
|
| 73 |
+
function approve(address _spender, uint256 _value) returns (bool success) {
|
| 74 |
+
allowed[msg.sender][_spender] = _value;
|
| 75 |
+
Approval(msg.sender, _spender, _value);
|
| 76 |
+
return true;
|
| 77 |
+
}
|
| 78 |
+
|
| 79 |
+
function allowance(address _owner, address _spender) constant returns (uint256 remaining) {
|
| 80 |
+
return allowed[_owner][_spender];
|
| 81 |
+
}
|
| 82 |
+
|
| 83 |
+
mapping (address => uint256) balances;
|
| 84 |
+
mapping (address => mapping (address => uint256)) allowed;
|
| 85 |
+
}
|
| 86 |
+
|
| 87 |
+
contract EBLLToken is StandardToken, SafeMath {
|
| 88 |
+
|
| 89 |
+
|
| 90 |
+
string public constant name = "易宝链";
|
| 91 |
+
string public constant symbol = "EBL";
|
| 92 |
+
uint256 public constant decimals = 18;
|
| 93 |
+
string public version = "1.0";
|
| 94 |
+
|
| 95 |
+
|
| 96 |
+
address public ethFundDeposit;
|
| 97 |
+
address public newContractAddr;
|
| 98 |
+
|
| 99 |
+
|
| 100 |
+
bool public isFunding;
|
| 101 |
+
uint256 public fundingStartBlock;
|
| 102 |
+
uint256 public fundingStopBlock;
|
| 103 |
+
|
| 104 |
+
uint256 public currentSupply;
|
| 105 |
+
uint256 public tokenRaised = 0;
|
| 106 |
+
uint256 public tokenMigrated = 0;
|
| 107 |
+
uint256 public tokenExchangeRate = 5963;
|
| 108 |
+
|
| 109 |
+
|
| 110 |
+
event AllocateToken(address indexed _to, uint256 _value);
|
| 111 |
+
event IssueToken(address indexed _to, uint256 _value);
|
| 112 |
+
event IncreaseSupply(uint256 _value);
|
| 113 |
+
event DecreaseSupply(uint256 _value);
|
| 114 |
+
event Migrate(address indexed _to, uint256 _value);
|
| 115 |
+
|
| 116 |
+
|
| 117 |
+
function formatDecimals(uint256 _value) internal returns (uint256 ) {
|
| 118 |
+
return _value * 10 ** decimals;
|
| 119 |
+
}
|
| 120 |
+
|
| 121 |
+
|
| 122 |
+
function EBLLToken(
|
| 123 |
+
address _ethFundDeposit,
|
| 124 |
+
uint256 _currentSupply)
|
| 125 |
+
{
|
| 126 |
+
ethFundDeposit = _ethFundDeposit;
|
| 127 |
+
|
| 128 |
+
isFunding = false;
|
| 129 |
+
fundingStartBlock = 0;
|
| 130 |
+
fundingStopBlock = 0;
|
| 131 |
+
|
| 132 |
+
currentSupply = formatDecimals(_currentSupply);
|
| 133 |
+
totalSupply = formatDecimals(1600000000);
|
| 134 |
+
balances[msg.sender] = totalSupply;
|
| 135 |
+
if(currentSupply > totalSupply) throw;
|
| 136 |
+
}
|
| 137 |
+
|
| 138 |
+
modifier isOwner() { require(msg.sender == ethFundDeposit); _; }
|
| 139 |
+
|
| 140 |
+
|
| 141 |
+
function setTokenExchangeRate(uint256 _tokenExchangeRate) isOwner external {
|
| 142 |
+
if (_tokenExchangeRate == 0) throw;
|
| 143 |
+
if (_tokenExchangeRate == tokenExchangeRate) throw;
|
| 144 |
+
|
| 145 |
+
tokenExchangeRate = _tokenExchangeRate;
|
| 146 |
+
}
|
| 147 |
+
|
| 148 |
+
|
| 149 |
+
function increaseSupply (uint256 _value) isOwner external {
|
| 150 |
+
uint256 value = formatDecimals(_value);
|
| 151 |
+
if (value + currentSupply > totalSupply) throw;
|
| 152 |
+
currentSupply = safeAdd(currentSupply, value);
|
| 153 |
+
IncreaseSupply(value);
|
| 154 |
+
}
|
| 155 |
+
|
| 156 |
+
|
| 157 |
+
function decreaseSupply (uint256 _value) isOwner external {
|
| 158 |
+
uint256 value = formatDecimals(_value);
|
| 159 |
+
if (value + tokenRaised > currentSupply) throw;
|
| 160 |
+
|
| 161 |
+
currentSupply = safeSubtract(currentSupply, value);
|
| 162 |
+
DecreaseSupply(value);
|
| 163 |
+
}
|
| 164 |
+
|
| 165 |
+
|
| 166 |
+
function startFunding (uint256 _fundingStartBlock, uint256 _fundingStopBlock) isOwner external {
|
| 167 |
+
if (isFunding) throw;
|
| 168 |
+
if (_fundingStartBlock >= _fundingStopBlock) throw;
|
| 169 |
+
if (block.number >= _fundingStartBlock) throw;
|
| 170 |
+
|
| 171 |
+
fundingStartBlock = _fundingStartBlock;
|
| 172 |
+
fundingStopBlock = _fundingStopBlock;
|
| 173 |
+
isFunding = true;
|
| 174 |
+
}
|
| 175 |
+
|
| 176 |
+
|
| 177 |
+
function stopFunding() isOwner external {
|
| 178 |
+
if (!isFunding) throw;
|
| 179 |
+
isFunding = false;
|
| 180 |
+
}
|
| 181 |
+
|
| 182 |
+
|
| 183 |
+
function setMigrateContract(address _newContractAddr) isOwner external {
|
| 184 |
+
if (_newContractAddr == newContractAddr) throw;
|
| 185 |
+
newContractAddr = _newContractAddr;
|
| 186 |
+
}
|
| 187 |
+
|
| 188 |
+
|
| 189 |
+
function changeOwner(address _newFundDeposit) isOwner() external {
|
| 190 |
+
if (_newFundDeposit == address(0x0)) throw;
|
| 191 |
+
ethFundDeposit = _newFundDeposit;
|
| 192 |
+
}
|
| 193 |
+
|
| 194 |
+
|
| 195 |
+
function migrate() external {
|
| 196 |
+
if(isFunding) throw;
|
| 197 |
+
if(newContractAddr == address(0x0)) throw;
|
| 198 |
+
|
| 199 |
+
uint256 tokens = balances[msg.sender];
|
| 200 |
+
if (tokens == 0) throw;
|
| 201 |
+
|
| 202 |
+
balances[msg.sender] = 0;
|
| 203 |
+
tokenMigrated = safeAdd(tokenMigrated, tokens);
|
| 204 |
+
|
| 205 |
+
IMigrationContract newContract = IMigrationContract(newContractAddr);
|
| 206 |
+
if (!newContract.migrate(msg.sender, tokens)) throw;
|
| 207 |
+
|
| 208 |
+
Migrate(msg.sender, tokens);
|
| 209 |
+
}
|
| 210 |
+
|
| 211 |
+
|
| 212 |
+
function transferETH() isOwner external {
|
| 213 |
+
if (this.balance == 0) throw;
|
| 214 |
+
if (!ethFundDeposit.send(this.balance)) throw;
|
| 215 |
+
}
|
| 216 |
+
|
| 217 |
+
|
| 218 |
+
function allocateToken (address _addr, uint256 _eth) isOwner external {
|
| 219 |
+
if (_eth == 0) throw;
|
| 220 |
+
if (_addr == address(0x0)) throw;
|
| 221 |
+
|
| 222 |
+
uint256 tokens = safeMult(formatDecimals(_eth), tokenExchangeRate);
|
| 223 |
+
if (tokens + tokenRaised > currentSupply) throw;
|
| 224 |
+
|
| 225 |
+
tokenRaised = safeAdd(tokenRaised, tokens);
|
| 226 |
+
balances[_addr] += tokens;
|
| 227 |
+
|
| 228 |
+
AllocateToken(_addr, tokens);
|
| 229 |
+
}
|
| 230 |
+
|
| 231 |
+
|
| 232 |
+
function () payable {
|
| 233 |
+
if (!isFunding) throw;
|
| 234 |
+
if (msg.value == 0) throw;
|
| 235 |
+
|
| 236 |
+
if (block.number < fundingStartBlock) throw;
|
| 237 |
+
if (block.number > fundingStopBlock) throw;
|
| 238 |
+
|
| 239 |
+
uint256 tokens = safeMult(msg.value, tokenExchangeRate);
|
| 240 |
+
if (tokens + tokenRaised > currentSupply) throw;
|
| 241 |
+
|
| 242 |
+
tokenRaised = safeAdd(tokenRaised, tokens);
|
| 243 |
+
balances[msg.sender] += tokens;
|
| 244 |
+
|
| 245 |
+
IssueToken(msg.sender, tokens);
|
| 246 |
+
}
|
| 247 |
+
}
|
smart_contract_dataset/block number dependency/1034.sol
ADDED
|
@@ -0,0 +1,258 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
pragma solidity ^0.4.21;
|
| 2 |
+
|
| 3 |
+
|
| 4 |
+
|
| 5 |
+
|
| 6 |
+
|
| 7 |
+
|
| 8 |
+
contract PoCGame
|
| 9 |
+
{
|
| 10 |
+
|
| 11 |
+
|
| 12 |
+
|
| 13 |
+
modifier onlyOwner()
|
| 14 |
+
{
|
| 15 |
+
require(msg.sender == owner);
|
| 16 |
+
_;
|
| 17 |
+
}
|
| 18 |
+
|
| 19 |
+
modifier isOpenToPublic()
|
| 20 |
+
{
|
| 21 |
+
require(openToPublic);
|
| 22 |
+
_;
|
| 23 |
+
}
|
| 24 |
+
|
| 25 |
+
modifier onlyRealPeople()
|
| 26 |
+
{
|
| 27 |
+
require (msg.sender == tx.origin);
|
| 28 |
+
_;
|
| 29 |
+
}
|
| 30 |
+
|
| 31 |
+
modifier onlyPlayers()
|
| 32 |
+
{
|
| 33 |
+
require (wagers[msg.sender] > 0);
|
| 34 |
+
_;
|
| 35 |
+
}
|
| 36 |
+
|
| 37 |
+
|
| 38 |
+
|
| 39 |
+
event Wager(uint256 amount, address depositer);
|
| 40 |
+
event Win(uint256 amount, address paidTo);
|
| 41 |
+
event Lose(uint256 amount, address loser);
|
| 42 |
+
event Donate(uint256 amount, address paidTo, address donator);
|
| 43 |
+
event DifficultyChanged(uint256 currentDifficulty);
|
| 44 |
+
event BetLimitChanged(uint256 currentBetLimit);
|
| 45 |
+
|
| 46 |
+
|
| 47 |
+
address private whale;
|
| 48 |
+
uint256 betLimit;
|
| 49 |
+
uint difficulty;
|
| 50 |
+
uint private randomSeed;
|
| 51 |
+
address owner;
|
| 52 |
+
mapping(address => uint256) timestamps;
|
| 53 |
+
mapping(address => uint256) wagers;
|
| 54 |
+
bool openToPublic;
|
| 55 |
+
uint256 totalDonated;
|
| 56 |
+
|
| 57 |
+
|
| 58 |
+
constructor(address whaleAddress, uint256 wagerLimit)
|
| 59 |
+
onlyRealPeople()
|
| 60 |
+
public
|
| 61 |
+
{
|
| 62 |
+
openToPublic = false;
|
| 63 |
+
owner = msg.sender;
|
| 64 |
+
whale = whaleAddress;
|
| 65 |
+
totalDonated = 0;
|
| 66 |
+
betLimit = wagerLimit;
|
| 67 |
+
|
| 68 |
+
}
|
| 69 |
+
|
| 70 |
+
|
| 71 |
+
|
| 72 |
+
function OpenToThePublic()
|
| 73 |
+
onlyOwner()
|
| 74 |
+
public
|
| 75 |
+
{
|
| 76 |
+
openToPublic = true;
|
| 77 |
+
}
|
| 78 |
+
|
| 79 |
+
|
| 80 |
+
function AdjustBetAmounts(uint256 amount)
|
| 81 |
+
onlyOwner()
|
| 82 |
+
public
|
| 83 |
+
{
|
| 84 |
+
betLimit = amount;
|
| 85 |
+
|
| 86 |
+
emit BetLimitChanged(betLimit);
|
| 87 |
+
}
|
| 88 |
+
|
| 89 |
+
|
| 90 |
+
function AdjustDifficulty(uint256 amount)
|
| 91 |
+
onlyOwner()
|
| 92 |
+
public
|
| 93 |
+
{
|
| 94 |
+
difficulty = amount;
|
| 95 |
+
|
| 96 |
+
emit DifficultyChanged(difficulty);
|
| 97 |
+
}
|
| 98 |
+
|
| 99 |
+
|
| 100 |
+
function() public payable { }
|
| 101 |
+
|
| 102 |
+
|
| 103 |
+
function wager()
|
| 104 |
+
isOpenToPublic()
|
| 105 |
+
onlyRealPeople()
|
| 106 |
+
payable
|
| 107 |
+
public
|
| 108 |
+
{
|
| 109 |
+
|
| 110 |
+
require(msg.value == betLimit);
|
| 111 |
+
|
| 112 |
+
|
| 113 |
+
require(wagers[msg.sender] == 0);
|
| 114 |
+
|
| 115 |
+
|
| 116 |
+
timestamps[msg.sender] = block.number;
|
| 117 |
+
wagers[msg.sender] = msg.value;
|
| 118 |
+
emit Wager(msg.value, msg.sender);
|
| 119 |
+
}
|
| 120 |
+
|
| 121 |
+
|
| 122 |
+
function play()
|
| 123 |
+
isOpenToPublic()
|
| 124 |
+
onlyRealPeople()
|
| 125 |
+
onlyPlayers()
|
| 126 |
+
public
|
| 127 |
+
{
|
| 128 |
+
uint256 blockNumber = timestamps[msg.sender];
|
| 129 |
+
if(blockNumber < block.number)
|
| 130 |
+
{
|
| 131 |
+
timestamps[msg.sender] = 0;
|
| 132 |
+
wagers[msg.sender] = 0;
|
| 133 |
+
|
| 134 |
+
uint256 winningNumber = uint256(keccak256(abi.encodePacked(blockhash(blockNumber), msg.sender)))%difficulty +1;
|
| 135 |
+
|
| 136 |
+
if(winningNumber == difficulty / 2)
|
| 137 |
+
{
|
| 138 |
+
payout(msg.sender);
|
| 139 |
+
}
|
| 140 |
+
else
|
| 141 |
+
{
|
| 142 |
+
|
| 143 |
+
loseWager(betLimit / 2);
|
| 144 |
+
}
|
| 145 |
+
}
|
| 146 |
+
else
|
| 147 |
+
{
|
| 148 |
+
revert();
|
| 149 |
+
}
|
| 150 |
+
}
|
| 151 |
+
|
| 152 |
+
|
| 153 |
+
function donate()
|
| 154 |
+
isOpenToPublic()
|
| 155 |
+
public
|
| 156 |
+
payable
|
| 157 |
+
{
|
| 158 |
+
donateToWhale(msg.value);
|
| 159 |
+
}
|
| 160 |
+
|
| 161 |
+
|
| 162 |
+
function payout(address winner)
|
| 163 |
+
internal
|
| 164 |
+
{
|
| 165 |
+
uint256 ethToTransfer = address(this).balance / 2;
|
| 166 |
+
|
| 167 |
+
winner.transfer(ethToTransfer);
|
| 168 |
+
emit Win(ethToTransfer, winner);
|
| 169 |
+
}
|
| 170 |
+
|
| 171 |
+
|
| 172 |
+
function donateToWhale(uint256 amount)
|
| 173 |
+
internal
|
| 174 |
+
{
|
| 175 |
+
whale.call.value(amount)(bytes4(keccak256("donate()")));
|
| 176 |
+
totalDonated += amount;
|
| 177 |
+
emit Donate(amount, whale, msg.sender);
|
| 178 |
+
}
|
| 179 |
+
|
| 180 |
+
|
| 181 |
+
function loseWager(uint256 amount)
|
| 182 |
+
internal
|
| 183 |
+
{
|
| 184 |
+
whale.call.value(amount)(bytes4(keccak256("donate()")));
|
| 185 |
+
totalDonated += amount;
|
| 186 |
+
emit Lose(amount, msg.sender);
|
| 187 |
+
}
|
| 188 |
+
|
| 189 |
+
|
| 190 |
+
|
| 191 |
+
function ethBalance()
|
| 192 |
+
public
|
| 193 |
+
view
|
| 194 |
+
returns (uint256)
|
| 195 |
+
{
|
| 196 |
+
return address(this).balance;
|
| 197 |
+
}
|
| 198 |
+
|
| 199 |
+
|
| 200 |
+
|
| 201 |
+
function currentDifficulty()
|
| 202 |
+
public
|
| 203 |
+
view
|
| 204 |
+
returns (uint256)
|
| 205 |
+
{
|
| 206 |
+
return difficulty;
|
| 207 |
+
}
|
| 208 |
+
|
| 209 |
+
|
| 210 |
+
|
| 211 |
+
function currentBetLimit()
|
| 212 |
+
public
|
| 213 |
+
view
|
| 214 |
+
returns (uint256)
|
| 215 |
+
{
|
| 216 |
+
return betLimit;
|
| 217 |
+
}
|
| 218 |
+
|
| 219 |
+
function hasPlayerWagered(address player)
|
| 220 |
+
public
|
| 221 |
+
view
|
| 222 |
+
returns (bool)
|
| 223 |
+
{
|
| 224 |
+
if(wagers[player] > 0)
|
| 225 |
+
{
|
| 226 |
+
return true;
|
| 227 |
+
}
|
| 228 |
+
else
|
| 229 |
+
{
|
| 230 |
+
return false;
|
| 231 |
+
}
|
| 232 |
+
|
| 233 |
+
}
|
| 234 |
+
|
| 235 |
+
|
| 236 |
+
function winnersPot()
|
| 237 |
+
public
|
| 238 |
+
view
|
| 239 |
+
returns (uint256)
|
| 240 |
+
{
|
| 241 |
+
return address(this).balance / 2;
|
| 242 |
+
}
|
| 243 |
+
|
| 244 |
+
|
| 245 |
+
function transferAnyERC20Token(address tokenAddress, address tokenOwner, uint tokens)
|
| 246 |
+
public
|
| 247 |
+
onlyOwner()
|
| 248 |
+
returns (bool success)
|
| 249 |
+
{
|
| 250 |
+
return ERC20Interface(tokenAddress).transfer(tokenOwner, tokens);
|
| 251 |
+
}
|
| 252 |
+
}
|
| 253 |
+
|
| 254 |
+
|
| 255 |
+
contract ERC20Interface
|
| 256 |
+
{
|
| 257 |
+
function transfer(address to, uint256 tokens) public returns (bool success);
|
| 258 |
+
}
|
smart_contract_dataset/block number dependency/1044.sol
ADDED
|
@@ -0,0 +1,255 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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}
|
| 18 |
+
|
| 19 |
+
modifier isOpenToPublic()
|
| 20 |
+
{
|
| 21 |
+
require(openToPublic);
|
| 22 |
+
_;
|
| 23 |
+
}
|
| 24 |
+
|
| 25 |
+
modifier onlyRealPeople()
|
| 26 |
+
{
|
| 27 |
+
require (msg.sender == tx.origin);
|
| 28 |
+
_;
|
| 29 |
+
}
|
| 30 |
+
|
| 31 |
+
modifier onlyPlayers()
|
| 32 |
+
{
|
| 33 |
+
require (wagers[msg.sender] > 0);
|
| 34 |
+
_;
|
| 35 |
+
}
|
| 36 |
+
|
| 37 |
+
|
| 38 |
+
|
| 39 |
+
event Wager(uint256 amount, address depositer);
|
| 40 |
+
event Win(uint256 amount, address paidTo);
|
| 41 |
+
event Lose(uint256 amount, address loser);
|
| 42 |
+
event Donate(uint256 amount, address paidTo, address donator);
|
| 43 |
+
event DifficultyChanged(uint256 currentDifficulty);
|
| 44 |
+
event BetLimitChanged(uint256 currentBetLimit);
|
| 45 |
+
|
| 46 |
+
|
| 47 |
+
address private whale;
|
| 48 |
+
uint256 betLimit;
|
| 49 |
+
uint difficulty;
|
| 50 |
+
uint private randomSeed;
|
| 51 |
+
address owner;
|
| 52 |
+
mapping(address => uint256) timestamps;
|
| 53 |
+
mapping(address => uint256) wagers;
|
| 54 |
+
bool openToPublic;
|
| 55 |
+
uint256 totalDonated;
|
| 56 |
+
|
| 57 |
+
|
| 58 |
+
constructor(address whaleAddress, uint256 wagerLimit)
|
| 59 |
+
onlyRealPeople()
|
| 60 |
+
public
|
| 61 |
+
{
|
| 62 |
+
openToPublic = false;
|
| 63 |
+
owner = msg.sender;
|
| 64 |
+
whale = whaleAddress;
|
| 65 |
+
totalDonated = 0;
|
| 66 |
+
betLimit = wagerLimit;
|
| 67 |
+
|
| 68 |
+
}
|
| 69 |
+
|
| 70 |
+
|
| 71 |
+
|
| 72 |
+
function OpenToThePublic()
|
| 73 |
+
onlyOwner()
|
| 74 |
+
public
|
| 75 |
+
{
|
| 76 |
+
openToPublic = true;
|
| 77 |
+
}
|
| 78 |
+
|
| 79 |
+
|
| 80 |
+
function AdjustBetAmounts(uint256 amount)
|
| 81 |
+
onlyOwner()
|
| 82 |
+
public
|
| 83 |
+
{
|
| 84 |
+
betLimit = amount;
|
| 85 |
+
|
| 86 |
+
emit BetLimitChanged(betLimit);
|
| 87 |
+
}
|
| 88 |
+
|
| 89 |
+
|
| 90 |
+
function AdjustDifficulty(uint256 amount)
|
| 91 |
+
onlyOwner()
|
| 92 |
+
public
|
| 93 |
+
{
|
| 94 |
+
difficulty = amount;
|
| 95 |
+
|
| 96 |
+
emit DifficultyChanged(difficulty);
|
| 97 |
+
}
|
| 98 |
+
|
| 99 |
+
|
| 100 |
+
function() public payable { }
|
| 101 |
+
|
| 102 |
+
|
| 103 |
+
function wager()
|
| 104 |
+
isOpenToPublic()
|
| 105 |
+
onlyRealPeople()
|
| 106 |
+
payable
|
| 107 |
+
public
|
| 108 |
+
{
|
| 109 |
+
|
| 110 |
+
require(msg.value == betLimit);
|
| 111 |
+
|
| 112 |
+
|
| 113 |
+
timestamps[msg.sender] = block.number;
|
| 114 |
+
wagers[msg.sender] = msg.value;
|
| 115 |
+
emit Wager(msg.value, msg.sender);
|
| 116 |
+
}
|
| 117 |
+
|
| 118 |
+
|
| 119 |
+
function play()
|
| 120 |
+
isOpenToPublic()
|
| 121 |
+
onlyRealPeople()
|
| 122 |
+
onlyPlayers()
|
| 123 |
+
public
|
| 124 |
+
{
|
| 125 |
+
uint256 blockNumber = timestamps[msg.sender];
|
| 126 |
+
if(blockNumber < block.number)
|
| 127 |
+
{
|
| 128 |
+
timestamps[msg.sender] = 0;
|
| 129 |
+
wagers[msg.sender] = 0;
|
| 130 |
+
|
| 131 |
+
uint256 winningNumber = uint256(keccak256(abi.encodePacked(blockhash(blockNumber), msg.sender)))%difficulty +1;
|
| 132 |
+
|
| 133 |
+
if(winningNumber == difficulty / 2)
|
| 134 |
+
{
|
| 135 |
+
payout(msg.sender);
|
| 136 |
+
}
|
| 137 |
+
else
|
| 138 |
+
{
|
| 139 |
+
|
| 140 |
+
loseWager(betLimit / 2);
|
| 141 |
+
}
|
| 142 |
+
}
|
| 143 |
+
else
|
| 144 |
+
{
|
| 145 |
+
revert();
|
| 146 |
+
}
|
| 147 |
+
}
|
| 148 |
+
|
| 149 |
+
|
| 150 |
+
function donate()
|
| 151 |
+
isOpenToPublic()
|
| 152 |
+
public
|
| 153 |
+
payable
|
| 154 |
+
{
|
| 155 |
+
donateToWhale(msg.value);
|
| 156 |
+
}
|
| 157 |
+
|
| 158 |
+
|
| 159 |
+
function payout(address winner)
|
| 160 |
+
internal
|
| 161 |
+
{
|
| 162 |
+
uint256 ethToTransfer = address(this).balance / 2;
|
| 163 |
+
|
| 164 |
+
winner.transfer(ethToTransfer);
|
| 165 |
+
emit Win(ethToTransfer, winner);
|
| 166 |
+
}
|
| 167 |
+
|
| 168 |
+
|
| 169 |
+
function donateToWhale(uint256 amount)
|
| 170 |
+
internal
|
| 171 |
+
{
|
| 172 |
+
whale.call.value(amount)(bytes4(keccak256("donate()")));
|
| 173 |
+
totalDonated += amount;
|
| 174 |
+
emit Donate(amount, whale, msg.sender);
|
| 175 |
+
}
|
| 176 |
+
|
| 177 |
+
|
| 178 |
+
function loseWager(uint256 amount)
|
| 179 |
+
internal
|
| 180 |
+
{
|
| 181 |
+
whale.call.value(amount)(bytes4(keccak256("donate()")));
|
| 182 |
+
totalDonated += amount;
|
| 183 |
+
emit Lose(amount, msg.sender);
|
| 184 |
+
}
|
| 185 |
+
|
| 186 |
+
|
| 187 |
+
|
| 188 |
+
function ethBalance()
|
| 189 |
+
public
|
| 190 |
+
view
|
| 191 |
+
returns (uint256)
|
| 192 |
+
{
|
| 193 |
+
return address(this).balance;
|
| 194 |
+
}
|
| 195 |
+
|
| 196 |
+
|
| 197 |
+
|
| 198 |
+
function currentDifficulty()
|
| 199 |
+
public
|
| 200 |
+
view
|
| 201 |
+
returns (uint256)
|
| 202 |
+
{
|
| 203 |
+
return difficulty;
|
| 204 |
+
}
|
| 205 |
+
|
| 206 |
+
|
| 207 |
+
|
| 208 |
+
function currentBetLimit()
|
| 209 |
+
public
|
| 210 |
+
view
|
| 211 |
+
returns (uint256)
|
| 212 |
+
{
|
| 213 |
+
return betLimit;
|
| 214 |
+
}
|
| 215 |
+
|
| 216 |
+
function hasPlayerWagered(address player)
|
| 217 |
+
public
|
| 218 |
+
view
|
| 219 |
+
returns (bool)
|
| 220 |
+
{
|
| 221 |
+
if(wagers[player] > 0)
|
| 222 |
+
{
|
| 223 |
+
return true;
|
| 224 |
+
}
|
| 225 |
+
else
|
| 226 |
+
{
|
| 227 |
+
return false;
|
| 228 |
+
}
|
| 229 |
+
|
| 230 |
+
}
|
| 231 |
+
|
| 232 |
+
|
| 233 |
+
function winnersPot()
|
| 234 |
+
public
|
| 235 |
+
view
|
| 236 |
+
returns (uint256)
|
| 237 |
+
{
|
| 238 |
+
return address(this).balance / 2;
|
| 239 |
+
}
|
| 240 |
+
|
| 241 |
+
|
| 242 |
+
function transferAnyERC20Token(address tokenAddress, address tokenOwner, uint tokens)
|
| 243 |
+
public
|
| 244 |
+
onlyOwner()
|
| 245 |
+
returns (bool success)
|
| 246 |
+
{
|
| 247 |
+
return ERC20Interface(tokenAddress).transfer(tokenOwner, tokens);
|
| 248 |
+
}
|
| 249 |
+
}
|
| 250 |
+
|
| 251 |
+
|
| 252 |
+
contract ERC20Interface
|
| 253 |
+
{
|
| 254 |
+
function transfer(address to, uint256 tokens) public returns (bool success);
|
| 255 |
+
}
|
smart_contract_dataset/block number dependency/1052.sol
ADDED
|
@@ -0,0 +1,625 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
pragma solidity ^0.4.24;
|
| 2 |
+
|
| 3 |
+
|
| 4 |
+
|
| 5 |
+
|
| 6 |
+
contract ZethrTokenBankroll{
|
| 7 |
+
|
| 8 |
+
function gameRequestTokens(address target, uint tokens) public;
|
| 9 |
+
function gameTokenAmount(address what) public returns (uint);
|
| 10 |
+
}
|
| 11 |
+
|
| 12 |
+
|
| 13 |
+
contract ZethrMainBankroll{
|
| 14 |
+
function gameGetTokenBankrollList() public view returns (address[7]);
|
| 15 |
+
}
|
| 16 |
+
|
| 17 |
+
|
| 18 |
+
contract ZethrInterface{
|
| 19 |
+
function withdraw() public;
|
| 20 |
+
}
|
| 21 |
+
|
| 22 |
+
|
| 23 |
+
library ZethrTierLibrary{
|
| 24 |
+
|
| 25 |
+
function getTier(uint divRate) internal pure returns (uint){
|
| 26 |
+
|
| 27 |
+
|
| 28 |
+
|
| 29 |
+
|
| 30 |
+
|
| 31 |
+
uint actualDiv = divRate;
|
| 32 |
+
if (actualDiv >= 30){
|
| 33 |
+
return 6;
|
| 34 |
+
} else if (actualDiv >= 25){
|
| 35 |
+
return 5;
|
| 36 |
+
} else if (actualDiv >= 20){
|
| 37 |
+
return 4;
|
| 38 |
+
} else if (actualDiv >= 15){
|
| 39 |
+
return 3;
|
| 40 |
+
} else if (actualDiv >= 10){
|
| 41 |
+
return 2;
|
| 42 |
+
} else if (actualDiv >= 5){
|
| 43 |
+
return 1;
|
| 44 |
+
} else if (actualDiv >= 2){
|
| 45 |
+
return 0;
|
| 46 |
+
} else{
|
| 47 |
+
|
| 48 |
+
revert();
|
| 49 |
+
}
|
| 50 |
+
}
|
| 51 |
+
}
|
| 52 |
+
|
| 53 |
+
|
| 54 |
+
contract ZlotsJackpotHoldingContract {
|
| 55 |
+
function payOutWinner(address winner) public;
|
| 56 |
+
function getJackpot() public view returns (uint);
|
| 57 |
+
}
|
| 58 |
+
|
| 59 |
+
|
| 60 |
+
contract ZethrBankrollBridge {
|
| 61 |
+
|
| 62 |
+
ZethrInterface Zethr;
|
| 63 |
+
|
| 64 |
+
|
| 65 |
+
|
| 66 |
+
|
| 67 |
+
|
| 68 |
+
address[7] UsedBankrollAddresses;
|
| 69 |
+
|
| 70 |
+
|
| 71 |
+
mapping(address => bool) ValidBankrollAddress;
|
| 72 |
+
|
| 73 |
+
|
| 74 |
+
function setupBankrollInterface(address ZethrMainBankrollAddress) internal {
|
| 75 |
+
|
| 76 |
+
|
| 77 |
+
Zethr = ZethrInterface(0xD48B633045af65fF636F3c6edd744748351E020D);
|
| 78 |
+
|
| 79 |
+
|
| 80 |
+
UsedBankrollAddresses = ZethrMainBankroll(ZethrMainBankrollAddress).gameGetTokenBankrollList();
|
| 81 |
+
for(uint i=0; i<7; i++){
|
| 82 |
+
ValidBankrollAddress[UsedBankrollAddresses[i]] = true;
|
| 83 |
+
}
|
| 84 |
+
}
|
| 85 |
+
|
| 86 |
+
|
| 87 |
+
modifier fromBankroll(){
|
| 88 |
+
require(ValidBankrollAddress[msg.sender], "msg.sender should be a valid bankroll");
|
| 89 |
+
_;
|
| 90 |
+
}
|
| 91 |
+
|
| 92 |
+
|
| 93 |
+
|
| 94 |
+
function RequestBankrollPayment(address to, uint tokens, uint tier) internal {
|
| 95 |
+
address tokenBankrollAddress = UsedBankrollAddresses[tier];
|
| 96 |
+
ZethrTokenBankroll(tokenBankrollAddress).gameRequestTokens(to, tokens);
|
| 97 |
+
}
|
| 98 |
+
|
| 99 |
+
function getZethrTokenBankroll(uint divRate) public constant returns (ZethrTokenBankroll){
|
| 100 |
+
return ZethrTokenBankroll(UsedBankrollAddresses[ZethrTierLibrary.getTier(divRate)]);
|
| 101 |
+
}
|
| 102 |
+
}
|
| 103 |
+
|
| 104 |
+
|
| 105 |
+
contract ZethrShell is ZethrBankrollBridge {
|
| 106 |
+
|
| 107 |
+
|
| 108 |
+
function WithdrawToBankroll() public {
|
| 109 |
+
address(UsedBankrollAddresses[0]).transfer(address(this).balance);
|
| 110 |
+
}
|
| 111 |
+
|
| 112 |
+
|
| 113 |
+
function WithdrawAndTransferToBankroll() public {
|
| 114 |
+
Zethr.withdraw();
|
| 115 |
+
WithdrawToBankroll();
|
| 116 |
+
}
|
| 117 |
+
}
|
| 118 |
+
|
| 119 |
+
|
| 120 |
+
|
| 121 |
+
contract Zlots is ZethrShell {
|
| 122 |
+
using SafeMath for uint;
|
| 123 |
+
|
| 124 |
+
|
| 125 |
+
|
| 126 |
+
|
| 127 |
+
event HouseRetrievedTake(
|
| 128 |
+
uint timeTaken,
|
| 129 |
+
uint tokensWithdrawn
|
| 130 |
+
);
|
| 131 |
+
|
| 132 |
+
|
| 133 |
+
event TokensWagered(
|
| 134 |
+
address _wagerer,
|
| 135 |
+
uint _wagered
|
| 136 |
+
);
|
| 137 |
+
|
| 138 |
+
event LogResult(
|
| 139 |
+
address _wagerer,
|
| 140 |
+
uint _result,
|
| 141 |
+
uint _profit,
|
| 142 |
+
uint _wagered,
|
| 143 |
+
uint _category,
|
| 144 |
+
bool _win
|
| 145 |
+
);
|
| 146 |
+
|
| 147 |
+
|
| 148 |
+
event Loss(address _wagerer, uint _block);
|
| 149 |
+
event ThreeMoonJackpot(address _wagerer, uint _block);
|
| 150 |
+
event TwoMoonPrize(address _wagerer, uint _block);
|
| 151 |
+
event ZTHPrize(address _wagerer, uint _block);
|
| 152 |
+
event ThreeZSymbols(address _wagerer, uint _block);
|
| 153 |
+
event ThreeTSymbols(address _wagerer, uint _block);
|
| 154 |
+
event ThreeHSymbols(address _wagerer, uint _block);
|
| 155 |
+
event ThreeEtherIcons(address _wagerer, uint _block);
|
| 156 |
+
event ThreePurplePyramids(address _wagerer, uint _block);
|
| 157 |
+
event ThreeGoldPyramids(address _wagerer, uint _block);
|
| 158 |
+
event ThreeRockets(address _wagerer, uint _block);
|
| 159 |
+
event OneMoonPrize(address _wagerer, uint _block);
|
| 160 |
+
event OneOfEachPyramidPrize(address _wagerer, uint _block);
|
| 161 |
+
event TwoZSymbols(address _wagerer, uint _block);
|
| 162 |
+
event TwoTSymbols(address _wagerer, uint _block);
|
| 163 |
+
event TwoHSymbols(address _wagerer, uint _block);
|
| 164 |
+
event TwoEtherIcons(address _wagerer, uint _block);
|
| 165 |
+
event TwoPurplePyramids(address _wagerer, uint _block);
|
| 166 |
+
event TwoGoldPyramids(address _wagerer, uint _block);
|
| 167 |
+
event TwoRockets(address _wagerer, uint _block);
|
| 168 |
+
event SpinConcluded(address _wagerer, uint _block);
|
| 169 |
+
|
| 170 |
+
|
| 171 |
+
|
| 172 |
+
|
| 173 |
+
|
| 174 |
+
modifier betIsValid(uint _betSize, uint divRate) {
|
| 175 |
+
require(_betSize.mul(100) <= getMaxProfit(divRate));
|
| 176 |
+
_;
|
| 177 |
+
}
|
| 178 |
+
|
| 179 |
+
|
| 180 |
+
modifier gameIsActive {
|
| 181 |
+
require(gamePaused == false);
|
| 182 |
+
_;
|
| 183 |
+
}
|
| 184 |
+
|
| 185 |
+
|
| 186 |
+
modifier onlyOwner {
|
| 187 |
+
require(msg.sender == owner);
|
| 188 |
+
_;
|
| 189 |
+
}
|
| 190 |
+
|
| 191 |
+
|
| 192 |
+
modifier onlyBankroll {
|
| 193 |
+
require(msg.sender == bankroll);
|
| 194 |
+
_;
|
| 195 |
+
}
|
| 196 |
+
|
| 197 |
+
|
| 198 |
+
modifier onlyOwnerOrBankroll {
|
| 199 |
+
require(msg.sender == owner || msg.sender == bankroll);
|
| 200 |
+
_;
|
| 201 |
+
}
|
| 202 |
+
|
| 203 |
+
|
| 204 |
+
|
| 205 |
+
|
| 206 |
+
uint constant public maxProfitDivisor = 1000000;
|
| 207 |
+
uint constant public houseEdgeDivisor = 1000;
|
| 208 |
+
mapping (uint => uint) public maxProfit;
|
| 209 |
+
uint public maxProfitAsPercentOfHouse;
|
| 210 |
+
uint public minBet = 1e18;
|
| 211 |
+
address public zlotsJackpot;
|
| 212 |
+
address private owner;
|
| 213 |
+
address private bankroll;
|
| 214 |
+
bool gamePaused;
|
| 215 |
+
|
| 216 |
+
|
| 217 |
+
uint public totalSpins;
|
| 218 |
+
uint public totalZTHWagered;
|
| 219 |
+
mapping (uint => uint) public contractBalance;
|
| 220 |
+
|
| 221 |
+
|
| 222 |
+
bool public gameActive;
|
| 223 |
+
|
| 224 |
+
address private ZTHTKNADDR;
|
| 225 |
+
address private ZTHBANKROLL;
|
| 226 |
+
|
| 227 |
+
|
| 228 |
+
|
| 229 |
+
|
| 230 |
+
constructor(address BankrollAddress) public {
|
| 231 |
+
|
| 232 |
+
setupBankrollInterface(BankrollAddress);
|
| 233 |
+
|
| 234 |
+
|
| 235 |
+
owner = msg.sender;
|
| 236 |
+
|
| 237 |
+
|
| 238 |
+
ownerSetMaxProfitAsPercentOfHouse(50000);
|
| 239 |
+
|
| 240 |
+
|
| 241 |
+
bankroll = ZTHBANKROLL;
|
| 242 |
+
gameActive = true;
|
| 243 |
+
|
| 244 |
+
|
| 245 |
+
ownerSetMinBet(1e18);
|
| 246 |
+
}
|
| 247 |
+
|
| 248 |
+
|
| 249 |
+
function() public payable { }
|
| 250 |
+
|
| 251 |
+
|
| 252 |
+
struct TKN { address sender; uint value; }
|
| 253 |
+
function execute(address _from, uint _value, uint divRate, bytes ) public fromBankroll returns (bool){
|
| 254 |
+
TKN memory _tkn;
|
| 255 |
+
_tkn.sender = _from;
|
| 256 |
+
_tkn.value = _value;
|
| 257 |
+
_spinTokens(_tkn, divRate);
|
| 258 |
+
return true;
|
| 259 |
+
}
|
| 260 |
+
|
| 261 |
+
struct playerSpin {
|
| 262 |
+
uint200 tokenValue;
|
| 263 |
+
uint48 blockn;
|
| 264 |
+
uint8 tier;
|
| 265 |
+
uint divRate;
|
| 266 |
+
}
|
| 267 |
+
|
| 268 |
+
|
| 269 |
+
mapping(address => playerSpin) public playerSpins;
|
| 270 |
+
|
| 271 |
+
|
| 272 |
+
function _spinTokens(TKN _tkn, uint divRate)
|
| 273 |
+
private
|
| 274 |
+
betIsValid(_tkn.value, divRate)
|
| 275 |
+
{
|
| 276 |
+
|
| 277 |
+
require(gameActive);
|
| 278 |
+
require(block.number < ((2 ** 56) - 1));
|
| 279 |
+
|
| 280 |
+
address _customerAddress = _tkn.sender;
|
| 281 |
+
uint _wagered = _tkn.value;
|
| 282 |
+
|
| 283 |
+
playerSpin memory spin = playerSpins[_tkn.sender];
|
| 284 |
+
|
| 285 |
+
|
| 286 |
+
|
| 287 |
+
|
| 288 |
+
addContractBalance(divRate, _wagered);
|
| 289 |
+
|
| 290 |
+
|
| 291 |
+
require(block.number != spin.blockn);
|
| 292 |
+
|
| 293 |
+
|
| 294 |
+
if (spin.blockn != 0) {
|
| 295 |
+
_finishSpin(_tkn.sender);
|
| 296 |
+
}
|
| 297 |
+
|
| 298 |
+
|
| 299 |
+
spin.blockn = uint48(block.number);
|
| 300 |
+
spin.tokenValue = uint200(_wagered);
|
| 301 |
+
spin.tier = uint8(ZethrTierLibrary.getTier(divRate));
|
| 302 |
+
spin.divRate = divRate;
|
| 303 |
+
|
| 304 |
+
|
| 305 |
+
playerSpins[_tkn.sender] = spin;
|
| 306 |
+
|
| 307 |
+
|
| 308 |
+
totalSpins += 1;
|
| 309 |
+
|
| 310 |
+
|
| 311 |
+
totalZTHWagered += _wagered;
|
| 312 |
+
|
| 313 |
+
emit TokensWagered(_customerAddress, _wagered);
|
| 314 |
+
}
|
| 315 |
+
|
| 316 |
+
|
| 317 |
+
function finishSpin() public
|
| 318 |
+
gameIsActive
|
| 319 |
+
returns (uint)
|
| 320 |
+
{
|
| 321 |
+
return _finishSpin(msg.sender);
|
| 322 |
+
}
|
| 323 |
+
|
| 324 |
+
|
| 325 |
+
function _finishSpin(address target)
|
| 326 |
+
private returns (uint)
|
| 327 |
+
{
|
| 328 |
+
playerSpin memory spin = playerSpins[target];
|
| 329 |
+
|
| 330 |
+
require(spin.tokenValue > 0);
|
| 331 |
+
require(spin.blockn != block.number);
|
| 332 |
+
|
| 333 |
+
uint profit = 0;
|
| 334 |
+
uint category = 0;
|
| 335 |
+
uint playerDivrate = spin.divRate;
|
| 336 |
+
|
| 337 |
+
|
| 338 |
+
|
| 339 |
+
uint result;
|
| 340 |
+
if (block.number - spin.blockn > 255) {
|
| 341 |
+
result = 1000000;
|
| 342 |
+
} else {
|
| 343 |
+
|
| 344 |
+
|
| 345 |
+
|
| 346 |
+
result = random(1000000, spin.blockn, target) + 1;
|
| 347 |
+
}
|
| 348 |
+
|
| 349 |
+
if (result > 506856) {
|
| 350 |
+
|
| 351 |
+
|
| 352 |
+
|
| 353 |
+
|
| 354 |
+
RequestBankrollPayment(zlotsJackpot, spin.tokenValue / 100, tier);
|
| 355 |
+
|
| 356 |
+
|
| 357 |
+
playerSpins[target] = playerSpin(uint200(0), uint48(0), uint8(0), uint(0));
|
| 358 |
+
|
| 359 |
+
emit Loss(target, spin.blockn);
|
| 360 |
+
emit LogResult(target, result, profit, spin.tokenValue, category, false);
|
| 361 |
+
} else if (result < 2) {
|
| 362 |
+
|
| 363 |
+
|
| 364 |
+
|
| 365 |
+
profit = ZlotsJackpotHoldingContract(zlotsJackpot).getJackpot();
|
| 366 |
+
category = 1;
|
| 367 |
+
|
| 368 |
+
|
| 369 |
+
emit ThreeMoonJackpot(target, spin.blockn);
|
| 370 |
+
emit LogResult(target, result, profit, spin.tokenValue, category, true);
|
| 371 |
+
|
| 372 |
+
|
| 373 |
+
uint8 tier = spin.tier;
|
| 374 |
+
|
| 375 |
+
|
| 376 |
+
playerSpins[target] = playerSpin(uint200(0), uint48(0), uint8(0), uint(0));
|
| 377 |
+
|
| 378 |
+
|
| 379 |
+
ZlotsJackpotHoldingContract(zlotsJackpot).payOutWinner(target);
|
| 380 |
+
} else {
|
| 381 |
+
if (result < 299) {
|
| 382 |
+
|
| 383 |
+
profit = SafeMath.mul(spin.tokenValue, 50);
|
| 384 |
+
category = 2;
|
| 385 |
+
emit TwoMoonPrize(target, spin.blockn);
|
| 386 |
+
} else if (result < 3128) {
|
| 387 |
+
|
| 388 |
+
profit = SafeMath.mul(spin.tokenValue, 20);
|
| 389 |
+
category = 3;
|
| 390 |
+
emit ZTHPrize(target, spin.blockn);
|
| 391 |
+
} else if (result < 16961) {
|
| 392 |
+
|
| 393 |
+
profit = SafeMath.div(SafeMath.mul(spin.tokenValue, 30), 10);
|
| 394 |
+
category = 4;
|
| 395 |
+
emit ThreeZSymbols(target, spin.blockn);
|
| 396 |
+
} else if (result < 30794) {
|
| 397 |
+
|
| 398 |
+
profit = SafeMath.div(SafeMath.mul(spin.tokenValue, 30), 10);
|
| 399 |
+
category = 5;
|
| 400 |
+
emit ThreeTSymbols(target, spin.blockn);
|
| 401 |
+
} else if (result < 44627) {
|
| 402 |
+
|
| 403 |
+
profit = SafeMath.div(SafeMath.mul(spin.tokenValue, 30), 10);
|
| 404 |
+
category = 6;
|
| 405 |
+
emit ThreeHSymbols(target, spin.blockn);
|
| 406 |
+
} else if (result < 46627) {
|
| 407 |
+
|
| 408 |
+
profit = SafeMath.mul(spin.tokenValue, 11);
|
| 409 |
+
category = 7;
|
| 410 |
+
emit ThreeEtherIcons(target, spin.blockn);
|
| 411 |
+
} else if (result < 49127) {
|
| 412 |
+
|
| 413 |
+
profit = SafeMath.div(SafeMath.mul(spin.tokenValue, 75), 10);
|
| 414 |
+
category = 8;
|
| 415 |
+
emit ThreePurplePyramids(target, spin.blockn);
|
| 416 |
+
} else if (result < 51627) {
|
| 417 |
+
|
| 418 |
+
profit = SafeMath.mul(spin.tokenValue, 9);
|
| 419 |
+
category = 9;
|
| 420 |
+
emit ThreeGoldPyramids(target, spin.blockn);
|
| 421 |
+
} else if (result < 53127) {
|
| 422 |
+
|
| 423 |
+
profit = SafeMath.mul(spin.tokenValue, 13);
|
| 424 |
+
category = 10;
|
| 425 |
+
emit ThreeRockets(target, spin.blockn);
|
| 426 |
+
} else if (result < 82530) {
|
| 427 |
+
|
| 428 |
+
profit = SafeMath.div(SafeMath.mul(spin.tokenValue, 25),10);
|
| 429 |
+
category = 11;
|
| 430 |
+
emit OneMoonPrize(target, spin.blockn);
|
| 431 |
+
} else if (result < 150423) {
|
| 432 |
+
|
| 433 |
+
profit = SafeMath.div(SafeMath.mul(spin.tokenValue, 15),10);
|
| 434 |
+
category = 12;
|
| 435 |
+
emit OneOfEachPyramidPrize(target, spin.blockn);
|
| 436 |
+
} else if (result < 203888) {
|
| 437 |
+
|
| 438 |
+
profit = spin.tokenValue;
|
| 439 |
+
category = 13;
|
| 440 |
+
emit TwoZSymbols(target, spin.blockn);
|
| 441 |
+
} else if (result < 257353) {
|
| 442 |
+
|
| 443 |
+
profit = spin.tokenValue;
|
| 444 |
+
category = 14;
|
| 445 |
+
emit TwoTSymbols(target, spin.blockn);
|
| 446 |
+
} else if (result < 310818) {
|
| 447 |
+
|
| 448 |
+
profit = spin.tokenValue;
|
| 449 |
+
category = 15;
|
| 450 |
+
emit TwoHSymbols(target, spin.blockn);
|
| 451 |
+
} else if (result < 364283) {
|
| 452 |
+
|
| 453 |
+
profit = SafeMath.mul(spin.tokenValue, 2);
|
| 454 |
+
category = 16;
|
| 455 |
+
emit TwoEtherIcons(target, spin.blockn);
|
| 456 |
+
} else if (result < 417748) {
|
| 457 |
+
|
| 458 |
+
profit = SafeMath.div(SafeMath.mul(spin.tokenValue, 125), 100);
|
| 459 |
+
category = 17;
|
| 460 |
+
emit TwoPurplePyramids(target, spin.blockn);
|
| 461 |
+
} else if (result < 471213) {
|
| 462 |
+
|
| 463 |
+
profit = SafeMath.div(SafeMath.mul(spin.tokenValue, 133), 100);
|
| 464 |
+
category = 18;
|
| 465 |
+
emit TwoGoldPyramids(target, spin.blockn);
|
| 466 |
+
} else {
|
| 467 |
+
|
| 468 |
+
profit = SafeMath.div(SafeMath.mul(spin.tokenValue, 25), 10);
|
| 469 |
+
category = 19;
|
| 470 |
+
emit TwoRockets(target, spin.blockn);
|
| 471 |
+
}
|
| 472 |
+
|
| 473 |
+
|
| 474 |
+
subContractBalance(playerDivrate, profit);
|
| 475 |
+
|
| 476 |
+
emit LogResult(target, result, profit, spin.tokenValue, category, true);
|
| 477 |
+
tier = spin.tier;
|
| 478 |
+
playerSpins[target] = playerSpin(uint200(0), uint48(0), uint8(0), uint(0));
|
| 479 |
+
RequestBankrollPayment(target, profit, tier);
|
| 480 |
+
}
|
| 481 |
+
|
| 482 |
+
emit SpinConcluded(target, spin.blockn);
|
| 483 |
+
return result;
|
| 484 |
+
}
|
| 485 |
+
|
| 486 |
+
|
| 487 |
+
|
| 488 |
+
function maxRandom(uint blockn, address entropy) private view returns (uint256 randomNumber) {
|
| 489 |
+
return uint256(keccak256(
|
| 490 |
+
abi.encodePacked(
|
| 491 |
+
|
| 492 |
+
blockhash(blockn),
|
| 493 |
+
entropy)
|
| 494 |
+
));
|
| 495 |
+
}
|
| 496 |
+
|
| 497 |
+
|
| 498 |
+
function random(uint256 upper, uint256 blockn, address entropy) internal view returns (uint256 randomNumber) {
|
| 499 |
+
return maxRandom(blockn, entropy) % upper;
|
| 500 |
+
}
|
| 501 |
+
|
| 502 |
+
|
| 503 |
+
function setMaxProfit(uint divRate) internal {
|
| 504 |
+
maxProfit[divRate] = (contractBalance[divRate] * maxProfitAsPercentOfHouse) / maxProfitDivisor;
|
| 505 |
+
}
|
| 506 |
+
|
| 507 |
+
|
| 508 |
+
function getMaxProfit(uint divRate) public view returns (uint) {
|
| 509 |
+
return (contractBalance[divRate] * maxProfitAsPercentOfHouse) / maxProfitDivisor;
|
| 510 |
+
}
|
| 511 |
+
|
| 512 |
+
|
| 513 |
+
function subContractBalance(uint divRate, uint sub) internal {
|
| 514 |
+
contractBalance[divRate] = contractBalance[divRate].sub(sub);
|
| 515 |
+
}
|
| 516 |
+
|
| 517 |
+
|
| 518 |
+
function addContractBalance(uint divRate, uint add) internal {
|
| 519 |
+
contractBalance[divRate] = contractBalance[divRate].add(add);
|
| 520 |
+
}
|
| 521 |
+
|
| 522 |
+
|
| 523 |
+
|
| 524 |
+
|
| 525 |
+
function bankrollExternalUpdateTokens(uint divRate, uint newBalance)
|
| 526 |
+
public
|
| 527 |
+
fromBankroll
|
| 528 |
+
{
|
| 529 |
+
contractBalance[divRate] = newBalance;
|
| 530 |
+
setMaxProfit(divRate);
|
| 531 |
+
}
|
| 532 |
+
|
| 533 |
+
|
| 534 |
+
|
| 535 |
+
function ownerSetMaxProfitAsPercentOfHouse(uint newMaxProfitAsPercent) public
|
| 536 |
+
onlyOwner
|
| 537 |
+
{
|
| 538 |
+
|
| 539 |
+
require(newMaxProfitAsPercent <= 500000);
|
| 540 |
+
maxProfitAsPercentOfHouse = newMaxProfitAsPercent;
|
| 541 |
+
setMaxProfit(2);
|
| 542 |
+
setMaxProfit(5);
|
| 543 |
+
setMaxProfit(10);
|
| 544 |
+
setMaxProfit(15);
|
| 545 |
+
setMaxProfit(20);
|
| 546 |
+
setMaxProfit(25);
|
| 547 |
+
setMaxProfit(33);
|
| 548 |
+
}
|
| 549 |
+
|
| 550 |
+
|
| 551 |
+
function ownerSetMinBet(uint newMinimumBet) public
|
| 552 |
+
onlyOwner
|
| 553 |
+
{
|
| 554 |
+
minBet = newMinimumBet;
|
| 555 |
+
}
|
| 556 |
+
|
| 557 |
+
|
| 558 |
+
function ownerSetZlotsAddress(address zlotsAddress) public
|
| 559 |
+
onlyOwner
|
| 560 |
+
{
|
| 561 |
+
zlotsJackpot = zlotsAddress;
|
| 562 |
+
}
|
| 563 |
+
|
| 564 |
+
|
| 565 |
+
function pauseGame() public onlyOwnerOrBankroll {
|
| 566 |
+
gameActive = false;
|
| 567 |
+
}
|
| 568 |
+
|
| 569 |
+
|
| 570 |
+
function resumeGame() public onlyOwnerOrBankroll {
|
| 571 |
+
gameActive = true;
|
| 572 |
+
}
|
| 573 |
+
|
| 574 |
+
|
| 575 |
+
function changeOwner(address _newOwner) public onlyOwnerOrBankroll {
|
| 576 |
+
owner = _newOwner;
|
| 577 |
+
}
|
| 578 |
+
|
| 579 |
+
|
| 580 |
+
function changeBankroll(address _newBankroll) public onlyOwnerOrBankroll {
|
| 581 |
+
bankroll = _newBankroll;
|
| 582 |
+
}
|
| 583 |
+
|
| 584 |
+
|
| 585 |
+
function _zthToken(address _tokenContract) private view returns (bool) {
|
| 586 |
+
return _tokenContract == ZTHTKNADDR;
|
| 587 |
+
}
|
| 588 |
+
}
|
| 589 |
+
|
| 590 |
+
|
| 591 |
+
|
| 592 |
+
|
| 593 |
+
library SafeMath {
|
| 594 |
+
|
| 595 |
+
|
| 596 |
+
function mul(uint a, uint b) internal pure returns (uint) {
|
| 597 |
+
if (a == 0) {
|
| 598 |
+
return 0;
|
| 599 |
+
}
|
| 600 |
+
uint c = a * b;
|
| 601 |
+
assert(c / a == b);
|
| 602 |
+
return c;
|
| 603 |
+
}
|
| 604 |
+
|
| 605 |
+
|
| 606 |
+
function div(uint a, uint b) internal pure returns (uint) {
|
| 607 |
+
|
| 608 |
+
uint c = a / b;
|
| 609 |
+
|
| 610 |
+
return c;
|
| 611 |
+
}
|
| 612 |
+
|
| 613 |
+
|
| 614 |
+
function sub(uint a, uint b) internal pure returns (uint) {
|
| 615 |
+
assert(b <= a);
|
| 616 |
+
return a - b;
|
| 617 |
+
}
|
| 618 |
+
|
| 619 |
+
|
| 620 |
+
function add(uint a, uint b) internal pure returns (uint) {
|
| 621 |
+
uint c = a + b;
|
| 622 |
+
assert(c >= a);
|
| 623 |
+
return c;
|
| 624 |
+
}
|
| 625 |
+
}
|
smart_contract_dataset/block number dependency/1056.sol
ADDED
|
@@ -0,0 +1,619 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
pragma solidity ^0.4.24;
|
| 2 |
+
|
| 3 |
+
|
| 4 |
+
|
| 5 |
+
|
| 6 |
+
contract ZethrTokenBankroll{
|
| 7 |
+
|
| 8 |
+
function gameRequestTokens(address target, uint tokens) public;
|
| 9 |
+
function gameTokenAmount(address what) public returns (uint);
|
| 10 |
+
}
|
| 11 |
+
|
| 12 |
+
|
| 13 |
+
contract ZethrMainBankroll{
|
| 14 |
+
function gameGetTokenBankrollList() public view returns (address[7]);
|
| 15 |
+
}
|
| 16 |
+
|
| 17 |
+
|
| 18 |
+
contract ZethrInterface{
|
| 19 |
+
function withdraw() public;
|
| 20 |
+
}
|
| 21 |
+
|
| 22 |
+
|
| 23 |
+
library ZethrTierLibrary{
|
| 24 |
+
|
| 25 |
+
function getTier(uint divRate) internal pure returns (uint){
|
| 26 |
+
|
| 27 |
+
|
| 28 |
+
|
| 29 |
+
|
| 30 |
+
|
| 31 |
+
uint actualDiv = divRate;
|
| 32 |
+
if (actualDiv >= 30){
|
| 33 |
+
return 6;
|
| 34 |
+
} else if (actualDiv >= 25){
|
| 35 |
+
return 5;
|
| 36 |
+
} else if (actualDiv >= 20){
|
| 37 |
+
return 4;
|
| 38 |
+
} else if (actualDiv >= 15){
|
| 39 |
+
return 3;
|
| 40 |
+
} else if (actualDiv >= 10){
|
| 41 |
+
return 2;
|
| 42 |
+
} else if (actualDiv >= 5){
|
| 43 |
+
return 1;
|
| 44 |
+
} else if (actualDiv >= 2){
|
| 45 |
+
return 0;
|
| 46 |
+
} else{
|
| 47 |
+
|
| 48 |
+
revert();
|
| 49 |
+
}
|
| 50 |
+
}
|
| 51 |
+
}
|
| 52 |
+
|
| 53 |
+
|
| 54 |
+
contract ZlotsJackpotHoldingContract {
|
| 55 |
+
function payOutWinner(address winner) public;
|
| 56 |
+
function getJackpot() public view returns (uint);
|
| 57 |
+
}
|
| 58 |
+
|
| 59 |
+
|
| 60 |
+
contract ZethrBankrollBridge {
|
| 61 |
+
|
| 62 |
+
ZethrInterface Zethr;
|
| 63 |
+
|
| 64 |
+
|
| 65 |
+
|
| 66 |
+
|
| 67 |
+
|
| 68 |
+
address[7] UsedBankrollAddresses;
|
| 69 |
+
|
| 70 |
+
|
| 71 |
+
mapping(address => bool) ValidBankrollAddress;
|
| 72 |
+
|
| 73 |
+
|
| 74 |
+
function setupBankrollInterface(address ZethrMainBankrollAddress) internal {
|
| 75 |
+
|
| 76 |
+
|
| 77 |
+
Zethr = ZethrInterface(0xD48B633045af65fF636F3c6edd744748351E020D);
|
| 78 |
+
|
| 79 |
+
|
| 80 |
+
UsedBankrollAddresses = ZethrMainBankroll(ZethrMainBankrollAddress).gameGetTokenBankrollList();
|
| 81 |
+
for(uint i=0; i<7; i++){
|
| 82 |
+
ValidBankrollAddress[UsedBankrollAddresses[i]] = true;
|
| 83 |
+
}
|
| 84 |
+
}
|
| 85 |
+
|
| 86 |
+
|
| 87 |
+
modifier fromBankroll(){
|
| 88 |
+
require(ValidBankrollAddress[msg.sender], "msg.sender should be a valid bankroll");
|
| 89 |
+
_;
|
| 90 |
+
}
|
| 91 |
+
|
| 92 |
+
|
| 93 |
+
|
| 94 |
+
function RequestBankrollPayment(address to, uint tokens, uint tier) internal {
|
| 95 |
+
address tokenBankrollAddress = UsedBankrollAddresses[tier];
|
| 96 |
+
ZethrTokenBankroll(tokenBankrollAddress).gameRequestTokens(to, tokens);
|
| 97 |
+
}
|
| 98 |
+
|
| 99 |
+
function getZethrTokenBankroll(uint divRate) public constant returns (ZethrTokenBankroll){
|
| 100 |
+
return ZethrTokenBankroll(UsedBankrollAddresses[ZethrTierLibrary.getTier(divRate)]);
|
| 101 |
+
}
|
| 102 |
+
}
|
| 103 |
+
|
| 104 |
+
|
| 105 |
+
contract ZethrShell is ZethrBankrollBridge {
|
| 106 |
+
|
| 107 |
+
|
| 108 |
+
function WithdrawToBankroll() public {
|
| 109 |
+
address(UsedBankrollAddresses[0]).transfer(address(this).balance);
|
| 110 |
+
}
|
| 111 |
+
|
| 112 |
+
|
| 113 |
+
function WithdrawAndTransferToBankroll() public {
|
| 114 |
+
Zethr.withdraw();
|
| 115 |
+
WithdrawToBankroll();
|
| 116 |
+
}
|
| 117 |
+
}
|
| 118 |
+
|
| 119 |
+
|
| 120 |
+
|
| 121 |
+
contract Zlots is ZethrShell {
|
| 122 |
+
using SafeMath for uint;
|
| 123 |
+
|
| 124 |
+
|
| 125 |
+
|
| 126 |
+
|
| 127 |
+
event HouseRetrievedTake(
|
| 128 |
+
uint timeTaken,
|
| 129 |
+
uint tokensWithdrawn
|
| 130 |
+
);
|
| 131 |
+
|
| 132 |
+
|
| 133 |
+
event TokensWagered(
|
| 134 |
+
address _wagerer,
|
| 135 |
+
uint _wagered
|
| 136 |
+
);
|
| 137 |
+
|
| 138 |
+
event LogResult(
|
| 139 |
+
address _wagerer,
|
| 140 |
+
uint _result,
|
| 141 |
+
uint _profit,
|
| 142 |
+
uint _wagered,
|
| 143 |
+
uint _category,
|
| 144 |
+
bool _win
|
| 145 |
+
);
|
| 146 |
+
|
| 147 |
+
|
| 148 |
+
event Loss(address _wagerer, uint _block);
|
| 149 |
+
event ThreeMoonJackpot(address _wagerer, uint _block);
|
| 150 |
+
event TwoMoonPrize(address _wagerer, uint _block);
|
| 151 |
+
event ZTHPrize(address _wagerer, uint _block);
|
| 152 |
+
event ThreeZSymbols(address _wagerer, uint _block);
|
| 153 |
+
event ThreeTSymbols(address _wagerer, uint _block);
|
| 154 |
+
event ThreeHSymbols(address _wagerer, uint _block);
|
| 155 |
+
event ThreeEtherIcons(address _wagerer, uint _block);
|
| 156 |
+
event ThreePurplePyramids(address _wagerer, uint _block);
|
| 157 |
+
event ThreeGoldPyramids(address _wagerer, uint _block);
|
| 158 |
+
event ThreeRockets(address _wagerer, uint _block);
|
| 159 |
+
event OneMoonPrize(address _wagerer, uint _block);
|
| 160 |
+
event OneOfEachPyramidPrize(address _wagerer, uint _block);
|
| 161 |
+
event TwoZSymbols(address _wagerer, uint _block);
|
| 162 |
+
event TwoTSymbols(address _wagerer, uint _block);
|
| 163 |
+
event TwoHSymbols(address _wagerer, uint _block);
|
| 164 |
+
event TwoEtherIcons(address _wagerer, uint _block);
|
| 165 |
+
event TwoPurplePyramids(address _wagerer, uint _block);
|
| 166 |
+
event TwoGoldPyramids(address _wagerer, uint _block);
|
| 167 |
+
event TwoRockets(address _wagerer, uint _block);
|
| 168 |
+
event SpinConcluded(address _wagerer, uint _block);
|
| 169 |
+
|
| 170 |
+
|
| 171 |
+
|
| 172 |
+
|
| 173 |
+
|
| 174 |
+
modifier betIsValid(uint _betSize, uint divRate) {
|
| 175 |
+
require(_betSize.mul(100) <= getMaxProfit(divRate));
|
| 176 |
+
_;
|
| 177 |
+
}
|
| 178 |
+
|
| 179 |
+
|
| 180 |
+
modifier gameIsActive {
|
| 181 |
+
require(gamePaused == false);
|
| 182 |
+
_;
|
| 183 |
+
}
|
| 184 |
+
|
| 185 |
+
|
| 186 |
+
modifier onlyOwner {
|
| 187 |
+
require(msg.sender == owner);
|
| 188 |
+
_;
|
| 189 |
+
}
|
| 190 |
+
|
| 191 |
+
|
| 192 |
+
modifier onlyBankroll {
|
| 193 |
+
require(msg.sender == bankroll);
|
| 194 |
+
_;
|
| 195 |
+
}
|
| 196 |
+
|
| 197 |
+
|
| 198 |
+
modifier onlyOwnerOrBankroll {
|
| 199 |
+
require(msg.sender == owner || msg.sender == bankroll);
|
| 200 |
+
_;
|
| 201 |
+
}
|
| 202 |
+
|
| 203 |
+
|
| 204 |
+
|
| 205 |
+
|
| 206 |
+
uint constant public maxProfitDivisor = 1000000;
|
| 207 |
+
uint constant public houseEdgeDivisor = 1000;
|
| 208 |
+
mapping (uint => uint) public maxProfit;
|
| 209 |
+
uint public maxProfitAsPercentOfHouse;
|
| 210 |
+
uint public minBet = 1e18;
|
| 211 |
+
address public zlotsJackpot;
|
| 212 |
+
address private owner;
|
| 213 |
+
address private bankroll;
|
| 214 |
+
bool gamePaused;
|
| 215 |
+
|
| 216 |
+
|
| 217 |
+
uint public totalSpins;
|
| 218 |
+
uint public totalZTHWagered;
|
| 219 |
+
mapping (uint => uint) public contractBalance;
|
| 220 |
+
|
| 221 |
+
|
| 222 |
+
bool public gameActive;
|
| 223 |
+
|
| 224 |
+
address private ZTHTKNADDR;
|
| 225 |
+
address private ZTHBANKROLL;
|
| 226 |
+
|
| 227 |
+
|
| 228 |
+
|
| 229 |
+
|
| 230 |
+
constructor(address BankrollAddress) public {
|
| 231 |
+
|
| 232 |
+
setupBankrollInterface(BankrollAddress);
|
| 233 |
+
|
| 234 |
+
|
| 235 |
+
owner = msg.sender;
|
| 236 |
+
|
| 237 |
+
|
| 238 |
+
ownerSetMaxProfitAsPercentOfHouse(50000);
|
| 239 |
+
|
| 240 |
+
|
| 241 |
+
bankroll = ZTHBANKROLL;
|
| 242 |
+
gameActive = true;
|
| 243 |
+
|
| 244 |
+
|
| 245 |
+
ownerSetMinBet(1e18);
|
| 246 |
+
}
|
| 247 |
+
|
| 248 |
+
|
| 249 |
+
function() public payable { }
|
| 250 |
+
|
| 251 |
+
|
| 252 |
+
struct TKN { address sender; uint value; }
|
| 253 |
+
function execute(address _from, uint _value, uint divRate, bytes ) public fromBankroll returns (bool){
|
| 254 |
+
TKN memory _tkn;
|
| 255 |
+
_tkn.sender = _from;
|
| 256 |
+
_tkn.value = _value;
|
| 257 |
+
_spinTokens(_tkn, divRate);
|
| 258 |
+
return true;
|
| 259 |
+
}
|
| 260 |
+
|
| 261 |
+
struct playerSpin {
|
| 262 |
+
uint200 tokenValue;
|
| 263 |
+
uint48 blockn;
|
| 264 |
+
uint8 tier;
|
| 265 |
+
}
|
| 266 |
+
|
| 267 |
+
|
| 268 |
+
mapping(address => playerSpin) public playerSpins;
|
| 269 |
+
|
| 270 |
+
|
| 271 |
+
function _spinTokens(TKN _tkn, uint divRate)
|
| 272 |
+
private
|
| 273 |
+
betIsValid(_tkn.value, divRate)
|
| 274 |
+
{
|
| 275 |
+
|
| 276 |
+
require(gameActive);
|
| 277 |
+
require(block.number < ((2 ** 56) - 1));
|
| 278 |
+
|
| 279 |
+
address _customerAddress = _tkn.sender;
|
| 280 |
+
uint _wagered = _tkn.value;
|
| 281 |
+
|
| 282 |
+
playerSpin memory spin = playerSpins[_tkn.sender];
|
| 283 |
+
|
| 284 |
+
|
| 285 |
+
|
| 286 |
+
|
| 287 |
+
addContractBalance(divRate, _wagered);
|
| 288 |
+
|
| 289 |
+
|
| 290 |
+
require(block.number != spin.blockn);
|
| 291 |
+
|
| 292 |
+
|
| 293 |
+
if (spin.blockn != 0) {
|
| 294 |
+
_finishSpin(_tkn.sender);
|
| 295 |
+
}
|
| 296 |
+
|
| 297 |
+
|
| 298 |
+
spin.blockn = uint48(block.number);
|
| 299 |
+
spin.tokenValue = uint200(_wagered);
|
| 300 |
+
spin.tier = uint8(ZethrTierLibrary.getTier(divRate));
|
| 301 |
+
|
| 302 |
+
|
| 303 |
+
playerSpins[_tkn.sender] = spin;
|
| 304 |
+
|
| 305 |
+
|
| 306 |
+
totalSpins += 1;
|
| 307 |
+
|
| 308 |
+
|
| 309 |
+
totalZTHWagered += _wagered;
|
| 310 |
+
|
| 311 |
+
emit TokensWagered(_customerAddress, _wagered);
|
| 312 |
+
}
|
| 313 |
+
|
| 314 |
+
|
| 315 |
+
function finishSpin() public
|
| 316 |
+
gameIsActive
|
| 317 |
+
returns (uint)
|
| 318 |
+
{
|
| 319 |
+
return _finishSpin(msg.sender);
|
| 320 |
+
}
|
| 321 |
+
|
| 322 |
+
|
| 323 |
+
function _finishSpin(address target)
|
| 324 |
+
private returns (uint)
|
| 325 |
+
{
|
| 326 |
+
playerSpin memory spin = playerSpins[target];
|
| 327 |
+
|
| 328 |
+
require(spin.tokenValue > 0);
|
| 329 |
+
require(spin.blockn != block.number);
|
| 330 |
+
|
| 331 |
+
uint profit = 0;
|
| 332 |
+
uint category = 0;
|
| 333 |
+
|
| 334 |
+
|
| 335 |
+
|
| 336 |
+
uint result;
|
| 337 |
+
if (block.number - spin.blockn > 255) {
|
| 338 |
+
result = 1000000;
|
| 339 |
+
} else {
|
| 340 |
+
|
| 341 |
+
|
| 342 |
+
|
| 343 |
+
result = random(1000000, spin.blockn, target) + 1;
|
| 344 |
+
}
|
| 345 |
+
|
| 346 |
+
if (result > 506856) {
|
| 347 |
+
|
| 348 |
+
|
| 349 |
+
|
| 350 |
+
|
| 351 |
+
RequestBankrollPayment(zlotsJackpot, spin.tokenValue / 100, tier);
|
| 352 |
+
|
| 353 |
+
|
| 354 |
+
playerSpins[target] = playerSpin(uint200(0), uint48(0), uint8(0));
|
| 355 |
+
|
| 356 |
+
emit Loss(target, spin.blockn);
|
| 357 |
+
emit LogResult(target, result, profit, spin.tokenValue, category, false);
|
| 358 |
+
} else if (result < 2) {
|
| 359 |
+
|
| 360 |
+
|
| 361 |
+
|
| 362 |
+
profit = ZlotsJackpotHoldingContract(zlotsJackpot).getJackpot();
|
| 363 |
+
category = 1;
|
| 364 |
+
|
| 365 |
+
|
| 366 |
+
emit ThreeMoonJackpot(target, spin.blockn);
|
| 367 |
+
emit LogResult(target, result, profit, spin.tokenValue, category, true);
|
| 368 |
+
|
| 369 |
+
|
| 370 |
+
uint8 tier = spin.tier;
|
| 371 |
+
|
| 372 |
+
|
| 373 |
+
playerSpins[target] = playerSpin(uint200(0), uint48(0), uint8(0));
|
| 374 |
+
|
| 375 |
+
|
| 376 |
+
ZlotsJackpotHoldingContract(zlotsJackpot).payOutWinner(target);
|
| 377 |
+
} else {
|
| 378 |
+
if (result < 299) {
|
| 379 |
+
|
| 380 |
+
profit = SafeMath.mul(spin.tokenValue, 50);
|
| 381 |
+
category = 2;
|
| 382 |
+
emit TwoMoonPrize(target, spin.blockn);
|
| 383 |
+
} else if (result < 3128) {
|
| 384 |
+
|
| 385 |
+
profit = SafeMath.mul(spin.tokenValue, 20);
|
| 386 |
+
category = 3;
|
| 387 |
+
emit ZTHPrize(target, spin.blockn);
|
| 388 |
+
} else if (result < 16961) {
|
| 389 |
+
|
| 390 |
+
profit = SafeMath.div(SafeMath.mul(spin.tokenValue, 30), 10);
|
| 391 |
+
category = 4;
|
| 392 |
+
emit ThreeZSymbols(target, spin.blockn);
|
| 393 |
+
} else if (result < 30794) {
|
| 394 |
+
|
| 395 |
+
profit = SafeMath.div(SafeMath.mul(spin.tokenValue, 30), 10);
|
| 396 |
+
category = 5;
|
| 397 |
+
emit ThreeTSymbols(target, spin.blockn);
|
| 398 |
+
} else if (result < 44627) {
|
| 399 |
+
|
| 400 |
+
profit = SafeMath.div(SafeMath.mul(spin.tokenValue, 30), 10);
|
| 401 |
+
category = 6;
|
| 402 |
+
emit ThreeHSymbols(target, spin.blockn);
|
| 403 |
+
} else if (result < 46627) {
|
| 404 |
+
|
| 405 |
+
profit = SafeMath.mul(spin.tokenValue, 11);
|
| 406 |
+
category = 7;
|
| 407 |
+
emit ThreeEtherIcons(target, spin.blockn);
|
| 408 |
+
} else if (result < 49127) {
|
| 409 |
+
|
| 410 |
+
profit = SafeMath.div(SafeMath.mul(spin.tokenValue, 75), 10);
|
| 411 |
+
category = 8;
|
| 412 |
+
emit ThreePurplePyramids(target, spin.blockn);
|
| 413 |
+
} else if (result < 51627) {
|
| 414 |
+
|
| 415 |
+
profit = SafeMath.mul(spin.tokenValue, 9);
|
| 416 |
+
category = 9;
|
| 417 |
+
emit ThreeGoldPyramids(target, spin.blockn);
|
| 418 |
+
} else if (result < 53127) {
|
| 419 |
+
|
| 420 |
+
profit = SafeMath.mul(spin.tokenValue, 13);
|
| 421 |
+
category = 10;
|
| 422 |
+
emit ThreeRockets(target, spin.blockn);
|
| 423 |
+
} else if (result < 82530) {
|
| 424 |
+
|
| 425 |
+
profit = SafeMath.div(SafeMath.mul(spin.tokenValue, 25),10);
|
| 426 |
+
category = 11;
|
| 427 |
+
emit OneMoonPrize(target, spin.blockn);
|
| 428 |
+
} else if (result < 150423) {
|
| 429 |
+
|
| 430 |
+
profit = SafeMath.div(SafeMath.mul(spin.tokenValue, 15),10);
|
| 431 |
+
category = 12;
|
| 432 |
+
emit OneOfEachPyramidPrize(target, spin.blockn);
|
| 433 |
+
} else if (result < 203888) {
|
| 434 |
+
|
| 435 |
+
profit = spin.tokenValue;
|
| 436 |
+
category = 13;
|
| 437 |
+
emit TwoZSymbols(target, spin.blockn);
|
| 438 |
+
} else if (result < 257353) {
|
| 439 |
+
|
| 440 |
+
profit = spin.tokenValue;
|
| 441 |
+
category = 14;
|
| 442 |
+
emit TwoTSymbols(target, spin.blockn);
|
| 443 |
+
} else if (result < 310818) {
|
| 444 |
+
|
| 445 |
+
profit = spin.tokenValue;
|
| 446 |
+
category = 15;
|
| 447 |
+
emit TwoHSymbols(target, spin.blockn);
|
| 448 |
+
} else if (result < 364283) {
|
| 449 |
+
|
| 450 |
+
profit = SafeMath.mul(spin.tokenValue, 2);
|
| 451 |
+
category = 16;
|
| 452 |
+
emit TwoEtherIcons(target, spin.blockn);
|
| 453 |
+
} else if (result < 417748) {
|
| 454 |
+
|
| 455 |
+
profit = SafeMath.div(SafeMath.mul(spin.tokenValue, 125), 100);
|
| 456 |
+
category = 17;
|
| 457 |
+
emit TwoPurplePyramids(target, spin.blockn);
|
| 458 |
+
} else if (result < 471213) {
|
| 459 |
+
|
| 460 |
+
profit = SafeMath.div(SafeMath.mul(spin.tokenValue, 133), 100);
|
| 461 |
+
category = 18;
|
| 462 |
+
emit TwoGoldPyramids(target, spin.blockn);
|
| 463 |
+
} else {
|
| 464 |
+
|
| 465 |
+
profit = SafeMath.div(SafeMath.mul(spin.tokenValue, 25), 10);
|
| 466 |
+
category = 19;
|
| 467 |
+
emit TwoRockets(target, spin.blockn);
|
| 468 |
+
}
|
| 469 |
+
|
| 470 |
+
emit LogResult(target, result, profit, spin.tokenValue, category, true);
|
| 471 |
+
tier = spin.tier;
|
| 472 |
+
playerSpins[target] = playerSpin(uint200(0), uint48(0), uint8(0));
|
| 473 |
+
RequestBankrollPayment(target, profit, tier);
|
| 474 |
+
}
|
| 475 |
+
|
| 476 |
+
emit SpinConcluded(target, spin.blockn);
|
| 477 |
+
return result;
|
| 478 |
+
}
|
| 479 |
+
|
| 480 |
+
|
| 481 |
+
|
| 482 |
+
function maxRandom(uint blockn, address entropy) private view returns (uint256 randomNumber) {
|
| 483 |
+
return uint256(keccak256(
|
| 484 |
+
abi.encodePacked(
|
| 485 |
+
|
| 486 |
+
blockhash(blockn),
|
| 487 |
+
entropy)
|
| 488 |
+
));
|
| 489 |
+
}
|
| 490 |
+
|
| 491 |
+
|
| 492 |
+
function random(uint256 upper, uint256 blockn, address entropy) internal view returns (uint256 randomNumber) {
|
| 493 |
+
return maxRandom(blockn, entropy) % upper;
|
| 494 |
+
}
|
| 495 |
+
|
| 496 |
+
|
| 497 |
+
function setMaxProfit(uint divRate) internal {
|
| 498 |
+
maxProfit[divRate] = (contractBalance[divRate] * maxProfitAsPercentOfHouse) / maxProfitDivisor;
|
| 499 |
+
}
|
| 500 |
+
|
| 501 |
+
|
| 502 |
+
function getMaxProfit(uint divRate) public view returns (uint) {
|
| 503 |
+
return (contractBalance[divRate] * maxProfitAsPercentOfHouse) / maxProfitDivisor;
|
| 504 |
+
}
|
| 505 |
+
|
| 506 |
+
|
| 507 |
+
function subContractBalance(uint divRate, uint sub) internal {
|
| 508 |
+
contractBalance[divRate] = contractBalance[divRate].sub(sub);
|
| 509 |
+
}
|
| 510 |
+
|
| 511 |
+
|
| 512 |
+
function addContractBalance(uint divRate, uint add) internal {
|
| 513 |
+
contractBalance[divRate] = contractBalance[divRate].add(add);
|
| 514 |
+
}
|
| 515 |
+
|
| 516 |
+
|
| 517 |
+
|
| 518 |
+
|
| 519 |
+
function bankrollExternalUpdateTokens(uint divRate, uint newBalance)
|
| 520 |
+
public
|
| 521 |
+
fromBankroll
|
| 522 |
+
{
|
| 523 |
+
contractBalance[divRate] = newBalance;
|
| 524 |
+
setMaxProfit(divRate);
|
| 525 |
+
}
|
| 526 |
+
|
| 527 |
+
|
| 528 |
+
|
| 529 |
+
function ownerSetMaxProfitAsPercentOfHouse(uint newMaxProfitAsPercent) public
|
| 530 |
+
onlyOwner
|
| 531 |
+
{
|
| 532 |
+
|
| 533 |
+
require(newMaxProfitAsPercent <= 500000);
|
| 534 |
+
maxProfitAsPercentOfHouse = newMaxProfitAsPercent;
|
| 535 |
+
setMaxProfit(2);
|
| 536 |
+
setMaxProfit(5);
|
| 537 |
+
setMaxProfit(10);
|
| 538 |
+
setMaxProfit(15);
|
| 539 |
+
setMaxProfit(20);
|
| 540 |
+
setMaxProfit(25);
|
| 541 |
+
setMaxProfit(33);
|
| 542 |
+
}
|
| 543 |
+
|
| 544 |
+
|
| 545 |
+
function ownerSetMinBet(uint newMinimumBet) public
|
| 546 |
+
onlyOwner
|
| 547 |
+
{
|
| 548 |
+
minBet = newMinimumBet;
|
| 549 |
+
}
|
| 550 |
+
|
| 551 |
+
|
| 552 |
+
function ownerSetZlotsAddress(address zlotsAddress) public
|
| 553 |
+
onlyOwner
|
| 554 |
+
{
|
| 555 |
+
zlotsJackpot = zlotsAddress;
|
| 556 |
+
}
|
| 557 |
+
|
| 558 |
+
|
| 559 |
+
function pauseGame() public onlyOwnerOrBankroll {
|
| 560 |
+
gameActive = false;
|
| 561 |
+
}
|
| 562 |
+
|
| 563 |
+
|
| 564 |
+
function resumeGame() public onlyOwnerOrBankroll {
|
| 565 |
+
gameActive = true;
|
| 566 |
+
}
|
| 567 |
+
|
| 568 |
+
|
| 569 |
+
function changeOwner(address _newOwner) public onlyOwnerOrBankroll {
|
| 570 |
+
owner = _newOwner;
|
| 571 |
+
}
|
| 572 |
+
|
| 573 |
+
|
| 574 |
+
function changeBankroll(address _newBankroll) public onlyOwnerOrBankroll {
|
| 575 |
+
bankroll = _newBankroll;
|
| 576 |
+
}
|
| 577 |
+
|
| 578 |
+
|
| 579 |
+
function _zthToken(address _tokenContract) private view returns (bool) {
|
| 580 |
+
return _tokenContract == ZTHTKNADDR;
|
| 581 |
+
}
|
| 582 |
+
}
|
| 583 |
+
|
| 584 |
+
|
| 585 |
+
|
| 586 |
+
|
| 587 |
+
library SafeMath {
|
| 588 |
+
|
| 589 |
+
|
| 590 |
+
function mul(uint a, uint b) internal pure returns (uint) {
|
| 591 |
+
if (a == 0) {
|
| 592 |
+
return 0;
|
| 593 |
+
}
|
| 594 |
+
uint c = a * b;
|
| 595 |
+
assert(c / a == b);
|
| 596 |
+
return c;
|
| 597 |
+
}
|
| 598 |
+
|
| 599 |
+
|
| 600 |
+
function div(uint a, uint b) internal pure returns (uint) {
|
| 601 |
+
|
| 602 |
+
uint c = a / b;
|
| 603 |
+
|
| 604 |
+
return c;
|
| 605 |
+
}
|
| 606 |
+
|
| 607 |
+
|
| 608 |
+
function sub(uint a, uint b) internal pure returns (uint) {
|
| 609 |
+
assert(b <= a);
|
| 610 |
+
return a - b;
|
| 611 |
+
}
|
| 612 |
+
|
| 613 |
+
|
| 614 |
+
function add(uint a, uint b) internal pure returns (uint) {
|
| 615 |
+
uint c = a + b;
|
| 616 |
+
assert(c >= a);
|
| 617 |
+
return c;
|
| 618 |
+
}
|
| 619 |
+
}
|
smart_contract_dataset/block number dependency/1096.sol
ADDED
|
@@ -0,0 +1,621 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
pragma solidity ^0.4.24;
|
| 2 |
+
|
| 3 |
+
|
| 4 |
+
|
| 5 |
+
|
| 6 |
+
contract ZethrTokenBankroll{
|
| 7 |
+
|
| 8 |
+
function gameRequestTokens(address target, uint tokens) public;
|
| 9 |
+
function gameTokenAmount(address what) public returns (uint);
|
| 10 |
+
}
|
| 11 |
+
|
| 12 |
+
|
| 13 |
+
contract ZethrMainBankroll{
|
| 14 |
+
function gameGetTokenBankrollList() public view returns (address[7]);
|
| 15 |
+
}
|
| 16 |
+
|
| 17 |
+
|
| 18 |
+
contract ZethrInterface{
|
| 19 |
+
function withdraw() public;
|
| 20 |
+
}
|
| 21 |
+
|
| 22 |
+
|
| 23 |
+
library ZethrTierLibrary{
|
| 24 |
+
|
| 25 |
+
function getTier(uint divRate) internal pure returns (uint){
|
| 26 |
+
|
| 27 |
+
|
| 28 |
+
|
| 29 |
+
|
| 30 |
+
|
| 31 |
+
uint actualDiv = divRate;
|
| 32 |
+
if (actualDiv >= 30){
|
| 33 |
+
return 6;
|
| 34 |
+
} else if (actualDiv >= 25){
|
| 35 |
+
return 5;
|
| 36 |
+
} else if (actualDiv >= 20){
|
| 37 |
+
return 4;
|
| 38 |
+
} else if (actualDiv >= 15){
|
| 39 |
+
return 3;
|
| 40 |
+
} else if (actualDiv >= 10){
|
| 41 |
+
return 2;
|
| 42 |
+
} else if (actualDiv >= 5){
|
| 43 |
+
return 1;
|
| 44 |
+
} else if (actualDiv >= 2){
|
| 45 |
+
return 0;
|
| 46 |
+
} else{
|
| 47 |
+
|
| 48 |
+
revert();
|
| 49 |
+
}
|
| 50 |
+
}
|
| 51 |
+
}
|
| 52 |
+
|
| 53 |
+
|
| 54 |
+
contract ZlotsJackpotHoldingContract {
|
| 55 |
+
function payOutWinner(address winner) public;
|
| 56 |
+
function getJackpot() public view returns (uint);
|
| 57 |
+
}
|
| 58 |
+
|
| 59 |
+
|
| 60 |
+
contract ZethrBankrollBridge {
|
| 61 |
+
|
| 62 |
+
ZethrInterface Zethr;
|
| 63 |
+
|
| 64 |
+
|
| 65 |
+
|
| 66 |
+
|
| 67 |
+
|
| 68 |
+
address[7] UsedBankrollAddresses;
|
| 69 |
+
|
| 70 |
+
|
| 71 |
+
mapping(address => bool) ValidBankrollAddress;
|
| 72 |
+
|
| 73 |
+
|
| 74 |
+
function setupBankrollInterface(address ZethrMainBankrollAddress) internal {
|
| 75 |
+
|
| 76 |
+
|
| 77 |
+
Zethr = ZethrInterface(0xD48B633045af65fF636F3c6edd744748351E020D);
|
| 78 |
+
|
| 79 |
+
|
| 80 |
+
UsedBankrollAddresses = ZethrMainBankroll(ZethrMainBankrollAddress).gameGetTokenBankrollList();
|
| 81 |
+
for(uint i=0; i<7; i++){
|
| 82 |
+
ValidBankrollAddress[UsedBankrollAddresses[i]] = true;
|
| 83 |
+
}
|
| 84 |
+
}
|
| 85 |
+
|
| 86 |
+
|
| 87 |
+
modifier fromBankroll(){
|
| 88 |
+
require(ValidBankrollAddress[msg.sender], "msg.sender should be a valid bankroll");
|
| 89 |
+
_;
|
| 90 |
+
}
|
| 91 |
+
|
| 92 |
+
|
| 93 |
+
|
| 94 |
+
function RequestBankrollPayment(address to, uint tokens, uint tier) internal {
|
| 95 |
+
address tokenBankrollAddress = UsedBankrollAddresses[tier];
|
| 96 |
+
ZethrTokenBankroll(tokenBankrollAddress).gameRequestTokens(to, tokens);
|
| 97 |
+
}
|
| 98 |
+
|
| 99 |
+
function getZethrTokenBankroll(uint divRate) public constant returns (ZethrTokenBankroll){
|
| 100 |
+
return ZethrTokenBankroll(UsedBankrollAddresses[ZethrTierLibrary.getTier(divRate)]);
|
| 101 |
+
}
|
| 102 |
+
}
|
| 103 |
+
|
| 104 |
+
|
| 105 |
+
contract ZethrShell is ZethrBankrollBridge {
|
| 106 |
+
|
| 107 |
+
|
| 108 |
+
function WithdrawToBankroll() public {
|
| 109 |
+
address(UsedBankrollAddresses[0]).transfer(address(this).balance);
|
| 110 |
+
}
|
| 111 |
+
|
| 112 |
+
|
| 113 |
+
function WithdrawAndTransferToBankroll() public {
|
| 114 |
+
Zethr.withdraw();
|
| 115 |
+
WithdrawToBankroll();
|
| 116 |
+
}
|
| 117 |
+
}
|
| 118 |
+
|
| 119 |
+
|
| 120 |
+
|
| 121 |
+
contract Zlots is ZethrShell {
|
| 122 |
+
using SafeMath for uint;
|
| 123 |
+
|
| 124 |
+
|
| 125 |
+
|
| 126 |
+
|
| 127 |
+
event HouseRetrievedTake(
|
| 128 |
+
uint timeTaken,
|
| 129 |
+
uint tokensWithdrawn
|
| 130 |
+
);
|
| 131 |
+
|
| 132 |
+
|
| 133 |
+
event TokensWagered(
|
| 134 |
+
address _wagerer,
|
| 135 |
+
uint _wagered
|
| 136 |
+
);
|
| 137 |
+
|
| 138 |
+
event LogResult(
|
| 139 |
+
address _wagerer,
|
| 140 |
+
uint _result,
|
| 141 |
+
uint _profit,
|
| 142 |
+
uint _wagered,
|
| 143 |
+
uint _category,
|
| 144 |
+
bool _win
|
| 145 |
+
);
|
| 146 |
+
|
| 147 |
+
|
| 148 |
+
event Loss(address _wagerer, uint _block);
|
| 149 |
+
event ThreeMoonJackpot(address _wagerer, uint _block);
|
| 150 |
+
event TwoMoonPrize(address _wagerer, uint _block);
|
| 151 |
+
event ZTHPrize(address _wagerer, uint _block);
|
| 152 |
+
event ThreeZSymbols(address _wagerer, uint _block);
|
| 153 |
+
event ThreeTSymbols(address _wagerer, uint _block);
|
| 154 |
+
event ThreeHSymbols(address _wagerer, uint _block);
|
| 155 |
+
event ThreeEtherIcons(address _wagerer, uint _block);
|
| 156 |
+
event ThreePurplePyramids(address _wagerer, uint _block);
|
| 157 |
+
event ThreeGoldPyramids(address _wagerer, uint _block);
|
| 158 |
+
event ThreeRockets(address _wagerer, uint _block);
|
| 159 |
+
event OneMoonPrize(address _wagerer, uint _block);
|
| 160 |
+
event OneOfEachPyramidPrize(address _wagerer, uint _block);
|
| 161 |
+
event TwoZSymbols(address _wagerer, uint _block);
|
| 162 |
+
event TwoTSymbols(address _wagerer, uint _block);
|
| 163 |
+
event TwoHSymbols(address _wagerer, uint _block);
|
| 164 |
+
event TwoEtherIcons(address _wagerer, uint _block);
|
| 165 |
+
event TwoPurplePyramids(address _wagerer, uint _block);
|
| 166 |
+
event TwoGoldPyramids(address _wagerer, uint _block);
|
| 167 |
+
event TwoRockets(address _wagerer, uint _block);
|
| 168 |
+
event SpinConcluded(address _wagerer, uint _block);
|
| 169 |
+
|
| 170 |
+
|
| 171 |
+
|
| 172 |
+
|
| 173 |
+
|
| 174 |
+
modifier betIsValid(uint _betSize, uint divRate) {
|
| 175 |
+
require(_betSize.mul(100) <= getMaxProfit(divRate));
|
| 176 |
+
_;
|
| 177 |
+
}
|
| 178 |
+
|
| 179 |
+
|
| 180 |
+
modifier gameIsActive {
|
| 181 |
+
require(gamePaused == false);
|
| 182 |
+
_;
|
| 183 |
+
}
|
| 184 |
+
|
| 185 |
+
|
| 186 |
+
modifier onlyOwner {
|
| 187 |
+
require(msg.sender == owner);
|
| 188 |
+
_;
|
| 189 |
+
}
|
| 190 |
+
|
| 191 |
+
|
| 192 |
+
modifier onlyBankroll {
|
| 193 |
+
require(msg.sender == bankroll);
|
| 194 |
+
_;
|
| 195 |
+
}
|
| 196 |
+
|
| 197 |
+
|
| 198 |
+
modifier onlyOwnerOrBankroll {
|
| 199 |
+
require(msg.sender == owner || msg.sender == bankroll);
|
| 200 |
+
_;
|
| 201 |
+
}
|
| 202 |
+
|
| 203 |
+
|
| 204 |
+
|
| 205 |
+
|
| 206 |
+
uint constant public maxProfitDivisor = 1000000;
|
| 207 |
+
uint constant public houseEdgeDivisor = 1000;
|
| 208 |
+
mapping (uint => uint) public maxProfit;
|
| 209 |
+
uint public maxProfitAsPercentOfHouse;
|
| 210 |
+
uint public minBet = 1e18;
|
| 211 |
+
address public zlotsJackpot;
|
| 212 |
+
address private owner;
|
| 213 |
+
address private bankroll;
|
| 214 |
+
bool gamePaused;
|
| 215 |
+
|
| 216 |
+
|
| 217 |
+
uint public totalSpins;
|
| 218 |
+
uint public totalZTHWagered;
|
| 219 |
+
mapping (uint => uint) public contractBalance;
|
| 220 |
+
|
| 221 |
+
|
| 222 |
+
bool public gameActive;
|
| 223 |
+
|
| 224 |
+
address private ZTHTKNADDR;
|
| 225 |
+
address private ZTHBANKROLL;
|
| 226 |
+
|
| 227 |
+
|
| 228 |
+
|
| 229 |
+
|
| 230 |
+
constructor(address BankrollAddress) public {
|
| 231 |
+
|
| 232 |
+
setupBankrollInterface(BankrollAddress);
|
| 233 |
+
|
| 234 |
+
|
| 235 |
+
owner = msg.sender;
|
| 236 |
+
|
| 237 |
+
|
| 238 |
+
ownerSetMaxProfitAsPercentOfHouse(50000);
|
| 239 |
+
|
| 240 |
+
|
| 241 |
+
bankroll = ZTHBANKROLL;
|
| 242 |
+
gameActive = true;
|
| 243 |
+
|
| 244 |
+
|
| 245 |
+
ownerSetMinBet(1e18);
|
| 246 |
+
}
|
| 247 |
+
|
| 248 |
+
|
| 249 |
+
function() public payable { }
|
| 250 |
+
|
| 251 |
+
|
| 252 |
+
struct TKN { address sender; uint value; }
|
| 253 |
+
function execute(address _from, uint _value, uint divRate, bytes ) public fromBankroll returns (bool){
|
| 254 |
+
TKN memory _tkn;
|
| 255 |
+
_tkn.sender = _from;
|
| 256 |
+
_tkn.value = _value;
|
| 257 |
+
_spinTokens(_tkn, divRate);
|
| 258 |
+
return true;
|
| 259 |
+
}
|
| 260 |
+
|
| 261 |
+
struct playerSpin {
|
| 262 |
+
uint200 tokenValue;
|
| 263 |
+
uint48 blockn;
|
| 264 |
+
uint8 tier;
|
| 265 |
+
}
|
| 266 |
+
|
| 267 |
+
|
| 268 |
+
mapping(address => playerSpin) public playerSpins;
|
| 269 |
+
|
| 270 |
+
|
| 271 |
+
function _spinTokens(TKN _tkn, uint divRate)
|
| 272 |
+
private
|
| 273 |
+
betIsValid(_tkn.value, divRate)
|
| 274 |
+
{
|
| 275 |
+
|
| 276 |
+
require(gameActive);
|
| 277 |
+
require(1e18 <= _tkn.value);
|
| 278 |
+
|
| 279 |
+
require(block.number < ((2 ** 56) - 1));
|
| 280 |
+
|
| 281 |
+
address _customerAddress = _tkn.sender;
|
| 282 |
+
uint _wagered = _tkn.value;
|
| 283 |
+
|
| 284 |
+
playerSpin memory spin = playerSpins[_tkn.sender];
|
| 285 |
+
|
| 286 |
+
|
| 287 |
+
|
| 288 |
+
|
| 289 |
+
addContractBalance(divRate, _wagered);
|
| 290 |
+
|
| 291 |
+
|
| 292 |
+
require(block.number != spin.blockn);
|
| 293 |
+
|
| 294 |
+
|
| 295 |
+
if (spin.blockn != 0) {
|
| 296 |
+
_finishSpin(_tkn.sender);
|
| 297 |
+
}
|
| 298 |
+
|
| 299 |
+
|
| 300 |
+
spin.blockn = uint48(block.number);
|
| 301 |
+
spin.tokenValue = uint200(_wagered);
|
| 302 |
+
spin.tier = uint8(ZethrTierLibrary.getTier(divRate));
|
| 303 |
+
|
| 304 |
+
|
| 305 |
+
playerSpins[_tkn.sender] = spin;
|
| 306 |
+
|
| 307 |
+
|
| 308 |
+
totalSpins += 1;
|
| 309 |
+
|
| 310 |
+
|
| 311 |
+
totalZTHWagered += _wagered;
|
| 312 |
+
|
| 313 |
+
emit TokensWagered(_customerAddress, _wagered);
|
| 314 |
+
}
|
| 315 |
+
|
| 316 |
+
|
| 317 |
+
function finishSpin() public
|
| 318 |
+
gameIsActive
|
| 319 |
+
returns (uint)
|
| 320 |
+
{
|
| 321 |
+
return _finishSpin(msg.sender);
|
| 322 |
+
}
|
| 323 |
+
|
| 324 |
+
|
| 325 |
+
function _finishSpin(address target)
|
| 326 |
+
private returns (uint)
|
| 327 |
+
{
|
| 328 |
+
playerSpin memory spin = playerSpins[target];
|
| 329 |
+
|
| 330 |
+
require(spin.tokenValue > 0);
|
| 331 |
+
require(spin.blockn != block.number);
|
| 332 |
+
|
| 333 |
+
uint profit = 0;
|
| 334 |
+
uint category = 0;
|
| 335 |
+
|
| 336 |
+
|
| 337 |
+
|
| 338 |
+
uint result;
|
| 339 |
+
if (block.number - spin.blockn > 255) {
|
| 340 |
+
result = 1000000;
|
| 341 |
+
} else {
|
| 342 |
+
|
| 343 |
+
|
| 344 |
+
|
| 345 |
+
result = random(1000000, spin.blockn, target) + 1;
|
| 346 |
+
}
|
| 347 |
+
|
| 348 |
+
if (result > 476662) {
|
| 349 |
+
|
| 350 |
+
|
| 351 |
+
|
| 352 |
+
|
| 353 |
+
RequestBankrollPayment(zlotsJackpot, profit, tier);
|
| 354 |
+
|
| 355 |
+
|
| 356 |
+
playerSpins[target] = playerSpin(uint200(0), uint48(0), uint8(0));
|
| 357 |
+
|
| 358 |
+
emit Loss(target, spin.blockn);
|
| 359 |
+
emit LogResult(target, result, profit, spin.tokenValue, category, false);
|
| 360 |
+
} else if (result < 2) {
|
| 361 |
+
|
| 362 |
+
|
| 363 |
+
|
| 364 |
+
profit = ZlotsJackpotHoldingContract(zlotsJackpot).getJackpot();
|
| 365 |
+
category = 1;
|
| 366 |
+
|
| 367 |
+
|
| 368 |
+
emit ThreeMoonJackpot(target, spin.blockn);
|
| 369 |
+
emit LogResult(target, result, profit, spin.tokenValue, category, true);
|
| 370 |
+
|
| 371 |
+
|
| 372 |
+
uint8 tier = spin.tier;
|
| 373 |
+
|
| 374 |
+
|
| 375 |
+
playerSpins[target] = playerSpin(uint200(0), uint48(0), uint8(0));
|
| 376 |
+
|
| 377 |
+
|
| 378 |
+
ZlotsJackpotHoldingContract(zlotsJackpot).payOutWinner(target);
|
| 379 |
+
} else {
|
| 380 |
+
if (result < 299) {
|
| 381 |
+
|
| 382 |
+
profit = SafeMath.mul(spin.tokenValue, 100);
|
| 383 |
+
category = 2;
|
| 384 |
+
emit TwoMoonPrize(target, spin.blockn);
|
| 385 |
+
} else if (result < 3128) {
|
| 386 |
+
|
| 387 |
+
profit = SafeMath.mul(spin.tokenValue, 20);
|
| 388 |
+
category = 3;
|
| 389 |
+
emit ZTHPrize(target, spin.blockn);
|
| 390 |
+
} else if (result < 5957) {
|
| 391 |
+
|
| 392 |
+
profit = SafeMath.div(SafeMath.mul(spin.tokenValue, 75), 10);
|
| 393 |
+
category = 4;
|
| 394 |
+
emit ThreeZSymbols(target, spin.blockn);
|
| 395 |
+
} else if (result < 8786) {
|
| 396 |
+
|
| 397 |
+
profit = SafeMath.div(SafeMath.mul(spin.tokenValue, 75), 10);
|
| 398 |
+
category = 5;
|
| 399 |
+
emit ThreeTSymbols(target, spin.blockn);
|
| 400 |
+
} else if (result < 11615) {
|
| 401 |
+
|
| 402 |
+
profit = SafeMath.div(SafeMath.mul(spin.tokenValue, 75), 10);
|
| 403 |
+
category = 6;
|
| 404 |
+
emit ThreeHSymbols(target, spin.blockn);
|
| 405 |
+
} else if (result < 14444) {
|
| 406 |
+
|
| 407 |
+
profit = SafeMath.mul(spin.tokenValue, 15);
|
| 408 |
+
category = 7;
|
| 409 |
+
emit ThreeEtherIcons(target, spin.blockn);
|
| 410 |
+
} else if (result < 17273) {
|
| 411 |
+
|
| 412 |
+
profit = SafeMath.mul(spin.tokenValue, 10);
|
| 413 |
+
category = 8;
|
| 414 |
+
emit ThreePurplePyramids(target, spin.blockn);
|
| 415 |
+
} else if (result < 20102) {
|
| 416 |
+
|
| 417 |
+
profit = SafeMath.mul(spin.tokenValue, 10);
|
| 418 |
+
category = 9;
|
| 419 |
+
emit ThreeGoldPyramids(target, spin.blockn);
|
| 420 |
+
} else if (result < 22930) {
|
| 421 |
+
|
| 422 |
+
profit = SafeMath.mul(spin.tokenValue, 12);
|
| 423 |
+
category = 10;
|
| 424 |
+
emit ThreeRockets(target, spin.blockn);
|
| 425 |
+
} else if (result < 52333) {
|
| 426 |
+
|
| 427 |
+
profit = SafeMath.div(SafeMath.mul(spin.tokenValue, 25),10);
|
| 428 |
+
category = 11;
|
| 429 |
+
emit OneMoonPrize(target, spin.blockn);
|
| 430 |
+
} else if (result < 120226) {
|
| 431 |
+
|
| 432 |
+
profit = SafeMath.div(SafeMath.mul(spin.tokenValue, 15),10);
|
| 433 |
+
category = 12;
|
| 434 |
+
emit OneOfEachPyramidPrize(target, spin.blockn);
|
| 435 |
+
} else if (result < 171147) {
|
| 436 |
+
|
| 437 |
+
profit = spin.tokenValue;
|
| 438 |
+
category = 13;
|
| 439 |
+
emit TwoZSymbols(target, spin.blockn);
|
| 440 |
+
} else if (result < 222068) {
|
| 441 |
+
|
| 442 |
+
profit = spin.tokenValue;
|
| 443 |
+
category = 14;
|
| 444 |
+
emit TwoTSymbols(target, spin.blockn);
|
| 445 |
+
} else if (result < 272989) {
|
| 446 |
+
|
| 447 |
+
profit = spin.tokenValue;
|
| 448 |
+
category = 15;
|
| 449 |
+
emit TwoHSymbols(target, spin.blockn);
|
| 450 |
+
} else if (result < 323910) {
|
| 451 |
+
|
| 452 |
+
profit = SafeMath.mul(spin.tokenValue, 2);
|
| 453 |
+
category = 16;
|
| 454 |
+
emit TwoEtherIcons(target, spin.blockn);
|
| 455 |
+
} else if (result < 374831) {
|
| 456 |
+
|
| 457 |
+
profit = SafeMath.div(SafeMath.mul(spin.tokenValue, 133),100);
|
| 458 |
+
category = 17;
|
| 459 |
+
emit TwoPurplePyramids(target, spin.blockn);
|
| 460 |
+
} else if (result < 425752) {
|
| 461 |
+
|
| 462 |
+
profit = SafeMath.div(SafeMath.mul(spin.tokenValue, 133),100);
|
| 463 |
+
category = 18;
|
| 464 |
+
emit TwoGoldPyramids(target, spin.blockn);
|
| 465 |
+
} else {
|
| 466 |
+
|
| 467 |
+
profit = SafeMath.mul(spin.tokenValue, 2);
|
| 468 |
+
category = 19;
|
| 469 |
+
emit TwoRockets(target, spin.blockn);
|
| 470 |
+
}
|
| 471 |
+
|
| 472 |
+
emit LogResult(target, result, profit, spin.tokenValue, category, true);
|
| 473 |
+
tier = spin.tier;
|
| 474 |
+
playerSpins[target] = playerSpin(uint200(0), uint48(0), uint8(0));
|
| 475 |
+
RequestBankrollPayment(target, profit, tier);
|
| 476 |
+
}
|
| 477 |
+
|
| 478 |
+
emit SpinConcluded(target, spin.blockn);
|
| 479 |
+
return result;
|
| 480 |
+
}
|
| 481 |
+
|
| 482 |
+
|
| 483 |
+
|
| 484 |
+
function maxRandom(uint blockn, address entropy) private view returns (uint256 randomNumber) {
|
| 485 |
+
return uint256(keccak256(
|
| 486 |
+
abi.encodePacked(
|
| 487 |
+
|
| 488 |
+
blockhash(blockn),
|
| 489 |
+
entropy)
|
| 490 |
+
));
|
| 491 |
+
}
|
| 492 |
+
|
| 493 |
+
|
| 494 |
+
function random(uint256 upper, uint256 blockn, address entropy) internal view returns (uint256 randomNumber) {
|
| 495 |
+
return maxRandom(blockn, entropy) % upper;
|
| 496 |
+
}
|
| 497 |
+
|
| 498 |
+
|
| 499 |
+
function setMaxProfit(uint divRate) internal {
|
| 500 |
+
maxProfit[divRate] = (contractBalance[divRate] * maxProfitAsPercentOfHouse) / maxProfitDivisor;
|
| 501 |
+
}
|
| 502 |
+
|
| 503 |
+
|
| 504 |
+
function getMaxProfit(uint divRate) public view returns (uint) {
|
| 505 |
+
return (contractBalance[divRate] * maxProfitAsPercentOfHouse) / maxProfitDivisor;
|
| 506 |
+
}
|
| 507 |
+
|
| 508 |
+
|
| 509 |
+
function subContractBalance(uint divRate, uint sub) internal {
|
| 510 |
+
contractBalance[divRate] = contractBalance[divRate].sub(sub);
|
| 511 |
+
}
|
| 512 |
+
|
| 513 |
+
|
| 514 |
+
function addContractBalance(uint divRate, uint add) internal {
|
| 515 |
+
contractBalance[divRate] = contractBalance[divRate].add(add);
|
| 516 |
+
}
|
| 517 |
+
|
| 518 |
+
|
| 519 |
+
|
| 520 |
+
|
| 521 |
+
function bankrollExternalUpdateTokens(uint divRate, uint newBalance)
|
| 522 |
+
public
|
| 523 |
+
fromBankroll
|
| 524 |
+
{
|
| 525 |
+
contractBalance[divRate] = newBalance;
|
| 526 |
+
setMaxProfit(divRate);
|
| 527 |
+
}
|
| 528 |
+
|
| 529 |
+
|
| 530 |
+
|
| 531 |
+
function ownerSetMaxProfitAsPercentOfHouse(uint newMaxProfitAsPercent) public
|
| 532 |
+
onlyOwner
|
| 533 |
+
{
|
| 534 |
+
|
| 535 |
+
require(newMaxProfitAsPercent <= 200000);
|
| 536 |
+
maxProfitAsPercentOfHouse = newMaxProfitAsPercent;
|
| 537 |
+
setMaxProfit(2);
|
| 538 |
+
setMaxProfit(5);
|
| 539 |
+
setMaxProfit(10);
|
| 540 |
+
setMaxProfit(15);
|
| 541 |
+
setMaxProfit(20);
|
| 542 |
+
setMaxProfit(25);
|
| 543 |
+
setMaxProfit(33);
|
| 544 |
+
}
|
| 545 |
+
|
| 546 |
+
|
| 547 |
+
function ownerSetMinBet(uint newMinimumBet) public
|
| 548 |
+
onlyOwner
|
| 549 |
+
{
|
| 550 |
+
minBet = newMinimumBet;
|
| 551 |
+
}
|
| 552 |
+
|
| 553 |
+
|
| 554 |
+
function ownerSetZlotsAddress(address zlotsAddress) public
|
| 555 |
+
onlyOwner
|
| 556 |
+
{
|
| 557 |
+
zlotsJackpot = zlotsAddress;
|
| 558 |
+
}
|
| 559 |
+
|
| 560 |
+
|
| 561 |
+
function pauseGame() public onlyOwnerOrBankroll {
|
| 562 |
+
gameActive = false;
|
| 563 |
+
}
|
| 564 |
+
|
| 565 |
+
|
| 566 |
+
function resumeGame() public onlyOwnerOrBankroll {
|
| 567 |
+
gameActive = true;
|
| 568 |
+
}
|
| 569 |
+
|
| 570 |
+
|
| 571 |
+
function changeOwner(address _newOwner) public onlyOwnerOrBankroll {
|
| 572 |
+
owner = _newOwner;
|
| 573 |
+
}
|
| 574 |
+
|
| 575 |
+
|
| 576 |
+
function changeBankroll(address _newBankroll) public onlyOwnerOrBankroll {
|
| 577 |
+
bankroll = _newBankroll;
|
| 578 |
+
}
|
| 579 |
+
|
| 580 |
+
|
| 581 |
+
function _zthToken(address _tokenContract) private view returns (bool) {
|
| 582 |
+
return _tokenContract == ZTHTKNADDR;
|
| 583 |
+
}
|
| 584 |
+
}
|
| 585 |
+
|
| 586 |
+
|
| 587 |
+
|
| 588 |
+
|
| 589 |
+
library SafeMath {
|
| 590 |
+
|
| 591 |
+
|
| 592 |
+
function mul(uint a, uint b) internal pure returns (uint) {
|
| 593 |
+
if (a == 0) {
|
| 594 |
+
return 0;
|
| 595 |
+
}
|
| 596 |
+
uint c = a * b;
|
| 597 |
+
assert(c / a == b);
|
| 598 |
+
return c;
|
| 599 |
+
}
|
| 600 |
+
|
| 601 |
+
|
| 602 |
+
function div(uint a, uint b) internal pure returns (uint) {
|
| 603 |
+
|
| 604 |
+
uint c = a / b;
|
| 605 |
+
|
| 606 |
+
return c;
|
| 607 |
+
}
|
| 608 |
+
|
| 609 |
+
|
| 610 |
+
function sub(uint a, uint b) internal pure returns (uint) {
|
| 611 |
+
assert(b <= a);
|
| 612 |
+
return a - b;
|
| 613 |
+
}
|
| 614 |
+
|
| 615 |
+
|
| 616 |
+
function add(uint a, uint b) internal pure returns (uint) {
|
| 617 |
+
uint c = a + b;
|
| 618 |
+
assert(c >= a);
|
| 619 |
+
return c;
|
| 620 |
+
}
|
| 621 |
+
}
|
smart_contract_dataset/block number dependency/1101.sol
ADDED
|
@@ -0,0 +1,626 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
pragma solidity ^0.4.24;
|
| 2 |
+
|
| 3 |
+
|
| 4 |
+
|
| 5 |
+
|
| 6 |
+
contract ZethrTokenBankroll{
|
| 7 |
+
|
| 8 |
+
function gameRequestTokens(address target, uint tokens) public;
|
| 9 |
+
function gameTokenAmount(address what) public returns (uint);
|
| 10 |
+
}
|
| 11 |
+
|
| 12 |
+
|
| 13 |
+
contract ZethrMainBankroll{
|
| 14 |
+
function gameGetTokenBankrollList() public view returns (address[7]);
|
| 15 |
+
}
|
| 16 |
+
|
| 17 |
+
|
| 18 |
+
contract ZethrInterface{
|
| 19 |
+
function withdraw() public;
|
| 20 |
+
}
|
| 21 |
+
|
| 22 |
+
|
| 23 |
+
library ZethrTierLibrary{
|
| 24 |
+
|
| 25 |
+
function getTier(uint divRate) internal pure returns (uint){
|
| 26 |
+
|
| 27 |
+
|
| 28 |
+
|
| 29 |
+
|
| 30 |
+
|
| 31 |
+
uint actualDiv = divRate;
|
| 32 |
+
if (actualDiv >= 30){
|
| 33 |
+
return 6;
|
| 34 |
+
} else if (actualDiv >= 25){
|
| 35 |
+
return 5;
|
| 36 |
+
} else if (actualDiv >= 20){
|
| 37 |
+
return 4;
|
| 38 |
+
} else if (actualDiv >= 15){
|
| 39 |
+
return 3;
|
| 40 |
+
} else if (actualDiv >= 10){
|
| 41 |
+
return 2;
|
| 42 |
+
} else if (actualDiv >= 5){
|
| 43 |
+
return 1;
|
| 44 |
+
} else if (actualDiv >= 2){
|
| 45 |
+
return 0;
|
| 46 |
+
} else{
|
| 47 |
+
|
| 48 |
+
revert();
|
| 49 |
+
}
|
| 50 |
+
}
|
| 51 |
+
}
|
| 52 |
+
|
| 53 |
+
|
| 54 |
+
contract ZlotsJackpotHoldingContract {
|
| 55 |
+
function payOutWinner(address winner) public;
|
| 56 |
+
function getJackpot() public view returns (uint);
|
| 57 |
+
}
|
| 58 |
+
|
| 59 |
+
|
| 60 |
+
contract ZethrBankrollBridge {
|
| 61 |
+
|
| 62 |
+
ZethrInterface Zethr;
|
| 63 |
+
|
| 64 |
+
|
| 65 |
+
|
| 66 |
+
|
| 67 |
+
|
| 68 |
+
address[7] UsedBankrollAddresses;
|
| 69 |
+
|
| 70 |
+
|
| 71 |
+
mapping(address => bool) ValidBankrollAddress;
|
| 72 |
+
|
| 73 |
+
|
| 74 |
+
function setupBankrollInterface(address ZethrMainBankrollAddress) internal {
|
| 75 |
+
|
| 76 |
+
|
| 77 |
+
Zethr = ZethrInterface(0xD48B633045af65fF636F3c6edd744748351E020D);
|
| 78 |
+
|
| 79 |
+
|
| 80 |
+
UsedBankrollAddresses = ZethrMainBankroll(ZethrMainBankrollAddress).gameGetTokenBankrollList();
|
| 81 |
+
for(uint i=0; i<7; i++){
|
| 82 |
+
ValidBankrollAddress[UsedBankrollAddresses[i]] = true;
|
| 83 |
+
}
|
| 84 |
+
}
|
| 85 |
+
|
| 86 |
+
|
| 87 |
+
modifier fromBankroll(){
|
| 88 |
+
require(ValidBankrollAddress[msg.sender], "msg.sender should be a valid bankroll");
|
| 89 |
+
_;
|
| 90 |
+
}
|
| 91 |
+
|
| 92 |
+
|
| 93 |
+
|
| 94 |
+
function RequestBankrollPayment(address to, uint tokens, uint tier) internal {
|
| 95 |
+
address tokenBankrollAddress = UsedBankrollAddresses[tier];
|
| 96 |
+
ZethrTokenBankroll(tokenBankrollAddress).gameRequestTokens(to, tokens);
|
| 97 |
+
}
|
| 98 |
+
|
| 99 |
+
function getZethrTokenBankroll(uint divRate) public constant returns (ZethrTokenBankroll){
|
| 100 |
+
return ZethrTokenBankroll(UsedBankrollAddresses[ZethrTierLibrary.getTier(divRate)]);
|
| 101 |
+
}
|
| 102 |
+
}
|
| 103 |
+
|
| 104 |
+
|
| 105 |
+
contract ZethrShell is ZethrBankrollBridge {
|
| 106 |
+
|
| 107 |
+
|
| 108 |
+
function WithdrawToBankroll() public {
|
| 109 |
+
address(UsedBankrollAddresses[0]).transfer(address(this).balance);
|
| 110 |
+
}
|
| 111 |
+
|
| 112 |
+
|
| 113 |
+
function WithdrawAndTransferToBankroll() public {
|
| 114 |
+
Zethr.withdraw();
|
| 115 |
+
WithdrawToBankroll();
|
| 116 |
+
}
|
| 117 |
+
}
|
| 118 |
+
|
| 119 |
+
|
| 120 |
+
|
| 121 |
+
contract Zlots is ZethrShell {
|
| 122 |
+
using SafeMath for uint;
|
| 123 |
+
|
| 124 |
+
|
| 125 |
+
|
| 126 |
+
|
| 127 |
+
event HouseRetrievedTake(
|
| 128 |
+
uint timeTaken,
|
| 129 |
+
uint tokensWithdrawn
|
| 130 |
+
);
|
| 131 |
+
|
| 132 |
+
|
| 133 |
+
event TokensWagered(
|
| 134 |
+
address _wagerer,
|
| 135 |
+
uint _wagered
|
| 136 |
+
);
|
| 137 |
+
|
| 138 |
+
event LogResult(
|
| 139 |
+
address _wagerer,
|
| 140 |
+
uint _result,
|
| 141 |
+
uint _profit,
|
| 142 |
+
uint _wagered,
|
| 143 |
+
uint _category,
|
| 144 |
+
bool _win
|
| 145 |
+
);
|
| 146 |
+
|
| 147 |
+
|
| 148 |
+
event Loss(address _wagerer, uint _block);
|
| 149 |
+
event ThreeMoonJackpot(address _wagerer, uint _block);
|
| 150 |
+
event TwoMoonPrize(address _wagerer, uint _block);
|
| 151 |
+
event ZTHPrize(address _wagerer, uint _block);
|
| 152 |
+
event ThreeZSymbols(address _wagerer, uint _block);
|
| 153 |
+
event ThreeTSymbols(address _wagerer, uint _block);
|
| 154 |
+
event ThreeHSymbols(address _wagerer, uint _block);
|
| 155 |
+
event ThreeEtherIcons(address _wagerer, uint _block);
|
| 156 |
+
event ThreePurplePyramids(address _wagerer, uint _block);
|
| 157 |
+
event ThreeGoldPyramids(address _wagerer, uint _block);
|
| 158 |
+
event ThreeRockets(address _wagerer, uint _block);
|
| 159 |
+
event OneMoonPrize(address _wagerer, uint _block);
|
| 160 |
+
event OneOfEachPyramidPrize(address _wagerer, uint _block);
|
| 161 |
+
event TwoZSymbols(address _wagerer, uint _block);
|
| 162 |
+
event TwoTSymbols(address _wagerer, uint _block);
|
| 163 |
+
event TwoHSymbols(address _wagerer, uint _block);
|
| 164 |
+
event TwoEtherIcons(address _wagerer, uint _block);
|
| 165 |
+
event TwoPurplePyramids(address _wagerer, uint _block);
|
| 166 |
+
event TwoGoldPyramids(address _wagerer, uint _block);
|
| 167 |
+
event TwoRockets(address _wagerer, uint _block);
|
| 168 |
+
event SpinConcluded(address _wagerer, uint _block);
|
| 169 |
+
|
| 170 |
+
|
| 171 |
+
|
| 172 |
+
|
| 173 |
+
|
| 174 |
+
modifier betIsValid(uint _betSize, uint divRate) {
|
| 175 |
+
require(_betSize.mul(100) <= getMaxProfit(divRate));
|
| 176 |
+
_;
|
| 177 |
+
}
|
| 178 |
+
|
| 179 |
+
|
| 180 |
+
modifier gameIsActive {
|
| 181 |
+
require(gamePaused == false);
|
| 182 |
+
_;
|
| 183 |
+
}
|
| 184 |
+
|
| 185 |
+
|
| 186 |
+
modifier onlyOwner {
|
| 187 |
+
require(msg.sender == owner);
|
| 188 |
+
_;
|
| 189 |
+
}
|
| 190 |
+
|
| 191 |
+
|
| 192 |
+
modifier onlyBankroll {
|
| 193 |
+
require(msg.sender == bankroll);
|
| 194 |
+
_;
|
| 195 |
+
}
|
| 196 |
+
|
| 197 |
+
|
| 198 |
+
modifier onlyOwnerOrBankroll {
|
| 199 |
+
require(msg.sender == owner || msg.sender == bankroll);
|
| 200 |
+
_;
|
| 201 |
+
}
|
| 202 |
+
|
| 203 |
+
|
| 204 |
+
|
| 205 |
+
|
| 206 |
+
uint constant public maxProfitDivisor = 1000000;
|
| 207 |
+
uint constant public houseEdgeDivisor = 1000;
|
| 208 |
+
mapping (uint => uint) public maxProfit;
|
| 209 |
+
uint public maxProfitAsPercentOfHouse;
|
| 210 |
+
uint public minBet = 1e18;
|
| 211 |
+
address public zlotsJackpot;
|
| 212 |
+
address private owner;
|
| 213 |
+
address private bankroll;
|
| 214 |
+
bool gamePaused;
|
| 215 |
+
|
| 216 |
+
|
| 217 |
+
uint public totalSpins;
|
| 218 |
+
uint public totalZTHWagered;
|
| 219 |
+
mapping (uint => uint) public contractBalance;
|
| 220 |
+
|
| 221 |
+
|
| 222 |
+
mapping(uint => uint) public maxBet;
|
| 223 |
+
|
| 224 |
+
|
| 225 |
+
bool public gameActive;
|
| 226 |
+
|
| 227 |
+
address private ZTHTKNADDR;
|
| 228 |
+
address private ZTHBANKROLL;
|
| 229 |
+
|
| 230 |
+
|
| 231 |
+
|
| 232 |
+
|
| 233 |
+
constructor(address BankrollAddress) public {
|
| 234 |
+
|
| 235 |
+
setupBankrollInterface(BankrollAddress);
|
| 236 |
+
|
| 237 |
+
|
| 238 |
+
owner = msg.sender;
|
| 239 |
+
|
| 240 |
+
|
| 241 |
+
ownerSetMaxProfitAsPercentOfHouse(50000);
|
| 242 |
+
|
| 243 |
+
|
| 244 |
+
bankroll = ZTHBANKROLL;
|
| 245 |
+
gameActive = true;
|
| 246 |
+
|
| 247 |
+
|
| 248 |
+
ownerSetMinBet(1e18);
|
| 249 |
+
}
|
| 250 |
+
|
| 251 |
+
|
| 252 |
+
function() public payable { }
|
| 253 |
+
|
| 254 |
+
|
| 255 |
+
struct TKN { address sender; uint value; }
|
| 256 |
+
function execute(address _from, uint _value, uint divRate, bytes ) public fromBankroll returns (bool){
|
| 257 |
+
TKN memory _tkn;
|
| 258 |
+
_tkn.sender = _from;
|
| 259 |
+
_tkn.value = _value;
|
| 260 |
+
_spinTokens(_tkn, divRate);
|
| 261 |
+
return true;
|
| 262 |
+
}
|
| 263 |
+
|
| 264 |
+
struct playerSpin {
|
| 265 |
+
uint200 tokenValue;
|
| 266 |
+
uint48 blockn;
|
| 267 |
+
uint8 tier;
|
| 268 |
+
}
|
| 269 |
+
|
| 270 |
+
|
| 271 |
+
mapping(address => playerSpin) public playerSpins;
|
| 272 |
+
|
| 273 |
+
|
| 274 |
+
function _spinTokens(TKN _tkn, uint divRate)
|
| 275 |
+
private
|
| 276 |
+
betIsValid(_tkn.value, divRate)
|
| 277 |
+
{
|
| 278 |
+
|
| 279 |
+
require(gameActive);
|
| 280 |
+
require(1e18 <= _tkn.value);
|
| 281 |
+
|
| 282 |
+
require(_tkn.value < ((2 ** 200) - 1));
|
| 283 |
+
require(block.number < ((2 ** 56) - 1));
|
| 284 |
+
|
| 285 |
+
address _customerAddress = _tkn.sender;
|
| 286 |
+
uint _wagered = _tkn.value;
|
| 287 |
+
|
| 288 |
+
playerSpin memory spin = playerSpins[_tkn.sender];
|
| 289 |
+
|
| 290 |
+
|
| 291 |
+
|
| 292 |
+
|
| 293 |
+
addContractBalance(divRate, _wagered);
|
| 294 |
+
|
| 295 |
+
|
| 296 |
+
require(block.number != spin.blockn);
|
| 297 |
+
|
| 298 |
+
|
| 299 |
+
if (spin.blockn != 0) {
|
| 300 |
+
_finishSpin(_tkn.sender);
|
| 301 |
+
}
|
| 302 |
+
|
| 303 |
+
|
| 304 |
+
spin.blockn = uint48(block.number);
|
| 305 |
+
spin.tokenValue = uint200(_wagered);
|
| 306 |
+
spin.tier = uint8(ZethrTierLibrary.getTier(divRate));
|
| 307 |
+
|
| 308 |
+
|
| 309 |
+
playerSpins[_tkn.sender] = spin;
|
| 310 |
+
|
| 311 |
+
|
| 312 |
+
totalSpins += 1;
|
| 313 |
+
|
| 314 |
+
|
| 315 |
+
totalZTHWagered += _wagered;
|
| 316 |
+
|
| 317 |
+
emit TokensWagered(_customerAddress, _wagered);
|
| 318 |
+
|
| 319 |
+
}
|
| 320 |
+
|
| 321 |
+
|
| 322 |
+
function finishSpin() public
|
| 323 |
+
gameIsActive
|
| 324 |
+
returns (uint)
|
| 325 |
+
{
|
| 326 |
+
return _finishSpin(msg.sender);
|
| 327 |
+
}
|
| 328 |
+
|
| 329 |
+
|
| 330 |
+
function _finishSpin(address target)
|
| 331 |
+
private returns (uint)
|
| 332 |
+
{
|
| 333 |
+
playerSpin memory spin = playerSpins[target];
|
| 334 |
+
|
| 335 |
+
require(spin.tokenValue > 0);
|
| 336 |
+
require(spin.blockn != block.number);
|
| 337 |
+
|
| 338 |
+
uint profit = 0;
|
| 339 |
+
uint category = 0;
|
| 340 |
+
|
| 341 |
+
|
| 342 |
+
|
| 343 |
+
uint result;
|
| 344 |
+
if (block.number - spin.blockn > 255) {
|
| 345 |
+
result = 1000000;
|
| 346 |
+
} else {
|
| 347 |
+
|
| 348 |
+
|
| 349 |
+
|
| 350 |
+
result = random(1000000, spin.blockn, target) + 1;
|
| 351 |
+
}
|
| 352 |
+
|
| 353 |
+
if (result > 476662) {
|
| 354 |
+
|
| 355 |
+
|
| 356 |
+
|
| 357 |
+
|
| 358 |
+
RequestBankrollPayment(zlotsJackpot, profit, tier);
|
| 359 |
+
|
| 360 |
+
|
| 361 |
+
playerSpins[target] = playerSpin(uint200(0), uint48(0), uint8(0));
|
| 362 |
+
|
| 363 |
+
emit Loss(target, spin.blockn);
|
| 364 |
+
emit LogResult(target, result, profit, spin.tokenValue, category, false);
|
| 365 |
+
} else if (result < 2) {
|
| 366 |
+
|
| 367 |
+
|
| 368 |
+
|
| 369 |
+
profit = ZlotsJackpotHoldingContract(zlotsJackpot).getJackpot();
|
| 370 |
+
category = 1;
|
| 371 |
+
|
| 372 |
+
|
| 373 |
+
emit ThreeMoonJackpot(target, spin.blockn);
|
| 374 |
+
emit LogResult(target, result, profit, spin.tokenValue, category, true);
|
| 375 |
+
|
| 376 |
+
|
| 377 |
+
uint8 tier = spin.tier;
|
| 378 |
+
|
| 379 |
+
|
| 380 |
+
playerSpins[target] = playerSpin(uint200(0), uint48(0), uint8(0));
|
| 381 |
+
|
| 382 |
+
|
| 383 |
+
ZlotsJackpotHoldingContract(zlotsJackpot).payOutWinner(target);
|
| 384 |
+
} else {
|
| 385 |
+
if (result < 299) {
|
| 386 |
+
|
| 387 |
+
profit = SafeMath.mul(spin.tokenValue, 100);
|
| 388 |
+
category = 2;
|
| 389 |
+
emit TwoMoonPrize(target, spin.blockn);
|
| 390 |
+
} else if (result < 3128) {
|
| 391 |
+
|
| 392 |
+
profit = SafeMath.mul(spin.tokenValue, 20);
|
| 393 |
+
category = 3;
|
| 394 |
+
emit ZTHPrize(target, spin.blockn);
|
| 395 |
+
} else if (result < 5957) {
|
| 396 |
+
|
| 397 |
+
profit = SafeMath.div(SafeMath.mul(spin.tokenValue, 75), 10);
|
| 398 |
+
category = 4;
|
| 399 |
+
emit ThreeZSymbols(target, spin.blockn);
|
| 400 |
+
} else if (result < 8786) {
|
| 401 |
+
|
| 402 |
+
profit = SafeMath.div(SafeMath.mul(spin.tokenValue, 75), 10);
|
| 403 |
+
category = 5;
|
| 404 |
+
emit ThreeTSymbols(target, spin.blockn);
|
| 405 |
+
} else if (result < 11615) {
|
| 406 |
+
|
| 407 |
+
profit = SafeMath.div(SafeMath.mul(spin.tokenValue, 75), 10);
|
| 408 |
+
category = 6;
|
| 409 |
+
emit ThreeHSymbols(target, spin.blockn);
|
| 410 |
+
} else if (result < 14444) {
|
| 411 |
+
|
| 412 |
+
profit = SafeMath.mul(spin.tokenValue, 15);
|
| 413 |
+
category = 7;
|
| 414 |
+
emit ThreeEtherIcons(target, spin.blockn);
|
| 415 |
+
} else if (result < 17273) {
|
| 416 |
+
|
| 417 |
+
profit = SafeMath.mul(spin.tokenValue, 10);
|
| 418 |
+
category = 8;
|
| 419 |
+
emit ThreePurplePyramids(target, spin.blockn);
|
| 420 |
+
} else if (result < 20102) {
|
| 421 |
+
|
| 422 |
+
profit = SafeMath.mul(spin.tokenValue, 10);
|
| 423 |
+
category = 9;
|
| 424 |
+
emit ThreeGoldPyramids(target, spin.blockn);
|
| 425 |
+
} else if (result < 22930) {
|
| 426 |
+
|
| 427 |
+
profit = SafeMath.mul(spin.tokenValue, 12);
|
| 428 |
+
category = 10;
|
| 429 |
+
emit ThreeRockets(target, spin.blockn);
|
| 430 |
+
} else if (result < 52333) {
|
| 431 |
+
|
| 432 |
+
profit = SafeMath.div(SafeMath.mul(spin.tokenValue, 25),10);
|
| 433 |
+
category = 11;
|
| 434 |
+
emit OneMoonPrize(target, spin.blockn);
|
| 435 |
+
} else if (result < 120226) {
|
| 436 |
+
|
| 437 |
+
profit = SafeMath.div(SafeMath.mul(spin.tokenValue, 15),10);
|
| 438 |
+
category = 12;
|
| 439 |
+
emit OneOfEachPyramidPrize(target, spin.blockn);
|
| 440 |
+
} else if (result < 171147) {
|
| 441 |
+
|
| 442 |
+
profit = spin.tokenValue;
|
| 443 |
+
category = 13;
|
| 444 |
+
emit TwoZSymbols(target, spin.blockn);
|
| 445 |
+
} else if (result < 222068) {
|
| 446 |
+
|
| 447 |
+
profit = spin.tokenValue;
|
| 448 |
+
category = 14;
|
| 449 |
+
emit TwoTSymbols(target, spin.blockn);
|
| 450 |
+
} else if (result < 272989) {
|
| 451 |
+
|
| 452 |
+
profit = spin.tokenValue;
|
| 453 |
+
category = 15;
|
| 454 |
+
emit TwoHSymbols(target, spin.blockn);
|
| 455 |
+
} else if (result < 323910) {
|
| 456 |
+
|
| 457 |
+
profit = SafeMath.mul(spin.tokenValue, 2);
|
| 458 |
+
category = 16;
|
| 459 |
+
emit TwoEtherIcons(target, spin.blockn);
|
| 460 |
+
} else if (result < 374831) {
|
| 461 |
+
|
| 462 |
+
profit = SafeMath.div(SafeMath.mul(spin.tokenValue, 133),100);
|
| 463 |
+
category = 17;
|
| 464 |
+
emit TwoPurplePyramids(target, spin.blockn);
|
| 465 |
+
} else if (result < 425752) {
|
| 466 |
+
|
| 467 |
+
profit = SafeMath.div(SafeMath.mul(spin.tokenValue, 133),100);
|
| 468 |
+
category = 18;
|
| 469 |
+
emit TwoGoldPyramids(target, spin.blockn);
|
| 470 |
+
} else {
|
| 471 |
+
|
| 472 |
+
profit = SafeMath.mul(spin.tokenValue, 2);
|
| 473 |
+
category = 19;
|
| 474 |
+
emit TwoRockets(target, spin.blockn);
|
| 475 |
+
}
|
| 476 |
+
|
| 477 |
+
emit LogResult(target, result, profit, spin.tokenValue, category, true);
|
| 478 |
+
tier = spin.tier;
|
| 479 |
+
playerSpins[target] = playerSpin(uint200(0), uint48(0), uint8(0));
|
| 480 |
+
RequestBankrollPayment(target, profit, tier);
|
| 481 |
+
}
|
| 482 |
+
|
| 483 |
+
emit SpinConcluded(target, spin.blockn);
|
| 484 |
+
return result;
|
| 485 |
+
}
|
| 486 |
+
|
| 487 |
+
|
| 488 |
+
|
| 489 |
+
function maxRandom(uint blockn, address entropy) private view returns (uint256 randomNumber) {
|
| 490 |
+
return uint256(keccak256(
|
| 491 |
+
abi.encodePacked(
|
| 492 |
+
|
| 493 |
+
blockhash(blockn),
|
| 494 |
+
entropy)
|
| 495 |
+
));
|
| 496 |
+
}
|
| 497 |
+
|
| 498 |
+
|
| 499 |
+
function random(uint256 upper, uint256 blockn, address entropy) internal view returns (uint256 randomNumber) {
|
| 500 |
+
return maxRandom(blockn, entropy) % upper;
|
| 501 |
+
}
|
| 502 |
+
|
| 503 |
+
|
| 504 |
+
function setMaxProfit(uint divRate) internal {
|
| 505 |
+
maxProfit[divRate] = (contractBalance[divRate] * maxProfitAsPercentOfHouse) / maxProfitDivisor;
|
| 506 |
+
}
|
| 507 |
+
|
| 508 |
+
|
| 509 |
+
function getMaxProfit(uint divRate) public view returns (uint) {
|
| 510 |
+
return (contractBalance[divRate] * maxProfitAsPercentOfHouse) / maxProfitDivisor;
|
| 511 |
+
}
|
| 512 |
+
|
| 513 |
+
|
| 514 |
+
function subContractBalance(uint divRate, uint sub) internal {
|
| 515 |
+
contractBalance[divRate] = contractBalance[divRate].sub(sub);
|
| 516 |
+
}
|
| 517 |
+
|
| 518 |
+
|
| 519 |
+
function addContractBalance(uint divRate, uint add) internal {
|
| 520 |
+
contractBalance[divRate] = contractBalance[divRate].add(add);
|
| 521 |
+
}
|
| 522 |
+
|
| 523 |
+
|
| 524 |
+
|
| 525 |
+
|
| 526 |
+
function bankrollExternalUpdateTokens(uint divRate, uint newBalance)
|
| 527 |
+
public
|
| 528 |
+
fromBankroll
|
| 529 |
+
{
|
| 530 |
+
contractBalance[divRate] = newBalance;
|
| 531 |
+
setMaxProfit(divRate);
|
| 532 |
+
}
|
| 533 |
+
|
| 534 |
+
|
| 535 |
+
|
| 536 |
+
function ownerSetMaxProfitAsPercentOfHouse(uint newMaxProfitAsPercent) public
|
| 537 |
+
onlyOwner
|
| 538 |
+
{
|
| 539 |
+
|
| 540 |
+
require(newMaxProfitAsPercent <= 200000);
|
| 541 |
+
maxProfitAsPercentOfHouse = newMaxProfitAsPercent;
|
| 542 |
+
setMaxProfit(2);
|
| 543 |
+
setMaxProfit(5);
|
| 544 |
+
setMaxProfit(10);
|
| 545 |
+
setMaxProfit(15);
|
| 546 |
+
setMaxProfit(20);
|
| 547 |
+
setMaxProfit(25);
|
| 548 |
+
setMaxProfit(33);
|
| 549 |
+
}
|
| 550 |
+
|
| 551 |
+
|
| 552 |
+
function ownerSetMinBet(uint newMinimumBet) public
|
| 553 |
+
onlyOwner
|
| 554 |
+
{
|
| 555 |
+
minBet = newMinimumBet;
|
| 556 |
+
}
|
| 557 |
+
|
| 558 |
+
|
| 559 |
+
function ownerSetZlotsAddress(address zlotsAddress) public
|
| 560 |
+
onlyOwner
|
| 561 |
+
{
|
| 562 |
+
zlotsJackpot = zlotsAddress;
|
| 563 |
+
}
|
| 564 |
+
|
| 565 |
+
|
| 566 |
+
function pauseGame() public onlyOwnerOrBankroll {
|
| 567 |
+
gameActive = false;
|
| 568 |
+
}
|
| 569 |
+
|
| 570 |
+
|
| 571 |
+
function resumeGame() public onlyOwnerOrBankroll {
|
| 572 |
+
gameActive = true;
|
| 573 |
+
}
|
| 574 |
+
|
| 575 |
+
|
| 576 |
+
function changeOwner(address _newOwner) public onlyOwnerOrBankroll {
|
| 577 |
+
owner = _newOwner;
|
| 578 |
+
}
|
| 579 |
+
|
| 580 |
+
|
| 581 |
+
function changeBankroll(address _newBankroll) public onlyOwnerOrBankroll {
|
| 582 |
+
bankroll = _newBankroll;
|
| 583 |
+
}
|
| 584 |
+
|
| 585 |
+
|
| 586 |
+
function _zthToken(address _tokenContract) private view returns (bool) {
|
| 587 |
+
return _tokenContract == ZTHTKNADDR;
|
| 588 |
+
}
|
| 589 |
+
}
|
| 590 |
+
|
| 591 |
+
|
| 592 |
+
|
| 593 |
+
|
| 594 |
+
library SafeMath {
|
| 595 |
+
|
| 596 |
+
|
| 597 |
+
function mul(uint a, uint b) internal pure returns (uint) {
|
| 598 |
+
if (a == 0) {
|
| 599 |
+
return 0;
|
| 600 |
+
}
|
| 601 |
+
uint c = a * b;
|
| 602 |
+
assert(c / a == b);
|
| 603 |
+
return c;
|
| 604 |
+
}
|
| 605 |
+
|
| 606 |
+
|
| 607 |
+
function div(uint a, uint b) internal pure returns (uint) {
|
| 608 |
+
|
| 609 |
+
uint c = a / b;
|
| 610 |
+
|
| 611 |
+
return c;
|
| 612 |
+
}
|
| 613 |
+
|
| 614 |
+
|
| 615 |
+
function sub(uint a, uint b) internal pure returns (uint) {
|
| 616 |
+
assert(b <= a);
|
| 617 |
+
return a - b;
|
| 618 |
+
}
|
| 619 |
+
|
| 620 |
+
|
| 621 |
+
function add(uint a, uint b) internal pure returns (uint) {
|
| 622 |
+
uint c = a + b;
|
| 623 |
+
assert(c >= a);
|
| 624 |
+
return c;
|
| 625 |
+
}
|
| 626 |
+
}
|
smart_contract_dataset/block number dependency/112.sol
ADDED
|
@@ -0,0 +1,253 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
pragma solidity ^0.4.24;
|
| 2 |
+
|
| 3 |
+
|
| 4 |
+
|
| 5 |
+
|
| 6 |
+
|
| 7 |
+
library SafeMath {
|
| 8 |
+
function add(uint a, uint b) internal pure returns (uint c) {
|
| 9 |
+
c = a + b;
|
| 10 |
+
require(c >= a);
|
| 11 |
+
}
|
| 12 |
+
function sub(uint a, uint b) internal pure returns (uint c) {
|
| 13 |
+
require(b <= a);
|
| 14 |
+
c = a - b;
|
| 15 |
+
}
|
| 16 |
+
function mul(uint a, uint b) internal pure returns (uint c) {
|
| 17 |
+
c = a * b;
|
| 18 |
+
require(a == 0 || c / a == b);
|
| 19 |
+
}
|
| 20 |
+
function div(uint a, uint b) internal pure returns (uint c) {
|
| 21 |
+
require(b > 0);
|
| 22 |
+
c = a / b;
|
| 23 |
+
}
|
| 24 |
+
}
|
| 25 |
+
|
| 26 |
+
|
| 27 |
+
|
| 28 |
+
contract Owned {
|
| 29 |
+
address public owner;
|
| 30 |
+
address public newOwner;
|
| 31 |
+
|
| 32 |
+
event OwnershipTransferred(address indexed _from, address indexed _to);
|
| 33 |
+
|
| 34 |
+
constructor() public {
|
| 35 |
+
owner = msg.sender;
|
| 36 |
+
}
|
| 37 |
+
|
| 38 |
+
modifier onlyOwner {
|
| 39 |
+
require(msg.sender == owner);
|
| 40 |
+
_;
|
| 41 |
+
}
|
| 42 |
+
|
| 43 |
+
function transferOwnership(address _newOwner) public onlyOwner {
|
| 44 |
+
newOwner = _newOwner;
|
| 45 |
+
}
|
| 46 |
+
|
| 47 |
+
function acceptOwnership() public {
|
| 48 |
+
require(msg.sender == newOwner);
|
| 49 |
+
|
| 50 |
+
emit OwnershipTransferred(owner, newOwner);
|
| 51 |
+
|
| 52 |
+
owner = newOwner;
|
| 53 |
+
|
| 54 |
+
newOwner = address(0);
|
| 55 |
+
}
|
| 56 |
+
}
|
| 57 |
+
|
| 58 |
+
|
| 59 |
+
|
| 60 |
+
contract ERC20Interface {
|
| 61 |
+
function totalSupply() public constant returns (uint);
|
| 62 |
+
function balanceOf(address tokenOwner) public constant returns (uint balance);
|
| 63 |
+
function allowance(address tokenOwner, address spender) public constant returns (uint remaining);
|
| 64 |
+
function transfer(address to, uint tokens) public returns (bool success);
|
| 65 |
+
function approve(address spender, uint tokens) public returns (bool success);
|
| 66 |
+
function transferFrom(address from, address to, uint tokens) public returns (bool success);
|
| 67 |
+
|
| 68 |
+
event Transfer(address indexed from, address indexed to, uint tokens);
|
| 69 |
+
event Approval(address indexed tokenOwner, address indexed spender, uint tokens);
|
| 70 |
+
}
|
| 71 |
+
|
| 72 |
+
|
| 73 |
+
|
| 74 |
+
contract ERC918Interface {
|
| 75 |
+
function getChallengeNumber() public constant returns (bytes32);
|
| 76 |
+
function getMiningDifficulty() public constant returns (uint);
|
| 77 |
+
function getMiningTarget() public constant returns (uint);
|
| 78 |
+
function getMiningReward() public constant returns (uint);
|
| 79 |
+
|
| 80 |
+
function mint(uint256 nonce, bytes32 challenge_digest) public returns (bool success);
|
| 81 |
+
event Mint(address indexed from, uint reward_amount, uint epochCount, bytes32 newChallengeNumber);
|
| 82 |
+
|
| 83 |
+
address public lastRewardTo;
|
| 84 |
+
uint public lastRewardAmount;
|
| 85 |
+
uint public lastRewardEthBlockNumber;
|
| 86 |
+
bytes32 public challengeNumber;
|
| 87 |
+
}
|
| 88 |
+
|
| 89 |
+
|
| 90 |
+
contract ZeroGoldPOWMining is Owned {
|
| 91 |
+
using SafeMath for uint;
|
| 92 |
+
|
| 93 |
+
|
| 94 |
+
ERC20Interface zeroGold;
|
| 95 |
+
|
| 96 |
+
|
| 97 |
+
ERC918Interface public miningLeader;
|
| 98 |
+
|
| 99 |
+
|
| 100 |
+
address public mintHelper = 0x0;
|
| 101 |
+
|
| 102 |
+
modifier onlyMintHelper {
|
| 103 |
+
require(msg.sender == mintHelper);
|
| 104 |
+
_;
|
| 105 |
+
}
|
| 106 |
+
|
| 107 |
+
|
| 108 |
+
|
| 109 |
+
|
| 110 |
+
uint rewardDivisor = 20;
|
| 111 |
+
|
| 112 |
+
|
| 113 |
+
uint epochCount = 0;
|
| 114 |
+
|
| 115 |
+
|
| 116 |
+
uint public lastRewardAmount = 0;
|
| 117 |
+
|
| 118 |
+
mapping(bytes32 => bytes32) solutionForChallenge;
|
| 119 |
+
|
| 120 |
+
event Mint(address indexed from, uint reward_amount, uint epochCount, bytes32 newChallengeNumber);
|
| 121 |
+
|
| 122 |
+
constructor(address _miningLeader, address _mintHelper) public {
|
| 123 |
+
|
| 124 |
+
miningLeader = ERC918Interface(_miningLeader);
|
| 125 |
+
|
| 126 |
+
|
| 127 |
+
mintHelper = _mintHelper;
|
| 128 |
+
|
| 129 |
+
|
| 130 |
+
|
| 131 |
+
zeroGold = ERC20Interface(0x6ef5bca539A4A01157af842B4823F54F9f7E9968);
|
| 132 |
+
}
|
| 133 |
+
|
| 134 |
+
|
| 135 |
+
function merge() external onlyMintHelper returns (bool success) {
|
| 136 |
+
|
| 137 |
+
bytes32 futureChallengeNumber = blockhash(block.number - 1);
|
| 138 |
+
|
| 139 |
+
|
| 140 |
+
bytes32 challengeNumber = miningLeader.getChallengeNumber();
|
| 141 |
+
|
| 142 |
+
|
| 143 |
+
if (challengeNumber == futureChallengeNumber) {
|
| 144 |
+
|
| 145 |
+
|
| 146 |
+
return false;
|
| 147 |
+
}
|
| 148 |
+
|
| 149 |
+
|
| 150 |
+
if (miningLeader.lastRewardTo() != msg.sender) {
|
| 151 |
+
|
| 152 |
+
|
| 153 |
+
return false;
|
| 154 |
+
}
|
| 155 |
+
|
| 156 |
+
|
| 157 |
+
if (miningLeader.lastRewardEthBlockNumber() != block.number) {
|
| 158 |
+
|
| 159 |
+
|
| 160 |
+
return false;
|
| 161 |
+
}
|
| 162 |
+
|
| 163 |
+
|
| 164 |
+
|
| 165 |
+
|
| 166 |
+
bytes32 parentChallengeNumber = miningLeader.challengeNumber();
|
| 167 |
+
bytes32 solution = solutionForChallenge[parentChallengeNumber];
|
| 168 |
+
if (solution != 0x0) return false;
|
| 169 |
+
|
| 170 |
+
bytes32 digest = 'merge';
|
| 171 |
+
solutionForChallenge[parentChallengeNumber] = digest;
|
| 172 |
+
|
| 173 |
+
|
| 174 |
+
|
| 175 |
+
|
| 176 |
+
|
| 177 |
+
uint rewardAmount = getRewardAmount();
|
| 178 |
+
|
| 179 |
+
|
| 180 |
+
uint balance = zeroGold.balanceOf(address(this));
|
| 181 |
+
|
| 182 |
+
|
| 183 |
+
assert(rewardAmount <= balance);
|
| 184 |
+
|
| 185 |
+
|
| 186 |
+
|
| 187 |
+
|
| 188 |
+
lastRewardAmount = rewardAmount;
|
| 189 |
+
|
| 190 |
+
|
| 191 |
+
epochCount = epochCount.add(1);
|
| 192 |
+
|
| 193 |
+
|
| 194 |
+
emit Mint(msg.sender, rewardAmount, epochCount, 0);
|
| 195 |
+
|
| 196 |
+
return true;
|
| 197 |
+
}
|
| 198 |
+
|
| 199 |
+
|
| 200 |
+
|
| 201 |
+
|
| 202 |
+
function transfer(
|
| 203 |
+
address _wallet,
|
| 204 |
+
uint _reward
|
| 205 |
+
) external onlyMintHelper returns (bool) {
|
| 206 |
+
|
| 207 |
+
if (_reward > lastRewardAmount) {
|
| 208 |
+
return false;
|
| 209 |
+
}
|
| 210 |
+
|
| 211 |
+
|
| 212 |
+
lastRewardAmount = lastRewardAmount.sub(_reward);
|
| 213 |
+
|
| 214 |
+
|
| 215 |
+
zeroGold.transfer(_wallet, _reward);
|
| 216 |
+
}
|
| 217 |
+
|
| 218 |
+
|
| 219 |
+
function getRewardAmount() public constant returns (uint) {
|
| 220 |
+
|
| 221 |
+
uint totalBalance = zeroGold.balanceOf(address(this));
|
| 222 |
+
|
| 223 |
+
return totalBalance.div(rewardDivisor);
|
| 224 |
+
}
|
| 225 |
+
|
| 226 |
+
|
| 227 |
+
function setMiningLeader(address _miningLeader) external onlyOwner {
|
| 228 |
+
miningLeader = ERC918Interface(_miningLeader);
|
| 229 |
+
}
|
| 230 |
+
|
| 231 |
+
|
| 232 |
+
function setMintHelper(address _mintHelper) external onlyOwner {
|
| 233 |
+
mintHelper = _mintHelper;
|
| 234 |
+
}
|
| 235 |
+
|
| 236 |
+
|
| 237 |
+
function setRewardDivisor(uint _rewardDivisor) external onlyOwner {
|
| 238 |
+
rewardDivisor = _rewardDivisor;
|
| 239 |
+
}
|
| 240 |
+
|
| 241 |
+
|
| 242 |
+
function () public payable {
|
| 243 |
+
|
| 244 |
+
revert('Oops! Direct payments are NOT permitted here.');
|
| 245 |
+
}
|
| 246 |
+
|
| 247 |
+
|
| 248 |
+
function transferAnyERC20Token(
|
| 249 |
+
address tokenAddress, uint tokens
|
| 250 |
+
) public onlyOwner returns (bool success) {
|
| 251 |
+
return ERC20Interface(tokenAddress).transfer(owner, tokens);
|
| 252 |
+
}
|
| 253 |
+
}
|
smart_contract_dataset/block number dependency/1121.sol
ADDED
|
@@ -0,0 +1,222 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
pragma solidity ^0.4.24;
|
| 2 |
+
|
| 3 |
+
library SafeMath {
|
| 4 |
+
|
| 5 |
+
|
| 6 |
+
function mul(uint256 a, uint256 b) internal pure returns (uint256 c) {
|
| 7 |
+
|
| 8 |
+
|
| 9 |
+
|
| 10 |
+
if (a == 0) {
|
| 11 |
+
return 0;
|
| 12 |
+
}
|
| 13 |
+
|
| 14 |
+
c = a * b;
|
| 15 |
+
assert(c / a == b);
|
| 16 |
+
return c;
|
| 17 |
+
}
|
| 18 |
+
|
| 19 |
+
|
| 20 |
+
function div(uint256 a, uint256 b) internal pure returns (uint256) {
|
| 21 |
+
|
| 22 |
+
|
| 23 |
+
|
| 24 |
+
return a / b;
|
| 25 |
+
}
|
| 26 |
+
|
| 27 |
+
|
| 28 |
+
function sub(uint256 a, uint256 b) internal pure returns (uint256) {
|
| 29 |
+
assert(b <= a);
|
| 30 |
+
return a - b;
|
| 31 |
+
}
|
| 32 |
+
|
| 33 |
+
|
| 34 |
+
function add(uint256 a, uint256 b) internal pure returns (uint256 c) {
|
| 35 |
+
c = a + b;
|
| 36 |
+
assert(c >= a);
|
| 37 |
+
return c;
|
| 38 |
+
}
|
| 39 |
+
}
|
| 40 |
+
|
| 41 |
+
contract Ownable {
|
| 42 |
+
address public owner;
|
| 43 |
+
|
| 44 |
+
|
| 45 |
+
event OwnershipRenounced(address indexed previousOwner);
|
| 46 |
+
event OwnershipTransferred(
|
| 47 |
+
address indexed previousOwner,
|
| 48 |
+
address indexed newOwner
|
| 49 |
+
);
|
| 50 |
+
|
| 51 |
+
|
| 52 |
+
|
| 53 |
+
constructor() public {
|
| 54 |
+
owner = msg.sender;
|
| 55 |
+
}
|
| 56 |
+
|
| 57 |
+
|
| 58 |
+
modifier onlyOwner() {
|
| 59 |
+
require(msg.sender == owner);
|
| 60 |
+
_;
|
| 61 |
+
}
|
| 62 |
+
|
| 63 |
+
|
| 64 |
+
function renounceOwnership() public onlyOwner {
|
| 65 |
+
emit OwnershipRenounced(owner);
|
| 66 |
+
owner = address(0);
|
| 67 |
+
}
|
| 68 |
+
|
| 69 |
+
|
| 70 |
+
function transferOwnership(address _newOwner) public onlyOwner {
|
| 71 |
+
_transferOwnership(_newOwner);
|
| 72 |
+
}
|
| 73 |
+
|
| 74 |
+
|
| 75 |
+
function _transferOwnership(address _newOwner) internal {
|
| 76 |
+
require(_newOwner != address(0));
|
| 77 |
+
emit OwnershipTransferred(owner, _newOwner);
|
| 78 |
+
owner = _newOwner;
|
| 79 |
+
}
|
| 80 |
+
}
|
| 81 |
+
|
| 82 |
+
contract Claimable is Ownable {
|
| 83 |
+
address public pendingOwner;
|
| 84 |
+
|
| 85 |
+
|
| 86 |
+
modifier onlyPendingOwner() {
|
| 87 |
+
require(msg.sender == pendingOwner);
|
| 88 |
+
_;
|
| 89 |
+
}
|
| 90 |
+
|
| 91 |
+
|
| 92 |
+
function transferOwnership(address newOwner) onlyOwner public {
|
| 93 |
+
pendingOwner = newOwner;
|
| 94 |
+
}
|
| 95 |
+
|
| 96 |
+
|
| 97 |
+
function claimOwnership() onlyPendingOwner public {
|
| 98 |
+
emit OwnershipTransferred(owner, pendingOwner);
|
| 99 |
+
owner = pendingOwner;
|
| 100 |
+
pendingOwner = address(0);
|
| 101 |
+
}
|
| 102 |
+
}
|
| 103 |
+
|
| 104 |
+
contract SimpleFlyDropToken is Claimable {
|
| 105 |
+
using SafeMath for uint256;
|
| 106 |
+
|
| 107 |
+
ERC20 internal erc20tk;
|
| 108 |
+
|
| 109 |
+
function setToken(address _token) onlyOwner public {
|
| 110 |
+
require(_token != address(0));
|
| 111 |
+
erc20tk = ERC20(_token);
|
| 112 |
+
}
|
| 113 |
+
|
| 114 |
+
|
| 115 |
+
function multiSend(address[] _destAddrs, uint256[] _values) onlyOwner public returns (uint256) {
|
| 116 |
+
require(_destAddrs.length == _values.length);
|
| 117 |
+
|
| 118 |
+
uint256 i = 0;
|
| 119 |
+
for (; i < _destAddrs.length; i = i.add(1)) {
|
| 120 |
+
if (!erc20tk.transfer(_destAddrs[i], _values[i])) {
|
| 121 |
+
break;
|
| 122 |
+
}
|
| 123 |
+
}
|
| 124 |
+
|
| 125 |
+
return (i);
|
| 126 |
+
}
|
| 127 |
+
}
|
| 128 |
+
|
| 129 |
+
contract DelayedClaimable is Claimable {
|
| 130 |
+
|
| 131 |
+
uint256 public end;
|
| 132 |
+
uint256 public start;
|
| 133 |
+
|
| 134 |
+
|
| 135 |
+
function setLimits(uint256 _start, uint256 _end) onlyOwner public {
|
| 136 |
+
require(_start <= _end);
|
| 137 |
+
end = _end;
|
| 138 |
+
start = _start;
|
| 139 |
+
}
|
| 140 |
+
|
| 141 |
+
|
| 142 |
+
function claimOwnership() onlyPendingOwner public {
|
| 143 |
+
require((block.number <= end) && (block.number >= start));
|
| 144 |
+
emit OwnershipTransferred(owner, pendingOwner);
|
| 145 |
+
owner = pendingOwner;
|
| 146 |
+
pendingOwner = address(0);
|
| 147 |
+
end = 0;
|
| 148 |
+
}
|
| 149 |
+
|
| 150 |
+
}
|
| 151 |
+
|
| 152 |
+
contract FlyDropTokenMgr is DelayedClaimable {
|
| 153 |
+
using SafeMath for uint256;
|
| 154 |
+
|
| 155 |
+
address[] dropTokenAddrs;
|
| 156 |
+
SimpleFlyDropToken currentDropTokenContract;
|
| 157 |
+
|
| 158 |
+
|
| 159 |
+
|
| 160 |
+
function prepare(uint256 _rand,
|
| 161 |
+
address _from,
|
| 162 |
+
address _token,
|
| 163 |
+
uint256 _value) onlyOwner public returns (bool) {
|
| 164 |
+
require(_token != address(0));
|
| 165 |
+
require(_from != address(0));
|
| 166 |
+
require(_rand > 0);
|
| 167 |
+
|
| 168 |
+
if (ERC20(_token).allowance(_from, this) < _value) {
|
| 169 |
+
return false;
|
| 170 |
+
}
|
| 171 |
+
|
| 172 |
+
if (_rand > dropTokenAddrs.length) {
|
| 173 |
+
SimpleFlyDropToken dropTokenContract = new SimpleFlyDropToken();
|
| 174 |
+
dropTokenAddrs.push(address(dropTokenContract));
|
| 175 |
+
currentDropTokenContract = dropTokenContract;
|
| 176 |
+
} else {
|
| 177 |
+
currentDropTokenContract = SimpleFlyDropToken(dropTokenAddrs[_rand.sub(1)]);
|
| 178 |
+
}
|
| 179 |
+
|
| 180 |
+
currentDropTokenContract.setToken(_token);
|
| 181 |
+
return ERC20(_token).transferFrom(_from, currentDropTokenContract, _value);
|
| 182 |
+
|
| 183 |
+
|
| 184 |
+
|
| 185 |
+
}
|
| 186 |
+
|
| 187 |
+
|
| 188 |
+
|
| 189 |
+
|
| 190 |
+
|
| 191 |
+
|
| 192 |
+
|
| 193 |
+
|
| 194 |
+
|
| 195 |
+
function flyDrop(address[] _destAddrs, uint256[] _values) onlyOwner public returns (uint256) {
|
| 196 |
+
require(address(currentDropTokenContract) != address(0));
|
| 197 |
+
return currentDropTokenContract.multiSend(_destAddrs, _values);
|
| 198 |
+
}
|
| 199 |
+
|
| 200 |
+
}
|
| 201 |
+
|
| 202 |
+
contract ERC20Basic {
|
| 203 |
+
function totalSupply() public view returns (uint256);
|
| 204 |
+
function balanceOf(address who) public view returns (uint256);
|
| 205 |
+
function transfer(address to, uint256 value) public returns (bool);
|
| 206 |
+
event Transfer(address indexed from, address indexed to, uint256 value);
|
| 207 |
+
}
|
| 208 |
+
|
| 209 |
+
contract ERC20 is ERC20Basic {
|
| 210 |
+
function allowance(address owner, address spender)
|
| 211 |
+
public view returns (uint256);
|
| 212 |
+
|
| 213 |
+
function transferFrom(address from, address to, uint256 value)
|
| 214 |
+
public returns (bool);
|
| 215 |
+
|
| 216 |
+
function approve(address spender, uint256 value) public returns (bool);
|
| 217 |
+
event Approval(
|
| 218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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
pragma solidity ^0.4.24;
|
| 2 |
+
|
| 3 |
+
|
| 4 |
+
|
| 5 |
+
contract ZTHReceivingContract {
|
| 6 |
+
|
| 7 |
+
function tokenFallback(address _from, uint _value, bytes _data) public returns (bool);
|
| 8 |
+
}
|
| 9 |
+
|
| 10 |
+
|
| 11 |
+
contract ZTHInterface {
|
| 12 |
+
function getFrontEndTokenBalanceOf(address who) public view returns (uint);
|
| 13 |
+
function transfer(address _to, uint _value) public returns (bool);
|
| 14 |
+
function approve(address spender, uint tokens) public returns (bool);
|
| 15 |
+
}
|
| 16 |
+
|
| 17 |
+
contract Zethroll is ZTHReceivingContract {
|
| 18 |
+
using SafeMath for uint;
|
| 19 |
+
|
| 20 |
+
|
| 21 |
+
|
| 22 |
+
modifier betIsValid(uint _betSize, uint _playerNumber) {
|
| 23 |
+
require( calculateProfit(_betSize, _playerNumber) < maxProfit
|
| 24 |
+
&& _betSize >= minBet
|
| 25 |
+
&& _playerNumber > minNumber
|
| 26 |
+
&& _playerNumber < maxNumber);
|
| 27 |
+
_;
|
| 28 |
+
}
|
| 29 |
+
|
| 30 |
+
|
| 31 |
+
modifier gameIsActive {
|
| 32 |
+
require(gamePaused == false);
|
| 33 |
+
_;
|
| 34 |
+
}
|
| 35 |
+
|
| 36 |
+
|
| 37 |
+
modifier onlyOwner {
|
| 38 |
+
require(msg.sender == owner);
|
| 39 |
+
_;
|
| 40 |
+
}
|
| 41 |
+
|
| 42 |
+
|
| 43 |
+
uint constant private MAX_INT = 2 ** 256 - 1;
|
| 44 |
+
uint constant public maxProfitDivisor = 1000000;
|
| 45 |
+
uint constant public maxNumber = 99;
|
| 46 |
+
uint constant public minNumber = 2;
|
| 47 |
+
uint constant public houseEdgeDivisor = 1000;
|
| 48 |
+
|
| 49 |
+
|
| 50 |
+
bool public gamePaused;
|
| 51 |
+
|
| 52 |
+
address public owner;
|
| 53 |
+
address public ZethrBankroll;
|
| 54 |
+
address public ZTHTKNADDR;
|
| 55 |
+
|
| 56 |
+
ZTHInterface public ZTHTKN;
|
| 57 |
+
|
| 58 |
+
uint public contractBalance;
|
| 59 |
+
uint public houseEdge;
|
| 60 |
+
uint public maxProfit;
|
| 61 |
+
uint public maxProfitAsPercentOfHouse;
|
| 62 |
+
uint public minBet = 0;
|
| 63 |
+
|
| 64 |
+
|
| 65 |
+
uint public totalBets;
|
| 66 |
+
uint public totalZTHWagered;
|
| 67 |
+
|
| 68 |
+
|
| 69 |
+
|
| 70 |
+
|
| 71 |
+
event LogBet(address sender, uint value, uint rollUnder);
|
| 72 |
+
|
| 73 |
+
|
| 74 |
+
|
| 75 |
+
event LogResult(address player, uint result, uint rollUnder, uint profit, uint tokensBetted, bool won);
|
| 76 |
+
|
| 77 |
+
|
| 78 |
+
event LogOwnerTransfer(address indexed SentToAddress, uint indexed AmountTransferred);
|
| 79 |
+
|
| 80 |
+
|
| 81 |
+
event MaxProfitChanged(uint _oldMaxProfit, uint _newMaxProfit);
|
| 82 |
+
|
| 83 |
+
|
| 84 |
+
event CurrentContractBalance(uint _tokens);
|
| 85 |
+
|
| 86 |
+
constructor (address zthtknaddr, address zthbankrolladdr) public {
|
| 87 |
+
|
| 88 |
+
owner = msg.sender;
|
| 89 |
+
|
| 90 |
+
|
| 91 |
+
ZTHTKN = ZTHInterface(zthtknaddr);
|
| 92 |
+
ZTHTKNADDR = zthtknaddr;
|
| 93 |
+
|
| 94 |
+
|
| 95 |
+
ZethrBankroll = zthbankrolladdr;
|
| 96 |
+
|
| 97 |
+
|
| 98 |
+
houseEdge = 990;
|
| 99 |
+
|
| 100 |
+
|
| 101 |
+
ownerSetMaxProfitAsPercentOfHouse(10000);
|
| 102 |
+
|
| 103 |
+
|
| 104 |
+
ownerSetMinBet(1e18);
|
| 105 |
+
|
| 106 |
+
|
| 107 |
+
ZTHTKN.approve(zthbankrolladdr, MAX_INT);
|
| 108 |
+
}
|
| 109 |
+
|
| 110 |
+
function() public payable {}
|
| 111 |
+
|
| 112 |
+
|
| 113 |
+
|
| 114 |
+
function maxRandom(uint blockn, address entropy) public view returns (uint256 randomNumber) {
|
| 115 |
+
return uint256(keccak256(
|
| 116 |
+
abi.encodePacked(
|
| 117 |
+
blockhash(blockn),
|
| 118 |
+
entropy)
|
| 119 |
+
));
|
| 120 |
+
}
|
| 121 |
+
|
| 122 |
+
|
| 123 |
+
function random(uint256 upper, uint256 blockn, address entropy) internal view returns (uint256 randomNumber) {
|
| 124 |
+
return maxRandom(blockn, entropy) % upper;
|
| 125 |
+
}
|
| 126 |
+
|
| 127 |
+
|
| 128 |
+
function calculateProfit(uint _initBet, uint _roll)
|
| 129 |
+
private
|
| 130 |
+
view
|
| 131 |
+
returns (uint)
|
| 132 |
+
{
|
| 133 |
+
return ((((_initBet * (100 - (_roll.sub(1)))) / (_roll.sub(1)) + _initBet)) * houseEdge / houseEdgeDivisor) - _initBet;
|
| 134 |
+
}
|
| 135 |
+
|
| 136 |
+
|
| 137 |
+
struct playerRoll{
|
| 138 |
+
uint200 tokenValue;
|
| 139 |
+
uint48 blockn;
|
| 140 |
+
uint8 rollUnder;
|
| 141 |
+
}
|
| 142 |
+
|
| 143 |
+
|
| 144 |
+
mapping(address => playerRoll) public playerRolls;
|
| 145 |
+
|
| 146 |
+
function _playerRollDice(uint _rollUnder, TKN _tkn) private
|
| 147 |
+
gameIsActive
|
| 148 |
+
betIsValid(_tkn.value, _rollUnder)
|
| 149 |
+
{
|
| 150 |
+
require(_tkn.value < ((2 ** 200) - 1));
|
| 151 |
+
require(block.number < ((2 ** 48) - 1));
|
| 152 |
+
|
| 153 |
+
|
| 154 |
+
|
| 155 |
+
|
| 156 |
+
|
| 157 |
+
require(_zthToken(msg.sender));
|
| 158 |
+
|
| 159 |
+
playerRoll memory roll = playerRolls[_tkn.sender];
|
| 160 |
+
|
| 161 |
+
|
| 162 |
+
require(block.number != roll.blockn);
|
| 163 |
+
|
| 164 |
+
|
| 165 |
+
if (roll.blockn != 0) {
|
| 166 |
+
_finishBet(false, _tkn.sender);
|
| 167 |
+
}
|
| 168 |
+
|
| 169 |
+
|
| 170 |
+
roll.blockn = uint48(block.number);
|
| 171 |
+
roll.tokenValue = uint200(_tkn.value);
|
| 172 |
+
roll.rollUnder = uint8(_rollUnder);
|
| 173 |
+
|
| 174 |
+
|
| 175 |
+
playerRolls[_tkn.sender] = roll;
|
| 176 |
+
|
| 177 |
+
|
| 178 |
+
emit LogBet(_tkn.sender, _tkn.value, _rollUnder);
|
| 179 |
+
|
| 180 |
+
|
| 181 |
+
totalBets += 1;
|
| 182 |
+
|
| 183 |
+
|
| 184 |
+
totalZTHWagered += _tkn.value;
|
| 185 |
+
}
|
| 186 |
+
|
| 187 |
+
|
| 188 |
+
function finishBet() public
|
| 189 |
+
gameIsActive
|
| 190 |
+
returns (uint)
|
| 191 |
+
{
|
| 192 |
+
return _finishBet(true, msg.sender);
|
| 193 |
+
}
|
| 194 |
+
|
| 195 |
+
|
| 196 |
+
function _finishBet(bool delete_it, address target) private returns (uint){
|
| 197 |
+
playerRoll memory roll = playerRolls[target];
|
| 198 |
+
require(roll.tokenValue > 0);
|
| 199 |
+
require(roll.blockn != block.number);
|
| 200 |
+
|
| 201 |
+
|
| 202 |
+
uint result;
|
| 203 |
+
if (block.number - roll.blockn > 255) {
|
| 204 |
+
result = 1000;
|
| 205 |
+
} else {
|
| 206 |
+
|
| 207 |
+
result = random(99, roll.blockn, target) + 1;
|
| 208 |
+
}
|
| 209 |
+
|
| 210 |
+
uint rollUnder = roll.rollUnder;
|
| 211 |
+
|
| 212 |
+
if (result < rollUnder) {
|
| 213 |
+
|
| 214 |
+
|
| 215 |
+
|
| 216 |
+
uint profit = calculateProfit(roll.tokenValue, rollUnder);
|
| 217 |
+
|
| 218 |
+
if (profit > maxProfit){
|
| 219 |
+
profit = maxProfit;
|
| 220 |
+
}
|
| 221 |
+
|
| 222 |
+
|
| 223 |
+
contractBalance = contractBalance.sub(profit);
|
| 224 |
+
|
| 225 |
+
emit LogResult(target, result, rollUnder, profit, roll.tokenValue, true);
|
| 226 |
+
|
| 227 |
+
|
| 228 |
+
setMaxProfit();
|
| 229 |
+
|
| 230 |
+
|
| 231 |
+
|
| 232 |
+
playerRolls[target] = playerRoll(uint200(0), uint48(0), uint8(0));
|
| 233 |
+
|
| 234 |
+
|
| 235 |
+
|
| 236 |
+
ZTHTKN.transfer(target, profit + roll.tokenValue);
|
| 237 |
+
|
| 238 |
+
return result;
|
| 239 |
+
|
| 240 |
+
} else {
|
| 241 |
+
|
| 242 |
+
emit LogResult(target, result, rollUnder, profit, roll.tokenValue, false);
|
| 243 |
+
|
| 244 |
+
|
| 245 |
+
contractBalance = contractBalance.add(roll.tokenValue);
|
| 246 |
+
|
| 247 |
+
playerRolls[target] = playerRoll(uint200(0), uint48(0), uint8(0));
|
| 248 |
+
|
| 249 |
+
|
| 250 |
+
|
| 251 |
+
|
| 252 |
+
setMaxProfit();
|
| 253 |
+
|
| 254 |
+
return result;
|
| 255 |
+
}
|
| 256 |
+
}
|
| 257 |
+
|
| 258 |
+
|
| 259 |
+
struct TKN {address sender; uint value;}
|
| 260 |
+
|
| 261 |
+
|
| 262 |
+
function tokenFallback(address _from, uint _value, bytes _data) public returns (bool) {
|
| 263 |
+
require(msg.sender == ZTHTKNADDR);
|
| 264 |
+
if (_from == ZethrBankroll) {
|
| 265 |
+
|
| 266 |
+
contractBalance = contractBalance.add(_value);
|
| 267 |
+
|
| 268 |
+
|
| 269 |
+
uint oldMaxProfit = maxProfit;
|
| 270 |
+
setMaxProfit();
|
| 271 |
+
|
| 272 |
+
emit MaxProfitChanged(oldMaxProfit, maxProfit);
|
| 273 |
+
return true;
|
| 274 |
+
|
| 275 |
+
} else {
|
| 276 |
+
TKN memory _tkn;
|
| 277 |
+
_tkn.sender = _from;
|
| 278 |
+
_tkn.value = _value;
|
| 279 |
+
uint8 chosenNumber = uint8(_data[0]);
|
| 280 |
+
_playerRollDice(chosenNumber, _tkn);
|
| 281 |
+
}
|
| 282 |
+
|
| 283 |
+
return true;
|
| 284 |
+
}
|
| 285 |
+
|
| 286 |
+
|
| 287 |
+
function setMaxProfit() internal {
|
| 288 |
+
emit CurrentContractBalance(contractBalance);
|
| 289 |
+
maxProfit = (contractBalance * maxProfitAsPercentOfHouse) / maxProfitDivisor;
|
| 290 |
+
}
|
| 291 |
+
|
| 292 |
+
|
| 293 |
+
function ownerUpdateContractBalance(uint newContractBalance) public
|
| 294 |
+
onlyOwner
|
| 295 |
+
{
|
| 296 |
+
contractBalance = newContractBalance;
|
| 297 |
+
}
|
| 298 |
+
|
| 299 |
+
|
| 300 |
+
function ownerSetMaxProfitAsPercentOfHouse(uint newMaxProfitAsPercent) public
|
| 301 |
+
onlyOwner
|
| 302 |
+
{
|
| 303 |
+
|
| 304 |
+
require(newMaxProfitAsPercent <= 200000);
|
| 305 |
+
maxProfitAsPercentOfHouse = newMaxProfitAsPercent;
|
| 306 |
+
setMaxProfit();
|
| 307 |
+
}
|
| 308 |
+
|
| 309 |
+
|
| 310 |
+
function ownerSetMinBet(uint newMinimumBet) public
|
| 311 |
+
onlyOwner
|
| 312 |
+
{
|
| 313 |
+
minBet = newMinimumBet;
|
| 314 |
+
}
|
| 315 |
+
|
| 316 |
+
|
| 317 |
+
function ownerTransferZTH(address sendTo, uint amount) public
|
| 318 |
+
onlyOwner
|
| 319 |
+
{
|
| 320 |
+
|
| 321 |
+
contractBalance = contractBalance.sub(amount);
|
| 322 |
+
|
| 323 |
+
|
| 324 |
+
setMaxProfit();
|
| 325 |
+
require(ZTHTKN.transfer(sendTo, amount));
|
| 326 |
+
emit LogOwnerTransfer(sendTo, amount);
|
| 327 |
+
}
|
| 328 |
+
|
| 329 |
+
|
| 330 |
+
function ownerPauseGame(bool newStatus) public
|
| 331 |
+
onlyOwner
|
| 332 |
+
{
|
| 333 |
+
gamePaused = newStatus;
|
| 334 |
+
}
|
| 335 |
+
|
| 336 |
+
|
| 337 |
+
function ownerSetBankroll(address newBankroll) public
|
| 338 |
+
onlyOwner
|
| 339 |
+
{
|
| 340 |
+
ZTHTKN.approve(ZethrBankroll, 0);
|
| 341 |
+
ZethrBankroll = newBankroll;
|
| 342 |
+
ZTHTKN.approve(newBankroll, MAX_INT);
|
| 343 |
+
}
|
| 344 |
+
|
| 345 |
+
|
| 346 |
+
function ownerChangeOwner(address newOwner) public
|
| 347 |
+
onlyOwner
|
| 348 |
+
{
|
| 349 |
+
owner = newOwner;
|
| 350 |
+
}
|
| 351 |
+
|
| 352 |
+
|
| 353 |
+
function ownerkill() public
|
| 354 |
+
onlyOwner
|
| 355 |
+
{
|
| 356 |
+
ZTHTKN.transfer(owner, contractBalance);
|
| 357 |
+
selfdestruct(owner);
|
| 358 |
+
}
|
| 359 |
+
|
| 360 |
+
function dumpdivs() public{
|
| 361 |
+
ZethrBankroll.transfer(address(this).balance);
|
| 362 |
+
}
|
| 363 |
+
|
| 364 |
+
function _zthToken(address _tokenContract) private view returns (bool) {
|
| 365 |
+
return _tokenContract == ZTHTKNADDR;
|
| 366 |
+
|
| 367 |
+
}
|
| 368 |
+
}
|
| 369 |
+
|
| 370 |
+
|
| 371 |
+
library SafeMath {
|
| 372 |
+
|
| 373 |
+
|
| 374 |
+
function mul(uint a, uint b) internal pure returns (uint) {
|
| 375 |
+
if (a == 0) {
|
| 376 |
+
return 0;
|
| 377 |
+
}
|
| 378 |
+
uint c = a * b;
|
| 379 |
+
assert(c / a == b);
|
| 380 |
+
return c;
|
| 381 |
+
}
|
| 382 |
+
|
| 383 |
+
|
| 384 |
+
function div(uint a, uint b) internal pure returns (uint) {
|
| 385 |
+
|
| 386 |
+
uint c = a / b;
|
| 387 |
+
|
| 388 |
+
return c;
|
| 389 |
+
}
|
| 390 |
+
|
| 391 |
+
|
| 392 |
+
function sub(uint a, uint b) internal pure returns (uint) {
|
| 393 |
+
assert(b <= a);
|
| 394 |
+
return a - b;
|
| 395 |
+
}
|
| 396 |
+
|
| 397 |
+
|
| 398 |
+
function add(uint a, uint b) internal pure returns (uint) {
|
| 399 |
+
uint c = a + b;
|
| 400 |
+
assert(c >= a);
|
| 401 |
+
return c;
|
| 402 |
+
}
|
| 403 |
+
}
|
smart_contract_dataset/block number dependency/1165.sol
ADDED
|
@@ -0,0 +1,222 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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|
| 7 |
+
|
| 8 |
+
|
| 9 |
+
|
| 10 |
+
if (a == 0) {
|
| 11 |
+
return 0;
|
| 12 |
+
}
|
| 13 |
+
|
| 14 |
+
c = a * b;
|
| 15 |
+
assert(c / a == b);
|
| 16 |
+
return c;
|
| 17 |
+
}
|
| 18 |
+
|
| 19 |
+
|
| 20 |
+
function div(uint256 a, uint256 b) internal pure returns (uint256) {
|
| 21 |
+
|
| 22 |
+
|
| 23 |
+
|
| 24 |
+
return a / b;
|
| 25 |
+
}
|
| 26 |
+
|
| 27 |
+
|
| 28 |
+
function sub(uint256 a, uint256 b) internal pure returns (uint256) {
|
| 29 |
+
assert(b <= a);
|
| 30 |
+
return a - b;
|
| 31 |
+
}
|
| 32 |
+
|
| 33 |
+
|
| 34 |
+
function add(uint256 a, uint256 b) internal pure returns (uint256 c) {
|
| 35 |
+
c = a + b;
|
| 36 |
+
assert(c >= a);
|
| 37 |
+
return c;
|
| 38 |
+
}
|
| 39 |
+
}
|
| 40 |
+
|
| 41 |
+
contract Ownable {
|
| 42 |
+
address public owner;
|
| 43 |
+
|
| 44 |
+
|
| 45 |
+
event OwnershipRenounced(address indexed previousOwner);
|
| 46 |
+
event OwnershipTransferred(
|
| 47 |
+
address indexed previousOwner,
|
| 48 |
+
address indexed newOwner
|
| 49 |
+
);
|
| 50 |
+
|
| 51 |
+
|
| 52 |
+
|
| 53 |
+
constructor() public {
|
| 54 |
+
owner = msg.sender;
|
| 55 |
+
}
|
| 56 |
+
|
| 57 |
+
|
| 58 |
+
modifier onlyOwner() {
|
| 59 |
+
require(msg.sender == owner);
|
| 60 |
+
_;
|
| 61 |
+
}
|
| 62 |
+
|
| 63 |
+
|
| 64 |
+
function renounceOwnership() public onlyOwner {
|
| 65 |
+
emit OwnershipRenounced(owner);
|
| 66 |
+
owner = address(0);
|
| 67 |
+
}
|
| 68 |
+
|
| 69 |
+
|
| 70 |
+
function transferOwnership(address _newOwner) public onlyOwner {
|
| 71 |
+
_transferOwnership(_newOwner);
|
| 72 |
+
}
|
| 73 |
+
|
| 74 |
+
|
| 75 |
+
function _transferOwnership(address _newOwner) internal {
|
| 76 |
+
require(_newOwner != address(0));
|
| 77 |
+
emit OwnershipTransferred(owner, _newOwner);
|
| 78 |
+
owner = _newOwner;
|
| 79 |
+
}
|
| 80 |
+
}
|
| 81 |
+
|
| 82 |
+
contract Claimable is Ownable {
|
| 83 |
+
address public pendingOwner;
|
| 84 |
+
|
| 85 |
+
|
| 86 |
+
modifier onlyPendingOwner() {
|
| 87 |
+
require(msg.sender == pendingOwner);
|
| 88 |
+
_;
|
| 89 |
+
}
|
| 90 |
+
|
| 91 |
+
|
| 92 |
+
function transferOwnership(address newOwner) onlyOwner public {
|
| 93 |
+
pendingOwner = newOwner;
|
| 94 |
+
}
|
| 95 |
+
|
| 96 |
+
|
| 97 |
+
function claimOwnership() onlyPendingOwner public {
|
| 98 |
+
emit OwnershipTransferred(owner, pendingOwner);
|
| 99 |
+
owner = pendingOwner;
|
| 100 |
+
pendingOwner = address(0);
|
| 101 |
+
}
|
| 102 |
+
}
|
| 103 |
+
|
| 104 |
+
contract SimpleFlyDropToken is Claimable {
|
| 105 |
+
using SafeMath for uint256;
|
| 106 |
+
|
| 107 |
+
ERC20 internal erc20tk;
|
| 108 |
+
|
| 109 |
+
function setToken(address _token) onlyOwner public {
|
| 110 |
+
require(_token != address(0));
|
| 111 |
+
erc20tk = ERC20(_token);
|
| 112 |
+
}
|
| 113 |
+
|
| 114 |
+
|
| 115 |
+
function multiSend(address[] _destAddrs, uint256[] _values) onlyOwner public returns (uint256) {
|
| 116 |
+
require(_destAddrs.length == _values.length);
|
| 117 |
+
|
| 118 |
+
uint256 i = 0;
|
| 119 |
+
for (; i < _destAddrs.length; i = i.add(1)) {
|
| 120 |
+
if (!erc20tk.transfer(_destAddrs[i], _values[i])) {
|
| 121 |
+
break;
|
| 122 |
+
}
|
| 123 |
+
}
|
| 124 |
+
|
| 125 |
+
return (i);
|
| 126 |
+
}
|
| 127 |
+
}
|
| 128 |
+
|
| 129 |
+
contract DelayedClaimable is Claimable {
|
| 130 |
+
|
| 131 |
+
uint256 public end;
|
| 132 |
+
uint256 public start;
|
| 133 |
+
|
| 134 |
+
|
| 135 |
+
function setLimits(uint256 _start, uint256 _end) onlyOwner public {
|
| 136 |
+
require(_start <= _end);
|
| 137 |
+
end = _end;
|
| 138 |
+
start = _start;
|
| 139 |
+
}
|
| 140 |
+
|
| 141 |
+
|
| 142 |
+
function claimOwnership() onlyPendingOwner public {
|
| 143 |
+
require((block.number <= end) && (block.number >= start));
|
| 144 |
+
emit OwnershipTransferred(owner, pendingOwner);
|
| 145 |
+
owner = pendingOwner;
|
| 146 |
+
pendingOwner = address(0);
|
| 147 |
+
end = 0;
|
| 148 |
+
}
|
| 149 |
+
|
| 150 |
+
}
|
| 151 |
+
|
| 152 |
+
contract FlyDropTokenMgr is DelayedClaimable {
|
| 153 |
+
using SafeMath for uint256;
|
| 154 |
+
|
| 155 |
+
address[] dropTokenAddrs;
|
| 156 |
+
SimpleFlyDropToken currentDropTokenContract;
|
| 157 |
+
|
| 158 |
+
|
| 159 |
+
|
| 160 |
+
function prepare(uint256 _rand,
|
| 161 |
+
address _from,
|
| 162 |
+
address _token,
|
| 163 |
+
uint256 _value) onlyOwner public returns (bool) {
|
| 164 |
+
require(_token != address(0));
|
| 165 |
+
require(_from != address(0));
|
| 166 |
+
require(_rand > 0);
|
| 167 |
+
|
| 168 |
+
if (ERC20(_token).allowance(_from, this) < _value) {
|
| 169 |
+
return false;
|
| 170 |
+
}
|
| 171 |
+
|
| 172 |
+
if (_rand > dropTokenAddrs.length) {
|
| 173 |
+
SimpleFlyDropToken dropTokenContract = new SimpleFlyDropToken();
|
| 174 |
+
dropTokenAddrs.push(address(dropTokenContract));
|
| 175 |
+
currentDropTokenContract = dropTokenContract;
|
| 176 |
+
} else {
|
| 177 |
+
currentDropTokenContract = SimpleFlyDropToken(dropTokenAddrs[_rand.sub(1)]);
|
| 178 |
+
}
|
| 179 |
+
|
| 180 |
+
currentDropTokenContract.setToken(_token);
|
| 181 |
+
return ERC20(_token).transferFrom(_from, currentDropTokenContract, _value);
|
| 182 |
+
|
| 183 |
+
|
| 184 |
+
|
| 185 |
+
}
|
| 186 |
+
|
| 187 |
+
|
| 188 |
+
|
| 189 |
+
|
| 190 |
+
|
| 191 |
+
|
| 192 |
+
|
| 193 |
+
|
| 194 |
+
|
| 195 |
+
function flyDrop(address[] _destAddrs, uint256[] _values) onlyOwner public returns (uint256) {
|
| 196 |
+
require(address(currentDropTokenContract) != address(0));
|
| 197 |
+
return currentDropTokenContract.multiSend(_destAddrs, _values);
|
| 198 |
+
}
|
| 199 |
+
|
| 200 |
+
}
|
| 201 |
+
|
| 202 |
+
contract ERC20Basic {
|
| 203 |
+
function totalSupply() public view returns (uint256);
|
| 204 |
+
function balanceOf(address who) public view returns (uint256);
|
| 205 |
+
function transfer(address to, uint256 value) public returns (bool);
|
| 206 |
+
event Transfer(address indexed from, address indexed to, uint256 value);
|
| 207 |
+
}
|
| 208 |
+
|
| 209 |
+
contract ERC20 is ERC20Basic {
|
| 210 |
+
function allowance(address owner, address spender)
|
| 211 |
+
public view returns (uint256);
|
| 212 |
+
|
| 213 |
+
function transferFrom(address from, address to, uint256 value)
|
| 214 |
+
public returns (bool);
|
| 215 |
+
|
| 216 |
+
function approve(address spender, uint256 value) public returns (bool);
|
| 217 |
+
event Approval(
|
| 218 |
+
address indexed owner,
|
| 219 |
+
address indexed spender,
|
| 220 |
+
uint256 value
|
| 221 |
+
);
|
| 222 |
+
}
|
smart_contract_dataset/block number dependency/129.sol
ADDED
|
@@ -0,0 +1,222 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
pragma solidity ^0.4.24;
|
| 2 |
+
|
| 3 |
+
library SafeMath {
|
| 4 |
+
|
| 5 |
+
|
| 6 |
+
function mul(uint256 a, uint256 b) internal pure returns (uint256 c) {
|
| 7 |
+
|
| 8 |
+
|
| 9 |
+
|
| 10 |
+
if (a == 0) {
|
| 11 |
+
return 0;
|
| 12 |
+
}
|
| 13 |
+
|
| 14 |
+
c = a * b;
|
| 15 |
+
assert(c / a == b);
|
| 16 |
+
return c;
|
| 17 |
+
}
|
| 18 |
+
|
| 19 |
+
|
| 20 |
+
function div(uint256 a, uint256 b) internal pure returns (uint256) {
|
| 21 |
+
|
| 22 |
+
|
| 23 |
+
|
| 24 |
+
return a / b;
|
| 25 |
+
}
|
| 26 |
+
|
| 27 |
+
|
| 28 |
+
function sub(uint256 a, uint256 b) internal pure returns (uint256) {
|
| 29 |
+
assert(b <= a);
|
| 30 |
+
return a - b;
|
| 31 |
+
}
|
| 32 |
+
|
| 33 |
+
|
| 34 |
+
function add(uint256 a, uint256 b) internal pure returns (uint256 c) {
|
| 35 |
+
c = a + b;
|
| 36 |
+
assert(c >= a);
|
| 37 |
+
return c;
|
| 38 |
+
}
|
| 39 |
+
}
|
| 40 |
+
|
| 41 |
+
contract Ownable {
|
| 42 |
+
address public owner;
|
| 43 |
+
|
| 44 |
+
|
| 45 |
+
event OwnershipRenounced(address indexed previousOwner);
|
| 46 |
+
event OwnershipTransferred(
|
| 47 |
+
address indexed previousOwner,
|
| 48 |
+
address indexed newOwner
|
| 49 |
+
);
|
| 50 |
+
|
| 51 |
+
|
| 52 |
+
|
| 53 |
+
constructor() public {
|
| 54 |
+
owner = msg.sender;
|
| 55 |
+
}
|
| 56 |
+
|
| 57 |
+
|
| 58 |
+
modifier onlyOwner() {
|
| 59 |
+
require(msg.sender == owner);
|
| 60 |
+
_;
|
| 61 |
+
}
|
| 62 |
+
|
| 63 |
+
|
| 64 |
+
function renounceOwnership() public onlyOwner {
|
| 65 |
+
emit OwnershipRenounced(owner);
|
| 66 |
+
owner = address(0);
|
| 67 |
+
}
|
| 68 |
+
|
| 69 |
+
|
| 70 |
+
function transferOwnership(address _newOwner) public onlyOwner {
|
| 71 |
+
_transferOwnership(_newOwner);
|
| 72 |
+
}
|
| 73 |
+
|
| 74 |
+
|
| 75 |
+
function _transferOwnership(address _newOwner) internal {
|
| 76 |
+
require(_newOwner != address(0));
|
| 77 |
+
emit OwnershipTransferred(owner, _newOwner);
|
| 78 |
+
owner = _newOwner;
|
| 79 |
+
}
|
| 80 |
+
}
|
| 81 |
+
|
| 82 |
+
contract Claimable is Ownable {
|
| 83 |
+
address public pendingOwner;
|
| 84 |
+
|
| 85 |
+
|
| 86 |
+
modifier onlyPendingOwner() {
|
| 87 |
+
require(msg.sender == pendingOwner);
|
| 88 |
+
_;
|
| 89 |
+
}
|
| 90 |
+
|
| 91 |
+
|
| 92 |
+
function transferOwnership(address newOwner) onlyOwner public {
|
| 93 |
+
pendingOwner = newOwner;
|
| 94 |
+
}
|
| 95 |
+
|
| 96 |
+
|
| 97 |
+
function claimOwnership() onlyPendingOwner public {
|
| 98 |
+
emit OwnershipTransferred(owner, pendingOwner);
|
| 99 |
+
owner = pendingOwner;
|
| 100 |
+
pendingOwner = address(0);
|
| 101 |
+
}
|
| 102 |
+
}
|
| 103 |
+
|
| 104 |
+
contract SimpleFlyDropToken is Claimable {
|
| 105 |
+
using SafeMath for uint256;
|
| 106 |
+
|
| 107 |
+
ERC20 internal erc20tk;
|
| 108 |
+
|
| 109 |
+
function setToken(address _token) onlyOwner public {
|
| 110 |
+
require(_token != address(0));
|
| 111 |
+
erc20tk = ERC20(_token);
|
| 112 |
+
}
|
| 113 |
+
|
| 114 |
+
|
| 115 |
+
function multiSend(address[] _destAddrs, uint256[] _values) onlyOwner public returns (uint256) {
|
| 116 |
+
require(_destAddrs.length == _values.length);
|
| 117 |
+
|
| 118 |
+
uint256 i = 0;
|
| 119 |
+
for (; i < _destAddrs.length; i = i.add(1)) {
|
| 120 |
+
if (!erc20tk.transfer(_destAddrs[i], _values[i])) {
|
| 121 |
+
break;
|
| 122 |
+
}
|
| 123 |
+
}
|
| 124 |
+
|
| 125 |
+
return (i);
|
| 126 |
+
}
|
| 127 |
+
}
|
| 128 |
+
|
| 129 |
+
contract DelayedClaimable is Claimable {
|
| 130 |
+
|
| 131 |
+
uint256 public end;
|
| 132 |
+
uint256 public start;
|
| 133 |
+
|
| 134 |
+
|
| 135 |
+
function setLimits(uint256 _start, uint256 _end) onlyOwner public {
|
| 136 |
+
require(_start <= _end);
|
| 137 |
+
end = _end;
|
| 138 |
+
start = _start;
|
| 139 |
+
}
|
| 140 |
+
|
| 141 |
+
|
| 142 |
+
function claimOwnership() onlyPendingOwner public {
|
| 143 |
+
require((block.number <= end) && (block.number >= start));
|
| 144 |
+
emit OwnershipTransferred(owner, pendingOwner);
|
| 145 |
+
owner = pendingOwner;
|
| 146 |
+
pendingOwner = address(0);
|
| 147 |
+
end = 0;
|
| 148 |
+
}
|
| 149 |
+
|
| 150 |
+
}
|
| 151 |
+
|
| 152 |
+
contract FlyDropTokenMgr is DelayedClaimable {
|
| 153 |
+
using SafeMath for uint256;
|
| 154 |
+
|
| 155 |
+
address[] dropTokenAddrs;
|
| 156 |
+
SimpleFlyDropToken currentDropTokenContract;
|
| 157 |
+
|
| 158 |
+
|
| 159 |
+
|
| 160 |
+
function prepare(uint256 _rand,
|
| 161 |
+
address _from,
|
| 162 |
+
address _token,
|
| 163 |
+
uint256 _value) onlyOwner public returns (bool) {
|
| 164 |
+
require(_token != address(0));
|
| 165 |
+
require(_from != address(0));
|
| 166 |
+
require(_rand > 0);
|
| 167 |
+
|
| 168 |
+
if (ERC20(_token).allowance(_from, this) < _value) {
|
| 169 |
+
return false;
|
| 170 |
+
}
|
| 171 |
+
|
| 172 |
+
if (_rand > dropTokenAddrs.length) {
|
| 173 |
+
SimpleFlyDropToken dropTokenContract = new SimpleFlyDropToken();
|
| 174 |
+
dropTokenAddrs.push(address(dropTokenContract));
|
| 175 |
+
currentDropTokenContract = dropTokenContract;
|
| 176 |
+
} else {
|
| 177 |
+
currentDropTokenContract = SimpleFlyDropToken(dropTokenAddrs[_rand.sub(1)]);
|
| 178 |
+
}
|
| 179 |
+
|
| 180 |
+
currentDropTokenContract.setToken(_token);
|
| 181 |
+
return ERC20(_token).transferFrom(_from, currentDropTokenContract, _value);
|
| 182 |
+
|
| 183 |
+
|
| 184 |
+
|
| 185 |
+
}
|
| 186 |
+
|
| 187 |
+
|
| 188 |
+
|
| 189 |
+
|
| 190 |
+
|
| 191 |
+
|
| 192 |
+
|
| 193 |
+
|
| 194 |
+
|
| 195 |
+
function flyDrop(address[] _destAddrs, uint256[] _values) onlyOwner public returns (uint256) {
|
| 196 |
+
require(address(currentDropTokenContract) != address(0));
|
| 197 |
+
return currentDropTokenContract.multiSend(_destAddrs, _values);
|
| 198 |
+
}
|
| 199 |
+
|
| 200 |
+
}
|
| 201 |
+
|
| 202 |
+
contract ERC20Basic {
|
| 203 |
+
function totalSupply() public view returns (uint256);
|
| 204 |
+
function balanceOf(address who) public view returns (uint256);
|
| 205 |
+
function transfer(address to, uint256 value) public returns (bool);
|
| 206 |
+
event Transfer(address indexed from, address indexed to, uint256 value);
|
| 207 |
+
}
|
| 208 |
+
|
| 209 |
+
contract ERC20 is ERC20Basic {
|
| 210 |
+
function allowance(address owner, address spender)
|
| 211 |
+
public view returns (uint256);
|
| 212 |
+
|
| 213 |
+
function transferFrom(address from, address to, uint256 value)
|
| 214 |
+
public returns (bool);
|
| 215 |
+
|
| 216 |
+
function approve(address spender, uint256 value) public returns (bool);
|
| 217 |
+
event Approval(
|
| 218 |
+
address indexed owner,
|
| 219 |
+
address indexed spender,
|
| 220 |
+
uint256 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8 |
+
uint8 pumpRate;
|
| 9 |
+
bool hasChange;
|
| 10 |
+
}
|
| 11 |
+
|
| 12 |
+
address owner = 0x0;
|
| 13 |
+
uint32 gameIndex = 0;
|
| 14 |
+
uint256 totalPrice= 0;
|
| 15 |
+
ContractParam public setConfig;
|
| 16 |
+
ContractParam public curConfig;
|
| 17 |
+
|
| 18 |
+
address[] public addressArray = new address[](0);
|
| 19 |
+
|
| 20 |
+
|
| 21 |
+
event addPlayerEvent(uint32,address);
|
| 22 |
+
event GameOverEvent(uint32,uint32,uint256,uint8,address,uint );
|
| 23 |
+
|
| 24 |
+
|
| 25 |
+
constructor ( uint32 _totalSize,
|
| 26 |
+
uint256 _singlePrice
|
| 27 |
+
) public payable {
|
| 28 |
+
owner = msg.sender;
|
| 29 |
+
setConfig = ContractParam(_totalSize,_singlePrice * 1 finney ,5,false);
|
| 30 |
+
curConfig = ContractParam(_totalSize,_singlePrice * 1 finney ,5,false);
|
| 31 |
+
startNewGame();
|
| 32 |
+
}
|
| 33 |
+
|
| 34 |
+
modifier onlyOwner {
|
| 35 |
+
require(msg.sender == owner);
|
| 36 |
+
_;
|
| 37 |
+
}
|
| 38 |
+
|
| 39 |
+
function transferOwnership(address newOwner) onlyOwner public {
|
| 40 |
+
if (newOwner != address(0)) {
|
| 41 |
+
owner = newOwner;
|
| 42 |
+
}
|
| 43 |
+
}
|
| 44 |
+
|
| 45 |
+
function changeConfig( uint32 _totalSize,uint256 _singlePrice,uint8 _pumpRate) onlyOwner public payable {
|
| 46 |
+
|
| 47 |
+
curConfig.hasChange = true;
|
| 48 |
+
if(setConfig.totalSize != _totalSize) {
|
| 49 |
+
setConfig.totalSize = _totalSize;
|
| 50 |
+
}
|
| 51 |
+
if(setConfig.pumpRate != _pumpRate){
|
| 52 |
+
setConfig.pumpRate = _pumpRate;
|
| 53 |
+
}
|
| 54 |
+
if(setConfig.singlePrice != _singlePrice * 1 finney){
|
| 55 |
+
setConfig.singlePrice = _singlePrice * 1 finney;
|
| 56 |
+
}
|
| 57 |
+
}
|
| 58 |
+
|
| 59 |
+
function startNewGame() private {
|
| 60 |
+
|
| 61 |
+
gameIndex++;
|
| 62 |
+
if(curConfig.hasChange) {
|
| 63 |
+
if(curConfig.totalSize != setConfig.totalSize) {
|
| 64 |
+
curConfig.totalSize = setConfig.totalSize;
|
| 65 |
+
}
|
| 66 |
+
if(curConfig.singlePrice != setConfig.singlePrice){
|
| 67 |
+
curConfig.singlePrice = setConfig.singlePrice;
|
| 68 |
+
}
|
| 69 |
+
if( curConfig.pumpRate != setConfig.pumpRate) {
|
| 70 |
+
curConfig.pumpRate = setConfig.pumpRate;
|
| 71 |
+
}
|
| 72 |
+
curConfig.hasChange = false;
|
| 73 |
+
}
|
| 74 |
+
addressArray.length=0;
|
| 75 |
+
}
|
| 76 |
+
|
| 77 |
+
|
| 78 |
+
function addPlayer() public payable {
|
| 79 |
+
|
| 80 |
+
require(msg.value == curConfig.singlePrice);
|
| 81 |
+
totalPrice = totalPrice + msg.value;
|
| 82 |
+
addressArray.push(msg.sender);
|
| 83 |
+
|
| 84 |
+
emit addPlayerEvent(gameIndex,msg.sender);
|
| 85 |
+
if(addressArray.length >= curConfig.totalSize) {
|
| 86 |
+
gameResult();
|
| 87 |
+
startNewGame();
|
| 88 |
+
}
|
| 89 |
+
}
|
| 90 |
+
|
| 91 |
+
function getGameInfo() public view returns (uint256,uint32,uint256,uint8,address[],uint256) {
|
| 92 |
+
return (gameIndex,
|
| 93 |
+
curConfig.totalSize,
|
| 94 |
+
curConfig.singlePrice,
|
| 95 |
+
curConfig.pumpRate,
|
| 96 |
+
addressArray,
|
| 97 |
+
totalPrice);
|
| 98 |
+
}
|
| 99 |
+
|
| 100 |
+
function getSelfCount() private view returns (uint32) {
|
| 101 |
+
uint32 count = 0;
|
| 102 |
+
for(uint i = 0; i < addressArray.length; i++) {
|
| 103 |
+
if(msg.sender == addressArray[i]) {
|
| 104 |
+
count++;
|
| 105 |
+
}
|
| 106 |
+
}
|
| 107 |
+
return count;
|
| 108 |
+
}
|
| 109 |
+
|
| 110 |
+
function gameResult() private {
|
| 111 |
+
|
| 112 |
+
uint index = getRamdon();
|
| 113 |
+
address lastAddress = addressArray[index];
|
| 114 |
+
uint totalBalace = address(this).balance;
|
| 115 |
+
uint giveToOwn = totalBalace * curConfig.pumpRate / 100;
|
| 116 |
+
uint giveToActor = totalBalace - giveToOwn;
|
| 117 |
+
owner.transfer(giveToOwn);
|
| 118 |
+
lastAddress.transfer(giveToActor);
|
| 119 |
+
emit GameOverEvent(
|
| 120 |
+
gameIndex,
|
| 121 |
+
curConfig.totalSize,
|
| 122 |
+
curConfig.singlePrice,
|
| 123 |
+
curConfig.pumpRate,
|
| 124 |
+
lastAddress,
|
| 125 |
+
now);
|
| 126 |
+
}
|
| 127 |
+
|
| 128 |
+
function getRamdon() private view returns (uint) {
|
| 129 |
+
bytes32 ramdon = keccak256(abi.encodePacked(ramdon,now,blockhash(block.number-1)));
|
| 130 |
+
for(uint i = 0; i < addressArray.length; i++) {
|
| 131 |
+
ramdon = keccak256(abi.encodePacked(ramdon,now, addressArray[i]));
|
| 132 |
+
}
|
| 133 |
+
uint index = uint(ramdon) % addressArray.length;
|
| 134 |
+
return index;
|
| 135 |
+
}
|
| 136 |
+
}
|
smart_contract_dataset/block number dependency/1345.sol
ADDED
|
@@ -0,0 +1,458 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
pragma solidity ^0.4.24;
|
| 2 |
+
|
| 3 |
+
|
| 4 |
+
contract ZethrTokenBankroll{
|
| 5 |
+
|
| 6 |
+
function gameRequestTokens(address target, uint tokens) public;
|
| 7 |
+
}
|
| 8 |
+
|
| 9 |
+
|
| 10 |
+
contract ZethrMainBankroll{
|
| 11 |
+
function gameGetTokenBankrollList() public view returns (address[7]);
|
| 12 |
+
}
|
| 13 |
+
|
| 14 |
+
|
| 15 |
+
contract ZethrInterface{
|
| 16 |
+
function withdraw() public;
|
| 17 |
+
}
|
| 18 |
+
|
| 19 |
+
|
| 20 |
+
library ZethrTierLibrary{
|
| 21 |
+
uint constant internal magnitude = 2**64;
|
| 22 |
+
function getTier(uint divRate) internal pure returns (uint){
|
| 23 |
+
|
| 24 |
+
|
| 25 |
+
|
| 26 |
+
|
| 27 |
+
|
| 28 |
+
uint actualDiv = divRate;
|
| 29 |
+
if (actualDiv >= 30){
|
| 30 |
+
return 6;
|
| 31 |
+
} else if (actualDiv >= 25){
|
| 32 |
+
return 5;
|
| 33 |
+
} else if (actualDiv >= 20){
|
| 34 |
+
return 4;
|
| 35 |
+
} else if (actualDiv >= 15){
|
| 36 |
+
return 3;
|
| 37 |
+
} else if (actualDiv >= 10){
|
| 38 |
+
return 2;
|
| 39 |
+
} else if (actualDiv >= 5){
|
| 40 |
+
return 1;
|
| 41 |
+
} else if (actualDiv >= 2){
|
| 42 |
+
return 0;
|
| 43 |
+
} else{
|
| 44 |
+
|
| 45 |
+
revert();
|
| 46 |
+
}
|
| 47 |
+
}
|
| 48 |
+
}
|
| 49 |
+
|
| 50 |
+
|
| 51 |
+
contract ZethrBankrollBridge{
|
| 52 |
+
|
| 53 |
+
ZethrInterface Zethr;
|
| 54 |
+
|
| 55 |
+
|
| 56 |
+
|
| 57 |
+
|
| 58 |
+
|
| 59 |
+
address[7] UsedBankrollAddresses;
|
| 60 |
+
|
| 61 |
+
|
| 62 |
+
mapping(address => bool) ValidBankrollAddress;
|
| 63 |
+
|
| 64 |
+
|
| 65 |
+
function setupBankrollInterface(address ZethrMainBankrollAddress) internal {
|
| 66 |
+
|
| 67 |
+
UsedBankrollAddresses = ZethrMainBankroll(ZethrMainBankrollAddress).gameGetTokenBankrollList();
|
| 68 |
+
for(uint i=0; i<7; i++){
|
| 69 |
+
ValidBankrollAddress[UsedBankrollAddresses[i]] = true;
|
| 70 |
+
}
|
| 71 |
+
}
|
| 72 |
+
|
| 73 |
+
|
| 74 |
+
modifier fromBankroll(){
|
| 75 |
+
require(ValidBankrollAddress[msg.sender], "msg.sender should be a valid bankroll");
|
| 76 |
+
_;
|
| 77 |
+
}
|
| 78 |
+
|
| 79 |
+
|
| 80 |
+
|
| 81 |
+
function RequestBankrollPayment(address to, uint tokens, uint userDivRate) internal {
|
| 82 |
+
uint tier = ZethrTierLibrary.getTier(userDivRate);
|
| 83 |
+
address tokenBankrollAddress = UsedBankrollAddresses[tier];
|
| 84 |
+
ZethrTokenBankroll(tokenBankrollAddress).gameRequestTokens(to, tokens);
|
| 85 |
+
}
|
| 86 |
+
}
|
| 87 |
+
|
| 88 |
+
|
| 89 |
+
contract ZethrShell is ZethrBankrollBridge{
|
| 90 |
+
|
| 91 |
+
|
| 92 |
+
function WithdrawToBankroll() public {
|
| 93 |
+
address(UsedBankrollAddresses[0]).transfer(address(this).balance);
|
| 94 |
+
}
|
| 95 |
+
|
| 96 |
+
|
| 97 |
+
function WithdrawAndTransferToBankroll() public {
|
| 98 |
+
Zethr.withdraw();
|
| 99 |
+
WithdrawToBankroll();
|
| 100 |
+
}
|
| 101 |
+
}
|
| 102 |
+
|
| 103 |
+
|
| 104 |
+
|
| 105 |
+
contract Zethroll is ZethrShell {
|
| 106 |
+
using SafeMath for uint;
|
| 107 |
+
|
| 108 |
+
|
| 109 |
+
|
| 110 |
+
modifier betIsValid(uint _betSize, uint _playerNumber, uint divRate) {
|
| 111 |
+
require( calculateProfit(_betSize, _playerNumber) < getMaxProfit(divRate)
|
| 112 |
+
&& _betSize >= minBet
|
| 113 |
+
&& _playerNumber >= minNumber
|
| 114 |
+
&& _playerNumber <= maxNumber);
|
| 115 |
+
_;
|
| 116 |
+
}
|
| 117 |
+
|
| 118 |
+
|
| 119 |
+
modifier gameIsActive {
|
| 120 |
+
require(gamePaused == false);
|
| 121 |
+
_;
|
| 122 |
+
}
|
| 123 |
+
|
| 124 |
+
|
| 125 |
+
modifier onlyOwner {
|
| 126 |
+
require(msg.sender == owner);
|
| 127 |
+
_;
|
| 128 |
+
}
|
| 129 |
+
|
| 130 |
+
|
| 131 |
+
uint constant private MAX_INT = 2 ** 256 - 1;
|
| 132 |
+
uint constant public maxProfitDivisor = 1000000;
|
| 133 |
+
uint constant public maxNumber = 100;
|
| 134 |
+
uint constant public minNumber = 2;
|
| 135 |
+
uint constant public houseEdgeDivisor = 1000;
|
| 136 |
+
|
| 137 |
+
|
| 138 |
+
bool public gamePaused;
|
| 139 |
+
|
| 140 |
+
address public owner;
|
| 141 |
+
|
| 142 |
+
mapping (uint => uint) public contractBalance;
|
| 143 |
+
mapping (uint => uint) public maxProfit;
|
| 144 |
+
uint public houseEdge;
|
| 145 |
+
uint public maxProfitAsPercentOfHouse;
|
| 146 |
+
uint public minBet = 0;
|
| 147 |
+
|
| 148 |
+
|
| 149 |
+
uint public totalBets;
|
| 150 |
+
uint public totalZTHWagered;
|
| 151 |
+
|
| 152 |
+
|
| 153 |
+
|
| 154 |
+
|
| 155 |
+
event LogBet(address sender, uint value, uint rollUnder);
|
| 156 |
+
|
| 157 |
+
|
| 158 |
+
|
| 159 |
+
event LogResult(address player, uint result, uint rollUnder, uint profit, uint tokensBetted, bool won);
|
| 160 |
+
|
| 161 |
+
|
| 162 |
+
event LogOwnerTransfer(address indexed SentToAddress, uint indexed AmountTransferred);
|
| 163 |
+
|
| 164 |
+
|
| 165 |
+
event MaxProfitChanged(uint _oldMaxProfit, uint _newMaxProfit);
|
| 166 |
+
|
| 167 |
+
|
| 168 |
+
event CurrentContractBalance(uint _tokens);
|
| 169 |
+
|
| 170 |
+
constructor (address ZethrMainBankrollAddress) public {
|
| 171 |
+
setupBankrollInterface(ZethrMainBankrollAddress);
|
| 172 |
+
|
| 173 |
+
|
| 174 |
+
owner = msg.sender;
|
| 175 |
+
|
| 176 |
+
|
| 177 |
+
houseEdge = 990;
|
| 178 |
+
|
| 179 |
+
|
| 180 |
+
ownerSetMaxProfitAsPercentOfHouse(10000);
|
| 181 |
+
|
| 182 |
+
|
| 183 |
+
ownerSetMinBet(1e18);
|
| 184 |
+
}
|
| 185 |
+
|
| 186 |
+
|
| 187 |
+
|
| 188 |
+
function maxRandom(uint blockn, address entropy) public view returns (uint256 randomNumber) {
|
| 189 |
+
return uint256(keccak256(
|
| 190 |
+
abi.encodePacked(
|
| 191 |
+
blockhash(blockn),
|
| 192 |
+
entropy)
|
| 193 |
+
));
|
| 194 |
+
}
|
| 195 |
+
|
| 196 |
+
|
| 197 |
+
function random(uint256 upper, uint256 blockn, address entropy) public view returns (uint256 randomNumber) {
|
| 198 |
+
return maxRandom(blockn, entropy) % upper;
|
| 199 |
+
}
|
| 200 |
+
|
| 201 |
+
|
| 202 |
+
function calculateProfit(uint _initBet, uint _roll)
|
| 203 |
+
private
|
| 204 |
+
view
|
| 205 |
+
returns (uint)
|
| 206 |
+
{
|
| 207 |
+
return ((((_initBet * (100 - (_roll.sub(1)))) / (_roll.sub(1)) + _initBet)) * houseEdge / houseEdgeDivisor) - _initBet;
|
| 208 |
+
}
|
| 209 |
+
|
| 210 |
+
|
| 211 |
+
struct playerRoll{
|
| 212 |
+
uint192 tokenValue;
|
| 213 |
+
uint48 blockn;
|
| 214 |
+
uint8 rollUnder;
|
| 215 |
+
uint8 divRate;
|
| 216 |
+
}
|
| 217 |
+
|
| 218 |
+
|
| 219 |
+
mapping(address => playerRoll) public playerRolls;
|
| 220 |
+
|
| 221 |
+
|
| 222 |
+
function _playerRollDice(uint _rollUnder, TKN _tkn, uint userDivRate) private
|
| 223 |
+
gameIsActive
|
| 224 |
+
betIsValid(_tkn.value, _rollUnder, userDivRate)
|
| 225 |
+
{
|
| 226 |
+
require(_tkn.value < ((2 ** 192) - 1));
|
| 227 |
+
require(block.number < ((2 ** 48) - 1));
|
| 228 |
+
require(userDivRate < (2 ** 8 - 1));
|
| 229 |
+
|
| 230 |
+
|
| 231 |
+
|
| 232 |
+
playerRoll memory roll = playerRolls[_tkn.sender];
|
| 233 |
+
|
| 234 |
+
|
| 235 |
+
require(block.number != roll.blockn);
|
| 236 |
+
|
| 237 |
+
|
| 238 |
+
if (roll.blockn != 0) {
|
| 239 |
+
_finishBet(_tkn.sender);
|
| 240 |
+
}
|
| 241 |
+
|
| 242 |
+
|
| 243 |
+
roll.blockn = uint48(block.number);
|
| 244 |
+
roll.tokenValue = uint192(_tkn.value);
|
| 245 |
+
roll.rollUnder = uint8(_rollUnder);
|
| 246 |
+
roll.divRate = uint8(userDivRate);
|
| 247 |
+
|
| 248 |
+
|
| 249 |
+
playerRolls[_tkn.sender] = roll;
|
| 250 |
+
|
| 251 |
+
|
| 252 |
+
emit LogBet(_tkn.sender, _tkn.value, _rollUnder);
|
| 253 |
+
|
| 254 |
+
|
| 255 |
+
totalBets += 1;
|
| 256 |
+
|
| 257 |
+
|
| 258 |
+
totalZTHWagered += _tkn.value;
|
| 259 |
+
}
|
| 260 |
+
|
| 261 |
+
|
| 262 |
+
function finishBet() public
|
| 263 |
+
gameIsActive
|
| 264 |
+
returns (uint)
|
| 265 |
+
{
|
| 266 |
+
return _finishBet(msg.sender);
|
| 267 |
+
}
|
| 268 |
+
|
| 269 |
+
|
| 270 |
+
function _finishBet(address target) private returns (uint){
|
| 271 |
+
playerRoll memory roll = playerRolls[target];
|
| 272 |
+
require(roll.tokenValue > 0);
|
| 273 |
+
require(roll.blockn != block.number);
|
| 274 |
+
|
| 275 |
+
|
| 276 |
+
uint result;
|
| 277 |
+
if (block.number - roll.blockn > 255) {
|
| 278 |
+
result = 1000;
|
| 279 |
+
} else {
|
| 280 |
+
|
| 281 |
+
result = random(100, roll.blockn, target) + 1;
|
| 282 |
+
}
|
| 283 |
+
|
| 284 |
+
uint rollUnder = roll.rollUnder;
|
| 285 |
+
|
| 286 |
+
if (result < rollUnder) {
|
| 287 |
+
|
| 288 |
+
|
| 289 |
+
|
| 290 |
+
uint profit = calculateProfit(roll.tokenValue, rollUnder);
|
| 291 |
+
uint mProfit = getMaxProfit(roll.divRate);
|
| 292 |
+
if (profit > mProfit){
|
| 293 |
+
profit = mProfit;
|
| 294 |
+
}
|
| 295 |
+
|
| 296 |
+
|
| 297 |
+
subContractBalance(roll.divRate, profit);
|
| 298 |
+
|
| 299 |
+
emit LogResult(target, result, rollUnder, profit, roll.tokenValue, true);
|
| 300 |
+
|
| 301 |
+
|
| 302 |
+
setMaxProfit(roll.divRate);
|
| 303 |
+
|
| 304 |
+
|
| 305 |
+
playerRolls[target] = playerRoll(uint192(0), uint48(0), uint8(0), uint8(0));
|
| 306 |
+
|
| 307 |
+
|
| 308 |
+
RequestBankrollPayment(target, profit + roll.tokenValue, roll.divRate);
|
| 309 |
+
return result;
|
| 310 |
+
|
| 311 |
+
} else {
|
| 312 |
+
|
| 313 |
+
emit LogResult(target, result, rollUnder, profit, roll.tokenValue, false);
|
| 314 |
+
|
| 315 |
+
|
| 316 |
+
addContractBalance(roll.divRate, roll.tokenValue);
|
| 317 |
+
|
| 318 |
+
playerRolls[target] = playerRoll(uint192(0), uint48(0), uint8(0), uint8(0));
|
| 319 |
+
|
| 320 |
+
|
| 321 |
+
|
| 322 |
+
|
| 323 |
+
setMaxProfit(roll.divRate);
|
| 324 |
+
|
| 325 |
+
return result;
|
| 326 |
+
}
|
| 327 |
+
}
|
| 328 |
+
|
| 329 |
+
|
| 330 |
+
struct TKN {address sender; uint value;}
|
| 331 |
+
|
| 332 |
+
|
| 333 |
+
function execute(address _from, uint _value, uint userDivRate, bytes _data) public fromBankroll gameIsActive returns (bool) {
|
| 334 |
+
TKN memory _tkn;
|
| 335 |
+
_tkn.sender = _from;
|
| 336 |
+
_tkn.value = _value;
|
| 337 |
+
uint8 chosenNumber = uint8(_data[0]);
|
| 338 |
+
_playerRollDice(chosenNumber, _tkn, userDivRate);
|
| 339 |
+
|
| 340 |
+
return true;
|
| 341 |
+
}
|
| 342 |
+
|
| 343 |
+
|
| 344 |
+
function setMaxProfit(uint divRate) internal {
|
| 345 |
+
|
| 346 |
+
maxProfit[divRate] = (contractBalance[divRate] * maxProfitAsPercentOfHouse) / maxProfitDivisor;
|
| 347 |
+
}
|
| 348 |
+
|
| 349 |
+
|
| 350 |
+
function getMaxProfit(uint divRate) public view returns (uint){
|
| 351 |
+
return (contractBalance[divRate] * maxProfitAsPercentOfHouse) / maxProfitDivisor;
|
| 352 |
+
}
|
| 353 |
+
|
| 354 |
+
|
| 355 |
+
function subContractBalance(uint divRate, uint sub) internal {
|
| 356 |
+
contractBalance[divRate] = contractBalance[divRate].sub(sub);
|
| 357 |
+
}
|
| 358 |
+
|
| 359 |
+
|
| 360 |
+
function addContractBalance(uint divRate, uint add) internal {
|
| 361 |
+
contractBalance[divRate] = contractBalance[divRate].add(add);
|
| 362 |
+
}
|
| 363 |
+
|
| 364 |
+
|
| 365 |
+
function ownerUpdateContractBalance(uint newContractBalance, uint divRate) public
|
| 366 |
+
onlyOwner
|
| 367 |
+
{
|
| 368 |
+
contractBalance[divRate] = newContractBalance;
|
| 369 |
+
}
|
| 370 |
+
|
| 371 |
+
|
| 372 |
+
|
| 373 |
+
|
| 374 |
+
function bankrollExternalUpdateTokens(uint divRate, uint newBalance) public fromBankroll {
|
| 375 |
+
contractBalance[divRate] = newBalance;
|
| 376 |
+
setMaxProfit(divRate);
|
| 377 |
+
}
|
| 378 |
+
|
| 379 |
+
|
| 380 |
+
function ownerSetMaxProfitAsPercentOfHouse(uint newMaxProfitAsPercent) public
|
| 381 |
+
onlyOwner
|
| 382 |
+
{
|
| 383 |
+
|
| 384 |
+
require(newMaxProfitAsPercent <= 200000);
|
| 385 |
+
maxProfitAsPercentOfHouse = newMaxProfitAsPercent;
|
| 386 |
+
setMaxProfit(2);
|
| 387 |
+
setMaxProfit(5);
|
| 388 |
+
setMaxProfit(10);
|
| 389 |
+
setMaxProfit(15);
|
| 390 |
+
setMaxProfit(20);
|
| 391 |
+
setMaxProfit(25);
|
| 392 |
+
setMaxProfit(33);
|
| 393 |
+
}
|
| 394 |
+
|
| 395 |
+
|
| 396 |
+
function ownerSetMinBet(uint newMinimumBet) public
|
| 397 |
+
onlyOwner
|
| 398 |
+
{
|
| 399 |
+
minBet = newMinimumBet;
|
| 400 |
+
}
|
| 401 |
+
|
| 402 |
+
|
| 403 |
+
function ownerPauseGame(bool newStatus) public
|
| 404 |
+
onlyOwner
|
| 405 |
+
{
|
| 406 |
+
gamePaused = newStatus;
|
| 407 |
+
}
|
| 408 |
+
|
| 409 |
+
|
| 410 |
+
function ownerChangeOwner(address newOwner) public
|
| 411 |
+
onlyOwner
|
| 412 |
+
{
|
| 413 |
+
owner = newOwner;
|
| 414 |
+
}
|
| 415 |
+
|
| 416 |
+
|
| 417 |
+
function ownerkill() public
|
| 418 |
+
onlyOwner
|
| 419 |
+
{
|
| 420 |
+
|
| 421 |
+
selfdestruct(owner);
|
| 422 |
+
}
|
| 423 |
+
}
|
| 424 |
+
|
| 425 |
+
|
| 426 |
+
library SafeMath {
|
| 427 |
+
|
| 428 |
+
|
| 429 |
+
function mul(uint a, uint b) internal pure returns (uint) {
|
| 430 |
+
if (a == 0) {
|
| 431 |
+
return 0;
|
| 432 |
+
}
|
| 433 |
+
uint c = a * b;
|
| 434 |
+
assert(c / a == b);
|
| 435 |
+
return c;
|
| 436 |
+
}
|
| 437 |
+
|
| 438 |
+
|
| 439 |
+
function div(uint a, uint b) internal pure returns (uint) {
|
| 440 |
+
|
| 441 |
+
uint c = a / b;
|
| 442 |
+
|
| 443 |
+
return c;
|
| 444 |
+
}
|
| 445 |
+
|
| 446 |
+
|
| 447 |
+
function sub(uint a, uint b) internal pure returns (uint) {
|
| 448 |
+
assert(b <= a);
|
| 449 |
+
return a - b;
|
| 450 |
+
}
|
| 451 |
+
|
| 452 |
+
|
| 453 |
+
function add(uint a, uint b) internal pure returns (uint) {
|
| 454 |
+
uint c = a + b;
|
| 455 |
+
assert(c >= a);
|
| 456 |
+
return c;
|
| 457 |
+
}
|
| 458 |
+
}
|
smart_contract_dataset/block number dependency/135.sol
ADDED
|
@@ -0,0 +1,1130 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
pragma solidity ^0.4.24;
|
| 2 |
+
|
| 3 |
+
|
| 4 |
+
|
| 5 |
+
|
| 6 |
+
contract Ownable {
|
| 7 |
+
address public owner;
|
| 8 |
+
|
| 9 |
+
|
| 10 |
+
event OwnershipRenounced(address indexed previousOwner);
|
| 11 |
+
event OwnershipTransferred(
|
| 12 |
+
address indexed previousOwner,
|
| 13 |
+
address indexed newOwner
|
| 14 |
+
);
|
| 15 |
+
|
| 16 |
+
|
| 17 |
+
|
| 18 |
+
constructor() public {
|
| 19 |
+
owner = msg.sender;
|
| 20 |
+
}
|
| 21 |
+
|
| 22 |
+
|
| 23 |
+
modifier onlyOwner() {
|
| 24 |
+
require(msg.sender == owner);
|
| 25 |
+
_;
|
| 26 |
+
}
|
| 27 |
+
|
| 28 |
+
|
| 29 |
+
function renounceOwnership() public onlyOwner {
|
| 30 |
+
emit OwnershipRenounced(owner);
|
| 31 |
+
owner = address(0);
|
| 32 |
+
}
|
| 33 |
+
|
| 34 |
+
|
| 35 |
+
function transferOwnership(address _newOwner) public onlyOwner {
|
| 36 |
+
_transferOwnership(_newOwner);
|
| 37 |
+
}
|
| 38 |
+
|
| 39 |
+
|
| 40 |
+
function _transferOwnership(address _newOwner) internal {
|
| 41 |
+
require(_newOwner != address(0));
|
| 42 |
+
emit OwnershipTransferred(owner, _newOwner);
|
| 43 |
+
owner = _newOwner;
|
| 44 |
+
}
|
| 45 |
+
}
|
| 46 |
+
|
| 47 |
+
|
| 48 |
+
|
| 49 |
+
|
| 50 |
+
contract Pausable is Ownable {
|
| 51 |
+
event Pause();
|
| 52 |
+
event Unpause();
|
| 53 |
+
|
| 54 |
+
bool public paused = false;
|
| 55 |
+
|
| 56 |
+
|
| 57 |
+
|
| 58 |
+
modifier whenNotPaused() {
|
| 59 |
+
require(!paused);
|
| 60 |
+
_;
|
| 61 |
+
}
|
| 62 |
+
|
| 63 |
+
|
| 64 |
+
modifier whenPaused() {
|
| 65 |
+
require(paused);
|
| 66 |
+
_;
|
| 67 |
+
}
|
| 68 |
+
|
| 69 |
+
|
| 70 |
+
function pause() public onlyOwner whenNotPaused {
|
| 71 |
+
paused = true;
|
| 72 |
+
emit Pause();
|
| 73 |
+
}
|
| 74 |
+
|
| 75 |
+
|
| 76 |
+
function unpause() public onlyOwner whenPaused {
|
| 77 |
+
paused = false;
|
| 78 |
+
emit Unpause();
|
| 79 |
+
}
|
| 80 |
+
}
|
| 81 |
+
|
| 82 |
+
|
| 83 |
+
|
| 84 |
+
|
| 85 |
+
contract ERC721Receiver {
|
| 86 |
+
|
| 87 |
+
bytes4 internal constant ERC721_RECEIVED = 0x150b7a02;
|
| 88 |
+
|
| 89 |
+
|
| 90 |
+
function onERC721Received(
|
| 91 |
+
address _operator,
|
| 92 |
+
address _from,
|
| 93 |
+
uint256 _tokenId,
|
| 94 |
+
bytes _data
|
| 95 |
+
)
|
| 96 |
+
public
|
| 97 |
+
returns(bytes4);
|
| 98 |
+
}
|
| 99 |
+
|
| 100 |
+
|
| 101 |
+
|
| 102 |
+
contract ERC721Holder is ERC721Receiver {
|
| 103 |
+
function onERC721Received(
|
| 104 |
+
address,
|
| 105 |
+
address,
|
| 106 |
+
uint256,
|
| 107 |
+
bytes
|
| 108 |
+
)
|
| 109 |
+
public
|
| 110 |
+
returns(bytes4)
|
| 111 |
+
{
|
| 112 |
+
return ERC721_RECEIVED;
|
| 113 |
+
}
|
| 114 |
+
}
|
| 115 |
+
|
| 116 |
+
|
| 117 |
+
|
| 118 |
+
|
| 119 |
+
contract ERC721Basic {
|
| 120 |
+
function balanceOf(address _owner) public view returns (uint256 _balance);
|
| 121 |
+
function ownerOf(uint256 _tokenId) public view returns (address _owner);
|
| 122 |
+
function exists(uint256 _tokenId) public view returns (bool _exists);
|
| 123 |
+
|
| 124 |
+
function approve(address _to, uint256 _tokenId) public;
|
| 125 |
+
function getApproved(uint256 _tokenId) public view returns (address _operator);
|
| 126 |
+
|
| 127 |
+
function transferFrom(address _from, address _to, uint256 _tokenId) public;
|
| 128 |
+
}
|
| 129 |
+
|
| 130 |
+
|
| 131 |
+
contract HorseyExchange is Pausable, ERC721Holder {
|
| 132 |
+
|
| 133 |
+
event HorseyDeposit(uint256 tokenId, uint256 price);
|
| 134 |
+
event SaleCanceled(uint256 tokenId);
|
| 135 |
+
event HorseyPurchased(uint256 tokenId, address newOwner, uint256 totalToPay);
|
| 136 |
+
|
| 137 |
+
|
| 138 |
+
uint256 public marketMakerFee = 3;
|
| 139 |
+
|
| 140 |
+
|
| 141 |
+
uint256 collectedFees = 0;
|
| 142 |
+
|
| 143 |
+
|
| 144 |
+
ERC721Basic public token;
|
| 145 |
+
|
| 146 |
+
|
| 147 |
+
struct SaleData {
|
| 148 |
+
uint256 price;
|
| 149 |
+
address owner;
|
| 150 |
+
}
|
| 151 |
+
|
| 152 |
+
|
| 153 |
+
mapping (uint256 => SaleData) market;
|
| 154 |
+
|
| 155 |
+
|
| 156 |
+
mapping (address => uint256[]) userBarn;
|
| 157 |
+
|
| 158 |
+
|
| 159 |
+
constructor() Pausable() ERC721Holder() public {
|
| 160 |
+
}
|
| 161 |
+
|
| 162 |
+
|
| 163 |
+
function setStables(address _token) external
|
| 164 |
+
onlyOwner()
|
| 165 |
+
{
|
| 166 |
+
require(address(_token) != 0,"Address of token is zero");
|
| 167 |
+
token = ERC721Basic(_token);
|
| 168 |
+
}
|
| 169 |
+
|
| 170 |
+
|
| 171 |
+
function setMarketFees(uint256 fees) external
|
| 172 |
+
onlyOwner()
|
| 173 |
+
{
|
| 174 |
+
marketMakerFee = fees;
|
| 175 |
+
}
|
| 176 |
+
|
| 177 |
+
|
| 178 |
+
function getTokensOnSale(address user) external view returns(uint256[]) {
|
| 179 |
+
return userBarn[user];
|
| 180 |
+
}
|
| 181 |
+
|
| 182 |
+
|
| 183 |
+
function getTokenPrice(uint256 tokenId) public view
|
| 184 |
+
isOnMarket(tokenId) returns (uint256) {
|
| 185 |
+
return market[tokenId].price + (market[tokenId].price / 100 * marketMakerFee);
|
| 186 |
+
}
|
| 187 |
+
|
| 188 |
+
|
| 189 |
+
function depositToExchange(uint256 tokenId, uint256 price) external
|
| 190 |
+
whenNotPaused()
|
| 191 |
+
isTokenOwner(tokenId)
|
| 192 |
+
nonZeroPrice(price)
|
| 193 |
+
tokenAvailable() {
|
| 194 |
+
require(token.getApproved(tokenId) == address(this),"Exchange is not allowed to transfer");
|
| 195 |
+
|
| 196 |
+
token.transferFrom(msg.sender, address(this), tokenId);
|
| 197 |
+
|
| 198 |
+
|
| 199 |
+
market[tokenId] = SaleData(price,msg.sender);
|
| 200 |
+
|
| 201 |
+
|
| 202 |
+
userBarn[msg.sender].push(tokenId);
|
| 203 |
+
|
| 204 |
+
emit HorseyDeposit(tokenId, price);
|
| 205 |
+
}
|
| 206 |
+
|
| 207 |
+
|
| 208 |
+
function cancelSale(uint256 tokenId) external
|
| 209 |
+
whenNotPaused()
|
| 210 |
+
originalOwnerOf(tokenId)
|
| 211 |
+
tokenAvailable() returns (bool) {
|
| 212 |
+
|
| 213 |
+
token.transferFrom(address(this),msg.sender,tokenId);
|
| 214 |
+
|
| 215 |
+
|
| 216 |
+
delete market[tokenId];
|
| 217 |
+
|
| 218 |
+
|
| 219 |
+
_removeTokenFromBarn(tokenId, msg.sender);
|
| 220 |
+
|
| 221 |
+
emit SaleCanceled(tokenId);
|
| 222 |
+
|
| 223 |
+
|
| 224 |
+
|
| 225 |
+
return userBarn[msg.sender].length > 0;
|
| 226 |
+
}
|
| 227 |
+
|
| 228 |
+
|
| 229 |
+
function purchaseToken(uint256 tokenId) external payable
|
| 230 |
+
whenNotPaused()
|
| 231 |
+
isOnMarket(tokenId)
|
| 232 |
+
tokenAvailable()
|
| 233 |
+
notOriginalOwnerOf(tokenId)
|
| 234 |
+
{
|
| 235 |
+
|
| 236 |
+
uint256 totalToPay = getTokenPrice(tokenId);
|
| 237 |
+
require(msg.value >= totalToPay, "Not paying enough");
|
| 238 |
+
|
| 239 |
+
|
| 240 |
+
SaleData memory sale = market[tokenId];
|
| 241 |
+
|
| 242 |
+
|
| 243 |
+
collectedFees += totalToPay - sale.price;
|
| 244 |
+
|
| 245 |
+
|
| 246 |
+
sale.owner.transfer(sale.price);
|
| 247 |
+
|
| 248 |
+
|
| 249 |
+
_removeTokenFromBarn(tokenId, sale.owner);
|
| 250 |
+
|
| 251 |
+
|
| 252 |
+
delete market[tokenId];
|
| 253 |
+
|
| 254 |
+
|
| 255 |
+
|
| 256 |
+
token.transferFrom(address(this), msg.sender, tokenId);
|
| 257 |
+
|
| 258 |
+
|
| 259 |
+
if(msg.value > totalToPay)
|
| 260 |
+
{
|
| 261 |
+
msg.sender.transfer(msg.value - totalToPay);
|
| 262 |
+
}
|
| 263 |
+
|
| 264 |
+
emit HorseyPurchased(tokenId, msg.sender, totalToPay);
|
| 265 |
+
}
|
| 266 |
+
|
| 267 |
+
|
| 268 |
+
function withdraw() external
|
| 269 |
+
onlyOwner()
|
| 270 |
+
{
|
| 271 |
+
assert(collectedFees <= address(this).balance);
|
| 272 |
+
owner.transfer(collectedFees);
|
| 273 |
+
collectedFees = 0;
|
| 274 |
+
}
|
| 275 |
+
|
| 276 |
+
|
| 277 |
+
function _removeTokenFromBarn(uint tokenId, address barnAddress) internal {
|
| 278 |
+
uint256[] storage barnArray = userBarn[barnAddress];
|
| 279 |
+
require(barnArray.length > 0,"No tokens to remove");
|
| 280 |
+
int index = _indexOf(tokenId, barnArray);
|
| 281 |
+
require(index >= 0, "Token not found in barn");
|
| 282 |
+
|
| 283 |
+
|
| 284 |
+
for (uint256 i = uint256(index); i<barnArray.length-1; i++){
|
| 285 |
+
barnArray[i] = barnArray[i+1];
|
| 286 |
+
}
|
| 287 |
+
|
| 288 |
+
|
| 289 |
+
|
| 290 |
+
barnArray.length--;
|
| 291 |
+
}
|
| 292 |
+
|
| 293 |
+
|
| 294 |
+
function _indexOf(uint item, uint256[] memory array) internal pure returns (int256){
|
| 295 |
+
|
| 296 |
+
|
| 297 |
+
for(uint256 i = 0; i < array.length; i++){
|
| 298 |
+
if(array[i] == item){
|
| 299 |
+
return int256(i);
|
| 300 |
+
}
|
| 301 |
+
}
|
| 302 |
+
|
| 303 |
+
|
| 304 |
+
return -1;
|
| 305 |
+
}
|
| 306 |
+
|
| 307 |
+
|
| 308 |
+
modifier isOnMarket(uint256 tokenId) {
|
| 309 |
+
require(token.ownerOf(tokenId) == address(this),"Token not on market");
|
| 310 |
+
_;
|
| 311 |
+
}
|
| 312 |
+
|
| 313 |
+
|
| 314 |
+
modifier isTokenOwner(uint256 tokenId) {
|
| 315 |
+
require(token.ownerOf(tokenId) == msg.sender,"Not tokens owner");
|
| 316 |
+
_;
|
| 317 |
+
}
|
| 318 |
+
|
| 319 |
+
|
| 320 |
+
modifier originalOwnerOf(uint256 tokenId) {
|
| 321 |
+
require(market[tokenId].owner == msg.sender,"Not the original owner of");
|
| 322 |
+
_;
|
| 323 |
+
}
|
| 324 |
+
|
| 325 |
+
|
| 326 |
+
modifier notOriginalOwnerOf(uint256 tokenId) {
|
| 327 |
+
require(market[tokenId].owner != msg.sender,"Is the original owner");
|
| 328 |
+
_;
|
| 329 |
+
}
|
| 330 |
+
|
| 331 |
+
|
| 332 |
+
modifier nonZeroPrice(uint256 price){
|
| 333 |
+
require(price > 0,"Price is zero");
|
| 334 |
+
_;
|
| 335 |
+
}
|
| 336 |
+
|
| 337 |
+
|
| 338 |
+
modifier tokenAvailable(){
|
| 339 |
+
require(address(token) != 0,"Token address not set");
|
| 340 |
+
_;
|
| 341 |
+
}
|
| 342 |
+
}
|
| 343 |
+
|
| 344 |
+
|
| 345 |
+
|
| 346 |
+
|
| 347 |
+
contract EthorseRace {
|
| 348 |
+
|
| 349 |
+
|
| 350 |
+
struct chronus_info {
|
| 351 |
+
bool betting_open;
|
| 352 |
+
bool race_start;
|
| 353 |
+
bool race_end;
|
| 354 |
+
bool voided_bet;
|
| 355 |
+
uint32 starting_time;
|
| 356 |
+
uint32 betting_duration;
|
| 357 |
+
uint32 race_duration;
|
| 358 |
+
uint32 voided_timestamp;
|
| 359 |
+
}
|
| 360 |
+
|
| 361 |
+
address public owner;
|
| 362 |
+
|
| 363 |
+
|
| 364 |
+
chronus_info public chronus;
|
| 365 |
+
|
| 366 |
+
|
| 367 |
+
mapping (bytes32 => bool) public winner_horse;
|
| 368 |
+
|
| 369 |
+
|
| 370 |
+
function getCoinIndex(bytes32 index, address candidate) external constant returns (uint, uint, uint, bool, uint);
|
| 371 |
+
}
|
| 372 |
+
|
| 373 |
+
|
| 374 |
+
contract EthorseHelpers {
|
| 375 |
+
|
| 376 |
+
|
| 377 |
+
bytes32[] public all_horses = [bytes32("BTC"),bytes32("ETH"),bytes32("LTC")];
|
| 378 |
+
mapping(address => bool) public legitRaces;
|
| 379 |
+
bool onlyLegit = false;
|
| 380 |
+
|
| 381 |
+
|
| 382 |
+
function _addHorse(bytes32 newHorse) internal {
|
| 383 |
+
all_horses.push(newHorse);
|
| 384 |
+
}
|
| 385 |
+
|
| 386 |
+
function _addLegitRace(address newRace) internal
|
| 387 |
+
{
|
| 388 |
+
legitRaces[newRace] = true;
|
| 389 |
+
if(!onlyLegit)
|
| 390 |
+
onlyLegit = true;
|
| 391 |
+
}
|
| 392 |
+
|
| 393 |
+
function getall_horsesCount() public view returns(uint) {
|
| 394 |
+
return all_horses.length;
|
| 395 |
+
}
|
| 396 |
+
|
| 397 |
+
|
| 398 |
+
function _isWinnerOf(address raceAddress, address eth_address) internal view returns (bool,bytes32)
|
| 399 |
+
{
|
| 400 |
+
|
| 401 |
+
EthorseRace race = EthorseRace(raceAddress);
|
| 402 |
+
|
| 403 |
+
|
| 404 |
+
if(onlyLegit)
|
| 405 |
+
require(legitRaces[raceAddress],"not legit race");
|
| 406 |
+
|
| 407 |
+
bool voided_bet;
|
| 408 |
+
bool race_end;
|
| 409 |
+
(,,race_end,voided_bet,,,,) = race.chronus();
|
| 410 |
+
|
| 411 |
+
|
| 412 |
+
if(voided_bet || !race_end)
|
| 413 |
+
return (false,bytes32(0));
|
| 414 |
+
|
| 415 |
+
|
| 416 |
+
bytes32 horse;
|
| 417 |
+
bool found = false;
|
| 418 |
+
uint256 arrayLength = all_horses.length;
|
| 419 |
+
|
| 420 |
+
|
| 421 |
+
for(uint256 i = 0; i < arrayLength; i++)
|
| 422 |
+
{
|
| 423 |
+
if(race.winner_horse(all_horses[i])) {
|
| 424 |
+
horse = all_horses[i];
|
| 425 |
+
found = true;
|
| 426 |
+
break;
|
| 427 |
+
}
|
| 428 |
+
}
|
| 429 |
+
|
| 430 |
+
if(!found)
|
| 431 |
+
return (false,bytes32(0));
|
| 432 |
+
|
| 433 |
+
|
| 434 |
+
uint256 bet_amount = 0;
|
| 435 |
+
(,,,, bet_amount) = race.getCoinIndex(horse, eth_address);
|
| 436 |
+
|
| 437 |
+
|
| 438 |
+
return (bet_amount > 0, horse);
|
| 439 |
+
}
|
| 440 |
+
}
|
| 441 |
+
|
| 442 |
+
|
| 443 |
+
|
| 444 |
+
contract RoyalStablesInterface {
|
| 445 |
+
|
| 446 |
+
struct Horsey {
|
| 447 |
+
address race;
|
| 448 |
+
bytes32 dna;
|
| 449 |
+
uint8 feedingCounter;
|
| 450 |
+
uint8 tier;
|
| 451 |
+
}
|
| 452 |
+
|
| 453 |
+
mapping(uint256 => Horsey) public horseys;
|
| 454 |
+
mapping(address => uint32) public carrot_credits;
|
| 455 |
+
mapping(uint256 => string) public names;
|
| 456 |
+
address public master;
|
| 457 |
+
|
| 458 |
+
function getOwnedTokens(address eth_address) public view returns (uint256[]);
|
| 459 |
+
function storeName(uint256 tokenId, string newName) public;
|
| 460 |
+
function storeCarrotsCredit(address client, uint32 amount) public;
|
| 461 |
+
function storeHorsey(address client, uint256 tokenId, address race, bytes32 dna, uint8 feedingCounter, uint8 tier) public;
|
| 462 |
+
function modifyHorsey(uint256 tokenId, address race, bytes32 dna, uint8 feedingCounter, uint8 tier) public;
|
| 463 |
+
function modifyHorseyDna(uint256 tokenId, bytes32 dna) public;
|
| 464 |
+
function modifyHorseyFeedingCounter(uint256 tokenId, uint8 feedingCounter) public;
|
| 465 |
+
function modifyHorseyTier(uint256 tokenId, uint8 tier) public;
|
| 466 |
+
function unstoreHorsey(uint256 tokenId) public;
|
| 467 |
+
function ownerOf(uint256 tokenId) public returns (address);
|
| 468 |
+
}
|
| 469 |
+
|
| 470 |
+
|
| 471 |
+
contract HorseyToken is EthorseHelpers,Pausable {
|
| 472 |
+
|
| 473 |
+
|
| 474 |
+
event Claimed(address raceAddress, address eth_address, uint256 tokenId);
|
| 475 |
+
|
| 476 |
+
|
| 477 |
+
event Feeding(uint256 tokenId);
|
| 478 |
+
|
| 479 |
+
|
| 480 |
+
event ReceivedCarrot(uint256 tokenId, bytes32 newDna);
|
| 481 |
+
|
| 482 |
+
|
| 483 |
+
event FeedingFailed(uint256 tokenId);
|
| 484 |
+
|
| 485 |
+
|
| 486 |
+
event HorseyRenamed(uint256 tokenId, string newName);
|
| 487 |
+
|
| 488 |
+
|
| 489 |
+
event HorseyFreed(uint256 tokenId);
|
| 490 |
+
|
| 491 |
+
|
| 492 |
+
RoyalStablesInterface public stables;
|
| 493 |
+
|
| 494 |
+
|
| 495 |
+
uint8 public carrotsMultiplier = 1;
|
| 496 |
+
|
| 497 |
+
|
| 498 |
+
uint8 public rarityMultiplier = 1;
|
| 499 |
+
|
| 500 |
+
|
| 501 |
+
uint256 public claimingFee = 0.000 ether;
|
| 502 |
+
|
| 503 |
+
|
| 504 |
+
struct FeedingData {
|
| 505 |
+
uint256 blockNumber;
|
| 506 |
+
uint256 horsey;
|
| 507 |
+
}
|
| 508 |
+
|
| 509 |
+
|
| 510 |
+
mapping(address => FeedingData) public pendingFeedings;
|
| 511 |
+
|
| 512 |
+
|
| 513 |
+
uint256 public renamingCostsPerChar = 0.001 ether;
|
| 514 |
+
|
| 515 |
+
|
| 516 |
+
constructor(address stablesAddress)
|
| 517 |
+
EthorseHelpers()
|
| 518 |
+
Pausable() public {
|
| 519 |
+
stables = RoyalStablesInterface(stablesAddress);
|
| 520 |
+
}
|
| 521 |
+
|
| 522 |
+
|
| 523 |
+
function setRarityMultiplier(uint8 newRarityMultiplier) external
|
| 524 |
+
onlyOwner() {
|
| 525 |
+
rarityMultiplier = newRarityMultiplier;
|
| 526 |
+
}
|
| 527 |
+
|
| 528 |
+
|
| 529 |
+
function setCarrotsMultiplier(uint8 newCarrotsMultiplier) external
|
| 530 |
+
onlyOwner() {
|
| 531 |
+
carrotsMultiplier = newCarrotsMultiplier;
|
| 532 |
+
}
|
| 533 |
+
|
| 534 |
+
|
| 535 |
+
function setRenamingCosts(uint256 newRenamingCost) external
|
| 536 |
+
onlyOwner() {
|
| 537 |
+
renamingCostsPerChar = newRenamingCost;
|
| 538 |
+
}
|
| 539 |
+
|
| 540 |
+
|
| 541 |
+
function setClaimingCosts(uint256 newClaimingFee) external
|
| 542 |
+
onlyOwner() {
|
| 543 |
+
claimingFee = newClaimingFee;
|
| 544 |
+
}
|
| 545 |
+
|
| 546 |
+
|
| 547 |
+
function addLegitRaceAddress(address newAddress) external
|
| 548 |
+
onlyOwner() {
|
| 549 |
+
_addLegitRace(newAddress);
|
| 550 |
+
}
|
| 551 |
+
|
| 552 |
+
|
| 553 |
+
function withdraw() external
|
| 554 |
+
onlyOwner() {
|
| 555 |
+
owner.transfer(address(this).balance);
|
| 556 |
+
}
|
| 557 |
+
|
| 558 |
+
|
| 559 |
+
|
| 560 |
+
function addHorseIndex(bytes32 newHorse) external
|
| 561 |
+
onlyOwner() {
|
| 562 |
+
_addHorse(newHorse);
|
| 563 |
+
}
|
| 564 |
+
|
| 565 |
+
|
| 566 |
+
function getOwnedTokens(address eth_address) public view returns (uint256[]) {
|
| 567 |
+
return stables.getOwnedTokens(eth_address);
|
| 568 |
+
}
|
| 569 |
+
|
| 570 |
+
|
| 571 |
+
function can_claim(address raceAddress, address eth_address) public view returns (bool) {
|
| 572 |
+
bool res;
|
| 573 |
+
(res,) = _isWinnerOf(raceAddress, eth_address);
|
| 574 |
+
return res;
|
| 575 |
+
}
|
| 576 |
+
|
| 577 |
+
|
| 578 |
+
function claim(address raceAddress) external payable
|
| 579 |
+
costs(claimingFee)
|
| 580 |
+
whenNotPaused()
|
| 581 |
+
{
|
| 582 |
+
|
| 583 |
+
bytes32 winner;
|
| 584 |
+
bool res;
|
| 585 |
+
(res,winner) = _isWinnerOf(raceAddress, msg.sender);
|
| 586 |
+
require(winner != bytes32(0),"Winner is zero");
|
| 587 |
+
require(res,"can_claim return false");
|
| 588 |
+
|
| 589 |
+
uint256 id = _generate_special_horsey(raceAddress, msg.sender, winner);
|
| 590 |
+
emit Claimed(raceAddress, msg.sender, id);
|
| 591 |
+
}
|
| 592 |
+
|
| 593 |
+
|
| 594 |
+
function renameHorsey(uint256 tokenId, string newName) external
|
| 595 |
+
whenNotPaused()
|
| 596 |
+
onlyOwnerOf(tokenId)
|
| 597 |
+
costs(renamingCostsPerChar * bytes(newName).length)
|
| 598 |
+
payable {
|
| 599 |
+
uint256 renamingFee = renamingCostsPerChar * bytes(newName).length;
|
| 600 |
+
|
| 601 |
+
if(msg.value > renamingFee)
|
| 602 |
+
{
|
| 603 |
+
msg.sender.transfer(msg.value - renamingFee);
|
| 604 |
+
}
|
| 605 |
+
|
| 606 |
+
stables.storeName(tokenId,newName);
|
| 607 |
+
emit HorseyRenamed(tokenId,newName);
|
| 608 |
+
}
|
| 609 |
+
|
| 610 |
+
|
| 611 |
+
function freeForCarrots(uint256 tokenId) external
|
| 612 |
+
whenNotPaused()
|
| 613 |
+
onlyOwnerOf(tokenId) {
|
| 614 |
+
require(pendingFeedings[msg.sender].horsey != tokenId,"");
|
| 615 |
+
|
| 616 |
+
uint8 feedingCounter;
|
| 617 |
+
(,,feedingCounter,) = stables.horseys(tokenId);
|
| 618 |
+
stables.storeCarrotsCredit(msg.sender,stables.carrot_credits(msg.sender) + uint32(feedingCounter * carrotsMultiplier));
|
| 619 |
+
stables.unstoreHorsey(tokenId);
|
| 620 |
+
emit HorseyFreed(tokenId);
|
| 621 |
+
}
|
| 622 |
+
|
| 623 |
+
|
| 624 |
+
function getCarrotCredits() external view returns (uint32) {
|
| 625 |
+
return stables.carrot_credits(msg.sender);
|
| 626 |
+
}
|
| 627 |
+
|
| 628 |
+
|
| 629 |
+
function getHorsey(uint256 tokenId) public view returns (address, bytes32, uint8, string) {
|
| 630 |
+
RoyalStablesInterface.Horsey memory temp;
|
| 631 |
+
(temp.race,temp.dna,temp.feedingCounter,temp.tier) = stables.horseys(tokenId);
|
| 632 |
+
return (temp.race,temp.dna,temp.feedingCounter,stables.names(tokenId));
|
| 633 |
+
}
|
| 634 |
+
|
| 635 |
+
|
| 636 |
+
function feed(uint256 tokenId) external
|
| 637 |
+
whenNotPaused()
|
| 638 |
+
onlyOwnerOf(tokenId)
|
| 639 |
+
carrotsMeetLevel(tokenId)
|
| 640 |
+
noFeedingInProgress()
|
| 641 |
+
{
|
| 642 |
+
pendingFeedings[msg.sender] = FeedingData(block.number,tokenId);
|
| 643 |
+
uint8 feedingCounter;
|
| 644 |
+
(,,feedingCounter,) = stables.horseys(tokenId);
|
| 645 |
+
stables.storeCarrotsCredit(msg.sender,stables.carrot_credits(msg.sender) - uint32(feedingCounter));
|
| 646 |
+
emit Feeding(tokenId);
|
| 647 |
+
}
|
| 648 |
+
|
| 649 |
+
|
| 650 |
+
function stopFeeding() external
|
| 651 |
+
feedingInProgress() returns (bool) {
|
| 652 |
+
uint256 blockNumber = pendingFeedings[msg.sender].blockNumber;
|
| 653 |
+
uint256 tokenId = pendingFeedings[msg.sender].horsey;
|
| 654 |
+
|
| 655 |
+
require(block.number - blockNumber >= 1,"feeding and stop feeding are in same block");
|
| 656 |
+
|
| 657 |
+
delete pendingFeedings[msg.sender];
|
| 658 |
+
|
| 659 |
+
|
| 660 |
+
|
| 661 |
+
if(block.number - blockNumber > 255) {
|
| 662 |
+
|
| 663 |
+
|
| 664 |
+
emit FeedingFailed(tokenId);
|
| 665 |
+
return false;
|
| 666 |
+
}
|
| 667 |
+
|
| 668 |
+
|
| 669 |
+
if(stables.ownerOf(tokenId) != msg.sender) {
|
| 670 |
+
|
| 671 |
+
|
| 672 |
+
emit FeedingFailed(tokenId);
|
| 673 |
+
return false;
|
| 674 |
+
}
|
| 675 |
+
|
| 676 |
+
|
| 677 |
+
_feed(tokenId, blockhash(blockNumber));
|
| 678 |
+
bytes32 dna;
|
| 679 |
+
(,dna,,) = stables.horseys(tokenId);
|
| 680 |
+
emit ReceivedCarrot(tokenId, dna);
|
| 681 |
+
return true;
|
| 682 |
+
}
|
| 683 |
+
|
| 684 |
+
|
| 685 |
+
function() external payable {
|
| 686 |
+
revert("Not accepting donations");
|
| 687 |
+
}
|
| 688 |
+
|
| 689 |
+
|
| 690 |
+
function _feed(uint256 tokenId, bytes32 blockHash) internal {
|
| 691 |
+
|
| 692 |
+
uint8 tier;
|
| 693 |
+
uint8 feedingCounter;
|
| 694 |
+
(,,feedingCounter,tier) = stables.horseys(tokenId);
|
| 695 |
+
uint256 probabilityByRarity = 10 ** uint256(tier + 1);
|
| 696 |
+
uint256 randNum = uint256(keccak256(abi.encodePacked(tokenId, blockHash))) % probabilityByRarity;
|
| 697 |
+
|
| 698 |
+
|
| 699 |
+
if(randNum <= (feedingCounter * rarityMultiplier)){
|
| 700 |
+
_increaseRarity(tokenId, blockHash);
|
| 701 |
+
}
|
| 702 |
+
|
| 703 |
+
|
| 704 |
+
|
| 705 |
+
if(feedingCounter < 255) {
|
| 706 |
+
stables.modifyHorseyFeedingCounter(tokenId,feedingCounter+1);
|
| 707 |
+
}
|
| 708 |
+
}
|
| 709 |
+
|
| 710 |
+
|
| 711 |
+
function _makeSpecialId(address race, address sender, bytes32 coinIndex) internal pure returns (uint256) {
|
| 712 |
+
return uint256(keccak256(abi.encodePacked(race, sender, coinIndex)));
|
| 713 |
+
}
|
| 714 |
+
|
| 715 |
+
|
| 716 |
+
function _generate_special_horsey(address race, address eth_address, bytes32 coinIndex) internal returns (uint256) {
|
| 717 |
+
uint256 id = _makeSpecialId(race, eth_address, coinIndex);
|
| 718 |
+
|
| 719 |
+
bytes32 dna = _shiftRight(keccak256(abi.encodePacked(race, coinIndex)),16);
|
| 720 |
+
|
| 721 |
+
stables.storeHorsey(eth_address,id,race,dna,1,0);
|
| 722 |
+
return id;
|
| 723 |
+
}
|
| 724 |
+
|
| 725 |
+
|
| 726 |
+
function _increaseRarity(uint256 tokenId, bytes32 blockHash) private {
|
| 727 |
+
uint8 tier;
|
| 728 |
+
bytes32 dna;
|
| 729 |
+
(,dna,,tier) = stables.horseys(tokenId);
|
| 730 |
+
if(tier < 254)
|
| 731 |
+
stables.modifyHorseyTier(tokenId,tier+1);
|
| 732 |
+
uint256 random = uint256(keccak256(abi.encodePacked(tokenId, blockHash)));
|
| 733 |
+
|
| 734 |
+
bytes32 rarityMask = _shiftLeft(bytes32(1), (random % 16 + 240));
|
| 735 |
+
bytes32 newdna = dna | rarityMask;
|
| 736 |
+
stables.modifyHorseyDna(tokenId,newdna);
|
| 737 |
+
}
|
| 738 |
+
|
| 739 |
+
|
| 740 |
+
function _shiftLeft(bytes32 data, uint n) internal pure returns (bytes32) {
|
| 741 |
+
return bytes32(uint256(data)*(2 ** n));
|
| 742 |
+
}
|
| 743 |
+
|
| 744 |
+
|
| 745 |
+
function _shiftRight(bytes32 data, uint n) internal pure returns (bytes32) {
|
| 746 |
+
return bytes32(uint256(data)/(2 ** n));
|
| 747 |
+
}
|
| 748 |
+
|
| 749 |
+
|
| 750 |
+
modifier carrotsMeetLevel(uint256 tokenId){
|
| 751 |
+
uint256 feedingCounter;
|
| 752 |
+
(,,feedingCounter,) = stables.horseys(tokenId);
|
| 753 |
+
require(feedingCounter <= stables.carrot_credits(msg.sender),"Not enough carrots");
|
| 754 |
+
_;
|
| 755 |
+
}
|
| 756 |
+
|
| 757 |
+
|
| 758 |
+
modifier costs(uint256 amount) {
|
| 759 |
+
require(msg.value >= amount,"Not enough funds");
|
| 760 |
+
_;
|
| 761 |
+
}
|
| 762 |
+
|
| 763 |
+
|
| 764 |
+
modifier validAddress(address addr) {
|
| 765 |
+
require(addr != address(0),"Address is zero");
|
| 766 |
+
_;
|
| 767 |
+
}
|
| 768 |
+
|
| 769 |
+
|
| 770 |
+
modifier noFeedingInProgress() {
|
| 771 |
+
|
| 772 |
+
require(pendingFeedings[msg.sender].blockNumber == 0,"Already feeding");
|
| 773 |
+
_;
|
| 774 |
+
}
|
| 775 |
+
|
| 776 |
+
|
| 777 |
+
modifier feedingInProgress() {
|
| 778 |
+
|
| 779 |
+
require(pendingFeedings[msg.sender].blockNumber != 0,"No pending feeding");
|
| 780 |
+
_;
|
| 781 |
+
}
|
| 782 |
+
|
| 783 |
+
|
| 784 |
+
modifier onlyOwnerOf(uint256 tokenId) {
|
| 785 |
+
require(stables.ownerOf(tokenId) == msg.sender, "Caller is not owner of this token");
|
| 786 |
+
_;
|
| 787 |
+
}
|
| 788 |
+
}
|
| 789 |
+
|
| 790 |
+
|
| 791 |
+
|
| 792 |
+
|
| 793 |
+
|
| 794 |
+
contract HorseyPilot {
|
| 795 |
+
|
| 796 |
+
|
| 797 |
+
event NewProposal(uint8 methodId, uint parameter, address proposer);
|
| 798 |
+
|
| 799 |
+
|
| 800 |
+
event ProposalPassed(uint8 methodId, uint parameter, address proposer);
|
| 801 |
+
|
| 802 |
+
|
| 803 |
+
|
| 804 |
+
uint8 constant votingThreshold = 2;
|
| 805 |
+
|
| 806 |
+
|
| 807 |
+
|
| 808 |
+
uint256 constant proposalLife = 7 days;
|
| 809 |
+
|
| 810 |
+
|
| 811 |
+
|
| 812 |
+
uint256 constant proposalCooldown = 1 days;
|
| 813 |
+
|
| 814 |
+
|
| 815 |
+
uint256 cooldownStart;
|
| 816 |
+
|
| 817 |
+
|
| 818 |
+
address public jokerAddress;
|
| 819 |
+
address public knightAddress;
|
| 820 |
+
address public paladinAddress;
|
| 821 |
+
|
| 822 |
+
|
| 823 |
+
address[3] public voters;
|
| 824 |
+
|
| 825 |
+
|
| 826 |
+
uint8 constant public knightEquity = 40;
|
| 827 |
+
uint8 constant public paladinEquity = 10;
|
| 828 |
+
|
| 829 |
+
|
| 830 |
+
address public exchangeAddress;
|
| 831 |
+
address public tokenAddress;
|
| 832 |
+
|
| 833 |
+
|
| 834 |
+
mapping(address => uint) internal _cBalance;
|
| 835 |
+
|
| 836 |
+
|
| 837 |
+
struct Proposal{
|
| 838 |
+
address proposer;
|
| 839 |
+
uint256 timestamp;
|
| 840 |
+
uint256 parameter;
|
| 841 |
+
uint8 methodId;
|
| 842 |
+
address[] yay;
|
| 843 |
+
address[] nay;
|
| 844 |
+
}
|
| 845 |
+
|
| 846 |
+
|
| 847 |
+
Proposal public currentProposal;
|
| 848 |
+
|
| 849 |
+
|
| 850 |
+
bool public proposalInProgress = false;
|
| 851 |
+
|
| 852 |
+
|
| 853 |
+
uint256 public toBeDistributed;
|
| 854 |
+
|
| 855 |
+
|
| 856 |
+
bool deployed = false;
|
| 857 |
+
|
| 858 |
+
|
| 859 |
+
constructor(
|
| 860 |
+
address _jokerAddress,
|
| 861 |
+
address _knightAddress,
|
| 862 |
+
address _paladinAddress,
|
| 863 |
+
address[3] _voters
|
| 864 |
+
) public {
|
| 865 |
+
jokerAddress = _jokerAddress;
|
| 866 |
+
knightAddress = _knightAddress;
|
| 867 |
+
paladinAddress = _paladinAddress;
|
| 868 |
+
|
| 869 |
+
for(uint i = 0; i < 3; i++) {
|
| 870 |
+
voters[i] = _voters[i];
|
| 871 |
+
}
|
| 872 |
+
|
| 873 |
+
|
| 874 |
+
cooldownStart = block.timestamp - proposalCooldown;
|
| 875 |
+
}
|
| 876 |
+
|
| 877 |
+
|
| 878 |
+
function deployChildren(address stablesAddress) external {
|
| 879 |
+
require(!deployed,"already deployed");
|
| 880 |
+
|
| 881 |
+
exchangeAddress = new HorseyExchange();
|
| 882 |
+
tokenAddress = new HorseyToken(stablesAddress);
|
| 883 |
+
|
| 884 |
+
|
| 885 |
+
HorseyExchange(exchangeAddress).setStables(stablesAddress);
|
| 886 |
+
|
| 887 |
+
deployed = true;
|
| 888 |
+
}
|
| 889 |
+
|
| 890 |
+
|
| 891 |
+
function transferJokerOwnership(address newJoker) external
|
| 892 |
+
validAddress(newJoker) {
|
| 893 |
+
require(jokerAddress == msg.sender,"Not right role");
|
| 894 |
+
_moveBalance(newJoker);
|
| 895 |
+
jokerAddress = newJoker;
|
| 896 |
+
}
|
| 897 |
+
|
| 898 |
+
|
| 899 |
+
function transferKnightOwnership(address newKnight) external
|
| 900 |
+
validAddress(newKnight) {
|
| 901 |
+
require(knightAddress == msg.sender,"Not right role");
|
| 902 |
+
_moveBalance(newKnight);
|
| 903 |
+
knightAddress = newKnight;
|
| 904 |
+
}
|
| 905 |
+
|
| 906 |
+
|
| 907 |
+
function transferPaladinOwnership(address newPaladin) external
|
| 908 |
+
validAddress(newPaladin) {
|
| 909 |
+
require(paladinAddress == msg.sender,"Not right role");
|
| 910 |
+
_moveBalance(newPaladin);
|
| 911 |
+
paladinAddress = newPaladin;
|
| 912 |
+
}
|
| 913 |
+
|
| 914 |
+
|
| 915 |
+
function withdrawCeo(address destination) external
|
| 916 |
+
onlyCLevelAccess()
|
| 917 |
+
validAddress(destination) {
|
| 918 |
+
|
| 919 |
+
|
| 920 |
+
if(toBeDistributed > 0){
|
| 921 |
+
_updateDistribution();
|
| 922 |
+
}
|
| 923 |
+
|
| 924 |
+
|
| 925 |
+
uint256 balance = _cBalance[msg.sender];
|
| 926 |
+
|
| 927 |
+
|
| 928 |
+
if(balance > 0 && (address(this).balance >= balance)) {
|
| 929 |
+
destination.transfer(balance);
|
| 930 |
+
_cBalance[msg.sender] = 0;
|
| 931 |
+
}
|
| 932 |
+
}
|
| 933 |
+
|
| 934 |
+
|
| 935 |
+
function syncFunds() external {
|
| 936 |
+
uint256 prevBalance = address(this).balance;
|
| 937 |
+
HorseyToken(tokenAddress).withdraw();
|
| 938 |
+
HorseyExchange(exchangeAddress).withdraw();
|
| 939 |
+
uint256 newBalance = address(this).balance;
|
| 940 |
+
|
| 941 |
+
toBeDistributed = toBeDistributed + (newBalance - prevBalance);
|
| 942 |
+
}
|
| 943 |
+
|
| 944 |
+
|
| 945 |
+
function getNobleBalance() external view
|
| 946 |
+
onlyCLevelAccess() returns (uint256) {
|
| 947 |
+
return _cBalance[msg.sender];
|
| 948 |
+
}
|
| 949 |
+
|
| 950 |
+
|
| 951 |
+
function makeProposal( uint8 methodId, uint256 parameter ) external
|
| 952 |
+
onlyCLevelAccess()
|
| 953 |
+
proposalAvailable()
|
| 954 |
+
cooledDown()
|
| 955 |
+
{
|
| 956 |
+
currentProposal.timestamp = block.timestamp;
|
| 957 |
+
currentProposal.parameter = parameter;
|
| 958 |
+
currentProposal.methodId = methodId;
|
| 959 |
+
currentProposal.proposer = msg.sender;
|
| 960 |
+
delete currentProposal.yay;
|
| 961 |
+
delete currentProposal.nay;
|
| 962 |
+
proposalInProgress = true;
|
| 963 |
+
|
| 964 |
+
emit NewProposal(methodId,parameter,msg.sender);
|
| 965 |
+
}
|
| 966 |
+
|
| 967 |
+
|
| 968 |
+
function voteOnProposal(bool voteFor) external
|
| 969 |
+
proposalPending()
|
| 970 |
+
onlyVoters()
|
| 971 |
+
notVoted() {
|
| 972 |
+
|
| 973 |
+
require((block.timestamp - currentProposal.timestamp) <= proposalLife);
|
| 974 |
+
if(voteFor)
|
| 975 |
+
{
|
| 976 |
+
currentProposal.yay.push(msg.sender);
|
| 977 |
+
|
| 978 |
+
if( currentProposal.yay.length >= votingThreshold )
|
| 979 |
+
{
|
| 980 |
+
_doProposal();
|
| 981 |
+
proposalInProgress = false;
|
| 982 |
+
|
| 983 |
+
return;
|
| 984 |
+
}
|
| 985 |
+
|
| 986 |
+
} else {
|
| 987 |
+
currentProposal.nay.push(msg.sender);
|
| 988 |
+
|
| 989 |
+
if( currentProposal.nay.length >= votingThreshold )
|
| 990 |
+
{
|
| 991 |
+
proposalInProgress = false;
|
| 992 |
+
cooldownStart = block.timestamp;
|
| 993 |
+
return;
|
| 994 |
+
}
|
| 995 |
+
}
|
| 996 |
+
}
|
| 997 |
+
|
| 998 |
+
|
| 999 |
+
function _moveBalance(address newAddress) internal
|
| 1000 |
+
validAddress(newAddress) {
|
| 1001 |
+
require(newAddress != msg.sender);
|
| 1002 |
+
_cBalance[newAddress] = _cBalance[msg.sender];
|
| 1003 |
+
_cBalance[msg.sender] = 0;
|
| 1004 |
+
}
|
| 1005 |
+
|
| 1006 |
+
|
| 1007 |
+
function _updateDistribution() internal {
|
| 1008 |
+
require(toBeDistributed != 0,"nothing to distribute");
|
| 1009 |
+
uint256 knightPayday = toBeDistributed / 100 * knightEquity;
|
| 1010 |
+
uint256 paladinPayday = toBeDistributed / 100 * paladinEquity;
|
| 1011 |
+
|
| 1012 |
+
|
| 1013 |
+
uint256 jokerPayday = toBeDistributed - knightPayday - paladinPayday;
|
| 1014 |
+
|
| 1015 |
+
_cBalance[jokerAddress] = _cBalance[jokerAddress] + jokerPayday;
|
| 1016 |
+
_cBalance[knightAddress] = _cBalance[knightAddress] + knightPayday;
|
| 1017 |
+
_cBalance[paladinAddress] = _cBalance[paladinAddress] + paladinPayday;
|
| 1018 |
+
|
| 1019 |
+
toBeDistributed = 0;
|
| 1020 |
+
}
|
| 1021 |
+
|
| 1022 |
+
|
| 1023 |
+
function _doProposal() internal {
|
| 1024 |
+
|
| 1025 |
+
if( currentProposal.methodId == 0 ) HorseyToken(tokenAddress).setRenamingCosts(currentProposal.parameter);
|
| 1026 |
+
|
| 1027 |
+
|
| 1028 |
+
if( currentProposal.methodId == 1 ) HorseyExchange(exchangeAddress).setMarketFees(currentProposal.parameter);
|
| 1029 |
+
|
| 1030 |
+
|
| 1031 |
+
if( currentProposal.methodId == 2 ) HorseyToken(tokenAddress).addLegitRaceAddress(address(currentProposal.parameter));
|
| 1032 |
+
|
| 1033 |
+
|
| 1034 |
+
if( currentProposal.methodId == 3 ) HorseyToken(tokenAddress).addHorseIndex(bytes32(currentProposal.parameter));
|
| 1035 |
+
|
| 1036 |
+
|
| 1037 |
+
if( currentProposal.methodId == 4 ) {
|
| 1038 |
+
if(currentProposal.parameter == 0) {
|
| 1039 |
+
HorseyExchange(exchangeAddress).unpause();
|
| 1040 |
+
HorseyToken(tokenAddress).unpause();
|
| 1041 |
+
} else {
|
| 1042 |
+
HorseyExchange(exchangeAddress).pause();
|
| 1043 |
+
HorseyToken(tokenAddress).pause();
|
| 1044 |
+
}
|
| 1045 |
+
}
|
| 1046 |
+
|
| 1047 |
+
|
| 1048 |
+
if( currentProposal.methodId == 5 ) HorseyToken(tokenAddress).setClaimingCosts(currentProposal.parameter);
|
| 1049 |
+
|
| 1050 |
+
|
| 1051 |
+
if( currentProposal.methodId == 8 ){
|
| 1052 |
+
HorseyToken(tokenAddress).setCarrotsMultiplier(uint8(currentProposal.parameter));
|
| 1053 |
+
}
|
| 1054 |
+
|
| 1055 |
+
|
| 1056 |
+
if( currentProposal.methodId == 9 ){
|
| 1057 |
+
HorseyToken(tokenAddress).setRarityMultiplier(uint8(currentProposal.parameter));
|
| 1058 |
+
}
|
| 1059 |
+
|
| 1060 |
+
emit ProposalPassed(currentProposal.methodId,currentProposal.parameter,currentProposal.proposer);
|
| 1061 |
+
}
|
| 1062 |
+
|
| 1063 |
+
|
| 1064 |
+
modifier validAddress(address addr) {
|
| 1065 |
+
require(addr != address(0),"Address is zero");
|
| 1066 |
+
_;
|
| 1067 |
+
}
|
| 1068 |
+
|
| 1069 |
+
|
| 1070 |
+
modifier onlyCLevelAccess() {
|
| 1071 |
+
require((jokerAddress == msg.sender) || (knightAddress == msg.sender) || (paladinAddress == msg.sender),"not c level");
|
| 1072 |
+
_;
|
| 1073 |
+
}
|
| 1074 |
+
|
| 1075 |
+
|
| 1076 |
+
|
| 1077 |
+
modifier proposalAvailable(){
|
| 1078 |
+
require(((!proposalInProgress) || ((block.timestamp - currentProposal.timestamp) > proposalLife)),"proposal already pending");
|
| 1079 |
+
_;
|
| 1080 |
+
}
|
| 1081 |
+
|
| 1082 |
+
|
| 1083 |
+
|
| 1084 |
+
modifier cooledDown( ){
|
| 1085 |
+
if(msg.sender == currentProposal.proposer && (block.timestamp - cooldownStart < 1 days)){
|
| 1086 |
+
revert("Cool down period not passed yet");
|
| 1087 |
+
}
|
| 1088 |
+
_;
|
| 1089 |
+
}
|
| 1090 |
+
|
| 1091 |
+
|
| 1092 |
+
modifier proposalPending() {
|
| 1093 |
+
require(proposalInProgress,"no proposal pending");
|
| 1094 |
+
_;
|
| 1095 |
+
}
|
| 1096 |
+
|
| 1097 |
+
|
| 1098 |
+
modifier notVoted() {
|
| 1099 |
+
uint256 length = currentProposal.yay.length;
|
| 1100 |
+
for(uint i = 0; i < length; i++) {
|
| 1101 |
+
if(currentProposal.yay[i] == msg.sender) {
|
| 1102 |
+
revert("Already voted");
|
| 1103 |
+
}
|
| 1104 |
+
}
|
| 1105 |
+
|
| 1106 |
+
length = currentProposal.nay.length;
|
| 1107 |
+
for(i = 0; i < length; i++) {
|
| 1108 |
+
if(currentProposal.nay[i] == msg.sender) {
|
| 1109 |
+
revert("Already voted");
|
| 1110 |
+
}
|
| 1111 |
+
}
|
| 1112 |
+
_;
|
| 1113 |
+
}
|
| 1114 |
+
|
| 1115 |
+
|
| 1116 |
+
modifier onlyVoters() {
|
| 1117 |
+
bool found = false;
|
| 1118 |
+
uint256 length = voters.length;
|
| 1119 |
+
for(uint i = 0; i < length; i++) {
|
| 1120 |
+
if(voters[i] == msg.sender) {
|
| 1121 |
+
found = true;
|
| 1122 |
+
break;
|
| 1123 |
+
}
|
| 1124 |
+
}
|
| 1125 |
+
if(!found) {
|
| 1126 |
+
revert("not a voter");
|
| 1127 |
+
}
|
| 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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
pragma solidity ^0.4.24;
|
| 2 |
+
|
| 3 |
+
|
| 4 |
+
|
| 5 |
+
|
| 6 |
+
contract Ownable {
|
| 7 |
+
address public owner;
|
| 8 |
+
|
| 9 |
+
|
| 10 |
+
event OwnershipRenounced(address indexed previousOwner);
|
| 11 |
+
event OwnershipTransferred(
|
| 12 |
+
address indexed previousOwner,
|
| 13 |
+
address indexed newOwner
|
| 14 |
+
);
|
| 15 |
+
|
| 16 |
+
|
| 17 |
+
|
| 18 |
+
constructor() public {
|
| 19 |
+
owner = msg.sender;
|
| 20 |
+
}
|
| 21 |
+
|
| 22 |
+
|
| 23 |
+
modifier onlyOwner() {
|
| 24 |
+
require(msg.sender == owner);
|
| 25 |
+
_;
|
| 26 |
+
}
|
| 27 |
+
|
| 28 |
+
|
| 29 |
+
function renounceOwnership() public onlyOwner {
|
| 30 |
+
emit OwnershipRenounced(owner);
|
| 31 |
+
owner = address(0);
|
| 32 |
+
}
|
| 33 |
+
|
| 34 |
+
|
| 35 |
+
function transferOwnership(address _newOwner) public onlyOwner {
|
| 36 |
+
_transferOwnership(_newOwner);
|
| 37 |
+
}
|
| 38 |
+
|
| 39 |
+
|
| 40 |
+
function _transferOwnership(address _newOwner) internal {
|
| 41 |
+
require(_newOwner != address(0));
|
| 42 |
+
emit OwnershipTransferred(owner, _newOwner);
|
| 43 |
+
owner = _newOwner;
|
| 44 |
+
}
|
| 45 |
+
}
|
| 46 |
+
|
| 47 |
+
|
| 48 |
+
|
| 49 |
+
|
| 50 |
+
contract Pausable is Ownable {
|
| 51 |
+
event Pause();
|
| 52 |
+
event Unpause();
|
| 53 |
+
|
| 54 |
+
bool public paused = false;
|
| 55 |
+
|
| 56 |
+
|
| 57 |
+
|
| 58 |
+
modifier whenNotPaused() {
|
| 59 |
+
require(!paused);
|
| 60 |
+
_;
|
| 61 |
+
}
|
| 62 |
+
|
| 63 |
+
|
| 64 |
+
modifier whenPaused() {
|
| 65 |
+
require(paused);
|
| 66 |
+
_;
|
| 67 |
+
}
|
| 68 |
+
|
| 69 |
+
|
| 70 |
+
function pause() public onlyOwner whenNotPaused {
|
| 71 |
+
paused = true;
|
| 72 |
+
emit Pause();
|
| 73 |
+
}
|
| 74 |
+
|
| 75 |
+
|
| 76 |
+
function unpause() public onlyOwner whenPaused {
|
| 77 |
+
paused = false;
|
| 78 |
+
emit Unpause();
|
| 79 |
+
}
|
| 80 |
+
}
|
| 81 |
+
|
| 82 |
+
|
| 83 |
+
|
| 84 |
+
|
| 85 |
+
contract ERC721Receiver {
|
| 86 |
+
|
| 87 |
+
bytes4 internal constant ERC721_RECEIVED = 0x150b7a02;
|
| 88 |
+
|
| 89 |
+
|
| 90 |
+
function onERC721Received(
|
| 91 |
+
address _operator,
|
| 92 |
+
address _from,
|
| 93 |
+
uint256 _tokenId,
|
| 94 |
+
bytes _data
|
| 95 |
+
)
|
| 96 |
+
public
|
| 97 |
+
returns(bytes4);
|
| 98 |
+
}
|
| 99 |
+
|
| 100 |
+
|
| 101 |
+
|
| 102 |
+
contract ERC721Holder is ERC721Receiver {
|
| 103 |
+
function onERC721Received(
|
| 104 |
+
address,
|
| 105 |
+
address,
|
| 106 |
+
uint256,
|
| 107 |
+
bytes
|
| 108 |
+
)
|
| 109 |
+
public
|
| 110 |
+
returns(bytes4)
|
| 111 |
+
{
|
| 112 |
+
return ERC721_RECEIVED;
|
| 113 |
+
}
|
| 114 |
+
}
|
| 115 |
+
|
| 116 |
+
|
| 117 |
+
|
| 118 |
+
|
| 119 |
+
contract ERC721Basic {
|
| 120 |
+
function balanceOf(address _owner) public view returns (uint256 _balance);
|
| 121 |
+
function ownerOf(uint256 _tokenId) public view returns (address _owner);
|
| 122 |
+
function exists(uint256 _tokenId) public view returns (bool _exists);
|
| 123 |
+
|
| 124 |
+
function approve(address _to, uint256 _tokenId) public;
|
| 125 |
+
function getApproved(uint256 _tokenId) public view returns (address _operator);
|
| 126 |
+
|
| 127 |
+
function transferFrom(address _from, address _to, uint256 _tokenId) public;
|
| 128 |
+
}
|
| 129 |
+
|
| 130 |
+
|
| 131 |
+
contract HorseyExchange is Pausable, ERC721Holder {
|
| 132 |
+
|
| 133 |
+
event HorseyDeposit(uint256 tokenId, uint256 price);
|
| 134 |
+
event SaleCanceled(uint256 tokenId);
|
| 135 |
+
event HorseyPurchased(uint256 tokenId, address newOwner, uint256 totalToPay);
|
| 136 |
+
|
| 137 |
+
|
| 138 |
+
uint256 public marketMakerFee = 3;
|
| 139 |
+
|
| 140 |
+
|
| 141 |
+
uint256 collectedFees = 0;
|
| 142 |
+
|
| 143 |
+
|
| 144 |
+
ERC721Basic public token;
|
| 145 |
+
|
| 146 |
+
|
| 147 |
+
struct SaleData {
|
| 148 |
+
uint256 price;
|
| 149 |
+
address owner;
|
| 150 |
+
}
|
| 151 |
+
|
| 152 |
+
|
| 153 |
+
mapping (uint256 => SaleData) market;
|
| 154 |
+
|
| 155 |
+
|
| 156 |
+
mapping (address => uint256[]) userBarn;
|
| 157 |
+
|
| 158 |
+
|
| 159 |
+
constructor() Pausable() ERC721Holder() public {
|
| 160 |
+
}
|
| 161 |
+
|
| 162 |
+
|
| 163 |
+
function setStables(address _token) external
|
| 164 |
+
onlyOwner()
|
| 165 |
+
{
|
| 166 |
+
require(address(_token) != 0,"Address of token is zero");
|
| 167 |
+
token = ERC721Basic(_token);
|
| 168 |
+
}
|
| 169 |
+
|
| 170 |
+
|
| 171 |
+
function setMarketFees(uint256 fees) external
|
| 172 |
+
onlyOwner()
|
| 173 |
+
{
|
| 174 |
+
marketMakerFee = fees;
|
| 175 |
+
}
|
| 176 |
+
|
| 177 |
+
|
| 178 |
+
function getTokensOnSale(address user) external view returns(uint256[]) {
|
| 179 |
+
return userBarn[user];
|
| 180 |
+
}
|
| 181 |
+
|
| 182 |
+
|
| 183 |
+
function getTokenPrice(uint256 tokenId) public view
|
| 184 |
+
isOnMarket(tokenId) returns (uint256) {
|
| 185 |
+
return market[tokenId].price + (market[tokenId].price / 100 * marketMakerFee);
|
| 186 |
+
}
|
| 187 |
+
|
| 188 |
+
|
| 189 |
+
function depositToExchange(uint256 tokenId, uint256 price) external
|
| 190 |
+
whenNotPaused()
|
| 191 |
+
isTokenOwner(tokenId)
|
| 192 |
+
nonZeroPrice(price)
|
| 193 |
+
tokenAvailable() {
|
| 194 |
+
require(token.getApproved(tokenId) == address(this),"Exchange is not allowed to transfer");
|
| 195 |
+
|
| 196 |
+
token.transferFrom(msg.sender, address(this), tokenId);
|
| 197 |
+
|
| 198 |
+
|
| 199 |
+
market[tokenId] = SaleData(price,msg.sender);
|
| 200 |
+
|
| 201 |
+
|
| 202 |
+
userBarn[msg.sender].push(tokenId);
|
| 203 |
+
|
| 204 |
+
emit HorseyDeposit(tokenId, price);
|
| 205 |
+
}
|
| 206 |
+
|
| 207 |
+
|
| 208 |
+
function cancelSale(uint256 tokenId) external
|
| 209 |
+
whenNotPaused()
|
| 210 |
+
originalOwnerOf(tokenId)
|
| 211 |
+
tokenAvailable() returns (bool) {
|
| 212 |
+
|
| 213 |
+
token.transferFrom(address(this),msg.sender,tokenId);
|
| 214 |
+
|
| 215 |
+
|
| 216 |
+
delete market[tokenId];
|
| 217 |
+
|
| 218 |
+
|
| 219 |
+
_removeTokenFromBarn(tokenId, msg.sender);
|
| 220 |
+
|
| 221 |
+
emit SaleCanceled(tokenId);
|
| 222 |
+
|
| 223 |
+
|
| 224 |
+
|
| 225 |
+
return userBarn[msg.sender].length > 0;
|
| 226 |
+
}
|
| 227 |
+
|
| 228 |
+
|
| 229 |
+
function purchaseToken(uint256 tokenId) external payable
|
| 230 |
+
whenNotPaused()
|
| 231 |
+
isOnMarket(tokenId)
|
| 232 |
+
tokenAvailable()
|
| 233 |
+
notOriginalOwnerOf(tokenId)
|
| 234 |
+
{
|
| 235 |
+
|
| 236 |
+
uint256 totalToPay = getTokenPrice(tokenId);
|
| 237 |
+
require(msg.value >= totalToPay, "Not paying enough");
|
| 238 |
+
|
| 239 |
+
|
| 240 |
+
SaleData memory sale = market[tokenId];
|
| 241 |
+
|
| 242 |
+
|
| 243 |
+
collectedFees += totalToPay - sale.price;
|
| 244 |
+
|
| 245 |
+
|
| 246 |
+
sale.owner.transfer(sale.price);
|
| 247 |
+
|
| 248 |
+
|
| 249 |
+
_removeTokenFromBarn(tokenId, sale.owner);
|
| 250 |
+
|
| 251 |
+
|
| 252 |
+
delete market[tokenId];
|
| 253 |
+
|
| 254 |
+
|
| 255 |
+
|
| 256 |
+
token.transferFrom(address(this), msg.sender, tokenId);
|
| 257 |
+
|
| 258 |
+
|
| 259 |
+
if(msg.value > totalToPay)
|
| 260 |
+
{
|
| 261 |
+
msg.sender.transfer(msg.value - totalToPay);
|
| 262 |
+
}
|
| 263 |
+
|
| 264 |
+
emit HorseyPurchased(tokenId, msg.sender, totalToPay);
|
| 265 |
+
}
|
| 266 |
+
|
| 267 |
+
|
| 268 |
+
function withdraw() external
|
| 269 |
+
onlyOwner()
|
| 270 |
+
{
|
| 271 |
+
assert(collectedFees <= address(this).balance);
|
| 272 |
+
owner.transfer(collectedFees);
|
| 273 |
+
collectedFees = 0;
|
| 274 |
+
}
|
| 275 |
+
|
| 276 |
+
|
| 277 |
+
function _removeTokenFromBarn(uint tokenId, address barnAddress) internal {
|
| 278 |
+
uint256[] storage barnArray = userBarn[barnAddress];
|
| 279 |
+
require(barnArray.length > 0,"No tokens to remove");
|
| 280 |
+
int index = _indexOf(tokenId, barnArray);
|
| 281 |
+
require(index >= 0, "Token not found in barn");
|
| 282 |
+
|
| 283 |
+
|
| 284 |
+
for (uint256 i = uint256(index); i<barnArray.length-1; i++){
|
| 285 |
+
barnArray[i] = barnArray[i+1];
|
| 286 |
+
}
|
| 287 |
+
|
| 288 |
+
|
| 289 |
+
|
| 290 |
+
barnArray.length--;
|
| 291 |
+
}
|
| 292 |
+
|
| 293 |
+
|
| 294 |
+
function _indexOf(uint item, uint256[] memory array) internal pure returns (int256){
|
| 295 |
+
|
| 296 |
+
|
| 297 |
+
for(uint256 i = 0; i < array.length; i++){
|
| 298 |
+
if(array[i] == item){
|
| 299 |
+
return int256(i);
|
| 300 |
+
}
|
| 301 |
+
}
|
| 302 |
+
|
| 303 |
+
|
| 304 |
+
return -1;
|
| 305 |
+
}
|
| 306 |
+
|
| 307 |
+
|
| 308 |
+
modifier isOnMarket(uint256 tokenId) {
|
| 309 |
+
require(token.ownerOf(tokenId) == address(this),"Token not on market");
|
| 310 |
+
_;
|
| 311 |
+
}
|
| 312 |
+
|
| 313 |
+
|
| 314 |
+
modifier isTokenOwner(uint256 tokenId) {
|
| 315 |
+
require(token.ownerOf(tokenId) == msg.sender,"Not tokens owner");
|
| 316 |
+
_;
|
| 317 |
+
}
|
| 318 |
+
|
| 319 |
+
|
| 320 |
+
modifier originalOwnerOf(uint256 tokenId) {
|
| 321 |
+
require(market[tokenId].owner == msg.sender,"Not the original owner of");
|
| 322 |
+
_;
|
| 323 |
+
}
|
| 324 |
+
|
| 325 |
+
|
| 326 |
+
modifier notOriginalOwnerOf(uint256 tokenId) {
|
| 327 |
+
require(market[tokenId].owner != msg.sender,"Is the original owner");
|
| 328 |
+
_;
|
| 329 |
+
}
|
| 330 |
+
|
| 331 |
+
|
| 332 |
+
modifier nonZeroPrice(uint256 price){
|
| 333 |
+
require(price > 0,"Price is zero");
|
| 334 |
+
_;
|
| 335 |
+
}
|
| 336 |
+
|
| 337 |
+
|
| 338 |
+
modifier tokenAvailable(){
|
| 339 |
+
require(address(token) != 0,"Token address not set");
|
| 340 |
+
_;
|
| 341 |
+
}
|
| 342 |
+
}
|
| 343 |
+
|
| 344 |
+
|
| 345 |
+
|
| 346 |
+
|
| 347 |
+
contract EthorseRace {
|
| 348 |
+
|
| 349 |
+
|
| 350 |
+
struct chronus_info {
|
| 351 |
+
bool betting_open;
|
| 352 |
+
bool race_start;
|
| 353 |
+
bool race_end;
|
| 354 |
+
bool voided_bet;
|
| 355 |
+
uint32 starting_time;
|
| 356 |
+
uint32 betting_duration;
|
| 357 |
+
uint32 race_duration;
|
| 358 |
+
uint32 voided_timestamp;
|
| 359 |
+
}
|
| 360 |
+
|
| 361 |
+
address public owner;
|
| 362 |
+
|
| 363 |
+
|
| 364 |
+
chronus_info public chronus;
|
| 365 |
+
|
| 366 |
+
|
| 367 |
+
mapping (bytes32 => bool) public winner_horse;
|
| 368 |
+
|
| 369 |
+
|
| 370 |
+
function getCoinIndex(bytes32 index, address candidate) external constant returns (uint, uint, uint, bool, uint);
|
| 371 |
+
}
|
| 372 |
+
|
| 373 |
+
|
| 374 |
+
contract EthorseHelpers {
|
| 375 |
+
|
| 376 |
+
|
| 377 |
+
bytes32[] public all_horses = [bytes32("BTC"),bytes32("ETH"),bytes32("LTC")];
|
| 378 |
+
mapping(address => bool) public legitRaces;
|
| 379 |
+
bool onlyLegit = false;
|
| 380 |
+
|
| 381 |
+
|
| 382 |
+
function _addHorse(bytes32 newHorse) internal {
|
| 383 |
+
all_horses.push(newHorse);
|
| 384 |
+
}
|
| 385 |
+
|
| 386 |
+
function _addLegitRace(address newRace) internal
|
| 387 |
+
{
|
| 388 |
+
legitRaces[newRace] = true;
|
| 389 |
+
if(!onlyLegit)
|
| 390 |
+
onlyLegit = true;
|
| 391 |
+
}
|
| 392 |
+
|
| 393 |
+
function getall_horsesCount() public view returns(uint) {
|
| 394 |
+
return all_horses.length;
|
| 395 |
+
}
|
| 396 |
+
|
| 397 |
+
|
| 398 |
+
function _isWinnerOf(address raceAddress, address eth_address) internal view returns (bool,bytes32)
|
| 399 |
+
{
|
| 400 |
+
|
| 401 |
+
EthorseRace race = EthorseRace(raceAddress);
|
| 402 |
+
|
| 403 |
+
|
| 404 |
+
if(onlyLegit)
|
| 405 |
+
require(legitRaces[raceAddress],"not legit race");
|
| 406 |
+
|
| 407 |
+
bool voided_bet;
|
| 408 |
+
bool race_end;
|
| 409 |
+
(,,race_end,voided_bet,,,,) = race.chronus();
|
| 410 |
+
|
| 411 |
+
|
| 412 |
+
if(voided_bet || !race_end)
|
| 413 |
+
return (false,bytes32(0));
|
| 414 |
+
|
| 415 |
+
|
| 416 |
+
bytes32 horse;
|
| 417 |
+
bool found = false;
|
| 418 |
+
uint256 arrayLength = all_horses.length;
|
| 419 |
+
|
| 420 |
+
|
| 421 |
+
for(uint256 i = 0; i < arrayLength; i++)
|
| 422 |
+
{
|
| 423 |
+
if(race.winner_horse(all_horses[i])) {
|
| 424 |
+
horse = all_horses[i];
|
| 425 |
+
found = true;
|
| 426 |
+
break;
|
| 427 |
+
}
|
| 428 |
+
}
|
| 429 |
+
|
| 430 |
+
if(!found)
|
| 431 |
+
return (false,bytes32(0));
|
| 432 |
+
|
| 433 |
+
|
| 434 |
+
uint256 bet_amount = 0;
|
| 435 |
+
(,,,, bet_amount) = race.getCoinIndex(horse, eth_address);
|
| 436 |
+
|
| 437 |
+
|
| 438 |
+
return (bet_amount > 0, horse);
|
| 439 |
+
}
|
| 440 |
+
}
|
| 441 |
+
|
| 442 |
+
|
| 443 |
+
|
| 444 |
+
contract RoyalStablesInterface {
|
| 445 |
+
|
| 446 |
+
struct Horsey {
|
| 447 |
+
address race;
|
| 448 |
+
bytes32 dna;
|
| 449 |
+
uint8 feedingCounter;
|
| 450 |
+
uint8 tier;
|
| 451 |
+
}
|
| 452 |
+
|
| 453 |
+
mapping(uint256 => Horsey) public horseys;
|
| 454 |
+
mapping(address => uint32) public carrot_credits;
|
| 455 |
+
mapping(uint256 => string) public names;
|
| 456 |
+
address public master;
|
| 457 |
+
|
| 458 |
+
function getOwnedTokens(address eth_address) public view returns (uint256[]);
|
| 459 |
+
function storeName(uint256 tokenId, string newName) public;
|
| 460 |
+
function storeCarrotsCredit(address client, uint32 amount) public;
|
| 461 |
+
function storeHorsey(address client, uint256 tokenId, address race, bytes32 dna, uint8 feedingCounter, uint8 tier) public;
|
| 462 |
+
function modifyHorsey(uint256 tokenId, address race, bytes32 dna, uint8 feedingCounter, uint8 tier) public;
|
| 463 |
+
function modifyHorseyDna(uint256 tokenId, bytes32 dna) public;
|
| 464 |
+
function modifyHorseyFeedingCounter(uint256 tokenId, uint8 feedingCounter) public;
|
| 465 |
+
function modifyHorseyTier(uint256 tokenId, uint8 tier) public;
|
| 466 |
+
function unstoreHorsey(uint256 tokenId) public;
|
| 467 |
+
function ownerOf(uint256 tokenId) public returns (address);
|
| 468 |
+
}
|
| 469 |
+
|
| 470 |
+
|
| 471 |
+
contract HorseyToken is EthorseHelpers,Pausable {
|
| 472 |
+
|
| 473 |
+
|
| 474 |
+
event Claimed(address raceAddress, address eth_address, uint256 tokenId);
|
| 475 |
+
|
| 476 |
+
|
| 477 |
+
event Feeding(uint256 tokenId);
|
| 478 |
+
|
| 479 |
+
|
| 480 |
+
event ReceivedCarrot(uint256 tokenId, bytes32 newDna);
|
| 481 |
+
|
| 482 |
+
|
| 483 |
+
event FeedingFailed(uint256 tokenId);
|
| 484 |
+
|
| 485 |
+
|
| 486 |
+
event HorseyRenamed(uint256 tokenId, string newName);
|
| 487 |
+
|
| 488 |
+
|
| 489 |
+
event HorseyFreed(uint256 tokenId);
|
| 490 |
+
|
| 491 |
+
|
| 492 |
+
RoyalStablesInterface public stables;
|
| 493 |
+
|
| 494 |
+
|
| 495 |
+
uint8 public carrotsMultiplier = 1;
|
| 496 |
+
|
| 497 |
+
|
| 498 |
+
uint8 public rarityMultiplier = 1;
|
| 499 |
+
|
| 500 |
+
|
| 501 |
+
uint256 public claimingFee = 0.000 ether;
|
| 502 |
+
|
| 503 |
+
|
| 504 |
+
struct FeedingData {
|
| 505 |
+
uint256 blockNumber;
|
| 506 |
+
uint256 horsey;
|
| 507 |
+
}
|
| 508 |
+
|
| 509 |
+
|
| 510 |
+
mapping(address => FeedingData) public pendingFeedings;
|
| 511 |
+
|
| 512 |
+
|
| 513 |
+
uint256 public renamingCostsPerChar = 0.001 ether;
|
| 514 |
+
|
| 515 |
+
|
| 516 |
+
constructor(address stablesAddress)
|
| 517 |
+
EthorseHelpers()
|
| 518 |
+
Pausable() public {
|
| 519 |
+
stables = RoyalStablesInterface(stablesAddress);
|
| 520 |
+
}
|
| 521 |
+
|
| 522 |
+
|
| 523 |
+
function setRarityMultiplier(uint8 newRarityMultiplier) external
|
| 524 |
+
onlyOwner() {
|
| 525 |
+
rarityMultiplier = newRarityMultiplier;
|
| 526 |
+
}
|
| 527 |
+
|
| 528 |
+
|
| 529 |
+
function setCarrotsMultiplier(uint8 newCarrotsMultiplier) external
|
| 530 |
+
onlyOwner() {
|
| 531 |
+
carrotsMultiplier = newCarrotsMultiplier;
|
| 532 |
+
}
|
| 533 |
+
|
| 534 |
+
|
| 535 |
+
function setRenamingCosts(uint256 newRenamingCost) external
|
| 536 |
+
onlyOwner() {
|
| 537 |
+
renamingCostsPerChar = newRenamingCost;
|
| 538 |
+
}
|
| 539 |
+
|
| 540 |
+
|
| 541 |
+
function setClaimingCosts(uint256 newClaimingFee) external
|
| 542 |
+
onlyOwner() {
|
| 543 |
+
claimingFee = newClaimingFee;
|
| 544 |
+
}
|
| 545 |
+
|
| 546 |
+
|
| 547 |
+
function addLegitRaceAddress(address newAddress) external
|
| 548 |
+
onlyOwner() {
|
| 549 |
+
_addLegitRace(newAddress);
|
| 550 |
+
}
|
| 551 |
+
|
| 552 |
+
|
| 553 |
+
function withdraw() external
|
| 554 |
+
onlyOwner() {
|
| 555 |
+
owner.transfer(address(this).balance);
|
| 556 |
+
}
|
| 557 |
+
|
| 558 |
+
|
| 559 |
+
|
| 560 |
+
function addHorseIndex(bytes32 newHorse) external
|
| 561 |
+
onlyOwner() {
|
| 562 |
+
_addHorse(newHorse);
|
| 563 |
+
}
|
| 564 |
+
|
| 565 |
+
|
| 566 |
+
function getOwnedTokens(address eth_address) public view returns (uint256[]) {
|
| 567 |
+
return stables.getOwnedTokens(eth_address);
|
| 568 |
+
}
|
| 569 |
+
|
| 570 |
+
|
| 571 |
+
function can_claim(address raceAddress, address eth_address) public view returns (bool) {
|
| 572 |
+
bool res;
|
| 573 |
+
(res,) = _isWinnerOf(raceAddress, eth_address);
|
| 574 |
+
return res;
|
| 575 |
+
}
|
| 576 |
+
|
| 577 |
+
|
| 578 |
+
function claim(address raceAddress) external payable
|
| 579 |
+
costs(claimingFee)
|
| 580 |
+
whenNotPaused()
|
| 581 |
+
{
|
| 582 |
+
|
| 583 |
+
bytes32 winner;
|
| 584 |
+
bool res;
|
| 585 |
+
(res,winner) = _isWinnerOf(raceAddress, msg.sender);
|
| 586 |
+
require(winner != bytes32(0),"Winner is zero");
|
| 587 |
+
require(res,"can_claim return false");
|
| 588 |
+
|
| 589 |
+
uint256 id = _generate_special_horsey(raceAddress, msg.sender, winner);
|
| 590 |
+
emit Claimed(raceAddress, msg.sender, id);
|
| 591 |
+
}
|
| 592 |
+
|
| 593 |
+
|
| 594 |
+
function renameHorsey(uint256 tokenId, string newName) external
|
| 595 |
+
whenNotPaused()
|
| 596 |
+
onlyOwnerOf(tokenId)
|
| 597 |
+
costs(renamingCostsPerChar * bytes(newName).length)
|
| 598 |
+
payable {
|
| 599 |
+
uint256 renamingFee = renamingCostsPerChar * bytes(newName).length;
|
| 600 |
+
|
| 601 |
+
if(msg.value > renamingFee)
|
| 602 |
+
{
|
| 603 |
+
msg.sender.transfer(msg.value - renamingFee);
|
| 604 |
+
}
|
| 605 |
+
|
| 606 |
+
stables.storeName(tokenId,newName);
|
| 607 |
+
emit HorseyRenamed(tokenId,newName);
|
| 608 |
+
}
|
| 609 |
+
|
| 610 |
+
|
| 611 |
+
function freeForCarrots(uint256 tokenId) external
|
| 612 |
+
whenNotPaused()
|
| 613 |
+
onlyOwnerOf(tokenId) {
|
| 614 |
+
require(pendingFeedings[msg.sender].horsey != tokenId,"");
|
| 615 |
+
|
| 616 |
+
uint8 feedingCounter;
|
| 617 |
+
(,,feedingCounter,) = stables.horseys(tokenId);
|
| 618 |
+
stables.storeCarrotsCredit(msg.sender,stables.carrot_credits(msg.sender) + uint32(feedingCounter * carrotsMultiplier));
|
| 619 |
+
stables.unstoreHorsey(tokenId);
|
| 620 |
+
emit HorseyFreed(tokenId);
|
| 621 |
+
}
|
| 622 |
+
|
| 623 |
+
|
| 624 |
+
function getCarrotCredits() external view returns (uint32) {
|
| 625 |
+
return stables.carrot_credits(msg.sender);
|
| 626 |
+
}
|
| 627 |
+
|
| 628 |
+
|
| 629 |
+
function getHorsey(uint256 tokenId) public view returns (address, bytes32, uint8, string) {
|
| 630 |
+
RoyalStablesInterface.Horsey memory temp;
|
| 631 |
+
(temp.race,temp.dna,temp.feedingCounter,temp.tier) = stables.horseys(tokenId);
|
| 632 |
+
return (temp.race,temp.dna,temp.feedingCounter,stables.names(tokenId));
|
| 633 |
+
}
|
| 634 |
+
|
| 635 |
+
|
| 636 |
+
function feed(uint256 tokenId) external
|
| 637 |
+
whenNotPaused()
|
| 638 |
+
onlyOwnerOf(tokenId)
|
| 639 |
+
carrotsMeetLevel(tokenId)
|
| 640 |
+
noFeedingInProgress()
|
| 641 |
+
{
|
| 642 |
+
pendingFeedings[msg.sender] = FeedingData(block.number,tokenId);
|
| 643 |
+
uint8 feedingCounter;
|
| 644 |
+
(,,feedingCounter,) = stables.horseys(tokenId);
|
| 645 |
+
stables.storeCarrotsCredit(msg.sender,stables.carrot_credits(msg.sender) - uint32(feedingCounter));
|
| 646 |
+
emit Feeding(tokenId);
|
| 647 |
+
}
|
| 648 |
+
|
| 649 |
+
|
| 650 |
+
function stopFeeding() external
|
| 651 |
+
feedingInProgress() returns (bool) {
|
| 652 |
+
uint256 blockNumber = pendingFeedings[msg.sender].blockNumber;
|
| 653 |
+
uint256 tokenId = pendingFeedings[msg.sender].horsey;
|
| 654 |
+
|
| 655 |
+
require(block.number - blockNumber >= 1,"feeding and stop feeding are in same block");
|
| 656 |
+
|
| 657 |
+
delete pendingFeedings[msg.sender];
|
| 658 |
+
|
| 659 |
+
|
| 660 |
+
|
| 661 |
+
if(block.number - blockNumber > 255) {
|
| 662 |
+
|
| 663 |
+
|
| 664 |
+
emit FeedingFailed(tokenId);
|
| 665 |
+
return false;
|
| 666 |
+
}
|
| 667 |
+
|
| 668 |
+
|
| 669 |
+
if(stables.ownerOf(tokenId) != msg.sender) {
|
| 670 |
+
|
| 671 |
+
|
| 672 |
+
emit FeedingFailed(tokenId);
|
| 673 |
+
return false;
|
| 674 |
+
}
|
| 675 |
+
|
| 676 |
+
|
| 677 |
+
_feed(tokenId, blockhash(blockNumber));
|
| 678 |
+
bytes32 dna;
|
| 679 |
+
(,dna,,) = stables.horseys(tokenId);
|
| 680 |
+
emit ReceivedCarrot(tokenId, dna);
|
| 681 |
+
return true;
|
| 682 |
+
}
|
| 683 |
+
|
| 684 |
+
|
| 685 |
+
function() external payable {
|
| 686 |
+
revert("Not accepting donations");
|
| 687 |
+
}
|
| 688 |
+
|
| 689 |
+
|
| 690 |
+
function _feed(uint256 tokenId, bytes32 blockHash) internal {
|
| 691 |
+
|
| 692 |
+
uint8 tier;
|
| 693 |
+
uint8 feedingCounter;
|
| 694 |
+
(,,feedingCounter,tier) = stables.horseys(tokenId);
|
| 695 |
+
uint256 probabilityByRarity = 10 ** uint256(tier + 1);
|
| 696 |
+
uint256 randNum = uint256(keccak256(abi.encodePacked(tokenId, blockHash))) % probabilityByRarity;
|
| 697 |
+
|
| 698 |
+
|
| 699 |
+
if(randNum <= (feedingCounter * rarityMultiplier)){
|
| 700 |
+
_increaseRarity(tokenId, blockHash);
|
| 701 |
+
}
|
| 702 |
+
|
| 703 |
+
|
| 704 |
+
|
| 705 |
+
if(feedingCounter < 255) {
|
| 706 |
+
stables.modifyHorseyFeedingCounter(tokenId,feedingCounter+1);
|
| 707 |
+
}
|
| 708 |
+
}
|
| 709 |
+
|
| 710 |
+
|
| 711 |
+
function _makeSpecialId(address race, address sender, bytes32 coinIndex) internal pure returns (uint256) {
|
| 712 |
+
return uint256(keccak256(abi.encodePacked(race, sender, coinIndex)));
|
| 713 |
+
}
|
| 714 |
+
|
| 715 |
+
|
| 716 |
+
function _generate_special_horsey(address race, address eth_address, bytes32 coinIndex) internal returns (uint256) {
|
| 717 |
+
uint256 id = _makeSpecialId(race, eth_address, coinIndex);
|
| 718 |
+
|
| 719 |
+
bytes32 dna = _shiftRight(keccak256(abi.encodePacked(race, coinIndex)),16);
|
| 720 |
+
|
| 721 |
+
stables.storeHorsey(eth_address,id,race,dna,1,0);
|
| 722 |
+
return id;
|
| 723 |
+
}
|
| 724 |
+
|
| 725 |
+
|
| 726 |
+
function _increaseRarity(uint256 tokenId, bytes32 blockHash) private {
|
| 727 |
+
uint8 tier;
|
| 728 |
+
bytes32 dna;
|
| 729 |
+
(,dna,,tier) = stables.horseys(tokenId);
|
| 730 |
+
if(tier < 254)
|
| 731 |
+
stables.modifyHorseyTier(tokenId,tier+1);
|
| 732 |
+
uint256 random = uint256(keccak256(abi.encodePacked(tokenId, blockHash)));
|
| 733 |
+
|
| 734 |
+
bytes32 rarityMask = _shiftLeft(bytes32(1), (random % 16 + 240));
|
| 735 |
+
bytes32 newdna = dna | rarityMask;
|
| 736 |
+
stables.modifyHorseyDna(tokenId,newdna);
|
| 737 |
+
}
|
| 738 |
+
|
| 739 |
+
|
| 740 |
+
function _shiftLeft(bytes32 data, uint n) internal pure returns (bytes32) {
|
| 741 |
+
return bytes32(uint256(data)*(2 ** n));
|
| 742 |
+
}
|
| 743 |
+
|
| 744 |
+
|
| 745 |
+
function _shiftRight(bytes32 data, uint n) internal pure returns (bytes32) {
|
| 746 |
+
return bytes32(uint256(data)/(2 ** n));
|
| 747 |
+
}
|
| 748 |
+
|
| 749 |
+
|
| 750 |
+
modifier carrotsMeetLevel(uint256 tokenId){
|
| 751 |
+
uint256 feedingCounter;
|
| 752 |
+
(,,feedingCounter,) = stables.horseys(tokenId);
|
| 753 |
+
require(feedingCounter <= stables.carrot_credits(msg.sender),"Not enough carrots");
|
| 754 |
+
_;
|
| 755 |
+
}
|
| 756 |
+
|
| 757 |
+
|
| 758 |
+
modifier costs(uint256 amount) {
|
| 759 |
+
require(msg.value >= amount,"Not enough funds");
|
| 760 |
+
_;
|
| 761 |
+
}
|
| 762 |
+
|
| 763 |
+
|
| 764 |
+
modifier validAddress(address addr) {
|
| 765 |
+
require(addr != address(0),"Address is zero");
|
| 766 |
+
_;
|
| 767 |
+
}
|
| 768 |
+
|
| 769 |
+
|
| 770 |
+
modifier noFeedingInProgress() {
|
| 771 |
+
|
| 772 |
+
require(pendingFeedings[msg.sender].blockNumber == 0,"Already feeding");
|
| 773 |
+
_;
|
| 774 |
+
}
|
| 775 |
+
|
| 776 |
+
|
| 777 |
+
modifier feedingInProgress() {
|
| 778 |
+
|
| 779 |
+
require(pendingFeedings[msg.sender].blockNumber != 0,"No pending feeding");
|
| 780 |
+
_;
|
| 781 |
+
}
|
| 782 |
+
|
| 783 |
+
|
| 784 |
+
modifier onlyOwnerOf(uint256 tokenId) {
|
| 785 |
+
require(stables.ownerOf(tokenId) == msg.sender, "Caller is not owner of this token");
|
| 786 |
+
_;
|
| 787 |
+
}
|
| 788 |
+
}
|
| 789 |
+
|
| 790 |
+
|
| 791 |
+
|
| 792 |
+
|
| 793 |
+
|
| 794 |
+
contract HorseyPilot {
|
| 795 |
+
|
| 796 |
+
|
| 797 |
+
event NewProposal(uint8 methodId, uint parameter, address proposer);
|
| 798 |
+
|
| 799 |
+
|
| 800 |
+
event ProposalPassed(uint8 methodId, uint parameter, address proposer);
|
| 801 |
+
|
| 802 |
+
|
| 803 |
+
|
| 804 |
+
uint8 constant votingThreshold = 2;
|
| 805 |
+
|
| 806 |
+
|
| 807 |
+
|
| 808 |
+
uint256 constant proposalLife = 7 days;
|
| 809 |
+
|
| 810 |
+
|
| 811 |
+
|
| 812 |
+
uint256 constant proposalCooldown = 1 days;
|
| 813 |
+
|
| 814 |
+
|
| 815 |
+
uint256 cooldownStart;
|
| 816 |
+
|
| 817 |
+
|
| 818 |
+
address public jokerAddress;
|
| 819 |
+
address public knightAddress;
|
| 820 |
+
address public paladinAddress;
|
| 821 |
+
|
| 822 |
+
|
| 823 |
+
address[3] public voters;
|
| 824 |
+
|
| 825 |
+
|
| 826 |
+
uint8 constant public knightEquity = 40;
|
| 827 |
+
uint8 constant public paladinEquity = 10;
|
| 828 |
+
|
| 829 |
+
|
| 830 |
+
address public exchangeAddress;
|
| 831 |
+
address public tokenAddress;
|
| 832 |
+
|
| 833 |
+
|
| 834 |
+
mapping(address => uint) internal _cBalance;
|
| 835 |
+
|
| 836 |
+
|
| 837 |
+
struct Proposal{
|
| 838 |
+
address proposer;
|
| 839 |
+
uint256 timestamp;
|
| 840 |
+
uint256 parameter;
|
| 841 |
+
uint8 methodId;
|
| 842 |
+
address[] yay;
|
| 843 |
+
address[] nay;
|
| 844 |
+
}
|
| 845 |
+
|
| 846 |
+
|
| 847 |
+
Proposal public currentProposal;
|
| 848 |
+
|
| 849 |
+
|
| 850 |
+
bool public proposalInProgress = false;
|
| 851 |
+
|
| 852 |
+
|
| 853 |
+
uint256 public toBeDistributed;
|
| 854 |
+
|
| 855 |
+
|
| 856 |
+
bool deployed = false;
|
| 857 |
+
|
| 858 |
+
|
| 859 |
+
constructor(
|
| 860 |
+
address _jokerAddress,
|
| 861 |
+
address _knightAddress,
|
| 862 |
+
address _paladinAddress,
|
| 863 |
+
address[3] _voters
|
| 864 |
+
) public {
|
| 865 |
+
jokerAddress = _jokerAddress;
|
| 866 |
+
knightAddress = _knightAddress;
|
| 867 |
+
paladinAddress = _paladinAddress;
|
| 868 |
+
|
| 869 |
+
for(uint i = 0; i < 3; i++) {
|
| 870 |
+
voters[i] = _voters[i];
|
| 871 |
+
}
|
| 872 |
+
|
| 873 |
+
|
| 874 |
+
cooldownStart = block.timestamp - proposalCooldown;
|
| 875 |
+
}
|
| 876 |
+
|
| 877 |
+
|
| 878 |
+
function deployChildren(address stablesAddress) external {
|
| 879 |
+
require(!deployed,"already deployed");
|
| 880 |
+
|
| 881 |
+
exchangeAddress = new HorseyExchange();
|
| 882 |
+
tokenAddress = new HorseyToken(stablesAddress);
|
| 883 |
+
|
| 884 |
+
|
| 885 |
+
HorseyExchange(exchangeAddress).setStables(stablesAddress);
|
| 886 |
+
|
| 887 |
+
deployed = true;
|
| 888 |
+
}
|
| 889 |
+
|
| 890 |
+
|
| 891 |
+
function transferJokerOwnership(address newJoker) external
|
| 892 |
+
validAddress(newJoker) {
|
| 893 |
+
require(jokerAddress == msg.sender,"Not right role");
|
| 894 |
+
_moveBalance(newJoker);
|
| 895 |
+
jokerAddress = newJoker;
|
| 896 |
+
}
|
| 897 |
+
|
| 898 |
+
|
| 899 |
+
function transferKnightOwnership(address newKnight) external
|
| 900 |
+
validAddress(newKnight) {
|
| 901 |
+
require(knightAddress == msg.sender,"Not right role");
|
| 902 |
+
_moveBalance(newKnight);
|
| 903 |
+
knightAddress = newKnight;
|
| 904 |
+
}
|
| 905 |
+
|
| 906 |
+
|
| 907 |
+
function transferPaladinOwnership(address newPaladin) external
|
| 908 |
+
validAddress(newPaladin) {
|
| 909 |
+
require(paladinAddress == msg.sender,"Not right role");
|
| 910 |
+
_moveBalance(newPaladin);
|
| 911 |
+
paladinAddress = newPaladin;
|
| 912 |
+
}
|
| 913 |
+
|
| 914 |
+
|
| 915 |
+
function withdrawCeo(address destination) external
|
| 916 |
+
onlyCLevelAccess()
|
| 917 |
+
validAddress(destination) {
|
| 918 |
+
|
| 919 |
+
|
| 920 |
+
if(toBeDistributed > 0){
|
| 921 |
+
_updateDistribution();
|
| 922 |
+
}
|
| 923 |
+
|
| 924 |
+
|
| 925 |
+
uint256 balance = _cBalance[msg.sender];
|
| 926 |
+
|
| 927 |
+
|
| 928 |
+
if(balance > 0 && (address(this).balance >= balance)) {
|
| 929 |
+
destination.transfer(balance);
|
| 930 |
+
_cBalance[msg.sender] = 0;
|
| 931 |
+
}
|
| 932 |
+
}
|
| 933 |
+
|
| 934 |
+
|
| 935 |
+
function syncFunds() external {
|
| 936 |
+
uint256 prevBalance = address(this).balance;
|
| 937 |
+
HorseyToken(tokenAddress).withdraw();
|
| 938 |
+
HorseyExchange(exchangeAddress).withdraw();
|
| 939 |
+
uint256 newBalance = address(this).balance;
|
| 940 |
+
|
| 941 |
+
toBeDistributed = toBeDistributed + (newBalance - prevBalance);
|
| 942 |
+
}
|
| 943 |
+
|
| 944 |
+
|
| 945 |
+
function getNobleBalance() external view
|
| 946 |
+
onlyCLevelAccess() returns (uint256) {
|
| 947 |
+
return _cBalance[msg.sender];
|
| 948 |
+
}
|
| 949 |
+
|
| 950 |
+
|
| 951 |
+
function makeProposal( uint8 methodId, uint256 parameter ) external
|
| 952 |
+
onlyCLevelAccess()
|
| 953 |
+
proposalAvailable()
|
| 954 |
+
cooledDown()
|
| 955 |
+
{
|
| 956 |
+
currentProposal.timestamp = block.timestamp;
|
| 957 |
+
currentProposal.parameter = parameter;
|
| 958 |
+
currentProposal.methodId = methodId;
|
| 959 |
+
currentProposal.proposer = msg.sender;
|
| 960 |
+
delete currentProposal.yay;
|
| 961 |
+
delete currentProposal.nay;
|
| 962 |
+
proposalInProgress = true;
|
| 963 |
+
|
| 964 |
+
emit NewProposal(methodId,parameter,msg.sender);
|
| 965 |
+
}
|
| 966 |
+
|
| 967 |
+
|
| 968 |
+
function voteOnProposal(bool voteFor) external
|
| 969 |
+
proposalPending()
|
| 970 |
+
onlyVoters()
|
| 971 |
+
notVoted() {
|
| 972 |
+
|
| 973 |
+
require((block.timestamp - currentProposal.timestamp) <= proposalLife);
|
| 974 |
+
if(voteFor)
|
| 975 |
+
{
|
| 976 |
+
currentProposal.yay.push(msg.sender);
|
| 977 |
+
|
| 978 |
+
if( currentProposal.yay.length >= votingThreshold )
|
| 979 |
+
{
|
| 980 |
+
_doProposal();
|
| 981 |
+
proposalInProgress = false;
|
| 982 |
+
|
| 983 |
+
return;
|
| 984 |
+
}
|
| 985 |
+
|
| 986 |
+
} else {
|
| 987 |
+
currentProposal.nay.push(msg.sender);
|
| 988 |
+
|
| 989 |
+
if( currentProposal.nay.length >= votingThreshold )
|
| 990 |
+
{
|
| 991 |
+
proposalInProgress = false;
|
| 992 |
+
cooldownStart = block.timestamp;
|
| 993 |
+
return;
|
| 994 |
+
}
|
| 995 |
+
}
|
| 996 |
+
}
|
| 997 |
+
|
| 998 |
+
|
| 999 |
+
function _moveBalance(address newAddress) internal
|
| 1000 |
+
validAddress(newAddress) {
|
| 1001 |
+
require(newAddress != msg.sender);
|
| 1002 |
+
_cBalance[newAddress] = _cBalance[msg.sender];
|
| 1003 |
+
_cBalance[msg.sender] = 0;
|
| 1004 |
+
}
|
| 1005 |
+
|
| 1006 |
+
|
| 1007 |
+
function _updateDistribution() internal {
|
| 1008 |
+
require(toBeDistributed != 0,"nothing to distribute");
|
| 1009 |
+
uint256 knightPayday = toBeDistributed / 100 * knightEquity;
|
| 1010 |
+
uint256 paladinPayday = toBeDistributed / 100 * paladinEquity;
|
| 1011 |
+
|
| 1012 |
+
|
| 1013 |
+
uint256 jokerPayday = toBeDistributed - knightPayday - paladinPayday;
|
| 1014 |
+
|
| 1015 |
+
_cBalance[jokerAddress] = _cBalance[jokerAddress] + jokerPayday;
|
| 1016 |
+
_cBalance[knightAddress] = _cBalance[knightAddress] + knightPayday;
|
| 1017 |
+
_cBalance[paladinAddress] = _cBalance[paladinAddress] + paladinPayday;
|
| 1018 |
+
|
| 1019 |
+
toBeDistributed = 0;
|
| 1020 |
+
}
|
| 1021 |
+
|
| 1022 |
+
|
| 1023 |
+
function _doProposal() internal {
|
| 1024 |
+
|
| 1025 |
+
if( currentProposal.methodId == 0 ) HorseyToken(tokenAddress).setRenamingCosts(currentProposal.parameter);
|
| 1026 |
+
|
| 1027 |
+
|
| 1028 |
+
if( currentProposal.methodId == 1 ) HorseyExchange(exchangeAddress).setMarketFees(currentProposal.parameter);
|
| 1029 |
+
|
| 1030 |
+
|
| 1031 |
+
if( currentProposal.methodId == 2 ) HorseyToken(tokenAddress).addLegitRaceAddress(address(currentProposal.parameter));
|
| 1032 |
+
|
| 1033 |
+
|
| 1034 |
+
if( currentProposal.methodId == 3 ) HorseyToken(tokenAddress).addHorseIndex(bytes32(currentProposal.parameter));
|
| 1035 |
+
|
| 1036 |
+
|
| 1037 |
+
if( currentProposal.methodId == 4 ) {
|
| 1038 |
+
if(currentProposal.parameter == 0) {
|
| 1039 |
+
HorseyExchange(exchangeAddress).unpause();
|
| 1040 |
+
HorseyToken(tokenAddress).unpause();
|
| 1041 |
+
} else {
|
| 1042 |
+
HorseyExchange(exchangeAddress).pause();
|
| 1043 |
+
HorseyToken(tokenAddress).pause();
|
| 1044 |
+
}
|
| 1045 |
+
}
|
| 1046 |
+
|
| 1047 |
+
|
| 1048 |
+
if( currentProposal.methodId == 5 ) HorseyToken(tokenAddress).setClaimingCosts(currentProposal.parameter);
|
| 1049 |
+
|
| 1050 |
+
|
| 1051 |
+
if( currentProposal.methodId == 8 ){
|
| 1052 |
+
HorseyToken(tokenAddress).setCarrotsMultiplier(uint8(currentProposal.parameter));
|
| 1053 |
+
}
|
| 1054 |
+
|
| 1055 |
+
|
| 1056 |
+
if( currentProposal.methodId == 9 ){
|
| 1057 |
+
HorseyToken(tokenAddress).setRarityMultiplier(uint8(currentProposal.parameter));
|
| 1058 |
+
}
|
| 1059 |
+
|
| 1060 |
+
emit ProposalPassed(currentProposal.methodId,currentProposal.parameter,currentProposal.proposer);
|
| 1061 |
+
}
|
| 1062 |
+
|
| 1063 |
+
|
| 1064 |
+
modifier validAddress(address addr) {
|
| 1065 |
+
require(addr != address(0),"Address is zero");
|
| 1066 |
+
_;
|
| 1067 |
+
}
|
| 1068 |
+
|
| 1069 |
+
|
| 1070 |
+
modifier onlyCLevelAccess() {
|
| 1071 |
+
require((jokerAddress == msg.sender) || (knightAddress == msg.sender) || (paladinAddress == msg.sender),"not c level");
|
| 1072 |
+
_;
|
| 1073 |
+
}
|
| 1074 |
+
|
| 1075 |
+
|
| 1076 |
+
|
| 1077 |
+
modifier proposalAvailable(){
|
| 1078 |
+
require(((!proposalInProgress) || ((block.timestamp - currentProposal.timestamp) > proposalLife)),"proposal already pending");
|
| 1079 |
+
_;
|
| 1080 |
+
}
|
| 1081 |
+
|
| 1082 |
+
|
| 1083 |
+
|
| 1084 |
+
modifier cooledDown( ){
|
| 1085 |
+
if(msg.sender == currentProposal.proposer && (block.timestamp - cooldownStart < 1 days)){
|
| 1086 |
+
revert("Cool down period not passed yet");
|
| 1087 |
+
}
|
| 1088 |
+
_;
|
| 1089 |
+
}
|
| 1090 |
+
|
| 1091 |
+
|
| 1092 |
+
modifier proposalPending() {
|
| 1093 |
+
require(proposalInProgress,"no proposal pending");
|
| 1094 |
+
_;
|
| 1095 |
+
}
|
| 1096 |
+
|
| 1097 |
+
|
| 1098 |
+
modifier notVoted() {
|
| 1099 |
+
uint256 length = currentProposal.yay.length;
|
| 1100 |
+
for(uint i = 0; i < length; i++) {
|
| 1101 |
+
if(currentProposal.yay[i] == msg.sender) {
|
| 1102 |
+
revert("Already voted");
|
| 1103 |
+
}
|
| 1104 |
+
}
|
| 1105 |
+
|
| 1106 |
+
length = currentProposal.nay.length;
|
| 1107 |
+
for(i = 0; i < length; i++) {
|
| 1108 |
+
if(currentProposal.nay[i] == msg.sender) {
|
| 1109 |
+
revert("Already voted");
|
| 1110 |
+
}
|
| 1111 |
+
}
|
| 1112 |
+
_;
|
| 1113 |
+
}
|
| 1114 |
+
|
| 1115 |
+
|
| 1116 |
+
modifier onlyVoters() {
|
| 1117 |
+
bool found = false;
|
| 1118 |
+
uint256 length = voters.length;
|
| 1119 |
+
for(uint i = 0; i < length; i++) {
|
| 1120 |
+
if(voters[i] == msg.sender) {
|
| 1121 |
+
found = true;
|
| 1122 |
+
break;
|
| 1123 |
+
}
|
| 1124 |
+
}
|
| 1125 |
+
if(!found) {
|
| 1126 |
+
revert("not a voter");
|
| 1127 |
+
}
|
| 1128 |
+
_;
|
| 1129 |
+
}
|
| 1130 |
+
}
|
smart_contract_dataset/block number dependency/137.sol
ADDED
|
@@ -0,0 +1,1130 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
pragma solidity ^0.4.24;
|
| 2 |
+
|
| 3 |
+
|
| 4 |
+
|
| 5 |
+
|
| 6 |
+
contract Ownable {
|
| 7 |
+
address public owner;
|
| 8 |
+
|
| 9 |
+
|
| 10 |
+
event OwnershipRenounced(address indexed previousOwner);
|
| 11 |
+
event OwnershipTransferred(
|
| 12 |
+
address indexed previousOwner,
|
| 13 |
+
address indexed newOwner
|
| 14 |
+
);
|
| 15 |
+
|
| 16 |
+
|
| 17 |
+
|
| 18 |
+
constructor() public {
|
| 19 |
+
owner = msg.sender;
|
| 20 |
+
}
|
| 21 |
+
|
| 22 |
+
|
| 23 |
+
modifier onlyOwner() {
|
| 24 |
+
require(msg.sender == owner);
|
| 25 |
+
_;
|
| 26 |
+
}
|
| 27 |
+
|
| 28 |
+
|
| 29 |
+
function renounceOwnership() public onlyOwner {
|
| 30 |
+
emit OwnershipRenounced(owner);
|
| 31 |
+
owner = address(0);
|
| 32 |
+
}
|
| 33 |
+
|
| 34 |
+
|
| 35 |
+
function transferOwnership(address _newOwner) public onlyOwner {
|
| 36 |
+
_transferOwnership(_newOwner);
|
| 37 |
+
}
|
| 38 |
+
|
| 39 |
+
|
| 40 |
+
function _transferOwnership(address _newOwner) internal {
|
| 41 |
+
require(_newOwner != address(0));
|
| 42 |
+
emit OwnershipTransferred(owner, _newOwner);
|
| 43 |
+
owner = _newOwner;
|
| 44 |
+
}
|
| 45 |
+
}
|
| 46 |
+
|
| 47 |
+
|
| 48 |
+
|
| 49 |
+
|
| 50 |
+
contract Pausable is Ownable {
|
| 51 |
+
event Pause();
|
| 52 |
+
event Unpause();
|
| 53 |
+
|
| 54 |
+
bool public paused = false;
|
| 55 |
+
|
| 56 |
+
|
| 57 |
+
|
| 58 |
+
modifier whenNotPaused() {
|
| 59 |
+
require(!paused);
|
| 60 |
+
_;
|
| 61 |
+
}
|
| 62 |
+
|
| 63 |
+
|
| 64 |
+
modifier whenPaused() {
|
| 65 |
+
require(paused);
|
| 66 |
+
_;
|
| 67 |
+
}
|
| 68 |
+
|
| 69 |
+
|
| 70 |
+
function pause() public onlyOwner whenNotPaused {
|
| 71 |
+
paused = true;
|
| 72 |
+
emit Pause();
|
| 73 |
+
}
|
| 74 |
+
|
| 75 |
+
|
| 76 |
+
function unpause() public onlyOwner whenPaused {
|
| 77 |
+
paused = false;
|
| 78 |
+
emit Unpause();
|
| 79 |
+
}
|
| 80 |
+
}
|
| 81 |
+
|
| 82 |
+
|
| 83 |
+
|
| 84 |
+
|
| 85 |
+
contract ERC721Receiver {
|
| 86 |
+
|
| 87 |
+
bytes4 internal constant ERC721_RECEIVED = 0x150b7a02;
|
| 88 |
+
|
| 89 |
+
|
| 90 |
+
function onERC721Received(
|
| 91 |
+
address _operator,
|
| 92 |
+
address _from,
|
| 93 |
+
uint256 _tokenId,
|
| 94 |
+
bytes _data
|
| 95 |
+
)
|
| 96 |
+
public
|
| 97 |
+
returns(bytes4);
|
| 98 |
+
}
|
| 99 |
+
|
| 100 |
+
|
| 101 |
+
|
| 102 |
+
contract ERC721Holder is ERC721Receiver {
|
| 103 |
+
function onERC721Received(
|
| 104 |
+
address,
|
| 105 |
+
address,
|
| 106 |
+
uint256,
|
| 107 |
+
bytes
|
| 108 |
+
)
|
| 109 |
+
public
|
| 110 |
+
returns(bytes4)
|
| 111 |
+
{
|
| 112 |
+
return ERC721_RECEIVED;
|
| 113 |
+
}
|
| 114 |
+
}
|
| 115 |
+
|
| 116 |
+
|
| 117 |
+
|
| 118 |
+
|
| 119 |
+
contract ERC721Basic {
|
| 120 |
+
function balanceOf(address _owner) public view returns (uint256 _balance);
|
| 121 |
+
function ownerOf(uint256 _tokenId) public view returns (address _owner);
|
| 122 |
+
function exists(uint256 _tokenId) public view returns (bool _exists);
|
| 123 |
+
|
| 124 |
+
function approve(address _to, uint256 _tokenId) public;
|
| 125 |
+
function getApproved(uint256 _tokenId) public view returns (address _operator);
|
| 126 |
+
|
| 127 |
+
function transferFrom(address _from, address _to, uint256 _tokenId) public;
|
| 128 |
+
}
|
| 129 |
+
|
| 130 |
+
|
| 131 |
+
contract HorseyExchange is Pausable, ERC721Holder {
|
| 132 |
+
|
| 133 |
+
event HorseyDeposit(uint256 tokenId, uint256 price);
|
| 134 |
+
event SaleCanceled(uint256 tokenId);
|
| 135 |
+
event HorseyPurchased(uint256 tokenId, address newOwner, uint256 totalToPay);
|
| 136 |
+
|
| 137 |
+
|
| 138 |
+
uint256 public marketMakerFee = 3;
|
| 139 |
+
|
| 140 |
+
|
| 141 |
+
uint256 collectedFees = 0;
|
| 142 |
+
|
| 143 |
+
|
| 144 |
+
ERC721Basic public token;
|
| 145 |
+
|
| 146 |
+
|
| 147 |
+
struct SaleData {
|
| 148 |
+
uint256 price;
|
| 149 |
+
address owner;
|
| 150 |
+
}
|
| 151 |
+
|
| 152 |
+
|
| 153 |
+
mapping (uint256 => SaleData) market;
|
| 154 |
+
|
| 155 |
+
|
| 156 |
+
mapping (address => uint256[]) userBarn;
|
| 157 |
+
|
| 158 |
+
|
| 159 |
+
constructor() Pausable() ERC721Holder() public {
|
| 160 |
+
}
|
| 161 |
+
|
| 162 |
+
|
| 163 |
+
function setStables(address _token) external
|
| 164 |
+
onlyOwner()
|
| 165 |
+
{
|
| 166 |
+
require(address(_token) != 0,"Address of token is zero");
|
| 167 |
+
token = ERC721Basic(_token);
|
| 168 |
+
}
|
| 169 |
+
|
| 170 |
+
|
| 171 |
+
function setMarketFees(uint256 fees) external
|
| 172 |
+
onlyOwner()
|
| 173 |
+
{
|
| 174 |
+
marketMakerFee = fees;
|
| 175 |
+
}
|
| 176 |
+
|
| 177 |
+
|
| 178 |
+
function getTokensOnSale(address user) external view returns(uint256[]) {
|
| 179 |
+
return userBarn[user];
|
| 180 |
+
}
|
| 181 |
+
|
| 182 |
+
|
| 183 |
+
function getTokenPrice(uint256 tokenId) public view
|
| 184 |
+
isOnMarket(tokenId) returns (uint256) {
|
| 185 |
+
return market[tokenId].price + (market[tokenId].price / 100 * marketMakerFee);
|
| 186 |
+
}
|
| 187 |
+
|
| 188 |
+
|
| 189 |
+
function depositToExchange(uint256 tokenId, uint256 price) external
|
| 190 |
+
whenNotPaused()
|
| 191 |
+
isTokenOwner(tokenId)
|
| 192 |
+
nonZeroPrice(price)
|
| 193 |
+
tokenAvailable() {
|
| 194 |
+
require(token.getApproved(tokenId) == address(this),"Exchange is not allowed to transfer");
|
| 195 |
+
|
| 196 |
+
token.transferFrom(msg.sender, address(this), tokenId);
|
| 197 |
+
|
| 198 |
+
|
| 199 |
+
market[tokenId] = SaleData(price,msg.sender);
|
| 200 |
+
|
| 201 |
+
|
| 202 |
+
userBarn[msg.sender].push(tokenId);
|
| 203 |
+
|
| 204 |
+
emit HorseyDeposit(tokenId, price);
|
| 205 |
+
}
|
| 206 |
+
|
| 207 |
+
|
| 208 |
+
function cancelSale(uint256 tokenId) external
|
| 209 |
+
whenNotPaused()
|
| 210 |
+
originalOwnerOf(tokenId)
|
| 211 |
+
tokenAvailable() returns (bool) {
|
| 212 |
+
|
| 213 |
+
token.transferFrom(address(this),msg.sender,tokenId);
|
| 214 |
+
|
| 215 |
+
|
| 216 |
+
delete market[tokenId];
|
| 217 |
+
|
| 218 |
+
|
| 219 |
+
_removeTokenFromBarn(tokenId, msg.sender);
|
| 220 |
+
|
| 221 |
+
emit SaleCanceled(tokenId);
|
| 222 |
+
|
| 223 |
+
|
| 224 |
+
|
| 225 |
+
return userBarn[msg.sender].length > 0;
|
| 226 |
+
}
|
| 227 |
+
|
| 228 |
+
|
| 229 |
+
function purchaseToken(uint256 tokenId) external payable
|
| 230 |
+
whenNotPaused()
|
| 231 |
+
isOnMarket(tokenId)
|
| 232 |
+
tokenAvailable()
|
| 233 |
+
notOriginalOwnerOf(tokenId)
|
| 234 |
+
{
|
| 235 |
+
|
| 236 |
+
uint256 totalToPay = getTokenPrice(tokenId);
|
| 237 |
+
require(msg.value >= totalToPay, "Not paying enough");
|
| 238 |
+
|
| 239 |
+
|
| 240 |
+
SaleData memory sale = market[tokenId];
|
| 241 |
+
|
| 242 |
+
|
| 243 |
+
collectedFees += totalToPay - sale.price;
|
| 244 |
+
|
| 245 |
+
|
| 246 |
+
sale.owner.transfer(sale.price);
|
| 247 |
+
|
| 248 |
+
|
| 249 |
+
_removeTokenFromBarn(tokenId, sale.owner);
|
| 250 |
+
|
| 251 |
+
|
| 252 |
+
delete market[tokenId];
|
| 253 |
+
|
| 254 |
+
|
| 255 |
+
|
| 256 |
+
token.transferFrom(address(this), msg.sender, tokenId);
|
| 257 |
+
|
| 258 |
+
|
| 259 |
+
if(msg.value > totalToPay)
|
| 260 |
+
{
|
| 261 |
+
msg.sender.transfer(msg.value - totalToPay);
|
| 262 |
+
}
|
| 263 |
+
|
| 264 |
+
emit HorseyPurchased(tokenId, msg.sender, totalToPay);
|
| 265 |
+
}
|
| 266 |
+
|
| 267 |
+
|
| 268 |
+
function withdraw() external
|
| 269 |
+
onlyOwner()
|
| 270 |
+
{
|
| 271 |
+
assert(collectedFees <= address(this).balance);
|
| 272 |
+
owner.transfer(collectedFees);
|
| 273 |
+
collectedFees = 0;
|
| 274 |
+
}
|
| 275 |
+
|
| 276 |
+
|
| 277 |
+
function _removeTokenFromBarn(uint tokenId, address barnAddress) internal {
|
| 278 |
+
uint256[] storage barnArray = userBarn[barnAddress];
|
| 279 |
+
require(barnArray.length > 0,"No tokens to remove");
|
| 280 |
+
int index = _indexOf(tokenId, barnArray);
|
| 281 |
+
require(index >= 0, "Token not found in barn");
|
| 282 |
+
|
| 283 |
+
|
| 284 |
+
for (uint256 i = uint256(index); i<barnArray.length-1; i++){
|
| 285 |
+
barnArray[i] = barnArray[i+1];
|
| 286 |
+
}
|
| 287 |
+
|
| 288 |
+
|
| 289 |
+
|
| 290 |
+
barnArray.length--;
|
| 291 |
+
}
|
| 292 |
+
|
| 293 |
+
|
| 294 |
+
function _indexOf(uint item, uint256[] memory array) internal pure returns (int256){
|
| 295 |
+
|
| 296 |
+
|
| 297 |
+
for(uint256 i = 0; i < array.length; i++){
|
| 298 |
+
if(array[i] == item){
|
| 299 |
+
return int256(i);
|
| 300 |
+
}
|
| 301 |
+
}
|
| 302 |
+
|
| 303 |
+
|
| 304 |
+
return -1;
|
| 305 |
+
}
|
| 306 |
+
|
| 307 |
+
|
| 308 |
+
modifier isOnMarket(uint256 tokenId) {
|
| 309 |
+
require(token.ownerOf(tokenId) == address(this),"Token not on market");
|
| 310 |
+
_;
|
| 311 |
+
}
|
| 312 |
+
|
| 313 |
+
|
| 314 |
+
modifier isTokenOwner(uint256 tokenId) {
|
| 315 |
+
require(token.ownerOf(tokenId) == msg.sender,"Not tokens owner");
|
| 316 |
+
_;
|
| 317 |
+
}
|
| 318 |
+
|
| 319 |
+
|
| 320 |
+
modifier originalOwnerOf(uint256 tokenId) {
|
| 321 |
+
require(market[tokenId].owner == msg.sender,"Not the original owner of");
|
| 322 |
+
_;
|
| 323 |
+
}
|
| 324 |
+
|
| 325 |
+
|
| 326 |
+
modifier notOriginalOwnerOf(uint256 tokenId) {
|
| 327 |
+
require(market[tokenId].owner != msg.sender,"Is the original owner");
|
| 328 |
+
_;
|
| 329 |
+
}
|
| 330 |
+
|
| 331 |
+
|
| 332 |
+
modifier nonZeroPrice(uint256 price){
|
| 333 |
+
require(price > 0,"Price is zero");
|
| 334 |
+
_;
|
| 335 |
+
}
|
| 336 |
+
|
| 337 |
+
|
| 338 |
+
modifier tokenAvailable(){
|
| 339 |
+
require(address(token) != 0,"Token address not set");
|
| 340 |
+
_;
|
| 341 |
+
}
|
| 342 |
+
}
|
| 343 |
+
|
| 344 |
+
|
| 345 |
+
|
| 346 |
+
|
| 347 |
+
contract EthorseRace {
|
| 348 |
+
|
| 349 |
+
|
| 350 |
+
struct chronus_info {
|
| 351 |
+
bool betting_open;
|
| 352 |
+
bool race_start;
|
| 353 |
+
bool race_end;
|
| 354 |
+
bool voided_bet;
|
| 355 |
+
uint32 starting_time;
|
| 356 |
+
uint32 betting_duration;
|
| 357 |
+
uint32 race_duration;
|
| 358 |
+
uint32 voided_timestamp;
|
| 359 |
+
}
|
| 360 |
+
|
| 361 |
+
address public owner;
|
| 362 |
+
|
| 363 |
+
|
| 364 |
+
chronus_info public chronus;
|
| 365 |
+
|
| 366 |
+
|
| 367 |
+
mapping (bytes32 => bool) public winner_horse;
|
| 368 |
+
|
| 369 |
+
|
| 370 |
+
function getCoinIndex(bytes32 index, address candidate) external constant returns (uint, uint, uint, bool, uint);
|
| 371 |
+
}
|
| 372 |
+
|
| 373 |
+
|
| 374 |
+
contract EthorseHelpers {
|
| 375 |
+
|
| 376 |
+
|
| 377 |
+
bytes32[] public all_horses = [bytes32("BTC"),bytes32("ETH"),bytes32("LTC")];
|
| 378 |
+
mapping(address => bool) public legitRaces;
|
| 379 |
+
bool onlyLegit = false;
|
| 380 |
+
|
| 381 |
+
|
| 382 |
+
function _addHorse(bytes32 newHorse) internal {
|
| 383 |
+
all_horses.push(newHorse);
|
| 384 |
+
}
|
| 385 |
+
|
| 386 |
+
function _addLegitRace(address newRace) internal
|
| 387 |
+
{
|
| 388 |
+
legitRaces[newRace] = true;
|
| 389 |
+
if(!onlyLegit)
|
| 390 |
+
onlyLegit = true;
|
| 391 |
+
}
|
| 392 |
+
|
| 393 |
+
function getall_horsesCount() public view returns(uint) {
|
| 394 |
+
return all_horses.length;
|
| 395 |
+
}
|
| 396 |
+
|
| 397 |
+
|
| 398 |
+
function _isWinnerOf(address raceAddress, address eth_address) internal view returns (bool,bytes32)
|
| 399 |
+
{
|
| 400 |
+
|
| 401 |
+
EthorseRace race = EthorseRace(raceAddress);
|
| 402 |
+
|
| 403 |
+
|
| 404 |
+
if(onlyLegit)
|
| 405 |
+
require(legitRaces[raceAddress],"not legit race");
|
| 406 |
+
|
| 407 |
+
bool voided_bet;
|
| 408 |
+
bool race_end;
|
| 409 |
+
(,,race_end,voided_bet,,,,) = race.chronus();
|
| 410 |
+
|
| 411 |
+
|
| 412 |
+
if(voided_bet || !race_end)
|
| 413 |
+
return (false,bytes32(0));
|
| 414 |
+
|
| 415 |
+
|
| 416 |
+
bytes32 horse;
|
| 417 |
+
bool found = false;
|
| 418 |
+
uint256 arrayLength = all_horses.length;
|
| 419 |
+
|
| 420 |
+
|
| 421 |
+
for(uint256 i = 0; i < arrayLength; i++)
|
| 422 |
+
{
|
| 423 |
+
if(race.winner_horse(all_horses[i])) {
|
| 424 |
+
horse = all_horses[i];
|
| 425 |
+
found = true;
|
| 426 |
+
break;
|
| 427 |
+
}
|
| 428 |
+
}
|
| 429 |
+
|
| 430 |
+
if(!found)
|
| 431 |
+
return (false,bytes32(0));
|
| 432 |
+
|
| 433 |
+
|
| 434 |
+
uint256 bet_amount = 0;
|
| 435 |
+
(,,,, bet_amount) = race.getCoinIndex(horse, eth_address);
|
| 436 |
+
|
| 437 |
+
|
| 438 |
+
return (bet_amount > 0, horse);
|
| 439 |
+
}
|
| 440 |
+
}
|
| 441 |
+
|
| 442 |
+
|
| 443 |
+
|
| 444 |
+
contract RoyalStablesInterface {
|
| 445 |
+
|
| 446 |
+
struct Horsey {
|
| 447 |
+
address race;
|
| 448 |
+
bytes32 dna;
|
| 449 |
+
uint8 feedingCounter;
|
| 450 |
+
uint8 tier;
|
| 451 |
+
}
|
| 452 |
+
|
| 453 |
+
mapping(uint256 => Horsey) public horseys;
|
| 454 |
+
mapping(address => uint32) public carrot_credits;
|
| 455 |
+
mapping(uint256 => string) public names;
|
| 456 |
+
address public master;
|
| 457 |
+
|
| 458 |
+
function getOwnedTokens(address eth_address) public view returns (uint256[]);
|
| 459 |
+
function storeName(uint256 tokenId, string newName) public;
|
| 460 |
+
function storeCarrotsCredit(address client, uint32 amount) public;
|
| 461 |
+
function storeHorsey(address client, uint256 tokenId, address race, bytes32 dna, uint8 feedingCounter, uint8 tier) public;
|
| 462 |
+
function modifyHorsey(uint256 tokenId, address race, bytes32 dna, uint8 feedingCounter, uint8 tier) public;
|
| 463 |
+
function modifyHorseyDna(uint256 tokenId, bytes32 dna) public;
|
| 464 |
+
function modifyHorseyFeedingCounter(uint256 tokenId, uint8 feedingCounter) public;
|
| 465 |
+
function modifyHorseyTier(uint256 tokenId, uint8 tier) public;
|
| 466 |
+
function unstoreHorsey(uint256 tokenId) public;
|
| 467 |
+
function ownerOf(uint256 tokenId) public returns (address);
|
| 468 |
+
}
|
| 469 |
+
|
| 470 |
+
|
| 471 |
+
contract HorseyToken is EthorseHelpers,Pausable {
|
| 472 |
+
|
| 473 |
+
|
| 474 |
+
event Claimed(address raceAddress, address eth_address, uint256 tokenId);
|
| 475 |
+
|
| 476 |
+
|
| 477 |
+
event Feeding(uint256 tokenId);
|
| 478 |
+
|
| 479 |
+
|
| 480 |
+
event ReceivedCarrot(uint256 tokenId, bytes32 newDna);
|
| 481 |
+
|
| 482 |
+
|
| 483 |
+
event FeedingFailed(uint256 tokenId);
|
| 484 |
+
|
| 485 |
+
|
| 486 |
+
event HorseyRenamed(uint256 tokenId, string newName);
|
| 487 |
+
|
| 488 |
+
|
| 489 |
+
event HorseyFreed(uint256 tokenId);
|
| 490 |
+
|
| 491 |
+
|
| 492 |
+
RoyalStablesInterface public stables;
|
| 493 |
+
|
| 494 |
+
|
| 495 |
+
uint8 public carrotsMultiplier = 1;
|
| 496 |
+
|
| 497 |
+
|
| 498 |
+
uint8 public rarityMultiplier = 1;
|
| 499 |
+
|
| 500 |
+
|
| 501 |
+
uint256 public claimingFee = 0.000 ether;
|
| 502 |
+
|
| 503 |
+
|
| 504 |
+
struct FeedingData {
|
| 505 |
+
uint256 blockNumber;
|
| 506 |
+
uint256 horsey;
|
| 507 |
+
}
|
| 508 |
+
|
| 509 |
+
|
| 510 |
+
mapping(address => FeedingData) public pendingFeedings;
|
| 511 |
+
|
| 512 |
+
|
| 513 |
+
uint256 public renamingCostsPerChar = 0.001 ether;
|
| 514 |
+
|
| 515 |
+
|
| 516 |
+
constructor(address stablesAddress)
|
| 517 |
+
EthorseHelpers()
|
| 518 |
+
Pausable() public {
|
| 519 |
+
stables = RoyalStablesInterface(stablesAddress);
|
| 520 |
+
}
|
| 521 |
+
|
| 522 |
+
|
| 523 |
+
function setRarityMultiplier(uint8 newRarityMultiplier) external
|
| 524 |
+
onlyOwner() {
|
| 525 |
+
rarityMultiplier = newRarityMultiplier;
|
| 526 |
+
}
|
| 527 |
+
|
| 528 |
+
|
| 529 |
+
function setCarrotsMultiplier(uint8 newCarrotsMultiplier) external
|
| 530 |
+
onlyOwner() {
|
| 531 |
+
carrotsMultiplier = newCarrotsMultiplier;
|
| 532 |
+
}
|
| 533 |
+
|
| 534 |
+
|
| 535 |
+
function setRenamingCosts(uint256 newRenamingCost) external
|
| 536 |
+
onlyOwner() {
|
| 537 |
+
renamingCostsPerChar = newRenamingCost;
|
| 538 |
+
}
|
| 539 |
+
|
| 540 |
+
|
| 541 |
+
function setClaimingCosts(uint256 newClaimingFee) external
|
| 542 |
+
onlyOwner() {
|
| 543 |
+
claimingFee = newClaimingFee;
|
| 544 |
+
}
|
| 545 |
+
|
| 546 |
+
|
| 547 |
+
function addLegitRaceAddress(address newAddress) external
|
| 548 |
+
onlyOwner() {
|
| 549 |
+
_addLegitRace(newAddress);
|
| 550 |
+
}
|
| 551 |
+
|
| 552 |
+
|
| 553 |
+
function withdraw() external
|
| 554 |
+
onlyOwner() {
|
| 555 |
+
owner.transfer(address(this).balance);
|
| 556 |
+
}
|
| 557 |
+
|
| 558 |
+
|
| 559 |
+
|
| 560 |
+
function addHorseIndex(bytes32 newHorse) external
|
| 561 |
+
onlyOwner() {
|
| 562 |
+
_addHorse(newHorse);
|
| 563 |
+
}
|
| 564 |
+
|
| 565 |
+
|
| 566 |
+
function getOwnedTokens(address eth_address) public view returns (uint256[]) {
|
| 567 |
+
return stables.getOwnedTokens(eth_address);
|
| 568 |
+
}
|
| 569 |
+
|
| 570 |
+
|
| 571 |
+
function can_claim(address raceAddress, address eth_address) public view returns (bool) {
|
| 572 |
+
bool res;
|
| 573 |
+
(res,) = _isWinnerOf(raceAddress, eth_address);
|
| 574 |
+
return res;
|
| 575 |
+
}
|
| 576 |
+
|
| 577 |
+
|
| 578 |
+
function claim(address raceAddress) external payable
|
| 579 |
+
costs(claimingFee)
|
| 580 |
+
whenNotPaused()
|
| 581 |
+
{
|
| 582 |
+
|
| 583 |
+
bytes32 winner;
|
| 584 |
+
bool res;
|
| 585 |
+
(res,winner) = _isWinnerOf(raceAddress, msg.sender);
|
| 586 |
+
require(winner != bytes32(0),"Winner is zero");
|
| 587 |
+
require(res,"can_claim return false");
|
| 588 |
+
|
| 589 |
+
uint256 id = _generate_special_horsey(raceAddress, msg.sender, winner);
|
| 590 |
+
emit Claimed(raceAddress, msg.sender, id);
|
| 591 |
+
}
|
| 592 |
+
|
| 593 |
+
|
| 594 |
+
function renameHorsey(uint256 tokenId, string newName) external
|
| 595 |
+
whenNotPaused()
|
| 596 |
+
onlyOwnerOf(tokenId)
|
| 597 |
+
costs(renamingCostsPerChar * bytes(newName).length)
|
| 598 |
+
payable {
|
| 599 |
+
uint256 renamingFee = renamingCostsPerChar * bytes(newName).length;
|
| 600 |
+
|
| 601 |
+
if(msg.value > renamingFee)
|
| 602 |
+
{
|
| 603 |
+
msg.sender.transfer(msg.value - renamingFee);
|
| 604 |
+
}
|
| 605 |
+
|
| 606 |
+
stables.storeName(tokenId,newName);
|
| 607 |
+
emit HorseyRenamed(tokenId,newName);
|
| 608 |
+
}
|
| 609 |
+
|
| 610 |
+
|
| 611 |
+
function freeForCarrots(uint256 tokenId) external
|
| 612 |
+
whenNotPaused()
|
| 613 |
+
onlyOwnerOf(tokenId) {
|
| 614 |
+
require(pendingFeedings[msg.sender].horsey != tokenId,"");
|
| 615 |
+
|
| 616 |
+
uint8 feedingCounter;
|
| 617 |
+
(,,feedingCounter,) = stables.horseys(tokenId);
|
| 618 |
+
stables.storeCarrotsCredit(msg.sender,stables.carrot_credits(msg.sender) + uint32(feedingCounter * carrotsMultiplier));
|
| 619 |
+
stables.unstoreHorsey(tokenId);
|
| 620 |
+
emit HorseyFreed(tokenId);
|
| 621 |
+
}
|
| 622 |
+
|
| 623 |
+
|
| 624 |
+
function getCarrotCredits() external view returns (uint32) {
|
| 625 |
+
return stables.carrot_credits(msg.sender);
|
| 626 |
+
}
|
| 627 |
+
|
| 628 |
+
|
| 629 |
+
function getHorsey(uint256 tokenId) public view returns (address, bytes32, uint8, string) {
|
| 630 |
+
RoyalStablesInterface.Horsey memory temp;
|
| 631 |
+
(temp.race,temp.dna,temp.feedingCounter,temp.tier) = stables.horseys(tokenId);
|
| 632 |
+
return (temp.race,temp.dna,temp.feedingCounter,stables.names(tokenId));
|
| 633 |
+
}
|
| 634 |
+
|
| 635 |
+
|
| 636 |
+
function feed(uint256 tokenId) external
|
| 637 |
+
whenNotPaused()
|
| 638 |
+
onlyOwnerOf(tokenId)
|
| 639 |
+
carrotsMeetLevel(tokenId)
|
| 640 |
+
noFeedingInProgress()
|
| 641 |
+
{
|
| 642 |
+
pendingFeedings[msg.sender] = FeedingData(block.number,tokenId);
|
| 643 |
+
uint8 feedingCounter;
|
| 644 |
+
(,,feedingCounter,) = stables.horseys(tokenId);
|
| 645 |
+
stables.storeCarrotsCredit(msg.sender,stables.carrot_credits(msg.sender) - uint32(feedingCounter));
|
| 646 |
+
emit Feeding(tokenId);
|
| 647 |
+
}
|
| 648 |
+
|
| 649 |
+
|
| 650 |
+
function stopFeeding() external
|
| 651 |
+
feedingInProgress() returns (bool) {
|
| 652 |
+
uint256 blockNumber = pendingFeedings[msg.sender].blockNumber;
|
| 653 |
+
uint256 tokenId = pendingFeedings[msg.sender].horsey;
|
| 654 |
+
|
| 655 |
+
require(block.number - blockNumber >= 1,"feeding and stop feeding are in same block");
|
| 656 |
+
|
| 657 |
+
delete pendingFeedings[msg.sender];
|
| 658 |
+
|
| 659 |
+
|
| 660 |
+
|
| 661 |
+
if(block.number - blockNumber > 255) {
|
| 662 |
+
|
| 663 |
+
|
| 664 |
+
emit FeedingFailed(tokenId);
|
| 665 |
+
return false;
|
| 666 |
+
}
|
| 667 |
+
|
| 668 |
+
|
| 669 |
+
if(stables.ownerOf(tokenId) != msg.sender) {
|
| 670 |
+
|
| 671 |
+
|
| 672 |
+
emit FeedingFailed(tokenId);
|
| 673 |
+
return false;
|
| 674 |
+
}
|
| 675 |
+
|
| 676 |
+
|
| 677 |
+
_feed(tokenId, blockhash(blockNumber));
|
| 678 |
+
bytes32 dna;
|
| 679 |
+
(,dna,,) = stables.horseys(tokenId);
|
| 680 |
+
emit ReceivedCarrot(tokenId, dna);
|
| 681 |
+
return true;
|
| 682 |
+
}
|
| 683 |
+
|
| 684 |
+
|
| 685 |
+
function() external payable {
|
| 686 |
+
revert("Not accepting donations");
|
| 687 |
+
}
|
| 688 |
+
|
| 689 |
+
|
| 690 |
+
function _feed(uint256 tokenId, bytes32 blockHash) internal {
|
| 691 |
+
|
| 692 |
+
uint8 tier;
|
| 693 |
+
uint8 feedingCounter;
|
| 694 |
+
(,,feedingCounter,tier) = stables.horseys(tokenId);
|
| 695 |
+
uint256 probabilityByRarity = 10 ** uint256(tier + 1);
|
| 696 |
+
uint256 randNum = uint256(keccak256(abi.encodePacked(tokenId, blockHash))) % probabilityByRarity;
|
| 697 |
+
|
| 698 |
+
|
| 699 |
+
if(randNum <= (feedingCounter * rarityMultiplier)){
|
| 700 |
+
_increaseRarity(tokenId, blockHash);
|
| 701 |
+
}
|
| 702 |
+
|
| 703 |
+
|
| 704 |
+
|
| 705 |
+
if(feedingCounter < 255) {
|
| 706 |
+
stables.modifyHorseyFeedingCounter(tokenId,feedingCounter+1);
|
| 707 |
+
}
|
| 708 |
+
}
|
| 709 |
+
|
| 710 |
+
|
| 711 |
+
function _makeSpecialId(address race, address sender, bytes32 coinIndex) internal pure returns (uint256) {
|
| 712 |
+
return uint256(keccak256(abi.encodePacked(race, sender, coinIndex)));
|
| 713 |
+
}
|
| 714 |
+
|
| 715 |
+
|
| 716 |
+
function _generate_special_horsey(address race, address eth_address, bytes32 coinIndex) internal returns (uint256) {
|
| 717 |
+
uint256 id = _makeSpecialId(race, eth_address, coinIndex);
|
| 718 |
+
|
| 719 |
+
bytes32 dna = _shiftRight(keccak256(abi.encodePacked(race, coinIndex)),16);
|
| 720 |
+
|
| 721 |
+
stables.storeHorsey(eth_address,id,race,dna,1,0);
|
| 722 |
+
return id;
|
| 723 |
+
}
|
| 724 |
+
|
| 725 |
+
|
| 726 |
+
function _increaseRarity(uint256 tokenId, bytes32 blockHash) private {
|
| 727 |
+
uint8 tier;
|
| 728 |
+
bytes32 dna;
|
| 729 |
+
(,dna,,tier) = stables.horseys(tokenId);
|
| 730 |
+
if(tier < 254)
|
| 731 |
+
stables.modifyHorseyTier(tokenId,tier+1);
|
| 732 |
+
uint256 random = uint256(keccak256(abi.encodePacked(tokenId, blockHash)));
|
| 733 |
+
|
| 734 |
+
bytes32 rarityMask = _shiftLeft(bytes32(1), (random % 16 + 240));
|
| 735 |
+
bytes32 newdna = dna | rarityMask;
|
| 736 |
+
stables.modifyHorseyDna(tokenId,newdna);
|
| 737 |
+
}
|
| 738 |
+
|
| 739 |
+
|
| 740 |
+
function _shiftLeft(bytes32 data, uint n) internal pure returns (bytes32) {
|
| 741 |
+
return bytes32(uint256(data)*(2 ** n));
|
| 742 |
+
}
|
| 743 |
+
|
| 744 |
+
|
| 745 |
+
function _shiftRight(bytes32 data, uint n) internal pure returns (bytes32) {
|
| 746 |
+
return bytes32(uint256(data)/(2 ** n));
|
| 747 |
+
}
|
| 748 |
+
|
| 749 |
+
|
| 750 |
+
modifier carrotsMeetLevel(uint256 tokenId){
|
| 751 |
+
uint256 feedingCounter;
|
| 752 |
+
(,,feedingCounter,) = stables.horseys(tokenId);
|
| 753 |
+
require(feedingCounter <= stables.carrot_credits(msg.sender),"Not enough carrots");
|
| 754 |
+
_;
|
| 755 |
+
}
|
| 756 |
+
|
| 757 |
+
|
| 758 |
+
modifier costs(uint256 amount) {
|
| 759 |
+
require(msg.value >= amount,"Not enough funds");
|
| 760 |
+
_;
|
| 761 |
+
}
|
| 762 |
+
|
| 763 |
+
|
| 764 |
+
modifier validAddress(address addr) {
|
| 765 |
+
require(addr != address(0),"Address is zero");
|
| 766 |
+
_;
|
| 767 |
+
}
|
| 768 |
+
|
| 769 |
+
|
| 770 |
+
modifier noFeedingInProgress() {
|
| 771 |
+
|
| 772 |
+
require(pendingFeedings[msg.sender].blockNumber == 0,"Already feeding");
|
| 773 |
+
_;
|
| 774 |
+
}
|
| 775 |
+
|
| 776 |
+
|
| 777 |
+
modifier feedingInProgress() {
|
| 778 |
+
|
| 779 |
+
require(pendingFeedings[msg.sender].blockNumber != 0,"No pending feeding");
|
| 780 |
+
_;
|
| 781 |
+
}
|
| 782 |
+
|
| 783 |
+
|
| 784 |
+
modifier onlyOwnerOf(uint256 tokenId) {
|
| 785 |
+
require(stables.ownerOf(tokenId) == msg.sender, "Caller is not owner of this token");
|
| 786 |
+
_;
|
| 787 |
+
}
|
| 788 |
+
}
|
| 789 |
+
|
| 790 |
+
|
| 791 |
+
|
| 792 |
+
|
| 793 |
+
|
| 794 |
+
contract HorseyPilot {
|
| 795 |
+
|
| 796 |
+
|
| 797 |
+
event NewProposal(uint8 methodId, uint parameter, address proposer);
|
| 798 |
+
|
| 799 |
+
|
| 800 |
+
event ProposalPassed(uint8 methodId, uint parameter, address proposer);
|
| 801 |
+
|
| 802 |
+
|
| 803 |
+
|
| 804 |
+
uint8 constant votingThreshold = 2;
|
| 805 |
+
|
| 806 |
+
|
| 807 |
+
|
| 808 |
+
uint256 constant proposalLife = 7 days;
|
| 809 |
+
|
| 810 |
+
|
| 811 |
+
|
| 812 |
+
uint256 constant proposalCooldown = 1 days;
|
| 813 |
+
|
| 814 |
+
|
| 815 |
+
uint256 cooldownStart;
|
| 816 |
+
|
| 817 |
+
|
| 818 |
+
address public jokerAddress;
|
| 819 |
+
address public knightAddress;
|
| 820 |
+
address public paladinAddress;
|
| 821 |
+
|
| 822 |
+
|
| 823 |
+
address[3] public voters;
|
| 824 |
+
|
| 825 |
+
|
| 826 |
+
uint8 constant public knightEquity = 40;
|
| 827 |
+
uint8 constant public paladinEquity = 10;
|
| 828 |
+
|
| 829 |
+
|
| 830 |
+
address public exchangeAddress;
|
| 831 |
+
address public tokenAddress;
|
| 832 |
+
|
| 833 |
+
|
| 834 |
+
mapping(address => uint) internal _cBalance;
|
| 835 |
+
|
| 836 |
+
|
| 837 |
+
struct Proposal{
|
| 838 |
+
address proposer;
|
| 839 |
+
uint256 timestamp;
|
| 840 |
+
uint256 parameter;
|
| 841 |
+
uint8 methodId;
|
| 842 |
+
address[] yay;
|
| 843 |
+
address[] nay;
|
| 844 |
+
}
|
| 845 |
+
|
| 846 |
+
|
| 847 |
+
Proposal public currentProposal;
|
| 848 |
+
|
| 849 |
+
|
| 850 |
+
bool public proposalInProgress = false;
|
| 851 |
+
|
| 852 |
+
|
| 853 |
+
uint256 public toBeDistributed;
|
| 854 |
+
|
| 855 |
+
|
| 856 |
+
bool deployed = false;
|
| 857 |
+
|
| 858 |
+
|
| 859 |
+
constructor(
|
| 860 |
+
address _jokerAddress,
|
| 861 |
+
address _knightAddress,
|
| 862 |
+
address _paladinAddress,
|
| 863 |
+
address[3] _voters
|
| 864 |
+
) public {
|
| 865 |
+
jokerAddress = _jokerAddress;
|
| 866 |
+
knightAddress = _knightAddress;
|
| 867 |
+
paladinAddress = _paladinAddress;
|
| 868 |
+
|
| 869 |
+
for(uint i = 0; i < 3; i++) {
|
| 870 |
+
voters[i] = _voters[i];
|
| 871 |
+
}
|
| 872 |
+
|
| 873 |
+
|
| 874 |
+
cooldownStart = block.timestamp - proposalCooldown;
|
| 875 |
+
}
|
| 876 |
+
|
| 877 |
+
|
| 878 |
+
function deployChildren(address stablesAddress) external {
|
| 879 |
+
require(!deployed,"already deployed");
|
| 880 |
+
|
| 881 |
+
exchangeAddress = new HorseyExchange();
|
| 882 |
+
tokenAddress = new HorseyToken(stablesAddress);
|
| 883 |
+
|
| 884 |
+
|
| 885 |
+
HorseyExchange(exchangeAddress).setStables(stablesAddress);
|
| 886 |
+
|
| 887 |
+
deployed = true;
|
| 888 |
+
}
|
| 889 |
+
|
| 890 |
+
|
| 891 |
+
function transferJokerOwnership(address newJoker) external
|
| 892 |
+
validAddress(newJoker) {
|
| 893 |
+
require(jokerAddress == msg.sender,"Not right role");
|
| 894 |
+
_moveBalance(newJoker);
|
| 895 |
+
jokerAddress = newJoker;
|
| 896 |
+
}
|
| 897 |
+
|
| 898 |
+
|
| 899 |
+
function transferKnightOwnership(address newKnight) external
|
| 900 |
+
validAddress(newKnight) {
|
| 901 |
+
require(knightAddress == msg.sender,"Not right role");
|
| 902 |
+
_moveBalance(newKnight);
|
| 903 |
+
knightAddress = newKnight;
|
| 904 |
+
}
|
| 905 |
+
|
| 906 |
+
|
| 907 |
+
function transferPaladinOwnership(address newPaladin) external
|
| 908 |
+
validAddress(newPaladin) {
|
| 909 |
+
require(paladinAddress == msg.sender,"Not right role");
|
| 910 |
+
_moveBalance(newPaladin);
|
| 911 |
+
paladinAddress = newPaladin;
|
| 912 |
+
}
|
| 913 |
+
|
| 914 |
+
|
| 915 |
+
function withdrawCeo(address destination) external
|
| 916 |
+
onlyCLevelAccess()
|
| 917 |
+
validAddress(destination) {
|
| 918 |
+
|
| 919 |
+
|
| 920 |
+
if(toBeDistributed > 0){
|
| 921 |
+
_updateDistribution();
|
| 922 |
+
}
|
| 923 |
+
|
| 924 |
+
|
| 925 |
+
uint256 balance = _cBalance[msg.sender];
|
| 926 |
+
|
| 927 |
+
|
| 928 |
+
if(balance > 0 && (address(this).balance >= balance)) {
|
| 929 |
+
destination.transfer(balance);
|
| 930 |
+
_cBalance[msg.sender] = 0;
|
| 931 |
+
}
|
| 932 |
+
}
|
| 933 |
+
|
| 934 |
+
|
| 935 |
+
function syncFunds() external {
|
| 936 |
+
uint256 prevBalance = address(this).balance;
|
| 937 |
+
HorseyToken(tokenAddress).withdraw();
|
| 938 |
+
HorseyExchange(exchangeAddress).withdraw();
|
| 939 |
+
uint256 newBalance = address(this).balance;
|
| 940 |
+
|
| 941 |
+
toBeDistributed = toBeDistributed + (newBalance - prevBalance);
|
| 942 |
+
}
|
| 943 |
+
|
| 944 |
+
|
| 945 |
+
function getNobleBalance() external view
|
| 946 |
+
onlyCLevelAccess() returns (uint256) {
|
| 947 |
+
return _cBalance[msg.sender];
|
| 948 |
+
}
|
| 949 |
+
|
| 950 |
+
|
| 951 |
+
function makeProposal( uint8 methodId, uint256 parameter ) external
|
| 952 |
+
onlyCLevelAccess()
|
| 953 |
+
proposalAvailable()
|
| 954 |
+
cooledDown()
|
| 955 |
+
{
|
| 956 |
+
currentProposal.timestamp = block.timestamp;
|
| 957 |
+
currentProposal.parameter = parameter;
|
| 958 |
+
currentProposal.methodId = methodId;
|
| 959 |
+
currentProposal.proposer = msg.sender;
|
| 960 |
+
delete currentProposal.yay;
|
| 961 |
+
delete currentProposal.nay;
|
| 962 |
+
proposalInProgress = true;
|
| 963 |
+
|
| 964 |
+
emit NewProposal(methodId,parameter,msg.sender);
|
| 965 |
+
}
|
| 966 |
+
|
| 967 |
+
|
| 968 |
+
function voteOnProposal(bool voteFor) external
|
| 969 |
+
proposalPending()
|
| 970 |
+
onlyVoters()
|
| 971 |
+
notVoted() {
|
| 972 |
+
|
| 973 |
+
require((block.timestamp - currentProposal.timestamp) <= proposalLife);
|
| 974 |
+
if(voteFor)
|
| 975 |
+
{
|
| 976 |
+
currentProposal.yay.push(msg.sender);
|
| 977 |
+
|
| 978 |
+
if( currentProposal.yay.length >= votingThreshold )
|
| 979 |
+
{
|
| 980 |
+
_doProposal();
|
| 981 |
+
proposalInProgress = false;
|
| 982 |
+
|
| 983 |
+
return;
|
| 984 |
+
}
|
| 985 |
+
|
| 986 |
+
} else {
|
| 987 |
+
currentProposal.nay.push(msg.sender);
|
| 988 |
+
|
| 989 |
+
if( currentProposal.nay.length >= votingThreshold )
|
| 990 |
+
{
|
| 991 |
+
proposalInProgress = false;
|
| 992 |
+
cooldownStart = block.timestamp;
|
| 993 |
+
return;
|
| 994 |
+
}
|
| 995 |
+
}
|
| 996 |
+
}
|
| 997 |
+
|
| 998 |
+
|
| 999 |
+
function _moveBalance(address newAddress) internal
|
| 1000 |
+
validAddress(newAddress) {
|
| 1001 |
+
require(newAddress != msg.sender);
|
| 1002 |
+
_cBalance[newAddress] = _cBalance[msg.sender];
|
| 1003 |
+
_cBalance[msg.sender] = 0;
|
| 1004 |
+
}
|
| 1005 |
+
|
| 1006 |
+
|
| 1007 |
+
function _updateDistribution() internal {
|
| 1008 |
+
require(toBeDistributed != 0,"nothing to distribute");
|
| 1009 |
+
uint256 knightPayday = toBeDistributed / 100 * knightEquity;
|
| 1010 |
+
uint256 paladinPayday = toBeDistributed / 100 * paladinEquity;
|
| 1011 |
+
|
| 1012 |
+
|
| 1013 |
+
uint256 jokerPayday = toBeDistributed - knightPayday - paladinPayday;
|
| 1014 |
+
|
| 1015 |
+
_cBalance[jokerAddress] = _cBalance[jokerAddress] + jokerPayday;
|
| 1016 |
+
_cBalance[knightAddress] = _cBalance[knightAddress] + knightPayday;
|
| 1017 |
+
_cBalance[paladinAddress] = _cBalance[paladinAddress] + paladinPayday;
|
| 1018 |
+
|
| 1019 |
+
toBeDistributed = 0;
|
| 1020 |
+
}
|
| 1021 |
+
|
| 1022 |
+
|
| 1023 |
+
function _doProposal() internal {
|
| 1024 |
+
|
| 1025 |
+
if( currentProposal.methodId == 0 ) HorseyToken(tokenAddress).setRenamingCosts(currentProposal.parameter);
|
| 1026 |
+
|
| 1027 |
+
|
| 1028 |
+
if( currentProposal.methodId == 1 ) HorseyExchange(exchangeAddress).setMarketFees(currentProposal.parameter);
|
| 1029 |
+
|
| 1030 |
+
|
| 1031 |
+
if( currentProposal.methodId == 2 ) HorseyToken(tokenAddress).addLegitRaceAddress(address(currentProposal.parameter));
|
| 1032 |
+
|
| 1033 |
+
|
| 1034 |
+
if( currentProposal.methodId == 3 ) HorseyToken(tokenAddress).addHorseIndex(bytes32(currentProposal.parameter));
|
| 1035 |
+
|
| 1036 |
+
|
| 1037 |
+
if( currentProposal.methodId == 4 ) {
|
| 1038 |
+
if(currentProposal.parameter == 0) {
|
| 1039 |
+
HorseyExchange(exchangeAddress).unpause();
|
| 1040 |
+
HorseyToken(tokenAddress).unpause();
|
| 1041 |
+
} else {
|
| 1042 |
+
HorseyExchange(exchangeAddress).pause();
|
| 1043 |
+
HorseyToken(tokenAddress).pause();
|
| 1044 |
+
}
|
| 1045 |
+
}
|
| 1046 |
+
|
| 1047 |
+
|
| 1048 |
+
if( currentProposal.methodId == 5 ) HorseyToken(tokenAddress).setClaimingCosts(currentProposal.parameter);
|
| 1049 |
+
|
| 1050 |
+
|
| 1051 |
+
if( currentProposal.methodId == 8 ){
|
| 1052 |
+
HorseyToken(tokenAddress).setCarrotsMultiplier(uint8(currentProposal.parameter));
|
| 1053 |
+
}
|
| 1054 |
+
|
| 1055 |
+
|
| 1056 |
+
if( currentProposal.methodId == 9 ){
|
| 1057 |
+
HorseyToken(tokenAddress).setRarityMultiplier(uint8(currentProposal.parameter));
|
| 1058 |
+
}
|
| 1059 |
+
|
| 1060 |
+
emit ProposalPassed(currentProposal.methodId,currentProposal.parameter,currentProposal.proposer);
|
| 1061 |
+
}
|
| 1062 |
+
|
| 1063 |
+
|
| 1064 |
+
modifier validAddress(address addr) {
|
| 1065 |
+
require(addr != address(0),"Address is zero");
|
| 1066 |
+
_;
|
| 1067 |
+
}
|
| 1068 |
+
|
| 1069 |
+
|
| 1070 |
+
modifier onlyCLevelAccess() {
|
| 1071 |
+
require((jokerAddress == msg.sender) || (knightAddress == msg.sender) || (paladinAddress == msg.sender),"not c level");
|
| 1072 |
+
_;
|
| 1073 |
+
}
|
| 1074 |
+
|
| 1075 |
+
|
| 1076 |
+
|
| 1077 |
+
modifier proposalAvailable(){
|
| 1078 |
+
require(((!proposalInProgress) || ((block.timestamp - currentProposal.timestamp) > proposalLife)),"proposal already pending");
|
| 1079 |
+
_;
|
| 1080 |
+
}
|
| 1081 |
+
|
| 1082 |
+
|
| 1083 |
+
|
| 1084 |
+
modifier cooledDown( ){
|
| 1085 |
+
if(msg.sender == currentProposal.proposer && (block.timestamp - cooldownStart < 1 days)){
|
| 1086 |
+
revert("Cool down period not passed yet");
|
| 1087 |
+
}
|
| 1088 |
+
_;
|
| 1089 |
+
}
|
| 1090 |
+
|
| 1091 |
+
|
| 1092 |
+
modifier proposalPending() {
|
| 1093 |
+
require(proposalInProgress,"no proposal pending");
|
| 1094 |
+
_;
|
| 1095 |
+
}
|
| 1096 |
+
|
| 1097 |
+
|
| 1098 |
+
modifier notVoted() {
|
| 1099 |
+
uint256 length = currentProposal.yay.length;
|
| 1100 |
+
for(uint i = 0; i < length; i++) {
|
| 1101 |
+
if(currentProposal.yay[i] == msg.sender) {
|
| 1102 |
+
revert("Already voted");
|
| 1103 |
+
}
|
| 1104 |
+
}
|
| 1105 |
+
|
| 1106 |
+
length = currentProposal.nay.length;
|
| 1107 |
+
for(i = 0; i < length; i++) {
|
| 1108 |
+
if(currentProposal.nay[i] == msg.sender) {
|
| 1109 |
+
revert("Already voted");
|
| 1110 |
+
}
|
| 1111 |
+
}
|
| 1112 |
+
_;
|
| 1113 |
+
}
|
| 1114 |
+
|
| 1115 |
+
|
| 1116 |
+
modifier onlyVoters() {
|
| 1117 |
+
bool found = false;
|
| 1118 |
+
uint256 length = voters.length;
|
| 1119 |
+
for(uint i = 0; i < length; i++) {
|
| 1120 |
+
if(voters[i] == msg.sender) {
|
| 1121 |
+
found = true;
|
| 1122 |
+
break;
|
| 1123 |
+
}
|
| 1124 |
+
}
|
| 1125 |
+
if(!found) {
|
| 1126 |
+
revert("not a voter");
|
| 1127 |
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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
pragma solidity ^0.4.24;
|
| 2 |
+
|
| 3 |
+
library SafeMath {
|
| 4 |
+
|
| 5 |
+
|
| 6 |
+
function mul(uint256 a, uint256 b) internal pure returns (uint256 c) {
|
| 7 |
+
|
| 8 |
+
|
| 9 |
+
|
| 10 |
+
if (a == 0) {
|
| 11 |
+
return 0;
|
| 12 |
+
}
|
| 13 |
+
|
| 14 |
+
c = a * b;
|
| 15 |
+
assert(c / a == b);
|
| 16 |
+
return c;
|
| 17 |
+
}
|
| 18 |
+
|
| 19 |
+
|
| 20 |
+
function div(uint256 a, uint256 b) internal pure returns (uint256) {
|
| 21 |
+
|
| 22 |
+
|
| 23 |
+
|
| 24 |
+
return a / b;
|
| 25 |
+
}
|
| 26 |
+
|
| 27 |
+
|
| 28 |
+
function sub(uint256 a, uint256 b) internal pure returns (uint256) {
|
| 29 |
+
assert(b <= a);
|
| 30 |
+
return a - b;
|
| 31 |
+
}
|
| 32 |
+
|
| 33 |
+
|
| 34 |
+
function add(uint256 a, uint256 b) internal pure returns (uint256 c) {
|
| 35 |
+
c = a + b;
|
| 36 |
+
assert(c >= a);
|
| 37 |
+
return c;
|
| 38 |
+
}
|
| 39 |
+
}
|
| 40 |
+
|
| 41 |
+
contract Ownable {
|
| 42 |
+
address public owner;
|
| 43 |
+
|
| 44 |
+
|
| 45 |
+
event OwnershipRenounced(address indexed previousOwner);
|
| 46 |
+
event OwnershipTransferred(
|
| 47 |
+
address indexed previousOwner,
|
| 48 |
+
address indexed newOwner
|
| 49 |
+
);
|
| 50 |
+
|
| 51 |
+
|
| 52 |
+
|
| 53 |
+
constructor() public {
|
| 54 |
+
owner = msg.sender;
|
| 55 |
+
}
|
| 56 |
+
|
| 57 |
+
|
| 58 |
+
modifier onlyOwner() {
|
| 59 |
+
require(msg.sender == owner);
|
| 60 |
+
_;
|
| 61 |
+
}
|
| 62 |
+
|
| 63 |
+
|
| 64 |
+
function renounceOwnership() public onlyOwner {
|
| 65 |
+
emit OwnershipRenounced(owner);
|
| 66 |
+
owner = address(0);
|
| 67 |
+
}
|
| 68 |
+
|
| 69 |
+
|
| 70 |
+
function transferOwnership(address _newOwner) public onlyOwner {
|
| 71 |
+
_transferOwnership(_newOwner);
|
| 72 |
+
}
|
| 73 |
+
|
| 74 |
+
|
| 75 |
+
function _transferOwnership(address _newOwner) internal {
|
| 76 |
+
require(_newOwner != address(0));
|
| 77 |
+
emit OwnershipTransferred(owner, _newOwner);
|
| 78 |
+
owner = _newOwner;
|
| 79 |
+
}
|
| 80 |
+
}
|
| 81 |
+
|
| 82 |
+
contract Claimable is Ownable {
|
| 83 |
+
address public pendingOwner;
|
| 84 |
+
|
| 85 |
+
|
| 86 |
+
modifier onlyPendingOwner() {
|
| 87 |
+
require(msg.sender == pendingOwner);
|
| 88 |
+
_;
|
| 89 |
+
}
|
| 90 |
+
|
| 91 |
+
|
| 92 |
+
function transferOwnership(address newOwner) onlyOwner public {
|
| 93 |
+
pendingOwner = newOwner;
|
| 94 |
+
}
|
| 95 |
+
|
| 96 |
+
|
| 97 |
+
function claimOwnership() onlyPendingOwner public {
|
| 98 |
+
emit OwnershipTransferred(owner, pendingOwner);
|
| 99 |
+
owner = pendingOwner;
|
| 100 |
+
pendingOwner = address(0);
|
| 101 |
+
}
|
| 102 |
+
}
|
| 103 |
+
|
| 104 |
+
contract SimpleFlyDropToken is Claimable {
|
| 105 |
+
using SafeMath for uint256;
|
| 106 |
+
|
| 107 |
+
ERC20 internal erc20tk;
|
| 108 |
+
|
| 109 |
+
function setToken(address _token) onlyOwner public {
|
| 110 |
+
require(_token != address(0));
|
| 111 |
+
erc20tk = ERC20(_token);
|
| 112 |
+
}
|
| 113 |
+
|
| 114 |
+
|
| 115 |
+
function multiSend(address[] _destAddrs, uint256[] _values) onlyOwner public returns (uint256) {
|
| 116 |
+
require(_destAddrs.length == _values.length);
|
| 117 |
+
|
| 118 |
+
uint256 i = 0;
|
| 119 |
+
for (; i < _destAddrs.length; i = i.add(1)) {
|
| 120 |
+
if (!erc20tk.transfer(_destAddrs[i], _values[i])) {
|
| 121 |
+
break;
|
| 122 |
+
}
|
| 123 |
+
}
|
| 124 |
+
|
| 125 |
+
return (i);
|
| 126 |
+
}
|
| 127 |
+
}
|
| 128 |
+
|
| 129 |
+
contract DelayedClaimable is Claimable {
|
| 130 |
+
|
| 131 |
+
uint256 public end;
|
| 132 |
+
uint256 public start;
|
| 133 |
+
|
| 134 |
+
|
| 135 |
+
function setLimits(uint256 _start, uint256 _end) onlyOwner public {
|
| 136 |
+
require(_start <= _end);
|
| 137 |
+
end = _end;
|
| 138 |
+
start = _start;
|
| 139 |
+
}
|
| 140 |
+
|
| 141 |
+
|
| 142 |
+
function claimOwnership() onlyPendingOwner public {
|
| 143 |
+
require((block.number <= end) && (block.number >= start));
|
| 144 |
+
emit OwnershipTransferred(owner, pendingOwner);
|
| 145 |
+
owner = pendingOwner;
|
| 146 |
+
pendingOwner = address(0);
|
| 147 |
+
end = 0;
|
| 148 |
+
}
|
| 149 |
+
|
| 150 |
+
}
|
| 151 |
+
|
| 152 |
+
contract FlyDropTokenMgr is DelayedClaimable {
|
| 153 |
+
using SafeMath for uint256;
|
| 154 |
+
|
| 155 |
+
address[] dropTokenAddrs;
|
| 156 |
+
SimpleFlyDropToken currentDropTokenContract;
|
| 157 |
+
|
| 158 |
+
|
| 159 |
+
|
| 160 |
+
function prepare(uint256 _rand,
|
| 161 |
+
address _from,
|
| 162 |
+
address _token,
|
| 163 |
+
uint256 _value) onlyOwner public returns (bool) {
|
| 164 |
+
require(_token != address(0));
|
| 165 |
+
require(_from != address(0));
|
| 166 |
+
require(_rand > 0);
|
| 167 |
+
|
| 168 |
+
if (ERC20(_token).allowance(_from, this) < _value) {
|
| 169 |
+
return false;
|
| 170 |
+
}
|
| 171 |
+
|
| 172 |
+
if (_rand > dropTokenAddrs.length) {
|
| 173 |
+
SimpleFlyDropToken dropTokenContract = new SimpleFlyDropToken();
|
| 174 |
+
dropTokenAddrs.push(address(dropTokenContract));
|
| 175 |
+
currentDropTokenContract = dropTokenContract;
|
| 176 |
+
} else {
|
| 177 |
+
currentDropTokenContract = SimpleFlyDropToken(dropTokenAddrs[_rand.sub(1)]);
|
| 178 |
+
}
|
| 179 |
+
|
| 180 |
+
currentDropTokenContract.setToken(_token);
|
| 181 |
+
return ERC20(_token).transferFrom(_from, currentDropTokenContract, _value);
|
| 182 |
+
|
| 183 |
+
|
| 184 |
+
|
| 185 |
+
}
|
| 186 |
+
|
| 187 |
+
|
| 188 |
+
|
| 189 |
+
|
| 190 |
+
|
| 191 |
+
|
| 192 |
+
|
| 193 |
+
|
| 194 |
+
|
| 195 |
+
function flyDrop(address[] _destAddrs, uint256[] _values) onlyOwner public returns (uint256) {
|
| 196 |
+
require(address(currentDropTokenContract) != address(0));
|
| 197 |
+
return currentDropTokenContract.multiSend(_destAddrs, _values);
|
| 198 |
+
}
|
| 199 |
+
|
| 200 |
+
}
|
| 201 |
+
|
| 202 |
+
contract ERC20Basic {
|
| 203 |
+
function totalSupply() public view returns (uint256);
|
| 204 |
+
function balanceOf(address who) public view returns (uint256);
|
| 205 |
+
function transfer(address to, uint256 value) public returns (bool);
|
| 206 |
+
event Transfer(address indexed from, address indexed to, uint256 value);
|
| 207 |
+
}
|
| 208 |
+
|
| 209 |
+
contract ERC20 is ERC20Basic {
|
| 210 |
+
function allowance(address owner, address spender)
|
| 211 |
+
public view returns (uint256);
|
| 212 |
+
|
| 213 |
+
function transferFrom(address from, address to, uint256 value)
|
| 214 |
+
public returns (bool);
|
| 215 |
+
|
| 216 |
+
function approve(address spender, uint256 value) public returns (bool);
|
| 217 |
+
event Approval(
|
| 218 |
+
address indexed owner,
|
| 219 |
+
address indexed spender,
|
| 220 |
+
uint256 value
|
| 221 |
+
);
|
| 222 |
+
}
|
smart_contract_dataset/block number dependency/1406.sol
ADDED
|
@@ -0,0 +1,247 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
pragma solidity ^0.4.12;
|
| 2 |
+
|
| 3 |
+
contract IMigrationContract {
|
| 4 |
+
function migrate(address addr, uint256 nas) returns (bool success);
|
| 5 |
+
}
|
| 6 |
+
|
| 7 |
+
|
| 8 |
+
contract SafeMath {
|
| 9 |
+
|
| 10 |
+
|
| 11 |
+
function safeAdd(uint256 x, uint256 y) internal returns(uint256) {
|
| 12 |
+
uint256 z = x + y;
|
| 13 |
+
assert((z >= x) && (z >= y));
|
| 14 |
+
return z;
|
| 15 |
+
}
|
| 16 |
+
|
| 17 |
+
function safeSubtract(uint256 x, uint256 y) internal returns(uint256) {
|
| 18 |
+
assert(x >= y);
|
| 19 |
+
uint256 z = x - y;
|
| 20 |
+
return z;
|
| 21 |
+
}
|
| 22 |
+
|
| 23 |
+
function safeMult(uint256 x, uint256 y) internal returns(uint256) {
|
| 24 |
+
uint256 z = x * y;
|
| 25 |
+
assert((x == 0)||(z/x == y));
|
| 26 |
+
return z;
|
| 27 |
+
}
|
| 28 |
+
|
| 29 |
+
}
|
| 30 |
+
|
| 31 |
+
contract Token {
|
| 32 |
+
uint256 public totalSupply;
|
| 33 |
+
function balanceOf(address _owner) constant returns (uint256 balance);
|
| 34 |
+
function transfer(address _to, uint256 _value) returns (bool success);
|
| 35 |
+
function transferFrom(address _from, address _to, uint256 _value) returns (bool success);
|
| 36 |
+
function approve(address _spender, uint256 _value) returns (bool success);
|
| 37 |
+
function allowance(address _owner, address _spender) constant returns (uint256 remaining);
|
| 38 |
+
event Transfer(address indexed _from, address indexed _to, uint256 _value);
|
| 39 |
+
event Approval(address indexed _owner, address indexed _spender, uint256 _value);
|
| 40 |
+
}
|
| 41 |
+
|
| 42 |
+
|
| 43 |
+
|
| 44 |
+
contract StandardToken is Token {
|
| 45 |
+
|
| 46 |
+
function transfer(address _to, uint256 _value) returns (bool success) {
|
| 47 |
+
if (balances[msg.sender] >= _value && _value > 0) {
|
| 48 |
+
balances[msg.sender] -= _value;
|
| 49 |
+
balances[_to] += _value;
|
| 50 |
+
Transfer(msg.sender, _to, _value);
|
| 51 |
+
return true;
|
| 52 |
+
} else {
|
| 53 |
+
return false;
|
| 54 |
+
}
|
| 55 |
+
}
|
| 56 |
+
|
| 57 |
+
function transferFrom(address _from, address _to, uint256 _value) returns (bool success) {
|
| 58 |
+
if (balances[_from] >= _value && allowed[_from][msg.sender] >= _value && _value > 0) {
|
| 59 |
+
balances[_to] += _value;
|
| 60 |
+
balances[_from] -= _value;
|
| 61 |
+
allowed[_from][msg.sender] -= _value;
|
| 62 |
+
Transfer(_from, _to, _value);
|
| 63 |
+
return true;
|
| 64 |
+
} else {
|
| 65 |
+
return false;
|
| 66 |
+
}
|
| 67 |
+
}
|
| 68 |
+
|
| 69 |
+
function balanceOf(address _owner) constant returns (uint256 balance) {
|
| 70 |
+
return balances[_owner];
|
| 71 |
+
}
|
| 72 |
+
|
| 73 |
+
function approve(address _spender, uint256 _value) returns (bool success) {
|
| 74 |
+
allowed[msg.sender][_spender] = _value;
|
| 75 |
+
Approval(msg.sender, _spender, _value);
|
| 76 |
+
return true;
|
| 77 |
+
}
|
| 78 |
+
|
| 79 |
+
function allowance(address _owner, address _spender) constant returns (uint256 remaining) {
|
| 80 |
+
return allowed[_owner][_spender];
|
| 81 |
+
}
|
| 82 |
+
|
| 83 |
+
mapping (address => uint256) balances;
|
| 84 |
+
mapping (address => mapping (address => uint256)) allowed;
|
| 85 |
+
}
|
| 86 |
+
|
| 87 |
+
contract EVTCTLToken is StandardToken, SafeMath {
|
| 88 |
+
|
| 89 |
+
|
| 90 |
+
string public constant name = "EVTC";
|
| 91 |
+
string public constant symbol = "EVTC";
|
| 92 |
+
uint256 public constant decimals = 18;
|
| 93 |
+
string public version = "1.0";
|
| 94 |
+
|
| 95 |
+
|
| 96 |
+
address public ethFundDeposit;
|
| 97 |
+
address public newContractAddr;
|
| 98 |
+
|
| 99 |
+
|
| 100 |
+
bool public isFunding;
|
| 101 |
+
uint256 public fundingStartBlock;
|
| 102 |
+
uint256 public fundingStopBlock;
|
| 103 |
+
|
| 104 |
+
uint256 public currentSupply;
|
| 105 |
+
uint256 public tokenRaised = 0;
|
| 106 |
+
uint256 public tokenMigrated = 0;
|
| 107 |
+
uint256 public tokenExchangeRate = 2600;
|
| 108 |
+
|
| 109 |
+
|
| 110 |
+
event AllocateToken(address indexed _to, uint256 _value);
|
| 111 |
+
event IssueToken(address indexed _to, uint256 _value);
|
| 112 |
+
event IncreaseSupply(uint256 _value);
|
| 113 |
+
event DecreaseSupply(uint256 _value);
|
| 114 |
+
event Migrate(address indexed _to, uint256 _value);
|
| 115 |
+
|
| 116 |
+
|
| 117 |
+
function formatDecimals(uint256 _value) internal returns (uint256 ) {
|
| 118 |
+
return _value * 10 ** decimals;
|
| 119 |
+
}
|
| 120 |
+
|
| 121 |
+
|
| 122 |
+
function EVTCTLToken(
|
| 123 |
+
address _ethFundDeposit,
|
| 124 |
+
uint256 _currentSupply)
|
| 125 |
+
{
|
| 126 |
+
ethFundDeposit = _ethFundDeposit;
|
| 127 |
+
|
| 128 |
+
isFunding = false;
|
| 129 |
+
fundingStartBlock = 0;
|
| 130 |
+
fundingStopBlock = 0;
|
| 131 |
+
|
| 132 |
+
currentSupply = formatDecimals(_currentSupply);
|
| 133 |
+
totalSupply = formatDecimals(100000000);
|
| 134 |
+
balances[msg.sender] = totalSupply;
|
| 135 |
+
if(currentSupply > totalSupply) throw;
|
| 136 |
+
}
|
| 137 |
+
|
| 138 |
+
modifier isOwner() { require(msg.sender == ethFundDeposit); _; }
|
| 139 |
+
|
| 140 |
+
|
| 141 |
+
function setTokenExchangeRate(uint256 _tokenExchangeRate) isOwner external {
|
| 142 |
+
if (_tokenExchangeRate == 0) throw;
|
| 143 |
+
if (_tokenExchangeRate == tokenExchangeRate) throw;
|
| 144 |
+
|
| 145 |
+
tokenExchangeRate = _tokenExchangeRate;
|
| 146 |
+
}
|
| 147 |
+
|
| 148 |
+
|
| 149 |
+
function increaseSupply (uint256 _value) isOwner external {
|
| 150 |
+
uint256 value = formatDecimals(_value);
|
| 151 |
+
if (value + currentSupply > totalSupply) throw;
|
| 152 |
+
currentSupply = safeAdd(currentSupply, value);
|
| 153 |
+
IncreaseSupply(value);
|
| 154 |
+
}
|
| 155 |
+
|
| 156 |
+
|
| 157 |
+
function decreaseSupply (uint256 _value) isOwner external {
|
| 158 |
+
uint256 value = formatDecimals(_value);
|
| 159 |
+
if (value + tokenRaised > currentSupply) throw;
|
| 160 |
+
|
| 161 |
+
currentSupply = safeSubtract(currentSupply, value);
|
| 162 |
+
DecreaseSupply(value);
|
| 163 |
+
}
|
| 164 |
+
|
| 165 |
+
|
| 166 |
+
function startFunding (uint256 _fundingStartBlock, uint256 _fundingStopBlock) isOwner external {
|
| 167 |
+
if (isFunding) throw;
|
| 168 |
+
if (_fundingStartBlock >= _fundingStopBlock) throw;
|
| 169 |
+
if (block.number >= _fundingStartBlock) throw;
|
| 170 |
+
|
| 171 |
+
fundingStartBlock = _fundingStartBlock;
|
| 172 |
+
fundingStopBlock = _fundingStopBlock;
|
| 173 |
+
isFunding = true;
|
| 174 |
+
}
|
| 175 |
+
|
| 176 |
+
|
| 177 |
+
function stopFunding() isOwner external {
|
| 178 |
+
if (!isFunding) throw;
|
| 179 |
+
isFunding = false;
|
| 180 |
+
}
|
| 181 |
+
|
| 182 |
+
|
| 183 |
+
function setMigrateContract(address _newContractAddr) isOwner external {
|
| 184 |
+
if (_newContractAddr == newContractAddr) throw;
|
| 185 |
+
newContractAddr = _newContractAddr;
|
| 186 |
+
}
|
| 187 |
+
|
| 188 |
+
|
| 189 |
+
function changeOwner(address _newFundDeposit) isOwner() external {
|
| 190 |
+
if (_newFundDeposit == address(0x0)) throw;
|
| 191 |
+
ethFundDeposit = _newFundDeposit;
|
| 192 |
+
}
|
| 193 |
+
|
| 194 |
+
|
| 195 |
+
function migrate() external {
|
| 196 |
+
if(isFunding) throw;
|
| 197 |
+
if(newContractAddr == address(0x0)) throw;
|
| 198 |
+
|
| 199 |
+
uint256 tokens = balances[msg.sender];
|
| 200 |
+
if (tokens == 0) throw;
|
| 201 |
+
|
| 202 |
+
balances[msg.sender] = 0;
|
| 203 |
+
tokenMigrated = safeAdd(tokenMigrated, tokens);
|
| 204 |
+
|
| 205 |
+
IMigrationContract newContract = IMigrationContract(newContractAddr);
|
| 206 |
+
if (!newContract.migrate(msg.sender, tokens)) throw;
|
| 207 |
+
|
| 208 |
+
Migrate(msg.sender, tokens);
|
| 209 |
+
}
|
| 210 |
+
|
| 211 |
+
|
| 212 |
+
function transferETH() isOwner external {
|
| 213 |
+
if (this.balance == 0) throw;
|
| 214 |
+
if (!ethFundDeposit.send(this.balance)) throw;
|
| 215 |
+
}
|
| 216 |
+
|
| 217 |
+
|
| 218 |
+
function allocateToken (address _addr, uint256 _eth) isOwner external {
|
| 219 |
+
if (_eth == 0) throw;
|
| 220 |
+
if (_addr == address(0x0)) throw;
|
| 221 |
+
|
| 222 |
+
uint256 tokens = safeMult(formatDecimals(_eth), tokenExchangeRate);
|
| 223 |
+
if (tokens + tokenRaised > currentSupply) throw;
|
| 224 |
+
|
| 225 |
+
tokenRaised = safeAdd(tokenRaised, tokens);
|
| 226 |
+
balances[_addr] += tokens;
|
| 227 |
+
|
| 228 |
+
AllocateToken(_addr, tokens);
|
| 229 |
+
}
|
| 230 |
+
|
| 231 |
+
|
| 232 |
+
function () payable {
|
| 233 |
+
if (!isFunding) throw;
|
| 234 |
+
if (msg.value == 0) throw;
|
| 235 |
+
|
| 236 |
+
if (block.number < fundingStartBlock) throw;
|
| 237 |
+
if (block.number > fundingStopBlock) throw;
|
| 238 |
+
|
| 239 |
+
uint256 tokens = safeMult(msg.value, tokenExchangeRate);
|
| 240 |
+
if (tokens + tokenRaised > currentSupply) throw;
|
| 241 |
+
|
| 242 |
+
tokenRaised = safeAdd(tokenRaised, tokens);
|
| 243 |
+
balances[msg.sender] += tokens;
|
| 244 |
+
|
| 245 |
+
IssueToken(msg.sender, tokens);
|
| 246 |
+
}
|
| 247 |
+
}
|
smart_contract_dataset/block number dependency/1472.sol
ADDED
|
@@ -0,0 +1,472 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
pragma solidity ^0.4.24;
|
| 2 |
+
|
| 3 |
+
|
| 4 |
+
|
| 5 |
+
contract ZTHReceivingContract {
|
| 6 |
+
function tokenFallback(address _from, uint _value, bytes _data) public returns (bool);
|
| 7 |
+
}
|
| 8 |
+
|
| 9 |
+
contract ZTHInterface {
|
| 10 |
+
function transfer(address _to, uint _value) public returns (bool);
|
| 11 |
+
function approve(address spender, uint tokens) public returns (bool);
|
| 12 |
+
}
|
| 13 |
+
|
| 14 |
+
contract Zlots is ZTHReceivingContract {
|
| 15 |
+
using SafeMath for uint;
|
| 16 |
+
|
| 17 |
+
address private owner;
|
| 18 |
+
address private bankroll;
|
| 19 |
+
|
| 20 |
+
|
| 21 |
+
uint totalSpins;
|
| 22 |
+
uint totalZTHWagered;
|
| 23 |
+
|
| 24 |
+
|
| 25 |
+
uint contractBalance;
|
| 26 |
+
|
| 27 |
+
|
| 28 |
+
bool public gameActive;
|
| 29 |
+
|
| 30 |
+
address private ZTHTKNADDR;
|
| 31 |
+
address private ZTHBANKROLL;
|
| 32 |
+
ZTHInterface private ZTHTKN;
|
| 33 |
+
|
| 34 |
+
mapping (uint => bool) validTokenBet;
|
| 35 |
+
|
| 36 |
+
|
| 37 |
+
event HouseRetrievedTake(
|
| 38 |
+
uint timeTaken,
|
| 39 |
+
uint tokensWithdrawn
|
| 40 |
+
);
|
| 41 |
+
|
| 42 |
+
|
| 43 |
+
event TokensWagered(
|
| 44 |
+
address _wagerer,
|
| 45 |
+
uint _wagered
|
| 46 |
+
);
|
| 47 |
+
|
| 48 |
+
event LogResult(
|
| 49 |
+
address _wagerer,
|
| 50 |
+
uint _result,
|
| 51 |
+
uint _profit,
|
| 52 |
+
uint _wagered,
|
| 53 |
+
uint _category,
|
| 54 |
+
bool _win
|
| 55 |
+
);
|
| 56 |
+
|
| 57 |
+
|
| 58 |
+
event Loss(address _wagerer, uint _block);
|
| 59 |
+
event ThreeMoonJackpot(address _wagerer, uint _block);
|
| 60 |
+
event TwoMoonPrize(address _wagerer, uint _block);
|
| 61 |
+
event ZTHJackpot(address _wagerer, uint _block);
|
| 62 |
+
event ThreeZSymbols(address _wagerer, uint _block);
|
| 63 |
+
event ThreeTSymbols(address _wagerer, uint _block);
|
| 64 |
+
event ThreeHSymbols(address _wagerer, uint _block);
|
| 65 |
+
event ThreeEtherIcons(address _wagerer, uint _block);
|
| 66 |
+
event ThreeGreenPyramids(address _wagerer, uint _block);
|
| 67 |
+
event ThreeGoldPyramids(address _wagerer, uint _block);
|
| 68 |
+
event ThreeWhitePyramids(address _wagerer, uint _block);
|
| 69 |
+
event OneMoonPrize(address _wagerer, uint _block);
|
| 70 |
+
event OneOfEachPyramidPrize(address _wagerer, uint _block);
|
| 71 |
+
event TwoZSymbols(address _wagerer, uint _block);
|
| 72 |
+
event TwoTSymbols(address _wagerer, uint _block);
|
| 73 |
+
event TwoHSymbols(address _wagerer, uint _block);
|
| 74 |
+
event TwoEtherIcons(address _wagerer, uint _block);
|
| 75 |
+
event TwoGreenPyramids(address _wagerer, uint _block);
|
| 76 |
+
event TwoGoldPyramids(address _wagerer, uint _block);
|
| 77 |
+
event TwoWhitePyramids(address _wagerer, uint _block);
|
| 78 |
+
|
| 79 |
+
event SpinConcluded(address _wagerer, uint _block);
|
| 80 |
+
|
| 81 |
+
modifier onlyOwner {
|
| 82 |
+
require(msg.sender == owner);
|
| 83 |
+
_;
|
| 84 |
+
}
|
| 85 |
+
|
| 86 |
+
modifier onlyBankroll {
|
| 87 |
+
require(msg.sender == bankroll);
|
| 88 |
+
_;
|
| 89 |
+
}
|
| 90 |
+
|
| 91 |
+
modifier onlyOwnerOrBankroll {
|
| 92 |
+
require(msg.sender == owner || msg.sender == bankroll);
|
| 93 |
+
_;
|
| 94 |
+
}
|
| 95 |
+
|
| 96 |
+
|
| 97 |
+
modifier gameIsActive {
|
| 98 |
+
require(gameActive == true);
|
| 99 |
+
_;
|
| 100 |
+
}
|
| 101 |
+
|
| 102 |
+
constructor(address ZethrAddress, address BankrollAddress) public {
|
| 103 |
+
|
| 104 |
+
|
| 105 |
+
ZTHTKNADDR = ZethrAddress;
|
| 106 |
+
ZTHBANKROLL = BankrollAddress;
|
| 107 |
+
|
| 108 |
+
|
| 109 |
+
owner = msg.sender;
|
| 110 |
+
bankroll = ZTHBANKROLL;
|
| 111 |
+
|
| 112 |
+
|
| 113 |
+
ZTHTKN = ZTHInterface(ZTHTKNADDR);
|
| 114 |
+
ZTHTKN.approve(ZTHBANKROLL, 2**256 - 1);
|
| 115 |
+
|
| 116 |
+
|
| 117 |
+
ZTHTKN.approve(owner, 2**256 - 1);
|
| 118 |
+
|
| 119 |
+
|
| 120 |
+
validTokenBet[1e18] = true;
|
| 121 |
+
validTokenBet[5e18] = true;
|
| 122 |
+
validTokenBet[10e18] = true;
|
| 123 |
+
validTokenBet[25e18] = true;
|
| 124 |
+
validTokenBet[50e18] = true;
|
| 125 |
+
|
| 126 |
+
gameActive = true;
|
| 127 |
+
}
|
| 128 |
+
|
| 129 |
+
|
| 130 |
+
function() public payable { }
|
| 131 |
+
|
| 132 |
+
|
| 133 |
+
struct TKN { address sender; uint value; }
|
| 134 |
+
function tokenFallback(address _from, uint _value, bytes ) public returns (bool){
|
| 135 |
+
if (_from == bankroll) {
|
| 136 |
+
|
| 137 |
+
contractBalance = contractBalance.add(_value);
|
| 138 |
+
return true;
|
| 139 |
+
} else {
|
| 140 |
+
TKN memory _tkn;
|
| 141 |
+
_tkn.sender = _from;
|
| 142 |
+
_tkn.value = _value;
|
| 143 |
+
_spinTokens(_tkn);
|
| 144 |
+
return true;
|
| 145 |
+
}
|
| 146 |
+
}
|
| 147 |
+
|
| 148 |
+
struct playerSpin {
|
| 149 |
+
uint200 tokenValue;
|
| 150 |
+
uint56 blockn;
|
| 151 |
+
}
|
| 152 |
+
|
| 153 |
+
|
| 154 |
+
mapping(address => playerSpin) public playerSpins;
|
| 155 |
+
|
| 156 |
+
|
| 157 |
+
function _spinTokens(TKN _tkn) private {
|
| 158 |
+
|
| 159 |
+
require(gameActive);
|
| 160 |
+
require(_zthToken(msg.sender));
|
| 161 |
+
require(validTokenBet[_tkn.value]);
|
| 162 |
+
require(jackpotGuard(_tkn.value));
|
| 163 |
+
|
| 164 |
+
require(_tkn.value < ((2 ** 200) - 1));
|
| 165 |
+
require(block.number < ((2 ** 56) - 1));
|
| 166 |
+
|
| 167 |
+
address _customerAddress = _tkn.sender;
|
| 168 |
+
uint _wagered = _tkn.value;
|
| 169 |
+
|
| 170 |
+
playerSpin memory spin = playerSpins[_tkn.sender];
|
| 171 |
+
|
| 172 |
+
contractBalance = contractBalance.add(_wagered);
|
| 173 |
+
|
| 174 |
+
|
| 175 |
+
require(block.number != spin.blockn);
|
| 176 |
+
|
| 177 |
+
|
| 178 |
+
if (spin.blockn != 0) {
|
| 179 |
+
_finishSpin(_tkn.sender);
|
| 180 |
+
}
|
| 181 |
+
|
| 182 |
+
|
| 183 |
+
spin.blockn = uint56(block.number);
|
| 184 |
+
spin.tokenValue = uint200(_wagered);
|
| 185 |
+
|
| 186 |
+
|
| 187 |
+
playerSpins[_tkn.sender] = spin;
|
| 188 |
+
|
| 189 |
+
|
| 190 |
+
totalSpins += 1;
|
| 191 |
+
|
| 192 |
+
|
| 193 |
+
totalZTHWagered += _wagered;
|
| 194 |
+
|
| 195 |
+
emit TokensWagered(_customerAddress, _wagered);
|
| 196 |
+
|
| 197 |
+
}
|
| 198 |
+
|
| 199 |
+
|
| 200 |
+
function finishSpin() public
|
| 201 |
+
gameIsActive
|
| 202 |
+
returns (uint)
|
| 203 |
+
{
|
| 204 |
+
return _finishSpin(msg.sender);
|
| 205 |
+
}
|
| 206 |
+
|
| 207 |
+
|
| 208 |
+
function _finishSpin(address target)
|
| 209 |
+
private returns (uint)
|
| 210 |
+
{
|
| 211 |
+
playerSpin memory spin = playerSpins[target];
|
| 212 |
+
|
| 213 |
+
require(spin.tokenValue > 0);
|
| 214 |
+
require(spin.blockn != block.number);
|
| 215 |
+
|
| 216 |
+
uint profit = 0;
|
| 217 |
+
uint category = 0;
|
| 218 |
+
|
| 219 |
+
|
| 220 |
+
|
| 221 |
+
uint result;
|
| 222 |
+
if (block.number - spin.blockn > 255) {
|
| 223 |
+
result = 999999;
|
| 224 |
+
} else {
|
| 225 |
+
|
| 226 |
+
|
| 227 |
+
|
| 228 |
+
result = random(1000000, spin.blockn, target);
|
| 229 |
+
}
|
| 230 |
+
|
| 231 |
+
if (result > 476661) {
|
| 232 |
+
|
| 233 |
+
emit Loss(target, spin.blockn);
|
| 234 |
+
emit LogResult(target, result, profit, spin.tokenValue, category, false);
|
| 235 |
+
} else {
|
| 236 |
+
if (result < 1) {
|
| 237 |
+
|
| 238 |
+
profit = SafeMath.mul(spin.tokenValue, 500);
|
| 239 |
+
category = 1;
|
| 240 |
+
emit ThreeMoonJackpot(target, spin.blockn);
|
| 241 |
+
} else
|
| 242 |
+
if (result < 298) {
|
| 243 |
+
|
| 244 |
+
profit = SafeMath.mul(spin.tokenValue, 232);
|
| 245 |
+
category = 2;
|
| 246 |
+
emit TwoMoonPrize(target, spin.blockn);
|
| 247 |
+
} else
|
| 248 |
+
if (result < 3127) {
|
| 249 |
+
|
| 250 |
+
profit = SafeMath.div(SafeMath.mul(spin.tokenValue, 232), 10);
|
| 251 |
+
category = 3;
|
| 252 |
+
emit ZTHJackpot(target, spin.blockn);
|
| 253 |
+
|
| 254 |
+
} else
|
| 255 |
+
if (result < 5956) {
|
| 256 |
+
|
| 257 |
+
profit = SafeMath.mul(spin.tokenValue, 25);
|
| 258 |
+
category = 4;
|
| 259 |
+
emit ThreeZSymbols(target, spin.blockn);
|
| 260 |
+
} else
|
| 261 |
+
if (result < 8785) {
|
| 262 |
+
|
| 263 |
+
profit = SafeMath.mul(spin.tokenValue, 25);
|
| 264 |
+
category = 5;
|
| 265 |
+
emit ThreeTSymbols(target, spin.blockn);
|
| 266 |
+
} else
|
| 267 |
+
if (result < 11614) {
|
| 268 |
+
|
| 269 |
+
profit = SafeMath.mul(spin.tokenValue, 25);
|
| 270 |
+
category = 6;
|
| 271 |
+
emit ThreeHSymbols(target, spin.blockn);
|
| 272 |
+
} else
|
| 273 |
+
if (result < 14443) {
|
| 274 |
+
|
| 275 |
+
profit = SafeMath.mul(spin.tokenValue, 50);
|
| 276 |
+
category = 7;
|
| 277 |
+
emit ThreeEtherIcons(target, spin.blockn);
|
| 278 |
+
} else
|
| 279 |
+
if (result < 17272) {
|
| 280 |
+
|
| 281 |
+
profit = SafeMath.mul(spin.tokenValue, 40);
|
| 282 |
+
category = 8;
|
| 283 |
+
emit ThreeGreenPyramids(target, spin.blockn);
|
| 284 |
+
} else
|
| 285 |
+
if (result < 20101) {
|
| 286 |
+
|
| 287 |
+
profit = SafeMath.mul(spin.tokenValue, 20);
|
| 288 |
+
category = 9;
|
| 289 |
+
emit ThreeGoldPyramids(target, spin.blockn);
|
| 290 |
+
} else
|
| 291 |
+
if (result < 22929) {
|
| 292 |
+
|
| 293 |
+
profit = SafeMath.mul(spin.tokenValue, 20);
|
| 294 |
+
category = 10;
|
| 295 |
+
emit ThreeWhitePyramids(target, spin.blockn);
|
| 296 |
+
} else
|
| 297 |
+
if (result < 52332) {
|
| 298 |
+
|
| 299 |
+
profit = SafeMath.div(SafeMath.mul(spin.tokenValue, 125),10);
|
| 300 |
+
category = 11;
|
| 301 |
+
emit OneMoonPrize(target, spin.blockn);
|
| 302 |
+
} else
|
| 303 |
+
if (result < 120225) {
|
| 304 |
+
|
| 305 |
+
profit = SafeMath.div(SafeMath.mul(spin.tokenValue, 15),10);
|
| 306 |
+
category = 12;
|
| 307 |
+
emit OneOfEachPyramidPrize(target, spin.blockn);
|
| 308 |
+
} else
|
| 309 |
+
if (result < 171146) {
|
| 310 |
+
|
| 311 |
+
profit = SafeMath.div(SafeMath.mul(spin.tokenValue, 232),100);
|
| 312 |
+
category = 13;
|
| 313 |
+
emit TwoZSymbols(target, spin.blockn);
|
| 314 |
+
} else
|
| 315 |
+
if (result < 222067) {
|
| 316 |
+
|
| 317 |
+
profit = SafeMath.div(SafeMath.mul(spin.tokenValue, 232),100);
|
| 318 |
+
category = 14;
|
| 319 |
+
emit TwoTSymbols(target, spin.blockn);
|
| 320 |
+
} else
|
| 321 |
+
if (result < 272988) {
|
| 322 |
+
|
| 323 |
+
profit = SafeMath.div(SafeMath.mul(spin.tokenValue, 232),100);
|
| 324 |
+
category = 15;
|
| 325 |
+
emit TwoHSymbols(target, spin.blockn);
|
| 326 |
+
} else
|
| 327 |
+
if (result < 323909) {
|
| 328 |
+
|
| 329 |
+
profit = SafeMath.div(SafeMath.mul(spin.tokenValue, 375),100);
|
| 330 |
+
category = 16;
|
| 331 |
+
emit TwoEtherIcons(target, spin.blockn);
|
| 332 |
+
} else
|
| 333 |
+
if (result < 374830) {
|
| 334 |
+
|
| 335 |
+
profit = SafeMath.div(SafeMath.mul(spin.tokenValue, 35),10);
|
| 336 |
+
category = 17;
|
| 337 |
+
emit TwoGreenPyramids(target, spin.blockn);
|
| 338 |
+
} else
|
| 339 |
+
if (result < 425751) {
|
| 340 |
+
|
| 341 |
+
profit = SafeMath.div(SafeMath.mul(spin.tokenValue, 225),100);
|
| 342 |
+
category = 18;
|
| 343 |
+
emit TwoGoldPyramids(target, spin.blockn);
|
| 344 |
+
} else {
|
| 345 |
+
|
| 346 |
+
profit = SafeMath.mul(spin.tokenValue, 2);
|
| 347 |
+
category = 19;
|
| 348 |
+
emit TwoWhitePyramids(target, spin.blockn);
|
| 349 |
+
}
|
| 350 |
+
|
| 351 |
+
emit LogResult(target, result, profit, spin.tokenValue, category, true);
|
| 352 |
+
contractBalance = contractBalance.sub(profit);
|
| 353 |
+
ZTHTKN.transfer(target, profit);
|
| 354 |
+
}
|
| 355 |
+
|
| 356 |
+
|
| 357 |
+
playerSpins[target] = playerSpin(uint200(0), uint56(0));
|
| 358 |
+
emit SpinConcluded(target, spin.blockn);
|
| 359 |
+
return result;
|
| 360 |
+
}
|
| 361 |
+
|
| 362 |
+
|
| 363 |
+
|
| 364 |
+
|
| 365 |
+
|
| 366 |
+
function jackpotGuard(uint _wager)
|
| 367 |
+
private
|
| 368 |
+
view
|
| 369 |
+
returns (bool)
|
| 370 |
+
{
|
| 371 |
+
uint maxProfit = SafeMath.mul(_wager, 500);
|
| 372 |
+
uint ninetyContractBalance = SafeMath.mul(SafeMath.div(contractBalance, 10), 9);
|
| 373 |
+
return (maxProfit <= ninetyContractBalance);
|
| 374 |
+
}
|
| 375 |
+
|
| 376 |
+
|
| 377 |
+
|
| 378 |
+
function maxRandom(uint blockn, address entropy) private view returns (uint256 randomNumber) {
|
| 379 |
+
return uint256(keccak256(
|
| 380 |
+
abi.encodePacked(
|
| 381 |
+
address(this),
|
| 382 |
+
blockhash(blockn),
|
| 383 |
+
entropy)
|
| 384 |
+
));
|
| 385 |
+
}
|
| 386 |
+
|
| 387 |
+
|
| 388 |
+
function random(uint256 upper, uint256 blockn, address entropy) internal view returns (uint256 randomNumber) {
|
| 389 |
+
return maxRandom(blockn, entropy) % upper;
|
| 390 |
+
}
|
| 391 |
+
|
| 392 |
+
|
| 393 |
+
function balanceOf() public view returns (uint) {
|
| 394 |
+
return contractBalance;
|
| 395 |
+
}
|
| 396 |
+
|
| 397 |
+
function addNewBetAmount(uint _tokenAmount)
|
| 398 |
+
public
|
| 399 |
+
onlyOwner
|
| 400 |
+
{
|
| 401 |
+
validTokenBet[_tokenAmount] = true;
|
| 402 |
+
}
|
| 403 |
+
|
| 404 |
+
|
| 405 |
+
function pauseGame() public onlyOwner {
|
| 406 |
+
gameActive = false;
|
| 407 |
+
}
|
| 408 |
+
|
| 409 |
+
|
| 410 |
+
function resumeGame() public onlyOwner {
|
| 411 |
+
gameActive = true;
|
| 412 |
+
}
|
| 413 |
+
|
| 414 |
+
|
| 415 |
+
function changeOwner(address _newOwner) public onlyOwner {
|
| 416 |
+
owner = _newOwner;
|
| 417 |
+
}
|
| 418 |
+
|
| 419 |
+
|
| 420 |
+
function changeBankroll(address _newBankroll) public onlyOwner {
|
| 421 |
+
bankroll = _newBankroll;
|
| 422 |
+
}
|
| 423 |
+
|
| 424 |
+
function divertDividendsToBankroll()
|
| 425 |
+
public
|
| 426 |
+
onlyOwner
|
| 427 |
+
{
|
| 428 |
+
bankroll.transfer(address(this).balance);
|
| 429 |
+
}
|
| 430 |
+
|
| 431 |
+
|
| 432 |
+
function _zthToken(address _tokenContract) private view returns (bool) {
|
| 433 |
+
return _tokenContract == ZTHTKNADDR;
|
| 434 |
+
}
|
| 435 |
+
}
|
| 436 |
+
|
| 437 |
+
|
| 438 |
+
|
| 439 |
+
|
| 440 |
+
library SafeMath {
|
| 441 |
+
|
| 442 |
+
|
| 443 |
+
function mul(uint a, uint b) internal pure returns (uint) {
|
| 444 |
+
if (a == 0) {
|
| 445 |
+
return 0;
|
| 446 |
+
}
|
| 447 |
+
uint c = a * b;
|
| 448 |
+
assert(c / a == b);
|
| 449 |
+
return c;
|
| 450 |
+
}
|
| 451 |
+
|
| 452 |
+
|
| 453 |
+
function div(uint a, uint b) internal pure returns (uint) {
|
| 454 |
+
|
| 455 |
+
uint c = a / b;
|
| 456 |
+
|
| 457 |
+
return c;
|
| 458 |
+
}
|
| 459 |
+
|
| 460 |
+
|
| 461 |
+
function sub(uint a, uint b) internal pure returns (uint) {
|
| 462 |
+
assert(b <= a);
|
| 463 |
+
return a - b;
|
| 464 |
+
}
|
| 465 |
+
|
| 466 |
+
|
| 467 |
+
function add(uint a, uint b) internal pure returns (uint) {
|
| 468 |
+
uint c = a + b;
|
| 469 |
+
assert(c >= a);
|
| 470 |
+
return c;
|
| 471 |
+
}
|
| 472 |
+
}
|
smart_contract_dataset/block number dependency/1482.sol
ADDED
|
@@ -0,0 +1,222 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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
return c;
|
| 17 |
+
}
|
| 18 |
+
|
| 19 |
+
|
| 20 |
+
function div(uint256 a, uint256 b) internal pure returns (uint256) {
|
| 21 |
+
|
| 22 |
+
|
| 23 |
+
|
| 24 |
+
return a / b;
|
| 25 |
+
}
|
| 26 |
+
|
| 27 |
+
|
| 28 |
+
function sub(uint256 a, uint256 b) internal pure returns (uint256) {
|
| 29 |
+
assert(b <= a);
|
| 30 |
+
return a - b;
|
| 31 |
+
}
|
| 32 |
+
|
| 33 |
+
|
| 34 |
+
function add(uint256 a, uint256 b) internal pure returns (uint256 c) {
|
| 35 |
+
c = a + b;
|
| 36 |
+
assert(c >= a);
|
| 37 |
+
return c;
|
| 38 |
+
}
|
| 39 |
+
}
|
| 40 |
+
|
| 41 |
+
contract Ownable {
|
| 42 |
+
address public owner;
|
| 43 |
+
|
| 44 |
+
|
| 45 |
+
event OwnershipRenounced(address indexed previousOwner);
|
| 46 |
+
event OwnershipTransferred(
|
| 47 |
+
address indexed previousOwner,
|
| 48 |
+
address indexed newOwner
|
| 49 |
+
);
|
| 50 |
+
|
| 51 |
+
|
| 52 |
+
|
| 53 |
+
constructor() public {
|
| 54 |
+
owner = msg.sender;
|
| 55 |
+
}
|
| 56 |
+
|
| 57 |
+
|
| 58 |
+
modifier onlyOwner() {
|
| 59 |
+
require(msg.sender == owner);
|
| 60 |
+
_;
|
| 61 |
+
}
|
| 62 |
+
|
| 63 |
+
|
| 64 |
+
function renounceOwnership() public onlyOwner {
|
| 65 |
+
emit OwnershipRenounced(owner);
|
| 66 |
+
owner = address(0);
|
| 67 |
+
}
|
| 68 |
+
|
| 69 |
+
|
| 70 |
+
function transferOwnership(address _newOwner) public onlyOwner {
|
| 71 |
+
_transferOwnership(_newOwner);
|
| 72 |
+
}
|
| 73 |
+
|
| 74 |
+
|
| 75 |
+
function _transferOwnership(address _newOwner) internal {
|
| 76 |
+
require(_newOwner != address(0));
|
| 77 |
+
emit OwnershipTransferred(owner, _newOwner);
|
| 78 |
+
owner = _newOwner;
|
| 79 |
+
}
|
| 80 |
+
}
|
| 81 |
+
|
| 82 |
+
contract Claimable is Ownable {
|
| 83 |
+
address public pendingOwner;
|
| 84 |
+
|
| 85 |
+
|
| 86 |
+
modifier onlyPendingOwner() {
|
| 87 |
+
require(msg.sender == pendingOwner);
|
| 88 |
+
_;
|
| 89 |
+
}
|
| 90 |
+
|
| 91 |
+
|
| 92 |
+
function transferOwnership(address newOwner) onlyOwner public {
|
| 93 |
+
pendingOwner = newOwner;
|
| 94 |
+
}
|
| 95 |
+
|
| 96 |
+
|
| 97 |
+
function claimOwnership() onlyPendingOwner public {
|
| 98 |
+
emit OwnershipTransferred(owner, pendingOwner);
|
| 99 |
+
owner = pendingOwner;
|
| 100 |
+
pendingOwner = address(0);
|
| 101 |
+
}
|
| 102 |
+
}
|
| 103 |
+
|
| 104 |
+
contract SimpleFlyDropToken is Claimable {
|
| 105 |
+
using SafeMath for uint256;
|
| 106 |
+
|
| 107 |
+
ERC20 internal erc20tk;
|
| 108 |
+
|
| 109 |
+
function setToken(address _token) onlyOwner public {
|
| 110 |
+
require(_token != address(0));
|
| 111 |
+
erc20tk = ERC20(_token);
|
| 112 |
+
}
|
| 113 |
+
|
| 114 |
+
|
| 115 |
+
function multiSend(address[] _destAddrs, uint256[] _values) onlyOwner public returns (uint256) {
|
| 116 |
+
require(_destAddrs.length == _values.length);
|
| 117 |
+
|
| 118 |
+
uint256 i = 0;
|
| 119 |
+
for (; i < _destAddrs.length; i = i.add(1)) {
|
| 120 |
+
if (!erc20tk.transfer(_destAddrs[i], _values[i])) {
|
| 121 |
+
break;
|
| 122 |
+
}
|
| 123 |
+
}
|
| 124 |
+
|
| 125 |
+
return (i);
|
| 126 |
+
}
|
| 127 |
+
}
|
| 128 |
+
|
| 129 |
+
contract DelayedClaimable is Claimable {
|
| 130 |
+
|
| 131 |
+
uint256 public end;
|
| 132 |
+
uint256 public start;
|
| 133 |
+
|
| 134 |
+
|
| 135 |
+
function setLimits(uint256 _start, uint256 _end) onlyOwner public {
|
| 136 |
+
require(_start <= _end);
|
| 137 |
+
end = _end;
|
| 138 |
+
start = _start;
|
| 139 |
+
}
|
| 140 |
+
|
| 141 |
+
|
| 142 |
+
function claimOwnership() onlyPendingOwner public {
|
| 143 |
+
require((block.number <= end) && (block.number >= start));
|
| 144 |
+
emit OwnershipTransferred(owner, pendingOwner);
|
| 145 |
+
owner = pendingOwner;
|
| 146 |
+
pendingOwner = address(0);
|
| 147 |
+
end = 0;
|
| 148 |
+
}
|
| 149 |
+
|
| 150 |
+
}
|
| 151 |
+
|
| 152 |
+
contract FlyDropTokenMgr is DelayedClaimable {
|
| 153 |
+
using SafeMath for uint256;
|
| 154 |
+
|
| 155 |
+
address[] dropTokenAddrs;
|
| 156 |
+
SimpleFlyDropToken currentDropTokenContract;
|
| 157 |
+
|
| 158 |
+
|
| 159 |
+
|
| 160 |
+
function prepare(uint256 _rand,
|
| 161 |
+
address _from,
|
| 162 |
+
address _token,
|
| 163 |
+
uint256 _value) onlyOwner public returns (bool) {
|
| 164 |
+
require(_token != address(0));
|
| 165 |
+
require(_from != address(0));
|
| 166 |
+
require(_rand > 0);
|
| 167 |
+
|
| 168 |
+
if (ERC20(_token).allowance(_from, this) < _value) {
|
| 169 |
+
return false;
|
| 170 |
+
}
|
| 171 |
+
|
| 172 |
+
if (_rand > dropTokenAddrs.length) {
|
| 173 |
+
SimpleFlyDropToken dropTokenContract = new SimpleFlyDropToken();
|
| 174 |
+
dropTokenAddrs.push(address(dropTokenContract));
|
| 175 |
+
currentDropTokenContract = dropTokenContract;
|
| 176 |
+
} else {
|
| 177 |
+
currentDropTokenContract = SimpleFlyDropToken(dropTokenAddrs[_rand.sub(1)]);
|
| 178 |
+
}
|
| 179 |
+
|
| 180 |
+
currentDropTokenContract.setToken(_token);
|
| 181 |
+
return ERC20(_token).transferFrom(_from, currentDropTokenContract, _value);
|
| 182 |
+
|
| 183 |
+
|
| 184 |
+
|
| 185 |
+
}
|
| 186 |
+
|
| 187 |
+
|
| 188 |
+
|
| 189 |
+
|
| 190 |
+
|
| 191 |
+
|
| 192 |
+
|
| 193 |
+
|
| 194 |
+
|
| 195 |
+
function flyDrop(address[] _destAddrs, uint256[] _values) onlyOwner public returns (uint256) {
|
| 196 |
+
require(address(currentDropTokenContract) != address(0));
|
| 197 |
+
return currentDropTokenContract.multiSend(_destAddrs, _values);
|
| 198 |
+
}
|
| 199 |
+
|
| 200 |
+
}
|
| 201 |
+
|
| 202 |
+
contract ERC20Basic {
|
| 203 |
+
function totalSupply() public view returns (uint256);
|
| 204 |
+
function balanceOf(address who) public view returns (uint256);
|
| 205 |
+
function transfer(address to, uint256 value) public returns (bool);
|
| 206 |
+
event Transfer(address indexed from, address indexed to, uint256 value);
|
| 207 |
+
}
|
| 208 |
+
|
| 209 |
+
contract ERC20 is ERC20Basic {
|
| 210 |
+
function allowance(address owner, address spender)
|
| 211 |
+
public view returns (uint256);
|
| 212 |
+
|
| 213 |
+
function transferFrom(address from, address to, uint256 value)
|
| 214 |
+
public returns (bool);
|
| 215 |
+
|
| 216 |
+
function approve(address spender, uint256 value) public returns (bool);
|
| 217 |
+
event Approval(
|
| 218 |
+
address indexed owner,
|
| 219 |
+
address indexed spender,
|
| 220 |
+
uint256 value
|
| 221 |
+
);
|
| 222 |
+
}
|
smart_contract_dataset/block number dependency/1546.sol
ADDED
|
@@ -0,0 +1,472 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
pragma solidity ^0.4.24;
|
| 2 |
+
|
| 3 |
+
|
| 4 |
+
|
| 5 |
+
contract ZTHReceivingContract {
|
| 6 |
+
function tokenFallback(address _from, uint _value, bytes _data) public returns (bool);
|
| 7 |
+
}
|
| 8 |
+
|
| 9 |
+
contract ZTHInterface {
|
| 10 |
+
function transfer(address _to, uint _value) public returns (bool);
|
| 11 |
+
function approve(address spender, uint tokens) public returns (bool);
|
| 12 |
+
}
|
| 13 |
+
|
| 14 |
+
contract Zlots is ZTHReceivingContract {
|
| 15 |
+
using SafeMath for uint;
|
| 16 |
+
|
| 17 |
+
address private owner;
|
| 18 |
+
address private bankroll;
|
| 19 |
+
|
| 20 |
+
|
| 21 |
+
uint totalSpins;
|
| 22 |
+
uint totalZTHWagered;
|
| 23 |
+
|
| 24 |
+
|
| 25 |
+
uint contractBalance;
|
| 26 |
+
|
| 27 |
+
|
| 28 |
+
bool public gameActive;
|
| 29 |
+
|
| 30 |
+
address private ZTHTKNADDR;
|
| 31 |
+
address private ZTHBANKROLL;
|
| 32 |
+
ZTHInterface private ZTHTKN;
|
| 33 |
+
|
| 34 |
+
mapping (uint => bool) validTokenBet;
|
| 35 |
+
|
| 36 |
+
|
| 37 |
+
event HouseRetrievedTake(
|
| 38 |
+
uint timeTaken,
|
| 39 |
+
uint tokensWithdrawn
|
| 40 |
+
);
|
| 41 |
+
|
| 42 |
+
|
| 43 |
+
event TokensWagered(
|
| 44 |
+
address _wagerer,
|
| 45 |
+
uint _wagered
|
| 46 |
+
);
|
| 47 |
+
|
| 48 |
+
event LogResult(
|
| 49 |
+
address _wagerer,
|
| 50 |
+
uint _result,
|
| 51 |
+
uint _profit,
|
| 52 |
+
uint _wagered,
|
| 53 |
+
uint _category,
|
| 54 |
+
bool _win
|
| 55 |
+
);
|
| 56 |
+
|
| 57 |
+
|
| 58 |
+
event Loss(address _wagerer, uint _block);
|
| 59 |
+
event ThreeMoonJackpot(address _wagerer, uint _block);
|
| 60 |
+
event TwoMoonPrize(address _wagerer, uint _block);
|
| 61 |
+
event ZTHJackpot(address _wagerer, uint _block);
|
| 62 |
+
event ThreeZSymbols(address _wagerer, uint _block);
|
| 63 |
+
event ThreeTSymbols(address _wagerer, uint _block);
|
| 64 |
+
event ThreeHSymbols(address _wagerer, uint _block);
|
| 65 |
+
event ThreeEtherIcons(address _wagerer, uint _block);
|
| 66 |
+
event ThreeGreenPyramids(address _wagerer, uint _block);
|
| 67 |
+
event ThreeGoldPyramids(address _wagerer, uint _block);
|
| 68 |
+
event ThreeWhitePyramids(address _wagerer, uint _block);
|
| 69 |
+
event OneMoonPrize(address _wagerer, uint _block);
|
| 70 |
+
event OneOfEachPyramidPrize(address _wagerer, uint _block);
|
| 71 |
+
event TwoZSymbols(address _wagerer, uint _block);
|
| 72 |
+
event TwoTSymbols(address _wagerer, uint _block);
|
| 73 |
+
event TwoHSymbols(address _wagerer, uint _block);
|
| 74 |
+
event TwoEtherIcons(address _wagerer, uint _block);
|
| 75 |
+
event TwoGreenPyramids(address _wagerer, uint _block);
|
| 76 |
+
event TwoGoldPyramids(address _wagerer, uint _block);
|
| 77 |
+
event TwoWhitePyramids(address _wagerer, uint _block);
|
| 78 |
+
|
| 79 |
+
event SpinConcluded(address _wagerer, uint _block);
|
| 80 |
+
|
| 81 |
+
modifier onlyOwner {
|
| 82 |
+
require(msg.sender == owner);
|
| 83 |
+
_;
|
| 84 |
+
}
|
| 85 |
+
|
| 86 |
+
modifier onlyBankroll {
|
| 87 |
+
require(msg.sender == bankroll);
|
| 88 |
+
_;
|
| 89 |
+
}
|
| 90 |
+
|
| 91 |
+
modifier onlyOwnerOrBankroll {
|
| 92 |
+
require(msg.sender == owner || msg.sender == bankroll);
|
| 93 |
+
_;
|
| 94 |
+
}
|
| 95 |
+
|
| 96 |
+
|
| 97 |
+
modifier gameIsActive {
|
| 98 |
+
require(gameActive == true);
|
| 99 |
+
_;
|
| 100 |
+
}
|
| 101 |
+
|
| 102 |
+
constructor(address ZethrAddress, address BankrollAddress) public {
|
| 103 |
+
|
| 104 |
+
|
| 105 |
+
ZTHTKNADDR = ZethrAddress;
|
| 106 |
+
ZTHBANKROLL = BankrollAddress;
|
| 107 |
+
|
| 108 |
+
|
| 109 |
+
owner = msg.sender;
|
| 110 |
+
bankroll = ZTHBANKROLL;
|
| 111 |
+
|
| 112 |
+
|
| 113 |
+
ZTHTKN = ZTHInterface(ZTHTKNADDR);
|
| 114 |
+
ZTHTKN.approve(ZTHBANKROLL, 2**256 - 1);
|
| 115 |
+
|
| 116 |
+
|
| 117 |
+
ZTHTKN.approve(owner, 2**256 - 1);
|
| 118 |
+
|
| 119 |
+
|
| 120 |
+
validTokenBet[5e18] = true;
|
| 121 |
+
validTokenBet[10e18] = true;
|
| 122 |
+
validTokenBet[25e18] = true;
|
| 123 |
+
validTokenBet[50e18] = true;
|
| 124 |
+
|
| 125 |
+
gameActive = true;
|
| 126 |
+
}
|
| 127 |
+
|
| 128 |
+
|
| 129 |
+
function() public payable { }
|
| 130 |
+
|
| 131 |
+
|
| 132 |
+
struct TKN { address sender; uint value; }
|
| 133 |
+
function tokenFallback(address _from, uint _value, bytes ) public returns (bool){
|
| 134 |
+
if (_from == bankroll) {
|
| 135 |
+
|
| 136 |
+
contractBalance = contractBalance.add(_value);
|
| 137 |
+
return true;
|
| 138 |
+
} else {
|
| 139 |
+
TKN memory _tkn;
|
| 140 |
+
_tkn.sender = _from;
|
| 141 |
+
_tkn.value = _value;
|
| 142 |
+
_spinTokens(_tkn);
|
| 143 |
+
return true;
|
| 144 |
+
}
|
| 145 |
+
}
|
| 146 |
+
|
| 147 |
+
struct playerSpin {
|
| 148 |
+
uint200 tokenValue;
|
| 149 |
+
uint56 blockn;
|
| 150 |
+
}
|
| 151 |
+
|
| 152 |
+
|
| 153 |
+
mapping(address => playerSpin) public playerSpins;
|
| 154 |
+
|
| 155 |
+
|
| 156 |
+
function _spinTokens(TKN _tkn) private {
|
| 157 |
+
|
| 158 |
+
require(gameActive);
|
| 159 |
+
require(_zthToken(msg.sender));
|
| 160 |
+
require(validTokenBet[_tkn.value]);
|
| 161 |
+
require(jackpotGuard(_tkn.value));
|
| 162 |
+
|
| 163 |
+
require(_tkn.value < ((2 ** 200) - 1));
|
| 164 |
+
require(block.number < ((2 ** 56) - 1));
|
| 165 |
+
|
| 166 |
+
address _customerAddress = _tkn.sender;
|
| 167 |
+
uint _wagered = _tkn.value;
|
| 168 |
+
|
| 169 |
+
playerSpin memory spin = playerSpins[_tkn.sender];
|
| 170 |
+
|
| 171 |
+
|
| 172 |
+
|
| 173 |
+
|
| 174 |
+
require(block.number != spin.blockn);
|
| 175 |
+
|
| 176 |
+
|
| 177 |
+
if (spin.blockn != 0) {
|
| 178 |
+
_finishSpin(_tkn.sender);
|
| 179 |
+
}
|
| 180 |
+
|
| 181 |
+
|
| 182 |
+
spin.blockn = uint56(block.number);
|
| 183 |
+
spin.tokenValue = uint200(_wagered);
|
| 184 |
+
|
| 185 |
+
|
| 186 |
+
playerSpins[_tkn.sender] = spin;
|
| 187 |
+
|
| 188 |
+
|
| 189 |
+
totalSpins += 1;
|
| 190 |
+
|
| 191 |
+
|
| 192 |
+
totalZTHWagered += _wagered;
|
| 193 |
+
|
| 194 |
+
emit TokensWagered(_customerAddress, _wagered);
|
| 195 |
+
|
| 196 |
+
}
|
| 197 |
+
|
| 198 |
+
|
| 199 |
+
function finishSpin() public
|
| 200 |
+
gameIsActive
|
| 201 |
+
returns (uint)
|
| 202 |
+
{
|
| 203 |
+
return _finishSpin(msg.sender);
|
| 204 |
+
}
|
| 205 |
+
|
| 206 |
+
|
| 207 |
+
function _finishSpin(address target)
|
| 208 |
+
private returns (uint)
|
| 209 |
+
{
|
| 210 |
+
playerSpin memory spin = playerSpins[target];
|
| 211 |
+
|
| 212 |
+
require(spin.tokenValue > 0);
|
| 213 |
+
require(spin.blockn != block.number);
|
| 214 |
+
|
| 215 |
+
uint profit = 0;
|
| 216 |
+
uint category = 0;
|
| 217 |
+
|
| 218 |
+
|
| 219 |
+
|
| 220 |
+
uint result;
|
| 221 |
+
if (block.number - spin.blockn > 255) {
|
| 222 |
+
result = 999999;
|
| 223 |
+
} else {
|
| 224 |
+
|
| 225 |
+
|
| 226 |
+
|
| 227 |
+
result = random(1000000, spin.blockn, target);
|
| 228 |
+
}
|
| 229 |
+
|
| 230 |
+
if (result > 476661) {
|
| 231 |
+
|
| 232 |
+
contractBalance = contractBalance.add(spin.tokenValue);
|
| 233 |
+
emit Loss(target, spin.blockn);
|
| 234 |
+
emit LogResult(target, result, profit, spin.tokenValue, category, false);
|
| 235 |
+
} else {
|
| 236 |
+
if (result < 1) {
|
| 237 |
+
|
| 238 |
+
profit = SafeMath.mul(spin.tokenValue, 500);
|
| 239 |
+
category = 1;
|
| 240 |
+
emit ThreeMoonJackpot(target, spin.blockn);
|
| 241 |
+
} else
|
| 242 |
+
if (result < 298) {
|
| 243 |
+
|
| 244 |
+
profit = SafeMath.mul(spin.tokenValue, 232);
|
| 245 |
+
category = 2;
|
| 246 |
+
emit TwoMoonPrize(target, spin.blockn);
|
| 247 |
+
} else
|
| 248 |
+
if (result < 3127) {
|
| 249 |
+
|
| 250 |
+
profit = SafeMath.div(SafeMath.mul(spin.tokenValue, 232), 10);
|
| 251 |
+
category = 3;
|
| 252 |
+
emit ZTHJackpot(target, spin.blockn);
|
| 253 |
+
|
| 254 |
+
} else
|
| 255 |
+
if (result < 5956) {
|
| 256 |
+
|
| 257 |
+
profit = SafeMath.mul(spin.tokenValue, 25);
|
| 258 |
+
category = 4;
|
| 259 |
+
emit ThreeZSymbols(target, spin.blockn);
|
| 260 |
+
} else
|
| 261 |
+
if (result < 8785) {
|
| 262 |
+
|
| 263 |
+
profit = SafeMath.mul(spin.tokenValue, 25);
|
| 264 |
+
category = 5;
|
| 265 |
+
emit ThreeTSymbols(target, spin.blockn);
|
| 266 |
+
} else
|
| 267 |
+
if (result < 11614) {
|
| 268 |
+
|
| 269 |
+
profit = SafeMath.mul(spin.tokenValue, 25);
|
| 270 |
+
category = 6;
|
| 271 |
+
emit ThreeHSymbols(target, spin.blockn);
|
| 272 |
+
} else
|
| 273 |
+
if (result < 14443) {
|
| 274 |
+
|
| 275 |
+
profit = SafeMath.mul(spin.tokenValue, 50);
|
| 276 |
+
category = 7;
|
| 277 |
+
emit ThreeEtherIcons(target, spin.blockn);
|
| 278 |
+
} else
|
| 279 |
+
if (result < 17272) {
|
| 280 |
+
|
| 281 |
+
profit = SafeMath.mul(spin.tokenValue, 40);
|
| 282 |
+
category = 8;
|
| 283 |
+
emit ThreeGreenPyramids(target, spin.blockn);
|
| 284 |
+
} else
|
| 285 |
+
if (result < 20101) {
|
| 286 |
+
|
| 287 |
+
profit = SafeMath.mul(spin.tokenValue, 20);
|
| 288 |
+
category = 9;
|
| 289 |
+
emit ThreeGoldPyramids(target, spin.blockn);
|
| 290 |
+
} else
|
| 291 |
+
if (result < 22929) {
|
| 292 |
+
|
| 293 |
+
profit = SafeMath.mul(spin.tokenValue, 20);
|
| 294 |
+
category = 10;
|
| 295 |
+
emit ThreeWhitePyramids(target, spin.blockn);
|
| 296 |
+
} else
|
| 297 |
+
if (result < 52332) {
|
| 298 |
+
|
| 299 |
+
profit = SafeMath.div(SafeMath.mul(spin.tokenValue, 125),10);
|
| 300 |
+
category = 11;
|
| 301 |
+
emit OneMoonPrize(target, spin.blockn);
|
| 302 |
+
} else
|
| 303 |
+
if (result < 120225) {
|
| 304 |
+
|
| 305 |
+
profit = SafeMath.div(SafeMath.mul(spin.tokenValue, 15),10);
|
| 306 |
+
category = 12;
|
| 307 |
+
emit OneOfEachPyramidPrize(target, spin.blockn);
|
| 308 |
+
} else
|
| 309 |
+
if (result < 171146) {
|
| 310 |
+
|
| 311 |
+
profit = SafeMath.div(SafeMath.mul(spin.tokenValue, 232),100);
|
| 312 |
+
category = 13;
|
| 313 |
+
emit TwoZSymbols(target, spin.blockn);
|
| 314 |
+
} else
|
| 315 |
+
if (result < 222067) {
|
| 316 |
+
|
| 317 |
+
profit = SafeMath.div(SafeMath.mul(spin.tokenValue, 232),100);
|
| 318 |
+
category = 14;
|
| 319 |
+
emit TwoTSymbols(target, spin.blockn);
|
| 320 |
+
} else
|
| 321 |
+
if (result < 272988) {
|
| 322 |
+
|
| 323 |
+
profit = SafeMath.div(SafeMath.mul(spin.tokenValue, 232),100);
|
| 324 |
+
category = 15;
|
| 325 |
+
emit TwoHSymbols(target, spin.blockn);
|
| 326 |
+
} else
|
| 327 |
+
if (result < 323909) {
|
| 328 |
+
|
| 329 |
+
profit = SafeMath.div(SafeMath.mul(spin.tokenValue, 375),100);
|
| 330 |
+
category = 16;
|
| 331 |
+
emit TwoEtherIcons(target, spin.blockn);
|
| 332 |
+
} else
|
| 333 |
+
if (result < 374830) {
|
| 334 |
+
|
| 335 |
+
profit = SafeMath.div(SafeMath.mul(spin.tokenValue, 35),10);
|
| 336 |
+
category = 17;
|
| 337 |
+
emit TwoGreenPyramids(target, spin.blockn);
|
| 338 |
+
} else
|
| 339 |
+
if (result < 425751) {
|
| 340 |
+
|
| 341 |
+
profit = SafeMath.div(SafeMath.mul(spin.tokenValue, 225),100);
|
| 342 |
+
category = 18;
|
| 343 |
+
emit TwoGoldPyramids(target, spin.blockn);
|
| 344 |
+
} else {
|
| 345 |
+
|
| 346 |
+
profit = SafeMath.mul(spin.tokenValue, 2);
|
| 347 |
+
category = 19;
|
| 348 |
+
emit TwoWhitePyramids(target, spin.blockn);
|
| 349 |
+
}
|
| 350 |
+
|
| 351 |
+
emit LogResult(target, result, profit, spin.tokenValue, category, true);
|
| 352 |
+
contractBalance = contractBalance.sub(profit);
|
| 353 |
+
ZTHTKN.transfer(target, profit);
|
| 354 |
+
}
|
| 355 |
+
|
| 356 |
+
|
| 357 |
+
playerSpins[target] = playerSpin(uint200(0), uint56(0));
|
| 358 |
+
emit SpinConcluded(target, spin.blockn);
|
| 359 |
+
return result;
|
| 360 |
+
}
|
| 361 |
+
|
| 362 |
+
|
| 363 |
+
|
| 364 |
+
|
| 365 |
+
|
| 366 |
+
function jackpotGuard(uint _wager)
|
| 367 |
+
private
|
| 368 |
+
view
|
| 369 |
+
returns (bool)
|
| 370 |
+
{
|
| 371 |
+
uint maxProfit = SafeMath.mul(_wager, 500);
|
| 372 |
+
uint ninetyContractBalance = SafeMath.mul(SafeMath.div(contractBalance, 10), 9);
|
| 373 |
+
return (maxProfit <= ninetyContractBalance);
|
| 374 |
+
}
|
| 375 |
+
|
| 376 |
+
|
| 377 |
+
|
| 378 |
+
function maxRandom(uint blockn, address entropy) private view returns (uint256 randomNumber) {
|
| 379 |
+
return uint256(keccak256(
|
| 380 |
+
abi.encodePacked(
|
| 381 |
+
address(this),
|
| 382 |
+
blockhash(blockn),
|
| 383 |
+
entropy)
|
| 384 |
+
));
|
| 385 |
+
}
|
| 386 |
+
|
| 387 |
+
|
| 388 |
+
function random(uint256 upper, uint256 blockn, address entropy) internal view returns (uint256 randomNumber) {
|
| 389 |
+
return maxRandom(blockn, entropy) % upper;
|
| 390 |
+
}
|
| 391 |
+
|
| 392 |
+
|
| 393 |
+
function balanceOf() public view returns (uint) {
|
| 394 |
+
return contractBalance;
|
| 395 |
+
}
|
| 396 |
+
|
| 397 |
+
function addNewBetAmount(uint _tokenAmount)
|
| 398 |
+
public
|
| 399 |
+
onlyOwner
|
| 400 |
+
{
|
| 401 |
+
validTokenBet[_tokenAmount] = true;
|
| 402 |
+
}
|
| 403 |
+
|
| 404 |
+
|
| 405 |
+
function pauseGame() public onlyOwner {
|
| 406 |
+
gameActive = false;
|
| 407 |
+
}
|
| 408 |
+
|
| 409 |
+
|
| 410 |
+
function resumeGame() public onlyOwner {
|
| 411 |
+
gameActive = true;
|
| 412 |
+
}
|
| 413 |
+
|
| 414 |
+
|
| 415 |
+
function changeOwner(address _newOwner) public onlyOwner {
|
| 416 |
+
owner = _newOwner;
|
| 417 |
+
}
|
| 418 |
+
|
| 419 |
+
|
| 420 |
+
function changeBankroll(address _newBankroll) public onlyOwner {
|
| 421 |
+
bankroll = _newBankroll;
|
| 422 |
+
}
|
| 423 |
+
|
| 424 |
+
function divertDividendsToBankroll()
|
| 425 |
+
public
|
| 426 |
+
onlyOwner
|
| 427 |
+
{
|
| 428 |
+
bankroll.transfer(address(this).balance);
|
| 429 |
+
}
|
| 430 |
+
|
| 431 |
+
|
| 432 |
+
function _zthToken(address _tokenContract) private view returns (bool) {
|
| 433 |
+
return _tokenContract == ZTHTKNADDR;
|
| 434 |
+
}
|
| 435 |
+
}
|
| 436 |
+
|
| 437 |
+
|
| 438 |
+
|
| 439 |
+
|
| 440 |
+
library SafeMath {
|
| 441 |
+
|
| 442 |
+
|
| 443 |
+
function mul(uint a, uint b) internal pure returns (uint) {
|
| 444 |
+
if (a == 0) {
|
| 445 |
+
return 0;
|
| 446 |
+
}
|
| 447 |
+
uint c = a * b;
|
| 448 |
+
assert(c / a == b);
|
| 449 |
+
return c;
|
| 450 |
+
}
|
| 451 |
+
|
| 452 |
+
|
| 453 |
+
function div(uint a, uint b) internal pure returns (uint) {
|
| 454 |
+
|
| 455 |
+
uint c = a / b;
|
| 456 |
+
|
| 457 |
+
return c;
|
| 458 |
+
}
|
| 459 |
+
|
| 460 |
+
|
| 461 |
+
function sub(uint a, uint b) internal pure returns (uint) {
|
| 462 |
+
assert(b <= a);
|
| 463 |
+
return a - b;
|
| 464 |
+
}
|
| 465 |
+
|
| 466 |
+
|
| 467 |
+
function add(uint a, uint b) internal pure returns (uint) {
|
| 468 |
+
uint c = a + b;
|
| 469 |
+
assert(c >= a);
|
| 470 |
+
return c;
|
| 471 |
+
}
|
| 472 |
+
}
|
smart_contract_dataset/block number dependency/1567.sol
ADDED
|
@@ -0,0 +1,395 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
pragma solidity ^0.4.24;
|
| 2 |
+
|
| 3 |
+
contract Ownable {
|
| 4 |
+
address public owner;
|
| 5 |
+
|
| 6 |
+
|
| 7 |
+
constructor() public {
|
| 8 |
+
owner = msg.sender;
|
| 9 |
+
}
|
| 10 |
+
|
| 11 |
+
|
| 12 |
+
|
| 13 |
+
modifier onlyOwner() {
|
| 14 |
+
require(msg.sender == owner);
|
| 15 |
+
_;
|
| 16 |
+
}
|
| 17 |
+
|
| 18 |
+
|
| 19 |
+
|
| 20 |
+
function transferOwnership(address newOwner) onlyOwner public {
|
| 21 |
+
require(newOwner != address(0));
|
| 22 |
+
owner = newOwner;
|
| 23 |
+
}
|
| 24 |
+
|
| 25 |
+
}
|
| 26 |
+
|
| 27 |
+
contract GuessEthEvents{
|
| 28 |
+
event drawLog(uint,uint,uint);
|
| 29 |
+
|
| 30 |
+
event guessEvt(
|
| 31 |
+
address indexed playerAddr,
|
| 32 |
+
uint[] numbers, uint amount
|
| 33 |
+
);
|
| 34 |
+
event winnersEvt(
|
| 35 |
+
uint blockNumber,
|
| 36 |
+
address indexed playerAddr,
|
| 37 |
+
uint amount,
|
| 38 |
+
uint winAmount
|
| 39 |
+
);
|
| 40 |
+
event withdrawEvt(
|
| 41 |
+
address indexed to,
|
| 42 |
+
uint256 value
|
| 43 |
+
);
|
| 44 |
+
event drawEvt(
|
| 45 |
+
uint indexed blocknumberr,
|
| 46 |
+
uint number
|
| 47 |
+
);
|
| 48 |
+
|
| 49 |
+
event sponseEvt(
|
| 50 |
+
address indexed addr,
|
| 51 |
+
uint amount
|
| 52 |
+
);
|
| 53 |
+
|
| 54 |
+
event pauseGameEvt(
|
| 55 |
+
bool pause
|
| 56 |
+
);
|
| 57 |
+
event setOddsEvt(
|
| 58 |
+
uint odds
|
| 59 |
+
);
|
| 60 |
+
|
| 61 |
+
}
|
| 62 |
+
|
| 63 |
+
contract GuessEth is Ownable,GuessEthEvents{
|
| 64 |
+
using SafeMath for uint;
|
| 65 |
+
|
| 66 |
+
|
| 67 |
+
|
| 68 |
+
struct bnumber{
|
| 69 |
+
address addr;
|
| 70 |
+
uint number;
|
| 71 |
+
uint value;
|
| 72 |
+
int8 result;
|
| 73 |
+
uint prize;
|
| 74 |
+
}
|
| 75 |
+
mapping(uint => bnumber[]) public bets;
|
| 76 |
+
mapping(uint => address) public betNumber;
|
| 77 |
+
|
| 78 |
+
|
| 79 |
+
mapping(address => uint[]) private playerBetBNumber;
|
| 80 |
+
|
| 81 |
+
|
| 82 |
+
struct winner{
|
| 83 |
+
bool result;
|
| 84 |
+
uint prize;
|
| 85 |
+
}
|
| 86 |
+
|
| 87 |
+
mapping(uint => winner[]) private winners;
|
| 88 |
+
mapping(uint => uint) private winResult;
|
| 89 |
+
|
| 90 |
+
address private wallet1;
|
| 91 |
+
address private wallet2;
|
| 92 |
+
|
| 93 |
+
uint private predictBlockInterval=3;
|
| 94 |
+
uint public odds=45;
|
| 95 |
+
uint public minBetVal=1 finney;
|
| 96 |
+
uint public blockInterval=500;
|
| 97 |
+
uint public curOpenBNumber=0;
|
| 98 |
+
uint public numberRange=100;
|
| 99 |
+
|
| 100 |
+
bool public gamePaused=false;
|
| 101 |
+
|
| 102 |
+
|
| 103 |
+
|
| 104 |
+
mapping(address => uint) Sponsors;
|
| 105 |
+
uint public balanceOfSPS=0;
|
| 106 |
+
address[] public SponsorAddresses;
|
| 107 |
+
|
| 108 |
+
uint reservefund=30 ether;
|
| 109 |
+
|
| 110 |
+
|
| 111 |
+
|
| 112 |
+
modifier isHuman() {
|
| 113 |
+
address _addr = msg.sender;
|
| 114 |
+
uint256 _codeLength;
|
| 115 |
+
|
| 116 |
+
assembly {_codeLength := extcodesize(_addr)}
|
| 117 |
+
require(_codeLength == 0, "sorry humans only");
|
| 118 |
+
_;
|
| 119 |
+
}
|
| 120 |
+
|
| 121 |
+
constructor(address _wallet1,address _wallet2) public{
|
| 122 |
+
wallet1=_wallet1;
|
| 123 |
+
wallet2=_wallet2;
|
| 124 |
+
|
| 125 |
+
curOpenBNumber=blockInterval*(block.number.div(blockInterval));
|
| 126 |
+
}
|
| 127 |
+
|
| 128 |
+
function pauseGame(bool _status) public onlyOwner returns(bool){
|
| 129 |
+
gamePaused=_status;
|
| 130 |
+
emit pauseGameEvt(_status);
|
| 131 |
+
}
|
| 132 |
+
|
| 133 |
+
function setOdds(uint _odds) isHuman() public onlyOwner returns(bool){
|
| 134 |
+
odds = _odds;
|
| 135 |
+
emit setOddsEvt(_odds);
|
| 136 |
+
}
|
| 137 |
+
function setReservefund(uint _reservefund) isHuman() public onlyOwner returns(bool){
|
| 138 |
+
reservefund = _reservefund * 1 ether;
|
| 139 |
+
}
|
| 140 |
+
|
| 141 |
+
function getTargetBNumber() view isHuman() public returns(uint){
|
| 142 |
+
uint n;
|
| 143 |
+
n=blockInterval*(predictBlockInterval + block.number/blockInterval);
|
| 144 |
+
return n;
|
| 145 |
+
}
|
| 146 |
+
|
| 147 |
+
function guess(uint[] _numbers) payable isHuman() public returns(uint){
|
| 148 |
+
require(msg.value >= _numbers.length.mul(minBetVal));
|
| 149 |
+
|
| 150 |
+
uint n=blockInterval*(predictBlockInterval + block.number/blockInterval);
|
| 151 |
+
|
| 152 |
+
for(uint _i=0;_i < _numbers.length;_i++){
|
| 153 |
+
bnumber memory b;
|
| 154 |
+
|
| 155 |
+
b.addr=msg.sender;
|
| 156 |
+
b.number=_numbers[_i];
|
| 157 |
+
b.value=msg.value/_numbers.length;
|
| 158 |
+
b.result=-1;
|
| 159 |
+
|
| 160 |
+
bets[n].push(b);
|
| 161 |
+
}
|
| 162 |
+
|
| 163 |
+
|
| 164 |
+
if(utils.inArray(playerBetBNumber[msg.sender],n)==false){
|
| 165 |
+
playerBetBNumber[msg.sender].push(n);
|
| 166 |
+
}
|
| 167 |
+
|
| 168 |
+
emit guessEvt(msg.sender,_numbers, msg.value);
|
| 169 |
+
|
| 170 |
+
return _numbers.length;
|
| 171 |
+
}
|
| 172 |
+
|
| 173 |
+
|
| 174 |
+
function getPlayerGuessNumbers() view public returns (uint[],uint[],uint256[],int8[],uint[]){
|
| 175 |
+
uint _c=0;
|
| 176 |
+
uint _i=0;
|
| 177 |
+
uint _j=0;
|
| 178 |
+
uint _bnumber;
|
| 179 |
+
uint limitRows=100;
|
| 180 |
+
|
| 181 |
+
while(_i < playerBetBNumber[msg.sender].length){
|
| 182 |
+
_bnumber=playerBetBNumber[msg.sender][_i];
|
| 183 |
+
for(_j=0 ; _j < bets[_bnumber].length && _c < limitRows ; _j++){
|
| 184 |
+
if(msg.sender==bets[_bnumber][_j].addr){
|
| 185 |
+
_c++;
|
| 186 |
+
}
|
| 187 |
+
}
|
| 188 |
+
_i++;
|
| 189 |
+
}
|
| 190 |
+
|
| 191 |
+
uint[] memory _blockNumbers=new uint[](_c);
|
| 192 |
+
uint[] memory _numbers=new uint[](_c);
|
| 193 |
+
uint[] memory _values=new uint[](_c);
|
| 194 |
+
int8[] memory _result=new int8[](_c);
|
| 195 |
+
uint[] memory _prize=new uint[](_c);
|
| 196 |
+
|
| 197 |
+
if(_c<=0){
|
| 198 |
+
return(_blockNumbers,_numbers,_values,_result,_prize);
|
| 199 |
+
}
|
| 200 |
+
|
| 201 |
+
|
| 202 |
+
|
| 203 |
+
uint _count=0;
|
| 204 |
+
for(_i=0 ; _i < playerBetBNumber[msg.sender].length ; _i++){
|
| 205 |
+
_bnumber=playerBetBNumber[msg.sender][_i];
|
| 206 |
+
|
| 207 |
+
for(_j=0 ; _j < bets[_bnumber].length && _count < limitRows ; _j++){
|
| 208 |
+
if(bets[_bnumber][_j].addr == msg.sender){
|
| 209 |
+
_blockNumbers[_count] = _bnumber;
|
| 210 |
+
_numbers[_count] = bets[_bnumber][_j].number;
|
| 211 |
+
_values[_count] = bets[_bnumber][_j].value;
|
| 212 |
+
_result[_count] = bets[_bnumber][_j].result;
|
| 213 |
+
_prize[_count] = bets[_bnumber][_j].prize;
|
| 214 |
+
|
| 215 |
+
_count++;
|
| 216 |
+
}
|
| 217 |
+
}
|
| 218 |
+
}
|
| 219 |
+
|
| 220 |
+
|
| 221 |
+
return(_blockNumbers,_numbers,_values,_result,_prize);
|
| 222 |
+
}
|
| 223 |
+
|
| 224 |
+
|
| 225 |
+
function draw(uint _blockNumber,uint _blockTimestamp) public onlyOwner returns (uint){
|
| 226 |
+
require(block.number >= curOpenBNumber + blockInterval);
|
| 227 |
+
|
| 228 |
+
|
| 229 |
+
curOpenBNumber=_blockNumber;
|
| 230 |
+
uint result=_blockTimestamp % numberRange;
|
| 231 |
+
winResult[_blockNumber]=result;
|
| 232 |
+
|
| 233 |
+
for(uint _i=0;_i < bets[_blockNumber].length;_i++){
|
| 234 |
+
|
| 235 |
+
|
| 236 |
+
|
| 237 |
+
if(bets[_blockNumber][_i].number==result){
|
| 238 |
+
bets[_blockNumber][_i].result = 1;
|
| 239 |
+
bets[_blockNumber][_i].prize = bets[_blockNumber][_i].value * odds;
|
| 240 |
+
|
| 241 |
+
emit winnersEvt(_blockNumber,bets[_blockNumber][_i].addr,bets[_blockNumber][_i].value,bets[_blockNumber][_i].prize);
|
| 242 |
+
|
| 243 |
+
withdraw(bets[_blockNumber][_i].addr,bets[_blockNumber][_i].prize);
|
| 244 |
+
|
| 245 |
+
}else{
|
| 246 |
+
bets[_blockNumber][_i].result = 0;
|
| 247 |
+
bets[_blockNumber][_i].prize = 0;
|
| 248 |
+
}
|
| 249 |
+
}
|
| 250 |
+
|
| 251 |
+
emit drawEvt(_blockNumber,curOpenBNumber);
|
| 252 |
+
|
| 253 |
+
return result;
|
| 254 |
+
}
|
| 255 |
+
|
| 256 |
+
function getWinners(uint _blockNumber) view public returns(address[],uint[]){
|
| 257 |
+
uint _count=winners[_blockNumber].length;
|
| 258 |
+
|
| 259 |
+
address[] memory _addresses = new address[](_count);
|
| 260 |
+
uint[] memory _prize = new uint[](_count);
|
| 261 |
+
|
| 262 |
+
uint _i=0;
|
| 263 |
+
for(_i=0;_i<_count;_i++){
|
| 264 |
+
|
| 265 |
+
_prize[_i] = winners[_blockNumber][_i].prize;
|
| 266 |
+
}
|
| 267 |
+
|
| 268 |
+
return (_addresses,_prize);
|
| 269 |
+
}
|
| 270 |
+
|
| 271 |
+
function getWinResults(uint _blockNumber) view public returns(uint){
|
| 272 |
+
return winResult[_blockNumber];
|
| 273 |
+
}
|
| 274 |
+
|
| 275 |
+
function withdraw(address _to,uint amount) public onlyOwner returns(bool){
|
| 276 |
+
require(address(this).balance.sub(amount) > 0);
|
| 277 |
+
_to.transfer(amount);
|
| 278 |
+
|
| 279 |
+
emit withdrawEvt(_to,amount);
|
| 280 |
+
return true;
|
| 281 |
+
}
|
| 282 |
+
|
| 283 |
+
|
| 284 |
+
function invest() isHuman payable public returns(uint){
|
| 285 |
+
require(msg.value >= 0.1 ether,"Minima amoun:0.1 ether");
|
| 286 |
+
|
| 287 |
+
Sponsors[msg.sender] = Sponsors[msg.sender].add(msg.value);
|
| 288 |
+
balanceOfSPS = balanceOfSPS.add(msg.value);
|
| 289 |
+
|
| 290 |
+
if(!utils.inArray(SponsorAddresses,msg.sender)){
|
| 291 |
+
SponsorAddresses.push(msg.sender);
|
| 292 |
+
emit sponseEvt(msg.sender,msg.value);
|
| 293 |
+
}
|
| 294 |
+
|
| 295 |
+
return Sponsors[msg.sender];
|
| 296 |
+
}
|
| 297 |
+
|
| 298 |
+
function distribute() public onlyOwner{
|
| 299 |
+
if(address(this).balance < reservefund){
|
| 300 |
+
return;
|
| 301 |
+
}
|
| 302 |
+
|
| 303 |
+
uint availableProfits=address(this).balance.sub(reservefund);
|
| 304 |
+
uint prft1=availableProfits.mul(3 ether).div(10 ether);
|
| 305 |
+
uint prft2=availableProfits.sub(prft1);
|
| 306 |
+
|
| 307 |
+
uint _val=0;
|
| 308 |
+
uint _i=0;
|
| 309 |
+
|
| 310 |
+
for(_i=0;_i<SponsorAddresses.length;_i++){
|
| 311 |
+
_val = (prft1 * Sponsors[SponsorAddresses[_i]]) / (balanceOfSPS);
|
| 312 |
+
SponsorAddresses[_i].transfer(_val);
|
| 313 |
+
}
|
| 314 |
+
|
| 315 |
+
uint w1p=prft2.mul(3 ether).div(10 ether);
|
| 316 |
+
|
| 317 |
+
wallet1.transfer(w1p);
|
| 318 |
+
wallet2.transfer(prft2.sub(w1p));
|
| 319 |
+
}
|
| 320 |
+
|
| 321 |
+
function sharesOfSPS() view public returns(uint,uint){
|
| 322 |
+
return (Sponsors[msg.sender],balanceOfSPS);
|
| 323 |
+
}
|
| 324 |
+
|
| 325 |
+
function getAllSponsors() view public returns(address[],uint[],uint){
|
| 326 |
+
uint _i=0;
|
| 327 |
+
uint _c=0;
|
| 328 |
+
for(_i=0;_i<SponsorAddresses.length;_i++){
|
| 329 |
+
_c+=1;
|
| 330 |
+
}
|
| 331 |
+
|
| 332 |
+
address[] memory addrs=new address[](_c);
|
| 333 |
+
uint[] memory amounts=new uint[](_c);
|
| 334 |
+
|
| 335 |
+
for(_i=0;_i<SponsorAddresses.length;_i++){
|
| 336 |
+
addrs[_i]=SponsorAddresses[_i];
|
| 337 |
+
amounts[_i]=Sponsors[SponsorAddresses[_i]];
|
| 338 |
+
}
|
| 339 |
+
|
| 340 |
+
return(addrs,amounts,balanceOfSPS);
|
| 341 |
+
}
|
| 342 |
+
|
| 343 |
+
function() payable isHuman() public {
|
| 344 |
+
}
|
| 345 |
+
|
| 346 |
+
|
| 347 |
+
}
|
| 348 |
+
|
| 349 |
+
library SafeMath {
|
| 350 |
+
function mul(uint256 a, uint256 b) internal pure returns (uint256) {
|
| 351 |
+
uint256 c = a * b;
|
| 352 |
+
assert(a == 0 || c / a == b);
|
| 353 |
+
return c;
|
| 354 |
+
}
|
| 355 |
+
|
| 356 |
+
function div(uint256 a, uint256 b) internal pure returns (uint256) {
|
| 357 |
+
|
| 358 |
+
uint256 c = a / b;
|
| 359 |
+
|
| 360 |
+
return c;
|
| 361 |
+
}
|
| 362 |
+
|
| 363 |
+
function sub(uint256 a, uint256 b) internal pure returns (uint256) {
|
| 364 |
+
assert(b <= a);
|
| 365 |
+
return a - b;
|
| 366 |
+
}
|
| 367 |
+
|
| 368 |
+
function add(uint256 a, uint256 b) internal pure returns (uint256) {
|
| 369 |
+
uint256 c = a + b;
|
| 370 |
+
assert(c >= a);
|
| 371 |
+
return c;
|
| 372 |
+
}
|
| 373 |
+
}
|
| 374 |
+
|
| 375 |
+
library utils{
|
| 376 |
+
function inArray(uint[] _arr,uint _val) internal pure returns(bool){
|
| 377 |
+
for(uint _i=0;_i< _arr.length;_i++){
|
| 378 |
+
if(_arr[_i]==_val){
|
| 379 |
+
return true;
|
| 380 |
+
break;
|
| 381 |
+
}
|
| 382 |
+
}
|
| 383 |
+
return false;
|
| 384 |
+
}
|
| 385 |
+
|
| 386 |
+
function inArray(address[] _arr,address _val) internal pure returns(bool){
|
| 387 |
+
for(uint _i=0;_i< _arr.length;_i++){
|
| 388 |
+
if(_arr[_i]==_val){
|
| 389 |
+
return true;
|
| 390 |
+
break;
|
| 391 |
+
}
|
| 392 |
+
}
|
| 393 |
+
return false;
|
| 394 |
+
}
|
| 395 |
+
}
|
smart_contract_dataset/block number dependency/164.sol
ADDED
|
@@ -0,0 +1,167 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
pragma solidity ^0.4.24;
|
| 2 |
+
contract BREBuy {
|
| 3 |
+
|
| 4 |
+
struct ContractParam {
|
| 5 |
+
uint32 totalSize ;
|
| 6 |
+
uint256 singlePrice;
|
| 7 |
+
uint8 pumpRate;
|
| 8 |
+
bool hasChange;
|
| 9 |
+
}
|
| 10 |
+
|
| 11 |
+
address owner = 0x0;
|
| 12 |
+
uint32 gameIndex = 0;
|
| 13 |
+
uint256 totalPrice= 0;
|
| 14 |
+
bool isLock = false;
|
| 15 |
+
ContractParam public setConfig;
|
| 16 |
+
ContractParam public curConfig;
|
| 17 |
+
|
| 18 |
+
address[] public addressArray = new address[](0);
|
| 19 |
+
|
| 20 |
+
event openLockEvent();
|
| 21 |
+
event addPlayerEvent(uint32 gameIndex,address player);
|
| 22 |
+
event gameOverEvent(uint32 gameIndex,uint32 totalSize,uint256 singlePrice,uint8 pumpRate,address winAddr,uint overTime);
|
| 23 |
+
event stopGameEvent(uint totalBalace,uint totalSize,uint price);
|
| 24 |
+
|
| 25 |
+
|
| 26 |
+
constructor ( uint32 _totalSize,
|
| 27 |
+
uint256 _singlePrice
|
| 28 |
+
) public {
|
| 29 |
+
owner = msg.sender;
|
| 30 |
+
setConfig = ContractParam(_totalSize,_singlePrice * 1 finney ,5,false);
|
| 31 |
+
curConfig = ContractParam(_totalSize,_singlePrice * 1 finney ,5,false);
|
| 32 |
+
startNewGame();
|
| 33 |
+
}
|
| 34 |
+
|
| 35 |
+
modifier onlyOwner {
|
| 36 |
+
require(msg.sender == owner,"only owner can call this function");
|
| 37 |
+
_;
|
| 38 |
+
}
|
| 39 |
+
|
| 40 |
+
modifier notLock {
|
| 41 |
+
require(isLock == false,"contract current is lock status");
|
| 42 |
+
_;
|
| 43 |
+
}
|
| 44 |
+
|
| 45 |
+
function isNotContract(address addr) private view returns (bool) {
|
| 46 |
+
uint size;
|
| 47 |
+
assembly { size := extcodesize(addr) }
|
| 48 |
+
return size <= 0;
|
| 49 |
+
}
|
| 50 |
+
|
| 51 |
+
function updateLock(bool b) onlyOwner public {
|
| 52 |
+
|
| 53 |
+
require(isLock != b," updateLock new status == old status");
|
| 54 |
+
|
| 55 |
+
isLock = b;
|
| 56 |
+
|
| 57 |
+
if(isLock) {
|
| 58 |
+
stopGame();
|
| 59 |
+
}else{
|
| 60 |
+
startNewGame();
|
| 61 |
+
emit openLockEvent();
|
| 62 |
+
}
|
| 63 |
+
}
|
| 64 |
+
|
| 65 |
+
function stopGame() onlyOwner private {
|
| 66 |
+
|
| 67 |
+
if(addressArray.length <= 0) {
|
| 68 |
+
return;
|
| 69 |
+
}
|
| 70 |
+
uint totalBalace = address(this).balance;
|
| 71 |
+
uint price = totalBalace / addressArray.length;
|
| 72 |
+
for(uint i = 0; i < addressArray.length; i++) {
|
| 73 |
+
address curPlayer = addressArray[i];
|
| 74 |
+
curPlayer.transfer(price);
|
| 75 |
+
}
|
| 76 |
+
emit stopGameEvent(totalBalace,addressArray.length,price);
|
| 77 |
+
addressArray.length=0;
|
| 78 |
+
}
|
| 79 |
+
|
| 80 |
+
function transferOwnership(address newOwner) onlyOwner public {
|
| 81 |
+
if (newOwner != address(0)) {
|
| 82 |
+
owner = newOwner;
|
| 83 |
+
}
|
| 84 |
+
}
|
| 85 |
+
|
| 86 |
+
function changeConfig( uint32 _totalSize,uint256 _singlePrice,uint8 _pumpRate) onlyOwner public payable {
|
| 87 |
+
|
| 88 |
+
curConfig.hasChange = true;
|
| 89 |
+
if(setConfig.totalSize != _totalSize) {
|
| 90 |
+
setConfig.totalSize = _totalSize;
|
| 91 |
+
}
|
| 92 |
+
if(setConfig.pumpRate != _pumpRate){
|
| 93 |
+
setConfig.pumpRate = _pumpRate;
|
| 94 |
+
}
|
| 95 |
+
if(setConfig.singlePrice != _singlePrice * 1 finney){
|
| 96 |
+
setConfig.singlePrice = _singlePrice * 1 finney;
|
| 97 |
+
}
|
| 98 |
+
}
|
| 99 |
+
|
| 100 |
+
function startNewGame() private {
|
| 101 |
+
|
| 102 |
+
gameIndex++;
|
| 103 |
+
if(curConfig.hasChange) {
|
| 104 |
+
if(curConfig.totalSize != setConfig.totalSize) {
|
| 105 |
+
curConfig.totalSize = setConfig.totalSize;
|
| 106 |
+
}
|
| 107 |
+
if(curConfig.singlePrice != setConfig.singlePrice){
|
| 108 |
+
curConfig.singlePrice = setConfig.singlePrice;
|
| 109 |
+
}
|
| 110 |
+
if( curConfig.pumpRate != setConfig.pumpRate) {
|
| 111 |
+
curConfig.pumpRate = setConfig.pumpRate;
|
| 112 |
+
}
|
| 113 |
+
curConfig.hasChange = false;
|
| 114 |
+
}
|
| 115 |
+
addressArray.length=0;
|
| 116 |
+
}
|
| 117 |
+
|
| 118 |
+
function getGameInfo() public view returns (uint256,uint32,uint256,uint8,address[],uint256,bool) {
|
| 119 |
+
return (gameIndex,
|
| 120 |
+
curConfig.totalSize,
|
| 121 |
+
curConfig.singlePrice,
|
| 122 |
+
curConfig.pumpRate,
|
| 123 |
+
addressArray,
|
| 124 |
+
totalPrice,
|
| 125 |
+
isLock);
|
| 126 |
+
}
|
| 127 |
+
|
| 128 |
+
function gameResult() private {
|
| 129 |
+
|
| 130 |
+
uint index = getRamdon();
|
| 131 |
+
address lastAddress = addressArray[index];
|
| 132 |
+
uint totalBalace = address(this).balance;
|
| 133 |
+
uint giveToOwn = totalBalace * curConfig.pumpRate / 100;
|
| 134 |
+
uint giveToActor = totalBalace - giveToOwn;
|
| 135 |
+
owner.transfer(giveToOwn);
|
| 136 |
+
lastAddress.transfer(giveToActor);
|
| 137 |
+
emit gameOverEvent(
|
| 138 |
+
gameIndex,
|
| 139 |
+
curConfig.totalSize,
|
| 140 |
+
curConfig.singlePrice,
|
| 141 |
+
curConfig.pumpRate,
|
| 142 |
+
lastAddress,
|
| 143 |
+
now);
|
| 144 |
+
}
|
| 145 |
+
|
| 146 |
+
function getRamdon() private view returns (uint) {
|
| 147 |
+
bytes32 ramdon = keccak256(abi.encodePacked(ramdon,now,blockhash(block.number-1)));
|
| 148 |
+
for(uint i = 0; i < addressArray.length; i++) {
|
| 149 |
+
ramdon = keccak256(abi.encodePacked(ramdon,now, addressArray[i]));
|
| 150 |
+
}
|
| 151 |
+
uint index = uint(ramdon) % addressArray.length;
|
| 152 |
+
return index;
|
| 153 |
+
}
|
| 154 |
+
|
| 155 |
+
function() notLock payable public{
|
| 156 |
+
require(isNotContract(msg.sender),"Contract not call addPlayer");
|
| 157 |
+
require(msg.value == curConfig.singlePrice,"msg.value error");
|
| 158 |
+
totalPrice = totalPrice + msg.value;
|
| 159 |
+
addressArray.push(msg.sender);
|
| 160 |
+
|
| 161 |
+
emit addPlayerEvent(gameIndex,msg.sender);
|
| 162 |
+
if(addressArray.length >= curConfig.totalSize) {
|
| 163 |
+
gameResult();
|
| 164 |
+
startNewGame();
|
| 165 |
+
}
|
| 166 |
+
}
|
| 167 |
+
}
|
smart_contract_dataset/block number dependency/1673.sol
ADDED
|
@@ -0,0 +1,466 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
pragma solidity ^0.4.24;
|
| 2 |
+
|
| 3 |
+
|
| 4 |
+
|
| 5 |
+
contract ZTHReceivingContract {
|
| 6 |
+
function tokenFallback(address _from, uint _value, bytes _data) public returns (bool);
|
| 7 |
+
}
|
| 8 |
+
|
| 9 |
+
contract ZTHInterface {
|
| 10 |
+
function transfer(address _to, uint _value) public returns (bool);
|
| 11 |
+
function approve(address spender, uint tokens) public returns (bool);
|
| 12 |
+
}
|
| 13 |
+
|
| 14 |
+
contract Zlots is ZTHReceivingContract {
|
| 15 |
+
using SafeMath for uint;
|
| 16 |
+
|
| 17 |
+
address private owner;
|
| 18 |
+
address private bankroll;
|
| 19 |
+
|
| 20 |
+
|
| 21 |
+
uint totalSpins;
|
| 22 |
+
uint totalZTHWagered;
|
| 23 |
+
|
| 24 |
+
|
| 25 |
+
uint contractBalance;
|
| 26 |
+
|
| 27 |
+
|
| 28 |
+
bool public gameActive;
|
| 29 |
+
|
| 30 |
+
address private ZTHTKNADDR;
|
| 31 |
+
address private ZTHBANKROLL;
|
| 32 |
+
ZTHInterface private ZTHTKN;
|
| 33 |
+
|
| 34 |
+
mapping (uint => bool) validTokenBet;
|
| 35 |
+
|
| 36 |
+
|
| 37 |
+
event HouseRetrievedTake(
|
| 38 |
+
uint timeTaken,
|
| 39 |
+
uint tokensWithdrawn
|
| 40 |
+
);
|
| 41 |
+
|
| 42 |
+
|
| 43 |
+
event TokensWagered(
|
| 44 |
+
address _wagerer,
|
| 45 |
+
uint _wagered
|
| 46 |
+
);
|
| 47 |
+
|
| 48 |
+
event LogResult(
|
| 49 |
+
address _wagerer,
|
| 50 |
+
uint _result,
|
| 51 |
+
uint _profit,
|
| 52 |
+
uint _wagered,
|
| 53 |
+
uint _category,
|
| 54 |
+
bool _win
|
| 55 |
+
);
|
| 56 |
+
|
| 57 |
+
|
| 58 |
+
event Loss(address _wagerer, uint _block);
|
| 59 |
+
event ThreeMoonJackpot(address _wagerer, uint _block);
|
| 60 |
+
event TwoMoonPrize(address _wagerer, uint _block);
|
| 61 |
+
event ZTHJackpot(address _wagerer, uint _block);
|
| 62 |
+
event ThreeZSymbols(address _wagerer, uint _block);
|
| 63 |
+
event ThreeTSymbols(address _wagerer, uint _block);
|
| 64 |
+
event ThreeHSymbols(address _wagerer, uint _block);
|
| 65 |
+
event ThreeEtherIcons(address _wagerer, uint _block);
|
| 66 |
+
event ThreeGreenPyramids(address _wagerer, uint _block);
|
| 67 |
+
event ThreeGoldPyramids(address _wagerer, uint _block);
|
| 68 |
+
event ThreeWhitePyramids(address _wagerer, uint _block);
|
| 69 |
+
event OneMoonPrize(address _wagerer, uint _block);
|
| 70 |
+
event OneOfEachPyramidPrize(address _wagerer, uint _block);
|
| 71 |
+
event TwoZSymbols(address _wagerer, uint _block);
|
| 72 |
+
event TwoTSymbols(address _wagerer, uint _block);
|
| 73 |
+
event TwoHSymbols(address _wagerer, uint _block);
|
| 74 |
+
event TwoEtherIcons(address _wagerer, uint _block);
|
| 75 |
+
event TwoGreenPyramids(address _wagerer, uint _block);
|
| 76 |
+
event TwoGoldPyramids(address _wagerer, uint _block);
|
| 77 |
+
event TwoWhitePyramids(address _wagerer, uint _block);
|
| 78 |
+
|
| 79 |
+
modifier onlyOwner {
|
| 80 |
+
require(msg.sender == owner);
|
| 81 |
+
_;
|
| 82 |
+
}
|
| 83 |
+
|
| 84 |
+
modifier onlyBankroll {
|
| 85 |
+
require(msg.sender == bankroll);
|
| 86 |
+
_;
|
| 87 |
+
}
|
| 88 |
+
|
| 89 |
+
modifier onlyOwnerOrBankroll {
|
| 90 |
+
require(msg.sender == owner || msg.sender == bankroll);
|
| 91 |
+
_;
|
| 92 |
+
}
|
| 93 |
+
|
| 94 |
+
|
| 95 |
+
modifier gameIsActive {
|
| 96 |
+
require(gameActive == true);
|
| 97 |
+
_;
|
| 98 |
+
}
|
| 99 |
+
|
| 100 |
+
constructor(address ZethrAddress, address BankrollAddress) public {
|
| 101 |
+
|
| 102 |
+
|
| 103 |
+
ZTHTKNADDR = ZethrAddress;
|
| 104 |
+
ZTHBANKROLL = BankrollAddress;
|
| 105 |
+
|
| 106 |
+
|
| 107 |
+
owner = msg.sender;
|
| 108 |
+
bankroll = ZTHBANKROLL;
|
| 109 |
+
|
| 110 |
+
|
| 111 |
+
ZTHTKN = ZTHInterface(ZTHTKNADDR);
|
| 112 |
+
ZTHTKN.approve(ZTHBANKROLL, 2**256 - 1);
|
| 113 |
+
|
| 114 |
+
|
| 115 |
+
ZTHTKN.approve(owner, 2**256 - 1);
|
| 116 |
+
|
| 117 |
+
|
| 118 |
+
validTokenBet[5e18] = true;
|
| 119 |
+
validTokenBet[10e18] = true;
|
| 120 |
+
validTokenBet[25e18] = true;
|
| 121 |
+
validTokenBet[50e18] = true;
|
| 122 |
+
|
| 123 |
+
gameActive = true;
|
| 124 |
+
}
|
| 125 |
+
|
| 126 |
+
|
| 127 |
+
function() public payable { }
|
| 128 |
+
|
| 129 |
+
|
| 130 |
+
struct TKN { address sender; uint value; }
|
| 131 |
+
function tokenFallback(address _from, uint _value, bytes ) public returns (bool){
|
| 132 |
+
if (_from == bankroll) {
|
| 133 |
+
|
| 134 |
+
contractBalance = contractBalance.add(_value);
|
| 135 |
+
return true;
|
| 136 |
+
} else {
|
| 137 |
+
TKN memory _tkn;
|
| 138 |
+
_tkn.sender = _from;
|
| 139 |
+
_tkn.value = _value;
|
| 140 |
+
_spinTokens(_tkn);
|
| 141 |
+
return true;
|
| 142 |
+
}
|
| 143 |
+
}
|
| 144 |
+
|
| 145 |
+
struct playerSpin {
|
| 146 |
+
uint200 tokenValue;
|
| 147 |
+
uint48 blockn;
|
| 148 |
+
}
|
| 149 |
+
|
| 150 |
+
|
| 151 |
+
mapping(address => playerSpin) public playerSpins;
|
| 152 |
+
|
| 153 |
+
|
| 154 |
+
function _spinTokens(TKN _tkn) private {
|
| 155 |
+
|
| 156 |
+
require(gameActive);
|
| 157 |
+
require(_zthToken(msg.sender));
|
| 158 |
+
require(validTokenBet[_tkn.value]);
|
| 159 |
+
require(jackpotGuard(_tkn.value));
|
| 160 |
+
|
| 161 |
+
require(_tkn.value < ((2 ** 200) - 1));
|
| 162 |
+
require(block.number < ((2 ** 48) - 1));
|
| 163 |
+
|
| 164 |
+
address _customerAddress = _tkn.sender;
|
| 165 |
+
uint _wagered = _tkn.value;
|
| 166 |
+
|
| 167 |
+
playerSpin memory spin = playerSpins[_tkn.sender];
|
| 168 |
+
|
| 169 |
+
contractBalance = contractBalance.add(_wagered);
|
| 170 |
+
|
| 171 |
+
|
| 172 |
+
require(block.number != spin.blockn);
|
| 173 |
+
|
| 174 |
+
|
| 175 |
+
if (spin.blockn != 0) {
|
| 176 |
+
_finishSpin(_tkn.sender);
|
| 177 |
+
}
|
| 178 |
+
|
| 179 |
+
|
| 180 |
+
spin.blockn = uint48(block.number);
|
| 181 |
+
spin.tokenValue = uint200(_wagered);
|
| 182 |
+
|
| 183 |
+
|
| 184 |
+
playerSpins[_tkn.sender] = spin;
|
| 185 |
+
|
| 186 |
+
|
| 187 |
+
totalSpins += 1;
|
| 188 |
+
|
| 189 |
+
|
| 190 |
+
totalZTHWagered += _wagered;
|
| 191 |
+
|
| 192 |
+
emit TokensWagered(_customerAddress, _wagered);
|
| 193 |
+
|
| 194 |
+
}
|
| 195 |
+
|
| 196 |
+
|
| 197 |
+
function finishSpin() public
|
| 198 |
+
gameIsActive
|
| 199 |
+
returns (uint)
|
| 200 |
+
{
|
| 201 |
+
return _finishSpin(msg.sender);
|
| 202 |
+
}
|
| 203 |
+
|
| 204 |
+
|
| 205 |
+
function _finishSpin(address target)
|
| 206 |
+
private returns (uint)
|
| 207 |
+
{
|
| 208 |
+
playerSpin memory spin = playerSpins[target];
|
| 209 |
+
|
| 210 |
+
require(spin.tokenValue > 0);
|
| 211 |
+
require(spin.blockn != block.number);
|
| 212 |
+
|
| 213 |
+
uint profit = 0;
|
| 214 |
+
uint category = 0;
|
| 215 |
+
|
| 216 |
+
|
| 217 |
+
|
| 218 |
+
uint result;
|
| 219 |
+
if (block.number - spin.blockn > 255) {
|
| 220 |
+
result = 9999;
|
| 221 |
+
} else {
|
| 222 |
+
|
| 223 |
+
|
| 224 |
+
|
| 225 |
+
result = random(1000000, spin.blockn, target);
|
| 226 |
+
}
|
| 227 |
+
|
| 228 |
+
if (result > 476661) {
|
| 229 |
+
|
| 230 |
+
emit Loss(target, spin.blockn);
|
| 231 |
+
emit LogResult(target, result, profit, spin.tokenValue, category, false);
|
| 232 |
+
} else
|
| 233 |
+
if (result < 1) {
|
| 234 |
+
|
| 235 |
+
profit = SafeMath.mul(spin.tokenValue, 500);
|
| 236 |
+
category = 1;
|
| 237 |
+
emit ThreeMoonJackpot(target, spin.blockn);
|
| 238 |
+
} else
|
| 239 |
+
if (result < 298) {
|
| 240 |
+
|
| 241 |
+
profit = SafeMath.mul(spin.tokenValue, 232);
|
| 242 |
+
category = 2;
|
| 243 |
+
emit TwoMoonPrize(target, spin.blockn);
|
| 244 |
+
} else
|
| 245 |
+
if (result < 3127) {
|
| 246 |
+
|
| 247 |
+
profit = SafeMath.div(SafeMath.mul(spin.tokenValue, 232), 10);
|
| 248 |
+
category = 3;
|
| 249 |
+
emit ZTHJackpot(target, spin.blockn);
|
| 250 |
+
|
| 251 |
+
} else
|
| 252 |
+
if (result < 5956) {
|
| 253 |
+
|
| 254 |
+
profit = SafeMath.mul(spin.tokenValue, 25);
|
| 255 |
+
category = 4;
|
| 256 |
+
emit ThreeZSymbols(target, spin.blockn);
|
| 257 |
+
} else
|
| 258 |
+
if (result < 8785) {
|
| 259 |
+
|
| 260 |
+
profit = SafeMath.mul(spin.tokenValue, 25);
|
| 261 |
+
category = 5;
|
| 262 |
+
emit ThreeTSymbols(target, spin.blockn);
|
| 263 |
+
} else
|
| 264 |
+
if (result < 11614) {
|
| 265 |
+
|
| 266 |
+
profit = SafeMath.mul(spin.tokenValue, 25);
|
| 267 |
+
category = 6;
|
| 268 |
+
emit ThreeHSymbols(target, spin.blockn);
|
| 269 |
+
} else
|
| 270 |
+
if (result < 14443) {
|
| 271 |
+
|
| 272 |
+
profit = SafeMath.mul(spin.tokenValue, 50);
|
| 273 |
+
category = 7;
|
| 274 |
+
emit ThreeEtherIcons(target, spin.blockn);
|
| 275 |
+
} else
|
| 276 |
+
if (result < 17272) {
|
| 277 |
+
|
| 278 |
+
profit = SafeMath.mul(spin.tokenValue, 40);
|
| 279 |
+
category = 8;
|
| 280 |
+
emit ThreeGreenPyramids(target, spin.blockn);
|
| 281 |
+
} else
|
| 282 |
+
if (result < 20101) {
|
| 283 |
+
|
| 284 |
+
profit = SafeMath.mul(spin.tokenValue, 20);
|
| 285 |
+
category = 9;
|
| 286 |
+
emit ThreeGoldPyramids(target, spin.blockn);
|
| 287 |
+
} else
|
| 288 |
+
if (result < 22929) {
|
| 289 |
+
|
| 290 |
+
profit = SafeMath.mul(spin.tokenValue, 20);
|
| 291 |
+
category = 10;
|
| 292 |
+
emit ThreeWhitePyramids(target, spin.blockn);
|
| 293 |
+
} else
|
| 294 |
+
if (result < 52332) {
|
| 295 |
+
|
| 296 |
+
profit = SafeMath.div(SafeMath.mul(spin.tokenValue, 125),10);
|
| 297 |
+
category = 11;
|
| 298 |
+
emit OneMoonPrize(target, spin.blockn);
|
| 299 |
+
} else
|
| 300 |
+
if (result < 120225) {
|
| 301 |
+
|
| 302 |
+
profit = SafeMath.div(SafeMath.mul(spin.tokenValue, 15),10);
|
| 303 |
+
category = 12;
|
| 304 |
+
emit OneOfEachPyramidPrize(target, spin.blockn);
|
| 305 |
+
} else
|
| 306 |
+
if (result < 171146) {
|
| 307 |
+
|
| 308 |
+
profit = SafeMath.div(SafeMath.mul(spin.tokenValue, 232),100);
|
| 309 |
+
category = 13;
|
| 310 |
+
emit TwoZSymbols(target, spin.blockn);
|
| 311 |
+
} else
|
| 312 |
+
if (result < 222067) {
|
| 313 |
+
|
| 314 |
+
profit = SafeMath.div(SafeMath.mul(spin.tokenValue, 232),100);
|
| 315 |
+
category = 14;
|
| 316 |
+
emit TwoTSymbols(target, spin.blockn);
|
| 317 |
+
} else
|
| 318 |
+
if (result < 272988) {
|
| 319 |
+
|
| 320 |
+
profit = SafeMath.div(SafeMath.mul(spin.tokenValue, 232),100);
|
| 321 |
+
category = 15;
|
| 322 |
+
emit TwoHSymbols(target, spin.blockn);
|
| 323 |
+
} else
|
| 324 |
+
if (result < 323909) {
|
| 325 |
+
|
| 326 |
+
profit = SafeMath.div(SafeMath.mul(spin.tokenValue, 375),100);
|
| 327 |
+
category = 16;
|
| 328 |
+
emit TwoEtherIcons(target, spin.blockn);
|
| 329 |
+
} else
|
| 330 |
+
if (result < 374830) {
|
| 331 |
+
|
| 332 |
+
profit = SafeMath.div(SafeMath.mul(spin.tokenValue, 35),10);
|
| 333 |
+
category = 17;
|
| 334 |
+
emit TwoGreenPyramids(target, spin.blockn);
|
| 335 |
+
} else
|
| 336 |
+
if (result < 425751) {
|
| 337 |
+
|
| 338 |
+
profit = SafeMath.div(SafeMath.mul(spin.tokenValue, 225),100);
|
| 339 |
+
category = 18;
|
| 340 |
+
emit TwoGoldPyramids(target, spin.blockn);
|
| 341 |
+
} else {
|
| 342 |
+
|
| 343 |
+
profit = SafeMath.mul(spin.tokenValue, 2);
|
| 344 |
+
category = 19;
|
| 345 |
+
emit TwoWhitePyramids(target, spin.blockn);
|
| 346 |
+
}
|
| 347 |
+
|
| 348 |
+
emit LogResult(target, result, profit, spin.tokenValue, category, true);
|
| 349 |
+
contractBalance = contractBalance.sub(profit);
|
| 350 |
+
ZTHTKN.transfer(target, profit);
|
| 351 |
+
|
| 352 |
+
|
| 353 |
+
playerSpins[target] = playerSpin(uint200(0), uint48(0));
|
| 354 |
+
return result;
|
| 355 |
+
}
|
| 356 |
+
|
| 357 |
+
|
| 358 |
+
|
| 359 |
+
|
| 360 |
+
|
| 361 |
+
function jackpotGuard(uint _wager)
|
| 362 |
+
private
|
| 363 |
+
view
|
| 364 |
+
returns (bool)
|
| 365 |
+
{
|
| 366 |
+
uint maxProfit = SafeMath.mul(_wager, 500);
|
| 367 |
+
uint ninetyContractBalance = SafeMath.mul(SafeMath.div(contractBalance, 10), 9);
|
| 368 |
+
return (maxProfit <= ninetyContractBalance);
|
| 369 |
+
}
|
| 370 |
+
|
| 371 |
+
|
| 372 |
+
|
| 373 |
+
function maxRandom(uint blockn, address entropy) private view returns (uint256 randomNumber) {
|
| 374 |
+
return uint256(keccak256(
|
| 375 |
+
abi.encodePacked(
|
| 376 |
+
blockhash(blockn),
|
| 377 |
+
entropy)
|
| 378 |
+
));
|
| 379 |
+
}
|
| 380 |
+
|
| 381 |
+
|
| 382 |
+
function random(uint256 upper, uint256 blockn, address entropy) internal view returns (uint256 randomNumber) {
|
| 383 |
+
return maxRandom(blockn, entropy) % upper;
|
| 384 |
+
}
|
| 385 |
+
|
| 386 |
+
|
| 387 |
+
function balanceOf() public view returns (uint) {
|
| 388 |
+
return contractBalance;
|
| 389 |
+
}
|
| 390 |
+
|
| 391 |
+
function addNewBetAmount(uint _tokenAmount)
|
| 392 |
+
public
|
| 393 |
+
onlyOwner
|
| 394 |
+
{
|
| 395 |
+
validTokenBet[_tokenAmount] = true;
|
| 396 |
+
}
|
| 397 |
+
|
| 398 |
+
|
| 399 |
+
function pauseGame() public onlyOwner {
|
| 400 |
+
gameActive = false;
|
| 401 |
+
}
|
| 402 |
+
|
| 403 |
+
|
| 404 |
+
function resumeGame() public onlyOwner {
|
| 405 |
+
gameActive = true;
|
| 406 |
+
}
|
| 407 |
+
|
| 408 |
+
|
| 409 |
+
function changeOwner(address _newOwner) public onlyOwner {
|
| 410 |
+
owner = _newOwner;
|
| 411 |
+
}
|
| 412 |
+
|
| 413 |
+
|
| 414 |
+
function changeBankroll(address _newBankroll) public onlyOwner {
|
| 415 |
+
bankroll = _newBankroll;
|
| 416 |
+
}
|
| 417 |
+
|
| 418 |
+
function divertDividendsToBankroll()
|
| 419 |
+
public
|
| 420 |
+
onlyOwner
|
| 421 |
+
{
|
| 422 |
+
bankroll.transfer(address(this).balance);
|
| 423 |
+
}
|
| 424 |
+
|
| 425 |
+
|
| 426 |
+
function _zthToken(address _tokenContract) private view returns (bool) {
|
| 427 |
+
return _tokenContract == ZTHTKNADDR;
|
| 428 |
+
}
|
| 429 |
+
}
|
| 430 |
+
|
| 431 |
+
|
| 432 |
+
|
| 433 |
+
|
| 434 |
+
library SafeMath {
|
| 435 |
+
|
| 436 |
+
|
| 437 |
+
function mul(uint a, uint b) internal pure returns (uint) {
|
| 438 |
+
if (a == 0) {
|
| 439 |
+
return 0;
|
| 440 |
+
}
|
| 441 |
+
uint c = a * b;
|
| 442 |
+
assert(c / a == b);
|
| 443 |
+
return c;
|
| 444 |
+
}
|
| 445 |
+
|
| 446 |
+
|
| 447 |
+
function div(uint a, uint b) internal pure returns (uint) {
|
| 448 |
+
|
| 449 |
+
uint c = a / b;
|
| 450 |
+
|
| 451 |
+
return c;
|
| 452 |
+
}
|
| 453 |
+
|
| 454 |
+
|
| 455 |
+
function sub(uint a, uint b) internal pure returns (uint) {
|
| 456 |
+
assert(b <= a);
|
| 457 |
+
return a - b;
|
| 458 |
+
}
|
| 459 |
+
|
| 460 |
+
|
| 461 |
+
function add(uint a, uint b) internal pure returns (uint) {
|
| 462 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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
pragma solidity ^0.4.12;
|
| 2 |
+
|
| 3 |
+
contract IMigrationContract {
|
| 4 |
+
function migrate(address addr, uint256 nas) returns (bool success);
|
| 5 |
+
}
|
| 6 |
+
|
| 7 |
+
|
| 8 |
+
contract SafeMath {
|
| 9 |
+
|
| 10 |
+
|
| 11 |
+
function safeAdd(uint256 x, uint256 y) internal returns(uint256) {
|
| 12 |
+
uint256 z = x + y;
|
| 13 |
+
assert((z >= x) && (z >= y));
|
| 14 |
+
return z;
|
| 15 |
+
}
|
| 16 |
+
|
| 17 |
+
function safeSubtract(uint256 x, uint256 y) internal returns(uint256) {
|
| 18 |
+
assert(x >= y);
|
| 19 |
+
uint256 z = x - y;
|
| 20 |
+
return z;
|
| 21 |
+
}
|
| 22 |
+
|
| 23 |
+
function safeMult(uint256 x, uint256 y) internal returns(uint256) {
|
| 24 |
+
uint256 z = x * y;
|
| 25 |
+
assert((x == 0)||(z/x == y));
|
| 26 |
+
return z;
|
| 27 |
+
}
|
| 28 |
+
|
| 29 |
+
}
|
| 30 |
+
|
| 31 |
+
contract Token {
|
| 32 |
+
uint256 public totalSupply;
|
| 33 |
+
function balanceOf(address _owner) constant returns (uint256 balance);
|
| 34 |
+
function transfer(address _to, uint256 _value) returns (bool success);
|
| 35 |
+
function transferFrom(address _from, address _to, uint256 _value) returns (bool success);
|
| 36 |
+
function approve(address _spender, uint256 _value) returns (bool success);
|
| 37 |
+
function allowance(address _owner, address _spender) constant returns (uint256 remaining);
|
| 38 |
+
event Transfer(address indexed _from, address indexed _to, uint256 _value);
|
| 39 |
+
event Approval(address indexed _owner, address indexed _spender, uint256 _value);
|
| 40 |
+
}
|
| 41 |
+
|
| 42 |
+
|
| 43 |
+
|
| 44 |
+
contract StandardToken is Token {
|
| 45 |
+
|
| 46 |
+
function transfer(address _to, uint256 _value) returns (bool success) {
|
| 47 |
+
if (balances[msg.sender] >= _value && _value > 0) {
|
| 48 |
+
balances[msg.sender] -= _value;
|
| 49 |
+
balances[_to] += _value;
|
| 50 |
+
Transfer(msg.sender, _to, _value);
|
| 51 |
+
return true;
|
| 52 |
+
} else {
|
| 53 |
+
return false;
|
| 54 |
+
}
|
| 55 |
+
}
|
| 56 |
+
|
| 57 |
+
function transferFrom(address _from, address _to, uint256 _value) returns (bool success) {
|
| 58 |
+
if (balances[_from] >= _value && allowed[_from][msg.sender] >= _value && _value > 0) {
|
| 59 |
+
balances[_to] += _value;
|
| 60 |
+
balances[_from] -= _value;
|
| 61 |
+
allowed[_from][msg.sender] -= _value;
|
| 62 |
+
Transfer(_from, _to, _value);
|
| 63 |
+
return true;
|
| 64 |
+
} else {
|
| 65 |
+
return false;
|
| 66 |
+
}
|
| 67 |
+
}
|
| 68 |
+
|
| 69 |
+
function balanceOf(address _owner) constant returns (uint256 balance) {
|
| 70 |
+
return balances[_owner];
|
| 71 |
+
}
|
| 72 |
+
|
| 73 |
+
function approve(address _spender, uint256 _value) returns (bool success) {
|
| 74 |
+
allowed[msg.sender][_spender] = _value;
|
| 75 |
+
Approval(msg.sender, _spender, _value);
|
| 76 |
+
return true;
|
| 77 |
+
}
|
| 78 |
+
|
| 79 |
+
function allowance(address _owner, address _spender) constant returns (uint256 remaining) {
|
| 80 |
+
return allowed[_owner][_spender];
|
| 81 |
+
}
|
| 82 |
+
|
| 83 |
+
mapping (address => uint256) balances;
|
| 84 |
+
mapping (address => mapping (address => uint256)) allowed;
|
| 85 |
+
}
|
| 86 |
+
|
| 87 |
+
contract EVTCToken is StandardToken, SafeMath {
|
| 88 |
+
|
| 89 |
+
|
| 90 |
+
string public constant name = "EVTC";
|
| 91 |
+
string public constant symbol = "ECoin";
|
| 92 |
+
uint256 public constant decimals = 18;
|
| 93 |
+
string public version = "1.0";
|
| 94 |
+
|
| 95 |
+
|
| 96 |
+
address public ethFundDeposit;
|
| 97 |
+
address public newContractAddr;
|
| 98 |
+
|
| 99 |
+
|
| 100 |
+
bool public isFunding;
|
| 101 |
+
uint256 public fundingStartBlock;
|
| 102 |
+
uint256 public fundingStopBlock;
|
| 103 |
+
|
| 104 |
+
uint256 public currentSupply;
|
| 105 |
+
uint256 public tokenRaised = 0;
|
| 106 |
+
uint256 public tokenMigrated = 0;
|
| 107 |
+
uint256 public tokenExchangeRate = 625;
|
| 108 |
+
|
| 109 |
+
|
| 110 |
+
event AllocateToken(address indexed _to, uint256 _value);
|
| 111 |
+
event IssueToken(address indexed _to, uint256 _value);
|
| 112 |
+
event IncreaseSupply(uint256 _value);
|
| 113 |
+
event DecreaseSupply(uint256 _value);
|
| 114 |
+
event Migrate(address indexed _to, uint256 _value);
|
| 115 |
+
|
| 116 |
+
|
| 117 |
+
function formatDecimals(uint256 _value) internal returns (uint256 ) {
|
| 118 |
+
return _value * 10 ** decimals;
|
| 119 |
+
}
|
| 120 |
+
|
| 121 |
+
|
| 122 |
+
function EVTCToken(
|
| 123 |
+
address _ethFundDeposit,
|
| 124 |
+
uint256 _currentSupply)
|
| 125 |
+
{
|
| 126 |
+
ethFundDeposit = _ethFundDeposit;
|
| 127 |
+
|
| 128 |
+
isFunding = false;
|
| 129 |
+
fundingStartBlock = 0;
|
| 130 |
+
fundingStopBlock = 0;
|
| 131 |
+
|
| 132 |
+
currentSupply = formatDecimals(_currentSupply);
|
| 133 |
+
totalSupply = formatDecimals(100000000);
|
| 134 |
+
balances[msg.sender] = totalSupply;
|
| 135 |
+
if(currentSupply > totalSupply) throw;
|
| 136 |
+
}
|
| 137 |
+
|
| 138 |
+
modifier isOwner() { require(msg.sender == ethFundDeposit); _; }
|
| 139 |
+
|
| 140 |
+
|
| 141 |
+
function setTokenExchangeRate(uint256 _tokenExchangeRate) isOwner external {
|
| 142 |
+
if (_tokenExchangeRate == 0) throw;
|
| 143 |
+
if (_tokenExchangeRate == tokenExchangeRate) throw;
|
| 144 |
+
|
| 145 |
+
tokenExchangeRate = _tokenExchangeRate;
|
| 146 |
+
}
|
| 147 |
+
|
| 148 |
+
|
| 149 |
+
function increaseSupply (uint256 _value) isOwner external {
|
| 150 |
+
uint256 value = formatDecimals(_value);
|
| 151 |
+
if (value + currentSupply > totalSupply) throw;
|
| 152 |
+
currentSupply = safeAdd(currentSupply, value);
|
| 153 |
+
IncreaseSupply(value);
|
| 154 |
+
}
|
| 155 |
+
|
| 156 |
+
|
| 157 |
+
function decreaseSupply (uint256 _value) isOwner external {
|
| 158 |
+
uint256 value = formatDecimals(_value);
|
| 159 |
+
if (value + tokenRaised > currentSupply) throw;
|
| 160 |
+
|
| 161 |
+
currentSupply = safeSubtract(currentSupply, value);
|
| 162 |
+
DecreaseSupply(value);
|
| 163 |
+
}
|
| 164 |
+
|
| 165 |
+
|
| 166 |
+
function startFunding (uint256 _fundingStartBlock, uint256 _fundingStopBlock) isOwner external {
|
| 167 |
+
if (isFunding) throw;
|
| 168 |
+
if (_fundingStartBlock >= _fundingStopBlock) throw;
|
| 169 |
+
if (block.number >= _fundingStartBlock) throw;
|
| 170 |
+
|
| 171 |
+
fundingStartBlock = _fundingStartBlock;
|
| 172 |
+
fundingStopBlock = _fundingStopBlock;
|
| 173 |
+
isFunding = true;
|
| 174 |
+
}
|
| 175 |
+
|
| 176 |
+
|
| 177 |
+
function stopFunding() isOwner external {
|
| 178 |
+
if (!isFunding) throw;
|
| 179 |
+
isFunding = false;
|
| 180 |
+
}
|
| 181 |
+
|
| 182 |
+
|
| 183 |
+
function setMigrateContract(address _newContractAddr) isOwner external {
|
| 184 |
+
if (_newContractAddr == newContractAddr) throw;
|
| 185 |
+
newContractAddr = _newContractAddr;
|
| 186 |
+
}
|
| 187 |
+
|
| 188 |
+
|
| 189 |
+
function changeOwner(address _newFundDeposit) isOwner() external {
|
| 190 |
+
if (_newFundDeposit == address(0x0)) throw;
|
| 191 |
+
ethFundDeposit = _newFundDeposit;
|
| 192 |
+
}
|
| 193 |
+
|
| 194 |
+
|
| 195 |
+
function migrate() external {
|
| 196 |
+
if(isFunding) throw;
|
| 197 |
+
if(newContractAddr == address(0x0)) throw;
|
| 198 |
+
|
| 199 |
+
uint256 tokens = balances[msg.sender];
|
| 200 |
+
if (tokens == 0) throw;
|
| 201 |
+
|
| 202 |
+
balances[msg.sender] = 0;
|
| 203 |
+
tokenMigrated = safeAdd(tokenMigrated, tokens);
|
| 204 |
+
|
| 205 |
+
IMigrationContract newContract = IMigrationContract(newContractAddr);
|
| 206 |
+
if (!newContract.migrate(msg.sender, tokens)) throw;
|
| 207 |
+
|
| 208 |
+
Migrate(msg.sender, tokens);
|
| 209 |
+
}
|
| 210 |
+
|
| 211 |
+
|
| 212 |
+
function transferETH() isOwner external {
|
| 213 |
+
if (this.balance == 0) throw;
|
| 214 |
+
if (!ethFundDeposit.send(this.balance)) throw;
|
| 215 |
+
}
|
| 216 |
+
|
| 217 |
+
|
| 218 |
+
function allocateToken (address _addr, uint256 _eth) isOwner external {
|
| 219 |
+
if (_eth == 0) throw;
|
| 220 |
+
if (_addr == address(0x0)) throw;
|
| 221 |
+
|
| 222 |
+
uint256 tokens = safeMult(formatDecimals(_eth), tokenExchangeRate);
|
| 223 |
+
if (tokens + tokenRaised > currentSupply) throw;
|
| 224 |
+
|
| 225 |
+
tokenRaised = safeAdd(tokenRaised, tokens);
|
| 226 |
+
balances[_addr] += tokens;
|
| 227 |
+
|
| 228 |
+
AllocateToken(_addr, tokens);
|
| 229 |
+
}
|
| 230 |
+
|
| 231 |
+
|
| 232 |
+
function () payable {
|
| 233 |
+
if (!isFunding) throw;
|
| 234 |
+
if (msg.value == 0) throw;
|
| 235 |
+
|
| 236 |
+
if (block.number < fundingStartBlock) throw;
|
| 237 |
+
if (block.number > fundingStopBlock) throw;
|
| 238 |
+
|
| 239 |
+
uint256 tokens = safeMult(msg.value, tokenExchangeRate);
|
| 240 |
+
if (tokens + tokenRaised > currentSupply) throw;
|
| 241 |
+
|
| 242 |
+
tokenRaised = safeAdd(tokenRaised, tokens);
|
| 243 |
+
balances[msg.sender] += tokens;
|
| 244 |
+
|
| 245 |
+
IssueToken(msg.sender, tokens);
|
| 246 |
+
}
|
| 247 |
+
}
|
smart_contract_dataset/block number dependency/1714.sol
ADDED
|
@@ -0,0 +1,403 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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0.4.24;
|
| 2 |
+
|
| 3 |
+
|
| 4 |
+
|
| 5 |
+
contract ZTHReceivingContract {
|
| 6 |
+
|
| 7 |
+
function tokenFallback(address _from, uint _value, bytes _data) public returns (bool);
|
| 8 |
+
}
|
| 9 |
+
|
| 10 |
+
|
| 11 |
+
contract ZTHInterface {
|
| 12 |
+
function getFrontEndTokenBalanceOf(address who) public view returns (uint);
|
| 13 |
+
function transfer(address _to, uint _value) public returns (bool);
|
| 14 |
+
function approve(address spender, uint tokens) public returns (bool);
|
| 15 |
+
}
|
| 16 |
+
|
| 17 |
+
contract Zethroll is ZTHReceivingContract {
|
| 18 |
+
using SafeMath for uint;
|
| 19 |
+
|
| 20 |
+
|
| 21 |
+
|
| 22 |
+
modifier betIsValid(uint _betSize, uint _playerNumber) {
|
| 23 |
+
require( calculateProfit(_betSize, _playerNumber) < maxProfit
|
| 24 |
+
&& _betSize >= minBet
|
| 25 |
+
&& _playerNumber > minNumber
|
| 26 |
+
&& _playerNumber < maxNumber);
|
| 27 |
+
_;
|
| 28 |
+
}
|
| 29 |
+
|
| 30 |
+
|
| 31 |
+
modifier gameIsActive {
|
| 32 |
+
require(gamePaused == false);
|
| 33 |
+
_;
|
| 34 |
+
}
|
| 35 |
+
|
| 36 |
+
|
| 37 |
+
modifier onlyOwner {
|
| 38 |
+
require(msg.sender == owner);
|
| 39 |
+
_;
|
| 40 |
+
}
|
| 41 |
+
|
| 42 |
+
|
| 43 |
+
uint constant private MAX_INT = 2 ** 256 - 1;
|
| 44 |
+
uint constant public maxProfitDivisor = 1000000;
|
| 45 |
+
uint constant public maxNumber = 99;
|
| 46 |
+
uint constant public minNumber = 2;
|
| 47 |
+
uint constant public houseEdgeDivisor = 1000;
|
| 48 |
+
|
| 49 |
+
|
| 50 |
+
bool public gamePaused;
|
| 51 |
+
|
| 52 |
+
address public owner;
|
| 53 |
+
address public ZethrBankroll;
|
| 54 |
+
address public ZTHTKNADDR;
|
| 55 |
+
|
| 56 |
+
ZTHInterface public ZTHTKN;
|
| 57 |
+
|
| 58 |
+
uint public contractBalance;
|
| 59 |
+
uint public houseEdge;
|
| 60 |
+
uint public maxProfit;
|
| 61 |
+
uint public maxProfitAsPercentOfHouse;
|
| 62 |
+
uint public minBet = 0;
|
| 63 |
+
|
| 64 |
+
|
| 65 |
+
uint public totalBets;
|
| 66 |
+
uint public totalZTHWagered;
|
| 67 |
+
|
| 68 |
+
|
| 69 |
+
|
| 70 |
+
|
| 71 |
+
event LogBet(address sender, uint value, uint rollUnder);
|
| 72 |
+
|
| 73 |
+
|
| 74 |
+
|
| 75 |
+
event LogResult(address player, uint result, uint rollUnder, uint profit, uint tokensBetted, bool won);
|
| 76 |
+
|
| 77 |
+
|
| 78 |
+
event LogOwnerTransfer(address indexed SentToAddress, uint indexed AmountTransferred);
|
| 79 |
+
|
| 80 |
+
|
| 81 |
+
event MaxProfitChanged(uint _oldMaxProfit, uint _newMaxProfit);
|
| 82 |
+
|
| 83 |
+
|
| 84 |
+
event CurrentContractBalance(uint _tokens);
|
| 85 |
+
|
| 86 |
+
constructor (address zthtknaddr, address zthbankrolladdr) public {
|
| 87 |
+
|
| 88 |
+
owner = msg.sender;
|
| 89 |
+
|
| 90 |
+
|
| 91 |
+
ZTHTKN = ZTHInterface(zthtknaddr);
|
| 92 |
+
ZTHTKNADDR = zthtknaddr;
|
| 93 |
+
|
| 94 |
+
|
| 95 |
+
ZethrBankroll = zthbankrolladdr;
|
| 96 |
+
|
| 97 |
+
|
| 98 |
+
houseEdge = 990;
|
| 99 |
+
|
| 100 |
+
|
| 101 |
+
ownerSetMaxProfitAsPercentOfHouse(10000);
|
| 102 |
+
|
| 103 |
+
|
| 104 |
+
ownerSetMinBet(1e18);
|
| 105 |
+
|
| 106 |
+
|
| 107 |
+
ZTHTKN.approve(zthbankrolladdr, MAX_INT);
|
| 108 |
+
}
|
| 109 |
+
|
| 110 |
+
function() public payable {}
|
| 111 |
+
|
| 112 |
+
|
| 113 |
+
|
| 114 |
+
function maxRandom(uint blockn, address entropy) public view returns (uint256 randomNumber) {
|
| 115 |
+
return uint256(keccak256(
|
| 116 |
+
abi.encodePacked(
|
| 117 |
+
blockhash(blockn),
|
| 118 |
+
entropy)
|
| 119 |
+
));
|
| 120 |
+
}
|
| 121 |
+
|
| 122 |
+
|
| 123 |
+
function random(uint256 upper, uint256 blockn, address entropy) internal view returns (uint256 randomNumber) {
|
| 124 |
+
return maxRandom(blockn, entropy) % upper;
|
| 125 |
+
}
|
| 126 |
+
|
| 127 |
+
|
| 128 |
+
function calculateProfit(uint _initBet, uint _roll)
|
| 129 |
+
private
|
| 130 |
+
view
|
| 131 |
+
returns (uint)
|
| 132 |
+
{
|
| 133 |
+
return ((((_initBet * (100 - (_roll.sub(1)))) / (_roll.sub(1)) + _initBet)) * houseEdge / houseEdgeDivisor) - _initBet;
|
| 134 |
+
}
|
| 135 |
+
|
| 136 |
+
|
| 137 |
+
struct playerRoll{
|
| 138 |
+
uint200 tokenValue;
|
| 139 |
+
uint48 blockn;
|
| 140 |
+
uint8 rollUnder;
|
| 141 |
+
}
|
| 142 |
+
|
| 143 |
+
|
| 144 |
+
mapping(address => playerRoll) public playerRolls;
|
| 145 |
+
|
| 146 |
+
function _playerRollDice(uint _rollUnder, TKN _tkn) private
|
| 147 |
+
gameIsActive
|
| 148 |
+
betIsValid(_tkn.value, _rollUnder)
|
| 149 |
+
{
|
| 150 |
+
require(_tkn.value < ((2 ** 200) - 1));
|
| 151 |
+
require(block.number < ((2 ** 48) - 1));
|
| 152 |
+
|
| 153 |
+
|
| 154 |
+
|
| 155 |
+
|
| 156 |
+
|
| 157 |
+
require(_zthToken(msg.sender));
|
| 158 |
+
|
| 159 |
+
playerRoll memory roll = playerRolls[_tkn.sender];
|
| 160 |
+
|
| 161 |
+
|
| 162 |
+
require(block.number != roll.blockn);
|
| 163 |
+
|
| 164 |
+
|
| 165 |
+
if (roll.blockn != 0) {
|
| 166 |
+
_finishBet(false, _tkn.sender);
|
| 167 |
+
}
|
| 168 |
+
|
| 169 |
+
|
| 170 |
+
roll.blockn = uint48(block.number);
|
| 171 |
+
roll.tokenValue = uint200(_tkn.value);
|
| 172 |
+
roll.rollUnder = uint8(_rollUnder);
|
| 173 |
+
|
| 174 |
+
|
| 175 |
+
playerRolls[_tkn.sender] = roll;
|
| 176 |
+
|
| 177 |
+
|
| 178 |
+
emit LogBet(_tkn.sender, _tkn.value, _rollUnder);
|
| 179 |
+
|
| 180 |
+
|
| 181 |
+
totalBets += 1;
|
| 182 |
+
|
| 183 |
+
|
| 184 |
+
totalZTHWagered += _tkn.value;
|
| 185 |
+
}
|
| 186 |
+
|
| 187 |
+
|
| 188 |
+
function finishBet() public
|
| 189 |
+
gameIsActive
|
| 190 |
+
returns (uint)
|
| 191 |
+
{
|
| 192 |
+
return _finishBet(true, msg.sender);
|
| 193 |
+
}
|
| 194 |
+
|
| 195 |
+
|
| 196 |
+
function _finishBet(bool delete_it, address target) private returns (uint){
|
| 197 |
+
playerRoll memory roll = playerRolls[target];
|
| 198 |
+
require(roll.tokenValue > 0);
|
| 199 |
+
require(roll.blockn != block.number);
|
| 200 |
+
|
| 201 |
+
|
| 202 |
+
uint result;
|
| 203 |
+
if (block.number - roll.blockn > 255) {
|
| 204 |
+
result = 1000;
|
| 205 |
+
} else {
|
| 206 |
+
|
| 207 |
+
result = random(99, roll.blockn, target) + 1;
|
| 208 |
+
}
|
| 209 |
+
|
| 210 |
+
uint rollUnder = roll.rollUnder;
|
| 211 |
+
|
| 212 |
+
if (result < rollUnder) {
|
| 213 |
+
|
| 214 |
+
|
| 215 |
+
|
| 216 |
+
uint profit = calculateProfit(roll.tokenValue, rollUnder);
|
| 217 |
+
|
| 218 |
+
if (profit > maxProfit){
|
| 219 |
+
profit = maxProfit;
|
| 220 |
+
}
|
| 221 |
+
|
| 222 |
+
|
| 223 |
+
contractBalance = contractBalance.sub(profit);
|
| 224 |
+
|
| 225 |
+
emit LogResult(target, result, rollUnder, profit, roll.tokenValue, true);
|
| 226 |
+
|
| 227 |
+
|
| 228 |
+
setMaxProfit();
|
| 229 |
+
|
| 230 |
+
|
| 231 |
+
|
| 232 |
+
playerRolls[target] = playerRoll(uint200(0), uint48(0), uint8(0));
|
| 233 |
+
|
| 234 |
+
|
| 235 |
+
|
| 236 |
+
ZTHTKN.transfer(target, profit + roll.tokenValue);
|
| 237 |
+
|
| 238 |
+
return result;
|
| 239 |
+
|
| 240 |
+
} else {
|
| 241 |
+
|
| 242 |
+
emit LogResult(target, result, rollUnder, profit, roll.tokenValue, false);
|
| 243 |
+
|
| 244 |
+
|
| 245 |
+
contractBalance = contractBalance.add(roll.tokenValue);
|
| 246 |
+
|
| 247 |
+
playerRolls[target] = playerRoll(uint200(0), uint48(0), uint8(0));
|
| 248 |
+
|
| 249 |
+
|
| 250 |
+
|
| 251 |
+
|
| 252 |
+
setMaxProfit();
|
| 253 |
+
|
| 254 |
+
return result;
|
| 255 |
+
}
|
| 256 |
+
}
|
| 257 |
+
|
| 258 |
+
|
| 259 |
+
struct TKN {address sender; uint value;}
|
| 260 |
+
|
| 261 |
+
|
| 262 |
+
function tokenFallback(address _from, uint _value, bytes _data) public returns (bool) {
|
| 263 |
+
require(msg.sender == ZTHTKNADDR);
|
| 264 |
+
if (_from == ZethrBankroll) {
|
| 265 |
+
|
| 266 |
+
contractBalance = contractBalance.add(_value);
|
| 267 |
+
|
| 268 |
+
|
| 269 |
+
uint oldMaxProfit = maxProfit;
|
| 270 |
+
setMaxProfit();
|
| 271 |
+
|
| 272 |
+
emit MaxProfitChanged(oldMaxProfit, maxProfit);
|
| 273 |
+
return true;
|
| 274 |
+
|
| 275 |
+
} else {
|
| 276 |
+
TKN memory _tkn;
|
| 277 |
+
_tkn.sender = _from;
|
| 278 |
+
_tkn.value = _value;
|
| 279 |
+
uint8 chosenNumber = uint8(_data[0]);
|
| 280 |
+
_playerRollDice(chosenNumber, _tkn);
|
| 281 |
+
}
|
| 282 |
+
|
| 283 |
+
return true;
|
| 284 |
+
}
|
| 285 |
+
|
| 286 |
+
|
| 287 |
+
function setMaxProfit() internal {
|
| 288 |
+
emit CurrentContractBalance(contractBalance);
|
| 289 |
+
maxProfit = (contractBalance * maxProfitAsPercentOfHouse) / maxProfitDivisor;
|
| 290 |
+
}
|
| 291 |
+
|
| 292 |
+
|
| 293 |
+
function ownerUpdateContractBalance(uint newContractBalance) public
|
| 294 |
+
onlyOwner
|
| 295 |
+
{
|
| 296 |
+
contractBalance = newContractBalance;
|
| 297 |
+
}
|
| 298 |
+
|
| 299 |
+
|
| 300 |
+
function ownerSetMaxProfitAsPercentOfHouse(uint newMaxProfitAsPercent) public
|
| 301 |
+
onlyOwner
|
| 302 |
+
{
|
| 303 |
+
|
| 304 |
+
require(newMaxProfitAsPercent <= 200000);
|
| 305 |
+
maxProfitAsPercentOfHouse = newMaxProfitAsPercent;
|
| 306 |
+
setMaxProfit();
|
| 307 |
+
}
|
| 308 |
+
|
| 309 |
+
|
| 310 |
+
function ownerSetMinBet(uint newMinimumBet) public
|
| 311 |
+
onlyOwner
|
| 312 |
+
{
|
| 313 |
+
minBet = newMinimumBet;
|
| 314 |
+
}
|
| 315 |
+
|
| 316 |
+
|
| 317 |
+
function ownerTransferZTH(address sendTo, uint amount) public
|
| 318 |
+
onlyOwner
|
| 319 |
+
{
|
| 320 |
+
|
| 321 |
+
contractBalance = contractBalance.sub(amount);
|
| 322 |
+
|
| 323 |
+
|
| 324 |
+
setMaxProfit();
|
| 325 |
+
require(ZTHTKN.transfer(sendTo, amount));
|
| 326 |
+
emit LogOwnerTransfer(sendTo, amount);
|
| 327 |
+
}
|
| 328 |
+
|
| 329 |
+
|
| 330 |
+
function ownerPauseGame(bool newStatus) public
|
| 331 |
+
onlyOwner
|
| 332 |
+
{
|
| 333 |
+
gamePaused = newStatus;
|
| 334 |
+
}
|
| 335 |
+
|
| 336 |
+
|
| 337 |
+
function ownerSetBankroll(address newBankroll) public
|
| 338 |
+
onlyOwner
|
| 339 |
+
{
|
| 340 |
+
ZTHTKN.approve(ZethrBankroll, 0);
|
| 341 |
+
ZethrBankroll = newBankroll;
|
| 342 |
+
ZTHTKN.approve(newBankroll, MAX_INT);
|
| 343 |
+
}
|
| 344 |
+
|
| 345 |
+
|
| 346 |
+
function ownerChangeOwner(address newOwner) public
|
| 347 |
+
onlyOwner
|
| 348 |
+
{
|
| 349 |
+
owner = newOwner;
|
| 350 |
+
}
|
| 351 |
+
|
| 352 |
+
|
| 353 |
+
function ownerkill() public
|
| 354 |
+
onlyOwner
|
| 355 |
+
{
|
| 356 |
+
ZTHTKN.transfer(owner, contractBalance);
|
| 357 |
+
selfdestruct(owner);
|
| 358 |
+
}
|
| 359 |
+
|
| 360 |
+
function dumpdivs() public{
|
| 361 |
+
ZethrBankroll.transfer(address(this).balance);
|
| 362 |
+
}
|
| 363 |
+
|
| 364 |
+
function _zthToken(address _tokenContract) private view returns (bool) {
|
| 365 |
+
return _tokenContract == ZTHTKNADDR;
|
| 366 |
+
|
| 367 |
+
}
|
| 368 |
+
}
|
| 369 |
+
|
| 370 |
+
|
| 371 |
+
library SafeMath {
|
| 372 |
+
|
| 373 |
+
|
| 374 |
+
function mul(uint a, uint b) internal pure returns (uint) {
|
| 375 |
+
if (a == 0) {
|
| 376 |
+
return 0;
|
| 377 |
+
}
|
| 378 |
+
uint c = a * b;
|
| 379 |
+
assert(c / a == b);
|
| 380 |
+
return c;
|
| 381 |
+
}
|
| 382 |
+
|
| 383 |
+
|
| 384 |
+
function div(uint a, uint b) internal pure returns (uint) {
|
| 385 |
+
|
| 386 |
+
uint c = a / b;
|
| 387 |
+
|
| 388 |
+
return c;
|
| 389 |
+
}
|
| 390 |
+
|
| 391 |
+
|
| 392 |
+
function sub(uint a, uint b) internal pure returns (uint) {
|
| 393 |
+
assert(b <= a);
|
| 394 |
+
return a - b;
|
| 395 |
+
}
|
| 396 |
+
|
| 397 |
+
|
| 398 |
+
function add(uint a, uint b) internal pure returns (uint) {
|
| 399 |
+
uint c = a + b;
|
| 400 |
+
assert(c >= a);
|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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
pragma solidity ^0.4.24;
|
| 2 |
+
|
| 3 |
+
contract IMigrationContract {
|
| 4 |
+
function migrate(address addr, uint256 nas) returns (bool success);
|
| 5 |
+
}
|
| 6 |
+
|
| 7 |
+
|
| 8 |
+
contract SafeMath {
|
| 9 |
+
|
| 10 |
+
|
| 11 |
+
function safeAdd(uint256 x, uint256 y) internal returns(uint256) {
|
| 12 |
+
uint256 z = x + y;
|
| 13 |
+
assert((z >= x) && (z >= y));
|
| 14 |
+
return z;
|
| 15 |
+
}
|
| 16 |
+
|
| 17 |
+
function safeSubtract(uint256 x, uint256 y) internal returns(uint256) {
|
| 18 |
+
assert(x >= y);
|
| 19 |
+
uint256 z = x - y;
|
| 20 |
+
return z;
|
| 21 |
+
}
|
| 22 |
+
|
| 23 |
+
function safeMult(uint256 x, uint256 y) internal returns(uint256) {
|
| 24 |
+
uint256 z = x * y;
|
| 25 |
+
assert((x == 0)||(z/x == y));
|
| 26 |
+
return z;
|
| 27 |
+
}
|
| 28 |
+
|
| 29 |
+
}
|
| 30 |
+
|
| 31 |
+
contract Token {
|
| 32 |
+
uint256 public totalSupply;
|
| 33 |
+
function balanceOf(address _owner) constant returns (uint256 balance);
|
| 34 |
+
function transfer(address _to, uint256 _value) returns (bool success);
|
| 35 |
+
function transferFrom(address _from, address _to, uint256 _value) returns (bool success);
|
| 36 |
+
function approve(address _spender, uint256 _value) returns (bool success);
|
| 37 |
+
function allowance(address _owner, address _spender) constant returns (uint256 remaining);
|
| 38 |
+
event Transfer(address indexed _from, address indexed _to, uint256 _value);
|
| 39 |
+
event Approval(address indexed _owner, address indexed _spender, uint256 _value);
|
| 40 |
+
}
|
| 41 |
+
|
| 42 |
+
|
| 43 |
+
|
| 44 |
+
contract StandardToken is Token {
|
| 45 |
+
|
| 46 |
+
function transfer(address _to, uint256 _value) returns (bool success) {
|
| 47 |
+
if (balances[msg.sender] >= _value && _value > 0) {
|
| 48 |
+
balances[msg.sender] -= _value;
|
| 49 |
+
balances[_to] += _value;
|
| 50 |
+
Transfer(msg.sender, _to, _value);
|
| 51 |
+
return true;
|
| 52 |
+
} else {
|
| 53 |
+
return false;
|
| 54 |
+
}
|
| 55 |
+
}
|
| 56 |
+
|
| 57 |
+
function transferFrom(address _from, address _to, uint256 _value) returns (bool success) {
|
| 58 |
+
if (balances[_from] >= _value && allowed[_from][msg.sender] >= _value && _value > 0) {
|
| 59 |
+
balances[_to] += _value;
|
| 60 |
+
balances[_from] -= _value;
|
| 61 |
+
allowed[_from][msg.sender] -= _value;
|
| 62 |
+
Transfer(_from, _to, _value);
|
| 63 |
+
return true;
|
| 64 |
+
} else {
|
| 65 |
+
return false;
|
| 66 |
+
}
|
| 67 |
+
}
|
| 68 |
+
|
| 69 |
+
function balanceOf(address _owner) constant returns (uint256 balance) {
|
| 70 |
+
return balances[_owner];
|
| 71 |
+
}
|
| 72 |
+
|
| 73 |
+
function approve(address _spender, uint256 _value) returns (bool success) {
|
| 74 |
+
allowed[msg.sender][_spender] = _value;
|
| 75 |
+
Approval(msg.sender, _spender, _value);
|
| 76 |
+
return true;
|
| 77 |
+
}
|
| 78 |
+
|
| 79 |
+
function allowance(address _owner, address _spender) constant returns (uint256 remaining) {
|
| 80 |
+
return allowed[_owner][_spender];
|
| 81 |
+
}
|
| 82 |
+
|
| 83 |
+
mapping (address => uint256) balances;
|
| 84 |
+
mapping (address => mapping (address => uint256)) allowed;
|
| 85 |
+
}
|
| 86 |
+
|
| 87 |
+
contract EBBToken is StandardToken, SafeMath {
|
| 88 |
+
|
| 89 |
+
|
| 90 |
+
string public constant name = "易宝币";
|
| 91 |
+
string public constant symbol = "EBB";
|
| 92 |
+
uint256 public constant decimals = 18;
|
| 93 |
+
string public version = "1.0";
|
| 94 |
+
|
| 95 |
+
|
| 96 |
+
address public ethFundDeposit;
|
| 97 |
+
address public newContractAddr;
|
| 98 |
+
|
| 99 |
+
|
| 100 |
+
bool public isFunding;
|
| 101 |
+
uint256 public fundingStartBlock;
|
| 102 |
+
uint256 public fundingStopBlock;
|
| 103 |
+
|
| 104 |
+
uint256 public currentSupply;
|
| 105 |
+
uint256 public tokenRaised = 0;
|
| 106 |
+
uint256 public tokenMigrated = 0;
|
| 107 |
+
uint256 public tokenExchangeRate = 5963;
|
| 108 |
+
|
| 109 |
+
|
| 110 |
+
event AllocateToken(address indexed _to, uint256 _value);
|
| 111 |
+
event IssueToken(address indexed _to, uint256 _value);
|
| 112 |
+
event IncreaseSupply(uint256 _value);
|
| 113 |
+
event DecreaseSupply(uint256 _value);
|
| 114 |
+
event Migrate(address indexed _to, uint256 _value);
|
| 115 |
+
|
| 116 |
+
|
| 117 |
+
function formatDecimals(uint256 _value) internal returns (uint256 ) {
|
| 118 |
+
return _value * 10 ** decimals;
|
| 119 |
+
}
|
| 120 |
+
|
| 121 |
+
|
| 122 |
+
function EBBToken(
|
| 123 |
+
address _ethFundDeposit,
|
| 124 |
+
uint256 _currentSupply)
|
| 125 |
+
{
|
| 126 |
+
ethFundDeposit = _ethFundDeposit;
|
| 127 |
+
|
| 128 |
+
isFunding = false;
|
| 129 |
+
fundingStartBlock = 0;
|
| 130 |
+
fundingStopBlock = 0;
|
| 131 |
+
|
| 132 |
+
currentSupply = formatDecimals(_currentSupply);
|
| 133 |
+
totalSupply = formatDecimals(1600000000);
|
| 134 |
+
balances[msg.sender] = totalSupply;
|
| 135 |
+
if(currentSupply > totalSupply) throw;
|
| 136 |
+
}
|
| 137 |
+
|
| 138 |
+
modifier isOwner() { require(msg.sender == ethFundDeposit); _; }
|
| 139 |
+
|
| 140 |
+
|
| 141 |
+
function setTokenExchangeRate(uint256 _tokenExchangeRate) isOwner external {
|
| 142 |
+
if (_tokenExchangeRate == 0) throw;
|
| 143 |
+
if (_tokenExchangeRate == tokenExchangeRate) throw;
|
| 144 |
+
|
| 145 |
+
tokenExchangeRate = _tokenExchangeRate;
|
| 146 |
+
}
|
| 147 |
+
|
| 148 |
+
|
| 149 |
+
function increaseSupply (uint256 _value) isOwner external {
|
| 150 |
+
uint256 value = formatDecimals(_value);
|
| 151 |
+
if (value + currentSupply > totalSupply) throw;
|
| 152 |
+
currentSupply = safeAdd(currentSupply, value);
|
| 153 |
+
IncreaseSupply(value);
|
| 154 |
+
}
|
| 155 |
+
|
| 156 |
+
|
| 157 |
+
function decreaseSupply (uint256 _value) isOwner external {
|
| 158 |
+
uint256 value = formatDecimals(_value);
|
| 159 |
+
if (value + tokenRaised > currentSupply) throw;
|
| 160 |
+
|
| 161 |
+
currentSupply = safeSubtract(currentSupply, value);
|
| 162 |
+
DecreaseSupply(value);
|
| 163 |
+
}
|
| 164 |
+
|
| 165 |
+
|
| 166 |
+
function startFunding (uint256 _fundingStartBlock, uint256 _fundingStopBlock) isOwner external {
|
| 167 |
+
if (isFunding) throw;
|
| 168 |
+
if (_fundingStartBlock >= _fundingStopBlock) throw;
|
| 169 |
+
if (block.number >= _fundingStartBlock) throw;
|
| 170 |
+
|
| 171 |
+
fundingStartBlock = _fundingStartBlock;
|
| 172 |
+
fundingStopBlock = _fundingStopBlock;
|
| 173 |
+
isFunding = true;
|
| 174 |
+
}
|
| 175 |
+
|
| 176 |
+
|
| 177 |
+
function stopFunding() isOwner external {
|
| 178 |
+
if (!isFunding) throw;
|
| 179 |
+
isFunding = false;
|
| 180 |
+
}
|
| 181 |
+
|
| 182 |
+
|
| 183 |
+
function setMigrateContract(address _newContractAddr) isOwner external {
|
| 184 |
+
if (_newContractAddr == newContractAddr) throw;
|
| 185 |
+
newContractAddr = _newContractAddr;
|
| 186 |
+
}
|
| 187 |
+
|
| 188 |
+
|
| 189 |
+
function changeOwner(address _newFundDeposit) isOwner() external {
|
| 190 |
+
if (_newFundDeposit == address(0x0)) throw;
|
| 191 |
+
ethFundDeposit = _newFundDeposit;
|
| 192 |
+
}
|
| 193 |
+
|
| 194 |
+
|
| 195 |
+
function migrate() external {
|
| 196 |
+
if(isFunding) throw;
|
| 197 |
+
if(newContractAddr == address(0x0)) throw;
|
| 198 |
+
|
| 199 |
+
uint256 tokens = balances[msg.sender];
|
| 200 |
+
if (tokens == 0) throw;
|
| 201 |
+
|
| 202 |
+
balances[msg.sender] = 0;
|
| 203 |
+
tokenMigrated = safeAdd(tokenMigrated, tokens);
|
| 204 |
+
|
| 205 |
+
IMigrationContract newContract = IMigrationContract(newContractAddr);
|
| 206 |
+
if (!newContract.migrate(msg.sender, tokens)) throw;
|
| 207 |
+
|
| 208 |
+
Migrate(msg.sender, tokens);
|
| 209 |
+
}
|
| 210 |
+
|
| 211 |
+
|
| 212 |
+
function transferETH() isOwner external {
|
| 213 |
+
if (this.balance == 0) throw;
|
| 214 |
+
if (!ethFundDeposit.send(this.balance)) throw;
|
| 215 |
+
}
|
| 216 |
+
|
| 217 |
+
|
| 218 |
+
function allocateToken (address _addr, uint256 _eth) isOwner external {
|
| 219 |
+
if (_eth == 0) throw;
|
| 220 |
+
if (_addr == address(0x0)) throw;
|
| 221 |
+
|
| 222 |
+
uint256 tokens = safeMult(formatDecimals(_eth), tokenExchangeRate);
|
| 223 |
+
if (tokens + tokenRaised > currentSupply) throw;
|
| 224 |
+
|
| 225 |
+
tokenRaised = safeAdd(tokenRaised, tokens);
|
| 226 |
+
balances[_addr] += tokens;
|
| 227 |
+
|
| 228 |
+
AllocateToken(_addr, tokens);
|
| 229 |
+
}
|
| 230 |
+
|
| 231 |
+
|
| 232 |
+
function () payable {
|
| 233 |
+
if (!isFunding) throw;
|
| 234 |
+
if (msg.value == 0) throw;
|
| 235 |
+
|
| 236 |
+
if (block.number < fundingStartBlock) throw;
|
| 237 |
+
if (block.number > fundingStopBlock) throw;
|
| 238 |
+
|
| 239 |
+
uint256 tokens = safeMult(msg.value, tokenExchangeRate);
|
| 240 |
+
if (tokens + tokenRaised > currentSupply) throw;
|
| 241 |
+
|
| 242 |
+
tokenRaised = safeAdd(tokenRaised, tokens);
|
| 243 |
+
balances[msg.sender] += tokens;
|
| 244 |
+
|
| 245 |
+
IssueToken(msg.sender, tokens);
|
| 246 |
+
}
|
| 247 |
+
}
|
smart_contract_dataset/block number dependency/1761.sol
ADDED
|
@@ -0,0 +1,490 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
pragma solidity ^0.4.24;
|
| 2 |
+
|
| 3 |
+
|
| 4 |
+
|
| 5 |
+
contract ZTHReceivingContract {
|
| 6 |
+
function tokenFallback(address _from, uint _value, bytes _data) public returns (bool);
|
| 7 |
+
}
|
| 8 |
+
|
| 9 |
+
contract ZTHInterface {
|
| 10 |
+
function transfer(address _to, uint _value) public returns (bool);
|
| 11 |
+
function approve(address spender, uint tokens) public returns (bool);
|
| 12 |
+
}
|
| 13 |
+
|
| 14 |
+
contract Zlots is ZTHReceivingContract {
|
| 15 |
+
using SafeMath for uint;
|
| 16 |
+
|
| 17 |
+
address private owner;
|
| 18 |
+
address private bankroll;
|
| 19 |
+
|
| 20 |
+
|
| 21 |
+
uint totalSpins;
|
| 22 |
+
uint totalZTHWagered;
|
| 23 |
+
|
| 24 |
+
|
| 25 |
+
uint contractBalance;
|
| 26 |
+
|
| 27 |
+
|
| 28 |
+
bool public gameActive;
|
| 29 |
+
|
| 30 |
+
address private ZTHTKNADDR;
|
| 31 |
+
address private ZTHBANKROLL;
|
| 32 |
+
ZTHInterface private ZTHTKN;
|
| 33 |
+
|
| 34 |
+
mapping (uint => bool) validTokenBet;
|
| 35 |
+
|
| 36 |
+
|
| 37 |
+
event HouseRetrievedTake(
|
| 38 |
+
uint timeTaken,
|
| 39 |
+
uint tokensWithdrawn
|
| 40 |
+
);
|
| 41 |
+
|
| 42 |
+
|
| 43 |
+
event TokensWagered(
|
| 44 |
+
address _wagerer,
|
| 45 |
+
uint _wagered
|
| 46 |
+
);
|
| 47 |
+
|
| 48 |
+
event LogResult(
|
| 49 |
+
address _wagerer,
|
| 50 |
+
uint _result,
|
| 51 |
+
uint _profit,
|
| 52 |
+
uint _wagered,
|
| 53 |
+
uint _category,
|
| 54 |
+
bool _win
|
| 55 |
+
);
|
| 56 |
+
|
| 57 |
+
|
| 58 |
+
event Loss(address _wagerer, uint _block);
|
| 59 |
+
event ThreeMoonJackpot(address _wagerer, uint _block);
|
| 60 |
+
event TwoMoonPrize(address _wagerer, uint _block);
|
| 61 |
+
event ZTHJackpot(address _wagerer, uint _block);
|
| 62 |
+
event ThreeZSymbols(address _wagerer, uint _block);
|
| 63 |
+
event ThreeTSymbols(address _wagerer, uint _block);
|
| 64 |
+
event ThreeHSymbols(address _wagerer, uint _block);
|
| 65 |
+
event ThreeEtherIcons(address _wagerer, uint _block);
|
| 66 |
+
event ThreeGreenPyramids(address _wagerer, uint _block);
|
| 67 |
+
event ThreeGoldPyramids(address _wagerer, uint _block);
|
| 68 |
+
event ThreeWhitePyramids(address _wagerer, uint _block);
|
| 69 |
+
event OneMoonPrize(address _wagerer, uint _block);
|
| 70 |
+
event OneOfEachPyramidPrize(address _wagerer, uint _block);
|
| 71 |
+
event TwoZSymbols(address _wagerer, uint _block);
|
| 72 |
+
event TwoTSymbols(address _wagerer, uint _block);
|
| 73 |
+
event TwoHSymbols(address _wagerer, uint _block);
|
| 74 |
+
event TwoEtherIcons(address _wagerer, uint _block);
|
| 75 |
+
event TwoGreenPyramids(address _wagerer, uint _block);
|
| 76 |
+
event TwoGoldPyramids(address _wagerer, uint _block);
|
| 77 |
+
event TwoWhitePyramids(address _wagerer, uint _block);
|
| 78 |
+
|
| 79 |
+
event ReturnBet(
|
| 80 |
+
address _wagerer
|
| 81 |
+
);
|
| 82 |
+
|
| 83 |
+
event TwoAndAHalfXMultiplier(
|
| 84 |
+
address _wagerer
|
| 85 |
+
);
|
| 86 |
+
|
| 87 |
+
event OneAndAHalfXMultiplier(
|
| 88 |
+
address _wagerer
|
| 89 |
+
);
|
| 90 |
+
|
| 91 |
+
modifier onlyOwner {
|
| 92 |
+
require(msg.sender == owner);
|
| 93 |
+
_;
|
| 94 |
+
}
|
| 95 |
+
|
| 96 |
+
modifier onlyBankroll {
|
| 97 |
+
require(msg.sender == bankroll);
|
| 98 |
+
_;
|
| 99 |
+
}
|
| 100 |
+
|
| 101 |
+
modifier onlyOwnerOrBankroll {
|
| 102 |
+
require(msg.sender == owner || msg.sender == bankroll);
|
| 103 |
+
_;
|
| 104 |
+
}
|
| 105 |
+
|
| 106 |
+
|
| 107 |
+
modifier gameIsActive {
|
| 108 |
+
require(gameActive == true);
|
| 109 |
+
_;
|
| 110 |
+
}
|
| 111 |
+
|
| 112 |
+
constructor(address ZethrAddress, address BankrollAddress) public {
|
| 113 |
+
|
| 114 |
+
|
| 115 |
+
ZTHTKNADDR = ZethrAddress;
|
| 116 |
+
ZTHBANKROLL = BankrollAddress;
|
| 117 |
+
|
| 118 |
+
|
| 119 |
+
owner = msg.sender;
|
| 120 |
+
bankroll = ZTHBANKROLL;
|
| 121 |
+
|
| 122 |
+
|
| 123 |
+
ZTHTKN = ZTHInterface(ZTHTKNADDR);
|
| 124 |
+
ZTHTKN.approve(ZTHBANKROLL, 2**256 - 1);
|
| 125 |
+
|
| 126 |
+
|
| 127 |
+
ZTHTKN.approve(owner, 2**256 - 1);
|
| 128 |
+
|
| 129 |
+
|
| 130 |
+
validTokenBet[5e18] = true;
|
| 131 |
+
validTokenBet[10e18] = true;
|
| 132 |
+
validTokenBet[25e18] = true;
|
| 133 |
+
validTokenBet[50e18] = true;
|
| 134 |
+
|
| 135 |
+
gameActive = true;
|
| 136 |
+
}
|
| 137 |
+
|
| 138 |
+
|
| 139 |
+
function() public payable { }
|
| 140 |
+
|
| 141 |
+
|
| 142 |
+
struct TKN { address sender; uint value; }
|
| 143 |
+
function tokenFallback(address _from, uint _value, bytes ) public returns (bool){
|
| 144 |
+
if (_from == bankroll) {
|
| 145 |
+
|
| 146 |
+
contractBalance = contractBalance.add(_value);
|
| 147 |
+
return true;
|
| 148 |
+
} else {
|
| 149 |
+
TKN memory _tkn;
|
| 150 |
+
_tkn.sender = _from;
|
| 151 |
+
_tkn.value = _value;
|
| 152 |
+
_spinTokens(_tkn);
|
| 153 |
+
return true;
|
| 154 |
+
}
|
| 155 |
+
}
|
| 156 |
+
|
| 157 |
+
struct playerSpin {
|
| 158 |
+
uint200 tokenValue;
|
| 159 |
+
uint48 blockn;
|
| 160 |
+
}
|
| 161 |
+
|
| 162 |
+
|
| 163 |
+
mapping(address => playerSpin) public playerSpins;
|
| 164 |
+
|
| 165 |
+
|
| 166 |
+
function _spinTokens(TKN _tkn) private {
|
| 167 |
+
|
| 168 |
+
require(gameActive);
|
| 169 |
+
require(_zthToken(msg.sender));
|
| 170 |
+
require(validTokenBet[_tkn.value]);
|
| 171 |
+
require(jackpotGuard(_tkn.value));
|
| 172 |
+
|
| 173 |
+
require(_tkn.value < ((2 ** 200) - 1));
|
| 174 |
+
require(block.number < ((2 ** 48) - 1));
|
| 175 |
+
|
| 176 |
+
address _customerAddress = _tkn.sender;
|
| 177 |
+
uint _wagered = _tkn.value;
|
| 178 |
+
|
| 179 |
+
playerSpin memory spin = playerSpins[_tkn.sender];
|
| 180 |
+
|
| 181 |
+
contractBalance = contractBalance.add(_wagered);
|
| 182 |
+
|
| 183 |
+
|
| 184 |
+
require(block.number != spin.blockn);
|
| 185 |
+
|
| 186 |
+
|
| 187 |
+
if (spin.blockn != 0) {
|
| 188 |
+
_finishSpin(_tkn.sender);
|
| 189 |
+
}
|
| 190 |
+
|
| 191 |
+
|
| 192 |
+
spin.blockn = uint48(block.number);
|
| 193 |
+
spin.tokenValue = uint200(_wagered);
|
| 194 |
+
|
| 195 |
+
|
| 196 |
+
playerSpins[_tkn.sender] = spin;
|
| 197 |
+
|
| 198 |
+
|
| 199 |
+
totalSpins += 1;
|
| 200 |
+
|
| 201 |
+
|
| 202 |
+
totalZTHWagered += _wagered;
|
| 203 |
+
|
| 204 |
+
emit TokensWagered(_customerAddress, _wagered);
|
| 205 |
+
|
| 206 |
+
}
|
| 207 |
+
|
| 208 |
+
|
| 209 |
+
function finishSpin() public
|
| 210 |
+
gameIsActive
|
| 211 |
+
returns (uint)
|
| 212 |
+
{
|
| 213 |
+
return _finishSpin(msg.sender);
|
| 214 |
+
}
|
| 215 |
+
|
| 216 |
+
|
| 217 |
+
function _finishSpin(address target)
|
| 218 |
+
private returns (uint)
|
| 219 |
+
{
|
| 220 |
+
playerSpin memory spin = playerSpins[target];
|
| 221 |
+
|
| 222 |
+
require(spin.tokenValue > 0);
|
| 223 |
+
require(spin.blockn != block.number);
|
| 224 |
+
|
| 225 |
+
uint profit = 0;
|
| 226 |
+
uint category = 0;
|
| 227 |
+
|
| 228 |
+
|
| 229 |
+
|
| 230 |
+
uint result;
|
| 231 |
+
if (block.number - spin.blockn > 255) {
|
| 232 |
+
result = 9999;
|
| 233 |
+
} else {
|
| 234 |
+
|
| 235 |
+
|
| 236 |
+
|
| 237 |
+
result = random(1000000, spin.blockn, target);
|
| 238 |
+
}
|
| 239 |
+
|
| 240 |
+
if (result > 476661) {
|
| 241 |
+
|
| 242 |
+
emit Loss(target, spin.blockn);
|
| 243 |
+
emit LogResult(target, result, profit, spin.tokenValue, category, false);
|
| 244 |
+
} else {
|
| 245 |
+
if (result < 1) {
|
| 246 |
+
|
| 247 |
+
profit = SafeMath.mul(spin.tokenValue, 500);
|
| 248 |
+
category = 1;
|
| 249 |
+
emit ThreeMoonJackpot(target, spin.blockn);
|
| 250 |
+
} else {
|
| 251 |
+
if (result < 298) {
|
| 252 |
+
|
| 253 |
+
profit = SafeMath.mul(spin.tokenValue, 232);
|
| 254 |
+
category = 2;
|
| 255 |
+
emit TwoMoonPrize(target, spin.blockn);
|
| 256 |
+
} else {
|
| 257 |
+
if (result < 3127) {
|
| 258 |
+
|
| 259 |
+
profit = SafeMath.div(SafeMath.mul(spin.tokenValue, 232), 10);
|
| 260 |
+
category = 3;
|
| 261 |
+
emit ZTHJackpot(target, spin.blockn);
|
| 262 |
+
|
| 263 |
+
} else {
|
| 264 |
+
if (result < 5956) {
|
| 265 |
+
|
| 266 |
+
profit = SafeMath.mul(spin.tokenValue, 25);
|
| 267 |
+
category = 4;
|
| 268 |
+
emit ThreeZSymbols(target, spin.blockn);
|
| 269 |
+
} else {
|
| 270 |
+
if (result < 8785) {
|
| 271 |
+
|
| 272 |
+
profit = SafeMath.mul(spin.tokenValue, 25);
|
| 273 |
+
category = 5;
|
| 274 |
+
emit ThreeTSymbols(target, spin.blockn);
|
| 275 |
+
} else {
|
| 276 |
+
if (result < 11614) {
|
| 277 |
+
|
| 278 |
+
profit = SafeMath.mul(spin.tokenValue, 25);
|
| 279 |
+
category = 6;
|
| 280 |
+
emit ThreeHSymbols(target, spin.blockn);
|
| 281 |
+
} else {
|
| 282 |
+
if (result < 14443) {
|
| 283 |
+
|
| 284 |
+
profit = SafeMath.mul(spin.tokenValue, 50);
|
| 285 |
+
category = 7;
|
| 286 |
+
emit ThreeEtherIcons(target, spin.blockn);
|
| 287 |
+
} else {
|
| 288 |
+
if (result < 17272) {
|
| 289 |
+
|
| 290 |
+
profit = SafeMath.mul(spin.tokenValue, 40);
|
| 291 |
+
category = 8;
|
| 292 |
+
emit ThreeGreenPyramids(target, spin.blockn);
|
| 293 |
+
} else {
|
| 294 |
+
if (result < 20101) {
|
| 295 |
+
|
| 296 |
+
profit = SafeMath.mul(spin.tokenValue, 20);
|
| 297 |
+
category = 9;
|
| 298 |
+
emit ThreeGoldPyramids(target, spin.blockn);
|
| 299 |
+
} else {
|
| 300 |
+
if (result < 22929) {
|
| 301 |
+
|
| 302 |
+
profit = SafeMath.mul(spin.tokenValue, 20);
|
| 303 |
+
category = 10;
|
| 304 |
+
emit ThreeWhitePyramids(target, spin.blockn);
|
| 305 |
+
} else {
|
| 306 |
+
if (result < 52332) {
|
| 307 |
+
|
| 308 |
+
profit = SafeMath.div(SafeMath.mul(spin.tokenValue, 125),10);
|
| 309 |
+
category = 11;
|
| 310 |
+
emit OneMoonPrize(target, spin.blockn);
|
| 311 |
+
} else {
|
| 312 |
+
if (result < 120225) {
|
| 313 |
+
|
| 314 |
+
profit = SafeMath.div(SafeMath.mul(spin.tokenValue, 15),10);
|
| 315 |
+
category = 12;
|
| 316 |
+
emit OneOfEachPyramidPrize(target, spin.blockn);
|
| 317 |
+
} else {
|
| 318 |
+
if (result < 171146) {
|
| 319 |
+
|
| 320 |
+
profit = SafeMath.div(SafeMath.mul(spin.tokenValue, 232),100);
|
| 321 |
+
category = 13;
|
| 322 |
+
emit TwoZSymbols(target, spin.blockn);
|
| 323 |
+
} else {
|
| 324 |
+
if (result < 222067) {
|
| 325 |
+
|
| 326 |
+
profit = SafeMath.div(SafeMath.mul(spin.tokenValue, 232),100);
|
| 327 |
+
category = 14;
|
| 328 |
+
emit TwoTSymbols(target, spin.blockn);
|
| 329 |
+
} else {
|
| 330 |
+
if (result < 272988) {
|
| 331 |
+
|
| 332 |
+
profit = SafeMath.div(SafeMath.mul(spin.tokenValue, 232),100);
|
| 333 |
+
category = 15;
|
| 334 |
+
emit TwoHSymbols(target, spin.blockn);
|
| 335 |
+
} else {
|
| 336 |
+
if (result < 323909) {
|
| 337 |
+
|
| 338 |
+
profit = SafeMath.div(SafeMath.mul(spin.tokenValue, 375),100);
|
| 339 |
+
category = 16;
|
| 340 |
+
emit TwoEtherIcons(target, spin.blockn);
|
| 341 |
+
} else {
|
| 342 |
+
if (result < 374830) {
|
| 343 |
+
|
| 344 |
+
profit = SafeMath.div(SafeMath.mul(spin.tokenValue, 35),10);
|
| 345 |
+
category = 17;
|
| 346 |
+
emit TwoGreenPyramids(target, spin.blockn);
|
| 347 |
+
} else {
|
| 348 |
+
if (result < 425751) {
|
| 349 |
+
|
| 350 |
+
profit = SafeMath.div(SafeMath.mul(spin.tokenValue, 225),100);
|
| 351 |
+
category = 18;
|
| 352 |
+
emit TwoGoldPyramids(target, spin.blockn);
|
| 353 |
+
} else {
|
| 354 |
+
|
| 355 |
+
profit = SafeMath.mul(spin.tokenValue, 2);
|
| 356 |
+
category = 19;
|
| 357 |
+
emit TwoWhitePyramids(target, spin.blockn);
|
| 358 |
+
}
|
| 359 |
+
|
| 360 |
+
emit LogResult(target, result, profit, spin.tokenValue, category, true);
|
| 361 |
+
contractBalance = contractBalance.sub(profit);
|
| 362 |
+
ZTHTKN.transfer(target, profit);
|
| 363 |
+
|
| 364 |
+
|
| 365 |
+
}}}}}}}}}}}}}}}}}}
|
| 366 |
+
|
| 367 |
+
playerSpins[target] = playerSpin(uint200(0), uint48(0));
|
| 368 |
+
return result;
|
| 369 |
+
}
|
| 370 |
+
|
| 371 |
+
|
| 372 |
+
|
| 373 |
+
|
| 374 |
+
|
| 375 |
+
function jackpotGuard(uint _wager)
|
| 376 |
+
private
|
| 377 |
+
view
|
| 378 |
+
returns (bool)
|
| 379 |
+
{
|
| 380 |
+
uint maxProfit = SafeMath.mul(_wager, 500);
|
| 381 |
+
uint ninetyContractBalance = SafeMath.mul(SafeMath.div(contractBalance, 10), 9);
|
| 382 |
+
return (maxProfit <= ninetyContractBalance);
|
| 383 |
+
}
|
| 384 |
+
|
| 385 |
+
|
| 386 |
+
|
| 387 |
+
function maxRandom(uint blockn, address entropy) private view returns (uint256 randomNumber) {
|
| 388 |
+
return uint256(keccak256(
|
| 389 |
+
abi.encodePacked(
|
| 390 |
+
blockhash(blockn),
|
| 391 |
+
entropy)
|
| 392 |
+
));
|
| 393 |
+
}
|
| 394 |
+
|
| 395 |
+
|
| 396 |
+
function random(uint256 upper, uint256 blockn, address entropy) internal view returns (uint256 randomNumber) {
|
| 397 |
+
return maxRandom(blockn, entropy) % upper;
|
| 398 |
+
}
|
| 399 |
+
|
| 400 |
+
|
| 401 |
+
function balanceOf() public view returns (uint) {
|
| 402 |
+
return contractBalance;
|
| 403 |
+
}
|
| 404 |
+
|
| 405 |
+
function addNewBetAmount(uint _tokenAmount)
|
| 406 |
+
public
|
| 407 |
+
onlyOwner
|
| 408 |
+
{
|
| 409 |
+
validTokenBet[_tokenAmount] = true;
|
| 410 |
+
}
|
| 411 |
+
|
| 412 |
+
|
| 413 |
+
function pauseGame() public onlyOwner {
|
| 414 |
+
gameActive = false;
|
| 415 |
+
}
|
| 416 |
+
|
| 417 |
+
|
| 418 |
+
function resumeGame() public onlyOwner {
|
| 419 |
+
gameActive = true;
|
| 420 |
+
}
|
| 421 |
+
|
| 422 |
+
|
| 423 |
+
function changeOwner(address _newOwner) public onlyOwner {
|
| 424 |
+
owner = _newOwner;
|
| 425 |
+
}
|
| 426 |
+
|
| 427 |
+
|
| 428 |
+
function changeBankroll(address _newBankroll) public onlyOwner {
|
| 429 |
+
bankroll = _newBankroll;
|
| 430 |
+
}
|
| 431 |
+
|
| 432 |
+
|
| 433 |
+
function divertDividendsToBankroll()
|
| 434 |
+
public
|
| 435 |
+
onlyOwner
|
| 436 |
+
{
|
| 437 |
+
bankroll.transfer(address(this).balance);
|
| 438 |
+
}
|
| 439 |
+
|
| 440 |
+
function testingSelfDestruct()
|
| 441 |
+
public
|
| 442 |
+
onlyOwner
|
| 443 |
+
{
|
| 444 |
+
|
| 445 |
+
ZTHTKN.transfer(owner, contractBalance);
|
| 446 |
+
selfdestruct(owner);
|
| 447 |
+
}
|
| 448 |
+
|
| 449 |
+
|
| 450 |
+
function _zthToken(address _tokenContract) private view returns (bool) {
|
| 451 |
+
return _tokenContract == ZTHTKNADDR;
|
| 452 |
+
}
|
| 453 |
+
}
|
| 454 |
+
|
| 455 |
+
|
| 456 |
+
|
| 457 |
+
|
| 458 |
+
library SafeMath {
|
| 459 |
+
|
| 460 |
+
|
| 461 |
+
function mul(uint a, uint b) internal pure returns (uint) {
|
| 462 |
+
if (a == 0) {
|
| 463 |
+
return 0;
|
| 464 |
+
}
|
| 465 |
+
uint c = a * b;
|
| 466 |
+
assert(c / a == b);
|
| 467 |
+
return c;
|
| 468 |
+
}
|
| 469 |
+
|
| 470 |
+
|
| 471 |
+
function div(uint a, uint b) internal pure returns (uint) {
|
| 472 |
+
|
| 473 |
+
uint c = a / b;
|
| 474 |
+
|
| 475 |
+
return c;
|
| 476 |
+
}
|
| 477 |
+
|
| 478 |
+
|
| 479 |
+
function sub(uint a, uint b) internal pure returns (uint) {
|
| 480 |
+
assert(b <= a);
|
| 481 |
+
return a - b;
|
| 482 |
+
}
|
| 483 |
+
|
| 484 |
+
|
| 485 |
+
function add(uint a, uint b) internal pure returns (uint) {
|
| 486 |
+
uint c = a + b;
|
| 487 |
+
assert(c >= a);
|
| 488 |
+
return c;
|
| 489 |
+
}
|
| 490 |
+
}
|
smart_contract_dataset/block number dependency/1791.sol
ADDED
|
@@ -0,0 +1,222 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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
+
|
| 8 |
+
|
| 9 |
+
|
| 10 |
+
if (a == 0) {
|
| 11 |
+
return 0;
|
| 12 |
+
}
|
| 13 |
+
|
| 14 |
+
c = a * b;
|
| 15 |
+
assert(c / a == b);
|
| 16 |
+
return c;
|
| 17 |
+
}
|
| 18 |
+
|
| 19 |
+
|
| 20 |
+
function div(uint256 a, uint256 b) internal pure returns (uint256) {
|
| 21 |
+
|
| 22 |
+
|
| 23 |
+
|
| 24 |
+
return a / b;
|
| 25 |
+
}
|
| 26 |
+
|
| 27 |
+
|
| 28 |
+
function sub(uint256 a, uint256 b) internal pure returns (uint256) {
|
| 29 |
+
assert(b <= a);
|
| 30 |
+
return a - b;
|
| 31 |
+
}
|
| 32 |
+
|
| 33 |
+
|
| 34 |
+
function add(uint256 a, uint256 b) internal pure returns (uint256 c) {
|
| 35 |
+
c = a + b;
|
| 36 |
+
assert(c >= a);
|
| 37 |
+
return c;
|
| 38 |
+
}
|
| 39 |
+
}
|
| 40 |
+
|
| 41 |
+
contract Ownable {
|
| 42 |
+
address public owner;
|
| 43 |
+
|
| 44 |
+
|
| 45 |
+
event OwnershipRenounced(address indexed previousOwner);
|
| 46 |
+
event OwnershipTransferred(
|
| 47 |
+
address indexed previousOwner,
|
| 48 |
+
address indexed newOwner
|
| 49 |
+
);
|
| 50 |
+
|
| 51 |
+
|
| 52 |
+
|
| 53 |
+
constructor() public {
|
| 54 |
+
owner = msg.sender;
|
| 55 |
+
}
|
| 56 |
+
|
| 57 |
+
|
| 58 |
+
modifier onlyOwner() {
|
| 59 |
+
require(msg.sender == owner);
|
| 60 |
+
_;
|
| 61 |
+
}
|
| 62 |
+
|
| 63 |
+
|
| 64 |
+
function renounceOwnership() public onlyOwner {
|
| 65 |
+
emit OwnershipRenounced(owner);
|
| 66 |
+
owner = address(0);
|
| 67 |
+
}
|
| 68 |
+
|
| 69 |
+
|
| 70 |
+
function transferOwnership(address _newOwner) public onlyOwner {
|
| 71 |
+
_transferOwnership(_newOwner);
|
| 72 |
+
}
|
| 73 |
+
|
| 74 |
+
|
| 75 |
+
function _transferOwnership(address _newOwner) internal {
|
| 76 |
+
require(_newOwner != address(0));
|
| 77 |
+
emit OwnershipTransferred(owner, _newOwner);
|
| 78 |
+
owner = _newOwner;
|
| 79 |
+
}
|
| 80 |
+
}
|
| 81 |
+
|
| 82 |
+
contract Claimable is Ownable {
|
| 83 |
+
address public pendingOwner;
|
| 84 |
+
|
| 85 |
+
|
| 86 |
+
modifier onlyPendingOwner() {
|
| 87 |
+
require(msg.sender == pendingOwner);
|
| 88 |
+
_;
|
| 89 |
+
}
|
| 90 |
+
|
| 91 |
+
|
| 92 |
+
function transferOwnership(address newOwner) onlyOwner public {
|
| 93 |
+
pendingOwner = newOwner;
|
| 94 |
+
}
|
| 95 |
+
|
| 96 |
+
|
| 97 |
+
function claimOwnership() onlyPendingOwner public {
|
| 98 |
+
emit OwnershipTransferred(owner, pendingOwner);
|
| 99 |
+
owner = pendingOwner;
|
| 100 |
+
pendingOwner = address(0);
|
| 101 |
+
}
|
| 102 |
+
}
|
| 103 |
+
|
| 104 |
+
contract SimpleFlyDropToken is Claimable {
|
| 105 |
+
using SafeMath for uint256;
|
| 106 |
+
|
| 107 |
+
ERC20 internal erc20tk;
|
| 108 |
+
|
| 109 |
+
function setToken(address _token) onlyOwner public {
|
| 110 |
+
require(_token != address(0));
|
| 111 |
+
erc20tk = ERC20(_token);
|
| 112 |
+
}
|
| 113 |
+
|
| 114 |
+
|
| 115 |
+
function multiSend(address[] _destAddrs, uint256[] _values) onlyOwner public returns (uint256) {
|
| 116 |
+
require(_destAddrs.length == _values.length);
|
| 117 |
+
|
| 118 |
+
uint256 i = 0;
|
| 119 |
+
for (; i < _destAddrs.length; i = i.add(1)) {
|
| 120 |
+
if (!erc20tk.transfer(_destAddrs[i], _values[i])) {
|
| 121 |
+
break;
|
| 122 |
+
}
|
| 123 |
+
}
|
| 124 |
+
|
| 125 |
+
return (i);
|
| 126 |
+
}
|
| 127 |
+
}
|
| 128 |
+
|
| 129 |
+
contract DelayedClaimable is Claimable {
|
| 130 |
+
|
| 131 |
+
uint256 public end;
|
| 132 |
+
uint256 public start;
|
| 133 |
+
|
| 134 |
+
|
| 135 |
+
function setLimits(uint256 _start, uint256 _end) onlyOwner public {
|
| 136 |
+
require(_start <= _end);
|
| 137 |
+
end = _end;
|
| 138 |
+
start = _start;
|
| 139 |
+
}
|
| 140 |
+
|
| 141 |
+
|
| 142 |
+
function claimOwnership() onlyPendingOwner public {
|
| 143 |
+
require((block.number <= end) && (block.number >= start));
|
| 144 |
+
emit OwnershipTransferred(owner, pendingOwner);
|
| 145 |
+
owner = pendingOwner;
|
| 146 |
+
pendingOwner = address(0);
|
| 147 |
+
end = 0;
|
| 148 |
+
}
|
| 149 |
+
|
| 150 |
+
}
|
| 151 |
+
|
| 152 |
+
contract FlyDropTokenMgr is DelayedClaimable {
|
| 153 |
+
using SafeMath for uint256;
|
| 154 |
+
|
| 155 |
+
address[] dropTokenAddrs;
|
| 156 |
+
SimpleFlyDropToken currentDropTokenContract;
|
| 157 |
+
|
| 158 |
+
|
| 159 |
+
|
| 160 |
+
function prepare(uint256 _rand,
|
| 161 |
+
address _from,
|
| 162 |
+
address _token,
|
| 163 |
+
uint256 _value) onlyOwner public returns (bool) {
|
| 164 |
+
require(_token != address(0));
|
| 165 |
+
require(_from != address(0));
|
| 166 |
+
require(_rand > 0);
|
| 167 |
+
|
| 168 |
+
if (ERC20(_token).allowance(_from, this) < _value) {
|
| 169 |
+
return false;
|
| 170 |
+
}
|
| 171 |
+
|
| 172 |
+
if (_rand > dropTokenAddrs.length) {
|
| 173 |
+
SimpleFlyDropToken dropTokenContract = new SimpleFlyDropToken();
|
| 174 |
+
dropTokenAddrs.push(address(dropTokenContract));
|
| 175 |
+
currentDropTokenContract = dropTokenContract;
|
| 176 |
+
} else {
|
| 177 |
+
currentDropTokenContract = SimpleFlyDropToken(dropTokenAddrs[_rand.sub(1)]);
|
| 178 |
+
}
|
| 179 |
+
|
| 180 |
+
currentDropTokenContract.setToken(_token);
|
| 181 |
+
return ERC20(_token).transferFrom(_from, currentDropTokenContract, _value);
|
| 182 |
+
|
| 183 |
+
|
| 184 |
+
|
| 185 |
+
}
|
| 186 |
+
|
| 187 |
+
|
| 188 |
+
|
| 189 |
+
|
| 190 |
+
|
| 191 |
+
|
| 192 |
+
|
| 193 |
+
|
| 194 |
+
|
| 195 |
+
function flyDrop(address[] _destAddrs, uint256[] _values) onlyOwner public returns (uint256) {
|
| 196 |
+
require(address(currentDropTokenContract) != address(0));
|
| 197 |
+
return currentDropTokenContract.multiSend(_destAddrs, _values);
|
| 198 |
+
}
|
| 199 |
+
|
| 200 |
+
}
|
| 201 |
+
|
| 202 |
+
contract ERC20Basic {
|
| 203 |
+
function totalSupply() public view returns (uint256);
|
| 204 |
+
function balanceOf(address who) public view returns (uint256);
|
| 205 |
+
function transfer(address to, uint256 value) public returns (bool);
|
| 206 |
+
event Transfer(address indexed from, address indexed to, uint256 value);
|
| 207 |
+
}
|
| 208 |
+
|
| 209 |
+
contract ERC20 is ERC20Basic {
|
| 210 |
+
function allowance(address owner, address spender)
|
| 211 |
+
public view returns (uint256);
|
| 212 |
+
|
| 213 |
+
function transferFrom(address from, address to, uint256 value)
|
| 214 |
+
public returns (bool);
|
| 215 |
+
|
| 216 |
+
function approve(address spender, uint256 value) public returns (bool);
|
| 217 |
+
event Approval(
|
| 218 |
+
address indexed owner,
|
| 219 |
+
address indexed spender,
|
| 220 |
+
uint256 value
|
| 221 |
+
);
|
| 222 |
+
}
|
smart_contract_dataset/block number dependency/1986.sol
ADDED
|
@@ -0,0 +1,1250 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
pragma solidity ^0.4.18;
|
| 2 |
+
|
| 3 |
+
contract PoP{
|
| 4 |
+
using SafeMath for uint256;
|
| 5 |
+
using SafeInt for int256;
|
| 6 |
+
using Player for Player.Data;
|
| 7 |
+
using BettingRecordArray for BettingRecordArray.Data;
|
| 8 |
+
using WrappedArray for WrappedArray.Data;
|
| 9 |
+
using FixedPoint for FixedPoint.Data;
|
| 10 |
+
|
| 11 |
+
|
| 12 |
+
string public name;
|
| 13 |
+
string public symbol;
|
| 14 |
+
uint8 public decimals;
|
| 15 |
+
address private author;
|
| 16 |
+
|
| 17 |
+
|
| 18 |
+
event Bet(address player, uint256 betAmount, uint256 betNumber, uint256 gameNumber);
|
| 19 |
+
event Withdraw(address player, uint256 amount, uint256 numberOfRecordsProcessed);
|
| 20 |
+
event EndGame(uint256 currentGameNumber);
|
| 21 |
+
|
| 22 |
+
|
| 23 |
+
event Transfer(address indexed from, address indexed to, uint256 value);
|
| 24 |
+
event Approval(address indexed owner, address indexed spender, uint256 value);
|
| 25 |
+
event Burn(address indexed burner, uint256 value);
|
| 26 |
+
event Mined(address indexed miner, uint256 value);
|
| 27 |
+
|
| 28 |
+
|
| 29 |
+
function PoP() public {
|
| 30 |
+
name = "PopCoin";
|
| 31 |
+
symbol = "PoP";
|
| 32 |
+
decimals = 18;
|
| 33 |
+
author = msg.sender;
|
| 34 |
+
totalSupply_ = 10000000 * 10 ** uint256(decimals);
|
| 35 |
+
lastBetBlockNumber = 0;
|
| 36 |
+
currentGameNumber = 0;
|
| 37 |
+
currentPot = 0;
|
| 38 |
+
initialSeed = 0;
|
| 39 |
+
minimumWager = kBaseMinBetSize.toUInt256Raw();
|
| 40 |
+
minimumNumberOfBlocksToEndGame = kLowerBoundBlocksTillGameEnd.add(kUpperBoundBlocksTillGameEnd).toUInt256Raw();
|
| 41 |
+
gameHasStarted = false;
|
| 42 |
+
currentMiningDifficulty = FixedPoint.fromInt256(kStartingGameMiningDifficulty);
|
| 43 |
+
unPromisedSupplyAtStartOfCurrentGame_ = totalSupply_;
|
| 44 |
+
nextGameMaxBlock = kUpperBoundBlocksTillGameEnd;
|
| 45 |
+
nextGameMinBlock = kLowerBoundBlocksTillGameEnd;
|
| 46 |
+
currentGameInitialMinBetSize = kBaseMinBetSize;
|
| 47 |
+
}
|
| 48 |
+
|
| 49 |
+
|
| 50 |
+
|
| 51 |
+
FixedPoint.Data _2pi = FixedPoint.Data({val: 26986075409});
|
| 52 |
+
FixedPoint.Data _pi = FixedPoint.Data({val: 13493037704});
|
| 53 |
+
FixedPoint.Data frontWindowAdjustmentRatio = FixedPoint.fromFraction(14, 10);
|
| 54 |
+
FixedPoint.Data backWindowAdjustmentRatio = FixedPoint.fromFraction(175, 100);
|
| 55 |
+
FixedPoint.Data kBackPayoutEndPointInitial = FixedPoint.fromFraction(1, 2);
|
| 56 |
+
FixedPoint.Data kFrontPayoutStartPointInitial = FixedPoint.fromFraction(1, 2);
|
| 57 |
+
uint256 constant kPercentToTakeAsRake = 3;
|
| 58 |
+
uint256 constant kPercentToTakeAsSeed = 9;
|
| 59 |
+
uint256 constant kDeveloperMiningPower = 30;
|
| 60 |
+
uint256 constant kTotalPercent = 100;
|
| 61 |
+
uint8 constant kStartingGameMiningDifficulty = 1;
|
| 62 |
+
uint8 constant kDifficultyWindow = 10;
|
| 63 |
+
FixedPoint.Data kDifficultyDropOffFactor = FixedPoint.fromFraction(8, 10);
|
| 64 |
+
uint256 constant kWeiConstant = 10 ** 18;
|
| 65 |
+
FixedPoint.Data kExpectedFirstGameSize = FixedPoint.fromInt256(Int256(10 * kWeiConstant));
|
| 66 |
+
FixedPoint.Data kExpectedPopCoinToBePromisedPercent = FixedPoint.fromFraction(1, 1000);
|
| 67 |
+
FixedPoint.Data kLowerBoundBlocksTillGameEnd = FixedPoint.fromInt256(6);
|
| 68 |
+
FixedPoint.Data kUpperBoundBlocksTillGameEnd = FixedPoint.fromInt256(80);
|
| 69 |
+
FixedPoint.Data kBaseMinBetSize = FixedPoint.fromInt256(Int256(kWeiConstant/1000));
|
| 70 |
+
FixedPoint.Data kMaxPopMiningPotMultiple = FixedPoint.fromFraction(118709955, 1000000);
|
| 71 |
+
|
| 72 |
+
|
| 73 |
+
|
| 74 |
+
uint256 public lastBetBlockNumber;
|
| 75 |
+
uint256 public minimumNumberOfBlocksToEndGame;
|
| 76 |
+
uint256 public currentPot;
|
| 77 |
+
uint256 public currentGameNumber;
|
| 78 |
+
FixedPoint.Data currentMiningDifficulty;
|
| 79 |
+
uint256 public initialSeed;
|
| 80 |
+
|
| 81 |
+
|
| 82 |
+
|
| 83 |
+
mapping (address => Player.Data) playerCollection;
|
| 84 |
+
BettingRecordArray.Data currentGameBettingRecords;
|
| 85 |
+
WrappedArray.Data gameMetaData;
|
| 86 |
+
mapping (address => uint256) playerInternalWallet;
|
| 87 |
+
FixedPoint.Data public initialBankrollGrowthAmount;
|
| 88 |
+
FixedPoint.Data nextGameInitialMinBetSize;
|
| 89 |
+
FixedPoint.Data currentGameInitialMinBetSize;
|
| 90 |
+
FixedPoint.Data nextGameMaxBlock;
|
| 91 |
+
FixedPoint.Data nextGameMinBlock;
|
| 92 |
+
uint256 bonusSeed;
|
| 93 |
+
uint256 minimumWager;
|
| 94 |
+
uint256 currentBetNumber;
|
| 95 |
+
|
| 96 |
+
|
| 97 |
+
mapping(address => uint256) popBalances;
|
| 98 |
+
mapping (address => mapping (address => uint256)) internal allowed;
|
| 99 |
+
uint256 totalSupply_;
|
| 100 |
+
uint256 supplyMined_;
|
| 101 |
+
uint256 supplyBurned_;
|
| 102 |
+
uint256 unPromisedSupplyAtStartOfCurrentGame_;
|
| 103 |
+
bool gameHasStarted;
|
| 104 |
+
|
| 105 |
+
function startGame () payable public {
|
| 106 |
+
require (msg.sender == author);
|
| 107 |
+
require (msg.value > 0);
|
| 108 |
+
require (gameHasStarted == false);
|
| 109 |
+
|
| 110 |
+
initialSeed = initialSeed.add(msg.value);
|
| 111 |
+
currentPot = initialSeed;
|
| 112 |
+
gameHasStarted = true;
|
| 113 |
+
}
|
| 114 |
+
|
| 115 |
+
function updateNextGameMinAndMaxBlockUntilGameEnd (uint256 maxBlocks, uint256 minBlocks) public {
|
| 116 |
+
require (msg.sender == author);
|
| 117 |
+
require (maxBlocks > 0);
|
| 118 |
+
require (minBlocks > 0);
|
| 119 |
+
FixedPoint.Data memory nextMaxBlock = FixedPoint.fromInt256(Int256(maxBlocks));
|
| 120 |
+
FixedPoint.Data memory nextMinBlock = FixedPoint.fromInt256(Int256(minBlocks));
|
| 121 |
+
require(nextMaxBlock.cmp(kUpperBoundBlocksTillGameEnd.mul(FixedPoint.fromInt256(2))) != 1);
|
| 122 |
+
require(nextMaxBlock.cmp(kUpperBoundBlocksTillGameEnd.div(FixedPoint.fromInt256(2))) != -1);
|
| 123 |
+
require(nextMinBlock.cmp(kLowerBoundBlocksTillGameEnd.mul(FixedPoint.fromInt256(2))) != 1);
|
| 124 |
+
require(nextMaxBlock.cmp(kLowerBoundBlocksTillGameEnd.div(FixedPoint.fromInt256(2))) != -1);
|
| 125 |
+
|
| 126 |
+
nextGameMaxBlock = FixedPoint.fromInt256(Int256(maxBlocks));
|
| 127 |
+
nextGameMinBlock = FixedPoint.fromInt256(Int256(minBlocks));
|
| 128 |
+
}
|
| 129 |
+
|
| 130 |
+
function addToRakePool () public payable{
|
| 131 |
+
assert (msg.value > 0);
|
| 132 |
+
playerInternalWallet[this] = playerInternalWallet[this].add(msg.value);
|
| 133 |
+
}
|
| 134 |
+
|
| 135 |
+
|
| 136 |
+
function bet () payable public {
|
| 137 |
+
|
| 138 |
+
require(msg.value >= minimumWager);
|
| 139 |
+
require(gameHasStarted);
|
| 140 |
+
|
| 141 |
+
uint256 betAmount = msg.value;
|
| 142 |
+
|
| 143 |
+
|
| 144 |
+
betAmount = betAmountAfterRakeHasBeenWithdrawnAndProcessed(betAmount);
|
| 145 |
+
|
| 146 |
+
if((block.number.sub(lastBetBlockNumber) >= minimumNumberOfBlocksToEndGame) && (lastBetBlockNumber != 0)) {
|
| 147 |
+
processEndGame(betAmount);
|
| 148 |
+
} else if (lastBetBlockNumber == 0) {
|
| 149 |
+
initialBankrollGrowthAmount = FixedPoint.fromInt256(Int256(betAmount.add(initialSeed)));
|
| 150 |
+
}
|
| 151 |
+
|
| 152 |
+
emit Bet(msg.sender, betAmount, currentBetNumber, currentGameNumber);
|
| 153 |
+
|
| 154 |
+
Player.BettingRecord memory newBetRecord = Player.BettingRecord(msg.sender, currentGameNumber, betAmount, currentBetNumber, currentPot.sub(initialSeed), 0, 0, true);
|
| 155 |
+
|
| 156 |
+
Player.Data storage currentPlayer = playerCollection[msg.sender];
|
| 157 |
+
|
| 158 |
+
currentPlayer.insertBettingRecord(newBetRecord);
|
| 159 |
+
|
| 160 |
+
Player.BettingRecord memory oldGameUnprocessedBettingRecord = currentGameBettingRecords.getNextRecord();
|
| 161 |
+
|
| 162 |
+
currentGameBettingRecords.pushRecord(newBetRecord);
|
| 163 |
+
|
| 164 |
+
if(oldGameUnprocessedBettingRecord.isActive == true) {
|
| 165 |
+
processBettingRecord(oldGameUnprocessedBettingRecord);
|
| 166 |
+
}
|
| 167 |
+
|
| 168 |
+
currentPot = currentPot.add(betAmount);
|
| 169 |
+
currentBetNumber = currentBetNumber.add(1);
|
| 170 |
+
lastBetBlockNumber = block.number;
|
| 171 |
+
FixedPoint.Data memory currentGameSize = FixedPoint.fromInt256(Int256(currentPot));
|
| 172 |
+
FixedPoint.Data memory expectedGameSize = currentMiningDifficulty.mul(kExpectedFirstGameSize);
|
| 173 |
+
minimumNumberOfBlocksToEndGame = calcNumberOfBlocksUntilGameEnds(currentGameSize, expectedGameSize).toUInt256Raw();
|
| 174 |
+
minimumWager = calcMinimumBetSize(currentGameSize, expectedGameSize).toUInt256Raw();
|
| 175 |
+
}
|
| 176 |
+
|
| 177 |
+
function getMyBetRecordCount() public view returns(uint256) {
|
| 178 |
+
Player.Data storage currentPlayer = playerCollection[msg.sender];
|
| 179 |
+
return currentPlayer.unprocessedBettingRecordCount();
|
| 180 |
+
}
|
| 181 |
+
|
| 182 |
+
|
| 183 |
+
function playerPopMining(uint256 recordIndex, bool onlyCurrentGame) public view returns(uint256) {
|
| 184 |
+
Player.Data storage currentPlayer = playerCollection[msg.sender];
|
| 185 |
+
return computeAmountToMineForBettingRecord(currentPlayer.getBettingRecordAtIndex(recordIndex), onlyCurrentGame).mul(kTotalPercent - kDeveloperMiningPower).div(kTotalPercent);
|
| 186 |
+
}
|
| 187 |
+
|
| 188 |
+
function getBetRecord(uint256 recordIndex) public view returns(uint256, uint256, uint256) {
|
| 189 |
+
Player.Data storage currentPlayer = playerCollection[msg.sender];
|
| 190 |
+
Player.BettingRecord memory bettingRecord = currentPlayer.getBettingRecordAtIndex(recordIndex);
|
| 191 |
+
return (bettingRecord.gamePotBeforeBet, bettingRecord.wagerAmount, bettingRecord.gameId);
|
| 192 |
+
}
|
| 193 |
+
|
| 194 |
+
function withdraw (uint256 withdrawCount) public returns(bool res) {
|
| 195 |
+
Player.Data storage currentPlayer = playerCollection[msg.sender];
|
| 196 |
+
|
| 197 |
+
uint256 playerBettingRecordCount = currentPlayer.unprocessedBettingRecordCount();
|
| 198 |
+
uint256 numberOfIterations = withdrawCount < playerBettingRecordCount ? withdrawCount : playerBettingRecordCount;
|
| 199 |
+
if(numberOfIterations == 0) {return;}
|
| 200 |
+
|
| 201 |
+
numberOfIterations = numberOfIterations.add(1);
|
| 202 |
+
|
| 203 |
+
for (uint256 i = 0 ; i < numberOfIterations; i = i.add(1)) {
|
| 204 |
+
Player.BettingRecord memory unprocessedRecord = currentPlayer.getNextRecord();
|
| 205 |
+
processBettingRecord(unprocessedRecord);
|
| 206 |
+
}
|
| 207 |
+
|
| 208 |
+
uint256 playerBalance = playerInternalWallet[msg.sender];
|
| 209 |
+
|
| 210 |
+
|
| 211 |
+
playerInternalWallet[msg.sender] = 0;
|
| 212 |
+
|
| 213 |
+
if(playerBalance == 0) {
|
| 214 |
+
return true;
|
| 215 |
+
}
|
| 216 |
+
|
| 217 |
+
emit Withdraw(msg.sender, playerBalance, numberOfIterations);
|
| 218 |
+
|
| 219 |
+
if(!msg.sender.send(playerBalance)) {
|
| 220 |
+
|
| 221 |
+
playerInternalWallet[msg.sender] = playerBalance;
|
| 222 |
+
return false;
|
| 223 |
+
}
|
| 224 |
+
return true;
|
| 225 |
+
}
|
| 226 |
+
|
| 227 |
+
|
| 228 |
+
function getCurrentMiningDifficulty() public view returns(uint256){
|
| 229 |
+
return UInt256(currentMiningDifficulty.toInt256());
|
| 230 |
+
}
|
| 231 |
+
|
| 232 |
+
function getPlayerInternalWallet() public view returns(uint256) {
|
| 233 |
+
return playerInternalWallet[msg.sender];
|
| 234 |
+
}
|
| 235 |
+
|
| 236 |
+
function getWinningsForRecordId(uint256 recordIndex, bool onlyWithdrawable, bool onlyCurrentGame) public view returns(uint256) {
|
| 237 |
+
Player.Data storage currentPlayer = playerCollection[msg.sender];
|
| 238 |
+
Player.BettingRecord memory record = currentPlayer.getBettingRecordAtIndex(recordIndex);
|
| 239 |
+
if(onlyCurrentGame && record.gameId != currentGameNumber) {
|
| 240 |
+
return 0;
|
| 241 |
+
}
|
| 242 |
+
return getWinningsForRecord(record, onlyWithdrawable);
|
| 243 |
+
}
|
| 244 |
+
|
| 245 |
+
function getWinningsForRecord(Player.BettingRecord record, bool onlyWithdrawable) private view returns(uint256) {
|
| 246 |
+
|
| 247 |
+
if(onlyWithdrawable && recordIsTooNewToProcess(record)) {
|
| 248 |
+
return 0;
|
| 249 |
+
}
|
| 250 |
+
|
| 251 |
+
uint256 payout = getPayoutForPlayer(record).toUInt256Raw();
|
| 252 |
+
payout = payout.sub(amountToSeedNextRound(payout));
|
| 253 |
+
return payout.sub(record.withdrawnAmount);
|
| 254 |
+
|
| 255 |
+
}
|
| 256 |
+
|
| 257 |
+
function totalAmountRaked () public constant returns(uint256 res) {
|
| 258 |
+
return playerInternalWallet[this];
|
| 259 |
+
}
|
| 260 |
+
|
| 261 |
+
function betAmountAfterRakeHasBeenWithdrawnAndProcessed (uint256 betAmount) private returns(uint256 betLessRake){
|
| 262 |
+
uint256 amountToRake = amountToTakeAsRake(betAmount);
|
| 263 |
+
playerInternalWallet[this] = playerInternalWallet[this].add(amountToRake);
|
| 264 |
+
return betAmount.sub(amountToRake);
|
| 265 |
+
}
|
| 266 |
+
|
| 267 |
+
function amountToSeedNextRound (uint256 value) private pure returns(uint256 res) {
|
| 268 |
+
return value.mul(kPercentToTakeAsSeed).div(kTotalPercent);
|
| 269 |
+
}
|
| 270 |
+
|
| 271 |
+
function addToBonusSeed () public payable {
|
| 272 |
+
require (msg.value > 0);
|
| 273 |
+
bonusSeed = bonusSeed.add(msg.value);
|
| 274 |
+
}
|
| 275 |
+
|
| 276 |
+
|
| 277 |
+
function amountToTakeAsRake (uint256 value) private pure returns(uint256 res) {
|
| 278 |
+
return value.mul(kPercentToTakeAsRake).div(kTotalPercent);
|
| 279 |
+
}
|
| 280 |
+
|
| 281 |
+
function amountOfPopDeveloperShouldMine (uint256 value) private pure returns(uint256 res) {
|
| 282 |
+
return value.mul(kDeveloperMiningPower).div(kTotalPercent);
|
| 283 |
+
}
|
| 284 |
+
|
| 285 |
+
function processEndGame (uint256 lastBetAmount) private {
|
| 286 |
+
|
| 287 |
+
|
| 288 |
+
emit EndGame(currentGameNumber);
|
| 289 |
+
|
| 290 |
+
gameMetaData.push(WrappedArray.GameMetaDataElement(currentPot, initialSeed, initialBankrollGrowthAmount.toUInt256Raw(), unPromisedSupplyAtStartOfCurrentGame_, currentMiningDifficulty, true));
|
| 291 |
+
|
| 292 |
+
kUpperBoundBlocksTillGameEnd = nextGameMaxBlock;
|
| 293 |
+
kLowerBoundBlocksTillGameEnd = nextGameMinBlock;
|
| 294 |
+
|
| 295 |
+
unPromisedSupplyAtStartOfCurrentGame_ = unPromisedPop();
|
| 296 |
+
|
| 297 |
+
initialSeed = amountToSeedNextRound(currentPot).add(bonusSeed);
|
| 298 |
+
bonusSeed = 0;
|
| 299 |
+
currentPot = initialSeed;
|
| 300 |
+
currentMiningDifficulty = calcDifficulty();
|
| 301 |
+
|
| 302 |
+
|
| 303 |
+
initialBankrollGrowthAmount = FixedPoint.fromInt256(Int256(lastBetAmount.add(initialSeed)));
|
| 304 |
+
|
| 305 |
+
|
| 306 |
+
currentGameBettingRecords.resetIndex();
|
| 307 |
+
|
| 308 |
+
|
| 309 |
+
currentGameNumber = currentGameNumber.add(1);
|
| 310 |
+
}
|
| 311 |
+
|
| 312 |
+
function processBettingRecord (Player.BettingRecord record) private {
|
| 313 |
+
Player.Data storage currentPlayer = playerCollection[record.playerAddress];
|
| 314 |
+
if(currentPlayer.containsBettingRecordFromId(record.bettingRecordId) == false) {
|
| 315 |
+
return;
|
| 316 |
+
}
|
| 317 |
+
|
| 318 |
+
Player.BettingRecord memory bettingRecord = currentPlayer.getBettingRecordForId(record.bettingRecordId);
|
| 319 |
+
|
| 320 |
+
currentPlayer.deleteBettingRecordForId(bettingRecord.bettingRecordId);
|
| 321 |
+
|
| 322 |
+
|
| 323 |
+
uint256 bettingRecordValue = getWinningsForRecord(bettingRecord, true);
|
| 324 |
+
uint256 amountToMineForBettingRecord = computeAmountToMineForBettingRecord(bettingRecord, false);
|
| 325 |
+
|
| 326 |
+
|
| 327 |
+
if(bettingRecord.gameId == currentGameNumber) {
|
| 328 |
+
bettingRecord.withdrawnAmount = bettingRecord.withdrawnAmount.add(bettingRecordValue);
|
| 329 |
+
bettingRecord.withdrawnPopAmount = bettingRecord.withdrawnPopAmount.add(amountToMineForBettingRecord);
|
| 330 |
+
currentPlayer.insertBettingRecord(bettingRecord);
|
| 331 |
+
}
|
| 332 |
+
minePoP(bettingRecord.playerAddress, amountToMineForBettingRecord);
|
| 333 |
+
playerInternalWallet[bettingRecord.playerAddress] = playerInternalWallet[bettingRecord.playerAddress].add(bettingRecordValue);
|
| 334 |
+
}
|
| 335 |
+
|
| 336 |
+
function potAmountForRecord (Player.BettingRecord record) private view returns(uint256 potAmount) {
|
| 337 |
+
require(record.gameId <= currentGameNumber);
|
| 338 |
+
if(record.gameId < currentGameNumber) {
|
| 339 |
+
return gameMetaData.itemAtIndex(record.gameId).totalPotAmount;
|
| 340 |
+
} else {
|
| 341 |
+
return currentPot;
|
| 342 |
+
}
|
| 343 |
+
}
|
| 344 |
+
|
| 345 |
+
|
| 346 |
+
function recordIsTooNewToProcess (Player.BettingRecord record) private view returns(bool res) {
|
| 347 |
+
uint256 potAtBet = record.gamePotBeforeBet.add(record.wagerAmount);
|
| 348 |
+
|
| 349 |
+
if(record.gameId == currentGameNumber) {
|
| 350 |
+
uint256 halfPot = currentPot.sub(initialSeed).div(2);
|
| 351 |
+
if(potAtBet >= halfPot) {
|
| 352 |
+
return true;
|
| 353 |
+
}
|
| 354 |
+
}
|
| 355 |
+
return false;
|
| 356 |
+
}
|
| 357 |
+
|
| 358 |
+
function UInt256 (int256 elem) private pure returns(uint256 res) {
|
| 359 |
+
assert(elem >= 0);
|
| 360 |
+
return uint256(elem);
|
| 361 |
+
}
|
| 362 |
+
|
| 363 |
+
function Int256 (uint256 elem) private pure returns(int256 res) {
|
| 364 |
+
assert(int256(elem) >= 0);
|
| 365 |
+
return int256(elem);
|
| 366 |
+
}
|
| 367 |
+
|
| 368 |
+
function getBankRollGrowthForGameId (uint256 gameId) private view returns(FixedPoint.Data res) {
|
| 369 |
+
if(gameId == currentGameNumber) {
|
| 370 |
+
return FixedPoint.fromInt256(Int256(currentPot)).div(initialBankrollGrowthAmount);
|
| 371 |
+
} else {
|
| 372 |
+
WrappedArray.GameMetaDataElement memory elem = gameMetaData.itemAtIndex(gameId);
|
| 373 |
+
return FixedPoint.fromInt256(Int256(elem.totalPotAmount)).div(FixedPoint.fromInt256(Int256(elem.initialBet)));
|
| 374 |
+
}
|
| 375 |
+
}
|
| 376 |
+
|
| 377 |
+
function getSeedAmountForGameId (uint256 gameId) private view returns(FixedPoint.Data res) {
|
| 378 |
+
if(gameId == currentGameNumber) {
|
| 379 |
+
return FixedPoint.fromInt256(Int256(initialSeed));
|
| 380 |
+
} else {
|
| 381 |
+
WrappedArray.GameMetaDataElement memory elem = gameMetaData.itemAtIndex(gameId);
|
| 382 |
+
return FixedPoint.fromInt256(Int256(elem.seedAmount));
|
| 383 |
+
}
|
| 384 |
+
}
|
| 385 |
+
|
| 386 |
+
function getPayoutForPlayer(Player.BettingRecord playerRecord) internal view returns (FixedPoint.Data) {
|
| 387 |
+
|
| 388 |
+
FixedPoint.Data memory frontWindowAdjustment = getWindowAdjustmentForGameIdAndRatio(playerRecord.gameId, frontWindowAdjustmentRatio);
|
| 389 |
+
FixedPoint.Data memory backWindowAdjustment = getWindowAdjustmentForGameIdAndRatio(playerRecord.gameId, backWindowAdjustmentRatio);
|
| 390 |
+
FixedPoint.Data memory backPayoutEndPoint = kBackPayoutEndPointInitial.div(backWindowAdjustment);
|
| 391 |
+
FixedPoint.Data memory frontPayoutSizePercent = kFrontPayoutStartPointInitial.div(frontWindowAdjustment);
|
| 392 |
+
FixedPoint.Data memory frontPayoutStartPoint = FixedPoint.fromInt256(1).sub(frontPayoutSizePercent);
|
| 393 |
+
|
| 394 |
+
FixedPoint.Data memory potAmountData = FixedPoint.fromInt256(Int256(potAmountForRecord(playerRecord)));
|
| 395 |
+
|
| 396 |
+
FixedPoint.Data memory frontPercent = FixedPoint.fromInt256(0);
|
| 397 |
+
if(playerRecord.gamePotBeforeBet != 0) {
|
| 398 |
+
frontPercent = FixedPoint.fromInt256(Int256(playerRecord.gamePotBeforeBet)).div(potAmountData.sub(getSeedAmountForGameId(playerRecord.gameId)));
|
| 399 |
+
}
|
| 400 |
+
|
| 401 |
+
FixedPoint.Data memory backPercent = FixedPoint.fromInt256(Int256(playerRecord.gamePotBeforeBet)).add(FixedPoint.fromInt256(Int256(playerRecord.wagerAmount))).div(potAmountData.sub(getSeedAmountForGameId(playerRecord.gameId)));
|
| 402 |
+
|
| 403 |
+
if(frontPercent.val < backPayoutEndPoint.val) {
|
| 404 |
+
if(backPercent.val <= backPayoutEndPoint.val) {
|
| 405 |
+
|
| 406 |
+
return calcWinnings(frontPercent, backPercent, backPayoutEndPoint, _pi.div(backWindowAdjustment), backWindowAdjustment, FixedPoint.fromInt256(0), potAmountData);
|
| 407 |
+
} else if (backPercent.val <= frontPayoutStartPoint.val) {
|
| 408 |
+
|
| 409 |
+
return calcWinnings(frontPercent, backPayoutEndPoint, backPayoutEndPoint, _pi.div(backWindowAdjustment), backWindowAdjustment, FixedPoint.fromInt256(0), potAmountData);
|
| 410 |
+
} else {
|
| 411 |
+
|
| 412 |
+
return calcWinnings(frontPercent, backPayoutEndPoint, backPayoutEndPoint, _pi.div(backWindowAdjustment), backWindowAdjustment, FixedPoint.fromInt256(0), potAmountData).add(calcWinnings(FixedPoint.fromInt256(0), backPercent.sub(frontPayoutStartPoint), frontPayoutSizePercent, _pi.div(frontWindowAdjustment), frontWindowAdjustment, _pi.div(frontWindowAdjustment), potAmountData));
|
| 413 |
+
}
|
| 414 |
+
} else if (frontPercent.val < frontPayoutStartPoint.val) {
|
| 415 |
+
if (backPercent.val <= frontPayoutStartPoint.val) {
|
| 416 |
+
|
| 417 |
+
return FixedPoint.fromInt256(0);
|
| 418 |
+
} else {
|
| 419 |
+
|
| 420 |
+
return calcWinnings(FixedPoint.fromInt256(0), backPercent.sub(frontPayoutStartPoint), frontPayoutSizePercent, _pi.div(frontWindowAdjustment), frontWindowAdjustment, _pi.div(frontWindowAdjustment), potAmountData);
|
| 421 |
+
}
|
| 422 |
+
} else {
|
| 423 |
+
|
| 424 |
+
return calcWinnings(frontPercent.sub(frontPayoutStartPoint), backPercent.sub(frontPayoutStartPoint), frontPayoutSizePercent, _pi.div(frontWindowAdjustment), frontWindowAdjustment, _pi.div(frontWindowAdjustment), potAmountData);
|
| 425 |
+
}
|
| 426 |
+
}
|
| 427 |
+
|
| 428 |
+
function getWindowAdjustmentForGameIdAndRatio(uint256 gameId, FixedPoint.Data adjustmentRatio) internal view returns (FixedPoint.Data) {
|
| 429 |
+
FixedPoint.Data memory growth = getBankRollGrowthForGameId(gameId);
|
| 430 |
+
FixedPoint.Data memory logGrowthRate = growth.ln();
|
| 431 |
+
return growth.div(adjustmentRatio.pow(logGrowthRate));
|
| 432 |
+
}
|
| 433 |
+
|
| 434 |
+
function integrate(FixedPoint.Data x, FixedPoint.Data a) internal pure returns (FixedPoint.Data) {
|
| 435 |
+
return a.mul(x).sin().div(a).add(x);
|
| 436 |
+
}
|
| 437 |
+
|
| 438 |
+
function calcWinnings(FixedPoint.Data playerFrontPercent, FixedPoint.Data playerBackPercent, FixedPoint.Data sectionPercentSize, FixedPoint.Data sectionRadiansSize, FixedPoint.Data windowAdjustment, FixedPoint.Data sectionOffset, FixedPoint.Data potSize) internal view returns (FixedPoint.Data) {
|
| 439 |
+
FixedPoint.Data memory startIntegrationPoint = sectionOffset.add(playerFrontPercent.div(sectionPercentSize).mul(sectionRadiansSize));
|
| 440 |
+
FixedPoint.Data memory endIntegrationPoint = sectionOffset.add(playerBackPercent.div(sectionPercentSize).mul(sectionRadiansSize));
|
| 441 |
+
return integrate(endIntegrationPoint, windowAdjustment).sub(integrate(startIntegrationPoint, windowAdjustment)).mul(potSize).mul(windowAdjustment).div(_2pi);
|
| 442 |
+
}
|
| 443 |
+
|
| 444 |
+
function computeAmountToMineForBettingRecord (Player.BettingRecord record, bool onlyCurrentGame) internal view returns(uint256 value) {
|
| 445 |
+
if(onlyCurrentGame && record.gameId != currentGameNumber){
|
| 446 |
+
return 0;
|
| 447 |
+
}
|
| 448 |
+
|
| 449 |
+
uint256 payout = getPopPayoutForRecord(record).toUInt256Raw();
|
| 450 |
+
return payout.sub(record.withdrawnPopAmount);
|
| 451 |
+
}
|
| 452 |
+
|
| 453 |
+
function getPopPayoutForRecord(Player.BettingRecord record) private view returns(FixedPoint.Data value) {
|
| 454 |
+
|
| 455 |
+
if(record.isActive == false) {
|
| 456 |
+
return FixedPoint.fromInt256(0);
|
| 457 |
+
}
|
| 458 |
+
|
| 459 |
+
return totalTokenPayout(getPotAsFixedPointForGameId(record.gameId).sub(getInitialSeedAsFixedPointForGameId(record.gameId)), getDifficultyAsFixedPointForGameId(record.gameId), getPopRemainingAsFixedPointForGameId(record.gameId), record.wagerAmount, record.gamePotBeforeBet);
|
| 460 |
+
}
|
| 461 |
+
|
| 462 |
+
function unMinedPop () private view returns(uint256 res) {
|
| 463 |
+
return totalSupply_.sub(supplyMined_);
|
| 464 |
+
}
|
| 465 |
+
|
| 466 |
+
function promisedPop () private view returns(uint256) {
|
| 467 |
+
FixedPoint.Data memory curPot = getPotAsFixedPointForGameId(currentGameNumber);
|
| 468 |
+
FixedPoint.Data memory seed = getInitialSeedAsFixedPointForGameId(currentGameNumber);
|
| 469 |
+
FixedPoint.Data memory difficulty = getDifficultyAsFixedPointForGameId(currentGameNumber);
|
| 470 |
+
FixedPoint.Data memory unpromised = getPopRemainingAsFixedPointForGameId(currentGameNumber);
|
| 471 |
+
|
| 472 |
+
uint256 promisedPopThisGame = totalTokenPayout(curPot.sub(seed), difficulty, unpromised, currentPot.sub(seed.toUInt256Raw()), 0).toUInt256Raw();
|
| 473 |
+
return totalSupply_.sub(unPromisedSupplyAtStartOfCurrentGame_).add(promisedPopThisGame);
|
| 474 |
+
}
|
| 475 |
+
|
| 476 |
+
function unPromisedPop () private view returns(uint256 res) {
|
| 477 |
+
return totalSupply_.sub(promisedPop());
|
| 478 |
+
}
|
| 479 |
+
|
| 480 |
+
function potentiallyCirculatingPop () public view returns(uint256 res) {
|
| 481 |
+
return promisedPop().sub(supplyBurned_);
|
| 482 |
+
}
|
| 483 |
+
|
| 484 |
+
function minePoP(address target, uint256 amountToMine) private {
|
| 485 |
+
if(supplyMined_ >= totalSupply_) {
|
| 486 |
+
return;
|
| 487 |
+
}
|
| 488 |
+
|
| 489 |
+
uint256 remainingPop = unMinedPop();
|
| 490 |
+
if(amountToMine == 0 || remainingPop == 0) {
|
| 491 |
+
return;
|
| 492 |
+
}
|
| 493 |
+
|
| 494 |
+
if(remainingPop < amountToMine) {
|
| 495 |
+
amountToMine = remainingPop;
|
| 496 |
+
}
|
| 497 |
+
|
| 498 |
+
uint256 developerMined = amountOfPopDeveloperShouldMine(amountToMine);
|
| 499 |
+
uint256 playerMined = amountToMine.sub(developerMined);
|
| 500 |
+
|
| 501 |
+
supplyMined_ = supplyMined_.add(amountToMine);
|
| 502 |
+
|
| 503 |
+
popBalances[target] = popBalances[target].add(playerMined);
|
| 504 |
+
popBalances[author] = popBalances[author].add(developerMined);
|
| 505 |
+
|
| 506 |
+
emit Mined(target, playerMined);
|
| 507 |
+
emit Transfer(0, target, playerMined);
|
| 508 |
+
emit Mined(author, developerMined);
|
| 509 |
+
emit Transfer(0, author, developerMined);
|
| 510 |
+
}
|
| 511 |
+
|
| 512 |
+
function redeemPop (uint256 popToRedeem) public returns(bool res) {
|
| 513 |
+
require(popBalances[msg.sender] >= popToRedeem);
|
| 514 |
+
require(popToRedeem != 0);
|
| 515 |
+
|
| 516 |
+
uint256 potentiallyAllocatedPop = potentiallyCirculatingPop();
|
| 517 |
+
require(popToRedeem <= potentiallyAllocatedPop);
|
| 518 |
+
|
| 519 |
+
FixedPoint.Data memory redeemRatio = FixedPoint.fromFraction(Int256(popToRedeem), Int256(potentiallyAllocatedPop));
|
| 520 |
+
FixedPoint.Data memory ethPayoutAmount = redeemRatio.mul(FixedPoint.fromInt256(Int256(totalAmountRaked())));
|
| 521 |
+
uint256 payout = ethPayoutAmount.toUInt256Raw();
|
| 522 |
+
require(payout<=totalAmountRaked());
|
| 523 |
+
require(payout <= address(this).balance);
|
| 524 |
+
|
| 525 |
+
burn(popToRedeem);
|
| 526 |
+
playerInternalWallet[this] = playerInternalWallet[this].sub(payout);
|
| 527 |
+
playerInternalWallet[msg.sender] = playerInternalWallet[msg.sender].add(payout);
|
| 528 |
+
|
| 529 |
+
return true;
|
| 530 |
+
}
|
| 531 |
+
|
| 532 |
+
|
| 533 |
+
function totalSupply() public view returns (uint256) {
|
| 534 |
+
return promisedPop();
|
| 535 |
+
}
|
| 536 |
+
|
| 537 |
+
function balanceOf(address _owner) public view returns (uint256 balance) {
|
| 538 |
+
return popBalances[_owner];
|
| 539 |
+
}
|
| 540 |
+
|
| 541 |
+
function transfer(address _to, uint256 _value) public returns (bool) {
|
| 542 |
+
require(_to != address(0));
|
| 543 |
+
require(_value <= popBalances[msg.sender]);
|
| 544 |
+
|
| 545 |
+
|
| 546 |
+
popBalances[msg.sender] = popBalances[msg.sender].sub(_value);
|
| 547 |
+
popBalances[_to] = popBalances[_to].add(_value);
|
| 548 |
+
emit Transfer(msg.sender, _to, _value);
|
| 549 |
+
return true;
|
| 550 |
+
}
|
| 551 |
+
|
| 552 |
+
function transferFrom(address _from, address _to, uint256 _value) public returns (bool) {
|
| 553 |
+
require(_to != address(0));
|
| 554 |
+
require(_value <= popBalances[_from]);
|
| 555 |
+
require(_value <= allowed[_from][msg.sender]);
|
| 556 |
+
|
| 557 |
+
popBalances[_from] = popBalances[_from].sub(_value);
|
| 558 |
+
popBalances[_to] = popBalances[_to].add(_value);
|
| 559 |
+
allowed[_from][msg.sender] = allowed[_from][msg.sender].sub(_value);
|
| 560 |
+
emit Transfer(_from, _to, _value);
|
| 561 |
+
return true;
|
| 562 |
+
}
|
| 563 |
+
|
| 564 |
+
function approve(address _spender, uint256 _value) public returns (bool) {
|
| 565 |
+
allowed[msg.sender][_spender] = _value;
|
| 566 |
+
emit Approval(msg.sender, _spender, _value);
|
| 567 |
+
return true;
|
| 568 |
+
}
|
| 569 |
+
|
| 570 |
+
function allowance(address _owner, address _spender) public view returns (uint256) {
|
| 571 |
+
return allowed[_owner][_spender];
|
| 572 |
+
}
|
| 573 |
+
|
| 574 |
+
function increaseApproval(address _spender, uint _addedValue) public returns (bool) {
|
| 575 |
+
allowed[msg.sender][_spender] = allowed[msg.sender][_spender].add(_addedValue);
|
| 576 |
+
emit Approval(msg.sender, _spender, allowed[msg.sender][_spender]);
|
| 577 |
+
return true;
|
| 578 |
+
}
|
| 579 |
+
|
| 580 |
+
function decreaseApproval(address _spender, uint _subtractedValue) public returns (bool) {
|
| 581 |
+
uint oldValue = allowed[msg.sender][_spender];
|
| 582 |
+
if (_subtractedValue > oldValue) {
|
| 583 |
+
allowed[msg.sender][_spender] = 0;
|
| 584 |
+
} else {
|
| 585 |
+
allowed[msg.sender][_spender] = oldValue.sub(_subtractedValue);
|
| 586 |
+
}
|
| 587 |
+
emit Approval(msg.sender, _spender, allowed[msg.sender][_spender]);
|
| 588 |
+
return true;
|
| 589 |
+
}
|
| 590 |
+
|
| 591 |
+
function burn(uint256 _value) public {
|
| 592 |
+
require (popBalances[msg.sender] >= _value);
|
| 593 |
+
|
| 594 |
+
address burner = msg.sender;
|
| 595 |
+
supplyBurned_ = supplyBurned_.add(_value);
|
| 596 |
+
popBalances[burner] = popBalances[burner].sub(_value);
|
| 597 |
+
emit Burn(burner, _value);
|
| 598 |
+
}
|
| 599 |
+
|
| 600 |
+
function getInitialSeedAsFixedPointForGameId (uint256 gameId) private view returns(FixedPoint.Data res) {
|
| 601 |
+
if(gameId == currentGameNumber) {
|
| 602 |
+
return FixedPoint.fromInt256(Int256(initialSeed));
|
| 603 |
+
} else {
|
| 604 |
+
WrappedArray.GameMetaDataElement memory elem = gameMetaData.itemAtIndex(gameId);
|
| 605 |
+
return FixedPoint.fromInt256(Int256(elem.seedAmount));
|
| 606 |
+
}
|
| 607 |
+
}
|
| 608 |
+
|
| 609 |
+
function getPotAsFixedPointForGameId (uint256 gameId) private view returns(FixedPoint.Data res) {
|
| 610 |
+
if(gameId == currentGameNumber) {
|
| 611 |
+
return FixedPoint.fromInt256(Int256(currentPot));
|
| 612 |
+
} else {
|
| 613 |
+
WrappedArray.GameMetaDataElement memory elem = gameMetaData.itemAtIndex(gameId);
|
| 614 |
+
return FixedPoint.fromInt256(Int256(elem.totalPotAmount));
|
| 615 |
+
}
|
| 616 |
+
}
|
| 617 |
+
|
| 618 |
+
function getPopRemainingAsFixedPointForGameId (uint256 gameId) private view returns(FixedPoint.Data res) {
|
| 619 |
+
if(gameId == currentGameNumber) {
|
| 620 |
+
return FixedPoint.fromInt256(Int256(unPromisedSupplyAtStartOfCurrentGame_));
|
| 621 |
+
} else {
|
| 622 |
+
WrappedArray.GameMetaDataElement memory elem = gameMetaData.itemAtIndex(gameId);
|
| 623 |
+
return FixedPoint.fromInt256(Int256(elem.coinsRemaining));
|
| 624 |
+
}
|
| 625 |
+
}
|
| 626 |
+
|
| 627 |
+
function getDifficultyAsFixedPointForGameId (uint256 gameId) private view returns(FixedPoint.Data res) {
|
| 628 |
+
if(gameId == currentGameNumber) {
|
| 629 |
+
return currentMiningDifficulty;
|
| 630 |
+
} else {
|
| 631 |
+
WrappedArray.GameMetaDataElement memory elem = gameMetaData.itemAtIndex(gameId);
|
| 632 |
+
return elem.miningDifficulty;
|
| 633 |
+
}
|
| 634 |
+
}
|
| 635 |
+
|
| 636 |
+
function calcDifficulty() private view returns (FixedPoint.Data) {
|
| 637 |
+
FixedPoint.Data memory total = FixedPoint.fromInt256(0);
|
| 638 |
+
FixedPoint.Data memory count = FixedPoint.fromInt256(0);
|
| 639 |
+
uint256 j = 0;
|
| 640 |
+
for(uint256 i=gameMetaData.length().sub(1) ; i>=0 && j<kDifficultyWindow; i = i.sub(1)){
|
| 641 |
+
WrappedArray.GameMetaDataElement memory thisGame = gameMetaData.itemAtIndex(i);
|
| 642 |
+
FixedPoint.Data memory thisGamePotSize = FixedPoint.fromInt256(Int256(thisGame.totalPotAmount));
|
| 643 |
+
FixedPoint.Data memory thisCount = kDifficultyDropOffFactor.pow(FixedPoint.fromInt256(Int256(j)));
|
| 644 |
+
total = total.add(thisCount.mul(thisGamePotSize));
|
| 645 |
+
count = count.add(thisCount);
|
| 646 |
+
j = j.add(1);
|
| 647 |
+
if(i == 0) {
|
| 648 |
+
break;
|
| 649 |
+
}
|
| 650 |
+
}
|
| 651 |
+
|
| 652 |
+
return total.div(count).div(kExpectedFirstGameSize);
|
| 653 |
+
}
|
| 654 |
+
|
| 655 |
+
function getBrAdj(FixedPoint.Data currentPotValue, FixedPoint.Data expectedGameSize) private pure returns (FixedPoint.Data) {
|
| 656 |
+
if(currentPotValue.cmp(expectedGameSize) == -1) {
|
| 657 |
+
return expectedGameSize.div(currentPotValue).log10().neg();
|
| 658 |
+
} else {
|
| 659 |
+
return currentPotValue.div(expectedGameSize).log10();
|
| 660 |
+
}
|
| 661 |
+
}
|
| 662 |
+
|
| 663 |
+
function getMiningRateAtPoint(FixedPoint.Data point, FixedPoint.Data difficulty, FixedPoint.Data currentPotValue, FixedPoint.Data coins_tbi) private view returns (FixedPoint.Data) {
|
| 664 |
+
assert (point.cmp(currentPotValue) != 1);
|
| 665 |
+
FixedPoint.Data memory expectedGameSize = kExpectedFirstGameSize.mul(difficulty);
|
| 666 |
+
FixedPoint.Data memory depositRatio = point.div(currentPotValue);
|
| 667 |
+
FixedPoint.Data memory brAdj = getBrAdj(currentPotValue, expectedGameSize);
|
| 668 |
+
if(brAdj.cmp(FixedPoint.fromInt256(0)) == -1) {
|
| 669 |
+
return coins_tbi.mul(FixedPoint.fromInt256(1).div(FixedPoint.fromInt256(2).pow(brAdj.neg()))).mul(FixedPoint.fromInt256(2).sub(depositRatio));
|
| 670 |
+
} else {
|
| 671 |
+
return coins_tbi.mul(FixedPoint.fromInt256(2).pow(brAdj)).mul(FixedPoint.fromInt256(2).sub(depositRatio));
|
| 672 |
+
}
|
| 673 |
+
}
|
| 674 |
+
|
| 675 |
+
function getExpectedGameSize() external view returns (int256) {
|
| 676 |
+
return kExpectedFirstGameSize.toInt256();
|
| 677 |
+
}
|
| 678 |
+
|
| 679 |
+
function totalTokenPayout(FixedPoint.Data currentPotValue, FixedPoint.Data difficulty, FixedPoint.Data unpromisedPopAtStartOfGame, uint256 wagerAmount, uint256 previousPotSize) private view returns (FixedPoint.Data) {
|
| 680 |
+
FixedPoint.Data memory maxPotSize = kExpectedFirstGameSize.mul(difficulty).mul(kMaxPopMiningPotMultiple);
|
| 681 |
+
FixedPoint.Data memory startPoint = FixedPoint.fromInt256(Int256(previousPotSize));
|
| 682 |
+
if(startPoint.cmp(maxPotSize) != -1){
|
| 683 |
+
return FixedPoint.fromInt256(0);
|
| 684 |
+
}
|
| 685 |
+
FixedPoint.Data memory endPoint = FixedPoint.fromInt256(Int256(previousPotSize + wagerAmount));
|
| 686 |
+
if(endPoint.cmp(maxPotSize) != -1){
|
| 687 |
+
endPoint = maxPotSize;
|
| 688 |
+
wagerAmount = maxPotSize.sub(startPoint).toUInt256Raw();
|
| 689 |
+
}
|
| 690 |
+
if(currentPotValue.cmp(maxPotSize) != -1){
|
| 691 |
+
currentPotValue = maxPotSize;
|
| 692 |
+
}
|
| 693 |
+
|
| 694 |
+
FixedPoint.Data memory betSizePercent = FixedPoint.fromInt256(Int256(wagerAmount)).div(kExpectedFirstGameSize.mul(difficulty));
|
| 695 |
+
FixedPoint.Data memory expectedCoinsToBeIssuedTwoThirds = FixedPoint.fromFraction(2, 3).mul(unpromisedPopAtStartOfGame.mul(kExpectedPopCoinToBePromisedPercent));
|
| 696 |
+
return getMiningRateAtPoint(startPoint.add(endPoint).div(FixedPoint.fromInt256(2)), difficulty, currentPotValue, expectedCoinsToBeIssuedTwoThirds).mul(betSizePercent);
|
| 697 |
+
}
|
| 698 |
+
|
| 699 |
+
function calcNumberOfBlocksUntilGameEnds(FixedPoint.Data currentGameSize, FixedPoint.Data targetGameSize) internal view returns (FixedPoint.Data) {
|
| 700 |
+
return kLowerBoundBlocksTillGameEnd.add(kUpperBoundBlocksTillGameEnd.mul(FixedPoint.fromInt256(1).div(currentGameSize.div(targetGameSize).exp())));
|
| 701 |
+
}
|
| 702 |
+
|
| 703 |
+
function calcMinimumBetSize(FixedPoint.Data currentGameSize, FixedPoint.Data targetGameSize) internal view returns (FixedPoint.Data) {
|
| 704 |
+
return currentGameInitialMinBetSize.mul(FixedPoint.fromInt256(2).pow(FixedPoint.fromInt256(1).add(currentGameSize.div(targetGameSize)).log10()));
|
| 705 |
+
}
|
| 706 |
+
}
|
| 707 |
+
|
| 708 |
+
library SafeMath {
|
| 709 |
+
|
| 710 |
+
|
| 711 |
+
function mul(uint256 a, uint256 b) internal pure returns (uint256) {
|
| 712 |
+
if (a == 0) {
|
| 713 |
+
return 0;
|
| 714 |
+
}
|
| 715 |
+
uint256 c = a * b;
|
| 716 |
+
assert(c / a == b);
|
| 717 |
+
return c;
|
| 718 |
+
}
|
| 719 |
+
|
| 720 |
+
|
| 721 |
+
function div(uint256 a, uint256 b) internal pure returns (uint256) {
|
| 722 |
+
|
| 723 |
+
uint256 c = a / b;
|
| 724 |
+
return c;
|
| 725 |
+
}
|
| 726 |
+
|
| 727 |
+
|
| 728 |
+
function sub(uint256 a, uint256 b) internal pure returns (uint256) {
|
| 729 |
+
assert(b <= a);
|
| 730 |
+
return a - b;
|
| 731 |
+
}
|
| 732 |
+
|
| 733 |
+
|
| 734 |
+
function add(uint256 a, uint256 b) internal pure returns (uint256) {
|
| 735 |
+
uint256 c = a + b;
|
| 736 |
+
assert(c >= a);
|
| 737 |
+
return c;
|
| 738 |
+
}
|
| 739 |
+
}
|
| 740 |
+
|
| 741 |
+
library SafeInt {
|
| 742 |
+
|
| 743 |
+
|
| 744 |
+
function mul(int256 a, int256 b) internal pure returns (int256) {
|
| 745 |
+
if (a == 0) {
|
| 746 |
+
return 0;
|
| 747 |
+
}
|
| 748 |
+
int256 c = a * b;
|
| 749 |
+
assert(c / a == b);
|
| 750 |
+
return c;
|
| 751 |
+
}
|
| 752 |
+
|
| 753 |
+
|
| 754 |
+
function div(int256 a, int256 b) internal pure returns (int256) {
|
| 755 |
+
|
| 756 |
+
int256 c = a / b;
|
| 757 |
+
return c;
|
| 758 |
+
}
|
| 759 |
+
|
| 760 |
+
|
| 761 |
+
function sub(int256 a, int256 b) internal pure returns (int256) {
|
| 762 |
+
int256 c = a - b;
|
| 763 |
+
if(a>0 && b<0) {
|
| 764 |
+
assert (c > a);
|
| 765 |
+
} else if(a<0 && b>0) {
|
| 766 |
+
assert (c < a);
|
| 767 |
+
}
|
| 768 |
+
return c;
|
| 769 |
+
}
|
| 770 |
+
|
| 771 |
+
|
| 772 |
+
function add(int256 a, int256 b) internal pure returns (int256) {
|
| 773 |
+
int256 c = a + b;
|
| 774 |
+
if(a>0 && b>0) {
|
| 775 |
+
assert(c > a);
|
| 776 |
+
} else if (a < 0 && b < 0) {
|
| 777 |
+
assert(c < a);
|
| 778 |
+
}
|
| 779 |
+
return c;
|
| 780 |
+
}
|
| 781 |
+
}
|
| 782 |
+
|
| 783 |
+
|
| 784 |
+
library WrappedArray {
|
| 785 |
+
using SafeMath for uint256;
|
| 786 |
+
using FixedPoint for FixedPoint.Data;
|
| 787 |
+
|
| 788 |
+
struct GameMetaDataElement {
|
| 789 |
+
uint256 totalPotAmount;
|
| 790 |
+
uint256 seedAmount;
|
| 791 |
+
uint256 initialBet;
|
| 792 |
+
uint256 coinsRemaining;
|
| 793 |
+
FixedPoint.Data miningDifficulty;
|
| 794 |
+
bool isActive;
|
| 795 |
+
}
|
| 796 |
+
|
| 797 |
+
struct Data {
|
| 798 |
+
GameMetaDataElement[] array;
|
| 799 |
+
}
|
| 800 |
+
|
| 801 |
+
|
| 802 |
+
function push (Data storage self, GameMetaDataElement element) internal {
|
| 803 |
+
self.array.length = self.array.length.add(1);
|
| 804 |
+
self.array[self.array.length.sub(1)] = element;
|
| 805 |
+
}
|
| 806 |
+
|
| 807 |
+
|
| 808 |
+
function itemAtIndex (Data storage self, uint256 index) internal view returns(GameMetaDataElement elem) {
|
| 809 |
+
|
| 810 |
+
assert(index < self.array.length);
|
| 811 |
+
return self.array[index];
|
| 812 |
+
}
|
| 813 |
+
|
| 814 |
+
|
| 815 |
+
function length (Data storage self) internal view returns(uint256 len) {
|
| 816 |
+
return self.array.length;
|
| 817 |
+
}
|
| 818 |
+
}
|
| 819 |
+
|
| 820 |
+
|
| 821 |
+
library CompactArray {
|
| 822 |
+
using SafeMath for uint256;
|
| 823 |
+
|
| 824 |
+
struct Element {
|
| 825 |
+
uint256 elem;
|
| 826 |
+
}
|
| 827 |
+
|
| 828 |
+
struct Data {
|
| 829 |
+
Element[] array;
|
| 830 |
+
uint256 len;
|
| 831 |
+
uint256 popNextIndex;
|
| 832 |
+
}
|
| 833 |
+
|
| 834 |
+
|
| 835 |
+
function push (Data storage self, Element element) internal returns(uint256 index) {
|
| 836 |
+
if(self.array.length == self.len) {
|
| 837 |
+
self.array.length = self.array.length.add(1);
|
| 838 |
+
}
|
| 839 |
+
self.array[self.len] = element;
|
| 840 |
+
self.len = self.len.add(1);
|
| 841 |
+
return self.len.sub(1);
|
| 842 |
+
}
|
| 843 |
+
|
| 844 |
+
|
| 845 |
+
function removeItemAtIndex (Data storage self, uint256 index) internal {
|
| 846 |
+
|
| 847 |
+
assert(index < self.len);
|
| 848 |
+
|
| 849 |
+
|
| 850 |
+
if(index == self.len.sub(1)) {
|
| 851 |
+
self.len = self.len.sub(1);
|
| 852 |
+
return;
|
| 853 |
+
}
|
| 854 |
+
|
| 855 |
+
|
| 856 |
+
Element storage temp = self.array[self.len.sub(1)];
|
| 857 |
+
self.array[index] = temp;
|
| 858 |
+
self.len = self.len.sub(1);
|
| 859 |
+
}
|
| 860 |
+
|
| 861 |
+
|
| 862 |
+
function pop (Data storage self) internal returns(Element elem) {
|
| 863 |
+
assert(self.len > 0);
|
| 864 |
+
|
| 865 |
+
|
| 866 |
+
self.len = self.len.sub(1);
|
| 867 |
+
|
| 868 |
+
|
| 869 |
+
return self.array[self.len];
|
| 870 |
+
}
|
| 871 |
+
|
| 872 |
+
|
| 873 |
+
function getNext (Data storage self) internal returns(Element elem) {
|
| 874 |
+
assert(self.len > 0);
|
| 875 |
+
|
| 876 |
+
if(self.popNextIndex >= self.len) {
|
| 877 |
+
|
| 878 |
+
self.popNextIndex = self.len.sub(1);
|
| 879 |
+
}
|
| 880 |
+
Element memory nextElement = itemAtIndex(self, self.popNextIndex);
|
| 881 |
+
|
| 882 |
+
if(self.popNextIndex == 0) {
|
| 883 |
+
self.popNextIndex = self.len.sub(1);
|
| 884 |
+
} else {
|
| 885 |
+
self.popNextIndex = self.popNextIndex.sub(1);
|
| 886 |
+
}
|
| 887 |
+
return nextElement;
|
| 888 |
+
}
|
| 889 |
+
|
| 890 |
+
|
| 891 |
+
function itemAtIndex (Data storage self, uint256 index) internal view returns(Element elem) {
|
| 892 |
+
|
| 893 |
+
assert(index < self.len);
|
| 894 |
+
|
| 895 |
+
return self.array[index];
|
| 896 |
+
}
|
| 897 |
+
|
| 898 |
+
|
| 899 |
+
function length (Data storage self) internal view returns(uint256 len) {
|
| 900 |
+
return self.len;
|
| 901 |
+
}
|
| 902 |
+
|
| 903 |
+
}
|
| 904 |
+
|
| 905 |
+
|
| 906 |
+
library UIntSet {
|
| 907 |
+
using CompactArray for CompactArray.Data;
|
| 908 |
+
|
| 909 |
+
struct SetEntry {
|
| 910 |
+
uint256 index;
|
| 911 |
+
bool active;
|
| 912 |
+
}
|
| 913 |
+
|
| 914 |
+
struct Data {
|
| 915 |
+
CompactArray.Data compactArray;
|
| 916 |
+
mapping (uint256 => SetEntry) storedValues;
|
| 917 |
+
}
|
| 918 |
+
|
| 919 |
+
|
| 920 |
+
function contains (Data storage self, uint256 element) internal view returns(bool res) {
|
| 921 |
+
return self.storedValues[element].active;
|
| 922 |
+
}
|
| 923 |
+
|
| 924 |
+
|
| 925 |
+
function insert (Data storage self, uint256 element) internal {
|
| 926 |
+
|
| 927 |
+
if(contains(self, element)) {
|
| 928 |
+
return;
|
| 929 |
+
}
|
| 930 |
+
|
| 931 |
+
CompactArray.Element memory newElem = CompactArray.Element(element);
|
| 932 |
+
|
| 933 |
+
|
| 934 |
+
uint256 index = self.compactArray.push(newElem);
|
| 935 |
+
|
| 936 |
+
|
| 937 |
+
SetEntry memory entry = SetEntry(index, true);
|
| 938 |
+
|
| 939 |
+
self.storedValues[element] = entry;
|
| 940 |
+
}
|
| 941 |
+
|
| 942 |
+
|
| 943 |
+
|
| 944 |
+
function removeElement (Data storage self, uint256 element) internal {
|
| 945 |
+
|
| 946 |
+
if(contains(self, element) == false) {
|
| 947 |
+
return;
|
| 948 |
+
}
|
| 949 |
+
|
| 950 |
+
|
| 951 |
+
uint256 index = self.storedValues[element].index;
|
| 952 |
+
|
| 953 |
+
|
| 954 |
+
self.compactArray.removeItemAtIndex(index);
|
| 955 |
+
|
| 956 |
+
|
| 957 |
+
self.storedValues[element].active = false;
|
| 958 |
+
|
| 959 |
+
|
| 960 |
+
if(index < self.compactArray.length()) {
|
| 961 |
+
|
| 962 |
+
CompactArray.Element memory swappedElem = self.compactArray.itemAtIndex(index);
|
| 963 |
+
|
| 964 |
+
|
| 965 |
+
self.storedValues[swappedElem.elem] = SetEntry(index, true);
|
| 966 |
+
|
| 967 |
+
}
|
| 968 |
+
}
|
| 969 |
+
|
| 970 |
+
|
| 971 |
+
function getNext (Data storage self) internal returns(CompactArray.Element) {
|
| 972 |
+
|
| 973 |
+
return self.compactArray.getNext();
|
| 974 |
+
}
|
| 975 |
+
|
| 976 |
+
|
| 977 |
+
function size (Data storage self) internal view returns(uint256 res) {
|
| 978 |
+
return self.compactArray.length();
|
| 979 |
+
}
|
| 980 |
+
|
| 981 |
+
function getItemAtIndex (Data storage self, uint256 index) internal view returns(CompactArray.Element) {
|
| 982 |
+
return self.compactArray.itemAtIndex(index);
|
| 983 |
+
}
|
| 984 |
+
|
| 985 |
+
}
|
| 986 |
+
|
| 987 |
+
|
| 988 |
+
|
| 989 |
+
library Player {
|
| 990 |
+
using UIntSet for UIntSet.Data;
|
| 991 |
+
using CompactArray for CompactArray.Data;
|
| 992 |
+
|
| 993 |
+
struct BettingRecord {
|
| 994 |
+
address playerAddress;
|
| 995 |
+
uint256 gameId;
|
| 996 |
+
uint256 wagerAmount;
|
| 997 |
+
uint256 bettingRecordId;
|
| 998 |
+
uint256 gamePotBeforeBet;
|
| 999 |
+
uint256 withdrawnAmount;
|
| 1000 |
+
uint256 withdrawnPopAmount;
|
| 1001 |
+
bool isActive;
|
| 1002 |
+
}
|
| 1003 |
+
|
| 1004 |
+
struct Data {
|
| 1005 |
+
UIntSet.Data bettingRecordIds;
|
| 1006 |
+
mapping (uint256 => BettingRecord) bettingRecordMapping;
|
| 1007 |
+
}
|
| 1008 |
+
|
| 1009 |
+
|
| 1010 |
+
function containsBettingRecordFromId (Data storage self, uint256 bettingRecordId) internal view returns(bool containsBettingRecord) {
|
| 1011 |
+
return self.bettingRecordIds.contains(bettingRecordId);
|
| 1012 |
+
}
|
| 1013 |
+
|
| 1014 |
+
|
| 1015 |
+
|
| 1016 |
+
function getBettingRecordForId (Data storage self, uint256 bettingRecordId) internal view returns(BettingRecord record) {
|
| 1017 |
+
if(containsBettingRecordFromId(self, bettingRecordId) == false) {
|
| 1018 |
+
return ;
|
| 1019 |
+
}
|
| 1020 |
+
return self.bettingRecordMapping[bettingRecordId];
|
| 1021 |
+
}
|
| 1022 |
+
|
| 1023 |
+
|
| 1024 |
+
|
| 1025 |
+
function insertBettingRecord (Data storage self, BettingRecord record) internal {
|
| 1026 |
+
|
| 1027 |
+
self.bettingRecordMapping[record.bettingRecordId] = record;
|
| 1028 |
+
self.bettingRecordIds.insert(record.bettingRecordId);
|
| 1029 |
+
}
|
| 1030 |
+
|
| 1031 |
+
|
| 1032 |
+
function getNextRecord (Data storage self) internal returns(BettingRecord record) {
|
| 1033 |
+
if(self.bettingRecordIds.size() == 0) {
|
| 1034 |
+
return ;
|
| 1035 |
+
}
|
| 1036 |
+
CompactArray.Element memory bettingRecordIdEntry = self.bettingRecordIds.getNext();
|
| 1037 |
+
return self.bettingRecordMapping[bettingRecordIdEntry.elem];
|
| 1038 |
+
}
|
| 1039 |
+
|
| 1040 |
+
function getBettingRecordAtIndex (Data storage self, uint256 index) internal view returns(BettingRecord record) {
|
| 1041 |
+
return self.bettingRecordMapping[self.bettingRecordIds.getItemAtIndex(index).elem];
|
| 1042 |
+
}
|
| 1043 |
+
|
| 1044 |
+
|
| 1045 |
+
|
| 1046 |
+
function deleteBettingRecordForId (Data storage self, uint256 bettingRecordId) internal {
|
| 1047 |
+
self.bettingRecordIds.removeElement(bettingRecordId);
|
| 1048 |
+
}
|
| 1049 |
+
|
| 1050 |
+
|
| 1051 |
+
function unprocessedBettingRecordCount (Data storage self) internal view returns(uint256 size) {
|
| 1052 |
+
return self.bettingRecordIds.size();
|
| 1053 |
+
}
|
| 1054 |
+
}
|
| 1055 |
+
|
| 1056 |
+
library BettingRecordArray {
|
| 1057 |
+
using Player for Player.Data;
|
| 1058 |
+
using SafeMath for uint256;
|
| 1059 |
+
|
| 1060 |
+
struct Data {
|
| 1061 |
+
Player.BettingRecord[] array;
|
| 1062 |
+
uint256 len;
|
| 1063 |
+
}
|
| 1064 |
+
|
| 1065 |
+
function resetIndex (Data storage self) internal {
|
| 1066 |
+
self.len = 0;
|
| 1067 |
+
}
|
| 1068 |
+
|
| 1069 |
+
function pushRecord (Data storage self, Player.BettingRecord record) internal {
|
| 1070 |
+
if(self.array.length == self.len) {
|
| 1071 |
+
self.array.length = self.array.length.add(1);
|
| 1072 |
+
}
|
| 1073 |
+
self.array[self.len] = record;
|
| 1074 |
+
self.len = self.len.add(1);
|
| 1075 |
+
}
|
| 1076 |
+
|
| 1077 |
+
function getNextRecord (Data storage self) internal view returns(Player.BettingRecord record) {
|
| 1078 |
+
if(self.array.length == self.len) {
|
| 1079 |
+
return;
|
| 1080 |
+
}
|
| 1081 |
+
return self.array[self.len];
|
| 1082 |
+
}
|
| 1083 |
+
}
|
| 1084 |
+
|
| 1085 |
+
library FixedPoint {
|
| 1086 |
+
using SafeMath for uint256;
|
| 1087 |
+
using SafeInt for int256;
|
| 1088 |
+
|
| 1089 |
+
int256 constant fracBits = 32;
|
| 1090 |
+
int256 constant scale = 1 << 32;
|
| 1091 |
+
int256 constant halfScale = scale >> 1;
|
| 1092 |
+
int256 constant precision = 1000000;
|
| 1093 |
+
int256 constant e = 11674931554;
|
| 1094 |
+
int256 constant pi = 13493037704;
|
| 1095 |
+
int256 constant _2pi = 26986075409;
|
| 1096 |
+
|
| 1097 |
+
struct Data {
|
| 1098 |
+
int256 val;
|
| 1099 |
+
}
|
| 1100 |
+
|
| 1101 |
+
function fromInt256(int256 n) internal pure returns (Data) {
|
| 1102 |
+
return Data({val: n.mul(scale)});
|
| 1103 |
+
}
|
| 1104 |
+
|
| 1105 |
+
function fromFraction(int256 numerator, int256 denominator) internal pure returns (Data) {
|
| 1106 |
+
return Data ({
|
| 1107 |
+
val: numerator.mul(scale).div(denominator)
|
| 1108 |
+
});
|
| 1109 |
+
}
|
| 1110 |
+
|
| 1111 |
+
function toInt256(Data n) internal pure returns (int256) {
|
| 1112 |
+
return (n.val * precision) >> fracBits;
|
| 1113 |
+
}
|
| 1114 |
+
|
| 1115 |
+
function toUInt256Raw(Data a) internal pure returns (uint256) {
|
| 1116 |
+
return uint256(a.val >> fracBits);
|
| 1117 |
+
}
|
| 1118 |
+
|
| 1119 |
+
function add(Data a, Data b) internal pure returns (Data) {
|
| 1120 |
+
return Data({val: a.val.add(b.val)});
|
| 1121 |
+
}
|
| 1122 |
+
|
| 1123 |
+
function sub(Data a, Data b) internal pure returns (Data) {
|
| 1124 |
+
return Data({val: a.val.sub(b.val)});
|
| 1125 |
+
}
|
| 1126 |
+
|
| 1127 |
+
function mul(Data a, Data b) internal pure returns (Data) {
|
| 1128 |
+
int256 result = a.val.mul(b.val).div(scale);
|
| 1129 |
+
return Data({val: result});
|
| 1130 |
+
}
|
| 1131 |
+
|
| 1132 |
+
function div(Data a, Data b) internal pure returns (Data) {
|
| 1133 |
+
int256 num = a.val.mul(scale);
|
| 1134 |
+
return Data({val: num.div(b.val)});
|
| 1135 |
+
}
|
| 1136 |
+
|
| 1137 |
+
function neg(Data a) internal pure returns (Data) {
|
| 1138 |
+
return Data({val: -a.val});
|
| 1139 |
+
}
|
| 1140 |
+
|
| 1141 |
+
function mod(Data a, Data b) internal pure returns (Data) {
|
| 1142 |
+
return Data({val: a.val % b.val});
|
| 1143 |
+
}
|
| 1144 |
+
|
| 1145 |
+
function expBySquaring(Data x, Data n) internal pure returns (Data) {
|
| 1146 |
+
if(n.val == 0) {
|
| 1147 |
+
return Data({val: scale});
|
| 1148 |
+
}
|
| 1149 |
+
Data memory extra = Data({val: scale});
|
| 1150 |
+
while(true) {
|
| 1151 |
+
if(n.val == scale) {
|
| 1152 |
+
return mul(x, extra);
|
| 1153 |
+
} else if (n.val % (2*scale) != 0) {
|
| 1154 |
+
extra = mul(extra, x);
|
| 1155 |
+
n = sub(n, fromInt256(1));
|
| 1156 |
+
}
|
| 1157 |
+
x = mul(x, x);
|
| 1158 |
+
n = div(n, fromInt256(2));
|
| 1159 |
+
}
|
| 1160 |
+
}
|
| 1161 |
+
|
| 1162 |
+
function sin(Data x) internal pure returns (Data) {
|
| 1163 |
+
int256 val = x.val % _2pi;
|
| 1164 |
+
|
| 1165 |
+
if(val < -pi) {
|
| 1166 |
+
val += _2pi;
|
| 1167 |
+
} else if (val > pi) {
|
| 1168 |
+
val -= _2pi;
|
| 1169 |
+
}
|
| 1170 |
+
Data memory result;
|
| 1171 |
+
if(val < 0) {
|
| 1172 |
+
result = add(mul(Data({val: 5468522184}), Data({val: val})), mul(Data({val: 1740684682}), mul(Data({val: val}), Data({val: val}))));
|
| 1173 |
+
if(result.val < 0) {
|
| 1174 |
+
result = add(mul(Data({val: 966367641}), sub(mul(result, neg(result)), result)), result);
|
| 1175 |
+
} else {
|
| 1176 |
+
result = add(mul(Data({val: 966367641}), sub(mul(result, result), result)), result);
|
| 1177 |
+
}
|
| 1178 |
+
return result;
|
| 1179 |
+
} else {
|
| 1180 |
+
result = sub(mul(Data({val: 5468522184}), Data({val: val})), mul(Data({val: 1740684682}), mul(Data({val: val}), Data({val: val}))));
|
| 1181 |
+
if(result.val < 0) {
|
| 1182 |
+
result = add(mul(Data({val: 966367641}), sub(mul(result, neg(result)), result)), result);
|
| 1183 |
+
} else {
|
| 1184 |
+
result = add(mul(Data({val: 966367641}), sub(mul(result, result), result)), result);
|
| 1185 |
+
}
|
| 1186 |
+
return result;
|
| 1187 |
+
}
|
| 1188 |
+
}
|
| 1189 |
+
|
| 1190 |
+
function cmp(Data a, Data b) internal pure returns (int256) {
|
| 1191 |
+
if(a.val > b.val) {
|
| 1192 |
+
return 1;
|
| 1193 |
+
} else if(a.val < b.val) {
|
| 1194 |
+
return -1;
|
| 1195 |
+
} else {
|
| 1196 |
+
return 0;
|
| 1197 |
+
}
|
| 1198 |
+
}
|
| 1199 |
+
|
| 1200 |
+
function log10(Data a) internal pure returns (Data) {
|
| 1201 |
+
return div(ln(a), ln(fromInt256(10)));
|
| 1202 |
+
}
|
| 1203 |
+
|
| 1204 |
+
function ln(Data a) internal pure returns (Data) {
|
| 1205 |
+
int256 LOG = 0;
|
| 1206 |
+
int256 prec = 1000000;
|
| 1207 |
+
int256 x = a.val.mul(prec) >> fracBits;
|
| 1208 |
+
|
| 1209 |
+
while(x >= 1500000) {
|
| 1210 |
+
LOG = LOG.add(405465);
|
| 1211 |
+
x = x.mul(2).div(3);
|
| 1212 |
+
}
|
| 1213 |
+
x = x.sub(prec);
|
| 1214 |
+
int256 y = x;
|
| 1215 |
+
int256 i = 1;
|
| 1216 |
+
while (i < 10){
|
| 1217 |
+
LOG = LOG.add(y.div(i));
|
| 1218 |
+
i = i.add(1);
|
| 1219 |
+
y = x.mul(y).div(prec);
|
| 1220 |
+
LOG = LOG.sub(y.div(i));
|
| 1221 |
+
i = i.add(1);
|
| 1222 |
+
y = x.mul(y).div(prec);
|
| 1223 |
+
}
|
| 1224 |
+
LOG = LOG.mul(scale);
|
| 1225 |
+
LOG = LOG.div(prec);
|
| 1226 |
+
return Data({val: LOG});
|
| 1227 |
+
}
|
| 1228 |
+
|
| 1229 |
+
function expRaw(Data a) internal pure returns (Data) {
|
| 1230 |
+
int256 l1 = scale.add(a.val.div(4));
|
| 1231 |
+
int256 l2 = scale.add(a.val.div(3).mul(l1).div(scale));
|
| 1232 |
+
int256 l3 = scale.add(a.val.div(2).mul(l2).div(scale));
|
| 1233 |
+
int256 l4 = scale.add(a.val.mul(l3).div(scale));
|
| 1234 |
+
|
| 1235 |
+
return Data({val: l4});
|
| 1236 |
+
}
|
| 1237 |
+
|
| 1238 |
+
function exp(Data a) internal pure returns (Data) {
|
| 1239 |
+
int256 pwr = a.val >> fracBits;
|
| 1240 |
+
int256 frac = a.val.sub(pwr << fracBits);
|
| 1241 |
+
|
| 1242 |
+
return mul(expRaw(Data({val: frac})), expBySquaring(Data({val: e}), fromInt256(pwr)));
|
| 1243 |
+
}
|
| 1244 |
+
|
| 1245 |
+
function pow(Data base, Data power) internal pure returns (Data) {
|
| 1246 |
+
int256 intpwr = power.val >> 32;
|
| 1247 |
+
int256 frac = power.val.sub(intpwr << fracBits);
|
| 1248 |
+
return mul(expRaw(mul(Data({val:frac}), ln(base))), expBySquaring(base, fromInt256(intpwr)));
|
| 1249 |
+
}
|
| 1250 |
+
}
|
smart_contract_dataset/block number dependency/2003.sol
ADDED
|
@@ -0,0 +1,383 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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ool);
|
| 7 |
+
}
|
| 8 |
+
|
| 9 |
+
contract ZTHInterface {
|
| 10 |
+
function transfer(address _to, uint _value) public returns (bool);
|
| 11 |
+
function approve(address spender, uint tokens) public returns (bool);
|
| 12 |
+
}
|
| 13 |
+
|
| 14 |
+
contract Zlots is ZTHReceivingContract {
|
| 15 |
+
using SafeMath for uint;
|
| 16 |
+
|
| 17 |
+
address private owner;
|
| 18 |
+
address private bankroll;
|
| 19 |
+
|
| 20 |
+
|
| 21 |
+
uint totalSpins;
|
| 22 |
+
uint totalZTHWagered;
|
| 23 |
+
|
| 24 |
+
|
| 25 |
+
uint contractBalance;
|
| 26 |
+
|
| 27 |
+
|
| 28 |
+
bool public gameActive;
|
| 29 |
+
|
| 30 |
+
address private ZTHTKNADDR;
|
| 31 |
+
address private ZTHBANKROLL;
|
| 32 |
+
ZTHInterface private ZTHTKN;
|
| 33 |
+
|
| 34 |
+
mapping (uint => bool) validTokenBet;
|
| 35 |
+
|
| 36 |
+
|
| 37 |
+
event HouseRetrievedTake(
|
| 38 |
+
uint timeTaken,
|
| 39 |
+
uint tokensWithdrawn
|
| 40 |
+
);
|
| 41 |
+
|
| 42 |
+
|
| 43 |
+
event TokensWagered(
|
| 44 |
+
address _wagerer,
|
| 45 |
+
uint _wagered
|
| 46 |
+
);
|
| 47 |
+
|
| 48 |
+
event LogResult(
|
| 49 |
+
address _wagerer,
|
| 50 |
+
uint _result,
|
| 51 |
+
uint _profit,
|
| 52 |
+
uint _wagered,
|
| 53 |
+
bool _win
|
| 54 |
+
);
|
| 55 |
+
|
| 56 |
+
event Loss(
|
| 57 |
+
address _wagerer
|
| 58 |
+
);
|
| 59 |
+
|
| 60 |
+
event Jackpot(
|
| 61 |
+
address _wagerer
|
| 62 |
+
);
|
| 63 |
+
|
| 64 |
+
event EightXMultiplier(
|
| 65 |
+
address _wagerer
|
| 66 |
+
);
|
| 67 |
+
|
| 68 |
+
event ReturnBet(
|
| 69 |
+
address _wagerer
|
| 70 |
+
);
|
| 71 |
+
|
| 72 |
+
event TwoAndAHalfXMultiplier(
|
| 73 |
+
address _wagerer
|
| 74 |
+
);
|
| 75 |
+
|
| 76 |
+
event OneAndAHalfXMultiplier(
|
| 77 |
+
address _wagerer
|
| 78 |
+
);
|
| 79 |
+
|
| 80 |
+
modifier onlyOwner {
|
| 81 |
+
require(msg.sender == owner);
|
| 82 |
+
_;
|
| 83 |
+
}
|
| 84 |
+
|
| 85 |
+
modifier onlyBankroll {
|
| 86 |
+
require(msg.sender == bankroll);
|
| 87 |
+
_;
|
| 88 |
+
}
|
| 89 |
+
|
| 90 |
+
modifier onlyOwnerOrBankroll {
|
| 91 |
+
require(msg.sender == owner || msg.sender == bankroll);
|
| 92 |
+
_;
|
| 93 |
+
}
|
| 94 |
+
|
| 95 |
+
|
| 96 |
+
modifier gameIsActive {
|
| 97 |
+
require(gameActive == true);
|
| 98 |
+
_;
|
| 99 |
+
}
|
| 100 |
+
|
| 101 |
+
constructor(address ZethrAddress, address BankrollAddress) public {
|
| 102 |
+
|
| 103 |
+
|
| 104 |
+
ZTHTKNADDR = ZethrAddress;
|
| 105 |
+
ZTHBANKROLL = BankrollAddress;
|
| 106 |
+
|
| 107 |
+
|
| 108 |
+
owner = msg.sender;
|
| 109 |
+
bankroll = ZTHBANKROLL;
|
| 110 |
+
|
| 111 |
+
|
| 112 |
+
ZTHTKN = ZTHInterface(ZTHTKNADDR);
|
| 113 |
+
ZTHTKN.approve(ZTHBANKROLL, 2**256 - 1);
|
| 114 |
+
|
| 115 |
+
|
| 116 |
+
ZTHTKN.approve(owner, 2**256 - 1);
|
| 117 |
+
|
| 118 |
+
|
| 119 |
+
validTokenBet[5e18] = true;
|
| 120 |
+
validTokenBet[10e18] = true;
|
| 121 |
+
validTokenBet[25e18] = true;
|
| 122 |
+
validTokenBet[50e18] = true;
|
| 123 |
+
|
| 124 |
+
gameActive = true;
|
| 125 |
+
}
|
| 126 |
+
|
| 127 |
+
|
| 128 |
+
function() public payable { }
|
| 129 |
+
|
| 130 |
+
|
| 131 |
+
struct TKN { address sender; uint value; }
|
| 132 |
+
function tokenFallback(address _from, uint _value, bytes ) public returns (bool){
|
| 133 |
+
TKN memory _tkn;
|
| 134 |
+
_tkn.sender = _from;
|
| 135 |
+
_tkn.value = _value;
|
| 136 |
+
_spinTokens(_tkn);
|
| 137 |
+
return true;
|
| 138 |
+
}
|
| 139 |
+
|
| 140 |
+
struct playerSpin {
|
| 141 |
+
uint200 tokenValue;
|
| 142 |
+
uint48 blockn;
|
| 143 |
+
}
|
| 144 |
+
|
| 145 |
+
|
| 146 |
+
mapping(address => playerSpin) public playerSpins;
|
| 147 |
+
|
| 148 |
+
|
| 149 |
+
function _spinTokens(TKN _tkn) private {
|
| 150 |
+
|
| 151 |
+
require(gameActive);
|
| 152 |
+
require(_zthToken(msg.sender));
|
| 153 |
+
require(validTokenBet[_tkn.value]);
|
| 154 |
+
require(jackpotGuard(_tkn.value));
|
| 155 |
+
|
| 156 |
+
require(_tkn.value < ((2 ** 200) - 1));
|
| 157 |
+
require(block.number < ((2 ** 48) - 1));
|
| 158 |
+
|
| 159 |
+
address _customerAddress = _tkn.sender;
|
| 160 |
+
uint _wagered = _tkn.value;
|
| 161 |
+
|
| 162 |
+
playerSpin memory spin = playerSpins[_tkn.sender];
|
| 163 |
+
|
| 164 |
+
contractBalance = contractBalance.add(_wagered);
|
| 165 |
+
|
| 166 |
+
|
| 167 |
+
require(block.number != spin.blockn);
|
| 168 |
+
|
| 169 |
+
|
| 170 |
+
if (spin.blockn != 0) {
|
| 171 |
+
_finishSpin(_tkn.sender);
|
| 172 |
+
}
|
| 173 |
+
|
| 174 |
+
|
| 175 |
+
spin.blockn = uint48(block.number);
|
| 176 |
+
spin.tokenValue = uint200(_wagered);
|
| 177 |
+
|
| 178 |
+
|
| 179 |
+
playerSpins[_tkn.sender] = spin;
|
| 180 |
+
|
| 181 |
+
|
| 182 |
+
totalSpins += 1;
|
| 183 |
+
|
| 184 |
+
|
| 185 |
+
totalZTHWagered += _wagered;
|
| 186 |
+
|
| 187 |
+
emit TokensWagered(_customerAddress, _wagered);
|
| 188 |
+
|
| 189 |
+
}
|
| 190 |
+
|
| 191 |
+
|
| 192 |
+
function finishSpin() public
|
| 193 |
+
gameIsActive
|
| 194 |
+
returns (uint)
|
| 195 |
+
{
|
| 196 |
+
return _finishSpin(msg.sender);
|
| 197 |
+
}
|
| 198 |
+
|
| 199 |
+
|
| 200 |
+
function _finishSpin(address target)
|
| 201 |
+
private returns (uint)
|
| 202 |
+
{
|
| 203 |
+
playerSpin memory spin = playerSpins[target];
|
| 204 |
+
|
| 205 |
+
require(spin.tokenValue > 0);
|
| 206 |
+
require(spin.blockn != block.number);
|
| 207 |
+
|
| 208 |
+
uint profit = 0;
|
| 209 |
+
|
| 210 |
+
|
| 211 |
+
|
| 212 |
+
uint result;
|
| 213 |
+
if (block.number - spin.blockn > 255) {
|
| 214 |
+
result = 9999;
|
| 215 |
+
} else {
|
| 216 |
+
|
| 217 |
+
|
| 218 |
+
|
| 219 |
+
result = random(10000, spin.blockn, target);
|
| 220 |
+
}
|
| 221 |
+
|
| 222 |
+
if (result > 4489) {
|
| 223 |
+
|
| 224 |
+
emit Loss(target);
|
| 225 |
+
emit LogResult(target, result, profit, spin.tokenValue, false);
|
| 226 |
+
} else {
|
| 227 |
+
if (result < 29) {
|
| 228 |
+
|
| 229 |
+
profit = SafeMath.mul(spin.tokenValue, 25);
|
| 230 |
+
emit Jackpot(target);
|
| 231 |
+
|
| 232 |
+
} else {
|
| 233 |
+
if (result < 233) {
|
| 234 |
+
|
| 235 |
+
profit = SafeMath.mul(spin.tokenValue, 8);
|
| 236 |
+
emit EightXMultiplier(target);
|
| 237 |
+
} else {
|
| 238 |
+
|
| 239 |
+
if (result < 641) {
|
| 240 |
+
|
| 241 |
+
profit = spin.tokenValue;
|
| 242 |
+
emit ReturnBet(target);
|
| 243 |
+
} else {
|
| 244 |
+
if (result < 1865) {
|
| 245 |
+
|
| 246 |
+
profit = SafeMath.div(SafeMath.mul(spin.tokenValue, 25), 10);
|
| 247 |
+
emit TwoAndAHalfXMultiplier(target);
|
| 248 |
+
} else {
|
| 249 |
+
|
| 250 |
+
profit = SafeMath.div(SafeMath.mul(spin.tokenValue, 15), 10);
|
| 251 |
+
emit OneAndAHalfXMultiplier(target);
|
| 252 |
+
}
|
| 253 |
+
}
|
| 254 |
+
}
|
| 255 |
+
}
|
| 256 |
+
emit LogResult(target, result, profit, spin.tokenValue, true);
|
| 257 |
+
contractBalance = contractBalance.sub(profit);
|
| 258 |
+
ZTHTKN.transfer(target, profit);
|
| 259 |
+
}
|
| 260 |
+
playerSpins[target] = playerSpin(uint200(0), uint48(0));
|
| 261 |
+
return result;
|
| 262 |
+
}
|
| 263 |
+
|
| 264 |
+
|
| 265 |
+
|
| 266 |
+
|
| 267 |
+
|
| 268 |
+
function jackpotGuard(uint _wager)
|
| 269 |
+
public
|
| 270 |
+
view
|
| 271 |
+
returns (bool)
|
| 272 |
+
{
|
| 273 |
+
uint maxProfit = SafeMath.mul(_wager, 25);
|
| 274 |
+
uint halfContractBalance = SafeMath.div(contractBalance, 2);
|
| 275 |
+
return (maxProfit <= halfContractBalance);
|
| 276 |
+
}
|
| 277 |
+
|
| 278 |
+
|
| 279 |
+
|
| 280 |
+
function maxRandom(uint blockn, address entropy) public view returns (uint256 randomNumber) {
|
| 281 |
+
return uint256(keccak256(
|
| 282 |
+
abi.encodePacked(
|
| 283 |
+
blockhash(blockn),
|
| 284 |
+
entropy)
|
| 285 |
+
));
|
| 286 |
+
}
|
| 287 |
+
|
| 288 |
+
|
| 289 |
+
function random(uint256 upper, uint256 blockn, address entropy) internal view returns (uint256 randomNumber) {
|
| 290 |
+
return maxRandom(blockn, entropy) % upper;
|
| 291 |
+
}
|
| 292 |
+
|
| 293 |
+
|
| 294 |
+
function balanceOf() public view returns (uint) {
|
| 295 |
+
return contractBalance;
|
| 296 |
+
}
|
| 297 |
+
|
| 298 |
+
function addNewBetAmount(uint _tokenAmount)
|
| 299 |
+
public
|
| 300 |
+
onlyOwner
|
| 301 |
+
{
|
| 302 |
+
validTokenBet[_tokenAmount] = true;
|
| 303 |
+
}
|
| 304 |
+
|
| 305 |
+
|
| 306 |
+
function pauseGame() public onlyOwner {
|
| 307 |
+
gameActive = false;
|
| 308 |
+
}
|
| 309 |
+
|
| 310 |
+
|
| 311 |
+
function resumeGame() public onlyOwner {
|
| 312 |
+
gameActive = true;
|
| 313 |
+
}
|
| 314 |
+
|
| 315 |
+
|
| 316 |
+
function changeOwner(address _newOwner) public onlyOwner {
|
| 317 |
+
owner = _newOwner;
|
| 318 |
+
}
|
| 319 |
+
|
| 320 |
+
|
| 321 |
+
function changeBankroll(address _newBankroll) public onlyOwner {
|
| 322 |
+
bankroll = _newBankroll;
|
| 323 |
+
}
|
| 324 |
+
|
| 325 |
+
|
| 326 |
+
function divertDividendsToBankroll()
|
| 327 |
+
public
|
| 328 |
+
onlyOwner
|
| 329 |
+
{
|
| 330 |
+
bankroll.transfer(address(this).balance);
|
| 331 |
+
}
|
| 332 |
+
|
| 333 |
+
function testingSelfDestruct()
|
| 334 |
+
public
|
| 335 |
+
onlyOwner
|
| 336 |
+
{
|
| 337 |
+
|
| 338 |
+
ZTHTKN.transfer(owner, contractBalance);
|
| 339 |
+
selfdestruct(owner);
|
| 340 |
+
}
|
| 341 |
+
|
| 342 |
+
|
| 343 |
+
function _zthToken(address _tokenContract) private view returns (bool) {
|
| 344 |
+
return _tokenContract == ZTHTKNADDR;
|
| 345 |
+
}
|
| 346 |
+
}
|
| 347 |
+
|
| 348 |
+
|
| 349 |
+
|
| 350 |
+
|
| 351 |
+
library SafeMath {
|
| 352 |
+
|
| 353 |
+
|
| 354 |
+
function mul(uint a, uint b) internal pure returns (uint) {
|
| 355 |
+
if (a == 0) {
|
| 356 |
+
return 0;
|
| 357 |
+
}
|
| 358 |
+
uint c = a * b;
|
| 359 |
+
assert(c / a == b);
|
| 360 |
+
return c;
|
| 361 |
+
}
|
| 362 |
+
|
| 363 |
+
|
| 364 |
+
function div(uint a, uint b) internal pure returns (uint) {
|
| 365 |
+
|
| 366 |
+
uint c = a / b;
|
| 367 |
+
|
| 368 |
+
return c;
|
| 369 |
+
}
|
| 370 |
+
|
| 371 |
+
|
| 372 |
+
function sub(uint a, uint b) internal pure returns (uint) {
|
| 373 |
+
assert(b <= a);
|
| 374 |
+
return a - b;
|
| 375 |
+
}
|
| 376 |
+
|
| 377 |
+
|
| 378 |
+
function add(uint a, uint b) internal pure returns (uint) {
|
| 379 |
+
uint c = a + b;
|
| 380 |
+
assert(c >= a);
|
| 381 |
+
return c;
|
| 382 |
+
}
|
| 383 |
+
}
|
smart_contract_dataset/block number dependency/2110.sol
ADDED
|
@@ -0,0 +1,395 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
pragma solidity ^0.4.24;
|
| 2 |
+
|
| 3 |
+
library SafeMath {
|
| 4 |
+
function mul(uint256 a, uint256 b) internal pure returns (uint256) {
|
| 5 |
+
uint256 c = a * b;
|
| 6 |
+
assert(a == 0 || c / a == b);
|
| 7 |
+
return c;
|
| 8 |
+
}
|
| 9 |
+
|
| 10 |
+
function div(uint256 a, uint256 b) internal pure returns (uint256) {
|
| 11 |
+
|
| 12 |
+
uint256 c = a / b;
|
| 13 |
+
|
| 14 |
+
return c;
|
| 15 |
+
}
|
| 16 |
+
|
| 17 |
+
function sub(uint256 a, uint256 b) internal pure returns (uint256) {
|
| 18 |
+
assert(b <= a);
|
| 19 |
+
return a - b;
|
| 20 |
+
}
|
| 21 |
+
|
| 22 |
+
function add(uint256 a, uint256 b) internal pure returns (uint256) {
|
| 23 |
+
uint256 c = a + b;
|
| 24 |
+
assert(c >= a);
|
| 25 |
+
return c;
|
| 26 |
+
}
|
| 27 |
+
}
|
| 28 |
+
|
| 29 |
+
library utils{
|
| 30 |
+
function inArray(uint[] _arr,uint _val) internal pure returns(bool){
|
| 31 |
+
for(uint _i=0;_i< _arr.length;_i++){
|
| 32 |
+
if(_arr[_i]==_val){
|
| 33 |
+
return true;
|
| 34 |
+
break;
|
| 35 |
+
}
|
| 36 |
+
}
|
| 37 |
+
return false;
|
| 38 |
+
}
|
| 39 |
+
|
| 40 |
+
function inArray(address[] _arr,address _val) internal pure returns(bool){
|
| 41 |
+
for(uint _i=0;_i< _arr.length;_i++){
|
| 42 |
+
if(_arr[_i]==_val){
|
| 43 |
+
return true;
|
| 44 |
+
break;
|
| 45 |
+
}
|
| 46 |
+
}
|
| 47 |
+
return false;
|
| 48 |
+
}
|
| 49 |
+
}
|
| 50 |
+
|
| 51 |
+
|
| 52 |
+
contract Ownable {
|
| 53 |
+
address public owner;
|
| 54 |
+
|
| 55 |
+
|
| 56 |
+
constructor() public {
|
| 57 |
+
owner = msg.sender;
|
| 58 |
+
}
|
| 59 |
+
|
| 60 |
+
|
| 61 |
+
|
| 62 |
+
modifier onlyOwner() {
|
| 63 |
+
require(msg.sender == owner);
|
| 64 |
+
_;
|
| 65 |
+
}
|
| 66 |
+
|
| 67 |
+
|
| 68 |
+
|
| 69 |
+
function transferOwnership(address newOwner) onlyOwner public {
|
| 70 |
+
require(newOwner != address(0));
|
| 71 |
+
owner = newOwner;
|
| 72 |
+
}
|
| 73 |
+
|
| 74 |
+
}
|
| 75 |
+
|
| 76 |
+
contract GuessEthEvents{
|
| 77 |
+
event drawLog(uint,uint,uint);
|
| 78 |
+
|
| 79 |
+
event guessEvt(
|
| 80 |
+
address indexed playerAddr,
|
| 81 |
+
uint[] numbers, uint amount
|
| 82 |
+
);
|
| 83 |
+
event winnersEvt(
|
| 84 |
+
uint blockNumber,
|
| 85 |
+
address indexed playerAddr,
|
| 86 |
+
uint amount,
|
| 87 |
+
uint winAmount
|
| 88 |
+
);
|
| 89 |
+
event withdrawEvt(
|
| 90 |
+
address indexed to,
|
| 91 |
+
uint256 value
|
| 92 |
+
);
|
| 93 |
+
event drawEvt(
|
| 94 |
+
uint indexed blocknumberr,
|
| 95 |
+
uint number
|
| 96 |
+
);
|
| 97 |
+
|
| 98 |
+
event sponseEvt(
|
| 99 |
+
address indexed addr,
|
| 100 |
+
uint amount
|
| 101 |
+
);
|
| 102 |
+
|
| 103 |
+
event pauseGameEvt(
|
| 104 |
+
bool pause
|
| 105 |
+
);
|
| 106 |
+
event setOddsEvt(
|
| 107 |
+
uint odds
|
| 108 |
+
);
|
| 109 |
+
|
| 110 |
+
}
|
| 111 |
+
|
| 112 |
+
contract GuessEth is Ownable,GuessEthEvents{
|
| 113 |
+
using SafeMath for uint;
|
| 114 |
+
|
| 115 |
+
|
| 116 |
+
|
| 117 |
+
struct bnumber{
|
| 118 |
+
address addr;
|
| 119 |
+
uint number;
|
| 120 |
+
uint value;
|
| 121 |
+
int8 result;
|
| 122 |
+
uint prize;
|
| 123 |
+
}
|
| 124 |
+
mapping(uint => bnumber[]) public bets;
|
| 125 |
+
mapping(uint => address) public betNumber;
|
| 126 |
+
|
| 127 |
+
|
| 128 |
+
mapping(address => uint[]) private playerBetBNumber;
|
| 129 |
+
|
| 130 |
+
|
| 131 |
+
struct winner{
|
| 132 |
+
bool result;
|
| 133 |
+
uint prize;
|
| 134 |
+
}
|
| 135 |
+
|
| 136 |
+
mapping(uint => winner[]) private winners;
|
| 137 |
+
mapping(uint => uint) private winResult;
|
| 138 |
+
|
| 139 |
+
address private wallet1;
|
| 140 |
+
address private wallet2;
|
| 141 |
+
|
| 142 |
+
uint private predictBlockInterval=3;
|
| 143 |
+
uint public odds=30;
|
| 144 |
+
uint public blockInterval=500;
|
| 145 |
+
uint public curOpenBNumber=0;
|
| 146 |
+
uint public numberRange=100;
|
| 147 |
+
|
| 148 |
+
bool public gamePaused=false;
|
| 149 |
+
|
| 150 |
+
|
| 151 |
+
|
| 152 |
+
mapping(address => uint) Sponsors;
|
| 153 |
+
uint public balanceOfSPS=0;
|
| 154 |
+
address[] public SponsorAddresses;
|
| 155 |
+
|
| 156 |
+
uint reservefund=30 ether;
|
| 157 |
+
|
| 158 |
+
|
| 159 |
+
|
| 160 |
+
modifier isHuman() {
|
| 161 |
+
address _addr = msg.sender;
|
| 162 |
+
uint256 _codeLength;
|
| 163 |
+
|
| 164 |
+
assembly {_codeLength := extcodesize(_addr)}
|
| 165 |
+
require(_codeLength == 0, "sorry humans only");
|
| 166 |
+
_;
|
| 167 |
+
}
|
| 168 |
+
|
| 169 |
+
constructor(address _wallet1,address _wallet2) public{
|
| 170 |
+
wallet1=_wallet1;
|
| 171 |
+
wallet2=_wallet2;
|
| 172 |
+
|
| 173 |
+
curOpenBNumber=blockInterval*(block.number.div(blockInterval));
|
| 174 |
+
}
|
| 175 |
+
|
| 176 |
+
function pauseGame(bool _status) public onlyOwner returns(bool){
|
| 177 |
+
gamePaused=_status;
|
| 178 |
+
emit pauseGameEvt(_status);
|
| 179 |
+
}
|
| 180 |
+
|
| 181 |
+
function setOdds(uint _odds) isHuman() public onlyOwner returns(bool){
|
| 182 |
+
odds = _odds;
|
| 183 |
+
emit setOddsEvt(_odds);
|
| 184 |
+
}
|
| 185 |
+
function setReservefund(uint _reservefund) isHuman() public onlyOwner returns(bool){
|
| 186 |
+
reservefund = _reservefund * 1 ether;
|
| 187 |
+
}
|
| 188 |
+
|
| 189 |
+
function getTargetBNumber() view isHuman() public returns(uint){
|
| 190 |
+
uint n;
|
| 191 |
+
n=blockInterval*(predictBlockInterval + block.number/blockInterval);
|
| 192 |
+
return n;
|
| 193 |
+
}
|
| 194 |
+
|
| 195 |
+
function guess(uint[] _numbers) payable isHuman() public returns(uint){
|
| 196 |
+
require(msg.value >= _numbers.length * 0.05 ether);
|
| 197 |
+
|
| 198 |
+
uint n=blockInterval*(predictBlockInterval + block.number/blockInterval);
|
| 199 |
+
|
| 200 |
+
for(uint _i=0;_i < _numbers.length;_i++){
|
| 201 |
+
bnumber memory b;
|
| 202 |
+
|
| 203 |
+
b.addr=msg.sender;
|
| 204 |
+
b.number=_numbers[_i];
|
| 205 |
+
b.value=msg.value/_numbers.length;
|
| 206 |
+
b.result=-1;
|
| 207 |
+
|
| 208 |
+
bets[n].push(b);
|
| 209 |
+
}
|
| 210 |
+
|
| 211 |
+
|
| 212 |
+
if(utils.inArray(playerBetBNumber[msg.sender],n)==false){
|
| 213 |
+
playerBetBNumber[msg.sender].push(n);
|
| 214 |
+
}
|
| 215 |
+
|
| 216 |
+
emit guessEvt(msg.sender,_numbers, msg.value);
|
| 217 |
+
|
| 218 |
+
return _numbers.length;
|
| 219 |
+
}
|
| 220 |
+
|
| 221 |
+
|
| 222 |
+
function getPlayerGuessNumbers() view public returns (uint[],uint[],uint256[],int8[],uint[]){
|
| 223 |
+
uint _c=0;
|
| 224 |
+
uint _i=0;
|
| 225 |
+
uint _j=0;
|
| 226 |
+
uint _bnumber;
|
| 227 |
+
uint limitRows=100;
|
| 228 |
+
|
| 229 |
+
while(_i < playerBetBNumber[msg.sender].length){
|
| 230 |
+
_bnumber=playerBetBNumber[msg.sender][_i];
|
| 231 |
+
for(_j=0 ; _j < bets[_bnumber].length && _c < limitRows ; _j++){
|
| 232 |
+
if(msg.sender==bets[_bnumber][_j].addr){
|
| 233 |
+
_c++;
|
| 234 |
+
}
|
| 235 |
+
}
|
| 236 |
+
_i++;
|
| 237 |
+
}
|
| 238 |
+
|
| 239 |
+
uint[] memory _blockNumbers=new uint[](_c);
|
| 240 |
+
uint[] memory _numbers=new uint[](_c);
|
| 241 |
+
uint[] memory _values=new uint[](_c);
|
| 242 |
+
int8[] memory _result=new int8[](_c);
|
| 243 |
+
uint[] memory _prize=new uint[](_c);
|
| 244 |
+
|
| 245 |
+
if(_c<=0){
|
| 246 |
+
return(_blockNumbers,_numbers,_values,_result,_prize);
|
| 247 |
+
}
|
| 248 |
+
|
| 249 |
+
|
| 250 |
+
|
| 251 |
+
uint _count=0;
|
| 252 |
+
for(_i=0 ; _i < playerBetBNumber[msg.sender].length ; _i++){
|
| 253 |
+
_bnumber=playerBetBNumber[msg.sender][_i];
|
| 254 |
+
|
| 255 |
+
for(_j=0 ; _j < bets[_bnumber].length && _count < limitRows ; _j++){
|
| 256 |
+
if(bets[_bnumber][_j].addr == msg.sender){
|
| 257 |
+
_blockNumbers[_count] = _bnumber;
|
| 258 |
+
_numbers[_count] = bets[_bnumber][_j].number;
|
| 259 |
+
_values[_count] = bets[_bnumber][_j].value;
|
| 260 |
+
_result[_count] = bets[_bnumber][_j].result;
|
| 261 |
+
_prize[_count] = bets[_bnumber][_j].prize;
|
| 262 |
+
|
| 263 |
+
_count++;
|
| 264 |
+
}
|
| 265 |
+
}
|
| 266 |
+
}
|
| 267 |
+
|
| 268 |
+
|
| 269 |
+
return(_blockNumbers,_numbers,_values,_result,_prize);
|
| 270 |
+
}
|
| 271 |
+
|
| 272 |
+
|
| 273 |
+
function draw(uint _blockNumber,uint _blockTimestamp) public onlyOwner returns (uint){
|
| 274 |
+
require(block.number >= curOpenBNumber + blockInterval);
|
| 275 |
+
|
| 276 |
+
|
| 277 |
+
curOpenBNumber=_blockNumber;
|
| 278 |
+
uint result=_blockTimestamp % numberRange;
|
| 279 |
+
winResult[_blockNumber]=result;
|
| 280 |
+
|
| 281 |
+
for(uint _i=0;_i < bets[_blockNumber].length;_i++){
|
| 282 |
+
|
| 283 |
+
|
| 284 |
+
|
| 285 |
+
if(bets[_blockNumber][_i].number==result){
|
| 286 |
+
bets[_blockNumber][_i].result = 1;
|
| 287 |
+
bets[_blockNumber][_i].prize = bets[_blockNumber][_i].value * odds;
|
| 288 |
+
|
| 289 |
+
emit winnersEvt(_blockNumber,bets[_blockNumber][_i].addr,bets[_blockNumber][_i].value,bets[_blockNumber][_i].prize);
|
| 290 |
+
|
| 291 |
+
withdraw(bets[_blockNumber][_i].addr,bets[_blockNumber][_i].prize);
|
| 292 |
+
|
| 293 |
+
}else{
|
| 294 |
+
bets[_blockNumber][_i].result = 0;
|
| 295 |
+
bets[_blockNumber][_i].prize = 0;
|
| 296 |
+
}
|
| 297 |
+
}
|
| 298 |
+
|
| 299 |
+
emit drawEvt(_blockNumber,curOpenBNumber);
|
| 300 |
+
|
| 301 |
+
return result;
|
| 302 |
+
}
|
| 303 |
+
|
| 304 |
+
function getWinners(uint _blockNumber) view public returns(address[],uint[]){
|
| 305 |
+
uint _count=winners[_blockNumber].length;
|
| 306 |
+
|
| 307 |
+
address[] memory _addresses = new address[](_count);
|
| 308 |
+
uint[] memory _prize = new uint[](_count);
|
| 309 |
+
|
| 310 |
+
uint _i=0;
|
| 311 |
+
for(_i=0;_i<_count;_i++){
|
| 312 |
+
|
| 313 |
+
_prize[_i] = winners[_blockNumber][_i].prize;
|
| 314 |
+
}
|
| 315 |
+
|
| 316 |
+
return (_addresses,_prize);
|
| 317 |
+
}
|
| 318 |
+
|
| 319 |
+
function getWinResults(uint _blockNumber) view public returns(uint){
|
| 320 |
+
return winResult[_blockNumber];
|
| 321 |
+
}
|
| 322 |
+
|
| 323 |
+
function withdraw(address _to,uint amount) public onlyOwner returns(bool){
|
| 324 |
+
require(address(this).balance.sub(amount) > 0);
|
| 325 |
+
_to.transfer(amount);
|
| 326 |
+
|
| 327 |
+
emit withdrawEvt(_to,amount);
|
| 328 |
+
return true;
|
| 329 |
+
}
|
| 330 |
+
|
| 331 |
+
|
| 332 |
+
function invest() isHuman payable public returns(uint){
|
| 333 |
+
require(msg.value >= 1 ether,"Minima amoun:1 ether");
|
| 334 |
+
|
| 335 |
+
Sponsors[msg.sender] = Sponsors[msg.sender].add(msg.value);
|
| 336 |
+
balanceOfSPS = balanceOfSPS.add(msg.value);
|
| 337 |
+
|
| 338 |
+
if(!utils.inArray(SponsorAddresses,msg.sender)){
|
| 339 |
+
SponsorAddresses.push(msg.sender);
|
| 340 |
+
emit sponseEvt(msg.sender,msg.value);
|
| 341 |
+
}
|
| 342 |
+
|
| 343 |
+
return Sponsors[msg.sender];
|
| 344 |
+
}
|
| 345 |
+
|
| 346 |
+
function distribute() public onlyOwner{
|
| 347 |
+
if(address(this).balance < reservefund){
|
| 348 |
+
return;
|
| 349 |
+
}
|
| 350 |
+
|
| 351 |
+
uint availableProfits=address(this).balance.sub(reservefund);
|
| 352 |
+
uint prft1=availableProfits.mul(3 ether).div(10 ether);
|
| 353 |
+
uint prft2=availableProfits.sub(prft1);
|
| 354 |
+
|
| 355 |
+
uint _val=0;
|
| 356 |
+
uint _i=0;
|
| 357 |
+
|
| 358 |
+
for(_i=0;_i<SponsorAddresses.length;_i++){
|
| 359 |
+
_val = (prft1 * Sponsors[SponsorAddresses[_i]]) / (balanceOfSPS);
|
| 360 |
+
SponsorAddresses[_i].transfer(_val);
|
| 361 |
+
}
|
| 362 |
+
|
| 363 |
+
uint w1p=prft2.mul(3 ether).div(10 ether);
|
| 364 |
+
|
| 365 |
+
wallet1.transfer(w1p);
|
| 366 |
+
wallet2.transfer(prft2.sub(w1p));
|
| 367 |
+
}
|
| 368 |
+
|
| 369 |
+
function sharesOfSPS() view public returns(uint,uint){
|
| 370 |
+
return (Sponsors[msg.sender],balanceOfSPS);
|
| 371 |
+
}
|
| 372 |
+
|
| 373 |
+
function getAllSponsors() view public returns(address[],uint[],uint){
|
| 374 |
+
uint _i=0;
|
| 375 |
+
uint _c=0;
|
| 376 |
+
for(_i=0;_i<SponsorAddresses.length;_i++){
|
| 377 |
+
_c+=1;
|
| 378 |
+
}
|
| 379 |
+
|
| 380 |
+
address[] memory addrs=new address[](_c);
|
| 381 |
+
uint[] memory amounts=new uint[](_c);
|
| 382 |
+
|
| 383 |
+
for(_i=0;_i<SponsorAddresses.length;_i++){
|
| 384 |
+
addrs[_i]=SponsorAddresses[_i];
|
| 385 |
+
amounts[_i]=Sponsors[SponsorAddresses[_i]];
|
| 386 |
+
}
|
| 387 |
+
|
| 388 |
+
return(addrs,amounts,balanceOfSPS);
|
| 389 |
+
}
|
| 390 |
+
|
| 391 |
+
function() payable isHuman() public {
|
| 392 |
+
}
|
| 393 |
+
|
| 394 |
+
|
| 395 |
+
}
|
smart_contract_dataset/block number dependency/215.sol
ADDED
|
@@ -0,0 +1,1133 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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|
+
|
| 9 |
+
|
| 10 |
+
event OwnershipRenounced(address indexed previousOwner);
|
| 11 |
+
event OwnershipTransferred(
|
| 12 |
+
address indexed previousOwner,
|
| 13 |
+
address indexed newOwner
|
| 14 |
+
);
|
| 15 |
+
|
| 16 |
+
|
| 17 |
+
|
| 18 |
+
constructor() public {
|
| 19 |
+
owner = msg.sender;
|
| 20 |
+
}
|
| 21 |
+
|
| 22 |
+
|
| 23 |
+
modifier onlyOwner() {
|
| 24 |
+
require(msg.sender == owner);
|
| 25 |
+
_;
|
| 26 |
+
}
|
| 27 |
+
|
| 28 |
+
|
| 29 |
+
function transferOwnership(address newOwner) public onlyOwner {
|
| 30 |
+
require(newOwner != address(0));
|
| 31 |
+
emit OwnershipTransferred(owner, newOwner);
|
| 32 |
+
owner = newOwner;
|
| 33 |
+
}
|
| 34 |
+
|
| 35 |
+
|
| 36 |
+
function renounceOwnership() public onlyOwner {
|
| 37 |
+
emit OwnershipRenounced(owner);
|
| 38 |
+
owner = address(0);
|
| 39 |
+
}
|
| 40 |
+
}
|
| 41 |
+
|
| 42 |
+
|
| 43 |
+
|
| 44 |
+
|
| 45 |
+
contract Pausable is Ownable {
|
| 46 |
+
event Pause();
|
| 47 |
+
event Unpause();
|
| 48 |
+
|
| 49 |
+
bool public paused = false;
|
| 50 |
+
|
| 51 |
+
|
| 52 |
+
|
| 53 |
+
modifier whenNotPaused() {
|
| 54 |
+
require(!paused);
|
| 55 |
+
_;
|
| 56 |
+
}
|
| 57 |
+
|
| 58 |
+
|
| 59 |
+
modifier whenPaused() {
|
| 60 |
+
require(paused);
|
| 61 |
+
_;
|
| 62 |
+
}
|
| 63 |
+
|
| 64 |
+
|
| 65 |
+
function pause() onlyOwner whenNotPaused public {
|
| 66 |
+
paused = true;
|
| 67 |
+
emit Pause();
|
| 68 |
+
}
|
| 69 |
+
|
| 70 |
+
|
| 71 |
+
function unpause() onlyOwner whenPaused public {
|
| 72 |
+
paused = false;
|
| 73 |
+
emit Unpause();
|
| 74 |
+
}
|
| 75 |
+
}
|
| 76 |
+
|
| 77 |
+
|
| 78 |
+
|
| 79 |
+
|
| 80 |
+
library SafeMath {
|
| 81 |
+
|
| 82 |
+
|
| 83 |
+
function mul(uint256 a, uint256 b) internal pure returns (uint256 c) {
|
| 84 |
+
if (a == 0) {
|
| 85 |
+
return 0;
|
| 86 |
+
}
|
| 87 |
+
c = a * b;
|
| 88 |
+
assert(c / a == b);
|
| 89 |
+
return c;
|
| 90 |
+
}
|
| 91 |
+
|
| 92 |
+
|
| 93 |
+
function div(uint256 a, uint256 b) internal pure returns (uint256) {
|
| 94 |
+
|
| 95 |
+
|
| 96 |
+
|
| 97 |
+
return a / b;
|
| 98 |
+
}
|
| 99 |
+
|
| 100 |
+
|
| 101 |
+
function sub(uint256 a, uint256 b) internal pure returns (uint256) {
|
| 102 |
+
assert(b <= a);
|
| 103 |
+
return a - b;
|
| 104 |
+
}
|
| 105 |
+
|
| 106 |
+
|
| 107 |
+
function add(uint256 a, uint256 b) internal pure returns (uint256 c) {
|
| 108 |
+
c = a + b;
|
| 109 |
+
assert(c >= a);
|
| 110 |
+
return c;
|
| 111 |
+
}
|
| 112 |
+
}
|
| 113 |
+
|
| 114 |
+
|
| 115 |
+
|
| 116 |
+
|
| 117 |
+
contract ERC721Basic {
|
| 118 |
+
function balanceOf(address _owner) public view returns (uint256 _balance);
|
| 119 |
+
function ownerOf(uint256 _tokenId) public view returns (address _owner);
|
| 120 |
+
function exists(uint256 _tokenId) public view returns (bool _exists);
|
| 121 |
+
|
| 122 |
+
function approve(address _to, uint256 _tokenId) public;
|
| 123 |
+
function getApproved(uint256 _tokenId) public view returns (address _operator);
|
| 124 |
+
|
| 125 |
+
function transferFrom(address _from, address _to, uint256 _tokenId) public;
|
| 126 |
+
}
|
| 127 |
+
|
| 128 |
+
|
| 129 |
+
contract HorseyExchange is Pausable {
|
| 130 |
+
|
| 131 |
+
using SafeMath for uint256;
|
| 132 |
+
|
| 133 |
+
event HorseyDeposit(uint256 tokenId, uint256 price);
|
| 134 |
+
event SaleCanceled(uint256 tokenId);
|
| 135 |
+
event HorseyPurchased(uint256 tokenId, address newOwner, uint256 totalToPay);
|
| 136 |
+
|
| 137 |
+
|
| 138 |
+
uint256 public marketMakerFee = 3;
|
| 139 |
+
|
| 140 |
+
|
| 141 |
+
uint256 collectedFees = 0;
|
| 142 |
+
|
| 143 |
+
|
| 144 |
+
ERC721Basic public token;
|
| 145 |
+
|
| 146 |
+
|
| 147 |
+
struct SaleData {
|
| 148 |
+
uint256 price;
|
| 149 |
+
address owner;
|
| 150 |
+
}
|
| 151 |
+
|
| 152 |
+
|
| 153 |
+
mapping (uint256 => SaleData) market;
|
| 154 |
+
|
| 155 |
+
|
| 156 |
+
mapping (address => uint256[]) userBarn;
|
| 157 |
+
|
| 158 |
+
|
| 159 |
+
constructor() Pausable() public {
|
| 160 |
+
}
|
| 161 |
+
|
| 162 |
+
|
| 163 |
+
function setStables(address _token) external
|
| 164 |
+
onlyOwner()
|
| 165 |
+
{
|
| 166 |
+
require(address(_token) != 0,"Address of token is zero");
|
| 167 |
+
token = ERC721Basic(_token);
|
| 168 |
+
}
|
| 169 |
+
|
| 170 |
+
|
| 171 |
+
function setMarketFees(uint256 fees) external
|
| 172 |
+
onlyOwner()
|
| 173 |
+
{
|
| 174 |
+
marketMakerFee = fees;
|
| 175 |
+
}
|
| 176 |
+
|
| 177 |
+
|
| 178 |
+
function getTokensOnSale(address user) external view returns(uint256[]) {
|
| 179 |
+
return userBarn[user];
|
| 180 |
+
}
|
| 181 |
+
|
| 182 |
+
|
| 183 |
+
function getTokenPrice(uint256 tokenId) public view
|
| 184 |
+
isOnMarket(tokenId) returns (uint256) {
|
| 185 |
+
return market[tokenId].price + (market[tokenId].price / 100 * marketMakerFee);
|
| 186 |
+
}
|
| 187 |
+
|
| 188 |
+
|
| 189 |
+
function depositToExchange(uint256 tokenId, uint256 price) external
|
| 190 |
+
whenNotPaused()
|
| 191 |
+
isTokenOwner(tokenId)
|
| 192 |
+
nonZeroPrice(price)
|
| 193 |
+
tokenAvailable() {
|
| 194 |
+
require(token.getApproved(tokenId) == address(this),"Exchange is not allowed to transfer");
|
| 195 |
+
|
| 196 |
+
token.transferFrom(msg.sender, address(this), tokenId);
|
| 197 |
+
|
| 198 |
+
|
| 199 |
+
market[tokenId] = SaleData(price,msg.sender);
|
| 200 |
+
|
| 201 |
+
|
| 202 |
+
userBarn[msg.sender].push(tokenId);
|
| 203 |
+
|
| 204 |
+
emit HorseyDeposit(tokenId, price);
|
| 205 |
+
}
|
| 206 |
+
|
| 207 |
+
|
| 208 |
+
function cancelSale(uint256 tokenId) external
|
| 209 |
+
whenNotPaused()
|
| 210 |
+
originalOwnerOf(tokenId)
|
| 211 |
+
tokenAvailable() returns (bool) {
|
| 212 |
+
|
| 213 |
+
token.transferFrom(address(this),msg.sender,tokenId);
|
| 214 |
+
|
| 215 |
+
|
| 216 |
+
delete market[tokenId];
|
| 217 |
+
|
| 218 |
+
|
| 219 |
+
_removeTokenFromBarn(tokenId, msg.sender);
|
| 220 |
+
|
| 221 |
+
emit SaleCanceled(tokenId);
|
| 222 |
+
|
| 223 |
+
|
| 224 |
+
|
| 225 |
+
return userBarn[msg.sender].length > 0;
|
| 226 |
+
}
|
| 227 |
+
|
| 228 |
+
|
| 229 |
+
function purchaseToken(uint256 tokenId) external payable
|
| 230 |
+
whenNotPaused()
|
| 231 |
+
isOnMarket(tokenId)
|
| 232 |
+
tokenAvailable()
|
| 233 |
+
notOriginalOwnerOf(tokenId)
|
| 234 |
+
{
|
| 235 |
+
|
| 236 |
+
uint256 totalToPay = getTokenPrice(tokenId);
|
| 237 |
+
require(msg.value >= totalToPay, "Not paying enough");
|
| 238 |
+
|
| 239 |
+
|
| 240 |
+
SaleData memory sale = market[tokenId];
|
| 241 |
+
|
| 242 |
+
|
| 243 |
+
collectedFees += totalToPay - sale.price;
|
| 244 |
+
|
| 245 |
+
|
| 246 |
+
sale.owner.transfer(sale.price);
|
| 247 |
+
|
| 248 |
+
|
| 249 |
+
_removeTokenFromBarn(tokenId, sale.owner);
|
| 250 |
+
|
| 251 |
+
|
| 252 |
+
delete market[tokenId];
|
| 253 |
+
|
| 254 |
+
|
| 255 |
+
|
| 256 |
+
token.transferFrom(address(this), msg.sender, tokenId);
|
| 257 |
+
|
| 258 |
+
|
| 259 |
+
if(msg.value > totalToPay)
|
| 260 |
+
{
|
| 261 |
+
msg.sender.transfer(msg.value.sub(totalToPay));
|
| 262 |
+
}
|
| 263 |
+
|
| 264 |
+
emit HorseyPurchased(tokenId, msg.sender, totalToPay);
|
| 265 |
+
}
|
| 266 |
+
|
| 267 |
+
|
| 268 |
+
function withdraw() external
|
| 269 |
+
onlyOwner()
|
| 270 |
+
{
|
| 271 |
+
assert(collectedFees <= address(this).balance);
|
| 272 |
+
owner.transfer(collectedFees);
|
| 273 |
+
collectedFees = 0;
|
| 274 |
+
}
|
| 275 |
+
|
| 276 |
+
|
| 277 |
+
function _removeTokenFromBarn(uint tokenId, address barnAddress) internal {
|
| 278 |
+
uint256[] storage barnArray = userBarn[barnAddress];
|
| 279 |
+
require(barnArray.length > 0,"No tokens to remove");
|
| 280 |
+
int index = _indexOf(tokenId, barnArray);
|
| 281 |
+
require(index >= 0, "Token not found in barn");
|
| 282 |
+
|
| 283 |
+
|
| 284 |
+
for (uint256 i = uint256(index); i<barnArray.length-1; i++){
|
| 285 |
+
barnArray[i] = barnArray[i+1];
|
| 286 |
+
}
|
| 287 |
+
|
| 288 |
+
|
| 289 |
+
|
| 290 |
+
barnArray.length--;
|
| 291 |
+
}
|
| 292 |
+
|
| 293 |
+
|
| 294 |
+
function _indexOf(uint item, uint256[] memory array) internal pure returns (int256){
|
| 295 |
+
|
| 296 |
+
|
| 297 |
+
for(uint256 i = 0; i < array.length; i++){
|
| 298 |
+
if(array[i] == item){
|
| 299 |
+
return int256(i);
|
| 300 |
+
}
|
| 301 |
+
}
|
| 302 |
+
|
| 303 |
+
|
| 304 |
+
return -1;
|
| 305 |
+
}
|
| 306 |
+
|
| 307 |
+
|
| 308 |
+
modifier isOnMarket(uint256 tokenId) {
|
| 309 |
+
require(token.ownerOf(tokenId) == address(this),"Token not on market");
|
| 310 |
+
_;
|
| 311 |
+
}
|
| 312 |
+
|
| 313 |
+
|
| 314 |
+
modifier isTokenOwner(uint256 tokenId) {
|
| 315 |
+
require(token.ownerOf(tokenId) == msg.sender,"Not tokens owner");
|
| 316 |
+
_;
|
| 317 |
+
}
|
| 318 |
+
|
| 319 |
+
|
| 320 |
+
modifier originalOwnerOf(uint256 tokenId) {
|
| 321 |
+
require(market[tokenId].owner == msg.sender,"Not the original owner of");
|
| 322 |
+
_;
|
| 323 |
+
}
|
| 324 |
+
|
| 325 |
+
|
| 326 |
+
modifier notOriginalOwnerOf(uint256 tokenId) {
|
| 327 |
+
require(market[tokenId].owner != msg.sender,"Is the original owner");
|
| 328 |
+
_;
|
| 329 |
+
}
|
| 330 |
+
|
| 331 |
+
|
| 332 |
+
modifier nonZeroPrice(uint256 price){
|
| 333 |
+
require(price > 0,"Price is zero");
|
| 334 |
+
_;
|
| 335 |
+
}
|
| 336 |
+
|
| 337 |
+
|
| 338 |
+
modifier tokenAvailable(){
|
| 339 |
+
require(address(token) != 0,"Token address not set");
|
| 340 |
+
_;
|
| 341 |
+
}
|
| 342 |
+
}
|
| 343 |
+
|
| 344 |
+
|
| 345 |
+
|
| 346 |
+
|
| 347 |
+
contract EthorseRace {
|
| 348 |
+
|
| 349 |
+
|
| 350 |
+
struct chronus_info {
|
| 351 |
+
bool betting_open;
|
| 352 |
+
bool race_start;
|
| 353 |
+
bool race_end;
|
| 354 |
+
bool voided_bet;
|
| 355 |
+
uint32 starting_time;
|
| 356 |
+
uint32 betting_duration;
|
| 357 |
+
uint32 race_duration;
|
| 358 |
+
uint32 voided_timestamp;
|
| 359 |
+
}
|
| 360 |
+
|
| 361 |
+
address public owner;
|
| 362 |
+
|
| 363 |
+
|
| 364 |
+
chronus_info public chronus;
|
| 365 |
+
|
| 366 |
+
|
| 367 |
+
mapping (bytes32 => bool) public winner_horse;
|
| 368 |
+
|
| 369 |
+
|
| 370 |
+
function getCoinIndex(bytes32 index, address candidate) external constant returns (uint, uint, uint, bool, uint);
|
| 371 |
+
}
|
| 372 |
+
|
| 373 |
+
|
| 374 |
+
contract EthorseHelpers {
|
| 375 |
+
|
| 376 |
+
|
| 377 |
+
bytes32[] public all_horses = [bytes32("BTC"),bytes32("ETH"),bytes32("LTC")];
|
| 378 |
+
mapping(address => bool) public legitRaces;
|
| 379 |
+
bool onlyLegit = false;
|
| 380 |
+
|
| 381 |
+
|
| 382 |
+
function _addHorse(bytes32 newHorse) internal {
|
| 383 |
+
all_horses.push(newHorse);
|
| 384 |
+
}
|
| 385 |
+
|
| 386 |
+
function _addLegitRace(address newRace) internal
|
| 387 |
+
{
|
| 388 |
+
legitRaces[newRace] = true;
|
| 389 |
+
if(!onlyLegit)
|
| 390 |
+
onlyLegit = true;
|
| 391 |
+
}
|
| 392 |
+
|
| 393 |
+
function getall_horsesCount() public view returns(uint) {
|
| 394 |
+
return all_horses.length;
|
| 395 |
+
}
|
| 396 |
+
|
| 397 |
+
|
| 398 |
+
function _isWinnerOf(address raceAddress, address eth_address) internal view returns (bool,bytes32)
|
| 399 |
+
{
|
| 400 |
+
|
| 401 |
+
EthorseRace race = EthorseRace(raceAddress);
|
| 402 |
+
|
| 403 |
+
|
| 404 |
+
if(onlyLegit)
|
| 405 |
+
require(legitRaces[raceAddress],"not legit race");
|
| 406 |
+
|
| 407 |
+
bool voided_bet;
|
| 408 |
+
bool race_end;
|
| 409 |
+
(,,race_end,voided_bet,,,,) = race.chronus();
|
| 410 |
+
|
| 411 |
+
|
| 412 |
+
if(voided_bet || !race_end)
|
| 413 |
+
return (false,bytes32(0));
|
| 414 |
+
|
| 415 |
+
|
| 416 |
+
bytes32 horse;
|
| 417 |
+
bool found = false;
|
| 418 |
+
uint256 arrayLength = all_horses.length;
|
| 419 |
+
|
| 420 |
+
|
| 421 |
+
for(uint256 i = 0; i < arrayLength; i++)
|
| 422 |
+
{
|
| 423 |
+
if(race.winner_horse(all_horses[i])) {
|
| 424 |
+
horse = all_horses[i];
|
| 425 |
+
found = true;
|
| 426 |
+
break;
|
| 427 |
+
}
|
| 428 |
+
}
|
| 429 |
+
|
| 430 |
+
if(!found)
|
| 431 |
+
return (false,bytes32(0));
|
| 432 |
+
|
| 433 |
+
|
| 434 |
+
uint256 bet_amount = 0;
|
| 435 |
+
if(eth_address != address(0)) {
|
| 436 |
+
(,,,, bet_amount) = race.getCoinIndex(horse, eth_address);
|
| 437 |
+
}
|
| 438 |
+
|
| 439 |
+
|
| 440 |
+
return (bet_amount > 0, horse);
|
| 441 |
+
}
|
| 442 |
+
}
|
| 443 |
+
|
| 444 |
+
|
| 445 |
+
|
| 446 |
+
contract RoyalStablesInterface {
|
| 447 |
+
|
| 448 |
+
struct Horsey {
|
| 449 |
+
address race;
|
| 450 |
+
bytes32 dna;
|
| 451 |
+
uint8 feedingCounter;
|
| 452 |
+
uint8 tier;
|
| 453 |
+
}
|
| 454 |
+
|
| 455 |
+
mapping(uint256 => Horsey) public horseys;
|
| 456 |
+
mapping(address => uint32) public carrot_credits;
|
| 457 |
+
mapping(uint256 => string) public names;
|
| 458 |
+
address public master;
|
| 459 |
+
|
| 460 |
+
function getOwnedTokens(address eth_address) public view returns (uint256[]);
|
| 461 |
+
function storeName(uint256 tokenId, string newName) public;
|
| 462 |
+
function storeCarrotsCredit(address client, uint32 amount) public;
|
| 463 |
+
function storeHorsey(address client, uint256 tokenId, address race, bytes32 dna, uint8 feedingCounter, uint8 tier) public;
|
| 464 |
+
function modifyHorsey(uint256 tokenId, address race, bytes32 dna, uint8 feedingCounter, uint8 tier) public;
|
| 465 |
+
function modifyHorseyDna(uint256 tokenId, bytes32 dna) public;
|
| 466 |
+
function modifyHorseyFeedingCounter(uint256 tokenId, uint8 feedingCounter) public;
|
| 467 |
+
function modifyHorseyTier(uint256 tokenId, uint8 tier) public;
|
| 468 |
+
function unstoreHorsey(uint256 tokenId) public;
|
| 469 |
+
function ownerOf(uint256 tokenId) public returns (address);
|
| 470 |
+
}
|
| 471 |
+
|
| 472 |
+
|
| 473 |
+
contract HorseyToken is EthorseHelpers,Pausable {
|
| 474 |
+
using SafeMath for uint256;
|
| 475 |
+
|
| 476 |
+
|
| 477 |
+
event Claimed(address raceAddress, address eth_address, uint256 tokenId);
|
| 478 |
+
|
| 479 |
+
|
| 480 |
+
event Feeding(uint256 tokenId);
|
| 481 |
+
|
| 482 |
+
|
| 483 |
+
event ReceivedCarrot(uint256 tokenId, bytes32 newDna);
|
| 484 |
+
|
| 485 |
+
|
| 486 |
+
event FeedingFailed(uint256 tokenId);
|
| 487 |
+
|
| 488 |
+
|
| 489 |
+
event HorseyRenamed(uint256 tokenId, string newName);
|
| 490 |
+
|
| 491 |
+
|
| 492 |
+
event HorseyFreed(uint256 tokenId);
|
| 493 |
+
|
| 494 |
+
|
| 495 |
+
RoyalStablesInterface public stables;
|
| 496 |
+
|
| 497 |
+
|
| 498 |
+
uint8 public carrotsMultiplier = 1;
|
| 499 |
+
|
| 500 |
+
|
| 501 |
+
uint8 public rarityMultiplier = 1;
|
| 502 |
+
|
| 503 |
+
|
| 504 |
+
uint256 public claimingFee = 0.000 ether;
|
| 505 |
+
|
| 506 |
+
|
| 507 |
+
struct FeedingData {
|
| 508 |
+
uint256 blockNumber;
|
| 509 |
+
uint256 horsey;
|
| 510 |
+
}
|
| 511 |
+
|
| 512 |
+
|
| 513 |
+
mapping(address => FeedingData) public pendingFeedings;
|
| 514 |
+
|
| 515 |
+
|
| 516 |
+
uint256 public renamingCostsPerChar = 0.001 ether;
|
| 517 |
+
|
| 518 |
+
|
| 519 |
+
constructor(address stablesAddress)
|
| 520 |
+
EthorseHelpers()
|
| 521 |
+
Pausable() public {
|
| 522 |
+
stables = RoyalStablesInterface(stablesAddress);
|
| 523 |
+
}
|
| 524 |
+
|
| 525 |
+
|
| 526 |
+
function setRarityMultiplier(uint8 newRarityMultiplier) external
|
| 527 |
+
onlyOwner() {
|
| 528 |
+
rarityMultiplier = newRarityMultiplier;
|
| 529 |
+
}
|
| 530 |
+
|
| 531 |
+
|
| 532 |
+
function setCarrotsMultiplier(uint8 newCarrotsMultiplier) external
|
| 533 |
+
onlyOwner() {
|
| 534 |
+
carrotsMultiplier = newCarrotsMultiplier;
|
| 535 |
+
}
|
| 536 |
+
|
| 537 |
+
|
| 538 |
+
function setRenamingCosts(uint256 newRenamingCost) external
|
| 539 |
+
onlyOwner() {
|
| 540 |
+
renamingCostsPerChar = newRenamingCost;
|
| 541 |
+
}
|
| 542 |
+
|
| 543 |
+
|
| 544 |
+
function setClaimingCosts(uint256 newClaimingFee) external
|
| 545 |
+
onlyOwner() {
|
| 546 |
+
claimingFee = newClaimingFee;
|
| 547 |
+
}
|
| 548 |
+
|
| 549 |
+
|
| 550 |
+
function addLegitRaceAddress(address newAddress) external
|
| 551 |
+
onlyOwner() {
|
| 552 |
+
_addLegitRace(newAddress);
|
| 553 |
+
}
|
| 554 |
+
|
| 555 |
+
|
| 556 |
+
function withdraw() external
|
| 557 |
+
onlyOwner() {
|
| 558 |
+
owner.transfer(address(this).balance);
|
| 559 |
+
}
|
| 560 |
+
|
| 561 |
+
|
| 562 |
+
|
| 563 |
+
function addHorseIndex(bytes32 newHorse) external
|
| 564 |
+
onlyOwner() {
|
| 565 |
+
_addHorse(newHorse);
|
| 566 |
+
}
|
| 567 |
+
|
| 568 |
+
|
| 569 |
+
function getOwnedTokens(address eth_address) public view returns (uint256[]) {
|
| 570 |
+
return stables.getOwnedTokens(eth_address);
|
| 571 |
+
}
|
| 572 |
+
|
| 573 |
+
|
| 574 |
+
function can_claim(address raceAddress, address eth_address) public view returns (bool) {
|
| 575 |
+
bool res;
|
| 576 |
+
(res,) = _isWinnerOf(raceAddress, eth_address);
|
| 577 |
+
return res;
|
| 578 |
+
}
|
| 579 |
+
|
| 580 |
+
|
| 581 |
+
function claim(address raceAddress) external payable
|
| 582 |
+
costs(claimingFee)
|
| 583 |
+
whenNotPaused()
|
| 584 |
+
{
|
| 585 |
+
|
| 586 |
+
bytes32 winner;
|
| 587 |
+
bool res;
|
| 588 |
+
(res,winner) = _isWinnerOf(raceAddress, address(0));
|
| 589 |
+
require(winner != bytes32(0),"Winner is zero");
|
| 590 |
+
require(res,"can_claim return false");
|
| 591 |
+
|
| 592 |
+
uint256 id = _generate_special_horsey(raceAddress, msg.sender, winner);
|
| 593 |
+
emit Claimed(raceAddress, msg.sender, id);
|
| 594 |
+
}
|
| 595 |
+
|
| 596 |
+
|
| 597 |
+
function renameHorsey(uint256 tokenId, string newName) external
|
| 598 |
+
whenNotPaused()
|
| 599 |
+
onlyOwnerOf(tokenId)
|
| 600 |
+
costs(renamingCostsPerChar * bytes(newName).length)
|
| 601 |
+
payable {
|
| 602 |
+
uint256 renamingFee = renamingCostsPerChar * bytes(newName).length;
|
| 603 |
+
|
| 604 |
+
if(msg.value > renamingFee)
|
| 605 |
+
{
|
| 606 |
+
msg.sender.transfer(msg.value.sub(renamingFee));
|
| 607 |
+
}
|
| 608 |
+
|
| 609 |
+
stables.storeName(tokenId,newName);
|
| 610 |
+
emit HorseyRenamed(tokenId,newName);
|
| 611 |
+
}
|
| 612 |
+
|
| 613 |
+
|
| 614 |
+
function freeForCarrots(uint256 tokenId) external
|
| 615 |
+
whenNotPaused()
|
| 616 |
+
onlyOwnerOf(tokenId) {
|
| 617 |
+
require(pendingFeedings[msg.sender].horsey != tokenId,"");
|
| 618 |
+
|
| 619 |
+
uint8 feedingCounter;
|
| 620 |
+
(,,feedingCounter,) = stables.horseys(tokenId);
|
| 621 |
+
stables.storeCarrotsCredit(msg.sender,stables.carrot_credits(msg.sender) + uint32(feedingCounter * carrotsMultiplier));
|
| 622 |
+
stables.unstoreHorsey(tokenId);
|
| 623 |
+
emit HorseyFreed(tokenId);
|
| 624 |
+
}
|
| 625 |
+
|
| 626 |
+
|
| 627 |
+
function getCarrotCredits() external view returns (uint32) {
|
| 628 |
+
return stables.carrot_credits(msg.sender);
|
| 629 |
+
}
|
| 630 |
+
|
| 631 |
+
|
| 632 |
+
function getHorsey(uint256 tokenId) public view returns (address, bytes32, uint8, string) {
|
| 633 |
+
RoyalStablesInterface.Horsey memory temp;
|
| 634 |
+
(temp.race,temp.dna,temp.feedingCounter,temp.tier) = stables.horseys(tokenId);
|
| 635 |
+
return (temp.race,temp.dna,temp.feedingCounter,stables.names(tokenId));
|
| 636 |
+
}
|
| 637 |
+
|
| 638 |
+
|
| 639 |
+
function feed(uint256 tokenId) external
|
| 640 |
+
whenNotPaused()
|
| 641 |
+
onlyOwnerOf(tokenId)
|
| 642 |
+
carrotsMeetLevel(tokenId)
|
| 643 |
+
noFeedingInProgress()
|
| 644 |
+
{
|
| 645 |
+
pendingFeedings[msg.sender] = FeedingData(block.number,tokenId);
|
| 646 |
+
uint8 feedingCounter;
|
| 647 |
+
(,,feedingCounter,) = stables.horseys(tokenId);
|
| 648 |
+
stables.storeCarrotsCredit(msg.sender,stables.carrot_credits(msg.sender) - uint32(feedingCounter));
|
| 649 |
+
emit Feeding(tokenId);
|
| 650 |
+
}
|
| 651 |
+
|
| 652 |
+
|
| 653 |
+
function stopFeeding() external
|
| 654 |
+
feedingInProgress() returns (bool) {
|
| 655 |
+
uint256 blockNumber = pendingFeedings[msg.sender].blockNumber;
|
| 656 |
+
uint256 tokenId = pendingFeedings[msg.sender].horsey;
|
| 657 |
+
|
| 658 |
+
require(block.number - blockNumber >= 1,"feeding and stop feeding are in same block");
|
| 659 |
+
|
| 660 |
+
delete pendingFeedings[msg.sender];
|
| 661 |
+
|
| 662 |
+
|
| 663 |
+
|
| 664 |
+
if(block.number - blockNumber > 255) {
|
| 665 |
+
|
| 666 |
+
|
| 667 |
+
emit FeedingFailed(tokenId);
|
| 668 |
+
return false;
|
| 669 |
+
}
|
| 670 |
+
|
| 671 |
+
|
| 672 |
+
if(stables.ownerOf(tokenId) != msg.sender) {
|
| 673 |
+
|
| 674 |
+
|
| 675 |
+
emit FeedingFailed(tokenId);
|
| 676 |
+
return false;
|
| 677 |
+
}
|
| 678 |
+
|
| 679 |
+
|
| 680 |
+
_feed(tokenId, blockhash(blockNumber));
|
| 681 |
+
bytes32 dna;
|
| 682 |
+
(,dna,,) = stables.horseys(tokenId);
|
| 683 |
+
emit ReceivedCarrot(tokenId, dna);
|
| 684 |
+
return true;
|
| 685 |
+
}
|
| 686 |
+
|
| 687 |
+
|
| 688 |
+
function() external payable {
|
| 689 |
+
revert("Not accepting donations");
|
| 690 |
+
}
|
| 691 |
+
|
| 692 |
+
|
| 693 |
+
function _feed(uint256 tokenId, bytes32 blockHash) internal {
|
| 694 |
+
|
| 695 |
+
uint8 tier;
|
| 696 |
+
uint8 feedingCounter;
|
| 697 |
+
(,,feedingCounter,tier) = stables.horseys(tokenId);
|
| 698 |
+
uint256 probabilityByRarity = 10 ** (uint256(tier).add(1));
|
| 699 |
+
uint256 randNum = uint256(keccak256(abi.encodePacked(tokenId, blockHash))) % probabilityByRarity;
|
| 700 |
+
|
| 701 |
+
|
| 702 |
+
if(randNum <= (feedingCounter * rarityMultiplier)){
|
| 703 |
+
_increaseRarity(tokenId, blockHash);
|
| 704 |
+
}
|
| 705 |
+
|
| 706 |
+
|
| 707 |
+
|
| 708 |
+
if(feedingCounter < 255) {
|
| 709 |
+
stables.modifyHorseyFeedingCounter(tokenId,feedingCounter+1);
|
| 710 |
+
}
|
| 711 |
+
}
|
| 712 |
+
|
| 713 |
+
|
| 714 |
+
function _makeSpecialId(address race, address sender, bytes32 coinIndex) internal pure returns (uint256) {
|
| 715 |
+
return uint256(keccak256(abi.encodePacked(race, sender, coinIndex)));
|
| 716 |
+
}
|
| 717 |
+
|
| 718 |
+
|
| 719 |
+
function _generate_special_horsey(address race, address eth_address, bytes32 coinIndex) internal returns (uint256) {
|
| 720 |
+
uint256 id = _makeSpecialId(race, eth_address, coinIndex);
|
| 721 |
+
|
| 722 |
+
bytes32 dna = _shiftRight(keccak256(abi.encodePacked(race, coinIndex)),16);
|
| 723 |
+
|
| 724 |
+
stables.storeHorsey(eth_address,id,race,dna,1,0);
|
| 725 |
+
return id;
|
| 726 |
+
}
|
| 727 |
+
|
| 728 |
+
|
| 729 |
+
function _increaseRarity(uint256 tokenId, bytes32 blockHash) private {
|
| 730 |
+
uint8 tier;
|
| 731 |
+
bytes32 dna;
|
| 732 |
+
(,dna,,tier) = stables.horseys(tokenId);
|
| 733 |
+
if(tier < 255)
|
| 734 |
+
stables.modifyHorseyTier(tokenId,tier+1);
|
| 735 |
+
uint256 random = uint256(keccak256(abi.encodePacked(tokenId, blockHash)));
|
| 736 |
+
|
| 737 |
+
bytes32 rarityMask = _shiftLeft(bytes32(1), (random % 16 + 240));
|
| 738 |
+
bytes32 newdna = dna | rarityMask;
|
| 739 |
+
stables.modifyHorseyDna(tokenId,newdna);
|
| 740 |
+
}
|
| 741 |
+
|
| 742 |
+
|
| 743 |
+
function _shiftLeft(bytes32 data, uint n) internal pure returns (bytes32) {
|
| 744 |
+
return bytes32(uint256(data)*(2 ** n));
|
| 745 |
+
}
|
| 746 |
+
|
| 747 |
+
|
| 748 |
+
function _shiftRight(bytes32 data, uint n) internal pure returns (bytes32) {
|
| 749 |
+
return bytes32(uint256(data)/(2 ** n));
|
| 750 |
+
}
|
| 751 |
+
|
| 752 |
+
|
| 753 |
+
modifier carrotsMeetLevel(uint256 tokenId){
|
| 754 |
+
uint256 feedingCounter;
|
| 755 |
+
(,,feedingCounter,) = stables.horseys(tokenId);
|
| 756 |
+
require(feedingCounter <= stables.carrot_credits(msg.sender),"Not enough carrots");
|
| 757 |
+
_;
|
| 758 |
+
}
|
| 759 |
+
|
| 760 |
+
|
| 761 |
+
modifier costs(uint256 amount) {
|
| 762 |
+
require(msg.value >= amount,"Not enough funds");
|
| 763 |
+
_;
|
| 764 |
+
}
|
| 765 |
+
|
| 766 |
+
|
| 767 |
+
modifier validAddress(address addr) {
|
| 768 |
+
require(addr != address(0),"Address is zero");
|
| 769 |
+
_;
|
| 770 |
+
}
|
| 771 |
+
|
| 772 |
+
|
| 773 |
+
modifier noFeedingInProgress() {
|
| 774 |
+
|
| 775 |
+
require(pendingFeedings[msg.sender].blockNumber == 0,"Already feeding");
|
| 776 |
+
_;
|
| 777 |
+
}
|
| 778 |
+
|
| 779 |
+
|
| 780 |
+
modifier feedingInProgress() {
|
| 781 |
+
|
| 782 |
+
require(pendingFeedings[msg.sender].blockNumber != 0,"No pending feeding");
|
| 783 |
+
_;
|
| 784 |
+
}
|
| 785 |
+
|
| 786 |
+
|
| 787 |
+
modifier onlyOwnerOf(uint256 tokenId) {
|
| 788 |
+
require(stables.ownerOf(tokenId) == msg.sender, "Caller is not owner of this token");
|
| 789 |
+
_;
|
| 790 |
+
}
|
| 791 |
+
}
|
| 792 |
+
|
| 793 |
+
|
| 794 |
+
|
| 795 |
+
|
| 796 |
+
|
| 797 |
+
contract HorseyPilot {
|
| 798 |
+
|
| 799 |
+
|
| 800 |
+
event NewProposal(uint8 methodId, uint parameter, address proposer);
|
| 801 |
+
|
| 802 |
+
|
| 803 |
+
event ProposalPassed(uint8 methodId, uint parameter, address proposer);
|
| 804 |
+
|
| 805 |
+
|
| 806 |
+
|
| 807 |
+
uint8 constant votingThreshold = 2;
|
| 808 |
+
|
| 809 |
+
|
| 810 |
+
|
| 811 |
+
uint256 constant proposalLife = 7 days;
|
| 812 |
+
|
| 813 |
+
|
| 814 |
+
|
| 815 |
+
uint256 constant proposalCooldown = 1 days;
|
| 816 |
+
|
| 817 |
+
|
| 818 |
+
uint256 cooldownStart;
|
| 819 |
+
|
| 820 |
+
|
| 821 |
+
address public jokerAddress;
|
| 822 |
+
address public knightAddress;
|
| 823 |
+
address public paladinAddress;
|
| 824 |
+
|
| 825 |
+
|
| 826 |
+
address[3] public voters;
|
| 827 |
+
|
| 828 |
+
|
| 829 |
+
uint8 constant public knightEquity = 40;
|
| 830 |
+
uint8 constant public paladinEquity = 10;
|
| 831 |
+
|
| 832 |
+
|
| 833 |
+
address public exchangeAddress;
|
| 834 |
+
address public tokenAddress;
|
| 835 |
+
|
| 836 |
+
|
| 837 |
+
mapping(address => uint) internal _cBalance;
|
| 838 |
+
|
| 839 |
+
|
| 840 |
+
struct Proposal{
|
| 841 |
+
address proposer;
|
| 842 |
+
uint256 timestamp;
|
| 843 |
+
uint256 parameter;
|
| 844 |
+
uint8 methodId;
|
| 845 |
+
address[] yay;
|
| 846 |
+
address[] nay;
|
| 847 |
+
}
|
| 848 |
+
|
| 849 |
+
|
| 850 |
+
Proposal public currentProposal;
|
| 851 |
+
|
| 852 |
+
|
| 853 |
+
bool public proposalInProgress = false;
|
| 854 |
+
|
| 855 |
+
|
| 856 |
+
uint256 public toBeDistributed;
|
| 857 |
+
|
| 858 |
+
|
| 859 |
+
bool deployed = false;
|
| 860 |
+
|
| 861 |
+
|
| 862 |
+
constructor(
|
| 863 |
+
address _jokerAddress,
|
| 864 |
+
address _knightAddress,
|
| 865 |
+
address _paladinAddress,
|
| 866 |
+
address[3] _voters
|
| 867 |
+
) public {
|
| 868 |
+
jokerAddress = _jokerAddress;
|
| 869 |
+
knightAddress = _knightAddress;
|
| 870 |
+
paladinAddress = _paladinAddress;
|
| 871 |
+
|
| 872 |
+
for(uint i = 0; i < 3; i++) {
|
| 873 |
+
voters[i] = _voters[i];
|
| 874 |
+
}
|
| 875 |
+
|
| 876 |
+
|
| 877 |
+
cooldownStart = block.timestamp - proposalCooldown;
|
| 878 |
+
}
|
| 879 |
+
|
| 880 |
+
|
| 881 |
+
function deployChildren(address stablesAddress) external {
|
| 882 |
+
require(!deployed,"already deployed");
|
| 883 |
+
|
| 884 |
+
exchangeAddress = new HorseyExchange();
|
| 885 |
+
tokenAddress = new HorseyToken(stablesAddress);
|
| 886 |
+
|
| 887 |
+
|
| 888 |
+
HorseyExchange(exchangeAddress).setStables(stablesAddress);
|
| 889 |
+
|
| 890 |
+
deployed = true;
|
| 891 |
+
}
|
| 892 |
+
|
| 893 |
+
|
| 894 |
+
function transferJokerOwnership(address newJoker) external
|
| 895 |
+
validAddress(newJoker) {
|
| 896 |
+
require(jokerAddress == msg.sender,"Not right role");
|
| 897 |
+
_moveBalance(newJoker);
|
| 898 |
+
jokerAddress = newJoker;
|
| 899 |
+
}
|
| 900 |
+
|
| 901 |
+
|
| 902 |
+
function transferKnightOwnership(address newKnight) external
|
| 903 |
+
validAddress(newKnight) {
|
| 904 |
+
require(knightAddress == msg.sender,"Not right role");
|
| 905 |
+
_moveBalance(newKnight);
|
| 906 |
+
knightAddress = newKnight;
|
| 907 |
+
}
|
| 908 |
+
|
| 909 |
+
|
| 910 |
+
function transferPaladinOwnership(address newPaladin) external
|
| 911 |
+
validAddress(newPaladin) {
|
| 912 |
+
require(paladinAddress == msg.sender,"Not right role");
|
| 913 |
+
_moveBalance(newPaladin);
|
| 914 |
+
paladinAddress = newPaladin;
|
| 915 |
+
}
|
| 916 |
+
|
| 917 |
+
|
| 918 |
+
function withdrawCeo(address destination) external
|
| 919 |
+
onlyCLevelAccess()
|
| 920 |
+
validAddress(destination) {
|
| 921 |
+
|
| 922 |
+
|
| 923 |
+
if(toBeDistributed > 0){
|
| 924 |
+
_updateDistribution();
|
| 925 |
+
}
|
| 926 |
+
|
| 927 |
+
|
| 928 |
+
uint256 balance = _cBalance[msg.sender];
|
| 929 |
+
|
| 930 |
+
|
| 931 |
+
if(balance > 0 && (address(this).balance >= balance)) {
|
| 932 |
+
destination.transfer(balance);
|
| 933 |
+
_cBalance[msg.sender] = 0;
|
| 934 |
+
}
|
| 935 |
+
}
|
| 936 |
+
|
| 937 |
+
|
| 938 |
+
function syncFunds() external {
|
| 939 |
+
uint256 prevBalance = address(this).balance;
|
| 940 |
+
HorseyToken(tokenAddress).withdraw();
|
| 941 |
+
HorseyExchange(exchangeAddress).withdraw();
|
| 942 |
+
uint256 newBalance = address(this).balance;
|
| 943 |
+
|
| 944 |
+
toBeDistributed = toBeDistributed + (newBalance - prevBalance);
|
| 945 |
+
}
|
| 946 |
+
|
| 947 |
+
|
| 948 |
+
function getNobleBalance() external view
|
| 949 |
+
onlyCLevelAccess() returns (uint256) {
|
| 950 |
+
return _cBalance[msg.sender];
|
| 951 |
+
}
|
| 952 |
+
|
| 953 |
+
|
| 954 |
+
function makeProposal( uint8 methodId, uint256 parameter ) external
|
| 955 |
+
onlyCLevelAccess()
|
| 956 |
+
proposalAvailable()
|
| 957 |
+
cooledDown()
|
| 958 |
+
{
|
| 959 |
+
currentProposal.timestamp = block.timestamp;
|
| 960 |
+
currentProposal.parameter = parameter;
|
| 961 |
+
currentProposal.methodId = methodId;
|
| 962 |
+
currentProposal.proposer = msg.sender;
|
| 963 |
+
delete currentProposal.yay;
|
| 964 |
+
delete currentProposal.nay;
|
| 965 |
+
proposalInProgress = true;
|
| 966 |
+
|
| 967 |
+
emit NewProposal(methodId,parameter,msg.sender);
|
| 968 |
+
}
|
| 969 |
+
|
| 970 |
+
|
| 971 |
+
function voteOnProposal(bool voteFor) external
|
| 972 |
+
proposalPending()
|
| 973 |
+
onlyVoters()
|
| 974 |
+
notVoted() {
|
| 975 |
+
|
| 976 |
+
require((block.timestamp - currentProposal.timestamp) <= proposalLife);
|
| 977 |
+
if(voteFor)
|
| 978 |
+
{
|
| 979 |
+
currentProposal.yay.push(msg.sender);
|
| 980 |
+
|
| 981 |
+
if( currentProposal.yay.length >= votingThreshold )
|
| 982 |
+
{
|
| 983 |
+
_doProposal();
|
| 984 |
+
proposalInProgress = false;
|
| 985 |
+
|
| 986 |
+
return;
|
| 987 |
+
}
|
| 988 |
+
|
| 989 |
+
} else {
|
| 990 |
+
currentProposal.nay.push(msg.sender);
|
| 991 |
+
|
| 992 |
+
if( currentProposal.nay.length >= votingThreshold )
|
| 993 |
+
{
|
| 994 |
+
proposalInProgress = false;
|
| 995 |
+
cooldownStart = block.timestamp;
|
| 996 |
+
return;
|
| 997 |
+
}
|
| 998 |
+
}
|
| 999 |
+
}
|
| 1000 |
+
|
| 1001 |
+
|
| 1002 |
+
function _moveBalance(address newAddress) internal
|
| 1003 |
+
validAddress(newAddress) {
|
| 1004 |
+
require(newAddress != msg.sender);
|
| 1005 |
+
_cBalance[newAddress] = _cBalance[msg.sender];
|
| 1006 |
+
_cBalance[msg.sender] = 0;
|
| 1007 |
+
}
|
| 1008 |
+
|
| 1009 |
+
|
| 1010 |
+
function _updateDistribution() internal {
|
| 1011 |
+
require(toBeDistributed != 0,"nothing to distribute");
|
| 1012 |
+
uint256 knightPayday = toBeDistributed / 100 * knightEquity;
|
| 1013 |
+
uint256 paladinPayday = toBeDistributed / 100 * paladinEquity;
|
| 1014 |
+
|
| 1015 |
+
|
| 1016 |
+
uint256 jokerPayday = toBeDistributed - knightPayday - paladinPayday;
|
| 1017 |
+
|
| 1018 |
+
_cBalance[jokerAddress] = _cBalance[jokerAddress] + jokerPayday;
|
| 1019 |
+
_cBalance[knightAddress] = _cBalance[knightAddress] + knightPayday;
|
| 1020 |
+
_cBalance[paladinAddress] = _cBalance[paladinAddress] + paladinPayday;
|
| 1021 |
+
|
| 1022 |
+
toBeDistributed = 0;
|
| 1023 |
+
}
|
| 1024 |
+
|
| 1025 |
+
|
| 1026 |
+
function _doProposal() internal {
|
| 1027 |
+
|
| 1028 |
+
if( currentProposal.methodId == 0 ) HorseyToken(tokenAddress).setRenamingCosts(currentProposal.parameter);
|
| 1029 |
+
|
| 1030 |
+
|
| 1031 |
+
if( currentProposal.methodId == 1 ) HorseyExchange(exchangeAddress).setMarketFees(currentProposal.parameter);
|
| 1032 |
+
|
| 1033 |
+
|
| 1034 |
+
if( currentProposal.methodId == 2 ) HorseyToken(tokenAddress).addLegitRaceAddress(address(currentProposal.parameter));
|
| 1035 |
+
|
| 1036 |
+
|
| 1037 |
+
if( currentProposal.methodId == 3 ) HorseyToken(tokenAddress).addHorseIndex(bytes32(currentProposal.parameter));
|
| 1038 |
+
|
| 1039 |
+
|
| 1040 |
+
if( currentProposal.methodId == 4 ) {
|
| 1041 |
+
if(currentProposal.parameter == 0) {
|
| 1042 |
+
HorseyExchange(exchangeAddress).unpause();
|
| 1043 |
+
HorseyToken(tokenAddress).unpause();
|
| 1044 |
+
} else {
|
| 1045 |
+
HorseyExchange(exchangeAddress).pause();
|
| 1046 |
+
HorseyToken(tokenAddress).pause();
|
| 1047 |
+
}
|
| 1048 |
+
}
|
| 1049 |
+
|
| 1050 |
+
|
| 1051 |
+
if( currentProposal.methodId == 5 ) HorseyToken(tokenAddress).setClaimingCosts(currentProposal.parameter);
|
| 1052 |
+
|
| 1053 |
+
|
| 1054 |
+
if( currentProposal.methodId == 8 ){
|
| 1055 |
+
HorseyToken(tokenAddress).setCarrotsMultiplier(uint8(currentProposal.parameter));
|
| 1056 |
+
}
|
| 1057 |
+
|
| 1058 |
+
|
| 1059 |
+
if( currentProposal.methodId == 9 ){
|
| 1060 |
+
HorseyToken(tokenAddress).setRarityMultiplier(uint8(currentProposal.parameter));
|
| 1061 |
+
}
|
| 1062 |
+
|
| 1063 |
+
emit ProposalPassed(currentProposal.methodId,currentProposal.parameter,currentProposal.proposer);
|
| 1064 |
+
}
|
| 1065 |
+
|
| 1066 |
+
|
| 1067 |
+
modifier validAddress(address addr) {
|
| 1068 |
+
require(addr != address(0),"Address is zero");
|
| 1069 |
+
_;
|
| 1070 |
+
}
|
| 1071 |
+
|
| 1072 |
+
|
| 1073 |
+
modifier onlyCLevelAccess() {
|
| 1074 |
+
require((jokerAddress == msg.sender) || (knightAddress == msg.sender) || (paladinAddress == msg.sender),"not c level");
|
| 1075 |
+
_;
|
| 1076 |
+
}
|
| 1077 |
+
|
| 1078 |
+
|
| 1079 |
+
|
| 1080 |
+
modifier proposalAvailable(){
|
| 1081 |
+
require(((!proposalInProgress) || ((block.timestamp - currentProposal.timestamp) > proposalLife)),"proposal already pending");
|
| 1082 |
+
_;
|
| 1083 |
+
}
|
| 1084 |
+
|
| 1085 |
+
|
| 1086 |
+
|
| 1087 |
+
modifier cooledDown( ){
|
| 1088 |
+
if(msg.sender == currentProposal.proposer && (block.timestamp - cooldownStart < 1 days)){
|
| 1089 |
+
revert("Cool down period not passed yet");
|
| 1090 |
+
}
|
| 1091 |
+
_;
|
| 1092 |
+
}
|
| 1093 |
+
|
| 1094 |
+
|
| 1095 |
+
modifier proposalPending() {
|
| 1096 |
+
require(proposalInProgress,"no proposal pending");
|
| 1097 |
+
_;
|
| 1098 |
+
}
|
| 1099 |
+
|
| 1100 |
+
|
| 1101 |
+
modifier notVoted() {
|
| 1102 |
+
uint256 length = currentProposal.yay.length;
|
| 1103 |
+
for(uint i = 0; i < length; i++) {
|
| 1104 |
+
if(currentProposal.yay[i] == msg.sender) {
|
| 1105 |
+
revert("Already voted");
|
| 1106 |
+
}
|
| 1107 |
+
}
|
| 1108 |
+
|
| 1109 |
+
length = currentProposal.nay.length;
|
| 1110 |
+
for(i = 0; i < length; i++) {
|
| 1111 |
+
if(currentProposal.nay[i] == msg.sender) {
|
| 1112 |
+
revert("Already voted");
|
| 1113 |
+
}
|
| 1114 |
+
}
|
| 1115 |
+
_;
|
| 1116 |
+
}
|
| 1117 |
+
|
| 1118 |
+
|
| 1119 |
+
modifier onlyVoters() {
|
| 1120 |
+
bool found = false;
|
| 1121 |
+
uint256 length = voters.length;
|
| 1122 |
+
for(uint i = 0; i < length; i++) {
|
| 1123 |
+
if(voters[i] == msg.sender) {
|
| 1124 |
+
found = true;
|
| 1125 |
+
break;
|
| 1126 |
+
}
|
| 1127 |
+
}
|
| 1128 |
+
if(!found) {
|
| 1129 |
+
revert("not a voter");
|
| 1130 |
+
}
|
| 1131 |
+
_;
|
| 1132 |
+
}
|
| 1133 |
+
}
|
smart_contract_dataset/block number dependency/216.sol
ADDED
|
@@ -0,0 +1,1133 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
pragma solidity ^0.4.24;
|
| 2 |
+
|
| 3 |
+
|
| 4 |
+
|
| 5 |
+
|
| 6 |
+
contract Ownable {
|
| 7 |
+
address public owner;
|
| 8 |
+
|
| 9 |
+
|
| 10 |
+
event OwnershipRenounced(address indexed previousOwner);
|
| 11 |
+
event OwnershipTransferred(
|
| 12 |
+
address indexed previousOwner,
|
| 13 |
+
address indexed newOwner
|
| 14 |
+
);
|
| 15 |
+
|
| 16 |
+
|
| 17 |
+
|
| 18 |
+
constructor() public {
|
| 19 |
+
owner = msg.sender;
|
| 20 |
+
}
|
| 21 |
+
|
| 22 |
+
|
| 23 |
+
modifier onlyOwner() {
|
| 24 |
+
require(msg.sender == owner);
|
| 25 |
+
_;
|
| 26 |
+
}
|
| 27 |
+
|
| 28 |
+
|
| 29 |
+
function transferOwnership(address newOwner) public onlyOwner {
|
| 30 |
+
require(newOwner != address(0));
|
| 31 |
+
emit OwnershipTransferred(owner, newOwner);
|
| 32 |
+
owner = newOwner;
|
| 33 |
+
}
|
| 34 |
+
|
| 35 |
+
|
| 36 |
+
function renounceOwnership() public onlyOwner {
|
| 37 |
+
emit OwnershipRenounced(owner);
|
| 38 |
+
owner = address(0);
|
| 39 |
+
}
|
| 40 |
+
}
|
| 41 |
+
|
| 42 |
+
|
| 43 |
+
|
| 44 |
+
|
| 45 |
+
contract Pausable is Ownable {
|
| 46 |
+
event Pause();
|
| 47 |
+
event Unpause();
|
| 48 |
+
|
| 49 |
+
bool public paused = false;
|
| 50 |
+
|
| 51 |
+
|
| 52 |
+
|
| 53 |
+
modifier whenNotPaused() {
|
| 54 |
+
require(!paused);
|
| 55 |
+
_;
|
| 56 |
+
}
|
| 57 |
+
|
| 58 |
+
|
| 59 |
+
modifier whenPaused() {
|
| 60 |
+
require(paused);
|
| 61 |
+
_;
|
| 62 |
+
}
|
| 63 |
+
|
| 64 |
+
|
| 65 |
+
function pause() onlyOwner whenNotPaused public {
|
| 66 |
+
paused = true;
|
| 67 |
+
emit Pause();
|
| 68 |
+
}
|
| 69 |
+
|
| 70 |
+
|
| 71 |
+
function unpause() onlyOwner whenPaused public {
|
| 72 |
+
paused = false;
|
| 73 |
+
emit Unpause();
|
| 74 |
+
}
|
| 75 |
+
}
|
| 76 |
+
|
| 77 |
+
|
| 78 |
+
|
| 79 |
+
|
| 80 |
+
library SafeMath {
|
| 81 |
+
|
| 82 |
+
|
| 83 |
+
function mul(uint256 a, uint256 b) internal pure returns (uint256 c) {
|
| 84 |
+
if (a == 0) {
|
| 85 |
+
return 0;
|
| 86 |
+
}
|
| 87 |
+
c = a * b;
|
| 88 |
+
assert(c / a == b);
|
| 89 |
+
return c;
|
| 90 |
+
}
|
| 91 |
+
|
| 92 |
+
|
| 93 |
+
function div(uint256 a, uint256 b) internal pure returns (uint256) {
|
| 94 |
+
|
| 95 |
+
|
| 96 |
+
|
| 97 |
+
return a / b;
|
| 98 |
+
}
|
| 99 |
+
|
| 100 |
+
|
| 101 |
+
function sub(uint256 a, uint256 b) internal pure returns (uint256) {
|
| 102 |
+
assert(b <= a);
|
| 103 |
+
return a - b;
|
| 104 |
+
}
|
| 105 |
+
|
| 106 |
+
|
| 107 |
+
function add(uint256 a, uint256 b) internal pure returns (uint256 c) {
|
| 108 |
+
c = a + b;
|
| 109 |
+
assert(c >= a);
|
| 110 |
+
return c;
|
| 111 |
+
}
|
| 112 |
+
}
|
| 113 |
+
|
| 114 |
+
|
| 115 |
+
|
| 116 |
+
|
| 117 |
+
contract ERC721Basic {
|
| 118 |
+
function balanceOf(address _owner) public view returns (uint256 _balance);
|
| 119 |
+
function ownerOf(uint256 _tokenId) public view returns (address _owner);
|
| 120 |
+
function exists(uint256 _tokenId) public view returns (bool _exists);
|
| 121 |
+
|
| 122 |
+
function approve(address _to, uint256 _tokenId) public;
|
| 123 |
+
function getApproved(uint256 _tokenId) public view returns (address _operator);
|
| 124 |
+
|
| 125 |
+
function transferFrom(address _from, address _to, uint256 _tokenId) public;
|
| 126 |
+
}
|
| 127 |
+
|
| 128 |
+
|
| 129 |
+
contract HorseyExchange is Pausable {
|
| 130 |
+
|
| 131 |
+
using SafeMath for uint256;
|
| 132 |
+
|
| 133 |
+
event HorseyDeposit(uint256 tokenId, uint256 price);
|
| 134 |
+
event SaleCanceled(uint256 tokenId);
|
| 135 |
+
event HorseyPurchased(uint256 tokenId, address newOwner, uint256 totalToPay);
|
| 136 |
+
|
| 137 |
+
|
| 138 |
+
uint256 public marketMakerFee = 3;
|
| 139 |
+
|
| 140 |
+
|
| 141 |
+
uint256 collectedFees = 0;
|
| 142 |
+
|
| 143 |
+
|
| 144 |
+
ERC721Basic public token;
|
| 145 |
+
|
| 146 |
+
|
| 147 |
+
struct SaleData {
|
| 148 |
+
uint256 price;
|
| 149 |
+
address owner;
|
| 150 |
+
}
|
| 151 |
+
|
| 152 |
+
|
| 153 |
+
mapping (uint256 => SaleData) market;
|
| 154 |
+
|
| 155 |
+
|
| 156 |
+
mapping (address => uint256[]) userBarn;
|
| 157 |
+
|
| 158 |
+
|
| 159 |
+
constructor() Pausable() public {
|
| 160 |
+
}
|
| 161 |
+
|
| 162 |
+
|
| 163 |
+
function setStables(address _token) external
|
| 164 |
+
onlyOwner()
|
| 165 |
+
{
|
| 166 |
+
require(address(_token) != 0,"Address of token is zero");
|
| 167 |
+
token = ERC721Basic(_token);
|
| 168 |
+
}
|
| 169 |
+
|
| 170 |
+
|
| 171 |
+
function setMarketFees(uint256 fees) external
|
| 172 |
+
onlyOwner()
|
| 173 |
+
{
|
| 174 |
+
marketMakerFee = fees;
|
| 175 |
+
}
|
| 176 |
+
|
| 177 |
+
|
| 178 |
+
function getTokensOnSale(address user) external view returns(uint256[]) {
|
| 179 |
+
return userBarn[user];
|
| 180 |
+
}
|
| 181 |
+
|
| 182 |
+
|
| 183 |
+
function getTokenPrice(uint256 tokenId) public view
|
| 184 |
+
isOnMarket(tokenId) returns (uint256) {
|
| 185 |
+
return market[tokenId].price + (market[tokenId].price / 100 * marketMakerFee);
|
| 186 |
+
}
|
| 187 |
+
|
| 188 |
+
|
| 189 |
+
function depositToExchange(uint256 tokenId, uint256 price) external
|
| 190 |
+
whenNotPaused()
|
| 191 |
+
isTokenOwner(tokenId)
|
| 192 |
+
nonZeroPrice(price)
|
| 193 |
+
tokenAvailable() {
|
| 194 |
+
require(token.getApproved(tokenId) == address(this),"Exchange is not allowed to transfer");
|
| 195 |
+
|
| 196 |
+
token.transferFrom(msg.sender, address(this), tokenId);
|
| 197 |
+
|
| 198 |
+
|
| 199 |
+
market[tokenId] = SaleData(price,msg.sender);
|
| 200 |
+
|
| 201 |
+
|
| 202 |
+
userBarn[msg.sender].push(tokenId);
|
| 203 |
+
|
| 204 |
+
emit HorseyDeposit(tokenId, price);
|
| 205 |
+
}
|
| 206 |
+
|
| 207 |
+
|
| 208 |
+
function cancelSale(uint256 tokenId) external
|
| 209 |
+
whenNotPaused()
|
| 210 |
+
originalOwnerOf(tokenId)
|
| 211 |
+
tokenAvailable() returns (bool) {
|
| 212 |
+
|
| 213 |
+
token.transferFrom(address(this),msg.sender,tokenId);
|
| 214 |
+
|
| 215 |
+
|
| 216 |
+
delete market[tokenId];
|
| 217 |
+
|
| 218 |
+
|
| 219 |
+
_removeTokenFromBarn(tokenId, msg.sender);
|
| 220 |
+
|
| 221 |
+
emit SaleCanceled(tokenId);
|
| 222 |
+
|
| 223 |
+
|
| 224 |
+
|
| 225 |
+
return userBarn[msg.sender].length > 0;
|
| 226 |
+
}
|
| 227 |
+
|
| 228 |
+
|
| 229 |
+
function purchaseToken(uint256 tokenId) external payable
|
| 230 |
+
whenNotPaused()
|
| 231 |
+
isOnMarket(tokenId)
|
| 232 |
+
tokenAvailable()
|
| 233 |
+
notOriginalOwnerOf(tokenId)
|
| 234 |
+
{
|
| 235 |
+
|
| 236 |
+
uint256 totalToPay = getTokenPrice(tokenId);
|
| 237 |
+
require(msg.value >= totalToPay, "Not paying enough");
|
| 238 |
+
|
| 239 |
+
|
| 240 |
+
SaleData memory sale = market[tokenId];
|
| 241 |
+
|
| 242 |
+
|
| 243 |
+
collectedFees += totalToPay - sale.price;
|
| 244 |
+
|
| 245 |
+
|
| 246 |
+
sale.owner.transfer(sale.price);
|
| 247 |
+
|
| 248 |
+
|
| 249 |
+
_removeTokenFromBarn(tokenId, sale.owner);
|
| 250 |
+
|
| 251 |
+
|
| 252 |
+
delete market[tokenId];
|
| 253 |
+
|
| 254 |
+
|
| 255 |
+
|
| 256 |
+
token.transferFrom(address(this), msg.sender, tokenId);
|
| 257 |
+
|
| 258 |
+
|
| 259 |
+
if(msg.value > totalToPay)
|
| 260 |
+
{
|
| 261 |
+
msg.sender.transfer(msg.value.sub(totalToPay));
|
| 262 |
+
}
|
| 263 |
+
|
| 264 |
+
emit HorseyPurchased(tokenId, msg.sender, totalToPay);
|
| 265 |
+
}
|
| 266 |
+
|
| 267 |
+
|
| 268 |
+
function withdraw() external
|
| 269 |
+
onlyOwner()
|
| 270 |
+
{
|
| 271 |
+
assert(collectedFees <= address(this).balance);
|
| 272 |
+
owner.transfer(collectedFees);
|
| 273 |
+
collectedFees = 0;
|
| 274 |
+
}
|
| 275 |
+
|
| 276 |
+
|
| 277 |
+
function _removeTokenFromBarn(uint tokenId, address barnAddress) internal {
|
| 278 |
+
uint256[] storage barnArray = userBarn[barnAddress];
|
| 279 |
+
require(barnArray.length > 0,"No tokens to remove");
|
| 280 |
+
int index = _indexOf(tokenId, barnArray);
|
| 281 |
+
require(index >= 0, "Token not found in barn");
|
| 282 |
+
|
| 283 |
+
|
| 284 |
+
for (uint256 i = uint256(index); i<barnArray.length-1; i++){
|
| 285 |
+
barnArray[i] = barnArray[i+1];
|
| 286 |
+
}
|
| 287 |
+
|
| 288 |
+
|
| 289 |
+
|
| 290 |
+
barnArray.length--;
|
| 291 |
+
}
|
| 292 |
+
|
| 293 |
+
|
| 294 |
+
function _indexOf(uint item, uint256[] memory array) internal pure returns (int256){
|
| 295 |
+
|
| 296 |
+
|
| 297 |
+
for(uint256 i = 0; i < array.length; i++){
|
| 298 |
+
if(array[i] == item){
|
| 299 |
+
return int256(i);
|
| 300 |
+
}
|
| 301 |
+
}
|
| 302 |
+
|
| 303 |
+
|
| 304 |
+
return -1;
|
| 305 |
+
}
|
| 306 |
+
|
| 307 |
+
|
| 308 |
+
modifier isOnMarket(uint256 tokenId) {
|
| 309 |
+
require(token.ownerOf(tokenId) == address(this),"Token not on market");
|
| 310 |
+
_;
|
| 311 |
+
}
|
| 312 |
+
|
| 313 |
+
|
| 314 |
+
modifier isTokenOwner(uint256 tokenId) {
|
| 315 |
+
require(token.ownerOf(tokenId) == msg.sender,"Not tokens owner");
|
| 316 |
+
_;
|
| 317 |
+
}
|
| 318 |
+
|
| 319 |
+
|
| 320 |
+
modifier originalOwnerOf(uint256 tokenId) {
|
| 321 |
+
require(market[tokenId].owner == msg.sender,"Not the original owner of");
|
| 322 |
+
_;
|
| 323 |
+
}
|
| 324 |
+
|
| 325 |
+
|
| 326 |
+
modifier notOriginalOwnerOf(uint256 tokenId) {
|
| 327 |
+
require(market[tokenId].owner != msg.sender,"Is the original owner");
|
| 328 |
+
_;
|
| 329 |
+
}
|
| 330 |
+
|
| 331 |
+
|
| 332 |
+
modifier nonZeroPrice(uint256 price){
|
| 333 |
+
require(price > 0,"Price is zero");
|
| 334 |
+
_;
|
| 335 |
+
}
|
| 336 |
+
|
| 337 |
+
|
| 338 |
+
modifier tokenAvailable(){
|
| 339 |
+
require(address(token) != 0,"Token address not set");
|
| 340 |
+
_;
|
| 341 |
+
}
|
| 342 |
+
}
|
| 343 |
+
|
| 344 |
+
|
| 345 |
+
|
| 346 |
+
|
| 347 |
+
contract EthorseRace {
|
| 348 |
+
|
| 349 |
+
|
| 350 |
+
struct chronus_info {
|
| 351 |
+
bool betting_open;
|
| 352 |
+
bool race_start;
|
| 353 |
+
bool race_end;
|
| 354 |
+
bool voided_bet;
|
| 355 |
+
uint32 starting_time;
|
| 356 |
+
uint32 betting_duration;
|
| 357 |
+
uint32 race_duration;
|
| 358 |
+
uint32 voided_timestamp;
|
| 359 |
+
}
|
| 360 |
+
|
| 361 |
+
address public owner;
|
| 362 |
+
|
| 363 |
+
|
| 364 |
+
chronus_info public chronus;
|
| 365 |
+
|
| 366 |
+
|
| 367 |
+
mapping (bytes32 => bool) public winner_horse;
|
| 368 |
+
|
| 369 |
+
|
| 370 |
+
function getCoinIndex(bytes32 index, address candidate) external constant returns (uint, uint, uint, bool, uint);
|
| 371 |
+
}
|
| 372 |
+
|
| 373 |
+
|
| 374 |
+
contract EthorseHelpers {
|
| 375 |
+
|
| 376 |
+
|
| 377 |
+
bytes32[] public all_horses = [bytes32("BTC"),bytes32("ETH"),bytes32("LTC")];
|
| 378 |
+
mapping(address => bool) public legitRaces;
|
| 379 |
+
bool onlyLegit = false;
|
| 380 |
+
|
| 381 |
+
|
| 382 |
+
function _addHorse(bytes32 newHorse) internal {
|
| 383 |
+
all_horses.push(newHorse);
|
| 384 |
+
}
|
| 385 |
+
|
| 386 |
+
function _addLegitRace(address newRace) internal
|
| 387 |
+
{
|
| 388 |
+
legitRaces[newRace] = true;
|
| 389 |
+
if(!onlyLegit)
|
| 390 |
+
onlyLegit = true;
|
| 391 |
+
}
|
| 392 |
+
|
| 393 |
+
function getall_horsesCount() public view returns(uint) {
|
| 394 |
+
return all_horses.length;
|
| 395 |
+
}
|
| 396 |
+
|
| 397 |
+
|
| 398 |
+
function _isWinnerOf(address raceAddress, address eth_address) internal view returns (bool,bytes32)
|
| 399 |
+
{
|
| 400 |
+
|
| 401 |
+
EthorseRace race = EthorseRace(raceAddress);
|
| 402 |
+
|
| 403 |
+
|
| 404 |
+
if(onlyLegit)
|
| 405 |
+
require(legitRaces[raceAddress],"not legit race");
|
| 406 |
+
|
| 407 |
+
bool voided_bet;
|
| 408 |
+
bool race_end;
|
| 409 |
+
(,,race_end,voided_bet,,,,) = race.chronus();
|
| 410 |
+
|
| 411 |
+
|
| 412 |
+
if(voided_bet || !race_end)
|
| 413 |
+
return (false,bytes32(0));
|
| 414 |
+
|
| 415 |
+
|
| 416 |
+
bytes32 horse;
|
| 417 |
+
bool found = false;
|
| 418 |
+
uint256 arrayLength = all_horses.length;
|
| 419 |
+
|
| 420 |
+
|
| 421 |
+
for(uint256 i = 0; i < arrayLength; i++)
|
| 422 |
+
{
|
| 423 |
+
if(race.winner_horse(all_horses[i])) {
|
| 424 |
+
horse = all_horses[i];
|
| 425 |
+
found = true;
|
| 426 |
+
break;
|
| 427 |
+
}
|
| 428 |
+
}
|
| 429 |
+
|
| 430 |
+
if(!found)
|
| 431 |
+
return (false,bytes32(0));
|
| 432 |
+
|
| 433 |
+
|
| 434 |
+
uint256 bet_amount = 0;
|
| 435 |
+
if(eth_address != address(0)) {
|
| 436 |
+
(,,,, bet_amount) = race.getCoinIndex(horse, eth_address);
|
| 437 |
+
}
|
| 438 |
+
|
| 439 |
+
|
| 440 |
+
return (bet_amount > 0, horse);
|
| 441 |
+
}
|
| 442 |
+
}
|
| 443 |
+
|
| 444 |
+
|
| 445 |
+
|
| 446 |
+
contract RoyalStablesInterface {
|
| 447 |
+
|
| 448 |
+
struct Horsey {
|
| 449 |
+
address race;
|
| 450 |
+
bytes32 dna;
|
| 451 |
+
uint8 feedingCounter;
|
| 452 |
+
uint8 tier;
|
| 453 |
+
}
|
| 454 |
+
|
| 455 |
+
mapping(uint256 => Horsey) public horseys;
|
| 456 |
+
mapping(address => uint32) public carrot_credits;
|
| 457 |
+
mapping(uint256 => string) public names;
|
| 458 |
+
address public master;
|
| 459 |
+
|
| 460 |
+
function getOwnedTokens(address eth_address) public view returns (uint256[]);
|
| 461 |
+
function storeName(uint256 tokenId, string newName) public;
|
| 462 |
+
function storeCarrotsCredit(address client, uint32 amount) public;
|
| 463 |
+
function storeHorsey(address client, uint256 tokenId, address race, bytes32 dna, uint8 feedingCounter, uint8 tier) public;
|
| 464 |
+
function modifyHorsey(uint256 tokenId, address race, bytes32 dna, uint8 feedingCounter, uint8 tier) public;
|
| 465 |
+
function modifyHorseyDna(uint256 tokenId, bytes32 dna) public;
|
| 466 |
+
function modifyHorseyFeedingCounter(uint256 tokenId, uint8 feedingCounter) public;
|
| 467 |
+
function modifyHorseyTier(uint256 tokenId, uint8 tier) public;
|
| 468 |
+
function unstoreHorsey(uint256 tokenId) public;
|
| 469 |
+
function ownerOf(uint256 tokenId) public returns (address);
|
| 470 |
+
}
|
| 471 |
+
|
| 472 |
+
|
| 473 |
+
contract HorseyToken is EthorseHelpers,Pausable {
|
| 474 |
+
using SafeMath for uint256;
|
| 475 |
+
|
| 476 |
+
|
| 477 |
+
event Claimed(address raceAddress, address eth_address, uint256 tokenId);
|
| 478 |
+
|
| 479 |
+
|
| 480 |
+
event Feeding(uint256 tokenId);
|
| 481 |
+
|
| 482 |
+
|
| 483 |
+
event ReceivedCarrot(uint256 tokenId, bytes32 newDna);
|
| 484 |
+
|
| 485 |
+
|
| 486 |
+
event FeedingFailed(uint256 tokenId);
|
| 487 |
+
|
| 488 |
+
|
| 489 |
+
event HorseyRenamed(uint256 tokenId, string newName);
|
| 490 |
+
|
| 491 |
+
|
| 492 |
+
event HorseyFreed(uint256 tokenId);
|
| 493 |
+
|
| 494 |
+
|
| 495 |
+
RoyalStablesInterface public stables;
|
| 496 |
+
|
| 497 |
+
|
| 498 |
+
uint8 public carrotsMultiplier = 1;
|
| 499 |
+
|
| 500 |
+
|
| 501 |
+
uint8 public rarityMultiplier = 1;
|
| 502 |
+
|
| 503 |
+
|
| 504 |
+
uint256 public claimingFee = 0.000 ether;
|
| 505 |
+
|
| 506 |
+
|
| 507 |
+
struct FeedingData {
|
| 508 |
+
uint256 blockNumber;
|
| 509 |
+
uint256 horsey;
|
| 510 |
+
}
|
| 511 |
+
|
| 512 |
+
|
| 513 |
+
mapping(address => FeedingData) public pendingFeedings;
|
| 514 |
+
|
| 515 |
+
|
| 516 |
+
uint256 public renamingCostsPerChar = 0.001 ether;
|
| 517 |
+
|
| 518 |
+
|
| 519 |
+
constructor(address stablesAddress)
|
| 520 |
+
EthorseHelpers()
|
| 521 |
+
Pausable() public {
|
| 522 |
+
stables = RoyalStablesInterface(stablesAddress);
|
| 523 |
+
}
|
| 524 |
+
|
| 525 |
+
|
| 526 |
+
function setRarityMultiplier(uint8 newRarityMultiplier) external
|
| 527 |
+
onlyOwner() {
|
| 528 |
+
rarityMultiplier = newRarityMultiplier;
|
| 529 |
+
}
|
| 530 |
+
|
| 531 |
+
|
| 532 |
+
function setCarrotsMultiplier(uint8 newCarrotsMultiplier) external
|
| 533 |
+
onlyOwner() {
|
| 534 |
+
carrotsMultiplier = newCarrotsMultiplier;
|
| 535 |
+
}
|
| 536 |
+
|
| 537 |
+
|
| 538 |
+
function setRenamingCosts(uint256 newRenamingCost) external
|
| 539 |
+
onlyOwner() {
|
| 540 |
+
renamingCostsPerChar = newRenamingCost;
|
| 541 |
+
}
|
| 542 |
+
|
| 543 |
+
|
| 544 |
+
function setClaimingCosts(uint256 newClaimingFee) external
|
| 545 |
+
onlyOwner() {
|
| 546 |
+
claimingFee = newClaimingFee;
|
| 547 |
+
}
|
| 548 |
+
|
| 549 |
+
|
| 550 |
+
function addLegitRaceAddress(address newAddress) external
|
| 551 |
+
onlyOwner() {
|
| 552 |
+
_addLegitRace(newAddress);
|
| 553 |
+
}
|
| 554 |
+
|
| 555 |
+
|
| 556 |
+
function withdraw() external
|
| 557 |
+
onlyOwner() {
|
| 558 |
+
owner.transfer(address(this).balance);
|
| 559 |
+
}
|
| 560 |
+
|
| 561 |
+
|
| 562 |
+
|
| 563 |
+
function addHorseIndex(bytes32 newHorse) external
|
| 564 |
+
onlyOwner() {
|
| 565 |
+
_addHorse(newHorse);
|
| 566 |
+
}
|
| 567 |
+
|
| 568 |
+
|
| 569 |
+
function getOwnedTokens(address eth_address) public view returns (uint256[]) {
|
| 570 |
+
return stables.getOwnedTokens(eth_address);
|
| 571 |
+
}
|
| 572 |
+
|
| 573 |
+
|
| 574 |
+
function can_claim(address raceAddress, address eth_address) public view returns (bool) {
|
| 575 |
+
bool res;
|
| 576 |
+
(res,) = _isWinnerOf(raceAddress, eth_address);
|
| 577 |
+
return res;
|
| 578 |
+
}
|
| 579 |
+
|
| 580 |
+
|
| 581 |
+
function claim(address raceAddress) external payable
|
| 582 |
+
costs(claimingFee)
|
| 583 |
+
whenNotPaused()
|
| 584 |
+
{
|
| 585 |
+
|
| 586 |
+
bytes32 winner;
|
| 587 |
+
bool res;
|
| 588 |
+
(res,winner) = _isWinnerOf(raceAddress, address(0));
|
| 589 |
+
require(winner != bytes32(0),"Winner is zero");
|
| 590 |
+
require(res,"can_claim return false");
|
| 591 |
+
|
| 592 |
+
uint256 id = _generate_special_horsey(raceAddress, msg.sender, winner);
|
| 593 |
+
emit Claimed(raceAddress, msg.sender, id);
|
| 594 |
+
}
|
| 595 |
+
|
| 596 |
+
|
| 597 |
+
function renameHorsey(uint256 tokenId, string newName) external
|
| 598 |
+
whenNotPaused()
|
| 599 |
+
onlyOwnerOf(tokenId)
|
| 600 |
+
costs(renamingCostsPerChar * bytes(newName).length)
|
| 601 |
+
payable {
|
| 602 |
+
uint256 renamingFee = renamingCostsPerChar * bytes(newName).length;
|
| 603 |
+
|
| 604 |
+
if(msg.value > renamingFee)
|
| 605 |
+
{
|
| 606 |
+
msg.sender.transfer(msg.value.sub(renamingFee));
|
| 607 |
+
}
|
| 608 |
+
|
| 609 |
+
stables.storeName(tokenId,newName);
|
| 610 |
+
emit HorseyRenamed(tokenId,newName);
|
| 611 |
+
}
|
| 612 |
+
|
| 613 |
+
|
| 614 |
+
function freeForCarrots(uint256 tokenId) external
|
| 615 |
+
whenNotPaused()
|
| 616 |
+
onlyOwnerOf(tokenId) {
|
| 617 |
+
require(pendingFeedings[msg.sender].horsey != tokenId,"");
|
| 618 |
+
|
| 619 |
+
uint8 feedingCounter;
|
| 620 |
+
(,,feedingCounter,) = stables.horseys(tokenId);
|
| 621 |
+
stables.storeCarrotsCredit(msg.sender,stables.carrot_credits(msg.sender) + uint32(feedingCounter * carrotsMultiplier));
|
| 622 |
+
stables.unstoreHorsey(tokenId);
|
| 623 |
+
emit HorseyFreed(tokenId);
|
| 624 |
+
}
|
| 625 |
+
|
| 626 |
+
|
| 627 |
+
function getCarrotCredits() external view returns (uint32) {
|
| 628 |
+
return stables.carrot_credits(msg.sender);
|
| 629 |
+
}
|
| 630 |
+
|
| 631 |
+
|
| 632 |
+
function getHorsey(uint256 tokenId) public view returns (address, bytes32, uint8, string) {
|
| 633 |
+
RoyalStablesInterface.Horsey memory temp;
|
| 634 |
+
(temp.race,temp.dna,temp.feedingCounter,temp.tier) = stables.horseys(tokenId);
|
| 635 |
+
return (temp.race,temp.dna,temp.feedingCounter,stables.names(tokenId));
|
| 636 |
+
}
|
| 637 |
+
|
| 638 |
+
|
| 639 |
+
function feed(uint256 tokenId) external
|
| 640 |
+
whenNotPaused()
|
| 641 |
+
onlyOwnerOf(tokenId)
|
| 642 |
+
carrotsMeetLevel(tokenId)
|
| 643 |
+
noFeedingInProgress()
|
| 644 |
+
{
|
| 645 |
+
pendingFeedings[msg.sender] = FeedingData(block.number,tokenId);
|
| 646 |
+
uint8 feedingCounter;
|
| 647 |
+
(,,feedingCounter,) = stables.horseys(tokenId);
|
| 648 |
+
stables.storeCarrotsCredit(msg.sender,stables.carrot_credits(msg.sender) - uint32(feedingCounter));
|
| 649 |
+
emit Feeding(tokenId);
|
| 650 |
+
}
|
| 651 |
+
|
| 652 |
+
|
| 653 |
+
function stopFeeding() external
|
| 654 |
+
feedingInProgress() returns (bool) {
|
| 655 |
+
uint256 blockNumber = pendingFeedings[msg.sender].blockNumber;
|
| 656 |
+
uint256 tokenId = pendingFeedings[msg.sender].horsey;
|
| 657 |
+
|
| 658 |
+
require(block.number - blockNumber >= 1,"feeding and stop feeding are in same block");
|
| 659 |
+
|
| 660 |
+
delete pendingFeedings[msg.sender];
|
| 661 |
+
|
| 662 |
+
|
| 663 |
+
|
| 664 |
+
if(block.number - blockNumber > 255) {
|
| 665 |
+
|
| 666 |
+
|
| 667 |
+
emit FeedingFailed(tokenId);
|
| 668 |
+
return false;
|
| 669 |
+
}
|
| 670 |
+
|
| 671 |
+
|
| 672 |
+
if(stables.ownerOf(tokenId) != msg.sender) {
|
| 673 |
+
|
| 674 |
+
|
| 675 |
+
emit FeedingFailed(tokenId);
|
| 676 |
+
return false;
|
| 677 |
+
}
|
| 678 |
+
|
| 679 |
+
|
| 680 |
+
_feed(tokenId, blockhash(blockNumber));
|
| 681 |
+
bytes32 dna;
|
| 682 |
+
(,dna,,) = stables.horseys(tokenId);
|
| 683 |
+
emit ReceivedCarrot(tokenId, dna);
|
| 684 |
+
return true;
|
| 685 |
+
}
|
| 686 |
+
|
| 687 |
+
|
| 688 |
+
function() external payable {
|
| 689 |
+
revert("Not accepting donations");
|
| 690 |
+
}
|
| 691 |
+
|
| 692 |
+
|
| 693 |
+
function _feed(uint256 tokenId, bytes32 blockHash) internal {
|
| 694 |
+
|
| 695 |
+
uint8 tier;
|
| 696 |
+
uint8 feedingCounter;
|
| 697 |
+
(,,feedingCounter,tier) = stables.horseys(tokenId);
|
| 698 |
+
uint256 probabilityByRarity = 10 ** (uint256(tier).add(1));
|
| 699 |
+
uint256 randNum = uint256(keccak256(abi.encodePacked(tokenId, blockHash))) % probabilityByRarity;
|
| 700 |
+
|
| 701 |
+
|
| 702 |
+
if(randNum <= (feedingCounter * rarityMultiplier)){
|
| 703 |
+
_increaseRarity(tokenId, blockHash);
|
| 704 |
+
}
|
| 705 |
+
|
| 706 |
+
|
| 707 |
+
|
| 708 |
+
if(feedingCounter < 255) {
|
| 709 |
+
stables.modifyHorseyFeedingCounter(tokenId,feedingCounter+1);
|
| 710 |
+
}
|
| 711 |
+
}
|
| 712 |
+
|
| 713 |
+
|
| 714 |
+
function _makeSpecialId(address race, address sender, bytes32 coinIndex) internal pure returns (uint256) {
|
| 715 |
+
return uint256(keccak256(abi.encodePacked(race, sender, coinIndex)));
|
| 716 |
+
}
|
| 717 |
+
|
| 718 |
+
|
| 719 |
+
function _generate_special_horsey(address race, address eth_address, bytes32 coinIndex) internal returns (uint256) {
|
| 720 |
+
uint256 id = _makeSpecialId(race, eth_address, coinIndex);
|
| 721 |
+
|
| 722 |
+
bytes32 dna = _shiftRight(keccak256(abi.encodePacked(race, coinIndex)),16);
|
| 723 |
+
|
| 724 |
+
stables.storeHorsey(eth_address,id,race,dna,1,0);
|
| 725 |
+
return id;
|
| 726 |
+
}
|
| 727 |
+
|
| 728 |
+
|
| 729 |
+
function _increaseRarity(uint256 tokenId, bytes32 blockHash) private {
|
| 730 |
+
uint8 tier;
|
| 731 |
+
bytes32 dna;
|
| 732 |
+
(,dna,,tier) = stables.horseys(tokenId);
|
| 733 |
+
if(tier < 255)
|
| 734 |
+
stables.modifyHorseyTier(tokenId,tier+1);
|
| 735 |
+
uint256 random = uint256(keccak256(abi.encodePacked(tokenId, blockHash)));
|
| 736 |
+
|
| 737 |
+
bytes32 rarityMask = _shiftLeft(bytes32(1), (random % 16 + 240));
|
| 738 |
+
bytes32 newdna = dna | rarityMask;
|
| 739 |
+
stables.modifyHorseyDna(tokenId,newdna);
|
| 740 |
+
}
|
| 741 |
+
|
| 742 |
+
|
| 743 |
+
function _shiftLeft(bytes32 data, uint n) internal pure returns (bytes32) {
|
| 744 |
+
return bytes32(uint256(data)*(2 ** n));
|
| 745 |
+
}
|
| 746 |
+
|
| 747 |
+
|
| 748 |
+
function _shiftRight(bytes32 data, uint n) internal pure returns (bytes32) {
|
| 749 |
+
return bytes32(uint256(data)/(2 ** n));
|
| 750 |
+
}
|
| 751 |
+
|
| 752 |
+
|
| 753 |
+
modifier carrotsMeetLevel(uint256 tokenId){
|
| 754 |
+
uint256 feedingCounter;
|
| 755 |
+
(,,feedingCounter,) = stables.horseys(tokenId);
|
| 756 |
+
require(feedingCounter <= stables.carrot_credits(msg.sender),"Not enough carrots");
|
| 757 |
+
_;
|
| 758 |
+
}
|
| 759 |
+
|
| 760 |
+
|
| 761 |
+
modifier costs(uint256 amount) {
|
| 762 |
+
require(msg.value >= amount,"Not enough funds");
|
| 763 |
+
_;
|
| 764 |
+
}
|
| 765 |
+
|
| 766 |
+
|
| 767 |
+
modifier validAddress(address addr) {
|
| 768 |
+
require(addr != address(0),"Address is zero");
|
| 769 |
+
_;
|
| 770 |
+
}
|
| 771 |
+
|
| 772 |
+
|
| 773 |
+
modifier noFeedingInProgress() {
|
| 774 |
+
|
| 775 |
+
require(pendingFeedings[msg.sender].blockNumber == 0,"Already feeding");
|
| 776 |
+
_;
|
| 777 |
+
}
|
| 778 |
+
|
| 779 |
+
|
| 780 |
+
modifier feedingInProgress() {
|
| 781 |
+
|
| 782 |
+
require(pendingFeedings[msg.sender].blockNumber != 0,"No pending feeding");
|
| 783 |
+
_;
|
| 784 |
+
}
|
| 785 |
+
|
| 786 |
+
|
| 787 |
+
modifier onlyOwnerOf(uint256 tokenId) {
|
| 788 |
+
require(stables.ownerOf(tokenId) == msg.sender, "Caller is not owner of this token");
|
| 789 |
+
_;
|
| 790 |
+
}
|
| 791 |
+
}
|
| 792 |
+
|
| 793 |
+
|
| 794 |
+
|
| 795 |
+
|
| 796 |
+
|
| 797 |
+
contract HorseyPilot {
|
| 798 |
+
|
| 799 |
+
|
| 800 |
+
event NewProposal(uint8 methodId, uint parameter, address proposer);
|
| 801 |
+
|
| 802 |
+
|
| 803 |
+
event ProposalPassed(uint8 methodId, uint parameter, address proposer);
|
| 804 |
+
|
| 805 |
+
|
| 806 |
+
|
| 807 |
+
uint8 constant votingThreshold = 2;
|
| 808 |
+
|
| 809 |
+
|
| 810 |
+
|
| 811 |
+
uint256 constant proposalLife = 7 days;
|
| 812 |
+
|
| 813 |
+
|
| 814 |
+
|
| 815 |
+
uint256 constant proposalCooldown = 1 days;
|
| 816 |
+
|
| 817 |
+
|
| 818 |
+
uint256 cooldownStart;
|
| 819 |
+
|
| 820 |
+
|
| 821 |
+
address public jokerAddress;
|
| 822 |
+
address public knightAddress;
|
| 823 |
+
address public paladinAddress;
|
| 824 |
+
|
| 825 |
+
|
| 826 |
+
address[3] public voters;
|
| 827 |
+
|
| 828 |
+
|
| 829 |
+
uint8 constant public knightEquity = 40;
|
| 830 |
+
uint8 constant public paladinEquity = 10;
|
| 831 |
+
|
| 832 |
+
|
| 833 |
+
address public exchangeAddress;
|
| 834 |
+
address public tokenAddress;
|
| 835 |
+
|
| 836 |
+
|
| 837 |
+
mapping(address => uint) internal _cBalance;
|
| 838 |
+
|
| 839 |
+
|
| 840 |
+
struct Proposal{
|
| 841 |
+
address proposer;
|
| 842 |
+
uint256 timestamp;
|
| 843 |
+
uint256 parameter;
|
| 844 |
+
uint8 methodId;
|
| 845 |
+
address[] yay;
|
| 846 |
+
address[] nay;
|
| 847 |
+
}
|
| 848 |
+
|
| 849 |
+
|
| 850 |
+
Proposal public currentProposal;
|
| 851 |
+
|
| 852 |
+
|
| 853 |
+
bool public proposalInProgress = false;
|
| 854 |
+
|
| 855 |
+
|
| 856 |
+
uint256 public toBeDistributed;
|
| 857 |
+
|
| 858 |
+
|
| 859 |
+
bool deployed = false;
|
| 860 |
+
|
| 861 |
+
|
| 862 |
+
constructor(
|
| 863 |
+
address _jokerAddress,
|
| 864 |
+
address _knightAddress,
|
| 865 |
+
address _paladinAddress,
|
| 866 |
+
address[3] _voters
|
| 867 |
+
) public {
|
| 868 |
+
jokerAddress = _jokerAddress;
|
| 869 |
+
knightAddress = _knightAddress;
|
| 870 |
+
paladinAddress = _paladinAddress;
|
| 871 |
+
|
| 872 |
+
for(uint i = 0; i < 3; i++) {
|
| 873 |
+
voters[i] = _voters[i];
|
| 874 |
+
}
|
| 875 |
+
|
| 876 |
+
|
| 877 |
+
cooldownStart = block.timestamp - proposalCooldown;
|
| 878 |
+
}
|
| 879 |
+
|
| 880 |
+
|
| 881 |
+
function deployChildren(address stablesAddress) external {
|
| 882 |
+
require(!deployed,"already deployed");
|
| 883 |
+
|
| 884 |
+
exchangeAddress = new HorseyExchange();
|
| 885 |
+
tokenAddress = new HorseyToken(stablesAddress);
|
| 886 |
+
|
| 887 |
+
|
| 888 |
+
HorseyExchange(exchangeAddress).setStables(stablesAddress);
|
| 889 |
+
|
| 890 |
+
deployed = true;
|
| 891 |
+
}
|
| 892 |
+
|
| 893 |
+
|
| 894 |
+
function transferJokerOwnership(address newJoker) external
|
| 895 |
+
validAddress(newJoker) {
|
| 896 |
+
require(jokerAddress == msg.sender,"Not right role");
|
| 897 |
+
_moveBalance(newJoker);
|
| 898 |
+
jokerAddress = newJoker;
|
| 899 |
+
}
|
| 900 |
+
|
| 901 |
+
|
| 902 |
+
function transferKnightOwnership(address newKnight) external
|
| 903 |
+
validAddress(newKnight) {
|
| 904 |
+
require(knightAddress == msg.sender,"Not right role");
|
| 905 |
+
_moveBalance(newKnight);
|
| 906 |
+
knightAddress = newKnight;
|
| 907 |
+
}
|
| 908 |
+
|
| 909 |
+
|
| 910 |
+
function transferPaladinOwnership(address newPaladin) external
|
| 911 |
+
validAddress(newPaladin) {
|
| 912 |
+
require(paladinAddress == msg.sender,"Not right role");
|
| 913 |
+
_moveBalance(newPaladin);
|
| 914 |
+
paladinAddress = newPaladin;
|
| 915 |
+
}
|
| 916 |
+
|
| 917 |
+
|
| 918 |
+
function withdrawCeo(address destination) external
|
| 919 |
+
onlyCLevelAccess()
|
| 920 |
+
validAddress(destination) {
|
| 921 |
+
|
| 922 |
+
|
| 923 |
+
if(toBeDistributed > 0){
|
| 924 |
+
_updateDistribution();
|
| 925 |
+
}
|
| 926 |
+
|
| 927 |
+
|
| 928 |
+
uint256 balance = _cBalance[msg.sender];
|
| 929 |
+
|
| 930 |
+
|
| 931 |
+
if(balance > 0 && (address(this).balance >= balance)) {
|
| 932 |
+
destination.transfer(balance);
|
| 933 |
+
_cBalance[msg.sender] = 0;
|
| 934 |
+
}
|
| 935 |
+
}
|
| 936 |
+
|
| 937 |
+
|
| 938 |
+
function syncFunds() external {
|
| 939 |
+
uint256 prevBalance = address(this).balance;
|
| 940 |
+
HorseyToken(tokenAddress).withdraw();
|
| 941 |
+
HorseyExchange(exchangeAddress).withdraw();
|
| 942 |
+
uint256 newBalance = address(this).balance;
|
| 943 |
+
|
| 944 |
+
toBeDistributed = toBeDistributed + (newBalance - prevBalance);
|
| 945 |
+
}
|
| 946 |
+
|
| 947 |
+
|
| 948 |
+
function getNobleBalance() external view
|
| 949 |
+
onlyCLevelAccess() returns (uint256) {
|
| 950 |
+
return _cBalance[msg.sender];
|
| 951 |
+
}
|
| 952 |
+
|
| 953 |
+
|
| 954 |
+
function makeProposal( uint8 methodId, uint256 parameter ) external
|
| 955 |
+
onlyCLevelAccess()
|
| 956 |
+
proposalAvailable()
|
| 957 |
+
cooledDown()
|
| 958 |
+
{
|
| 959 |
+
currentProposal.timestamp = block.timestamp;
|
| 960 |
+
currentProposal.parameter = parameter;
|
| 961 |
+
currentProposal.methodId = methodId;
|
| 962 |
+
currentProposal.proposer = msg.sender;
|
| 963 |
+
delete currentProposal.yay;
|
| 964 |
+
delete currentProposal.nay;
|
| 965 |
+
proposalInProgress = true;
|
| 966 |
+
|
| 967 |
+
emit NewProposal(methodId,parameter,msg.sender);
|
| 968 |
+
}
|
| 969 |
+
|
| 970 |
+
|
| 971 |
+
function voteOnProposal(bool voteFor) external
|
| 972 |
+
proposalPending()
|
| 973 |
+
onlyVoters()
|
| 974 |
+
notVoted() {
|
| 975 |
+
|
| 976 |
+
require((block.timestamp - currentProposal.timestamp) <= proposalLife);
|
| 977 |
+
if(voteFor)
|
| 978 |
+
{
|
| 979 |
+
currentProposal.yay.push(msg.sender);
|
| 980 |
+
|
| 981 |
+
if( currentProposal.yay.length >= votingThreshold )
|
| 982 |
+
{
|
| 983 |
+
_doProposal();
|
| 984 |
+
proposalInProgress = false;
|
| 985 |
+
|
| 986 |
+
return;
|
| 987 |
+
}
|
| 988 |
+
|
| 989 |
+
} else {
|
| 990 |
+
currentProposal.nay.push(msg.sender);
|
| 991 |
+
|
| 992 |
+
if( currentProposal.nay.length >= votingThreshold )
|
| 993 |
+
{
|
| 994 |
+
proposalInProgress = false;
|
| 995 |
+
cooldownStart = block.timestamp;
|
| 996 |
+
return;
|
| 997 |
+
}
|
| 998 |
+
}
|
| 999 |
+
}
|
| 1000 |
+
|
| 1001 |
+
|
| 1002 |
+
function _moveBalance(address newAddress) internal
|
| 1003 |
+
validAddress(newAddress) {
|
| 1004 |
+
require(newAddress != msg.sender);
|
| 1005 |
+
_cBalance[newAddress] = _cBalance[msg.sender];
|
| 1006 |
+
_cBalance[msg.sender] = 0;
|
| 1007 |
+
}
|
| 1008 |
+
|
| 1009 |
+
|
| 1010 |
+
function _updateDistribution() internal {
|
| 1011 |
+
require(toBeDistributed != 0,"nothing to distribute");
|
| 1012 |
+
uint256 knightPayday = toBeDistributed / 100 * knightEquity;
|
| 1013 |
+
uint256 paladinPayday = toBeDistributed / 100 * paladinEquity;
|
| 1014 |
+
|
| 1015 |
+
|
| 1016 |
+
uint256 jokerPayday = toBeDistributed - knightPayday - paladinPayday;
|
| 1017 |
+
|
| 1018 |
+
_cBalance[jokerAddress] = _cBalance[jokerAddress] + jokerPayday;
|
| 1019 |
+
_cBalance[knightAddress] = _cBalance[knightAddress] + knightPayday;
|
| 1020 |
+
_cBalance[paladinAddress] = _cBalance[paladinAddress] + paladinPayday;
|
| 1021 |
+
|
| 1022 |
+
toBeDistributed = 0;
|
| 1023 |
+
}
|
| 1024 |
+
|
| 1025 |
+
|
| 1026 |
+
function _doProposal() internal {
|
| 1027 |
+
|
| 1028 |
+
if( currentProposal.methodId == 0 ) HorseyToken(tokenAddress).setRenamingCosts(currentProposal.parameter);
|
| 1029 |
+
|
| 1030 |
+
|
| 1031 |
+
if( currentProposal.methodId == 1 ) HorseyExchange(exchangeAddress).setMarketFees(currentProposal.parameter);
|
| 1032 |
+
|
| 1033 |
+
|
| 1034 |
+
if( currentProposal.methodId == 2 ) HorseyToken(tokenAddress).addLegitRaceAddress(address(currentProposal.parameter));
|
| 1035 |
+
|
| 1036 |
+
|
| 1037 |
+
if( currentProposal.methodId == 3 ) HorseyToken(tokenAddress).addHorseIndex(bytes32(currentProposal.parameter));
|
| 1038 |
+
|
| 1039 |
+
|
| 1040 |
+
if( currentProposal.methodId == 4 ) {
|
| 1041 |
+
if(currentProposal.parameter == 0) {
|
| 1042 |
+
HorseyExchange(exchangeAddress).unpause();
|
| 1043 |
+
HorseyToken(tokenAddress).unpause();
|
| 1044 |
+
} else {
|
| 1045 |
+
HorseyExchange(exchangeAddress).pause();
|
| 1046 |
+
HorseyToken(tokenAddress).pause();
|
| 1047 |
+
}
|
| 1048 |
+
}
|
| 1049 |
+
|
| 1050 |
+
|
| 1051 |
+
if( currentProposal.methodId == 5 ) HorseyToken(tokenAddress).setClaimingCosts(currentProposal.parameter);
|
| 1052 |
+
|
| 1053 |
+
|
| 1054 |
+
if( currentProposal.methodId == 8 ){
|
| 1055 |
+
HorseyToken(tokenAddress).setCarrotsMultiplier(uint8(currentProposal.parameter));
|
| 1056 |
+
}
|
| 1057 |
+
|
| 1058 |
+
|
| 1059 |
+
if( currentProposal.methodId == 9 ){
|
| 1060 |
+
HorseyToken(tokenAddress).setRarityMultiplier(uint8(currentProposal.parameter));
|
| 1061 |
+
}
|
| 1062 |
+
|
| 1063 |
+
emit ProposalPassed(currentProposal.methodId,currentProposal.parameter,currentProposal.proposer);
|
| 1064 |
+
}
|
| 1065 |
+
|
| 1066 |
+
|
| 1067 |
+
modifier validAddress(address addr) {
|
| 1068 |
+
require(addr != address(0),"Address is zero");
|
| 1069 |
+
_;
|
| 1070 |
+
}
|
| 1071 |
+
|
| 1072 |
+
|
| 1073 |
+
modifier onlyCLevelAccess() {
|
| 1074 |
+
require((jokerAddress == msg.sender) || (knightAddress == msg.sender) || (paladinAddress == msg.sender),"not c level");
|
| 1075 |
+
_;
|
| 1076 |
+
}
|
| 1077 |
+
|
| 1078 |
+
|
| 1079 |
+
|
| 1080 |
+
modifier proposalAvailable(){
|
| 1081 |
+
require(((!proposalInProgress) || ((block.timestamp - currentProposal.timestamp) > proposalLife)),"proposal already pending");
|
| 1082 |
+
_;
|
| 1083 |
+
}
|
| 1084 |
+
|
| 1085 |
+
|
| 1086 |
+
|
| 1087 |
+
modifier cooledDown( ){
|
| 1088 |
+
if(msg.sender == currentProposal.proposer && (block.timestamp - cooldownStart < 1 days)){
|
| 1089 |
+
revert("Cool down period not passed yet");
|
| 1090 |
+
}
|
| 1091 |
+
_;
|
| 1092 |
+
}
|
| 1093 |
+
|
| 1094 |
+
|
| 1095 |
+
modifier proposalPending() {
|
| 1096 |
+
require(proposalInProgress,"no proposal pending");
|
| 1097 |
+
_;
|
| 1098 |
+
}
|
| 1099 |
+
|
| 1100 |
+
|
| 1101 |
+
modifier notVoted() {
|
| 1102 |
+
uint256 length = currentProposal.yay.length;
|
| 1103 |
+
for(uint i = 0; i < length; i++) {
|
| 1104 |
+
if(currentProposal.yay[i] == msg.sender) {
|
| 1105 |
+
revert("Already voted");
|
| 1106 |
+
}
|
| 1107 |
+
}
|
| 1108 |
+
|
| 1109 |
+
length = currentProposal.nay.length;
|
| 1110 |
+
for(i = 0; i < length; i++) {
|
| 1111 |
+
if(currentProposal.nay[i] == msg.sender) {
|
| 1112 |
+
revert("Already voted");
|
| 1113 |
+
}
|
| 1114 |
+
}
|
| 1115 |
+
_;
|
| 1116 |
+
}
|
| 1117 |
+
|
| 1118 |
+
|
| 1119 |
+
modifier onlyVoters() {
|
| 1120 |
+
bool found = false;
|
| 1121 |
+
uint256 length = voters.length;
|
| 1122 |
+
for(uint i = 0; i < length; i++) {
|
| 1123 |
+
if(voters[i] == msg.sender) {
|
| 1124 |
+
found = true;
|
| 1125 |
+
break;
|
| 1126 |
+
}
|
| 1127 |
+
}
|
| 1128 |
+
if(!found) {
|
| 1129 |
+
revert("not a voter");
|
| 1130 |
+
}
|
| 1131 |
+
_;
|
| 1132 |
+
}
|
| 1133 |
+
}
|
smart_contract_dataset/block number dependency/217.sol
ADDED
|
@@ -0,0 +1,1133 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
pragma solidity ^0.4.24;
|
| 2 |
+
|
| 3 |
+
|
| 4 |
+
|
| 5 |
+
|
| 6 |
+
contract Ownable {
|
| 7 |
+
address public owner;
|
| 8 |
+
|
| 9 |
+
|
| 10 |
+
event OwnershipRenounced(address indexed previousOwner);
|
| 11 |
+
event OwnershipTransferred(
|
| 12 |
+
address indexed previousOwner,
|
| 13 |
+
address indexed newOwner
|
| 14 |
+
);
|
| 15 |
+
|
| 16 |
+
|
| 17 |
+
|
| 18 |
+
constructor() public {
|
| 19 |
+
owner = msg.sender;
|
| 20 |
+
}
|
| 21 |
+
|
| 22 |
+
|
| 23 |
+
modifier onlyOwner() {
|
| 24 |
+
require(msg.sender == owner);
|
| 25 |
+
_;
|
| 26 |
+
}
|
| 27 |
+
|
| 28 |
+
|
| 29 |
+
function transferOwnership(address newOwner) public onlyOwner {
|
| 30 |
+
require(newOwner != address(0));
|
| 31 |
+
emit OwnershipTransferred(owner, newOwner);
|
| 32 |
+
owner = newOwner;
|
| 33 |
+
}
|
| 34 |
+
|
| 35 |
+
|
| 36 |
+
function renounceOwnership() public onlyOwner {
|
| 37 |
+
emit OwnershipRenounced(owner);
|
| 38 |
+
owner = address(0);
|
| 39 |
+
}
|
| 40 |
+
}
|
| 41 |
+
|
| 42 |
+
|
| 43 |
+
|
| 44 |
+
|
| 45 |
+
contract Pausable is Ownable {
|
| 46 |
+
event Pause();
|
| 47 |
+
event Unpause();
|
| 48 |
+
|
| 49 |
+
bool public paused = false;
|
| 50 |
+
|
| 51 |
+
|
| 52 |
+
|
| 53 |
+
modifier whenNotPaused() {
|
| 54 |
+
require(!paused);
|
| 55 |
+
_;
|
| 56 |
+
}
|
| 57 |
+
|
| 58 |
+
|
| 59 |
+
modifier whenPaused() {
|
| 60 |
+
require(paused);
|
| 61 |
+
_;
|
| 62 |
+
}
|
| 63 |
+
|
| 64 |
+
|
| 65 |
+
function pause() onlyOwner whenNotPaused public {
|
| 66 |
+
paused = true;
|
| 67 |
+
emit Pause();
|
| 68 |
+
}
|
| 69 |
+
|
| 70 |
+
|
| 71 |
+
function unpause() onlyOwner whenPaused public {
|
| 72 |
+
paused = false;
|
| 73 |
+
emit Unpause();
|
| 74 |
+
}
|
| 75 |
+
}
|
| 76 |
+
|
| 77 |
+
|
| 78 |
+
|
| 79 |
+
|
| 80 |
+
library SafeMath {
|
| 81 |
+
|
| 82 |
+
|
| 83 |
+
function mul(uint256 a, uint256 b) internal pure returns (uint256 c) {
|
| 84 |
+
if (a == 0) {
|
| 85 |
+
return 0;
|
| 86 |
+
}
|
| 87 |
+
c = a * b;
|
| 88 |
+
assert(c / a == b);
|
| 89 |
+
return c;
|
| 90 |
+
}
|
| 91 |
+
|
| 92 |
+
|
| 93 |
+
function div(uint256 a, uint256 b) internal pure returns (uint256) {
|
| 94 |
+
|
| 95 |
+
|
| 96 |
+
|
| 97 |
+
return a / b;
|
| 98 |
+
}
|
| 99 |
+
|
| 100 |
+
|
| 101 |
+
function sub(uint256 a, uint256 b) internal pure returns (uint256) {
|
| 102 |
+
assert(b <= a);
|
| 103 |
+
return a - b;
|
| 104 |
+
}
|
| 105 |
+
|
| 106 |
+
|
| 107 |
+
function add(uint256 a, uint256 b) internal pure returns (uint256 c) {
|
| 108 |
+
c = a + b;
|
| 109 |
+
assert(c >= a);
|
| 110 |
+
return c;
|
| 111 |
+
}
|
| 112 |
+
}
|
| 113 |
+
|
| 114 |
+
|
| 115 |
+
|
| 116 |
+
|
| 117 |
+
contract ERC721Basic {
|
| 118 |
+
function balanceOf(address _owner) public view returns (uint256 _balance);
|
| 119 |
+
function ownerOf(uint256 _tokenId) public view returns (address _owner);
|
| 120 |
+
function exists(uint256 _tokenId) public view returns (bool _exists);
|
| 121 |
+
|
| 122 |
+
function approve(address _to, uint256 _tokenId) public;
|
| 123 |
+
function getApproved(uint256 _tokenId) public view returns (address _operator);
|
| 124 |
+
|
| 125 |
+
function transferFrom(address _from, address _to, uint256 _tokenId) public;
|
| 126 |
+
}
|
| 127 |
+
|
| 128 |
+
|
| 129 |
+
contract HorseyExchange is Pausable {
|
| 130 |
+
|
| 131 |
+
using SafeMath for uint256;
|
| 132 |
+
|
| 133 |
+
event HorseyDeposit(uint256 tokenId, uint256 price);
|
| 134 |
+
event SaleCanceled(uint256 tokenId);
|
| 135 |
+
event HorseyPurchased(uint256 tokenId, address newOwner, uint256 totalToPay);
|
| 136 |
+
|
| 137 |
+
|
| 138 |
+
uint256 public marketMakerFee = 3;
|
| 139 |
+
|
| 140 |
+
|
| 141 |
+
uint256 collectedFees = 0;
|
| 142 |
+
|
| 143 |
+
|
| 144 |
+
ERC721Basic public token;
|
| 145 |
+
|
| 146 |
+
|
| 147 |
+
struct SaleData {
|
| 148 |
+
uint256 price;
|
| 149 |
+
address owner;
|
| 150 |
+
}
|
| 151 |
+
|
| 152 |
+
|
| 153 |
+
mapping (uint256 => SaleData) market;
|
| 154 |
+
|
| 155 |
+
|
| 156 |
+
mapping (address => uint256[]) userBarn;
|
| 157 |
+
|
| 158 |
+
|
| 159 |
+
constructor() Pausable() public {
|
| 160 |
+
}
|
| 161 |
+
|
| 162 |
+
|
| 163 |
+
function setStables(address _token) external
|
| 164 |
+
onlyOwner()
|
| 165 |
+
{
|
| 166 |
+
require(address(_token) != 0,"Address of token is zero");
|
| 167 |
+
token = ERC721Basic(_token);
|
| 168 |
+
}
|
| 169 |
+
|
| 170 |
+
|
| 171 |
+
function setMarketFees(uint256 fees) external
|
| 172 |
+
onlyOwner()
|
| 173 |
+
{
|
| 174 |
+
marketMakerFee = fees;
|
| 175 |
+
}
|
| 176 |
+
|
| 177 |
+
|
| 178 |
+
function getTokensOnSale(address user) external view returns(uint256[]) {
|
| 179 |
+
return userBarn[user];
|
| 180 |
+
}
|
| 181 |
+
|
| 182 |
+
|
| 183 |
+
function getTokenPrice(uint256 tokenId) public view
|
| 184 |
+
isOnMarket(tokenId) returns (uint256) {
|
| 185 |
+
return market[tokenId].price + (market[tokenId].price / 100 * marketMakerFee);
|
| 186 |
+
}
|
| 187 |
+
|
| 188 |
+
|
| 189 |
+
function depositToExchange(uint256 tokenId, uint256 price) external
|
| 190 |
+
whenNotPaused()
|
| 191 |
+
isTokenOwner(tokenId)
|
| 192 |
+
nonZeroPrice(price)
|
| 193 |
+
tokenAvailable() {
|
| 194 |
+
require(token.getApproved(tokenId) == address(this),"Exchange is not allowed to transfer");
|
| 195 |
+
|
| 196 |
+
token.transferFrom(msg.sender, address(this), tokenId);
|
| 197 |
+
|
| 198 |
+
|
| 199 |
+
market[tokenId] = SaleData(price,msg.sender);
|
| 200 |
+
|
| 201 |
+
|
| 202 |
+
userBarn[msg.sender].push(tokenId);
|
| 203 |
+
|
| 204 |
+
emit HorseyDeposit(tokenId, price);
|
| 205 |
+
}
|
| 206 |
+
|
| 207 |
+
|
| 208 |
+
function cancelSale(uint256 tokenId) external
|
| 209 |
+
whenNotPaused()
|
| 210 |
+
originalOwnerOf(tokenId)
|
| 211 |
+
tokenAvailable() returns (bool) {
|
| 212 |
+
|
| 213 |
+
token.transferFrom(address(this),msg.sender,tokenId);
|
| 214 |
+
|
| 215 |
+
|
| 216 |
+
delete market[tokenId];
|
| 217 |
+
|
| 218 |
+
|
| 219 |
+
_removeTokenFromBarn(tokenId, msg.sender);
|
| 220 |
+
|
| 221 |
+
emit SaleCanceled(tokenId);
|
| 222 |
+
|
| 223 |
+
|
| 224 |
+
|
| 225 |
+
return userBarn[msg.sender].length > 0;
|
| 226 |
+
}
|
| 227 |
+
|
| 228 |
+
|
| 229 |
+
function purchaseToken(uint256 tokenId) external payable
|
| 230 |
+
whenNotPaused()
|
| 231 |
+
isOnMarket(tokenId)
|
| 232 |
+
tokenAvailable()
|
| 233 |
+
notOriginalOwnerOf(tokenId)
|
| 234 |
+
{
|
| 235 |
+
|
| 236 |
+
uint256 totalToPay = getTokenPrice(tokenId);
|
| 237 |
+
require(msg.value >= totalToPay, "Not paying enough");
|
| 238 |
+
|
| 239 |
+
|
| 240 |
+
SaleData memory sale = market[tokenId];
|
| 241 |
+
|
| 242 |
+
|
| 243 |
+
collectedFees += totalToPay - sale.price;
|
| 244 |
+
|
| 245 |
+
|
| 246 |
+
sale.owner.transfer(sale.price);
|
| 247 |
+
|
| 248 |
+
|
| 249 |
+
_removeTokenFromBarn(tokenId, sale.owner);
|
| 250 |
+
|
| 251 |
+
|
| 252 |
+
delete market[tokenId];
|
| 253 |
+
|
| 254 |
+
|
| 255 |
+
|
| 256 |
+
token.transferFrom(address(this), msg.sender, tokenId);
|
| 257 |
+
|
| 258 |
+
|
| 259 |
+
if(msg.value > totalToPay)
|
| 260 |
+
{
|
| 261 |
+
msg.sender.transfer(msg.value.sub(totalToPay));
|
| 262 |
+
}
|
| 263 |
+
|
| 264 |
+
emit HorseyPurchased(tokenId, msg.sender, totalToPay);
|
| 265 |
+
}
|
| 266 |
+
|
| 267 |
+
|
| 268 |
+
function withdraw() external
|
| 269 |
+
onlyOwner()
|
| 270 |
+
{
|
| 271 |
+
assert(collectedFees <= address(this).balance);
|
| 272 |
+
owner.transfer(collectedFees);
|
| 273 |
+
collectedFees = 0;
|
| 274 |
+
}
|
| 275 |
+
|
| 276 |
+
|
| 277 |
+
function _removeTokenFromBarn(uint tokenId, address barnAddress) internal {
|
| 278 |
+
uint256[] storage barnArray = userBarn[barnAddress];
|
| 279 |
+
require(barnArray.length > 0,"No tokens to remove");
|
| 280 |
+
int index = _indexOf(tokenId, barnArray);
|
| 281 |
+
require(index >= 0, "Token not found in barn");
|
| 282 |
+
|
| 283 |
+
|
| 284 |
+
for (uint256 i = uint256(index); i<barnArray.length-1; i++){
|
| 285 |
+
barnArray[i] = barnArray[i+1];
|
| 286 |
+
}
|
| 287 |
+
|
| 288 |
+
|
| 289 |
+
|
| 290 |
+
barnArray.length--;
|
| 291 |
+
}
|
| 292 |
+
|
| 293 |
+
|
| 294 |
+
function _indexOf(uint item, uint256[] memory array) internal pure returns (int256){
|
| 295 |
+
|
| 296 |
+
|
| 297 |
+
for(uint256 i = 0; i < array.length; i++){
|
| 298 |
+
if(array[i] == item){
|
| 299 |
+
return int256(i);
|
| 300 |
+
}
|
| 301 |
+
}
|
| 302 |
+
|
| 303 |
+
|
| 304 |
+
return -1;
|
| 305 |
+
}
|
| 306 |
+
|
| 307 |
+
|
| 308 |
+
modifier isOnMarket(uint256 tokenId) {
|
| 309 |
+
require(token.ownerOf(tokenId) == address(this),"Token not on market");
|
| 310 |
+
_;
|
| 311 |
+
}
|
| 312 |
+
|
| 313 |
+
|
| 314 |
+
modifier isTokenOwner(uint256 tokenId) {
|
| 315 |
+
require(token.ownerOf(tokenId) == msg.sender,"Not tokens owner");
|
| 316 |
+
_;
|
| 317 |
+
}
|
| 318 |
+
|
| 319 |
+
|
| 320 |
+
modifier originalOwnerOf(uint256 tokenId) {
|
| 321 |
+
require(market[tokenId].owner == msg.sender,"Not the original owner of");
|
| 322 |
+
_;
|
| 323 |
+
}
|
| 324 |
+
|
| 325 |
+
|
| 326 |
+
modifier notOriginalOwnerOf(uint256 tokenId) {
|
| 327 |
+
require(market[tokenId].owner != msg.sender,"Is the original owner");
|
| 328 |
+
_;
|
| 329 |
+
}
|
| 330 |
+
|
| 331 |
+
|
| 332 |
+
modifier nonZeroPrice(uint256 price){
|
| 333 |
+
require(price > 0,"Price is zero");
|
| 334 |
+
_;
|
| 335 |
+
}
|
| 336 |
+
|
| 337 |
+
|
| 338 |
+
modifier tokenAvailable(){
|
| 339 |
+
require(address(token) != 0,"Token address not set");
|
| 340 |
+
_;
|
| 341 |
+
}
|
| 342 |
+
}
|
| 343 |
+
|
| 344 |
+
|
| 345 |
+
|
| 346 |
+
|
| 347 |
+
contract EthorseRace {
|
| 348 |
+
|
| 349 |
+
|
| 350 |
+
struct chronus_info {
|
| 351 |
+
bool betting_open;
|
| 352 |
+
bool race_start;
|
| 353 |
+
bool race_end;
|
| 354 |
+
bool voided_bet;
|
| 355 |
+
uint32 starting_time;
|
| 356 |
+
uint32 betting_duration;
|
| 357 |
+
uint32 race_duration;
|
| 358 |
+
uint32 voided_timestamp;
|
| 359 |
+
}
|
| 360 |
+
|
| 361 |
+
address public owner;
|
| 362 |
+
|
| 363 |
+
|
| 364 |
+
chronus_info public chronus;
|
| 365 |
+
|
| 366 |
+
|
| 367 |
+
mapping (bytes32 => bool) public winner_horse;
|
| 368 |
+
|
| 369 |
+
|
| 370 |
+
function getCoinIndex(bytes32 index, address candidate) external constant returns (uint, uint, uint, bool, uint);
|
| 371 |
+
}
|
| 372 |
+
|
| 373 |
+
|
| 374 |
+
contract EthorseHelpers {
|
| 375 |
+
|
| 376 |
+
|
| 377 |
+
bytes32[] public all_horses = [bytes32("BTC"),bytes32("ETH"),bytes32("LTC")];
|
| 378 |
+
mapping(address => bool) public legitRaces;
|
| 379 |
+
bool onlyLegit = false;
|
| 380 |
+
|
| 381 |
+
|
| 382 |
+
function _addHorse(bytes32 newHorse) internal {
|
| 383 |
+
all_horses.push(newHorse);
|
| 384 |
+
}
|
| 385 |
+
|
| 386 |
+
function _addLegitRace(address newRace) internal
|
| 387 |
+
{
|
| 388 |
+
legitRaces[newRace] = true;
|
| 389 |
+
if(!onlyLegit)
|
| 390 |
+
onlyLegit = true;
|
| 391 |
+
}
|
| 392 |
+
|
| 393 |
+
function getall_horsesCount() public view returns(uint) {
|
| 394 |
+
return all_horses.length;
|
| 395 |
+
}
|
| 396 |
+
|
| 397 |
+
|
| 398 |
+
function _isWinnerOf(address raceAddress, address eth_address) internal view returns (bool,bytes32)
|
| 399 |
+
{
|
| 400 |
+
|
| 401 |
+
EthorseRace race = EthorseRace(raceAddress);
|
| 402 |
+
|
| 403 |
+
|
| 404 |
+
if(onlyLegit)
|
| 405 |
+
require(legitRaces[raceAddress],"not legit race");
|
| 406 |
+
|
| 407 |
+
bool voided_bet;
|
| 408 |
+
bool race_end;
|
| 409 |
+
(,,race_end,voided_bet,,,,) = race.chronus();
|
| 410 |
+
|
| 411 |
+
|
| 412 |
+
if(voided_bet || !race_end)
|
| 413 |
+
return (false,bytes32(0));
|
| 414 |
+
|
| 415 |
+
|
| 416 |
+
bytes32 horse;
|
| 417 |
+
bool found = false;
|
| 418 |
+
uint256 arrayLength = all_horses.length;
|
| 419 |
+
|
| 420 |
+
|
| 421 |
+
for(uint256 i = 0; i < arrayLength; i++)
|
| 422 |
+
{
|
| 423 |
+
if(race.winner_horse(all_horses[i])) {
|
| 424 |
+
horse = all_horses[i];
|
| 425 |
+
found = true;
|
| 426 |
+
break;
|
| 427 |
+
}
|
| 428 |
+
}
|
| 429 |
+
|
| 430 |
+
if(!found)
|
| 431 |
+
return (false,bytes32(0));
|
| 432 |
+
|
| 433 |
+
|
| 434 |
+
uint256 bet_amount = 0;
|
| 435 |
+
if(eth_address != address(0)) {
|
| 436 |
+
(,,,, bet_amount) = race.getCoinIndex(horse, eth_address);
|
| 437 |
+
}
|
| 438 |
+
|
| 439 |
+
|
| 440 |
+
return (bet_amount > 0, horse);
|
| 441 |
+
}
|
| 442 |
+
}
|
| 443 |
+
|
| 444 |
+
|
| 445 |
+
|
| 446 |
+
contract RoyalStablesInterface {
|
| 447 |
+
|
| 448 |
+
struct Horsey {
|
| 449 |
+
address race;
|
| 450 |
+
bytes32 dna;
|
| 451 |
+
uint8 feedingCounter;
|
| 452 |
+
uint8 tier;
|
| 453 |
+
}
|
| 454 |
+
|
| 455 |
+
mapping(uint256 => Horsey) public horseys;
|
| 456 |
+
mapping(address => uint32) public carrot_credits;
|
| 457 |
+
mapping(uint256 => string) public names;
|
| 458 |
+
address public master;
|
| 459 |
+
|
| 460 |
+
function getOwnedTokens(address eth_address) public view returns (uint256[]);
|
| 461 |
+
function storeName(uint256 tokenId, string newName) public;
|
| 462 |
+
function storeCarrotsCredit(address client, uint32 amount) public;
|
| 463 |
+
function storeHorsey(address client, uint256 tokenId, address race, bytes32 dna, uint8 feedingCounter, uint8 tier) public;
|
| 464 |
+
function modifyHorsey(uint256 tokenId, address race, bytes32 dna, uint8 feedingCounter, uint8 tier) public;
|
| 465 |
+
function modifyHorseyDna(uint256 tokenId, bytes32 dna) public;
|
| 466 |
+
function modifyHorseyFeedingCounter(uint256 tokenId, uint8 feedingCounter) public;
|
| 467 |
+
function modifyHorseyTier(uint256 tokenId, uint8 tier) public;
|
| 468 |
+
function unstoreHorsey(uint256 tokenId) public;
|
| 469 |
+
function ownerOf(uint256 tokenId) public returns (address);
|
| 470 |
+
}
|
| 471 |
+
|
| 472 |
+
|
| 473 |
+
contract HorseyToken is EthorseHelpers,Pausable {
|
| 474 |
+
using SafeMath for uint256;
|
| 475 |
+
|
| 476 |
+
|
| 477 |
+
event Claimed(address raceAddress, address eth_address, uint256 tokenId);
|
| 478 |
+
|
| 479 |
+
|
| 480 |
+
event Feeding(uint256 tokenId);
|
| 481 |
+
|
| 482 |
+
|
| 483 |
+
event ReceivedCarrot(uint256 tokenId, bytes32 newDna);
|
| 484 |
+
|
| 485 |
+
|
| 486 |
+
event FeedingFailed(uint256 tokenId);
|
| 487 |
+
|
| 488 |
+
|
| 489 |
+
event HorseyRenamed(uint256 tokenId, string newName);
|
| 490 |
+
|
| 491 |
+
|
| 492 |
+
event HorseyFreed(uint256 tokenId);
|
| 493 |
+
|
| 494 |
+
|
| 495 |
+
RoyalStablesInterface public stables;
|
| 496 |
+
|
| 497 |
+
|
| 498 |
+
uint8 public carrotsMultiplier = 1;
|
| 499 |
+
|
| 500 |
+
|
| 501 |
+
uint8 public rarityMultiplier = 1;
|
| 502 |
+
|
| 503 |
+
|
| 504 |
+
uint256 public claimingFee = 0.000 ether;
|
| 505 |
+
|
| 506 |
+
|
| 507 |
+
struct FeedingData {
|
| 508 |
+
uint256 blockNumber;
|
| 509 |
+
uint256 horsey;
|
| 510 |
+
}
|
| 511 |
+
|
| 512 |
+
|
| 513 |
+
mapping(address => FeedingData) public pendingFeedings;
|
| 514 |
+
|
| 515 |
+
|
| 516 |
+
uint256 public renamingCostsPerChar = 0.001 ether;
|
| 517 |
+
|
| 518 |
+
|
| 519 |
+
constructor(address stablesAddress)
|
| 520 |
+
EthorseHelpers()
|
| 521 |
+
Pausable() public {
|
| 522 |
+
stables = RoyalStablesInterface(stablesAddress);
|
| 523 |
+
}
|
| 524 |
+
|
| 525 |
+
|
| 526 |
+
function setRarityMultiplier(uint8 newRarityMultiplier) external
|
| 527 |
+
onlyOwner() {
|
| 528 |
+
rarityMultiplier = newRarityMultiplier;
|
| 529 |
+
}
|
| 530 |
+
|
| 531 |
+
|
| 532 |
+
function setCarrotsMultiplier(uint8 newCarrotsMultiplier) external
|
| 533 |
+
onlyOwner() {
|
| 534 |
+
carrotsMultiplier = newCarrotsMultiplier;
|
| 535 |
+
}
|
| 536 |
+
|
| 537 |
+
|
| 538 |
+
function setRenamingCosts(uint256 newRenamingCost) external
|
| 539 |
+
onlyOwner() {
|
| 540 |
+
renamingCostsPerChar = newRenamingCost;
|
| 541 |
+
}
|
| 542 |
+
|
| 543 |
+
|
| 544 |
+
function setClaimingCosts(uint256 newClaimingFee) external
|
| 545 |
+
onlyOwner() {
|
| 546 |
+
claimingFee = newClaimingFee;
|
| 547 |
+
}
|
| 548 |
+
|
| 549 |
+
|
| 550 |
+
function addLegitRaceAddress(address newAddress) external
|
| 551 |
+
onlyOwner() {
|
| 552 |
+
_addLegitRace(newAddress);
|
| 553 |
+
}
|
| 554 |
+
|
| 555 |
+
|
| 556 |
+
function withdraw() external
|
| 557 |
+
onlyOwner() {
|
| 558 |
+
owner.transfer(address(this).balance);
|
| 559 |
+
}
|
| 560 |
+
|
| 561 |
+
|
| 562 |
+
|
| 563 |
+
function addHorseIndex(bytes32 newHorse) external
|
| 564 |
+
onlyOwner() {
|
| 565 |
+
_addHorse(newHorse);
|
| 566 |
+
}
|
| 567 |
+
|
| 568 |
+
|
| 569 |
+
function getOwnedTokens(address eth_address) public view returns (uint256[]) {
|
| 570 |
+
return stables.getOwnedTokens(eth_address);
|
| 571 |
+
}
|
| 572 |
+
|
| 573 |
+
|
| 574 |
+
function can_claim(address raceAddress, address eth_address) public view returns (bool) {
|
| 575 |
+
bool res;
|
| 576 |
+
(res,) = _isWinnerOf(raceAddress, eth_address);
|
| 577 |
+
return res;
|
| 578 |
+
}
|
| 579 |
+
|
| 580 |
+
|
| 581 |
+
function claim(address raceAddress) external payable
|
| 582 |
+
costs(claimingFee)
|
| 583 |
+
whenNotPaused()
|
| 584 |
+
{
|
| 585 |
+
|
| 586 |
+
bytes32 winner;
|
| 587 |
+
bool res;
|
| 588 |
+
(res,winner) = _isWinnerOf(raceAddress, address(0));
|
| 589 |
+
require(winner != bytes32(0),"Winner is zero");
|
| 590 |
+
require(res,"can_claim return false");
|
| 591 |
+
|
| 592 |
+
uint256 id = _generate_special_horsey(raceAddress, msg.sender, winner);
|
| 593 |
+
emit Claimed(raceAddress, msg.sender, id);
|
| 594 |
+
}
|
| 595 |
+
|
| 596 |
+
|
| 597 |
+
function renameHorsey(uint256 tokenId, string newName) external
|
| 598 |
+
whenNotPaused()
|
| 599 |
+
onlyOwnerOf(tokenId)
|
| 600 |
+
costs(renamingCostsPerChar * bytes(newName).length)
|
| 601 |
+
payable {
|
| 602 |
+
uint256 renamingFee = renamingCostsPerChar * bytes(newName).length;
|
| 603 |
+
|
| 604 |
+
if(msg.value > renamingFee)
|
| 605 |
+
{
|
| 606 |
+
msg.sender.transfer(msg.value.sub(renamingFee));
|
| 607 |
+
}
|
| 608 |
+
|
| 609 |
+
stables.storeName(tokenId,newName);
|
| 610 |
+
emit HorseyRenamed(tokenId,newName);
|
| 611 |
+
}
|
| 612 |
+
|
| 613 |
+
|
| 614 |
+
function freeForCarrots(uint256 tokenId) external
|
| 615 |
+
whenNotPaused()
|
| 616 |
+
onlyOwnerOf(tokenId) {
|
| 617 |
+
require(pendingFeedings[msg.sender].horsey != tokenId,"");
|
| 618 |
+
|
| 619 |
+
uint8 feedingCounter;
|
| 620 |
+
(,,feedingCounter,) = stables.horseys(tokenId);
|
| 621 |
+
stables.storeCarrotsCredit(msg.sender,stables.carrot_credits(msg.sender) + uint32(feedingCounter * carrotsMultiplier));
|
| 622 |
+
stables.unstoreHorsey(tokenId);
|
| 623 |
+
emit HorseyFreed(tokenId);
|
| 624 |
+
}
|
| 625 |
+
|
| 626 |
+
|
| 627 |
+
function getCarrotCredits() external view returns (uint32) {
|
| 628 |
+
return stables.carrot_credits(msg.sender);
|
| 629 |
+
}
|
| 630 |
+
|
| 631 |
+
|
| 632 |
+
function getHorsey(uint256 tokenId) public view returns (address, bytes32, uint8, string) {
|
| 633 |
+
RoyalStablesInterface.Horsey memory temp;
|
| 634 |
+
(temp.race,temp.dna,temp.feedingCounter,temp.tier) = stables.horseys(tokenId);
|
| 635 |
+
return (temp.race,temp.dna,temp.feedingCounter,stables.names(tokenId));
|
| 636 |
+
}
|
| 637 |
+
|
| 638 |
+
|
| 639 |
+
function feed(uint256 tokenId) external
|
| 640 |
+
whenNotPaused()
|
| 641 |
+
onlyOwnerOf(tokenId)
|
| 642 |
+
carrotsMeetLevel(tokenId)
|
| 643 |
+
noFeedingInProgress()
|
| 644 |
+
{
|
| 645 |
+
pendingFeedings[msg.sender] = FeedingData(block.number,tokenId);
|
| 646 |
+
uint8 feedingCounter;
|
| 647 |
+
(,,feedingCounter,) = stables.horseys(tokenId);
|
| 648 |
+
stables.storeCarrotsCredit(msg.sender,stables.carrot_credits(msg.sender) - uint32(feedingCounter));
|
| 649 |
+
emit Feeding(tokenId);
|
| 650 |
+
}
|
| 651 |
+
|
| 652 |
+
|
| 653 |
+
function stopFeeding() external
|
| 654 |
+
feedingInProgress() returns (bool) {
|
| 655 |
+
uint256 blockNumber = pendingFeedings[msg.sender].blockNumber;
|
| 656 |
+
uint256 tokenId = pendingFeedings[msg.sender].horsey;
|
| 657 |
+
|
| 658 |
+
require(block.number - blockNumber >= 1,"feeding and stop feeding are in same block");
|
| 659 |
+
|
| 660 |
+
delete pendingFeedings[msg.sender];
|
| 661 |
+
|
| 662 |
+
|
| 663 |
+
|
| 664 |
+
if(block.number - blockNumber > 255) {
|
| 665 |
+
|
| 666 |
+
|
| 667 |
+
emit FeedingFailed(tokenId);
|
| 668 |
+
return false;
|
| 669 |
+
}
|
| 670 |
+
|
| 671 |
+
|
| 672 |
+
if(stables.ownerOf(tokenId) != msg.sender) {
|
| 673 |
+
|
| 674 |
+
|
| 675 |
+
emit FeedingFailed(tokenId);
|
| 676 |
+
return false;
|
| 677 |
+
}
|
| 678 |
+
|
| 679 |
+
|
| 680 |
+
_feed(tokenId, blockhash(blockNumber));
|
| 681 |
+
bytes32 dna;
|
| 682 |
+
(,dna,,) = stables.horseys(tokenId);
|
| 683 |
+
emit ReceivedCarrot(tokenId, dna);
|
| 684 |
+
return true;
|
| 685 |
+
}
|
| 686 |
+
|
| 687 |
+
|
| 688 |
+
function() external payable {
|
| 689 |
+
revert("Not accepting donations");
|
| 690 |
+
}
|
| 691 |
+
|
| 692 |
+
|
| 693 |
+
function _feed(uint256 tokenId, bytes32 blockHash) internal {
|
| 694 |
+
|
| 695 |
+
uint8 tier;
|
| 696 |
+
uint8 feedingCounter;
|
| 697 |
+
(,,feedingCounter,tier) = stables.horseys(tokenId);
|
| 698 |
+
uint256 probabilityByRarity = 10 ** (uint256(tier).add(1));
|
| 699 |
+
uint256 randNum = uint256(keccak256(abi.encodePacked(tokenId, blockHash))) % probabilityByRarity;
|
| 700 |
+
|
| 701 |
+
|
| 702 |
+
if(randNum <= (feedingCounter * rarityMultiplier)){
|
| 703 |
+
_increaseRarity(tokenId, blockHash);
|
| 704 |
+
}
|
| 705 |
+
|
| 706 |
+
|
| 707 |
+
|
| 708 |
+
if(feedingCounter < 255) {
|
| 709 |
+
stables.modifyHorseyFeedingCounter(tokenId,feedingCounter+1);
|
| 710 |
+
}
|
| 711 |
+
}
|
| 712 |
+
|
| 713 |
+
|
| 714 |
+
function _makeSpecialId(address race, address sender, bytes32 coinIndex) internal pure returns (uint256) {
|
| 715 |
+
return uint256(keccak256(abi.encodePacked(race, sender, coinIndex)));
|
| 716 |
+
}
|
| 717 |
+
|
| 718 |
+
|
| 719 |
+
function _generate_special_horsey(address race, address eth_address, bytes32 coinIndex) internal returns (uint256) {
|
| 720 |
+
uint256 id = _makeSpecialId(race, eth_address, coinIndex);
|
| 721 |
+
|
| 722 |
+
bytes32 dna = _shiftRight(keccak256(abi.encodePacked(race, coinIndex)),16);
|
| 723 |
+
|
| 724 |
+
stables.storeHorsey(eth_address,id,race,dna,1,0);
|
| 725 |
+
return id;
|
| 726 |
+
}
|
| 727 |
+
|
| 728 |
+
|
| 729 |
+
function _increaseRarity(uint256 tokenId, bytes32 blockHash) private {
|
| 730 |
+
uint8 tier;
|
| 731 |
+
bytes32 dna;
|
| 732 |
+
(,dna,,tier) = stables.horseys(tokenId);
|
| 733 |
+
if(tier < 255)
|
| 734 |
+
stables.modifyHorseyTier(tokenId,tier+1);
|
| 735 |
+
uint256 random = uint256(keccak256(abi.encodePacked(tokenId, blockHash)));
|
| 736 |
+
|
| 737 |
+
bytes32 rarityMask = _shiftLeft(bytes32(1), (random % 16 + 240));
|
| 738 |
+
bytes32 newdna = dna | rarityMask;
|
| 739 |
+
stables.modifyHorseyDna(tokenId,newdna);
|
| 740 |
+
}
|
| 741 |
+
|
| 742 |
+
|
| 743 |
+
function _shiftLeft(bytes32 data, uint n) internal pure returns (bytes32) {
|
| 744 |
+
return bytes32(uint256(data)*(2 ** n));
|
| 745 |
+
}
|
| 746 |
+
|
| 747 |
+
|
| 748 |
+
function _shiftRight(bytes32 data, uint n) internal pure returns (bytes32) {
|
| 749 |
+
return bytes32(uint256(data)/(2 ** n));
|
| 750 |
+
}
|
| 751 |
+
|
| 752 |
+
|
| 753 |
+
modifier carrotsMeetLevel(uint256 tokenId){
|
| 754 |
+
uint256 feedingCounter;
|
| 755 |
+
(,,feedingCounter,) = stables.horseys(tokenId);
|
| 756 |
+
require(feedingCounter <= stables.carrot_credits(msg.sender),"Not enough carrots");
|
| 757 |
+
_;
|
| 758 |
+
}
|
| 759 |
+
|
| 760 |
+
|
| 761 |
+
modifier costs(uint256 amount) {
|
| 762 |
+
require(msg.value >= amount,"Not enough funds");
|
| 763 |
+
_;
|
| 764 |
+
}
|
| 765 |
+
|
| 766 |
+
|
| 767 |
+
modifier validAddress(address addr) {
|
| 768 |
+
require(addr != address(0),"Address is zero");
|
| 769 |
+
_;
|
| 770 |
+
}
|
| 771 |
+
|
| 772 |
+
|
| 773 |
+
modifier noFeedingInProgress() {
|
| 774 |
+
|
| 775 |
+
require(pendingFeedings[msg.sender].blockNumber == 0,"Already feeding");
|
| 776 |
+
_;
|
| 777 |
+
}
|
| 778 |
+
|
| 779 |
+
|
| 780 |
+
modifier feedingInProgress() {
|
| 781 |
+
|
| 782 |
+
require(pendingFeedings[msg.sender].blockNumber != 0,"No pending feeding");
|
| 783 |
+
_;
|
| 784 |
+
}
|
| 785 |
+
|
| 786 |
+
|
| 787 |
+
modifier onlyOwnerOf(uint256 tokenId) {
|
| 788 |
+
require(stables.ownerOf(tokenId) == msg.sender, "Caller is not owner of this token");
|
| 789 |
+
_;
|
| 790 |
+
}
|
| 791 |
+
}
|
| 792 |
+
|
| 793 |
+
|
| 794 |
+
|
| 795 |
+
|
| 796 |
+
|
| 797 |
+
contract HorseyPilot {
|
| 798 |
+
|
| 799 |
+
|
| 800 |
+
event NewProposal(uint8 methodId, uint parameter, address proposer);
|
| 801 |
+
|
| 802 |
+
|
| 803 |
+
event ProposalPassed(uint8 methodId, uint parameter, address proposer);
|
| 804 |
+
|
| 805 |
+
|
| 806 |
+
|
| 807 |
+
uint8 constant votingThreshold = 2;
|
| 808 |
+
|
| 809 |
+
|
| 810 |
+
|
| 811 |
+
uint256 constant proposalLife = 7 days;
|
| 812 |
+
|
| 813 |
+
|
| 814 |
+
|
| 815 |
+
uint256 constant proposalCooldown = 1 days;
|
| 816 |
+
|
| 817 |
+
|
| 818 |
+
uint256 cooldownStart;
|
| 819 |
+
|
| 820 |
+
|
| 821 |
+
address public jokerAddress;
|
| 822 |
+
address public knightAddress;
|
| 823 |
+
address public paladinAddress;
|
| 824 |
+
|
| 825 |
+
|
| 826 |
+
address[3] public voters;
|
| 827 |
+
|
| 828 |
+
|
| 829 |
+
uint8 constant public knightEquity = 40;
|
| 830 |
+
uint8 constant public paladinEquity = 10;
|
| 831 |
+
|
| 832 |
+
|
| 833 |
+
address public exchangeAddress;
|
| 834 |
+
address public tokenAddress;
|
| 835 |
+
|
| 836 |
+
|
| 837 |
+
mapping(address => uint) internal _cBalance;
|
| 838 |
+
|
| 839 |
+
|
| 840 |
+
struct Proposal{
|
| 841 |
+
address proposer;
|
| 842 |
+
uint256 timestamp;
|
| 843 |
+
uint256 parameter;
|
| 844 |
+
uint8 methodId;
|
| 845 |
+
address[] yay;
|
| 846 |
+
address[] nay;
|
| 847 |
+
}
|
| 848 |
+
|
| 849 |
+
|
| 850 |
+
Proposal public currentProposal;
|
| 851 |
+
|
| 852 |
+
|
| 853 |
+
bool public proposalInProgress = false;
|
| 854 |
+
|
| 855 |
+
|
| 856 |
+
uint256 public toBeDistributed;
|
| 857 |
+
|
| 858 |
+
|
| 859 |
+
bool deployed = false;
|
| 860 |
+
|
| 861 |
+
|
| 862 |
+
constructor(
|
| 863 |
+
address _jokerAddress,
|
| 864 |
+
address _knightAddress,
|
| 865 |
+
address _paladinAddress,
|
| 866 |
+
address[3] _voters
|
| 867 |
+
) public {
|
| 868 |
+
jokerAddress = _jokerAddress;
|
| 869 |
+
knightAddress = _knightAddress;
|
| 870 |
+
paladinAddress = _paladinAddress;
|
| 871 |
+
|
| 872 |
+
for(uint i = 0; i < 3; i++) {
|
| 873 |
+
voters[i] = _voters[i];
|
| 874 |
+
}
|
| 875 |
+
|
| 876 |
+
|
| 877 |
+
cooldownStart = block.timestamp - proposalCooldown;
|
| 878 |
+
}
|
| 879 |
+
|
| 880 |
+
|
| 881 |
+
function deployChildren(address stablesAddress) external {
|
| 882 |
+
require(!deployed,"already deployed");
|
| 883 |
+
|
| 884 |
+
exchangeAddress = new HorseyExchange();
|
| 885 |
+
tokenAddress = new HorseyToken(stablesAddress);
|
| 886 |
+
|
| 887 |
+
|
| 888 |
+
HorseyExchange(exchangeAddress).setStables(stablesAddress);
|
| 889 |
+
|
| 890 |
+
deployed = true;
|
| 891 |
+
}
|
| 892 |
+
|
| 893 |
+
|
| 894 |
+
function transferJokerOwnership(address newJoker) external
|
| 895 |
+
validAddress(newJoker) {
|
| 896 |
+
require(jokerAddress == msg.sender,"Not right role");
|
| 897 |
+
_moveBalance(newJoker);
|
| 898 |
+
jokerAddress = newJoker;
|
| 899 |
+
}
|
| 900 |
+
|
| 901 |
+
|
| 902 |
+
function transferKnightOwnership(address newKnight) external
|
| 903 |
+
validAddress(newKnight) {
|
| 904 |
+
require(knightAddress == msg.sender,"Not right role");
|
| 905 |
+
_moveBalance(newKnight);
|
| 906 |
+
knightAddress = newKnight;
|
| 907 |
+
}
|
| 908 |
+
|
| 909 |
+
|
| 910 |
+
function transferPaladinOwnership(address newPaladin) external
|
| 911 |
+
validAddress(newPaladin) {
|
| 912 |
+
require(paladinAddress == msg.sender,"Not right role");
|
| 913 |
+
_moveBalance(newPaladin);
|
| 914 |
+
paladinAddress = newPaladin;
|
| 915 |
+
}
|
| 916 |
+
|
| 917 |
+
|
| 918 |
+
function withdrawCeo(address destination) external
|
| 919 |
+
onlyCLevelAccess()
|
| 920 |
+
validAddress(destination) {
|
| 921 |
+
|
| 922 |
+
|
| 923 |
+
if(toBeDistributed > 0){
|
| 924 |
+
_updateDistribution();
|
| 925 |
+
}
|
| 926 |
+
|
| 927 |
+
|
| 928 |
+
uint256 balance = _cBalance[msg.sender];
|
| 929 |
+
|
| 930 |
+
|
| 931 |
+
if(balance > 0 && (address(this).balance >= balance)) {
|
| 932 |
+
destination.transfer(balance);
|
| 933 |
+
_cBalance[msg.sender] = 0;
|
| 934 |
+
}
|
| 935 |
+
}
|
| 936 |
+
|
| 937 |
+
|
| 938 |
+
function syncFunds() external {
|
| 939 |
+
uint256 prevBalance = address(this).balance;
|
| 940 |
+
HorseyToken(tokenAddress).withdraw();
|
| 941 |
+
HorseyExchange(exchangeAddress).withdraw();
|
| 942 |
+
uint256 newBalance = address(this).balance;
|
| 943 |
+
|
| 944 |
+
toBeDistributed = toBeDistributed + (newBalance - prevBalance);
|
| 945 |
+
}
|
| 946 |
+
|
| 947 |
+
|
| 948 |
+
function getNobleBalance() external view
|
| 949 |
+
onlyCLevelAccess() returns (uint256) {
|
| 950 |
+
return _cBalance[msg.sender];
|
| 951 |
+
}
|
| 952 |
+
|
| 953 |
+
|
| 954 |
+
function makeProposal( uint8 methodId, uint256 parameter ) external
|
| 955 |
+
onlyCLevelAccess()
|
| 956 |
+
proposalAvailable()
|
| 957 |
+
cooledDown()
|
| 958 |
+
{
|
| 959 |
+
currentProposal.timestamp = block.timestamp;
|
| 960 |
+
currentProposal.parameter = parameter;
|
| 961 |
+
currentProposal.methodId = methodId;
|
| 962 |
+
currentProposal.proposer = msg.sender;
|
| 963 |
+
delete currentProposal.yay;
|
| 964 |
+
delete currentProposal.nay;
|
| 965 |
+
proposalInProgress = true;
|
| 966 |
+
|
| 967 |
+
emit NewProposal(methodId,parameter,msg.sender);
|
| 968 |
+
}
|
| 969 |
+
|
| 970 |
+
|
| 971 |
+
function voteOnProposal(bool voteFor) external
|
| 972 |
+
proposalPending()
|
| 973 |
+
onlyVoters()
|
| 974 |
+
notVoted() {
|
| 975 |
+
|
| 976 |
+
require((block.timestamp - currentProposal.timestamp) <= proposalLife);
|
| 977 |
+
if(voteFor)
|
| 978 |
+
{
|
| 979 |
+
currentProposal.yay.push(msg.sender);
|
| 980 |
+
|
| 981 |
+
if( currentProposal.yay.length >= votingThreshold )
|
| 982 |
+
{
|
| 983 |
+
_doProposal();
|
| 984 |
+
proposalInProgress = false;
|
| 985 |
+
|
| 986 |
+
return;
|
| 987 |
+
}
|
| 988 |
+
|
| 989 |
+
} else {
|
| 990 |
+
currentProposal.nay.push(msg.sender);
|
| 991 |
+
|
| 992 |
+
if( currentProposal.nay.length >= votingThreshold )
|
| 993 |
+
{
|
| 994 |
+
proposalInProgress = false;
|
| 995 |
+
cooldownStart = block.timestamp;
|
| 996 |
+
return;
|
| 997 |
+
}
|
| 998 |
+
}
|
| 999 |
+
}
|
| 1000 |
+
|
| 1001 |
+
|
| 1002 |
+
function _moveBalance(address newAddress) internal
|
| 1003 |
+
validAddress(newAddress) {
|
| 1004 |
+
require(newAddress != msg.sender);
|
| 1005 |
+
_cBalance[newAddress] = _cBalance[msg.sender];
|
| 1006 |
+
_cBalance[msg.sender] = 0;
|
| 1007 |
+
}
|
| 1008 |
+
|
| 1009 |
+
|
| 1010 |
+
function _updateDistribution() internal {
|
| 1011 |
+
require(toBeDistributed != 0,"nothing to distribute");
|
| 1012 |
+
uint256 knightPayday = toBeDistributed / 100 * knightEquity;
|
| 1013 |
+
uint256 paladinPayday = toBeDistributed / 100 * paladinEquity;
|
| 1014 |
+
|
| 1015 |
+
|
| 1016 |
+
uint256 jokerPayday = toBeDistributed - knightPayday - paladinPayday;
|
| 1017 |
+
|
| 1018 |
+
_cBalance[jokerAddress] = _cBalance[jokerAddress] + jokerPayday;
|
| 1019 |
+
_cBalance[knightAddress] = _cBalance[knightAddress] + knightPayday;
|
| 1020 |
+
_cBalance[paladinAddress] = _cBalance[paladinAddress] + paladinPayday;
|
| 1021 |
+
|
| 1022 |
+
toBeDistributed = 0;
|
| 1023 |
+
}
|
| 1024 |
+
|
| 1025 |
+
|
| 1026 |
+
function _doProposal() internal {
|
| 1027 |
+
|
| 1028 |
+
if( currentProposal.methodId == 0 ) HorseyToken(tokenAddress).setRenamingCosts(currentProposal.parameter);
|
| 1029 |
+
|
| 1030 |
+
|
| 1031 |
+
if( currentProposal.methodId == 1 ) HorseyExchange(exchangeAddress).setMarketFees(currentProposal.parameter);
|
| 1032 |
+
|
| 1033 |
+
|
| 1034 |
+
if( currentProposal.methodId == 2 ) HorseyToken(tokenAddress).addLegitRaceAddress(address(currentProposal.parameter));
|
| 1035 |
+
|
| 1036 |
+
|
| 1037 |
+
if( currentProposal.methodId == 3 ) HorseyToken(tokenAddress).addHorseIndex(bytes32(currentProposal.parameter));
|
| 1038 |
+
|
| 1039 |
+
|
| 1040 |
+
if( currentProposal.methodId == 4 ) {
|
| 1041 |
+
if(currentProposal.parameter == 0) {
|
| 1042 |
+
HorseyExchange(exchangeAddress).unpause();
|
| 1043 |
+
HorseyToken(tokenAddress).unpause();
|
| 1044 |
+
} else {
|
| 1045 |
+
HorseyExchange(exchangeAddress).pause();
|
| 1046 |
+
HorseyToken(tokenAddress).pause();
|
| 1047 |
+
}
|
| 1048 |
+
}
|
| 1049 |
+
|
| 1050 |
+
|
| 1051 |
+
if( currentProposal.methodId == 5 ) HorseyToken(tokenAddress).setClaimingCosts(currentProposal.parameter);
|
| 1052 |
+
|
| 1053 |
+
|
| 1054 |
+
if( currentProposal.methodId == 8 ){
|
| 1055 |
+
HorseyToken(tokenAddress).setCarrotsMultiplier(uint8(currentProposal.parameter));
|
| 1056 |
+
}
|
| 1057 |
+
|
| 1058 |
+
|
| 1059 |
+
if( currentProposal.methodId == 9 ){
|
| 1060 |
+
HorseyToken(tokenAddress).setRarityMultiplier(uint8(currentProposal.parameter));
|
| 1061 |
+
}
|
| 1062 |
+
|
| 1063 |
+
emit ProposalPassed(currentProposal.methodId,currentProposal.parameter,currentProposal.proposer);
|
| 1064 |
+
}
|
| 1065 |
+
|
| 1066 |
+
|
| 1067 |
+
modifier validAddress(address addr) {
|
| 1068 |
+
require(addr != address(0),"Address is zero");
|
| 1069 |
+
_;
|
| 1070 |
+
}
|
| 1071 |
+
|
| 1072 |
+
|
| 1073 |
+
modifier onlyCLevelAccess() {
|
| 1074 |
+
require((jokerAddress == msg.sender) || (knightAddress == msg.sender) || (paladinAddress == msg.sender),"not c level");
|
| 1075 |
+
_;
|
| 1076 |
+
}
|
| 1077 |
+
|
| 1078 |
+
|
| 1079 |
+
|
| 1080 |
+
modifier proposalAvailable(){
|
| 1081 |
+
require(((!proposalInProgress) || ((block.timestamp - currentProposal.timestamp) > proposalLife)),"proposal already pending");
|
| 1082 |
+
_;
|
| 1083 |
+
}
|
| 1084 |
+
|
| 1085 |
+
|
| 1086 |
+
|
| 1087 |
+
modifier cooledDown( ){
|
| 1088 |
+
if(msg.sender == currentProposal.proposer && (block.timestamp - cooldownStart < 1 days)){
|
| 1089 |
+
revert("Cool down period not passed yet");
|
| 1090 |
+
}
|
| 1091 |
+
_;
|
| 1092 |
+
}
|
| 1093 |
+
|
| 1094 |
+
|
| 1095 |
+
modifier proposalPending() {
|
| 1096 |
+
require(proposalInProgress,"no proposal pending");
|
| 1097 |
+
_;
|
| 1098 |
+
}
|
| 1099 |
+
|
| 1100 |
+
|
| 1101 |
+
modifier notVoted() {
|
| 1102 |
+
uint256 length = currentProposal.yay.length;
|
| 1103 |
+
for(uint i = 0; i < length; i++) {
|
| 1104 |
+
if(currentProposal.yay[i] == msg.sender) {
|
| 1105 |
+
revert("Already voted");
|
| 1106 |
+
}
|
| 1107 |
+
}
|
| 1108 |
+
|
| 1109 |
+
length = currentProposal.nay.length;
|
| 1110 |
+
for(i = 0; i < length; i++) {
|
| 1111 |
+
if(currentProposal.nay[i] == msg.sender) {
|
| 1112 |
+
revert("Already voted");
|
| 1113 |
+
}
|
| 1114 |
+
}
|
| 1115 |
+
_;
|
| 1116 |
+
}
|
| 1117 |
+
|
| 1118 |
+
|
| 1119 |
+
modifier onlyVoters() {
|
| 1120 |
+
bool found = false;
|
| 1121 |
+
uint256 length = voters.length;
|
| 1122 |
+
for(uint i = 0; i < length; i++) {
|
| 1123 |
+
if(voters[i] == msg.sender) {
|
| 1124 |
+
found = true;
|
| 1125 |
+
break;
|
| 1126 |
+
}
|
| 1127 |
+
}
|
| 1128 |
+
if(!found) {
|
| 1129 |
+
revert("not a voter");
|
| 1130 |
+
}
|
| 1131 |
+
_;
|
| 1132 |
+
}
|
| 1133 |
+
}
|
smart_contract_dataset/block number dependency/220.sol
ADDED
|
@@ -0,0 +1,222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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
pragma solidity ^0.4.24;
|
| 2 |
+
|
| 3 |
+
library SafeMath {
|
| 4 |
+
|
| 5 |
+
|
| 6 |
+
function mul(uint256 a, uint256 b) internal pure returns (uint256 c) {
|
| 7 |
+
|
| 8 |
+
|
| 9 |
+
|
| 10 |
+
if (a == 0) {
|
| 11 |
+
return 0;
|
| 12 |
+
}
|
| 13 |
+
|
| 14 |
+
c = a * b;
|
| 15 |
+
assert(c / a == b);
|
| 16 |
+
return c;
|
| 17 |
+
}
|
| 18 |
+
|
| 19 |
+
|
| 20 |
+
function div(uint256 a, uint256 b) internal pure returns (uint256) {
|
| 21 |
+
|
| 22 |
+
|
| 23 |
+
|
| 24 |
+
return a / b;
|
| 25 |
+
}
|
| 26 |
+
|
| 27 |
+
|
| 28 |
+
function sub(uint256 a, uint256 b) internal pure returns (uint256) {
|
| 29 |
+
assert(b <= a);
|
| 30 |
+
return a - b;
|
| 31 |
+
}
|
| 32 |
+
|
| 33 |
+
|
| 34 |
+
function add(uint256 a, uint256 b) internal pure returns (uint256 c) {
|
| 35 |
+
c = a + b;
|
| 36 |
+
assert(c >= a);
|
| 37 |
+
return c;
|
| 38 |
+
}
|
| 39 |
+
}
|
| 40 |
+
|
| 41 |
+
contract Ownable {
|
| 42 |
+
address public owner;
|
| 43 |
+
|
| 44 |
+
|
| 45 |
+
event OwnershipRenounced(address indexed previousOwner);
|
| 46 |
+
event OwnershipTransferred(
|
| 47 |
+
address indexed previousOwner,
|
| 48 |
+
address indexed newOwner
|
| 49 |
+
);
|
| 50 |
+
|
| 51 |
+
|
| 52 |
+
|
| 53 |
+
constructor() public {
|
| 54 |
+
owner = msg.sender;
|
| 55 |
+
}
|
| 56 |
+
|
| 57 |
+
|
| 58 |
+
modifier onlyOwner() {
|
| 59 |
+
require(msg.sender == owner);
|
| 60 |
+
_;
|
| 61 |
+
}
|
| 62 |
+
|
| 63 |
+
|
| 64 |
+
function renounceOwnership() public onlyOwner {
|
| 65 |
+
emit OwnershipRenounced(owner);
|
| 66 |
+
owner = address(0);
|
| 67 |
+
}
|
| 68 |
+
|
| 69 |
+
|
| 70 |
+
function transferOwnership(address _newOwner) public onlyOwner {
|
| 71 |
+
_transferOwnership(_newOwner);
|
| 72 |
+
}
|
| 73 |
+
|
| 74 |
+
|
| 75 |
+
function _transferOwnership(address _newOwner) internal {
|
| 76 |
+
require(_newOwner != address(0));
|
| 77 |
+
emit OwnershipTransferred(owner, _newOwner);
|
| 78 |
+
owner = _newOwner;
|
| 79 |
+
}
|
| 80 |
+
}
|
| 81 |
+
|
| 82 |
+
contract Claimable is Ownable {
|
| 83 |
+
address public pendingOwner;
|
| 84 |
+
|
| 85 |
+
|
| 86 |
+
modifier onlyPendingOwner() {
|
| 87 |
+
require(msg.sender == pendingOwner);
|
| 88 |
+
_;
|
| 89 |
+
}
|
| 90 |
+
|
| 91 |
+
|
| 92 |
+
function transferOwnership(address newOwner) onlyOwner public {
|
| 93 |
+
pendingOwner = newOwner;
|
| 94 |
+
}
|
| 95 |
+
|
| 96 |
+
|
| 97 |
+
function claimOwnership() onlyPendingOwner public {
|
| 98 |
+
emit OwnershipTransferred(owner, pendingOwner);
|
| 99 |
+
owner = pendingOwner;
|
| 100 |
+
pendingOwner = address(0);
|
| 101 |
+
}
|
| 102 |
+
}
|
| 103 |
+
|
| 104 |
+
contract SimpleFlyDropToken is Claimable {
|
| 105 |
+
using SafeMath for uint256;
|
| 106 |
+
|
| 107 |
+
ERC20 internal erc20tk;
|
| 108 |
+
|
| 109 |
+
function setToken(address _token) onlyOwner public {
|
| 110 |
+
require(_token != address(0));
|
| 111 |
+
erc20tk = ERC20(_token);
|
| 112 |
+
}
|
| 113 |
+
|
| 114 |
+
|
| 115 |
+
function multiSend(address[] _destAddrs, uint256[] _values) onlyOwner public returns (uint256) {
|
| 116 |
+
require(_destAddrs.length == _values.length);
|
| 117 |
+
|
| 118 |
+
uint256 i = 0;
|
| 119 |
+
for (; i < _destAddrs.length; i = i.add(1)) {
|
| 120 |
+
if (!erc20tk.transfer(_destAddrs[i], _values[i])) {
|
| 121 |
+
break;
|
| 122 |
+
}
|
| 123 |
+
}
|
| 124 |
+
|
| 125 |
+
return (i);
|
| 126 |
+
}
|
| 127 |
+
}
|
| 128 |
+
|
| 129 |
+
contract DelayedClaimable is Claimable {
|
| 130 |
+
|
| 131 |
+
uint256 public end;
|
| 132 |
+
uint256 public start;
|
| 133 |
+
|
| 134 |
+
|
| 135 |
+
function setLimits(uint256 _start, uint256 _end) onlyOwner public {
|
| 136 |
+
require(_start <= _end);
|
| 137 |
+
end = _end;
|
| 138 |
+
start = _start;
|
| 139 |
+
}
|
| 140 |
+
|
| 141 |
+
|
| 142 |
+
function claimOwnership() onlyPendingOwner public {
|
| 143 |
+
require((block.number <= end) && (block.number >= start));
|
| 144 |
+
emit OwnershipTransferred(owner, pendingOwner);
|
| 145 |
+
owner = pendingOwner;
|
| 146 |
+
pendingOwner = address(0);
|
| 147 |
+
end = 0;
|
| 148 |
+
}
|
| 149 |
+
|
| 150 |
+
}
|
| 151 |
+
|
| 152 |
+
contract FlyDropTokenMgr is DelayedClaimable {
|
| 153 |
+
using SafeMath for uint256;
|
| 154 |
+
|
| 155 |
+
address[] dropTokenAddrs;
|
| 156 |
+
SimpleFlyDropToken currentDropTokenContract;
|
| 157 |
+
|
| 158 |
+
|
| 159 |
+
|
| 160 |
+
function prepare(uint256 _rand,
|
| 161 |
+
address _from,
|
| 162 |
+
address _token,
|
| 163 |
+
uint256 _value) onlyOwner public returns (bool) {
|
| 164 |
+
require(_token != address(0));
|
| 165 |
+
require(_from != address(0));
|
| 166 |
+
require(_rand > 0);
|
| 167 |
+
|
| 168 |
+
if (ERC20(_token).allowance(_from, this) < _value) {
|
| 169 |
+
return false;
|
| 170 |
+
}
|
| 171 |
+
|
| 172 |
+
if (_rand > dropTokenAddrs.length) {
|
| 173 |
+
SimpleFlyDropToken dropTokenContract = new SimpleFlyDropToken();
|
| 174 |
+
dropTokenAddrs.push(address(dropTokenContract));
|
| 175 |
+
currentDropTokenContract = dropTokenContract;
|
| 176 |
+
} else {
|
| 177 |
+
currentDropTokenContract = SimpleFlyDropToken(dropTokenAddrs[_rand.sub(1)]);
|
| 178 |
+
}
|
| 179 |
+
|
| 180 |
+
currentDropTokenContract.setToken(_token);
|
| 181 |
+
return ERC20(_token).transferFrom(_from, currentDropTokenContract, _value);
|
| 182 |
+
|
| 183 |
+
|
| 184 |
+
|
| 185 |
+
}
|
| 186 |
+
|
| 187 |
+
|
| 188 |
+
|
| 189 |
+
|
| 190 |
+
|
| 191 |
+
|
| 192 |
+
|
| 193 |
+
|
| 194 |
+
|
| 195 |
+
function flyDrop(address[] _destAddrs, uint256[] _values) onlyOwner public returns (uint256) {
|
| 196 |
+
require(address(currentDropTokenContract) != address(0));
|
| 197 |
+
return currentDropTokenContract.multiSend(_destAddrs, _values);
|
| 198 |
+
}
|
| 199 |
+
|
| 200 |
+
}
|
| 201 |
+
|
| 202 |
+
contract ERC20Basic {
|
| 203 |
+
function totalSupply() public view returns (uint256);
|
| 204 |
+
function balanceOf(address who) public view returns (uint256);
|
| 205 |
+
function transfer(address to, uint256 value) public returns (bool);
|
| 206 |
+
event Transfer(address indexed from, address indexed to, uint256 value);
|
| 207 |
+
}
|
| 208 |
+
|
| 209 |
+
contract ERC20 is ERC20Basic {
|
| 210 |
+
function allowance(address owner, address spender)
|
| 211 |
+
public view returns (uint256);
|
| 212 |
+
|
| 213 |
+
function transferFrom(address from, address to, uint256 value)
|
| 214 |
+
public returns (bool);
|
| 215 |
+
|
| 216 |
+
function approve(address spender, uint256 value) public returns (bool);
|
| 217 |
+
event Approval(
|
| 218 |
+
address indexed owner,
|
| 219 |
+
address indexed spender,
|
| 220 |
+
uint256 value
|
| 221 |
+
);
|
| 222 |
+
}
|
smart_contract_dataset/block number dependency/2295.sol
ADDED
|
@@ -0,0 +1,269 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
pragma solidity ^0.4.24;
|
| 2 |
+
|
| 3 |
+
|
| 4 |
+
contract ERC20Basic {
|
| 5 |
+
function totalSupply() public view returns (uint256);
|
| 6 |
+
function balanceOf(address who) public view returns (uint256);
|
| 7 |
+
function transfer(address to, uint256 value) public returns (bool);
|
| 8 |
+
event Transfer(address indexed from, address indexed to, uint256 value);
|
| 9 |
+
}
|
| 10 |
+
|
| 11 |
+
contract ERC20 is ERC20Basic {
|
| 12 |
+
function allowance(address owner, address spender) public view returns (uint256);
|
| 13 |
+
function transferFrom(address from, address to, uint256 value) public returns (bool);
|
| 14 |
+
function approve(address spender, uint256 value) public returns (bool);
|
| 15 |
+
event Approval(address indexed owner, address indexed spender, uint256 value);
|
| 16 |
+
}
|
| 17 |
+
|
| 18 |
+
|
| 19 |
+
contract ERC20OldBasic {
|
| 20 |
+
function totalSupply() public view returns (uint256);
|
| 21 |
+
function balanceOf(address who) public view returns (uint256);
|
| 22 |
+
function transfer(address to, uint256 value) public;
|
| 23 |
+
event Transfer(address indexed from, address indexed to, uint256 value);
|
| 24 |
+
}
|
| 25 |
+
|
| 26 |
+
|
| 27 |
+
contract ERC20Old is ERC20OldBasic {
|
| 28 |
+
function allowance(address owner, address spender) public view returns (uint256);
|
| 29 |
+
function transferFrom(address from, address to, uint256 value) public;
|
| 30 |
+
function approve(address spender, uint256 value) public returns (bool);
|
| 31 |
+
event Approval(address indexed owner, address indexed spender, uint256 value);
|
| 32 |
+
}
|
| 33 |
+
|
| 34 |
+
|
| 35 |
+
library SafeMath {
|
| 36 |
+
|
| 37 |
+
|
| 38 |
+
function mul(uint256 a, uint256 b) internal pure returns (uint256) {
|
| 39 |
+
if (a == 0) {
|
| 40 |
+
return 0;
|
| 41 |
+
}
|
| 42 |
+
uint256 c = a * b;
|
| 43 |
+
assert(c / a == b);
|
| 44 |
+
return c;
|
| 45 |
+
}
|
| 46 |
+
|
| 47 |
+
|
| 48 |
+
function div(uint256 a, uint256 b) internal pure returns (uint256) {
|
| 49 |
+
|
| 50 |
+
uint256 c = a / b;
|
| 51 |
+
|
| 52 |
+
return c;
|
| 53 |
+
}
|
| 54 |
+
|
| 55 |
+
|
| 56 |
+
function sub(uint256 a, uint256 b) internal pure returns (uint256) {
|
| 57 |
+
assert(b <= a);
|
| 58 |
+
return a - b;
|
| 59 |
+
}
|
| 60 |
+
|
| 61 |
+
|
| 62 |
+
function add(uint256 a, uint256 b) internal pure returns (uint256) {
|
| 63 |
+
uint256 c = a + b;
|
| 64 |
+
assert(c >= a);
|
| 65 |
+
return c;
|
| 66 |
+
}
|
| 67 |
+
}
|
| 68 |
+
|
| 69 |
+
|
| 70 |
+
contract BasicToken is ERC20Basic {
|
| 71 |
+
using SafeMath for uint256;
|
| 72 |
+
|
| 73 |
+
mapping(address => uint256) balances;
|
| 74 |
+
|
| 75 |
+
uint256 totalSupply_;
|
| 76 |
+
|
| 77 |
+
|
| 78 |
+
function totalSupply() public view returns (uint256) {
|
| 79 |
+
return totalSupply_;
|
| 80 |
+
}
|
| 81 |
+
|
| 82 |
+
|
| 83 |
+
function transfer(address _to, uint256 _value) public returns (bool) {
|
| 84 |
+
require(_to != address(0));
|
| 85 |
+
require(_value <= balances[msg.sender]);
|
| 86 |
+
|
| 87 |
+
|
| 88 |
+
balances[msg.sender] = balances[msg.sender].sub(_value);
|
| 89 |
+
balances[_to] = balances[_to].add(_value);
|
| 90 |
+
Transfer(msg.sender, _to, _value);
|
| 91 |
+
return true;
|
| 92 |
+
}
|
| 93 |
+
|
| 94 |
+
|
| 95 |
+
function balanceOf(address _owner) public view returns (uint256 balance) {
|
| 96 |
+
return balances[_owner];
|
| 97 |
+
}
|
| 98 |
+
|
| 99 |
+
}
|
| 100 |
+
|
| 101 |
+
|
| 102 |
+
contract Ownable {
|
| 103 |
+
address public owner;
|
| 104 |
+
|
| 105 |
+
|
| 106 |
+
event OwnershipTransferred(address indexed previousOwner, address indexed newOwner);
|
| 107 |
+
|
| 108 |
+
|
| 109 |
+
|
| 110 |
+
function Ownable() public {
|
| 111 |
+
owner = msg.sender;
|
| 112 |
+
}
|
| 113 |
+
|
| 114 |
+
|
| 115 |
+
modifier onlyOwner() {
|
| 116 |
+
require(msg.sender == owner);
|
| 117 |
+
_;
|
| 118 |
+
}
|
| 119 |
+
|
| 120 |
+
|
| 121 |
+
function transferOwnership(address newOwner) public onlyOwner {
|
| 122 |
+
require(newOwner != address(0));
|
| 123 |
+
OwnershipTransferred(owner, newOwner);
|
| 124 |
+
owner = newOwner;
|
| 125 |
+
}
|
| 126 |
+
|
| 127 |
+
}
|
| 128 |
+
|
| 129 |
+
|
| 130 |
+
|
| 131 |
+
contract WrapperLock is BasicToken, Ownable {
|
| 132 |
+
using SafeMath for uint256;
|
| 133 |
+
|
| 134 |
+
|
| 135 |
+
address public TRANSFER_PROXY;
|
| 136 |
+
mapping (address => bool) public isSigner;
|
| 137 |
+
|
| 138 |
+
bool public erc20old;
|
| 139 |
+
string public name;
|
| 140 |
+
string public symbol;
|
| 141 |
+
uint public decimals;
|
| 142 |
+
address public originalToken;
|
| 143 |
+
|
| 144 |
+
mapping (address => uint256) public depositLock;
|
| 145 |
+
mapping (address => uint256) public balances;
|
| 146 |
+
|
| 147 |
+
function WrapperLock(address _originalToken, string _name, string _symbol, uint _decimals, address _transferProxy, bool _erc20old) Ownable() {
|
| 148 |
+
originalToken = _originalToken;
|
| 149 |
+
TRANSFER_PROXY = _transferProxy;
|
| 150 |
+
name = _name;
|
| 151 |
+
symbol = _symbol;
|
| 152 |
+
decimals = _decimals;
|
| 153 |
+
isSigner[msg.sender] = true;
|
| 154 |
+
erc20old = _erc20old;
|
| 155 |
+
}
|
| 156 |
+
|
| 157 |
+
function deposit(uint _value, uint _forTime) public returns (bool success) {
|
| 158 |
+
require(_forTime >= 1);
|
| 159 |
+
require(now + _forTime * 1 hours >= depositLock[msg.sender]);
|
| 160 |
+
if (erc20old) {
|
| 161 |
+
ERC20Old(originalToken).transferFrom(msg.sender, address(this), _value);
|
| 162 |
+
} else {
|
| 163 |
+
require(ERC20(originalToken).transferFrom(msg.sender, address(this), _value));
|
| 164 |
+
}
|
| 165 |
+
balances[msg.sender] = balances[msg.sender].add(_value);
|
| 166 |
+
totalSupply_ = totalSupply_.add(_value);
|
| 167 |
+
depositLock[msg.sender] = now + _forTime * 1 hours;
|
| 168 |
+
return true;
|
| 169 |
+
}
|
| 170 |
+
|
| 171 |
+
function withdraw(
|
| 172 |
+
uint _value,
|
| 173 |
+
uint8 v,
|
| 174 |
+
bytes32 r,
|
| 175 |
+
bytes32 s,
|
| 176 |
+
uint signatureValidUntilBlock
|
| 177 |
+
)
|
| 178 |
+
public
|
| 179 |
+
returns
|
| 180 |
+
(bool success)
|
| 181 |
+
{
|
| 182 |
+
require(balanceOf(msg.sender) >= _value);
|
| 183 |
+
if (now <= depositLock[msg.sender]) {
|
| 184 |
+
require(block.number < signatureValidUntilBlock);
|
| 185 |
+
require(isValidSignature(keccak256(msg.sender, address(this), signatureValidUntilBlock), v, r, s));
|
| 186 |
+
}
|
| 187 |
+
balances[msg.sender] = balances[msg.sender].sub(_value);
|
| 188 |
+
totalSupply_ = totalSupply_.sub(_value);
|
| 189 |
+
depositLock[msg.sender] = 0;
|
| 190 |
+
if (erc20old) {
|
| 191 |
+
ERC20Old(originalToken).transfer(msg.sender, _value);
|
| 192 |
+
} else {
|
| 193 |
+
require(ERC20(originalToken).transfer(msg.sender, _value));
|
| 194 |
+
}
|
| 195 |
+
return true;
|
| 196 |
+
}
|
| 197 |
+
|
| 198 |
+
function withdrawBalanceDifference() public onlyOwner returns (bool success) {
|
| 199 |
+
require(ERC20(originalToken).balanceOf(address(this)).sub(totalSupply_) > 0);
|
| 200 |
+
if (erc20old) {
|
| 201 |
+
ERC20Old(originalToken).transfer(msg.sender, ERC20(originalToken).balanceOf(address(this)).sub(totalSupply_));
|
| 202 |
+
} else {
|
| 203 |
+
require(ERC20(originalToken).transfer(msg.sender, ERC20(originalToken).balanceOf(address(this)).sub(totalSupply_)));
|
| 204 |
+
}
|
| 205 |
+
return true;
|
| 206 |
+
}
|
| 207 |
+
|
| 208 |
+
function withdrawDifferentToken(address _differentToken, bool _erc20old) public onlyOwner returns (bool) {
|
| 209 |
+
require(_differentToken != originalToken);
|
| 210 |
+
require(ERC20(_differentToken).balanceOf(address(this)) > 0);
|
| 211 |
+
if (_erc20old) {
|
| 212 |
+
ERC20Old(_differentToken).transfer(msg.sender, ERC20(_differentToken).balanceOf(address(this)));
|
| 213 |
+
} else {
|
| 214 |
+
require(ERC20(_differentToken).transfer(msg.sender, ERC20(_differentToken).balanceOf(address(this))));
|
| 215 |
+
}
|
| 216 |
+
return true;
|
| 217 |
+
}
|
| 218 |
+
|
| 219 |
+
function transfer(address _to, uint256 _value) public returns (bool) {
|
| 220 |
+
return false;
|
| 221 |
+
}
|
| 222 |
+
|
| 223 |
+
function transferFrom(address _from, address _to, uint _value) public {
|
| 224 |
+
require(isSigner[_to] || isSigner[_from]);
|
| 225 |
+
assert(msg.sender == TRANSFER_PROXY);
|
| 226 |
+
balances[_to] = balances[_to].add(_value);
|
| 227 |
+
depositLock[_to] = depositLock[_to] > now ? depositLock[_to] : now + 1 hours;
|
| 228 |
+
balances[_from] = balances[_from].sub(_value);
|
| 229 |
+
Transfer(_from, _to, _value);
|
| 230 |
+
}
|
| 231 |
+
|
| 232 |
+
function allowance(address _owner, address _spender) public constant returns (uint) {
|
| 233 |
+
if (_spender == TRANSFER_PROXY) {
|
| 234 |
+
return 2**256 - 1;
|
| 235 |
+
}
|
| 236 |
+
}
|
| 237 |
+
|
| 238 |
+
function balanceOf(address _owner) public constant returns (uint256) {
|
| 239 |
+
return balances[_owner];
|
| 240 |
+
}
|
| 241 |
+
|
| 242 |
+
function isValidSignature(
|
| 243 |
+
bytes32 hash,
|
| 244 |
+
uint8 v,
|
| 245 |
+
bytes32 r,
|
| 246 |
+
bytes32 s
|
| 247 |
+
)
|
| 248 |
+
public
|
| 249 |
+
constant
|
| 250 |
+
returns (bool)
|
| 251 |
+
{
|
| 252 |
+
return isSigner[ecrecover(
|
| 253 |
+
keccak256("\x19Ethereum Signed Message:\n32", hash),
|
| 254 |
+
v,
|
| 255 |
+
r,
|
| 256 |
+
s
|
| 257 |
+
)];
|
| 258 |
+
}
|
| 259 |
+
|
| 260 |
+
function addSigner(address _newSigner) public {
|
| 261 |
+
require(isSigner[msg.sender]);
|
| 262 |
+
isSigner[_newSigner] = true;
|
| 263 |
+
}
|
| 264 |
+
|
| 265 |
+
function keccak(address _sender, address _wrapper, uint _validTill) public constant returns(bytes32) {
|
| 266 |
+
return keccak256(_sender, _wrapper, _validTill);
|
| 267 |
+
}
|
| 268 |
+
|
| 269 |
+
}
|
smart_contract_dataset/block number dependency/2296.sol
ADDED
|
@@ -0,0 +1,247 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
pragma solidity 0.4.24;
|
| 2 |
+
|
| 3 |
+
|
| 4 |
+
contract ERC20Basic {
|
| 5 |
+
function totalSupply() public view returns (uint256);
|
| 6 |
+
function balanceOf(address who) public view returns (uint256);
|
| 7 |
+
function transfer(address to, uint256 value) public returns (bool);
|
| 8 |
+
event Transfer(address indexed from, address indexed to, uint256 value);
|
| 9 |
+
}
|
| 10 |
+
|
| 11 |
+
contract ERC20 is ERC20Basic {
|
| 12 |
+
function allowance(address owner, address spender) public view returns (uint256);
|
| 13 |
+
function transferFrom(address from, address to, uint256 value) public returns (bool);
|
| 14 |
+
function approve(address spender, uint256 value) public returns (bool);
|
| 15 |
+
event Approval(address indexed owner, address indexed spender, uint256 value);
|
| 16 |
+
}
|
| 17 |
+
|
| 18 |
+
|
| 19 |
+
contract ERC20OldBasic {
|
| 20 |
+
function totalSupply() public view returns (uint256);
|
| 21 |
+
function balanceOf(address who) public view returns (uint256);
|
| 22 |
+
function transfer(address to, uint256 value) public;
|
| 23 |
+
event Transfer(address indexed from, address indexed to, uint256 value);
|
| 24 |
+
}
|
| 25 |
+
|
| 26 |
+
|
| 27 |
+
contract ERC20Old is ERC20OldBasic {
|
| 28 |
+
function allowance(address owner, address spender) public view returns (uint256);
|
| 29 |
+
function transferFrom(address from, address to, uint256 value) public;
|
| 30 |
+
function approve(address spender, uint256 value) public returns (bool);
|
| 31 |
+
event Approval(address indexed owner, address indexed spender, uint256 value);
|
| 32 |
+
}
|
| 33 |
+
|
| 34 |
+
|
| 35 |
+
library SafeMath {
|
| 36 |
+
|
| 37 |
+
|
| 38 |
+
function mul(uint256 a, uint256 b) internal pure returns (uint256) {
|
| 39 |
+
if (a == 0) {
|
| 40 |
+
return 0;
|
| 41 |
+
}
|
| 42 |
+
uint256 c = a * b;
|
| 43 |
+
assert(c / a == b);
|
| 44 |
+
return c;
|
| 45 |
+
}
|
| 46 |
+
|
| 47 |
+
|
| 48 |
+
function div(uint256 a, uint256 b) internal pure returns (uint256) {
|
| 49 |
+
|
| 50 |
+
uint256 c = a / b;
|
| 51 |
+
|
| 52 |
+
return c;
|
| 53 |
+
}
|
| 54 |
+
|
| 55 |
+
|
| 56 |
+
function sub(uint256 a, uint256 b) internal pure returns (uint256) {
|
| 57 |
+
assert(b <= a);
|
| 58 |
+
return a - b;
|
| 59 |
+
}
|
| 60 |
+
|
| 61 |
+
|
| 62 |
+
function add(uint256 a, uint256 b) internal pure returns (uint256) {
|
| 63 |
+
uint256 c = a + b;
|
| 64 |
+
assert(c >= a);
|
| 65 |
+
return c;
|
| 66 |
+
}
|
| 67 |
+
}
|
| 68 |
+
|
| 69 |
+
|
| 70 |
+
contract BasicToken is ERC20Basic {
|
| 71 |
+
using SafeMath for uint256;
|
| 72 |
+
|
| 73 |
+
mapping(address => uint256) balances;
|
| 74 |
+
|
| 75 |
+
uint256 totalSupply_;
|
| 76 |
+
|
| 77 |
+
|
| 78 |
+
function totalSupply() public view returns (uint256) {
|
| 79 |
+
return totalSupply_;
|
| 80 |
+
}
|
| 81 |
+
|
| 82 |
+
|
| 83 |
+
function transfer(address _to, uint256 _value) public returns (bool) {
|
| 84 |
+
require(_to != address(0));
|
| 85 |
+
require(_value <= balances[msg.sender]);
|
| 86 |
+
|
| 87 |
+
|
| 88 |
+
balances[msg.sender] = balances[msg.sender].sub(_value);
|
| 89 |
+
balances[_to] = balances[_to].add(_value);
|
| 90 |
+
Transfer(msg.sender, _to, _value);
|
| 91 |
+
return true;
|
| 92 |
+
}
|
| 93 |
+
|
| 94 |
+
|
| 95 |
+
function balanceOf(address _owner) public view returns (uint256 balance) {
|
| 96 |
+
return balances[_owner];
|
| 97 |
+
}
|
| 98 |
+
|
| 99 |
+
}
|
| 100 |
+
|
| 101 |
+
|
| 102 |
+
contract Ownable {
|
| 103 |
+
address public owner;
|
| 104 |
+
|
| 105 |
+
|
| 106 |
+
event OwnershipTransferred(address indexed previousOwner, address indexed newOwner);
|
| 107 |
+
|
| 108 |
+
|
| 109 |
+
|
| 110 |
+
function Ownable() public {
|
| 111 |
+
owner = msg.sender;
|
| 112 |
+
}
|
| 113 |
+
|
| 114 |
+
|
| 115 |
+
modifier onlyOwner() {
|
| 116 |
+
require(msg.sender == owner);
|
| 117 |
+
_;
|
| 118 |
+
}
|
| 119 |
+
|
| 120 |
+
|
| 121 |
+
function transferOwnership(address newOwner) public onlyOwner {
|
| 122 |
+
require(newOwner != address(0));
|
| 123 |
+
OwnershipTransferred(owner, newOwner);
|
| 124 |
+
owner = newOwner;
|
| 125 |
+
}
|
| 126 |
+
|
| 127 |
+
}
|
| 128 |
+
|
| 129 |
+
|
| 130 |
+
|
| 131 |
+
contract WrapperLockEth is BasicToken, Ownable {
|
| 132 |
+
using SafeMath for uint256;
|
| 133 |
+
|
| 134 |
+
address public TRANSFER_PROXY;
|
| 135 |
+
mapping (address => bool) public isSigner;
|
| 136 |
+
|
| 137 |
+
string public name;
|
| 138 |
+
string public symbol;
|
| 139 |
+
uint public decimals;
|
| 140 |
+
address public originalToken = 0x00;
|
| 141 |
+
|
| 142 |
+
mapping (address => uint) public depositLock;
|
| 143 |
+
mapping (address => uint256) public balances;
|
| 144 |
+
|
| 145 |
+
function WrapperLockEth(string _name, string _symbol, uint _decimals, address _transferProxy) Ownable() {
|
| 146 |
+
TRANSFER_PROXY = _transferProxy;
|
| 147 |
+
name = _name;
|
| 148 |
+
symbol = _symbol;
|
| 149 |
+
decimals = _decimals;
|
| 150 |
+
isSigner[msg.sender] = true;
|
| 151 |
+
}
|
| 152 |
+
|
| 153 |
+
function deposit(uint _value, uint _forTime) public payable returns (bool success) {
|
| 154 |
+
require(_forTime >= 1);
|
| 155 |
+
require(now + _forTime * 1 hours >= depositLock[msg.sender]);
|
| 156 |
+
balances[msg.sender] = balances[msg.sender].add(msg.value);
|
| 157 |
+
totalSupply_ = totalSupply_.add(msg.value);
|
| 158 |
+
depositLock[msg.sender] = now + _forTime * 1 hours;
|
| 159 |
+
return true;
|
| 160 |
+
}
|
| 161 |
+
|
| 162 |
+
function withdraw(
|
| 163 |
+
uint _value,
|
| 164 |
+
uint8 v,
|
| 165 |
+
bytes32 r,
|
| 166 |
+
bytes32 s,
|
| 167 |
+
uint signatureValidUntilBlock
|
| 168 |
+
)
|
| 169 |
+
public
|
| 170 |
+
returns
|
| 171 |
+
(bool)
|
| 172 |
+
{
|
| 173 |
+
require(balanceOf(msg.sender) >= _value);
|
| 174 |
+
if (now > depositLock[msg.sender]) {
|
| 175 |
+
balances[msg.sender] = balances[msg.sender].sub(_value);
|
| 176 |
+
totalSupply_ = totalSupply_.sub(msg.value);
|
| 177 |
+
msg.sender.transfer(_value);
|
| 178 |
+
} else {
|
| 179 |
+
require(block.number < signatureValidUntilBlock);
|
| 180 |
+
require(isValidSignature(keccak256(msg.sender, address(this), signatureValidUntilBlock), v, r, s));
|
| 181 |
+
balances[msg.sender] = balances[msg.sender].sub(_value);
|
| 182 |
+
totalSupply_ = totalSupply_.sub(msg.value);
|
| 183 |
+
depositLock[msg.sender] = 0;
|
| 184 |
+
msg.sender.transfer(_value);
|
| 185 |
+
}
|
| 186 |
+
return true;
|
| 187 |
+
}
|
| 188 |
+
|
| 189 |
+
function withdrawDifferentToken(address _token, bool _erc20old) public onlyOwner returns (bool) {
|
| 190 |
+
require(ERC20(_token).balanceOf(address(this)) > 0);
|
| 191 |
+
if (_erc20old) {
|
| 192 |
+
ERC20Old(_token).transfer(msg.sender, ERC20(_token).balanceOf(address(this)));
|
| 193 |
+
} else {
|
| 194 |
+
ERC20(_token).transfer(msg.sender, ERC20(_token).balanceOf(address(this)));
|
| 195 |
+
}
|
| 196 |
+
return true;
|
| 197 |
+
}
|
| 198 |
+
|
| 199 |
+
function transfer(address _to, uint256 _value) public returns (bool) {
|
| 200 |
+
return false;
|
| 201 |
+
}
|
| 202 |
+
|
| 203 |
+
function transferFrom(address _from, address _to, uint _value) public {
|
| 204 |
+
require(isSigner[_to] || isSigner[_from]);
|
| 205 |
+
assert(msg.sender == TRANSFER_PROXY);
|
| 206 |
+
balances[_to] = balances[_to].add(_value);
|
| 207 |
+
depositLock[_to] = depositLock[_to] > now ? depositLock[_to] : now + 1 hours;
|
| 208 |
+
balances[_from] = balances[_from].sub(_value);
|
| 209 |
+
Transfer(_from, _to, _value);
|
| 210 |
+
}
|
| 211 |
+
|
| 212 |
+
function allowance(address _owner, address _spender) public constant returns (uint) {
|
| 213 |
+
if (_spender == TRANSFER_PROXY) {
|
| 214 |
+
return 2**256 - 1;
|
| 215 |
+
}
|
| 216 |
+
}
|
| 217 |
+
|
| 218 |
+
function balanceOf(address _owner) public constant returns (uint256) {
|
| 219 |
+
return balances[_owner];
|
| 220 |
+
}
|
| 221 |
+
|
| 222 |
+
function isValidSignature(
|
| 223 |
+
bytes32 hash,
|
| 224 |
+
uint8 v,
|
| 225 |
+
bytes32 r,
|
| 226 |
+
bytes32 s)
|
| 227 |
+
public
|
| 228 |
+
constant
|
| 229 |
+
returns (bool)
|
| 230 |
+
{
|
| 231 |
+
return isSigner[ecrecover(
|
| 232 |
+
keccak256("\x19Ethereum Signed Message:\n32", hash),
|
| 233 |
+
v,
|
| 234 |
+
r,
|
| 235 |
+
s
|
| 236 |
+
)];
|
| 237 |
+
}
|
| 238 |
+
|
| 239 |
+
function addSigner(address _newSigner) public {
|
| 240 |
+
require(isSigner[msg.sender]);
|
| 241 |
+
isSigner[_newSigner] = true;
|
| 242 |
+
}
|
| 243 |
+
|
| 244 |
+
function keccak(address _sender, address _wrapper, uint _validTill) public constant returns(bytes32) {
|
| 245 |
+
return keccak256(_sender, _wrapper, _validTill);
|
| 246 |
+
}
|
| 247 |
+
}
|
smart_contract_dataset/block number dependency/238.sol
ADDED
|
@@ -0,0 +1,183 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
pragma solidity ^0.4.12;
|
| 2 |
+
|
| 3 |
+
|
| 4 |
+
|
| 5 |
+
|
| 6 |
+
|
| 7 |
+
|
| 8 |
+
contract IMigrationContract {
|
| 9 |
+
function migrate(address addr, uint256 nas) returns (bool success);
|
| 10 |
+
}
|
| 11 |
+
|
| 12 |
+
|
| 13 |
+
contract SafeMath {
|
| 14 |
+
|
| 15 |
+
|
| 16 |
+
function safeAdd(uint256 x, uint256 y) internal returns(uint256) {
|
| 17 |
+
uint256 z = x + y;
|
| 18 |
+
assert((z >= x) && (z >= y));
|
| 19 |
+
return z;
|
| 20 |
+
}
|
| 21 |
+
|
| 22 |
+
function safeSubtract(uint256 x, uint256 y) internal returns(uint256) {
|
| 23 |
+
assert(x >= y);
|
| 24 |
+
uint256 z = x - y;
|
| 25 |
+
return z;
|
| 26 |
+
}
|
| 27 |
+
|
| 28 |
+
function safeMult(uint256 x, uint256 y) internal returns(uint256) {
|
| 29 |
+
uint256 z = x * y;
|
| 30 |
+
assert((x == 0)||(z/x == y));
|
| 31 |
+
return z;
|
| 32 |
+
}
|
| 33 |
+
|
| 34 |
+
}
|
| 35 |
+
|
| 36 |
+
contract Token {
|
| 37 |
+
uint256 public totalSupply;
|
| 38 |
+
function balanceOf(address _owner) constant returns (uint256 balance);
|
| 39 |
+
function transfer(address _to, uint256 _value) returns (bool success);
|
| 40 |
+
function transferFrom(address _from, address _to, uint256 _value) returns (bool success);
|
| 41 |
+
function approve(address _spender, uint256 _value) returns (bool success);
|
| 42 |
+
function allowance(address _owner, address _spender) constant returns (uint256 remaining);
|
| 43 |
+
event Transfer(address indexed _from, address indexed _to, uint256 _value);
|
| 44 |
+
event Approval(address indexed _owner, address indexed _spender, uint256 _value);
|
| 45 |
+
}
|
| 46 |
+
|
| 47 |
+
|
| 48 |
+
|
| 49 |
+
contract StandardToken is Token {
|
| 50 |
+
|
| 51 |
+
function transfer(address _to, uint256 _value) returns (bool success) {
|
| 52 |
+
if (balances[msg.sender] >= _value && _value > 0) {
|
| 53 |
+
balances[msg.sender] -= _value;
|
| 54 |
+
balances[_to] += _value;
|
| 55 |
+
Transfer(msg.sender, _to, _value);
|
| 56 |
+
return true;
|
| 57 |
+
} else {
|
| 58 |
+
return false;
|
| 59 |
+
}
|
| 60 |
+
}
|
| 61 |
+
|
| 62 |
+
function transferFrom(address _from, address _to, uint256 _value) returns (bool success) {
|
| 63 |
+
if (balances[_from] >= _value && allowed[_from][msg.sender] >= _value && _value > 0) {
|
| 64 |
+
balances[_to] += _value;
|
| 65 |
+
balances[_from] -= _value;
|
| 66 |
+
allowed[_from][msg.sender] -= _value;
|
| 67 |
+
Transfer(_from, _to, _value);
|
| 68 |
+
return true;
|
| 69 |
+
} else {
|
| 70 |
+
return false;
|
| 71 |
+
}
|
| 72 |
+
}
|
| 73 |
+
|
| 74 |
+
function balanceOf(address _owner) constant returns (uint256 balance) {
|
| 75 |
+
return balances[_owner];
|
| 76 |
+
}
|
| 77 |
+
|
| 78 |
+
function approve(address _spender, uint256 _value) returns (bool success) {
|
| 79 |
+
allowed[msg.sender][_spender] = _value;
|
| 80 |
+
Approval(msg.sender, _spender, _value);
|
| 81 |
+
return true;
|
| 82 |
+
}
|
| 83 |
+
|
| 84 |
+
function allowance(address _owner, address _spender) constant returns (uint256 remaining) {
|
| 85 |
+
return allowed[_owner][_spender];
|
| 86 |
+
}
|
| 87 |
+
|
| 88 |
+
mapping (address => uint256) balances;
|
| 89 |
+
mapping (address => mapping (address => uint256)) allowed;
|
| 90 |
+
}
|
| 91 |
+
|
| 92 |
+
contract DEJToken is StandardToken, SafeMath {
|
| 93 |
+
|
| 94 |
+
|
| 95 |
+
string public constant name = "De Home";
|
| 96 |
+
string public constant symbol = "DEJ";
|
| 97 |
+
uint256 public constant decimals = 18;
|
| 98 |
+
string public version = "1.0";
|
| 99 |
+
|
| 100 |
+
|
| 101 |
+
address public ethFundDeposit;
|
| 102 |
+
address public newContractAddr;
|
| 103 |
+
|
| 104 |
+
|
| 105 |
+
bool public isFunding;
|
| 106 |
+
uint256 public fundingStartBlock;
|
| 107 |
+
uint256 public fundingStopBlock;
|
| 108 |
+
|
| 109 |
+
uint256 public currentSupply;
|
| 110 |
+
uint256 public tokenRaised = 0;
|
| 111 |
+
uint256 public tokenMigrated = 0;
|
| 112 |
+
|
| 113 |
+
|
| 114 |
+
|
| 115 |
+
event IncreaseSupply(uint256 _value);
|
| 116 |
+
event DecreaseSupply(uint256 _value);
|
| 117 |
+
|
| 118 |
+
|
| 119 |
+
function formatDecimals(uint256 _value) internal returns (uint256 ) {
|
| 120 |
+
return _value * 10 ** decimals;
|
| 121 |
+
}
|
| 122 |
+
|
| 123 |
+
|
| 124 |
+
function DEJToken()
|
| 125 |
+
{
|
| 126 |
+
ethFundDeposit = 0x697e6C6845212AE294E55E0adB13977de0F0BD37;
|
| 127 |
+
|
| 128 |
+
isFunding = false;
|
| 129 |
+
fundingStartBlock = 0;
|
| 130 |
+
fundingStopBlock = 0;
|
| 131 |
+
|
| 132 |
+
currentSupply = formatDecimals(1000000000);
|
| 133 |
+
totalSupply = formatDecimals(1000000000);
|
| 134 |
+
balances[msg.sender] = totalSupply;
|
| 135 |
+
if(currentSupply > totalSupply) throw;
|
| 136 |
+
}
|
| 137 |
+
|
| 138 |
+
modifier isOwner() { require(msg.sender == ethFundDeposit); _; }
|
| 139 |
+
|
| 140 |
+
|
| 141 |
+
|
| 142 |
+
|
| 143 |
+
function increaseSupply (uint256 _value) isOwner external {
|
| 144 |
+
uint256 value = formatDecimals(_value);
|
| 145 |
+
if (value + currentSupply > totalSupply) throw;
|
| 146 |
+
currentSupply = safeAdd(currentSupply, value);
|
| 147 |
+
IncreaseSupply(value);
|
| 148 |
+
}
|
| 149 |
+
|
| 150 |
+
|
| 151 |
+
function decreaseSupply (uint256 _value) isOwner external {
|
| 152 |
+
uint256 value = formatDecimals(_value);
|
| 153 |
+
if (value + tokenRaised > currentSupply) throw;
|
| 154 |
+
|
| 155 |
+
currentSupply = safeSubtract(currentSupply, value);
|
| 156 |
+
DecreaseSupply(value);
|
| 157 |
+
}
|
| 158 |
+
|
| 159 |
+
|
| 160 |
+
function startFunding (uint256 _fundingStartBlock, uint256 _fundingStopBlock) isOwner external {
|
| 161 |
+
if (isFunding) throw;
|
| 162 |
+
if (_fundingStartBlock >= _fundingStopBlock) throw;
|
| 163 |
+
if (block.number >= _fundingStartBlock) throw;
|
| 164 |
+
|
| 165 |
+
fundingStartBlock = _fundingStartBlock;
|
| 166 |
+
fundingStopBlock = _fundingStopBlock;
|
| 167 |
+
isFunding = true;
|
| 168 |
+
}
|
| 169 |
+
|
| 170 |
+
|
| 171 |
+
function stopFunding() isOwner external {
|
| 172 |
+
if (!isFunding) throw;
|
| 173 |
+
isFunding = false;
|
| 174 |
+
}
|
| 175 |
+
|
| 176 |
+
|
| 177 |
+
|
| 178 |
+
|
| 179 |
+
function transferETH() isOwner external {
|
| 180 |
+
if (this.balance == 0) throw;
|
| 181 |
+
if (!ethFundDeposit.send(this.balance)) throw;
|
| 182 |
+
}
|
| 183 |
+
}
|
smart_contract_dataset/block number dependency/246.sol
ADDED
|
@@ -0,0 +1,1532 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
pragma solidity ^0.4.24;
|
| 2 |
+
|
| 3 |
+
|
| 4 |
+
|
| 5 |
+
contract PEpsilon {
|
| 6 |
+
Pinakion public pinakion;
|
| 7 |
+
Kleros public court;
|
| 8 |
+
|
| 9 |
+
uint public balance;
|
| 10 |
+
uint public disputeID;
|
| 11 |
+
uint public desiredOutcome;
|
| 12 |
+
uint public epsilon;
|
| 13 |
+
bool public settled;
|
| 14 |
+
uint public maxAppeals;
|
| 15 |
+
mapping (address => uint) public withdraw;
|
| 16 |
+
|
| 17 |
+
address public attacker;
|
| 18 |
+
uint public remainingWithdraw;
|
| 19 |
+
|
| 20 |
+
modifier onlyBy(address _account) {require(msg.sender == _account); _;}
|
| 21 |
+
|
| 22 |
+
event AmountShift(uint val, uint epsilon ,address juror);
|
| 23 |
+
event Log(uint val, address addr, string message);
|
| 24 |
+
|
| 25 |
+
|
| 26 |
+
constructor(Pinakion _pinakion, Kleros _kleros, uint _disputeID, uint _desiredOutcome, uint _epsilon, uint _maxAppeals) public {
|
| 27 |
+
pinakion = _pinakion;
|
| 28 |
+
court = _kleros;
|
| 29 |
+
disputeID = _disputeID;
|
| 30 |
+
desiredOutcome = _desiredOutcome;
|
| 31 |
+
epsilon = _epsilon;
|
| 32 |
+
attacker = msg.sender;
|
| 33 |
+
maxAppeals = _maxAppeals;
|
| 34 |
+
}
|
| 35 |
+
|
| 36 |
+
|
| 37 |
+
function receiveApproval(address _from, uint _amount, address, bytes) public onlyBy(pinakion) {
|
| 38 |
+
require(pinakion.transferFrom(_from, this, _amount));
|
| 39 |
+
|
| 40 |
+
balance += _amount;
|
| 41 |
+
}
|
| 42 |
+
|
| 43 |
+
|
| 44 |
+
function withdrawJuror() {
|
| 45 |
+
withdrawSelect(msg.sender);
|
| 46 |
+
}
|
| 47 |
+
|
| 48 |
+
|
| 49 |
+
function withdrawSelect(address _juror) {
|
| 50 |
+
uint amount = withdraw[_juror];
|
| 51 |
+
withdraw[_juror] = 0;
|
| 52 |
+
|
| 53 |
+
balance = sub(balance, amount);
|
| 54 |
+
remainingWithdraw = sub(remainingWithdraw, amount);
|
| 55 |
+
|
| 56 |
+
|
| 57 |
+
require(pinakion.transfer(_juror, amount));
|
| 58 |
+
}
|
| 59 |
+
|
| 60 |
+
|
| 61 |
+
function sub(uint256 _a, uint256 _b) internal pure returns (uint256) {
|
| 62 |
+
assert(_b <= _a);
|
| 63 |
+
return _a - _b;
|
| 64 |
+
}
|
| 65 |
+
|
| 66 |
+
|
| 67 |
+
function withdrawAttacker(){
|
| 68 |
+
require(settled);
|
| 69 |
+
|
| 70 |
+
if (balance > remainingWithdraw) {
|
| 71 |
+
|
| 72 |
+
uint amount = balance - remainingWithdraw;
|
| 73 |
+
balance = remainingWithdraw;
|
| 74 |
+
|
| 75 |
+
require(pinakion.transfer(attacker, amount));
|
| 76 |
+
}
|
| 77 |
+
}
|
| 78 |
+
|
| 79 |
+
|
| 80 |
+
function settle() public {
|
| 81 |
+
require(court.disputeStatus(disputeID) == Arbitrator.DisputeStatus.Solved);
|
| 82 |
+
require(!settled);
|
| 83 |
+
|
| 84 |
+
settled = true;
|
| 85 |
+
|
| 86 |
+
|
| 87 |
+
var (, , appeals, choices, , , ,) = court.disputes(disputeID);
|
| 88 |
+
|
| 89 |
+
if (court.currentRuling(disputeID) != desiredOutcome){
|
| 90 |
+
|
| 91 |
+
uint amountShift = court.getStakePerDraw();
|
| 92 |
+
uint winningChoice = court.getWinningChoice(disputeID, appeals);
|
| 93 |
+
|
| 94 |
+
|
| 95 |
+
for (uint i=0; i <= (appeals > maxAppeals ? maxAppeals : appeals); i++){
|
| 96 |
+
|
| 97 |
+
|
| 98 |
+
|
| 99 |
+
if (winningChoice != 0){
|
| 100 |
+
|
| 101 |
+
|
| 102 |
+
uint votesLen = 0;
|
| 103 |
+
for (uint c = 0; c <= choices; c++) {
|
| 104 |
+
votesLen += court.getVoteCount(disputeID, i, c);
|
| 105 |
+
}
|
| 106 |
+
|
| 107 |
+
emit Log(amountShift, 0x0 ,"stakePerDraw");
|
| 108 |
+
emit Log(votesLen, 0x0, "votesLen");
|
| 109 |
+
|
| 110 |
+
uint totalToRedistribute = 0;
|
| 111 |
+
uint nbCoherent = 0;
|
| 112 |
+
|
| 113 |
+
|
| 114 |
+
for (uint j=0; j < votesLen; j++){
|
| 115 |
+
uint voteRuling = court.getVoteRuling(disputeID, i, j);
|
| 116 |
+
address voteAccount = court.getVoteAccount(disputeID, i, j);
|
| 117 |
+
|
| 118 |
+
emit Log(voteRuling, voteAccount, "voted");
|
| 119 |
+
|
| 120 |
+
if (voteRuling != winningChoice){
|
| 121 |
+
totalToRedistribute += amountShift;
|
| 122 |
+
|
| 123 |
+
if (voteRuling == desiredOutcome){
|
| 124 |
+
|
| 125 |
+
withdraw[voteAccount] += amountShift + epsilon;
|
| 126 |
+
remainingWithdraw += amountShift + epsilon;
|
| 127 |
+
emit AmountShift(amountShift, epsilon, voteAccount);
|
| 128 |
+
}
|
| 129 |
+
} else {
|
| 130 |
+
nbCoherent++;
|
| 131 |
+
}
|
| 132 |
+
}
|
| 133 |
+
|
| 134 |
+
uint toRedistribute = (totalToRedistribute - amountShift) / (nbCoherent + 1);
|
| 135 |
+
|
| 136 |
+
|
| 137 |
+
for (j = 0; j < votesLen; j++){
|
| 138 |
+
voteRuling = court.getVoteRuling(disputeID, i, j);
|
| 139 |
+
voteAccount = court.getVoteAccount(disputeID, i, j);
|
| 140 |
+
|
| 141 |
+
if (voteRuling == desiredOutcome){
|
| 142 |
+
|
| 143 |
+
withdraw[voteAccount] += toRedistribute;
|
| 144 |
+
remainingWithdraw += toRedistribute;
|
| 145 |
+
emit AmountShift(toRedistribute, 0, voteAccount);
|
| 146 |
+
}
|
| 147 |
+
}
|
| 148 |
+
}
|
| 149 |
+
}
|
| 150 |
+
}
|
| 151 |
+
}
|
| 152 |
+
}
|
| 153 |
+
|
| 154 |
+
|
| 155 |
+
|
| 156 |
+
pragma solidity ^0.4.24;
|
| 157 |
+
|
| 158 |
+
|
| 159 |
+
contract ApproveAndCallFallBack {
|
| 160 |
+
function receiveApproval(address from, uint256 _amount, address _token, bytes _data) public;
|
| 161 |
+
}
|
| 162 |
+
|
| 163 |
+
|
| 164 |
+
contract TokenController {
|
| 165 |
+
|
| 166 |
+
|
| 167 |
+
|
| 168 |
+
function proxyPayment(address _owner) public payable returns(bool);
|
| 169 |
+
|
| 170 |
+
|
| 171 |
+
|
| 172 |
+
|
| 173 |
+
|
| 174 |
+
|
| 175 |
+
|
| 176 |
+
function onTransfer(address _from, address _to, uint _amount) public returns(bool);
|
| 177 |
+
|
| 178 |
+
|
| 179 |
+
|
| 180 |
+
|
| 181 |
+
|
| 182 |
+
|
| 183 |
+
|
| 184 |
+
function onApprove(address _owner, address _spender, uint _amount) public
|
| 185 |
+
returns(bool);
|
| 186 |
+
}
|
| 187 |
+
|
| 188 |
+
contract Controlled {
|
| 189 |
+
|
| 190 |
+
|
| 191 |
+
modifier onlyController { require(msg.sender == controller); _; }
|
| 192 |
+
|
| 193 |
+
address public controller;
|
| 194 |
+
|
| 195 |
+
function Controlled() public { controller = msg.sender;}
|
| 196 |
+
|
| 197 |
+
|
| 198 |
+
|
| 199 |
+
function changeController(address _newController) public onlyController {
|
| 200 |
+
controller = _newController;
|
| 201 |
+
}
|
| 202 |
+
}
|
| 203 |
+
|
| 204 |
+
|
| 205 |
+
|
| 206 |
+
|
| 207 |
+
contract Pinakion is Controlled {
|
| 208 |
+
|
| 209 |
+
string public name;
|
| 210 |
+
uint8 public decimals;
|
| 211 |
+
string public symbol;
|
| 212 |
+
string public version = 'MMT_0.2';
|
| 213 |
+
|
| 214 |
+
|
| 215 |
+
|
| 216 |
+
|
| 217 |
+
|
| 218 |
+
struct Checkpoint {
|
| 219 |
+
|
| 220 |
+
|
| 221 |
+
uint128 fromBlock;
|
| 222 |
+
|
| 223 |
+
|
| 224 |
+
uint128 value;
|
| 225 |
+
}
|
| 226 |
+
|
| 227 |
+
|
| 228 |
+
|
| 229 |
+
Pinakion public parentToken;
|
| 230 |
+
|
| 231 |
+
|
| 232 |
+
|
| 233 |
+
uint public parentSnapShotBlock;
|
| 234 |
+
|
| 235 |
+
|
| 236 |
+
uint public creationBlock;
|
| 237 |
+
|
| 238 |
+
|
| 239 |
+
|
| 240 |
+
|
| 241 |
+
mapping (address => Checkpoint[]) balances;
|
| 242 |
+
|
| 243 |
+
|
| 244 |
+
mapping (address => mapping (address => uint256)) allowed;
|
| 245 |
+
|
| 246 |
+
|
| 247 |
+
Checkpoint[] totalSupplyHistory;
|
| 248 |
+
|
| 249 |
+
|
| 250 |
+
bool public transfersEnabled;
|
| 251 |
+
|
| 252 |
+
|
| 253 |
+
MiniMeTokenFactory public tokenFactory;
|
| 254 |
+
|
| 255 |
+
|
| 256 |
+
|
| 257 |
+
|
| 258 |
+
|
| 259 |
+
|
| 260 |
+
|
| 261 |
+
|
| 262 |
+
|
| 263 |
+
|
| 264 |
+
|
| 265 |
+
|
| 266 |
+
|
| 267 |
+
|
| 268 |
+
|
| 269 |
+
|
| 270 |
+
|
| 271 |
+
|
| 272 |
+
function Pinakion(
|
| 273 |
+
address _tokenFactory,
|
| 274 |
+
address _parentToken,
|
| 275 |
+
uint _parentSnapShotBlock,
|
| 276 |
+
string _tokenName,
|
| 277 |
+
uint8 _decimalUnits,
|
| 278 |
+
string _tokenSymbol,
|
| 279 |
+
bool _transfersEnabled
|
| 280 |
+
) public {
|
| 281 |
+
tokenFactory = MiniMeTokenFactory(_tokenFactory);
|
| 282 |
+
name = _tokenName;
|
| 283 |
+
decimals = _decimalUnits;
|
| 284 |
+
symbol = _tokenSymbol;
|
| 285 |
+
parentToken = Pinakion(_parentToken);
|
| 286 |
+
parentSnapShotBlock = _parentSnapShotBlock;
|
| 287 |
+
transfersEnabled = _transfersEnabled;
|
| 288 |
+
creationBlock = block.number;
|
| 289 |
+
}
|
| 290 |
+
|
| 291 |
+
|
| 292 |
+
|
| 293 |
+
|
| 294 |
+
|
| 295 |
+
|
| 296 |
+
|
| 297 |
+
|
| 298 |
+
|
| 299 |
+
|
| 300 |
+
function transfer(address _to, uint256 _amount) public returns (bool success) {
|
| 301 |
+
require(transfersEnabled);
|
| 302 |
+
doTransfer(msg.sender, _to, _amount);
|
| 303 |
+
return true;
|
| 304 |
+
}
|
| 305 |
+
|
| 306 |
+
|
| 307 |
+
|
| 308 |
+
|
| 309 |
+
|
| 310 |
+
|
| 311 |
+
|
| 312 |
+
function transferFrom(address _from, address _to, uint256 _amount
|
| 313 |
+
) public returns (bool success) {
|
| 314 |
+
|
| 315 |
+
|
| 316 |
+
|
| 317 |
+
|
| 318 |
+
|
| 319 |
+
if (msg.sender != controller) {
|
| 320 |
+
require(transfersEnabled);
|
| 321 |
+
|
| 322 |
+
|
| 323 |
+
require(allowed[_from][msg.sender] >= _amount);
|
| 324 |
+
allowed[_from][msg.sender] -= _amount;
|
| 325 |
+
}
|
| 326 |
+
doTransfer(_from, _to, _amount);
|
| 327 |
+
return true;
|
| 328 |
+
}
|
| 329 |
+
|
| 330 |
+
|
| 331 |
+
|
| 332 |
+
|
| 333 |
+
|
| 334 |
+
|
| 335 |
+
|
| 336 |
+
function doTransfer(address _from, address _to, uint _amount
|
| 337 |
+
) internal {
|
| 338 |
+
|
| 339 |
+
if (_amount == 0) {
|
| 340 |
+
Transfer(_from, _to, _amount);
|
| 341 |
+
return;
|
| 342 |
+
}
|
| 343 |
+
|
| 344 |
+
require(parentSnapShotBlock < block.number);
|
| 345 |
+
|
| 346 |
+
|
| 347 |
+
require((_to != 0) && (_to != address(this)));
|
| 348 |
+
|
| 349 |
+
|
| 350 |
+
|
| 351 |
+
var previousBalanceFrom = balanceOfAt(_from, block.number);
|
| 352 |
+
|
| 353 |
+
require(previousBalanceFrom >= _amount);
|
| 354 |
+
|
| 355 |
+
|
| 356 |
+
if (isContract(controller)) {
|
| 357 |
+
require(TokenController(controller).onTransfer(_from, _to, _amount));
|
| 358 |
+
}
|
| 359 |
+
|
| 360 |
+
|
| 361 |
+
|
| 362 |
+
updateValueAtNow(balances[_from], previousBalanceFrom - _amount);
|
| 363 |
+
|
| 364 |
+
|
| 365 |
+
|
| 366 |
+
var previousBalanceTo = balanceOfAt(_to, block.number);
|
| 367 |
+
require(previousBalanceTo + _amount >= previousBalanceTo);
|
| 368 |
+
updateValueAtNow(balances[_to], previousBalanceTo + _amount);
|
| 369 |
+
|
| 370 |
+
|
| 371 |
+
Transfer(_from, _to, _amount);
|
| 372 |
+
|
| 373 |
+
}
|
| 374 |
+
|
| 375 |
+
|
| 376 |
+
|
| 377 |
+
function balanceOf(address _owner) public constant returns (uint256 balance) {
|
| 378 |
+
return balanceOfAt(_owner, block.number);
|
| 379 |
+
}
|
| 380 |
+
|
| 381 |
+
|
| 382 |
+
|
| 383 |
+
|
| 384 |
+
|
| 385 |
+
|
| 386 |
+
function approve(address _spender, uint256 _amount) public returns (bool success) {
|
| 387 |
+
require(transfersEnabled);
|
| 388 |
+
|
| 389 |
+
|
| 390 |
+
if (isContract(controller)) {
|
| 391 |
+
require(TokenController(controller).onApprove(msg.sender, _spender, _amount));
|
| 392 |
+
}
|
| 393 |
+
|
| 394 |
+
allowed[msg.sender][_spender] = _amount;
|
| 395 |
+
Approval(msg.sender, _spender, _amount);
|
| 396 |
+
return true;
|
| 397 |
+
}
|
| 398 |
+
|
| 399 |
+
|
| 400 |
+
|
| 401 |
+
|
| 402 |
+
|
| 403 |
+
|
| 404 |
+
function allowance(address _owner, address _spender
|
| 405 |
+
) public constant returns (uint256 remaining) {
|
| 406 |
+
return allowed[_owner][_spender];
|
| 407 |
+
}
|
| 408 |
+
|
| 409 |
+
|
| 410 |
+
|
| 411 |
+
|
| 412 |
+
|
| 413 |
+
|
| 414 |
+
|
| 415 |
+
|
| 416 |
+
function approveAndCall(address _spender, uint256 _amount, bytes _extraData
|
| 417 |
+
) public returns (bool success) {
|
| 418 |
+
require(approve(_spender, _amount));
|
| 419 |
+
|
| 420 |
+
ApproveAndCallFallBack(_spender).receiveApproval(
|
| 421 |
+
msg.sender,
|
| 422 |
+
_amount,
|
| 423 |
+
this,
|
| 424 |
+
_extraData
|
| 425 |
+
);
|
| 426 |
+
|
| 427 |
+
return true;
|
| 428 |
+
}
|
| 429 |
+
|
| 430 |
+
|
| 431 |
+
|
| 432 |
+
function totalSupply() public constant returns (uint) {
|
| 433 |
+
return totalSupplyAt(block.number);
|
| 434 |
+
}
|
| 435 |
+
|
| 436 |
+
|
| 437 |
+
|
| 438 |
+
|
| 439 |
+
|
| 440 |
+
|
| 441 |
+
|
| 442 |
+
|
| 443 |
+
|
| 444 |
+
|
| 445 |
+
function balanceOfAt(address _owner, uint _blockNumber) public constant
|
| 446 |
+
returns (uint) {
|
| 447 |
+
|
| 448 |
+
|
| 449 |
+
|
| 450 |
+
|
| 451 |
+
|
| 452 |
+
|
| 453 |
+
if ((balances[_owner].length == 0)
|
| 454 |
+
|| (balances[_owner][0].fromBlock > _blockNumber)) {
|
| 455 |
+
if (address(parentToken) != 0) {
|
| 456 |
+
return parentToken.balanceOfAt(_owner, min(_blockNumber, parentSnapShotBlock));
|
| 457 |
+
} else {
|
| 458 |
+
|
| 459 |
+
return 0;
|
| 460 |
+
}
|
| 461 |
+
|
| 462 |
+
|
| 463 |
+
} else {
|
| 464 |
+
return getValueAt(balances[_owner], _blockNumber);
|
| 465 |
+
}
|
| 466 |
+
}
|
| 467 |
+
|
| 468 |
+
|
| 469 |
+
|
| 470 |
+
|
| 471 |
+
function totalSupplyAt(uint _blockNumber) public constant returns(uint) {
|
| 472 |
+
|
| 473 |
+
|
| 474 |
+
|
| 475 |
+
|
| 476 |
+
|
| 477 |
+
|
| 478 |
+
if ((totalSupplyHistory.length == 0)
|
| 479 |
+
|| (totalSupplyHistory[0].fromBlock > _blockNumber)) {
|
| 480 |
+
if (address(parentToken) != 0) {
|
| 481 |
+
return parentToken.totalSupplyAt(min(_blockNumber, parentSnapShotBlock));
|
| 482 |
+
} else {
|
| 483 |
+
return 0;
|
| 484 |
+
}
|
| 485 |
+
|
| 486 |
+
|
| 487 |
+
} else {
|
| 488 |
+
return getValueAt(totalSupplyHistory, _blockNumber);
|
| 489 |
+
}
|
| 490 |
+
}
|
| 491 |
+
|
| 492 |
+
|
| 493 |
+
|
| 494 |
+
|
| 495 |
+
|
| 496 |
+
|
| 497 |
+
|
| 498 |
+
|
| 499 |
+
|
| 500 |
+
|
| 501 |
+
|
| 502 |
+
|
| 503 |
+
|
| 504 |
+
|
| 505 |
+
|
| 506 |
+
function createCloneToken(
|
| 507 |
+
string _cloneTokenName,
|
| 508 |
+
uint8 _cloneDecimalUnits,
|
| 509 |
+
string _cloneTokenSymbol,
|
| 510 |
+
uint _snapshotBlock,
|
| 511 |
+
bool _transfersEnabled
|
| 512 |
+
) public returns(address) {
|
| 513 |
+
if (_snapshotBlock == 0) _snapshotBlock = block.number;
|
| 514 |
+
Pinakion cloneToken = tokenFactory.createCloneToken(
|
| 515 |
+
this,
|
| 516 |
+
_snapshotBlock,
|
| 517 |
+
_cloneTokenName,
|
| 518 |
+
_cloneDecimalUnits,
|
| 519 |
+
_cloneTokenSymbol,
|
| 520 |
+
_transfersEnabled
|
| 521 |
+
);
|
| 522 |
+
|
| 523 |
+
cloneToken.changeController(msg.sender);
|
| 524 |
+
|
| 525 |
+
|
| 526 |
+
NewCloneToken(address(cloneToken), _snapshotBlock);
|
| 527 |
+
return address(cloneToken);
|
| 528 |
+
}
|
| 529 |
+
|
| 530 |
+
|
| 531 |
+
|
| 532 |
+
|
| 533 |
+
|
| 534 |
+
|
| 535 |
+
|
| 536 |
+
|
| 537 |
+
|
| 538 |
+
function generateTokens(address _owner, uint _amount
|
| 539 |
+
) public onlyController returns (bool) {
|
| 540 |
+
uint curTotalSupply = totalSupply();
|
| 541 |
+
require(curTotalSupply + _amount >= curTotalSupply);
|
| 542 |
+
uint previousBalanceTo = balanceOf(_owner);
|
| 543 |
+
require(previousBalanceTo + _amount >= previousBalanceTo);
|
| 544 |
+
updateValueAtNow(totalSupplyHistory, curTotalSupply + _amount);
|
| 545 |
+
updateValueAtNow(balances[_owner], previousBalanceTo + _amount);
|
| 546 |
+
Transfer(0, _owner, _amount);
|
| 547 |
+
return true;
|
| 548 |
+
}
|
| 549 |
+
|
| 550 |
+
|
| 551 |
+
|
| 552 |
+
|
| 553 |
+
|
| 554 |
+
|
| 555 |
+
function destroyTokens(address _owner, uint _amount
|
| 556 |
+
) onlyController public returns (bool) {
|
| 557 |
+
uint curTotalSupply = totalSupply();
|
| 558 |
+
require(curTotalSupply >= _amount);
|
| 559 |
+
uint previousBalanceFrom = balanceOf(_owner);
|
| 560 |
+
require(previousBalanceFrom >= _amount);
|
| 561 |
+
updateValueAtNow(totalSupplyHistory, curTotalSupply - _amount);
|
| 562 |
+
updateValueAtNow(balances[_owner], previousBalanceFrom - _amount);
|
| 563 |
+
Transfer(_owner, 0, _amount);
|
| 564 |
+
return true;
|
| 565 |
+
}
|
| 566 |
+
|
| 567 |
+
|
| 568 |
+
|
| 569 |
+
|
| 570 |
+
|
| 571 |
+
|
| 572 |
+
|
| 573 |
+
|
| 574 |
+
function enableTransfers(bool _transfersEnabled) public onlyController {
|
| 575 |
+
transfersEnabled = _transfersEnabled;
|
| 576 |
+
}
|
| 577 |
+
|
| 578 |
+
|
| 579 |
+
|
| 580 |
+
|
| 581 |
+
|
| 582 |
+
|
| 583 |
+
|
| 584 |
+
|
| 585 |
+
|
| 586 |
+
function getValueAt(Checkpoint[] storage checkpoints, uint _block
|
| 587 |
+
) constant internal returns (uint) {
|
| 588 |
+
if (checkpoints.length == 0) return 0;
|
| 589 |
+
|
| 590 |
+
|
| 591 |
+
if (_block >= checkpoints[checkpoints.length-1].fromBlock)
|
| 592 |
+
return checkpoints[checkpoints.length-1].value;
|
| 593 |
+
if (_block < checkpoints[0].fromBlock) return 0;
|
| 594 |
+
|
| 595 |
+
|
| 596 |
+
uint min = 0;
|
| 597 |
+
uint max = checkpoints.length-1;
|
| 598 |
+
while (max > min) {
|
| 599 |
+
uint mid = (max + min + 1)/ 2;
|
| 600 |
+
if (checkpoints[mid].fromBlock<=_block) {
|
| 601 |
+
min = mid;
|
| 602 |
+
} else {
|
| 603 |
+
max = mid-1;
|
| 604 |
+
}
|
| 605 |
+
}
|
| 606 |
+
return checkpoints[min].value;
|
| 607 |
+
}
|
| 608 |
+
|
| 609 |
+
|
| 610 |
+
|
| 611 |
+
|
| 612 |
+
|
| 613 |
+
function updateValueAtNow(Checkpoint[] storage checkpoints, uint _value
|
| 614 |
+
) internal {
|
| 615 |
+
if ((checkpoints.length == 0)
|
| 616 |
+
|| (checkpoints[checkpoints.length -1].fromBlock < block.number)) {
|
| 617 |
+
Checkpoint storage newCheckPoint = checkpoints[ checkpoints.length++ ];
|
| 618 |
+
newCheckPoint.fromBlock = uint128(block.number);
|
| 619 |
+
newCheckPoint.value = uint128(_value);
|
| 620 |
+
} else {
|
| 621 |
+
Checkpoint storage oldCheckPoint = checkpoints[checkpoints.length-1];
|
| 622 |
+
oldCheckPoint.value = uint128(_value);
|
| 623 |
+
}
|
| 624 |
+
}
|
| 625 |
+
|
| 626 |
+
|
| 627 |
+
|
| 628 |
+
|
| 629 |
+
function isContract(address _addr) constant internal returns(bool) {
|
| 630 |
+
uint size;
|
| 631 |
+
if (_addr == 0) return false;
|
| 632 |
+
assembly {
|
| 633 |
+
size := extcodesize(_addr)
|
| 634 |
+
}
|
| 635 |
+
return size>0;
|
| 636 |
+
}
|
| 637 |
+
|
| 638 |
+
|
| 639 |
+
function min(uint a, uint b) pure internal returns (uint) {
|
| 640 |
+
return a < b ? a : b;
|
| 641 |
+
}
|
| 642 |
+
|
| 643 |
+
|
| 644 |
+
|
| 645 |
+
|
| 646 |
+
function () public payable {
|
| 647 |
+
require(isContract(controller));
|
| 648 |
+
require(TokenController(controller).proxyPayment.value(msg.value)(msg.sender));
|
| 649 |
+
}
|
| 650 |
+
|
| 651 |
+
|
| 652 |
+
|
| 653 |
+
|
| 654 |
+
|
| 655 |
+
|
| 656 |
+
|
| 657 |
+
|
| 658 |
+
|
| 659 |
+
function claimTokens(address _token) public onlyController {
|
| 660 |
+
if (_token == 0x0) {
|
| 661 |
+
controller.transfer(this.balance);
|
| 662 |
+
return;
|
| 663 |
+
}
|
| 664 |
+
|
| 665 |
+
Pinakion token = Pinakion(_token);
|
| 666 |
+
uint balance = token.balanceOf(this);
|
| 667 |
+
token.transfer(controller, balance);
|
| 668 |
+
ClaimedTokens(_token, controller, balance);
|
| 669 |
+
}
|
| 670 |
+
|
| 671 |
+
|
| 672 |
+
|
| 673 |
+
|
| 674 |
+
event ClaimedTokens(address indexed _token, address indexed _controller, uint _amount);
|
| 675 |
+
event Transfer(address indexed _from, address indexed _to, uint256 _amount);
|
| 676 |
+
event NewCloneToken(address indexed _cloneToken, uint _snapshotBlock);
|
| 677 |
+
event Approval(
|
| 678 |
+
address indexed _owner,
|
| 679 |
+
address indexed _spender,
|
| 680 |
+
uint256 _amount
|
| 681 |
+
);
|
| 682 |
+
|
| 683 |
+
}
|
| 684 |
+
|
| 685 |
+
|
| 686 |
+
|
| 687 |
+
|
| 688 |
+
|
| 689 |
+
|
| 690 |
+
|
| 691 |
+
|
| 692 |
+
|
| 693 |
+
contract MiniMeTokenFactory {
|
| 694 |
+
|
| 695 |
+
|
| 696 |
+
|
| 697 |
+
|
| 698 |
+
|
| 699 |
+
|
| 700 |
+
|
| 701 |
+
|
| 702 |
+
|
| 703 |
+
|
| 704 |
+
|
| 705 |
+
function createCloneToken(
|
| 706 |
+
address _parentToken,
|
| 707 |
+
uint _snapshotBlock,
|
| 708 |
+
string _tokenName,
|
| 709 |
+
uint8 _decimalUnits,
|
| 710 |
+
string _tokenSymbol,
|
| 711 |
+
bool _transfersEnabled
|
| 712 |
+
) public returns (Pinakion) {
|
| 713 |
+
Pinakion newToken = new Pinakion(
|
| 714 |
+
this,
|
| 715 |
+
_parentToken,
|
| 716 |
+
_snapshotBlock,
|
| 717 |
+
_tokenName,
|
| 718 |
+
_decimalUnits,
|
| 719 |
+
_tokenSymbol,
|
| 720 |
+
_transfersEnabled
|
| 721 |
+
);
|
| 722 |
+
|
| 723 |
+
newToken.changeController(msg.sender);
|
| 724 |
+
return newToken;
|
| 725 |
+
}
|
| 726 |
+
}
|
| 727 |
+
|
| 728 |
+
contract RNG{
|
| 729 |
+
|
| 730 |
+
|
| 731 |
+
function contribute(uint _block) public payable;
|
| 732 |
+
|
| 733 |
+
|
| 734 |
+
function requestRN(uint _block) public payable {
|
| 735 |
+
contribute(_block);
|
| 736 |
+
}
|
| 737 |
+
|
| 738 |
+
|
| 739 |
+
function getRN(uint _block) public returns (uint RN);
|
| 740 |
+
|
| 741 |
+
|
| 742 |
+
function getUncorrelatedRN(uint _block) public returns (uint RN) {
|
| 743 |
+
uint baseRN=getRN(_block);
|
| 744 |
+
if (baseRN==0)
|
| 745 |
+
return 0;
|
| 746 |
+
else
|
| 747 |
+
return uint(keccak256(msg.sender,baseRN));
|
| 748 |
+
}
|
| 749 |
+
|
| 750 |
+
}
|
| 751 |
+
|
| 752 |
+
|
| 753 |
+
contract BlockHashRNG is RNG {
|
| 754 |
+
|
| 755 |
+
mapping (uint => uint) public randomNumber;
|
| 756 |
+
mapping (uint => uint) public reward;
|
| 757 |
+
|
| 758 |
+
|
| 759 |
+
|
| 760 |
+
|
| 761 |
+
function contribute(uint _block) public payable { reward[_block]+=msg.value; }
|
| 762 |
+
|
| 763 |
+
|
| 764 |
+
|
| 765 |
+
function getRN(uint _block) public returns (uint RN) {
|
| 766 |
+
RN=randomNumber[_block];
|
| 767 |
+
if (RN==0){
|
| 768 |
+
saveRN(_block);
|
| 769 |
+
return randomNumber[_block];
|
| 770 |
+
}
|
| 771 |
+
else
|
| 772 |
+
return RN;
|
| 773 |
+
}
|
| 774 |
+
|
| 775 |
+
|
| 776 |
+
function saveRN(uint _block) public {
|
| 777 |
+
if (blockhash(_block) != 0x0)
|
| 778 |
+
randomNumber[_block] = uint(blockhash(_block));
|
| 779 |
+
if (randomNumber[_block] != 0) {
|
| 780 |
+
uint rewardToSend = reward[_block];
|
| 781 |
+
reward[_block] = 0;
|
| 782 |
+
msg.sender.send(rewardToSend);
|
| 783 |
+
}
|
| 784 |
+
}
|
| 785 |
+
|
| 786 |
+
}
|
| 787 |
+
|
| 788 |
+
|
| 789 |
+
|
| 790 |
+
contract BlockHashRNGFallback is BlockHashRNG {
|
| 791 |
+
|
| 792 |
+
|
| 793 |
+
function saveRN(uint _block) public {
|
| 794 |
+
if (_block<block.number && randomNumber[_block]==0) {
|
| 795 |
+
if (blockhash(_block)!=0x0)
|
| 796 |
+
randomNumber[_block]=uint(blockhash(_block));
|
| 797 |
+
else
|
| 798 |
+
randomNumber[_block]=uint(blockhash(block.number-1));
|
| 799 |
+
}
|
| 800 |
+
if (randomNumber[_block] != 0) {
|
| 801 |
+
uint rewardToSend=reward[_block];
|
| 802 |
+
reward[_block]=0;
|
| 803 |
+
msg.sender.send(rewardToSend);
|
| 804 |
+
}
|
| 805 |
+
}
|
| 806 |
+
|
| 807 |
+
}
|
| 808 |
+
|
| 809 |
+
|
| 810 |
+
contract Arbitrable{
|
| 811 |
+
Arbitrator public arbitrator;
|
| 812 |
+
bytes public arbitratorExtraData;
|
| 813 |
+
|
| 814 |
+
modifier onlyArbitrator {require(msg.sender==address(arbitrator)); _;}
|
| 815 |
+
|
| 816 |
+
|
| 817 |
+
event Ruling(Arbitrator indexed _arbitrator, uint indexed _disputeID, uint _ruling);
|
| 818 |
+
|
| 819 |
+
|
| 820 |
+
event MetaEvidence(uint indexed _metaEvidenceID, string _evidence);
|
| 821 |
+
|
| 822 |
+
|
| 823 |
+
event Dispute(Arbitrator indexed _arbitrator, uint indexed _disputeID, uint _metaEvidenceID);
|
| 824 |
+
|
| 825 |
+
|
| 826 |
+
event Evidence(Arbitrator indexed _arbitrator, uint indexed _disputeID, address _party, string _evidence);
|
| 827 |
+
|
| 828 |
+
|
| 829 |
+
constructor(Arbitrator _arbitrator, bytes _arbitratorExtraData) public {
|
| 830 |
+
arbitrator = _arbitrator;
|
| 831 |
+
arbitratorExtraData = _arbitratorExtraData;
|
| 832 |
+
}
|
| 833 |
+
|
| 834 |
+
|
| 835 |
+
function rule(uint _disputeID, uint _ruling) public onlyArbitrator {
|
| 836 |
+
emit Ruling(Arbitrator(msg.sender),_disputeID,_ruling);
|
| 837 |
+
|
| 838 |
+
executeRuling(_disputeID,_ruling);
|
| 839 |
+
}
|
| 840 |
+
|
| 841 |
+
|
| 842 |
+
|
| 843 |
+
function executeRuling(uint _disputeID, uint _ruling) internal;
|
| 844 |
+
}
|
| 845 |
+
|
| 846 |
+
|
| 847 |
+
contract Arbitrator{
|
| 848 |
+
|
| 849 |
+
enum DisputeStatus {Waiting, Appealable, Solved}
|
| 850 |
+
|
| 851 |
+
modifier requireArbitrationFee(bytes _extraData) {require(msg.value>=arbitrationCost(_extraData)); _;}
|
| 852 |
+
modifier requireAppealFee(uint _disputeID, bytes _extraData) {require(msg.value>=appealCost(_disputeID, _extraData)); _;}
|
| 853 |
+
|
| 854 |
+
|
| 855 |
+
event AppealPossible(uint _disputeID);
|
| 856 |
+
|
| 857 |
+
|
| 858 |
+
event DisputeCreation(uint indexed _disputeID, Arbitrable _arbitrable);
|
| 859 |
+
|
| 860 |
+
|
| 861 |
+
event AppealDecision(uint indexed _disputeID, Arbitrable _arbitrable);
|
| 862 |
+
|
| 863 |
+
|
| 864 |
+
function createDispute(uint _choices, bytes _extraData) public requireArbitrationFee(_extraData) payable returns(uint disputeID) {}
|
| 865 |
+
|
| 866 |
+
|
| 867 |
+
function arbitrationCost(bytes _extraData) public constant returns(uint fee);
|
| 868 |
+
|
| 869 |
+
|
| 870 |
+
function appeal(uint _disputeID, bytes _extraData) public requireAppealFee(_disputeID,_extraData) payable {
|
| 871 |
+
emit AppealDecision(_disputeID, Arbitrable(msg.sender));
|
| 872 |
+
}
|
| 873 |
+
|
| 874 |
+
|
| 875 |
+
function appealCost(uint _disputeID, bytes _extraData) public constant returns(uint fee);
|
| 876 |
+
|
| 877 |
+
|
| 878 |
+
function disputeStatus(uint _disputeID) public constant returns(DisputeStatus status);
|
| 879 |
+
|
| 880 |
+
|
| 881 |
+
function currentRuling(uint _disputeID) public constant returns(uint ruling);
|
| 882 |
+
|
| 883 |
+
}
|
| 884 |
+
|
| 885 |
+
|
| 886 |
+
|
| 887 |
+
contract Kleros is Arbitrator, ApproveAndCallFallBack {
|
| 888 |
+
|
| 889 |
+
|
| 890 |
+
|
| 891 |
+
|
| 892 |
+
|
| 893 |
+
|
| 894 |
+
Pinakion public pinakion;
|
| 895 |
+
uint public constant NON_PAYABLE_AMOUNT = (2**256 - 2) / 2;
|
| 896 |
+
|
| 897 |
+
|
| 898 |
+
|
| 899 |
+
RNG public rng;
|
| 900 |
+
uint public arbitrationFeePerJuror = 0.05 ether;
|
| 901 |
+
uint16 public defaultNumberJuror = 3;
|
| 902 |
+
uint public minActivatedToken = 0.1 * 1e18;
|
| 903 |
+
uint[5] public timePerPeriod;
|
| 904 |
+
uint public alpha = 2000;
|
| 905 |
+
uint constant ALPHA_DIVISOR = 1e4;
|
| 906 |
+
uint public maxAppeals = 5;
|
| 907 |
+
|
| 908 |
+
|
| 909 |
+
address public governor;
|
| 910 |
+
|
| 911 |
+
|
| 912 |
+
uint public session = 1;
|
| 913 |
+
uint public lastPeriodChange;
|
| 914 |
+
uint public segmentSize;
|
| 915 |
+
uint public rnBlock;
|
| 916 |
+
uint public randomNumber;
|
| 917 |
+
|
| 918 |
+
enum Period {
|
| 919 |
+
Activation,
|
| 920 |
+
Draw,
|
| 921 |
+
Vote,
|
| 922 |
+
Appeal,
|
| 923 |
+
Execution
|
| 924 |
+
}
|
| 925 |
+
|
| 926 |
+
Period public period;
|
| 927 |
+
|
| 928 |
+
struct Juror {
|
| 929 |
+
uint balance;
|
| 930 |
+
uint atStake;
|
| 931 |
+
uint lastSession;
|
| 932 |
+
uint segmentStart;
|
| 933 |
+
uint segmentEnd;
|
| 934 |
+
}
|
| 935 |
+
|
| 936 |
+
mapping (address => Juror) public jurors;
|
| 937 |
+
|
| 938 |
+
struct Vote {
|
| 939 |
+
address account;
|
| 940 |
+
uint ruling;
|
| 941 |
+
}
|
| 942 |
+
|
| 943 |
+
struct VoteCounter {
|
| 944 |
+
uint winningChoice;
|
| 945 |
+
uint winningCount;
|
| 946 |
+
mapping (uint => uint) voteCount;
|
| 947 |
+
}
|
| 948 |
+
|
| 949 |
+
enum DisputeState {
|
| 950 |
+
Open,
|
| 951 |
+
Resolving,
|
| 952 |
+
Executable,
|
| 953 |
+
Executed
|
| 954 |
+
}
|
| 955 |
+
|
| 956 |
+
struct Dispute {
|
| 957 |
+
Arbitrable arbitrated;
|
| 958 |
+
uint session;
|
| 959 |
+
uint appeals;
|
| 960 |
+
uint choices;
|
| 961 |
+
uint16 initialNumberJurors;
|
| 962 |
+
uint arbitrationFeePerJuror;
|
| 963 |
+
DisputeState state;
|
| 964 |
+
Vote[][] votes;
|
| 965 |
+
VoteCounter[] voteCounter;
|
| 966 |
+
mapping (address => uint) lastSessionVote;
|
| 967 |
+
uint currentAppealToRepartition;
|
| 968 |
+
AppealsRepartitioned[] appealsRepartitioned;
|
| 969 |
+
}
|
| 970 |
+
|
| 971 |
+
enum RepartitionStage {
|
| 972 |
+
Incoherent,
|
| 973 |
+
Coherent,
|
| 974 |
+
AtStake,
|
| 975 |
+
Complete
|
| 976 |
+
}
|
| 977 |
+
|
| 978 |
+
struct AppealsRepartitioned {
|
| 979 |
+
uint totalToRedistribute;
|
| 980 |
+
uint nbCoherent;
|
| 981 |
+
uint currentIncoherentVote;
|
| 982 |
+
uint currentCoherentVote;
|
| 983 |
+
uint currentAtStakeVote;
|
| 984 |
+
RepartitionStage stage;
|
| 985 |
+
}
|
| 986 |
+
|
| 987 |
+
Dispute[] public disputes;
|
| 988 |
+
|
| 989 |
+
|
| 990 |
+
|
| 991 |
+
|
| 992 |
+
|
| 993 |
+
|
| 994 |
+
event NewPeriod(Period _period, uint indexed _session);
|
| 995 |
+
|
| 996 |
+
|
| 997 |
+
event TokenShift(address indexed _account, uint _disputeID, int _amount);
|
| 998 |
+
|
| 999 |
+
|
| 1000 |
+
event ArbitrationReward(address indexed _account, uint _disputeID, uint _amount);
|
| 1001 |
+
|
| 1002 |
+
|
| 1003 |
+
|
| 1004 |
+
|
| 1005 |
+
modifier onlyBy(address _account) {require(msg.sender == _account); _;}
|
| 1006 |
+
modifier onlyDuring(Period _period) {require(period == _period); _;}
|
| 1007 |
+
modifier onlyGovernor() {require(msg.sender == governor); _;}
|
| 1008 |
+
|
| 1009 |
+
|
| 1010 |
+
|
| 1011 |
+
constructor(Pinakion _pinakion, RNG _rng, uint[5] _timePerPeriod, address _governor) public {
|
| 1012 |
+
pinakion = _pinakion;
|
| 1013 |
+
rng = _rng;
|
| 1014 |
+
lastPeriodChange = now;
|
| 1015 |
+
timePerPeriod = _timePerPeriod;
|
| 1016 |
+
governor = _governor;
|
| 1017 |
+
}
|
| 1018 |
+
|
| 1019 |
+
|
| 1020 |
+
|
| 1021 |
+
|
| 1022 |
+
|
| 1023 |
+
|
| 1024 |
+
|
| 1025 |
+
function receiveApproval(address _from, uint _amount, address, bytes) public onlyBy(pinakion) {
|
| 1026 |
+
require(pinakion.transferFrom(_from, this, _amount));
|
| 1027 |
+
|
| 1028 |
+
jurors[_from].balance += _amount;
|
| 1029 |
+
}
|
| 1030 |
+
|
| 1031 |
+
|
| 1032 |
+
function withdraw(uint _value) public {
|
| 1033 |
+
Juror storage juror = jurors[msg.sender];
|
| 1034 |
+
require(juror.atStake <= juror.balance);
|
| 1035 |
+
require(_value <= juror.balance-juror.atStake);
|
| 1036 |
+
require(juror.lastSession != session);
|
| 1037 |
+
|
| 1038 |
+
juror.balance -= _value;
|
| 1039 |
+
require(pinakion.transfer(msg.sender,_value));
|
| 1040 |
+
}
|
| 1041 |
+
|
| 1042 |
+
|
| 1043 |
+
|
| 1044 |
+
|
| 1045 |
+
|
| 1046 |
+
|
| 1047 |
+
|
| 1048 |
+
function passPeriod() public {
|
| 1049 |
+
require(now-lastPeriodChange >= timePerPeriod[uint8(period)]);
|
| 1050 |
+
|
| 1051 |
+
if (period == Period.Activation) {
|
| 1052 |
+
rnBlock = block.number + 1;
|
| 1053 |
+
rng.requestRN(rnBlock);
|
| 1054 |
+
period = Period.Draw;
|
| 1055 |
+
} else if (period == Period.Draw) {
|
| 1056 |
+
randomNumber = rng.getUncorrelatedRN(rnBlock);
|
| 1057 |
+
require(randomNumber != 0);
|
| 1058 |
+
period = Period.Vote;
|
| 1059 |
+
} else if (period == Period.Vote) {
|
| 1060 |
+
period = Period.Appeal;
|
| 1061 |
+
} else if (period == Period.Appeal) {
|
| 1062 |
+
period = Period.Execution;
|
| 1063 |
+
} else if (period == Period.Execution) {
|
| 1064 |
+
period = Period.Activation;
|
| 1065 |
+
++session;
|
| 1066 |
+
segmentSize = 0;
|
| 1067 |
+
rnBlock = 0;
|
| 1068 |
+
randomNumber = 0;
|
| 1069 |
+
}
|
| 1070 |
+
|
| 1071 |
+
|
| 1072 |
+
lastPeriodChange = now;
|
| 1073 |
+
NewPeriod(period, session);
|
| 1074 |
+
}
|
| 1075 |
+
|
| 1076 |
+
|
| 1077 |
+
|
| 1078 |
+
function activateTokens(uint _value) public onlyDuring(Period.Activation) {
|
| 1079 |
+
Juror storage juror = jurors[msg.sender];
|
| 1080 |
+
require(_value <= juror.balance);
|
| 1081 |
+
require(_value >= minActivatedToken);
|
| 1082 |
+
require(juror.lastSession != session);
|
| 1083 |
+
|
| 1084 |
+
juror.lastSession = session;
|
| 1085 |
+
juror.segmentStart = segmentSize;
|
| 1086 |
+
segmentSize += _value;
|
| 1087 |
+
juror.segmentEnd = segmentSize;
|
| 1088 |
+
|
| 1089 |
+
}
|
| 1090 |
+
|
| 1091 |
+
|
| 1092 |
+
function voteRuling(uint _disputeID, uint _ruling, uint[] _draws) public onlyDuring(Period.Vote) {
|
| 1093 |
+
Dispute storage dispute = disputes[_disputeID];
|
| 1094 |
+
Juror storage juror = jurors[msg.sender];
|
| 1095 |
+
VoteCounter storage voteCounter = dispute.voteCounter[dispute.appeals];
|
| 1096 |
+
require(dispute.lastSessionVote[msg.sender] != session);
|
| 1097 |
+
require(_ruling <= dispute.choices);
|
| 1098 |
+
|
| 1099 |
+
require(validDraws(msg.sender, _disputeID, _draws));
|
| 1100 |
+
|
| 1101 |
+
dispute.lastSessionVote[msg.sender] = session;
|
| 1102 |
+
voteCounter.voteCount[_ruling] += _draws.length;
|
| 1103 |
+
if (voteCounter.winningCount < voteCounter.voteCount[_ruling]) {
|
| 1104 |
+
voteCounter.winningCount = voteCounter.voteCount[_ruling];
|
| 1105 |
+
voteCounter.winningChoice = _ruling;
|
| 1106 |
+
} else if (voteCounter.winningCount==voteCounter.voteCount[_ruling] && _draws.length!=0) {
|
| 1107 |
+
voteCounter.winningChoice = 0;
|
| 1108 |
+
}
|
| 1109 |
+
for (uint i = 0; i < _draws.length; ++i) {
|
| 1110 |
+
dispute.votes[dispute.appeals].push(Vote({
|
| 1111 |
+
account: msg.sender,
|
| 1112 |
+
ruling: _ruling
|
| 1113 |
+
}));
|
| 1114 |
+
}
|
| 1115 |
+
|
| 1116 |
+
juror.atStake += _draws.length * getStakePerDraw();
|
| 1117 |
+
uint feeToPay = _draws.length * dispute.arbitrationFeePerJuror;
|
| 1118 |
+
msg.sender.transfer(feeToPay);
|
| 1119 |
+
ArbitrationReward(msg.sender, _disputeID, feeToPay);
|
| 1120 |
+
}
|
| 1121 |
+
|
| 1122 |
+
|
| 1123 |
+
function penalizeInactiveJuror(address _jurorAddress, uint _disputeID, uint[] _draws) public {
|
| 1124 |
+
Dispute storage dispute = disputes[_disputeID];
|
| 1125 |
+
Juror storage inactiveJuror = jurors[_jurorAddress];
|
| 1126 |
+
require(period > Period.Vote);
|
| 1127 |
+
require(dispute.lastSessionVote[_jurorAddress] != session);
|
| 1128 |
+
dispute.lastSessionVote[_jurorAddress] = session;
|
| 1129 |
+
require(validDraws(_jurorAddress, _disputeID, _draws));
|
| 1130 |
+
uint penality = _draws.length * minActivatedToken * 2 * alpha / ALPHA_DIVISOR;
|
| 1131 |
+
penality = (penality < inactiveJuror.balance) ? penality : inactiveJuror.balance;
|
| 1132 |
+
inactiveJuror.balance -= penality;
|
| 1133 |
+
TokenShift(_jurorAddress, _disputeID, -int(penality));
|
| 1134 |
+
jurors[msg.sender].balance += penality / 2;
|
| 1135 |
+
TokenShift(msg.sender, _disputeID, int(penality / 2));
|
| 1136 |
+
jurors[governor].balance += penality / 2;
|
| 1137 |
+
TokenShift(governor, _disputeID, int(penality / 2));
|
| 1138 |
+
msg.sender.transfer(_draws.length*dispute.arbitrationFeePerJuror);
|
| 1139 |
+
}
|
| 1140 |
+
|
| 1141 |
+
|
| 1142 |
+
function oneShotTokenRepartition(uint _disputeID) public onlyDuring(Period.Execution) {
|
| 1143 |
+
Dispute storage dispute = disputes[_disputeID];
|
| 1144 |
+
require(dispute.state == DisputeState.Open);
|
| 1145 |
+
require(dispute.session+dispute.appeals <= session);
|
| 1146 |
+
|
| 1147 |
+
uint winningChoice = dispute.voteCounter[dispute.appeals].winningChoice;
|
| 1148 |
+
uint amountShift = getStakePerDraw();
|
| 1149 |
+
for (uint i = 0; i <= dispute.appeals; ++i) {
|
| 1150 |
+
|
| 1151 |
+
|
| 1152 |
+
|
| 1153 |
+
if (winningChoice!=0 || (dispute.voteCounter[dispute.appeals].voteCount[0] == dispute.voteCounter[dispute.appeals].winningCount)) {
|
| 1154 |
+
uint totalToRedistribute = 0;
|
| 1155 |
+
uint nbCoherent = 0;
|
| 1156 |
+
|
| 1157 |
+
for (uint j = 0; j < dispute.votes[i].length; ++j) {
|
| 1158 |
+
Vote storage vote = dispute.votes[i][j];
|
| 1159 |
+
if (vote.ruling != winningChoice) {
|
| 1160 |
+
Juror storage juror = jurors[vote.account];
|
| 1161 |
+
uint penalty = amountShift<juror.balance ? amountShift : juror.balance;
|
| 1162 |
+
juror.balance -= penalty;
|
| 1163 |
+
TokenShift(vote.account, _disputeID, int(-penalty));
|
| 1164 |
+
totalToRedistribute += penalty;
|
| 1165 |
+
} else {
|
| 1166 |
+
++nbCoherent;
|
| 1167 |
+
}
|
| 1168 |
+
}
|
| 1169 |
+
if (nbCoherent == 0) {
|
| 1170 |
+
jurors[governor].balance += totalToRedistribute;
|
| 1171 |
+
TokenShift(governor, _disputeID, int(totalToRedistribute));
|
| 1172 |
+
} else {
|
| 1173 |
+
uint toRedistribute = totalToRedistribute / nbCoherent;
|
| 1174 |
+
|
| 1175 |
+
for (j = 0; j < dispute.votes[i].length; ++j) {
|
| 1176 |
+
vote = dispute.votes[i][j];
|
| 1177 |
+
if (vote.ruling == winningChoice) {
|
| 1178 |
+
juror = jurors[vote.account];
|
| 1179 |
+
juror.balance += toRedistribute;
|
| 1180 |
+
TokenShift(vote.account, _disputeID, int(toRedistribute));
|
| 1181 |
+
}
|
| 1182 |
+
}
|
| 1183 |
+
}
|
| 1184 |
+
}
|
| 1185 |
+
|
| 1186 |
+
for (j = 0; j < dispute.votes[i].length; ++j) {
|
| 1187 |
+
vote = dispute.votes[i][j];
|
| 1188 |
+
juror = jurors[vote.account];
|
| 1189 |
+
juror.atStake -= amountShift;
|
| 1190 |
+
}
|
| 1191 |
+
}
|
| 1192 |
+
dispute.state = DisputeState.Executable;
|
| 1193 |
+
}
|
| 1194 |
+
|
| 1195 |
+
|
| 1196 |
+
function multipleShotTokenRepartition(uint _disputeID, uint _maxIterations) public onlyDuring(Period.Execution) {
|
| 1197 |
+
Dispute storage dispute = disputes[_disputeID];
|
| 1198 |
+
require(dispute.state <= DisputeState.Resolving);
|
| 1199 |
+
require(dispute.session+dispute.appeals <= session);
|
| 1200 |
+
dispute.state = DisputeState.Resolving;
|
| 1201 |
+
|
| 1202 |
+
uint winningChoice = dispute.voteCounter[dispute.appeals].winningChoice;
|
| 1203 |
+
uint amountShift = getStakePerDraw();
|
| 1204 |
+
uint currentIterations = 0;
|
| 1205 |
+
for (uint i = dispute.currentAppealToRepartition; i <= dispute.appeals; ++i) {
|
| 1206 |
+
|
| 1207 |
+
if (dispute.appealsRepartitioned.length < i+1) {
|
| 1208 |
+
dispute.appealsRepartitioned.length++;
|
| 1209 |
+
}
|
| 1210 |
+
|
| 1211 |
+
|
| 1212 |
+
if (winningChoice==0 && (dispute.voteCounter[dispute.appeals].voteCount[0] != dispute.voteCounter[dispute.appeals].winningCount)) {
|
| 1213 |
+
|
| 1214 |
+
dispute.appealsRepartitioned[i].stage = RepartitionStage.AtStake;
|
| 1215 |
+
}
|
| 1216 |
+
|
| 1217 |
+
|
| 1218 |
+
if (dispute.appealsRepartitioned[i].stage == RepartitionStage.Incoherent) {
|
| 1219 |
+
for (uint j = dispute.appealsRepartitioned[i].currentIncoherentVote; j < dispute.votes[i].length; ++j) {
|
| 1220 |
+
if (currentIterations >= _maxIterations) {
|
| 1221 |
+
return;
|
| 1222 |
+
}
|
| 1223 |
+
Vote storage vote = dispute.votes[i][j];
|
| 1224 |
+
if (vote.ruling != winningChoice) {
|
| 1225 |
+
Juror storage juror = jurors[vote.account];
|
| 1226 |
+
uint penalty = amountShift<juror.balance ? amountShift : juror.balance;
|
| 1227 |
+
juror.balance -= penalty;
|
| 1228 |
+
TokenShift(vote.account, _disputeID, int(-penalty));
|
| 1229 |
+
dispute.appealsRepartitioned[i].totalToRedistribute += penalty;
|
| 1230 |
+
} else {
|
| 1231 |
+
++dispute.appealsRepartitioned[i].nbCoherent;
|
| 1232 |
+
}
|
| 1233 |
+
|
| 1234 |
+
++dispute.appealsRepartitioned[i].currentIncoherentVote;
|
| 1235 |
+
++currentIterations;
|
| 1236 |
+
}
|
| 1237 |
+
|
| 1238 |
+
dispute.appealsRepartitioned[i].stage = RepartitionStage.Coherent;
|
| 1239 |
+
}
|
| 1240 |
+
|
| 1241 |
+
|
| 1242 |
+
if (dispute.appealsRepartitioned[i].stage == RepartitionStage.Coherent) {
|
| 1243 |
+
if (dispute.appealsRepartitioned[i].nbCoherent == 0) {
|
| 1244 |
+
jurors[governor].balance += dispute.appealsRepartitioned[i].totalToRedistribute;
|
| 1245 |
+
TokenShift(governor, _disputeID, int(dispute.appealsRepartitioned[i].totalToRedistribute));
|
| 1246 |
+
dispute.appealsRepartitioned[i].stage = RepartitionStage.AtStake;
|
| 1247 |
+
} else {
|
| 1248 |
+
uint toRedistribute = dispute.appealsRepartitioned[i].totalToRedistribute / dispute.appealsRepartitioned[i].nbCoherent;
|
| 1249 |
+
|
| 1250 |
+
for (j = dispute.appealsRepartitioned[i].currentCoherentVote; j < dispute.votes[i].length; ++j) {
|
| 1251 |
+
if (currentIterations >= _maxIterations) {
|
| 1252 |
+
return;
|
| 1253 |
+
}
|
| 1254 |
+
vote = dispute.votes[i][j];
|
| 1255 |
+
if (vote.ruling == winningChoice) {
|
| 1256 |
+
juror = jurors[vote.account];
|
| 1257 |
+
juror.balance += toRedistribute;
|
| 1258 |
+
TokenShift(vote.account, _disputeID, int(toRedistribute));
|
| 1259 |
+
}
|
| 1260 |
+
|
| 1261 |
+
++currentIterations;
|
| 1262 |
+
++dispute.appealsRepartitioned[i].currentCoherentVote;
|
| 1263 |
+
}
|
| 1264 |
+
|
| 1265 |
+
dispute.appealsRepartitioned[i].stage = RepartitionStage.AtStake;
|
| 1266 |
+
}
|
| 1267 |
+
}
|
| 1268 |
+
|
| 1269 |
+
if (dispute.appealsRepartitioned[i].stage == RepartitionStage.AtStake) {
|
| 1270 |
+
|
| 1271 |
+
for (j = dispute.appealsRepartitioned[i].currentAtStakeVote; j < dispute.votes[i].length; ++j) {
|
| 1272 |
+
if (currentIterations >= _maxIterations) {
|
| 1273 |
+
return;
|
| 1274 |
+
}
|
| 1275 |
+
vote = dispute.votes[i][j];
|
| 1276 |
+
juror = jurors[vote.account];
|
| 1277 |
+
juror.atStake -= amountShift;
|
| 1278 |
+
|
| 1279 |
+
++currentIterations;
|
| 1280 |
+
++dispute.appealsRepartitioned[i].currentAtStakeVote;
|
| 1281 |
+
}
|
| 1282 |
+
|
| 1283 |
+
dispute.appealsRepartitioned[i].stage = RepartitionStage.Complete;
|
| 1284 |
+
}
|
| 1285 |
+
|
| 1286 |
+
if (dispute.appealsRepartitioned[i].stage == RepartitionStage.Complete) {
|
| 1287 |
+
++dispute.currentAppealToRepartition;
|
| 1288 |
+
}
|
| 1289 |
+
}
|
| 1290 |
+
|
| 1291 |
+
dispute.state = DisputeState.Executable;
|
| 1292 |
+
}
|
| 1293 |
+
|
| 1294 |
+
|
| 1295 |
+
|
| 1296 |
+
|
| 1297 |
+
|
| 1298 |
+
|
| 1299 |
+
|
| 1300 |
+
function amountJurors(uint _disputeID) public view returns (uint nbJurors) {
|
| 1301 |
+
Dispute storage dispute = disputes[_disputeID];
|
| 1302 |
+
return (dispute.initialNumberJurors + 1) * 2**dispute.appeals - 1;
|
| 1303 |
+
}
|
| 1304 |
+
|
| 1305 |
+
|
| 1306 |
+
function validDraws(address _jurorAddress, uint _disputeID, uint[] _draws) public view returns (bool valid) {
|
| 1307 |
+
uint draw = 0;
|
| 1308 |
+
Juror storage juror = jurors[_jurorAddress];
|
| 1309 |
+
Dispute storage dispute = disputes[_disputeID];
|
| 1310 |
+
uint nbJurors = amountJurors(_disputeID);
|
| 1311 |
+
|
| 1312 |
+
if (juror.lastSession != session) return false;
|
| 1313 |
+
if (dispute.session+dispute.appeals != session) return false;
|
| 1314 |
+
if (period <= Period.Draw) return false;
|
| 1315 |
+
for (uint i = 0; i < _draws.length; ++i) {
|
| 1316 |
+
if (_draws[i] <= draw) return false;
|
| 1317 |
+
draw = _draws[i];
|
| 1318 |
+
if (draw > nbJurors) return false;
|
| 1319 |
+
uint position = uint(keccak256(randomNumber, _disputeID, draw)) % segmentSize;
|
| 1320 |
+
require(position >= juror.segmentStart);
|
| 1321 |
+
require(position < juror.segmentEnd);
|
| 1322 |
+
}
|
| 1323 |
+
|
| 1324 |
+
return true;
|
| 1325 |
+
}
|
| 1326 |
+
|
| 1327 |
+
|
| 1328 |
+
|
| 1329 |
+
|
| 1330 |
+
|
| 1331 |
+
|
| 1332 |
+
|
| 1333 |
+
function createDispute(uint _choices, bytes _extraData) public payable returns (uint disputeID) {
|
| 1334 |
+
uint16 nbJurors = extraDataToNbJurors(_extraData);
|
| 1335 |
+
require(msg.value >= arbitrationCost(_extraData));
|
| 1336 |
+
|
| 1337 |
+
disputeID = disputes.length++;
|
| 1338 |
+
Dispute storage dispute = disputes[disputeID];
|
| 1339 |
+
dispute.arbitrated = Arbitrable(msg.sender);
|
| 1340 |
+
if (period < Period.Draw)
|
| 1341 |
+
dispute.session = session;
|
| 1342 |
+
else
|
| 1343 |
+
dispute.session = session+1;
|
| 1344 |
+
dispute.choices = _choices;
|
| 1345 |
+
dispute.initialNumberJurors = nbJurors;
|
| 1346 |
+
dispute.arbitrationFeePerJuror = arbitrationFeePerJuror;
|
| 1347 |
+
dispute.votes.length++;
|
| 1348 |
+
dispute.voteCounter.length++;
|
| 1349 |
+
|
| 1350 |
+
DisputeCreation(disputeID, Arbitrable(msg.sender));
|
| 1351 |
+
return disputeID;
|
| 1352 |
+
}
|
| 1353 |
+
|
| 1354 |
+
|
| 1355 |
+
function appeal(uint _disputeID, bytes _extraData) public payable onlyDuring(Period.Appeal) {
|
| 1356 |
+
super.appeal(_disputeID,_extraData);
|
| 1357 |
+
Dispute storage dispute = disputes[_disputeID];
|
| 1358 |
+
require(msg.value >= appealCost(_disputeID, _extraData));
|
| 1359 |
+
require(dispute.session+dispute.appeals == session);
|
| 1360 |
+
require(dispute.arbitrated == msg.sender);
|
| 1361 |
+
|
| 1362 |
+
dispute.appeals++;
|
| 1363 |
+
dispute.votes.length++;
|
| 1364 |
+
dispute.voteCounter.length++;
|
| 1365 |
+
}
|
| 1366 |
+
|
| 1367 |
+
|
| 1368 |
+
function executeRuling(uint disputeID) public {
|
| 1369 |
+
Dispute storage dispute = disputes[disputeID];
|
| 1370 |
+
require(dispute.state == DisputeState.Executable);
|
| 1371 |
+
|
| 1372 |
+
dispute.state = DisputeState.Executed;
|
| 1373 |
+
dispute.arbitrated.rule(disputeID, dispute.voteCounter[dispute.appeals].winningChoice);
|
| 1374 |
+
}
|
| 1375 |
+
|
| 1376 |
+
|
| 1377 |
+
|
| 1378 |
+
|
| 1379 |
+
|
| 1380 |
+
|
| 1381 |
+
|
| 1382 |
+
function arbitrationCost(bytes _extraData) public view returns (uint fee) {
|
| 1383 |
+
return extraDataToNbJurors(_extraData) * arbitrationFeePerJuror;
|
| 1384 |
+
}
|
| 1385 |
+
|
| 1386 |
+
|
| 1387 |
+
function appealCost(uint _disputeID, bytes _extraData) public view returns (uint fee) {
|
| 1388 |
+
Dispute storage dispute = disputes[_disputeID];
|
| 1389 |
+
|
| 1390 |
+
if(dispute.appeals >= maxAppeals) return NON_PAYABLE_AMOUNT;
|
| 1391 |
+
|
| 1392 |
+
return (2*amountJurors(_disputeID) + 1) * dispute.arbitrationFeePerJuror;
|
| 1393 |
+
}
|
| 1394 |
+
|
| 1395 |
+
|
| 1396 |
+
function extraDataToNbJurors(bytes _extraData) internal view returns (uint16 nbJurors) {
|
| 1397 |
+
if (_extraData.length < 2)
|
| 1398 |
+
return defaultNumberJuror;
|
| 1399 |
+
else
|
| 1400 |
+
return (uint16(_extraData[0]) << 8) + uint16(_extraData[1]);
|
| 1401 |
+
}
|
| 1402 |
+
|
| 1403 |
+
|
| 1404 |
+
function getStakePerDraw() public view returns (uint minActivatedTokenInAlpha) {
|
| 1405 |
+
return (alpha * minActivatedToken) / ALPHA_DIVISOR;
|
| 1406 |
+
}
|
| 1407 |
+
|
| 1408 |
+
|
| 1409 |
+
|
| 1410 |
+
|
| 1411 |
+
|
| 1412 |
+
|
| 1413 |
+
|
| 1414 |
+
function getVoteAccount(uint _disputeID, uint _appeals, uint _voteID) public view returns (address account) {
|
| 1415 |
+
return disputes[_disputeID].votes[_appeals][_voteID].account;
|
| 1416 |
+
}
|
| 1417 |
+
|
| 1418 |
+
|
| 1419 |
+
function getVoteRuling(uint _disputeID, uint _appeals, uint _voteID) public view returns (uint ruling) {
|
| 1420 |
+
return disputes[_disputeID].votes[_appeals][_voteID].ruling;
|
| 1421 |
+
}
|
| 1422 |
+
|
| 1423 |
+
|
| 1424 |
+
function getWinningChoice(uint _disputeID, uint _appeals) public view returns (uint winningChoice) {
|
| 1425 |
+
return disputes[_disputeID].voteCounter[_appeals].winningChoice;
|
| 1426 |
+
}
|
| 1427 |
+
|
| 1428 |
+
|
| 1429 |
+
function getWinningCount(uint _disputeID, uint _appeals) public view returns (uint winningCount) {
|
| 1430 |
+
return disputes[_disputeID].voteCounter[_appeals].winningCount;
|
| 1431 |
+
}
|
| 1432 |
+
|
| 1433 |
+
|
| 1434 |
+
function getVoteCount(uint _disputeID, uint _appeals, uint _choice) public view returns (uint voteCount) {
|
| 1435 |
+
return disputes[_disputeID].voteCounter[_appeals].voteCount[_choice];
|
| 1436 |
+
}
|
| 1437 |
+
|
| 1438 |
+
|
| 1439 |
+
function getLastSessionVote(uint _disputeID, address _juror) public view returns (uint lastSessionVote) {
|
| 1440 |
+
return disputes[_disputeID].lastSessionVote[_juror];
|
| 1441 |
+
}
|
| 1442 |
+
|
| 1443 |
+
|
| 1444 |
+
function isDrawn(uint _disputeID, address _juror, uint _draw) public view returns (bool drawn) {
|
| 1445 |
+
Dispute storage dispute = disputes[_disputeID];
|
| 1446 |
+
Juror storage juror = jurors[_juror];
|
| 1447 |
+
if (juror.lastSession != session
|
| 1448 |
+
|| (dispute.session+dispute.appeals != session)
|
| 1449 |
+
|| period<=Period.Draw
|
| 1450 |
+
|| _draw>amountJurors(_disputeID)
|
| 1451 |
+
|| _draw==0
|
| 1452 |
+
|| segmentSize==0
|
| 1453 |
+
) {
|
| 1454 |
+
return false;
|
| 1455 |
+
} else {
|
| 1456 |
+
uint position = uint(keccak256(randomNumber,_disputeID,_draw)) % segmentSize;
|
| 1457 |
+
return (position >= juror.segmentStart) && (position < juror.segmentEnd);
|
| 1458 |
+
}
|
| 1459 |
+
|
| 1460 |
+
}
|
| 1461 |
+
|
| 1462 |
+
|
| 1463 |
+
function currentRuling(uint _disputeID) public view returns (uint ruling) {
|
| 1464 |
+
Dispute storage dispute = disputes[_disputeID];
|
| 1465 |
+
return dispute.voteCounter[dispute.appeals].winningChoice;
|
| 1466 |
+
}
|
| 1467 |
+
|
| 1468 |
+
|
| 1469 |
+
function disputeStatus(uint _disputeID) public view returns (DisputeStatus status) {
|
| 1470 |
+
Dispute storage dispute = disputes[_disputeID];
|
| 1471 |
+
if (dispute.session+dispute.appeals < session)
|
| 1472 |
+
return DisputeStatus.Solved;
|
| 1473 |
+
else if(dispute.session+dispute.appeals == session) {
|
| 1474 |
+
if (dispute.state == DisputeState.Open) {
|
| 1475 |
+
if (period < Period.Appeal)
|
| 1476 |
+
return DisputeStatus.Waiting;
|
| 1477 |
+
else if (period == Period.Appeal)
|
| 1478 |
+
return DisputeStatus.Appealable;
|
| 1479 |
+
else return DisputeStatus.Solved;
|
| 1480 |
+
} else return DisputeStatus.Solved;
|
| 1481 |
+
} else return DisputeStatus.Waiting;
|
| 1482 |
+
}
|
| 1483 |
+
|
| 1484 |
+
|
| 1485 |
+
|
| 1486 |
+
|
| 1487 |
+
|
| 1488 |
+
|
| 1489 |
+
function executeOrder(bytes32 _data, uint _value, address _target) public onlyGovernor {
|
| 1490 |
+
_target.call.value(_value)(_data);
|
| 1491 |
+
}
|
| 1492 |
+
|
| 1493 |
+
|
| 1494 |
+
function setRng(RNG _rng) public onlyGovernor {
|
| 1495 |
+
rng = _rng;
|
| 1496 |
+
}
|
| 1497 |
+
|
| 1498 |
+
|
| 1499 |
+
function setArbitrationFeePerJuror(uint _arbitrationFeePerJuror) public onlyGovernor {
|
| 1500 |
+
arbitrationFeePerJuror = _arbitrationFeePerJuror;
|
| 1501 |
+
}
|
| 1502 |
+
|
| 1503 |
+
|
| 1504 |
+
function setDefaultNumberJuror(uint16 _defaultNumberJuror) public onlyGovernor {
|
| 1505 |
+
defaultNumberJuror = _defaultNumberJuror;
|
| 1506 |
+
}
|
| 1507 |
+
|
| 1508 |
+
|
| 1509 |
+
function setMinActivatedToken(uint _minActivatedToken) public onlyGovernor {
|
| 1510 |
+
minActivatedToken = _minActivatedToken;
|
| 1511 |
+
}
|
| 1512 |
+
|
| 1513 |
+
|
| 1514 |
+
function setTimePerPeriod(uint[5] _timePerPeriod) public onlyGovernor {
|
| 1515 |
+
timePerPeriod = _timePerPeriod;
|
| 1516 |
+
}
|
| 1517 |
+
|
| 1518 |
+
|
| 1519 |
+
function setAlpha(uint _alpha) public onlyGovernor {
|
| 1520 |
+
alpha = _alpha;
|
| 1521 |
+
}
|
| 1522 |
+
|
| 1523 |
+
|
| 1524 |
+
function setMaxAppeals(uint _maxAppeals) public onlyGovernor {
|
| 1525 |
+
maxAppeals = _maxAppeals;
|
| 1526 |
+
}
|
| 1527 |
+
|
| 1528 |
+
|
| 1529 |
+
function setGovernor(address _governor) public onlyGovernor {
|
| 1530 |
+
governor = _governor;
|
| 1531 |
+
}
|
| 1532 |
+
}
|
smart_contract_dataset/block number dependency/2584.sol
ADDED
|
@@ -0,0 +1,402 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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 |
+
pragma solidity ^0.4.23;
|
| 2 |
+
|
| 3 |
+
|
| 4 |
+
|
| 5 |
+
contract ZTHReceivingContract {
|
| 6 |
+
|
| 7 |
+
function tokenFallback(address _from, uint _value, bytes _data) public returns (bool);
|
| 8 |
+
}
|
| 9 |
+
|
| 10 |
+
|
| 11 |
+
contract ZTHInterface {
|
| 12 |
+
function getFrontEndTokenBalanceOf(address who) public view returns (uint);
|
| 13 |
+
function transfer(address _to, uint _value) public returns (bool);
|
| 14 |
+
function approve(address spender, uint tokens) public returns (bool);
|
| 15 |
+
}
|
| 16 |
+
|
| 17 |
+
contract Zethroll is ZTHReceivingContract {
|
| 18 |
+
using SafeMath for uint;
|
| 19 |
+
|
| 20 |
+
|
| 21 |
+
|
| 22 |
+
modifier betIsValid(uint _betSize, uint _playerNumber) {
|
| 23 |
+
require( calculateProfit(_betSize, _playerNumber) < maxProfit
|
| 24 |
+
&& _betSize >= minBet
|
| 25 |
+
&& _playerNumber > minNumber
|
| 26 |
+
&& _playerNumber < maxNumber);
|
| 27 |
+
_;
|
| 28 |
+
}
|
| 29 |
+
|
| 30 |
+
|
| 31 |
+
modifier gameIsActive {
|
| 32 |
+
require(gamePaused == false);
|
| 33 |
+
_;
|
| 34 |
+
}
|
| 35 |
+
|
| 36 |
+
|
| 37 |
+
modifier onlyOwner {
|
| 38 |
+
require(msg.sender == owner);
|
| 39 |
+
_;
|
| 40 |
+
}
|
| 41 |
+
|
| 42 |
+
|
| 43 |
+
uint constant private MAX_INT = 2 ** 256 - 1;
|
| 44 |
+
uint constant public maxProfitDivisor = 1000000;
|
| 45 |
+
uint constant public maxNumber = 99;
|
| 46 |
+
uint constant public minNumber = 2;
|
| 47 |
+
uint constant public houseEdgeDivisor = 1000;
|
| 48 |
+
|
| 49 |
+
|
| 50 |
+
bool public gamePaused;
|
| 51 |
+
|
| 52 |
+
address public owner;
|
| 53 |
+
address public ZethrBankroll;
|
| 54 |
+
address public ZTHTKNADDR;
|
| 55 |
+
|
| 56 |
+
ZTHInterface public ZTHTKN;
|
| 57 |
+
|
| 58 |
+
uint public contractBalance;
|
| 59 |
+
uint public houseEdge;
|
| 60 |
+
uint public maxProfit;
|
| 61 |
+
uint public maxProfitAsPercentOfHouse;
|
| 62 |
+
uint public minBet = 0;
|
| 63 |
+
|
| 64 |
+
|
| 65 |
+
uint public totalBets;
|
| 66 |
+
uint public totalZTHWagered;
|
| 67 |
+
|
| 68 |
+
|
| 69 |
+
|
| 70 |
+
|
| 71 |
+
event LogBet(address sender, uint value, uint rollUnder);
|
| 72 |
+
|
| 73 |
+
|
| 74 |
+
|
| 75 |
+
event LogResult(address player, uint result, uint rollUnder, uint profit, uint tokensBetted, bool won);
|
| 76 |
+
|
| 77 |
+
|
| 78 |
+
event LogOwnerTransfer(address indexed SentToAddress, uint indexed AmountTransferred);
|
| 79 |
+
|
| 80 |
+
|
| 81 |
+
event MaxProfitChanged(uint _oldMaxProfit, uint _newMaxProfit);
|
| 82 |
+
|
| 83 |
+
|
| 84 |
+
event CurrentContractBalance(uint _tokens);
|
| 85 |
+
|
| 86 |
+
constructor (address zthtknaddr, address zthbankrolladdr) public {
|
| 87 |
+
|
| 88 |
+
owner = msg.sender;
|
| 89 |
+
|
| 90 |
+
|
| 91 |
+
ZTHTKN = ZTHInterface(zthtknaddr);
|
| 92 |
+
ZTHTKNADDR = zthtknaddr;
|
| 93 |
+
|
| 94 |
+
|
| 95 |
+
ZethrBankroll = zthbankrolladdr;
|
| 96 |
+
|
| 97 |
+
|
| 98 |
+
houseEdge = 990;
|
| 99 |
+
|
| 100 |
+
|
| 101 |
+
ownerSetMaxProfitAsPercentOfHouse(10000);
|
| 102 |
+
|
| 103 |
+
|
| 104 |
+
ownerSetMinBet(1e18);
|
| 105 |
+
|
| 106 |
+
|
| 107 |
+
ZTHTKN.approve(zthbankrolladdr, MAX_INT);
|
| 108 |
+
}
|
| 109 |
+
|
| 110 |
+
function() public payable {}
|
| 111 |
+
|
| 112 |
+
|
| 113 |
+
|
| 114 |
+
function maxRandom(uint blockn, address entropy) public view returns (uint256 randomNumber) {
|
| 115 |
+
return uint256(keccak256(
|
| 116 |
+
abi.encodePacked(
|
| 117 |
+
blockhash(blockn),
|
| 118 |
+
entropy)
|
| 119 |
+
));
|
| 120 |
+
}
|
| 121 |
+
|
| 122 |
+
|
| 123 |
+
function random(uint256 upper, uint256 blockn, address entropy) internal view returns (uint256 randomNumber) {
|
| 124 |
+
return maxRandom(blockn, entropy) % upper;
|
| 125 |
+
}
|
| 126 |
+
|
| 127 |
+
|
| 128 |
+
function calculateProfit(uint _initBet, uint _roll)
|
| 129 |
+
private
|
| 130 |
+
view
|
| 131 |
+
returns (uint)
|
| 132 |
+
{
|
| 133 |
+
return ((((_initBet * (100 - (_roll.sub(1)))) / (_roll.sub(1)) + _initBet)) * houseEdge / houseEdgeDivisor) - _initBet;
|
| 134 |
+
}
|
| 135 |
+
|
| 136 |
+
|
| 137 |
+
struct playerRoll{
|
| 138 |
+
uint200 tokenValue;
|
| 139 |
+
uint48 blockn;
|
| 140 |
+
uint8 rollUnder;
|
| 141 |
+
}
|
| 142 |
+
|
| 143 |
+
|
| 144 |
+
mapping(address => playerRoll) public playerRolls;
|
| 145 |
+
|
| 146 |
+
function _playerRollDice(uint _rollUnder, TKN _tkn) private
|
| 147 |
+
gameIsActive
|
| 148 |
+
betIsValid(_tkn.value, _rollUnder)
|
| 149 |
+
{
|
| 150 |
+
require(_tkn.value < ((2 ** 200) - 1));
|
| 151 |
+
require(block.number < ((2 ** 48) - 1));
|
| 152 |
+
|
| 153 |
+
|
| 154 |
+
|
| 155 |
+
|
| 156 |
+
|
| 157 |
+
require(_zthToken(msg.sender));
|
| 158 |
+
|
| 159 |
+
playerRoll memory roll = playerRolls[_tkn.sender];
|
| 160 |
+
|
| 161 |
+
|
| 162 |
+
require(block.number != roll.blockn);
|
| 163 |
+
|
| 164 |
+
|
| 165 |
+
if (roll.blockn != 0) {
|
| 166 |
+
_finishBet(false, _tkn.sender);
|
| 167 |
+
}
|
| 168 |
+
|
| 169 |
+
|
| 170 |
+
roll.blockn = uint48(block.number);
|
| 171 |
+
roll.tokenValue = uint200(_tkn.value);
|
| 172 |
+
roll.rollUnder = uint8(_rollUnder);
|
| 173 |
+
|
| 174 |
+
|
| 175 |
+
playerRolls[_tkn.sender] = roll;
|
| 176 |
+
|
| 177 |
+
|
| 178 |
+
emit LogBet(_tkn.sender, _tkn.value, _rollUnder);
|
| 179 |
+
|
| 180 |
+
|
| 181 |
+
totalBets += 1;
|
| 182 |
+
|
| 183 |
+
|
| 184 |
+
totalZTHWagered += _tkn.value;
|
| 185 |
+
}
|
| 186 |
+
|
| 187 |
+
|
| 188 |
+
function finishBet() public
|
| 189 |
+
gameIsActive
|
| 190 |
+
returns (uint)
|
| 191 |
+
{
|
| 192 |
+
return _finishBet(true, msg.sender);
|
| 193 |
+
}
|
| 194 |
+
|
| 195 |
+
|
| 196 |
+
function _finishBet(bool delete_it, address target) private returns (uint){
|
| 197 |
+
playerRoll memory roll = playerRolls[target];
|
| 198 |
+
require(roll.tokenValue > 0);
|
| 199 |
+
require(roll.blockn != block.number);
|
| 200 |
+
|
| 201 |
+
|
| 202 |
+
uint result;
|
| 203 |
+
if (block.number - roll.blockn > 255) {
|
| 204 |
+
result = 1000;
|
| 205 |
+
} else {
|
| 206 |
+
|
| 207 |
+
result = random(99, roll.blockn, target) + 1;
|
| 208 |
+
}
|
| 209 |
+
|
| 210 |
+
uint rollUnder = roll.rollUnder;
|
| 211 |
+
|
| 212 |
+
if (result < rollUnder) {
|
| 213 |
+
|
| 214 |
+
|
| 215 |
+
|
| 216 |
+
uint profit = calculateProfit(roll.tokenValue, rollUnder);
|
| 217 |
+
|
| 218 |
+
if (profit > maxProfit){
|
| 219 |
+
profit = maxProfit;
|
| 220 |
+
}
|
| 221 |
+
|
| 222 |
+
|
| 223 |
+
contractBalance = contractBalance.sub(profit);
|
| 224 |
+
|
| 225 |
+
emit LogResult(target, result, rollUnder, profit, roll.tokenValue, true);
|
| 226 |
+
|
| 227 |
+
|
| 228 |
+
setMaxProfit();
|
| 229 |
+
|
| 230 |
+
|
| 231 |
+
|
| 232 |
+
delete playerRolls[target];
|
| 233 |
+
|
| 234 |
+
|
| 235 |
+
|
| 236 |
+
ZTHTKN.transfer(target, profit + roll.tokenValue);
|
| 237 |
+
|
| 238 |
+
return result;
|
| 239 |
+
|
| 240 |
+
} else {
|
| 241 |
+
|
| 242 |
+
emit LogResult(target, result, rollUnder, profit, roll.tokenValue, false);
|
| 243 |
+
|
| 244 |
+
|
| 245 |
+
contractBalance = contractBalance.add(roll.tokenValue);
|
| 246 |
+
|
| 247 |
+
|
| 248 |
+
|
| 249 |
+
|
| 250 |
+
|
| 251 |
+
setMaxProfit();
|
| 252 |
+
|
| 253 |
+
return result;
|
| 254 |
+
}
|
| 255 |
+
}
|
| 256 |
+
|
| 257 |
+
|
| 258 |
+
struct TKN {address sender; uint value;}
|
| 259 |
+
|
| 260 |
+
|
| 261 |
+
function tokenFallback(address _from, uint _value, bytes _data) public returns (bool) {
|
| 262 |
+
require(msg.sender == ZTHTKNADDR);
|
| 263 |
+
if (_from == ZethrBankroll) {
|
| 264 |
+
|
| 265 |
+
contractBalance = contractBalance.add(_value);
|
| 266 |
+
|
| 267 |
+
|
| 268 |
+
uint oldMaxProfit = maxProfit;
|
| 269 |
+
setMaxProfit();
|
| 270 |
+
|
| 271 |
+
emit MaxProfitChanged(oldMaxProfit, maxProfit);
|
| 272 |
+
return true;
|
| 273 |
+
|
| 274 |
+
} else {
|
| 275 |
+
TKN memory _tkn;
|
| 276 |
+
_tkn.sender = _from;
|
| 277 |
+
_tkn.value = _value;
|
| 278 |
+
uint8 chosenNumber = uint8(_data[0]);
|
| 279 |
+
_playerRollDice(chosenNumber, _tkn);
|
| 280 |
+
}
|
| 281 |
+
|
| 282 |
+
return true;
|
| 283 |
+
}
|
| 284 |
+
|
| 285 |
+
|
| 286 |
+
function setMaxProfit() internal {
|
| 287 |
+
emit CurrentContractBalance(contractBalance);
|
| 288 |
+
maxProfit = (contractBalance * maxProfitAsPercentOfHouse) / maxProfitDivisor;
|
| 289 |
+
}
|
| 290 |
+
|
| 291 |
+
|
| 292 |
+
function ownerUpdateContractBalance(uint newContractBalance) public
|
| 293 |
+
onlyOwner
|
| 294 |
+
{
|
| 295 |
+
contractBalance = newContractBalance;
|
| 296 |
+
}
|
| 297 |
+
|
| 298 |
+
|
| 299 |
+
function ownerSetMaxProfitAsPercentOfHouse(uint newMaxProfitAsPercent) public
|
| 300 |
+
onlyOwner
|
| 301 |
+
{
|
| 302 |
+
|
| 303 |
+
require(newMaxProfitAsPercent <= 200000);
|
| 304 |
+
maxProfitAsPercentOfHouse = newMaxProfitAsPercent;
|
| 305 |
+
setMaxProfit();
|
| 306 |
+
}
|
| 307 |
+
|
| 308 |
+
|
| 309 |
+
function ownerSetMinBet(uint newMinimumBet) public
|
| 310 |
+
onlyOwner
|
| 311 |
+
{
|
| 312 |
+
minBet = newMinimumBet;
|
| 313 |
+
}
|
| 314 |
+
|
| 315 |
+
|
| 316 |
+
function ownerTransferZTH(address sendTo, uint amount) public
|
| 317 |
+
onlyOwner
|
| 318 |
+
{
|
| 319 |
+
|
| 320 |
+
contractBalance = contractBalance.sub(amount);
|
| 321 |
+
|
| 322 |
+
|
| 323 |
+
setMaxProfit();
|
| 324 |
+
require(ZTHTKN.transfer(sendTo, amount));
|
| 325 |
+
emit LogOwnerTransfer(sendTo, amount);
|
| 326 |
+
}
|
| 327 |
+
|
| 328 |
+
|
| 329 |
+
function ownerPauseGame(bool newStatus) public
|
| 330 |
+
onlyOwner
|
| 331 |
+
{
|
| 332 |
+
gamePaused = newStatus;
|
| 333 |
+
}
|
| 334 |
+
|
| 335 |
+
|
| 336 |
+
function ownerSetBankroll(address newBankroll) public
|
| 337 |
+
onlyOwner
|
| 338 |
+
{
|
| 339 |
+
ZTHTKN.approve(ZethrBankroll, 0);
|
| 340 |
+
ZethrBankroll = newBankroll;
|
| 341 |
+
ZTHTKN.approve(newBankroll, MAX_INT);
|
| 342 |
+
}
|
| 343 |
+
|
| 344 |
+
|
| 345 |
+
function ownerChangeOwner(address newOwner) public
|
| 346 |
+
onlyOwner
|
| 347 |
+
{
|
| 348 |
+
owner = newOwner;
|
| 349 |
+
}
|
| 350 |
+
|
| 351 |
+
|
| 352 |
+
function ownerkill() public
|
| 353 |
+
onlyOwner
|
| 354 |
+
{
|
| 355 |
+
ZTHTKN.transfer(owner, contractBalance);
|
| 356 |
+
selfdestruct(owner);
|
| 357 |
+
}
|
| 358 |
+
|
| 359 |
+
function dumpdivs() public{
|
| 360 |
+
ZethrBankroll.transfer(address(this).balance);
|
| 361 |
+
}
|
| 362 |
+
|
| 363 |
+
function _zthToken(address _tokenContract) private view returns (bool) {
|
| 364 |
+
return _tokenContract == ZTHTKNADDR;
|
| 365 |
+
|
| 366 |
+
}
|
| 367 |
+
}
|
| 368 |
+
|
| 369 |
+
|
| 370 |
+
library SafeMath {
|
| 371 |
+
|
| 372 |
+
|
| 373 |
+
function mul(uint a, uint b) internal pure returns (uint) {
|
| 374 |
+
if (a == 0) {
|
| 375 |
+
return 0;
|
| 376 |
+
}
|
| 377 |
+
uint c = a * b;
|
| 378 |
+
assert(c / a == b);
|
| 379 |
+
return c;
|
| 380 |
+
}
|
| 381 |
+
|
| 382 |
+
|
| 383 |
+
function div(uint a, uint b) internal pure returns (uint) {
|
| 384 |
+
|
| 385 |
+
uint c = a / b;
|
| 386 |
+
|
| 387 |
+
return c;
|
| 388 |
+
}
|
| 389 |
+
|
| 390 |
+
|
| 391 |
+
function sub(uint a, uint b) internal pure returns (uint) {
|
| 392 |
+
assert(b <= a);
|
| 393 |
+
return a - b;
|
| 394 |
+
}
|
| 395 |
+
|
| 396 |
+
|
| 397 |
+
function add(uint a, uint b) internal pure returns (uint) {
|
| 398 |
+
uint c = a + b;
|
| 399 |
+
assert(c >= a);
|
| 400 |
+
return c;
|
| 401 |
+
}
|
| 402 |
+
}
|
smart_contract_dataset/block number dependency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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
pragma solidity ^0.4.23;
|
| 2 |
+
|
| 3 |
+
|
| 4 |
+
|
| 5 |
+
contract ZTHReceivingContract {
|
| 6 |
+
|
| 7 |
+
function tokenFallback(address _from, uint _value, bytes _data) public returns (bool);
|
| 8 |
+
}
|
| 9 |
+
|
| 10 |
+
|
| 11 |
+
contract ZTHInterface {
|
| 12 |
+
function getFrontEndTokenBalanceOf(address who) public view returns (uint);
|
| 13 |
+
function transfer(address _to, uint _value) public returns (bool);
|
| 14 |
+
function approve(address spender, uint tokens) public returns (bool);
|
| 15 |
+
}
|
| 16 |
+
|
| 17 |
+
contract Zethroll is ZTHReceivingContract {
|
| 18 |
+
using SafeMath for uint;
|
| 19 |
+
|
| 20 |
+
|
| 21 |
+
|
| 22 |
+
modifier betIsValid(uint _betSize, uint _playerNumber) {
|
| 23 |
+
require( calculateProfit(_betSize, _playerNumber) < maxProfit
|
| 24 |
+
&& _betSize >= minBet
|
| 25 |
+
&& _playerNumber > minNumber
|
| 26 |
+
&& _playerNumber < maxNumber);
|
| 27 |
+
_;
|
| 28 |
+
}
|
| 29 |
+
|
| 30 |
+
|
| 31 |
+
modifier gameIsActive {
|
| 32 |
+
require(gamePaused == false);
|
| 33 |
+
_;
|
| 34 |
+
}
|
| 35 |
+
|
| 36 |
+
|
| 37 |
+
modifier onlyOwner {
|
| 38 |
+
require(msg.sender == owner);
|
| 39 |
+
_;
|
| 40 |
+
}
|
| 41 |
+
|
| 42 |
+
|
| 43 |
+
uint constant private MAX_INT = 2 ** 256 - 1;
|
| 44 |
+
uint constant public maxProfitDivisor = 1000000;
|
| 45 |
+
uint constant public maxNumber = 99;
|
| 46 |
+
uint constant public minNumber = 2;
|
| 47 |
+
uint constant public houseEdgeDivisor = 1000;
|
| 48 |
+
|
| 49 |
+
|
| 50 |
+
bool public gamePaused;
|
| 51 |
+
|
| 52 |
+
address public owner;
|
| 53 |
+
address public ZethrBankroll;
|
| 54 |
+
address public ZTHTKNADDR;
|
| 55 |
+
|
| 56 |
+
ZTHInterface public ZTHTKN;
|
| 57 |
+
|
| 58 |
+
uint public contractBalance;
|
| 59 |
+
uint public houseEdge;
|
| 60 |
+
uint public maxProfit;
|
| 61 |
+
uint public maxProfitAsPercentOfHouse;
|
| 62 |
+
uint public minBet = 0;
|
| 63 |
+
|
| 64 |
+
|
| 65 |
+
uint public totalBets;
|
| 66 |
+
uint public totalZTHWagered;
|
| 67 |
+
|
| 68 |
+
|
| 69 |
+
|
| 70 |
+
|
| 71 |
+
event LogBet(address sender, uint value, uint rollUnder);
|
| 72 |
+
|
| 73 |
+
|
| 74 |
+
|
| 75 |
+
event LogResult(address player, uint result, uint rollUnder, uint profit, uint tokensBetted, bool won);
|
| 76 |
+
|
| 77 |
+
|
| 78 |
+
event LogOwnerTransfer(address indexed SentToAddress, uint indexed AmountTransferred);
|
| 79 |
+
|
| 80 |
+
|
| 81 |
+
event MaxProfitChanged(uint _oldMaxProfit, uint _newMaxProfit);
|
| 82 |
+
|
| 83 |
+
|
| 84 |
+
event CurrentContractBalance(uint _tokens);
|
| 85 |
+
|
| 86 |
+
constructor (address zthtknaddr, address zthbankrolladdr) public {
|
| 87 |
+
|
| 88 |
+
owner = msg.sender;
|
| 89 |
+
|
| 90 |
+
|
| 91 |
+
ZTHTKN = ZTHInterface(zthtknaddr);
|
| 92 |
+
ZTHTKNADDR = zthtknaddr;
|
| 93 |
+
|
| 94 |
+
|
| 95 |
+
ZethrBankroll = zthbankrolladdr;
|
| 96 |
+
|
| 97 |
+
|
| 98 |
+
houseEdge = 990;
|
| 99 |
+
|
| 100 |
+
|
| 101 |
+
ownerSetMaxProfitAsPercentOfHouse(10000);
|
| 102 |
+
|
| 103 |
+
|
| 104 |
+
ownerSetMinBet(1e18);
|
| 105 |
+
|
| 106 |
+
|
| 107 |
+
ZTHTKN.approve(zthbankrolladdr, MAX_INT);
|
| 108 |
+
}
|
| 109 |
+
|
| 110 |
+
function() public payable {}
|
| 111 |
+
|
| 112 |
+
|
| 113 |
+
|
| 114 |
+
function maxRandom(uint blockn, address entropy) public view returns (uint256 randomNumber) {
|
| 115 |
+
return uint256(keccak256(
|
| 116 |
+
abi.encodePacked(
|
| 117 |
+
blockhash(blockn),
|
| 118 |
+
entropy)
|
| 119 |
+
));
|
| 120 |
+
}
|
| 121 |
+
|
| 122 |
+
|
| 123 |
+
function random(uint256 upper, uint256 blockn, address entropy) internal view returns (uint256 randomNumber) {
|
| 124 |
+
return maxRandom(blockn, entropy) % upper;
|
| 125 |
+
}
|
| 126 |
+
|
| 127 |
+
|
| 128 |
+
function calculateProfit(uint _initBet, uint _roll)
|
| 129 |
+
private
|
| 130 |
+
view
|
| 131 |
+
returns (uint)
|
| 132 |
+
{
|
| 133 |
+
return ((((_initBet * (100 - (_roll.sub(1)))) / (_roll.sub(1)) + _initBet)) * houseEdge / houseEdgeDivisor) - _initBet;
|
| 134 |
+
}
|
| 135 |
+
|
| 136 |
+
|
| 137 |
+
struct playerRoll{
|
| 138 |
+
uint200 tokenValue;
|
| 139 |
+
uint48 blockn;
|
| 140 |
+
uint8 rollUnder;
|
| 141 |
+
}
|
| 142 |
+
|
| 143 |
+
|
| 144 |
+
mapping(address => playerRoll) public playerRolls;
|
| 145 |
+
|
| 146 |
+
function _playerRollDice(uint _rollUnder, TKN _tkn) private
|
| 147 |
+
gameIsActive
|
| 148 |
+
betIsValid(_tkn.value, _rollUnder)
|
| 149 |
+
{
|
| 150 |
+
require(_tkn.value < ((2 ** 200) - 1));
|
| 151 |
+
require(block.number < ((2 ** 48) - 1));
|
| 152 |
+
|
| 153 |
+
|
| 154 |
+
|
| 155 |
+
|
| 156 |
+
|
| 157 |
+
require(_zthToken(msg.sender));
|
| 158 |
+
|
| 159 |
+
playerRoll memory roll = playerRolls[_tkn.sender];
|
| 160 |
+
|
| 161 |
+
|
| 162 |
+
require(block.number != roll.blockn);
|
| 163 |
+
|
| 164 |
+
|
| 165 |
+
if (roll.blockn != 0) {
|
| 166 |
+
_finishBet(false, _tkn.sender);
|
| 167 |
+
}
|
| 168 |
+
|
| 169 |
+
|
| 170 |
+
roll.blockn = uint48(block.number);
|
| 171 |
+
roll.tokenValue = uint200(_tkn.value);
|
| 172 |
+
roll.rollUnder = uint8(_rollUnder);
|
| 173 |
+
|
| 174 |
+
|
| 175 |
+
playerRolls[_tkn.sender] = roll;
|
| 176 |
+
|
| 177 |
+
|
| 178 |
+
emit LogBet(_tkn.sender, _tkn.value, _rollUnder);
|
| 179 |
+
|
| 180 |
+
|
| 181 |
+
totalBets += 1;
|
| 182 |
+
|
| 183 |
+
|
| 184 |
+
totalZTHWagered += _tkn.value;
|
| 185 |
+
}
|
| 186 |
+
|
| 187 |
+
|
| 188 |
+
function finishBet() public
|
| 189 |
+
gameIsActive
|
| 190 |
+
returns (uint)
|
| 191 |
+
{
|
| 192 |
+
return _finishBet(true, msg.sender);
|
| 193 |
+
}
|
| 194 |
+
|
| 195 |
+
|
| 196 |
+
function _finishBet(bool delete_it, address target) private returns (uint){
|
| 197 |
+
playerRoll memory roll = playerRolls[target];
|
| 198 |
+
require(roll.tokenValue > 0);
|
| 199 |
+
require(roll.blockn != block.number);
|
| 200 |
+
|
| 201 |
+
|
| 202 |
+
uint result;
|
| 203 |
+
if (block.number - roll.blockn > 255) {
|
| 204 |
+
result = 1000;
|
| 205 |
+
} else {
|
| 206 |
+
|
| 207 |
+
result = random(99, roll.blockn, target) + 1;
|
| 208 |
+
}
|
| 209 |
+
|
| 210 |
+
uint rollUnder = roll.rollUnder;
|
| 211 |
+
|
| 212 |
+
if (result < rollUnder) {
|
| 213 |
+
|
| 214 |
+
|
| 215 |
+
|
| 216 |
+
uint profit = calculateProfit(roll.tokenValue, rollUnder);
|
| 217 |
+
|
| 218 |
+
if (profit > maxProfit){
|
| 219 |
+
profit = maxProfit;
|
| 220 |
+
}
|
| 221 |
+
|
| 222 |
+
|
| 223 |
+
contractBalance = contractBalance.sub(profit);
|
| 224 |
+
|
| 225 |
+
emit LogResult(target, result, rollUnder, profit, roll.tokenValue, true);
|
| 226 |
+
|
| 227 |
+
|
| 228 |
+
setMaxProfit();
|
| 229 |
+
|
| 230 |
+
if (delete_it){
|
| 231 |
+
|
| 232 |
+
delete playerRolls[target];
|
| 233 |
+
}
|
| 234 |
+
|
| 235 |
+
|
| 236 |
+
ZTHTKN.transfer(target, profit + roll.tokenValue);
|
| 237 |
+
|
| 238 |
+
return result;
|
| 239 |
+
|
| 240 |
+
} else {
|
| 241 |
+
|
| 242 |
+
emit LogResult(target, result, rollUnder, profit, roll.tokenValue, false);
|
| 243 |
+
|
| 244 |
+
|
| 245 |
+
contractBalance = contractBalance.add(roll.tokenValue);
|
| 246 |
+
|
| 247 |
+
|
| 248 |
+
|
| 249 |
+
|
| 250 |
+
|
| 251 |
+
setMaxProfit();
|
| 252 |
+
|
| 253 |
+
return result;
|
| 254 |
+
}
|
| 255 |
+
}
|
| 256 |
+
|
| 257 |
+
|
| 258 |
+
struct TKN {address sender; uint value;}
|
| 259 |
+
|
| 260 |
+
|
| 261 |
+
function tokenFallback(address _from, uint _value, bytes _data) public returns (bool) {
|
| 262 |
+
require(msg.sender == ZTHTKNADDR);
|
| 263 |
+
if (_from == ZethrBankroll) {
|
| 264 |
+
|
| 265 |
+
contractBalance = contractBalance.add(_value);
|
| 266 |
+
|
| 267 |
+
|
| 268 |
+
uint oldMaxProfit = maxProfit;
|
| 269 |
+
setMaxProfit();
|
| 270 |
+
|
| 271 |
+
emit MaxProfitChanged(oldMaxProfit, maxProfit);
|
| 272 |
+
return true;
|
| 273 |
+
|
| 274 |
+
} else {
|
| 275 |
+
TKN memory _tkn;
|
| 276 |
+
_tkn.sender = _from;
|
| 277 |
+
_tkn.value = _value;
|
| 278 |
+
uint8 chosenNumber = uint8(_data[0]);
|
| 279 |
+
_playerRollDice(chosenNumber, _tkn);
|
| 280 |
+
}
|
| 281 |
+
|
| 282 |
+
return true;
|
| 283 |
+
}
|
| 284 |
+
|
| 285 |
+
|
| 286 |
+
function setMaxProfit() internal {
|
| 287 |
+
emit CurrentContractBalance(contractBalance);
|
| 288 |
+
maxProfit = (contractBalance * maxProfitAsPercentOfHouse) / maxProfitDivisor;
|
| 289 |
+
}
|
| 290 |
+
|
| 291 |
+
|
| 292 |
+
function ownerUpdateContractBalance(uint newContractBalance) public
|
| 293 |
+
onlyOwner
|
| 294 |
+
{
|
| 295 |
+
contractBalance = newContractBalance;
|
| 296 |
+
}
|
| 297 |
+
|
| 298 |
+
|
| 299 |
+
function ownerSetMaxProfitAsPercentOfHouse(uint newMaxProfitAsPercent) public
|
| 300 |
+
onlyOwner
|
| 301 |
+
{
|
| 302 |
+
|
| 303 |
+
require(newMaxProfitAsPercent <= 200000);
|
| 304 |
+
maxProfitAsPercentOfHouse = newMaxProfitAsPercent;
|
| 305 |
+
setMaxProfit();
|
| 306 |
+
}
|
| 307 |
+
|
| 308 |
+
|
| 309 |
+
function ownerSetMinBet(uint newMinimumBet) public
|
| 310 |
+
onlyOwner
|
| 311 |
+
{
|
| 312 |
+
minBet = newMinimumBet;
|
| 313 |
+
}
|
| 314 |
+
|
| 315 |
+
|
| 316 |
+
function ownerTransferZTH(address sendTo, uint amount) public
|
| 317 |
+
onlyOwner
|
| 318 |
+
{
|
| 319 |
+
|
| 320 |
+
contractBalance = contractBalance.sub(amount);
|
| 321 |
+
|
| 322 |
+
|
| 323 |
+
setMaxProfit();
|
| 324 |
+
require(ZTHTKN.transfer(sendTo, amount));
|
| 325 |
+
emit LogOwnerTransfer(sendTo, amount);
|
| 326 |
+
}
|
| 327 |
+
|
| 328 |
+
|
| 329 |
+
function ownerPauseGame(bool newStatus) public
|
| 330 |
+
onlyOwner
|
| 331 |
+
{
|
| 332 |
+
gamePaused = newStatus;
|
| 333 |
+
}
|
| 334 |
+
|
| 335 |
+
|
| 336 |
+
function ownerSetBankroll(address newBankroll) public
|
| 337 |
+
onlyOwner
|
| 338 |
+
{
|
| 339 |
+
ZTHTKN.approve(ZethrBankroll, 0);
|
| 340 |
+
ZethrBankroll = newBankroll;
|
| 341 |
+
ZTHTKN.approve(newBankroll, MAX_INT);
|
| 342 |
+
}
|
| 343 |
+
|
| 344 |
+
|
| 345 |
+
function ownerChangeOwner(address newOwner) public
|
| 346 |
+
onlyOwner
|
| 347 |
+
{
|
| 348 |
+
owner = newOwner;
|
| 349 |
+
}
|
| 350 |
+
|
| 351 |
+
|
| 352 |
+
function ownerkill() public
|
| 353 |
+
onlyOwner
|
| 354 |
+
{
|
| 355 |
+
ZTHTKN.transfer(owner, contractBalance);
|
| 356 |
+
selfdestruct(owner);
|
| 357 |
+
}
|
| 358 |
+
|
| 359 |
+
function dumpdivs() public{
|
| 360 |
+
ZethrBankroll.transfer(address(this).balance);
|
| 361 |
+
}
|
| 362 |
+
|
| 363 |
+
function _zthToken(address _tokenContract) private view returns (bool) {
|
| 364 |
+
return _tokenContract == ZTHTKNADDR;
|
| 365 |
+
|
| 366 |
+
}
|
| 367 |
+
}
|
| 368 |
+
|
| 369 |
+
|
| 370 |
+
library SafeMath {
|
| 371 |
+
|
| 372 |
+
|
| 373 |
+
function mul(uint a, uint b) internal pure returns (uint) {
|
| 374 |
+
if (a == 0) {
|
| 375 |
+
return 0;
|
| 376 |
+
}
|
| 377 |
+
uint c = a * b;
|
| 378 |
+
assert(c / a == b);
|
| 379 |
+
return c;
|
| 380 |
+
}
|
| 381 |
+
|
| 382 |
+
|
| 383 |
+
function div(uint a, uint b) internal pure returns (uint) {
|
| 384 |
+
|
| 385 |
+
uint c = a / b;
|
| 386 |
+
|
| 387 |
+
return c;
|
| 388 |
+
}
|
| 389 |
+
|
| 390 |
+
|
| 391 |
+
function sub(uint a, uint b) internal pure returns (uint) {
|
| 392 |
+
assert(b <= a);
|
| 393 |
+
return a - b;
|
| 394 |
+
}
|
| 395 |
+
|
| 396 |
+
|
| 397 |
+
function add(uint a, uint b) internal pure returns (uint) {
|
| 398 |
+
uint c = a + b;
|
| 399 |
+
assert(c >= a);
|
| 400 |
+
return c;
|
| 401 |
+
}
|
| 402 |
+
}
|
smart_contract_dataset/block number dependency/2589.sol
ADDED
|
@@ -0,0 +1,398 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
pragma solidity ^0.4.23;
|
| 2 |
+
|
| 3 |
+
|
| 4 |
+
|
| 5 |
+
contract ZTHReceivingContract {
|
| 6 |
+
|
| 7 |
+
function tokenFallback(address _from, uint _value, bytes _data) public returns (bool);
|
| 8 |
+
}
|
| 9 |
+
|
| 10 |
+
|
| 11 |
+
contract ZTHInterface {
|
| 12 |
+
function getFrontEndTokenBalanceOf(address who) public view returns (uint);
|
| 13 |
+
function transfer(address _to, uint _value) public returns (bool);
|
| 14 |
+
function approve(address spender, uint tokens) public returns (bool);
|
| 15 |
+
}
|
| 16 |
+
|
| 17 |
+
contract Zethroll is ZTHReceivingContract {
|
| 18 |
+
using SafeMath for uint;
|
| 19 |
+
|
| 20 |
+
|
| 21 |
+
|
| 22 |
+
modifier betIsValid(uint _betSize, uint _playerNumber) {
|
| 23 |
+
require( calculateProfit(_betSize, _playerNumber) < maxProfit
|
| 24 |
+
&& _betSize >= minBet
|
| 25 |
+
&& _playerNumber > minNumber
|
| 26 |
+
&& _playerNumber < maxNumber);
|
| 27 |
+
_;
|
| 28 |
+
}
|
| 29 |
+
|
| 30 |
+
|
| 31 |
+
modifier gameIsActive {
|
| 32 |
+
require(gamePaused == false);
|
| 33 |
+
_;
|
| 34 |
+
}
|
| 35 |
+
|
| 36 |
+
|
| 37 |
+
modifier onlyOwner {
|
| 38 |
+
require(msg.sender == owner);
|
| 39 |
+
_;
|
| 40 |
+
}
|
| 41 |
+
|
| 42 |
+
|
| 43 |
+
uint constant private MAX_INT = 2 ** 256 - 1;
|
| 44 |
+
uint constant public maxProfitDivisor = 1000000;
|
| 45 |
+
uint constant public maxNumber = 99;
|
| 46 |
+
uint constant public minNumber = 2;
|
| 47 |
+
uint constant public houseEdgeDivisor = 1000;
|
| 48 |
+
|
| 49 |
+
|
| 50 |
+
bool public gamePaused;
|
| 51 |
+
|
| 52 |
+
address public owner;
|
| 53 |
+
address public ZethrBankroll;
|
| 54 |
+
address public ZTHTKNADDR;
|
| 55 |
+
|
| 56 |
+
ZTHInterface public ZTHTKN;
|
| 57 |
+
|
| 58 |
+
uint public contractBalance;
|
| 59 |
+
uint public houseEdge;
|
| 60 |
+
uint public maxProfit;
|
| 61 |
+
uint public maxProfitAsPercentOfHouse;
|
| 62 |
+
uint public minBet = 0;
|
| 63 |
+
|
| 64 |
+
|
| 65 |
+
uint public totalBets;
|
| 66 |
+
uint public totalZTHWagered;
|
| 67 |
+
|
| 68 |
+
|
| 69 |
+
|
| 70 |
+
|
| 71 |
+
event LogBet(address sender, uint value, uint rollUnder);
|
| 72 |
+
|
| 73 |
+
|
| 74 |
+
|
| 75 |
+
event LogResult(address player, uint result, uint rollUnder, uint profit, uint tokensBetted, bool won);
|
| 76 |
+
|
| 77 |
+
|
| 78 |
+
event LogOwnerTransfer(address indexed SentToAddress, uint indexed AmountTransferred);
|
| 79 |
+
|
| 80 |
+
|
| 81 |
+
event MaxProfitChanged(uint _oldMaxProfit, uint _newMaxProfit);
|
| 82 |
+
|
| 83 |
+
|
| 84 |
+
event CurrentContractBalance(uint _tokens);
|
| 85 |
+
|
| 86 |
+
constructor (address zthtknaddr, address zthbankrolladdr) public {
|
| 87 |
+
|
| 88 |
+
owner = msg.sender;
|
| 89 |
+
|
| 90 |
+
|
| 91 |
+
ZTHTKN = ZTHInterface(zthtknaddr);
|
| 92 |
+
ZTHTKNADDR = zthtknaddr;
|
| 93 |
+
|
| 94 |
+
|
| 95 |
+
ZethrBankroll = zthbankrolladdr;
|
| 96 |
+
|
| 97 |
+
|
| 98 |
+
houseEdge = 990;
|
| 99 |
+
|
| 100 |
+
|
| 101 |
+
ownerSetMaxProfitAsPercentOfHouse(10000);
|
| 102 |
+
|
| 103 |
+
|
| 104 |
+
ownerSetMinBet(1e18);
|
| 105 |
+
|
| 106 |
+
|
| 107 |
+
ZTHTKN.approve(zthbankrolladdr, MAX_INT);
|
| 108 |
+
}
|
| 109 |
+
|
| 110 |
+
function() public payable {}
|
| 111 |
+
|
| 112 |
+
|
| 113 |
+
|
| 114 |
+
function maxRandom(uint blockn, address entropy) public view returns (uint256 randomNumber) {
|
| 115 |
+
return uint256(keccak256(
|
| 116 |
+
abi.encodePacked(
|
| 117 |
+
blockhash(blockn),
|
| 118 |
+
entropy)
|
| 119 |
+
));
|
| 120 |
+
}
|
| 121 |
+
|
| 122 |
+
|
| 123 |
+
function random(uint256 upper, uint256 blockn, address entropy) internal view returns (uint256 randomNumber) {
|
| 124 |
+
return maxRandom(blockn, entropy) % upper;
|
| 125 |
+
}
|
| 126 |
+
|
| 127 |
+
|
| 128 |
+
function calculateProfit(uint _initBet, uint _roll)
|
| 129 |
+
private
|
| 130 |
+
view
|
| 131 |
+
returns (uint)
|
| 132 |
+
{
|
| 133 |
+
return ((((_initBet * (100 - (_roll.sub(1)))) / (_roll.sub(1)) + _initBet)) * houseEdge / houseEdgeDivisor) - _initBet;
|
| 134 |
+
}
|
| 135 |
+
|
| 136 |
+
|
| 137 |
+
struct playerRoll{
|
| 138 |
+
uint200 tokenValue;
|
| 139 |
+
uint48 blockn;
|
| 140 |
+
uint8 rollUnder;
|
| 141 |
+
}
|
| 142 |
+
|
| 143 |
+
|
| 144 |
+
mapping(address => playerRoll) public playerRolls;
|
| 145 |
+
|
| 146 |
+
function _playerRollDice(uint _rollUnder, TKN _tkn) private
|
| 147 |
+
gameIsActive
|
| 148 |
+
betIsValid(_tkn.value, _rollUnder)
|
| 149 |
+
{
|
| 150 |
+
require(_tkn.value < ((2 ** 200) - 1));
|
| 151 |
+
require(block.number < ((2 ** 48) - 1));
|
| 152 |
+
|
| 153 |
+
|
| 154 |
+
|
| 155 |
+
|
| 156 |
+
|
| 157 |
+
require(_zthToken(msg.sender));
|
| 158 |
+
|
| 159 |
+
playerRoll memory roll = playerRolls[_tkn.sender];
|
| 160 |
+
|
| 161 |
+
|
| 162 |
+
require(block.number != roll.blockn);
|
| 163 |
+
|
| 164 |
+
|
| 165 |
+
if (roll.blockn != 0) {
|
| 166 |
+
_finishBet(false, _tkn.sender);
|
| 167 |
+
}
|
| 168 |
+
|
| 169 |
+
|
| 170 |
+
roll.blockn = uint40(block.number);
|
| 171 |
+
roll.tokenValue = uint200(_tkn.value);
|
| 172 |
+
roll.rollUnder = uint8(_rollUnder);
|
| 173 |
+
|
| 174 |
+
|
| 175 |
+
playerRolls[_tkn.sender] = roll;
|
| 176 |
+
|
| 177 |
+
|
| 178 |
+
emit LogBet(_tkn.sender, _tkn.value, _rollUnder);
|
| 179 |
+
|
| 180 |
+
|
| 181 |
+
totalBets += 1;
|
| 182 |
+
|
| 183 |
+
|
| 184 |
+
totalZTHWagered += _tkn.value;
|
| 185 |
+
}
|
| 186 |
+
|
| 187 |
+
|
| 188 |
+
function finishBet() public
|
| 189 |
+
gameIsActive
|
| 190 |
+
returns (uint)
|
| 191 |
+
{
|
| 192 |
+
return _finishBet(true, msg.sender);
|
| 193 |
+
}
|
| 194 |
+
|
| 195 |
+
|
| 196 |
+
function _finishBet(bool delete_it, address target) private returns (uint){
|
| 197 |
+
playerRoll memory roll = playerRolls[target];
|
| 198 |
+
require(roll.tokenValue > 0);
|
| 199 |
+
require(roll.blockn != block.number);
|
| 200 |
+
|
| 201 |
+
|
| 202 |
+
uint result;
|
| 203 |
+
if (block.number - roll.blockn > 255) {
|
| 204 |
+
result = 1000;
|
| 205 |
+
} else {
|
| 206 |
+
|
| 207 |
+
result = random(99, roll.blockn, target) + 1;
|
| 208 |
+
}
|
| 209 |
+
|
| 210 |
+
uint rollUnder = roll.rollUnder;
|
| 211 |
+
|
| 212 |
+
if (result < rollUnder) {
|
| 213 |
+
|
| 214 |
+
|
| 215 |
+
|
| 216 |
+
uint profit = calculateProfit(roll.tokenValue, rollUnder);
|
| 217 |
+
|
| 218 |
+
|
| 219 |
+
contractBalance = contractBalance.sub(profit);
|
| 220 |
+
|
| 221 |
+
emit LogResult(target, result, rollUnder, profit, roll.tokenValue, true);
|
| 222 |
+
|
| 223 |
+
|
| 224 |
+
setMaxProfit();
|
| 225 |
+
|
| 226 |
+
if (delete_it){
|
| 227 |
+
|
| 228 |
+
delete playerRolls[target];
|
| 229 |
+
}
|
| 230 |
+
|
| 231 |
+
|
| 232 |
+
ZTHTKN.transfer(target, profit + roll.tokenValue);
|
| 233 |
+
|
| 234 |
+
return result;
|
| 235 |
+
|
| 236 |
+
} else {
|
| 237 |
+
|
| 238 |
+
emit LogResult(target, result, rollUnder, profit, roll.tokenValue, false);
|
| 239 |
+
|
| 240 |
+
|
| 241 |
+
contractBalance = contractBalance.add(roll.tokenValue);
|
| 242 |
+
|
| 243 |
+
|
| 244 |
+
|
| 245 |
+
|
| 246 |
+
|
| 247 |
+
setMaxProfit();
|
| 248 |
+
|
| 249 |
+
return result;
|
| 250 |
+
}
|
| 251 |
+
}
|
| 252 |
+
|
| 253 |
+
|
| 254 |
+
struct TKN {address sender; uint value;}
|
| 255 |
+
|
| 256 |
+
|
| 257 |
+
function tokenFallback(address _from, uint _value, bytes _data) public returns (bool) {
|
| 258 |
+
require(msg.sender == ZTHTKNADDR);
|
| 259 |
+
if (_from == ZethrBankroll) {
|
| 260 |
+
|
| 261 |
+
contractBalance = contractBalance.add(_value);
|
| 262 |
+
|
| 263 |
+
|
| 264 |
+
uint oldMaxProfit = maxProfit;
|
| 265 |
+
setMaxProfit();
|
| 266 |
+
|
| 267 |
+
emit MaxProfitChanged(oldMaxProfit, maxProfit);
|
| 268 |
+
return true;
|
| 269 |
+
|
| 270 |
+
} else {
|
| 271 |
+
TKN memory _tkn;
|
| 272 |
+
_tkn.sender = _from;
|
| 273 |
+
_tkn.value = _value;
|
| 274 |
+
uint8 chosenNumber = uint8(_data[0]);
|
| 275 |
+
_playerRollDice(chosenNumber, _tkn);
|
| 276 |
+
}
|
| 277 |
+
|
| 278 |
+
return true;
|
| 279 |
+
}
|
| 280 |
+
|
| 281 |
+
|
| 282 |
+
function setMaxProfit() internal {
|
| 283 |
+
emit CurrentContractBalance(contractBalance);
|
| 284 |
+
maxProfit = (contractBalance * maxProfitAsPercentOfHouse) / maxProfitDivisor;
|
| 285 |
+
}
|
| 286 |
+
|
| 287 |
+
|
| 288 |
+
function ownerUpdateContractBalance(uint newContractBalance) public
|
| 289 |
+
onlyOwner
|
| 290 |
+
{
|
| 291 |
+
contractBalance = newContractBalance;
|
| 292 |
+
}
|
| 293 |
+
|
| 294 |
+
|
| 295 |
+
function ownerSetMaxProfitAsPercentOfHouse(uint newMaxProfitAsPercent) public
|
| 296 |
+
onlyOwner
|
| 297 |
+
{
|
| 298 |
+
|
| 299 |
+
require(newMaxProfitAsPercent <= 200000);
|
| 300 |
+
maxProfitAsPercentOfHouse = newMaxProfitAsPercent;
|
| 301 |
+
setMaxProfit();
|
| 302 |
+
}
|
| 303 |
+
|
| 304 |
+
|
| 305 |
+
function ownerSetMinBet(uint newMinimumBet) public
|
| 306 |
+
onlyOwner
|
| 307 |
+
{
|
| 308 |
+
minBet = newMinimumBet;
|
| 309 |
+
}
|
| 310 |
+
|
| 311 |
+
|
| 312 |
+
function ownerTransferZTH(address sendTo, uint amount) public
|
| 313 |
+
onlyOwner
|
| 314 |
+
{
|
| 315 |
+
|
| 316 |
+
contractBalance = contractBalance.sub(amount);
|
| 317 |
+
|
| 318 |
+
|
| 319 |
+
setMaxProfit();
|
| 320 |
+
require(ZTHTKN.transfer(sendTo, amount));
|
| 321 |
+
emit LogOwnerTransfer(sendTo, amount);
|
| 322 |
+
}
|
| 323 |
+
|
| 324 |
+
|
| 325 |
+
function ownerPauseGame(bool newStatus) public
|
| 326 |
+
onlyOwner
|
| 327 |
+
{
|
| 328 |
+
gamePaused = newStatus;
|
| 329 |
+
}
|
| 330 |
+
|
| 331 |
+
|
| 332 |
+
function ownerSetBankroll(address newBankroll) public
|
| 333 |
+
onlyOwner
|
| 334 |
+
{
|
| 335 |
+
ZTHTKN.approve(ZethrBankroll, 0);
|
| 336 |
+
ZethrBankroll = newBankroll;
|
| 337 |
+
ZTHTKN.approve(newBankroll, MAX_INT);
|
| 338 |
+
}
|
| 339 |
+
|
| 340 |
+
|
| 341 |
+
function ownerChangeOwner(address newOwner) public
|
| 342 |
+
onlyOwner
|
| 343 |
+
{
|
| 344 |
+
owner = newOwner;
|
| 345 |
+
}
|
| 346 |
+
|
| 347 |
+
|
| 348 |
+
function ownerkill() public
|
| 349 |
+
onlyOwner
|
| 350 |
+
{
|
| 351 |
+
ZTHTKN.transfer(owner, contractBalance);
|
| 352 |
+
selfdestruct(owner);
|
| 353 |
+
}
|
| 354 |
+
|
| 355 |
+
function dumpdivs() public{
|
| 356 |
+
ZethrBankroll.transfer(address(this).balance);
|
| 357 |
+
}
|
| 358 |
+
|
| 359 |
+
function _zthToken(address _tokenContract) private view returns (bool) {
|
| 360 |
+
return _tokenContract == ZTHTKNADDR;
|
| 361 |
+
|
| 362 |
+
}
|
| 363 |
+
}
|
| 364 |
+
|
| 365 |
+
|
| 366 |
+
library SafeMath {
|
| 367 |
+
|
| 368 |
+
|
| 369 |
+
function mul(uint a, uint b) internal pure returns (uint) {
|
| 370 |
+
if (a == 0) {
|
| 371 |
+
return 0;
|
| 372 |
+
}
|
| 373 |
+
uint c = a * b;
|
| 374 |
+
assert(c / a == b);
|
| 375 |
+
return c;
|
| 376 |
+
}
|
| 377 |
+
|
| 378 |
+
|
| 379 |
+
function div(uint a, uint b) internal pure returns (uint) {
|
| 380 |
+
|
| 381 |
+
uint c = a / b;
|
| 382 |
+
|
| 383 |
+
return c;
|
| 384 |
+
}
|
| 385 |
+
|
| 386 |
+
|
| 387 |
+
function sub(uint a, uint b) internal pure returns (uint) {
|
| 388 |
+
assert(b <= a);
|
| 389 |
+
return a - b;
|
| 390 |
+
}
|
| 391 |
+
|
| 392 |
+
|
| 393 |
+
function add(uint a, uint b) internal pure returns (uint) {
|
| 394 |
+
uint c = a + b;
|
| 395 |
+
assert(c >= a);
|
| 396 |
+
return c;
|
| 397 |
+
}
|
| 398 |
+
}
|
smart_contract_dataset/block number dependency/2593.sol
ADDED
|
@@ -0,0 +1,397 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
pragma solidity ^0.4.23;
|
| 2 |
+
|
| 3 |
+
|
| 4 |
+
|
| 5 |
+
contract ZTHReceivingContract {
|
| 6 |
+
|
| 7 |
+
function tokenFallback(address _from, uint _value, bytes _data) public returns (bool);
|
| 8 |
+
}
|
| 9 |
+
|
| 10 |
+
|
| 11 |
+
contract ZTHInterface {
|
| 12 |
+
function getFrontEndTokenBalanceOf(address who) public view returns (uint);
|
| 13 |
+
function transfer(address _to, uint _value) public returns (bool);
|
| 14 |
+
function approve(address spender, uint tokens) public returns (bool);
|
| 15 |
+
}
|
| 16 |
+
|
| 17 |
+
contract Zethroll is ZTHReceivingContract {
|
| 18 |
+
using SafeMath for uint;
|
| 19 |
+
|
| 20 |
+
|
| 21 |
+
|
| 22 |
+
modifier betIsValid(uint _betSize, uint _playerNumber) {
|
| 23 |
+
require( calculateProfit(_betSize, _playerNumber) < maxProfit
|
| 24 |
+
&& _betSize >= minBet
|
| 25 |
+
&& _playerNumber > minNumber
|
| 26 |
+
&& _playerNumber < maxNumber);
|
| 27 |
+
_;
|
| 28 |
+
}
|
| 29 |
+
|
| 30 |
+
|
| 31 |
+
modifier gameIsActive {
|
| 32 |
+
require(gamePaused == false);
|
| 33 |
+
_;
|
| 34 |
+
}
|
| 35 |
+
|
| 36 |
+
|
| 37 |
+
modifier onlyOwner {
|
| 38 |
+
require(msg.sender == owner);
|
| 39 |
+
_;
|
| 40 |
+
}
|
| 41 |
+
|
| 42 |
+
|
| 43 |
+
uint constant private MAX_INT = 2 ** 256 - 1;
|
| 44 |
+
uint constant public maxProfitDivisor = 1000000;
|
| 45 |
+
uint constant public maxNumber = 99;
|
| 46 |
+
uint constant public minNumber = 2;
|
| 47 |
+
uint constant public houseEdgeDivisor = 1000;
|
| 48 |
+
|
| 49 |
+
|
| 50 |
+
bool public gamePaused;
|
| 51 |
+
|
| 52 |
+
address public owner;
|
| 53 |
+
address public ZethrBankroll;
|
| 54 |
+
address public ZTHTKNADDR;
|
| 55 |
+
|
| 56 |
+
ZTHInterface public ZTHTKN;
|
| 57 |
+
|
| 58 |
+
uint public contractBalance;
|
| 59 |
+
uint public houseEdge;
|
| 60 |
+
uint public maxProfit;
|
| 61 |
+
uint public maxProfitAsPercentOfHouse;
|
| 62 |
+
uint public minBet = 0;
|
| 63 |
+
|
| 64 |
+
|
| 65 |
+
uint public totalBets;
|
| 66 |
+
uint public totalZTHWagered;
|
| 67 |
+
|
| 68 |
+
|
| 69 |
+
|
| 70 |
+
|
| 71 |
+
event LogBet(address sender, uint value, uint rollUnder);
|
| 72 |
+
|
| 73 |
+
|
| 74 |
+
|
| 75 |
+
event LogResult(address player, uint result, uint rollUnder, uint profit, uint tokensBetted, bool won);
|
| 76 |
+
|
| 77 |
+
|
| 78 |
+
event LogOwnerTransfer(address indexed SentToAddress, uint indexed AmountTransferred);
|
| 79 |
+
|
| 80 |
+
|
| 81 |
+
event MaxProfitChanged(uint _oldMaxProfit, uint _newMaxProfit);
|
| 82 |
+
|
| 83 |
+
|
| 84 |
+
event CurrentContractBalance(uint _tokens);
|
| 85 |
+
|
| 86 |
+
constructor (address zthtknaddr, address zthbankrolladdr) public {
|
| 87 |
+
|
| 88 |
+
owner = msg.sender;
|
| 89 |
+
|
| 90 |
+
|
| 91 |
+
ZTHTKN = ZTHInterface(zthtknaddr);
|
| 92 |
+
ZTHTKNADDR = zthtknaddr;
|
| 93 |
+
|
| 94 |
+
|
| 95 |
+
ZethrBankroll = zthbankrolladdr;
|
| 96 |
+
|
| 97 |
+
|
| 98 |
+
houseEdge = 990;
|
| 99 |
+
|
| 100 |
+
|
| 101 |
+
ownerSetMaxProfitAsPercentOfHouse(10000);
|
| 102 |
+
|
| 103 |
+
|
| 104 |
+
ownerSetMinBet(1e18);
|
| 105 |
+
|
| 106 |
+
|
| 107 |
+
ZTHTKN.approve(zthbankrolladdr, MAX_INT);
|
| 108 |
+
}
|
| 109 |
+
|
| 110 |
+
function() public payable {}
|
| 111 |
+
|
| 112 |
+
|
| 113 |
+
|
| 114 |
+
function maxRandom(uint blockn, address entropy) public view returns (uint256 randomNumber) {
|
| 115 |
+
return uint256(keccak256(
|
| 116 |
+
abi.encodePacked(
|
| 117 |
+
blockhash(blockn),
|
| 118 |
+
entropy)
|
| 119 |
+
));
|
| 120 |
+
}
|
| 121 |
+
|
| 122 |
+
|
| 123 |
+
function random(uint256 upper, uint256 blockn, address entropy) internal view returns (uint256 randomNumber) {
|
| 124 |
+
return maxRandom(blockn, entropy) % upper;
|
| 125 |
+
}
|
| 126 |
+
|
| 127 |
+
|
| 128 |
+
function calculateProfit(uint _initBet, uint _roll)
|
| 129 |
+
private
|
| 130 |
+
view
|
| 131 |
+
returns (uint)
|
| 132 |
+
{
|
| 133 |
+
return ((((_initBet * (100 - (_roll.sub(1)))) / (_roll.sub(1)) + _initBet)) * houseEdge / houseEdgeDivisor) - _initBet;
|
| 134 |
+
}
|
| 135 |
+
|
| 136 |
+
|
| 137 |
+
struct playerRoll{
|
| 138 |
+
uint200 tokenValue;
|
| 139 |
+
uint48 blockn;
|
| 140 |
+
uint8 rollUnder;
|
| 141 |
+
}
|
| 142 |
+
|
| 143 |
+
|
| 144 |
+
mapping(address => playerRoll) public playerRolls;
|
| 145 |
+
|
| 146 |
+
function _playerRollDice(uint _rollUnder, TKN _tkn) private
|
| 147 |
+
gameIsActive
|
| 148 |
+
betIsValid(_tkn.value, _rollUnder)
|
| 149 |
+
{
|
| 150 |
+
require(_tkn.value < ((2 ** 200) - 1));
|
| 151 |
+
require(block.number < ((2 ** 48) - 1));
|
| 152 |
+
|
| 153 |
+
|
| 154 |
+
|
| 155 |
+
|
| 156 |
+
|
| 157 |
+
require(_zthToken(msg.sender));
|
| 158 |
+
|
| 159 |
+
playerRoll memory roll = playerRolls[_tkn.sender];
|
| 160 |
+
|
| 161 |
+
|
| 162 |
+
require(block.number != roll.blockn);
|
| 163 |
+
|
| 164 |
+
|
| 165 |
+
if (roll.blockn != 0) {
|
| 166 |
+
_finishBet(false, _tkn.sender);
|
| 167 |
+
}
|
| 168 |
+
|
| 169 |
+
|
| 170 |
+
roll.blockn = uint40(block.number);
|
| 171 |
+
roll.tokenValue = uint200(_tkn.value);
|
| 172 |
+
roll.rollUnder = uint8(_rollUnder);
|
| 173 |
+
|
| 174 |
+
|
| 175 |
+
playerRolls[_tkn.sender] = roll;
|
| 176 |
+
|
| 177 |
+
|
| 178 |
+
emit LogBet(_tkn.sender, _tkn.value, _rollUnder);
|
| 179 |
+
|
| 180 |
+
|
| 181 |
+
totalBets += 1;
|
| 182 |
+
|
| 183 |
+
|
| 184 |
+
totalZTHWagered += _tkn.value;
|
| 185 |
+
}
|
| 186 |
+
|
| 187 |
+
|
| 188 |
+
function finishBet() public
|
| 189 |
+
gameIsActive
|
| 190 |
+
returns (uint)
|
| 191 |
+
{
|
| 192 |
+
return _finishBet(true, msg.sender);
|
| 193 |
+
}
|
| 194 |
+
|
| 195 |
+
|
| 196 |
+
function _finishBet(bool delete_it, address target) private returns (uint){
|
| 197 |
+
playerRoll memory roll = playerRolls[target];
|
| 198 |
+
require(roll.tokenValue > 0);
|
| 199 |
+
require(roll.blockn != block.number);
|
| 200 |
+
|
| 201 |
+
|
| 202 |
+
uint result;
|
| 203 |
+
if (block.number - roll.blockn > 255) {
|
| 204 |
+
result = 1000;
|
| 205 |
+
} else {
|
| 206 |
+
|
| 207 |
+
result = random(99, roll.blockn, target) + 1;
|
| 208 |
+
}
|
| 209 |
+
|
| 210 |
+
uint rollUnder = roll.rollUnder;
|
| 211 |
+
|
| 212 |
+
if (result < rollUnder) {
|
| 213 |
+
|
| 214 |
+
|
| 215 |
+
|
| 216 |
+
uint profit = calculateProfit(roll.tokenValue, rollUnder);
|
| 217 |
+
|
| 218 |
+
|
| 219 |
+
contractBalance = contractBalance.sub(profit);
|
| 220 |
+
|
| 221 |
+
emit LogResult(target, result, rollUnder, profit, roll.tokenValue, true);
|
| 222 |
+
|
| 223 |
+
|
| 224 |
+
setMaxProfit();
|
| 225 |
+
|
| 226 |
+
if (delete_it){
|
| 227 |
+
|
| 228 |
+
delete playerRolls[target];
|
| 229 |
+
}
|
| 230 |
+
|
| 231 |
+
|
| 232 |
+
ZTHTKN.transfer(target, profit + roll.tokenValue);
|
| 233 |
+
|
| 234 |
+
return result;
|
| 235 |
+
|
| 236 |
+
} else {
|
| 237 |
+
|
| 238 |
+
emit LogResult(target, result, rollUnder, profit, roll.tokenValue, false);
|
| 239 |
+
|
| 240 |
+
|
| 241 |
+
contractBalance = contractBalance.add(roll.tokenValue);
|
| 242 |
+
|
| 243 |
+
|
| 244 |
+
|
| 245 |
+
|
| 246 |
+
|
| 247 |
+
setMaxProfit();
|
| 248 |
+
|
| 249 |
+
return result;
|
| 250 |
+
}
|
| 251 |
+
}
|
| 252 |
+
|
| 253 |
+
|
| 254 |
+
struct TKN {address sender; uint value;}
|
| 255 |
+
|
| 256 |
+
|
| 257 |
+
function tokenFallback(address _from, uint _value, bytes _data) public returns (bool) {
|
| 258 |
+
if (_from == ZethrBankroll) {
|
| 259 |
+
|
| 260 |
+
contractBalance = contractBalance.add(_value);
|
| 261 |
+
|
| 262 |
+
|
| 263 |
+
uint oldMaxProfit = maxProfit;
|
| 264 |
+
setMaxProfit();
|
| 265 |
+
|
| 266 |
+
emit MaxProfitChanged(oldMaxProfit, maxProfit);
|
| 267 |
+
return true;
|
| 268 |
+
|
| 269 |
+
} else {
|
| 270 |
+
TKN memory _tkn;
|
| 271 |
+
_tkn.sender = _from;
|
| 272 |
+
_tkn.value = _value;
|
| 273 |
+
uint8 chosenNumber = uint8(_data[0]);
|
| 274 |
+
_playerRollDice(chosenNumber, _tkn);
|
| 275 |
+
}
|
| 276 |
+
|
| 277 |
+
return true;
|
| 278 |
+
}
|
| 279 |
+
|
| 280 |
+
|
| 281 |
+
function setMaxProfit() internal {
|
| 282 |
+
emit CurrentContractBalance(contractBalance);
|
| 283 |
+
maxProfit = (contractBalance * maxProfitAsPercentOfHouse) / maxProfitDivisor;
|
| 284 |
+
}
|
| 285 |
+
|
| 286 |
+
|
| 287 |
+
function ownerUpdateContractBalance(uint newContractBalance) public
|
| 288 |
+
onlyOwner
|
| 289 |
+
{
|
| 290 |
+
contractBalance = newContractBalance;
|
| 291 |
+
}
|
| 292 |
+
|
| 293 |
+
|
| 294 |
+
function ownerSetMaxProfitAsPercentOfHouse(uint newMaxProfitAsPercent) public
|
| 295 |
+
onlyOwner
|
| 296 |
+
{
|
| 297 |
+
|
| 298 |
+
require(newMaxProfitAsPercent <= 200000);
|
| 299 |
+
maxProfitAsPercentOfHouse = newMaxProfitAsPercent;
|
| 300 |
+
setMaxProfit();
|
| 301 |
+
}
|
| 302 |
+
|
| 303 |
+
|
| 304 |
+
function ownerSetMinBet(uint newMinimumBet) public
|
| 305 |
+
onlyOwner
|
| 306 |
+
{
|
| 307 |
+
minBet = newMinimumBet;
|
| 308 |
+
}
|
| 309 |
+
|
| 310 |
+
|
| 311 |
+
function ownerTransferZTH(address sendTo, uint amount) public
|
| 312 |
+
onlyOwner
|
| 313 |
+
{
|
| 314 |
+
|
| 315 |
+
contractBalance = contractBalance.sub(amount);
|
| 316 |
+
|
| 317 |
+
|
| 318 |
+
setMaxProfit();
|
| 319 |
+
require(ZTHTKN.transfer(sendTo, amount));
|
| 320 |
+
emit LogOwnerTransfer(sendTo, amount);
|
| 321 |
+
}
|
| 322 |
+
|
| 323 |
+
|
| 324 |
+
function ownerPauseGame(bool newStatus) public
|
| 325 |
+
onlyOwner
|
| 326 |
+
{
|
| 327 |
+
gamePaused = newStatus;
|
| 328 |
+
}
|
| 329 |
+
|
| 330 |
+
|
| 331 |
+
function ownerSetBankroll(address newBankroll) public
|
| 332 |
+
onlyOwner
|
| 333 |
+
{
|
| 334 |
+
ZTHTKN.approve(ZethrBankroll, 0);
|
| 335 |
+
ZethrBankroll = newBankroll;
|
| 336 |
+
ZTHTKN.approve(newBankroll, MAX_INT);
|
| 337 |
+
}
|
| 338 |
+
|
| 339 |
+
|
| 340 |
+
function ownerChangeOwner(address newOwner) public
|
| 341 |
+
onlyOwner
|
| 342 |
+
{
|
| 343 |
+
owner = newOwner;
|
| 344 |
+
}
|
| 345 |
+
|
| 346 |
+
|
| 347 |
+
function ownerkill() public
|
| 348 |
+
onlyOwner
|
| 349 |
+
{
|
| 350 |
+
ZTHTKN.transfer(owner, contractBalance);
|
| 351 |
+
selfdestruct(owner);
|
| 352 |
+
}
|
| 353 |
+
|
| 354 |
+
function dumpdivs() public{
|
| 355 |
+
ZethrBankroll.transfer(address(this).balance);
|
| 356 |
+
}
|
| 357 |
+
|
| 358 |
+
function _zthToken(address _tokenContract) private view returns (bool) {
|
| 359 |
+
return _tokenContract == ZTHTKNADDR;
|
| 360 |
+
|
| 361 |
+
}
|
| 362 |
+
}
|
| 363 |
+
|
| 364 |
+
|
| 365 |
+
library SafeMath {
|
| 366 |
+
|
| 367 |
+
|
| 368 |
+
function mul(uint a, uint b) internal pure returns (uint) {
|
| 369 |
+
if (a == 0) {
|
| 370 |
+
return 0;
|
| 371 |
+
}
|
| 372 |
+
uint c = a * b;
|
| 373 |
+
assert(c / a == b);
|
| 374 |
+
return c;
|
| 375 |
+
}
|
| 376 |
+
|
| 377 |
+
|
| 378 |
+
function div(uint a, uint b) internal pure returns (uint) {
|
| 379 |
+
|
| 380 |
+
uint c = a / b;
|
| 381 |
+
|
| 382 |
+
return c;
|
| 383 |
+
}
|
| 384 |
+
|
| 385 |
+
|
| 386 |
+
function sub(uint a, uint b) internal pure returns (uint) {
|
| 387 |
+
assert(b <= a);
|
| 388 |
+
return a - b;
|
| 389 |
+
}
|
| 390 |
+
|
| 391 |
+
|
| 392 |
+
function add(uint a, uint b) internal pure returns (uint) {
|
| 393 |
+
uint c = a + b;
|
| 394 |
+
assert(c >= a);
|
| 395 |
+
return c;
|
| 396 |
+
}
|
| 397 |
+
}
|
smart_contract_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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
pragma solidity ^0.4.12;
|
| 2 |
+
|
| 3 |
+
contract IMigrationContract {
|
| 4 |
+
function migrate(address addr, uint256 nas) returns (bool success);
|
| 5 |
+
}
|
| 6 |
+
|
| 7 |
+
|
| 8 |
+
contract SafeMath {
|
| 9 |
+
|
| 10 |
+
|
| 11 |
+
function safeAdd(uint256 x, uint256 y) internal returns(uint256) {
|
| 12 |
+
uint256 z = x + y;
|
| 13 |
+
assert((z >= x) && (z >= y));
|
| 14 |
+
return z;
|
| 15 |
+
}
|
| 16 |
+
|
| 17 |
+
function safeSubtract(uint256 x, uint256 y) internal returns(uint256) {
|
| 18 |
+
assert(x >= y);
|
| 19 |
+
uint256 z = x - y;
|
| 20 |
+
return z;
|
| 21 |
+
}
|
| 22 |
+
|
| 23 |
+
function safeMult(uint256 x, uint256 y) internal returns(uint256) {
|
| 24 |
+
uint256 z = x * y;
|
| 25 |
+
assert((x == 0)||(z/x == y));
|
| 26 |
+
return z;
|
| 27 |
+
}
|
| 28 |
+
|
| 29 |
+
}
|
| 30 |
+
|
| 31 |
+
contract Token {
|
| 32 |
+
uint256 public totalSupply;
|
| 33 |
+
function balanceOf(address _owner) constant returns (uint256 balance);
|
| 34 |
+
|
| 35 |
+
function transfer(address _to, uint256 _value) returns (bool success);
|
| 36 |
+
function transferFrom(address _from, address _to, uint256 _value) returns (bool success);
|
| 37 |
+
function approve(address _spender, uint256 _value) returns (bool success);
|
| 38 |
+
function allowance(address _owner, address _spender) constant returns (uint256 remaining);
|
| 39 |
+
event Transfer(address indexed _from, address indexed _to, uint256 _value);
|
| 40 |
+
event Approval(address indexed _owner, address indexed _spender, uint256 _value);
|
| 41 |
+
}
|
| 42 |
+
|
| 43 |
+
|
| 44 |
+
|
| 45 |
+
contract StandardToken is Token {
|
| 46 |
+
|
| 47 |
+
function transfer(address _to, uint256 _value) returns (bool success) {
|
| 48 |
+
if (balances[msg.sender] >= _value && _value > 0) {
|
| 49 |
+
balances[msg.sender] -= _value;
|
| 50 |
+
balances[_to] += _value;
|
| 51 |
+
Transfer(msg.sender, _to, _value);
|
| 52 |
+
return true;
|
| 53 |
+
} else {
|
| 54 |
+
return false;
|
| 55 |
+
}
|
| 56 |
+
}
|
| 57 |
+
|
| 58 |
+
function transferFrom(address _from, address _to, uint256 _value) returns (bool success) {
|
| 59 |
+
if (balances[_from] >= _value && allowed[_from][msg.sender] >= _value && _value > 0) {
|
| 60 |
+
balances[_to] += _value;
|
| 61 |
+
balances[_from] -= _value;
|
| 62 |
+
allowed[_from][msg.sender] -= _value;
|
| 63 |
+
Transfer(_from, _to, _value);
|
| 64 |
+
return true;
|
| 65 |
+
} else {
|
| 66 |
+
return false;
|
| 67 |
+
}
|
| 68 |
+
}
|
| 69 |
+
|
| 70 |
+
function balanceOf(address _owner) constant returns (uint256 balance) {
|
| 71 |
+
return balances[_owner];
|
| 72 |
+
}
|
| 73 |
+
|
| 74 |
+
function approve(address _spender, uint256 _value) returns (bool success) {
|
| 75 |
+
allowed[msg.sender][_spender] = _value;
|
| 76 |
+
Approval(msg.sender, _spender, _value);
|
| 77 |
+
return true;
|
| 78 |
+
}
|
| 79 |
+
|
| 80 |
+
function allowance(address _owner, address _spender) constant returns (uint256 remaining) {
|
| 81 |
+
return allowed[_owner][_spender];
|
| 82 |
+
}
|
| 83 |
+
|
| 84 |
+
mapping (address => uint256) balances;
|
| 85 |
+
mapping (address => mapping (address => uint256)) allowed;
|
| 86 |
+
}
|
| 87 |
+
|
| 88 |
+
contract UnityToken is StandardToken, SafeMath {
|
| 89 |
+
|
| 90 |
+
|
| 91 |
+
string public constant name = "Ping";
|
| 92 |
+
string public constant symbol = "PIN";
|
| 93 |
+
uint256 public constant decimals = 3;
|
| 94 |
+
string public version = "1.0";
|
| 95 |
+
|
| 96 |
+
|
| 97 |
+
address public ethFundDeposit;
|
| 98 |
+
address public newContractAddr;
|
| 99 |
+
|
| 100 |
+
|
| 101 |
+
bool public isFunding;
|
| 102 |
+
uint256 public fundingStartBlock;
|
| 103 |
+
uint256 public fundingStopBlock;
|
| 104 |
+
|
| 105 |
+
uint256 public currentSupply;
|
| 106 |
+
uint256 public tokenRaised = 0;
|
| 107 |
+
uint256 public tokenMigrated = 0;
|
| 108 |
+
uint256 public tokenExchangeRate = 3;
|
| 109 |
+
|
| 110 |
+
|
| 111 |
+
event AllocateToken(address indexed _to, uint256 _value);
|
| 112 |
+
event IssueToken(address indexed _to, uint256 _value);
|
| 113 |
+
event IncreaseSupply(uint256 _value);
|
| 114 |
+
event DecreaseSupply(uint256 _value);
|
| 115 |
+
event Migrate(address indexed _to, uint256 _value);
|
| 116 |
+
|
| 117 |
+
|
| 118 |
+
function formatDecimals(uint256 _value) internal returns (uint256 ) {
|
| 119 |
+
return _value * 10 ** decimals;
|
| 120 |
+
}
|
| 121 |
+
|
| 122 |
+
|
| 123 |
+
function UnityToken(
|
| 124 |
+
address _ethFundDeposit,
|
| 125 |
+
uint256 _currentSupply)
|
| 126 |
+
{
|
| 127 |
+
ethFundDeposit = _ethFundDeposit;
|
| 128 |
+
|
| 129 |
+
isFunding = false;
|
| 130 |
+
fundingStartBlock = 0;
|
| 131 |
+
fundingStopBlock = 0;
|
| 132 |
+
|
| 133 |
+
currentSupply = formatDecimals(_currentSupply);
|
| 134 |
+
totalSupply = formatDecimals(10000000);
|
| 135 |
+
balances[msg.sender] = totalSupply;
|
| 136 |
+
if(currentSupply > totalSupply) throw;
|
| 137 |
+
}
|
| 138 |
+
|
| 139 |
+
modifier isOwner() { require(msg.sender == ethFundDeposit); _; }
|
| 140 |
+
|
| 141 |
+
|
| 142 |
+
function setTokenExchangeRate(uint256 _tokenExchangeRate) isOwner external {
|
| 143 |
+
if (_tokenExchangeRate == 0) throw;
|
| 144 |
+
if (_tokenExchangeRate == tokenExchangeRate) throw;
|
| 145 |
+
|
| 146 |
+
tokenExchangeRate = _tokenExchangeRate;
|
| 147 |
+
}
|
| 148 |
+
|
| 149 |
+
|
| 150 |
+
function increaseSupply (uint256 _value) isOwner external {
|
| 151 |
+
uint256 value = formatDecimals(_value);
|
| 152 |
+
if (value + currentSupply > totalSupply) throw;
|
| 153 |
+
currentSupply = safeAdd(currentSupply, value);
|
| 154 |
+
IncreaseSupply(value);
|
| 155 |
+
}
|
| 156 |
+
|
| 157 |
+
|
| 158 |
+
function decreaseSupply (uint256 _value) isOwner external {
|
| 159 |
+
uint256 value = formatDecimals(_value);
|
| 160 |
+
if (value + tokenRaised > currentSupply) throw;
|
| 161 |
+
|
| 162 |
+
currentSupply = safeSubtract(currentSupply, value);
|
| 163 |
+
DecreaseSupply(value);
|
| 164 |
+
}
|
| 165 |
+
|
| 166 |
+
|
| 167 |
+
function startFunding (uint256 _fundingStartBlock, uint256 _fundingStopBlock) isOwner external {
|
| 168 |
+
if (isFunding) throw;
|
| 169 |
+
if (_fundingStartBlock >= _fundingStopBlock) throw;
|
| 170 |
+
if (block.number >= _fundingStartBlock) throw;
|
| 171 |
+
|
| 172 |
+
fundingStartBlock = _fundingStartBlock;
|
| 173 |
+
fundingStopBlock = _fundingStopBlock;
|
| 174 |
+
isFunding = true;
|
| 175 |
+
}
|
| 176 |
+
|
| 177 |
+
|
| 178 |
+
function stopFunding() isOwner external {
|
| 179 |
+
if (!isFunding) throw;
|
| 180 |
+
isFunding = false;
|
| 181 |
+
}
|
| 182 |
+
|
| 183 |
+
|
| 184 |
+
function setMigrateContract(address _newContractAddr) isOwner external {
|
| 185 |
+
if (_newContractAddr == newContractAddr) throw;
|
| 186 |
+
newContractAddr = _newContractAddr;
|
| 187 |
+
}
|
| 188 |
+
|
| 189 |
+
|
| 190 |
+
function changeOwner(address _newFundDeposit) isOwner() external {
|
| 191 |
+
if (_newFundDeposit == address(0x0)) throw;
|
| 192 |
+
ethFundDeposit = _newFundDeposit;
|
| 193 |
+
}
|
| 194 |
+
|
| 195 |
+
|
| 196 |
+
function migrate() external {
|
| 197 |
+
if(isFunding) throw;
|
| 198 |
+
if(newContractAddr == address(0x0)) throw;
|
| 199 |
+
|
| 200 |
+
uint256 tokens = balances[msg.sender];
|
| 201 |
+
if (tokens == 0) throw;
|
| 202 |
+
|
| 203 |
+
balances[msg.sender] = 0;
|
| 204 |
+
tokenMigrated = safeAdd(tokenMigrated, tokens);
|
| 205 |
+
|
| 206 |
+
IMigrationContract newContract = IMigrationContract(newContractAddr);
|
| 207 |
+
if (!newContract.migrate(msg.sender, tokens)) throw;
|
| 208 |
+
|
| 209 |
+
Migrate(msg.sender, tokens);
|
| 210 |
+
}
|
| 211 |
+
|
| 212 |
+
|
| 213 |
+
function transferETH() isOwner external {
|
| 214 |
+
if (this.balance == 0) throw;
|
| 215 |
+
if (!ethFundDeposit.send(this.balance)) throw;
|
| 216 |
+
}
|
| 217 |
+
|
| 218 |
+
|
| 219 |
+
function allocateToken (address _addr, uint256 _fin) isOwner public {
|
| 220 |
+
if (_fin == 0) throw;
|
| 221 |
+
if (_addr == address(0x0)) throw;
|
| 222 |
+
|
| 223 |
+
uint256 tokens = safeMult(formatDecimals(_fin), tokenExchangeRate);
|
| 224 |
+
|
| 225 |
+
if (tokens + tokenRaised > currentSupply) throw;
|
| 226 |
+
|
| 227 |
+
tokenRaised = safeAdd(tokenRaised, tokens);
|
| 228 |
+
|
| 229 |
+
balances[_addr] += tokens;
|
| 230 |
+
|
| 231 |
+
AllocateToken(_addr, tokens);
|
| 232 |
+
}
|
| 233 |
+
|
| 234 |
+
|
| 235 |
+
function () payable {
|
| 236 |
+
if (!isFunding) throw;
|
| 237 |
+
if (msg.value == 0) throw;
|
| 238 |
+
|
| 239 |
+
if (block.number < fundingStartBlock) throw;
|
| 240 |
+
if (block.number > fundingStopBlock) throw;
|
| 241 |
+
|
| 242 |
+
uint256 tokens = safeMult(msg.value, tokenExchangeRate);
|
| 243 |
+
if (tokens + tokenRaised > currentSupply) throw;
|
| 244 |
+
|
| 245 |
+
tokenRaised = safeAdd(tokenRaised, tokens);
|
| 246 |
+
balances[msg.sender] += tokens;
|
| 247 |
+
|
| 248 |
+
IssueToken(msg.sender, tokens);
|
| 249 |
+
}
|
| 250 |
+
}
|
smart_contract_dataset/block number dependency/2632.sol
ADDED
|
@@ -0,0 +1,247 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
pragma solidity ^0.4.12;
|
| 2 |
+
|
| 3 |
+
contract IMigrationContract {
|
| 4 |
+
function migrate(address addr, uint256 nas) returns (bool success);
|
| 5 |
+
}
|
| 6 |
+
|
| 7 |
+
|
| 8 |
+
contract SafeMath {
|
| 9 |
+
|
| 10 |
+
|
| 11 |
+
function safeAdd(uint256 x, uint256 y) internal returns(uint256) {
|
| 12 |
+
uint256 z = x + y;
|
| 13 |
+
assert((z >= x) && (z >= y));
|
| 14 |
+
return z;
|
| 15 |
+
}
|
| 16 |
+
|
| 17 |
+
function safeSubtract(uint256 x, uint256 y) internal returns(uint256) {
|
| 18 |
+
assert(x >= y);
|
| 19 |
+
uint256 z = x - y;
|
| 20 |
+
return z;
|
| 21 |
+
}
|
| 22 |
+
|
| 23 |
+
function safeMult(uint256 x, uint256 y) internal returns(uint256) {
|
| 24 |
+
uint256 z = x * y;
|
| 25 |
+
assert((x == 0)||(z/x == y));
|
| 26 |
+
return z;
|
| 27 |
+
}
|
| 28 |
+
|
| 29 |
+
}
|
| 30 |
+
|
| 31 |
+
contract Token {
|
| 32 |
+
uint256 public totalSupply;
|
| 33 |
+
function balanceOf(address _owner) constant returns (uint256 balance);
|
| 34 |
+
function transfer(address _to, uint256 _value) returns (bool success);
|
| 35 |
+
function transferFrom(address _from, address _to, uint256 _value) returns (bool success);
|
| 36 |
+
function approve(address _spender, uint256 _value) returns (bool success);
|
| 37 |
+
function allowance(address _owner, address _spender) constant returns (uint256 remaining);
|
| 38 |
+
event Transfer(address indexed _from, address indexed _to, uint256 _value);
|
| 39 |
+
event Approval(address indexed _owner, address indexed _spender, uint256 _value);
|
| 40 |
+
}
|
| 41 |
+
|
| 42 |
+
|
| 43 |
+
|
| 44 |
+
contract StandardToken is Token {
|
| 45 |
+
|
| 46 |
+
function transfer(address _to, uint256 _value) returns (bool success) {
|
| 47 |
+
if (balances[msg.sender] >= _value && _value > 0) {
|
| 48 |
+
balances[msg.sender] -= _value;
|
| 49 |
+
balances[_to] += _value;
|
| 50 |
+
Transfer(msg.sender, _to, _value);
|
| 51 |
+
return true;
|
| 52 |
+
} else {
|
| 53 |
+
return false;
|
| 54 |
+
}
|
| 55 |
+
}
|
| 56 |
+
|
| 57 |
+
function transferFrom(address _from, address _to, uint256 _value) returns (bool success) {
|
| 58 |
+
if (balances[_from] >= _value && allowed[_from][msg.sender] >= _value && _value > 0) {
|
| 59 |
+
balances[_to] += _value;
|
| 60 |
+
balances[_from] -= _value;
|
| 61 |
+
allowed[_from][msg.sender] -= _value;
|
| 62 |
+
Transfer(_from, _to, _value);
|
| 63 |
+
return true;
|
| 64 |
+
} else {
|
| 65 |
+
return false;
|
| 66 |
+
}
|
| 67 |
+
}
|
| 68 |
+
|
| 69 |
+
function balanceOf(address _owner) constant returns (uint256 balance) {
|
| 70 |
+
return balances[_owner];
|
| 71 |
+
}
|
| 72 |
+
|
| 73 |
+
function approve(address _spender, uint256 _value) returns (bool success) {
|
| 74 |
+
allowed[msg.sender][_spender] = _value;
|
| 75 |
+
Approval(msg.sender, _spender, _value);
|
| 76 |
+
return true;
|
| 77 |
+
}
|
| 78 |
+
|
| 79 |
+
function allowance(address _owner, address _spender) constant returns (uint256 remaining) {
|
| 80 |
+
return allowed[_owner][_spender];
|
| 81 |
+
}
|
| 82 |
+
|
| 83 |
+
mapping (address => uint256) balances;
|
| 84 |
+
mapping (address => mapping (address => uint256)) allowed;
|
| 85 |
+
}
|
| 86 |
+
|
| 87 |
+
contract AntiFakeLabelToken is StandardToken, SafeMath {
|
| 88 |
+
|
| 89 |
+
|
| 90 |
+
string public constant name = "Anti-Fake Label";
|
| 91 |
+
string public constant symbol = "AFL";
|
| 92 |
+
uint256 public constant decimals = 18;
|
| 93 |
+
string public version = "1.0";
|
| 94 |
+
|
| 95 |
+
|
| 96 |
+
address public ethFundDeposit;
|
| 97 |
+
address public newContractAddr;
|
| 98 |
+
|
| 99 |
+
|
| 100 |
+
bool public isFunding;
|
| 101 |
+
uint256 public fundingStartBlock;
|
| 102 |
+
uint256 public fundingStopBlock;
|
| 103 |
+
|
| 104 |
+
uint256 public currentSupply;
|
| 105 |
+
uint256 public tokenRaised = 0;
|
| 106 |
+
uint256 public tokenMigrated = 0;
|
| 107 |
+
uint256 public tokenExchangeRate = 3500;
|
| 108 |
+
|
| 109 |
+
|
| 110 |
+
event AllocateToken(address indexed _to, uint256 _value);
|
| 111 |
+
event IssueToken(address indexed _to, uint256 _value);
|
| 112 |
+
event IncreaseSupply(uint256 _value);
|
| 113 |
+
event DecreaseSupply(uint256 _value);
|
| 114 |
+
event Migrate(address indexed _to, uint256 _value);
|
| 115 |
+
|
| 116 |
+
|
| 117 |
+
function formatDecimals(uint256 _value) internal returns (uint256 ) {
|
| 118 |
+
return _value * 10 ** decimals;
|
| 119 |
+
}
|
| 120 |
+
|
| 121 |
+
|
| 122 |
+
function AntiFakeLabelToken(
|
| 123 |
+
address _ethFundDeposit,
|
| 124 |
+
uint256 _currentSupply)
|
| 125 |
+
{
|
| 126 |
+
ethFundDeposit = _ethFundDeposit;
|
| 127 |
+
|
| 128 |
+
isFunding = false;
|
| 129 |
+
fundingStartBlock = 0;
|
| 130 |
+
fundingStopBlock = 0;
|
| 131 |
+
|
| 132 |
+
currentSupply = formatDecimals(_currentSupply);
|
| 133 |
+
totalSupply = formatDecimals(5000000000);
|
| 134 |
+
balances[msg.sender] = totalSupply;
|
| 135 |
+
if(currentSupply > totalSupply) throw;
|
| 136 |
+
}
|
| 137 |
+
|
| 138 |
+
modifier isOwner() { require(msg.sender == ethFundDeposit); _; }
|
| 139 |
+
|
| 140 |
+
|
| 141 |
+
function setTokenExchangeRate(uint256 _tokenExchangeRate) isOwner external {
|
| 142 |
+
if (_tokenExchangeRate == 0) throw;
|
| 143 |
+
if (_tokenExchangeRate == tokenExchangeRate) throw;
|
| 144 |
+
|
| 145 |
+
tokenExchangeRate = _tokenExchangeRate;
|
| 146 |
+
}
|
| 147 |
+
|
| 148 |
+
|
| 149 |
+
function increaseSupply (uint256 _value) isOwner external {
|
| 150 |
+
uint256 value = formatDecimals(_value);
|
| 151 |
+
if (value + currentSupply > totalSupply) throw;
|
| 152 |
+
currentSupply = safeAdd(currentSupply, value);
|
| 153 |
+
IncreaseSupply(value);
|
| 154 |
+
}
|
| 155 |
+
|
| 156 |
+
|
| 157 |
+
function decreaseSupply (uint256 _value) isOwner external {
|
| 158 |
+
uint256 value = formatDecimals(_value);
|
| 159 |
+
if (value + tokenRaised > currentSupply) throw;
|
| 160 |
+
|
| 161 |
+
currentSupply = safeSubtract(currentSupply, value);
|
| 162 |
+
DecreaseSupply(value);
|
| 163 |
+
}
|
| 164 |
+
|
| 165 |
+
|
| 166 |
+
function startFunding (uint256 _fundingStartBlock, uint256 _fundingStopBlock) isOwner external {
|
| 167 |
+
if (isFunding) throw;
|
| 168 |
+
if (_fundingStartBlock >= _fundingStopBlock) throw;
|
| 169 |
+
if (block.number >= _fundingStartBlock) throw;
|
| 170 |
+
|
| 171 |
+
fundingStartBlock = _fundingStartBlock;
|
| 172 |
+
fundingStopBlock = _fundingStopBlock;
|
| 173 |
+
isFunding = true;
|
| 174 |
+
}
|
| 175 |
+
|
| 176 |
+
|
| 177 |
+
function stopFunding() isOwner external {
|
| 178 |
+
if (!isFunding) throw;
|
| 179 |
+
isFunding = false;
|
| 180 |
+
}
|
| 181 |
+
|
| 182 |
+
|
| 183 |
+
function setMigrateContract(address _newContractAddr) isOwner external {
|
| 184 |
+
if (_newContractAddr == newContractAddr) throw;
|
| 185 |
+
newContractAddr = _newContractAddr;
|
| 186 |
+
}
|
| 187 |
+
|
| 188 |
+
|
| 189 |
+
function changeOwner(address _newFundDeposit) isOwner() external {
|
| 190 |
+
if (_newFundDeposit == address(0x0)) throw;
|
| 191 |
+
ethFundDeposit = _newFundDeposit;
|
| 192 |
+
}
|
| 193 |
+
|
| 194 |
+
|
| 195 |
+
function migrate() external {
|
| 196 |
+
if(isFunding) throw;
|
| 197 |
+
if(newContractAddr == address(0x0)) throw;
|
| 198 |
+
|
| 199 |
+
uint256 tokens = balances[msg.sender];
|
| 200 |
+
if (tokens == 0) throw;
|
| 201 |
+
|
| 202 |
+
balances[msg.sender] = 0;
|
| 203 |
+
tokenMigrated = safeAdd(tokenMigrated, tokens);
|
| 204 |
+
|
| 205 |
+
IMigrationContract newContract = IMigrationContract(newContractAddr);
|
| 206 |
+
if (!newContract.migrate(msg.sender, tokens)) throw;
|
| 207 |
+
|
| 208 |
+
Migrate(msg.sender, tokens);
|
| 209 |
+
}
|
| 210 |
+
|
| 211 |
+
|
| 212 |
+
function transferETH() isOwner external {
|
| 213 |
+
if (this.balance == 0) throw;
|
| 214 |
+
if (!ethFundDeposit.send(this.balance)) throw;
|
| 215 |
+
}
|
| 216 |
+
|
| 217 |
+
|
| 218 |
+
function allocateToken (address _addr, uint256 _eth) isOwner external {
|
| 219 |
+
if (_eth == 0) throw;
|
| 220 |
+
if (_addr == address(0x0)) throw;
|
| 221 |
+
|
| 222 |
+
uint256 tokens = safeMult(formatDecimals(_eth), tokenExchangeRate);
|
| 223 |
+
if (tokens + tokenRaised > currentSupply) throw;
|
| 224 |
+
|
| 225 |
+
tokenRaised = safeAdd(tokenRaised, tokens);
|
| 226 |
+
balances[_addr] += tokens;
|
| 227 |
+
|
| 228 |
+
AllocateToken(_addr, tokens);
|
| 229 |
+
}
|
| 230 |
+
|
| 231 |
+
|
| 232 |
+
function () payable {
|
| 233 |
+
if (!isFunding) throw;
|
| 234 |
+
if (msg.value == 0) throw;
|
| 235 |
+
|
| 236 |
+
if (block.number < fundingStartBlock) throw;
|
| 237 |
+
if (block.number > fundingStopBlock) throw;
|
| 238 |
+
|
| 239 |
+
uint256 tokens = safeMult(msg.value, tokenExchangeRate);
|
| 240 |
+
if (tokens + tokenRaised > currentSupply) throw;
|
| 241 |
+
|
| 242 |
+
tokenRaised = safeAdd(tokenRaised, tokens);
|
| 243 |
+
balances[msg.sender] += tokens;
|
| 244 |
+
|
| 245 |
+
IssueToken(msg.sender, tokens);
|
| 246 |
+
}
|
| 247 |
+
}
|