From e29efe1371af984fad0e7e93ec854828ad86df9e Mon Sep 17 00:00:00 2001 From: Nayan Das Date: Tue, 10 Nov 2026 06:47:40 +0530 Subject: [PATCH] fix(statics): pre-populate networkFeatureMapForTokens for EVM families Ticket: CECHO-2706 --- modules/statics/src/index.ts | 1 + .../statics/src/networkFeatureMapForTokens.ts | 48 ++++++++++++++++--- modules/statics/test/unit/coins.ts | 31 ++++++------ 3 files changed, 60 insertions(+), 20 deletions(-) diff --git a/modules/statics/src/index.ts b/modules/statics/src/index.ts index 0e6c40ed513..d32f40ff2c8 100644 --- a/modules/statics/src/index.ts +++ b/modules/statics/src/index.ts @@ -62,6 +62,7 @@ export { getTokenFeatures, EVM_TOKEN_FEATURES, EVM_TOKEN_FEATURES_NON_EIP1559, + STATIC_NETWORK_FEATURE_FAMILIES, } from './networkFeatureMapForTokens'; export { generateErc20Coin, diff --git a/modules/statics/src/networkFeatureMapForTokens.ts b/modules/statics/src/networkFeatureMapForTokens.ts index 8c16e9f93fc..1c15ccca09f 100644 --- a/modules/statics/src/networkFeatureMapForTokens.ts +++ b/modules/statics/src/networkFeatureMapForTokens.ts @@ -80,36 +80,72 @@ export function getTokenFeatures( } 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, - baseeth: EVM_TOKEN_FEATURES, eos: AccountCoin.DEFAULT_FEATURES, - // flow, okbxlayer and hoodeth must be static: botTokens.ts resolves getTokenFeatures at module load, - // before registerErc20Families backfills EVM families in coins.ts. flow: EVM_TOKEN_FEATURES, - okbxlayer: EVM_TOKEN_FEATURES, - hoodeth: EVM_TOKEN_FEATURES, gasevm: EVM_TOKEN_FEATURES, + h: EVM_TOKEN_FEATURES, hbar: AccountCoin.DEFAULT_FEATURES, - opeth: [...AccountCoin.DEFAULT_FEATURES, CoinFeature.EIP1559], + 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, + 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])) +); diff --git a/modules/statics/test/unit/coins.ts b/modules/statics/test/unit/coins.ts index a213a0d6d4e..7dbd053cbfa 100644 --- a/modules/statics/test/unit/coins.ts +++ b/modules/statics/test/unit/coins.ts @@ -25,6 +25,7 @@ import { NetworkType, registerNetwork, SolCoin, + STATIC_NETWORK_FEATURE_FAMILIES, SuiCoin, tokens, TrimmedAmsTokenConfig, @@ -1899,26 +1900,28 @@ describe('create token map using config details', () => { }); describe('getNetworkFeatures EVM fallback (drift guard)', () => { - it('should return EVM_TOKEN_FEATURES for every mainnet family that supports ERC20 but has no explicit entry in networkFeatureMapForTokens', () => { - const erc20Families = new Set( - allCoinsAndTokens - .filter( - (coin) => - !coin.isToken && - coin.network.type === NetworkType.MAINNET && - coin.features.includes(CoinFeature.SUPPORTS_ERC20) - ) - .map((coin) => coin.family) + it('should statically include every mainnet SUPPORTS_ERC20 family in networkFeatureMapForTokens before registerErc20Families runs', () => { + const erc20Coins = allCoinsAndTokens.filter( + (coin) => + !coin.isToken && coin.network.type === NetworkType.MAINNET && coin.features.includes(CoinFeature.SUPPORTS_ERC20) ); - erc20Families.forEach((family) => { - const features = getNetworkFeatures(family); + erc20Coins.forEach((coin) => { + Boolean(STATIC_NETWORK_FEATURE_FAMILIES[coin.family]).should.eql( + true, + `Expected ${coin.family} (CoinFeature.SUPPORTS_ERC20) to be statically listed in networkFeatureMapForTokens so botTokens.ts can resolve getTokenFeatures('${coin.family}') at module load` + ); + const features = getNetworkFeatures(coin.family); features?.should.not.be.undefined(); + const expected = coin.features.includes(CoinFeature.EIP1559) + ? EVM_TOKEN_FEATURES + : EVM_TOKEN_FEATURES_NON_EIP1559; + features?.should.deepEqual(expected); }); - // baseeth is the concrete gap this fallback closes: it has no hand-written entry in - // networkFeatureMapForTokens, but its base coin supports ERC20. getNetworkFeatures('baseeth')?.should.deepEqual(EVM_TOKEN_FEATURES); + getNetworkFeatures('chiliz')?.should.deepEqual(EVM_TOKEN_FEATURES); + getNetworkFeatures('prividiumeth')?.should.deepEqual(EVM_TOKEN_FEATURES_NON_EIP1559); }); });