Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@xchainjs/xchain-evm

Package Overview
Dependencies
Maintainers
10
Versions
41
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@xchainjs/xchain-evm - npm Package Compare versions

Comparing version 0.3.4 to 0.3.5

12

lib/client.d.ts
import { Provider, TransactionResponse } from '@ethersproject/abstract-provider';
import { AssetInfo, Balance, BaseXChainClient, ExplorerProviders, FeeOption, Fees, Network, OnlineDataProviders, PreparedTx, Tx, TxHash, TxHistoryParams, TxParams, TxsPage, XChainClient, XChainClientParams } from '@xchainjs/xchain-client';
import { AssetInfo, Balance, BaseXChainClient, EvmOnlineDataProviders, ExplorerProviders, FeeOption, FeeRates, Fees, Network, PreparedTx, Tx, TxHash, TxHistoryParams, TxParams, TxsPage, XChainClient, XChainClientParams } from '@xchainjs/xchain-client';
import { Address, Asset, BaseAmount, Chain } from '@xchainjs/xchain-util';
import { BigNumber, Signer, ethers } from 'ethers';
import { ApproveParams, CallParams, EstimateApproveParams, EstimateCallParams, FeesWithGasPricesAndLimits, GasPrices, IsApprovedParams } from './types';
export declare enum Protocol {
THORCHAIN = 1
}
/**

@@ -22,3 +25,3 @@ * Interface for custom EVM client

explorerProviders: ExplorerProviders;
dataProviders: OnlineDataProviders[];
dataProviders: EvmOnlineDataProviders[];
};

@@ -242,7 +245,7 @@ /**

* Estimate gas price.
* @see https://etherscan.io/apis#gastracker
* @param {Protocol} protocol Protocol to interact with. If there's no protocol provided, fee rates are retrieved from chain data providers
*
* @returns {GasPrices} The gas prices (average, fast, fastest) in `Wei` (`BaseAmount`)
*/
estimateGasPrices(): Promise<GasPrices>;
estimateGasPrices(protocol?: Protocol): Promise<GasPrices>;
/**

@@ -281,2 +284,3 @@ * Estimate gas.

protected roundRobinGetTransactions(params: TxHistoryParams): Promise<TxsPage>;
protected roundRobinGetFeeRates(): Promise<FeeRates>;
/**

@@ -283,0 +287,0 @@ * Prepare transfer.

@@ -395,2 +395,6 @@ import { BaseXChainClient, Network, FeeOption, checkFeeBounds, standardFeeRates, FeeType } from '@xchainjs/xchain-client';

var Protocol;
(function (Protocol) {
Protocol[Protocol["THORCHAIN"] = 1] = "THORCHAIN";
})(Protocol || (Protocol = {}));
/**

@@ -793,41 +797,45 @@ * Custom EVM client

* Estimate gas price.
* @see https://etherscan.io/apis#gastracker
* @param {Protocol} protocol Protocol to interact with. If there's no protocol provided, fee rates are retrieved from chain data providers
*
* @returns {GasPrices} The gas prices (average, fast, fastest) in `Wei` (`BaseAmount`)
*/
estimateGasPrices() {
estimateGasPrices(protocol) {
return __awaiter(this, void 0, void 0, function* () {
try {
// Note: `rates` are in `gwei`
// @see https://gitlab.com/thorchain/thornode/-/blob/develop/x/thorchain/querier.go#L416-420
// To have all values in `BaseAmount`, they needs to be converted into `wei` (1 gwei = 1,000,000,000 wei = 1e9)
const ratesInGwei = standardFeeRates(yield this.getFeeRateFromThorchain());
return {
[FeeOption.Average]: baseAmount(ratesInGwei[FeeOption.Average] * Math.pow(10, 9), this.gasAssetDecimals),
[FeeOption.Fast]: baseAmount(ratesInGwei[FeeOption.Fast] * Math.pow(10, 9), this.gasAssetDecimals),
[FeeOption.Fastest]: baseAmount(ratesInGwei[FeeOption.Fastest] * Math.pow(10, 9), this.gasAssetDecimals),
};
if (!protocol) {
try {
const feeRates = yield this.roundRobinGetFeeRates();
return {
[FeeOption.Average]: baseAmount(feeRates.average, this.gasAssetDecimals),
[FeeOption.Fast]: baseAmount(feeRates.fast, this.gasAssetDecimals),
[FeeOption.Fastest]: baseAmount(feeRates.fastest, this.gasAssetDecimals),
};
}
catch (error) {
console.warn(`Can not round robin over GetFeeRates: ${error}`);
}
}
catch (error) {
console.warn(error);
// If chain data providers fail, THORCHAIN as fallback
if (!protocol || protocol === Protocol.THORCHAIN) {
try {
// Note: `rates` are in `gwei`
// @see https://gitlab.com/thorchain/thornode/-/blob/develop/x/thorchain/querier.go#L416-420
// To have all values in `BaseAmount`, they needs to be converted into `wei` (1 gwei = 1,000,000,000 wei = 1e9)
const ratesInGwei = standardFeeRates(yield this.getFeeRateFromThorchain());
return {
[FeeOption.Average]: baseAmount(ratesInGwei[FeeOption.Average] * Math.pow(10, 9), this.gasAssetDecimals),
[FeeOption.Fast]: baseAmount(ratesInGwei[FeeOption.Fast] * Math.pow(10, 9), this.gasAssetDecimals),
[FeeOption.Fastest]: baseAmount(ratesInGwei[FeeOption.Fastest] * Math.pow(10, 9), this.gasAssetDecimals),
};
}
catch (error) {
console.warn(error);
}
}
try {
const feeRateInWei = yield this.providers[this.network].getGasPrice();
const feeRateInGWei = feeRateInWei.div(Math.pow(10, 9));
const ratesInGwei = standardFeeRates(feeRateInGWei.toNumber());
return {
[FeeOption.Average]: baseAmount(ratesInGwei[FeeOption.Average] * Math.pow(10, 9), this.gasAssetDecimals),
[FeeOption.Fast]: baseAmount(ratesInGwei[FeeOption.Fast] * Math.pow(10, 9), this.gasAssetDecimals),
[FeeOption.Fastest]: baseAmount(ratesInGwei[FeeOption.Fastest] * Math.pow(10, 9), this.gasAssetDecimals),
};
}
catch (error) {
console.warn(error);
const defaultRatesInGwei = standardFeeRates(this.defaults[this.network].gasPrice.toNumber());
return {
[FeeOption.Average]: baseAmount(defaultRatesInGwei[FeeOption.Average] * Math.pow(10, 9), this.gasAssetDecimals),
[FeeOption.Fast]: baseAmount(defaultRatesInGwei[FeeOption.Fast] * Math.pow(10, 9), this.gasAssetDecimals),
[FeeOption.Fastest]: baseAmount(defaultRatesInGwei[FeeOption.Fastest] * Math.pow(10, 9), this.gasAssetDecimals),
};
}
// Default fee rates if everything else fails
const defaultRatesInGwei = standardFeeRates(this.defaults[this.network].gasPrice.toNumber());
return {
[FeeOption.Average]: baseAmount(defaultRatesInGwei[FeeOption.Average] * Math.pow(10, 9), this.gasAssetDecimals),
[FeeOption.Fast]: baseAmount(defaultRatesInGwei[FeeOption.Fast] * Math.pow(10, 9), this.gasAssetDecimals),
[FeeOption.Fastest]: baseAmount(defaultRatesInGwei[FeeOption.Fastest] * Math.pow(10, 9), this.gasAssetDecimals),
};
});

@@ -959,2 +967,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 available to getFeeRates');
});
}
/**

@@ -1471,3 +1494,3 @@ * Prepare transfer.

export { Client, MAX_APPROVAL, abi, call, estimateApprove, estimateCall, getApprovalAmount, getFee, getPrefix, getTokenAddress, isApproved, strip0x, validateAddress };
export { Client, MAX_APPROVAL, Protocol, abi, call, estimateApprove, estimateCall, getApprovalAmount, getFee, getPrefix, getTokenAddress, isApproved, strip0x, validateAddress };
//# sourceMappingURL=index.esm.js.map

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

exports.Protocol = void 0;
(function (Protocol) {
Protocol[Protocol["THORCHAIN"] = 1] = "THORCHAIN";
})(exports.Protocol || (exports.Protocol = {}));
/**

@@ -797,41 +801,45 @@ * Custom EVM client

* Estimate gas price.
* @see https://etherscan.io/apis#gastracker
* @param {Protocol} protocol Protocol to interact with. If there's no protocol provided, fee rates are retrieved from chain data providers
*
* @returns {GasPrices} The gas prices (average, fast, fastest) in `Wei` (`BaseAmount`)
*/
estimateGasPrices() {
estimateGasPrices(protocol) {
return __awaiter(this, void 0, void 0, function* () {
try {
// Note: `rates` are in `gwei`
// @see https://gitlab.com/thorchain/thornode/-/blob/develop/x/thorchain/querier.go#L416-420
// To have all values in `BaseAmount`, they needs to be converted into `wei` (1 gwei = 1,000,000,000 wei = 1e9)
const ratesInGwei = xchainClient.standardFeeRates(yield this.getFeeRateFromThorchain());
return {
[xchainClient.FeeOption.Average]: xchainUtil.baseAmount(ratesInGwei[xchainClient.FeeOption.Average] * Math.pow(10, 9), this.gasAssetDecimals),
[xchainClient.FeeOption.Fast]: xchainUtil.baseAmount(ratesInGwei[xchainClient.FeeOption.Fast] * Math.pow(10, 9), this.gasAssetDecimals),
[xchainClient.FeeOption.Fastest]: xchainUtil.baseAmount(ratesInGwei[xchainClient.FeeOption.Fastest] * Math.pow(10, 9), this.gasAssetDecimals),
};
if (!protocol) {
try {
const feeRates = yield this.roundRobinGetFeeRates();
return {
[xchainClient.FeeOption.Average]: xchainUtil.baseAmount(feeRates.average, this.gasAssetDecimals),
[xchainClient.FeeOption.Fast]: xchainUtil.baseAmount(feeRates.fast, this.gasAssetDecimals),
[xchainClient.FeeOption.Fastest]: xchainUtil.baseAmount(feeRates.fastest, this.gasAssetDecimals),
};
}
catch (error) {
console.warn(`Can not round robin over GetFeeRates: ${error}`);
}
}
catch (error) {
console.warn(error);
// If chain data providers fail, THORCHAIN as fallback
if (!protocol || protocol === exports.Protocol.THORCHAIN) {
try {
// Note: `rates` are in `gwei`
// @see https://gitlab.com/thorchain/thornode/-/blob/develop/x/thorchain/querier.go#L416-420
// To have all values in `BaseAmount`, they needs to be converted into `wei` (1 gwei = 1,000,000,000 wei = 1e9)
const ratesInGwei = xchainClient.standardFeeRates(yield this.getFeeRateFromThorchain());
return {
[xchainClient.FeeOption.Average]: xchainUtil.baseAmount(ratesInGwei[xchainClient.FeeOption.Average] * Math.pow(10, 9), this.gasAssetDecimals),
[xchainClient.FeeOption.Fast]: xchainUtil.baseAmount(ratesInGwei[xchainClient.FeeOption.Fast] * Math.pow(10, 9), this.gasAssetDecimals),
[xchainClient.FeeOption.Fastest]: xchainUtil.baseAmount(ratesInGwei[xchainClient.FeeOption.Fastest] * Math.pow(10, 9), this.gasAssetDecimals),
};
}
catch (error) {
console.warn(error);
}
}
try {
const feeRateInWei = yield this.providers[this.network].getGasPrice();
const feeRateInGWei = feeRateInWei.div(Math.pow(10, 9));
const ratesInGwei = xchainClient.standardFeeRates(feeRateInGWei.toNumber());
return {
[xchainClient.FeeOption.Average]: xchainUtil.baseAmount(ratesInGwei[xchainClient.FeeOption.Average] * Math.pow(10, 9), this.gasAssetDecimals),
[xchainClient.FeeOption.Fast]: xchainUtil.baseAmount(ratesInGwei[xchainClient.FeeOption.Fast] * Math.pow(10, 9), this.gasAssetDecimals),
[xchainClient.FeeOption.Fastest]: xchainUtil.baseAmount(ratesInGwei[xchainClient.FeeOption.Fastest] * Math.pow(10, 9), this.gasAssetDecimals),
};
}
catch (error) {
console.warn(error);
const defaultRatesInGwei = xchainClient.standardFeeRates(this.defaults[this.network].gasPrice.toNumber());
return {
[xchainClient.FeeOption.Average]: xchainUtil.baseAmount(defaultRatesInGwei[xchainClient.FeeOption.Average] * Math.pow(10, 9), this.gasAssetDecimals),
[xchainClient.FeeOption.Fast]: xchainUtil.baseAmount(defaultRatesInGwei[xchainClient.FeeOption.Fast] * Math.pow(10, 9), this.gasAssetDecimals),
[xchainClient.FeeOption.Fastest]: xchainUtil.baseAmount(defaultRatesInGwei[xchainClient.FeeOption.Fastest] * Math.pow(10, 9), this.gasAssetDecimals),
};
}
// Default fee rates if everything else fails
const defaultRatesInGwei = xchainClient.standardFeeRates(this.defaults[this.network].gasPrice.toNumber());
return {
[xchainClient.FeeOption.Average]: xchainUtil.baseAmount(defaultRatesInGwei[xchainClient.FeeOption.Average] * Math.pow(10, 9), this.gasAssetDecimals),
[xchainClient.FeeOption.Fast]: xchainUtil.baseAmount(defaultRatesInGwei[xchainClient.FeeOption.Fast] * Math.pow(10, 9), this.gasAssetDecimals),
[xchainClient.FeeOption.Fastest]: xchainUtil.baseAmount(defaultRatesInGwei[xchainClient.FeeOption.Fastest] * Math.pow(10, 9), this.gasAssetDecimals),
};
});

@@ -963,2 +971,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 available to getFeeRates');
});
}
/**

@@ -965,0 +988,0 @@ * Prepare transfer.

{
"name": "@xchainjs/xchain-evm",
"version": "0.3.4",
"version": "0.3.5",
"description": "Genereic EVM client for XChainJS",

@@ -37,6 +37,6 @@ "keywords": [

"devDependencies": {
"@xchainjs/xchain-client": "^0.15.1",
"@xchainjs/xchain-client": "^0.15.2",
"@xchainjs/xchain-crypto": "^0.3.0",
"@xchainjs/xchain-util": "^0.13.1",
"@xchainjs/xchain-evm-providers": "^0.1.1",
"@xchainjs/xchain-evm-providers": "^0.1.2",
"axios": "^1.3.6",

@@ -46,3 +46,3 @@ "ethers": "^5.7.2"

"peerDependencies": {
"@xchainjs/xchain-client": "^0.15.1",
"@xchainjs/xchain-client": "^0.15.2",
"@xchainjs/xchain-crypto": "^0.3.0",

@@ -53,2 +53,2 @@ "@xchainjs/xchain-util": "^0.13.1",

}
}
}

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