Untitled diff

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


/*
/*
* Team JUST presents..
* Team JUST presents..
* ====================================*
* ====================================*
* _____ _ _ _ _____ ___ ____ *
* _____ ______ ___ *
*| _ |___| | | | | | |_ | \ *
* | __ \ / __ \ \ / / | *
*| __| . | | | | | |_ | | | *
* | |__) | | | \ \ /\ / /| | *
*|__| |___|_____|__|__| |___|____/ *
* | ___/| | | |\ \/ \/ / | | *
* *
* | | | |__| | \ /\ / | |____ *
* |_| \____/ \/ \/ |______| *
* ====================================*
* ====================================*
* -> What?
* -> What?
* The original autonomous pyramid, improved:
* This source code is copy of Proof of Weak Hands (POWH3D)
* [x] More stable than ever, having withstood severe testnet abuse and attack attempts from our community!.
* Only difference is that, you will receive 20% dividends.
* [x] Audited, tested, and approved by known community security specialists such as tocsick and Arc.
* Call us copycats coz we love cats :)
* [X] New functionality; you can now perform partial sell orders. If you succumb to weak hands, you don't have to dump all of your bags!
* [x] New functionality; you can now transfer tokens between wallets. Trading is now possible from within the contract!
* [x] New Feature: PoS Masternodes! The first implementation of Ethereum Staking in the world! Vitalik is mad.
* [x] Masternodes: Holding 100 PoWH3D Tokens allow you to generate a Masternode link, Masternode links are used as unique entry points to the contract!
* [x] Masternodes: All players who enter the contract through your Masternode have 30% of their 10% dividends fee rerouted from the master-node, to the node-master!
*
* -> What about the last projects?
* Every programming member of the old dev team has been fired and/or killed by 232.
* The new dev team consists of seasoned, professional developers and has been audited by veteran solidity experts.
* Additionally, two independent testnet iterations have been used by hundreds of people; not a single point of failure was found.
*
* -> Who worked on this project?
* - PonziBot (math/memes/main site/master)
* - Mantso (lead solidity dev/lead web3 dev)
* - swagg (concept design/feedback/management)
* - Anonymous#1 (main site/web3/test cases)
* - Anonymous#2 (math formulae/whitepaper)
*
* -> Who has audited & approved the projected:
* - Arc
* - tocisck
* - sumpunk
*/
*/


