UNPKG

@xchainjs/xchain-cosmos

Version:

Custom Cosmos client and utilities used by XChainJS clients

116 lines (115 loc) 4.51 kB
import { StdFee } from '@cosmjs/amino'; import { AssetInfo, Fees, PreparedTx } from '@xchainjs/xchain-client'; import { Client as CosmosSDKClient, CosmosSdkClientParams, MsgTypes } from '@xchainjs/xchain-cosmos-sdk'; import { Address, Asset } from '@xchainjs/xchain-util'; import BigNumber from 'bignumber.js'; import { CompatibleAsset, TxOfflineParams, TxParams } from './types'; /** * Partial parameters for the Cosmos client. */ export type CosmosClientParams = Partial<CosmosSdkClientParams>; /** * Cosmos client class extending the Cosmos SDK client. */ export declare abstract class Client extends CosmosSDKClient { /** * Constructor for the Cosmos client. * @param {CosmosClientParams} config Configuration parameters for the client. */ constructor(config?: CosmosClientParams); /** * Get information about the client's native asset. * @returns {AssetInfo} Information about the native asset. */ getAssetInfo(): AssetInfo; /** * Get the number of decimals for a given asset. * @param {CompatibleAsset} asset The asset to get the decimals for. * @returns {number} The number of decimals. */ getAssetDecimals(asset: CompatibleAsset): number; /** * Get the explorer URL. * @returns {string} The explorer URL. */ getExplorerUrl(): string; /** * Get the explorer url for the given address. * * @param {Address} address * @returns {string} The explorer url for the given address. */ getExplorerAddressUrl(address: Address): string; /** * Get the explorer url for the given transaction id. * * @param {string} txID * @returns {string} The explorer url for the given transaction id. */ getExplorerTxUrl(txID: string): string; /** * Get the asset from a given denomination. * @param {string} denom The denomination to convert. * @returns {CompatibleAsset | null} The asset corresponding to the given denomination. */ assetFromDenom(denom: string): CompatibleAsset | null; /** * Get the denomination from a given asset. * @param {Asset} asset The asset to get the denomination for. * @returns {string | null} The denomination of the given asset. */ getDenom(asset: CompatibleAsset): string | null; /** * Get the current fees. * If possible, fetches the fees from THORChain's `inbound_addresses`. * Otherwise, returns default fees. * @returns {Fees} The current fees. */ getFees(): Promise<Fees>; /** * Prepare a transaction for signing. * @param {TxParams & { sender: Address }} params Transaction parameters including sender address. * @returns {PreparedTx} The prepared transaction. * @throws {"Invalid sender address"} Thrown if the sender address is invalid. * @throws {"Invalid recipient address"} Thrown if the recipient address is invalid. * @throws {"Invalid asset"} Thrown if the asset is invalid or not supported. */ prepareTx({ sender, recipient, asset, amount, memo, }: TxParams & { sender: Address; }): Promise<PreparedTx>; /** * Creates and signs a transaction without broadcasting it. * @deprecated Use prepareTx instead. */ transferOffline({ walletIndex, recipient, asset, amount, memo, gasLimit, }: TxOfflineParams & { gasLimit?: BigNumber; }): Promise<string>; /** * Get the address prefix based on the network. * @param {Network} network The network of which return the prefix * @returns the address prefix */ protected getPrefix(): string; /** * Get the message type URL by message type. * @param {MsgTypes} msgType The message type. * @returns {string} The message type URL. */ protected getMsgTypeUrlByType(msgType: MsgTypes): string; /** * Returns the standard fee used by the client for an asset. * @param {Asset} asset The asset to retrieve the fee for. * @returns {StdFee} The standard fee. */ protected getStandardFee(asset: Asset): StdFee; /** * Sign a transaction making a round robin over the clients urls provided to the client * * @param {string} sender Sender address * @param {DecodedTxRaw} unsignedTx Unsigned transaction * @param {DirectSecp256k1HdWallet} signer Signer * @param {BigNumber} gasLimit Transaction gas limit * @returns {TxRaw} The raw signed transaction */ private roundRobinSign; }