@bit-gpt/h402
Version:
BitGPT's 402 open protocol for blockchain-native payments
71 lines • 2.49 kB
JavaScript
import { z } from "zod";
// Define network types
export const EVMNetworkSchema = z.enum([
/*"base", "avalanche", "iotex",*/ "bsc",
]);
export const SolanaNetworkSchema = z.enum(["solana"]);
// Combined network schema
export const NetworkSchema = z.union([EVMNetworkSchema, SolanaNetworkSchema]);
// Network categorization
export const SupportedEVMNetworks = [
//"base",
//"avalanche",
//"iotex",
"bsc",
];
export const SupportedSolanaNetworks = ["solana"];
export const SupportedNetworks = [
...SupportedEVMNetworks,
...SupportedSolanaNetworks,
];
// EVM-specific mappings
export const EvmNetworkToChainId = new Map([
// ["base", 8453],
// ["avalanche", 43114],
// ["iotex", 4689],
["bsc", 56],
]);
export const ChainIdToEvmNetwork = Object.fromEntries(SupportedEVMNetworks.map((network) => [
EvmNetworkToChainId.get(network),
network,
]));
// Solana-specific mappings (using cluster names)
export const SolanaNetworkToCluster = new Map([
["solana", "mainnet-beta"],
]);
export const ClusterToSolanaNetwork = Object.fromEntries(SupportedSolanaNetworks.map((network) => [
SolanaNetworkToCluster.get(network),
network,
]));
// Utility functions for network type checking
export const isEVMNetwork = (network) => {
return SupportedEVMNetworks.includes(network);
};
export const isSolanaNetwork = (network) => {
return SupportedSolanaNetworks.includes(network);
};
// Network metadata (optional - for display purposes)
export const NetworkMetadata = {
// EVM Networks
// base: { name: "Base", type: "evm" },
// avalanche: { name: "Avalanche", type: "evm" },
// iotex: { name: "IoTeX", type: "evm" },
bsc: { name: "BNB Smart Chain", type: "evm" },
// Solana Networks
solana: { name: "Solana", type: "solana" },
};
// Helper to get network type
export const getNetworkType = (network) => {
return isEVMNetwork(network) ? "evm" : "solana";
};
// Check if a networkId/chainId corresponds to a supported EVM network
export const isSupportedEVMNetworkId = (networkId) => {
const id = typeof networkId === "string" ? parseInt(networkId, 10) : networkId;
return !isNaN(id) && ChainIdToEvmNetwork.hasOwnProperty(id);
};
// Get EVM network from networkId/chainId
export const getEVMNetworkById = (networkId) => {
const id = typeof networkId === "string" ? parseInt(networkId, 10) : networkId;
return !isNaN(id) ? ChainIdToEvmNetwork[id] : undefined;
};
//# sourceMappingURL=network.js.map