/** * @pwngh/economy-lab * * Copyright (c) Preston Neal * * This source code is licensed under the MIT license found in the * LICENSE.md file in the root directory of this source tree. * * @license MIT */ import type { Amount } from './money.js'; import type { AccountRef } from './accounts.js'; import type { Config } from './config.js'; import type { Ledger, Lot } from './ports.js'; /** The maturity config plus an optional AbortSignal passed through to the ledger's balance read. */ export type MaturityOptions = { config: Config; signal?: AbortSignal; }; /** * {@link MaturityOptions} plus the `amount` the matured balance must reach. A caller that already * has the balance can pass it as `live` to avoid re-reading it; the spend handler does, with the * balance read under the lock. */ export type MaturedAtLeastOptions = MaturityOptions & { amount: Amount; live?: Amount; }; /** * Returns the wait in milliseconds before credits from a funding source can be cashed out. The wait * covers the window in which the payment could still be reversed, such as a card chargeback. A * source not in the config falls back to the 'default' horizon, so an unknown or misspelled source * is treated cautiously rather than as instantly available. */ export declare function maturityHorizonMs(source: string, config: Config): number; /** * Returns the moment in epoch milliseconds a lot matures: the top-up time plus the source's * required wait. The wait is computed from `source` rather than read from the lot's own * `maturesAt`, because a top-up may record the source without a maturity time. This depends on a * caller rule: any handler issuing spendable credits records the funding source on the posting (a * missing source falls back to the 'default' horizon, just less precisely). */ export declare function lotMaturesAt(lot: Lot, config: Config): number; /** * Reports whether a lot has matured as of `now`. The boundary is inclusive, so the lot is matured * the moment its wait elapses. */ export declare function isMatured(lot: Lot, now: number, config: Config): boolean; /** * When `amount` would be fully matured, assuming no further postings: the latest matures-at * among the earliest-maturing slices that cover it. Null when the live balance cannot cover * the amount at all, since maturity is not what blocks it then. Runs only on the * FUNDS_IMMATURE rejection path, so walking the whole tail is acceptable. */ export declare function maturedAvailableAt(ledger: Ledger, account: AccountRef, now: number, options: MaturedAtLeastOptions): Promise; /** * The lot that blocks an immature draw: the binding slice of the same walk as * {@link maturedAvailableAt}, with the funding source that set its wait. When the walk cannot * name a binding lot (a balance row that outran its lots), the answer falls back to the * 'default' horizon from `now` — the module's conservative rule for unknown funding. */ export declare function maturityBlocker(ledger: Ledger, account: AccountRef, now: number, options: MaturedAtLeastOptions): Promise<{ source: string; availableAt: number; }>; /** * Returns the matured part of an account's balance as of `now`: how much a cash-out may draw * without dipping into funds still in their settlement wait. It reads the newest-first FIFO tail and * stops the instant the lots cover the live balance, so it never scans the already-spent history. * {@link maturedBalanceFullScan} keeps the naive O(account history) version for the differential * test. The computation is currency-agnostic, so it covers spendable credits and earned balances * alike. * * @see {@link https://economy-lab-docs.pages.dev/economy/concepts/credit-maturity/ Credit maturity} * for the dated-lot model, the FIFO tail, and why only the matured run may be drawn. */ export declare function maturedBalance(ledger: Ledger, account: AccountRef, now: number, options: MaturityOptions): Promise; /** * Reports whether an account has at least `amount` of matured balance as of `now`, short-circuiting * once the matured running sum reaches `amount`. Equals `maturedBalance(...).minor >= amount.minor` * but stops early, so a request well within cleared funds costs O(amount-worth-of-lots). A * non-positive `amount` is trivially covered. * * @see {@link https://economy-lab-docs.pages.dev/economy/concepts/credit-maturity/ Credit maturity} * for the dated-lot model behind the running sum. */ export declare function maturedAtLeast(ledger: Ledger, account: AccountRef, now: number, options: MaturedAtLeastOptions): Promise; /** * Computes the matured balance by scanning the full history: kept verbatim as the oracle the * differential test checks the bounded {@link maturedBalance} against. Correct but O(account * history), so it lives here only for tests and never on the production read path. */ export declare function maturedBalanceFullScan(ledger: Ledger, account: AccountRef, now: number, options: MaturityOptions): Promise; /** * Returns the part of an account's balance still in its settlement wait as of `now`. The matured * and still-waiting amounts sum to the current balance. */ export declare function immatureBalance(ledger: Ledger, account: AccountRef, now: number, options: MaturityOptions): Promise;