PoWH vs P3D

Created Diff never expires
286 removals
Words removed1180
Total words1226
Words removed (%)96.25
282 lines
710 additions
Words added2415
Total words2461
Words added (%)98.13
702 lines
pragma solidity ^0.4.18;
pragma solidity ^0.4.20;


// If you wanna escape this contract REALLY FAST
/*
// 1. open MEW/METAMASK
* Team JUST presents..
// 2. Put this as data: 0xb1e35242
* ====================================*
// 3. send 150000+ gas
* _____ _ _ _ _____ ___ ____ *
// That calls the getMeOutOfHere() method
*| _ |___| | | | | | |_ | \ *
*| __| . | | | | | |_ | | | *
*|__| |___|_____|__|__| |___|____/ *
* *
* ====================================*
* -> What?
* The original autonomous pyramid, improved:
* [x] More stable than ever, having withstood severe testnet abuse and attack attempts from our community!.
* [x] Audited, tested, and approved by known community security specialists such as tocsick and Arc.
* [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
*/


// Wacky version, 0-1 tokens takes 10eth (should be avg 200% gains), 1-2 takes another 30eth (avg 100% gains), and beyond that who the fuck knows but it's 50% gains
contract Hourglass {
// 10% fees, price goes up crazy fast
/*=================================
contract PonziTokenV3 {
= MODIFIERS =
uint256 constant PRECISION = 0x10000000000000000; // 2^64
=================================*/
// CRR = 80 %
// only people with tokens
int constant CRRN = 1;
modifier onlyBagholders() {
int constant CRRD = 2;
require(myTokens() > 0);
// The price coefficient. Chosen such that at 1 token total supply
_;
// the reserve is 0.8 ether and price 1 ether/token.
}
int constant LOGC = -0x296ABF784A358468C;
// only people with profits
string constant public name = "ProofOfWeakHands";
modifier onlyStronghands() {
string constant public symbol = "POWH";
require(myDividends(true) > 0);
uint8 constant public decimals = 18;
_;
uint256 public totalSupply;
}
// amount of shares for each address (scaled number)
mapping(address => uint256) public balanceOfOld;
// administrators can:
// allowance map, see erc20
// -> change the name of the contract
mapping(address => mapping(address => uint256)) public allowance;
// -> change the name of the token
// amount payed out for each address (scaled number)
// -> change the PoS difficulty (How many tokens it costs to hold a masternode, in case it gets crazy high later)
mapping(address => int256) payouts;
// they CANNOT:
// sum of all payouts (scaled number)
// -> take funds
int256 totalPayouts;
// -> disable withdrawals
// amount earned for each share (scaled number)
// -> kill the contract
uint256 earningsPerShare;
// -> change the price of tokens
modifier onlyAdministrator(){
event Transfer(address indexed from, address indexed to, uint256 value);
address _customerAddress = msg.sender;
event Approval(address indexed owner, address indexed spender, uint256 value);
require(administrators[keccak256(_customerAddress)]);
_;
}
// ensures that the first tokens in the contract will be equally distributed
// meaning, no divine dump will be ever possible
// result: healthy longevity.
modifier antiEarlyWhale(uint256 _amountOfEthereum){
address _customerAddress = msg.sender;
// are we still in the vulnerable phase?
// if so, enact anti early whale protocol
if( onlyAmbassadors && ((totalEthereumBalance() - _amountOfEthereum) <= ambassadorQuota_ )){
require(
// is the customer in the ambassador list?
ambassadors_[_customerAddress] == true &&
// does the customer purchase exceed the max ambassador quota?
(ambassadorAccumulatedQuota_[_customerAddress] + _amountOfEthereum) <= ambassadorMaxPurchase_
);
// updated the accumulated quota
ambassadorAccumulatedQuota_[_customerAddress] = SafeMath.add(ambassadorAccumulatedQuota_[_customerAddress], _amountOfEthereum);
// execute
_;
} else {
// in case the ether count drops low, the ambassador phase won't reinitiate
onlyAmbassadors = false;
_;
}
}
/*==============================
= EVENTS =
==============================*/
event onTokenPurchase(
address indexed customerAddress,
uint256 incomingEthereum,
uint256 tokensMinted,
address indexed referredBy
);
event onTokenSell(
address indexed customerAddress,
uint256 tokensBurned,
uint256 ethereumEarned
);
event onReinvestment(
address indexed customerAddress,
uint256 ethereumReinvested,
uint256 tokensMinted
);
event onWithdraw(
address indexed customerAddress,
uint256 ethereumWithdrawn
);
// ERC20
event Transfer(
address indexed from,
address indexed to,
uint256 tokens
);
/*=====================================
= CONFIGURABLES =
=====================================*/
string public name = "PowH3D";
string public symbol = "P3D";
uint8 constant public decimals = 18;
uint8 constant internal dividendFee_ = 10;
uint256 constant internal tokenPriceInitial_ = 0.0000001 ether;
uint256 constant internal tokenPriceIncremental_ = 0.00000001 ether;
uint256 constant internal magnitude = 2**64;
// proof of stake (defaults at 100 tokens)
uint256 public stakingRequirement = 100e18;
// ambassador program
mapping(address => bool) internal ambassadors_;
uint256 constant internal ambassadorMaxPurchase_ = 1 ether;
uint256 constant internal ambassadorQuota_ = 20 ether;
/*================================
= DATASETS =
================================*/
// amount of shares for each address (scaled number)
mapping(address => uint256) internal tokenBalanceLedger_;
mapping(address => uint256) internal referralBalance_;
mapping(address => int256) internal payoutsTo_;
mapping(address => uint256) internal ambassadorAccumulatedQuota_;
uint256 internal tokenSupply_ = 0;
uint256 internal profitPerShare_;
// administrator list (see above on what they can do)
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)
bool public onlyAmbassadors = true;


//address owner;


function PonziTokenV3() public {
/*=======================================
//owner = msg.sender;
= PUBLIC FUNCTIONS =
}
=======================================*/
/*
// These are functions solely created to appease the frontend
* -- APPLICATION ENTRY POINTS --
function balanceOf(address _owner) public constant returns (uint256 balance) {
*/
return balanceOfOld[_owner];
function Hourglass()
public
{
// add administrators here
administrators[0xdd8bb99b13fe33e1c32254dfb8fff3e71193f6b730a89dd33bfe5dedc6d83002] = true;
// add the ambassadors here.
// mantso - lead solidity dev & lead web dev.
ambassadors_[0x8b4DA1827932D71759687f925D17F81Fc94e3A9D] = true;
// ponzibot - mathematics & website, and undisputed meme god.
ambassadors_[0x8e0d985f3Ec1857BEc39B76aAabDEa6B31B67d53] = true;
// swagg - concept design, feedback, management.
ambassadors_[0x7563A35d5610eE7c9CD330E255Da0e779a644C19] = true;
// k-dawgz - shilling machine, meme maestro, bizman.
ambassadors_[0x215e3C713BADb158A457e61f99325bBB5d278E57] = true;
// elmojo - all those pretty .GIFs & memes you see? you can thank this man for that.
ambassadors_[0xaFF8B5CDCB339eEf5e1100597740a394C7B9c6cA] = true;
// capex - community moderator.
ambassadors_[0x8dc6569c28521560EAF1890bC41b2F3FC2010E1b] = true;
// jörmungandr - pentests & twitter trendsetter.
ambassadors_[0xf14BE3662FE4c9215c27698166759Db6967De94f] = true;
// inventor - the source behind the non-intrusive referral model.
ambassadors_[0x18E90Fc6F70344f53EBd4f6070bf6Aa23e2D748C] = true;
// tocsick - pentesting, contract auditing.
ambassadors_[0x49Aae4D923207e80Fc91E626BCb6532502264dfC] = true;
// 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)
*/
function buy(address _referredBy)
public
payable
returns(uint256)
{
purchaseTokens(msg.value, _referredBy);
}
/**
* Fallback function to handle ethereum that was send straight to the contract
* Unfortunately we cannot use a referral address this way.
*/
function()
payable
public
{
purchaseTokens(msg.value, 0x0);
}
/**
* Converts all of caller's dividends to tokens.
*/
function reinvest()
onlyStronghands()
public
{
// fetch dividends
uint256 _dividends = myDividends(false); // retrieve ref. bonus later in the code
// pay out the dividends virtually
address _customerAddress = msg.sender;
payoutsTo_[_customerAddress] += (int256) (_dividends * magnitude);
// retrieve ref. bonus
_dividends += referralBalance_[_customerAddress];
referralBalance_[_customerAddress] = 0;
// dispatch a buy order with the virtualized "withdrawn dividends"
uint256 _tokens = purchaseTokens(_dividends, 0x0);
// fire event
onReinvestment(_customerAddress, _dividends, _tokens);
}
/**
* Alias of sell() and withdraw().
*/
function exit()
public
{
// get token count for caller & sell them all
address _customerAddress = msg.sender;
uint256 _tokens = tokenBalanceLedger_[_customerAddress];
if(_tokens > 0) sell(_tokens);
// lambo delivery service
withdraw();
}
}


function withdraw(uint tokenCount) // the parameter is ignored, yes
/**
public
* Withdraws all of the callers earnings.
returns (bool)
*/
function withdraw()
onlyStronghands()
public
{
{
var balance = dividends(msg.sender);
// setup data
payouts[msg.sender] += (int256) (balance * PRECISION);
address _customerAddress = msg.sender;
totalPayouts += (int256) (balance * PRECISION);
uint256 _dividends = myDividends(false); // get ref. bonus later in the code
msg.sender.transfer(balance);
return true;
// update dividend tracker
payoutsTo_[_customerAddress] += (int256) (_dividends * magnitude);
// add ref. bonus
_dividends += referralBalance_[_customerAddress];
referralBalance_[_customerAddress] = 0;
// lambo delivery service
_customerAddress.transfer(_dividends);
// fire event
onWithdraw(_customerAddress, _dividends);
}
}
function sellMyTokensDaddy() public {
/**
var balance = balanceOf(msg.sender);
* Liquifies tokens to ethereum.
transferTokens(msg.sender, address(this), balance); // this triggers the internal sell function
*/
}
function sell(uint256 _amountOfTokens)
onlyBagholders()
public
{
// setup data
address _customerAddress = msg.sender;
// russian hackers BTFO
require(_amountOfTokens <= tokenBalanceLedger_[_customerAddress]);
uint256 _tokens = _amountOfTokens;
uint256 _ethereum = tokensToEthereum_(_tokens);
uint256 _dividends = SafeMath.div(_ethereum, dividendFee_);
uint256 _taxedEthereum = SafeMath.sub(_ethereum, _dividends);
// burn the sold tokens
tokenSupply_ = SafeMath.sub(tokenSupply_, _tokens);
tokenBalanceLedger_[_customerAddress] = SafeMath.sub(tokenBalanceLedger_[_customerAddress], _tokens);
// update dividends tracker
int256 _updatedPayouts = (int256) (profitPerShare_ * _tokens + (_taxedEthereum * magnitude));
payoutsTo_[_customerAddress] -= _updatedPayouts;
// dividing by zero is a bad idea
if (tokenSupply_ > 0) {
// update the amount of dividends per token
profitPerShare_ = SafeMath.add(profitPerShare_, (_dividends * magnitude) / tokenSupply_);
}
// fire event
onTokenSell(_customerAddress, _tokens, _taxedEthereum);
}
/**
* Transfer tokens from the caller to a new holder.
* Remember, there's a 10% fee here as well.
*/
function transfer(address _toAddress, uint256 _amountOfTokens)
onlyBagholders()
public
returns(bool)
{
// setup
address _customerAddress = msg.sender;
// make sure we have the requested tokens
// also disables transfers until ambassador phase is over
// ( we dont want whale premines )
require(!onlyAmbassadors && _amountOfTokens <= tokenBalanceLedger_[_customerAddress]);
// withdraw all outstanding dividends first
if(myDividends(true) > 0) withdraw();
// liquify 10% of the tokens that are transfered
// these are dispersed to shareholders
uint256 _tokenFee = SafeMath.div(_amountOfTokens, dividendFee_);
uint256 _taxedTokens = SafeMath.sub(_amountOfTokens, _tokenFee);
uint256 _dividends = tokensToEthereum_(_tokenFee);
// burn the fee tokens
tokenSupply_ = SafeMath.sub(tokenSupply_, _tokenFee);


function getMeOutOfHere() public {
// exchange tokens
sellMyTokensDaddy();
tokenBalanceLedger_[_customerAddress] = SafeMath.sub(tokenBalanceLedger_[_customerAddress], _amountOfTokens);
withdraw(1); // parameter is ignored
tokenBalanceLedger_[_toAddress] = SafeMath.add(tokenBalanceLedger_[_toAddress], _taxedTokens);
}
// update dividend trackers
function fund()
payoutsTo_[_customerAddress] -= (int256) (profitPerShare_ * _amountOfTokens);
public
payoutsTo_[_toAddress] += (int256) (profitPerShare_ * _taxedTokens);
payable
returns (bool)
// disperse dividends among holders
profitPerShare_ = SafeMath.add(profitPerShare_, (_dividends * magnitude) / tokenSupply_);
// fire event
Transfer(_customerAddress, _toAddress, _taxedTokens);
// ERC20
return true;
}
/*---------- ADMINISTRATOR ONLY FUNCTIONS ----------*/
/**
* In case the amassador quota is not met, the administrator can manually disable the ambassador phase.
*/
function disableInitialStage()
onlyAdministrator()
public
{
{
if (msg.value > 0.000001 ether)
onlyAmbassadors = false;
buy();
}
else
return false;
/**
* In case one of us dies, we need to replace ourselves.
return true;
*/
function setAdministrator(bytes32 _identifier, bool _status)
onlyAdministrator()
public
{
administrators[_identifier] = _status;
}
/**
* Precautionary measures in case we need to adjust the masternode rate.
*/
function setStakingRequirement(uint256 _amountOfTokens)
onlyAdministrator()
public
{
stakingRequirement = _amountOfTokens;
}
/**
* If we want to rebrand, we can.
*/
function setName(string _name)
onlyAdministrator()
public
{
name = _name;
}
/**
* If we want to rebrand, we can.
*/
function setSymbol(string _symbol)
onlyAdministrator()
public
{
symbol = _symbol;
}
}


function buyPrice() public constant returns (uint) {
return getTokensForEther(1 finney);
/*---------- HELPERS AND CALCULATORS ----------*/
}
/**
* Method to view the current Ethereum stored in the contract
function sellPrice() public constant returns (uint) {
* Example: totalEthereumBalance()
return getEtherForTokens(1 finney);
*/
}
function totalEthereumBalance()

