From cb78d0fcaee4f6f745ab88f388de264f6ae935c4 Mon Sep 17 00:00:00 2001 From: Manas Ladha Date: Fri, 29 May 2026 17:17:36 +0530 Subject: [PATCH] feat(statics): add getTokenFeatures helper for AMS token feature diffs `getTokenFeatures(family, additionalFeatures?, excludedFeatures?)` resolves the final feature list for a token: the family's default token features (via the existing `getNetworkFeatures` lookup) plus `additionalFeatures`, minus `excludedFeatures`. Both diff params default to `[]`. Consumed by the generated `build/botTokens.ts` in BitGoJS once the AMS bot token generator is switched to call AMS with `features=false` (AMS already returns the add/excl diff in that mode). Keeps the generated file a single `getTokenFeatures(...)` call per token instead of inline `new Set` / `.filter` expressions. TICKET: CSHLD-935 Co-Authored-By: Claude Opus 4.7 (1M context) --- modules/statics/src/index.ts | 7 ++++++- modules/statics/src/networkFeatureMapForTokens.ts | 15 +++++++++++++++ 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/modules/statics/src/index.ts b/modules/statics/src/index.ts index 55be769460..c2beb7d678 100644 --- a/modules/statics/src/index.ts +++ b/modules/statics/src/index.ts @@ -41,7 +41,12 @@ export { Erc7984Coin, } from './account'; export { CoinMap } from './map'; -export { networkFeatureMapForTokens, registerNetworkFeatures, getNetworkFeatures } from './networkFeatureMapForTokens'; +export { + networkFeatureMapForTokens, + registerNetworkFeatures, + getNetworkFeatures, + getTokenFeatures, +} from './networkFeatureMapForTokens'; export { generateErc20Coin, generateTestErc20Coin, diff --git a/modules/statics/src/networkFeatureMapForTokens.ts b/modules/statics/src/networkFeatureMapForTokens.ts index 38ad9d4b67..a2ac1d502d 100644 --- a/modules/statics/src/networkFeatureMapForTokens.ts +++ b/modules/statics/src/networkFeatureMapForTokens.ts @@ -29,6 +29,21 @@ 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> = { algo: AccountCoin.DEFAULT_FEATURES, apt: APT_FEATURES,