import { GeneratedType, Registry } from '@cosmjs/proto-signing'; import { Account, StargateClient, StdFee } from '@cosmjs/stargate'; import { AssetInfo, BaseXChainClient, Fees, Network, PreparedTx, TxHistoryParams, XChainClient, XChainClientParams } from '@xchainjs/xchain-client'; import { Address, Asset, BaseAmount, CachedValue, Chain } from '@xchainjs/xchain-util'; import { Balance, CompatibleAsset, Tx, TxParams, TxsPage } from './types'; /** * Represents the parameters required to configure a Cosmos SDK client. */ export type CosmosSdkClientParams = XChainClientParams & { chain: Chain; clientUrls: Record; prefix: string; defaultDecimals: number; defaultFee: BaseAmount; baseDenom: string; registryTypes: Iterable<[string, GeneratedType]>; }; /** * Enum representing different message types for transactions. */ export declare enum MsgTypes { TRANSFER = "transfer" } /** * Abstract class representing a generic implementation of an XChainClient interface for chains built with Cosmos SDK. * Uses dependencies from the official @cosmjs monorepo. */ export default abstract class Client extends BaseXChainClient implements XChainClient { private readonly defaultFee; private txLock; protected stargateClients: CachedValue; protected prefix: string; protected readonly defaultDecimals: number; protected readonly clientUrls: Record; protected readonly baseDenom: string; protected readonly registry: Registry; /** * Constructor for initializing the Cosmos SDK client. * @param {CosmosSdkClientParams} params Configuration parameters for the client */ constructor(params: CosmosSdkClientParams); /** * Connects the client to a given client URL. * @private * @param {string} clientUrl The URL of the client to connect to * @returns {Promise} The connected StargateClient instance */ private connectClient; /** * Sets the network for the client to work with. * @param {Network} network The network to set * @returns {void} */ setNetwork(network: Network): void; /** * Splits the amount and denomination strings. * @private * @param {string[]} amountsAndDenoms The strings in the format '3000uatom' * @returns {Array} An array of objects containing the amount and denomination */ private splitAmountAndDenom; /** * Maps the indexed transaction to the transaction type used by xchainjs. * @private * @param {IndexedTx} indexedTx The indexed transaction to transform * @returns {Promise} The transformed transaction */ private mapIndexedTxToTx; /** * Serializes async operations to prevent concurrent sequence number conflicts. * Each call waits for the previous one to complete before executing. */ protected withTxLock(fn: () => Promise): Promise; /** * Returns the fee object in a generalized way for a simple transfer function. * @returns {Fees} fees estimation for average, fast and fastests scenarios. */ getFees(): Promise; /** * Validates the format of the provided address. * @param {string} address The address to be validated. * @returns {boolean} Returns true if the address is valid, otherwise false. */ validateAddress(address: string): boolean; /** * Obtains the balances of the specified address for all assets on the network. * @param {string} address The address for which balances are to be retrieved. * @param {Asset[] | undefined} assets An array of assets. Ignored in this implementation. * @returns {Balance[]} A promise that resolves to an array of balances. */ getBalance(address: string, assets?: CompatibleAsset[]): Promise; /** * Retrieves transactions filtered using specified parameters. * @param {TxHistoryParams | undefined} params Parameters for filtering transactions. Only the 'address' parameter is supported in this client. * @returns {TxsPage} A promise that resolves to an array of transactions. */ getTransactions(params?: TxHistoryParams): Promise; /** * Retrieves transaction data using the transaction ID. * @param {string} txId The identifier of the transaction. * @param {string | undefined} _assetAddress Ignored parameter. * @returns {Tx} A promise that resolves to transaction data. */ getTransactionData(txId: string, _assetAddress?: string): Promise; broadcastTx(txHex: string): Promise; /** * Get the chain id of the network connected the client is connected * @returns {string} - The chain id * @throws {Error} If the chain id can not be retrieved */ protected getChainId(): Promise; /** * Get the account of an address * @param {Address} address - The address of which return the account * @returns {Account} - The address account * @throws {Error} If the account can not be retrieved */ protected getAccount(address: Address): Promise; /** * Connect to each url provided * * @param {string[]} urls URLs of the providers to connect * @returns {StargateClient[]} List of the providers that can be used to interact with the blockchain */ private connectToClientUrls; /** * Retrieve the balance of an address making a round robin over the clients urls provided to the client * @param {string} address The address for which balances are to be retrieved. * @returns {Coin[]} List of balances of the address * @throws {Error} if balance can not be retrieved */ private roundRobinGetBalance; /** * Retrieve a block making a round robin over the clients urls provided to the client * @param {number} height The height of the block to be retrieved. * @returns {Block} The block linked to the height provided * @throws {Error} if the block can not be retrieved */ private roundRobinGetBlock; /** * Retrieve a transaction making a round robin over the clients urls provided to the client * @param {string} txId The hash of the transaction to be retrieved. * @returns {IndexedTx} The transaction linked to the hash provided * @throws {Error} if the transaction can not be retrieved */ private roundRobinGetTransaction; /** * Broadcast a raw signed transaction making a round robin over the clients urls provided to the client * @param {Uint8Array} txHex The raw signed transaction to be broadcast. * @returns {DeliverTxResponse} The broadcasted transaction * @throws {Error} if the transaction can not be broadcasted */ private roundRobinBroadcast; /** * Search transactions by the filters provided making a round robin over the clients urls provided to the client * @param {{ key: string; value: string }[]} filters The raw signed transaction to be broadcast. * @returns {IndexedTx[]} The broadcasted transaction * @throws {Error} if the transaction can not be broadcasted */ private roundRobinSearchTx; /** * Get the account of an address making a round robin system over the stargate clients * @param {Address} address - The address of which return the account * @returns {Account | null} - The account if it is found * @throws {Error} If the account can not be retrieved from the stargate clients */ private roundRobinGetAccount; /** * Get the chain id of the network connected the client is connected making a round robin over * the stargate clients * @returns {string} - The chain id * @throws {Error} If the chain id can not be retrieved from the stargate clients */ private roundRobinGetChainId; abstract prepareTx({ sender, recipient, asset, amount, memo, }: TxParams & { sender: Address; }): Promise; abstract getAssetInfo(): AssetInfo; abstract getExplorerUrl(): string; abstract getExplorerAddressUrl(_address: string): string; abstract getExplorerTxUrl(txID: string): string; abstract assetFromDenom(denom: string): CompatibleAsset | null; abstract getDenom(asset: CompatibleAsset): string | null; abstract getAssetDecimals(asset: CompatibleAsset): number; protected abstract getMsgTypeUrlByType(msgType: MsgTypes): string; protected abstract getStandardFee(asset: Asset): StdFee; protected abstract getPrefix(network: Network): string; } export { Client };