@pioneer-platform/pioneer-router 8.4.72 → 8.4.74

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/lib/index.d.ts CHANGED
@@ -1,5 +1,7 @@
1
1
  declare const TAG = " | Pioneer-router | ";
2
2
  declare const log: any;
3
+ declare const redis: any;
4
+ declare let proToken: any;
3
5
  declare let thorswap: any;
4
6
  declare const caipToRango: any, caipToNetworkId: any;
5
7
  declare let rango: any;
@@ -50,6 +52,7 @@ interface Swap {
50
52
  }
51
53
  declare let NetworksByIntegration: any;
52
54
  declare function get_quote_from_integration(integration: string, quote: Swap): Promise<any>;
55
+ declare let get_pro_rate_usd: () => Promise<any>;
53
56
  declare function get_quote(quote: Swap): Promise<{
54
57
  integration: string;
55
58
  quote: any;
package/lib/index.js CHANGED
@@ -76,6 +76,8 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
76
76
  };
77
77
  var TAG = " | Pioneer-router | ";
78
78
  var log = require('@pioneer-platform/loggerdog')();
79
+ var redis = require('@pioneer-platform/default-redis').redis;
80
+ var proToken = require("@pioneer-platform/pro-token");
79
81
  //thorswap
80
82
  var thorswap = require("@pioneer-platform/thorswap-client");
81
83
  var _a = require("@pioneer-platform/pioneer-caip"), caipToRango = _a.caipToRango, caipToNetworkId = _a.caipToNetworkId;
@@ -263,6 +265,7 @@ function get_quote_from_integration(integration, quote) {
263
265
  return [4 /*yield*/, uniswap.getQuote(payloadUniswap)];
264
266
  case 13:
265
267
  quoteUniswap = _c.sent();
268
+ log.info(tag, "quoteUniswap: ", quoteUniswap);
266
269
  return [2 /*return*/, [quoteUniswap]];
267
270
  case 14:
268
271
  payloadAcross = {
@@ -289,16 +292,45 @@ function get_quote_from_integration(integration, quote) {
289
292
  });
290
293
  });
291
294
  }
