@pioneer-platform/thorchain-client 0.0.31 → 0.0.33

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 +114 -15
  2. package/package.json +1 -1
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."));
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."));
174
185
  }
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
- }
181
- }
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))
@@ -193,6 +197,7 @@ var get_quote = function (quote) {
193
197
  quoteFromNode = _a.sent();
194
198
  if (quoteFromNode.error)
195
199
  throw new Error(quoteFromNode.error);
200
+ log.info(tag, "quoteFromNode: ", quoteFromNode);
196
201
  amountOutMin = quoteFromNode.amount_out_min;
197
202
  amountOutEstimated = (parseInt(quoteFromNode.expected_amount_out) / BASE_UNIT).toFixed(DECIMALS);
198
203
  output.amountOut = amountOutEstimated;
@@ -204,7 +209,8 @@ var get_quote = function (quote) {
204
209
  };
205
210
  memo = createMemo(memoInput);
206
211
  log.info(tag, "memo: ", memo);
207
- txType = sellAssetChain === "MAYA" ? 'deposit' : 'transfer';
212
+ txType = sellAssetChain === "THOR" ? 'deposit' : 'transfer';
213
+ output.id = uuid();
208
214
  output.txs = [
209
215
  {
210
216
  type: txType,
@@ -224,7 +230,7 @@ var get_quote = function (quote) {
224
230
  output.steps = 1;
225
231
  output.complete = true;
226
232
  output.source = 'thorchain';
227
- output.id = uuid();
233
+ output.raw = quoteFromNode;
228
234
  return [2 /*return*/, output];
229
235
  case 4:
230
236
  e_2 = _a.sent();
@@ -235,3 +241,96 @@ var get_quote = function (quote) {
235
241
  });
236
242
  });
237
243
  };
244
+ // const get_quote = async function (quote: any) {
245
+ // const tag = TAG + " | get_quote | ";
246
+ // try {
247
+ // let output: any = {};
248
+ // if (!quote.sellAsset) throw new Error("missing sellAsset");
249
+ // if (!quote.buyAsset) throw new Error("missing buyAsset");
250
+ // if (!quote.sellAmount) throw new Error("missing sellAmount");
251
+ // if (!quote.senderAddress) throw new Error("missing senderAddress");
252
+ // if (!quote.recipientAddress) throw new Error("missing recipientAddress");
253
+ // if (!quote.slippage) throw new Error("missing slippage");
254
+ //
255
+ // // Get pools from network
256
+ // const pools = await getPools();
257
+ //
258
+ // // Find the pool for the sellAsset
259
+ // const poolIn = pools.find((p: any) => p.asset === quote.sellAsset);
260
+ // if (!poolIn) {
261
+ // log.error(tag, `Pool for sellAsset (${quote.sellAsset}) not found.`);
262
+ // throw new Error(`Pool for sellAsset (${quote.sellAsset}) not found.`);
263
+ // }
264
+ //
265
+ // let poolOut: any = null;
266
+ //
267
+ // // Skip poolOut lookup if buyAsset is RUNE/THOR
268
+ // if (quote.buyAsset === 'THOR.RUNE' || quote.buyAsset === 'RUNE.RUNE') {
269
+ // log.info(tag, `BuyAsset (${quote.buyAsset}) is RUNE/THOR. Skipping poolOut lookup.`);
270
+ // } else {
271
+ // poolOut = pools.find((p: any) => p.asset === quote.buyAsset);
272
+ // if (!poolOut) {
273
+ // log.error(tag, `Pool for buyAsset (${quote.buyAsset}) not found.`);
274
+ // throw new Error(`Pool for buyAsset (${quote.buyAsset}) not found.`);
275
+ // }
276
+ // }
277
+ //
278
+ // log.info(tag, "poolIn: ", poolIn, "poolOut: ", poolOut || 'N/A (RUNE/THOR as buyAsset)');
279
+ //
280
+ // const sellAssetChain = quote.sellAsset.split(".")[0];
281
+ // const DECIMALS = Number(BaseDecimal[sellAssetChain]);
282
+ // if (isNaN(DECIMALS)) throw new Error(`Invalid DECIMALS value for asset: ${sellAssetChain}`);
283
+ // const BASE_UNIT = Math.pow(10, DECIMALS);
284
+ // const sellAmountInBaseUnits = parseFloat(quote.sellAmount) * BASE_UNIT;
285
+ //
286
+ // // Create URL for the API
287
+ // const URL = `/thorchain/quote/swap?from_asset=${quote.sellAsset}&to_asset=${quote.buyAsset}&amount=${sellAmountInBaseUnits}&destination=${quote.recipientAddress}`;
288
+ // log.info(tag, "URL: ", URL);
289
+ //
290
+ // const quoteFromNode = await nodeRequest(URL);
291
+ // if (quoteFromNode.error) throw new Error(quoteFromNode.error);
292
+ //
293
+ // const amountOutMin = quoteFromNode.amount_out_min;
294
+ // const amountOutEstimated = (parseInt(quoteFromNode.expected_amount_out) / BASE_UNIT).toFixed(DECIMALS);
295
+ //
296
+ // output.amountOut = amountOutEstimated;
297
+ //
298
+ // const memoInput = {
299
+ // type: 'SWAP',
300
+ // asset: quote.buyAsset,
301
+ // destAddr: quote.recipientAddress,
302
+ // lim: amountOutMin,
303
+ // };
304
+ // const memo = createMemo(memoInput);
305
+ // log.info(tag, "memo: ", memo);
306
+ //
307
+ // const txType = sellAssetChain === "MAYA" ? 'deposit' : 'transfer';
308
+ //
309
+ // output.txs = [
310
+ // {
311
+ // type: txType,
312
+ // chain: ChainToNetworkId[sellAssetChain],
313
+ // txParams: {
314
+ // senderAddress: quote.senderAddress,
315
+ // recipientAddress: quoteFromNode.inbound_address,
316
+ // amount: quote.sellAmount,
317
+ // token: quote.sellAsset.split(".")[1],
318
+ // memo: quoteFromNode.memo || memo,
319
+ // },
320
+ // },
321
+ // ];
322
+ //
323
+ // output.meta = {
324
+ // quoteMode: "TC_SUPPORTED_TO_TC_SUPPORTED",
325
+ // };
326
+ // output.steps = 1;
327
+ // output.complete = true;
328
+ // output.source = 'thorchain';
329
+ // output.id = uuid();
330
+ //
331
+ // return output;
332
+ // } catch (e) {
333
+ // log.error(tag, "Error: ", e);
334
+ // throw e;
335
+ // }
336
+ // };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pioneer-platform/thorchain-client",
3
- "version": "0.0.31",
3
+ "version": "0.0.33",
4
4
  "main": "./lib/index.js",
5
5
  "types": "./lib/index.d.ts",
6
6
  "dependencies": {