@pioneer-platform/pioneer-router 8.4.98 → 8.4.100
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 +3 -3
- package/lib/index.js +107 -132
- package/package.json +9 -9
package/lib/index.d.ts
CHANGED
@@ -2,11 +2,11 @@ declare const TAG = " | Pioneer-router | ";
|
|
2
2
|
declare const log: any;
|
3
3
|
declare const redis: any;
|
4
4
|
declare let proToken: any;
|
5
|
-
declare
|
6
|
-
declare const caipToRango: any, caipToNetworkId: any;
|
5
|
+
declare const caipToRango: any, caipToNetworkId: any, caipToThorchain: any;
|
7
6
|
declare let rango: any;
|
8
7
|
declare let changelly: any;
|
9
8
|
declare let osmosis: any;
|
9
|
+
declare let thorchain: any;
|
10
10
|
declare let mayachain: any;
|
11
11
|
declare let uniswap: any;
|
12
12
|
declare let chainflip: any;
|
@@ -54,7 +54,7 @@ interface Swap {
|
|
54
54
|
}
|
55
55
|
declare let NetworksByIntegration: any;
|
56
56
|
declare let AssetsByIntegration: any;
|
57
|
-
declare function get_quote_from_integration(integration: string, quote: Swap): Promise<any>;
|
57
|
+
declare function get_quote_from_integration(integration: string, quote: Swap): Promise<any[] | null>;
|
58
58
|
declare let get_pro_rate_usd: () => Promise<any>;
|
59
59
|
declare function get_quote(quote: Swap): Promise<{
|
60
60
|
integration: string;
|
package/lib/index.js
CHANGED
@@ -38,17 +38,6 @@
|
|
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
|
-
};
|
52
41
|
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
53
42
|
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
54
43
|
return new (P || (P = Promise))(function (resolve, reject) {
|
@@ -89,15 +78,15 @@ var TAG = " | Pioneer-router | ";
|
|
89
78
|
var log = require('@pioneer-platform/loggerdog')();
|
90
79
|
var redis = require('@pioneer-platform/default-redis').redis;
|
91
80
|
var proToken = require("@pioneer-platform/pro-token");
|
92
|
-
|
93
|
-
var thorswap = require("@pioneer-platform/thorswap-client");
|
94
|
-
var _a = require("@pioneer-platform/pioneer-caip"), caipToRango = _a.caipToRango, caipToNetworkId = _a.caipToNetworkId;
|
81
|
+
var _a = require("@pioneer-platform/pioneer-caip"), caipToRango = _a.caipToRango, caipToNetworkId = _a.caipToNetworkId, caipToThorchain = _a.caipToThorchain;
|
95
82
|
//rango
|
96
83
|
var rango = require("@pioneer-platform/rango-client");
|
97
84
|
//changelly
|
98
85
|
var changelly = require("@pioneer-platform/changelly-client");
|
99
86
|
//osmosis
|
100
87
|
var osmosis = require("@pioneer-platform/osmosis-client");
|
88
|
+
//
|
89
|
+
var thorchain = require("@pioneer-platform/thorchain-client");
|
101
90
|
//osmosis
|
102
91
|
var mayachain = require("@pioneer-platform/mayachain-client");
|
103
92
|
//uniswap
|
@@ -118,39 +107,39 @@ module.exports = {
|
|
118
107
|
return __awaiter(this, void 0, void 0, function () {
|
119
108
|
return __generator(this, function (_a) {
|
120
109
|
switch (_a.label) {
|
121
|
-
case 0: return [4 /*yield*/,
|
110
|
+
case 0: return [4 /*yield*/, rango.init()];
|
122
111
|
case 1:
|
123
112
|
_a.sent();
|
124
|
-
return [4 /*yield*/,
|
113
|
+
return [4 /*yield*/, changelly.init()];
|
125
114
|
case 2:
|
126
115
|
_a.sent();
|
127
|
-
return [4 /*yield*/,
|
116
|
+
return [4 /*yield*/, osmosis.init()];
|
128
117
|
case 3:
|
129
118
|
_a.sent();
|
130
|
-
return [4 /*yield*/,
|
119
|
+
return [4 /*yield*/, mayachain.init()];
|
131
120
|
case 4:
|
132
121
|
_a.sent();
|
133
|
-
return [4 /*yield*/,
|
122
|
+
return [4 /*yield*/, uniswap.init()];
|
134
123
|
case 5:
|
135
124
|
_a.sent();
|
136
|
-
return [4 /*yield*/,
|
125
|
+
return [4 /*yield*/, thorchain.init({})];
|
137
126
|
case 6:
|
138
127
|
_a.sent();
|
139
128
|
NetworksByIntegration['mayachain'] = mayachain.networkSupport();
|
140
129
|
NetworksByIntegration['changelly'] = changelly.networkSupport();
|
141
|
-
NetworksByIntegration['thorswap'] = thorswap.networkSupport();
|
142
130
|
NetworksByIntegration['rango'] = rango.networkSupport();
|
143
131
|
NetworksByIntegration['osmosis'] = osmosis.networkSupport();
|
144
132
|
NetworksByIntegration['uniswap'] = uniswap.networkSupport();
|
145
133
|
// NetworksByIntegration['across'] = across.networkSupport()
|
146
134
|
NetworksByIntegration['chainflip'] = chainflip.networkSupport();
|
135
|
+
NetworksByIntegration['thorchain'] = thorchain.networkSupport();
|
147
136
|
//get assets
|
148
137
|
AssetsByIntegration['mayachain'] = mayachain.assetSupport();
|
149
138
|
AssetsByIntegration['changelly'] = changelly.assetSupport();
|
150
|
-
AssetsByIntegration['thorswap'] = thorswap.assetSupport();
|
151
139
|
AssetsByIntegration['rango'] = rango.assetSupport();
|
152
140
|
AssetsByIntegration['osmosis'] = osmosis.assetSupport();
|
153
141
|
AssetsByIntegration['uniswap'] = uniswap.assetSupport();
|
142
|
+
AssetsByIntegration['thorchain'] = thorchain.assetSupport();
|
154
143
|
// AssetsByIntegration['across'] = across.assetSupport()
|
155
144
|
AssetsByIntegration['chainflip'] = chainflip.assetSupport();
|
156
145
|
return [2 /*return*/, true];
|
@@ -177,7 +166,7 @@ module.exports = {
|
|
177
166
|
};
|
178
167
|
function get_quote_from_integration(integration, quote) {
|
179
168
|
return __awaiter(this, void 0, void 0, function () {
|
180
|
-
var tag, _a,
|
169
|
+
var tag, _a, thorchainNameSellAsset, thorchainBuyAsset, payloadThorchain, quoteThorchain, rangoNameSellAsset, rangoNameBuyAsset, payloadRango, quoteRango, payloadOsmosis, quoteOsmosis, from, to, address, amount, quoteChangelly, payloadMayachain, quoteMayachain, payloadUniswap, quoteUniswap, payloadChainflip, quoteChainflip, e_1;
|
181
170
|
var _b;
|
182
171
|
return __generator(this, function (_c) {
|
183
172
|
switch (_c.label) {
|
@@ -188,7 +177,7 @@ function get_quote_from_integration(integration, quote) {
|
|
188
177
|
_c.trys.push([1, 18, , 19]);
|
189
178
|
_a = integration;
|
190
179
|
switch (_a) {
|
191
|
-
case "
|
180
|
+
case "thorchain": return [3 /*break*/, 2];
|
192
181
|
case "rango": return [3 /*break*/, 4];
|
193
182
|
case "osmosis": return [3 /*break*/, 6];
|
194
183
|
case "changelly": return [3 /*break*/, 8];
|
@@ -198,23 +187,30 @@ function get_quote_from_integration(integration, quote) {
|
|
198
187
|
}
|
199
188
|
return [3 /*break*/, 16];
|
200
189
|
case 2:
|
190
|
+
log.info(tag, "thorchain quote: ", quote);
|
201
191
|
if (!quote.senderAddress)
|
202
192
|
throw Error('invalid quote! missing senderAddress');
|
203
193
|
if (!quote.recipientAddress)
|
204
194
|
throw Error('invalid quote! missing recipientAddress');
|
205
|
-
|
206
|
-
|
207
|
-
|
208
|
-
|
195
|
+
thorchainNameSellAsset = caipToThorchain(quote.sellAsset.caip, quote.sellAsset.ticker, null);
|
196
|
+
thorchainBuyAsset = caipToThorchain(quote.buyAsset.caip, quote.buyAsset.ticker, null);
|
197
|
+
if (!thorchainNameSellAsset)
|
198
|
+
throw Error('invalid thorchainNameSellAsset');
|
199
|
+
if (!thorchainBuyAsset)
|
200
|
+
throw Error('invalid thorchainBuyAsset');
|
201
|
+
payloadThorchain = {
|
202
|
+
sellAsset: thorchainNameSellAsset,
|
203
|
+
sellAmount: '30',
|
204
|
+
buyAsset: thorchainBuyAsset,
|
209
205
|
senderAddress: quote.senderAddress,
|
210
206
|
recipientAddress: quote.recipientAddress,
|
211
|
-
slippage:
|
207
|
+
slippage: 3,
|
212
208
|
};
|
213
|
-
log.info(tag, "
|
214
|
-
return [4 /*yield*/,
|
209
|
+
log.info(tag, "payloadThorchain: ", payloadThorchain);
|
210
|
+
return [4 /*yield*/, thorchain.getQuote(payloadThorchain)];
|
215
211
|
case 3:
|
216
|
-
|
217
|
-
return [2 /*return*/,
|
212
|
+
quoteThorchain = _c.sent();
|
213
|
+
return [2 /*return*/, [quoteThorchain]];
|
218
214
|
case 4:
|
219
215
|
rangoNameSellAsset = caipToRango(quote.sellAsset.caip, quote.sellAsset.ticker, null);
|
220
216
|
rangoNameBuyAsset = caipToRango(quote.buyAsset.caip, quote.buyAsset.ticker, null);
|
@@ -373,14 +369,14 @@ var get_pro_rate_usd = function () {
|
|
373
369
|
};
|
374
370
|
function get_quote(quote) {
|
375
371
|
return __awaiter(this, void 0, void 0, function () {
|
376
|
-
var tag, sellChain, buyChain, integrations, quotes, supportsInput, supportsOutput, supportsBoth, _i, integrations_1, integration, supportedAssets, supportsInputOnly, supportsOutputOnly, supportsBothAssets, integrationQuotes, i, integrationQuote, sellAssetValueUsd, buyAssetValueUsd,
|
377
|
-
return __generator(this, function (
|
378
|
-
switch (
|
372
|
+
var tag, sellChain, buyChain, integrations, quotes, supportsInput, supportsOutput, supportsBoth, _i, integrations_1, integration, supportedAssets, supportsInputOnly, supportsOutputOnly, supportsBothAssets, integrationQuotes, i, integrationQuote, sellAssetValueUsd, buyAssetValueUsd, err_1;
|
373
|
+
return __generator(this, function (_a) {
|
374
|
+
switch (_a.label) {
|
379
375
|
case 0:
|
380
376
|
tag = " | get_quote | ";
|
381
|
-
|
377
|
+
_a.label = 1;
|
382
378
|
case 1:
|
383
|
-
|
379
|
+
_a.trys.push([1, 6, , 7]);
|
384
380
|
sellChain = caipToNetworkId(quote.sellAsset.caip);
|
385
381
|
buyChain = caipToNetworkId(quote.buyAsset.caip);
|
386
382
|
integrations = Object.keys(NetworksByIntegration);
|
@@ -395,9 +391,9 @@ function get_quote(quote) {
|
|
395
391
|
supportsOutput = [];
|
396
392
|
supportsBoth = [];
|
397
393
|
_i = 0, integrations_1 = integrations;
|
398
|
-
|
394
|
+
_a.label = 2;
|
399
395
|
case 2:
|
400
|
-
if (!(_i < integrations_1.length)) return [3 /*break*/,
|
396
|
+
if (!(_i < integrations_1.length)) return [3 /*break*/, 5];
|
401
397
|
integration = integrations_1[_i];
|
402
398
|
supportedAssets = AssetsByIntegration[integration];
|
403
399
|
log.info(tag, integration + " supportedAssets: ", supportedAssets);
|
@@ -416,110 +412,89 @@ function get_quote(quote) {
|
|
416
412
|
supportsBoth.push(integration);
|
417
413
|
log.info(tag, integration + " supports both assets: ", quote.sellAsset.caip, quote.buyAsset.caip);
|
418
414
|
}
|
419
|
-
if (!supportsBothAssets) return [3 /*break*/,
|
415
|
+
if (!supportsBothAssets) return [3 /*break*/, 4];
|
420
416
|
log.info(tag, "Found supported integration for both assets:", integration);
|
421
417
|
return [4 /*yield*/, get_quote_from_integration(integration, quote)];
|
422
418
|
case 3:
|
423
|
-
integrationQuotes =
|
424
|
-
if (
|
425
|
-
|
426
|
-
|
419
|
+
integrationQuotes = _a.sent();
|
420
|
+
if (integrationQuotes) {
|
421
|
+
for (i = 0; i < integrationQuotes.length; i++) {
|
422
|
+
integrationQuote = integrationQuotes[i];
|
423
|
+
integrationQuote.sellAsset = quote.sellAsset.caip;
|
424
|
+
integrationQuote.sellAmount = quote.sellAmount;
|
425
|
+
integrationQuote.buyAsset = quote.buyAsset.caip;
|
426
|
+
integrationQuote.buyAmount = integrationQuote.amountOut;
|
427
|
+
if (integrationQuote.amountOut > 0) {
|
428
|
+
log.info("integrationQuote.amountOut: ", integrationQuote.amountOut);
|
429
|
+
sellAssetValueUsd = parseFloat(quote.sellAmount) * quote.sellAsset.priceUsd;
|
430
|
+
buyAssetValueUsd = parseFloat(integrationQuote.amountOut) * quote.buyAsset.priceUsd;
|
431
|
+
//let proTokenEarned = sellAssetValueUsd * 0.1; // For every 1 USD, they earn 0.01 PRO token
|
432
|
+
//integrationQuote.proTokenEarned = proTokenEarned;
|
433
|
+
//integrationQuote.proTokenEarnedUsd = proTokenEarned * await get_pro_rate_usd(); //TODO get dynamic price
|
434
|
+
integrationQuote.sellAssetValueUsd = sellAssetValueUsd;
|
435
|
+
integrationQuote.buyAssetValueUsd = buyAssetValueUsd;
|
436
|
+
quotes.push({ integration: integration, quote: integrationQuote });
|
437
|
+
}
|
438
|
+
else {
|
439
|
+
log.error("Failed to get amountOut from integration: ", integration);
|
440
|
+
}
|
441
|
+
}
|
442
|
+
}
|
443
|
+
_a.label = 4;
|
427
444
|
case 4:
|
428
|
-
if (!(i < integrationQuotes.length)) return [3 /*break*/, 8];
|
429
|
-
integrationQuote = integrationQuotes[i];
|
430
|
-
integrationQuote.sellAsset = quote.sellAsset.caip;
|
431
|
-
integrationQuote.sellAmount = quote.sellAmount;
|
432
|
-
integrationQuote.buyAsset = quote.buyAsset.caip;
|
433
|
-
integrationQuote.buyAmount = integrationQuote.amountOut;
|
434
|
-
if (!(integrationQuote.amountOut > 0)) return [3 /*break*/, 6];
|
435
|
-
log.info("integrationQuote.amountOut: ", integrationQuote.amountOut);
|
436
|
-
sellAssetValueUsd = parseFloat(quote.sellAmount) * quote.sellAsset.priceUsd;
|
437
|
-
buyAssetValueUsd = parseFloat(integrationQuote.amountOut) * quote.buyAsset.priceUsd;
|
438
|
-
proTokenEarned = sellAssetValueUsd * 0.1;
|
439
|
-
integrationQuote.proTokenEarned = proTokenEarned;
|
440
|
-
_a = integrationQuote;
|
441
|
-
_b = proTokenEarned;
|
442
|
-
return [4 /*yield*/, get_pro_rate_usd()];
|
443
|
-
case 5:
|
444
|
-
_a.proTokenEarnedUsd = _b * (_f.sent()); //TODO get dynamic price
|
445
|
-
integrationQuote.sellAssetValueUsd = sellAssetValueUsd;
|
446
|
-
integrationQuote.buyAssetValueUsd = buyAssetValueUsd;
|
447
|
-
quotes.push({ integration: integration, quote: integrationQuote });
|
448
|
-
return [3 /*break*/, 7];
|
449
|
-
case 6:
|
450
|
-
log.error("Failed to get amountOut from integration: ", integration);
|
451
|
-
_f.label = 7;
|
452
|
-
case 7:
|
453
|
-
i++;
|
454
|
-
return [3 /*break*/, 4];
|
455
|
-
case 8:
|
456
445
|
_i++;
|
457
446
|
return [3 /*break*/, 2];
|
458
|
-
case
|
447
|
+
case 5:
|
459
448
|
log.info(tag, "Integrations supporting input asset: ", supportsInput);
|
460
449
|
log.info(tag, "Integrations supporting output asset: ", supportsOutput);
|
461
450
|
log.info(tag, "Integrations supporting both assets: ", supportsBoth);
|
462
451
|
//TODO if no quote found for both assets, find a pivot asset
|
463
452
|
log.info(tag, "quotes: ", quotes);
|
464
|
-
|
465
|
-
|
466
|
-
|
467
|
-
|
468
|
-
|
469
|
-
|
470
|
-
|
471
|
-
|
472
|
-
|
473
|
-
|
474
|
-
integration
|
475
|
-
|
476
|
-
|
477
|
-
|
478
|
-
if (
|
479
|
-
|
480
|
-
|
481
|
-
|
482
|
-
|
483
|
-
|
484
|
-
|
485
|
-
|
486
|
-
|
487
|
-
|
488
|
-
|
489
|
-
|
490
|
-
|
491
|
-
|
492
|
-
|
493
|
-
|
494
|
-
|
495
|
-
|
496
|
-
|
497
|
-
|
498
|
-
|
499
|
-
|
500
|
-
|
501
|
-
|
502
|
-
|
503
|
-
|
504
|
-
|
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();
|
453
|
+
//TODO FUTURE!
|
454
|
+
// if (quotes.length === 0) {
|
455
|
+
// log.info(tag, "No direct quotes found. Searching for pivot trades...");
|
456
|
+
//
|
457
|
+
// const PIVOT_ASSETS:any = [
|
458
|
+
// { caip: 'eip155:1/slip44:60', name: 'ETH' },
|
459
|
+
// { caip: 'bip122:000000000019d6689c085ae165831e93/slip44:0', name: 'BTC' }
|
460
|
+
// ];
|
461
|
+
//
|
462
|
+
// // Find pivot trades
|
463
|
+
// for (let integration of supportsInput) {
|
464
|
+
// for (let pivotAsset of PIVOT_ASSETS) {
|
465
|
+
// // @ts-ignore
|
466
|
+
// let pivotQuote = await get_quote_from_integration(integration, { ...quote, buyAsset: { caip: pivotAsset } });
|
467
|
+
// if (pivotQuote && pivotQuote.length > 0) {
|
468
|
+
// let pivotAmount = pivotQuote[0].amountOut;
|
469
|
+
// log.info(tag, "Pivot trade found: ", pivotAmount, " of ", pivotAsset);
|
470
|
+
//
|
471
|
+
// for (let outputIntegration of supportsOutput) {
|
472
|
+
// // @ts-ignore
|
473
|
+
// let finalQuote = await get_quote_from_integration(outputIntegration, { sellAsset: { caip: pivotAsset }, sellAmount: pivotAmount, buyAsset: quote.buyAsset });
|
474
|
+
// if (finalQuote && finalQuote.length > 0 && finalQuote[0].amountOut > 0) {
|
475
|
+
// let finalAmount = finalQuote[0].amountOut;
|
476
|
+
// quotes.push({
|
477
|
+
// integration: integration + " -> " + outputIntegration,
|
478
|
+
// quote: {
|
479
|
+
// sellAsset: quote.sellAsset.caip,
|
480
|
+
// sellAmount: quote.sellAmount,
|
481
|
+
// buyAsset: quote.buyAsset.caip,
|
482
|
+
// buyAmount: finalAmount,
|
483
|
+
// pivotAsset: pivotAsset,
|
484
|
+
// pivotAmount: pivotAmount
|
485
|
+
// }
|
486
|
+
// });
|
487
|
+
// }
|
488
|
+
// }
|
489
|
+
// }
|
490
|
+
// }
|
491
|
+
// }
|
492
|
+
// }
|
493
|
+
return [2 /*return*/, quotes];
|
494
|
+
case 6:
|
495
|
+
err_1 = _a.sent();
|
521
496
|
throw err_1;
|
522
|
-
case
|
497
|
+
case 7: return [2 /*return*/];
|
523
498
|
}
|
524
499
|
});
|
525
500
|
});
|
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.100",
|
4
4
|
"main": "./lib/index.js",
|
5
5
|
"types": "./lib/index.d.ts",
|
6
6
|
"scripts": {
|
@@ -20,15 +20,15 @@
|
|
20
20
|
"clean": "rm -rf coverage src/**/*.js src/**/*.map lib node_modules"
|
21
21
|
},
|
22
22
|
"dependencies": {
|
23
|
-
"@pioneer-platform/chainflip-client": "^0.0.
|
24
|
-
"@pioneer-platform/changelly-client": "^8.3.
|
25
|
-
"@pioneer-platform/mayachain-client": "^0.0.
|
26
|
-
"@pioneer-platform/osmosis-client": "^0.0.
|
27
|
-
"@pioneer-platform/pioneer-caip": "^9.2.
|
23
|
+
"@pioneer-platform/chainflip-client": "^0.0.10",
|
24
|
+
"@pioneer-platform/changelly-client": "^8.3.20",
|
25
|
+
"@pioneer-platform/mayachain-client": "^0.0.37",
|
26
|
+
"@pioneer-platform/osmosis-client": "^0.0.16",
|
27
|
+
"@pioneer-platform/pioneer-caip": "^9.2.34",
|
28
28
|
"@pioneer-platform/pro-token": "^0.0.3",
|
29
|
-
"@pioneer-platform/rango-client": "^8.3.
|
30
|
-
"@pioneer-platform/
|
31
|
-
"@pioneer-platform/uniswap-client": "^0.0.
|
29
|
+
"@pioneer-platform/rango-client": "^8.3.23",
|
30
|
+
"@pioneer-platform/thorchain-client": "^0.0.30",
|
31
|
+
"@pioneer-platform/uniswap-client": "^0.0.29",
|
32
32
|
"@uniswap/sdk-core": "^4.2.0",
|
33
33
|
"@uniswap/universal-router-sdk": "^1.9.0",
|
34
34
|
"dotenv": "^8.2.0",
|