EthDiamond

-6 Removals
+17 Additions
/**/**
*Submitted for verification at Etherscan.io on 2020-07-04 *Submitted for verification at Etherscan.io on 2018-04-30
*/*/
pragma solidity ^0.4.20;pragma solidity ^0.4.20;
/*/*
* Trevon James Presents....
* https://potj.me/
* https://discord.gg/8FdGtS8
* Twitter: https://twitter.com/BitcoinTre
* YouTube: https://www.youtube.com/channel/UCWZbtMeOAb_qpEVUl551l7w
*
*
*
* Proof of Trevon James
* Don't Talk To Me Unless It's About Intangible Coins.
*
* -> What?* -> What?
* Incorporated the strong points of different POW{x}, best config:* Incorporated the strong points of different POW{x}, best config:
* [✓] 20% dividends for token purchase, shared among all token holders.* [✓] 20% dividends for token purchase, shared among all token holders.
* [✓] 10% dividends for token transfer, shared among all token holders.* [✓] 10% dividends for token transfer, shared among all token holders.
* [✓] 25% dividends for token selling.* [✓] 25% dividends for token selling.
* [✓] 7% dividends is given to referrer.* [✓] 7% dividends is given to referrer.
* [✓] 50 tokens to activate Masternodes.* [✓] 50 tokens to activate Masternodes.
**
*/*/
contract EtherDiamond {contract POTJ {
/*================================= /*=================================
= MODIFIERS = = MODIFIERS =
=================================*/ =================================*/
/// @dev Only people with tokens /// @dev Only people with tokens
modifier onlyBagholders { modifier onlyBagholders {
require(myTokens() > 0); require(myTokens() > 0);
_; _;
} }
/// @dev Only people with profits /// @dev Only people with profits
modifier onlyStronghands { modifier onlyStronghands {
require(myDividends(true) > 0); require(myDividends(true) > 0);
_; _;
} }
/*============================== /*==============================
= 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,
uint timestamp, uint timestamp,
uint256 price uint256 price
); );
event onTokenSell( event onTokenSell(
address indexed customerAddress, address indexed customerAddress,
uint256 tokensBurned, uint256 tokensBurned,
uint256 ethereumEarned, uint256 ethereumEarned,
uint timestamp, uint timestamp,
uint256 price uint256 price
); );
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 = "Ether Diamond"; string public name = "Proof of Trevon James";
string public symbol = "ETHD"; string public symbol = "PoTJ";
uint8 constant public decimals = 18; uint8 constant public decimals = 18;
/// @dev 20% dividends for token purchase /// @dev 15% dividends for token purchase
uint8 constant internal entryFee_ = 20; uint8 constant internal entryFee_ = 20;
/// @dev 10% dividends for token transfer /// @dev 10% dividends for token transfer
uint8 constant internal transferFee_ = 10; uint8 constant internal transferFee_ = 10;
/// @dev 25% dividends for token selling /// @dev 25% dividends for token selling
uint8 constant internal exitFee_ = 25; uint8 constant internal exitFee_ = 25;
/// @dev 35% of entryFee_ (i.e. 7% dividends) is given to referrer /// @dev 35% of entryFee_ (i.e. 7% dividends) is given to referrer
uint8 constant internal refferalFee_ = 35; uint8 constant internal refferalFee_ = 35;
uint256 constant internal tokenPriceInitial_ = 0.00000001 ether; uint256 constant internal tokenPriceInitial_ = 0.00000001 ether;
uint256 constant internal tokenPriceIncremental_ = 0.000000001 ether; uint256 constant internal tokenPriceIncremental_ = 0.000000001 ether;
uint256 constant internal magnitude = 2 ** 64; uint256 constant internal magnitude = 2 ** 64;
/// @dev proof of stake (defaults at 50 tokens) /// @dev proof of stake (defaults at 50 tokens)
uint256 public stakingRequirement = 50e18; uint256 public stakingRequirement = 50e18;
/*================================= /*=================================
= 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_;
uint256 internal tokenSupply_; uint256 internal tokenSupply_;
uint256 internal profitPerShare_; uint256 internal profitPerShare_;
/*======================================= /*=======================================
= PUBLIC FUNCTIONS = = PUBLIC FUNCTIONS =
=======================================*/ =======================================*/
/// @dev Converts all incoming ethereum to tokens for the caller, and passes down the referral addy (if any) /// @dev 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) { function buy(address _referredBy) public payable returns (uint256) {
purchaseTokens(msg.value, _referredBy); purchaseTokens(msg.value, _referredBy);
} }
/** /**
* @dev Fallback function to handle ethereum that was send straight to the contract * @dev 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() payable public { function() payable public {
purchaseTokens(msg.value, 0x0); purchaseTokens(msg.value, 0x0);
} }
/// @dev Converts all of caller's dividends to tokens. /// @dev Converts all of caller's dividends to tokens.
function reinvest() onlyStronghands public { function reinvest() onlyStronghands 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);
} }
/// @dev Alias of sell() and withdraw(). /// @dev Alias of sell() and withdraw().
function exit() public { function exit() 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();
} }
/// @dev Withdraws all of the callers earnings. /// @dev Withdraws all of the callers earnings.
function withdraw() onlyStronghands public { function withdraw() onlyStronghands 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);
} }
/// @dev Liquifies tokens to ethereum. /// @dev Liquifies tokens to ethereum.
function sell(uint256 _amountOfTokens) onlyBagholders public { function sell(uint256 _amountOfTokens) onlyBagholders 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, exitFee_), 100); uint256 _dividends = SafeMath.div(SafeMath.mul(_ethereum, exitFee_), 100);
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, now, buyPrice()); onTokenSell(_customerAddress, _tokens, _taxedEthereum, now, buyPrice());
} }
/** /**
* @dev Transfer tokens from the caller to a new holder. * @dev Transfer tokens from the caller to a new holder.
* Remember, there's a 15% fee here as well. * Remember, there's a 15% fee here as well.
*/ */
function transfer(address _toAddress, uint256 _amountOfTokens) onlyBagholders public returns (bool) { function transfer(address _toAddress, uint256 _amountOfTokens) onlyBagholders public 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
require(_amountOfTokens <= tokenBalanceLedger_[_customerAddress]); require(_amountOfTokens <= tokenBalanceLedger_[_customerAddress]);
// withdraw all outstanding dividends first // withdraw all outstanding dividends first
if (myDividends(true) > 0) { if (myDividends(true) > 0) {
withdraw(); 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(SafeMath.mul(_amountOfTokens, transferFee_), 100); uint256 _tokenFee = SafeMath.div(SafeMath.mul(_amountOfTokens, transferFee_), 100);
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;
} }
/*===================================== /*=====================================
= HELPERS AND CALCULATORS = = HELPERS AND CALCULATORS =
=====================================*/ =====================================*/
/** /**
* @dev Method to view the current Ethereum stored in the contract * @dev Method to view the current Ethereum stored in the contract
* Example: totalEthereumBalance() * Example: totalEthereumBalance()
*/ */
function totalEthereumBalance() public view returns (uint256) { function totalEthereumBalance() public view returns (uint256) {
return this.balance; return this.balance;
} }
/// @dev Retrieve the total token supply. /// @dev Retrieve the total token supply.
function totalSupply() public view returns (uint256) { function totalSupply() public view returns (uint256) {
return tokenSupply_; return tokenSupply_;
} }
/// @dev Retrieve the tokens owned by the caller. /// @dev Retrieve the tokens owned by the caller.
function myTokens() public view returns (uint256) { function myTokens() public view returns (uint256) {
address _customerAddress = msg.sender; address _customerAddress = msg.sender;
return balanceOf(_customerAddress); return balanceOf(_customerAddress);
} }
/** /**
* @dev Retrieve the dividends owned by the caller. * @dev 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) public view returns (uint256) { function myDividends(bool _includeReferralBonus) public view 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) ;
} }
/// @dev Retrieve the token balance of any single address. /// @dev Retrieve the token balance of any single address.
function balanceOf(address _customerAddress) public view returns (uint256) { function balanceOf(address _customerAddress) public view returns (uint256) {
return tokenBalanceLedger_[_customerAddress]; return tokenBalanceLedger_[_customerAddress];
} }
/// @dev Retrieve the dividend balance of any single address. /// @dev Retrieve the dividend balance of any single address.
function dividendsOf(address _customerAddress) public view returns (uint256) { function dividendsOf(address _customerAddress) public view returns (uint256) {
return (uint256) ((int256) (profitPerShare_ * tokenBalanceLedger_[_customerAddress]) - payoutsTo_[_customerAddress]) / magnitude; return (uint256) ((int256) (profitPerShare_ * tokenBalanceLedger_[_customerAddress]) - payoutsTo_[_customerAddress]) / magnitude;
} }
/// @dev Return the sell price of 1 individual token. /// @dev Return the sell price of 1 individual token.
function sellPrice() public view returns (uint256) { function sellPrice() public view 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, exitFee_), 100); uint256 _dividends = SafeMath.div(SafeMath.mul(_ethereum, exitFee_), 100);
uint256 _taxedEthereum = SafeMath.sub(_ethereum, _dividends); uint256 _taxedEthereum = SafeMath.sub(_ethereum, _dividends);
return _taxedEthereum; return _taxedEthereum;
} }
} }
/// @dev Return the buy price of 1 individual token. /// @dev Return the buy price of 1 individual token.
function buyPrice() public view returns (uint256) { function buyPrice() public view 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, entryFee_), 100); uint256 _dividends = SafeMath.div(SafeMath.mul(_ethereum, entryFee_), 100);
uint256 _taxedEthereum = SafeMath.add(_ethereum, _dividends); uint256 _taxedEthereum = SafeMath.add(_ethereum, _dividends);
return _taxedEthereum; return _taxedEthereum;
} }
} }
/// @dev Function for the frontend to dynamically retrieve the price scaling of buy orders. /// @dev Function for the frontend to dynamically retrieve the price scaling of buy orders.
function calculateTokensReceived(uint256 _ethereumToSpend) public view returns (uint256) { function calculateTokensReceived(uint256 _ethereumToSpend) public view returns (uint256) {
uint256 _dividends = SafeMath.div(SafeMath.mul(_ethereumToSpend, entryFee_), 100); uint256 _dividends = SafeMath.div(SafeMath.mul(_ethereumToSpend, entryFee_), 100);
uint256 _taxedEthereum = SafeMath.sub(_ethereumToSpend, _dividends); uint256 _taxedEthereum = SafeMath.sub(_ethereumToSpend, _dividends);
uint256 _amountOfTokens = ethereumToTokens_(_taxedEthereum); uint256 _amountOfTokens = ethereumToTokens_(_taxedEthereum);
return _amountOfTokens; return _amountOfTokens;
} }
/// @dev Function for the frontend to dynamically retrieve the price scaling of sell orders. /// @dev Function for the frontend to dynamically retrieve the price scaling of sell orders.
function calculateEthereumReceived(uint256 _tokensToSell) public view returns (uint256) { function calculateEthereumReceived(uint256 _tokensToSell) public view returns (uint256) {
require(_tokensToSell <= tokenSupply_); require(_tokensToSell <= tokenSupply_);
uint256 _ethereum = tokensToEthereum_(_tokensToSell); uint256 _ethereum = tokensToEthereum_(_tokensToSell);
uint256 _dividends = SafeMath.div(SafeMath.mul(_ethereum, exitFee_), 100); uint256 _dividends = SafeMath.div(SafeMath.mul(_ethereum, exitFee_), 100);
uint256 _taxedEthereum = SafeMath.sub(_ethereum, _dividends); uint256 _taxedEthereum = SafeMath.sub(_ethereum, _dividends);
return _taxedEthereum; return _taxedEthereum;
} }
/*========================================== /*==========================================
= INTERNAL FUNCTIONS = = INTERNAL FUNCTIONS =
==========================================*/ ==========================================*/
/// @dev Internal function to actually purchase the tokens. /// @dev Internal function to actually purchase the tokens.
function purchaseTokens(uint256 _incomingEthereum, address _referredBy) internal returns (uint256) { function purchaseTokens(uint256 _incomingEthereum, address _referredBy) internal returns (uint256) {
// data setup // data setup
address _customerAddress = msg.sender; address _customerAddress = msg.sender;
uint256 _undividedDividends = SafeMath.div(SafeMath.mul(_incomingEthereum, entryFee_), 100); uint256 _undividedDividends = SafeMath.div(SafeMath.mul(_incomingEthereum, entryFee_), 100);
uint256 _referralBonus = SafeMath.div(SafeMath.mul(_undividedDividends, refferalFee_), 100); uint256 _referralBonus = SafeMath.div(SafeMath.mul(_undividedDividends, refferalFee_), 100);
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, now, buyPrice()); onTokenPurchase(_customerAddress, _incomingEthereum, _amountOfTokens, _referredBy, now, buyPrice());
return _amountOfTokens; return _amountOfTokens;
} }
/** /**
* @dev Calculate Token price based on an amount of incoming ethereum * @dev 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) internal view returns (uint256) { function ethereumToTokens_(uint256 _ethereum) internal view returns (uint256) {
uint256 _tokenPriceInitial = tokenPriceInitial_ * 1e18; uint256 _tokenPriceInitial = tokenPriceInitial_ * 1e18;
uint256 _tokensReceived = uint256 _tokensReceived =
( (
( (
// underflow attempts BTFO // underflow attempts BTFO
SafeMath.sub( SafeMath.sub(
(sqrt (sqrt
( (
(_tokenPriceInitial ** 2) (_tokenPriceInitial ** 2)
+ +
(2 * (tokenPriceIncremental_ * 1e18) * (_ethereum * 1e18)) (2 * (tokenPriceIncremental_ * 1e18) * (_ethereum * 1e18))
+ +
((tokenPriceIncremental_ ** 2) * (tokenSupply_ ** 2)) ((tokenPriceIncremental_ ** 2) * (tokenSupply_ ** 2))
+ +
(2 * tokenPriceIncremental_ * _tokenPriceInitial*tokenSupply_) (2 * tokenPriceIncremental_ * _tokenPriceInitial*tokenSupply_)
) )
), _tokenPriceInitial ), _tokenPriceInitial
) )
) / (tokenPriceIncremental_) ) / (tokenPriceIncremental_)
) - (tokenSupply_); ) - (tokenSupply_);
return _tokensReceived; return _tokensReceived;
} }
/** /**
* @dev Calculate token sell value. * @dev Calculate token sell value.
* 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 tokensToEthereum_(uint256 _tokens) internal view returns (uint256) { function tokensToEthereum_(uint256 _tokens) internal view returns (uint256) {
uint256 tokens_ = (_tokens + 1e18); uint256 tokens_ = (_tokens + 1e18);
uint256 _tokenSupply = (tokenSupply_ + 1e18); uint256 _tokenSupply = (tokenSupply_ + 1e18);
uint256 _etherReceived = uint256 _etherReceived =
( (
// underflow attempts BTFO // underflow attempts BTFO
SafeMath.sub( SafeMath.sub(
( (
( (
( (
tokenPriceInitial_ + (tokenPriceIncremental_ * (_tokenSupply / 1e18)) tokenPriceInitial_ + (tokenPriceIncremental_ * (_tokenSupply / 1e18))
) - tokenPriceIncremental_ ) - tokenPriceIncremental_
) * (tokens_ - 1e18) ) * (tokens_ - 1e18)
), (tokenPriceIncremental_ * ((tokens_ ** 2 - tokens_) / 1e18)) / 2 ), (tokenPriceIncremental_ * ((tokens_ ** 2 - tokens_) / 1e18)) / 2
) )
/ 1e18); / 1e18);
return _etherReceived; return _etherReceived;
} }
/// @dev This is where all your gas goes. /// @dev This is where all your gas goes.
function sqrt(uint256 x) internal pure returns (uint256 y) { function sqrt(uint256 x) internal pure returns (uint256 y) {
uint256 z = (x + 1) / 2; uint256 z = (x + 1) / 2;
y = x; y = x;
while (z < y) { while (z < y) {
y = z; y = z;
z = (x / z + z) / 2; z = (x / z + z) / 2;
} }
} }
}}
/**/**
* @title SafeMath * @title SafeMath
* @dev Math operations with safety checks that throw on error * @dev Math operations with safety checks that throw on error
*/ */
library SafeMath {library SafeMath {
/** /**
* @dev Multiplies two numbers, throws on overflow. * @dev Multiplies two numbers, throws on overflow.
*/ */
function mul(uint256 a, uint256 b) internal pure returns (uint256) { function mul(uint256 a, uint256 b) internal pure returns (uint256) {
if (a == 0) { if (a == 0) {
return 0; return 0;
} }
uint256 c = a * b; uint256 c = a * b;
assert(c / a == b); assert(c / a == b);
return c; return c;
} }
/** /**
* @dev Integer division of two numbers, truncating the quotient. * @dev Integer division of two numbers, truncating the quotient.
*/ */
function div(uint256 a, uint256 b) internal pure returns (uint256) { function div(uint256 a, uint256 b) internal pure returns (uint256) {
// assert(b > 0); // Solidity automatically throws when dividing by 0 // assert(b > 0); // Solidity automatically throws when dividing by 0
uint256 c = a / b; uint256 c = a / b;
// assert(a == b * c + a % b); // There is no case in which this doesn't hold // assert(a == b * c + a % b); // There is no case in which this doesn't hold
return c; return c;
} }
/** /**
* @dev Substracts two numbers, throws on overflow (i.e. if subtrahend is greater than minuend). * @dev Substracts two numbers, throws on overflow (i.e. if subtrahend is greater than minuend).
*/ */
function sub(uint256 a, uint256 b) internal pure returns (uint256) { function sub(uint256 a, uint256 b) internal pure returns (uint256) {
assert(b <= a); assert(b <= a);
return a - b; return a - b;
} }
/** /**
* @dev Adds two numbers, throws on overflow. * @dev Adds two numbers, throws on overflow.
*/ */
function add(uint256 a, uint256 b) internal pure returns (uint256) { function add(uint256 a, uint256 b) internal pure returns (uint256) {
uint256 c = a + b; uint256 c = a + b;
assert(c >= a); assert(c >= a);
return c; return c;
} }
}}
Editor
Clear
Export as PDF
Original Text
Changed Text