import type { Context } from 'hono'; import * as z from 'zod/mini'; import type * as App from '../App.js'; import * as Db from '../db/Db.js'; import * as core_VerifiedTokens from '../db/tables/verifiedTokens.js'; import * as Schema from './Schema.js'; /** Chain id covered by the curated verified-token lists. */ export type ChainId = z.output; /** Schema for a chain's verified token list (validated at the write boundary). */ export declare const Data: z.ZodMiniArray, z.ZodMiniTransform<`0x${string}`, `0x${string}`>>; currency: z.ZodMiniString; decimals: z.ZodMiniNumber; id: z.ZodMiniString; logoUri: z.ZodMiniOptional; name: z.ZodMiniString; symbol: z.ZodMiniString; }, z.core.$strip>>; type SnapshotToken = z.output[number]; /** A single curated verified TIP-20 token accepted by write/compile APIs. */ export type Token = Omit & { id?: string | undefined; }; /** Verified-token input accepted before the stable resource id is derived. */ export type TokenInput = Token; /** * A compiled, indexed snapshot of one chain's curated verified-token list. * Fetched once per request and threaded into per-row enrichment so lookups are * plain in-memory map reads rather than repeated array scans. */ export type Snapshot = { /** Tokens indexed by lowercased contract address (membership + lookup). */ byAddress: ReadonlyMap; /** Tokens grouped by lowercased display currency, preserving list order. */ byCurrency: ReadonlyMap; /** Tokens indexed by lowercased ticker symbol. */ bySymbol: ReadonlyMap; /** Chain the snapshot belongs to. */ chainId: number; /** Sorted, distinct display currencies present in the list. */ currencies: readonly string[]; /** The curated tokens in their canonical order. */ list: readonly SnapshotToken[]; /** ISO timestamp of the snapshot's last update. */ updatedAt: string; /** Opaque snapshot version; changes whenever the list changes. */ version: string; }; /** Compiles a raw token list into an indexed {@link Snapshot}. */ export declare function compile(options: compile.Options): Snapshot; export declare namespace compile { /** Options for {@link compile}. */ type Options = { /** Chain the tokens belong to. */ chainId: number; /** Curated tokens in canonical order. */ tokens: readonly TokenInput[]; /** ISO timestamp of the snapshot's last update. */ updatedAt: string; /** Opaque snapshot version. */ version: string; }; } /** A chain's list-level metadata (the "head" the cache compares against). */ export type Head = core_VerifiedTokens.Meta; /** * Reads and compiles a chain's current verified list. Returns `null` when the * chain has none. */ export declare function read(db: Db.Db, chainId: ChainId): Promise; /** * Appends a verified token to a chain's list and publishes a new snapshot. * Throws on a duplicate address or (case-insensitive) symbol. */ export declare function create(db: Db.Db, input: create.Input): Promise; export declare namespace create { /** Input for {@link create}. */ type Input = { /** TIP-20 token contract address (normalized to lowercase). */ address: string; /** Chain the token belongs to. */ chainId: ChainId; /** Display currency, e.g. `USD`. */ currency: string; /** Decimal precision. */ decimals: number; /** Curated HTTPS logo URL. Omit when no curated logo is set. */ logoUri?: string | undefined; /** Display name. */ name: string; /** Ticker symbol. */ symbol: string; }; /** Result of {@link create}. */ type Result = { /** The published snapshot reflecting the new token. */ snapshot: Snapshot; /** The created token. */ token: Token; }; } /** * Partially updates a verified token in place (preserving list order) and * publishes a new snapshot. Throws {@link NotFoundError} when the address is * absent, and the uniqueness errors when an edit collides with another entry. */ export declare function patch(db: Db.Db, chainId: ChainId, address: string, input: patch.Input, options?: patch.Options): Promise; export declare namespace patch { /** Patchable fields for {@link patch} (address and chain are immutable). */ type Input = { /** Display currency, e.g. `USD`. */ currency?: string | undefined; /** Decimal precision. */ decimals?: number | undefined; /** Curated HTTPS logo URL. Omitting keeps the current value (use `replace` to clear). */ logoUri?: string | undefined; /** Display name. */ name?: string | undefined; /** Ticker symbol. */ symbol?: string | undefined; }; /** Options for {@link patch}. */ type Options = { /** Expected current version for optimistic concurrency (best-effort). */ ifMatch?: string | undefined; }; } /** * Removes a verified token from a chain's list and publishes a new snapshot. * Throws {@link NotFoundError} when the address is absent. */ export declare function remove(db: Db.Db, chainId: ChainId, address: string, options?: patch.Options): Promise; export declare namespace remove { /** Result of {@link remove}. */ type Result = { /** The published snapshot reflecting the removal. */ snapshot: Snapshot; }; } /** * Replaces a chain's entire verified list and publishes a new snapshot. Used to * bulk-load the initial list and to roll back to a previous one. */ export declare function replace(db: Db.Db, chainId: ChainId, tokens: readonly TokenInput[], options?: patch.Options): Promise; /** * Primes this isolate's in-memory snapshot for a chain. The writer isolate calls * this after a successful publish so the next read reflects the write without * waiting on store propagation (read-your-write). */ export declare function prime(chainId: ChainId, snapshot: Snapshot): void; /** * Returns the compiled verified-token {@link Snapshot} for a chain. * * When the verified-tokens feature is unconfigured, serves an empty snapshot. * When configured, serves a per-isolate snapshot backed by the app database, * refreshed on a soft TTL: fresh lookups do zero database I/O; soft-stale * lookups return the current snapshot immediately and refresh in the background * (single-flight, head-only unless the version changed); a cold isolate loads * from the database (an empty snapshot when no head exists). */ export declare function snapshot(c: Context, chainId: ChainId): Promise; /** * Well-known display currencies surfaced as an OpenAPI `examples` hint on * filters that accept any currency string but want to populate the well-known * ones in Swagger/Stoplight/Scalar dropdowns. Static hint only — the * authoritative set is `Snapshot.currencies` from the live store. */ export declare const currencies: string[]; /** Thrown when a write would introduce a duplicate address on a chain. */ export declare class DuplicateAddressError extends Error { name: string; constructor(options: { address: string; chainId: number; }); } /** * Thrown when a write would introduce a duplicate (case-insensitive) symbol on a * chain — which would make `GET /tokens/:symbol` ambiguous. */ export declare class DuplicateSymbolError extends Error { name: string; constructor(options: { chainId: number; symbol: string; }); } /** Thrown when a patch/delete targets an address not in a chain's verified list. */ export declare class NotFoundError extends Error { name: string; constructor(options: { address: string; chainId: number; }); } /** * Thrown when an `If-Match` precondition does not equal the current head version * (best-effort optimistic concurrency). */ export declare class VersionMismatchError extends Error { name: string; constructor(options: { actual: string; chainId: number; expected: string; }); } export {}; //# sourceMappingURL=VerifiedTokens.d.ts.map