/ src / data / crypto / networks.js
networks.js
  1  export const networks = {
  2    ethereum: {
  3      id: "ethereum",
  4      name: "Ethereum",
  5      shortName: "ETH",
  6      type: "evm",
  7      nativeCoinId: "ETH",
  8      explorerUrl: "https://etherscan.io",
  9      avgBlockTime: 12,
 10      broadcast: false,
 11      enabled: true,
 12    },
 13    solana: {
 14      id: "solana",
 15      name: "Solana",
 16      shortName: "SOL",
 17      type: "solana",
 18      nativeCoinId: "SOL",
 19      explorerUrl: "https://solscan.io",
 20      avgBlockTime: 0.4,
 21      broadcast: true,
 22      enabled: true,
 23    },
 24    sui: {
 25      id: "sui",
 26      name: "Sui",
 27      shortName: "SUI",
 28      type: "sui",
 29      nativeCoinId: "SUI",
 30      explorerUrl: "https://suiscan.xyz",
 31      avgBlockTime: 0.5,
 32      broadcast: true,
 33      enabled: false,
 34    },
 35    arbitrum: {
 36      id: "arbitrum",
 37      name: "Arbitrum",
 38      shortName: "ARB",
 39      type: "evm",
 40      nativeCoinId: "ETH",
 41      explorerUrl: "https://arbiscan.io",
 42      avgBlockTime: 0.25,
 43      broadcast: false,
 44      enabled: true,
 45    },
 46    polygon: {
 47      id: "polygon",
 48      name: "Polygon",
 49      shortName: "MATIC",
 50      type: "evm",
 51      nativeCoinId: "MATIC",
 52      explorerUrl: "https://polygonscan.com",
 53      avgBlockTime: 2,
 54      broadcast: false,
 55      enabled: true,
 56    },
 57    base: {
 58      id: "base",
 59      name: "Base",
 60      shortName: "BASE",
 61      type: "evm",
 62      nativeCoinId: "ETH",
 63      explorerUrl: "https://basescan.org",
 64      avgBlockTime: 2,
 65      broadcast: false,
 66      enabled: true,
 67    },
 68    bsc: {
 69      id: "bsc",
 70      name: "BSC",
 71      shortName: "BNB",
 72      type: "evm",
 73      nativeCoinId: "BNB",
 74      explorerUrl: "https://bscscan.com",
 75      avgBlockTime: 3,
 76      broadcast: false,
 77      enabled: true,
 78    },
 79    avalanche: {
 80      id: "avalanche",
 81      name: "Avalanche",
 82      shortName: "AVAX",
 83      type: "evm",
 84      nativeCoinId: "AVAX",
 85      explorerUrl: "https://snowtrace.io",
 86      avgBlockTime: 2,
 87      broadcast: false,
 88      enabled: true,
 89    },
 90    optimism: {
 91      id: "optimism",
 92      name: "Optimism",
 93      shortName: "OP",
 94      type: "evm",
 95      nativeCoinId: "ETH",
 96      explorerUrl: "https://optimistic.etherscan.io",
 97      avgBlockTime: 2,
 98      broadcast: false,
 99      enabled: true,
100    },
101  };
102  
103  function validateNetworkId(networkId) {
104    if (typeof networkId !== "string" || !/^[a-z0-9-]{3,20}$/.test(networkId)) {
105      throw new Error("Invalid network ID format");
106    }
107    return networkId;
108  }
109  
110  function validateCoinId(coinId) {
111    if (typeof coinId !== "string" || !/^[A-Z0-9]{2,10}$/.test(coinId)) {
112      throw new Error("Invalid coin ID format");
113    }
114    return coinId;
115  }
116  
117  export default networks;
118  
119  export function getNetworkConfig(networkId) {
120    const validNetworkId = validateNetworkId(networkId);
121  
122    if (!Object.prototype.hasOwnProperty.call(networks, validNetworkId)) {
123      return null;
124    }
125  
126    return networks[validNetworkId] || null;
127  }
128  
129  export function getEnabledNetworks() {
130    const result = {};
131    for (const [id, config] of Object.entries(networks)) {
132      if (config.enabled !== false) {
133        if (Object.prototype.hasOwnProperty.call(networks, id)) {
134          result[id] = config;
135        }
136      }
137    }
138    return result;
139  }
140  
141  export function getEnabledNetworksForType(type) {
142    const result = {};
143    for (const [id, config] of Object.entries(networks)) {
144      if (config.enabled !== false && config.type === type) {
145        if (Object.prototype.hasOwnProperty.call(networks, id)) {
146          result[id] = config;
147        }
148      }
149    }
150    return result;
151  }