@@ -9,7 +9,8 @@ import { Near, TNear, Nep141Token } from '@bitgo/sdk-coin-near';
99import { SolToken } from '@bitgo/sdk-coin-sol' ;
1010import { TrxToken } from '@bitgo/sdk-coin-trx' ;
1111import { CoinFactory , CoinConstructor } from '@bitgo/sdk-core' ;
12- import { EthLikeErc20Token } from '@bitgo/sdk-coin-evm' ;
12+ import { EthLikeErc20Token , EthLikeErc721Token } from '@bitgo/sdk-coin-evm' ;
13+
1314import {
1415 CoinMap ,
1516 coins ,
@@ -38,7 +39,6 @@ import {
3839 TaoTokenConfig ,
3940 PolyxTokenConfig ,
4041 JettonTokenConfig ,
41- NetworkType ,
4242} from '@bitgo/statics' ;
4343import {
4444 Ada ,
@@ -569,6 +569,20 @@ export function registerCoinConstructors(coinFactory: CoinFactory, coinMap: Coin
569569 coinFactory . register ( name , coinConstructor ) ;
570570 } ) ;
571571 } ) ;
572+
573+ // Generic ERC721 token registration for coins with SUPPORTS_ERC721 feature
574+ coins
575+ . filter ( ( coin ) => coin . features . includes ( CoinFeature . SUPPORTS_ERC721 ) && ! coin . isToken )
576+ . forEach ( ( coin ) => {
577+ const coinNames = {
578+ Mainnet : `${ coin . name } ` ,
579+ Testnet : `t${ coin . name } ` ,
580+ } ;
581+
582+ EthLikeErc721Token . createTokenConstructors ( coinNames ) . forEach ( ( { name, coinConstructor } ) => {
583+ coinFactory . register ( name , coinConstructor ) ;
584+ } ) ;
585+ } ) ;
572586}
573587
574588export function getCoinConstructor ( coinName : string ) : CoinConstructor | undefined {
@@ -916,45 +930,31 @@ export function getCoinConstructor(coinName: string): CoinConstructor | undefine
916930 }
917931}
918932
919- export const buildEthLikeChainToTestnetMap = ( ) : {
920- mainnetToTestnetMap : Record < string , string > ;
921- testnetToMainnetMap : Record < string , string > ;
922- } => {
923- const testnetToMainnetMap : Record < string , string > = { } ;
924- const mainnetToTestnetMap : Record < string , string > = { } ;
925-
926- const enabledEvmCoins = [ 'ip' , 'hypeevm' , 'plume' ] ;
927-
928- // TODO: remove ip and hypeeevm coins here and remove other evm coins from switch block, once changes are tested (Ticket: https://bitgoinc.atlassian.net/browse/WIN-7835)
929- coins . forEach ( ( coin ) => {
930- if ( coin . network . type === NetworkType . TESTNET && ! coin . isToken && enabledEvmCoins . includes ( coin . family ) ) {
931- if ( coins . get ( coin . family ) ?. features . includes ( CoinFeature . SUPPORTS_ERC20 ) ) {
932- mainnetToTestnetMap [ coin . family ] = `${ coin . name } ` ;
933- testnetToMainnetMap [ coin . name ] = `${ coin . family } ` ;
934- }
935- }
936- } ) ;
937-
938- return { mainnetToTestnetMap, testnetToMainnetMap } ;
939- } ;
940-
941- const { mainnetToTestnetMap, testnetToMainnetMap } = buildEthLikeChainToTestnetMap ( ) ;
942-
943933export function getTokenConstructor ( tokenConfig : TokenConfig ) : CoinConstructor | undefined {
944- const testnetCoin = mainnetToTestnetMap [ tokenConfig . coin ] ;
945- if ( testnetCoin ) {
934+ const coin = coins . get ( tokenConfig . coin ) ;
935+
936+ if (
937+ 'network' in tokenConfig &&
938+ tokenConfig . network === 'Mainnet' &&
939+ coin ?. features . includes ( CoinFeature . SUPPORTS_ERC20 )
940+ ) {
946941 return EthLikeErc20Token . createTokenConstructor ( tokenConfig as EthLikeTokenConfig , {
947942 Mainnet : tokenConfig . coin ,
948- Testnet : testnetCoin ,
943+ Testnet : `t ${ tokenConfig . coin } ` ,
949944 } ) ;
950945 }
951- const mainnetCoin = testnetToMainnetMap [ tokenConfig . coin ] ;
952- if ( mainnetCoin ) {
953- return EthLikeErc20Token . createTokenConstructor ( tokenConfig as EthLikeTokenConfig , {
954- Mainnet : mainnetCoin ,
955- Testnet : tokenConfig . coin ,
946+
947+ if (
948+ 'network' in tokenConfig &&
949+ tokenConfig . network === 'Mainnet' &&
950+ coin ?. features . includes ( CoinFeature . SUPPORTS_ERC721 )
951+ ) {
952+ return EthLikeErc721Token . createTokenConstructor ( tokenConfig as EthLikeTokenConfig , {
953+ Mainnet : tokenConfig . coin ,
954+ Testnet : `t${ tokenConfig . coin } ` ,
956955 } ) ;
957956 }
957+
958958 switch ( tokenConfig . coin ) {
959959 case 'eth' :
960960 case 'hteth' :
0 commit comments