getFeeIndex function

int getFeeIndex(
  1. num fee,
  2. num amount
)

Calculates the appropriate fee factor depending on what's the fee as a percentage of the amount

@param {Number} fee - The fee in token value @param {BigInt} amount - The amount as a BigInt string

@return {Number} feeFactor

Implementation

int getFeeIndex(num fee, num amount) {
  num low = 0;
  int mid;
  int high = feeFactors.length - 1;
  while (high - low > 1) {
    mid = ((low + high) / 2).floor();
    if (getFeeValue(mid, amount).toDouble() < fee) {
      low = mid;
    } else {
      high = mid;
    }
  }

  return high;
}