import { AccountCoin } from './account'; import { CoinFamily, CoinFeature } from './base'; import { ADA_TOKEN_FEATURES, APT_FEATURES, BSC_TOKEN_FEATURES, CANTON_TOKEN_FEATURES, EVM_FEATURES, POLYGON_TOKEN_FEATURES, POLYX_TOKEN_FEATURES, SOL_TOKEN_FEATURES, STX_TOKEN_FEATURES, SUI_TOKEN_FEATURES, TAO_TOKEN_FEATURES, } from './coinFeatures'; const dynamicNetworkFeaturesMap = new Map(); /** Register default token features for a dynamically onboarded chain family. */ export function registerNetworkFeatures(family: string, features: CoinFeature[]): void { dynamicNetworkFeaturesMap.set(family, features); } /** Default token feature set shared by "plain" EVM-compatible chain families (no bespoke features). */ export const EVM_TOKEN_FEATURES: CoinFeature[] = [ ...EVM_FEATURES, CoinFeature.SHARED_EVM_SIGNING, CoinFeature.SHARED_EVM_SDK, CoinFeature.EVM_COMPATIBLE_IMS, CoinFeature.EVM_COMPATIBLE_UI, CoinFeature.EVM_COMPATIBLE_WP, CoinFeature.SUPPORTS_ERC20, ]; /** Same as EVM_TOKEN_FEATURES, minus EIP1559, for EVM-compatible families that don't support it (e.g. xdc). */ export const EVM_TOKEN_FEATURES_NON_EIP1559: CoinFeature[] = EVM_TOKEN_FEATURES.filter( (feature) => feature !== CoinFeature.EIP1559 ); /** * Populate networkFeatureMapForTokens for every family whose base coin carries * CoinFeature.SUPPORTS_ERC20 and isn't already explicitly listed below, using EVM_TOKEN_FEATURES * (or its non-EIP1559 variant, mirroring the base coin's own EIP1559 support). Called once from * coins.ts (which has access to the full coin map) so this module doesn't need to import it * directly (that would create a circular import: coins.ts -> networkFeatureMapForTokens.ts -> * allCoinsAndTokens.ts -> coins/botTokens.ts -> networkFeatureMapForTokens.ts). */ export function registerErc20Families(families: Iterable<[family: string, supportsEip1559: boolean]>): void { for (const [family, supportsEip1559] of families) { if (!(family in networkFeatureMapForTokens)) { networkFeatureMapForTokens[family as CoinFamily] = supportsEip1559 ? EVM_TOKEN_FEATURES : EVM_TOKEN_FEATURES_NON_EIP1559; } } } /** * Look up token features for a family. * Checks the static map first (including entries backfilled by registerErc20Families), then the * dynamic map. Returns undefined if the family isn't recognized by either. */ export function getNetworkFeatures(family: string): CoinFeature[] | undefined { return networkFeatureMapForTokens[family as CoinFamily] ?? dynamicNetworkFeaturesMap.get(family); } /** * Resolve the final feature list for a token: the family's default token features * plus `additionalFeatures`, minus `excludedFeatures`. Used by generated bot-token * lists to apply the per-token diff returned by AMS (`features=false`). */ export function getTokenFeatures( family: string, additionalFeatures: CoinFeature[] = [], excludedFeatures: CoinFeature[] = [] ): CoinFeature[] { const base = getNetworkFeatures(family) ?? []; const excluded = new Set(excludedFeatures); return [...new Set([...base, ...additionalFeatures])].filter((f) => !excluded.has(f)); } export const networkFeatureMapForTokens: Partial> = { abstracteth: EVM_TOKEN_FEATURES, algo: AccountCoin.DEFAULT_FEATURES, apt: APT_FEATURES, arbeth: [...AccountCoin.DEFAULT_FEATURES, CoinFeature.EIP1559], arcusdc: EVM_TOKEN_FEATURES, avaxc: AccountCoin.DEFAULT_FEATURES, baseeth: EVM_TOKEN_FEATURES, bera: [...AccountCoin.DEFAULT_FEATURES, CoinFeature.EIP1559], bobaeth: EVM_TOKEN_FEATURES, bsc: BSC_TOKEN_FEATURES, canton: CANTON_TOKEN_FEATURES, celo: AccountCoin.DEFAULT_FEATURES, // All SUPPORTS_ERC20 EVM families must be present statically: botTokens.ts resolves // getTokenFeatures(family) at module load, before registerErc20Families runs in coins.ts. chiliz: EVM_TOKEN_FEATURES, codexeth: EVM_TOKEN_FEATURES, dogeos: EVM_TOKEN_FEATURES, eth: AccountCoin.DEFAULT_FEATURES, eos: AccountCoin.DEFAULT_FEATURES, flow: EVM_TOKEN_FEATURES, gasevm: EVM_TOKEN_FEATURES, h: EVM_TOKEN_FEATURES, hbar: AccountCoin.DEFAULT_FEATURES, hbarevm: EVM_TOKEN_FEATURES, hemieth: EVM_TOKEN_FEATURES, hoodeth: EVM_TOKEN_FEATURES, hppeth: EVM_TOKEN_FEATURES, hypeevm: EVM_TOKEN_FEATURES, inketh: EVM_TOKEN_FEATURES, ip: EVM_TOKEN_FEATURES, jovayeth: EVM_TOKEN_FEATURES, katanaeth: EVM_TOKEN_FEATURES, lineaeth: EVM_TOKEN_FEATURES, mantle: EVM_TOKEN_FEATURES, megaeth: EVM_TOKEN_FEATURES, // Monad tokens are AccountCoin-derived (MonERC20Token) and require account-model, which // EVM_TOKEN_FEATURES does not carry. Mirrors the default feature set of monErc20(). Without // this entry getTokenFeatures('mon') resolves to [] and a dynamically onboarded token is // built with only its supplied features, failing with MissingRequiredCoinFeatureError. mon: [...AccountCoin.DEFAULT_FEATURES, CoinFeature.EIP1559], morph: EVM_TOKEN_FEATURES, morpheth: EVM_TOKEN_FEATURES, og: EVM_TOKEN_FEATURES, okbxlayer: EVM_TOKEN_FEATURES, opeth: [...AccountCoin.DEFAULT_FEATURES, CoinFeature.EIP1559], polygon: POLYGON_TOKEN_FEATURES, prividiumeth: EVM_TOKEN_FEATURES_NON_EIP1559, scrolleth: EVM_TOKEN_FEATURES, seievm: EVM_TOKEN_FEATURES, sol: SOL_TOKEN_FEATURES, stx: STX_TOKEN_FEATURES, sui: SUI_TOKEN_FEATURES, tao: TAO_TOKEN_FEATURES, polyx: POLYX_TOKEN_FEATURES, trx: AccountCoin.DEFAULT_FEATURES, unieth: EVM_TOKEN_FEATURES, usdt0: EVM_TOKEN_FEATURES, xlm: AccountCoin.DEFAULT_FEATURES, xpl: EVM_TOKEN_FEATURES, xrp: AccountCoin.DEFAULT_FEATURES, xtzevm: EVM_TOKEN_FEATURES, zksyncera: EVM_TOKEN_FEATURES, ofc: [], ada: ADA_TOKEN_FEATURES, }; /** * Snapshot of families statically present in `networkFeatureMapForTokens` at module load * (before `registerErc20Families` runs in `coins.ts`). Used by unit tests to ensure every * `SUPPORTS_ERC20` family can resolve `getTokenFeatures(family)` when `botTokens.ts` is evaluated. */ export const STATIC_NETWORK_FEATURE_FAMILIES: Readonly> = Object.freeze( Object.fromEntries(Object.keys(networkFeatureMapForTokens).map((k) => [k, true as const])) );