File size: 16,340 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 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 |
pragma solidity ^0.4.24;
contract ZethrTokenBankroll{
function gameRequestTokens(address target, uint tokens) public;
function gameTokenAmount(address what) public returns (uint);
}
contract ZethrMainBankroll{
function gameGetTokenBankrollList() public view returns (address[7]);
}
contract ZethrInterface{
function withdraw() public;
}
library ZethrTierLibrary{
function getTier(uint divRate) internal pure returns (uint){
uint actualDiv = divRate;
if (actualDiv >= 30){
return 6;
} else if (actualDiv >= 25){
return 5;
} else if (actualDiv >= 20){
return 4;
} else if (actualDiv >= 15){
return 3;
} else if (actualDiv >= 10){
return 2;
} else if (actualDiv >= 5){
return 1;
} else if (actualDiv >= 2){
return 0;
} else{
revert();
}
}
}
contract ZlotsJackpotHoldingContract {
function payOutWinner(address winner) public;
function getJackpot() public view returns (uint);
}
contract ZethrBankrollBridge {
ZethrInterface Zethr;
address[7] UsedBankrollAddresses;
mapping(address => bool) ValidBankrollAddress;
function setupBankrollInterface(address ZethrMainBankrollAddress) internal {
Zethr = ZethrInterface(0xD48B633045af65fF636F3c6edd744748351E020D);
UsedBankrollAddresses = ZethrMainBankroll(ZethrMainBankrollAddress).gameGetTokenBankrollList();
for(uint i=0; i<7; i++){
ValidBankrollAddress[UsedBankrollAddresses[i]] = true;
}
}
modifier fromBankroll(){
require(ValidBankrollAddress[msg.sender], "msg.sender should be a valid bankroll");
_;
}
function RequestBankrollPayment(address to, uint tokens, uint tier) internal {
address tokenBankrollAddress = UsedBankrollAddresses[tier];
ZethrTokenBankroll(tokenBankrollAddress).gameRequestTokens(to, tokens);
}
function getZethrTokenBankroll(uint divRate) public constant returns (ZethrTokenBankroll){
return ZethrTokenBankroll(UsedBankrollAddresses[ZethrTierLibrary.getTier(divRate)]);
}
}
contract ZethrShell is ZethrBankrollBridge {
function WithdrawToBankroll() public {
address(UsedBankrollAddresses[0]).transfer(address(this).balance);
}
function WithdrawAndTransferToBankroll() public {
Zethr.withdraw();
WithdrawToBankroll();
}
}
contract Zlots is ZethrShell {
using SafeMath for uint;
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 ZTHPrize(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 ThreePurplePyramids(address _wagerer, uint _block);
event ThreeGoldPyramids(address _wagerer, uint _block);
event ThreeRockets(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 TwoPurplePyramids(address _wagerer, uint _block);
event TwoGoldPyramids(address _wagerer, uint _block);
event TwoRockets(address _wagerer, uint _block);
event SpinConcluded(address _wagerer, uint _block);
modifier betIsValid(uint _betSize, uint divRate) {
require(_betSize.mul(100) <= getMaxProfit(divRate));
_;
}
modifier gameIsActive {
require(gamePaused == false);
_;
}
modifier onlyOwner {
require(msg.sender == owner);
_;
}
modifier onlyBankroll {
require(msg.sender == bankroll);
_;
}
modifier onlyOwnerOrBankroll {
require(msg.sender == owner || msg.sender == bankroll);
_;
}
uint constant public maxProfitDivisor = 1000000;
uint constant public houseEdgeDivisor = 1000;
mapping (uint => uint) public maxProfit;
uint public maxProfitAsPercentOfHouse;
uint public minBet = 1e18;
address public zlotsJackpot;
address private owner;
address private bankroll;
bool gamePaused;
uint public totalSpins;
uint public totalZTHWagered;
mapping (uint => uint) public contractBalance;
bool public gameActive;
address private ZTHTKNADDR;
address private ZTHBANKROLL;
constructor(address BankrollAddress) public {
setupBankrollInterface(BankrollAddress);
owner = msg.sender;
ownerSetMaxProfitAsPercentOfHouse(50000);
bankroll = ZTHBANKROLL;
gameActive = true;
ownerSetMinBet(1e18);
}
function() public payable { }
struct TKN { address sender; uint value; }
function execute(address _from, uint _value, uint divRate, bytes ) public fromBankroll returns (bool){
TKN memory _tkn;
_tkn.sender = _from;
_tkn.value = _value;
_spinTokens(_tkn, divRate);
return true;
}
struct playerSpin {
uint200 tokenValue;
uint48 blockn;
uint8 tier;
}
mapping(address => playerSpin) public playerSpins;
function _spinTokens(TKN _tkn, uint divRate)
private
betIsValid(_tkn.value, divRate)
{
require(gameActive);
require(1e18 <= _tkn.value);
require(block.number < ((2 ** 56) - 1));
address _customerAddress = _tkn.sender;
uint _wagered = _tkn.value;
playerSpin memory spin = playerSpins[_tkn.sender];
addContractBalance(divRate, _wagered);
require(block.number != spin.blockn);
if (spin.blockn != 0) {
_finishSpin(_tkn.sender);
}
spin.blockn = uint48(block.number);
spin.tokenValue = uint200(_wagered);
spin.tier = uint8(ZethrTierLibrary.getTier(divRate));
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 = 1000000;
} else {
result = random(1000000, spin.blockn, target) + 1;
}
if (result > 476662) {
RequestBankrollPayment(zlotsJackpot, profit, tier);
playerSpins[target] = playerSpin(uint200(0), uint48(0), uint8(0));
emit Loss(target, spin.blockn);
emit LogResult(target, result, profit, spin.tokenValue, category, false);
} else if (result < 2) {
profit = ZlotsJackpotHoldingContract(zlotsJackpot).getJackpot();
category = 1;
emit ThreeMoonJackpot(target, spin.blockn);
emit LogResult(target, result, profit, spin.tokenValue, category, true);
uint8 tier = spin.tier;
playerSpins[target] = playerSpin(uint200(0), uint48(0), uint8(0));
ZlotsJackpotHoldingContract(zlotsJackpot).payOutWinner(target);
} else {
if (result < 299) {
profit = SafeMath.mul(spin.tokenValue, 100);
category = 2;
emit TwoMoonPrize(target, spin.blockn);
} else if (result < 3128) {
profit = SafeMath.mul(spin.tokenValue, 20);
category = 3;
emit ZTHPrize(target, spin.blockn);
} else if (result < 5957) {
profit = SafeMath.div(SafeMath.mul(spin.tokenValue, 75), 10);
category = 4;
emit ThreeZSymbols(target, spin.blockn);
} else if (result < 8786) {
profit = SafeMath.div(SafeMath.mul(spin.tokenValue, 75), 10);
category = 5;
emit ThreeTSymbols(target, spin.blockn);
} else if (result < 11615) {
profit = SafeMath.div(SafeMath.mul(spin.tokenValue, 75), 10);
category = 6;
emit ThreeHSymbols(target, spin.blockn);
} else if (result < 14444) {
profit = SafeMath.mul(spin.tokenValue, 15);
category = 7;
emit ThreeEtherIcons(target, spin.blockn);
} else if (result < 17273) {
profit = SafeMath.mul(spin.tokenValue, 10);
category = 8;
emit ThreePurplePyramids(target, spin.blockn);
} else if (result < 20102) {
profit = SafeMath.mul(spin.tokenValue, 10);
category = 9;
emit ThreeGoldPyramids(target, spin.blockn);
} else if (result < 22930) {
profit = SafeMath.mul(spin.tokenValue, 12);
category = 10;
emit ThreeRockets(target, spin.blockn);
} else if (result < 52333) {
profit = SafeMath.div(SafeMath.mul(spin.tokenValue, 25),10);
category = 11;
emit OneMoonPrize(target, spin.blockn);
} else if (result < 120226) {
profit = SafeMath.div(SafeMath.mul(spin.tokenValue, 15),10);
category = 12;
emit OneOfEachPyramidPrize(target, spin.blockn);
} else if (result < 171147) {
profit = spin.tokenValue;
category = 13;
emit TwoZSymbols(target, spin.blockn);
} else if (result < 222068) {
profit = spin.tokenValue;
category = 14;
emit TwoTSymbols(target, spin.blockn);
} else if (result < 272989) {
profit = spin.tokenValue;
category = 15;
emit TwoHSymbols(target, spin.blockn);
} else if (result < 323910) {
profit = SafeMath.mul(spin.tokenValue, 2);
category = 16;
emit TwoEtherIcons(target, spin.blockn);
} else if (result < 374831) {
profit = SafeMath.div(SafeMath.mul(spin.tokenValue, 133),100);
category = 17;
emit TwoPurplePyramids(target, spin.blockn);
} else if (result < 425752) {
profit = SafeMath.div(SafeMath.mul(spin.tokenValue, 133),100);
category = 18;
emit TwoGoldPyramids(target, spin.blockn);
} else {
profit = SafeMath.mul(spin.tokenValue, 2);
category = 19;
emit TwoRockets(target, spin.blockn);
}
emit LogResult(target, result, profit, spin.tokenValue, category, true);
tier = spin.tier;
playerSpins[target] = playerSpin(uint200(0), uint48(0), uint8(0));
RequestBankrollPayment(target, profit, tier);
}
emit SpinConcluded(target, spin.blockn);
return result;
}
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 setMaxProfit(uint divRate) internal {
maxProfit[divRate] = (contractBalance[divRate] * maxProfitAsPercentOfHouse) / maxProfitDivisor;
}
function getMaxProfit(uint divRate) public view returns (uint) {
return (contractBalance[divRate] * maxProfitAsPercentOfHouse) / maxProfitDivisor;
}
function subContractBalance(uint divRate, uint sub) internal {
contractBalance[divRate] = contractBalance[divRate].sub(sub);
}
function addContractBalance(uint divRate, uint add) internal {
contractBalance[divRate] = contractBalance[divRate].add(add);
}
function bankrollExternalUpdateTokens(uint divRate, uint newBalance)
public
fromBankroll
{
contractBalance[divRate] = newBalance;
setMaxProfit(divRate);
}
function ownerSetMaxProfitAsPercentOfHouse(uint newMaxProfitAsPercent) public
onlyOwner
{
require(newMaxProfitAsPercent <= 200000);
maxProfitAsPercentOfHouse = newMaxProfitAsPercent;
setMaxProfit(2);
setMaxProfit(5);
setMaxProfit(10);
setMaxProfit(15);
setMaxProfit(20);
setMaxProfit(25);
setMaxProfit(33);
}
function ownerSetMinBet(uint newMinimumBet) public
onlyOwner
{
minBet = newMinimumBet;
}
function ownerSetZlotsAddress(address zlotsAddress) public
onlyOwner
{
zlotsJackpot = zlotsAddress;
}
function pauseGame() public onlyOwnerOrBankroll {
gameActive = false;
}
function resumeGame() public onlyOwnerOrBankroll {
gameActive = true;
}
function changeOwner(address _newOwner) public onlyOwnerOrBankroll {
owner = _newOwner;
}
function changeBankroll(address _newBankroll) public onlyOwnerOrBankroll {
bankroll = _newBankroll;
}
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;
}
} |