@pioneer-platform/pioneer-router 8.4.73 → 8.4.75
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 +5 -0
- package/lib/index.js +85 -35
- package/package.json +4 -3
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;
|
@@ -8,7 +10,9 @@ declare let osmosis: any;
|
|
8
10
|
declare let mayachain: any;
|
9
11
|
declare let uniswap: any;
|
10
12
|
declare let across: any;
|
13
|
+
declare let MEMOLESS_SUPPORT: any;
|
11
14
|
interface Swap {
|
15
|
+
memoless?: boolean;
|
12
16
|
sellAsset: {
|
13
17
|
context: string;
|
14
18
|
caip: string;
|
@@ -50,6 +54,7 @@ interface Swap {
|
|
50
54
|
}
|
51
55
|
declare let NetworksByIntegration: any;
|
52
56
|
declare function get_quote_from_integration(integration: string, quote: Swap): Promise<any>;
|
57
|
+
declare let get_pro_rate_usd: () => Promise<any>;
|
53
58
|
declare function get_quote(quote: Swap): Promise<{
|
54
59
|
integration: string;
|
55
60
|
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;
|
@@ -92,6 +94,10 @@ var uniswap = require("@pioneer-platform/uniswap-client");
|
|
92
94
|
//1inch/0x
|
93
95
|
//bridge
|
94
96
|
var across = require("@pioneer-platform/across-client");
|
97
|
+
var MEMOLESS_SUPPORT = {
|
98
|
+
"changelly": true,
|
99
|
+
"chainflip": true,
|
100
|
+
};
|
95
101
|
var NetworksByIntegration = {};
|
96
102
|
module.exports = {
|
97
103
|
init: function () {
|
@@ -222,8 +228,8 @@ function get_quote_from_integration(integration, quote) {
|
|
222
228
|
quoteOsmosis = _c.sent();
|
223
229
|
return [2 /*return*/, [quoteOsmosis]];
|
224
230
|
case 8:
|
225
|
-
from = quote.sellAsset.ticker;
|
226
|
-
to = quote.buyAsset.ticker;
|
231
|
+
from = quote.sellAsset.ticker || quote.sellAsset.symbol;
|
232
|
+
to = quote.buyAsset.ticker || quote.buyAsset.symbol;
|
227
233
|
address = quote.buyAsset.address;
|
228
234
|
amount = quote.sellAmount;
|
229
235
|
log.info({
|
@@ -263,6 +269,7 @@ function get_quote_from_integration(integration, quote) {
|
|
263
269
|
return [4 /*yield*/, uniswap.getQuote(payloadUniswap)];
|
264
270
|
case 13:
|
265
271
|
quoteUniswap = _c.sent();
|
272
|
+
log.info(tag, "quoteUniswap: ", quoteUniswap);
|
266
273
|
return [2 /*return*/, [quoteUniswap]];
|
267
274
|
case 14:
|
268
275
|
payloadAcross = {
|
@@ -289,68 +296,111 @@ function get_quote_from_integration(integration, quote) {
|
|
289
296
|
});
|
290
297
|
});
|
291
298
|
}
|
292
|
-
function
|
299
|
+
var get_pro_rate_usd = function () {
|
293
300
|
return __awaiter(this, void 0, void 0, function () {
|
294
|
-
var
|
301
|
+
var cacheValue, proRateUsd, e_2;
|
295
302
|
return __generator(this, function (_a) {
|
296
303
|
switch (_a.label) {
|
304
|
+
case 0:
|
305
|
+
_a.trys.push([0, 6, , 7]);
|
306
|
+
return [4 /*yield*/, redis.get('proRateUsd')];
|
307
|
+
case 1:
|
308
|
+
cacheValue = _a.sent();
|
309
|
+
if (!cacheValue) return [3 /*break*/, 2];
|
310
|
+
return [2 /*return*/, parseFloat(cacheValue)]; // Convert string to float if necessary
|
311
|
+
case 2: return [4 /*yield*/, proToken.getRateProUsd()];
|
312
|
+
case 3:
|
313
|
+
proRateUsd = _a.sent();
|
314
|
+
return [4 /*yield*/, redis.setex('proRateUsd', 300, proRateUsd.toString())];
|
315
|
+
case 4:
|
316
|
+
_a.sent(); // Expiry time in seconds, value as string
|
317
|
+
return [2 /*return*/, proRateUsd];
|
318
|
+
case 5: return [3 /*break*/, 7];
|
319
|
+
case 6:
|
320
|
+
e_2 = _a.sent();
|
321
|
+
log.error(e_2);
|
322
|
+
return [2 /*return*/, 1];
|
323
|
+
case 7: return [2 /*return*/];
|
324
|
+
}
|
325
|
+
});
|
326
|
+
});
|
327
|
+
};
|
328
|
+
function get_quote(quote) {
|
329
|
+
return __awaiter(this, void 0, void 0, function () {
|
330
|
+
var tag, sellChain, buyChain, integrations, quotes, _i, integrations_1, integration, supportedNetworks, integrationQuotes, i, integrationQuote, sellAssetValueUsd, buyAssetValueUsd, proTokenEarned, _a, _b, err_1;
|
331
|
+
return __generator(this, function (_c) {
|
332
|
+
switch (_c.label) {
|
297
333
|
case 0:
|
298
334
|
tag = " | get_quote | ";
|
299
|
-
|
335
|
+
_c.label = 1;
|
300
336
|
case 1:
|
301
|
-
|
337
|
+
_c.trys.push([1, 10, , 11]);
|
302
338
|
sellChain = caipToNetworkId(quote.sellAsset.caip);
|
303
339
|
buyChain = caipToNetworkId(quote.buyAsset.caip);
|
304
340
|
integrations = Object.keys(NetworksByIntegration);
|
305
341
|
quotes = [];
|
306
342
|
log.info("sellChain: ", sellChain);
|
307
343
|
log.info("buyChain: ", buyChain);
|
344
|
+
//if memoless filter
|
345
|
+
if (quote.memoless) {
|
346
|
+
integrations = integrations.filter(function (integration) { return MEMOLESS_SUPPORT[integration]; });
|
347
|
+
}
|
308
348
|
_i = 0, integrations_1 = integrations;
|
309
|
-
|
349
|
+
_c.label = 2;
|
310
350
|
case 2:
|
311
|
-
if (!(_i < integrations_1.length)) return [3 /*break*/,
|
351
|
+
if (!(_i < integrations_1.length)) return [3 /*break*/, 9];
|
312
352
|
integration = integrations_1[_i];
|
313
353
|
supportedNetworks = NetworksByIntegration[integration];
|
314
354
|
log.info(tag, integration + " supportedNetworks: ", supportedNetworks);
|
315
|
-
if (!(supportedNetworks.includes(sellChain) && supportedNetworks.includes(buyChain))) return [3 /*break*/,
|
355
|
+
if (!(supportedNetworks.includes(sellChain) && supportedNetworks.includes(buyChain))) return [3 /*break*/, 8];
|
316
356
|
console.log(TAG, "Found supported integration for both networks:", integration);
|
317
357
|
return [4 /*yield*/, get_quote_from_integration(integration, quote)];
|
318
358
|
case 3:
|
319
|
-
integrationQuotes =
|
320
|
-
if (integrationQuotes)
|
321
|
-
|
322
|
-
|
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;
|
359
|
+
integrationQuotes = _c.sent();
|
360
|
+
if (!integrationQuotes) return [3 /*break*/, 8];
|
361
|
+
i = 0;
|
362
|
+
_c.label = 4;
|
341
363
|
case 4:
|
364
|
+
if (!(i < integrationQuotes.length)) return [3 /*break*/, 8];
|
365
|
+
integrationQuote = integrationQuotes[i];
|
366
|
+
integrationQuote.sellAsset = quote.sellAsset.caip;
|
367
|
+
integrationQuote.sellAmount = quote.sellAmount;
|
368
|
+
integrationQuote.buyAsset = quote.buyAsset.caip;
|
369
|
+
integrationQuote.buyAmount = integrationQuote.amountOut;
|
370
|
+
if (!(integrationQuote.amountOut > 0)) return [3 /*break*/, 6];
|
371
|
+
log.info("integrationQuote.amountOut: ", integrationQuote.amountOut);
|
372
|
+
sellAssetValueUsd = parseFloat(quote.sellAmount) * quote.sellAsset.priceUsd;
|
373
|
+
buyAssetValueUsd = parseFloat(integrationQuote.amountOut) * quote.buyAsset.priceUsd;
|
374
|
+
proTokenEarned = sellAssetValueUsd * 0.1;
|
375
|
+
integrationQuote.proTokenEarned = proTokenEarned;
|
376
|
+
_a = integrationQuote;
|
377
|
+
_b = proTokenEarned;
|
378
|
+
return [4 /*yield*/, get_pro_rate_usd()]; //TODO get dynamic price
|
379
|
+
case 5:
|
380
|
+
_a.proTokenEarnedUsd = _b * (_c.sent()); //TODO get dynamic price
|
381
|
+
integrationQuote.sellAssetValueUsd = sellAssetValueUsd;
|
382
|
+
integrationQuote.buyAssetValueUsd = buyAssetValueUsd;
|
383
|
+
quotes.push({ integration: integration, quote: integrationQuote });
|
384
|
+
return [3 /*break*/, 7];
|
385
|
+
case 6:
|
386
|
+
log.error("Failed to get amountOut from integration: ", integration);
|
387
|
+
_c.label = 7;
|
388
|
+
case 7:
|
389
|
+
i++;
|
390
|
+
return [3 /*break*/, 4];
|
391
|
+
case 8:
|
342
392
|
_i++;
|
343
393
|
return [3 /*break*/, 2];
|
344
|
-
case
|
394
|
+
case 9:
|
345
395
|
//return applicable intergrations
|
346
396
|
//for each intergration get quote
|
347
397
|
//set best quote
|
348
398
|
//return quotes
|
349
399
|
return [2 /*return*/, quotes];
|
350
|
-
case
|
351
|
-
err_1 =
|
400
|
+
case 10:
|
401
|
+
err_1 = _c.sent();
|
352
402
|
throw err_1;
|
353
|
-
case
|
403
|
+
case 11: return [2 /*return*/];
|
354
404
|
}
|
355
405
|
});
|
356
406
|
});
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "@pioneer-platform/pioneer-router",
|
3
|
-
"version": "8.4.
|
3
|
+
"version": "8.4.75",
|
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.
|
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",
|