@shapeshiftoss/swapper 11.0.1 → 11.0.2

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.
@@ -10,8 +10,10 @@ const constants_2 = require("../utils/constants");
10
10
  const estimateTradeFee_1 = require("../utils/estimateTradeFee/estimateTradeFee");
11
11
  const getThorTxData_2 = require("../utils/ethereum/utils/getThorTxData");
12
12
  const getTradeRate_1 = require("../utils/getTradeRate/getTradeRate");
13
+ const getUsdRate_1 = require("../utils/getUsdRate/getUsdRate");
13
14
  const getBtcTxFees_1 = require("../utils/txFeeHelpers/btcTxFees/getBtcTxFees");
14
15
  const getEthTxFees_1 = require("../utils/txFeeHelpers/ethTxFees/getEthTxFees");
16
+ const MINIMUM_USD_TRADE_AMOUNT = (0, bignumber_1.bn)(1);
15
17
  const getThorTradeQuote = async ({ deps, input }) => {
16
18
  const { sellAsset, buyAsset, sellAmount, sellAssetAccountNumber, chainId, receiveAddress } = input;
17
19
  try {
@@ -24,7 +26,12 @@ const getThorTradeQuote = async ({ deps, input }) => {
24
26
  });
25
27
  const rate = await (0, getTradeRate_1.getTradeRate)(sellAsset, buyAsset.assetId, sellAmount, deps);
26
28
  const buyAmount = (0, bignumber_1.toBaseUnit)((0, bignumber_1.bnOrZero)((0, bignumber_1.fromBaseUnit)(sellAmount, sellAsset.precision)).times(rate), buyAsset.precision);
27
- const tradeFee = await (0, estimateTradeFee_1.estimateTradeFee)(deps, buyAsset);
29
+ const estimatedTradeFee = await (0, estimateTradeFee_1.estimateTradeFee)(deps, buyAsset);
30
+ const buyAssetUsdRate = await (0, getUsdRate_1.getUsdRate)({ deps, input: { assetId: buyAsset.assetId } });
31
+ const minTradeFeeAmount = MINIMUM_USD_TRADE_AMOUNT.div(buyAssetUsdRate);
32
+ const tradeFee = minTradeFeeAmount.gt(estimatedTradeFee)
33
+ ? minTradeFeeAmount.toString()
34
+ : estimatedTradeFee;
28
35
  const sellAssetTradeFee = (0, bignumber_1.bnOrZero)(tradeFee).dividedBy((0, bignumber_1.bnOrZero)(rate));
29
36
  // minimum is tradeFee padded by an amount to be sure they get something back
30
37
  // usually it will be slightly more than the amount because sellAssetTradeFee is already a high estimate
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@shapeshiftoss/swapper",
3
- "version": "11.0.1",
3
+ "version": "11.0.2",
4
4
  "description": "An interface and implementations to trade coins via various protocols",
5
5
  "repository": "https://github.com/shapeshift/lib",
6
6
  "license": "MIT",