@pioneer-platform/thorchain-client 0.0.35 → 0.1.1

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/CHANGELOG.md ADDED
@@ -0,0 +1,24 @@
1
+ # @pioneer-platform/thorchain-client
2
+
3
+ ## 0.1.1
4
+
5
+ ### Patch Changes
6
+
7
+ - Automated patch version bump for all packages
8
+ - Updated dependencies
9
+ - @pioneer-platform/loggerdog@8.4.1
10
+ - @pioneer-platform/pioneer-coins@9.4.1
11
+ - @pioneer-platform/pioneer-caip@9.3.1
12
+
13
+ ## 0.1.0
14
+
15
+ ### Minor Changes
16
+
17
+ - Release: minor version bump for all packages
18
+
19
+ ### Patch Changes
20
+
21
+ - Updated dependencies
22
+ - @pioneer-platform/loggerdog@8.4.0
23
+ - @pioneer-platform/pioneer-coins@9.4.0
24
+ - @pioneer-platform/pioneer-caip@9.3.0
package/package.json CHANGED
@@ -1,12 +1,12 @@
1
1
  {
2
2
  "name": "@pioneer-platform/thorchain-client",
3
- "version": "0.0.35",
3
+ "version": "0.1.1",
4
4
  "main": "./lib/index.js",
5
5
  "types": "./lib/index.d.ts",
6
6
  "dependencies": {
7
- "@pioneer-platform/loggerdog": "^8.3.1",
8
- "@pioneer-platform/pioneer-caip": "^9.2.38",
9
- "@pioneer-platform/pioneer-coins": "^9.2.24",
7
+ "@pioneer-platform/loggerdog": "^8.4.1",
8
+ "@pioneer-platform/pioneer-caip": "^9.3.1",
9
+ "@pioneer-platform/pioneer-coins": "^9.4.1",
10
10
  "axios": "^1.6.0",
11
11
  "dotenv": "^8.2.0",
12
12
  "rango-sdk": "^0.1.45",
package/lib/index.d.ts DELETED
@@ -1,11 +0,0 @@
1
- declare const TAG = " | maya | ";
2
- declare const BaseDecimal: Record<string, number>;
3
- declare const uuid: any;
4
- declare const log: any;
5
- declare let caipToNetworkId: any, shortListSymbolToCaip: any, ChainToNetworkId: any;
6
- declare const createMemo: any, parseMemo: any;
7
- declare let networkSupport: any[];
8
- declare function nodeRequest(path: string): Promise<any>;
9
- declare let assets: string[];
10
- declare function getPools(): Promise<any>;
11
- declare const get_quote: (quote: any) => Promise<any>;
package/lib/index.js DELETED
@@ -1,344 +0,0 @@
1
- "use strict";
2
- /*
3
- Maya Swap Integration
4
- - Highlander
5
- */
6
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
7
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
8
- return new (P || (P = Promise))(function (resolve, reject) {
9
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
10
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
11
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
12
- step((generator = generator.apply(thisArg, _arguments || [])).next());
13
- });
14
- };
15
- var __generator = (this && this.__generator) || function (thisArg, body) {
16
- var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g = Object.create((typeof Iterator === "function" ? Iterator : Object).prototype);
17
- return g.next = verb(0), g["throw"] = verb(1), g["return"] = verb(2), typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
18
- function verb(n) { return function (v) { return step([n, v]); }; }
19
- function step(op) {
20
- if (f) throw new TypeError("Generator is already executing.");
21
- while (g && (g = 0, op[0] && (_ = 0)), _) try {
22
- if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
23
- if (y = 0, t) op = [op[0] & 2, t.value];
24
- switch (op[0]) {
25
- case 0: case 1: t = op; break;
26
- case 4: _.label++; return { value: op[1], done: false };
27
- case 5: _.label++; y = op[1]; op = [0]; continue;
28
- case 7: op = _.ops.pop(); _.trys.pop(); continue;
29
- default:
30
- if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
31
- if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
32
- if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
33
- if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
34
- if (t[2]) _.ops.pop();
35
- _.trys.pop(); continue;
36
- }
37
- op = body.call(thisArg, _);
38
- } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
39
- if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
40
- }
41
- };
42
- var TAG = " | maya | ";
43
- // Replace BaseDecimal import with local definition
44
- // Define BaseDecimal as a simple record of string chains to number values
45
- var BaseDecimal = {
46
- "BTC": 8,
47
- "ETH": 18,
48
- "DOGE": 8,
49
- "BCH": 8,
50
- "LTC": 8,
51
- "THOR": 8
52
- };
53
- var uuid = require('uuidv4').uuid;
54
- var log = require('@pioneer-platform/loggerdog')();
55
- var _a = require("@pioneer-platform/pioneer-caip"), caipToNetworkId = _a.caipToNetworkId, shortListSymbolToCaip = _a.shortListSymbolToCaip, ChainToNetworkId = _a.ChainToNetworkId;
56
- var _b = require('@pioneer-platform/pioneer-coins'), createMemo = _b.createMemo, parseMemo = _b.parseMemo;
57
- var networkSupport = [
58
- ChainToNetworkId["BTC"],
59
- ChainToNetworkId["ETH"],
60
- ChainToNetworkId["DOGE"],
61
- ChainToNetworkId["BCH"],
62
- ChainToNetworkId["LTC"],
63
- ChainToNetworkId["THOR"],
64
- ];
65
- // Function to make a request to the node
66
- function nodeRequest(path) {
67
- return __awaiter(this, void 0, void 0, function () {
68
- var response, data, error_1;
69
- return __generator(this, function (_a) {
70
- switch (_a.label) {
71
- case 0:
72
- _a.trys.push([0, 3, , 4]);
73
- return [4 /*yield*/, fetch("https://thornode.ninerealms.com".concat(path))];
74
- case 1:
75
- response = _a.sent();
76
- if (!response.ok) {
77
- throw new Error("Node request failed with status: ".concat(response.status, ", message: ").concat(response.statusText));
78
- }
79
- return [4 /*yield*/, response.json()];
80
- case 2:
81
- data = _a.sent();
82
- return [2 /*return*/, data];
83
- case 3:
84
- error_1 = _a.sent();
85
- log.error("".concat(TAG, " Error fetching from node:"), error_1);
86
- throw error_1;
87
- case 4: return [2 /*return*/];
88
- }
89
- });
90
- });
91
- }
92
- var assets = [
93
- 'bip122:000000000019d6689c085ae165831e93/slip44:0', // BTC
94
- 'eip155:1/slip44:60', // ETH
95
- 'cosmos:thorchain-mainnet-v1/slip44:931', // RUNE
96
- 'bip122:00000000001a91e3dace36e2be3bf030/slip44:3', // Doge
97
- 'bip122:000000000000000000651ef99cb9fcbe/slip44:145', // BCH
98
- ];
99
- module.exports = {
100
- init: function (settings) {
101
- return true;
102
- },
103
- networkSupport: function () {
104
- return networkSupport;
105
- },
106
- assetSupport: function () {
107
- return assets;
108
- },
109
- getQuote: function (quote) {
110
- return __awaiter(this, void 0, void 0, function () {
111
- return __generator(this, function (_a) {
112
- switch (_a.label) {
113
- case 0: return [4 /*yield*/, get_quote(quote)];
114
- case 1: return [2 /*return*/, _a.sent()];
115
- }
116
- });
117
- });
118
- },
119
- };
120
- function getPools() {
121
- return __awaiter(this, void 0, void 0, function () {
122
- var tag, pools, e_1;
123
- return __generator(this, function (_a) {
124
- switch (_a.label) {
125
- case 0:
126
- tag = TAG + " | getPools | ";
127
- _a.label = 1;
128
- case 1:
129
- _a.trys.push([1, 3, , 4]);
130
- return [4 /*yield*/, nodeRequest('/thorchain/pools')];
131
- case 2:
132
- pools = _a.sent();
133
- if (!pools || pools.length === 0) {
134
- throw new Error("No pools fetched from network!");
135
- }
136
- log.info(tag, "Pools fetched: ", pools.map(function (p) { return p.asset; }));
137
- return [2 /*return*/, pools];
138
- case 3:
139
- e_1 = _a.sent();
140
- log.error(tag, "Error fetching pools: ", e_1);
141
- throw new Error("Unable to fetch pools");
142
- case 4: return [2 /*return*/];
143
- }
144
- });
145
- });
146
- }
147
- var get_quote = function (quote) {
148
- return __awaiter(this, void 0, void 0, function () {
149
- var tag, output, pools, poolIn, poolOut, sellAssetChain, DECIMALS, BASE_UNIT, sellAmountInBaseUnits, URL_1, quoteFromNode, amountOutMin, amountOutEstimated, memoInput, memo, txType, e_2;
150
- return __generator(this, function (_a) {
151
- switch (_a.label) {
152
- case 0:
153
- tag = TAG + " | get_quote | ";
154
- _a.label = 1;
155
- case 1:
156
- _a.trys.push([1, 4, , 5]);
157
- output = {};
158
- if (!quote.sellAsset)
159
- throw new Error("missing sellAsset");
160
- if (!quote.buyAsset)
161
- throw new Error("missing buyAsset");
162
- if (!quote.sellAmount)
163
- throw new Error("missing sellAmount");
164
- if (!quote.senderAddress)
165
- throw new Error("missing senderAddress");
166
- if (!quote.recipientAddress)
167
- throw new Error("missing recipientAddress");
168
- if (!quote.slippage)
169
- throw new Error("missing slippage");
170
- return [4 /*yield*/, getPools()];
171
- case 2:
172
- pools = _a.sent();
173
- poolIn = pools.find(function (p) { return p.asset === quote.sellAsset; });
174
- poolOut = pools.find(function (p) { return p.asset === quote.buyAsset; });
175
- // If the sellAsset is RUNE, use the pool for the buyAsset
176
- if (quote.sellAsset === 'THOR.RUNE') {
177
- poolIn = null; // RUNE does not need an "in" pool, only "out"
178
- poolOut = pools.find(function (p) { return p.asset === quote.buyAsset; });
179
- }
180
- // If the buyAsset is RUNE, use the pool for the sellAsset
181
- if (quote.buyAsset === 'THOR.RUNE') {
182
- poolOut = null; // RUNE does not need an "out" pool, only "in"
183
- poolIn = pools.find(function (p) { return p.asset === quote.sellAsset; });
184
- }
185
- // Handle case where pools are not found
186
- if (!poolIn && quote.sellAsset !== 'THOR.RUNE') {
187
- log.error(tag, "Pool for sellAsset (".concat(quote.sellAsset, ") not found."));
188
- throw new Error("Pool for sellAsset (".concat(quote.sellAsset, ") not found."));
189
- }
190
- if (!poolOut && quote.buyAsset !== 'THOR.RUNE') {
191
- log.error(tag, "Pool for buyAsset (".concat(quote.buyAsset, ") not found."));
192
- throw new Error("Pool for buyAsset (".concat(quote.buyAsset, ") not found."));
193
- }
194
- log.info(tag, "poolIn: ", poolIn, "poolOut: ", poolOut);
195
- sellAssetChain = quote.sellAsset.split(".")[0];
196
- DECIMALS = Number(BaseDecimal[sellAssetChain]);
197
- if (isNaN(DECIMALS))
198
- throw new Error("Invalid DECIMALS value for asset: ".concat(sellAssetChain));
199
- BASE_UNIT = Math.pow(10, DECIMALS);
200
- sellAmountInBaseUnits = Math.round(parseFloat(quote.sellAmount) * BASE_UNIT);
201
- URL_1 = "/thorchain/quote/swap?from_asset=".concat(quote.sellAsset, "&to_asset=").concat(quote.buyAsset, "&amount=").concat(sellAmountInBaseUnits, "&destination=").concat(quote.recipientAddress);
202
- log.info(tag, "URL: ", URL_1);
203
- return [4 /*yield*/, nodeRequest(URL_1)];
204
- case 3:
205
- quoteFromNode = _a.sent();
206
- if (quoteFromNode.error)
207
- throw new Error(quoteFromNode.error);
208
- log.info(tag, "quoteFromNode: ", quoteFromNode);
209
- amountOutMin = quoteFromNode.amount_out_min;
210
- amountOutEstimated = (parseInt(quoteFromNode.expected_amount_out) / BASE_UNIT).toFixed(DECIMALS);
211
- output.amountOut = amountOutEstimated;
212
- memoInput = {
213
- type: 'SWAP',
214
- asset: quote.buyAsset,
215
- destAddr: quote.recipientAddress,
216
- lim: amountOutMin,
217
- };
218
- memo = createMemo(memoInput);
219
- log.info(tag, "memo: ", memo);
220
- txType = sellAssetChain === "THOR" ? 'deposit' : 'transfer';
221
- output.id = uuid();
222
- output.txs = [
223
- {
224
- type: txType,
225
- chain: ChainToNetworkId[sellAssetChain],
226
- txParams: {
227
- senderAddress: quote.senderAddress,
228
- recipientAddress: quoteFromNode.inbound_address,
229
- amount: quote.sellAmount,
230
- token: quote.sellAsset.split(".")[1],
231
- memo: quoteFromNode.memo || memo,
232
- },
233
- },
234
- ];
235
- output.meta = {
236
- quoteMode: "TC_SUPPORTED_TO_TC_SUPPORTED",
237
- };
238
- output.steps = 1;
239
- output.complete = true;
240
- output.source = 'thorchain';
241
- output.raw = quoteFromNode;
242
- return [2 /*return*/, output];
243
- case 4:
244
- e_2 = _a.sent();
245
- log.error(tag, "Error: ", e_2);
246
- throw e_2;
247
- case 5: return [2 /*return*/];
248
- }
249
- });
250
- });
251
- };
252
- // const get_quote = async function (quote: any) {
253
- // const tag = TAG + " | get_quote | ";
254
- // try {
255
- // let output: any = {};
256
- // if (!quote.sellAsset) throw new Error("missing sellAsset");
257
- // if (!quote.buyAsset) throw new Error("missing buyAsset");
258
- // if (!quote.sellAmount) throw new Error("missing sellAmount");
259
- // if (!quote.senderAddress) throw new Error("missing senderAddress");
260
- // if (!quote.recipientAddress) throw new Error("missing recipientAddress");
261
- // if (!quote.slippage) throw new Error("missing slippage");
262
- //
263
- // // Get pools from network
264
- // const pools = await getPools();
265
- //
266
- // // Find the pool for the sellAsset
267
- // const poolIn = pools.find((p: any) => p.asset === quote.sellAsset);
268
- // if (!poolIn) {
269
- // log.error(tag, `Pool for sellAsset (${quote.sellAsset}) not found.`);
270
- // throw new Error(`Pool for sellAsset (${quote.sellAsset}) not found.`);
271
- // }
272
- //
273
- // let poolOut: any = null;
274
- //
275
- // // Skip poolOut lookup if buyAsset is RUNE/THOR
276
- // if (quote.buyAsset === 'THOR.RUNE' || quote.buyAsset === 'RUNE.RUNE') {
277
- // log.info(tag, `BuyAsset (${quote.buyAsset}) is RUNE/THOR. Skipping poolOut lookup.`);
278
- // } else {
279
- // poolOut = pools.find((p: any) => p.asset === quote.buyAsset);
280
- // if (!poolOut) {
281
- // log.error(tag, `Pool for buyAsset (${quote.buyAsset}) not found.`);
282
- // throw new Error(`Pool for buyAsset (${quote.buyAsset}) not found.`);
283
- // }
284
- // }
285
- //
286
- // log.info(tag, "poolIn: ", poolIn, "poolOut: ", poolOut || 'N/A (RUNE/THOR as buyAsset)');
287
- //
288
- // const sellAssetChain = quote.sellAsset.split(".")[0];
289
- // const DECIMALS = Number(BaseDecimal[sellAssetChain]);
290
- // if (isNaN(DECIMALS)) throw new Error(`Invalid DECIMALS value for asset: ${sellAssetChain}`);
291
- // const BASE_UNIT = Math.pow(10, DECIMALS);
292
- // const sellAmountInBaseUnits = parseFloat(quote.sellAmount) * BASE_UNIT;
293
- //
294
- // // Create URL for the API
295
- // const URL = `/thorchain/quote/swap?from_asset=${quote.sellAsset}&to_asset=${quote.buyAsset}&amount=${sellAmountInBaseUnits}&destination=${quote.recipientAddress}`;
296
- // log.info(tag, "URL: ", URL);
297
- //
298
- // const quoteFromNode = await nodeRequest(URL);
299
- // if (quoteFromNode.error) throw new Error(quoteFromNode.error);
300
- //
301
- // const amountOutMin = quoteFromNode.amount_out_min;
302
- // const amountOutEstimated = (parseInt(quoteFromNode.expected_amount_out) / BASE_UNIT).toFixed(DECIMALS);
303
- //
304
- // output.amountOut = amountOutEstimated;
305
- //
306
- // const memoInput = {
307
- // type: 'SWAP',
308
- // asset: quote.buyAsset,
309
- // destAddr: quote.recipientAddress,
310
- // lim: amountOutMin,
311
- // };
312
- // const memo = createMemo(memoInput);
313
- // log.info(tag, "memo: ", memo);
314
- //
315
- // const txType = sellAssetChain === "MAYA" ? 'deposit' : 'transfer';
316
- //
317
- // output.txs = [
318
- // {
319
- // type: txType,
320
- // chain: ChainToNetworkId[sellAssetChain],
321
- // txParams: {
322
- // senderAddress: quote.senderAddress,
323
- // recipientAddress: quoteFromNode.inbound_address,
324
- // amount: quote.sellAmount,
325
- // token: quote.sellAsset.split(".")[1],
326
- // memo: quoteFromNode.memo || memo,
327
- // },
328
- // },
329
- // ];
330
- //
331
- // output.meta = {
332
- // quoteMode: "TC_SUPPORTED_TO_TC_SUPPORTED",
333
- // };
334
- // output.steps = 1;
335
- // output.complete = true;
336
- // output.source = 'thorchain';
337
- // output.id = uuid();
338
- //
339
- // return output;
340
- // } catch (e) {
341
- // log.error(tag, "Error: ", e);
342
- // throw e;
343
- // }
344
- // };