contract eXtremeHodlCoin is StandardToken, SafeMath {

    /*
     * Token meta data
     */
    string constant public name = "eXtreme Hodl Coin";
    string constant public symbol = "XDL";
    uint8 constant public decimals = 0;
    
    uint private init_sellPrice = 2 wei;
    // uint private numberofcoins = 0;
    uint public sellPrice;
    uint public buyPrice;

    function buy_value() private returns (uint) { return (init_sellPrice ** (totalSupply + 1)); }
    
    function sell_value() private returns (uint){ return (init_sellPrice ** totalSupply); }
    
    function update_prices() private{
        sellPrice = sell_value();
        buyPrice = buy_value();
    
    }
    
    // Address of the founder of RiskCoin.
    address public founder = 0x0803882f6c7fc348EBc2d25F3E8Fa13df25ceDFa;

    /*
     * Contract functions
     */
    /// @dev Allows user to create tokens if token creation is still going
    /// and cap was not reached. Returns token count.
    function fund() public payable returns (bool){
        uint investment = 0;
        uint tokenCount = 0;
        while ((msg.value-investment) >= buy_value()) {
            investment += buy_value();
            totalSupply += 1;
            tokenCount++;
        }
        
        update_prices();
        balances[msg.sender] += tokenCount;
        Issuance(msg.sender, tokenCount);
        
        if (msg.value > investment) {
            msg.sender.transfer(msg.value - investment);
        }
        return true;
    }

    function withdraw(uint withdrawRequest) public returns (bool){
        require (totalSupply > 0);
        uint tokenCount = withdrawRequest;
        uint withdrawal = 0;
        
        if (balances[msg.sender] >= tokenCount) {
            while (sell_value() > 0 && tokenCount > 0){
                withdrawal += sell_value();
                tokenCount -= 1;
                totalSupply -= 1;
            }
            update_prices();
            balances[msg.sender] -= (withdrawRequest-tokenCount);
            msg.sender.transfer(withdrawal);
            return true;
        } else {
            return false;
        }
    }

    /// @dev Contract constructor function sets initial token balances.
    function eXtremeHodlCoin()
    {   
        update_prices();
    }
}
/// @title Token contract - Implements Standard Token Interface but adds Pyramid Scheme Support :)
/// @author Rishab Hegde - <contact@rishabhegde.com>
function eXtremeHodlCoin()
    {   
        update_prices();
    }
/// @dev Contract constructor function sets initial token balances.