Untitled diff

Created Diff never expires
pragma solidity ^0.4.21;
pragma solidity ^0.4.21;



/*
/*
******************** HALO 3D *********************

* ===============================================*

MMMMMMMMMMMMMMMMMMMMMWWXKKXNWMMMMMMMMMMMMMMMMMMMMM
******************** OmniDex *********************
MMMMMMMMMMMMMMMMMMWWXko;'',lkKNWWMMMMMMMMMMMMMMMMM
* [x] What is new?
MMMMMMMMMMMMMMMMMNOc'. .:d0XWWMMMMMMMMMMMMMM
* [x] 0% TRANSFER FEES! This allows for tokens to be used in future games with out being taxed
MMMMMMMMMMMMMMMMMNOc'. .,lkKNWWMMMMMMMMMM
* [X] 18% DIVIDENDS AND MASTERNODES!
MMMMMMMWWNKKXWWMMMWNKkl' .:d0XWWMMMMMMM
* [x] 2% Bankroll Fee
MMMMWWXOo;..'cx0NNWX0d:. .,lkKWWMMMM
* 75% of Bankroll ETH will be dumped back into the contract Every Monday at Midnight Eastern Time. 25% of Bankroll ETH collect will go to funding future development.
MMWWKo,. .;lc,. . 'l0NWMM
* [x] DAPP INTEROPERABILITY, games and other dAPPs can incorporate OmniDex tokens!
MMWOc;,'. .,lkOdc'. ..,,:xNWM
MWNd. .';;,. .lOXNWWWNXOo;,,,'. :XWM
MWNo. .ckxl,. .'cxKNWMMMWWXd. :KWM
MWNo. :KNNXOo;. 'oKNWMMWNo. :KWM
MWNd. :KWWWW0l;;;'. ..,,,:kWMMWNo. :KWM
MWNo. ;0WWWWO' .,;;;;;;'. .dNWMWXo. :KWM
MWNo. .lkXNNO' 'dx; .dXNX0d, :KWM
MWNo. .':dd. .ox; .lxl;. :KWM
MWNo. . .ox; .. :KWM
MWNd. .ox; :KWM
MWNd. ,dl;. .ox; .'cdc. :KWM
MMNx. ;0NN0d;. .ox; 'oOXNXo. .oXWM
MMWNOo;. :KWMWNO' .ox; .oXWMWNo. .,lkXWMM
MMMMWWN0xlxNWMMWO' .ox; .dNWMMWOox0NWWMMMM
MMMMMMMMWWWMMMMWO' .ox; .dNWMMMWWWMMMMMMMM
MMMMMMMMMMMMMMMWKc. .ox, ,OWMMMMMMMMMMMMMMM
MMMMMMMMMMMMMMMMWXOo;. .ox; .,lkXWWMMMMMMMMMMMMMMM
MMMMMMMMMMMMMMMMMMWWN0xx0Kkx0NWWMMMMMMMMMMMMMMMMMM
MMMMMMMMMMMMMMMMMMMMMMMWWWWWMMMMMMMMMMMMMMMMMMMMMM
* ===============================================*
******************** HALO 3D *********************
*
* The World's FIRST Charity/Gaming Pyramid! All the features of a classic pyramid plus more.
* Brought to you by a collaboration of crypto gaming experts and YouTubers.
*
*
* What is new?
* [x] REVOLUTIONARY 0% TRANSFER FEES, Now you can send Halo3D tokens to all your family, no charge
* [X] 20% DIVIDENDS AND MASTERNODES! We know you all love your divies :D
* [x] GENEROUS 2% FEE ON EACH BUY AND SELL GO TO CHARITY https://giveth.io/
* https://etherscan.io/address/0x5ADF43DD006c6C36506e2b2DFA352E60002d22Dc
* [x] DAPP INTEROPERABILITY, games and other dAPPs can incorporate Halo3D tokens!
*
* Official website is https://h3d.pw/ :)
* Official discord is https://discord.gg/w6HamAS 0_0
*/
*/




/**
/**
* Definition of contract accepting Halo3D tokens
* Definition of contract accepting OmniDex tokens
* Games, casinos, anything can reuse this contract to support Halo3D tokens
* Games, casinos, anything can reuse this contract to support OmniDex tokens
*/
*/
contract AcceptsHalo3D {
contract AcceptsOmniDex {
Halo3D public tokenContract;
OmniDex public tokenContract;


function AcceptsHalo3D(address _tokenContract) public {
function AcceptsOmniDex(address _tokenContract) public {
tokenContract = Halo3D(_tokenContract);
tokenContract = OmniDex(_tokenContract);
}
}


modifier onlyTokenContract {
modifier onlyTokenContract {
require(msg.sender == address(tokenContract));
require(msg.sender == address(tokenContract));
_;
_;
}
}


/**
/**
* @dev Standard ERC677 function that will handle incoming token transfers.
* @dev Standard ERC677 function that will handle incoming token transfers.
*
*
* @param _from Token sender address.
* @param _from Token sender address.
* @param _value Amount of tokens.
* @param _value Amount of tokens.
* @param _data Transaction metadata.
* @param _data Transaction metadata.
*/
*/
function tokenFallback(address _from, uint256 _value, bytes _data) external returns (bool);
function tokenFallback(address _from, uint256 _value, bytes _data) external returns (bool);
}
}




