// Vulnerability label: TOD1
pragma solidity ^0.4.24;

/**

https://fortisgames.com https://fortisgames.com https://fortisgames.com https://fortisgames.com https://fortisgames.com

                                                                                                        
FFFFFFFFFFFFFFFFFFFFFF                                           tttt            iiii                   
F::::::::::::::::::::F                                        ttt:::t           i::::i                  
F::::::::::::::::::::F                                        t:::::t            iiii                   
FF::::::FFFFFFFFF::::F                                        t:::::t                                   
  F:::::F       FFFFFFooooooooooo   rrrrr   rrrrrrrrr   ttttttt:::::ttttttt    iiiiiii     ssssssssss   
  F:::::F           oo:::::::::::oo r::::rrr:::::::::r  t:::::::::::::::::t    i:::::i   ss::::::::::s  
  F::::::FFFFFFFFFFo:::::::::::::::or:::::::::::::::::r t:::::::::::::::::t     i::::i ss:::::::::::::s 
  F:::::::::::::::Fo:::::ooooo:::::orr::::::rrrrr::::::rtttttt:::::::tttttt     i::::i s::::::ssss:::::s
  F:::::::::::::::Fo::::o     o::::o r:::::r     r:::::r      t:::::t           i::::i  s:::::s  ssssss 
  F::::::FFFFFFFFFFo::::o     o::::o r:::::r     rrrrrrr      t:::::t           i::::i    s::::::s      
  F:::::F          o::::o     o::::o r:::::r                  t:::::t           i::::i       s::::::s   
  F:::::F          o::::o     o::::o r:::::r                  t:::::t    tttttt i::::i ssssss   s:::::s 
FF:::::::FF        o:::::ooooo:::::o r:::::r                  t::::::tttt:::::ti::::::is:::::ssss::::::s
F::::::::FF        o:::::::::::::::o r:::::r                  tt::::::::::::::ti::::::is::::::::::::::s 
F::::::::FF         oo:::::::::::oo  r:::::r                    tt:::::::::::tti::::::i s:::::::::::ss  
FFFFFFFFFFF           ooooooooooo    rrrrrrr                      ttttttttttt  iiiiiiii  sssssssssss    
                                                                                                        
Discord:   https://discord.gg/gDtTX62


/** Proxy contract to buy tokens on Zethr,
 *  because we forgot to add the onTokenBuy event to Zethr.
 *  So we're proxying Zethr buys through this contract so that our website
 *  can properly track and display Zethr token buys.
**/
contract ZethrProxy {
    ZethrInterface zethr = ZethrInterface(address(0x573e869cA9355299cDdb3a912D444F137ded397c));
    address owner = msg.sender;
    
    event onTokenPurchase(
        address indexed customerAddress,
        uint incomingEthereum,
        uint tokensMinted,
        address indexed referredBy
    );
    
    function buyTokensWithProperEvent(address _referredBy, uint8 divChoice) public payable {
        // Query token balance before & after to see how much we bought
        uint balanceBefore = zethr.balanceOf(msg.sender);
        
        // Buy tokens with selected div rate
        zethr.buyAndTransfer.value(msg.value)(_referredBy, msg.sender, "", divChoice);
        
        // Query balance after
        uint balanceAfter = zethr.balanceOf(msg.sender);
        
        emit onTokenPurchase(
            msg.sender,
            msg.value,
            balanceAfter - balanceBefore,
            _referredBy
        );
    }
    
    function () public payable {
        
    }
    
    // Yes there are tiny amounts of divs generated on buy,
    // but not enough to justify transferring to msg.sender - gas price makes it not worth it.
    function withdrawMicroDivs() public {
        require(msg.sender == owner);
        owner.transfer(address(this).balance);
    }
}

contract ZethrInterface {
    function buyAndTransfer(address _referredBy, address target, bytes _data, uint8 divChoice) public payable;
    function balanceOf(address _owner) view public returns(uint);
}