@pioneer-platform/pioneer-router 8.4.93 → 8.4.95

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 +89 -11
  2. package/package.json +1 -1
package/lib/index.js CHANGED
@@ -358,7 +358,7 @@ var get_pro_rate_usd = function () {
358
358
  };
359
359
  function get_quote(quote) {
360
360
  return __awaiter(this, void 0, void 0, function () {
361
- var tag, sellChain, buyChain, integrations, quotes, _i, integrations_1, integration, supportedAssets, integrationQuotes, i, integrationQuote, sellAssetValueUsd, buyAssetValueUsd, proTokenEarned, _a, _b, err_1;
361
+ var tag, sellChain, buyChain, integrations, quotes, supportsInput, supportsOutput, supportsBoth, _i, integrations_1, integration, supportedAssets, supportsInputOnly, supportsOutputOnly, supportsBothAssets, integrationQuotes, i, integrationQuote, sellAssetValueUsd, buyAssetValueUsd, proTokenEarned, _a, _b, err_1;
362
362
  return __generator(this, function (_c) {
363
363
  switch (_c.label) {
364
364
  case 0:
@@ -372,10 +372,13 @@ function get_quote(quote) {
372
372
  quotes = [];
373
373
  log.info("sellChain: ", sellChain);
374
374
  log.info("buyChain: ", buyChain);
375
- //if memoless filter
375
+ // Filter integrations for memoless support if applicable
376
376
  if (quote.memoless) {
377
377
  integrations = integrations.filter(function (integration) { return MEMOLESS_SUPPORT[integration]; });
378
378
  }
379
+ supportsInput = [];
380
+ supportsOutput = [];
381
+ supportsBoth = [];
379
382
  _i = 0, integrations_1 = integrations;
380
383
  _c.label = 2;
381
384
  case 2:
@@ -383,8 +386,23 @@ function get_quote(quote) {
383
386
  integration = integrations_1[_i];
384
387
  supportedAssets = AssetsByIntegration[integration];
385
388
  log.info(tag, integration + " supportedAssets: ", supportedAssets);
386
- if (!(supportedAssets.includes(quote.sellAsset.caip) && supportedAssets.includes(quote.buyAsset.caip))) return [3 /*break*/, 8];
387
- console.log(TAG, "Found supported integration for both assets:", integration);
389
+ supportsInputOnly = supportedAssets.includes(quote.sellAsset.caip) && !supportedAssets.includes(quote.buyAsset.caip);
390
+ supportsOutputOnly = !supportedAssets.includes(quote.sellAsset.caip) && supportedAssets.includes(quote.buyAsset.caip);
391
+ supportsBothAssets = supportedAssets.includes(quote.sellAsset.caip) && supportedAssets.includes(quote.buyAsset.caip);
392
+ if (supportsInputOnly) {
393
+ supportsInput.push(integration);
394
+ log.info(tag, integration + " supports input asset: ", quote.sellAsset.caip);
395
+ }
396
+ if (supportsOutputOnly) {
397
+ supportsOutput.push(integration);
398
+ log.info(tag, integration + " supports output asset: ", quote.buyAsset.caip);
399
+ }
400
+ if (supportsBothAssets) {
401
+ supportsBoth.push(integration);
402
+ log.info(tag, integration + " supports both assets: ", quote.sellAsset.caip, quote.buyAsset.caip);
403
+ }
404
+ if (!supportsBothAssets) return [3 /*break*/, 8];
405
+ log.info(tag, "Found supported integration for both assets:", integration);
388
406
  return [4 /*yield*/, get_quote_from_integration(integration, quote)];
389
407
  case 3:
390
408
  integrationQuotes = _c.sent();
@@ -406,7 +424,7 @@ function get_quote(quote) {
406
424
  integrationQuote.proTokenEarned = proTokenEarned;
407
425
  _a = integrationQuote;
408
426
  _b = proTokenEarned;
409
- return [4 /*yield*/, get_pro_rate_usd()]; //TODO get dynamic price
427
+ return [4 /*yield*/, get_pro_rate_usd()];
410
428
  case 5:
411
429
  _a.proTokenEarnedUsd = _b * (_c.sent()); //TODO get dynamic price
412
430
  integrationQuote.sellAssetValueUsd = sellAssetValueUsd;
@@ -422,12 +440,11 @@ function get_quote(quote) {
422
440
  case 8:
423
441
  _i++;
424
442
  return [3 /*break*/, 2];
425
- case 9:
426
- //return applicable intergrations
427
- //for each intergration get quote
428
- //set best quote
429
- //return quotes
430
- return [2 /*return*/, quotes];
443
+ case 9:
444
+ log.info(tag, "Integrations supporting input asset: ", supportsInput);
445
+ log.info(tag, "Integrations supporting output asset: ", supportsOutput);
446
+ log.info(tag, "Integrations supporting both assets: ", supportsBoth);
447
+ return [2 /*return*/, quotes];
431
448
  case 10:
432
449
  err_1 = _c.sent();
433
450
  throw err_1;
@@ -436,3 +453,64 @@ function get_quote(quote) {
436
453
  });
437
454
  });
438
455
  }
456
+ // async function get_quote(quote:Swap) {
457
+ // let tag = " | get_quote | "
458
+ // try {
459
+ //
460
+ // let sellChain = caipToNetworkId(quote.sellAsset.caip);
461
+ // let buyChain = caipToNetworkId(quote.buyAsset.caip);
462
+ // let integrations = Object.keys(NetworksByIntegration);
463
+ // let quotes = [];
464
+ // log.info("sellChain: ",sellChain)
465
+ // log.info("buyChain: ",buyChain)
466
+ //
467
+ // //if memoless filter
468
+ // if (quote.memoless) {
469
+ // integrations = integrations.filter(integration => MEMOLESS_SUPPORT[integration]);
470
+ // }
471
+ //
472
+ // for (let integration of integrations) {
473
+ // let supportedAssets = AssetsByIntegration[integration];
474
+ // log.info(tag,integration+" supportedAssets: ",supportedAssets)
475
+ // if (supportedAssets.includes(quote.sellAsset.caip) && supportedAssets.includes(quote.buyAsset.caip)) {
476
+ // console.log(TAG, "Found supported integration for both assets:", integration);
477
+ // let integrationQuotes = await get_quote_from_integration(integration, quote);
478
+ // if(integrationQuotes) {
479
+ // for(let i = 0; i < integrationQuotes.length; i++){
480
+ // let integrationQuote = integrationQuotes[i]
481
+ // integrationQuote.sellAsset = quote.sellAsset.caip
482
+ // integrationQuote.sellAmount = quote.sellAmount
483
+ // integrationQuote.buyAsset = quote.buyAsset.caip
484
+ // integrationQuote.buyAmount = integrationQuote.amountOut
485
+ // if(integrationQuote.amountOut > 0){
486
+ // log.info("integrationQuote.amountOut: ",integrationQuote.amountOut)
487
+ // let sellAssetValueUsd = parseFloat(quote.sellAmount) * quote.sellAsset.priceUsd;
488
+ // let buyAssetValueUsd = parseFloat(integrationQuote.amountOut) * quote.buyAsset.priceUsd;
489
+ // let proTokenEarned = sellAssetValueUsd * 0.1; // For every 1 USD, they earn 0.01 PRO token
490
+ // integrationQuote.proTokenEarned = proTokenEarned;
491
+ // integrationQuote.proTokenEarnedUsd = proTokenEarned * await get_pro_rate_usd() //TODO get dynamic price
492
+ // integrationQuote.sellAssetValueUsd = sellAssetValueUsd;
493
+ // integrationQuote.buyAssetValueUsd = buyAssetValueUsd;
494
+ // quotes.push({ integration, quote: integrationQuote });
495
+ // } else {
496
+ // log.error("Failed to get amountOut from integration: ",integration)
497
+ // }
498
+ // }
499
+ // }
500
+ // }
501
+ // }
502
+ //
503
+ //
504
+ // //return applicable intergrations
505
+ //
506
+ // //for each intergration get quote
507
+ //
508
+ // //set best quote
509
+ //
510
+ // //return quotes
511
+ // return quotes;
512
+ // } catch (err) {
513
+ // throw err;
514
+ // }
515
+ // }
516
+ //
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pioneer-platform/pioneer-router",
3
- "version": "8.4.93",
3
+ "version": "8.4.95",
4
4
  "main": "./lib/index.js",
5
5
  "types": "./lib/index.d.ts",
6
6
  "scripts": {