292
- function get_quote(quote) {
295
+ var get_pro_rate_usd = function () {
293
296
  return __awaiter(this, void 0, void 0, function () {
294
- var tag, sellChain, buyChain, integrations, quotes, _i, integrations_1, integration, supportedNetworks, integrationQuotes, i, integrationQuote, sellAssetValueUsd, buyAssetValueUsd, proTokenEarned, err_1;
297
+ var cacheValue, proRateUsd, e_2;
295
298
  return __generator(this, function (_a) {
296
299
  switch (_a.label) {
300
+ case 0:
301
+ _a.trys.push([0, 6, , 7]);
302
+ return [4 /*yield*/, redis.get('proRateUsd')];
303
+ case 1:
304
+ cacheValue = _a.sent();
305
+ if (!cacheValue) return [3 /*break*/, 2];
306
+ return [2 /*return*/, parseFloat(cacheValue)]; // Convert string to float if necessary
307
+ case 2: return [4 /*yield*/, proToken.getRateProUsd()];
308
+ case 3:
309
+ proRateUsd = _a.sent();
310
+ return [4 /*yield*/, redis.setex('proRateUsd', 300, proRateUsd.toString())];
311
+ case 4:
312
+ _a.sent(); // Expiry time in seconds, value as string
313
+ return [2 /*return*/, proRateUsd];
314
+ case 5: return [3 /*break*/, 7];
315
+ case 6:
316
+ e_2 = _a.sent();
317
+ log.error(e_2);
318
+ return [2 /*return*/, 1];
319
+ case 7: return [2 /*return*/];
320
+ }
321
+ });
322
+ });
323
+ };
324
+ function get_quote(quote) {
325
+ return __awaiter(this, void 0, void 0, function () {
326
+ var tag, sellChain, buyChain, integrations, quotes, _i, integrations_1, integration, supportedNetworks, integrationQuotes, i, integrationQuote, sellAssetValueUsd, buyAssetValueUsd, proTokenEarned, _a, _b, err_1;
327
+ return __generator(this, function (_c) {
328
+ switch (_c.label) {
297
329
  case 0:
298
330
  tag = " | get_quote | ";
299
- _a.label = 1;
331
+ _c.label = 1;
300
332
  case 1:
301
- _a.trys.push([1, 6, , 7]);
333
+ _c.trys.push([1, 10, , 11]);
302
334
  sellChain = caipToNetworkId(quote.sellAsset.caip);
303
335
  buyChain = caipToNetworkId(quote.buyAsset.caip);
304
336
  integrations = Object.keys(NetworksByIntegration);
@@ -306,51 +338,61 @@ function get_quote(quote) {
306
338
  log.info("sellChain: ", sellChain);
307
339
  log.info("buyChain: ", buyChain);
308
340
  _i = 0, integrations_1 = integrations;
309
- _a.label = 2;
341
+ _c.label = 2;
310
342
  case 2:
311
- if (!(_i < integrations_1.length)) return [3 /*break*/, 5];
343
+ if (!(_i < integrations_1.length)) return [3 /*break*/, 9];
312
344
  integration = integrations_1[_i];
313
345
  supportedNetworks = NetworksByIntegration[integration];
314
346
  log.info(tag, integration + " supportedNetworks: ", supportedNetworks);
315
- if (!(supportedNetworks.includes(sellChain) && supportedNetworks.includes(buyChain))) return [3 /*break*/, 4];
347
+ if (!(supportedNetworks.includes(sellChain) && supportedNetworks.includes(buyChain))) return [3 /*break*/, 8];
316
348
  console.log(TAG, "Found supported integration for both networks:", integration);
317
349
  return [4 /*yield*/, get_quote_from_integration(integration, quote)];
318
350
  case 3:
319
- integrationQuotes = _a.sent();
320
- if (integrationQuotes) {
321
- for (i = 0; i < integrationQuotes.length; i++) {
322
- integrationQuote = integrationQuotes[i];
323
- integrationQuote.sellAsset = quote.sellAsset.caip;
324
- integrationQuote.sellAmount = quote.sellAmount;
325
- integrationQuote.buyAsset = quote.buyAsset.caip;
326
- integrationQuote.buyAmount = integrationQuote.amountOut;
327
- if (integrationQuote.amountOut > 0) {
328
- log.info("integrationQuote.amountOut: ", integrationQuote.amountOut);
329
- sellAssetValueUsd = parseFloat(quote.sellAmount) * quote.sellAsset.priceUsd;
330
- buyAssetValueUsd = parseFloat(integrationQuote.amountOut) * quote.buyAsset.priceUsd;
331
- proTokenEarned = sellAssetValueUsd * 0.1;
332
- integrationQuote.proTokenEarned = proTokenEarned;
333
- integrationQuote.proTokenEarnedUsd = proTokenEarned * 1; //TODO get dynamic price
334
- integrationQuote.sellAssetValueUsd = sellAssetValueUsd;
335
- integrationQuote.buyAssetValueUsd = buyAssetValueUsd;
336
- quotes.push({ integration: integration, quote: integrationQuote });
337
- }
338
- }
339
- }
340
- _a.label = 4;
351
+ integrationQuotes = _c.sent();
352
+ if (!integrationQuotes) return [3 /*break*/, 8];
353
+ i = 0;
354
+ _c.label = 4;
341
355
  case 4:
356
+ if (!(i < integrationQuotes.length)) return [3 /*break*/, 8];
357
+ integrationQuote = integrationQuotes[i];
358
+ integrationQuote.sellAsset = quote.sellAsset.caip;
359
+ integrationQuote.sellAmount = quote.sellAmount;
360
+ integrationQuote.buyAsset = quote.buyAsset.caip;
361
+ integrationQuote.buyAmount = integrationQuote.amountOut;
362
+ if (!(integrationQuote.amountOut > 0)) return [3 /*break*/, 6];
363
+ log.info("integrationQuote.amountOut: ", integrationQuote.amountOut);
364
+ sellAssetValueUsd = parseFloat(quote.sellAmount) * quote.sellAsset.priceUsd;
365
+ buyAssetValueUsd = parseFloat(integrationQuote.amountOut) * quote.buyAsset.priceUsd;
366
+ proTokenEarned = sellAssetValueUsd * 0.1;
367
+ integrationQuote.proTokenEarned = proTokenEarned;
368
+ _a = integrationQuote;
369
+ _b = proTokenEarned;
370
+ return [4 /*yield*/, get_pro_rate_usd()]; //TODO get dynamic price
371
+ case 5:
372
+ _a.proTokenEarnedUsd = _b * (_c.sent()); //TODO get dynamic price
373
+ integrationQuote.sellAssetValueUsd = sellAssetValueUsd;
374
+ integrationQuote.buyAssetValueUsd = buyAssetValueUsd;
375
+ quotes.push({ integration: integration, quote: integrationQuote });
376
+ return [3 /*break*/, 7];
377
+ case 6:
378
+ log.error("Failed to get amountOut from integration: ", integration);
379
+ _c.label = 7;
380
+ case 7:
381
+ i++;
382
+ return [3 /*break*/, 4];
383
+ case 8:
342
384
  _i++;
343
385
  return [3 /*break*/, 2];
344
- case 5:
386
+ case 9:
345
387
  //return applicable intergrations
346
388
  //for each intergration get quote
347
389
  //set best quote
348
390
  //return quotes
349
391
  return [2 /*return*/, quotes];
350
- case 6:
351
- err_1 = _a.sent();
392
+ case 10:
393
+ err_1 = _c.sent();
352
394
  throw err_1;
353
- case 7: return [2 /*return*/];
395
+ case 11: return [2 /*return*/];
354
396
  }
355
397
  });
356
398
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pioneer-platform/pioneer-router",
3
- "version": "8.4.72",
3
+ "version": "8.4.74",
4
4
  "main": "./lib/index.js",
5
5
  "types": "./lib/index.d.ts",
6
6
  "scripts": {
@@ -20,14 +20,15 @@
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",
23
24
  "@pioneer-platform/changelly-client": "^8.3.10",
24
25
  "@pioneer-platform/mayachain-client": "^0.0.34",
25
26
  "@pioneer-platform/osmosis-client": "^0.0.14",
26
27
  "@pioneer-platform/pioneer-caip": "^9.2.26",
28
+ "@pioneer-platform/pro-token": "^0.0.3",
27
29
  "@pioneer-platform/rango-client": "^8.3.19",
28
30
  "@pioneer-platform/thorswap-client": "^8.3.10",
29
- "@pioneer-platform/uniswap-client": "^0.0.21",
30
- "@pioneer-platform/across-client": "^0.0.2",
31
+ "@pioneer-platform/uniswap-client": "^0.0.26",
31
32
  "@uniswap/sdk-core": "^4.2.0",
32
33
  "@uniswap/universal-router-sdk": "^1.9.0",
33
34
  "dotenv": "^8.2.0",