@shapeshiftoss/swapper 17.6.1 → 17.6.3

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
@@ -67,6 +66,7 @@ async function getCowSwapTradeQuote(deps, input) {
67
66
  */
68
67
  const quoteResponse = await cowService_1.cowService.post(`${deps.apiUrl}/v1/quote/`, apiInput);
69
68
  const { data: { quote: { buyAmount: buyAmountCryptoBaseUnit, sellAmount: sellAmountCryptoBaseUnit, feeAmount: feeAmountInSellTokenCryptoBaseUnit, }, }, } = quoteResponse;
69
+ const quoteSellAmountPlusFeesCryptoBaseUnit = (0, bignumber_1.bnOrZero)(sellAmountCryptoBaseUnit).plus(feeAmountInSellTokenCryptoBaseUnit);
70
70
  const buyCryptoAmount = (0, bignumber_1.bn)(buyAmountCryptoBaseUnit).div((0, bignumber_1.bn)(10).exponentiatedBy(buyAsset.precision));
71
71
  const sellCryptoAmount = (0, bignumber_1.bn)(sellAmountCryptoBaseUnit).div((0, bignumber_1.bn)(10).exponentiatedBy(sellAsset.precision));
72
72
  const rate = buyCryptoAmount.div(sellCryptoAmount).toString();
@@ -88,11 +88,17 @@ async function getCowSwapTradeQuote(deps, input) {
88
88
  .multipliedBy((0, bignumber_1.bnOrZero)(sellAssetUsdRate))
89
89
  .toString();
90
90
  const feeData = feeDataOptions['fast'];
91
- // If original sellAmount is < minQuoteSellAmount, we don't want to replace it with normalizedSellAmount
91
+ const isQuoteSellAmountBelowMinimum = (0, bignumber_1.bnOrZero)(quoteSellAmountPlusFeesCryptoBaseUnit).lt(minQuoteSellAmount);
92
+ // If isQuoteSellAmountBelowMinimum we don't want to replace it with normalizedSellAmount
92
93
  // 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)
94
+ const quoteSellAmountCryptoBaseUnit = isQuoteSellAmountBelowMinimum
94
95
  ? sellAmountBeforeFeesCryptoBaseUnit
95
- : normalizedSellAmount;
96
+ : normalizedSellAmountCryptoBaseUnit;
97
+ // Similarly, if isQuoteSellAmountBelowMinimum we can't use the buy amount from the quote
98
+ // because we aren't actually selling the minimum amount (we are attempting to sell an amount less than it)
99
+ const quoteBuyAmountCryptoBaseUnit = isQuoteSellAmountBelowMinimum
100
+ ? '0'
101
+ : buyAmountCryptoBaseUnit;
96
102
  return {
97
103
  rate,
98
104
  minimumCryptoHuman: minimum,
@@ -109,8 +115,8 @@ async function getCowSwapTradeQuote(deps, input) {
109
115
  buyAssetTradeFeeUsd: '0',
110
116
  sellAssetTradeFeeUsd,
111
117
  },
112
- sellAmountBeforeFeesCryptoBaseUnit: quoteSellAmount,
113
- buyAmountCryptoBaseUnit,
118
+ sellAmountBeforeFeesCryptoBaseUnit: quoteSellAmountCryptoBaseUnit,
119
+ buyAmountCryptoBaseUnit: quoteBuyAmountCryptoBaseUnit,
114
120
  sources: constants_1.DEFAULT_SOURCE,
115
121
  allowanceContract: constants_1.COW_SWAP_VAULT_RELAYER_ADDRESS,
116
122
  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.3",
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",