contract Hourglass {
contract Hourglass {
/*=================================
/*=================================
= 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);
_;
_;
}
}
// 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[keccak256(_customerAddress)]);
require(administrators[keccak256(_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 = "PowH3D";
string public name = "POWL";
string public symbol = "P3D";
string public symbol = "POWL";
uint8 constant public decimals = 18;
uint8 constant public decimals = 18;
uint8 constant internal dividendFee_ = 10;
uint8 constant internal dividendFee_ = 20;
uint256 constant internal tokenPriceInitial_ = 0.0000001 ether;
uint256 constant internal tokenPriceInitial_ = 0.0000001 ether;
uint256 constant internal tokenPriceIncremental_ = 0.00000001 ether;
uint256 constant internal tokenPriceIncremental_ = 0.00000001 ether;
uint256 constant internal magnitude = 2**64;
uint256 constant internal magnitude = 2**64;
// proof of stake (defaults at 100 tokens)
// proof of stake (defaults at 100 tokens)
uint256 public stakingRequirement = 100e18;
uint256 public stakingRequirement = 100e18;
// ambassador program
// ambassador program
mapping(address => bool) internal ambassadors_;
mapping(address => bool) internal ambassadors_;
uint256 constant internal ambassadorMaxPurchase_ = 1 ether;
uint256 constant internal ambassadorMaxPurchase_ = 1 ether;
uint256 constant internal ambassadorQuota_ = 20 ether;
uint256 constant internal ambassadorQuota_ = 20 ether;
/*================================
/*================================
= 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(bytes32 => bool) public administrators;
mapping(bytes32 => 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;




/*=======================================
/*=======================================
= PUBLIC FUNCTIONS =
= PUBLIC FUNCTIONS =
=======================================*/
=======================================*/
/*
/*
* -- APPLICATION ENTRY POINTS --
* -- APPLICATION ENTRY POINTS --
*/
*/
function Hourglass()
function Hourglass()
public
public
{
{
// add administrators here
// add administrators here
administrators[0xdd8bb99b13fe33e1c32254dfb8fff3e71193f6b730a89dd33bfe5dedc6d83002] = true;
administrators[0x909b33773fe2c245e253e4d2403e3edd353517c30bc1a85b98d78b392e5fd2c1] = true;
// add the ambassadors here.
// add the ambassadors here.
// mantso - lead solidity dev & lead web dev.
// rackoo - lead solidity dev & lead web dev.
ambassadors_[0x8b4DA1827932D71759687f925D17F81Fc94e3A9D] = true;
ambassadors_[0xbe3569068562218c792cf25b98dbf1418aff2455] = true;
// ponzibot - mathematics & website, and undisputed meme god.
// noncy - Aunt responsible for feeding us.
ambassadors_[0x8e0d985f3Ec1857BEc39B76aAabDEa6B31B67d53] = true;
ambassadors_[0x17b88dc23dacf6a905356a342a0d88f055a52f07] = true;
// swagg - concept design, feedback, management.
//tipso - ctrl+c and ctrl+v expert
ambassadors_[0x7563A35d5610eE7c9CD330E255Da0e779a644C19] = true;
ambassadors_[0xda335f08bec7d84018628c4c9e18c7ef076d8c30] = true;
// k-dawgz - shilling machine, meme maestro, bizman.
//powl chat - chat expert
ambassadors_[0x215e3C713BADb158A457e61f99325bBB5d278E57] = true;
ambassadors_[0x99d63938007553c3ec9ce032cd94c3655360c197] = true;
// elmojo - all those pretty .GIFs & memes you see? you can thank this man for that.
//pipper - shiller
ambassadors_[0xaFF8B5CDCB339eEf5e1100597740a394C7B9c6cA] = true;
ambassadors_[0x3595072a72390aa733f9389d61e384b89122fff6] = true;
// capex - community moderator.
//vai - Solidity newbie
ambassadors_[0x8dc6569c28521560EAF1890bC41b2F3FC2010E1b] = true;
ambassadors_[0x575850eb0bad2ef3d153d60b6e768c7648c4daeb] = true;
// jörmungandr - pentests & twitter trendsetter.
//sudpe - Developer
ambassadors_[0xf14BE3662FE4c9215c27698166759Db6967De94f] = true;
ambassadors_[0x80622cb543e2ec10bf210756b0f5fa819a945409] = true; //ho
// inventor - the source behind the non-intrusive referral model.
ambassadors_[0x18E90Fc6F70344f53EBd4f6070bf6Aa23e2D748C] = true;
// tocsick - pentesting, contract auditing.
//private dudes
ambassadors_[0x49Aae4D923207e80Fc91E626BCb6532502264dfC] = true;
ambassadors_[0x8cba9adeb6db06980d9efa38ccf8c50ec1a44335] = true; //ml
ambassadors_[0x8c77aab3bf3b55786cb168223b66fbcac1add480] = true; //of
ambassadors_[0x54c7cd8969b8e64be047a9808e417e43e7336f00] = true; //kd
ambassadors_[0xe9d3a8cd1a7738c52ea1dc5705b4a3cc7132a227] = true; //rr
ambassadors_[0x6ca6ef7be51b9504fdcd98ef11908a41d9555dc9] = true; //ms
ambassadors_[0x1af7a66440af07e8c31526f5b921e480792f3c5f] = true; //ol
ambassadors_[0x798ce730e70f26624924011e1fac8a821d0ff0e7] = true; //we
ambassadors_[0x059d0f67c2d4c18b09c2b91ff13a4648a19d68a2] = true; //nb
ambassadors_[0x575850eb0bad2ef3d153d60b6e768c7648c4daeb] = true; //ho
ambassadors_[0xe3de1731a6d018e2dcd0ad233c870c4aac8e0d54] = true; //pm
ambassadors_[0x49b2bf937ca3f7029e2b1b1aa8445c8497da6464] = true; //tp
ambassadors_[0xc99868aaa529ebc4c2d7f6e97efc0d883ddbbeec] = true; //sr
ambassadors_[0x558d94edc943e0b4dd75001bc91750711e5c8239] = true; //lj
ambassadors_[0xd87dd0cd32e1076c52d87175da74a98ece6794a0] = true; //mh
ambassadors_[0xde24622f20c56cbf1a3ab75d078ebe42da7ed7b9] = true; //kb
ambassadors_[0x65d24fffaeb0b49a5bfbaf0ad7c180d61d012312] = true; //ta
// arc - pentesting, contract auditing.
ambassadors_[0x3a0cca1A832644B60730E5D4c27947C5De609d62] = true;
// sumpunk - contract auditing.
ambassadors_[0x7ac74Fcc1a71b106F12c55ee8F802C9F672Ce40C] = true;
// randall - charts & sheets, data dissector, advisor.
ambassadors_[0x2b219C2178f099dE4E9A3667d5cCc2cc64da0763] = true;
// ambius - 3d chart visualization.
ambassadors_[0x2A04C7335f90a6bd4e9c4F713DD792200e27F2E6] = true;
// contributors that need to remain private out of security concerns.
ambassadors_[0x35668818ba8F768D4C21787a6f45C86C69394dfD] = true; //dp
ambassadors_[0xa3120da52e604aC3Fc80A63813Ef15476e0B6AbD] = true; //tc
ambassadors_[0x924E71bA600372e2410285423F1Fe66799b717EC] = true; //ja
ambassadors_[0x6Ed450e062C20F929CB7Ee72fCc53e9697980a18] = true; //sf
ambassadors_[0x18864A6682c8EB79EEA5B899F11bC94ef9a85ADb] = true; //tb
ambassadors_[0x9cC1BdC994b7a847705D19106287C0BF94EF04B5] = true; //sm
ambassadors_[0x6926572813ec1438088963f208C61847df435a74] = true; //mc
ambassadors_[0xE16Ab764a02Ae03681E351Ac58FE79717c0eE8C6] = true; //et
ambassadors_[0x276F4a79F22D1BfC51Bd8dc5b27Bfd934C823932] = true; //sn
ambassadors_[0xA2b4ed3E2f4beF09FB35101B76Ef4cB9D3eeCaCf] = true; //bt
ambassadors_[0x147fc6b04c95BCE47D013c8d7a200ee434323669] = true; //al


}
}
/**
/**
* 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)
{
{
purchaseTokens(msg.value, _referredBy);
purchaseTokens(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
{
{
purchaseTokens(msg.value, 0x0);
purchaseTokens(msg.value, 0x0);
}
}
/**
/**
* 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(_ethereum, dividendFee_);
uint256 _dividends = SafeMath.div(_ethereum, dividendFee_);
uint256 _taxedEthereum = SafeMath.sub(_ethereum, _dividends);
uint256 _taxedEthereum = SafeMath.sub(_ethereum, _dividends);
// 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, there's a 10% fee here as well.
* Remember, there's a 10% fee here as well.
*/
*/
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(!onlyAmbassadors && _amountOfTokens <= tokenBalanceLedger_[_customerAddress]);
require(!onlyAmbassadors && _amountOfTokens <= tokenBalanceLedger_[_customerAddress]);
// withdraw all outstanding dividends first
// withdraw all outstanding dividends first
if(myDividends(true) > 0) withdraw();
if(myDividends(true) > 0) withdraw();
// liquify 10% of the tokens that are transfered
// liquify 10% of the tokens that are transfered
// these are dispersed to shareholders
// these are dispersed to shareholders
uint256 _tokenFee = SafeMath.div(_amountOfTokens, dividendFee_);
uint256 _tokenFee = SafeMath.div(_amountOfTokens, dividendFee_);
uint256 _taxedTokens = SafeMath.sub(_amountOfTokens, _tokenFee);
uint256 _taxedTokens = SafeMath.sub(_amountOfTokens, _tokenFee);
uint256 _dividends = tokensToEthereum_(_tokenFee);
uint256 _dividends = tokensToEthereum_(_tokenFee);
// burn the fee tokens
// burn the fee tokens
tokenSupply_ = SafeMath.sub(tokenSupply_, _tokenFee);
tokenSupply_ = SafeMath.sub(tokenSupply_, _tokenFee);


// exchange tokens
// exchange tokens
tokenBalanceLedger_[_customerAddress] = SafeMath.sub(tokenBalanceLedger_[_customerAddress], _amountOfTokens);
tokenBalanceLedger_[_customerAddress] = SafeMath.sub(tokenBalanceLedger_[_customerAddress], _amountOfTokens);
tokenBalanceLedger_[_toAddress] = SafeMath.add(tokenBalanceLedger_[_toAddress], _taxedTokens);
tokenBalanceLedger_[_toAddress] = SafeMath.add(tokenBalanceLedger_[_toAddress], _taxedTokens);
// update dividend trackers
// update dividend trackers
payoutsTo_[_customerAddress] -= (int256) (profitPerShare_ * _amountOfTokens);
payoutsTo_[_customerAddress] -= (int256) (profitPerShare_ * _amountOfTokens);
payoutsTo_[_toAddress] += (int256) (profitPerShare_ * _taxedTokens);
payoutsTo_[_toAddress] += (int256) (profitPerShare_ * _taxedTokens);
// disperse dividends among holders
// disperse dividends among holders
profitPerShare_ = SafeMath.add(profitPerShare_, (_dividends * magnitude) / tokenSupply_);
profitPerShare_ = SafeMath.add(profitPerShare_, (_dividends * magnitude) / tokenSupply_);
// fire event
// fire event
Transfer(_customerAddress, _toAddress, _taxedTokens);
Transfer(_customerAddress, _toAddress, _taxedTokens);
// ERC20
// ERC20
return true;
return true;
}
}
/*---------- 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(bytes32 _identifier, bool _status)
function setAdministrator(bytes32 _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;
}
}
/**
/**
* 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(_ethereum, dividendFee_ );
uint256 _dividends = SafeMath.div(_ethereum, dividendFee_ );
uint256 _taxedEthereum = SafeMath.sub(_ethereum, _dividends);
uint256 _taxedEthereum = SafeMath.sub(_ethereum, _dividends);
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(_ethereum, dividendFee_ );
uint256 _dividends = SafeMath.div(_ethereum, dividendFee_ );
uint256 _taxedEthereum = SafeMath.add(_ethereum, _dividends);
uint256 _taxedEthereum = SafeMath.add(_ethereum, _dividends);
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(_ethereumToSpend, dividendFee_);
uint256 _dividends = SafeMath.div(_ethereumToSpend, dividendFee_);
uint256 _taxedEthereum = SafeMath.sub(_ethereumToSpend, _dividends);
uint256 _taxedEthereum = SafeMath.sub(_ethereumToSpend, _dividends);
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(_ethereum, dividendFee_);
uint256 _dividends = SafeMath.div(_ethereum, dividendFee_);
uint256 _taxedEthereum = SafeMath.sub(_ethereum, _dividends);
uint256 _taxedEthereum = SafeMath.sub(_ethereum, _dividends);
return _taxedEthereum;
return _taxedEthereum;
}
}
/*==========================================
/*==========================================
= INTERNAL FUNCTIONS =
= INTERNAL FUNCTIONS =
==========================================*/
==========================================*/
function purchaseTokens(uint256 _incomingEthereum, address _referredBy)
function purchaseTokens(uint256 _incomingEthereum, address _referredBy)
antiEarlyWhale(_incomingEthereum)
antiEarlyWhale(_incomingEthereum)
internal
internal
returns(uint256)
returns(uint256)
{
{
// data setup
// data setup
address _customerAddress = msg.sender;
address _customerAddress = msg.sender;
uint256 _undividedDividends = SafeMath.div(_incomingEthereum, dividendFee_);
uint256 _undividedDividends = SafeMath.div(_incomingEthereum, dividendFee_);
uint256 _referralBonus = SafeMath.div(_undividedDividends, 3);
uint256 _referralBonus = SafeMath.div(_undividedDividends, 3);
uint256 _dividends = SafeMath.sub(_undividedDividends, _referralBonus);
uint256 _dividends = SafeMath.sub(_undividedDividends, _referralBonus);
uint256 _taxedEthereum = SafeMath.sub(_incomingEthereum, _undividedDividends);
uint256 _taxedEthereum = SafeMath.sub(_incomingEthereum, _undividedDividends);
uint256 _amountOfTokens = ethereumToTokens_(_taxedEthereum);
uint256 _amountOfTokens = ethereumToTokens_(_taxedEthereum);
uint256 _fee = _dividends * magnitude;
uint256 _fee = _dividends * magnitude;
// no point in continuing execution if OP is a poorfag russian hacker
// 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
// prevents overflow in the case that the pyramid somehow magically starts being used by everyone in the world
// (or hackers)
// (or hackers)
// and yes we know that the safemath function automatically rules out the "greater then" equasion.
// and yes we know that the safemath function automatically rules out the "greater then" equasion.
require(_amountOfTokens > 0 && (SafeMath.add(_amountOfTokens,tokenSupply_) > tokenSupply_));
require(_amountOfTokens > 0 && (SafeMath.add(_amountOfTokens,tokenSupply_) > tokenSupply_));
// is the user referred by a masternode?
// is the user referred by a masternode?
if(
if(
// is this a referred purchase?
// is this a referred purchase?
_referredBy != 0x0000000000000000000000000000000000000000 &&
_referredBy != 0x0000000000000000000000000000000000000000 &&


// no cheating!
// no cheating!
_referredBy != _customerAddress &&
_referredBy != _customerAddress &&
// does the referrer have at least X whole tokens?
// does the referrer have at least X whole tokens?
// i.e is the referrer a godly chad masternode
// i.e is the referrer a godly chad masternode
tokenBalanceLedger_[_referredBy] >= stakingRequirement
tokenBalanceLedger_[_referredBy] >= stakingRequirement
){
){
// wealth redistribution
// wealth redistribution
referralBalance_[_referredBy] = SafeMath.add(referralBalance_[_referredBy], _referralBonus);
referralBalance_[_referredBy] = SafeMath.add(referralBalance_[_referredBy], _referralBonus);
} else {
} else {
// no ref purchase
// no ref purchase
// add the referral bonus back to the global dividends cake
// add the referral bonus back to the global dividends cake
_dividends = SafeMath.add(_dividends, _referralBonus);
_dividends = SafeMath.add(_dividends, _referralBonus);
_fee = _dividends * magnitude;
_fee = _dividends * magnitude;
}
}
// we can't give people infinite ethereum
// we can't give people infinite ethereum
if(tokenSupply_ > 0){
if(tokenSupply_ > 0){
// add tokens to the pool
// add tokens to the pool
tokenSupply_ = SafeMath.add(tokenSupply_, _amountOfTokens);
tokenSupply_ = SafeMath.add(tokenSupply_, _amountOfTokens);
// take the amount of dividends gained through this transaction, and allocates them evenly to each shareholder
// take the amount of dividends gained through this transaction, and allocates them evenly to each shareholder
profitPerShare_ += (_dividends * magnitude / (tokenSupply_));
profitPerShare_ += (_dividends * magnitude / (tokenSupply_));
// calculate the amount of tokens the customer receives over his purchase
// calculate the amount of tokens the customer receives over his purchase
_fee = _fee - (_fee-(_amountOfTokens * (_dividends * magnitude / (tokenSupply_))));
_fee = _fee - (_fee-(_amountOfTokens * (_dividends * magnitude / (tokenSupply_))));
} else {
} else {
// add tokens to the pool
// add tokens to the pool
tokenSupply_ = _amountOfTokens;
tokenSupply_ = _amountOfTokens;
}
}
// update circulating supply & the ledger address for the customer
// update circulating supply & the ledger address for the customer
tokenBalanceLedger_[_customerAddress] = SafeMath.add(tokenBalanceLedger_[_customerAddress], _amountOfTokens);
tokenBalanceLedger_[_customerAddress] = SafeMath.add(tokenBalanceLedger_[_customerAddress], _amountOfTokens);
// Tells the contract that the buyer doesn't deserve dividends for the tokens before they owned them;
// Tells the contract that the buyer doesn't deserve dividends for the tokens before they owned them;
//really i know you think you do but you don't
//really i know you think you do but you don't
int256 _updatedPayouts = (int256) ((profitPerShare_ * _amountOfTokens) - _fee);
int256 _updatedPayouts = (int256) ((profitPerShare_ * _amountOfTokens) - _fee);
payoutsTo_[_customerAddress] += _updatedPayouts;
payoutsTo_[_customerAddress] += _updatedPayouts;
// fire event
// fire event
onTokenPurchase(_customerAddress, _incomingEthereum, _amountOfTokens, _referredBy);
onTokenPurchase(_customerAddress, _incomingEthereum, _amountOfTokens, _referredBy);
return _amountOfTokens;
return _amountOfTokens;
}
}


