@xchainjs/xchain-client
Advanced tools
Comparing version 0.16.1 to 0.16.2
import { Address, Asset, Chain } from '@xchainjs/xchain-util'; | ||
/** | ||
* This abstract class serves as the base for XChain clients. | ||
* It provides common functionality and abstract methods that concrete XChain clients must implement. | ||
*/ | ||
import { AssetInfo, Balance, FeeBounds, FeeRate, Fees, Network, PreparedTx, RootDerivationPaths, Tx, TxHash, TxHistoryParams, TxParams, TxsPage, XChainClient, XChainClientParams } from './types'; | ||
@@ -10,20 +14,14 @@ export declare abstract class BaseXChainClient implements XChainClient { | ||
/** | ||
* Constructor | ||
* | ||
* Client has to be initialised with network type and phrase. | ||
* It will throw an error if an invalid phrase has been passed. | ||
* | ||
* @param {XChainClientParams} params | ||
* | ||
* @throws {"Invalid phrase"} Thrown if the given phase is invalid. | ||
* Constructor for the BaseXChainClient class. | ||
* Initializes the client with the provided chain and parameters. | ||
* @param {Chain} chain The blockchain chain identifier | ||
* @param {XChainClientParams} params The client parameters, including network, fee bounds, and root derivation paths | ||
* @throws {"Invalid phrase"} Thrown if an invalid mnemonic phrase is provided | ||
*/ | ||
constructor(chain: Chain, params: XChainClientParams); | ||
/** | ||
* Set/update the current network. | ||
* | ||
* @param {Network} network | ||
* Set or update the current network. | ||
* @param {Network} network The network to set | ||
* @returns {void} | ||
* | ||
* @throws {"Network must be provided"} | ||
* Thrown if network has not been set before. | ||
* @throws {"Network must be provided"} Thrown if no network is provided | ||
*/ | ||
@@ -33,29 +31,32 @@ setNetwork(network: Network): void; | ||
* Get the current network. | ||
* | ||
* @returns {Network} | ||
* @returns {Network} The current network | ||
*/ | ||
getNetwork(): Network; | ||
/** | ||
* Get the fee rate from the Thorchain API. | ||
* @returns {Promise<FeeRate>} The fee rate | ||
*/ | ||
protected getFeeRateFromThorchain(): Promise<FeeRate>; | ||
/** | ||
* Make a GET request to the Thorchain API. | ||
* @param {string} endpoint The API endpoint | ||
* @returns {Promise<unknown>} The response data | ||
*/ | ||
protected thornodeAPIGet(endpoint: string): Promise<unknown>; | ||
/** | ||
* Set/update a new phrase | ||
* | ||
* @param {string} phrase A new phrase. | ||
* @param {number} walletIndex (optional) HD wallet index | ||
* @returns {Address} The address from the given phrase | ||
* | ||
* @throws {"Invalid phrase"} | ||
* Thrown if the given phase is invalid. | ||
* Set or update the mnemonic phrase. | ||
* @param {string} phrase The new mnemonic phrase | ||
* @param {number} walletIndex (Optional) The HD wallet index | ||
* @returns {Address} The address derived from the provided phrase | ||
* @throws {"Invalid phrase"} Thrown if an invalid mnemonic phrase is provided | ||
*/ | ||
setPhrase(phrase: string, walletIndex?: number): Address; | ||
/** | ||
* Get getFullDerivationPath | ||
* | ||
* @param {number} walletIndex HD wallet index | ||
* @returns {string} The bitcoin derivation path based on the network. | ||
* Get the full derivation path based on the wallet index. | ||
* @param {number} walletIndex The HD wallet index | ||
* @returns {string} The full derivation path | ||
*/ | ||
protected getFullDerivationPath(walletIndex: number): string; | ||
/** | ||
* Purge client. | ||
* | ||
* Purge the client by clearing the mnemonic phrase. | ||
* @returns {void} | ||
@@ -62,0 +63,0 @@ */ |
import { Address } from '@xchainjs/xchain-util'; | ||
/** | ||
* ExplorerProvider class is responsible for generating URLs for blockchain explorers. | ||
* It constructs explorer URLs and replaces placeholders with specific addresses or transaction IDs. | ||
*/ | ||
export declare class ExplorerProvider { | ||
@@ -6,6 +10,30 @@ private explorerUrl; | ||
private explorerTxUrlTemplate; | ||
/** | ||
* Constructor for ExplorerProvider class. | ||
* | ||
* @param {string} explorerUrl The base URL of the blockchain explorer | ||
* @param {string} explorerAddressUrlTemplate The template URL for address exploration | ||
* @param {string} explorerTxUrlTemplate The template URL for transaction exploration | ||
*/ | ||
constructor(explorerUrl: string, explorerAddressUrlTemplate: string, explorerTxUrlTemplate: string); | ||
/** | ||
* Get the base URL of the blockchain explorer. | ||
* | ||
* @returns {string} The base URL of the blockchain explorer | ||
*/ | ||
getExplorerUrl(): string; | ||
/** | ||
* Get the URL for exploring a specific address. | ||
* | ||
* @param {Address} address The address to be explored | ||
* @returns {string} The URL for exploring the specified address | ||
*/ | ||
getExplorerAddressUrl(address: Address): string; | ||
/** | ||
* Get the URL for exploring a specific transaction. | ||
* | ||
* @param {string} txID The transaction ID to be explored | ||
* @returns {string} The URL for exploring the specified transaction | ||
*/ | ||
getExplorerTxUrl(txID: string): string; | ||
} |
import { FeeBounds, FeeRate, FeeRates } from './types'; | ||
/** | ||
* singleFeeRate function generates fee rates object with a single rate for all fee options. | ||
* | ||
* @param {FeeRate} rate The fee rate to be applied to all fee options. | ||
* @returns {FeeRates} The fee rates object with the provided rate for all fee options. | ||
*/ | ||
export declare function singleFeeRate(rate: FeeRate): FeeRates; | ||
/** | ||
* standardFeeRates function generates standard fee rates object based on a base rate. | ||
* | ||
* @param {FeeRate} rate The base fee rate to be applied to fee options. | ||
* @returns {FeeRates} The fee rates object with different rates for each fee option. | ||
*/ | ||
export declare function standardFeeRates(rate: FeeRate): FeeRates; | ||
/** | ||
* checkFeeBounds function checks if the given fee rate falls within predetermined bounds. | ||
* Throws an error if the fee rate is outside the bounds. | ||
* | ||
* @param {FeeBounds} feeBounds The predetermined fee rate bounds. | ||
* @param {FeeRate} feeRate The fee rate to be checked. | ||
* @throws {Error} Thrown if the fee rate is outside the predetermined bounds. | ||
*/ | ||
export declare function checkFeeBounds(feeBounds: FeeBounds, feeRate: FeeRate): void; |
import { Fee, FeeType, Fees } from './types'; | ||
/** | ||
* singleFee function generates a fees object with a single fee amount for all fee options. | ||
* | ||
* @param {FeeType} feeType The type of fee. | ||
* @param {Fee} amount The fee amount to be applied to all fee options. | ||
* @returns {Fees} The fees object with the provided fee amount for all fee options. | ||
*/ | ||
export declare function singleFee(feeType: FeeType, amount: Fee): Fees; | ||
/** | ||
* standardFees function generates standard fees object based on a base fee amount. | ||
* | ||
* @param {FeeType} feeType The type of fee. | ||
* @param {Fee} amount The base fee amount to be applied to fee options. | ||
* @returns {Fees} The fees object with different fee amounts for each fee option. | ||
*/ | ||
export declare function standardFees(feeType: FeeType, amount: Fee): Fees; |
@@ -0,1 +1,11 @@ | ||
/** | ||
* This file exports various modules related to XChainClient functionality: | ||
* - BaseXChainClient: The base class for XChainClient. | ||
* - types: Type definitions used within XChainClient. | ||
* - feeRates: Modules related to fee rates calculation and manipulation. | ||
* - fees: Modules related to fee calculation and manipulation. | ||
* - explorer-provider: Modules related to explorer providers. | ||
* - provider-types: Type definitions for provider-related functionality. | ||
* - protocols: Modules related to different blockchain protocols supported by XChainClient. | ||
*/ | ||
export * from './BaseXChainClient'; | ||
@@ -2,0 +12,0 @@ export * from './types'; |
@@ -29,2 +29,5 @@ import { validatePhrase } from '@xchainjs/xchain-crypto'; | ||
/** | ||
* Enumeration of network types. | ||
*/ | ||
var Network; | ||
@@ -36,2 +39,5 @@ (function (Network) { | ||
})(Network || (Network = {})); | ||
/** | ||
* Enumeration of transaction types. | ||
*/ | ||
var TxType; | ||
@@ -42,2 +48,5 @@ (function (TxType) { | ||
})(TxType || (TxType = {})); | ||
/** | ||
* Enumeration of fee options. | ||
*/ | ||
var FeeOption; | ||
@@ -49,2 +58,5 @@ (function (FeeOption) { | ||
})(FeeOption || (FeeOption = {})); | ||
/** | ||
* Enumeration of fee types. | ||
*/ | ||
var FeeType; | ||
@@ -61,17 +73,15 @@ (function (FeeType) { | ||
/** | ||
* Constructor | ||
* | ||
* Client has to be initialised with network type and phrase. | ||
* It will throw an error if an invalid phrase has been passed. | ||
* | ||
* @param {XChainClientParams} params | ||
* | ||
* @throws {"Invalid phrase"} Thrown if the given phase is invalid. | ||
* Constructor for the BaseXChainClient class. | ||
* Initializes the client with the provided chain and parameters. | ||
* @param {Chain} chain The blockchain chain identifier | ||
* @param {XChainClientParams} params The client parameters, including network, fee bounds, and root derivation paths | ||
* @throws {"Invalid phrase"} Thrown if an invalid mnemonic phrase is provided | ||
*/ | ||
constructor(chain, params) { | ||
this.phrase = ''; | ||
this.phrase = ''; // The mnemonic phrase used for wallet generation | ||
// Initialize class properties | ||
this.chain = chain; | ||
this.network = params.network || Network.Testnet; | ||
this.feeBounds = params.feeBounds || { lower: 1, upper: Infinity }; | ||
// Fire off a warning in the console to indicate that stagenet and real assets are being used. | ||
// Warn if using Stagenet for real assets | ||
if (this.network === Network.Stagenet) | ||
@@ -81,3 +91,3 @@ console.warn('WARNING: This is using stagenet! Real assets are being used!'); | ||
this.rootDerivationPaths = params.rootDerivationPaths; | ||
//NOTE: we don't call this.setPhrase() to vaoid generating an address and paying the perf penalty | ||
// Set the mnemonic phrase if provided | ||
if (params.phrase) { | ||
@@ -91,9 +101,6 @@ if (!validatePhrase(params.phrase)) { | ||
/** | ||
* Set/update the current network. | ||
* | ||
* @param {Network} network | ||
* Set or update the current network. | ||
* @param {Network} network The network to set | ||
* @returns {void} | ||
* | ||
* @throws {"Network must be provided"} | ||
* Thrown if network has not been set before. | ||
* @throws {"Network must be provided"} Thrown if no network is provided | ||
*/ | ||
@@ -105,3 +112,3 @@ setNetwork(network) { | ||
this.network = network; | ||
// Fire off a warning in the console to indicate that stagenet and real assets are being used. | ||
// Warn if using Stagenet for real assets | ||
if (this.network === Network.Stagenet) | ||
@@ -112,4 +119,3 @@ console.warn('WARNING: This is using stagenet! Real assets are being used!'); | ||
* Get the current network. | ||
* | ||
* @returns {Network} | ||
* @returns {Network} The current network | ||
*/ | ||
@@ -119,2 +125,6 @@ getNetwork() { | ||
} | ||
/** | ||
* Get the fee rate from the Thorchain API. | ||
* @returns {Promise<FeeRate>} The fee rate | ||
*/ | ||
getFeeRateFromThorchain() { | ||
@@ -131,2 +141,7 @@ return __awaiter(this, void 0, void 0, function* () { | ||
} | ||
/** | ||
* Make a GET request to the Thorchain API. | ||
* @param {string} endpoint The API endpoint | ||
* @returns {Promise<unknown>} The response data | ||
*/ | ||
thornodeAPIGet(endpoint) { | ||
@@ -148,10 +163,7 @@ return __awaiter(this, void 0, void 0, function* () { | ||
/** | ||
* Set/update a new phrase | ||
* | ||
* @param {string} phrase A new phrase. | ||
* @param {number} walletIndex (optional) HD wallet index | ||
* @returns {Address} The address from the given phrase | ||
* | ||
* @throws {"Invalid phrase"} | ||
* Thrown if the given phase is invalid. | ||
* Set or update the mnemonic phrase. | ||
* @param {string} phrase The new mnemonic phrase | ||
* @param {number} walletIndex (Optional) The HD wallet index | ||
* @returns {Address} The address derived from the provided phrase | ||
* @throws {"Invalid phrase"} Thrown if an invalid mnemonic phrase is provided | ||
*/ | ||
@@ -168,6 +180,5 @@ setPhrase(phrase, walletIndex = 0) { | ||
/** | ||
* Get getFullDerivationPath | ||
* | ||
* @param {number} walletIndex HD wallet index | ||
* @returns {string} The bitcoin derivation path based on the network. | ||
* Get the full derivation path based on the wallet index. | ||
* @param {number} walletIndex The HD wallet index | ||
* @returns {string} The full derivation path | ||
*/ | ||
@@ -178,4 +189,3 @@ getFullDerivationPath(walletIndex) { | ||
/** | ||
* Purge client. | ||
* | ||
* Purge the client by clearing the mnemonic phrase. | ||
* @returns {void} | ||
@@ -188,8 +198,28 @@ */ | ||
/** | ||
* singleFeeRate function generates fee rates object with a single rate for all fee options. | ||
* | ||
* @param {FeeRate} rate The fee rate to be applied to all fee options. | ||
* @returns {FeeRates} The fee rates object with the provided rate for all fee options. | ||
*/ | ||
function singleFeeRate(rate) { | ||
return Object.values(FeeOption).reduce((a, x) => ((a[x] = rate), a), {}); | ||
} | ||
/** | ||
* standardFeeRates function generates standard fee rates object based on a base rate. | ||
* | ||
* @param {FeeRate} rate The base fee rate to be applied to fee options. | ||
* @returns {FeeRates} The fee rates object with different rates for each fee option. | ||
*/ | ||
function standardFeeRates(rate) { | ||
return Object.assign(Object.assign({}, singleFeeRate(rate)), { [FeeOption.Average]: rate * 0.5, [FeeOption.Fastest]: rate * 5.0 }); | ||
} | ||
/** | ||
* checkFeeBounds function checks if the given fee rate falls within predetermined bounds. | ||
* Throws an error if the fee rate is outside the bounds. | ||
* | ||
* @param {FeeBounds} feeBounds The predetermined fee rate bounds. | ||
* @param {FeeRate} feeRate The fee rate to be checked. | ||
* @throws {Error} Thrown if the fee rate is outside the predetermined bounds. | ||
*/ | ||
function checkFeeBounds(feeBounds, feeRate) { | ||
@@ -201,2 +231,9 @@ if (feeRate < feeBounds.lower || feeRate > feeBounds.upper) { | ||
/** | ||
* singleFee function generates a fees object with a single fee amount for all fee options. | ||
* | ||
* @param {FeeType} feeType The type of fee. | ||
* @param {Fee} amount The fee amount to be applied to all fee options. | ||
* @returns {Fees} The fees object with the provided fee amount for all fee options. | ||
*/ | ||
function singleFee(feeType, amount) { | ||
@@ -207,2 +244,9 @@ return Object.values(FeeOption).reduce((a, x) => ((a[x] = amount), a), { | ||
} | ||
/** | ||
* standardFees function generates standard fees object based on a base fee amount. | ||
* | ||
* @param {FeeType} feeType The type of fee. | ||
* @param {Fee} amount The base fee amount to be applied to fee options. | ||
* @returns {Fees} The fees object with different fee amounts for each fee option. | ||
*/ | ||
function standardFees(feeType, amount) { | ||
@@ -212,19 +256,50 @@ return Object.assign(Object.assign({}, singleFee(feeType, amount)), { [FeeOption.Average]: amount.times(0.5), [FeeOption.Fastest]: amount.times(5.0) }); | ||
/** | ||
* ExplorerProvider class is responsible for generating URLs for blockchain explorers. | ||
* It constructs explorer URLs and replaces placeholders with specific addresses or transaction IDs. | ||
*/ | ||
class ExplorerProvider { | ||
/** | ||
* Constructor for ExplorerProvider class. | ||
* | ||
* @param {string} explorerUrl The base URL of the blockchain explorer | ||
* @param {string} explorerAddressUrlTemplate The template URL for address exploration | ||
* @param {string} explorerTxUrlTemplate The template URL for transaction exploration | ||
*/ | ||
constructor(explorerUrl, explorerAddressUrlTemplate, explorerTxUrlTemplate) { | ||
this.explorerUrl = explorerUrl; | ||
this.explorerAddressUrlTemplate = explorerAddressUrlTemplate; | ||
this.explorerTxUrlTemplate = explorerTxUrlTemplate; | ||
this.explorerUrl = explorerUrl; // Initialize explorerUrl property | ||
this.explorerAddressUrlTemplate = explorerAddressUrlTemplate; // Initialize explorerAddressUrlTemplate property | ||
this.explorerTxUrlTemplate = explorerTxUrlTemplate; // Initialize explorerTxUrlTemplate property | ||
} | ||
/** | ||
* Get the base URL of the blockchain explorer. | ||
* | ||
* @returns {string} The base URL of the blockchain explorer | ||
*/ | ||
getExplorerUrl() { | ||
return this.explorerUrl; | ||
return this.explorerUrl; // Return the explorerUrl property | ||
} | ||
/** | ||
* Get the URL for exploring a specific address. | ||
* | ||
* @param {Address} address The address to be explored | ||
* @returns {string} The URL for exploring the specified address | ||
*/ | ||
getExplorerAddressUrl(address) { | ||
return this.explorerAddressUrlTemplate.replace('%%ADDRESS%%', address); | ||
return this.explorerAddressUrlTemplate.replace('%%ADDRESS%%', address); // Replace the placeholder in the URL with the specified address | ||
} | ||
/** | ||
* Get the URL for exploring a specific transaction. | ||
* | ||
* @param {string} txID The transaction ID to be explored | ||
* @returns {string} The URL for exploring the specified transaction | ||
*/ | ||
getExplorerTxUrl(txID) { | ||
return this.explorerTxUrlTemplate.replace('%%TX_ID%%', txID); | ||
return this.explorerTxUrlTemplate.replace('%%TX_ID%%', txID); // Replace the placeholder in the URL with the specified transaction ID | ||
} | ||
} | ||
/** | ||
* Enum defining supported blockchain protocols. | ||
*/ | ||
var Protocol; | ||
@@ -231,0 +306,0 @@ (function (Protocol) { |
155
lib/index.js
@@ -37,2 +37,5 @@ 'use strict'; | ||
/** | ||
* Enumeration of network types. | ||
*/ | ||
exports.Network = void 0; | ||
@@ -44,2 +47,5 @@ (function (Network) { | ||
})(exports.Network || (exports.Network = {})); | ||
/** | ||
* Enumeration of transaction types. | ||
*/ | ||
exports.TxType = void 0; | ||
@@ -50,2 +56,5 @@ (function (TxType) { | ||
})(exports.TxType || (exports.TxType = {})); | ||
/** | ||
* Enumeration of fee options. | ||
*/ | ||
exports.FeeOption = void 0; | ||
@@ -57,2 +66,5 @@ (function (FeeOption) { | ||
})(exports.FeeOption || (exports.FeeOption = {})); | ||
/** | ||
* Enumeration of fee types. | ||
*/ | ||
exports.FeeType = void 0; | ||
@@ -69,17 +81,15 @@ (function (FeeType) { | ||
/** | ||
* Constructor | ||
* | ||
* Client has to be initialised with network type and phrase. | ||
* It will throw an error if an invalid phrase has been passed. | ||
* | ||
* @param {XChainClientParams} params | ||
* | ||
* @throws {"Invalid phrase"} Thrown if the given phase is invalid. | ||
* Constructor for the BaseXChainClient class. | ||
* Initializes the client with the provided chain and parameters. | ||
* @param {Chain} chain The blockchain chain identifier | ||
* @param {XChainClientParams} params The client parameters, including network, fee bounds, and root derivation paths | ||
* @throws {"Invalid phrase"} Thrown if an invalid mnemonic phrase is provided | ||
*/ | ||
constructor(chain, params) { | ||
this.phrase = ''; | ||
this.phrase = ''; // The mnemonic phrase used for wallet generation | ||
// Initialize class properties | ||
this.chain = chain; | ||
this.network = params.network || exports.Network.Testnet; | ||
this.feeBounds = params.feeBounds || { lower: 1, upper: Infinity }; | ||
// Fire off a warning in the console to indicate that stagenet and real assets are being used. | ||
// Warn if using Stagenet for real assets | ||
if (this.network === exports.Network.Stagenet) | ||
@@ -89,3 +99,3 @@ console.warn('WARNING: This is using stagenet! Real assets are being used!'); | ||
this.rootDerivationPaths = params.rootDerivationPaths; | ||
//NOTE: we don't call this.setPhrase() to vaoid generating an address and paying the perf penalty | ||
// Set the mnemonic phrase if provided | ||
if (params.phrase) { | ||
@@ -99,9 +109,6 @@ if (!xchainCrypto.validatePhrase(params.phrase)) { | ||
/** | ||
* Set/update the current network. | ||
* | ||
* @param {Network} network | ||
* Set or update the current network. | ||
* @param {Network} network The network to set | ||
* @returns {void} | ||
* | ||
* @throws {"Network must be provided"} | ||
* Thrown if network has not been set before. | ||
* @throws {"Network must be provided"} Thrown if no network is provided | ||
*/ | ||
@@ -113,3 +120,3 @@ setNetwork(network) { | ||
this.network = network; | ||
// Fire off a warning in the console to indicate that stagenet and real assets are being used. | ||
// Warn if using Stagenet for real assets | ||
if (this.network === exports.Network.Stagenet) | ||
@@ -120,4 +127,3 @@ console.warn('WARNING: This is using stagenet! Real assets are being used!'); | ||
* Get the current network. | ||
* | ||
* @returns {Network} | ||
* @returns {Network} The current network | ||
*/ | ||
@@ -127,2 +133,6 @@ getNetwork() { | ||
} | ||
/** | ||
* Get the fee rate from the Thorchain API. | ||
* @returns {Promise<FeeRate>} The fee rate | ||
*/ | ||
getFeeRateFromThorchain() { | ||
@@ -139,2 +149,7 @@ return __awaiter(this, void 0, void 0, function* () { | ||
} | ||
/** | ||
* Make a GET request to the Thorchain API. | ||
* @param {string} endpoint The API endpoint | ||
* @returns {Promise<unknown>} The response data | ||
*/ | ||
thornodeAPIGet(endpoint) { | ||
@@ -156,10 +171,7 @@ return __awaiter(this, void 0, void 0, function* () { | ||
/** | ||
* Set/update a new phrase | ||
* | ||
* @param {string} phrase A new phrase. | ||
* @param {number} walletIndex (optional) HD wallet index | ||
* @returns {Address} The address from the given phrase | ||
* | ||
* @throws {"Invalid phrase"} | ||
* Thrown if the given phase is invalid. | ||
* Set or update the mnemonic phrase. | ||
* @param {string} phrase The new mnemonic phrase | ||
* @param {number} walletIndex (Optional) The HD wallet index | ||
* @returns {Address} The address derived from the provided phrase | ||
* @throws {"Invalid phrase"} Thrown if an invalid mnemonic phrase is provided | ||
*/ | ||
@@ -176,6 +188,5 @@ setPhrase(phrase, walletIndex = 0) { | ||
/** | ||
* Get getFullDerivationPath | ||
* | ||
* @param {number} walletIndex HD wallet index | ||
* @returns {string} The bitcoin derivation path based on the network. | ||
* Get the full derivation path based on the wallet index. | ||
* @param {number} walletIndex The HD wallet index | ||
* @returns {string} The full derivation path | ||
*/ | ||
@@ -186,4 +197,3 @@ getFullDerivationPath(walletIndex) { | ||
/** | ||
* Purge client. | ||
* | ||
* Purge the client by clearing the mnemonic phrase. | ||
* @returns {void} | ||
@@ -196,8 +206,28 @@ */ | ||
/** | ||
* singleFeeRate function generates fee rates object with a single rate for all fee options. | ||
* | ||
* @param {FeeRate} rate The fee rate to be applied to all fee options. | ||
* @returns {FeeRates} The fee rates object with the provided rate for all fee options. | ||
*/ | ||
function singleFeeRate(rate) { | ||
return Object.values(exports.FeeOption).reduce((a, x) => ((a[x] = rate), a), {}); | ||
} | ||
/** | ||
* standardFeeRates function generates standard fee rates object based on a base rate. | ||
* | ||
* @param {FeeRate} rate The base fee rate to be applied to fee options. | ||
* @returns {FeeRates} The fee rates object with different rates for each fee option. | ||
*/ | ||
function standardFeeRates(rate) { | ||
return Object.assign(Object.assign({}, singleFeeRate(rate)), { [exports.FeeOption.Average]: rate * 0.5, [exports.FeeOption.Fastest]: rate * 5.0 }); | ||
} | ||
/** | ||
* checkFeeBounds function checks if the given fee rate falls within predetermined bounds. | ||
* Throws an error if the fee rate is outside the bounds. | ||
* | ||
* @param {FeeBounds} feeBounds The predetermined fee rate bounds. | ||
* @param {FeeRate} feeRate The fee rate to be checked. | ||
* @throws {Error} Thrown if the fee rate is outside the predetermined bounds. | ||
*/ | ||
function checkFeeBounds(feeBounds, feeRate) { | ||
@@ -209,2 +239,9 @@ if (feeRate < feeBounds.lower || feeRate > feeBounds.upper) { | ||
/** | ||
* singleFee function generates a fees object with a single fee amount for all fee options. | ||
* | ||
* @param {FeeType} feeType The type of fee. | ||
* @param {Fee} amount The fee amount to be applied to all fee options. | ||
* @returns {Fees} The fees object with the provided fee amount for all fee options. | ||
*/ | ||
function singleFee(feeType, amount) { | ||
@@ -215,2 +252,9 @@ return Object.values(exports.FeeOption).reduce((a, x) => ((a[x] = amount), a), { | ||
} | ||
/** | ||
* standardFees function generates standard fees object based on a base fee amount. | ||
* | ||
* @param {FeeType} feeType The type of fee. | ||
* @param {Fee} amount The base fee amount to be applied to fee options. | ||
* @returns {Fees} The fees object with different fee amounts for each fee option. | ||
*/ | ||
function standardFees(feeType, amount) { | ||
@@ -220,19 +264,50 @@ return Object.assign(Object.assign({}, singleFee(feeType, amount)), { [exports.FeeOption.Average]: amount.times(0.5), [exports.FeeOption.Fastest]: amount.times(5.0) }); | ||
/** | ||
* ExplorerProvider class is responsible for generating URLs for blockchain explorers. | ||
* It constructs explorer URLs and replaces placeholders with specific addresses or transaction IDs. | ||
*/ | ||
class ExplorerProvider { | ||
/** | ||
* Constructor for ExplorerProvider class. | ||
* | ||
* @param {string} explorerUrl The base URL of the blockchain explorer | ||
* @param {string} explorerAddressUrlTemplate The template URL for address exploration | ||
* @param {string} explorerTxUrlTemplate The template URL for transaction exploration | ||
*/ | ||
constructor(explorerUrl, explorerAddressUrlTemplate, explorerTxUrlTemplate) { | ||
this.explorerUrl = explorerUrl; | ||
this.explorerAddressUrlTemplate = explorerAddressUrlTemplate; | ||
this.explorerTxUrlTemplate = explorerTxUrlTemplate; | ||
this.explorerUrl = explorerUrl; // Initialize explorerUrl property | ||
this.explorerAddressUrlTemplate = explorerAddressUrlTemplate; // Initialize explorerAddressUrlTemplate property | ||
this.explorerTxUrlTemplate = explorerTxUrlTemplate; // Initialize explorerTxUrlTemplate property | ||
} | ||
/** | ||
* Get the base URL of the blockchain explorer. | ||
* | ||
* @returns {string} The base URL of the blockchain explorer | ||
*/ | ||
getExplorerUrl() { | ||
return this.explorerUrl; | ||
return this.explorerUrl; // Return the explorerUrl property | ||
} | ||
/** | ||
* Get the URL for exploring a specific address. | ||
* | ||
* @param {Address} address The address to be explored | ||
* @returns {string} The URL for exploring the specified address | ||
*/ | ||
getExplorerAddressUrl(address) { | ||
return this.explorerAddressUrlTemplate.replace('%%ADDRESS%%', address); | ||
return this.explorerAddressUrlTemplate.replace('%%ADDRESS%%', address); // Replace the placeholder in the URL with the specified address | ||
} | ||
/** | ||
* Get the URL for exploring a specific transaction. | ||
* | ||
* @param {string} txID The transaction ID to be explored | ||
* @returns {string} The URL for exploring the specified transaction | ||
*/ | ||
getExplorerTxUrl(txID) { | ||
return this.explorerTxUrlTemplate.replace('%%TX_ID%%', txID); | ||
return this.explorerTxUrlTemplate.replace('%%TX_ID%%', txID); // Replace the placeholder in the URL with the specified transaction ID | ||
} | ||
} | ||
/** | ||
* Enum defining supported blockchain protocols. | ||
*/ | ||
exports.Protocol = void 0; | ||
@@ -239,0 +314,0 @@ (function (Protocol) { |
@@ -0,3 +1,6 @@ | ||
/** | ||
* Enum defining supported blockchain protocols. | ||
*/ | ||
export declare enum Protocol { | ||
THORCHAIN = 1 | ||
} |
import { Address, Asset } from '@xchainjs/xchain-util'; | ||
import { ExplorerProvider } from './explorer-provider'; | ||
import { Balance, FeeRates, Network, Tx, TxHistoryParams, TxsPage } from './types'; | ||
/** | ||
* Interface for online data providers. | ||
*/ | ||
export interface OnlineDataProvider { | ||
/** | ||
* Get the balance for a given address. | ||
* @param {Address} address The address to get the balance for. | ||
* @param {Asset[]} assets (Optional) An array of assets to get the balance for. | ||
* @returns {Promise<Balance[]>} A promise that resolves to an array of balances. | ||
*/ | ||
getBalance(address: Address, assets?: Asset[]): Promise<Balance[]>; | ||
/** | ||
* Get transactions based on provided parameters. | ||
* @param {TxHistoryParams} params The parameters for fetching transactions. | ||
* @returns {Promise<TxsPage>} A promise that resolves to a page of transactions. | ||
*/ | ||
getTransactions(params: TxHistoryParams): Promise<TxsPage>; | ||
/** | ||
* Get transaction data based on its ID. | ||
* @param {string} txId The ID of the transaction. | ||
* @param {Address} assetAddress (Optional) The address of the asset. | ||
* @returns {Promise<Tx>} A promise that resolves to the transaction data. | ||
*/ | ||
getTransactionData(txId: string, assetAddress?: Address): Promise<Tx>; | ||
/** | ||
* Get the fee rates. | ||
* @returns {Promise<FeeRates>} A promise that resolves to the fee rates. | ||
*/ | ||
getFeeRates(): Promise<FeeRates>; | ||
} | ||
/** | ||
* Type alias for Ethereum Virtual Machine (EVM) online data provider. | ||
*/ | ||
export type EvmOnlineDataProvider = OnlineDataProvider; | ||
/** | ||
* Type alias for explorer providers. | ||
*/ | ||
export type ExplorerProviders = Record<Network, ExplorerProvider>; | ||
/** | ||
* Type alias for online data providers. | ||
*/ | ||
export type OnlineDataProviders = Record<Network, OnlineDataProvider | undefined>; | ||
/** | ||
* Type alias for EVM online data providers. | ||
*/ | ||
export type EvmOnlineDataProviders = Record<Network, EvmOnlineDataProvider | undefined>; |
import { Address, Asset, BaseAmount } from '@xchainjs/xchain-util'; | ||
/** | ||
* Enumeration of network types. | ||
*/ | ||
export declare enum Network { | ||
@@ -7,2 +10,5 @@ Mainnet = "mainnet", | ||
} | ||
/** | ||
* Type definition for asset information. | ||
*/ | ||
export type AssetInfo = { | ||
@@ -12,2 +18,5 @@ asset: Asset; | ||
}; | ||
/** | ||
* Type definition for a balance. | ||
*/ | ||
export type Balance = { | ||
@@ -17,2 +26,5 @@ asset: Asset; | ||
}; | ||
/** | ||
* Enumeration of transaction types. | ||
*/ | ||
export declare enum TxType { | ||
@@ -22,3 +34,9 @@ Transfer = "transfer", | ||
} | ||
/** | ||
* Type definition for a transaction hash. | ||
*/ | ||
export type TxHash = string; | ||
/** | ||
* Type definition for the recipient of a transaction. | ||
*/ | ||
export type TxTo = { | ||
@@ -29,2 +47,5 @@ to: Address; | ||
}; | ||
/** | ||
* Type definition for the sender of a transaction. | ||
*/ | ||
export type TxFrom = { | ||
@@ -35,2 +56,5 @@ from: Address | TxHash; | ||
}; | ||
/** | ||
* Type definition for a transaction. | ||
*/ | ||
export type Tx = { | ||
@@ -44,2 +68,5 @@ asset: Asset; | ||
}; | ||
/** | ||
* Type definition for a page of transactions. | ||
*/ | ||
export type TxsPage = { | ||
@@ -49,2 +76,5 @@ total: number; | ||
}; | ||
/** | ||
* Type definition for parameters used to retrieve transaction history. | ||
*/ | ||
export type TxHistoryParams = { | ||
@@ -57,2 +87,5 @@ address: Address; | ||
}; | ||
/** | ||
* Type definition for transaction parameters. | ||
*/ | ||
export type TxParams = { | ||
@@ -65,2 +98,5 @@ walletIndex?: number; | ||
}; | ||
/** | ||
* Type definition for fee estimate options. | ||
*/ | ||
export type FeeEstimateOptions = { | ||
@@ -70,2 +106,5 @@ memo?: string; | ||
}; | ||
/** | ||
* Enumeration of fee options. | ||
*/ | ||
export declare enum FeeOption { | ||
@@ -76,4 +115,13 @@ Average = "average", | ||
} | ||
/** | ||
* Type definition for a fee rate. | ||
*/ | ||
export type FeeRate = number; | ||
/** | ||
* Type definition for fee rates. | ||
*/ | ||
export type FeeRates = Record<FeeOption, FeeRate>; | ||
/** | ||
* Enumeration of fee types. | ||
*/ | ||
export declare enum FeeType { | ||
@@ -83,6 +131,15 @@ FlatFee = "base", | ||
} | ||
/** | ||
* Type definition for a fee. | ||
*/ | ||
export type Fee = BaseAmount; | ||
/** | ||
* Type definition for fees. | ||
*/ | ||
export type Fees = Record<FeeOption, Fee> & { | ||
type: FeeType; | ||
}; | ||
/** | ||
* Type definition for fees with rates. | ||
*/ | ||
export type FeesWithRates = { | ||
@@ -92,2 +149,5 @@ rates: FeeRates; | ||
}; | ||
/** | ||
* Type definition for fee bounds. | ||
*/ | ||
export type FeeBounds = { | ||
@@ -97,3 +157,9 @@ lower: number; | ||
}; | ||
/** | ||
* Type definition for root derivation paths. | ||
*/ | ||
export type RootDerivationPaths = Record<Network, string>; | ||
/** | ||
* Type definition for parameters used to configure an XChain client. | ||
*/ | ||
export type XChainClientParams = { | ||
@@ -105,5 +171,11 @@ network?: Network; | ||
}; | ||
/** | ||
* Type definition for a prepared transaction. | ||
*/ | ||
export type PreparedTx = { | ||
rawUnsignedTx: string; | ||
}; | ||
/** | ||
* Interface for an XChain client. | ||
*/ | ||
export interface XChainClient { | ||
@@ -110,0 +182,0 @@ setNetwork(net: Network): void; |
{ | ||
"name": "@xchainjs/xchain-client", | ||
"version": "0.16.1", | ||
"version": "0.16.2", | ||
"license": "MIT", | ||
@@ -15,3 +15,3 @@ "main": "lib/index.js", | ||
"scripts": { | ||
"clean": "rimraf lib/**", | ||
"clean": "rimraf --glob ./lib/**", | ||
"build": "yarn clean && rollup -c", | ||
@@ -23,3 +23,3 @@ "compile": "tsc -p tsconfig.build.json", | ||
"devDependencies": { | ||
"@xchainjs/xchain-util": "^0.13.1", | ||
"@xchainjs/xchain-util": "^0.13.3", | ||
"@xchainjs/xchain-crypto": "^0.3.1", | ||
@@ -29,6 +29,6 @@ "axios": "^1.3.6" | ||
"peerDependencies": { | ||
"@xchainjs/xchain-util": "^0.13.1", | ||
"@xchainjs/xchain-util": "^0.13.3", | ||
"@xchainjs/xchain-crypto": "^0.3.1", | ||
"axios": "^1.3.6" | ||
} | ||
} | ||
} |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
85073
985