@pioneer-platform/pioneer-router 8.4.95 → 8.4.97

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 +85 -14
  2. package/package.json +1 -2
package/lib/index.js CHANGED
@@ -38,6 +38,17 @@
38
38
  }
39
39
 
40
40
  */
41
+ var __assign = (this && this.__assign) || function () {
42
+ __assign = Object.assign || function(t) {
43
+ for (var s, i = 1, n = arguments.length; i < n; i++) {
44
+ s = arguments[i];
45
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
46
+ t[p] = s[p];
47
+ }
48
+ return t;
49
+ };
50
+ return __assign.apply(this, arguments);
51
+ };
41
52
  var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
42
53
  function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
43
54
  return new (P || (P = Promise))(function (resolve, reject) {
@@ -187,6 +198,10 @@ function get_quote_from_integration(integration, quote) {
187
198
  }
188
199
  return [3 /*break*/, 16];
189
200
  case 2:
201
+ if (!quote.senderAddress)
202
+ throw Error('invalid quote! missing senderAddress');
203
+ if (!quote.recipientAddress)
204
+ throw Error('invalid quote! missing recipientAddress');
190
205
  payloadThorswap = {
191
206
  sellAsset: quote.sellAsset.identifier,
192
207
  buyAsset: quote.buyAsset.identifier,
@@ -358,14 +373,14 @@ var get_pro_rate_usd = function () {
358
373
  };
359
374
  function get_quote(quote) {
360
375
  return __awaiter(this, void 0, void 0, function () {
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
- return __generator(this, function (_c) {
363
- switch (_c.label) {
376
+ 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, PIVOT_ASSETS, _c, supportsInput_1, integration, _d, PIVOT_ASSETS_1, pivotAsset, pivotQuote, pivotAmount, _e, supportsOutput_1, outputIntegration, finalQuote, finalAmount, err_1;
377
+ return __generator(this, function (_f) {
378
+ switch (_f.label) {
364
379
  case 0:
365
380
  tag = " | get_quote | ";
366
- _c.label = 1;
381
+ _f.label = 1;
367
382
  case 1:
368
- _c.trys.push([1, 10, , 11]);
383
+ _f.trys.push([1, 19, , 20]);
369
384
  sellChain = caipToNetworkId(quote.sellAsset.caip);
370
385
  buyChain = caipToNetworkId(quote.buyAsset.caip);
371
386
  integrations = Object.keys(NetworksByIntegration);
@@ -380,13 +395,13 @@ function get_quote(quote) {
380
395
  supportsOutput = [];
381
396
  supportsBoth = [];
382
397
  _i = 0, integrations_1 = integrations;
383
- _c.label = 2;
398
+ _f.label = 2;
384
399
  case 2:
385
400
  if (!(_i < integrations_1.length)) return [3 /*break*/, 9];
386
401
  integration = integrations_1[_i];
387
402
  supportedAssets = AssetsByIntegration[integration];
388
403
  log.info(tag, integration + " supportedAssets: ", supportedAssets);
389
- supportsInputOnly = supportedAssets.includes(quote.sellAsset.caip) && !supportedAssets.includes(quote.buyAsset.caip);
404
+ supportsInputOnly = supportedAssets.includes(quote.sellAsset.caip);
390
405
  supportsOutputOnly = !supportedAssets.includes(quote.sellAsset.caip) && supportedAssets.includes(quote.buyAsset.caip);
391
406
  supportsBothAssets = supportedAssets.includes(quote.sellAsset.caip) && supportedAssets.includes(quote.buyAsset.caip);
392
407
  if (supportsInputOnly) {
@@ -405,10 +420,10 @@ function get_quote(quote) {
405
420
  log.info(tag, "Found supported integration for both assets:", integration);
406
421
  return [4 /*yield*/, get_quote_from_integration(integration, quote)];
407
422
  case 3:
408
- integrationQuotes = _c.sent();
423
+ integrationQuotes = _f.sent();
409
424
  if (!integrationQuotes) return [3 /*break*/, 8];
410
425
  i = 0;
411
- _c.label = 4;
426
+ _f.label = 4;
412
427
  case 4:
413
428
  if (!(i < integrationQuotes.length)) return [3 /*break*/, 8];
414
429
  integrationQuote = integrationQuotes[i];
@@ -426,14 +441,14 @@ function get_quote(quote) {
426
441
  _b = proTokenEarned;
427
442
  return [4 /*yield*/, get_pro_rate_usd()];
428
443
  case 5:
429
- _a.proTokenEarnedUsd = _b * (_c.sent()); //TODO get dynamic price
444
+ _a.proTokenEarnedUsd = _b * (_f.sent()); //TODO get dynamic price
430
445
  integrationQuote.sellAssetValueUsd = sellAssetValueUsd;
431
446
  integrationQuote.buyAssetValueUsd = buyAssetValueUsd;
432
447
  quotes.push({ integration: integration, quote: integrationQuote });
433
448
  return [3 /*break*/, 7];
434
449
  case 6:
435
450
  log.error("Failed to get amountOut from integration: ", integration);
436
- _c.label = 7;
451
+ _f.label = 7;
437
452
  case 7:
438
453
  i++;
439
454
  return [3 /*break*/, 4];
@@ -444,11 +459,67 @@ function get_quote(quote) {
444
459
  log.info(tag, "Integrations supporting input asset: ", supportsInput);
445
460
  log.info(tag, "Integrations supporting output asset: ", supportsOutput);
446
461
  log.info(tag, "Integrations supporting both assets: ", supportsBoth);
447
- return [2 /*return*/, quotes];
462
+ //TODO if no quote found for both assets, find a pivot asset
463
+ log.info(tag, "quotes: ", quotes);
464
+ if (!(quotes.length === 0)) return [3 /*break*/, 18];
465
+ log.info(tag, "No direct quotes found. Searching for pivot trades...");
466
+ PIVOT_ASSETS = [
467
+ { caip: 'eip155:1/slip44:60', name: 'ETH' },
468
+ { caip: 'bip122:000000000019d6689c085ae165831e93/slip44:0', name: 'BTC' }
469
+ ];
470
+ _c = 0, supportsInput_1 = supportsInput;
471
+ _f.label = 10;
448
472
  case 10:
449
- err_1 = _c.sent();
473
+ if (!(_c < supportsInput_1.length)) return [3 /*break*/, 18];
474
+ integration = supportsInput_1[_c];
475
+ _d = 0, PIVOT_ASSETS_1 = PIVOT_ASSETS;
476
+ _f.label = 11;
477
+ case 11:
478
+ if (!(_d < PIVOT_ASSETS_1.length)) return [3 /*break*/, 17];
479
+ pivotAsset = PIVOT_ASSETS_1[_d];
480
+ return [4 /*yield*/, get_quote_from_integration(integration, __assign(__assign({}, quote), { buyAsset: { caip: pivotAsset } }))];
481
+ case 12:
482
+ pivotQuote = _f.sent();
483
+ if (!(pivotQuote && pivotQuote.length > 0)) return [3 /*break*/, 16];
484
+ pivotAmount = pivotQuote[0].amountOut;
485
+ log.info(tag, "Pivot trade found: ", pivotAmount, " of ", pivotAsset);
486
+ _e = 0, supportsOutput_1 = supportsOutput;
487
+ _f.label = 13;
488
+ case 13:
489
+ if (!(_e < supportsOutput_1.length)) return [3 /*break*/, 16];
490
+ outputIntegration = supportsOutput_1[_e];
491
+ return [4 /*yield*/, get_quote_from_integration(outputIntegration, { sellAsset: { caip: pivotAsset }, sellAmount: pivotAmount, buyAsset: quote.buyAsset })];
492
+ case 14:
493
+ finalQuote = _f.sent();
494
+ if (finalQuote && finalQuote.length > 0 && finalQuote[0].amountOut > 0) {
495
+ finalAmount = finalQuote[0].amountOut;
496
+ quotes.push({
497
+ integration: integration + " -> " + outputIntegration,
498
+ quote: {
499
+ sellAsset: quote.sellAsset.caip,
500
+ sellAmount: quote.sellAmount,
501
+ buyAsset: quote.buyAsset.caip,
502
+ buyAmount: finalAmount,
503
+ pivotAsset: pivotAsset,
504
+ pivotAmount: pivotAmount
505
+ }
506
+ });
507
+ }
508
+ _f.label = 15;
509
+ case 15:
510
+ _e++;
511
+ return [3 /*break*/, 13];
512
+ case 16:
513
+ _d++;
514
+ return [3 /*break*/, 11];
515
+ case 17:
516
+ _c++;
517
+ return [3 /*break*/, 10];
518
+ case 18: return [2 /*return*/, quotes];
519
+ case 19:
520
+ err_1 = _f.sent();
450
521
  throw err_1;
451
- case 11: return [2 /*return*/];
522
+ case 20: return [2 /*return*/];
452
523
  }
453
524
  });
454
525
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pioneer-platform/pioneer-router",
3
- "version": "8.4.95",
3
+ "version": "8.4.97",
4
4
  "main": "./lib/index.js",
5
5
  "types": "./lib/index.d.ts",
6
6
  "scripts": {
@@ -20,7 +20,6 @@
20
20
  "clean": "rm -rf coverage src/**/*.js src/**/*.map lib node_modules"
21
21
  },
22
22
  "dependencies": {
23
- "@pioneer-platform/across-client": "^0.0.2",
24
23
  "@pioneer-platform/chainflip-client": "^0.0.9",
25
24
  "@pioneer-platform/changelly-client": "^8.3.19",
26
25
  "@pioneer-platform/mayachain-client": "^0.0.36",