import { getChainIdFromNetworkType , getCoinGeckoConstants , getCoinMarketCapConstants , NetworkType , } from '@masknet/web3-shared-evm' ; import { TagType } from '../../types' ; import { DataProvider } from '@masknet/public-api' ; import MIRRORED_TOKENS from './mirrored_tokens.json' ; import STOCKS_KEYWORDS from './stocks.json' ; import CASHTAG_KEYWORDS from './cashtag.json' ; import HASHTAG_KEYWORDS from './hashtag.json' ; import { currentNetworkSettings } from '../../../Wallet/settings' ; import { getEnumAsArray } from '@dimensiondev/kit' ; const BLACKLIST_MAP = { [ DataProvider . COIN_MARKET_CAP ] : { [ NetworkType . Ethereum ] : [ '8410' , ] , } , [ DataProvider . COIN_GECKO ] : { [ NetworkType . Ethereum ] : [ 'swaptoken' , 'nftx-hashmasks-index' ] , } , [ DataProvider . UNISWAP_INFO ] : { [ NetworkType . Ethereum ] : [ ] , } , } ; const KEYWORD_ALIAS_MAP = { [ DataProvider . COIN_MARKET_CAP ] : { [ NetworkType . Ethereum ] : { NYFI : 'n0031' , } , } , [ DataProvider . COIN_GECKO ] : { [ NetworkType . Ethereum ] : { NYFI : 'n0031' , } , } , [ DataProvider . UNISWAP_INFO ] : { } , } ; const KEYWORD_ID_MAP = { [ DataProvider . COIN_MARKET_CAP ] : { [ NetworkType . Ethereum ] : { UNI : '7083' , YAM : '7131' , } , } , [ DataProvider . COIN_GECKO ] : { [ NetworkType . Ethereum ] : { UNI : 'uniswap' , } , } , [ DataProvider . UNISWAP_INFO ] : { } , } ; const ID_ADDRESS_MAP = { [ DataProvider . COIN_MARKET_CAP ] : { [ NetworkType . Ethereum ] : { '6747' : '0x32a7c02e79c4ea1008dd6564b35f131428673c41' , '8536' : '0x69af81e73A73B40adF4f3d4223Cd9b1ECE623074' , } , [ NetworkType . Polygon ] : { '8536' : '0x2B9E7ccDF0F4e5B24757c1E1a80e311E34Cb10c7' , } , } , [ DataProvider . COIN_GECKO ] : { [ NetworkType . Ethereum ] : { 'crust-network' : '0x32a7c02e79c4ea1008dd6564b35f131428673c41' , } , [ NetworkType . Polygon ] : { 'mask-network' : '0x2B9E7ccDF0F4e5B24757c1E1a80e311E34Cb10c7' , } , } , [ DataProvider . UNISWAP_INFO ] : { } , } ; const NETWORK_ID_MAP = { [ DataProvider . COIN_GECKO ] : { } , [ DataProvider . COIN_MARKET_CAP ] : { } , [ DataProvider . UNISWAP_INFO ] : { } , } ; getEnumAsArray ( NetworkType ) . map ( ( { value : networkType } ) => { const chainId = getChainIdFromNetworkType ( networkType ) ; NETWORK_ID_MAP [ DataProvider . COIN_GECKO ] [ networkType ] = getCoinGeckoConstants ( chainId ) . PLATFORM_ID ?? '' ; NETWORK_ID_MAP [ DataProvider . COIN_MARKET_CAP ] [ networkType ] = getCoinMarketCapConstants ( chainId ) . CHAIN_ID ?? '' ; } ) ; export function resolveAlias ( keyword , dataProvider ) { if ( dataProvider === DataProvider . UNISWAP_INFO ) return keyword ; return KEYWORD_ALIAS_MAP [ dataProvider ] [ currentNetworkSettings . value ] ?. [ keyword . toUpperCase ( ) ] ?? keyword ; } export function resolveCoinId ( keyword , dataProvider ) { return KEYWORD_ID_MAP [ dataProvider ] [ currentNetworkSettings . value ] ?. [ keyword . toUpperCase ( ) ] ; } export function resolveCoinAddress ( id , dataProvider ) { return ID_ADDRESS_MAP [ dataProvider ] [ currentNetworkSettings . value ] ?. [ id ] ; } export function resolveNetworkType ( id , dataProvider ) { if ( dataProvider === DataProvider . UNISWAP_INFO ) return NetworkType . Ethereum ; const networks = NETWORK_ID_MAP [ dataProvider ] ; return Object . entries ( networks ) . find ( ( [ _ , key ] ) => key === id ) ?. [ 0 ] ; } export function isBlockedId ( id , dataProvider ) { return BLACKLIST_MAP [ dataProvider ] [ currentNetworkSettings . value ] ?. includes ( id ) ; } export function isBlockedKeyword ( type , keyword ) { const search = keyword . toUpperCase ( ) ; if ( STOCKS_KEYWORDS . includes ( search ) ) return true ; if ( type === TagType . HASH ) return HASHTAG_KEYWORDS . includes ( search ) ; if ( type === TagType . CASH ) return CASHTAG_KEYWORDS . includes ( search ) ; return true ; } export function isMirroredKeyword ( symbol ) { return MIRRORED_TOKENS . map ( ( x ) => x . symbol ) . some ( ( x ) => x . toUpperCase ( ) === symbol . toUpperCase ( ) ) ; }