@pioneer-platform/thorchain-client 0.0.30 → 0.0.32

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.
Files changed (2) hide show
  1. package/lib/index.js +110 -13
  2. package/package.json +2 -2
package/lib/index.js CHANGED
@@ -163,23 +163,27 @@ var get_quote = function (quote) {
163
163
  case 2:
164
164
  pools = _a.sent();
165
165
  poolIn = pools.find(function (p) { return p.asset === quote.sellAsset; });
166
- if (!poolIn) {
166
+ poolOut = pools.find(function (p) { return p.asset === quote.buyAsset; });
167
+ // If the sellAsset is RUNE, use the pool for the buyAsset
168
+ if (quote.sellAsset === 'THOR.RUNE') {
169
+ poolIn = null; // RUNE does not need an "in" pool, only "out"
170
+ poolOut = pools.find(function (p) { return p.asset === quote.buyAsset; });
171
+ }
172
+ // If the buyAsset is RUNE, use the pool for the sellAsset
173
+ if (quote.buyAsset === 'THOR.RUNE') {
174
+ poolOut = null; // RUNE does not need an "out" pool, only "in"
175
+ poolIn = pools.find(function (p) { return p.asset === quote.sellAsset; });
176
+ }
177
+ // Handle case where pools are not found
178
+ if (!poolIn && quote.sellAsset !== 'THOR.RUNE') {
167
179
  log.error(tag, "Pool for sellAsset (".concat(quote.sellAsset, ") not found."));
168
180
  throw new Error("Pool for sellAsset (".concat(quote.sellAsset, ") not found."));
169
181
  }
170
- poolOut = null;
171
- // Skip poolOut lookup if buyAsset is RUNE/THOR
172
- if (quote.buyAsset === 'THOR.RUNE' || quote.buyAsset === 'RUNE.RUNE') {
173
- log.info(tag, "BuyAsset (".concat(quote.buyAsset, ") is RUNE/THOR. Skipping poolOut lookup."));
174
- }
175
- else {
176
- poolOut = pools.find(function (p) { return p.asset === quote.buyAsset; });
177
- if (!poolOut) {
178
- log.error(tag, "Pool for buyAsset (".concat(quote.buyAsset, ") not found."));
179
- throw new Error("Pool for buyAsset (".concat(quote.buyAsset, ") not found."));
180
- }
182
+ if (!poolOut && quote.buyAsset !== 'THOR.RUNE') {
183
+ log.error(tag, "Pool for buyAsset (".concat(quote.buyAsset, ") not found."));
184
+ throw new Error("Pool for buyAsset (".concat(quote.buyAsset, ") not found."));
181
185
  }
182
- log.info(tag, "poolIn: ", poolIn, "poolOut: ", poolOut || 'N/A (RUNE/THOR as buyAsset)');
186
+ log.info(tag, "poolIn: ", poolIn, "poolOut: ", poolOut);
183
187
  sellAssetChain = quote.sellAsset.split(".")[0];
184
188
  DECIMALS = Number(types_1.BaseDecimal[sellAssetChain]);
185
189
  if (isNaN(DECIMALS))
@@ -235,3 +239,96 @@ var get_quote = function (quote) {
235
239
  });
236
240
  });
237
241
  };
