@@ -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 ,
@@ -565,6 +565,20 @@ export function registerCoinConstructors(coinFactory: CoinFactory, coinMap: Coin
565565 coinFactory . register ( name , coinConstructor ) ;
566566 } ) ;
567567 } ) ;
568+
569+ // Generic ERC721 token registration for coins with SUPPORTS_ERC721 feature
570+ coins
571+ . filter ( ( coin ) => coin . features . includes ( CoinFeature . SUPPORTS_ERC721 ) && ! coin . isToken )
572+ . forEach ( ( coin ) => {
573+ const coinNames = {
574+ Mainnet : `${ coin . name } ` ,
575+ Testnet : `t${ coin . name } ` ,
576+ } ;
577+
578+ EthLikeErc721Token . createTokenConstructors ( coinNames ) . forEach ( ( { name, coinConstructor } ) => {
579+ coinFactory . register ( name , coinConstructor ) ;
580+ } ) ;
581+ } ) ;
568582}
569583
570584export function getCoinConstructor ( coinName : string ) : CoinConstructor | undefined {
@@ -904,45 +918,31 @@ export function getCoinConstructor(coinName: string): CoinConstructor | undefine
904918 }
905919}
906920
907- export const buildEthLikeChainToTestnetMap = ( ) : {
908- mainnetToTestnetMap : Record < string , string > ;
909- testnetToMainnetMap : Record < string , string > ;
910- } => {
911- const testnetToMainnetMap : Record < string , string > = { } ;
912- const mainnetToTestnetMap : Record < string , string > = { } ;
913-
914- const enabledEvmCoins = [ 'ip' , 'hypeevm' , 'plume' ] ;
915-
916- // 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)
917- coins . forEach ( ( coin ) => {
918- if ( coin . network . type === NetworkType . TESTNET && ! coin . isToken && enabledEvmCoins . includes ( coin . family ) ) {
919- if ( coins . get ( coin . family ) ?. features . includes ( CoinFeature . SUPPORTS_ERC20 ) ) {
920- mainnetToTestnetMap [ coin . family ] = `${ coin . name } ` ;
921- testnetToMainnetMap [ coin . name ] = `${ coin . family } ` ;
922- }
923- }
924- } ) ;
925-
926- return { mainnetToTestnetMap, testnetToMainnetMap } ;
927- } ;
928-
929- const { mainnetToTestnetMap, testnetToMainnetMap } = buildEthLikeChainToTestnetMap ( ) ;
930-
931921export function getTokenConstructor ( tokenConfig : TokenConfig ) : CoinConstructor | undefined {
932- const testnetCoin = mainnetToTestnetMap [ tokenConfig . coin ] ;
933- if ( testnetCoin ) {
922+ const coin = coins . get ( tokenConfig . coin ) ;
923+
924+ if (
925+ 'network' in tokenConfig &&
926+ tokenConfig . network === 'Mainnet' &&
927+ coin ?. features . includes ( CoinFeature . SUPPORTS_ERC20 )
928+ ) {
934929 return EthLikeErc20Token . createTokenConstructor ( tokenConfig as EthLikeTokenConfig , {
935930 Mainnet : tokenConfig . coin ,
936- Testnet : testnetCoin ,
931+ Testnet : `t ${ tokenConfig . coin } ` ,
937932 } ) ;
938933 }
939- const mainnetCoin = testnetToMainnetMap [ tokenConfig . coin ] ;
940- if ( mainnetCoin ) {
941- return EthLikeErc20Token . createTokenConstructor ( tokenConfig as EthLikeTokenConfig , {
942- Mainnet : mainnetCoin ,
943- Testnet : tokenConfig . coin ,
934+
935+ if (
936+ 'network' in tokenConfig &&
937+ tokenConfig . network === 'Mainnet' &&
938+ coin ?. features . includes ( CoinFeature . SUPPORTS_ERC721 )
939+ ) {
940+ return EthLikeErc721Token . createTokenConstructor ( tokenConfig as EthLikeTokenConfig , {
941+ Mainnet : tokenConfig . coin ,
942+ Testnet : `t${ tokenConfig . coin } ` ,
944943 } ) ;
945944 }
945+
946946 switch ( tokenConfig . coin ) {
947947 case 'eth' :
948948 case 'hteth' :
0 commit comments