contract Invest2Fulcrum_iDAI is Ownable, ReentrancyGuard {
    using SafeMath for uint;
 
    
    // state variables
    uint public balance;
    IKyberNetworkProxy public kyberNetworkProxyContract = IKyberNetworkProxy(0x818E6FECD516Ecc3849DAf6845e3EC868087B755);
    ERC20 constant public ETH_TOKEN_ADDRESS = ERC20(0x00eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee);
    ERC20 public DAI_TOKEN_ADDRESS = ERC20(0x89d24A6b4CcB1B6fAA2625fE562bDD9a23260359);
    

    
    fulcrumInterface public fulcrumInterfaceContract = fulcrumInterface(0x14094949152EDDBFcd073717200DA82fEd8dC960);
    
    // events
    event AmountInvested(string successmessage, uint numberOfTokensIssued);
    
    // fx in relation to invest with ETH in fulcrum
    
     // - should we ever want to change the interface contract
    function set_fulcrumInterface(fulcrumInterface _fulcrumInterfaceContract) onlyOwner public {
        fulcrumInterfaceContract = _fulcrumInterfaceContract;
    }
    
    function set_kyberNetworkProxyContract(IKyberNetworkProxy _kyberNetworkProxyContract) onlyOwner public {
        kyberNetworkProxyContract = _kyberNetworkProxyContract;
    }
    
    // this function should be called should we ever want to change the DAI_TOKEN_ADDRESS
    function set_DAI_TOKEN_ADDRESS(ERC20 _DAI_TOKEN_ADDRESS) onlyOwner public {
        DAI_TOKEN_ADDRESS = _DAI_TOKEN_ADDRESS;
    }
    
    // the investment fx
    function LetsInvest2FulcrumiDAI(address _towhomtoissue) public payable {
        require(_towhomtoissue != address(0));
        require(msg.value > 0);
        uint minConversionRate;
        (minConversionRate,) = kyberNetworkProxyContract.getExpectedRate(ETH_TOKEN_ADDRESS, DAI_TOKEN_ADDRESS, msg.value);
        uint destAmount = kyberNetworkProxyContract.swapEtherToToken.value(msg.value)(DAI_TOKEN_ADDRESS, minConversionRate);
        uint qty2approve = SafeMath.mul(destAmount, 3);
        require(DAI_TOKEN_ADDRESS.approve(address(fulcrumInterfaceContract), qty2approve));
        fulcrumInterfaceContract.mint(_towhomtoissue, destAmount); 
    }
    
    // fx, in case something goes wrong {hint! learnt from experience}
    function inCaseDAIgetsStuck() onlyOwner public {
        uint qty = DAI_TOKEN_ADDRESS.balanceOf(address(this));
        DAI_TOKEN_ADDRESS.transfer(owner, qty);
    }
    

    // fx in relation to ETH held by the contract sent by the owner
    
    // - this function lets you deposit ETH into this wallet
    function depositETH() payable public onlyOwner returns (uint) {
        balance += msg.value;
    }
    
    // - fallback function let you / anyone send ETH to this wallet without the need to call any function
    function() external payable {
        if (msg.sender == owner) {
            depositETH();
        } else {
            LetsInvest2FulcrumiDAI(msg.sender);
        }
    }
    
    // - to withdraw any ETH balance sitting in the contract
    function withdraw() onlyOwner public{
        owner.transfer(address(this).balance);
    }
    
    
}
function depositETH() payable public onlyOwner returns (uint) {
    balance += msg.value;
}

// fx in relation to ETH held by the contract sent by the owner
// - this function lets you deposit ETH into this wallet