import { AxiosInstance } from 'axios'; import { Contract, Signer, Provider, JsonRpcProvider } from 'ethers'; import { Pair, TokenInfo, ChainConfig } from '../types/index.js'; import { DexalotConfig } from './config.js'; import { WebSocketManager } from '../utils/websocketManager.js'; import { Result } from '../utils/result.js'; import { AsyncRateLimiter } from '../utils/rateLimit.js'; import { AsyncNonceManager } from '../utils/nonceManager.js'; import { ProviderManager } from '../utils/providerManager.js'; import { RetryOptions } from '../utils/retry.js'; import { MemoryCache } from '../utils/cache.js'; import { Logger } from '../utils/observability.js'; import { ResolvedChain } from '../utils/chainResolver.js'; export declare class BaseClient { signer: Signer | null; provider: Provider | null; subnetProvider: Provider | null; /** WebSocket manager when enabled (see CLOBClient subscribeToEvents). */ _wsManager: WebSocketManager | null; apiBaseUrl: string; axios: AxiosInstance; config: DexalotConfig; _apiRateLimiter: AsyncRateLimiter | null; _rpcRateLimiter: AsyncRateLimiter | null; _nonceManager: AsyncNonceManager | null; _providerManager: ProviderManager | null; _logger: Logger; _cacheEnabled: boolean; _staticCache: MemoryCache; _semiStaticCache: MemoryCache; _balanceCache: MemoryCache; _orderbookCache: MemoryCache; pairs: Record; tokenData: Record>; deployments: Record; chainConfig: Record; environmentsCache: any[]; tradePairsContract: Contract | null; portfolioSubContract: Contract | null; portfolioSubContractView: Contract | null; portfolioMainContracts: Record; mainnetRfqContracts: Record; get portfolioMainAvaxContract(): Contract | null; connectedChainProviders: Record; env: string; subnetEnv: string; chainId: number; subnetChainId: number | null; parentEnv: string; /** * Create a new BaseClient. * @param configOrSigner - DexalotConfig, Signer, or API URL string * @param baseUrl - Optional API base URL (only used if first arg is Signer) */ constructor(configOrSigner?: DexalotConfig | Signer | string, baseUrl?: string); /** * Construct a Wallet from `config.privateKey` and immediately clear the key * from config in both the success and failure paths. Once the Wallet exists * the raw key should no longer live in the in-memory config. Callers that * pass a pre-built `Signer` never populate `config.privateKey`, so this * helper is only invoked from the config / env-load constructor branches. */ private _setupSignerFromPrivateKey; /** * Reject http:// RPC URLs unless `allowInsecureRpc` is enabled. */ _rejectInsecureRpcUrls(urls: string[]): string[]; /** * Resolve RPC URL list: env override DEXALOT_RPC_{chainId} / DEXALOT_RPC_{SYMBOL}, else API value (comma-separated). */ _getRpcUrls(chainId: number | undefined, nativeSymbol: string | undefined, apiRpc: string | undefined): string[]; /** * Sanitize error message to prevent information leaks. */ _sanitizeError(error: Error | unknown, context: string): string; /** * Make an API call with rate limiting and retry. * * On failure, lifts backend `reasonCode` + `reason` from the axios * response body (when present) into the thrown Error's `message`. * The Dexalot REST API encodes failures as * `{ reasonCode: "FQ-015", reason: "..." }` (also tolerates the * snake_case `reason_code` and the alternate `message` field that * some endpoints emit). Without this lift the raw axios message * collapses everything to `"Request failed with status code N"`, * which swallows the backend-level reason and makes user-visible * `Result.fail` strings useless for diagnosis. */ _apiCall(method: 'get' | 'post' | 'put' | 'delete', url: string, options?: { params?: any; data?: any; headers?: any; }): Promise; getRevertReason(error: any): string; /** * Load environments, tokens, RFQ pairs, deployments, and CLOB pairs into the client. */ initializeClient(): Promise>; /** * Explicit open hook; axios is already created in the constructor, so this resolves immediately. */ connect(): Promise; /** * Transform API token response to match standardized field names. * Maps lowercase/snake_case API fields to camelCase SDK fields. * Preserves existing camelCase fields if present, otherwise transforms from alternative formats. */ private _transformTokenFromAPI; /** * Transform API environment response to match standardized field names. * Maps lowercase/snake_case API fields to camelCase SDK fields. * Preserves existing camelCase fields if present, otherwise transforms from alternative formats. */ private _transformEnvironmentFromAPI; /** * Transform API deployment response to match standardized field names. * Maps lowercase/camelCase API fields to lowercase SDK fields. * Preserves existing lowercase fields if present, otherwise transforms from alternative formats. */ private _transformDeploymentFromAPI; _fetchEnvironments(): Promise; _fetchTokens(): Promise; /** * Fetch RFQ pairs for all configured chains. * Stores results in this.rfqPairs[chainId] (from SwapMixin). */ private _fetchRfqPairs; /** * Fetch RFQ pairs for a specific chain. */ private _fetchRfqPairsForChain; /** * Fetch CLOB pairs if getClobPairs method is available. * * This is a wrapper around getClobPairs() to make it consistent * with other _fetch_* methods that handle errors internally. */ private _fetchClobPairs; _fetchDeployments(): Promise; _fetchContractDeployment(contractType: string): Promise; _getChainNameFromEnv(envString: string): string | null; _resolveChainId(identifier: string | number): number | null; _getChainNameFromId(chainId: number): string | null; /** * Get token decimals for a symbol on a chain. */ _getTokenDecimals(symbol: string, chainId: number): number | null; /** * Fetch and return the list of environments. * Cached for 1 hour (static data). */ getEnvironments(): Promise>; /** * Map of chain IDs to network display names from the environments API (static cache tier). */ getChains(): Promise>>; /** * Assign the signer and rebuild cached contract instances to use it as the transaction runner. */ setSigner(newSigner: Signer): Promise>; /** * Rebuild subnet/mainnet contract instances for the current signer. */ private _reconnectContractsForSigner; /** * Get list of available tokens on Dexalot. * Cached for 15 minutes (semi-static data). */ getTokens(): Promise>; getConnectedChains(): string[]; /** * Get deployment configuration from the REST API. * Cached for 1 hour (static data). * * Backward-compatible: no-args call still works and uses defaults * (`env = config.parentEnv`, `contracttype = 'All'`, `returnabi = true`). * The backend expects lowercase query param names (`contracttype`, * `returnabi`), not the TS camelCase form on the opts object. * * The cache key includes all three resolved params so filter * variants do not collide on the same static-cache slot. */ getDeployment(opts?: { env?: string; contractType?: 'All' | 'Portfolio' | 'TradePairs' | 'MainnetRFQ' | 'PortfolioMain' | 'PortfolioSub' | 'OrderBooks' | string; returnAbi?: boolean; }): Promise>; getSubnetNetworkInfo(): { chainId: number; rpc: string; name: string; } | null; /** * Reinitialize all client configuration data. * * Refreshes all data loaded during `initializeClient()`: * - Environments (chainConfig, providers, chainId, subnetChainId, env) * - Tokens (tokenData) * - RFQ pairs (rfqPairs) * - Deployments (deployments, contract instances) * - CLOB pairs (pairs) * * @param forceRefresh - If true, clears relevant caches before reinitializing. * This ensures fresh data is fetched even if cache TTL hasn't expired. * @returns Result with success message on success, or error message on failure */ reinitialize(forceRefresh?: boolean): Promise>; /** * Invalidate cache entries. * * @param level - Cache level to invalidate, or 'all' for all caches */ invalidateCache(level?: 'static' | 'semi_static' | 'balance' | 'orderbook' | 'all'): void; /** * Normalize a user-supplied token symbol (strip, uppercase, apply alias map). */ normalizeToken(token: string): string; /** * Normalize a user-supplied trading pair (e.g., "eth/usdc" -> "ETH/USDC"). */ normalizePair(pair: string): string; /** * Resolve a human-friendly chain alias to the canonical connected chain. */ resolveChainReference(chainReference: string | number, includeDexalotL1?: boolean): Result; /** * Map user-facing chain name to ProviderManager registry key (`Dexalot L1` → `DEXALOT_L1`). */ _providerManagerChainKey(chainDisplayName: string): string; /** * Current JsonRpcProvider for a chain: ProviderManager selection first, else subnet / connected map. */ getProviderForChain(chainDisplayName: string): JsonRpcProvider | null; /** Whether balance-style RPC can be attempted for this chain display name. */ isChainRpcAvailable(chainDisplayName: string): boolean; /** * Connected mainnet-style chain names plus any chain_config entry that has providers registered. */ getAvailableChainNames(): string[]; /** * Display name for the Dexalot subnet used as ProviderManager key `DEXALOT_L1`. */ protected _dexalotL1DisplayName(): string; protected _tradePairsDeployment(): { address: string; abi: any[]; } | null; protected _portfolioSubDeployment(): { address: string; abi: any[]; } | null; protected _portfolioMainDeployment(chainName: string): { address: string; abi: any[]; } | null; protected _mainnetRfqDeployment(chainName: string): { address: string; abi: any[]; } | null; /** * `DexalotRouter` deployment published by the deployments endpoint for a * connected chain, or `null` when the backend did not list it. */ protected _dexalotRouterDeployment(chainName: string): { address: string; abi: any[]; } | null; /** Signed contract on a specific RPC (failover-aware). */ protected _contractForSigner(provider: JsonRpcProvider, address: string, abi: any[]): Contract; /** Read-only contract for view calls on a specific RPC. */ protected _contractReadOnly(provider: JsonRpcProvider, address: string, abi: any[]): Contract; protected _rpcRetryOptions(): RetryOptions; protected acquireRpcRateLimiter(): Promise; /** * Run an RPC operation with per-provider retry and failover across registered URLs. */ withRpcFailover(chainDisplayName: string, op: (provider: JsonRpcProvider) => Promise): Promise; /** * Tear down WebSockets, rate limiters, and nonce manager state. */ close(): Promise; } //# sourceMappingURL=base.d.ts.map