contract BasicToken is ERC20Basic, Pausable {
  using SafeMath for uint256;

  mapping(address => uint256) balances;
  
  struct Purchase {
    uint unlockTokens;
    uint unlockDate;
  }
  mapping(address => Purchase[]) balancesLock;

  uint256 totalSupply_;

  address public rubusBlackAddress;
  uint256 public priceEthPerToken;
  uint256 public depositCommission;
  uint256 public withdrawCommission;
  uint256 public investCommission;
  address public depositWallet;
  address public withdrawWallet;
  address public investWallet;
  bool public lock;
  uint256 public minimalEthers;
  uint256 public lockTokensPercent;
  uint256 public lockTimestamp;
  event Deposit(address indexed buyer, uint256 weiAmount, uint256 tokensAmount, uint256 tokenPrice, uint256 commission);
  event Withdraw(address indexed buyer, uint256 weiAmount, uint256 tokensAmount, uint256 tokenPrice, uint256 commission);

  /**
  * @dev Total number of tokens in existence
  */
  function totalSupply() public view returns (uint256) {
    return totalSupply_;
  }

  /**
  * @dev Transfer token for a specified address
  * @param _to The address to transfer to.
  * @param _value The amount to be transferred.
  */
  function transfer(address _to, uint256 _value) whenNotPaused public returns (bool) {
    require(_to != address(0));
    require(_value <= balances[msg.sender]);
    require(_value <= checkVesting(msg.sender));

    if (_to == rubusBlackAddress) {
      require(!lock);
      uint256 weiAmount = _value.mul(withdrawCommission).div(priceEthPerToken);
      require(weiAmount <= uint256(address(this).balance));
      
      totalSupply_ = totalSupply_.sub(_value);
      msg.sender.transfer(weiAmount);
      withdrawWallet.transfer(weiAmount.mul(uint256(100).sub(withdrawCommission)).div(100));
      
      emit Withdraw(msg.sender, weiAmount, _value, priceEthPerToken, withdrawCommission);
    } else {
      balances[_to] = balances[_to].add(_value);
    }

    balances[msg.sender] = balances[msg.sender].sub(_value);
    emit Transfer(msg.sender, _to, _value);
    return true;
  }
  
  function getPurchases(address sender, uint index) public view returns(uint, uint) {
    return (balancesLock[sender][index].unlockTokens, balancesLock[sender][index].unlockDate);
  }
  
  function checkVesting(address sender) public view returns (uint256) {
    uint256 availableTokens = balances[sender];

    if (balancesLock[sender].length != 0) {
      for (uint i = 0; i < balancesLock[sender].length; i++) {
        (uint lockTokens, uint lockTime) = getPurchases(sender, i);
        if (lockTime >= now) {
          availableTokens = availableTokens.sub(lockTokens);
        }
      }
    }
    
    return availableTokens;
  }

  /**
  * @dev Gets the balance of the specified address.
  * @param _owner The address to query the the balance of.
  * @return An uint256 representing the amount owned by the passed address.
  */
  function balanceOf(address _owner) public view returns (uint256) {
    return checkVesting(_owner);
  }
  
  function balanceOfUnlockTokens(address _owner) public view returns (uint256) {
    return balances[_owner];
  }
}
/**
 * @title Basic token
 * @dev Basic version of StandardToken, with no allowances.
 */
function totalSupply() public view returns (uint256) {
  return totalSupply_;
}

/**
 * @dev Total number of tokens in existence
 */