File size: 13,537 Bytes
dec6d5d |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 |
pragma solidity ^0.4.24;
contract ZTHReceivingContract {
function tokenFallback(address _from, uint _value, bytes _data) public returns (bool);
}
contract ZTHInterface {
function transfer(address _to, uint _value) public returns (bool);
function approve(address spender, uint tokens) public returns (bool);
}
contract Zlots is ZTHReceivingContract {
using SafeMath for uint;
address private owner;
address private bankroll;
uint totalSpins;
uint totalZTHWagered;
uint contractBalance;
bool public gameActive;
address private ZTHTKNADDR;
address private ZTHBANKROLL;
ZTHInterface private ZTHTKN;
mapping (uint => bool) validTokenBet;
event HouseRetrievedTake(
uint timeTaken,
uint tokensWithdrawn
);
event TokensWagered(
address _wagerer,
uint _wagered
);
event LogResult(
address _wagerer,
uint _result,
uint _profit,
uint _wagered,
uint _category,
bool _win
);
event Loss(address _wagerer, uint _block);
event ThreeMoonJackpot(address _wagerer, uint _block);
event TwoMoonPrize(address _wagerer, uint _block);
event ZTHJackpot(address _wagerer, uint _block);
event ThreeZSymbols(address _wagerer, uint _block);
event ThreeTSymbols(address _wagerer, uint _block);
event ThreeHSymbols(address _wagerer, uint _block);
event ThreeEtherIcons(address _wagerer, uint _block);
event ThreeGreenPyramids(address _wagerer, uint _block);
event ThreeGoldPyramids(address _wagerer, uint _block);
event ThreeWhitePyramids(address _wagerer, uint _block);
event OneMoonPrize(address _wagerer, uint _block);
event OneOfEachPyramidPrize(address _wagerer, uint _block);
event TwoZSymbols(address _wagerer, uint _block);
event TwoTSymbols(address _wagerer, uint _block);
event TwoHSymbols(address _wagerer, uint _block);
event TwoEtherIcons(address _wagerer, uint _block);
event TwoGreenPyramids(address _wagerer, uint _block);
event TwoGoldPyramids(address _wagerer, uint _block);
event TwoWhitePyramids(address _wagerer, uint _block);
event ReturnBet(
address _wagerer
);
event TwoAndAHalfXMultiplier(
address _wagerer
);
event OneAndAHalfXMultiplier(
address _wagerer
);
modifier onlyOwner {
require(msg.sender == owner);
_;
}
modifier onlyBankroll {
require(msg.sender == bankroll);
_;
}
modifier onlyOwnerOrBankroll {
require(msg.sender == owner || msg.sender == bankroll);
_;
}
modifier gameIsActive {
require(gameActive == true);
_;
}
constructor(address ZethrAddress, address BankrollAddress) public {
ZTHTKNADDR = ZethrAddress;
ZTHBANKROLL = BankrollAddress;
owner = msg.sender;
bankroll = ZTHBANKROLL;
ZTHTKN = ZTHInterface(ZTHTKNADDR);
ZTHTKN.approve(ZTHBANKROLL, 2**256 - 1);
ZTHTKN.approve(owner, 2**256 - 1);
validTokenBet[5e18] = true;
validTokenBet[10e18] = true;
validTokenBet[25e18] = true;
validTokenBet[50e18] = true;
gameActive = true;
}
function() public payable { }
struct TKN { address sender; uint value; }
function tokenFallback(address _from, uint _value, bytes ) public returns (bool){
if (_from == bankroll) {
contractBalance = contractBalance.add(_value);
return true;
} else {
TKN memory _tkn;
_tkn.sender = _from;
_tkn.value = _value;
_spinTokens(_tkn);
return true;
}
}
struct playerSpin {
uint200 tokenValue;
uint48 blockn;
}
mapping(address => playerSpin) public playerSpins;
function _spinTokens(TKN _tkn) private {
require(gameActive);
require(_zthToken(msg.sender));
require(validTokenBet[_tkn.value]);
require(jackpotGuard(_tkn.value));
require(_tkn.value < ((2 ** 200) - 1));
require(block.number < ((2 ** 48) - 1));
address _customerAddress = _tkn.sender;
uint _wagered = _tkn.value;
playerSpin memory spin = playerSpins[_tkn.sender];
contractBalance = contractBalance.add(_wagered);
require(block.number != spin.blockn);
if (spin.blockn != 0) {
_finishSpin(_tkn.sender);
}
spin.blockn = uint48(block.number);
spin.tokenValue = uint200(_wagered);
playerSpins[_tkn.sender] = spin;
totalSpins += 1;
totalZTHWagered += _wagered;
emit TokensWagered(_customerAddress, _wagered);
}
function finishSpin() public
gameIsActive
returns (uint)
{
return _finishSpin(msg.sender);
}
function _finishSpin(address target)
private returns (uint)
{
playerSpin memory spin = playerSpins[target];
require(spin.tokenValue > 0);
require(spin.blockn != block.number);
uint profit = 0;
uint category = 0;
uint result;
if (block.number - spin.blockn > 255) {
result = 9999;
} else {
result = random(1000000, spin.blockn, target);
}
if (result > 476661) {
emit Loss(target, spin.blockn);
emit LogResult(target, result, profit, spin.tokenValue, category, false);
} else {
if (result < 1) {
profit = SafeMath.mul(spin.tokenValue, 500);
category = 1;
emit ThreeMoonJackpot(target, spin.blockn);
} else {
if (result < 298) {
profit = SafeMath.mul(spin.tokenValue, 232);
category = 2;
emit TwoMoonPrize(target, spin.blockn);
} else {
if (result < 3127) {
profit = SafeMath.div(SafeMath.mul(spin.tokenValue, 232), 10);
category = 3;
emit ZTHJackpot(target, spin.blockn);
} else {
if (result < 5956) {
profit = SafeMath.mul(spin.tokenValue, 25);
category = 4;
emit ThreeZSymbols(target, spin.blockn);
} else {
if (result < 8785) {
profit = SafeMath.mul(spin.tokenValue, 25);
category = 5;
emit ThreeTSymbols(target, spin.blockn);
} else {
if (result < 11614) {
profit = SafeMath.mul(spin.tokenValue, 25);
category = 6;
emit ThreeHSymbols(target, spin.blockn);
} else {
if (result < 14443) {
profit = SafeMath.mul(spin.tokenValue, 50);
category = 7;
emit ThreeEtherIcons(target, spin.blockn);
} else {
if (result < 17272) {
profit = SafeMath.mul(spin.tokenValue, 40);
category = 8;
emit ThreeGreenPyramids(target, spin.blockn);
} else {
if (result < 20101) {
profit = SafeMath.mul(spin.tokenValue, 20);
category = 9;
emit ThreeGoldPyramids(target, spin.blockn);
} else {
if (result < 22929) {
profit = SafeMath.mul(spin.tokenValue, 20);
category = 10;
emit ThreeWhitePyramids(target, spin.blockn);
} else {
if (result < 52332) {
profit = SafeMath.div(SafeMath.mul(spin.tokenValue, 125),10);
category = 11;
emit OneMoonPrize(target, spin.blockn);
} else {
if (result < 120225) {
profit = SafeMath.div(SafeMath.mul(spin.tokenValue, 15),10);
category = 12;
emit OneOfEachPyramidPrize(target, spin.blockn);
} else {
if (result < 171146) {
profit = SafeMath.div(SafeMath.mul(spin.tokenValue, 232),100);
category = 13;
emit TwoZSymbols(target, spin.blockn);
} else {
if (result < 222067) {
profit = SafeMath.div(SafeMath.mul(spin.tokenValue, 232),100);
category = 14;
emit TwoTSymbols(target, spin.blockn);
} else {
if (result < 272988) {
profit = SafeMath.div(SafeMath.mul(spin.tokenValue, 232),100);
category = 15;
emit TwoHSymbols(target, spin.blockn);
} else {
if (result < 323909) {
profit = SafeMath.div(SafeMath.mul(spin.tokenValue, 375),100);
category = 16;
emit TwoEtherIcons(target, spin.blockn);
} else {
if (result < 374830) {
profit = SafeMath.div(SafeMath.mul(spin.tokenValue, 35),10);
category = 17;
emit TwoGreenPyramids(target, spin.blockn);
} else {
if (result < 425751) {
profit = SafeMath.div(SafeMath.mul(spin.tokenValue, 225),100);
category = 18;
emit TwoGoldPyramids(target, spin.blockn);
} else {
profit = SafeMath.mul(spin.tokenValue, 2);
category = 19;
emit TwoWhitePyramids(target, spin.blockn);
}
emit LogResult(target, result, profit, spin.tokenValue, category, true);
contractBalance = contractBalance.sub(profit);
ZTHTKN.transfer(target, profit);
}}}}}}}}}}}}}}}}}}
playerSpins[target] = playerSpin(uint200(0), uint48(0));
return result;
}
function jackpotGuard(uint _wager)
private
view
returns (bool)
{
uint maxProfit = SafeMath.mul(_wager, 500);
uint ninetyContractBalance = SafeMath.mul(SafeMath.div(contractBalance, 10), 9);
return (maxProfit <= ninetyContractBalance);
}
function maxRandom(uint blockn, address entropy) private view returns (uint256 randomNumber) {
return uint256(keccak256(
abi.encodePacked(
blockhash(blockn),
entropy)
));
}
function random(uint256 upper, uint256 blockn, address entropy) internal view returns (uint256 randomNumber) {
return maxRandom(blockn, entropy) % upper;
}
function balanceOf() public view returns (uint) {
return contractBalance;
}
function addNewBetAmount(uint _tokenAmount)
public
onlyOwner
{
validTokenBet[_tokenAmount] = true;
}
function pauseGame() public onlyOwner {
gameActive = false;
}
function resumeGame() public onlyOwner {
gameActive = true;
}
function changeOwner(address _newOwner) public onlyOwner {
owner = _newOwner;
}
function changeBankroll(address _newBankroll) public onlyOwner {
bankroll = _newBankroll;
}
function divertDividendsToBankroll()
public
onlyOwner
{
bankroll.transfer(address(this).balance);
}
function testingSelfDestruct()
public
onlyOwner
{
ZTHTKN.transfer(owner, contractBalance);
selfdestruct(owner);
}
function _zthToken(address _tokenContract) private view returns (bool) {
return _tokenContract == ZTHTKNADDR;
}
}
library SafeMath {
function mul(uint a, uint b) internal pure returns (uint) {
if (a == 0) {
return 0;
}
uint c = a * b;
assert(c / a == b);
return c;
}
function div(uint a, uint b) internal pure returns (uint) {
uint c = a / b;
return c;
}
function sub(uint a, uint b) internal pure returns (uint) {
assert(b <= a);
return a - b;
}
function add(uint a, uint b) internal pure returns (uint) {
uint c = a + b;
assert(c >= a);
return c;
}
} |