@pioneer-platform/pioneer-router 8.6.0 → 8.8.0

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.
@@ -0,0 +1 @@
1
+ $ tsc -p .
package/CHANGELOG.md CHANGED
@@ -1,5 +1,45 @@
1
1
  # @pioneer-platform/pioneer-router
2
2
 
3
+ ## 8.8.0
4
+
5
+ ### Minor Changes
6
+
7
+ - Automated minor version bump for all packages
8
+
9
+ ### Patch Changes
10
+
11
+ - Updated dependencies
12
+ - @pioneer-platform/uniswap-client@0.4.0
13
+ - @pioneer-platform/thorchain-client@0.4.0
14
+ - @pioneer-platform/pro-token@0.4.0
15
+ - @pioneer-platform/rango-client@8.7.0
16
+ - @pioneer-platform/chainflip-client@0.4.0
17
+ - @pioneer-platform/osmosis-client@0.4.0
18
+ - @pioneer-platform/mayachain-client@0.4.0
19
+ - @pioneer-platform/changelly-client@8.7.0
20
+ - @pioneer-platform/loggerdog@8.7.0
21
+ - @pioneer-platform/pioneer-caip@9.6.0
22
+
23
+ ## 8.7.0
24
+
25
+ ### Minor Changes
26
+
27
+ - Automated minor version bump for all packages
28
+
29
+ ### Patch Changes
30
+
31
+ - Updated dependencies
32
+ - @pioneer-platform/uniswap-client@0.3.0
33
+ - @pioneer-platform/thorchain-client@0.3.0
34
+ - @pioneer-platform/pro-token@0.3.0
35
+ - @pioneer-platform/rango-client@8.6.0
36
+ - @pioneer-platform/chainflip-client@0.3.0
37
+ - @pioneer-platform/osmosis-client@0.3.0
38
+ - @pioneer-platform/mayachain-client@0.3.0
39
+ - @pioneer-platform/changelly-client@8.6.0
40
+ - @pioneer-platform/loggerdog@8.6.0
41
+ - @pioneer-platform/pioneer-caip@9.5.0
42
+
3
43
  ## 8.6.0
4
44
 
5
45
  ### Minor Changes
