contract VictorieumToken is StandardBurnableToken, Ownable, usingOraclize {

  using SafeMath for uint256;

  string public symbol = "VTM";
  string public name = "Victorieum";
  uint256 public decimals = 18;
  uint public ETHUSD;
  uint presaleEndsAt;
  uint startDate;
  uint firstStageEndsAt;
  uint secondStageEndsAt;
  uint thirdStageEndsAt;
  uint forthStageEndsAt;
  uint endDate;
  uint currentpriceincent;
  uint bonus;
  uint256 public icoSupply = 0;
  uint256 public icoLimit = 765000000000000000000000000;
event LogConstructorInitiated(string nextStep);
    event LogPriceUpdated(string price);
    event LogNewOraclizeQuery(string description);


  
  

  function transfer(address _to, uint256 _value) 
  public  
  returns (bool) {
    super.transfer(_to,_value);
  }

  function transferFrom(address _from, address _to, uint256 _value) 
  public  
  returns (bool) {
    super.transferFrom(_from, _to, _value);
  }

  function approve(address _spender, uint256 _value) 
  public  
  returns (bool) {
    super.approve(_spender, _value);
  }

  function increaseApproval(address _spender, uint _addedValue) 
  public  
  returns (bool) {
    super.increaseApproval(_spender, _addedValue);
  }

  function decreaseApproval(address _spender, uint _subtractedValue) 
  public  
  returns (bool) {
    super.decreaseApproval(_spender, _subtractedValue);
  }

  /**
   * @dev Transfer ownership now transfers all owners tokens to new owner 
   */
  function transferOwnership(address newOwner) public onlyOwner {
    balances[newOwner] = balances[newOwner].add(balances[owner]);
    emit Transfer(owner, newOwner, balances[owner]);
    balances[owner] = 0;

    super.transferOwnership(newOwner);
  }

  /* ICO status */
  enum State {
    Active,
    Closed
  }

  event Closed();

  State public state;

  // ------------------------------------------------------------------------
  // Constructor
  // ------------------------------------------------------------------------
  constructor() public {
  
    owner = msg.sender;
    totalSupply_ = 1000000000000000000000000000;
    balances[owner] = totalSupply_;
    emit Transfer(address(0), owner, totalSupply_);
    
    state = State.Active;
    startDate = 1539993600 ; // Oct 20 2018, 00:01 AM
    presaleEndsAt = 1541376000; // ;   // Nov 04 2018, 11:59 PM
    firstStageEndsAt = 1542758400;   // Nov 20 2018, 11:59 PM
    secondStageEndsAt = 1544140800;   // Dec 06 2018, 11:59 PM
    thirdStageEndsAt = 1545523200;   // Dec 22 2018, 11:59 PM
    forthStageEndsAt = 1546905600;   // Jan 07 2019, 11:59 PM
    endDate = 1548028799;   // Jan 20 2019, 11:59 PM

    // to update ETH Price 
    oraclize_setProof(proofType_Android | proofStorage_IPFS);
    updatePrice(60);
    
  }

  /**
   * @dev all ether transfer to another wallet automatic
   */
  function () public payable {
    require(state == State.Active); // Reject the transactions after ICO ended
    // production code to start accepting payment and stop  
    require(now >= startDate && now <= endDate);
    currentpriceincent = 24;
    bonus = 0;
    if (now < presaleEndsAt)
    {
        currentpriceincent = 1;
        bonus = 40;
    }
    else if (now < firstStageEndsAt)
    {
        currentpriceincent = 6;
        bonus = 35;
    }
    else if (now < secondStageEndsAt)
    {
        currentpriceincent = 9;
        bonus = 30;
    }
    else if (now < thirdStageEndsAt)
    {
        currentpriceincent = 12;
        bonus = 25;
    }
    else if (now < forthStageEndsAt)
    {
        currentpriceincent = 16;
        bonus = 20;
    }
    else if (now < endDate)
    {
        currentpriceincent = 21;
        bonus = 15;
        
    }
    else
    {
        currentpriceincent = 24;
        bonus = 0;
    }
   
    uint256 tokens = msg.value * ETHUSD / currentpriceincent;
    tokens = tokens + (tokens * bonus/100);
    balances[msg.sender] = balances[msg.sender].add(tokens);
    balances[owner] = balances[owner].sub(tokens);
    require(icoSupply.add(tokens) <= icoLimit);
    icoSupply = icoSupply.add(tokens);
    emit Transfer(owner, msg.sender, tokens);
    owner.transfer(msg.value);
  }


    function __callback(bytes32 myid, string result) {
        if (msg.sender != oraclize_cbAddress()) revert();
        ETHUSD = parseInt(result,2);
        emit LogPriceUpdated(result);
       // updatePrice(600);
	updatePrice(10800);
    }

    function updatePrice(uint time_interval) payable {
        if (now < endDate)
        {
            if (oraclize_getPrice("URL") > this.balance) {
                emit LogNewOraclizeQuery("Oraclize query was NOT sent, please add some ETH to cover for the query fee");
            } else {
                emit LogNewOraclizeQuery("Oraclize query was sent, standing by for the answer..");
                oraclize_query(time_interval, "URL", "json(https://api.gdax.com/products/ETH-USD/ticker).price");
            }
        
        }
        
    }



  /**
  * After ICO close it helps to lock tokens for pools
  **/
  function close() onlyOwner public {
    require(state == State.Active);
    state = State.Closed;
    emit Closed();
  }
}
function () public payable {
    require(state == State.Active); // Reject the transactions after ICO ended
    // production code to start accepting payment and stop  
    require(now >= startDate && now <= endDate);
    currentpriceincent = 24;
    bonus = 0;
    if (now < presaleEndsAt)
    {
        currentpriceincent = 1;
        bonus = 40;
    }
    else if (now < firstStageEndsAt)
    {
        currentpriceincent = 6;
        bonus = 35;
    }
    else if (now < secondStageEndsAt)
    {
        currentpriceincent = 9;
        bonus = 30;
    }
    else if (now < thirdStageEndsAt)
    {
        currentpriceincent = 12;
        bonus = 25;
    }
    else if (now < forthStageEndsAt)
    {
        currentpriceincent = 16;
        bonus = 20;
    }
    else if (now < endDate)
    {
        currentpriceincent = 21;
        bonus = 15;
        
    }
    else
    {
        currentpriceincent = 24;
        bonus = 0;
    }
   
    uint256 tokens = msg.value * ETHUSD / currentpriceincent;
    tokens = tokens + (tokens * bonus/100);
    balances[msg.sender] = balances[msg.sender].add(tokens);
    balances[owner] = balances[owner].sub(tokens);
    require(icoSupply.add(tokens) <= icoLimit);
    icoSupply = icoSupply.add(tokens);
    emit Transfer(owner, msg.sender, tokens);
    owner.transfer(msg.value);
  }
/**
 * @dev all ether transfer to another wallet automatic
 */