@wasserstoff/tribes-sdk
Version:
SDK for integrating with Tribes by Astrix platform on any EVM compatible chain
95 lines (94 loc) • 3.04 kB
TypeScript
import { ethers, InterfaceAbi } from 'ethers';
import { AstrixSDKConfig, ErrorType, CacheOptions } from '../types/core';
/**
* Base class for all SDK modules with caching support
*/
export declare abstract class BaseModule {
protected provider: ethers.JsonRpcProvider;
protected signer: ethers.Signer | null;
protected config: AstrixSDKConfig;
private cache;
private blockListener;
private currentBlockNumber;
private readonly DEFAULT_CACHE_TIME;
/**
* Create a new module instance
* @param provider Provider for read operations
* @param config SDK configuration
*/
constructor(provider: ethers.JsonRpcProvider, config: AstrixSDKConfig);
/**
* Sets up block monitoring to invalidate cache based on new blocks
*/
private setupBlockMonitoring;
/**
* Invalidates cache entries that are bound to specific blocks
*/
private invalidateBlockBasedCache;
/**
* Clean up block subscription
*/
private cleanupBlockSubscription;
/**
* Set the signer for write operations
* @param signer Ethers signer object
*/
setSigner(signer: ethers.Signer): void;
/**
* Check if a signer is connected
*/
protected requireSigner(): ethers.Signer;
/**
* Get a contract instance
* @param address Contract address
* @param abi Contract ABI
* @param useSigner Whether to use the signer or provider
*/
protected getContract<T extends ethers.BaseContract>(address: string, abi: InterfaceAbi, useSigner?: boolean): T;
/**
* Get cached data or fetch it if not available
* @param key Cache key
* @param fetchFn Function to fetch data if not in cache
* @param options Cache options
*/
protected getWithCache<T>(key: string, fetchFn: () => Promise<T>, options?: CacheOptions): Promise<T>;
/**
* Determine if cached data should be used
*/
private shouldUseCache;
/**
* Build a standardized cache key
*/
private buildCacheKey;
/**
* Invalidate a specific cache entry
* @param key Cache key to invalidate
*/
protected invalidateCache(key: string): void;
/**
* Invalidate cache entries that match a pattern
* @param pattern Pattern to match cache keys against
*/
protected invalidateCacheByPattern(pattern: string): void;
/**
* Clear all cached data
*/
protected clearCache(): void;
/**
* Handle errors by wrapping them in AstrixSDKError
* @param error Original error
* @param message Error message
* @param type Error type
*/
protected handleError(error: unknown, message?: string, type?: ErrorType): never;
/**
* Log a message if verbose mode is enabled
* @param message Message to log
* @param data Optional data to log
*/
protected log(_message: string, _data?: Record<string, unknown> | string | number): void;
/**
* Dispose of resources and subscriptions
*/
dispose(): void;
}