@shapeshiftoss/swapper 14.2.2 → 14.2.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.
@@ -56,13 +56,19 @@ const getLimit = async ({ sellAsset, buyAssetId, sellAmountCryptoPrecision, deps
56
56
  }
57
57
  })();
58
58
  const highestPossibleFeeCryptoPrecision8 = (0, max_1.default)([
59
- buyAssetTradeFeeCryptoPrecision8,
60
- refundFeeBuyAssetCryptoPrecision8,
59
+ // both fees are denominated in buy asset crypto precision 8
60
+ (0, bignumber_1.bnOrZero)(buyAssetTradeFeeCryptoPrecision8).toNumber(),
61
+ (0, bignumber_1.bnOrZero)(refundFeeBuyAssetCryptoPrecision8).toNumber(),
61
62
  ]);
62
- return (0, bignumber_1.bnOrZero)(expectedBuyAmountCryptoPrecision8)
63
+ const expectedBuyAmountAfterHighestFeeCryptoPrecision8 = (0, bignumber_1.bnOrZero)(expectedBuyAmountCryptoPrecision8)
63
64
  .times((0, bignumber_1.bn)(1).minus(slippageTolerance))
64
- .minus((0, bignumber_1.bnOrZero)(highestPossibleFeeCryptoPrecision8))
65
- .decimalPlaces(0)
66
- .toString();
65
+ .minus(highestPossibleFeeCryptoPrecision8 !== null && highestPossibleFeeCryptoPrecision8 !== void 0 ? highestPossibleFeeCryptoPrecision8 : 0)
66
+ .decimalPlaces(0);
67
+ // expectedBuyAmountAfterHighestFeeCryptoPrecision8 can be negative if the sell asset has a higher inbound_fee
68
+ // (a refund) than the buy asset's inbound_fee + buy amount.
69
+ // I.e. we've come this far - we don't have enough to refund, so the limit can slide all the way to 0.
70
+ return expectedBuyAmountAfterHighestFeeCryptoPrecision8.isPositive()
71
+ ? expectedBuyAmountAfterHighestFeeCryptoPrecision8.toString()
72
+ : '0';
67
73
  };
68
74
  exports.getLimit = getLimit;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@shapeshiftoss/swapper",
3
- "version": "14.2.2",
3
+ "version": "14.2.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",