/** Reputation-aware budget manager for x402 payments. * * Provides per-transaction and per-session spending limits that scale * with the target service's on-chain reputation. Higher reputation = * higher trust = higher allowed spending. * * Budget tiers are configurable and layer ON TOP of the Guardian Module's * on-chain dailySpendLimitUSD (which is the hard ceiling that can't be bypassed). * This is a client-side soft limit for convenience and safety. */ /** A single budget tier: reputation threshold → per-transaction limit */ export interface BudgetTier { /** Minimum reputation score to qualify for this tier (0-100) */ minReputation: number; /** Maximum payment per transaction in token smallest unit (e.g., USDC 6 decimals) */ maxPerTransaction: bigint; /** Tier label for display/logging */ label: string; } /** Default budget tiers (ordered highest reputation first) */ export declare const DEFAULT_BUDGET_TIERS: readonly BudgetTier[]; /** Budget manager configuration */ export interface BudgetConfig { /** Custom budget tiers (overrides defaults). Must be sorted by minReputation descending. */ tiers?: BudgetTier[]; /** Maximum spending per session across all services (in token smallest unit). * Default: 10,000,000 (10 USDC) */ maxPerSession?: bigint; /** Whether to enforce budget checks (default: true). * When false, budget is tracked but not enforced. */ enforce?: boolean; /** Fallback per-tx limit when reputation is unknown (default: bronze tier) */ unknownReputationLimit?: bigint; } /** Result of a budget check */ export interface BudgetCheckResult { allowed: boolean; reason?: string; /** The tier that was matched */ tier?: string; /** Maximum allowed for this transaction */ maxAllowed?: bigint; /** Remaining session budget */ sessionRemaining?: bigint; } /** Record of a completed payment for budget tracking */ interface SpendRecord { amount: bigint; service: string; timestamp: number; } /** Manages spending limits based on service reputation. * * Usage: * ```ts * const budget = new BudgetManager({ maxPerSession: 10_000_000n }); * const check = budget.checkBudget(amount, serviceReputation); * if (!check.allowed) throw new Error(check.reason); * // ... make payment ... * budget.recordSpend(amount, serviceUrl); * ``` */ export declare class BudgetManager { private static readonly MAX_HISTORY; private readonly _tiers; private readonly _maxPerSession; private readonly _enforce; private readonly _unknownLimit; private _sessionSpent; private _history; /** Promise-based mutex for atomic check-and-spend operations (C-1 fix) */ private _lock; constructor(config?: BudgetConfig); /** Acquire exclusive budget access for atomic check-and-spend. * * Serializes concurrent async operations so that checkBudget + recordSpend * cannot be interleaved by parallel payment flows (TOCTOU prevention). * * Audit #10: Timeout prevents permanent deadlock if fn() never resolves. * 120s allows for full smart_pay cycle: discovery + on-chain settlement + * UserOp bundling + retries + reputation feedback. * * @param fn - The async function to execute while holding the lock * @returns The return value of fn */ acquireBudgetLock(fn: () => Promise): Promise; /** Check if a payment is within budget. * * @param amount - Payment amount in token smallest unit * @param serviceReputation - Service's reputation score (0-100), or undefined if unknown * @returns Budget check result with allowed/denied and reason */ checkBudget(amount: bigint, serviceReputation?: number): BudgetCheckResult; /** Record a completed payment. * * History is capped at MAX_HISTORY entries (M-1 fix) to prevent unbounded growth. */ recordSpend(amount: bigint, service: string): void; /** Get total spent this session */ getSessionSpent(): bigint; /** Get remaining session budget */ getRemaining(): bigint; /** Get spending history */ getHistory(): readonly SpendRecord[]; /** Reset session spending (e.g., for a new session) */ reset(): void; /** Get the per-transaction limit for a given reputation score */ getLimitForReputation(reputation?: number): bigint; private _findTier; } /** Compute a reputation score (0-100) from on-chain summary data. * * Converts the raw summaryValue/summaryValueDecimals from the ERC-8004 * Reputation Registry into a 0-100 integer score suitable for budget tier lookup. */ export declare function reputationToScore(summaryValue: bigint, summaryValueDecimals: number): number; export {}; //# sourceMappingURL=budget.d.ts.map