@shapeshiftoss/swapper 7.7.0 → 7.7.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.getEthTxFees = void 0;
|
|
4
|
+
const chain_adapters_1 = require("@shapeshiftoss/chain-adapters");
|
|
4
5
|
const types_1 = require("@shapeshiftoss/types");
|
|
5
6
|
const api_1 = require("../../../../../api");
|
|
6
7
|
const bignumber_1 = require("../../../../utils/bignumber");
|
|
@@ -9,17 +10,36 @@ const estimateTradeFee_1 = require("../../estimateTradeFee/estimateTradeFee");
|
|
|
9
10
|
const getEthTxFees = async ({ deps, data, router, buyAsset, sellAmount, adapterManager, receiveAddress, sellAssetReference }) => {
|
|
10
11
|
try {
|
|
11
12
|
const adapter = adapterManager.get(types_1.KnownChainIds.EthereumMainnet);
|
|
12
|
-
if (!adapter)
|
|
13
|
+
if (!adapter) {
|
|
13
14
|
throw new api_1.SwapError(`[getThorTxInfo] - No chain adapter found for ${types_1.KnownChainIds.EthereumMainnet}.`, {
|
|
14
15
|
code: api_1.SwapErrorTypes.UNSUPPORTED_CHAIN,
|
|
15
16
|
details: { chainId: types_1.KnownChainIds.EthereumMainnet }
|
|
16
17
|
});
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
18
|
+
}
|
|
19
|
+
let feeDataOptions;
|
|
20
|
+
try {
|
|
21
|
+
feeDataOptions = await adapter.getFeeData({
|
|
22
|
+
to: router,
|
|
23
|
+
value: sellAmount,
|
|
24
|
+
chainSpecific: { from: receiveAddress, contractData: data }
|
|
25
|
+
});
|
|
26
|
+
}
|
|
27
|
+
catch (e) {
|
|
28
|
+
// Fallback to fixed fee amount in case of failure so that quote will not fail
|
|
29
|
+
// eslint-disable-next-line no-console
|
|
30
|
+
console.debug('[ThorSwapper:getEthTxFees] precise gas estimate failed, falling back on hard coded limit');
|
|
31
|
+
const gasFeeData = await adapter.getGasFeeData();
|
|
32
|
+
const gasLimit = '100000'; // good value to cover all thortrades out of eth/erc20
|
|
33
|
+
feeDataOptions = {
|
|
34
|
+
fast: {
|
|
35
|
+
txFee: (0, bignumber_1.bn)(gasLimit).times(gasFeeData[chain_adapters_1.FeeDataKey.Fast].gasPrice).toString(),
|
|
36
|
+
chainSpecific: {
|
|
37
|
+
gasPrice: gasFeeData[chain_adapters_1.FeeDataKey.Fast].gasPrice,
|
|
38
|
+
gasLimit
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
};
|
|
42
|
+
}
|
|
23
43
|
const feeData = feeDataOptions['fast'];
|
|
24
44
|
const tradeFee = await (0, estimateTradeFee_1.estimateTradeFee)(deps, buyAsset.assetId);
|
|
25
45
|
return {
|
package/package.json
CHANGED