@dojima-wallet/connection
Version:
Initialise and connection for layer 1&2 blockchain
287 lines (286 loc) • 9.73 kB
TypeScript
import { cosmosclient, proto } from "@cosmos-client/core";
import { Balance, Fees, Network, TxHash } from "../client";
import { CosmosSDKClient, TxLog } from "../cosmos";
import { Address, Asset, BaseAmount } from "@dojima-wallet/utils";
import Long from "long";
import { MsgCreateOperator, MsgRegisterChain, MsgNativeTx, MsgSetIpAddressTx, MsgSetPubkeysTx, MsgSetVersionTx, MsgCreateEndpoint } from "./messages";
import { ChainId, ExplorerUrls, TxData } from "./types";
export declare const DOJ_DECIMAL = 8;
export declare const DEFAULT_GAS_ADJUSTMENT = 2;
export declare const DEFAULT_GAS_LIMIT_VALUE = "8000000";
export declare const DEPOSIT_GAS_LIMIT_VALUE = "600000000";
export declare const MAX_TX_COUNT = 100;
/**
* Get denomination from Asset
*
* @param {Asset} asset
* @returns {string} The denomination of the given asset.
*/
export declare const getDenom: (asset: Asset) => string;
/**
* Get Asset from denomination
*
* @param {string} denom
* @returns {Asset|null} The asset of the given denomination.
*/
export declare const assetFromDenom: (denom: string) => Asset | null;
/**
* Response guard for transaction broadcast
*
* @param {any} response The response from the node.
* @returns {boolean} `true` or `false`.
*/
export declare const isBroadcastSuccess: (response: unknown) => boolean;
/**
* Get address prefix based on the network.
*
* @param {Network} network
* @returns {string} The address prefix based on the network.
*
**/
export declare const getPrefix: (network: Network) => "dojima" | "sdojima" | "tdojima";
/**
* Register type for encoding `MsgSetVersion` messages
*/
export declare const registerSetVersionCodecs: () => void;
/**
* Register type for encoding `MsgSetNodeKeys` messages
*/
export declare const registerSetNodePubkeysCodecs: () => void;
/**
* Register type for encoding `MsgCreateOperator` messages
*/
export declare const registerCreateOperatorCodecs: () => void;
/**
* Register type for encoding `MsgRegisterChain` messages
*/
export declare const registerRegisterChainCodecs: () => void;
export declare const registerCreateEndpointCodecs: () => void;
/**
* Register type for encoding `MsgDeposit` messages
*/
export declare const registerDepositCodecs: () => void;
/**
* Register type for encoding `MsgSend` messages
*/
export declare const registerSendCodecs: () => void;
/**
* Register type for encoding `MsgSetIpAddress` messages
*/
export declare const registerSetIpAddrCodecs: () => void;
/**
* Parse transaction data from event logs
*
* @param {TxLog[]} logs List of tx logs
* @param {Address} address - Address to get transaction data for
* @returns {TxData} Parsed transaction data
*/
export declare const getDepositTxDataFromLogs: (logs: TxLog[], address: Address) => TxData;
/**
* Get the default fee.
*
* @returns {Fees} The default fee.
*/
export declare const getDefaultFees: () => Fees;
/**
* Get transaction type.
*
* @param {string} txData the transaction input data
* @param {string} encoding `base64` or `hex`
* @returns {string} the transaction type.
*/
export declare const getTxType: (txData: string, encoding: "base64" | "hex") => string;
/**
* Helper to get HermesChain's chain id
* @param {string} nodeUrl HermesNode url
*/
export declare const getChainId: (nodeUrl: string) => Promise<ChainId>;
/**
* Builds final unsigned TX
*
* @param cosmosSdk - CosmosSDK
* @param txBody - txBody with encoded Msgs
* @param signerPubkey - signerPubkey string
* @param sequence - account sequence
* @param gasLimit - transaction gas limit
* @returns
*/
export declare const buildUnsignedTx: ({ cosmosSdk, txBody, signerPubkey, sequence, gasLimit, }: {
cosmosSdk: cosmosclient.CosmosSDK;
txBody: proto.cosmos.tx.v1beta1.TxBody;
signerPubkey: proto.google.protobuf.Any;
sequence: Long;
gasLimit?: Long;
}) => cosmosclient.TxBuilder;
/**
* Estimates usage of gas
*
* Note: Be careful by using this helper function,
* it's still experimental and result might be incorrect.
* Change `multiplier` to get a valid estimation of gas.
*/
export declare const getEstimatedGas: ({ cosmosSDKClient, txBody, privKey, accountNumber, accountSequence, multiplier, }: {
cosmosSDKClient: CosmosSDKClient;
txBody: proto.cosmos.tx.v1beta1.TxBody;
privKey: proto.cosmos.crypto.secp256k1.PrivKey;
accountNumber: Long;
accountSequence: Long;
multiplier?: number;
}) => Promise<Long | undefined>;
export declare const buildRegisterChainTx: ({ msgRegisterChain, nodeUrl, chainId, }: {
msgRegisterChain: MsgRegisterChain;
nodeUrl: string;
chainId: ChainId;
}) => Promise<proto.cosmos.tx.v1beta1.TxBody>;
export declare const buildCreateEndpointTx: ({ msgCreateEndpoint, nodeUrl, chainId, }: {
msgCreateEndpoint: MsgCreateEndpoint;
nodeUrl: string;
chainId: ChainId;
}) => Promise<proto.cosmos.tx.v1beta1.TxBody>;
/**
* Builds a create operator transaction
* @param {MsgCreateOperator} msgCreateOperator
* @param {string} nodeUrl
* @param {ChainId} chainId
*/
export declare const buildCreateOperatorTx: ({ msgCreateOperator, nodeUrl, chainId, }: {
msgCreateOperator: MsgCreateOperator;
nodeUrl: string;
chainId: ChainId;
}) => Promise<proto.cosmos.tx.v1beta1.TxBody>;
/**
* Structure a MsgDeposit
*
* @param {MsgNativeTx} msgNativeTx Msg of type `MsgNativeTx`.
* @param {string} nodeUrl Node url
* @param {chainId} ChainId Chain id of the network
*
* @returns {Tx} The transaction details of the given transaction id.
*
* @throws {"Invalid client url"} Thrown if the client url is an invalid one.
*/
export declare const buildDepositTx: ({ msgNativeTx, nodeUrl, chainId, }: {
msgNativeTx: MsgNativeTx;
nodeUrl: string;
chainId: ChainId;
}) => Promise<proto.cosmos.tx.v1beta1.TxBody>;
/**
* Structure a MsgSetVersion
*
* @param {MsgSetVersionTx} msgSetVersionTx Msg of type `MsgSetVersionTx`.
* @param {string} nodeUrl Node url
* @param {chainId} ChainId Chain id of the network
*
* @returns {Tx} The transaction details of the given transaction id.
*
* @throws {"Invalid client url"} Thrown if the client url is an invalid one.
*/
export declare const buildSetVersionTx: ({ msgSetVersionTx, nodeUrl, chainId, }: {
msgSetVersionTx: MsgSetVersionTx;
nodeUrl: string;
chainId: ChainId;
}) => Promise<proto.cosmos.tx.v1beta1.TxBody>;
/**
* Structure a MsgSetNodeKeys
*
* @param {MsgSetPubkeysTx} msgSetPubkeysTx Msg of type `MsgSetPubkeysTx`.
* @param {string} nodeUrl Node url
* @param {chainId} ChainId Chain id of the network
*
* @returns {Tx} The transaction details of the given transaction id.
*
* @throws {"Invalid client url"} Thrown if the client url is an invalid one.
*/
export declare const buildSetPubkeysTx: ({ msgSetNodePubkeysTx, nodeUrl, chainId, }: {
msgSetNodePubkeysTx: MsgSetPubkeysTx;
nodeUrl: string;
chainId: ChainId;
}) => Promise<proto.cosmos.tx.v1beta1.TxBody>;
/**
* Structure a MsgSetIpAddress
*
* @param {MsgSetIpAddressTx} msgSetIpAddressTx Msg of type `MsgSetIpAddressTx`.
* @param {string} nodeUrl Node url
* @param {chainId} ChainId Chain id of the network
*
* @returns {Tx} The transaction details of the given transaction id.
*
* @throws {"Invalid client url"} Thrown if the client url is an invalid one.
*/
export declare const buildSetIpAddressTx: ({ msgSetIpAddressTx, nodeUrl, chainId, }: {
msgSetIpAddressTx: MsgSetIpAddressTx;
nodeUrl: string;
chainId: ChainId;
}) => Promise<proto.cosmos.tx.v1beta1.TxBody>;
/**
* Structure a MsgSend
*
* @param fromAddress - required, from address string
* @param toAddress - required, to address string
* @param assetAmount - required, asset amount string (e.g. "10000")
* @param assetDenom - required, asset denom string (e.g. "doj")
* @param memo - optional, memo string
*
* @returns
*/
export declare const buildTransferTx: ({ fromAddress, toAddress, assetAmount, assetDenom, memo, nodeUrl, chainId, }: {
fromAddress: Address;
toAddress: Address;
assetAmount: BaseAmount;
assetDenom: string;
memo?: string;
nodeUrl: string;
chainId: ChainId;
}) => Promise<proto.cosmos.tx.v1beta1.TxBody>;
/**
* 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)
* @param {cosmosClient} CosmosSDKClient
*
* @returns {Balance[]} The balance of the address.
*/
export declare const getBalance: ({ address, assets, cosmosClient, }: {
address: Address;
assets?: Asset[];
cosmosClient: CosmosSDKClient;
}) => Promise<Balance[]>;
/**
* Get the explorer url.
*
* @param {Network} network
* @param {ExplorerUrls} Explorer urls
* @returns {string} The explorer url for hermeschain based on the given network.
*/
export declare const getExplorerUrl: ({ root }: ExplorerUrls, network: Network) => string;
/**
* Get explorer address url.
*
* @param {ExplorerUrls} Explorer urls
* @param {Network} network
* @param {Address} address
* @returns {string} The explorer url for the given address.
*/
export declare const getExplorerAddressUrl: ({ urls, network, address, }: {
urls: ExplorerUrls;
network: Network;
address: Address;
}) => string;
/**
* Get transaction url.
*
* @param {ExplorerUrls} Explorer urls
* @param {Network} network
* @param {TxHash} txID
* @returns {string} The explorer url for the given transaction id.
*/
export declare const getExplorerTxUrl: ({ urls, network, txID, }: {
urls: ExplorerUrls;
network: Network;
txID: TxHash;
}) => string;
export type ComputeUnits = {
blockUnits: number;
txnUnits: number;
};