/** * Network configuration management * * Provides access to network-specific contract addresses and settings * Port from serverless-strategy-tx-processor networks.json */ import { Chain } from '@steerprotocol/sdk'; import { networks, NetworkConfig, NetworksConfig } from '../config/networks'; /** * Contract address configuration for a specific contract */ export interface ContractConfig { address: string; [key: string]: any; } /** * All available networks */ export type Networks = NetworksConfig; // Re-export NetworkConfig from networks.ts export type { NetworkConfig }; /** * Get network configuration by network name * * @param networkName - The network name (case-insensitive, e.g., "arbitrum", "polygon") * @returns NetworkConfig - The network configuration * @throws Error if network not found * * @example * ```typescript * const config = getNetworkConfig('arbitrum'); * const quoterAddress = config.QuoterV2.address; * ``` */ export function getNetworkConfig(networkName: Chain): NetworkConfig { // Normalize network name to lowercase // Check if network exists if (!networks[networkName]) { throw new Error(`Network '${networkName}' not found in network configuration. Available networks: ${Object.keys(networks).join(', ')}`); } const config = networks[networkName]; // Validate that config has chainId if (!config.chainId) { throw new Error(`Network '${networkName}' configuration is missing required 'chainId' field`); } return config; } /** * Get all available network names * * @returns string[] - Array of all network names */ export function getAvailableNetworks(): string[] { return Object.keys(networks); } /** * Check if a network exists in the configuration * * @param networkName - The network name to check * @returns boolean - True if network exists, false otherwise */ export function hasNetwork(networkName: Chain): boolean { return !!networks[networkName]; }