Skip to content

Conversation

@ArunBala-Bitgo
Copy link
Contributor

@ArunBala-Bitgo ArunBala-Bitgo commented Nov 19, 2025

Ticket: WIN-7914

Optimisation:

coinFactory.ts - Added map-based routing for EthLike chains

Screenshot 2025-11-19 at 11 41 34 AM

Adding to the above map would reduce code bloat by decreasing the size of the switch case. Around 6 chains from the switch case would be removed and added to the map, and future coins would only be added to the map, reducing multiple lines of code and code bloat for each chain.

tokenConfig.ts - Currently has repetitive token config functions

Screenshot 2025-11-21 at 4 32 46 PM

the above generic method reduces around 120 lines by removing all the token specific methods:

function getOgTokenConfig(coin: EthLikeERC20Token): EthLikeTokenConfig {
  return {
    type: coin.name,
    coin: coin.network.type === NetworkType.MAINNET ? 'og' : 'tog',
    network: coin.network.type === NetworkType.MAINNET ? 'Mainnet' : 'Testnet',
    name: coin.fullName,
    tokenContractAddress: coin.contractAddress.toString().toLowerCase(),
    decimalPlaces: coin.decimalPlaces,
  };
}
const getFormattedOgTokens = (customCoinMap = coins) =>
  customCoinMap.reduce((acc: EthLikeTokenConfig[], coin) => {
    if (coin instanceof EthLikeERC20Token && (coin.name.includes('og:') || coin.name.includes('tog:'))) {
      acc.push(getOgTokenConfig(coin));
    }
    return acc;
  }, []);

function getSeievmTokenConfig(coin: EthLikeERC20Token): EthLikeTokenConfig {
  return {
    type: coin.name,
    coin: coin.network.type === NetworkType.MAINNET ? 'seievm' : 'tseievm',
    network: coin.network.type === NetworkType.MAINNET ? 'Mainnet' : 'Testnet',
    name: coin.fullName,
    tokenContractAddress: coin.contractAddress.toString().toLowerCase(),
    decimalPlaces: coin.decimalPlaces,
  };
}
const getFormattedSeievmTokens = (customCoinMap = coins) =>
  customCoinMap.reduce((acc: EthLikeTokenConfig[], coin) => {
    if (coin instanceof EthLikeERC20Token && (coin.name.includes('seievm:') || coin.name.includes('tseievm:'))) {
      acc.push(getSeievmTokenConfig(coin));
    }
    return acc;
  }, []);

This avoids code repetition, keeping the code clean and preventing code bloat.

Also extracted TokenNetwork interface and created reusable type definition for token network structure, created getFormattedTokensByNetwork helper and consolidated mainnet/testnet token formatting logic

Before & After
Before (Token Configuration)
Screenshot 2025-11-20 at 9 51 12 AM

After (Token Configuration)
Screenshot 2025-11-20 at 9 51 32 AM

Test case results:

Screenshot 2025-11-21 at 10 44 49 PM

@ArunBala-Bitgo ArunBala-Bitgo force-pushed the WIN-7914-1 branch 4 times, most recently from 0bbc64f to c0491b5 Compare November 19, 2025 11:41
@ArunBala-Bitgo ArunBala-Bitgo marked this pull request as ready for review November 20, 2025 05:09
@ArunBala-Bitgo ArunBala-Bitgo requested review from a team as code owners November 20, 2025 05:09
Taseen08
Taseen08 previously approved these changes Nov 20, 2025
Copy link
Contributor

@Taseen08 Taseen08 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm from WP, coins team review would be more relevant

Copy link
Contributor

@pritam-gembali pritam-gembali left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good effort to simplify. Let's do it the right way please

Taseen08
Taseen08 previously approved these changes Nov 20, 2025
@ArunBala-Bitgo ArunBala-Bitgo force-pushed the WIN-7914-1 branch 3 times, most recently from 5c25d02 to e58fc9e Compare November 21, 2025 11:00
@ArunBala-Bitgo ArunBala-Bitgo changed the title feat: code optimisation for erc20 refactor: code optimisation for erc20 Nov 21, 2025
@ArunBala-Bitgo ArunBala-Bitgo force-pushed the WIN-7914-1 branch 2 times, most recently from 3dda2b1 to d325b85 Compare November 21, 2025 14:54
Copy link
Contributor

@mmcshinsky-bitgo mmcshinsky-bitgo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we add tests to make sure there aren't any regressions to these changes?

Copy link
Contributor

@Taseen08 Taseen08 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can we address the comment regarding test cov?

@ArunBala-Bitgo
Copy link
Contributor Author

ArunBala-Bitgo commented Nov 21, 2025

Can we add tests to make sure there aren't any regressions to these changes?

Added test cases for all the newly added methods and to ensure it doesn't affect any existing data:

Screenshot 2025-11-21 at 10 44 49 PM

Copy link
Contributor

@Taseen08 Taseen08 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm

@ArunBala-Bitgo ArunBala-Bitgo dismissed pritam-gembali’s stale review November 24, 2025 06:13

concerns addressed - EthLikeErc20Token is used for evm coins and ERC20Token instance is already being used by eth coin

@ArunBala-Bitgo ArunBala-Bitgo merged commit 001c662 into master Nov 24, 2025
14 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants