@shapeshiftoss/swapper 8.3.0 → 8.3.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.
- package/dist/swappers/thorchain/ThorchainSwapper.js +2 -0
- package/dist/swappers/thorchain/getThorTradeQuote/getTradeQuote.js +2 -3
- package/dist/swappers/thorchain/utils/estimateTradeFee/estimateTradeFee.js +16 -3
- package/dist/swappers/thorchain/utils/getPriceRatio/getPriceRatio.js +1 -1
- package/package.json +1 -1
|
@@ -52,6 +52,8 @@ class ThorchainSwapper {
|
|
|
52
52
|
}
|
|
53
53
|
filterBuyAssetsBySellAssetId(args) {
|
|
54
54
|
const { assetIds = [], sellAssetId } = args;
|
|
55
|
+
if (!this.supportedAssetIds.includes(sellAssetId))
|
|
56
|
+
return [];
|
|
55
57
|
return assetIds.filter((assetId) => this.supportedAssetIds.includes(assetId) && assetId !== sellAssetId);
|
|
56
58
|
}
|
|
57
59
|
filterAssetIdsBySellable() {
|
|
@@ -36,14 +36,13 @@ const getThorTradeQuote = async ({ deps, input }) => {
|
|
|
36
36
|
code: api_1.SwapErrorTypes.VALIDATION_FAILED,
|
|
37
37
|
details: { buyAssetId }
|
|
38
38
|
});
|
|
39
|
-
const feeAssetRatio = await (0, getPriceRatio_1.getPriceRatio)(deps, { sellAssetId, buyAssetId: feeAssetId });
|
|
40
39
|
const priceRatio = await (0, getPriceRatio_1.getPriceRatio)(deps, { sellAssetId, buyAssetId });
|
|
41
40
|
const rate = (0, bignumber_1.bnOrZero)(1).div(priceRatio).toString();
|
|
42
41
|
const buyAmount = (0, helpers_1.normalizeAmount)((0, bignumber_1.bnOrZero)(sellAmount).times(rate));
|
|
43
42
|
const tradeFee = await (0, estimateTradeFee_1.estimateTradeFee)(deps, buyAsset.assetId);
|
|
44
|
-
const sellAssetTradeFee = (0, bignumber_1.bnOrZero)(tradeFee).times((0, bignumber_1.bnOrZero)(
|
|
43
|
+
const sellAssetTradeFee = (0, bignumber_1.fromBaseUnit)((0, bignumber_1.bnOrZero)(tradeFee).times((0, bignumber_1.bnOrZero)(priceRatio)), buyAsset.precision);
|
|
45
44
|
// padding minimum by 1.5 the trade fee to avoid thorchain "not enough to cover fee" errors.
|
|
46
|
-
const minimum = (0, bignumber_1.
|
|
45
|
+
const minimum = (0, bignumber_1.bnOrZero)(sellAssetTradeFee).times(1.5).toString();
|
|
47
46
|
const commonQuoteFields = {
|
|
48
47
|
rate,
|
|
49
48
|
maximum: constants_2.MAX_THORCHAIN_TRADE,
|
|
@@ -4,6 +4,7 @@ exports.estimateTradeFee = void 0;
|
|
|
4
4
|
const caip_1 = require("@shapeshiftoss/caip");
|
|
5
5
|
const api_1 = require("../../../../api");
|
|
6
6
|
const bignumber_1 = require("../../../utils/bignumber");
|
|
7
|
+
const getPriceRatio_1 = require("../getPriceRatio/getPriceRatio");
|
|
7
8
|
const thorService_1 = require("../thorService");
|
|
8
9
|
const gweiGasPrecision = 9;
|
|
9
10
|
// https://docs.thorchain.org/how-it-works/fees#outbound-fee
|
|
@@ -31,15 +32,27 @@ const estimateTradeFee = async (deps, buyAssetId) => {
|
|
|
31
32
|
});
|
|
32
33
|
const gasRate = inboundInfo.gas_rate;
|
|
33
34
|
const { chainId, assetNamespace } = (0, caip_1.fromAssetId)(buyAssetId);
|
|
35
|
+
const feeAssetId = (0, caip_1.getFeeAssetIdFromAssetId)(buyAssetId);
|
|
36
|
+
if (!feeAssetId)
|
|
37
|
+
throw new api_1.SwapError('[estimateTradeFee] - no fee assetId', {
|
|
38
|
+
code: api_1.SwapErrorTypes.VALIDATION_FAILED,
|
|
39
|
+
details: { buyAssetId }
|
|
40
|
+
});
|
|
41
|
+
const feeAssetRatio = buyAssetId !== feeAssetId
|
|
42
|
+
? await (0, getPriceRatio_1.getPriceRatio)(deps, {
|
|
43
|
+
sellAssetId: buyAssetId,
|
|
44
|
+
buyAssetId: feeAssetId
|
|
45
|
+
})
|
|
46
|
+
: '1';
|
|
34
47
|
switch (chainId) {
|
|
35
48
|
case 'bip122:000000000019d6689c085ae165831e93':
|
|
36
|
-
return btcEstimate(gasRate);
|
|
49
|
+
return (0, bignumber_1.bnOrZero)(btcEstimate(gasRate)).times(feeAssetRatio).dp(0).toString();
|
|
37
50
|
case 'eip155:1':
|
|
38
51
|
switch (assetNamespace) {
|
|
39
52
|
case 'slip44':
|
|
40
|
-
return ethEstimate(gasRate);
|
|
53
|
+
return (0, bignumber_1.bnOrZero)(ethEstimate(gasRate)).times(feeAssetRatio).dp(0).toString();
|
|
41
54
|
case 'erc20':
|
|
42
|
-
return erc20Estimate(gasRate);
|
|
55
|
+
return (0, bignumber_1.bnOrZero)(erc20Estimate(gasRate)).times(feeAssetRatio).dp(0).toString();
|
|
43
56
|
default:
|
|
44
57
|
throw new api_1.SwapError('[estimateTradeFee] - unsupported asset namespace', {
|
|
45
58
|
code: api_1.SwapErrorTypes.VALIDATION_FAILED,
|
|
@@ -29,7 +29,7 @@ const getPriceRatio = async (deps, input) => {
|
|
|
29
29
|
catch (e) {
|
|
30
30
|
if (e instanceof api_1.SwapError)
|
|
31
31
|
throw e;
|
|
32
|
-
throw new api_1.SwapError('[
|
|
32
|
+
throw new api_1.SwapError('[getPriceRatio]: Thorchain getPriceRatio failed', {
|
|
33
33
|
code: api_1.SwapErrorTypes.PRICE_RATIO_FAILED,
|
|
34
34
|
cause: e
|
|
35
35
|
});
|
package/package.json
CHANGED