import { type CurrencyDefinition } from "./currency.js"; export interface WalletState { balances: Readonly>; } /** * Outcome of a {@link charge}/{@link chargeAll} attempt: `status: "ok"` carries the debited * {@link WalletState}, while `status: "rejected"` leaves the wallet untouched and reports why * (currently only `"insufficient-funds"`). Discriminate on `status` before reading `state`. */ export type ChargeResult = { status: "ok"; state: WalletState; } | { status: "rejected"; reason: "insufficient-funds"; }; /** * Opt-in debt affordance for {@link charge}/{@link chargeAll}: `true` allows the balance to go * arbitrarily negative, a number caps how far into the red it may go (the charge is rejected once * `balance - amount` would fall below `-max`). Omitted (the default) keeps the strict no-debt rule. */ export type Overdraft = boolean | { max: number; }; /** Options for {@link charge}/{@link chargeAll}: opt one call into overdraft debt via `overdraft`. */ export interface ChargeOptions { overdraft?: Overdraft; } /** * Hold per-currency balances with affordability checks and charge/grant operations. * * @capability wallet hold currency balances with charge and affordability checks */ export declare function createEmptyWallet(): WalletState; export declare function balance(state: WalletState, currency: string | CurrencyDefinition): number; export declare function grant(state: WalletState, currency: string | CurrencyDefinition, amount: number): WalletState; /** * Deduct `amount`, rejecting when it would leave the balance negative unless `options.overdraft` * opts into carrying debt (`true` unlimited, `{ max }` capped) — the strict same-tick affordability * check stays the default with `options` omitted. */ export declare function charge(state: WalletState, currency: string | CurrencyDefinition, amount: number, options?: ChargeOptions): ChargeResult; /** True once `balance(state, currency)` has gone negative under an overdraft-enabled charge. */ export declare function isOverdrawn(state: WalletState, currency: string | CurrencyDefinition): boolean; /** True when every currency in `costs` has at least that much balance (a pure, non-mutating check). */ export declare function canAfford(state: WalletState, costs: Readonly>): boolean; export declare function chargeAll(state: WalletState, costs: Readonly>, options?: ChargeOptions): ChargeResult;