Contract Address Details

0x5DF93a44D6B4E360fB17345cE47B83049d091A2a

Sacrific3C Last Balance Update: Block #13531182
Created by 0x4b4f72–eb5072 at 0xf96e81–63d746

Balance

4.526135219559283414 ETC

(@ /ETC)

Fetching tokens...

Contract name:
Sacrific3C




Optimization enabled
true
Compiler version
v0.4.24+commit.e67f0147




Optimization runs
200
EVM Version
byzantium




Verified at
2019-12-25 04:28:28.767438Z

Contract source code

pragma solidity ^0.4.24;
contract Sacrific3C {
struct Stage {
uint8 numberOfPlayers;
uint256 blocknumber;
bool finalized;
mapping (uint8 => address) slotXplayer;
mapping (address => bool) players;
}
HourglassInterface constant p3cContract = HourglassInterface(0xDe6FB6a5adbe6415CDaF143F8d90Eb01883e42ac);
//a small part of every winners share of the sacrificed players offer is used to purchase p3c instead
uint256 constant private P3C_SHARE = 0.005 ether;
uint8 constant public MAX_PLAYERS_PER_STAGE = 5;
uint256 constant public OFFER_SIZE = 0.1 ether;
uint256 private p3cPerStage = P3C_SHARE * (MAX_PLAYERS_PER_STAGE - 1);
//not sacrificed players receive their offer back and also a share of the sacrificed players offer
uint256 public winningsPerRound = OFFER_SIZE + OFFER_SIZE / (MAX_PLAYERS_PER_STAGE - 1) - P3C_SHARE;
mapping(address => uint256) private playerVault;
mapping(uint256 => Stage) private stages;
uint256 private numberOfFinalizedStages;
uint256 public numberOfStages;
event SacrificeOffered(address indexed player);
event SacrificeChosen(address indexed sarifice);
event EarningsWithdrawn(address indexed player, uint256 indexed amount);
event StageInvalidated(uint256 indexed stage);
modifier isValidOffer()
{
require(msg.value == OFFER_SIZE);
_;
}
modifier canPayFromVault()
{
require(playerVault[msg.sender] >= OFFER_SIZE);
_;
}
modifier hasEarnings()
{
require(playerVault[msg.sender] > 0);
_;
}
modifier prepareStage()
{
//create a new stage if current has reached max amount of players
if(stages[numberOfStages - 1].numberOfPlayers == MAX_PLAYERS_PER_STAGE) {
stages[numberOfStages] = Stage(0, 0, false);
numberOfStages++;
}
_;
}
modifier isNewToStage()
{
require(stages[numberOfStages - 1].players[msg.sender] == false);
_;
}
constructor()
public
{
stages[numberOfStages] = Stage(0, 0, false);
numberOfStages++;
}
function() external payable {}
function offerAsSacrifice()
external
payable
isValidOffer
prepareStage
isNewToStage
{
acceptOffer();
//try to choose a sacrifice in an already full stage (finalize a stage)
tryFinalizeStage();
}
function offerAsSacrificeFromVault()
external
canPayFromVault
prepareStage
isNewToStage
{
playerVault[msg.sender] -= OFFER_SIZE;
acceptOffer();
tryFinalizeStage();
}
function withdraw()
external
hasEarnings
{
tryFinalizeStage();
uint256 amount = playerVault[msg.sender];
playerVault[msg.sender] = 0;
emit EarningsWithdrawn(msg.sender, amount);
msg.sender.transfer(amount);
}
function myEarnings()
external
view
hasEarnings
returns(uint256)
{
return playerVault[msg.sender];
}
function currentPlayers()
external
view
returns(uint256)
{
return stages[numberOfStages - 1].numberOfPlayers;
}
function acceptOffer()
private
{
Stage storage currentStage = stages[numberOfStages - 1];
assert(currentStage.numberOfPlayers < MAX_PLAYERS_PER_STAGE);
address player = msg.sender;
//add player to current stage
currentStage.slotXplayer[currentStage.numberOfPlayers] = player;
currentStage.numberOfPlayers++;
currentStage.players[player] = true;
emit SacrificeOffered(player);
//add blocknumber to current stage when the last player is added
if(currentStage.numberOfPlayers == MAX_PLAYERS_PER_STAGE) {
currentStage.blocknumber = block.number;
}
}
function tryFinalizeStage()
private
{
assert(numberOfStages >= numberOfFinalizedStages);
//there are no stages to finalize
if(numberOfStages == numberOfFinalizedStages) {return;}
Stage storage stageToFinalize = stages[numberOfFinalizedStages];
assert(!stageToFinalize.finalized);
//stage is not ready to be finalized
if(stageToFinalize.numberOfPlayers < MAX_PLAYERS_PER_STAGE) {return;}
assert(stageToFinalize.blocknumber != 0);
//check if blockhash can be determined
if(block.number - 256 <= stageToFinalize.blocknumber) {
//blocknumber of stage can not be equal to current block number -> blockhash() won't work
if(block.number == stageToFinalize.blocknumber) {return;}
//determine sacrifice
uint8 sacrificeSlot = uint8(blockhash(stageToFinalize.blocknumber)) % MAX_PLAYERS_PER_STAGE;
address sacrifice = stageToFinalize.slotXplayer[sacrificeSlot];
emit SacrificeChosen(sacrifice);
//allocate winnings to survivors
allocateSurvivorWinnings(sacrifice);
//allocate p3c dividends to sacrifice if existing
uint256 dividends = p3cContract.myDividends(true);
if(dividends > 0) {
p3cContract.withdraw();
playerVault[sacrifice]+= dividends;
}
//purchase p3c (using ref)
p3cContract.buy.value(p3cPerStage)(address(0x4B4f724B936290bDADC87439856Eaf2671eb5072));
} else {
invalidateStage(numberOfFinalizedStages);
emit StageInvalidated(numberOfFinalizedStages);
}
//finalize stage
stageToFinalize.finalized = true;
numberOfFinalizedStages++;
}
function allocateSurvivorWinnings(address sacrifice)
private
{
for (uint8 i = 0; i < MAX_PLAYERS_PER_STAGE; i++) {
address survivor = stages[numberOfFinalizedStages].slotXplayer[i];
if(survivor != sacrifice) {
playerVault[survivor] += winningsPerRound;
}
}
}
function invalidateStage(uint256 stageIndex)
private
{
Stage storage stageToInvalidate = stages[stageIndex];
for (uint8 i = 0; i < MAX_PLAYERS_PER_STAGE; i++) {
address player = stageToInvalidate.slotXplayer[i];
playerVault[player] += OFFER_SIZE;
}
}
}
interface HourglassInterface {
function buy(address _playerAddress) payable external returns(uint256);
function withdraw() external;
function myDividends(bool _includeReferralBonus) external view returns(uint256);
}

