From 647eae1e26fcab4617aa3dd1bb2bc1c37c42fa78 Mon Sep 17 00:00:00 2001 From: ArunBala-Bitgo Date: Wed, 19 Nov 2025 11:39:28 +0530 Subject: [PATCH] refactor: code optimisation for erc20 Ticket: WIN-7914 --- modules/bitgo/src/v2/coinFactory.ts | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/modules/bitgo/src/v2/coinFactory.ts b/modules/bitgo/src/v2/coinFactory.ts index 1bff1cf45f..a8799a2f85 100644 --- a/modules/bitgo/src/v2/coinFactory.ts +++ b/modules/bitgo/src/v2/coinFactory.ts @@ -38,6 +38,7 @@ import { TaoTokenConfig, PolyxTokenConfig, JettonTokenConfig, + NetworkType, } from '@bitgo/statics'; import { Ada, @@ -903,8 +904,26 @@ export function getCoinConstructor(coinName: string): CoinConstructor | undefine } } +export const buildEthLikeChainToTestnetMap = (): Record => { + const map: Record = {}; + + const enabledEvmCoins = ['ip']; + + // TODO: remove ip coin here and remove other evm coins from switch block, once changes are tested (Ticket: https://bitgoinc.atlassian.net/browse/WIN-7835) + coins.forEach((coin) => { + if (coin.network.type === NetworkType.TESTNET && !coin.isToken && enabledEvmCoins.includes(coin.family)) { + if (coins.get(coin.family)?.features.includes(CoinFeature.SUPPORTS_ERC20)) { + map[coin.family] = `${coin.name}`; + } + } + }); + + return map; +}; + // TODO: add IP token here and test changes (Ticket: https://bitgoinc.atlassian.net/browse/WIN-7835) -const ethLikeChainToTestnetMap: Record = {}; +const ethLikeChainToTestnetMap: Record = buildEthLikeChainToTestnetMap(); + export function getTokenConstructor(tokenConfig: TokenConfig): CoinConstructor | undefined { if (tokenConfig.coin in ethLikeChainToTestnetMap) { return EthLikeErc20Token.createTokenConstructor(tokenConfig as EthLikeTokenConfig, {