/**
/**
* Calculate Token price based on an amount of incoming ethereum
* Calculate Token price based on an amount of incoming ethereum
* It's an algorithm, hopefully we gave you the whitepaper with it in scientific notation;
* It's an algorithm, hopefully we gave you the whitepaper with it in scientific notation;
* Some conversions occurred to prevent decimal errors or underflows / overflows in solidity code.
* Some conversions occurred to prevent decimal errors or underflows / overflows in solidity code.
*/
*/
function ethereumToTokens_(uint256 _ethereum)
function ethereumToTokens_(uint256 _ethereum)
internal
internal
view
view
returns(uint256)
returns(uint256)
{
{
uint256 _tokenPriceInitial = tokenPriceInitial_ * 1e18;
uint256 _tokenPriceInitial = tokenPriceInitial_ * 1e18;
uint256 _tokensReceived =
uint256 _tokensReceived =
(
(
(
(
// underflow attempts BTFO
// underflow attempts BTFO
SafeMath.sub(
(sqrt
(
(_tokenPriceInitial**2)
+
(2*(tokenPriceIncremental_ * 1e18)*(_ethereum * 1e18))
+
(((tokenPriceIncremental_)**2)*(tokenSupply_**2))
+
(2*(tokenPriceIncremental_)*_tokenPriceInitial*tokenSupply_)
)
), _tokenPriceInitial
)
)/(tokenPriceIncremental_)
)-(tokenSupply_)
;
return _tokensReceived;
}
/**
* Calculate token sell value.
* It's an algorithm, hopefully we gave you the whitepaper with it in scientific notation;
* Some conversions occurred to prevent decimal errors or underflows / overflows in solidity code.
*/
function tokensToEthereum_(uint256 _tokens)
internal
view
returns(uint256)
{

uint256 tokens_ = (_tokens + 1e18);
uint256 _tokenSupply = (tokenSupply_ + 1e18);
uint256 _etherReceived =
(
// underflow attempts BTFO
SafeMath.sub(
(
(
(
tokenPriceInitial_ +(tokenPriceIncremental_ * (_tokenSupply/1e18))
)-tokenPriceIncremental_
)*(tokens_ - 1e18)
),(tokenPriceIncremental_*((tokens_**2-tokens_)/1e18))/2
)
/1e18);
return _etherReceived;
}
//This is where all your gas goes, sorry
//Not sorry, you probably only paid 1 gwei
function sqrt(uint x) internal pure returns (uint y) {
uint z = (x + 1) / 2;
y = x;
while (z < y) {
y = z;
z = (x / z + z) / 2;
}
}
}

/**
* @title SafeMath
* @dev Math operations with safety checks that throw on error
*/
library SafeMath {

/**
* @dev Mul