package/build.sh ADDED
@@ -0,0 +1,22 @@
1
+ #!/bin/bash
2
+ # Fast Bun build (replaces slow tsc)
3
+
4
+ OUTDIR="${1:-lib}"
5
+ ENTRY="${2:-src/index.ts}"
6
+
7
+ # Clean output
8
+ rm -rf "$OUTDIR"
9
+ mkdir -p "$OUTDIR"
10
+
11
+ # Build with Bun (10x faster than tsc)
12
+ bun build "$ENTRY" \
13
+ --outdir "$OUTDIR" \
14
+ --target node \
15
+ --format cjs \
16
+ --sourcemap \
17
+ --minify
18
+
19
+ # Generate TypeScript declarations
20
+ bunx tsc --emitDeclarationOnly --outDir "$OUTDIR" --project .
21
+
22
+ echo "✅ Built $OUTDIR"
package/lib/index.d.ts ADDED
@@ -0,0 +1,62 @@
1
+ declare const TAG = " | Pioneer-router | ";
2
+ declare const log: any;
3
+ declare const redis: any;
4
+ declare let proToken: any;
5
+ declare const caipToRango: any, caipToNetworkId: any, caipToThorchain: any;
6
+ declare let rango: any;
7
+ declare let changelly: any;
8
+ declare let osmosis: any;
9
+ declare let thorchain: any;
10
+ declare let mayachain: any;
11
+ declare let uniswap: any;
12
+ declare let chainflip: any;
13
+ declare let MEMOLESS_SUPPORT: any;
14
+ interface Swap {
15
+ memoless?: boolean;
16
+ sellAsset: {
17
+ context: string;
18
+ caip: string;
19
+ identifier: string;
20
+ address: string;
21
+ symbol: string;
22
+ chain: string;
23
+ ticker: string;
24
+ type: string;
25
+ balance: string;
26
+ priceUsd: number;
27
+ rank: number;
28
+ name: string;
29
+ source: string;
30
+ alias: number;
31
+ valueUsd: string;
32
+ };
33
+ sellAmount: string;
34
+ buyAsset: {
35
+ context: string;
36
+ caip: string;
37
+ identifier: string;
38
+ address: string;
39
+ symbol: string;
40
+ chain: string;
41
+ ticker: string;
42
+ type: string;
43
+ balance: string;
44
+ priceUsd: number;
45
+ rank: number;
46
+ name: string;
47
+ source: string;
48
+ alias: number;
49
+ valueUsd: string;
50
+ };
51
+ senderAddress: string;
52
+ recipientAddress: string;
53
+ slippage: string;
54
+ }
55
+ declare let NetworksByIntegration: any;
56
+ declare let AssetsByIntegration: any;
57
+ declare function get_quote_from_integration(integration: string, quote: Swap): Promise<any[] | null>;
58
+ declare let get_pro_rate_usd: () => Promise<any>;
59
+ declare function get_quote(quote: Swap): Promise<{
60
+ integration: string;
61
+ quote: any;
62
+ }[]>;
package/lib/index.js ADDED
@@ -0,0 +1,568 @@
1
+ "use strict";
2
+ /*
3
+
4
+ Pioneer API
5
+ A High Availability blockchain api
6
+
7
+ Goals:
8
+ v1 compatibility with watchtower with 0 change
9
+ Multi-asset support
10
+
11
+ V2 goals:
12
+ Treat Xpubs as passwords
13
+ encrypt long term data storage
14
+ maintain hash table to detect and cache payments
15
+
16
+
17
+
18
+ getTransactions:
19
+
20
+ Data: example
21
+
22
+ { success: true,
23
+ pagination: { page: 1, total_objects: 88, total_pages: 9 },
24
+ data:
25
+ [ { txid:
26
+ '',
27
+ status: 'confirmed',
28
+ type: 'send',
29
+ amount: -78602,
30
+ date: '2019-05-10T21:01:23Z',
31
+ confirmations: 1055,
32
+ network: 'BTC',
33
+ xpub:
34
+ '' },
35
+ }
36
+ ]
37
+ }
38
+ }
39
+
40
+ */
41
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
42
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
43
+ return new (P || (P = Promise))(function (resolve, reject) {
44
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
45
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
46
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
47
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
48
+ });
49
+ };
50
+ var __generator = (this && this.__generator) || function (thisArg, body) {
51
+ var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g = Object.create((typeof Iterator === "function" ? Iterator : Object).prototype);
52
+ return g.next = verb(0), g["throw"] = verb(1), g["return"] = verb(2), typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
53
+ function verb(n) { return function (v) { return step([n, v]); }; }
54
+ function step(op) {
55
+ if (f) throw new TypeError("Generator is already executing.");
56
+ while (g && (g = 0, op[0] && (_ = 0)), _) try {
57
+ if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
58
+ if (y = 0, t) op = [op[0] & 2, t.value];
59
+ switch (op[0]) {
60
+ case 0: case 1: t = op; break;
61
+ case 4: _.label++; return { value: op[1], done: false };
62
+ case 5: _.label++; y = op[1]; op = [0]; continue;
63
+ case 7: op = _.ops.pop(); _.trys.pop(); continue;
64
+ default:
65
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
66
+ if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
67
+ if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
68
+ if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
69
+ if (t[2]) _.ops.pop();
70
+ _.trys.pop(); continue;
71
+ }
72
+ op = body.call(thisArg, _);
73
+ } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
74
+ if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
75
+ }
76
+ };
77
+ var TAG = " | Pioneer-router | ";
78
+ var log = require('@pioneer-platform/loggerdog')();
79
+ var redis = require('@pioneer-platform/default-redis').redis;
80
+ var proToken = require("@pioneer-platform/pro-token");
81
+ var _a = require("@pioneer-platform/pioneer-caip"), caipToRango = _a.caipToRango, caipToNetworkId = _a.caipToNetworkId, caipToThorchain = _a.caipToThorchain;
82
+ //rango
83
+ var rango = require("@pioneer-platform/rango-client");
84
+ //changelly
85
+ var changelly = require("@pioneer-platform/changelly-client");
86
+ //osmosis
87
+ var osmosis = require("@pioneer-platform/osmosis-client");
88
+ //
89
+ var thorchain = require("@pioneer-platform/thorchain-client");
90
+ //osmosis
91
+ var mayachain = require("@pioneer-platform/mayachain-client");
92
+ //uniswap
93
+ var uniswap = require("@pioneer-platform/uniswap-client");
94
+ //
95
+ var chainflip = require("@pioneer-platform/chainflip-client");
96
+ //1inch/0x
97
+ // //bridge
98
+ // let across = require("@pioneer-platform/across-client")
99
+ var MEMOLESS_SUPPORT = {
100
+ "changelly": true,
101
+ "chainflip": true,
102
+ };
103
+ var NetworksByIntegration = {};
104
+ var AssetsByIntegration = {};
105
+ module.exports = {
106
+ init: function () {
107
+ return __awaiter(this, void 0, void 0, function () {
108
+ return __generator(this, function (_a) {
109
+ switch (_a.label) {
110
+ case 0: return [4 /*yield*/, rango.init()];
111
+ case 1:
112
+ _a.sent();
113
+ return [4 /*yield*/, changelly.init()];
114
+ case 2:
115
+ _a.sent();
116
+ return [4 /*yield*/, osmosis.init()];
117
+ case 3:
118
+ _a.sent();
119
+ return [4 /*yield*/, mayachain.init()];
120
+ case 4:
121
+ _a.sent();
122
+ return [4 /*yield*/, uniswap.init()];
123
+ case 5:
124
+ _a.sent();
125
+ return [4 /*yield*/, thorchain.init({})];
126
+ case 6:
127
+ _a.sent();
128
+ NetworksByIntegration['mayachain'] = mayachain.networkSupport();
129
+ NetworksByIntegration['changelly'] = changelly.networkSupport();
130
+ NetworksByIntegration['rango'] = rango.networkSupport();
131
+ NetworksByIntegration['osmosis'] = osmosis.networkSupport();
132
+ NetworksByIntegration['uniswap'] = uniswap.networkSupport();
133
+ // NetworksByIntegration['across'] = across.networkSupport()
134
+ NetworksByIntegration['chainflip'] = chainflip.networkSupport();
135
+ NetworksByIntegration['thorchain'] = thorchain.networkSupport();
136
+ //get assets
137
+ AssetsByIntegration['mayachain'] = mayachain.assetSupport();
138
+ AssetsByIntegration['changelly'] = changelly.assetSupport();
139
+ AssetsByIntegration['rango'] = rango.assetSupport();
140
+ AssetsByIntegration['osmosis'] = osmosis.assetSupport();
141
+ AssetsByIntegration['uniswap'] = uniswap.assetSupport();
142
+ AssetsByIntegration['thorchain'] = thorchain.assetSupport();
143
+ // AssetsByIntegration['across'] = across.assetSupport()
144
+ AssetsByIntegration['chainflip'] = chainflip.assetSupport();
145
+ return [2 /*return*/, true];
146
+ }
147
+ });
148
+ });
149
+ },
150
+ memoless: function () {
151
+ return MEMOLESS_SUPPORT;
152
+ },
153
+ assetSupport: function () {
154
+ return AssetsByIntegration;
155
+ },
156
+ routes: function () {
157
+ return NetworksByIntegration;
158
+ },
159
+ quote: function (quote) {
160
+ return __awaiter(this, void 0, void 0, function () {
161
+ return __generator(this, function (_a) {
162
+ return [2 /*return*/, get_quote(quote)];
163
+ });
164
+ });
165
+ }
166
+ };
167
+ function get_quote_from_integration(integration, quote) {
168
+ return __awaiter(this, void 0, void 0, function () {
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;
170
+ var _b;
171
+ return __generator(this, function (_c) {
172
+ switch (_c.label) {
173
+ case 0:
174
+ tag = TAG + " | get_quote_from_integration | ";
175
+ _c.label = 1;
176
+ case 1:
177
+ _c.trys.push([1, 18, , 19]);
178
+ _a = integration;
179
+ switch (_a) {
180
+ case "thorchain": return [3 /*break*/, 2];
181
+ case "rango": return [3 /*break*/, 4];
182
+ case "osmosis": return [3 /*break*/, 6];
183
+ case "changelly": return [3 /*break*/, 8];
184
+ case "mayachain": return [3 /*break*/, 10];
185
+ case "uniswap": return [3 /*break*/, 12];
186
+ case "chainflip": return [3 /*break*/, 14];
187
+ }
188
+ return [3 /*break*/, 16];
189
+ case 2:
190
+ log.info(tag, "thorchain quote: ", quote);
191
+ if (!quote.senderAddress)
192
+ throw Error('invalid quote! missing senderAddress');
193
+ if (!quote.recipientAddress)
194
+ throw Error('invalid quote! missing recipientAddress');
195
+ thorchainNameSellAsset = caipToThorchain(quote.sellAsset.caip, quote.sellAsset.ticker || quote.sellAsset.symbol, null);
196
+ thorchainBuyAsset = caipToThorchain(quote.buyAsset.caip, quote.buyAsset.ticker || quote.buyAsset.symbol, null);
197
+ log.info(tag, "thorchainBuyAsset: ", thorchainBuyAsset);
198
+ log.info(tag, "thorchainNameSellAsset: ", thorchainNameSellAsset);
199
+ if (thorchainBuyAsset === 'THOR.THOR')
200
+ thorchainBuyAsset = 'THOR.RUNE';
201
+ if (thorchainNameSellAsset === 'THOR.THOR')
202
+ thorchainNameSellAsset = 'THOR.RUNE';
203
+ if (!thorchainNameSellAsset)
204
+ throw Error('invalid thorchainNameSellAsset');
205
+ if (!thorchainBuyAsset)
206
+ throw Error('invalid thorchainBuyAsset');
207
+ payloadThorchain = {
208
+ sellAsset: thorchainNameSellAsset,
209
+ sellAmount: quote.sellAmount,
210
+ buyAsset: thorchainBuyAsset,
211
+ senderAddress: quote.senderAddress,
212
+ recipientAddress: quote.recipientAddress,
213
+ slippage: 3,
214
+ };
215
+ log.info(tag, "payloadThorchain: ", payloadThorchain);
216
+ return [4 /*yield*/, thorchain.getQuote(payloadThorchain)];
217
+ case 3:
218
+ quoteThorchain = _c.sent();
219
+ return [2 /*return*/, [quoteThorchain]];
220
+ case 4:
221
+ rangoNameSellAsset = caipToRango(quote.sellAsset.caip, quote.sellAsset.ticker, null);
222
+ rangoNameBuyAsset = caipToRango(quote.buyAsset.caip, quote.buyAsset.ticker, null);
223
+ payloadRango = {
224
+ "from": rangoNameSellAsset,
225
+ "to": rangoNameBuyAsset,
226
+ "amount": quote.sellAmount,
227
+ "connectedWallets": [
228
+ {
229
+ "blockchain": rangoNameSellAsset.blockchain,
230
+ "addresses": [
231
+ quote.sellAsset.address
232
+ ]
233
+ },
234
+ {
235
+ "blockchain": rangoNameBuyAsset.blockchain,
236
+ "addresses": [
237
+ quote.buyAsset.address
238
+ ]
239
+ }
240
+ ],
241
+ "selectedWallets": (_b = {},
242
+ _b[rangoNameBuyAsset.blockchain] = quote.buyAsset.address,
243
+ _b[rangoNameSellAsset.blockchain] = quote.sellAsset.address,
244
+ _b),
245
+ "checkPrerequisites": false,
246
+ "affiliateRef": null
247
+ };
248
+ log.info(tag, "payloadRango: ", JSON.stringify(payloadRango));
249
+ return [4 /*yield*/, rango.getQuote(payloadRango)];
250
+ case 5:
251
+ quoteRango = _c.sent();
252
+ return [2 /*return*/, [quoteRango]];
253
+ case 6:
254
+ payloadOsmosis = {
255
+ sellAsset: quote.sellAsset.caip,
256
+ buyAsset: quote.buyAsset.caip,
257
+ sellAmount: quote.sellAmount,
258
+ senderAddress: quote.senderAddress,
259
+ recipientAddress: quote.recipientAddress,
260
+ slippage: quote.slippage
261
+ };
262
+ return [4 /*yield*/, osmosis.getQuote(payloadOsmosis)];
263
+ case 7:
264
+ quoteOsmosis = _c.sent();
265
+ return [2 /*return*/, [quoteOsmosis]];
266
+ case 8:
267
+ from = quote.sellAsset.ticker || quote.sellAsset.symbol;
268
+ to = quote.buyAsset.ticker || quote.buyAsset.symbol;
269
+ address = quote.buyAsset.address;
270
+ amount = quote.sellAmount;
271
+ log.info({
272
+ from: from,
273
+ to: to,
274
+ address: address,
275
+ amount: amount
276
+ });
277
+ return [4 /*yield*/, changelly.getQuote(from, to, address, amount)];
278
+ case 9:
279
+ quoteChangelly = _c.sent();
280
+ return [2 /*return*/, [quoteChangelly]];
281
+ case 10:
282
+ payloadMayachain = {
283
+ sellAsset: quote.sellAsset.identifier,
284
+ buyAsset: quote.buyAsset.identifier,
285
+ sellAmount: quote.sellAmount,
286
+ senderAddress: quote.senderAddress,
287
+ recipientAddress: quote.recipientAddress,
288
+ slippage: quote.slippage
289
+ };
290
+ log.info(tag, "payloadMayachain: ", payloadMayachain);
291
+ return [4 /*yield*/, mayachain.getQuote(payloadMayachain)];
292
+ case 11:
293
+ quoteMayachain = _c.sent();
294
+ return [2 /*return*/, [quoteMayachain]];
295
+ case 12:
296
+ payloadUniswap = {
297
+ sellAsset: quote.sellAsset.caip,
298
+ buyAsset: quote.buyAsset.caip,
299
+ sellAmount: quote.sellAmount,
300
+ senderAddress: quote.senderAddress,
301
+ recipientAddress: quote.recipientAddress,
302
+ slippage: quote.slippage
303
+ };
304
+ log.info(tag, "payloadUniswap: ", payloadUniswap);
305
+ return [4 /*yield*/, uniswap.getQuote(payloadUniswap)];
306
+ case 13:
307
+ quoteUniswap = _c.sent();
308
+ log.info(tag, "quoteUniswap: ", quoteUniswap);
309
+ return [2 /*return*/, [quoteUniswap]];
310
+ case 14:
311
+ payloadChainflip = {
312
+ sellAsset: quote.sellAsset.caip,
313
+ buyAsset: quote.buyAsset.caip,
314
+ sellAmount: quote.sellAmount,
315
+ recipientAddress: quote.recipientAddress,
316
+ slippage: quote.slippage
317
+ };
318
+ log.info(tag, "payloadChainflip: ", payloadChainflip);
319
+ return [4 /*yield*/, chainflip.getQuote(payloadChainflip)];
320
+ case 15:
321
+ quoteChainflip = _c.sent();
322
+ return [2 /*return*/, [quoteChainflip]
323
+ // case "across":
324
+ // let payloadAcross = {
325
+ // sellAsset: quote.sellAsset.caip,
326
+ // buyAsset: quote.buyAsset.caip,
327
+ // sellAmount: quote.sellAmount,
328
+ // senderAddress: quote.senderAddress,
329
+ // recipientAddress: quote.recipientAddress,
330
+ // slippage: quote.slippage
331
+ // }
332
+ // log.info(tag,"payloadAcross: ",payloadAcross)
333
+ // let quotedAcross = await accross.getQuote(payloadAcross)
334
+ // return [quotedAcross]
335
+ ];
336
+ case 16: throw new Error("Intergration not found");
337
+ case 17: return [3 /*break*/, 19];
338
+ case 18:
339
+ e_1 = _c.sent();
340
+ log.error(tag, "Error: ", e_1);
341
+ return [2 /*return*/, null];
342
+ case 19: return [2 /*return*/];
343
+ }
344
+ });
345
+ });
346
+ }
347
+ var get_pro_rate_usd = function () {
348
+ return __awaiter(this, void 0, void 0, function () {
349
+ var cacheValue, proRateUsd, e_2;
350
+ return __generator(this, function (_a) {
351
+ switch (_a.label) {
352
+ case 0:
353
+ _a.trys.push([0, 6, , 7]);
354
+ return [4 /*yield*/, redis.get('proRateUsd')];
355
+ case 1:
356
+ cacheValue = _a.sent();
357
+ if (!cacheValue) return [3 /*break*/, 2];
358
+ return [2 /*return*/, parseFloat(cacheValue)]; // Convert string to float if necessary
359
+ case 2: return [4 /*yield*/, proToken.getRateProUsd()];
360
+ case 3:
361
+ proRateUsd = _a.sent();
362
+ return [4 /*yield*/, redis.setex('proRateUsd', 300, proRateUsd.toString())];
363
+ case 4:
364
+ _a.sent(); // Expiry time in seconds, value as string
365
+ return [2 /*return*/, proRateUsd];
366
+ case 5: return [3 /*break*/, 7];
367
+ case 6:
368
+ e_2 = _a.sent();
369
+ log.error(e_2);
370
+ return [2 /*return*/, 1];
371
+ case 7: return [2 /*return*/];
372
+ }
373
+ });
374
+ });
375
+ };
376
+ function get_quote(quote) {
377
+ return __awaiter(this, void 0, void 0, function () {
378
+ var tag, sellChain, buyChain, integrations, quotes, supportsInput, supportsOutput, supportsBoth, _i, integrations_1, integration, supportedAssets, supportsInputOnly, supportsOutputOnly, supportsBothAssets, integrationQuotes, i, integrationQuote, sellAssetValueUsd, buyAssetValueUsd, err_1;
379
+ return __generator(this, function (_a) {
380
+ switch (_a.label) {
381
+ case 0:
382
+ tag = " | get_quote | ";
383
+ _a.label = 1;
384
+ case 1:
385
+ _a.trys.push([1, 6, , 7]);
386
+ sellChain = caipToNetworkId(quote.sellAsset.caip);
387
+ buyChain = caipToNetworkId(quote.buyAsset.caip);
388
+ integrations = Object.keys(NetworksByIntegration);
389
+ quotes = [];
390
+ log.info("sellChain: ", sellChain);
391
+ log.info("buyChain: ", buyChain);
392
+ // Filter integrations for memoless support if applicable
393
+ if (quote.memoless) {
394
+ integrations = integrations.filter(function (integration) { return MEMOLESS_SUPPORT[integration]; });
395
+ }
396
+ supportsInput = [];
397
+ supportsOutput = [];
398
+ supportsBoth = [];
399
+ _i = 0, integrations_1 = integrations;
400
+ _a.label = 2;
401
+ case 2:
402
+ if (!(_i < integrations_1.length)) return [3 /*break*/, 5];
403
+ integration = integrations_1[_i];
404
+ supportedAssets = AssetsByIntegration[integration];
405
+ log.info(tag, integration + " supportedAssets: ", supportedAssets);
406
+ supportsInputOnly = supportedAssets.includes(quote.sellAsset.caip);
407
+ supportsOutputOnly = !supportedAssets.includes(quote.sellAsset.caip) && supportedAssets.includes(quote.buyAsset.caip);
408
+ supportsBothAssets = supportedAssets.includes(quote.sellAsset.caip) && supportedAssets.includes(quote.buyAsset.caip);
409
+ if (supportsInputOnly) {
410
+ supportsInput.push(integration);
411
+ log.info(tag, integration + " supports input asset: ", quote.sellAsset.caip);
412
+ }
413
+ if (supportsOutputOnly) {
414
+ supportsOutput.push(integration);
415
+ log.info(tag, integration + " supports output asset: ", quote.buyAsset.caip);
416
+ }
417
+ if (supportsBothAssets) {
418
+ supportsBoth.push(integration);
419
+ log.info(tag, integration + " supports both assets: ", quote.sellAsset.caip, quote.buyAsset.caip);
420
+ }
421
+ if (!supportsBothAssets) return [3 /*break*/, 4];
422
+ log.info(tag, "Found supported integration for both assets:", integration);
423
+ return [4 /*yield*/, get_quote_from_integration(integration, quote)];
424
+ case 3:
425
+ integrationQuotes = _a.sent();
426
+ if (integrationQuotes) {
427
+ for (i = 0; i < integrationQuotes.length; i++) {
428
+ integrationQuote = integrationQuotes[i];
429
+ integrationQuote.sellAsset = quote.sellAsset.caip;
430
+ integrationQuote.sellAmount = quote.sellAmount;
431
+ integrationQuote.buyAsset = quote.buyAsset.caip;
432
+ integrationQuote.buyAmount = integrationQuote.amountOut;
433
+ if (integrationQuote.amountOut > 0) {
434
+ log.info("integrationQuote.amountOut: ", integrationQuote.amountOut);
435
+ sellAssetValueUsd = parseFloat(quote.sellAmount) * quote.sellAsset.priceUsd;
436
+ buyAssetValueUsd = parseFloat(integrationQuote.amountOut) * quote.buyAsset.priceUsd;
437
+ //let proTokenEarned = sellAssetValueUsd * 0.1; // For every 1 USD, they earn 0.01 PRO token
438
+ //integrationQuote.proTokenEarned = proTokenEarned;
439
+ //integrationQuote.proTokenEarnedUsd = proTokenEarned * await get_pro_rate_usd(); //TODO get dynamic price
440
+ integrationQuote.sellAssetValueUsd = sellAssetValueUsd;
441
+ integrationQuote.buyAssetValueUsd = buyAssetValueUsd;
442
+ quotes.push({ integration: integration, quote: integrationQuote });
443
+ }
444
+ else {
445
+ log.error("Failed to get amountOut from integration: ", integration);
446
+ }
447
+ }
448
+ }
449
+ _a.label = 4;
450
+ case 4:
451
+ _i++;
452
+ return [3 /*break*/, 2];
453
+ case 5:
454
+ log.info(tag, "Integrations supporting input asset: ", supportsInput);
455
+ log.info(tag, "Integrations supporting output asset: ", supportsOutput);
456
+ log.info(tag, "Integrations supporting both assets: ", supportsBoth);
457
+ //TODO if no quote found for both assets, find a pivot asset
458
+ log.info(tag, "quotes: ", quotes);
459
+ //TODO FUTURE!
460
+ // if (quotes.length === 0) {
461
+ // log.info(tag, "No direct quotes found. Searching for pivot trades...");
462
+ //
463
+ // const PIVOT_ASSETS:any = [
464
+ // { caip: 'eip155:1/slip44:60', name: 'ETH' },
465
+ // { caip: 'bip122:000000000019d6689c085ae165831e93/slip44:0', name: 'BTC' }
466
+ // ];
467
+ //
468
+ // // Find pivot trades
469
+ // for (let integration of supportsInput) {
470
+ // for (let pivotAsset of PIVOT_ASSETS) {
471
+ // // @ts-ignore
472
+ // let pivotQuote = await get_quote_from_integration(integration, { ...quote, buyAsset: { caip: pivotAsset } });
473
+ // if (pivotQuote && pivotQuote.length > 0) {
474
+ // let pivotAmount = pivotQuote[0].amountOut;
475
+ // log.info(tag, "Pivot trade found: ", pivotAmount, " of ", pivotAsset);
476
+ //
477
+ // for (let outputIntegration of supportsOutput) {
478
+ // // @ts-ignore
479
+ // let finalQuote = await get_quote_from_integration(outputIntegration, { sellAsset: { caip: pivotAsset }, sellAmount: pivotAmount, buyAsset: quote.buyAsset });
480
+ // if (finalQuote && finalQuote.length > 0 && finalQuote[0].amountOut > 0) {
481
+ // let finalAmount = finalQuote[0].amountOut;
482
+ // quotes.push({
483
+ // integration: integration + " -> " + outputIntegration,
484
+ // quote: {
485
+ // sellAsset: quote.sellAsset.caip,
486
+ // sellAmount: quote.sellAmount,
487
+ // buyAsset: quote.buyAsset.caip,
488
+ // buyAmount: finalAmount,
489
+ // pivotAsset: pivotAsset,
490
+ // pivotAmount: pivotAmount
491
+ // }
492
+ // });
493
+ // }
494
+ // }
495
+ // }
496
+ // }
497
+ // }
498
+ // }
499
+ return [2 /*return*/, quotes];
500
+ case 6:
501
+ err_1 = _a.sent();
502
+ throw err_1;
503
+ case 7: return [2 /*return*/];
504
+ }
505
+ });
506
+ });
507
+ }
508
+ // async function get_quote(quote:Swap) {
509
+ // let tag = " | get_quote | "
510
+ // try {
511
+ //
512
+ // let sellChain = caipToNetworkId(quote.sellAsset.caip);
513
+ // let buyChain = caipToNetworkId(quote.buyAsset.caip);
514
+ // let integrations = Object.keys(NetworksByIntegration);
515
+ // let quotes = [];
516
+ // log.info("sellChain: ",sellChain)
517
+ // log.info("buyChain: ",buyChain)
518
+ //
519
+ // //if memoless filter
520
+ // if (quote.memoless) {
521
+ // integrations = integrations.filter(integration => MEMOLESS_SUPPORT[integration]);
522
+ // }
523
+ //
524
+ // for (let integration of integrations) {
525
+ // let supportedAssets = AssetsByIntegration[integration];
526
+ // log.info(tag,integration+" supportedAssets: ",supportedAssets)
527
+ // if (supportedAssets.includes(quote.sellAsset.caip) && supportedAssets.includes(quote.buyAsset.caip)) {
528
+ // console.log(TAG, "Found supported integration for both assets:", integration);
529
+ // let integrationQuotes = await get_quote_from_integration(integration, quote);
530
+ // if(integrationQuotes) {
531
+ // for(let i = 0; i < integrationQuotes.length; i++){
532
+ // let integrationQuote = integrationQuotes[i]
533
+ // integrationQuote.sellAsset = quote.sellAsset.caip
534
+ // integrationQuote.sellAmount = quote.sellAmount
535
+ // integrationQuote.buyAsset = quote.buyAsset.caip
536
+ // integrationQuote.buyAmount = integrationQuote.amountOut
537
+ // if(integrationQuote.amountOut > 0){
538
+ // log.info("integrationQuote.amountOut: ",integrationQuote.amountOut)
539
+ // let sellAssetValueUsd = parseFloat(quote.sellAmount) * quote.sellAsset.priceUsd;
540
+ // let buyAssetValueUsd = parseFloat(integrationQuote.amountOut) * quote.buyAsset.priceUsd;
541
+ // let proTokenEarned = sellAssetValueUsd * 0.1; // For every 1 USD, they earn 0.01 PRO token
542
+ // integrationQuote.proTokenEarned = proTokenEarned;
543
+ // integrationQuote.proTokenEarnedUsd = proTokenEarned * await get_pro_rate_usd() //TODO get dynamic price
544
+ // integrationQuote.sellAssetValueUsd = sellAssetValueUsd;
545
+ // integrationQuote.buyAssetValueUsd = buyAssetValueUsd;
546
+ // quotes.push({ integration, quote: integrationQuote });
547
+ // } else {
548
+ // log.error("Failed to get amountOut from integration: ",integration)
549
+ // }
550
+ // }
551
+ // }
552
+ // }
553
+ // }
554
+ //
555
+ //
556
+ // //return applicable intergrations
557
+ //
558
+ // //for each intergration get quote
559
+ //
560
+ // //set best quote
561
+ //
562
+ // //return quotes
563
+ // return quotes;
564
+ // } catch (err) {
565
+ // throw err;
566
+ // }
567
+ // }
568
+ //
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pioneer-platform/pioneer-router",
3
- "version": "8.6.0",
3
+ "version": "8.8.0",
4
4
  "main": "./lib/index.js",
