@@ -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 ,
@@ -567,6 +567,20 @@ export function registerCoinConstructors(coinFactory: CoinFactory, coinMap: Coin
567567 coinFactory . register ( name , coinConstructor ) ;
568568 } ) ;
569569 } ) ;
570+
571+ // Generic ERC721 token registration for coins with SUPPORTS_ERC721 feature
572+ coins
573+ . filter ( ( coin ) => coin . features . includes ( CoinFeature . SUPPORTS_ERC721 ) && ! coin . isToken )
574+ . forEach ( ( coin ) => {
575+ const coinNames = {
576+ Mainnet : `${ coin . name } ` ,
577+ Testnet : `t${ coin . name } ` ,
578+ } ;
579+
580+ EthLikeErc721Token . createTokenConstructors ( coinNames ) . forEach ( ( { name, coinConstructor } ) => {
581+ coinFactory . register ( name , coinConstructor ) ;
582+ } ) ;
583+ } ) ;
570584}
571585
572586export function getCoinConstructor ( coinName : string ) : CoinConstructor | undefined {
@@ -910,45 +924,31 @@ export function getCoinConstructor(coinName: string): CoinConstructor | undefine
910924 }
911925}
912926
913- export const buildEthLikeChainToTestnetMap = ( ) : {
914- mainnetToTestnetMap : Record < string , string > ;
915- testnetToMainnetMap : Record < string , string > ;
916- } => {
917- const testnetToMainnetMap : Record < string , string > = { } ;
918- const mainnetToTestnetMap : Record < string , string > = { } ;
919-
920- const enabledEvmCoins = [ 'ip' , 'hypeevm' , 'plume' ] ;
921-
922- // 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)
923- coins . forEach ( ( coin ) => {
924- if ( coin . network . type === NetworkType . TESTNET && ! coin . isToken && enabledEvmCoins . includes ( coin . family ) ) {
925- if ( coins . get ( coin . family ) ?. features . includes ( CoinFeature . SUPPORTS_ERC20 ) ) {
926- mainnetToTestnetMap [ coin . family ] = `${ coin . name } ` ;
927- testnetToMainnetMap [ coin . name ] = `${ coin . family } ` ;
928- }
929- }
930- } ) ;
931-
932- return { mainnetToTestnetMap, testnetToMainnetMap } ;
933- } ;
934-
935- const { mainnetToTestnetMap, testnetToMainnetMap } = buildEthLikeChainToTestnetMap ( ) ;
936-
937927export function getTokenConstructor ( tokenConfig : TokenConfig ) : CoinConstructor | undefined {
938- const testnetCoin = mainnetToTestnetMap [ tokenConfig . coin ] ;
939- if ( testnetCoin ) {
928+ const coin = coins . get ( tokenConfig . coin ) ;
929+
930+ if (
931+ 'network' in tokenConfig &&
932+ tokenConfig . network === 'Mainnet' &&
933+ coin ?. features . includes ( CoinFeature . SUPPORTS_ERC20 )
934+ ) {
940935 return EthLikeErc20Token . createTokenConstructor ( tokenConfig as EthLikeTokenConfig , {
941936 Mainnet : tokenConfig . coin ,
942- Testnet : testnetCoin ,
937+ Testnet : `t ${ tokenConfig . coin } ` ,
943938 } ) ;
944939 }
945- const mainnetCoin = testnetToMainnetMap [ tokenConfig . coin ] ;
946- if ( mainnetCoin ) {
947- return EthLikeErc20Token . createTokenConstructor ( tokenConfig as EthLikeTokenConfig , {
948- Mainnet : mainnetCoin ,
949- Testnet : tokenConfig . coin ,
940+
941+ if (
942+ 'network' in tokenConfig &&
943+ tokenConfig . network === 'Mainnet' &&
944+ coin ?. features . includes ( CoinFeature . SUPPORTS_ERC721 )
945+ ) {
946+ return EthLikeErc721Token . createTokenConstructor ( tokenConfig as EthLikeTokenConfig , {
947+ Mainnet : tokenConfig . coin ,
948+ Testnet : `t${ tokenConfig . coin } ` ,
950949 } ) ;
951950 }
951+
952952 switch ( tokenConfig . coin ) {
953953 case 'eth' :
954954 case 'hteth' :
0 commit comments