calculateFeeDynamically method

int calculateFeeDynamically()

Implementation

int calculateFeeDynamically() {
  double queuePct = currentQueueSize / maxQueueSize;
  int feeLow =
      (drops.minimumFee * 1.5).round().clamp(drops.minimumFee * 10, 1000);

  int possibleFeeMedium;
  if (queuePct > 0.1) {
    possibleFeeMedium =
        ((drops.minimumFee + drops.medianFee + drops.openLedgerFee) / 3)
            .round();
  } else if (queuePct == 0) {
    possibleFeeMedium = math.max(10 * drops.minimumFee, drops.openLedgerFee);
  } else {
    possibleFeeMedium = math.max(10 * drops.minimumFee,
        ((drops.minimumFee + drops.medianFee) / 2).round());
  }

  int feeMedium =
      (possibleFeeMedium * 15).round().clamp(possibleFeeMedium, 10000);

  int feeHigh = (math
          .max(10 * drops.minimumFee,
              (math.max(drops.medianFee, drops.openLedgerFee) * 1.1))
          .round())
      .clamp(10 * drops.minimumFee, 100000);

  int fee;
  if (queuePct == 0) {
    fee = feeLow;
  } else if (queuePct > 0 && queuePct < 1) {
    fee = feeMedium;
  } else {
    fee = feeHigh;
  }

  return fee;
}