export function calcCustomSubscriptionPrice(tokenCount: number, period: number) { const MIN_TOKEN_COUNT = 1000; const MAX_DISCOUNT = 0.85; const DISCOUNT_PER_STEP = 0.005; const STEP = 500; const BASE_PRICE = 0.95; if (tokenCount < 0) { throw new Error('Token count must be a non-negative integer'); } if (tokenCount < MIN_TOKEN_COUNT) { throw new Error(`Token count must be at least ${MIN_TOKEN_COUNT}`); } const discount = Math.max(0, (tokenCount - MIN_TOKEN_COUNT) / STEP) * DISCOUNT_PER_STEP; const priceMultiplier = Math.max(BASE_PRICE - discount, MAX_DISCOUNT); return Math.round(tokenCount * priceMultiplier * period); }