mintCost function

MintCost mintCost(
  1. MintCostInputs inputs
)

All-in cost of minting an exact payout quantity — the mint_exact_quantity shape, priced entirely client-side. Mirrors compute_mint_quote, including its admission checks: the entry-probability band on each finite leg and on the range, the min_premium floor, the lot grid, and the all_in_cost <= quantity bound (a contract may never cost more than it can pay out). Each violation throws the PredictInputError naming the abort the chain would have raised.

Implementation

MintCost mintCost(MintCostInputs inputs) {
  _assertCostInputs(
      inputs.fees, inputs.book, inputs.penaltyRate, inputs.lotSize);
  final resolved = _resolveBoundaries(inputs.probabilities);
  final boundaries = resolved.boundaries;
  final lotSize = inputs.lotSize ?? POSITION_LOT_SIZE;
  final quantity = _rawAmount(inputs.quantity);
  final ttl = _timeToExpiry(_rawMs(inputs.expiryMs),
      _rawMs(inputs.nowMs ?? DateTime.now().millisecondsSinceEpoch));

  _assertRangeMintPolicy(inputs.fees, boundaries);
  final premium = _mulDown(rangeProbabilityRaw(boundaries), quantity);
  if (premium < MIN_PREMIUM) {
    throw PredictInputError('premium $premium is below the $MIN_PREMIUM '
        'minimum (EPremiumBelowMinimum)');
  }
  _assertValidQuantity(quantity, lotSize);

  final quote =
      _mintCostFrom(inputs, boundaries, resolved.exact, quantity, ttl);
  if (quote.raw.cost > quantity) {
    throw PredictInputError('all-in cost ${quote.raw.cost} exceeds the '
        'maximum payout $quantity (EMintCostAboveMaxPayout)');
  }
  return quote;
}