import { type Address, type Client } from 'viem'; import * as Db from '../../db/Db.js'; import * as SponsoredTransactions from '../../db/tables/sponsoredTransactions.js'; import * as Tidx from '../../internal/Tidx.js'; import * as Viem from '../../internal/Viem.js'; /** * Runs one finalization pass over pending sponsored transactions: rows with a * receipt finalize with the actual fee (`gasUsed × effectiveGasPrice`, in * fee-token base units); rows still unmined past the pending TTL fail, as do * hash-less fill intents the TTL outlives. Rows whose receipt lookup errors * persist past the error TTL fail so they cannot monopolize every batch. * * @param db - The database holding `sponsored_transactions`. * @param options - Finalization options. * @returns Counters for the pass. */ export declare function finalize(db: Db.Db, options: finalize.Options): Promise; export declare namespace finalize { /** Options for {@link finalize}. */ type Options = { /** Maximum pending rows processed per pass. @default 100 */ batchSize?: number | undefined; /** Client resolver keyed by the row's chain id. */ getClient: (chainId: number) => Client; /** Clock; injectable for tests. */ now?: (() => Date) | undefined; /** Age after which an unmined sponsorship fails. @default 1 hour */ pendingTtlMs?: number | undefined; /** Age after which repeated receipt lookup errors fail a row. @default 24 hours */ receiptErrorTtlMs?: number | undefined; }; /** Counters returned by one finalization pass. */ type Result = { /** Receipt lookup errors that prevented finalization work. */ errors: number; /** Rows marked failed (unmined past the pending TTL). */ failed: number; /** Rows finalized with an actual fee. */ finalized: number; /** Rows left pending (unmined, or receipt lookup errored within the error TTL). */ pending: number; }; } /** * Runs one reconciliation pass over pending fill intents (rows with no * transaction hash): fetches the fee payer's recent on-chain transactions * from TIDX, recomputes each candidate's fee-payer sign payload, and fills * matching intents' hashes so the receipt pass can finalize them. Query or * candidate errors leave intents for the next pass. * * @param db - The database holding `sponsored_transactions`. * @param options - Reconciliation options. * @returns Counters for the pass. */ export declare function reconcile(db: Db.Db, options: reconcile.Options): Promise; export declare namespace reconcile { /** Options for {@link reconcile}. */ type Options = { /** Maximum intents considered per pass. @default 100 */ batchSize?: number | undefined; /** Maximum on-chain candidates fetched per chain per pass. @default 500 */ candidateCap?: number | undefined; /** How long failed intents remain reconciliation candidates. @default 24 hours */ failedIntentTtlMs?: number | undefined; /** Fee payer address whose on-chain transactions are candidates. */ feePayer: Address; /** Client resolver keyed by the intent's chain id. */ getClient: (chainId: number) => Client; /** TIDX client resolver keyed by the intent's chain id. */ getTidx: (chainId: number) => Tidx.Client; /** Resolves the current period spend limit before reopening a failed intent. */ limitFor?: ((intent: SponsoredTransactions.Record) => Promise) | undefined; /** Lookback slack before the oldest intent's creation. @default 2 minutes */ skewMs?: number | undefined; }; /** Counters returned by one reconciliation pass. */ type Result = { /** Dependency or candidate errors that prevented reconciliation work. */ errors: number; /** Intents matched to an on-chain transaction. */ matched: number; /** On-chain candidates inspected. */ scanned: number; }; } /** * Builds a scheduled sponsorship finalizer bound to a database and RPC config. * A host runtime drives {@link createFinalizer.Finalizer.tick} on a timer (a * Cloudflare `scheduled` cron handler, a self-host `setInterval`, …); each * tick reconciles fill intents (when `feePayer` + `tidx` are configured) and * runs one {@link finalize} pass, with memoized per-chain clients. */ export declare function createFinalizer(options: createFinalizer.Options): createFinalizer.Finalizer; export declare namespace createFinalizer { /** Options for {@link createFinalizer}. */ type Options = Pick & { /** Database holding sponsorship rows, or a factory resolved per tick (Workers/Hyperdrive). */ db: Db.Source; /** Default chain id for the TIDX client resolver. */ defaultChainId?: Viem.ChainId | undefined; /** Fee payer address whose on-chain transactions reconcile fill intents; omit to skip reconciliation. */ feePayer?: Address | undefined; /** RPC options for the receipt-lookup clients. */ rpc?: Viem.getClient.Rpc | undefined; /** TIDX query client options for intent reconciliation; omit to skip reconciliation. */ tidx?: Tidx.getClient.Tidx | undefined; }; /** A scheduled sponsorship finalizer. */ type Finalizer = { /** Runs one reconcile + finalize pass. */ tick(): Promise; }; } //# sourceMappingURL=Sponsorships.d.ts.map