5
5
  "types": "./lib/index.d.ts",
6
6
  "scripts": {
@@ -21,16 +21,16 @@
21
21
  },
22
22
  "dependencies": {
23
23
  "@coinmasters/types": "^4.10.2",
24
- "@pioneer-platform/chainflip-client": "^0.2.0",
25
- "@pioneer-platform/changelly-client": "^8.5.0",
26
- "@pioneer-platform/loggerdog": "^8.5.0",
27
- "@pioneer-platform/mayachain-client": "^0.2.0",
28
- "@pioneer-platform/osmosis-client": "^0.2.0",
29
- "@pioneer-platform/pioneer-caip": "^9.4.0",
30
- "@pioneer-platform/pro-token": "^0.2.0",
31
- "@pioneer-platform/rango-client": "^8.5.0",
32
- "@pioneer-platform/thorchain-client": "^0.2.0",
33
- "@pioneer-platform/uniswap-client": "^0.2.0",
24
+ "@pioneer-platform/chainflip-client": "^0.4.0",
25
+ "@pioneer-platform/changelly-client": "^8.7.0",
26
+ "@pioneer-platform/loggerdog": "^8.7.0",
27
+ "@pioneer-platform/mayachain-client": "^0.4.0",
28
+ "@pioneer-platform/osmosis-client": "^0.4.0",
29
+ "@pioneer-platform/pioneer-caip": "^9.6.0",
30
+ "@pioneer-platform/pro-token": "^0.4.0",
31
+ "@pioneer-platform/rango-client": "^8.7.0",
32
+ "@pioneer-platform/thorchain-client": "^0.4.0",
33
+ "@pioneer-platform/uniswap-client": "^0.4.0",
34
34
  "@uniswap/sdk-core": "^4.2.0",
35
35
  "@uniswap/universal-router-sdk": "^1.9.0",
36
36
  "dotenv": "^8.2.0",