contract MenapayToken is Pausable, StandardToken {

  string public name;
  string public symbol;
  uint public decimals;
  address public upgradedAddress;
  bool public deprecated;

  function MenapayToken(uint _initialSupply, string _name, string _symbol, uint _decimals){
      _totalSupply = _initialSupply;
      name = _name;
      symbol = _symbol;
      decimals = _decimals;
      balances[owner] = _initialSupply;
      deprecated = false;
  }

  function transfer(address _to, uint _value) whenNotPaused {
    if (deprecated) {
      return UpgradedStandardToken(upgradedAddress).transferByLegacy(msg.sender, _to, _value);
    } else {
      return super.transfer(_to, _value);
    }
  }

  function transferFrom(address _from, address _to, uint _value) whenNotPaused {
    if (deprecated) {
      return UpgradedStandardToken(upgradedAddress).transferFromByLegacy(msg.sender, _from, _to, _value);
    } else {
      return super.transferFrom(_from, _to, _value);
    }
  }

  function balanceOf(address who) constant returns (uint){
    if (deprecated) {
      return UpgradedStandardToken(upgradedAddress).balanceOf(who);
    } else {
      return super.balanceOf(who);
    }
  }

  function approve(address _spender, uint _value) onlyPayloadSize(2 * 32) {
    if (deprecated) {
      return UpgradedStandardToken(upgradedAddress).approveByLegacy(msg.sender, _spender, _value);
    } else {
      return super.approve(_spender, _value);
    }
  }

  function allowance(address _owner, address _spender) constant returns (uint remaining) {
    if (deprecated) {
      return StandardToken(upgradedAddress).allowance(_owner, _spender);
    } else {
      return super.allowance(_owner, _spender);
    }
  }

  function deprecate(address _upgradedAddress) onlyOwner {
    deprecated = true;
    upgradedAddress = _upgradedAddress;
    Deprecate(_upgradedAddress);
  }

  // deprecate current contract if favour of a new one
  function totalSupply() constant returns (uint){
    if (deprecated) {
      return StandardToken(upgradedAddress).totalSupply();
    } else {
      return _totalSupply;
    }
  }


  function issue(uint amount) onlyOwner {
    if (_totalSupply + amount < _totalSupply) throw;
    if (balances[owner] + amount < balances[owner]) throw;

    balances[owner] += amount;
    _totalSupply += amount;
    Issue(amount);
  }

  function redeem(uint amount) onlyOwner {
      if (_totalSupply < amount) throw;
      if (balances[owner] < amount) throw;

      _totalSupply -= amount;
      balances[owner] -= amount;
      Redeem(amount);
  }

  function setParams(uint newBasisPoints, uint newMaxFee) onlyOwner {
      if (newBasisPoints > 20) throw;
      if (newMaxFee > 50) throw;

      basisPointsRate = newBasisPoints;
      maximumFee = newMaxFee.mul(10**decimals);

      Params(basisPointsRate, maximumFee);
  }

  event Issue(uint amount);

  event Redeem(uint amount);

  event Deprecate(address newAddress);

  event Params(uint feeBasisPoints, uint maxFee);
}
function totalSupply() constant returns (uint){
  if (deprecated) {
    return StandardToken(upgradedAddress).totalSupply();
  } else {
    return _totalSupply;
  }
}

// deprecate current contract if favour of a new one