@dojima-wallet/connection
Version:
Initialise and connection for layer 1&2 blockchain
276 lines (275 loc) • 10.7 kB
TypeScript
import { cosmosclient, proto } from "@cosmos-client/core";
import { Balance, BaseChainClient, ChainClient, ChainClientParams, Fees, Network, Tx, TxHash, TxHistoryParams, TxParams, TxsPage } from "../client";
import { CosmosSDKClient, RPCTxResult } from "../cosmos";
import { Address, Asset } from "@dojima-wallet/utils";
import BigNumber from "bignumber.js";
import { ChainId, ChainIds, ClientUrl, DepositParam, ExplorerUrls, HermeschainClientParams, NodeUrl, TxOfflineParams, VersionParam, IpAddressParam, NodePubkeyParam, CreateOperatorParam, RegisterChainParam, CreateEndpointParam } from "./types";
import { PoolData, SwapFeeResult } from "../swap_utils";
/**
* Interface for custom Hermeschain client
*/
export interface HermeschainClient {
setClientUrl(clientUrl: ClientUrl): void;
getClientUrl(): NodeUrl;
setExplorerUrls(explorerUrls: ExplorerUrls): void;
getCosmosClient(): CosmosSDKClient;
deposit(params: DepositParam): Promise<TxHash>;
createOperator(params: CreateOperatorParam): Promise<TxHash>;
createEndpoint(params: CreateEndpointParam): Promise<TxHash>;
registerChain(params: RegisterChainParam): Promise<TxHash>;
transferOffline(params: TxOfflineParams): Promise<string>;
}
/**
* Custom Hermeschain Client
*/
declare class HermesClient extends BaseChainClient implements HermeschainClient, ChainClient {
private clientUrl;
private explorerUrls;
private chainIds;
private cosmosClient;
private apiUrl;
private rpcUrl;
/**
* Constructor
*
* Client has to be initialised with network type and phrase.
* It will throw an error if an invalid phrase has been passed.
*
* @param {ChainClientParams} params
*
* @throws {"Invalid phrase"} Thrown if the given phase is invalid.
*/
constructor({ network, phrase, apiUrl, rpcUrl, rootDerivationPaths, }: ChainClientParams & HermeschainClientParams);
/**
* Get default chainId's
* */
getDefaultChainIds(): ChainIds;
/**
* Get default client url's
* */
getDefaultClientUrls(): ClientUrl;
/**
* Get default Explorer Url's
* */
getDefaultExplorerUrls(): ExplorerUrls;
/**
* Set/update the current network.
*
* @param {Network} network
* @returns {void}
*
* @throws {"Network must be provided"}
* Thrown if network has not been set before.
*/
setNetwork(network: Network): void;
/**
* Set/update the client URL.
*
* @param {ClientUrl} clientUrl The client url to be set.
* @returns {void}
*/
setClientUrl(clientUrl: ClientUrl): void;
/**
* Get the client url.
*
* @returns {NodeUrl} The client url for hermeschain based on the current network.
*/
getClientUrl(): NodeUrl;
/**
* Set/update the explorer URLs.
*
* @param {ExplorerUrls} urls The explorer urls to be set.
* @returns {void}
*/
setExplorerUrls(urls: ExplorerUrls): void;
/**
* Get the explorer url.
*
* @returns {string} The explorer url for hermeschain based on the current network.
*/
getExplorerUrl(): string;
/**
* Sets chain id
*
* @param {ChainId} chainId Chain id to update
* @param {Network} network (optional) Network for given chainId. If `network`not set, current network of the client is used
*
* @returns {void}
*/
setChainId(chainId: ChainId, network?: Network): void;
/**
* Gets chain id
*
* @param {Network} network (optional) Network to get chain id from. If `network`not set, current network of the client is used
*
* @returns {ChainId} Chain id based on the current network.
*/
getChainId(network?: Network): ChainId;
/**
* Get cosmos client
* @returns {CosmosSDKClient} current cosmos client
*/
getCosmosClient(): CosmosSDKClient;
/**
* 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 private key
*
* @param {number} index the HD wallet index (optional)
* @returns {PrivKey} The private key generated from the given phrase
*
* @throws {"Phrase not set"}
* Throws an error if phrase has not been set before
* */
getPrivateKey(index?: number): proto.cosmos.crypto.secp256k1.PrivKey;
/**
* Get public key
*
* @param {number} index the HD wallet index (optional)
*
* @returns {PubKey} The public key generated from the given phrase
*
* @throws {"Phrase not set"}
* Throws an error if phrase has not been set before
**/
getPubKey(index?: number): cosmosclient.PubKey;
/**
* Get secondary root derivation path required for account retrieval instead of default
*/
private getSecondaryAccountRootDerivationPath;
/**
* Get the current address.
*
* @returns {Address} The current address.
*
* @throws {Error} Thrown if phrase has not been set before. A phrase is needed to create a wallet and to derive an address from it.
*/
getAddress(index?: number, secondaryAccountIndex?: number): string;
/**
* Validate the given address.
*
* @param {Address} address
* @returns {boolean} `true` or `false`
*/
validateAddress(address: Address): boolean;
/**
* Get the balance of a given address.
*
* @param {Address} address By default, it will return the balance of the current wallet. (optional)
* @param {Asset} asset If not set, it will return all assets available. (optional)
* @returns {Balance[]} The balance of the address.
*/
getBalance(address: Address, assets?: Asset[]): Promise<Balance[]>;
/**
* Get transaction history of a given address with pagination options.
* By default, it will return the transaction history of the current wallet.
*
* @param {TxHistoryParams} params The options to get transaction history. (optional)
* @returns {TxsPage} The transaction history.
*/
getTransactions: (params?: TxHistoryParams & {
filterFn?: (tx: RPCTxResult) => boolean;
}) => Promise<TxsPage>;
/**
* Get the transaction details of a given transaction id.
*
* @param {string} txId The transaction id.
* @returns {Tx} The transaction details of the given transaction id.
*/
getTransactionData(txId: string, address: Address): Promise<Tx>;
/**
* Get the transaction details of a given transaction id. (from /hermeschain/txs/hash)
*
* Node: /hermeschain/txs/hash response doesn't have timestamp field.
*
* @param {string} txId The transaction id.
* @returns {Tx} The transaction details of the given transaction id.
*/
getDepositTransaction(txId: string): Promise<Omit<Tx, "date">>;
createOperator({ walletIndex, serverAddress, stakeAmount, gasLimit, }: CreateOperatorParam): Promise<TxHash>;
registerChain({ walletIndex, chain, cmpUnits, gasLimit, }: RegisterChainParam): Promise<TxHash>;
createEndpoint({ walletIndex, chain, rpcUrl, wsUrl, gasLimit, }: CreateEndpointParam): Promise<TxHash>;
/**
* Transaction with MsgNativeTx.
*
* @param {DepositParam} params The transaction options.
* @returns {TxHash} The transaction hash.
*
* @throws {"insufficient funds"} Thrown if the wallet has insufficient funds.
* @throws {"Invalid transaction hash"} Thrown by missing tx hash
*/
deposit({ walletIndex, asset, amount, memo, gasLimit, }: DepositParam): Promise<TxHash>;
/**
* Transfer balances with MsgSend
*
* @param {TxParams} params The transfer options.
* @returns {TxHash} The transaction hash.
*
* @throws {"insufficient funds"} Thrown if the wallet has insufficient funds.
* @throws {"Invalid transaction hash"} Thrown by missing tx hash
*/
transfer({ walletIndex, asset, amount, recipient, memo, gasLimit, }: TxParams & {
gasLimit?: BigNumber;
}): Promise<TxHash>;
/**
* Transfer without broadcast balances with MsgSend
*
* @param {TxOfflineParams} params The transfer offline options.
* @returns {string} The signed transaction bytes.
*/
transferOffline({ walletIndex, asset, amount, recipient, memo, fromDojBalance: from_doj_balance, fromAssetBalance: from_asset_balance, fromAccountNumber, fromSequence, gasLimit, }: TxOfflineParams): Promise<string>;
/**
* Transaction with MsgSetNodePubkeysTx.
*
* @param {NodePubkeyParam} params The transaction options.
* @returns {TxHash} The transaction hash.
*
* @throws {"insufficient funds"} Thrown if the wallet has insufficient funds.
* @throws {"Invalid transaction hash"} Thrown by missing tx hash
*/
setPubkeys({ walletIndex, secp256k1Pubkey, ed25519Pubkey, validatorConsPubkey, gasLimit, }: NodePubkeyParam): Promise<TxHash>;
/**
* Transaction with MsgSetVersionTx.
*
* @param {VersionParam} params The transaction options.
* @returns {TxHash} The transaction hash.
*
* @throws {"insufficient funds"} Thrown if the wallet has insufficient funds.
* @throws {"Invalid transaction hash"} Thrown by missing tx hash
*/
setVersion({ walletIndex, version, gasLimit, }: VersionParam): Promise<TxHash>;
/**
* Transaction with MsgSetIpAddressTx.
*
* @param {IpAddressParam} params The transaction options.
* @returns {TxHash} The transaction hash.
*
* @throws {"insufficient funds"} Thrown if the wallet has insufficient funds.
* @throws {"Invalid transaction hash"} Thrown by missing tx hash
*/
setIpAddress({ walletIndex, ipAddress, gasLimit, }: IpAddressParam): Promise<TxHash>;
/**
* Gets fees from Node
*
* @returns {Fees}
*/
getFees(): Promise<Fees>;
getSwapOutput(inputAmount: number, pool: PoolData, toDoj: boolean): number;
getDoubleSwapOutput(inputAmount: number, pool1: PoolData, pool2: PoolData): number;
getSwapSlip(inputAmount: number, pool: PoolData, toDoj: boolean): number;
getDoubleSwapSlip(inputAmount: number, pool1: PoolData, pool2: PoolData): number;
getSwapFeesData(): Promise<SwapFeeResult>;
}
export { HermesClient };