Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 25 additions & 2 deletions modules/statics/src/coins.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,10 @@ import {
erc20Token,
} from './account';
import { ofcToken } from './ofc';
import { BaseCoin } from './base';
import { BaseCoin, CoinFeature } from './base';
import { AmsTokenConfig, TrimmedAmsTokenConfig } from './tokenConfig';
import { CoinMap } from './map';
import { Networks } from './networks';
import { Networks, NetworkType } from './networks';
import { networkFeatureMapForTokens } from './networkFeatureMapForTokens';
import { ofcErc20Coins, tOfcErc20Coins } from './coins/ofcErc20Coins';
import { ofcCoins } from './coins/ofcCoins';
Expand All @@ -47,6 +47,23 @@ export const coins = CoinMap.fromCoins([
...botOfcTokens,
]);

// Build a map of ERC20-supporting chain family names to their mainnet coin names
// Maps family -> coin name (e.g., 'ip' -> 'ip')
const erc20ChainToNameMap: Record<string, string> = {};

// 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)
const enabledEvmCoins = ['ip'];
allCoinsAndTokens.forEach((coin) => {
if (
coin.features.includes(CoinFeature.SUPPORTS_ERC20) &&
coin.network.type === NetworkType.MAINNET &&
!coin.isToken &&
enabledEvmCoins.includes(coin.family)
) {
erc20ChainToNameMap[coin.family] = coin.name;
}
});

export function createToken(token: AmsTokenConfig): Readonly<BaseCoin> | undefined {
const initializerMap: Record<string, unknown> = {
algo: algoToken,
Expand Down Expand Up @@ -83,6 +100,11 @@ export function createToken(token: AmsTokenConfig): Readonly<BaseCoin> | undefin
ton: jettonToken,
};

// dynamically add erc20 token initializers for eth like chains to the initializer map
Object.keys(erc20ChainToNameMap).forEach((key) => {
initializerMap[key] = erc20Token;
});

//return the BaseCoin from default coin map if present
if (isCoinPresentInCoinMap({ ...token })) {
if (coins.has(token.name)) {
Expand Down Expand Up @@ -130,6 +152,7 @@ export function createToken(token: AmsTokenConfig): Readonly<BaseCoin> | undefin
case 'opeth':
case 'polygon':
case 'trx':
case erc20ChainToNameMap[family]:
return initializer(
...commonArgs.slice(0, 4), // id, name, fullName, decimalPlaces
token.contractAddress || token.tokenAddress, // contractAddress
Expand Down