contract Halo3D {
contract OmniDex {
/*=================================
/*=================================
= MODIFIERS =
= MODIFIERS =
=================================*/
=================================*/
// only people with tokens
// only people with tokens
modifier onlyBagholders() {
modifier onlyBagholders() {
require(myTokens() > 0);
require(myTokens() > 0);
_;
_;
}
}


// only people with profits
// only people with profits
modifier onlyStronghands() {
modifier onlyStronghands() {
require(myDividends(true) > 0);
require(myDividends(true) > 0);
_;
_;
}
}


modifier notContract() {
modifier notContract() {
require (msg.sender == tx.origin);
require (msg.sender == tx.origin);
_;
_;
}
}


// administrators can:
// administrators can:
// -> change the name of the contract
// -> change the name of the contract
// -> change the name of the token
// -> change the name of the token
// -> change the PoS difficulty (How many tokens it costs to hold a masternode, in case it gets crazy high later)
// -> change the PoS difficulty (How many tokens it costs to hold a masternode, in case it gets crazy high later)
// they CANNOT:
// they CANNOT:
// -> take funds
// -> take funds
// -> disable withdrawals
// -> disable withdrawals
// -> kill the contract
// -> kill the contract
// -> change the price of tokens
// -> change the price of tokens
modifier onlyAdministrator(){
modifier onlyAdministrator(){
address _customerAddress = msg.sender;
address _customerAddress = msg.sender;
require(administrators[_customerAddress]);
require(administrators[_customerAddress]);
_;
_;
}
}




// ensures that the first tokens in the contract will be equally distributed
// ensures that the first tokens in the contract will be equally distributed
// meaning, no divine dump will be ever possible
// meaning, no divine dump will be ever possible
// result: healthy longevity.
// result: healthy longevity.
modifier antiEarlyWhale(uint256 _amountOfEthereum){
modifier antiEarlyWhale(uint256 _amountOfEthereum){
address _customerAddress = msg.sender;
address _customerAddress = msg.sender;


// are we still in the vulnerable phase?
// are we still in the vulnerable phase?
// if so, enact anti early whale protocol
// if so, enact anti early whale protocol
if( onlyAmbassadors && ((totalEthereumBalance() - _amountOfEthereum) <= ambassadorQuota_ )){
if( onlyAmbassadors && ((totalEthereumBalance() - _amountOfEthereum) <= ambassadorQuota_ )){
require(
require(
// is the customer in the ambassador list?
// is the customer in the ambassador list?
ambassadors_[_customerAddress] == true &&
ambassadors_[_customerAddress] == true &&


// does the customer purchase exceed the max ambassador quota?
// does the customer purchase exceed the max ambassador quota?
(ambassadorAccumulatedQuota_[_customerAddress] + _amountOfEthereum) <= ambassadorMaxPurchase_
(ambassadorAccumulatedQuota_[_customerAddress] + _amountOfEthereum) <= ambassadorMaxPurchase_


);
);


// updated the accumulated quota
// updated the accumulated quota
ambassadorAccumulatedQuota_[_customerAddress] = SafeMath.add(ambassadorAccumulatedQuota_[_customerAddress], _amountOfEthereum);
ambassadorAccumulatedQuota_[_customerAddress] = SafeMath.add(ambassadorAccumulatedQuota_[_customerAddress], _amountOfEthereum);


// execute
// execute
_;
_;
} else {
} else {
// in case the ether count drops low, the ambassador phase won't reinitiate
// in case the ether count drops low, the ambassador phase won't reinitiate
onlyAmbassadors = false;
onlyAmbassadors = false;
_;
_;
}
}


}
}


/*==============================
/*==============================
= EVENTS =
= EVENTS =
==============================*/
==============================*/
event onTokenPurchase(
event onTokenPurchase(
address indexed customerAddress,
address indexed customerAddress,
uint256 incomingEthereum,
uint256 incomingEthereum,
uint256 tokensMinted,
uint256 tokensMinted,
address indexed referredBy
address indexed referredBy
);
);


event onTokenSell(
event onTokenSell(
address indexed customerAddress,
address indexed customerAddress,
uint256 tokensBurned,
uint256 tokensBurned,
uint256 ethereumEarned
uint256 ethereumEarned
);
);


event onReinvestment(
event onReinvestment(
address indexed customerAddress,
address indexed customerAddress,
uint256 ethereumReinvested,
uint256 ethereumReinvested,
uint256 tokensMinted
uint256 tokensMinted
);
);


event onWithdraw(
event onWithdraw(
address indexed customerAddress,
address indexed customerAddress,
uint256 ethereumWithdrawn
uint256 ethereumWithdrawn
);
);


// ERC20
// ERC20
event Transfer(
event Transfer(
address indexed from,
address indexed from,
address indexed to,
address indexed to,
uint256 tokens
uint256 tokens
);
);




/*=====================================
/*=====================================
= CONFIGURABLES =
= CONFIGURABLES =
=====================================*/
=====================================*/
string public name = "Halo3D";
string public name = "OmniDex";
string public symbol = "H3D";
string public symbol = "OMNI";
uint8 constant public decimals = 18;
uint8 constant public decimals = 18;
uint8 constant internal dividendFee_ = 20; // 20% dividend fee on each buy and sell
uint8 constant internal dividendFee_ = 18; // 18% dividend fee on each buy and sell
uint8 constant internal charityFee_ = 2; // 2% charity fee on each buy and sell
uint8 constant internal bankrollFee_ = 2; // 2% Bankroll fee on each buy and sell
uint256 constant internal tokenPriceInitial_ = 0.0000001 ether;
uint256 constant internal tokenPriceInitial_ = 0.00000001 ether;
uint256 constant internal tokenPriceIncremental_ = 0.00000001 ether;
uint256 constant internal tokenPriceIncremental_ = 0.000000001 ether;
uint256 constant internal magnitude = 2**64;
uint256 constant internal magnitude = 2**64;


// Address to send the charity ! :)
// Address to send the Bankroll
// https://giveth.io/
// https://etherscan.io/address/0x5ADF43DD006c6C36506e2b2DFA352E60002d22Dc
address constant public giveEthBankrollAddress = 0x523a819E6dd9295Dba794C275627C95fa0644E8D;
address constant public giveEthCharityAddress = 0x5ADF43DD006c6C36506e2b2DFA352E60002d22Dc;
uint256 public totalEthBankrollRecieved; // total ETH Bankroll recieved from this contract
uint256 public totalEthCharityRecieved; // total ETH charity recieved from this contract
uint256 public totalEthBankrollCollected; // total ETH Bankroll collected in this contract
uint256 public totalEthCharityCollected; // total ETH charity collected in this contract


// proof of stake (defaults at 100 tokens)
// proof of stake (defaults at 100 tokens)
uint256 public stakingRequirement = 100e18;
uint256 public stakingRequirement = 30e18;


// ambassador program
// ambassador program
mapping(address => bool) internal ambassadors_;
mapping(address => bool) internal ambassadors_;
uint256 constant internal ambassadorMaxPurchase_ = 0.4 ether;
uint256 constant internal ambassadorMaxPurchase_ = 0.5 ether;
uint256 constant internal ambassadorQuota_ = 10 ether;
uint256 constant internal ambassadorQuota_ = 3 ether; // If ambassor quota not met, disable to open to public






/*================================
/*================================
= DATASETS =
= DATASETS =
================================*/
================================*/
// amount of shares for each address (scaled number)
// amount of shares for each address (scaled number)
mapping(address => uint256) internal tokenBalanceLedger_;
mapping(address => uint256) internal tokenBalanceLedger_;
mapping(address => uint256) internal referralBalance_;
mapping(address => uint256) internal referralBalance_;
mapping(address => int256) internal payoutsTo_;
mapping(address => int256) internal payoutsTo_;
mapping(address => uint256) internal ambassadorAccumulatedQuota_;
mapping(address => uint256) internal ambassadorAccumulatedQuota_;
uint256 internal tokenSupply_ = 0;
uint256 internal tokenSupply_ = 0;
uint256 internal profitPerShare_;
uint256 internal profitPerShare_;


// administrator list (see above on what they can do)
// administrator list (see above on what they can do)
mapping(address => bool) public administrators;
mapping(address => bool) public administrators;


// when this is set to true, only ambassadors can purchase tokens (this prevents a whale premine, it ensures a fairly distributed upper pyramid)
// when this is set to true, only ambassadors can purchase tokens (this prevents a whale premine, it ensures a fairly distributed upper pyramid)
bool public onlyAmbassadors = true;
bool public onlyAmbassadors = true;


// Special Halo3D Platform control from scam game contracts on Halo3D platform
// Special OmniDex Platform control from scam game contracts on OmniDex platform
mapping(address => bool) public canAcceptTokens_; // contracts, which can accept Halo3D tokens
mapping(address => bool) public canAcceptTokens_; // contracts, which can accept OmniDex tokens






/*=======================================
/*=======================================
= PUBLIC FUNCTIONS =
= PUBLIC FUNCTIONS =
=======================================*/
=======================================*/
/*
/*
* -- APPLICATION ENTRY POINTS --
* -- APPLICATION ENTRY POINTS --
*/
*/
function Halo3D()
function OmniDex()
public
public
{
{
// add administrators here
// add administrators here
administrators[0xf4cFeD6A0f869548F73f05a364B329b86B6Bb157] = true;
administrators[0xDEAD04D223220ACb19B46AFc84E04D490b872249] = true;


// add the ambassadors here.
// add the ambassadors here.
ambassadors_[0xf4cFeD6A0f869548F73f05a364B329b86B6Bb157] = true;
ambassadors_[0xDEAD04D223220ACb19B46AFc84E04D490b872249] = true;
//ambassador B
//ambassador Dev
ambassadors_[0xe436cbd3892c6dc3d6c8a3580153e6e0fa613cfc] = true;
//ambassador W
ambassadors_[0x922cFfa33A078B4Cc6077923e43447d8467F8B55] = true;
//ambassador B1
ambassadors_[0x8Dd512843c24c382210a9CcC9C98B8b5eEED97e8] = true;
//ambassador J
ambassadors_[0x4ffe17a2a72bc7422cb176bc71c04ee6d87ce329] = true;
//ambassador CG
ambassadors_[0x3747EaFE2Bc9cB5221879758ca24a0d15B47A9B6] = true;
//ambassador BL
ambassadors_[0xB38094D492af4FfffF760707F36869713bFb2250] = true;
//ambassador BU
ambassadors_[0xBa21d01125D6932ce8ABf3625977899Fd2C7fa30] = true;
//ambassador SW
ambassadors_[0x2e6236591bfa37c683ce60d6cfde40396a114ff1] = true;
//ambassador Tr
ambassadors_[0xa683C1b815997a7Fa38f6178c84675FC4c79AC2B] = true;
//ambassador NM
ambassadors_[0x84ECB387395a1be65E133c75Ff9e5FCC6F756DB3] = true;
//ambassador Kh
ambassadors_[0x05f2c11996d73288AbE8a31d8b593a693FF2E5D8] = true;
//ambassador KA
ambassadors_[0x5632CA98e5788edDB2397757Aa82d1Ed6171e5aD] = true;
//ambassador FL
ambassadors_[0xA790fa6422A15a3637885f6811e5428de3513169] = true;
//ambassador Al
ambassadors_[0x008ca4F1bA79D1A265617c6206d7884ee8108a78] = true;
ambassadors_[0x008ca4F1bA79D1A265617c6206d7884ee8108a78] = true;
//ambassador KC
//ambassador Crypto Alex
ambassadors_[0x7c377B7bCe53a5CEF88458b2cBBe11C3babe16DA] = true;
ambassadors_[0x9f06A41D9F00007009e4c1842D2f2aA9FC844a26] = true;
//ambassador Ph
//ambassador FROG
ambassadors_[0x183feBd8828a9ac6c70C0e27FbF441b93004fC05] = true;
ambassadors_[0xAAa2792AC2A60c694a87Cec7516E8CdFE85B0463] = true;
//ambassador CW
//ambassador Cliffy
ambassadors_[0x29A9c76aD091c015C12081A1B201c3ea56884579] = true;
ambassadors_[0x41a21b264f9ebf6cf571d4543a5b3ab1c6bed98c] = true;
//ambassador Ravi
ambassadors_[0xAD6D6c25FCDAb2e737e8de31795df4c6bB6D9Bae] = true;
//ambassador Hellina
}
}




/**
/**
* Converts all incoming ethereum to tokens for the caller, and passes down the referral addy (if any)
* Converts all incoming ethereum to tokens for the caller, and passes down the referral addy (if any)
*/
*/
function buy(address _referredBy)
function buy(address _referredBy)
public
public
payable
payable
returns(uint256)
returns(uint256)
{
{
purchaseInternal(msg.value, _referredBy);
purchaseInternal(msg.value, _referredBy);
}
}


/**
/**
* Fallback function to handle ethereum that was send straight to the contract
* Fallback function to handle ethereum that was send straight to the contract
* Unfortunately we cannot use a referral address this way.
* Unfortunately we cannot use a referral address this way.
*/
*/
function()
function()
payable
payable
public
public
{
{
purchaseInternal(msg.value, 0x0);
purchaseInternal(msg.value, 0x0);
}
}


/**
/**
* Sends charity money to the https://giveth.io/
* Sends Bankroll funds for additional dividends
* Their charity address is here https://etherscan.io/address/0x5ADF43DD006c6C36506e2b2DFA352E60002d22Dc
* Bankroll Address: https://etherscan.io/address/0x523a819E6dd9295Dba794C275627C95fa0644E8D
*/
*/
function payCharity() payable public {
function payBankroll() payable public {
uint256 ethToPay = SafeMath.sub(totalEthCharityCollected, totalEthCharityRecieved);
uint256 ethToPay = SafeMath.sub(totalEthBankrollCollected, totalEthBankrollRecieved);
require(ethToPay > 1);
require(ethToPay > 1);
totalEthCharityRecieved = SafeMath.add(totalEthCharityRecieved, ethToPay);
totalEthBankrollRecieved = SafeMath.add(totalEthBankrollRecieved, ethToPay);
if(!giveEthCharityAddress.call.value(ethToPay).gas(400000)()) {
if(!giveEthBankrollAddress.call.value(ethToPay).gas(400000)()) {
totalEthCharityRecieved = SafeMath.sub(totalEthCharityRecieved, ethToPay);
totalEthBankrollRecieved = SafeMath.sub(totalEthBankrollRecieved, ethToPay);
}
}
}
}


/**
/**
* Converts all of caller's dividends to tokens.
* Converts all of caller's dividends to tokens.
*/
*/
function reinvest()
function reinvest()
onlyStronghands()
onlyStronghands()
public
public
{
{
// fetch dividends
// fetch dividends
uint256 _dividends = myDividends(false); // retrieve ref. bonus later in the code
uint256 _dividends = myDividends(false); // retrieve ref. bonus later in the code


// pay out the dividends virtually
// pay out the dividends virtually
address _customerAddress = msg.sender;
address _customerAddress = msg.sender;
payoutsTo_[_customerAddress] += (int256) (_dividends * magnitude);
payoutsTo_[_customerAddress] += (int256) (_dividends * magnitude);


// retrieve ref. bonus
// retrieve ref. bonus
_dividends += referralBalance_[_customerAddress];
_dividends += referralBalance_[_customerAddress];
referralBalance_[_customerAddress] = 0;
referralBalance_[_customerAddress] = 0;


// dispatch a buy order with the virtualized "withdrawn dividends"
// dispatch a buy order with the virtualized "withdrawn dividends"
uint256 _tokens = purchaseTokens(_dividends, 0x0);
uint256 _tokens = purchaseTokens(_dividends, 0x0);


// fire event
// fire event
onReinvestment(_customerAddress, _dividends, _tokens);
onReinvestment(_customerAddress, _dividends, _tokens);
}
}


/**
/**
* Alias of sell() and withdraw().
* Alias of sell() and withdraw().
*/
*/
function exit()
function exit()
public
public
{
{
// get token count for caller & sell them all
// get token count for caller & sell them all
address _customerAddress = msg.sender;
address _customerAddress = msg.sender;
uint256 _tokens = tokenBalanceLedger_[_customerAddress];
uint256 _tokens = tokenBalanceLedger_[_customerAddress];
if(_tokens > 0) sell(_tokens);
if(_tokens > 0) sell(_tokens);


// lambo delivery service
// lambo delivery service
withdraw();
withdraw();
}
}


/**
/**
* Withdraws all of the callers earnings.
* Withdraws all of the callers earnings.
*/
*/
function withdraw()
function withdraw()
onlyStronghands()
onlyStronghands()
public
public
{
{
// setup data
// setup data
address _customerAddress = msg.sender;
address _customerAddress = msg.sender;
uint256 _dividends = myDividends(false); // get ref. bonus later in the code
uint256 _dividends = myDividends(false); // get ref. bonus later in the code


// update dividend tracker
// update dividend tracker
payoutsTo_[_customerAddress] += (int256) (_dividends * magnitude);
payoutsTo_[_customerAddress] += (int256) (_dividends * magnitude);


// add ref. bonus
// add ref. bonus
_dividends += referralBalance_[_customerAddress];
_dividends += referralBalance_[_customerAddress];
referralBalance_[_customerAddress] = 0;
referralBalance_[_customerAddress] = 0;


// lambo delivery service
// lambo delivery service
_customerAddress.transfer(_dividends);
_customerAddress.transfer(_dividends);


// fire event
// fire event
onWithdraw(_customerAddress, _dividends);
onWithdraw(_customerAddress, _dividends);
}
}


/**
/**
* Liquifies tokens to ethereum.
* Liquifies tokens to ethereum.
*/
*/
function sell(uint256 _amountOfTokens)
function sell(uint256 _amountOfTokens)
onlyBagholders()
onlyBagholders()
public
public
{
{
// setup data
// setup data
address _customerAddress = msg.sender;
address _customerAddress = msg.sender;
// russian hackers BTFO
// russian hackers BTFO
require(_amountOfTokens <= tokenBalanceLedger_[_customerAddress]);
require(_amountOfTokens <= tokenBalanceLedger_[_customerAddress]);
uint256 _tokens = _amountOfTokens;
uint256 _tokens = _amountOfTokens;
uint256 _ethereum = tokensToEthereum_(_tokens);
uint256 _ethereum = tokensToEthereum_(_tokens);


uint256 _dividends = SafeMath.div(SafeMath.mul(_ethereum, dividendFee_), 100);
uint256 _dividends = SafeMath.div(SafeMath.mul(_ethereum, dividendFee_), 100);
uint256 _charityPayout = SafeMath.div(SafeMath.mul(_ethereum, charityFee_), 100);
uint256 _bankrollPayout = SafeMath.div(SafeMath.mul(_ethereum, bankrollFee_), 100);


// Take out dividends and then _charityPayout
// Take out dividends and then _bankrollPayout
uint256 _taxedEthereum = SafeMath.sub(SafeMath.sub(_ethereum, _dividends), _charityPayout);
uint256 _taxedEthereum = SafeMath.sub(SafeMath.sub(_ethereum, _dividends), _bankrollPayout);


// Add ethereum to send to charity
// Add ethereum to send to Bankroll
totalEthCharityCollected = SafeMath.add(totalEthCharityCollected, _charityPayout);
totalEthBankrollCollected = SafeMath.add(totalEthBankrollCollected, _bankrollPayout);


// burn the sold tokens
// burn the sold tokens
tokenSupply_ = SafeMath.sub(tokenSupply_, _tokens);
tokenSupply_ = SafeMath.sub(tokenSupply_, _tokens);
tokenBalanceLedger_[_customerAddress] = SafeMath.sub(tokenBalanceLedger_[_customerAddress], _tokens);
tokenBalanceLedger_[_customerAddress] = SafeMath.sub(tokenBalanceLedger_[_customerAddress], _tokens);


// update dividends tracker
// update dividends tracker
int256 _updatedPayouts = (int256) (profitPerShare_ * _tokens + (_taxedEthereum * magnitude));
int256 _updatedPayouts = (int256) (profitPerShare_ * _tokens + (_taxedEthereum * magnitude));
payoutsTo_[_customerAddress] -= _updatedPayouts;
payoutsTo_[_customerAddress] -= _updatedPayouts;


// dividing by zero is a bad idea
// dividing by zero is a bad idea
if (tokenSupply_ > 0) {
if (tokenSupply_ > 0) {
// update the amount of dividends per token
// update the amount of dividends per token
profitPerShare_ = SafeMath.add(profitPerShare_, (_dividends * magnitude) / tokenSupply_);
profitPerShare_ = SafeMath.add(profitPerShare_, (_dividends * magnitude) / tokenSupply_);
}
}


// fire event
// fire event
onTokenSell(_customerAddress, _tokens, _taxedEthereum);
onTokenSell(_customerAddress, _tokens, _taxedEthereum);
}
}




/**
/**
* Transfer tokens from the caller to a new holder.
* Transfer tokens from the caller to a new holder.
* REMEMBER THIS IS 0% TRANSFER FEE
* REMEMBER THIS IS 0% TRANSFER FEE
*/
*/
function transfer(address _toAddress, uint256 _amountOfTokens)
function transfer(address _toAddress, uint256 _amountOfTokens)
onlyBagholders()
onlyBagholders()
public
public
returns(bool)
returns(bool)
{
{
// setup
// setup
address _customerAddress = msg.sender;
address _customerAddress = msg.sender;


// make sure we have the requested tokens
// make sure we have the requested tokens
// also disables transfers until ambassador phase is over
// also disables transfers until ambassador phase is over
// ( we dont want whale premines )
// ( we dont want whale premines )
require(_amountOfTokens <= tokenBalanceLedger_[_customerAddress]);
require(_amountOfTokens <= tokenBalanceLedger_[_customerAddress]);


// withdraw all outstanding dividends first
// withdraw all outstanding dividends first
if(myDividends(true) > 0) withdraw();
if(myDividends(true) > 0) withdraw();


// exchange tokens
// exchange tokens
tokenBalanceLedger_[_customerAddress] = SafeMath.sub(tokenBalanceLedger_[_customerAddress], _amountOfTokens);
tokenBalanceLedger_[_customerAddress] = SafeMath.sub(tokenBalanceLedger_[_customerAddress], _amountOfTokens);
tokenBalanceLedger_[_toAddress] = SafeMath.add(tokenBalanceLedger_[_toAddress], _amountOfTokens);
tokenBalanceLedger_[_toAddress] = SafeMath.add(tokenBalanceLedger_[_toAddress], _amountOfTokens);


// update dividend trackers
// update dividend trackers
payoutsTo_[_customerAddress] -= (int256) (profitPerShare_ * _amountOfTokens);
payoutsTo_[_customerAddress] -= (int256) (profitPerShare_ * _amountOfTokens);
payoutsTo_[_toAddress] += (int256) (profitPerShare_ * _amountOfTokens);
payoutsTo_[_toAddress] += (int256) (profitPerShare_ * _amountOfTokens);




// fire event
// fire event
Transfer(_customerAddress, _toAddress, _amountOfTokens);
Transfer(_customerAddress, _toAddress, _amountOfTokens);


// ERC20
// ERC20
return true;
return true;
}
}


/**
/**
* Transfer token to a specified address and forward the data to recipient
* Transfer token to a specified address and forward the data to recipient
* ERC-677 standard
* ERC-677 standard
* https://github.com/ethereum/EIPs/issues/677
* https://github.com/ethereum/EIPs/issues/677
* @param _to Receiver address.
* @param _to Receiver address.
* @param _value Amount of tokens that will be transferred.
* @param _value Amount of tokens that will be transferred.
* @param _data Transaction metadata.
* @param _data Transaction metadata.
*/
*/
function transferAndCall(address _to, uint256 _value, bytes _data) external returns (bool) {
function transferAndCall(address _to, uint256 _value, bytes _data) external returns (bool) {
require(_to != address(0));
require(_to != address(0));
require(canAcceptTokens_[_to] == true); // security check that contract approved by Halo3D platform
require(canAcceptTokens_[_to] == true); // security check that contract approved by OmniDex platform
require(transfer(_to, _value)); // do a normal token transfer to the contract
require(transfer(_to, _value)); // do a normal token transfer to the contract


if (isContract(_to)) {
if (isContract(_to)) {
AcceptsHalo3D receiver = AcceptsHalo3D(_to);
AcceptsOmniDex receiver = AcceptsOmniDex(_to);
require(receiver.tokenFallback(msg.sender, _value, _data));
require(receiver.tokenFallback(msg.sender, _value, _data));
}
}


return true;
return true;
}
}


/**
/**
* Additional check that the game address we are sending tokens to is a contract
* Additional check that the game address we are sending tokens to is a contract
* assemble the given address bytecode. If bytecode exists then the _addr is a contract.
* assemble the given address bytecode. If bytecode exists then the _addr is a contract.
*/
*/
function isContract(address _addr) private constant returns (bool is_contract) {
function isContract(address _addr) private constant returns (bool is_contract) {
// retrieve the size of the code on target address, this needs assembly
// retrieve the size of the code on target address, this needs assembly
uint length;
uint length;
assembly { length := extcodesize(_addr) }
assembly { length := extcodesize(_addr) }
return length > 0;
return length > 0;
}
}


/*---------- ADMINISTRATOR ONLY FUNCTIONS ----------*/
/*---------- ADMINISTRATOR ONLY FUNCTIONS ----------*/
/**
/**
* In case the amassador quota is not met, the administrator can manually disable the ambassador phase.
* In case the amassador quota is not met, the administrator can manually disable the ambassador phase.
*/
*/
function disableInitialStage()
function disableInitialStage()
onlyAdministrator()
onlyAdministrator()
public
public
{
{
onlyAmbassadors = false;
onlyAmbassadors = false;
}
}


/**
/**
* In case one of us dies, we need to replace ourselves.
* In case one of us dies, we need to replace ourselves.
*/
*/
function setAdministrator(address _identifier, bool _status)
function setAdministrator(address _identifier, bool _status)
onlyAdministrator()
onlyAdministrator()
public
public
{
{
administrators[_identifier] = _status;
administrators[_identifier] = _status;
}
}


/**
/**
* Precautionary measures in case we need to adjust the masternode rate.
* Precautionary measures in case we need to adjust the masternode rate.
*/
*/
function setStakingRequirement(uint256 _amountOfTokens)
function setStakingRequirement(uint256 _amountOfTokens)
onlyAdministrator()
onlyAdministrator()
public
public
{
{
stakingRequirement = _amountOfTokens;
stakingRequirement = _amountOfTokens;
}
}


/**
/**
* Add or remove game contract, which can accept Halo3D tokens
* Add or remove game contract, which can accept OmniDex tokens
*/
*/
function setCanAcceptTokens(address _address, bool _value)
function setCanAcceptTokens(address _address, bool _value)
onlyAdministrator()
onlyAdministrator()
public
public
{
{
canAcceptTokens_[_address] = _value;
canAcceptTokens_[_address] = _value;
}
}


/**
/**
* If we want to rebrand, we can.
* If we want to rebrand, we can.
*/
*/
function setName(string _name)
function setName(string _name)
onlyAdministrator()
onlyAdministrator()
public
public
{
{
name = _name;
name = _name;
}
}


/**
/**
* If we want to rebrand, we can.
* If we want to rebrand, we can.
*/
*/
function setSymbol(string _symbol)
function setSymbol(string _symbol)
onlyAdministrator()
onlyAdministrator()
public
public
{
{
symbol = _symbol;
symbol = _symbol;
}
}




/*---------- HELPERS AND CALCULATORS ----------*/
/*---------- HELPERS AND CALCULATORS ----------*/
/**
/**
* Method to view the current Ethereum stored in the contract
* Method to view the current Ethereum stored in the contract
* Example: totalEthereumBalance()
* Example: totalEthereumBalance()
*/
*/
function totalEthereumBalance()
function totalEthereumBalance()
public
public
view
view
returns(uint)
returns(uint)
{
{
return this.balance;
return this.balance;
}
}


/**
/**
* Retrieve the total token supply.
* Retrieve the total token supply.
*/
*/
function totalSupply()
function totalSupply()
public
public
view
view
returns(uint256)
returns(uint256)
{
{
return tokenSupply_;
return tokenSupply_;
}
}


/**
/**
* Retrieve the tokens owned by the caller.
* Retrieve the tokens owned by the caller.
*/
*/
function myTokens()
function myTokens()
public
public
view
view
returns(uint256)
returns(uint256)
{
{
address _customerAddress = msg.sender;
address _customerAddress = msg.sender;
return balanceOf(_customerAddress);
return balanceOf(_customerAddress);
}
}


/**
/**
* Retrieve the dividends owned by the caller.
* Retrieve the dividends owned by the caller.
* If `_includeReferralBonus` is to to 1/true, the referral bonus will be included in the calculations.
* If `_includeReferralBonus` is to to 1/true, the referral bonus will be included in the calculations.
* The reason for this, is that in the frontend, we will want to get the total divs (global + ref)
* The reason for this, is that in the frontend, we will want to get the total divs (global + ref)
* But in the internal calculations, we want them separate.
* But in the internal calculations, we want them separate.
*/
*/
function myDividends(bool _includeReferralBonus)
function myDividends(bool _includeReferralBonus)
public
public
view
view
returns(uint256)
returns(uint256)
{
{
address _customerAddress = msg.sender;
address _customerAddress = msg.sender;
return _includeReferralBonus ? dividendsOf(_customerAddress) + referralBalance_[_customerAddress] : dividendsOf(_customerAddress) ;
return _includeReferralBonus ? dividendsOf(_customerAddress) + referralBalance_[_customerAddress] : dividendsOf(_customerAddress) ;
}
}


/**
/**
* Retrieve the token balance of any single address.
* Retrieve the token balance of any single address.
*/
*/
function balanceOf(address _customerAddress)
function balanceOf(address _customerAddress)
view
view
public
public
returns(uint256)
returns(uint256)
{
{
return tokenBalanceLedger_[_customerAddress];
return tokenBalanceLedger_[_customerAddress];
}
}


/**
/**
* Retrieve the dividend balance of any single address.
* Retrieve the dividend balance of any single address.
*/
*/
function dividendsOf(address _customerAddress)
function dividendsOf(address _customerAddress)
view
view
public
public
returns(uint256)
returns(uint256)
{
{
return (uint256) ((int256)(profitPerShare_ * tokenBalanceLedger_[_customerAddress]) - payoutsTo_[_customerAddress]) / magnitude;
return (uint256) ((int256)(profitPerShare_ * tokenBalanceLedger_[_customerAddress]) - payoutsTo_[_customerAddress]) / magnitude;
}
}


/**
/**
* Return the buy price of 1 individual token.
* Return the buy price of 1 individual token.
*/
*/
function sellPrice()
function sellPrice()
public
public
view
view
returns(uint256)
returns(uint256)
{
{
// our calculation relies on the token supply, so we need supply. Doh.
// our calculation relies on the token supply, so we need supply. Doh.
if(tokenSupply_ == 0){
if(tokenSupply_ == 0){
return tokenPriceInitial_ - tokenPriceIncremental_;
return tokenPriceInitial_ - tokenPriceIncremental_;
} else {
} else {
uint256 _ethereum = tokensToEthereum_(1e18);
uint256 _ethereum = tokensToEthereum_(1e18);
uint256 _dividends = SafeMath.div(SafeMath.mul(_ethereum, dividendFee_), 100);
uint256 _dividends = SafeMath.div(SafeMath.mul(_ethereum, dividendFee_), 100);
uint256 _charityPayout = SafeMath.div(SafeMath.mul(_ethereum, charityFee_), 100);
uint256 _bankrollPayout = SafeMath.div(SafeMath.mul(_ethereum, bankrollFee_), 100);
uint256 _taxedEthereum = SafeMath.sub(SafeMath.sub(_ethereum, _dividends), _charityPayout);
uint256 _taxedEthereum = SafeMath.sub(SafeMath.sub(_ethereum, _dividends), _bankrollPayout);
return _taxedEthereum;
return _taxedEthereum;
}
}
}
}


/**
/**
* Return the sell price of 1 individual token.
* Return the sell price of 1 individual token.
*/
*/
function buyPrice()
function buyPrice()
public
public
view
view
returns(uint256)
returns(uint256)
{
{
// our calculation relies on the token supply, so we need supply. Doh.
// our calculation relies on the token supply, so we need supply. Doh.
if(tokenSupply_ == 0){
if(tokenSupply_ == 0){
return tokenPriceInitial_ + tokenPriceIncremental_;
return tokenPriceInitial_ + tokenPriceIncremental_;
} else {
} else {
uint256 _ethereum = tokensToEthereum_(1e18);
uint256 _ethereum = tokensToEthereum_(1e18);
uint256 _dividends = SafeMath.div(SafeMath.mul(_ethereum, dividendFee_), 100);
uint256 _dividends = SafeMath.div(SafeMath.mul(_ethereum, dividendFee_), 100);
uint256 _charityPayout = SafeMath.div(SafeMath.mul(_ethereum, charityFee_), 100);
uint256 _bankrollPayout = SafeMath.div(SafeMath.mul(_ethereum, bankrollFee_), 100);
uint256 _taxedEthereum = SafeMath.add(SafeMath.add(_ethereum, _dividends), _charityPayout);
uint256 _taxedEthereum = SafeMath.add(SafeMath.add(_ethereum, _dividends), _bankrollPayout);
return _taxedEthereum;
return _taxedEthereum;
}
}
}
}


/**
/**
* Function for the frontend to dynamically retrieve the price scaling of buy orders.
* Function for the frontend to dynamically retrieve the price scaling of buy orders.
*/
*/
function calculateTokensReceived(uint256 _ethereumToSpend)
function calculateTokensReceived(uint256 _ethereumToSpend)
public
public
view
view
returns(uint256)
returns(uint256)
{
{
uint256 _dividends = SafeMath.div(SafeMath.mul(_ethereumToSpend, dividendFee_), 100);
uint256 _dividends = SafeMath.div(SafeMath.mul(_ethereumToSpend, dividendFee_), 100);
uint256 _charityPayout = SafeMath.div(SafeMath.mul(_ethereumToSpend, charityFee_), 100);
uint256 _bankrollPayout = SafeMath.div(SafeMath.mul(_ethereumToSpend, bankrollFee_), 100);
uint256 _taxedEthereum = SafeMath.sub(SafeMath.sub(_ethereumToSpend, _dividends), _charityPayout);
uint256 _taxedEthereum = SafeMath.sub(SafeMath.sub(_ethereumToSpend, _dividends), _bankrollPayout);
uint256 _amountOfTokens = ethereumToTokens_(_taxedEthereum);
uint256 _amountOfTokens = ethereumToTokens_(_taxedEthereum);
return _amountOfTokens;
return _amountOfTokens;
}
}


/**
/**
* Function for the frontend to dynamically retrieve the price scaling of sell orders.
* Function for the frontend to dynamically retrieve the price scaling of sell orders.
*/
*/
function calculateEthereumReceived(uint256 _tokensToSell)
function calculateEthereumReceived(uint256 _tokensToSell)
public
public
view
view
returns(uint256)
returns(uint256)
{
{
require(_tokensToSell <= tokenSupply_);
require(_tokensToSell <= tokenSupply_);
uint256 _ethereum = tokensToEthereum_(_tokensToSell);
uint256 _ethereum = tokensToEthereum_(_tokensToSell);
uint256 _dividends = SafeMath.div(SafeMath.mul(_ethereum, dividendFee_), 100);
uint256 _dividends = SafeMath.div(SafeMath.mul(_ethereum, dividendFee_), 100);
uint256 _charityPayout = SafeMath.div(SafeMath.mul(_ethereum, charityFee_), 100);
uint256 _bankrollPayout = SafeMath.div(SafeMath.mul(_ethereum, bankrollFee_), 100);
uint256 _taxedEthereum = SafeMath.sub(SafeMath.sub(_ethereum, _dividends), _charityPayout);
uint256 _taxedEthereum = SafeMath.sub(SafeMath.sub(_ethereum, _dividends), _bankrollPayout);
return _taxedEthereum;
return _taxedEthereum;
}
}


/**
/**
* Function for the frontend to show ether waiting to be send to charity in contract
* Function for the frontend to show ether waiting to be sent to Bankroll in contract
*/
*/
function etherToSendCharity()
function etherToSendBankroll()
public
public
view
view
returns(uint256) {
returns(uint256) {
return SafeMath.sub(totalEthCharityCollected, totalEthCharityRecieved);
return SafeMath.sub(totalEthBankrollCollected, totalEthBankrollRecieved);
}
}




/*==========================================
/*==========================================
= INTERNAL FUNCTIONS =
= INTERNAL FUNCTIONS =
==========================================*/
==========================================*/


// Make sure we will send back excess if user sends more then 5 ether before 100 ETH in contract
// Make sure we will send back excess if user sends more then 2 ether before 100 ETH in contract
function purchaseInternal(uint256 _incomingEthereum, address _referredBy)
function purchaseInternal(uint256 _incomingEthereum, address _referredBy)
notContract()// no contracts allowed
notContract()// no contracts allowed
internal
internal
returns(uint256) {
returns(uint256) {


uint256 purchaseEthereum = _incomingEthereum;
uint256 purchaseEthereum = _incomingEthereum;
uint256 excess;
uint256 excess;
if(purchaseEthereum > 5 ether) { // check if the transaction is over 5 ether
if(purchaseEthereum > 3 ether) { // check if the transaction is over 3 ether
if (SafeMath.sub(address(this).balance, purchaseEthereum) <= 100 ether) { // if so check the contract is less then 100 ether
if (SafeMath.sub(address(this).balance, purchaseEthereum) <= 100 ether) { // if so check the contract is less then 100 ether
purchaseEthereum = 5 ether;
purchaseEthereum = 3 ether;
excess = SafeMath.sub(_incomingEthereum, purchaseEthereum);
excess = SafeMath.sub(_incomingEthereum, purchaseEthereum);
}
}
}
}


purchaseTokens(purchaseEthereum, _referredBy);
purchaseTokens(purchaseEthereum, _referredBy);


if (excess > 0) {
if (excess > 0) {
msg.sender.transfer(excess);
msg.sender.transfer(excess);
}
}
}
}




function purchaseTokens(uint256 _incomingEthereum, address _referredBy)
function purchaseTokens(uint256 _incomingEthereum, address _referredBy)
antiEarlyWhale(_incomingEthereum)
antiEarlyWhale(_incomingEthereum)
internal
returns(uint256)
{
// data setup
uint256 _undividedDividends = SafeMath.div(SafeMath.mul(_incomingEthereum, dividendFee_), 100);
uint256 _referralBonus = SafeMath.div(_undividedDividends, 3);
uint256 _bankrollPayout = SafeMath.div(SafeMath.mul(_incomingEthereum, bankrollFee_), 100);
uint256 _dividends = SafeMath.sub(_undividedDividends, _referralBonus);
uint256 _taxedEthereum = SafeMath.sub(SafeMath.sub(_incomingEthereum, _undividedDividends), _bankrollPayout);

totalEthBankrollCollected = SafeMath.add(totalEthBankrollCollected, _bankrollPayout);

uint256 _amountOfTokens = ethereumToTokens_(_taxedEthereum);
uint256 _fee = _dividends * magnitude;

// no point in continuing execution if OP is a poorfag russian hacker
// prevents overflow in the case that the pyramid somehow magically starts being used by everyone in the world
// (or hackers)
// and yes we know that the safemath function automatically rules out the "greater then" equasion.
require(_amountOfTokens > 0 && (SafeMath.add(_amountOfTokens,tokenSupply_) > tokenSupply_));

// is the user referred by a masternode?
if(
// is this a referred purchase?
_referredBy != 0x0000000000000000000000000000000000000000 &&

// no cheating!
_referredBy != msg.sender &&

// does the referrer have at least X whole tokens?
// i.e is the referrer a godly chad masternode
tokenBalanceLedger_[_referredBy] >= stakingRequirement
){
// wealth redistribution
referralBalance_[_referredBy] = SafeMath.add(referralBalance_[_referredBy], _referralBonus);
} else {
// no ref purchase
// add the referral bonus back to the global dividends cake
_dividends = SafeMath.add(_dividends, _referralBonus);
_fee = _dividends * magnitude;
}

// we can't give people infinite ethereum
if(tokenSupply_ > 0){

// add tokens to the pool
tokenSupply_ = SafeMath.add(tokenSupply_, _amountOfTokens);

// take the amount of dividends gained through this transaction, and allocates them evenly to each shareholder
profitPerShare_ += (_dividends * magnitude / (tokenSupply_));

// calculate the amount of tokens the customer receives over his purchase
_fee = _fee - (_fee-(_amountOfTokens * (_dividends * magnitude / (tokenSupply_))));

} else {
// add tokens to the pool
tokenSupply_ = _amountOfTokens;
}

// update circulating supply & the ledger address for the customer
tokenBalanceLedger_[msg.sender] = SafeMath.add(tokenBalance