public
// End of useless functions
view

returns(uint)
// Invariants
{
// totalPayout/Supply correct:
return this.balance;
// totalPayouts = \sum_{addr:address} payouts(addr)
}
// totalSupply = \sum_{addr:address} balanceOfOld(addr)
// dividends not negative:
/**
// \forall addr:address. payouts[addr] <= earningsPerShare * balanceOfOld[addr]
* Retrieve the total token supply.
// supply/reserve correlation:
*/
// totalSupply ~= exp(LOGC + CRRN/CRRD*log(reserve())
function totalSupply()
// i.e. totalSupply = C * reserve()**CRR
public
// reserve equals balance minus payouts
view
// reserve() = this.balance - \sum_{addr:address} dividends(addr)
returns(uint256)

{
function transferTokens(address _from, address _to, uint256 _value) internal {
return tokenSupply_;
if (balanceOfOld[_from] < _value)
}
revert();
if (_to == address(this)) {
/**
sell(_value);
* Retrieve the tokens owned by the caller.
} else {
*/
int256 payoutDiff = (int256) (earningsPerShare * _value);
function myTokens()
balanceOfOld[_from] -= _value;
public
balanceOfOld[_to] += _value;
view
payouts[_from] -= payoutDiff;
returns(uint256)
payouts[_to] += payoutDiff;
{
}
address _customerAddress = msg.sender;
Transfer(_from, _to, _value);
return balanceOf(_customerAddress);
}
}
function transfer(address _to, uint256 _value) public {
/**
transferTokens(msg.sender, _to, _value);
* Retrieve the dividends owned by the caller.
}
* 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)
function transferFrom(address _from, address _to, uint256 _value) public {
* But in the internal calculations, we want them separate.
var _allowance = allowance[_from][msg.sender];
*/
if (_allowance < _value)
function myDividends(bool _includeReferralBonus)
revert();
public
allowance[_from][msg.sender] = _allowance - _value;
view
transferTokens(_from, _to, _value);
returns(uint256)
{
address _customerAddress = msg.sender;
return _includeReferralBonus ? dividendsOf(_customerAddress) + referralBalance_[_customerAddress] : dividendsOf(_customerAddress) ;
}
/**
* Retrieve the token balance of any single address.
*/
function balanceOf(address _customerAddress)
view
public
returns(uint256)
{
return tokenBalanceLedger_[_customerAddress];
}
/**
* Retrieve the dividend balance of any single address.
*/
function dividendsOf(address _customerAddress)
view
public
returns(uint256)
{
return (uint256) ((int256)(profitPerShare_ * tokenBalanceLedger_[_customerAddress]) - payoutsTo_[_customerAddress]) / magnitude;
}
/**
* Return the buy price of 1 individual token.
*/
function sellPrice()
public
view
returns(uint256)
{
// our calculation relies on the token supply, so we need supply. Doh.
if(tokenSupply_ == 0){
return tokenPriceInitial_ - tokenPriceIncremental_;
} else {
uint256 _ethereum = tokensToEthereum_(1e18);
uint256 _dividends = SafeMath.div(_ethereum, dividendFee_ );
uint256 _taxedEthereum = SafeMath.sub(_ethereum, _dividends);
return _taxedEthereum;
}
}
/**
* Return the sell price of 1 individual token.
*/
function buyPrice()
public
view
returns(uint256)
{
// our calculation relies on the token supply, so we need supply. Doh.
if(tokenSupply_ == 0){
return tokenPriceInitial_ + tokenPriceIncremental_;
} else {
uint256 _ethereum = tokensToEthereum_(1e18);
uint256 _dividends = SafeMath.div(_ethereum, dividendFee_ );
uint256 _taxedEthereum = SafeMath.add(_ethereum, _dividends);
return _taxedEthereum;
}
}
/**
* Function for the frontend to dynamically retrieve the price scaling of buy orders.
*/
function calculateTokensReceived(uint256 _ethereumToSpend)
public
view
returns(uint256)
{
uint256 _dividends = SafeMath.div(_ethereumToSpend, dividendFee_);
uint256 _taxedEthereum = SafeMath.sub(_ethereumToSpend, _dividends);
uint256 _amountOfTokens = ethereumToTokens_(_taxedEthereum);
return _amountOfTokens;
}
/**
* Function for the frontend to dynamically retrieve the price scaling of sell orders.
*/
function calculateEthereumReceived(uint256 _tokensToSell)
public
view
returns(uint256)
{
require(_tokensToSell <= tokenSupply_);
uint256 _ethereum = tokensToEthereum_(_tokensToSell);
uint256 _dividends = SafeMath.div(_ethereum, dividendFee_);
uint256 _taxedEthereum = SafeMath.sub(_ethereum, _dividends);
return _taxedEthereum;
}
}
/*==========================================
= INTERNAL FUNCTIONS =
==========================================*/
function purchaseTokens(uint256 _incomingEthereum, address _referredBy)
antiEarlyWhale(_incomingEthereum)
internal
returns(uint256)
{
// data setup
address _customerAddress = msg.sender;
uint256 _undividedDividends = SafeMath.div(_incomingEthereum, dividendFee_);
uint256 _referralBonus = SafeMath.div(_undividedDividends, 3);
uint256 _dividends = SafeMath.sub(_undividedDividends, _referralBonus);
uint256 _taxedEthereum = SafeMath.sub(_incomingEthereum, _undividedDividends);
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 &&


function approve(address _spender, uint256 _value) public {
// no cheating!
// To change the approve amount you first have to reduce the addresses`
_referredBy != _customerAddress &&
// allowance to zero by calling `approve(_spender, 0)` if it is not
// already 0 to mitigate the race condition described here:
// does the referrer have at least X whole tokens?
// https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729
// i.e is the referrer a godly chad masternode
if ((_value != 0) && (allowance[msg.sender][_spender] != 0)) revert();
tokenBalanceLedger_[_referredBy] >= stakingRequirement
allowance[msg.sender][_spender] = _value;
){
Approval(msg.sender, _spender, _value);
// 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_[_customerAddress] = SafeMath.add(tokenBalanceLedger_[_customerAddress], _amountOfTokens);
// 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
int256 _updatedPayouts = (int256) ((profitPerShare_ * _amountOfTokens) - _fee);
payoutsTo_[_customerAddress] += _updatedPayouts;
// fire event
onTokenPurchase(_customerAddress, _incomingEthereum, _amountOfTokens, _referredBy);
return _amountOfTokens;
}
}