Contract ABI

[{"type":"function","stateMutability":"nonpayable","payable":false,"outputs":[],"name":"offerAsSacrificeFromVault","inputs":[],"constant":false},{"type":"function","stateMutability":"nonpayable","payable":false,"outputs":[],"name":"withdraw","inputs":[],"constant":false},{"type":"function","stateMutability":"view","payable":false,"outputs":[{"type":"uint256","name":""}],"name":"OFFER_SIZE","inputs":[],"constant":true},{"type":"function","stateMutability":"payable","payable":true,"outputs":[],"name":"offerAsSacrifice","inputs":[],"constant":false},{"type":"function","stateMutability":"view","payable":false,"outputs":[{"type":"uint256","name":""}],"name":"winningsPerRound","inputs":[],"constant":true},{"type":"function","stateMutability":"view","payable":false,"outputs":[{"type":"uint256","name":""}],"name":"currentPlayers","inputs":[],"constant":true},{"type":"function","stateMutability":"view","payable":false,"outputs":[{"type":"uint256","name":""}],"name":"numberOfStages","inputs":[],"constant":true},{"type":"function","stateMutability":"view","payable":false,"outputs":[{"type":"uint8","name":""}],"name":"MAX_PLAYERS_PER_STAGE","inputs":[],"constant":true},{"type":"function","stateMutability":"view","payable":false,"outputs":[{"type":"uint256","name":""}],"name":"myEarnings","inputs":[],"constant":true},{"type":"constructor","stateMutability":"nonpayable","payable":false,"inputs":[]},{"type":"fallback","stateMutability":"payable","payable":true},{"type":"event","name":"SacrificeOffered","inputs":[{"type":"address","name":"player","indexed":true}],"anonymous":false},{"type":"event","name":"SacrificeChosen","inputs":[{"type":"address","name":"sarifice","indexed":true}],"anonymous":false},{"type":"event","name":"EarningsWithdrawn","inputs":[{"type":"address","name":"player","indexed":true},{"type":"uint256","name":"amount","indexed":true}],"anonymous":false},{"type":"event","name":"StageInvalidated","inputs":[{"type":"uint256","name":"stage","indexed":true}],"anonymous":false}]
            

Deployed ByteCode

