import { ILogger } from "../types/logger.js"; import { Token } from "../../model/primitives.js"; import { AddressMap } from "../utils/AddressMap.js"; import { MulticallBatch } from "../utils/viem/executeMulticallBatches.js"; import { Asset } from "./types.js"; import "../utils/index.js"; import { PhantomTokenMeta, RWATokenMeta, TokenMetaData } from "./token-types.js"; import { Address, Chain, PublicClient, Transport } from "viem"; //#region src/onchain/base/TokensMeta.d.ts /** * Options for {@link TokensMeta.formatBN}. **/ export interface FormatBNOptions { /** * Number of decimal places in the formatted output. **/ precision?: number; /** * When `true`, appends the token symbol to the formatted string. **/ symbol?: boolean; } /** * Source, target, and phantom token of a delayed redemption, used to rewrite * the phantom's display symbol as `"target redemption from source"`. **/ export interface RedemptionPhantomRename { /** * Redemption phantom token whose symbol is rewritten. **/ phantom: Address; /** * Token being redeemed (e.g. mGLOBAL, ACRED). **/ source: Address; /** * Token received when the redemption is claimed (e.g. USDC). **/ target: Address; } /** * Serializable snapshot of the token metadata registry. **/ export interface TokensMetaState { /** * Metadata of all known tokens. **/ tokens: TokenMetaData[]; /** * Tokens whose extended data (`contractType`, `serialize()`) was loaded, * so that the loaded/not-loaded distinction round-trips through hydration. **/ extendedLoaded: Address[]; } /** * Registry of token metadata (symbol, decimals, phantom type) keyed by address. * * Extends {@link AddressMap} with convenience accessors for formatting token * amounts and looking up tokens by symbol. * * Provides methods to lazy-load information about certain classes of tokens (e.g. phantom tokens) */ export declare class TokensMeta extends AddressMap { #private; constructor(client: PublicClient, logger?: ILogger); /** * Clears all token metadata **/ reset(): void; upsert(address: string, value: TokenMetaData | undefined): void; /** * Returns the display symbol for a token. * * This is not always the on-chain ERC-20 `symbol()`: curated pretty names * and redemption phantom tokens (`"target redemption from source"`) replace it. * * @param token - Token address. * @throws If the token is not in the registry. */ symbol(token: Address): string; /** * Returns the decimal count for a token. * @param token - Token address. * @throws If the token is not in the registry. */ decimals(token: Address): number; /** * Returns true if the token is a phantom token, throws if the token data is not loaded * @param t * @returns */ isPhantomToken(t: TokenMetaData): t is PhantomTokenMeta; /** * Returns underlying token of a phantom token, or the token itself if it is not a phantom token. * * @param token - Token address. * @throws If extended token data is not loaded, or a phantom token has no * serialized params. */ depositedToken(token: Address): Address; /** * Returns true if the token is a RWA underlying token, throws if the token data is not loaded * @param t * @returns */ isRWAUnderlying(t: TokenMetaData): t is RWATokenMeta; /** * Returns a map of all phantom tokens * Throws if token data is not loaded */ get phantomTokens(): AddressMap; /** * Returns a map of all RWA underlying tokens * Throws if token data is not loaded */ get rwaUnderlyings(): AddressMap; /** * Describes a token the way the shared read model does. * * @param address - Token address. * @throws If the token is not in the registry. */ mustGetToken(address: Address): Token; /** * Like {@link mustGetToken}, but returns `undefined` instead of throwing when the * token is not in the registry. * * @param address - Token address. */ getToken(address: Address): Token | undefined; /** * The token an RWA wrapper holds, or the token itself when it is not one. * * An RWA market borrows a compliance wrapper (e.g. `dcUSDC`) that converts * one-for-one with the token behind it (`USDC`), and only that token means * anything to a reader. Pricing still goes through the wrapper, which is what * a market's oracle knows. * * @param token - Token address, wrapper or not. */ unwrapRWA(token: Address): Address; /** * Rewrites display symbols of redemption phantom tokens to * `"${target} redemption from ${source}"`. * * @param renames - Phantom / source / target address triples. **/ renameRedemptionPhantoms(renames: RedemptionPhantomRename[]): void; /** * Formats a raw token amount into a human-readable decimal string, * dividing by `10^decimals` for the token. * * Accepts either an {@link Asset} object or a separate `(token, amount)` pair. * * @param asset - Asset object containing `token` address and `balance`. * @param options - Formatting options. */ formatBN(asset: Asset, options?: FormatBNOptions): string; /** * @param token - Token address. * @param amount - Raw amount (in smallest unit). * @param options - Formatting options. */ formatBN(token: Address, amount: number | bigint | string | undefined, options?: FormatBNOptions): string; /** * Finds a token by its symbol (e.g. `"USDC"`). * @param symbol - Case-sensitive ticker symbol. * @returns The matching metadata, or `undefined` if no token has this symbol. */ findBySymbol(symbol: string): TokenMetaData | undefined; /** * Finds a token by its symbol, throwing if not found. * @param symbol - Case-sensitive ticker symbol. * @throws If no token matches the symbol. */ mustFindBySymbol(symbol: string): TokenMetaData; /** * @internal * * Returns the multicall batch that loads extended token data (`contractType` * and `serialize()`) for the tokens that do not have it yet. Used by the SDK * to warm this cache together with other loaders in a single multicall. * * @param tokens - tokens to load data for, defaults to all tokens **/ getLoadTokenDataMulticall(...tokens: Address[]): MulticallBatch; /** * Loads token information about phantom tokens * In future other custom tokens types that do not have compressors might be handled here * * Tokens loaded during SDK attach or restored by {@link hydrate} are skipped, * so calling this after either is a no-op. * * @param tokens - tokens to load data for, defaults to all tokens */ loadTokenData(...tokens: Address[]): Promise; /** * Serializable snapshot of all token metadata, suitable for hydration. **/ get state(): TokensMetaState; /** * Restores token metadata from a previously serialized snapshot, * bypassing on-chain reads. * * Entries are merged into the ones already registered by markets, zappers and * the RWA registry (see {@link upsert}), so the snapshot must be applied last * for its augmented fields to win. * * @param state - Token metadata snapshot. **/ hydrate(state: TokensMetaState): void; } //#endregion