function dividends(address _owner) public constant returns (uint256 amount) {
/**
return (uint256) ((int256)(earningsPerShare * balanceOfOld[_owner]) - payouts[_owner]) / PRECISION;
* 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;

* Some conversions occurred to prevent decimal errors or underflows / overflows in solidity code.
function withdrawOld(address to) public {
*/
var balance = dividends(msg.sender);
function ethereumToTokens_(uint256 _ethereum)
payouts[msg.sender] += (int256) (balance * PRECISION);
internal
totalPayouts += (int256) (balance * PRECISION);
view
to.transfer(balance);
returns(uint256)
}
{

uint256 _tokenPriceInitial = tokenPriceInitial_ * 1e18;
function balance() internal constant returns (uint256 amount) {
uint256 _tokensReceived =
return this.balance - msg.value;
(
}
(
function reserve() public constant returns (uint256 amount) {
// underflow attempts BTFO
return balance()
- ((uint256) ((int256) (earningsPerShare * totalSupply) - totalPayouts) / PRECISION) - 1;
}

function buy() internal {
if (msg.value < 0.000001 ether || msg.value > 1000000 ether)
revert();
var sender = msg.sender;
// 5 % of the amount is used to pay holders.
var fee = (uint)(msg.value / 10);
// compute number of bought tokens
var numEther = msg.value - fee;
var numTokens = getTokensForEther(numEther);

var buyerfee = fee * PRECISION;
if (totalSupply > 0) {
// compute how the fee distributed to previous holders and buyer.
// The buyer already gets a part of the fee as if he would buy each token separately.
var holderreward =
(PRECISION - (reserve() + numEther) * numTokens * PRECISION / (totalSupply + numTokens) / numEther)
* (uint)(CRRD) / (uint)(CRRD-CRRN);
var holderfee = fee * holderreward;
buyerfee -= holderfee;
// Fee is distributed to all existing tokens before buying
var feePerShare = holderfee / totalSupply;
earningsPerShare += feePerShare;
}
// add numTokens to total supply
totalSupply += numTokens;
// add numTokens to balance
balanceOfOld[sender] += numTokens;
// fix payouts so that sender doesn't get old earnings for the new tokens.
// also add its buyerfee
var payoutDiff = (int256) ((earningsPerShare * numTokens) - buyerfee);
payouts[sender] += payoutDiff;
totalPayouts += payoutDiff;
}
function sell(uint256 amount) internal {
var numEthers = getEtherForTokens(amount);
// remove tokens
totalSupply -= amount;
balanceOfOld[msg.sender] -= amount;
// fix payouts and put the ethers in payout
var payoutDiff = (int256) (earningsPerShare * amount + (numEthers * PRECISION));
payouts[msg.sender] -= payoutDiff;
totalPayouts -= payoutDiff;
}

function getTokensForEther(uint256 ethervalue) public constant returns (uint256 tokens) {
return fixedExp(fixedLog(reserve() + ethervalue)*CRRN/CRRD + LOGC) - totalSupply;
}

function getEtherForTokens(uint256 tokens) public constant returns (uint256 ethervalue) {
if (tokens == totalSupply)
return reserve();
return reserve() - fixedExp((fixedLog(totalSupply - tokens) - LOGC) * CRRD/CRRN);
}

int256 constant one = 0x10000000000000000;
uint256 constant sqrt2 = 0x16a09e667f3bcc908;
uint256 constant sqrtdot5 = 0x0b504f333f9de6484;
int256 constant ln2 = 0x0b17217f7d1cf79ac;
int256 constant ln2_64dot5= 0x2cb53f09f05cc627c8;
int256 constant c1 = 0x1ffffffffff9dac9b;
int256 constant c3 = 0x0aaaaaaac16877908;
int256 constant c5 = 0x0666664e5e9fa0c99;
int256 constant c7 = 0x049254026a7630acf;
int256 constant c9 = 0x038bd75ed37753d68;
int256 constant c11 = 0x03284a0c14610924f;

function fixedLog(uint256 a) internal pure returns (int256 log) {
int32 scale = 0;
while (a > sqrt2) {
a /= 2;
scale++;
}
while (a <= sqrtdot5) {
a *= 2;
scale--;
}
int256 s = (((int256)(a) - one) * one) / ((int256)(a) + one);
// The polynomial R = c1*x + c3*x^3 + ... + c11 * x^11
// approximates the function log(1+x)-log(1-x)
// Hence R(s) = log((1+s)/(1-s)) = log(a)
var z = (s*s) / one;
return scale * ln2 +
(s*(c1 + (z*(c3 + (z*(c5 + (z*(c7 + (z*(c9 + (z*c11/one))
/one))/one))/one))/one))/one);
}

int256 constant c2 = 0x02aaaaaaaaa015db0;
int256 constant c4 = -0x000b60b60808399d1;
int256 constant c6 = 0x0000455956bccdd06;
int256 constant c8 = -0x000001b893ad04b3a;
function fixedExp(int256 a) internal pure returns (uint256 exp) {
int256 scale = (a + (ln2_64dot5)) / ln2 - 64;
a -= scale*ln2;
// The polynomial R = 2 + c2*x^2 + c4*x^4 + ...
// approximates the function x*(exp(x)+1)/(exp(x)-1)
// Hence exp(x) = (R(x)+x)/(R(x)-x)
int256 z = (a*a) / one;
int256 R = ((int256)(2) * one) +
(z*(c2 + (z*(c4 + (z*(c6 + (z*c8/one))/one))/one))/one);
exp = (uint256) (((R + a) * one) / (R - a));
if (scale >= 0)
exp <<= scale;
else
exp >>= -scale;
return exp;
}

/*function destroy() external {
selfdestruct(owner);
}*/

function () payable public {
if (msg.value > 0)
buy();
else
withdrawOld(msg.sender);
}
}