@pioneer-platform/thorchain-client 0.18.1 → 0.18.5
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/.turbo/turbo-build.log +1 -1
- package/CHANGELOG.md +30 -0
- package/lib/index.js +86 -40
- package/package.json +4 -4
package/.turbo/turbo-build.log
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
|
|
2
2
|
|
|
3
|
-
> @pioneer-platform/thorchain-client@0.18.
|
|
3
|
+
> @pioneer-platform/thorchain-client@0.18.5 build /Users/highlander/WebstormProjects/keepkey-stack/projects/pioneer/modules/intergrations/thorchain
|
|
4
4
|
> tsc -p .
|
|
5
5
|
|
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,35 @@
|
|
|
1
1
|
# @pioneer-platform/thorchain-client
|
|
2
2
|
|
|
3
|
+
## 0.18.5
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- chore: fix(pioneer-server): use package exports for @pioneer-platform/nodes
|
|
8
|
+
|
|
9
|
+
## 0.18.4
|
|
10
|
+
|
|
11
|
+
### Patch Changes
|
|
12
|
+
|
|
13
|
+
- fix(pioneer-server): use package exports for @pioneer-platform/nodes
|
|
14
|
+
|
|
15
|
+
## 0.18.3
|
|
16
|
+
|
|
17
|
+
### Patch Changes
|
|
18
|
+
|
|
19
|
+
- chore: chore: - Services (discovery-service, watchtower)
|
|
20
|
+
- Updated dependencies
|
|
21
|
+
- @pioneer-platform/pioneer-caip@9.19.3
|
|
22
|
+
- @pioneer-platform/pioneer-coins@9.18.3
|
|
23
|
+
|
|
24
|
+
## 0.18.2
|
|
25
|
+
|
|
26
|
+
### Patch Changes
|
|
27
|
+
|
|
28
|
+
- fa09397: chore: - Services (discovery-service, watchtower)
|
|
29
|
+
- Updated dependencies [fa09397]
|
|
30
|
+
- @pioneer-platform/pioneer-caip@9.19.2
|
|
31
|
+
- @pioneer-platform/pioneer-coins@9.18.2
|
|
32
|
+
|
|
3
33
|
## 0.18.1
|
|
4
34
|
|
|
5
35
|
### Patch Changes
|
package/lib/index.js
CHANGED
|
@@ -75,26 +75,44 @@ var networkSupport = [
|
|
|
75
75
|
// Function to make a request to the node
|
|
76
76
|
function nodeRequest(path) {
|
|
77
77
|
return __awaiter(this, void 0, void 0, function () {
|
|
78
|
-
var response, data, error_1;
|
|
78
|
+
var fullUrl, response, errorText, errorMessage, errorJson, data, error_1;
|
|
79
79
|
return __generator(this, function (_a) {
|
|
80
80
|
switch (_a.label) {
|
|
81
81
|
case 0:
|
|
82
|
-
_a.trys.push([0,
|
|
83
|
-
|
|
82
|
+
_a.trys.push([0, 5, , 6]);
|
|
83
|
+
fullUrl = "https://thornode.ninerealms.com".concat(path);
|
|
84
|
+
log.info("".concat(TAG, " | nodeRequest | Fetching: ").concat(fullUrl));
|
|
85
|
+
return [4 /*yield*/, fetch(fullUrl)];
|
|
84
86
|
case 1:
|
|
85
87
|
response = _a.sent();
|
|
86
|
-
if (
|
|
87
|
-
|
|
88
|
-
}
|
|
89
|
-
return [4 /*yield*/, response.json()];
|
|
88
|
+
if (!!response.ok) return [3 /*break*/, 3];
|
|
89
|
+
return [4 /*yield*/, response.text()];
|
|
90
90
|
case 2:
|
|
91
|
+
errorText = _a.sent();
|
|
92
|
+
log.error("".concat(TAG, " | nodeRequest | THORNode error response:"), {
|
|
93
|
+
status: response.status,
|
|
94
|
+
statusText: response.statusText,
|
|
95
|
+
url: fullUrl,
|
|
96
|
+
body: errorText
|
|
97
|
+
});
|
|
98
|
+
errorMessage = errorText;
|
|
99
|
+
try {
|
|
100
|
+
errorJson = JSON.parse(errorText);
|
|
101
|
+
errorMessage = errorJson.error || errorJson.message || errorText;
|
|
102
|
+
}
|
|
103
|
+
catch (e) {
|
|
104
|
+
// Not JSON, use raw text
|
|
105
|
+
}
|
|
106
|
+
throw new Error("THORNode request failed (".concat(response.status, "): ").concat(errorMessage));
|
|
107
|
+
case 3: return [4 /*yield*/, response.json()];
|
|
108
|
+
case 4:
|
|
91
109
|
data = _a.sent();
|
|
92
110
|
return [2 /*return*/, data];
|
|
93
|
-
case
|
|
111
|
+
case 5:
|
|
94
112
|
error_1 = _a.sent();
|
|
95
113
|
log.error("".concat(TAG, " Error fetching from node:"), error_1);
|
|
96
114
|
throw error_1;
|
|
97
|
-
case
|
|
115
|
+
case 6: return [2 /*return*/];
|
|
98
116
|
}
|
|
99
117
|
});
|
|
100
118
|
});
|
|
@@ -215,6 +233,36 @@ module.exports = {
|
|
|
215
233
|
});
|
|
216
234
|
});
|
|
217
235
|
},
|
|
236
|
+
getMarkets: function () {
|
|
237
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
238
|
+
var tag, response, errorText, error_3;
|
|
239
|
+
return __generator(this, function (_a) {
|
|
240
|
+
switch (_a.label) {
|
|
241
|
+
case 0:
|
|
242
|
+
tag = TAG + " | getMarkets | ";
|
|
243
|
+
_a.label = 1;
|
|
244
|
+
case 1:
|
|
245
|
+
_a.trys.push([1, 5, , 6]);
|
|
246
|
+
log.info(tag, "Fetching THORChain markets (pools)");
|
|
247
|
+
return [4 /*yield*/, fetch('https://thornode.ninerealms.com/thorchain/pools')];
|
|
248
|
+
case 2:
|
|
249
|
+
response = _a.sent();
|
|
250
|
+
if (!!response.ok) return [3 /*break*/, 4];
|
|
251
|
+
return [4 /*yield*/, response.text()];
|
|
252
|
+
case 3:
|
|
253
|
+
errorText = _a.sent();
|
|
254
|
+
log.error(tag, "THORNode pools request failed: ".concat(response.status, " - ").concat(errorText));
|
|
255
|
+
throw new Error("THORNode pools request failed: ".concat(response.status));
|
|
256
|
+
case 4: return [2 /*return*/, response];
|
|
257
|
+
case 5:
|
|
258
|
+
error_3 = _a.sent();
|
|
259
|
+
log.error(tag, "Failed to fetch THORChain markets: ".concat(error_3.message));
|
|
260
|
+
throw error_3;
|
|
261
|
+
case 6: return [2 /*return*/];
|
|
262
|
+
}
|
|
263
|
+
});
|
|
264
|
+
});
|
|
265
|
+
},
|
|
218
266
|
};
|
|
219
267
|
function getPools() {
|
|
220
268
|
return __awaiter(this, void 0, void 0, function () {
|
|
@@ -245,7 +293,7 @@ function getPools() {
|
|
|
245
293
|
}
|
|
246
294
|
var get_quote = function (quote) {
|
|
247
295
|
return __awaiter(this, void 0, void 0, function () {
|
|
248
|
-
var tag, output, pools, poolIn, poolOut, sellAssetChain, sellAssetParts, sellAssetToken,
|
|
296
|
+
var tag, output, pools, poolIn, poolOut, sellAssetChain, sellAssetParts, sellAssetToken, THORCHAIN_DECIMALS, BASE_UNIT, amountNum, sellAmountInBaseUnits, URL_1, quoteFromNode, expectedOut, nodeMinOut, slippagePercentage, slippageTolerance, slippageAdjustedMin, finalAmountOutMin, amountOutEstimated, amountOutMinFormatted, memoInput, memo, isEvmChain, txType, e_2, errorMessage;
|
|
249
297
|
return __generator(this, function (_a) {
|
|
250
298
|
switch (_a.label) {
|
|
251
299
|
case 0:
|
|
@@ -294,35 +342,21 @@ var get_quote = function (quote) {
|
|
|
294
342
|
sellAssetChain = quote.sellAsset.split(".")[0];
|
|
295
343
|
sellAssetParts = quote.sellAsset.split(".");
|
|
296
344
|
sellAssetToken = sellAssetParts[1];
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
tokenSymbol = sellAssetToken.split('-')[0].toUpperCase();
|
|
300
|
-
knownTokenDecimals = {
|
|
301
|
-
'USDT': 6,
|
|
302
|
-
'USDC': 6,
|
|
303
|
-
'DAI': 18,
|
|
304
|
-
'WBTC': 8,
|
|
305
|
-
};
|
|
306
|
-
DECIMALS = knownTokenDecimals[tokenSymbol] || 6; // Default to 6 for unknown tokens
|
|
307
|
-
log.info(tag, "Using ".concat(DECIMALS, " decimals for token ").concat(tokenSymbol));
|
|
308
|
-
}
|
|
309
|
-
else {
|
|
310
|
-
// Native asset - use chain decimals
|
|
311
|
-
DECIMALS = Number(BaseDecimal[sellAssetChain]);
|
|
312
|
-
if (isNaN(DECIMALS))
|
|
313
|
-
throw new Error("Invalid DECIMALS value for asset: ".concat(sellAssetChain));
|
|
314
|
-
}
|
|
315
|
-
BASE_UNIT = Math.pow(10, DECIMALS);
|
|
316
|
-
sellAmountInBaseUnits = void 0;
|
|
345
|
+
THORCHAIN_DECIMALS = 8;
|
|
346
|
+
BASE_UNIT = Math.pow(10, THORCHAIN_DECIMALS);
|
|
317
347
|
amountNum = parseFloat(quote.sellAmount);
|
|
318
|
-
if (amountNum
|
|
319
|
-
|
|
320
|
-
sellAmountInBaseUnits = Math.round(amountNum);
|
|
321
|
-
}
|
|
322
|
-
else {
|
|
323
|
-
// Human-readable format (e.g., '30', '0.01') - convert to base units
|
|
324
|
-
sellAmountInBaseUnits = Math.round(amountNum * BASE_UNIT);
|
|
348
|
+
if (isNaN(amountNum) || amountNum <= 0) {
|
|
349
|
+
throw new Error("Invalid sellAmount: ".concat(quote.sellAmount));
|
|
325
350
|
}
|
|
351
|
+
sellAmountInBaseUnits = Math.round(amountNum * BASE_UNIT);
|
|
352
|
+
log.info(tag, 'Amount conversion for THORChain:', {
|
|
353
|
+
input: quote.sellAmount,
|
|
354
|
+
parsed: amountNum,
|
|
355
|
+
thorchainDecimals: THORCHAIN_DECIMALS,
|
|
356
|
+
baseUnits: sellAmountInBaseUnits,
|
|
357
|
+
calculation: "".concat(amountNum, " * 10^").concat(THORCHAIN_DECIMALS, " = ").concat(sellAmountInBaseUnits),
|
|
358
|
+
note: 'THORChain uses 8 decimals for ALL assets internally'
|
|
359
|
+
});
|
|
326
360
|
URL_1 = "/thorchain/quote/swap?from_asset=".concat(quote.sellAsset, "&to_asset=").concat(quote.buyAsset, "&amount=").concat(sellAmountInBaseUnits, "&destination=").concat(quote.recipientAddress);
|
|
327
361
|
log.info(tag, "URL: ", URL_1);
|
|
328
362
|
return [4 /*yield*/, nodeRequest(URL_1)];
|
|
@@ -332,11 +366,11 @@ var get_quote = function (quote) {
|
|
|
332
366
|
throw new Error(quoteFromNode.error);
|
|
333
367
|
log.info(tag, "quoteFromNode: ", quoteFromNode);
|
|
334
368
|
expectedOut = parseInt(quoteFromNode.expected_amount_out);
|
|
335
|
-
nodeMinOut = parseInt(quoteFromNode.amount_out_min);
|
|
369
|
+
nodeMinOut = quoteFromNode.amount_out_min ? parseInt(quoteFromNode.amount_out_min) : 0;
|
|
336
370
|
slippagePercentage = quote.slippage || 20;
|
|
337
371
|
slippageTolerance = slippagePercentage / 100;
|
|
338
372
|
slippageAdjustedMin = Math.floor(expectedOut * (1 - slippageTolerance));
|
|
339
|
-
finalAmountOutMin = Math.max(nodeMinOut, slippageAdjustedMin);
|
|
373
|
+
finalAmountOutMin = nodeMinOut > 0 ? Math.max(nodeMinOut, slippageAdjustedMin) : slippageAdjustedMin;
|
|
340
374
|
log.info(tag, "Slippage calculation:", {
|
|
341
375
|
expectedOut: expectedOut,
|
|
342
376
|
nodeMinOut: nodeMinOut,
|
|
@@ -345,8 +379,11 @@ var get_quote = function (quote) {
|
|
|
345
379
|
finalAmountOutMin: finalAmountOutMin,
|
|
346
380
|
usingNodeMin: finalAmountOutMin === nodeMinOut
|
|
347
381
|
});
|
|
348
|
-
amountOutEstimated = (expectedOut / BASE_UNIT).toFixed(
|
|
382
|
+
amountOutEstimated = (expectedOut / BASE_UNIT).toFixed(THORCHAIN_DECIMALS);
|
|
383
|
+
amountOutMinFormatted = (finalAmountOutMin / BASE_UNIT).toFixed(THORCHAIN_DECIMALS);
|
|
349
384
|
output.amountOut = amountOutEstimated;
|
|
385
|
+
output.amountOutMin = amountOutMinFormatted;
|
|
386
|
+
output.buyAmount = amountOutEstimated; // Alias for consistency with quote API
|
|
350
387
|
memoInput = {
|
|
351
388
|
type: 'SWAP',
|
|
352
389
|
asset: quote.buyAsset,
|
|
@@ -409,6 +446,15 @@ var get_quote = function (quote) {
|
|
|
409
446
|
case 4:
|
|
410
447
|
e_2 = _a.sent();
|
|
411
448
|
log.error(tag, "Error: ", e_2);
|
|
449
|
+
errorMessage = e_2.message || String(e_2);
|
|
450
|
+
// Check for common THORChain error patterns
|
|
451
|
+
if (errorMessage.includes('trading is halted')) {
|
|
452
|
+
throw new Error("Trading is temporarily halted for this swap pair. ".concat(quote.sellAsset, " \u2192 ").concat(quote.buyAsset, " is unavailable at the protocol level. Please try a different asset pair or check back later."));
|
|
453
|
+
}
|
|
454
|
+
else if (errorMessage.includes('Pool for')) {
|
|
455
|
+
throw new Error("".concat(errorMessage, ". This asset is not supported by THORChain."));
|
|
456
|
+
}
|
|
457
|
+
// Re-throw with original message
|
|
412
458
|
throw e_2;
|
|
413
459
|
case 5: return [2 /*return*/];
|
|
414
460
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@pioneer-platform/thorchain-client",
|
|
3
|
-
"version": "0.18.
|
|
3
|
+
"version": "0.18.5",
|
|
4
4
|
"main": "./lib/index.js",
|
|
5
5
|
"types": "./lib/index.d.ts",
|
|
6
6
|
"dependencies": {
|
|
@@ -8,9 +8,9 @@
|
|
|
8
8
|
"dotenv": "^17.2.3",
|
|
9
9
|
"rango-sdk": "^0.1.45",
|
|
10
10
|
"uuidv4": "^6.2.13",
|
|
11
|
-
"@pioneer-platform/
|
|
12
|
-
"@pioneer-platform/pioneer-coins": "9.18.
|
|
13
|
-
"@pioneer-platform/
|
|
11
|
+
"@pioneer-platform/pioneer-caip": "9.19.3",
|
|
12
|
+
"@pioneer-platform/pioneer-coins": "9.18.3",
|
|
13
|
+
"@pioneer-platform/loggerdog": "8.11.0"
|
|
14
14
|
},
|
|
15
15
|
"devDependencies": {
|
|
16
16
|
"@types/jest": "^25.2.3",
|