@shapeshiftoss/swapper 17.6.1 → 17.6.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.
@@ -36,10 +36,9 @@ async function getCowSwapTradeQuote(deps, input) {
36
36
  const buyToken = buyAsset.assetId !== caip_1.ethAssetId ? buyAssetErc20Address : constants_1.COW_SWAP_ETH_MARKER_ADDRESS;
37
37
  const { minimum, maximum } = await (0, getCowSwapMinMax_1.getCowSwapMinMax)(deps, sellAsset, buyAsset);
38
38
  const minQuoteSellAmount = (0, bignumber_1.bnOrZero)(minimum).times((0, bignumber_1.bn)(10).exponentiatedBy(sellAsset.precision));
39
+ const isSellAmountBelowMinimum = (0, bignumber_1.bnOrZero)(sellAmountBeforeFeesCryptoBaseUnit).lt(minQuoteSellAmount);
39
40
  // making sure we do not have decimals for cowswap api (can happen at least from minQuoteSellAmount)
40
- const normalizedSellAmount = (0, helpers_1.normalizeIntegerAmount)((0, bignumber_1.bnOrZero)(sellAmountBeforeFeesCryptoBaseUnit).lt(minQuoteSellAmount)
41
- ? minQuoteSellAmount
42
- : sellAmountBeforeFeesCryptoBaseUnit);
41
+ const normalizedSellAmountCryptoBaseUnit = (0, helpers_1.normalizeIntegerAmount)(isSellAmountBelowMinimum ? minQuoteSellAmount : sellAmountBeforeFeesCryptoBaseUnit);
43
42
  const apiInput = {
44
43
  sellToken: sellAssetErc20Address,
45
44
  buyToken,
@@ -49,7 +48,7 @@ async function getCowSwapTradeQuote(deps, input) {
49
48
  partiallyFillable: false,
50
49
  from: constants_1.DEFAULT_ADDRESS,
51
50
  kind: constants_1.ORDER_KIND_SELL,
52
- sellAmountBeforeFee: normalizedSellAmount,
51
+ sellAmountBeforeFee: normalizedSellAmountCryptoBaseUnit,
53
52
  };
54
53
  /**
55
54
  * /v1/quote
@@ -88,11 +87,17 @@ async function getCowSwapTradeQuote(deps, input) {
88
87
  .multipliedBy((0, bignumber_1.bnOrZero)(sellAssetUsdRate))
89
88
  .toString();
90
89
  const feeData = feeDataOptions['fast'];
91
- // If original sellAmount is < minQuoteSellAmount, we don't want to replace it with normalizedSellAmount
90
+ const isQuoteSellAmountBelowMinimum = (0, bignumber_1.bnOrZero)(sellAmountCryptoBaseUnit).lt(minQuoteSellAmount);
91
+ // If isQuoteSellAmountBelowMinimum we don't want to replace it with normalizedSellAmount
92
92
  // The purpose of this was to get a quote from CowSwap even with small amounts
93
- const quoteSellAmount = (0, bignumber_1.bnOrZero)(sellAmountCryptoBaseUnit).lt(minQuoteSellAmount)
93
+ const quoteSellAmountCryptoBaseUnit = isQuoteSellAmountBelowMinimum
94
94
  ? sellAmountBeforeFeesCryptoBaseUnit
95
- : normalizedSellAmount;
95
+ : normalizedSellAmountCryptoBaseUnit;
96
+ // Similarly, if isQuoteSellAmountBelowMinimum we can't use the buy amount from the quote
97
+ // because we aren't actually selling the minimum amount (we are attempting to sell an amount less than it)
98
+ const quoteBuyAmountCryptoBaseUnit = isQuoteSellAmountBelowMinimum
99
+ ? '0'
100
+ : buyAmountCryptoBaseUnit;
96
101
  return {
97
102
  rate,
98
103
  minimumCryptoHuman: minimum,
@@ -109,8 +114,8 @@ async function getCowSwapTradeQuote(deps, input) {
109
114
  buyAssetTradeFeeUsd: '0',
110
115
  sellAssetTradeFeeUsd,
111
116
  },
112
- sellAmountBeforeFeesCryptoBaseUnit: quoteSellAmount,
113
- buyAmountCryptoBaseUnit,
117
+ sellAmountBeforeFeesCryptoBaseUnit: quoteSellAmountCryptoBaseUnit,
118
+ buyAmountCryptoBaseUnit: quoteBuyAmountCryptoBaseUnit,
114
119
  sources: constants_1.DEFAULT_SOURCE,
115
120
  allowanceContract: constants_1.COW_SWAP_VAULT_RELAYER_ADDRESS,
116
121
  buyAsset,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@shapeshiftoss/swapper",
3
- "version": "17.6.1",
3
+ "version": "17.6.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",