@shapeshiftoss/swapper 9.10.1 → 9.12.0
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.
- package/dist/api.d.ts +1 -0
- package/dist/api.js +1 -0
- package/dist/swappers/cow/cowGetTradeTxs/cowGetTradeTxs.js +1 -1
- package/dist/swappers/cow/getCowSwapTradeQuote/getCowSwapTradeQuote.js +14 -0
- package/dist/swappers/osmosis/OsmosisSwapper.js +9 -3
- package/dist/swappers/osmosis/utils/helpers.js +4 -4
- package/package.json +1 -1
package/dist/api.d.ts
CHANGED
|
@@ -173,6 +173,7 @@ export declare enum SwapErrorTypes {
|
|
|
173
173
|
RESPONSE_ERROR = "RESPONSE_ERROR",
|
|
174
174
|
SIGN_AND_BROADCAST_FAILED = "SIGN_AND_BROADCAST_FAILED",
|
|
175
175
|
TRADE_QUOTE_FAILED = "TRADE_QUOTE_FAILED",
|
|
176
|
+
TRADE_QUOTE_INPUT_LOWER_THAN_FEES = "TRADE_QUOTE_INPUT_LOWER_THAN_FEES",
|
|
176
177
|
UNSUPPORTED_PAIR = "UNSUPPORTED_PAIR",
|
|
177
178
|
USD_RATE_FAILED = "USD_RATE_FAILED",
|
|
178
179
|
UNSUPPORTED_CHAIN = "UNSUPPORTED_CHAIN",
|
package/dist/api.js
CHANGED
|
@@ -28,6 +28,7 @@ var SwapErrorTypes;
|
|
|
28
28
|
SwapErrorTypes["RESPONSE_ERROR"] = "RESPONSE_ERROR";
|
|
29
29
|
SwapErrorTypes["SIGN_AND_BROADCAST_FAILED"] = "SIGN_AND_BROADCAST_FAILED";
|
|
30
30
|
SwapErrorTypes["TRADE_QUOTE_FAILED"] = "TRADE_QUOTE_FAILED";
|
|
31
|
+
SwapErrorTypes["TRADE_QUOTE_INPUT_LOWER_THAN_FEES"] = "TRADE_QUOTE_INPUT_LOWER_THAN_FEES";
|
|
31
32
|
SwapErrorTypes["UNSUPPORTED_PAIR"] = "UNSUPPORTED_PAIR";
|
|
32
33
|
SwapErrorTypes["USD_RATE_FAILED"] = "USD_RATE_FAILED";
|
|
33
34
|
SwapErrorTypes["UNSUPPORTED_CHAIN"] = "UNSUPPORTED_CHAIN";
|
|
@@ -15,7 +15,7 @@ async function cowGetTradeTxs(deps, input) {
|
|
|
15
15
|
}
|
|
16
16
|
const getTradesResponse = await cowService_1.cowService.get(`${deps.apiUrl}/v1/trades/?orderUid=${input.tradeId}`);
|
|
17
17
|
return {
|
|
18
|
-
sellTxid:
|
|
18
|
+
sellTxid: input.tradeId,
|
|
19
19
|
buyTxid: getTradesResponse.data[0].txHash
|
|
20
20
|
};
|
|
21
21
|
}
|
|
@@ -1,8 +1,12 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
2
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
6
|
exports.getCowSwapTradeQuote = void 0;
|
|
4
7
|
const caip_1 = require("@shapeshiftoss/caip");
|
|
5
8
|
const types_1 = require("@shapeshiftoss/types");
|
|
9
|
+
const axios_1 = __importDefault(require("axios"));
|
|
6
10
|
const api_1 = require("../../../api");
|
|
7
11
|
const bignumber_1 = require("../../utils/bignumber");
|
|
8
12
|
const helpers_1 = require("../../utils/helpers/helpers");
|
|
@@ -11,6 +15,7 @@ const constants_1 = require("../utils/constants");
|
|
|
11
15
|
const cowService_1 = require("../utils/cowService");
|
|
12
16
|
const helpers_2 = require("../utils/helpers/helpers");
|
|
13
17
|
async function getCowSwapTradeQuote(deps, input) {
|
|
18
|
+
var _a, _b;
|
|
14
19
|
try {
|
|
15
20
|
const { sellAsset, buyAsset, sellAmount, sellAssetAccountNumber, wallet } = input;
|
|
16
21
|
const { adapter, web3 } = deps;
|
|
@@ -113,6 +118,15 @@ async function getCowSwapTradeQuote(deps, input) {
|
|
|
113
118
|
};
|
|
114
119
|
}
|
|
115
120
|
catch (e) {
|
|
121
|
+
if (axios_1.default.isAxiosError(e) &&
|
|
122
|
+
((_a = e.response) === null || _a === void 0 ? void 0 : _a.status) === 400 &&
|
|
123
|
+
((_b = e.response) === null || _b === void 0 ? void 0 : _b.data.errorType) ===
|
|
124
|
+
'SellAmountDoesNotCoverFee') {
|
|
125
|
+
throw new api_1.SwapError('[getCowSwapTradeQuote]', {
|
|
126
|
+
cause: e,
|
|
127
|
+
code: api_1.SwapErrorTypes.TRADE_QUOTE_INPUT_LOWER_THAN_FEES
|
|
128
|
+
});
|
|
129
|
+
}
|
|
116
130
|
if (e instanceof api_1.SwapError)
|
|
117
131
|
throw e;
|
|
118
132
|
throw new api_1.SwapError('[getCowSwapTradeQuote]', {
|
|
@@ -76,7 +76,7 @@ class OsmosisSwapper {
|
|
|
76
76
|
code: api_1.SwapErrorTypes.BUILD_TRADE_FAILED
|
|
77
77
|
});
|
|
78
78
|
const feeData = await osmosisAdapter.getFeeData({});
|
|
79
|
-
const fee = feeData.
|
|
79
|
+
const fee = feeData.fast.txFee;
|
|
80
80
|
return {
|
|
81
81
|
buyAmount,
|
|
82
82
|
buyAsset,
|
|
@@ -104,7 +104,7 @@ class OsmosisSwapper {
|
|
|
104
104
|
code: api_1.SwapErrorTypes.TRADE_QUOTE_FAILED
|
|
105
105
|
});
|
|
106
106
|
const feeData = await osmosisAdapter.getFeeData({});
|
|
107
|
-
const fee = feeData.
|
|
107
|
+
const fee = feeData.fast.txFee;
|
|
108
108
|
return {
|
|
109
109
|
buyAsset,
|
|
110
110
|
feeData: { fee, tradeFee },
|
|
@@ -134,7 +134,7 @@ class OsmosisSwapper {
|
|
|
134
134
|
}
|
|
135
135
|
let sellAddress;
|
|
136
136
|
const feeData = await osmosisAdapter.getFeeData({});
|
|
137
|
-
const gas = feeData.
|
|
137
|
+
const gas = feeData.fast.chainSpecific.gasLimit;
|
|
138
138
|
if (!isFromOsmo) {
|
|
139
139
|
const sellBip44Params = cosmosAdapter.buildBIP44Params({
|
|
140
140
|
accountNumber: Number(sellAssetAccountNumber)
|
|
@@ -160,6 +160,9 @@ class OsmosisSwapper {
|
|
|
160
160
|
code: api_1.SwapErrorTypes.EXECUTE_TRADE_FAILED
|
|
161
161
|
});
|
|
162
162
|
ibcSellAmount = await (0, helpers_1.pollForAtomChannelBalance)(receiveAddress, this.deps.osmoUrl);
|
|
163
|
+
// delay to ensure all nodes we interact with are up to date at this point
|
|
164
|
+
// seeing intermittent bugs that suggest the balances and sequence numbers were sometimes off
|
|
165
|
+
await new Promise((resolve) => setTimeout(resolve, 3000));
|
|
163
166
|
}
|
|
164
167
|
else {
|
|
165
168
|
const sellBip44Params = osmosisAdapter.buildBIP44Params({
|
|
@@ -199,6 +202,9 @@ class OsmosisSwapper {
|
|
|
199
202
|
const ibcResponseAccount = await osmosisAdapter.getAccount(sellAddress);
|
|
200
203
|
const ibcAccountNumber = ibcResponseAccount.chainSpecific.accountNumber || '0';
|
|
201
204
|
const ibcSequence = ibcResponseAccount.chainSpecific.sequence || '0';
|
|
205
|
+
// delay to ensure all nodes we interact with are up to date at this point
|
|
206
|
+
// seeing intermittent bugs that suggest the balances and sequence numbers were sometimes off
|
|
207
|
+
await new Promise((resolve) => setTimeout(resolve, 3000));
|
|
202
208
|
await (0, helpers_1.performIbcTransfer)(transfer, osmosisAdapter, wallet, this.deps.cosmosUrl, buyAssetDenom, constants_1.OSMO_COSMO_CHANNEL, trade.feeData.fee, ibcAccountNumber, ibcSequence, gas);
|
|
203
209
|
}
|
|
204
210
|
return { tradeId: tradeId || 'error' };
|
|
@@ -27,14 +27,14 @@ const txStatus = async (txid, baseUrl) => {
|
|
|
27
27
|
return 'failed';
|
|
28
28
|
}
|
|
29
29
|
catch (e) {
|
|
30
|
-
console.
|
|
30
|
+
console.warn('Retrying to retrieve status');
|
|
31
31
|
}
|
|
32
32
|
return 'not found';
|
|
33
33
|
};
|
|
34
34
|
// TODO: leverage chain-adapters websockets
|
|
35
35
|
const pollForComplete = async (txid, baseUrl) => {
|
|
36
36
|
return new Promise((resolve, reject) => {
|
|
37
|
-
const timeout =
|
|
37
|
+
const timeout = 300000; // 5 mins
|
|
38
38
|
const startTime = Date.now();
|
|
39
39
|
const interval = 5000; // 5 seconds
|
|
40
40
|
const poll = async function () {
|
|
@@ -72,14 +72,14 @@ const getAtomChannelBalance = async (address, osmoUrl) => {
|
|
|
72
72
|
toAtomChannelBalance = Number(amount);
|
|
73
73
|
}
|
|
74
74
|
catch (e) {
|
|
75
|
-
console.
|
|
75
|
+
console.warn('Retrying to get ibc balance');
|
|
76
76
|
}
|
|
77
77
|
return toAtomChannelBalance;
|
|
78
78
|
};
|
|
79
79
|
exports.getAtomChannelBalance = getAtomChannelBalance;
|
|
80
80
|
const pollForAtomChannelBalance = async (address, osmoUrl) => {
|
|
81
81
|
return new Promise((resolve, reject) => {
|
|
82
|
-
const timeout =
|
|
82
|
+
const timeout = 300000; // 5 mins
|
|
83
83
|
const startTime = Date.now();
|
|
84
84
|
const interval = 5000; // 5 seconds
|
|
85
85
|
const poll = async function () {
|
package/package.json
CHANGED