@shapeshiftoss/swapper 17.6.0 → 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
|
|
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:
|
|
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
|
-
|
|
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
|
|
93
|
+
const quoteSellAmountCryptoBaseUnit = isQuoteSellAmountBelowMinimum
|
|
94
94
|
? sellAmountBeforeFeesCryptoBaseUnit
|
|
95
|
-
:
|
|
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:
|
|
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,
|
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.OsmosisSwapper = void 0;
|
|
4
4
|
const caip_1 = require("@shapeshiftoss/caip");
|
|
5
|
+
const chain_adapters_1 = require("@shapeshiftoss/chain-adapters");
|
|
5
6
|
const api_1 = require("../../api");
|
|
6
7
|
const bignumber_1 = require("../utils/bignumber");
|
|
7
8
|
const constants_1 = require("./utils/constants");
|
|
@@ -246,7 +247,7 @@ class OsmosisSwapper {
|
|
|
246
247
|
pubkey: cosmosAddress,
|
|
247
248
|
pageSize: 1,
|
|
248
249
|
});
|
|
249
|
-
await (0, helpers_1.performIbcTransfer)(transfer, osmosisAdapter, wallet, this.deps.cosmosUrl, buyAssetDenom, constants_1.OSMO_COSMO_CHANNEL,
|
|
250
|
+
await (0, helpers_1.performIbcTransfer)(transfer, osmosisAdapter, wallet, this.deps.cosmosUrl, buyAssetDenom, constants_1.OSMO_COSMO_CHANNEL, chain_adapters_1.osmosis.MIN_FEE, accountNumber, ibcAccountNumber, ibcSequence, gas, 'uosmo');
|
|
250
251
|
return { tradeId, previousCosmosTxid: (_a = cosmosTxHistory.transactions[0]) === null || _a === void 0 ? void 0 : _a.txid, cosmosAddress };
|
|
251
252
|
}
|
|
252
253
|
return { tradeId, previousCosmosTxid: cosmosIbcTradeId };
|
package/package.json
CHANGED