Socket
Socket
Sign inDemoInstall

@xchainjs/xchain-client

Package Overview
Dependencies
Maintainers
10
Versions
57
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@xchainjs/xchain-client - npm Package Compare versions

Comparing version 0.15.3 to 0.15.4

52

lib/index.esm.js

@@ -206,2 +206,6 @@ import { validatePhrase } from '@xchainjs/xchain-crypto';

var Protocol;
(function (Protocol) {
Protocol[Protocol["THORCHAIN"] = 1] = "THORCHAIN";
})(Protocol || (Protocol = {}));
class UTXOClient extends BaseXChainClient {

@@ -316,2 +320,3 @@ calcFee(feeRate, options) {

return {
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore

@@ -329,14 +334,30 @@ fees: yield calcFeesAsync(rates, this.calcFee.bind(this), options),

}
getFeeRates() {
/**
* Get fee rates
* @param {Protocol} protocol Protocol to interact with. If there's no protocol provided, fee rates are retrieved from chain data providers
*
* @returns {FeeRates} The fee rates (average, fast, fastest) in `Satoshis/byte`
*/
getFeeRates(protocol) {
return __awaiter(this, void 0, void 0, function* () {
const feeRate = yield (() => __awaiter(this, void 0, void 0, function* () {
if (!protocol) {
try {
return yield this.getFeeRateFromThorchain();
const feeRates = yield this.roundRobinGetFeeRates();
return feeRates;
}
catch (error) {
console.warn(`Rate lookup via Thorchain failed: ${error}`);
console.warn('Can not retrieve fee rates from provider');
}
return yield this.getSuggestedFeeRate();
}))();
return standardFeeRates(feeRate);
}
if (!protocol || Protocol.THORCHAIN) {
try {
const feeRate = yield this.getFeeRateFromThorchain();
return standardFeeRates(feeRate);
}
catch (error) {
console.warn(`Can not retrieve fee rates from Thorchain`);
}
}
// TODO: Return default value
throw Error('Can not retrieve fee rates');
});

@@ -425,2 +446,17 @@ }

}
roundRobinGetFeeRates() {
return __awaiter(this, void 0, void 0, function* () {
for (const provider of this.dataProviders) {
try {
const prov = provider[this.network];
if (prov)
return yield prov.getFeeRates();
}
catch (error) {
console.warn(error);
}
}
throw Error('no provider able to get fee rates');
});
}
}

@@ -445,3 +481,3 @@

export { BaseXChainClient, ExplorerProvider, FeeOption, FeeType, Network, TxType, UTXOClient, calcFees, calcFeesAsync, checkFeeBounds, singleFee, singleFeeRate, standardFeeRates, standardFees };
export { BaseXChainClient, ExplorerProvider, FeeOption, FeeType, Network, Protocol, TxType, UTXOClient, calcFees, calcFeesAsync, checkFeeBounds, singleFee, singleFeeRate, standardFeeRates, standardFees };
//# sourceMappingURL=index.esm.js.map

@@ -214,2 +214,6 @@ 'use strict';

exports.Protocol = void 0;
(function (Protocol) {
Protocol[Protocol["THORCHAIN"] = 1] = "THORCHAIN";
})(exports.Protocol || (exports.Protocol = {}));
class UTXOClient extends BaseXChainClient {

@@ -324,2 +328,3 @@ calcFee(feeRate, options) {

return {
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore

@@ -337,14 +342,30 @@ fees: yield calcFeesAsync(rates, this.calcFee.bind(this), options),

}
getFeeRates() {
/**
* Get fee rates
* @param {Protocol} protocol Protocol to interact with. If there's no protocol provided, fee rates are retrieved from chain data providers
*
* @returns {FeeRates} The fee rates (average, fast, fastest) in `Satoshis/byte`
*/
getFeeRates(protocol) {
return __awaiter(this, void 0, void 0, function* () {
const feeRate = yield (() => __awaiter(this, void 0, void 0, function* () {
if (!protocol) {
try {
return yield this.getFeeRateFromThorchain();
const feeRates = yield this.roundRobinGetFeeRates();
return feeRates;
}
catch (error) {
console.warn(`Rate lookup via Thorchain failed: ${error}`);
console.warn('Can not retrieve fee rates from provider');
}
return yield this.getSuggestedFeeRate();
}))();
return standardFeeRates(feeRate);
}
if (!protocol || exports.Protocol.THORCHAIN) {
try {
const feeRate = yield this.getFeeRateFromThorchain();
return standardFeeRates(feeRate);
}
catch (error) {
console.warn(`Can not retrieve fee rates from Thorchain`);
}
}
// TODO: Return default value
throw Error('Can not retrieve fee rates');
});

@@ -433,2 +454,17 @@ }

}
roundRobinGetFeeRates() {
return __awaiter(this, void 0, void 0, function* () {
for (const provider of this.dataProviders) {
try {
const prov = provider[this.network];
if (prov)
return yield prov.getFeeRates();
}
catch (error) {
console.warn(error);
}
}
throw Error('no provider able to get fee rates');
});
}
}

@@ -435,0 +471,0 @@

5

lib/provider-types.d.ts

@@ -21,2 +21,3 @@ /// <reference types="node" />

getTransactionData(txId: string, assetAddress?: Address): Promise<Tx>;
getFeeRates(): Promise<FeeRates>;
}

@@ -28,5 +29,3 @@ export interface UtxoOnlineDataProvider extends OnlineDataProvider {

}
export interface EvmOnlineDataProvider extends OnlineDataProvider {
getFeeRates(): Promise<FeeRates>;
}
export type EvmOnlineDataProvider = OnlineDataProvider;
export type ExplorerProviders = Record<Network, ExplorerProvider>;

@@ -33,0 +32,0 @@ export type OnlineDataProviders = Record<Network, OnlineDataProvider | undefined>;

@@ -10,6 +10,8 @@ /// <reference types="node" />

};
export declare enum Protocol {
THORCHAIN = 1
}
export declare abstract class UTXOClient extends Client {
protected explorerProviders: ExplorerProviders;
protected dataProviders: UtxoOnlineDataProviders[];
protected abstract getSuggestedFeeRate(): Promise<FeeRate>;
protected abstract compileMemo(memo: string): Buffer;

@@ -73,3 +75,9 @@ protected abstract getFeeFromUtxos(inputs: UTXO[], feeRate: FeeRate, data: Buffer | null): number;

getFees(options?: FeeEstimateOptions): Promise<Fees>;
getFeeRates(): Promise<FeeRates>;
/**
* Get fee rates
* @param {Protocol} protocol Protocol to interact with. If there's no protocol provided, fee rates are retrieved from chain data providers
*
* @returns {FeeRates} The fee rates (average, fast, fastest) in `Satoshis/byte`
*/
getFeeRates(protocol?: Protocol): Promise<FeeRates>;
broadcastTx(txHex: string): Promise<TxHash>;

@@ -81,2 +89,3 @@ protected roundRobinGetBalance(address: Address): Promise<Balance[]>;

protected roundRobinBroadcastTx(txHex: string): Promise<string>;
protected roundRobinGetFeeRates(): Promise<FeeRates>;
}
{
"name": "@xchainjs/xchain-client",
"version": "0.15.3",
"version": "0.15.4",
"license": "MIT",

@@ -5,0 +5,0 @@ "main": "lib/index.js",

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc