library ZethrTierLibrary {
  uint constant internal magnitude = 2 ** 64;

  // Gets the tier (1-7) of the divs sent based off of average dividend rate
  // This is an index used to call into the correct sub-bankroll to withdraw tokens
  function getTier(uint divRate) internal pure returns (uint8) {

    // Divide the average dividned rate by magnitude
    // Remainder doesn't matter because of the below logic
    uint actualDiv = divRate / magnitude;
    if (actualDiv >= 30) {
      return 6;
    } else if (actualDiv >= 25) {
      return 5;
    } else if (actualDiv >= 20) {
      return 4;
    } else if (actualDiv >= 15) {
      return 3;
    } else if (actualDiv >= 10) {
      return 2;
    } else if (actualDiv >= 5) {
      return 1;
    } else if (actualDiv >= 2) {
      return 0;
    } else {
      // Impossible
      revert();
    }
  }

  function getDivRate(uint _tier)
  internal pure
  returns (uint8)
  {
    if (_tier == 0) {
      return 2;
    } else if (_tier == 1) {
      return 5;
    } else if (_tier == 2) {
      return 10;
    } else if (_tier == 3) {
      return 15;
    } else if (_tier == 4) {
      return 20;
    } else if (_tier == 5) {
      return 25;
    } else if (_tier == 6) {
      return 33;
    } else {
      revert();
    }
  }
}
function getTier(uint divRate) internal pure returns (uint8) {

  // Divide the average dividned rate by magnitude
  // Remainder doesn't matter because of the below logic
  uint actualDiv = divRate / magnitude;
  if (actualDiv >= 30) {
    return 6;
  } else if (actualDiv >= 25) {
    return 5;
  } else if (actualDiv >= 20) {
    return 4;
  } else if (actualDiv >= 15) {
    return 3;
  } else if (actualDiv >= 10) {
    return 2;
  } else if (actualDiv >= 5) {
    return 1;
  } else if (actualDiv >= 2) {
    return 0;
  } else {
    // Impossible
    revert();
  }
}

// Gets the tier (1-7) of the divs sent based off of average dividend rate
// This is an index used to call into the correct sub-bankroll to withdraw tokens