import { IAssetAccount, IReservationHandle } from '../interfaces/assetAccount'; import { Checksum } from '../types/checksum'; /** * Documentation marker describing the consistency contract of the * operational tier. The store is an **operational projection cache**; * once Layer 3 (asset ledger) attaches, this cache MAY lag the * authoritative ledger by up to one batch window. * * @see asset-account-store-generalization spec, Requirement 5.1. */ export type OperationalSemantics = 'operational projection cache; may lag the asset ledger by up to one batch window once Layer 3 is enabled.'; /** * Forward-declared write surface that Layer 3 will fulfill. Defined here * as a minimal placeholder so {@link AssetAccountStore.attachLedger} can * accept an instance without taking a runtime dependency on the ledger * implementation. * * @see asset-account-store-generalization spec, Requirement 5.3. */ export interface ILedgerWriter { /** Returns the timestamp of the most recently settled batch for an asset. */ getLastSettledAt(assetId: string): Date | null; } /** * Asset-agnostic, in-memory account store keyed by `(memberId, assetId)`. * * The legacy {@link EnergyAccountStore} is preserved untouched during the * additive refactor. A future phase will fold it onto this base via * subclassing with `defaultAssetId = 'joule'`. * * @see asset-account-store-generalization spec, Phase 4. */ export declare class AssetAccountStore { readonly defaultAssetId: string; /** * Eventual-consistency contract for this tier. Surfaced as a runtime * value so call sites can assert / log it. */ readonly operationalSemantics: OperationalSemantics; protected readonly accounts: Map; protected readonly reservations: Map; protected ledger: ILedgerWriter | null; constructor(defaultAssetId?: string); protected static key(memberId: Checksum, assetId: string): string; get(memberId: Checksum): IAssetAccount | undefined; set(memberId: Checksum, account: IAssetAccount): void | Promise; has(memberId: Checksum): boolean; delete(memberId: Checksum): boolean; getForAsset(memberId: Checksum, assetId: string): IAssetAccount | undefined; setForAsset(memberId: Checksum, assetId: string, account: IAssetAccount): void; hasForAsset(memberId: Checksum, assetId: string): boolean; deleteForAsset(memberId: Checksum, assetId: string): boolean; getAllForAsset(assetId: string): IAssetAccount[]; getAllAccounts(): IAssetAccount[]; get size(): number; clear(): void; /** * Reserve `amount` microunits against the available balance of * `(memberId, assetId)`. The reservation expires after `ttlMs` ms; an * expired reservation is reaped lazily on next read or settlement * attempt. */ reserve(memberId: Checksum, assetId: string, amount: bigint, ttlMs: number): IReservationHandle; /** * Settle `actualAmount` of a reservation: deduct from `balance`, * increment `spent`, and return any remainder to the available balance. * No ledger entry is emitted here — that is a Layer-2 concern. */ settle(handle: IReservationHandle, actualAmount: bigint): void; /** * Release the full reservation back to the available balance with no * spend recorded. */ release(handle: IReservationHandle): void; protected releaseHold(handle: IReservationHandle): void; /** * Reap any expired reservations belonging to `(memberId, assetId)`. * Idempotent — re-running produces identical state. */ protected reapExpiredFor(memberId: Checksum, assetId: string): void; /** Reap every expired reservation in the store. */ reapAllExpired(): number; /** * Sum the `balance` field across `accounts`. Throws * {@link MixedAssetError} if the input contains more than one * `assetId`. */ static sumBalances(accounts: readonly IAssetAccount[]): bigint; sumBalances(accounts: readonly IAssetAccount[]): bigint; /** * One-shot setter wiring this operational store to a Layer-3 ledger * writer. Throws {@link LedgerAlreadyAttachedError} on second call so * the system-of-record never silently switches mid-lifetime. */ attachLedger(writer: ILedgerWriter): void; /** * Returns the timestamp of the most recently settled batch for the * supplied asset, or `null` if no ledger is attached. Never throws. */ getLastSettledAt(assetId: string): Date | null; } //# sourceMappingURL=assetAccountStore.d.ts.map