242
+ // const get_quote = async function (quote: any) {
243
+ // const tag = TAG + " | get_quote | ";
244
+ // try {
245
+ // let output: any = {};
246
+ // if (!quote.sellAsset) throw new Error("missing sellAsset");
247
+ // if (!quote.buyAsset) throw new Error("missing buyAsset");
248
+ // if (!quote.sellAmount) throw new Error("missing sellAmount");
249
+ // if (!quote.senderAddress) throw new Error("missing senderAddress");
250
+ // if (!quote.recipientAddress) throw new Error("missing recipientAddress");
251
+ // if (!quote.slippage) throw new Error("missing slippage");
252
+ //
253
+ // // Get pools from network
254
+ // const pools = await getPools();
255
+ //
256
+ // // Find the pool for the sellAsset
257
+ // const poolIn = pools.find((p: any) => p.asset === quote.sellAsset);
258
+ // if (!poolIn) {
259
+ // log.error(tag, `Pool for sellAsset (${quote.sellAsset}) not found.`);
260
+ // throw new Error(`Pool for sellAsset (${quote.sellAsset}) not found.`);
261
+ // }
262
+ //
263
+ // let poolOut: any = null;
264
+ //
265
+ // // Skip poolOut lookup if buyAsset is RUNE/THOR
266
+ // if (quote.buyAsset === 'THOR.RUNE' || quote.buyAsset === 'RUNE.RUNE') {
267
+ // log.info(tag, `BuyAsset (${quote.buyAsset}) is RUNE/THOR. Skipping poolOut lookup.`);
268
+ // } else {
269
+ // poolOut = pools.find((p: any) => p.asset === quote.buyAsset);
270
+ // if (!poolOut) {
271
+ // log.error(tag, `Pool for buyAsset (${quote.buyAsset}) not found.`);
272
+ // throw new Error(`Pool for buyAsset (${quote.buyAsset}) not found.`);
273
+ // }
274
+ // }
275
+ //
276
+ // log.info(tag, "poolIn: ", poolIn, "poolOut: ", poolOut || 'N/A (RUNE/THOR as buyAsset)');
277
+ //
278
+ // const sellAssetChain = quote.sellAsset.split(".")[0];
279
+ // const DECIMALS = Number(BaseDecimal[sellAssetChain]);
280
+ // if (isNaN(DECIMALS)) throw new Error(`Invalid DECIMALS value for asset: ${sellAssetChain}`);
281
+ // const BASE_UNIT = Math.pow(10, DECIMALS);
282
+ // const sellAmountInBaseUnits = parseFloat(quote.sellAmount) * BASE_UNIT;
283
+ //
284
+ // // Create URL for the API
285
+ // const URL = `/thorchain/quote/swap?from_asset=${quote.sellAsset}&to_asset=${quote.buyAsset}&amount=${sellAmountInBaseUnits}&destination=${quote.recipientAddress}`;
286
+ // log.info(tag, "URL: ", URL);
287
+ //
288
+ // const quoteFromNode = await nodeRequest(URL);
289
+ // if (quoteFromNode.error) throw new Error(quoteFromNode.error);
290
+ //
291
+ // const amountOutMin = quoteFromNode.amount_out_min;
292
+ // const amountOutEstimated = (parseInt(quoteFromNode.expected_amount_out) / BASE_UNIT).toFixed(DECIMALS);
293
+ //
294
+ // output.amountOut = amountOutEstimated;
295
+ //
296
+ // const memoInput = {
297
+ // type: 'SWAP',
298
+ // asset: quote.buyAsset,
299
+ // destAddr: quote.recipientAddress,
300
+ // lim: amountOutMin,
301
+ // };
302
+ // const memo = createMemo(memoInput);
303
+ // log.info(tag, "memo: ", memo);
304
+ //
305
+ // const txType = sellAssetChain === "MAYA" ? 'deposit' : 'transfer';
306
+ //
307
+ // output.txs = [
308
+ // {
309
+ // type: txType,
310
+ // chain: ChainToNetworkId[sellAssetChain],
311
+ // txParams: {
312
+ // senderAddress: quote.senderAddress,
313
+ // recipientAddress: quoteFromNode.inbound_address,
314
+ // amount: quote.sellAmount,
315
+ // token: quote.sellAsset.split(".")[1],
316
+ // memo: quoteFromNode.memo || memo,
317
+ // },
318
+ // },
319
+ // ];
320
+ //
321
+ // output.meta = {
322
+ // quoteMode: "TC_SUPPORTED_TO_TC_SUPPORTED",
323
+ // };
324
+ // output.steps = 1;
325
+ // output.complete = true;
326
+ // output.source = 'thorchain';
327
+ // output.id = uuid();
328
+ //
329
+ // return output;
330
+ // } catch (e) {
331
+ // log.error(tag, "Error: ", e);
332
+ // throw e;
333
+ // }
334
+ // };
package/package.json CHANGED
@@ -1,11 +1,11 @@
1
1
  {
2
2
  "name": "@pioneer-platform/thorchain-client",
3
- "version": "0.0.30",
3
+ "version": "0.0.32",
4
4
  "main": "./lib/index.js",
5
5
  "types": "./lib/index.d.ts",
6
6
  "dependencies": {
7
7
  "@pioneer-platform/loggerdog": "^8.3.1",
8
- "@pioneer-platform/pioneer-caip": "^9.2.34",
8
+ "@pioneer-platform/pioneer-caip": "^9.2.38",
9
9
  "@pioneer-platform/pioneer-coins": "^9.2.24",
10
10
  "axios": "^1.3.4",
11
11
  "dotenv": "^8.2.0",