/** Paid-for credit: top-ups (net of a coupon discount), operator credit grants, won disputes. */ export declare const PAID_INFLOW_TYPES: readonly ["credit_topup", "manual_credit_grant", "credit_dispute_release"]; /** Paid-for credit taken back: Stripe refunds and dispute holds. */ export declare const PAID_REVERSAL_TYPES: readonly ["credit_refund", "credit_dispute_hold"]; /** * Positive general (unscoped) credit of any other type is unpaid: promotional * grants, usage refunds, unknown future types. A top-up's coupon discount is * unpaid too. */ export declare const NEVER_UNPAID_TYPES: readonly string[]; /** * What a top-up added in paid credit: its credit, net of the share a coupon * discounted (Stripe records the amount paid and the discount in cents). * Rounded down. Mirrors the read's SQL. */ export declare function topUpPaidMicros(amountMicros: number, metadata?: Record): number; /** * Running totals a receipt carries (`paidCreditTotals`), over every ledger * row up to and including its own. Fees are this month's (UTC), `feeMonth`. */ export type PaidCreditChain = { /** Receipts so far: orders receipts written in the same microsecond. */ n: number; /** Paid credit receipts added or took back (fees: what they drew). */ paidPart: number; /** Fee debt repaid. */ repaid: number; /** Fees' unfunded shares. */ unfunded: number; /** The lowest mark. */ markFloor: number | null; /** Paid inflows' paid parts. */ paidInflow: number; feeMonth: string | null; feesInMonth: number; }; export declare const EMPTY_PAID_CREDIT_CHAIN: PaidCreditChain; /** The read's per-account paid-credit totals (see readBillingBalance). */ export type PaidCreditTotals = { /** Running totals through now: the latest receipt's plus the rows after it. */ chain: PaidCreditChain; /** When the latest receipt was written, epoch microseconds; null before the first. */ latestMarkAt: number | null; /** The unpaid credit the latest receipt left (`unpaidCreditsAfterMicros`). */ latestMarkUnpaid: number | null; /** Paid inflows' paid parts up to the latest receipt. */ paidInflowBefore: number; /** `[at, paid micros, has a receipt]` per paid inflow after it, `at` in epoch microseconds. */ paidInflows: [number, number, boolean][] | null; /** `[at, unpaid micros]` per unpaid inflow without a receipt after it. */ unpaidInflows: [number, number][] | null; /** The latest row that can carry a receipt (created_at, as text); null for none. */ receiptRowsThrough: string | null; }; export type PaidCreditState = { /** Paid credit a fee may draw now; never negative. */ paidCreditsMicros: number; /** Paid funding, net of fees and fee debt repaid: the receipts' baseline. */ paidFundingMicros: number; /** Own-key fee debt still owed. */ feeDebtMicros: number; /** Fee debt that top-ups written without a receipt repaid; the next receipt records it. */ unrecordedFeeDebtRepaidMicros: number; /** Unpaid credit: credits (with fee debt added back) that are not paid credit. */ unpaidCreditsMicros: number; /** Running totals through now, which the next receipt extends. */ chain: PaidCreditChain; /** The latest row that can carry a receipt; the next receipt is stamped after it. */ receiptRowsThrough: string | null; }; /** Paid credit from the read's totals and the account's credits (`creditsMicros`). */ export declare function paidCreditState(totals: PaidCreditTotals, creditsMicros: number): PaidCreditState; /** * A receipt with the running totals after its row (`paidCreditTotals`): * the state's totals through now plus what this row adds. Every receipt * writer extends the chain, under the account lock. */ export declare function chainedReceipt & { paidCreditsBeforeMicros: number; paidFundingBeforeMicros: number; }>(state: PaidCreditState, row: { type: string; amountMicros: number; }, receipt: R): R & { paidCreditTotals: PaidCreditChain; }; /** * A receipt's mark: paid credits and paid funding just before its row, and * the unpaid credit just after it (at most what was there plus the unpaid * credit the row adds, `unpaidAddedMicros`). */ export declare function paidCreditMark(state: PaidCreditState, restoredMicros?: number, unpaidAddedMicros?: number): { paidCreditsBeforeMicros: number; paidFundingBeforeMicros: number; paidRestoredMicros?: number; unpaidCreditsAfterMicros: number; }; /** Fee debt a receipt records as repaid: what unrecorded top-ups repaid, then its own share. */ export declare function feeDebtRepaid(state: PaidCreditState, ownMicros?: number): { feeDebtRepaidMicros: number; } | { feeDebtRepaidMicros?: never; };