import type * as Chain from './Chain.js' /** A token accepted or returned by a funding provider. */ export type Token = { /** Chain-specific token metadata keyed by CAIP-2 chain id. */ chains: Partial> /** Monetary denomination represented by the token. */ currency: string /** Human-readable token name. */ name: string /** Stable token segment used in quote identifiers. */ slug: string /** Short token ticker symbol. */ symbol: string } /** Chain-specific token metadata. */ export type ChainConfig = { /** Contract address, mint, or issuer address on the chain. */ address: string /** Number of decimal places used by the token on the chain. */ decimals: number /** Chain-specific token name override. */ name?: string | undefined /** Token standard on the chain. */ standard: string } /** A token resolved to one funding chain. */ export type Resolved = Omit & Omit & { /** Chain where the token exists. */ chain: Chain.Chain /** Human-readable token name for this chain. */ name: string } /** Creates a canonical funding token. */ export function from(options: token): token { return options } /** Resolves a funding token to its metadata on one chain. */ export function resolve(token: Token, chain: Chain.Chain): Resolved { const config = token.chains[chain.id] if (!config) throw new MissingChainError() const { chains: _chains, ...metadata } = token return { ...metadata, ...config, chain, name: config.name ?? token.name, } } /** Error thrown when a token is not configured for a selected chain. */ export class MissingChainError extends Error { override name = 'Funding.Token.MissingChainError' }