0x6080604052600436106100985763ffffffff7c0100000000000000000000000000000000000000000000000000000000600035041663213a2622811461009a5780633ccfd60b146100af5780634eff13dc146100c45780635d69f16f146100eb57806395dd489b146100f35780639cf8ccfd14610108578063d13a73c41461011d578063efe6c77214610132578063ffe6bbd81461015d575b005b3480156100a657600080fd5b50610098610172565b3480156100bb57600080fd5b5061009861027f565b3480156100d057600080fd5b506100d9610316565b60408051918252519081900360200190f35b610098610322565b3480156100ff57600080fd5b506100d96103f7565b34801561011457600080fd5b506100d96103fd565b34801561012957600080fd5b506100d9610419565b34801561013e57600080fd5b5061014761041f565b6040805160ff9092168252519081900360200190f35b34801561016957600080fd5b506100d9610424565b3360009081526002602052604090205467016345785d8a0000111561019657600080fd5b600580546000190160009081526003602052604090205460ff16141561021e5760408051606081018252600080825260208083018281528385018381526005805485526003909352949092209251835460ff9190911660ff19918216178455915160018481019190915593516002909301805493151593909216929092179055805490910190555b60055460001901600090815260036020908152604080832033845260040190915290205460ff161561024f57600080fd5b336000908152600260205260409020805467016345785d89ffff19019055610275610453565b61027d61051f565b565b33600090815260026020526040812054811061029a57600080fd5b6102a261051f565b503360008181526002602052604080822080549083905590519092839290917f48dc35af7b45e2a81fffad55f6e2fafacdb1d3d0d50d24ebdc16324f5ba757f19190a3604051339082156108fc029083906000818181858888f19350505050158015610312573d6000803e3d6000fd5b5050565b67016345785d8a000081565b3467016345785d8a00001461033657600080fd5b600580546000190160009081526003602052604090205460ff1614156103be5760408051606081018252600080825260208083018281528385018381526005805485526003909352949092209251835460ff9190911660ff19918216178455915160018481019190915593516002909301805493151593909216929092179055805490910190555b60055460001901600090815260036020908152604080832033845260040190915290205460ff16156103ef57600080fd5b610275610453565b60015481565b6005546000190160009081526003602052604090205460ff1690565b60055481565b600581565b33600090815260026020526040812054811061043f57600080fd5b503360009081526002602052604090205490565b600580546000190160009081526003602052604081208054909260ff9091161061047957fe5b50805460ff90811660009081526003830160209081526040808320805473ffffffffffffffffffffffffffffffffffffffff1916339081179091558554808616600190810190961660ff199182161787558185526004870190935281842080549093169094179091555182917f53572b7c2bc733aef4eee14d2f251f8d38bd1b54d23167fcc83e5298d427db9f91a2815460ff1660051415610312574360018301555050565b6000806000806004546005541015151561053557fe5b600454600554141561054657610884565b6004546000908152600360205260409020600281015490945060ff161561056957fe5b8354600560ff909116101561057d57610884565b6001840154151561058a57fe5b600184015460ff194301116108305783600101544314156105aa57610884565b60018401546005904060ff160660ff8116600090815260038601602052604080822054905192955073ffffffffffffffffffffffffffffffffffffffff16935083917f7a1bc82d0aa0c6ec064f947f3007b8c603bde2db8b2ed004c07bc105dc5e25a49190a26106198261088a565b604080517f688abbf700000000000000000000000000000000000000000000000000000000815260016004820152905173de6fb6a5adbe6415cdaf143f8d90eb01883e42ac9163688abbf79160248083019260209291908290030181600087803b15801561068657600080fd5b505af115801561069a573d6000803e3d6000fd5b505050506040513d60208110156106b057600080fd5b5051905060008111156107795773de6fb6a5adbe6415cdaf143f8d90eb01883e42ac73ffffffffffffffffffffffffffffffffffffffff16633ccfd60b6040518163ffffffff167c0100000000000000000000000000000000000000000000000000000000028152600401600060405180830381600087803b15801561073557600080fd5b505af1158015610749573d6000803e3d6000fd5b50505073ffffffffffffffffffffffffffffffffffffffff83166000908152600260205260409020805483019055505b600054604080517ff088d547000000000000000000000000000000000000000000000000000000008152734b4f724b936290bdadc87439856eaf2671eb50726004820152905173de6fb6a5adbe6415cdaf143f8d90eb01883e42ac9263f088d547929091602480830192602092919082900301818588803b1580156107fd57600080fd5b505af1158015610811573d6000803e3d6000fd5b50505050506040513d602081101561082857600080fd5b506108689050565b61083b60045461091e565b6004546040517f734a18a68f572b3535e4ddb7d4bc879c3ef7083d347b4a0c247a6eda7a7001e190600090a25b60028401805460ff191660019081179091556004805490910190555b50505050565b6000805b600560ff831610156109195750600454600090815260036020818152604080842060ff86168552909201905290205473ffffffffffffffffffffffffffffffffffffffff908116908316811461090e5760015473ffffffffffffffffffffffffffffffffffffffff82166000908152600260205260409020805490910190555b60019091019061088e565b505050565b600081815260036020526040812090805b600560ff83161015610884575060ff8116600090815260038301602090815260408083205473ffffffffffffffffffffffffffffffffffffffff168084526002909252909120805467016345785d8a000001905560019091019061092f5600a165627a7a72305820871921acc7d1d9b787373c3c2f1127887cc3271620d3dc198394d28d6ae4d7540029