@pioneer-platform/pioneer-sdk 4.20.9 → 4.20.11
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/dist/index.cjs +70 -18
- package/dist/index.es.js +70 -18
- package/dist/index.js +70 -18
- package/package.json +6 -6
- package/src/charts/evm.ts +91 -10
- package/src/charts/stable-coins-config.ts +162 -0
package/dist/index.cjs
CHANGED
|
@@ -40,7 +40,7 @@ var __export = (target, all) => {
|
|
|
40
40
|
});
|
|
41
41
|
};
|
|
42
42
|
|
|
43
|
-
//
|
|
43
|
+
// ../pioneer-client/lib/index.js
|
|
44
44
|
var require_lib = __commonJS((exports2) => {
|
|
45
45
|
var __assign = exports2 && exports2.__assign || function() {
|
|
46
46
|
__assign = Object.assign || function(t) {
|
|
@@ -314,9 +314,9 @@ var require_lib = __commonJS((exports2) => {
|
|
|
314
314
|
spec: specData_1,
|
|
315
315
|
execute: function(request) {
|
|
316
316
|
return __awaiter(_this, undefined, undefined, function() {
|
|
317
|
-
var operationId, parameters, requestBody, targetPath, targetMethod, path, method, baseUrl, url, httpReq;
|
|
318
|
-
return __generator(this, function(
|
|
319
|
-
switch (
|
|
317
|
+
var operationId, parameters, requestBody, targetPath, targetMethod, path, method, baseUrl, finalPath, _i, _a2, _b2, key, value, placeholder, url, httpReq;
|
|
318
|
+
return __generator(this, function(_c) {
|
|
319
|
+
switch (_c.label) {
|
|
320
320
|
case 0:
|
|
321
321
|
operationId = request.operationId, parameters = request.parameters, requestBody = request.requestBody;
|
|
322
322
|
targetPath = "";
|
|
@@ -339,7 +339,17 @@ var require_lib = __commonJS((exports2) => {
|
|
|
339
339
|
if (specData_1.servers && specData_1.servers.length > 0) {
|
|
340
340
|
baseUrl = specData_1.servers[0].url;
|
|
341
341
|
}
|
|
342
|
-
|
|
342
|
+
finalPath = targetPath;
|
|
343
|
+
if (parameters) {
|
|
344
|
+
for (_i = 0, _a2 = Object.entries(parameters);_i < _a2.length; _i++) {
|
|
345
|
+
_b2 = _a2[_i], key = _b2[0], value = _b2[1];
|
|
346
|
+
placeholder = "{".concat(key, "}");
|
|
347
|
+
if (finalPath.includes(placeholder)) {
|
|
348
|
+
finalPath = finalPath.replace(placeholder, encodeURIComponent(String(value)));
|
|
349
|
+
}
|
|
350
|
+
}
|
|
351
|
+
}
|
|
352
|
+
url = "".concat(baseUrl).concat(finalPath);
|
|
343
353
|
httpReq = {
|
|
344
354
|
method: targetMethod.toUpperCase(),
|
|
345
355
|
url,
|
|
@@ -351,7 +361,7 @@ var require_lib = __commonJS((exports2) => {
|
|
|
351
361
|
};
|
|
352
362
|
return [4, customHttpClient(httpReq)];
|
|
353
363
|
case 1:
|
|
354
|
-
return [2,
|
|
364
|
+
return [2, _c.sent()];
|
|
355
365
|
}
|
|
356
366
|
});
|
|
357
367
|
});
|
|
@@ -432,7 +442,7 @@ var require_lib = __commonJS((exports2) => {
|
|
|
432
442
|
exports2.default = Pioneer;
|
|
433
443
|
});
|
|
434
444
|
|
|
435
|
-
// node_modules/coinselect/utils.js
|
|
445
|
+
// ../../../node_modules/coinselect/utils.js
|
|
436
446
|
var require_utils = __commonJS((exports2, module2) => {
|
|
437
447
|
var TX_EMPTY_SIZE = 4 + 1 + 1 + 4;
|
|
438
448
|
var TX_INPUT_BASE = 32 + 4 + 1 + 4;
|
|
@@ -505,7 +515,7 @@ var require_utils = __commonJS((exports2, module2) => {
|
|
|
505
515
|
};
|
|
506
516
|
});
|
|
507
517
|
|
|
508
|
-
// node_modules/coinselect/accumulative.js
|
|
518
|
+
// ../../../node_modules/coinselect/accumulative.js
|
|
509
519
|
var require_accumulative = __commonJS((exports2, module2) => {
|
|
510
520
|
var utils = require_utils();
|
|
511
521
|
module2.exports = function accumulative(utxos, outputs, feeRate) {
|
|
@@ -537,7 +547,7 @@ var require_accumulative = __commonJS((exports2, module2) => {
|
|
|
537
547
|
};
|
|
538
548
|
});
|
|
539
549
|
|
|
540
|
-
// node_modules/coinselect/blackjack.js
|
|
550
|
+
// ../../../node_modules/coinselect/blackjack.js
|
|
541
551
|
var require_blackjack = __commonJS((exports2, module2) => {
|
|
542
552
|
var utils = require_utils();
|
|
543
553
|
module2.exports = function blackjack(utxos, outputs, feeRate) {
|
|
@@ -566,7 +576,7 @@ var require_blackjack = __commonJS((exports2, module2) => {
|
|
|
566
576
|
};
|
|
567
577
|
});
|
|
568
578
|
|
|
569
|
-
// node_modules/coinselect/index.js
|
|
579
|
+
// ../../../node_modules/coinselect/index.js
|
|
570
580
|
var require_coinselect = __commonJS((exports2, module2) => {
|
|
571
581
|
var accumulative = require_accumulative();
|
|
572
582
|
var blackjack = require_blackjack();
|
|
@@ -585,7 +595,7 @@ var require_coinselect = __commonJS((exports2, module2) => {
|
|
|
585
595
|
};
|
|
586
596
|
});
|
|
587
597
|
|
|
588
|
-
// node_modules/coinselect/split.js
|
|
598
|
+
// ../../../node_modules/coinselect/split.js
|
|
589
599
|
var require_split = __commonJS((exports2, module2) => {
|
|
590
600
|
var utils = require_utils();
|
|
591
601
|
module2.exports = function split(utxos, outputs, feeRate) {
|
|
@@ -669,19 +679,32 @@ async function getEvmCharts(params) {
|
|
|
669
679
|
return balances;
|
|
670
680
|
}
|
|
671
681
|
console.log(tag, "Using EVM address for portfolio:", primaryAddress);
|
|
682
|
+
await fetchStableCoins(pioneer, primaryAddress, blockchains, balances, context);
|
|
672
683
|
try {
|
|
673
|
-
let portfolio = await pioneer.GetPortfolio({
|
|
674
|
-
|
|
684
|
+
let portfolio = await pioneer.GetPortfolio({
|
|
685
|
+
networkId: "eip155:1",
|
|
686
|
+
address: primaryAddress
|
|
687
|
+
});
|
|
688
|
+
portfolio = portfolio.data?.data || portfolio.data;
|
|
675
689
|
if (!portfolio || !portfolio.balances) {
|
|
676
690
|
console.error(tag, "No portfolio.balances found:", portfolio);
|
|
677
691
|
return balances;
|
|
678
692
|
}
|
|
693
|
+
console.log(tag, `Portfolio returned ${portfolio.balances.length} balances`);
|
|
694
|
+
let processedCount = 0;
|
|
695
|
+
let skippedCount = 0;
|
|
679
696
|
for (const balance of portfolio.balances) {
|
|
680
697
|
const processedBalance = processPortfolioBalance(balance, primaryAddress, context, blockchains);
|
|
681
|
-
if (processedBalance
|
|
682
|
-
balances.
|
|
698
|
+
if (processedBalance) {
|
|
699
|
+
if (!checkDuplicateBalance(balances, processedBalance.caip, processedBalance.pubkey)) {
|
|
700
|
+
balances.push(processedBalance);
|
|
701
|
+
processedCount++;
|
|
702
|
+
}
|
|
703
|
+
} else {
|
|
704
|
+
skippedCount++;
|
|
683
705
|
}
|
|
684
706
|
}
|
|
707
|
+
console.log(tag, `Processed ${processedCount} balances, skipped ${skippedCount}`);
|
|
685
708
|
if (portfolio.tokens && portfolio.tokens.length > 0) {
|
|
686
709
|
console.log(tag, "Processing portfolio.tokens:", portfolio.tokens.length);
|
|
687
710
|
for (const token of portfolio.tokens) {
|
|
@@ -702,7 +725,8 @@ function processPortfolioBalance(balance, primaryAddress, context, blockchains)
|
|
|
702
725
|
return null;
|
|
703
726
|
}
|
|
704
727
|
const networkId = balance.caip.split("/")[0];
|
|
705
|
-
|
|
728
|
+
const isEip155 = networkId.startsWith("eip155:");
|
|
729
|
+
if (!isEip155 && !blockchains.includes(networkId)) {
|
|
706
730
|
return null;
|
|
707
731
|
}
|
|
708
732
|
const assetInfo = hydrateAssetData(balance.caip);
|
|
@@ -759,7 +783,8 @@ function processPortfolioToken(token, primaryAddress, context, blockchains) {
|
|
|
759
783
|
} else if (token.networkId && token.networkId.includes("/")) {
|
|
760
784
|
extractedNetworkId = token.networkId.split("/")[0];
|
|
761
785
|
}
|
|
762
|
-
|
|
786
|
+
const isEip155 = extractedNetworkId.startsWith("eip155:");
|
|
787
|
+
if (!isEip155 && !blockchains.includes(extractedNetworkId)) {
|
|
763
788
|
return null;
|
|
764
789
|
}
|
|
765
790
|
const tokenAssetInfo = hydrateAssetData(token.assetCaip);
|
|
@@ -787,6 +812,33 @@ function processPortfolioToken(token, primaryAddress, context, blockchains) {
|
|
|
787
812
|
};
|
|
788
813
|
return chartBalance;
|
|
789
814
|
}
|
|
815
|
+
async function fetchStableCoins(pioneer, primaryAddress, blockchains, balances, context) {
|
|
816
|
+
console.log(tag, "Fetching stable coins for redundancy...");
|
|
817
|
+
const supportedNetworks = ["eip155:1", "eip155:137", "eip155:8453", "eip155:56"];
|
|
818
|
+
const networksToCheck = blockchains.filter((net) => supportedNetworks.includes(net));
|
|
819
|
+
if (networksToCheck.length === 0) {
|
|
820
|
+
console.log(tag, "No supported networks for stable coins");
|
|
821
|
+
return;
|
|
822
|
+
}
|
|
823
|
+
console.log(tag, `Checking stable coins on ${networksToCheck.length} networks`);
|
|
824
|
+
for (const networkId of networksToCheck) {
|
|
825
|
+
try {
|
|
826
|
+
const response = await pioneer.GetStableCoins({ networkId, address: primaryAddress });
|
|
827
|
+
const stableCoins = response?.data?.tokens || [];
|
|
828
|
+
console.log(tag, `Found ${stableCoins.length} stable coins on ${networkId}`);
|
|
829
|
+
for (const token of stableCoins) {
|
|
830
|
+
const chartBalance = processPortfolioToken(token, primaryAddress, context, blockchains);
|
|
831
|
+
if (chartBalance && !checkDuplicateBalance(balances, chartBalance.caip, chartBalance.pubkey)) {
|
|
832
|
+
balances.push(chartBalance);
|
|
833
|
+
console.log(tag, `Added stable coin: ${chartBalance.symbol} = ${chartBalance.balance}`);
|
|
834
|
+
}
|
|
835
|
+
}
|
|
836
|
+
} catch (error) {
|
|
837
|
+
console.error(tag, `Error fetching stable coins for ${networkId}:`, error.message);
|
|
838
|
+
}
|
|
839
|
+
}
|
|
840
|
+
console.log(tag, `Stable coin redundancy complete. Total balances: ${balances.length}`);
|
|
841
|
+
}
|
|
790
842
|
|
|
791
843
|
// src/charts/maya.ts
|
|
792
844
|
var tag2 = "| charts-maya |";
|
|
@@ -982,7 +1034,7 @@ var getCharts = async (blockchains, pioneer, pubkeys, context) => {
|
|
|
982
1034
|
}
|
|
983
1035
|
};
|
|
984
1036
|
|
|
985
|
-
// node_modules/@coinmasters/types/dist/index.es.js
|
|
1037
|
+
// ../../../node_modules/@coinmasters/types/dist/index.es.js
|
|
986
1038
|
var n = /* @__PURE__ */ ((e) => (e.INVALID_INPUT_PARAMETERS = "1000", e.UNKNOWN_PROVIDERS = "1001", e.CANNOT_FIND_INBOUND_ADDRESS = "1002", e.NO_INBOUND_ADDRESSES = "1003", e.CHAIN_HALTED_OR_UNSUPPORTED = "1004", e.MISSING_INPUT_PARAMETER = "1005", e.INVALID_TYPE_GENERIC = "1100", e.INVALID_NUMBER_STRING = "1101", e.INVALID_NUMBER = "1102", e.INVALID_BOOLEAN = "1103", e.INVALID_OBJECT = "1104", e.INVALID_ARRAY = "1105", e.SELL_AMOUNT_MUST_BE_POSITIVE_INTEGER = "2000", e.SELL_BUY_ASSETS_ARE_THE_SAME = "2001", e.MISSING_SOURCE_ADDRESS_FOR_SYNTH = "2002", e.AFF_ADDRESS_AND_BPS_OR_NEITHER = "2003", e.AFF_ADDRESS_TOO_LONG = "2004", e.AFF_BPS_INTEGER_0_100 = "2005", e.SOURCE_ADDRESS_INVALID_FOR_SELL_CHAIN = "2006", e.DESTINATION_ADDRESS_INVALID_FOR_BUY_CHAIN = "2007", e.PREFERRED_PROFVIDER_NOT_SUPPORTED = "2008", e.DESTINATION_ADDRESS_SMART_CONTRACT = "2009", e.BUY_AMOUNT_MUST_BE_POSITIVE_INTEGER = "2010", e.SOURCE_ADDRESS_SMART_CONTRACT = "2011", e.INVALID_PROVIDER = "2100", e.MISSING_CROSS_CHAIN_PROVIDER = "2101", e.MISSING_AVAX_PROVIDER = "2102", e.MISSING_BSC_PROVIDER = "2103", e.MISSING_ETH_PROVIDER = "2104", e.INVALID_PROVIDER_FOR_SWAP_OUT = "2105", e.MISSING_ARB_PROVIDER = "2106", e.INVALID_CHAIN = "2200", e.INVALID_ASSET = "2201", e.INVALID_ASSET_IDENTIFIER = "2202", e.UNSUPPORTED_CHAIN = "2204", e.UNSUPPORTED_ASSET = "2203", e.UNSUPPORTED_ASSET_FOR_SWAPOUT = "2205", e.INVALID_SOURCE_ADDRESS = "2300", e.INVALID_DESTINATION_ADDRESS = "2301", e.THORNODE_QUOTE_GENERIC_ERROR = "3000", e.NOT_ENOUGH_SYNTH_BALANCE = "3001", e.SYNTH_MINTING_CAP_REACHED = "3002", e.INVALID_QUOTE_MODE = "4000", e.NO_QUOTES = "4001", e.SERVICE_UNAVAILABLE_GENERIC = "5000", e.MISSING_GAS_DATA_GENERIC = "5100", e.MISSING_TOKEN_INFO_GENERIC = "5200", e.CANT_FIND_TOKEN_LIST = "5201", e.NO_PRICE = "5202", e.PRICE_IS_STALE = "5203", e.ADDRESS_NOT_WHITELISTED = "6000", e.ADDRESS_ALREADY_CLAIMED = "6001", e.TEMPORARY_ERROR = "9999", e))(n || {});
|
|
987
1039
|
var b = {
|
|
988
1040
|
[n.INVALID_INPUT_PARAMETERS]: "Invalid input parameters: {0}.",
|
package/dist/index.es.js
CHANGED
|
@@ -23,7 +23,7 @@ var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require
|
|
|
23
23
|
throw Error('Dynamic require of "' + x + '" is not supported');
|
|
24
24
|
});
|
|
25
25
|
|
|
26
|
-
//
|
|
26
|
+
// ../pioneer-client/lib/index.js
|
|
27
27
|
var require_lib = __commonJS((exports) => {
|
|
28
28
|
var __assign = exports && exports.__assign || function() {
|
|
29
29
|
__assign = Object.assign || function(t) {
|
|
@@ -297,9 +297,9 @@ var require_lib = __commonJS((exports) => {
|
|
|
297
297
|
spec: specData_1,
|
|
298
298
|
execute: function(request) {
|
|
299
299
|
return __awaiter(_this, undefined, undefined, function() {
|
|
300
|
-
var operationId, parameters, requestBody, targetPath, targetMethod, path, method, baseUrl, url, httpReq;
|
|
301
|
-
return __generator(this, function(
|
|
302
|
-
switch (
|
|
300
|
+
var operationId, parameters, requestBody, targetPath, targetMethod, path, method, baseUrl, finalPath, _i, _a2, _b2, key, value, placeholder, url, httpReq;
|
|
301
|
+
return __generator(this, function(_c) {
|
|
302
|
+
switch (_c.label) {
|
|
303
303
|
case 0:
|
|
304
304
|
operationId = request.operationId, parameters = request.parameters, requestBody = request.requestBody;
|
|
305
305
|
targetPath = "";
|
|
@@ -322,7 +322,17 @@ var require_lib = __commonJS((exports) => {
|
|
|
322
322
|
if (specData_1.servers && specData_1.servers.length > 0) {
|
|
323
323
|
baseUrl = specData_1.servers[0].url;
|
|
324
324
|
}
|
|
325
|
-
|
|
325
|
+
finalPath = targetPath;
|
|
326
|
+
if (parameters) {
|
|
327
|
+
for (_i = 0, _a2 = Object.entries(parameters);_i < _a2.length; _i++) {
|
|
328
|
+
_b2 = _a2[_i], key = _b2[0], value = _b2[1];
|
|
329
|
+
placeholder = "{".concat(key, "}");
|
|
330
|
+
if (finalPath.includes(placeholder)) {
|
|
331
|
+
finalPath = finalPath.replace(placeholder, encodeURIComponent(String(value)));
|
|
332
|
+
}
|
|
333
|
+
}
|
|
334
|
+
}
|
|
335
|
+
url = "".concat(baseUrl).concat(finalPath);
|
|
326
336
|
httpReq = {
|
|
327
337
|
method: targetMethod.toUpperCase(),
|
|
328
338
|
url,
|
|
@@ -334,7 +344,7 @@ var require_lib = __commonJS((exports) => {
|
|
|
334
344
|
};
|
|
335
345
|
return [4, customHttpClient(httpReq)];
|
|
336
346
|
case 1:
|
|
337
|
-
return [2,
|
|
347
|
+
return [2, _c.sent()];
|
|
338
348
|
}
|
|
339
349
|
});
|
|
340
350
|
});
|
|
@@ -415,7 +425,7 @@ var require_lib = __commonJS((exports) => {
|
|
|
415
425
|
exports.default = Pioneer;
|
|
416
426
|
});
|
|
417
427
|
|
|
418
|
-
// node_modules/coinselect/utils.js
|
|
428
|
+
// ../../../node_modules/coinselect/utils.js
|
|
419
429
|
var require_utils = __commonJS((exports, module) => {
|
|
420
430
|
var TX_EMPTY_SIZE = 4 + 1 + 1 + 4;
|
|
421
431
|
var TX_INPUT_BASE = 32 + 4 + 1 + 4;
|
|
@@ -488,7 +498,7 @@ var require_utils = __commonJS((exports, module) => {
|
|
|
488
498
|
};
|
|
489
499
|
});
|
|
490
500
|
|
|
491
|
-
// node_modules/coinselect/accumulative.js
|
|
501
|
+
// ../../../node_modules/coinselect/accumulative.js
|
|
492
502
|
var require_accumulative = __commonJS((exports, module) => {
|
|
493
503
|
var utils = require_utils();
|
|
494
504
|
module.exports = function accumulative(utxos, outputs, feeRate) {
|
|
@@ -520,7 +530,7 @@ var require_accumulative = __commonJS((exports, module) => {
|
|
|
520
530
|
};
|
|
521
531
|
});
|
|
522
532
|
|
|
523
|
-
// node_modules/coinselect/blackjack.js
|
|
533
|
+
// ../../../node_modules/coinselect/blackjack.js
|
|
524
534
|
var require_blackjack = __commonJS((exports, module) => {
|
|
525
535
|
var utils = require_utils();
|
|
526
536
|
module.exports = function blackjack(utxos, outputs, feeRate) {
|
|
@@ -549,7 +559,7 @@ var require_blackjack = __commonJS((exports, module) => {
|
|
|
549
559
|
};
|
|
550
560
|
});
|
|
551
561
|
|
|
552
|
-
// node_modules/coinselect/index.js
|
|
562
|
+
// ../../../node_modules/coinselect/index.js
|
|
553
563
|
var require_coinselect = __commonJS((exports, module) => {
|
|
554
564
|
var accumulative = require_accumulative();
|
|
555
565
|
var blackjack = require_blackjack();
|
|
@@ -568,7 +578,7 @@ var require_coinselect = __commonJS((exports, module) => {
|
|
|
568
578
|
};
|
|
569
579
|
});
|
|
570
580
|
|
|
571
|
-
// node_modules/coinselect/split.js
|
|
581
|
+
// ../../../node_modules/coinselect/split.js
|
|
572
582
|
var require_split = __commonJS((exports, module) => {
|
|
573
583
|
var utils = require_utils();
|
|
574
584
|
module.exports = function split(utxos, outputs, feeRate) {
|
|
@@ -841,19 +851,32 @@ async function getEvmCharts(params) {
|
|
|
841
851
|
return balances;
|
|
842
852
|
}
|
|
843
853
|
console.log(tag, "Using EVM address for portfolio:", primaryAddress);
|
|
854
|
+
await fetchStableCoins(pioneer, primaryAddress, blockchains, balances, context);
|
|
844
855
|
try {
|
|
845
|
-
let portfolio = await pioneer.GetPortfolio({
|
|
846
|
-
|
|
856
|
+
let portfolio = await pioneer.GetPortfolio({
|
|
857
|
+
networkId: "eip155:1",
|
|
858
|
+
address: primaryAddress
|
|
859
|
+
});
|
|
860
|
+
portfolio = portfolio.data?.data || portfolio.data;
|
|
847
861
|
if (!portfolio || !portfolio.balances) {
|
|
848
862
|
console.error(tag, "No portfolio.balances found:", portfolio);
|
|
849
863
|
return balances;
|
|
850
864
|
}
|
|
865
|
+
console.log(tag, `Portfolio returned ${portfolio.balances.length} balances`);
|
|
866
|
+
let processedCount = 0;
|
|
867
|
+
let skippedCount = 0;
|
|
851
868
|
for (const balance of portfolio.balances) {
|
|
852
869
|
const processedBalance = processPortfolioBalance(balance, primaryAddress, context, blockchains);
|
|
853
|
-
if (processedBalance
|
|
854
|
-
balances.
|
|
870
|
+
if (processedBalance) {
|
|
871
|
+
if (!checkDuplicateBalance(balances, processedBalance.caip, processedBalance.pubkey)) {
|
|
872
|
+
balances.push(processedBalance);
|
|
873
|
+
processedCount++;
|
|
874
|
+
}
|
|
875
|
+
} else {
|
|
876
|
+
skippedCount++;
|
|
855
877
|
}
|
|
856
878
|
}
|
|
879
|
+
console.log(tag, `Processed ${processedCount} balances, skipped ${skippedCount}`);
|
|
857
880
|
if (portfolio.tokens && portfolio.tokens.length > 0) {
|
|
858
881
|
console.log(tag, "Processing portfolio.tokens:", portfolio.tokens.length);
|
|
859
882
|
for (const token of portfolio.tokens) {
|
|
@@ -874,7 +897,8 @@ function processPortfolioBalance(balance, primaryAddress, context, blockchains)
|
|
|
874
897
|
return null;
|
|
875
898
|
}
|
|
876
899
|
const networkId = balance.caip.split("/")[0];
|
|
877
|
-
|
|
900
|
+
const isEip155 = networkId.startsWith("eip155:");
|
|
901
|
+
if (!isEip155 && !blockchains.includes(networkId)) {
|
|
878
902
|
return null;
|
|
879
903
|
}
|
|
880
904
|
const assetInfo = hydrateAssetData(balance.caip);
|
|
@@ -931,7 +955,8 @@ function processPortfolioToken(token, primaryAddress, context, blockchains) {
|
|
|
931
955
|
} else if (token.networkId && token.networkId.includes("/")) {
|
|
932
956
|
extractedNetworkId = token.networkId.split("/")[0];
|
|
933
957
|
}
|
|
934
|
-
|
|
958
|
+
const isEip155 = extractedNetworkId.startsWith("eip155:");
|
|
959
|
+
if (!isEip155 && !blockchains.includes(extractedNetworkId)) {
|
|
935
960
|
return null;
|
|
936
961
|
}
|
|
937
962
|
const tokenAssetInfo = hydrateAssetData(token.assetCaip);
|
|
@@ -959,6 +984,33 @@ function processPortfolioToken(token, primaryAddress, context, blockchains) {
|
|
|
959
984
|
};
|
|
960
985
|
return chartBalance;
|
|
961
986
|
}
|
|
987
|
+
async function fetchStableCoins(pioneer, primaryAddress, blockchains, balances, context) {
|
|
988
|
+
console.log(tag, "Fetching stable coins for redundancy...");
|
|
989
|
+
const supportedNetworks = ["eip155:1", "eip155:137", "eip155:8453", "eip155:56"];
|
|
990
|
+
const networksToCheck = blockchains.filter((net) => supportedNetworks.includes(net));
|
|
991
|
+
if (networksToCheck.length === 0) {
|
|
992
|
+
console.log(tag, "No supported networks for stable coins");
|
|
993
|
+
return;
|
|
994
|
+
}
|
|
995
|
+
console.log(tag, `Checking stable coins on ${networksToCheck.length} networks`);
|
|
996
|
+
for (const networkId of networksToCheck) {
|
|
997
|
+
try {
|
|
998
|
+
const response = await pioneer.GetStableCoins({ networkId, address: primaryAddress });
|
|
999
|
+
const stableCoins = response?.data?.tokens || [];
|
|
1000
|
+
console.log(tag, `Found ${stableCoins.length} stable coins on ${networkId}`);
|
|
1001
|
+
for (const token of stableCoins) {
|
|
1002
|
+
const chartBalance = processPortfolioToken(token, primaryAddress, context, blockchains);
|
|
1003
|
+
if (chartBalance && !checkDuplicateBalance(balances, chartBalance.caip, chartBalance.pubkey)) {
|
|
1004
|
+
balances.push(chartBalance);
|
|
1005
|
+
console.log(tag, `Added stable coin: ${chartBalance.symbol} = ${chartBalance.balance}`);
|
|
1006
|
+
}
|
|
1007
|
+
}
|
|
1008
|
+
} catch (error) {
|
|
1009
|
+
console.error(tag, `Error fetching stable coins for ${networkId}:`, error.message);
|
|
1010
|
+
}
|
|
1011
|
+
}
|
|
1012
|
+
console.log(tag, `Stable coin redundancy complete. Total balances: ${balances.length}`);
|
|
1013
|
+
}
|
|
962
1014
|
|
|
963
1015
|
// src/charts/maya.ts
|
|
964
1016
|
var tag2 = "| charts-maya |";
|
|
@@ -1154,7 +1206,7 @@ var getCharts = async (blockchains, pioneer, pubkeys, context) => {
|
|
|
1154
1206
|
}
|
|
1155
1207
|
};
|
|
1156
1208
|
|
|
1157
|
-
// node_modules/@coinmasters/types/dist/index.es.js
|
|
1209
|
+
// ../../../node_modules/@coinmasters/types/dist/index.es.js
|
|
1158
1210
|
var n = /* @__PURE__ */ ((e) => (e.INVALID_INPUT_PARAMETERS = "1000", e.UNKNOWN_PROVIDERS = "1001", e.CANNOT_FIND_INBOUND_ADDRESS = "1002", e.NO_INBOUND_ADDRESSES = "1003", e.CHAIN_HALTED_OR_UNSUPPORTED = "1004", e.MISSING_INPUT_PARAMETER = "1005", e.INVALID_TYPE_GENERIC = "1100", e.INVALID_NUMBER_STRING = "1101", e.INVALID_NUMBER = "1102", e.INVALID_BOOLEAN = "1103", e.INVALID_OBJECT = "1104", e.INVALID_ARRAY = "1105", e.SELL_AMOUNT_MUST_BE_POSITIVE_INTEGER = "2000", e.SELL_BUY_ASSETS_ARE_THE_SAME = "2001", e.MISSING_SOURCE_ADDRESS_FOR_SYNTH = "2002", e.AFF_ADDRESS_AND_BPS_OR_NEITHER = "2003", e.AFF_ADDRESS_TOO_LONG = "2004", e.AFF_BPS_INTEGER_0_100 = "2005", e.SOURCE_ADDRESS_INVALID_FOR_SELL_CHAIN = "2006", e.DESTINATION_ADDRESS_INVALID_FOR_BUY_CHAIN = "2007", e.PREFERRED_PROFVIDER_NOT_SUPPORTED = "2008", e.DESTINATION_ADDRESS_SMART_CONTRACT = "2009", e.BUY_AMOUNT_MUST_BE_POSITIVE_INTEGER = "2010", e.SOURCE_ADDRESS_SMART_CONTRACT = "2011", e.INVALID_PROVIDER = "2100", e.MISSING_CROSS_CHAIN_PROVIDER = "2101", e.MISSING_AVAX_PROVIDER = "2102", e.MISSING_BSC_PROVIDER = "2103", e.MISSING_ETH_PROVIDER = "2104", e.INVALID_PROVIDER_FOR_SWAP_OUT = "2105", e.MISSING_ARB_PROVIDER = "2106", e.INVALID_CHAIN = "2200", e.INVALID_ASSET = "2201", e.INVALID_ASSET_IDENTIFIER = "2202", e.UNSUPPORTED_CHAIN = "2204", e.UNSUPPORTED_ASSET = "2203", e.UNSUPPORTED_ASSET_FOR_SWAPOUT = "2205", e.INVALID_SOURCE_ADDRESS = "2300", e.INVALID_DESTINATION_ADDRESS = "2301", e.THORNODE_QUOTE_GENERIC_ERROR = "3000", e.NOT_ENOUGH_SYNTH_BALANCE = "3001", e.SYNTH_MINTING_CAP_REACHED = "3002", e.INVALID_QUOTE_MODE = "4000", e.NO_QUOTES = "4001", e.SERVICE_UNAVAILABLE_GENERIC = "5000", e.MISSING_GAS_DATA_GENERIC = "5100", e.MISSING_TOKEN_INFO_GENERIC = "5200", e.CANT_FIND_TOKEN_LIST = "5201", e.NO_PRICE = "5202", e.PRICE_IS_STALE = "5203", e.ADDRESS_NOT_WHITELISTED = "6000", e.ADDRESS_ALREADY_CLAIMED = "6001", e.TEMPORARY_ERROR = "9999", e))(n || {});
|
|
1159
1211
|
var b2 = {
|
|
1160
1212
|
[n.INVALID_INPUT_PARAMETERS]: "Invalid input parameters: {0}.",
|
package/dist/index.js
CHANGED
|
@@ -23,7 +23,7 @@ var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require
|
|
|
23
23
|
throw Error('Dynamic require of "' + x + '" is not supported');
|
|
24
24
|
});
|
|
25
25
|
|
|
26
|
-
//
|
|
26
|
+
// ../pioneer-client/lib/index.js
|
|
27
27
|
var require_lib = __commonJS((exports) => {
|
|
28
28
|
var __assign = exports && exports.__assign || function() {
|
|
29
29
|
__assign = Object.assign || function(t) {
|
|
@@ -297,9 +297,9 @@ var require_lib = __commonJS((exports) => {
|
|
|
297
297
|
spec: specData_1,
|
|
298
298
|
execute: function(request) {
|
|
299
299
|
return __awaiter(_this, undefined, undefined, function() {
|
|
300
|
-
var operationId, parameters, requestBody, targetPath, targetMethod, path, method, baseUrl, url, httpReq;
|
|
301
|
-
return __generator(this, function(
|
|
302
|
-
switch (
|
|
300
|
+
var operationId, parameters, requestBody, targetPath, targetMethod, path, method, baseUrl, finalPath, _i, _a2, _b2, key, value, placeholder, url, httpReq;
|
|
301
|
+
return __generator(this, function(_c) {
|
|
302
|
+
switch (_c.label) {
|
|
303
303
|
case 0:
|
|
304
304
|
operationId = request.operationId, parameters = request.parameters, requestBody = request.requestBody;
|
|
305
305
|
targetPath = "";
|
|
@@ -322,7 +322,17 @@ var require_lib = __commonJS((exports) => {
|
|
|
322
322
|
if (specData_1.servers && specData_1.servers.length > 0) {
|
|
323
323
|
baseUrl = specData_1.servers[0].url;
|
|
324
324
|
}
|
|
325
|
-
|
|
325
|
+
finalPath = targetPath;
|
|
326
|
+
if (parameters) {
|
|
327
|
+
for (_i = 0, _a2 = Object.entries(parameters);_i < _a2.length; _i++) {
|
|
328
|
+
_b2 = _a2[_i], key = _b2[0], value = _b2[1];
|
|
329
|
+
placeholder = "{".concat(key, "}");
|
|
330
|
+
if (finalPath.includes(placeholder)) {
|
|
331
|
+
finalPath = finalPath.replace(placeholder, encodeURIComponent(String(value)));
|
|
332
|
+
}
|
|
333
|
+
}
|
|
334
|
+
}
|
|
335
|
+
url = "".concat(baseUrl).concat(finalPath);
|
|
326
336
|
httpReq = {
|
|
327
337
|
method: targetMethod.toUpperCase(),
|
|
328
338
|
url,
|
|
@@ -334,7 +344,7 @@ var require_lib = __commonJS((exports) => {
|
|
|
334
344
|
};
|
|
335
345
|
return [4, customHttpClient(httpReq)];
|
|
336
346
|
case 1:
|
|
337
|
-
return [2,
|
|
347
|
+
return [2, _c.sent()];
|
|
338
348
|
}
|
|
339
349
|
});
|
|
340
350
|
});
|
|
@@ -415,7 +425,7 @@ var require_lib = __commonJS((exports) => {
|
|
|
415
425
|
exports.default = Pioneer;
|
|
416
426
|
});
|
|
417
427
|
|
|
418
|
-
// node_modules/coinselect/utils.js
|
|
428
|
+
// ../../../node_modules/coinselect/utils.js
|
|
419
429
|
var require_utils = __commonJS((exports, module) => {
|
|
420
430
|
var TX_EMPTY_SIZE = 4 + 1 + 1 + 4;
|
|
421
431
|
var TX_INPUT_BASE = 32 + 4 + 1 + 4;
|
|
@@ -488,7 +498,7 @@ var require_utils = __commonJS((exports, module) => {
|
|
|
488
498
|
};
|
|
489
499
|
});
|
|
490
500
|
|
|
491
|
-
// node_modules/coinselect/accumulative.js
|
|
501
|
+
// ../../../node_modules/coinselect/accumulative.js
|
|
492
502
|
var require_accumulative = __commonJS((exports, module) => {
|
|
493
503
|
var utils = require_utils();
|
|
494
504
|
module.exports = function accumulative(utxos, outputs, feeRate) {
|
|
@@ -520,7 +530,7 @@ var require_accumulative = __commonJS((exports, module) => {
|
|
|
520
530
|
};
|
|
521
531
|
});
|
|
522
532
|
|
|
523
|
-
// node_modules/coinselect/blackjack.js
|
|
533
|
+
// ../../../node_modules/coinselect/blackjack.js
|
|
524
534
|
var require_blackjack = __commonJS((exports, module) => {
|
|
525
535
|
var utils = require_utils();
|
|
526
536
|
module.exports = function blackjack(utxos, outputs, feeRate) {
|
|
@@ -549,7 +559,7 @@ var require_blackjack = __commonJS((exports, module) => {
|
|
|
549
559
|
};
|
|
550
560
|
});
|
|
551
561
|
|
|
552
|
-
// node_modules/coinselect/index.js
|
|
562
|
+
// ../../../node_modules/coinselect/index.js
|
|
553
563
|
var require_coinselect = __commonJS((exports, module) => {
|
|
554
564
|
var accumulative = require_accumulative();
|
|
555
565
|
var blackjack = require_blackjack();
|
|
@@ -568,7 +578,7 @@ var require_coinselect = __commonJS((exports, module) => {
|
|
|
568
578
|
};
|
|
569
579
|
});
|
|
570
580
|
|
|
571
|
-
// node_modules/coinselect/split.js
|
|
581
|
+
// ../../../node_modules/coinselect/split.js
|
|
572
582
|
var require_split = __commonJS((exports, module) => {
|
|
573
583
|
var utils = require_utils();
|
|
574
584
|
module.exports = function split(utxos, outputs, feeRate) {
|
|
@@ -841,19 +851,32 @@ async function getEvmCharts(params) {
|
|
|
841
851
|
return balances;
|
|
842
852
|
}
|
|
843
853
|
console.log(tag, "Using EVM address for portfolio:", primaryAddress);
|
|
854
|
+
await fetchStableCoins(pioneer, primaryAddress, blockchains, balances, context);
|
|
844
855
|
try {
|
|
845
|
-
let portfolio = await pioneer.GetPortfolio({
|
|
846
|
-
|
|
856
|
+
let portfolio = await pioneer.GetPortfolio({
|
|
857
|
+
networkId: "eip155:1",
|
|
858
|
+
address: primaryAddress
|
|
859
|
+
});
|
|
860
|
+
portfolio = portfolio.data?.data || portfolio.data;
|
|
847
861
|
if (!portfolio || !portfolio.balances) {
|
|
848
862
|
console.error(tag, "No portfolio.balances found:", portfolio);
|
|
849
863
|
return balances;
|
|
850
864
|
}
|
|
865
|
+
console.log(tag, `Portfolio returned ${portfolio.balances.length} balances`);
|
|
866
|
+
let processedCount = 0;
|
|
867
|
+
let skippedCount = 0;
|
|
851
868
|
for (const balance of portfolio.balances) {
|
|
852
869
|
const processedBalance = processPortfolioBalance(balance, primaryAddress, context, blockchains);
|
|
853
|
-
if (processedBalance
|
|
854
|
-
balances.
|
|
870
|
+
if (processedBalance) {
|
|
871
|
+
if (!checkDuplicateBalance(balances, processedBalance.caip, processedBalance.pubkey)) {
|
|
872
|
+
balances.push(processedBalance);
|
|
873
|
+
processedCount++;
|
|
874
|
+
}
|
|
875
|
+
} else {
|
|
876
|
+
skippedCount++;
|
|
855
877
|
}
|
|
856
878
|
}
|
|
879
|
+
console.log(tag, `Processed ${processedCount} balances, skipped ${skippedCount}`);
|
|
857
880
|
if (portfolio.tokens && portfolio.tokens.length > 0) {
|
|
858
881
|
console.log(tag, "Processing portfolio.tokens:", portfolio.tokens.length);
|
|
859
882
|
for (const token of portfolio.tokens) {
|
|
@@ -874,7 +897,8 @@ function processPortfolioBalance(balance, primaryAddress, context, blockchains)
|
|
|
874
897
|
return null;
|
|
875
898
|
}
|
|
876
899
|
const networkId = balance.caip.split("/")[0];
|
|
877
|
-
|
|
900
|
+
const isEip155 = networkId.startsWith("eip155:");
|
|
901
|
+
if (!isEip155 && !blockchains.includes(networkId)) {
|
|
878
902
|
return null;
|
|
879
903
|
}
|
|
880
904
|
const assetInfo = hydrateAssetData(balance.caip);
|
|
@@ -931,7 +955,8 @@ function processPortfolioToken(token, primaryAddress, context, blockchains) {
|
|
|
931
955
|
} else if (token.networkId && token.networkId.includes("/")) {
|
|
932
956
|
extractedNetworkId = token.networkId.split("/")[0];
|
|
933
957
|
}
|
|
934
|
-
|
|
958
|
+
const isEip155 = extractedNetworkId.startsWith("eip155:");
|
|
959
|
+
if (!isEip155 && !blockchains.includes(extractedNetworkId)) {
|
|
935
960
|
return null;
|
|
936
961
|
}
|
|
937
962
|
const tokenAssetInfo = hydrateAssetData(token.assetCaip);
|
|
@@ -959,6 +984,33 @@ function processPortfolioToken(token, primaryAddress, context, blockchains) {
|
|
|
959
984
|
};
|
|
960
985
|
return chartBalance;
|
|
961
986
|
}
|
|
987
|
+
async function fetchStableCoins(pioneer, primaryAddress, blockchains, balances, context) {
|
|
988
|
+
console.log(tag, "Fetching stable coins for redundancy...");
|
|
989
|
+
const supportedNetworks = ["eip155:1", "eip155:137", "eip155:8453", "eip155:56"];
|
|
990
|
+
const networksToCheck = blockchains.filter((net) => supportedNetworks.includes(net));
|
|
991
|
+
if (networksToCheck.length === 0) {
|
|
992
|
+
console.log(tag, "No supported networks for stable coins");
|
|
993
|
+
return;
|
|
994
|
+
}
|
|
995
|
+
console.log(tag, `Checking stable coins on ${networksToCheck.length} networks`);
|
|
996
|
+
for (const networkId of networksToCheck) {
|
|
997
|
+
try {
|
|
998
|
+
const response = await pioneer.GetStableCoins({ networkId, address: primaryAddress });
|
|
999
|
+
const stableCoins = response?.data?.tokens || [];
|
|
1000
|
+
console.log(tag, `Found ${stableCoins.length} stable coins on ${networkId}`);
|
|
1001
|
+
for (const token of stableCoins) {
|
|
1002
|
+
const chartBalance = processPortfolioToken(token, primaryAddress, context, blockchains);
|
|
1003
|
+
if (chartBalance && !checkDuplicateBalance(balances, chartBalance.caip, chartBalance.pubkey)) {
|
|
1004
|
+
balances.push(chartBalance);
|
|
1005
|
+
console.log(tag, `Added stable coin: ${chartBalance.symbol} = ${chartBalance.balance}`);
|
|
1006
|
+
}
|
|
1007
|
+
}
|
|
1008
|
+
} catch (error) {
|
|
1009
|
+
console.error(tag, `Error fetching stable coins for ${networkId}:`, error.message);
|
|
1010
|
+
}
|
|
1011
|
+
}
|
|
1012
|
+
console.log(tag, `Stable coin redundancy complete. Total balances: ${balances.length}`);
|
|
1013
|
+
}
|
|
962
1014
|
|
|
963
1015
|
// src/charts/maya.ts
|
|
964
1016
|
var tag2 = "| charts-maya |";
|
|
@@ -1154,7 +1206,7 @@ var getCharts = async (blockchains, pioneer, pubkeys, context) => {
|
|
|
1154
1206
|
}
|
|
1155
1207
|
};
|
|
1156
1208
|
|
|
1157
|
-
// node_modules/@coinmasters/types/dist/index.es.js
|
|
1209
|
+
// ../../../node_modules/@coinmasters/types/dist/index.es.js
|
|
1158
1210
|
var n = /* @__PURE__ */ ((e) => (e.INVALID_INPUT_PARAMETERS = "1000", e.UNKNOWN_PROVIDERS = "1001", e.CANNOT_FIND_INBOUND_ADDRESS = "1002", e.NO_INBOUND_ADDRESSES = "1003", e.CHAIN_HALTED_OR_UNSUPPORTED = "1004", e.MISSING_INPUT_PARAMETER = "1005", e.INVALID_TYPE_GENERIC = "1100", e.INVALID_NUMBER_STRING = "1101", e.INVALID_NUMBER = "1102", e.INVALID_BOOLEAN = "1103", e.INVALID_OBJECT = "1104", e.INVALID_ARRAY = "1105", e.SELL_AMOUNT_MUST_BE_POSITIVE_INTEGER = "2000", e.SELL_BUY_ASSETS_ARE_THE_SAME = "2001", e.MISSING_SOURCE_ADDRESS_FOR_SYNTH = "2002", e.AFF_ADDRESS_AND_BPS_OR_NEITHER = "2003", e.AFF_ADDRESS_TOO_LONG = "2004", e.AFF_BPS_INTEGER_0_100 = "2005", e.SOURCE_ADDRESS_INVALID_FOR_SELL_CHAIN = "2006", e.DESTINATION_ADDRESS_INVALID_FOR_BUY_CHAIN = "2007", e.PREFERRED_PROFVIDER_NOT_SUPPORTED = "2008", e.DESTINATION_ADDRESS_SMART_CONTRACT = "2009", e.BUY_AMOUNT_MUST_BE_POSITIVE_INTEGER = "2010", e.SOURCE_ADDRESS_SMART_CONTRACT = "2011", e.INVALID_PROVIDER = "2100", e.MISSING_CROSS_CHAIN_PROVIDER = "2101", e.MISSING_AVAX_PROVIDER = "2102", e.MISSING_BSC_PROVIDER = "2103", e.MISSING_ETH_PROVIDER = "2104", e.INVALID_PROVIDER_FOR_SWAP_OUT = "2105", e.MISSING_ARB_PROVIDER = "2106", e.INVALID_CHAIN = "2200", e.INVALID_ASSET = "2201", e.INVALID_ASSET_IDENTIFIER = "2202", e.UNSUPPORTED_CHAIN = "2204", e.UNSUPPORTED_ASSET = "2203", e.UNSUPPORTED_ASSET_FOR_SWAPOUT = "2205", e.INVALID_SOURCE_ADDRESS = "2300", e.INVALID_DESTINATION_ADDRESS = "2301", e.THORNODE_QUOTE_GENERIC_ERROR = "3000", e.NOT_ENOUGH_SYNTH_BALANCE = "3001", e.SYNTH_MINTING_CAP_REACHED = "3002", e.INVALID_QUOTE_MODE = "4000", e.NO_QUOTES = "4001", e.SERVICE_UNAVAILABLE_GENERIC = "5000", e.MISSING_GAS_DATA_GENERIC = "5100", e.MISSING_TOKEN_INFO_GENERIC = "5200", e.CANT_FIND_TOKEN_LIST = "5201", e.NO_PRICE = "5202", e.PRICE_IS_STALE = "5203", e.ADDRESS_NOT_WHITELISTED = "6000", e.ADDRESS_ALREADY_CLAIMED = "6001", e.TEMPORARY_ERROR = "9999", e))(n || {});
|
|
1159
1211
|
var b2 = {
|
|
1160
1212
|
[n.INVALID_INPUT_PARAMETERS]: "Invalid input parameters: {0}.",
|
package/package.json
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"author": "highlander",
|
|
3
3
|
"name": "@pioneer-platform/pioneer-sdk",
|
|
4
|
-
"version": "4.20.
|
|
4
|
+
"version": "4.20.11",
|
|
5
5
|
"dependencies": {
|
|
6
6
|
"@keepkey/keepkey-sdk": "^0.2.62",
|
|
7
7
|
"@pioneer-platform/loggerdog": "^8.11.0",
|
|
8
8
|
"@pioneer-platform/pioneer-caip": "^9.10.0",
|
|
9
|
-
"@pioneer-platform/pioneer-client": "^9.10.
|
|
9
|
+
"@pioneer-platform/pioneer-client": "^9.10.4",
|
|
10
10
|
"@pioneer-platform/pioneer-coins": "^9.11.0",
|
|
11
11
|
"@pioneer-platform/pioneer-discovery": "^0.8.0",
|
|
12
12
|
"@pioneer-platform/pioneer-events": "^8.11.0",
|
|
@@ -48,6 +48,8 @@
|
|
|
48
48
|
},
|
|
49
49
|
"react-native": "./src/index.ts",
|
|
50
50
|
"repository": "https://github.com/thorswap/SwapKit.git",
|
|
51
|
+
"type": "module",
|
|
52
|
+
"types": "./dist/index.d.ts",
|
|
51
53
|
"scripts": {
|
|
52
54
|
"build": "bash scripts/build.sh",
|
|
53
55
|
"build:watch": "nodemon --watch src --exec 'bun run build'",
|
|
@@ -55,7 +57,5 @@
|
|
|
55
57
|
"lint": "eslint ./ --ext .ts,.tsx --fix; tsc --noEmit",
|
|
56
58
|
"test": "echo 'vitest --run'",
|
|
57
59
|
"test:coverage": "echo 'vitest run --coverage'"
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
"types": "./dist/index.d.ts"
|
|
61
|
-
}
|
|
60
|
+
}
|
|
61
|
+
}
|
package/src/charts/evm.ts
CHANGED
|
@@ -6,7 +6,7 @@ const tag = '| charts-evm |';
|
|
|
6
6
|
export async function getEvmCharts(params: ChartParams): Promise<ChartBalance[]> {
|
|
7
7
|
const { blockchains, pioneer, pubkeys, context } = params;
|
|
8
8
|
const balances: ChartBalance[] = [];
|
|
9
|
-
|
|
9
|
+
|
|
10
10
|
// Find the primary address for portfolio lookup
|
|
11
11
|
// ONLY use EVM addresses since the portfolio endpoint uses Zapper which only supports Ethereum
|
|
12
12
|
const evmPubkey = pubkeys.find(
|
|
@@ -28,22 +28,45 @@ export async function getEvmCharts(params: ChartParams): Promise<ChartBalance[]>
|
|
|
28
28
|
|
|
29
29
|
console.log(tag, 'Using EVM address for portfolio:', primaryAddress);
|
|
30
30
|
|
|
31
|
+
// REDUNDANCY: Fetch stable coins from dedicated endpoint for ALL EVM networks
|
|
32
|
+
// This ensures USDC/USDT balances are always available even if Zapper fails
|
|
33
|
+
await fetchStableCoins(pioneer, primaryAddress, blockchains, balances, context);
|
|
34
|
+
|
|
31
35
|
try {
|
|
32
|
-
|
|
33
|
-
|
|
36
|
+
// NOTE: Zapper API returns portfolio data across ALL networks for a given address
|
|
37
|
+
// We use eip155:1 as the networkId parameter, but Zapper will return data for all EVM chains
|
|
38
|
+
let portfolio = await pioneer.GetPortfolio({
|
|
39
|
+
networkId: 'eip155:1', // Required by endpoint, but Zapper returns all networks
|
|
40
|
+
address: primaryAddress
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
// Handle double-wrapped response from Swagger client
|
|
44
|
+
// Server returns { data: { balances: [...] } }
|
|
45
|
+
// Swagger client wraps as { data: { data: { balances: [...] } } }
|
|
46
|
+
portfolio = portfolio.data?.data || portfolio.data;
|
|
34
47
|
|
|
35
48
|
if (!portfolio || !portfolio.balances) {
|
|
36
49
|
console.error(tag, 'No portfolio.balances found:', portfolio);
|
|
37
50
|
return balances;
|
|
38
51
|
}
|
|
39
52
|
|
|
53
|
+
console.log(tag, `Portfolio returned ${portfolio.balances.length} balances`);
|
|
54
|
+
|
|
40
55
|
// Process main balances
|
|
56
|
+
let processedCount = 0;
|
|
57
|
+
let skippedCount = 0;
|
|
41
58
|
for (const balance of portfolio.balances) {
|
|
42
59
|
const processedBalance = processPortfolioBalance(balance, primaryAddress, context, blockchains);
|
|
43
|
-
if (processedBalance
|
|
44
|
-
balances.
|
|
60
|
+
if (processedBalance) {
|
|
61
|
+
if (!checkDuplicateBalance(balances, processedBalance.caip, processedBalance.pubkey)) {
|
|
62
|
+
balances.push(processedBalance);
|
|
63
|
+
processedCount++;
|
|
64
|
+
}
|
|
65
|
+
} else {
|
|
66
|
+
skippedCount++;
|
|
45
67
|
}
|
|
46
68
|
}
|
|
69
|
+
console.log(tag, `Processed ${processedCount} balances, skipped ${skippedCount}`);
|
|
47
70
|
|
|
48
71
|
// Process tokens from portfolio (if they exist)
|
|
49
72
|
if (portfolio.tokens && portfolio.tokens.length > 0) {
|
|
@@ -76,9 +99,11 @@ function processPortfolioBalance(
|
|
|
76
99
|
|
|
77
100
|
// Always derive networkId from CAIP
|
|
78
101
|
const networkId = balance.caip.split('/')[0];
|
|
79
|
-
|
|
80
|
-
//
|
|
81
|
-
if
|
|
102
|
+
|
|
103
|
+
// Accept ALL EIP155 chains (since we have eip155:* pubkey)
|
|
104
|
+
// For non-EVM chains, check if explicitly in blockchains list
|
|
105
|
+
const isEip155 = networkId.startsWith('eip155:');
|
|
106
|
+
if (!isEip155 && !blockchains.includes(networkId)) {
|
|
82
107
|
return null;
|
|
83
108
|
}
|
|
84
109
|
|
|
@@ -162,8 +187,10 @@ function processPortfolioToken(
|
|
|
162
187
|
extractedNetworkId = token.networkId.split('/')[0];
|
|
163
188
|
}
|
|
164
189
|
|
|
165
|
-
//
|
|
166
|
-
if
|
|
190
|
+
// Accept ALL EIP155 chains (since we have eip155:* pubkey)
|
|
191
|
+
// For non-EVM chains, check if explicitly in blockchains list
|
|
192
|
+
const isEip155 = extractedNetworkId.startsWith('eip155:');
|
|
193
|
+
if (!isEip155 && !blockchains.includes(extractedNetworkId)) {
|
|
167
194
|
return null;
|
|
168
195
|
}
|
|
169
196
|
|
|
@@ -196,4 +223,58 @@ function processPortfolioToken(
|
|
|
196
223
|
};
|
|
197
224
|
|
|
198
225
|
return chartBalance;
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
/**
|
|
229
|
+
* Fetch hardcoded stable coins from dedicated endpoint
|
|
230
|
+
* This provides redundancy for USDC/USDT balances using direct web3 queries
|
|
231
|
+
*/
|
|
232
|
+
async function fetchStableCoins(
|
|
233
|
+
pioneer: any,
|
|
234
|
+
primaryAddress: string,
|
|
235
|
+
blockchains: string[],
|
|
236
|
+
balances: ChartBalance[],
|
|
237
|
+
context: string
|
|
238
|
+
): Promise<void> {
|
|
239
|
+
console.log(tag, 'Fetching stable coins for redundancy...');
|
|
240
|
+
|
|
241
|
+
// Networks that support stable coins endpoint
|
|
242
|
+
const supportedNetworks = ['eip155:1', 'eip155:137', 'eip155:8453', 'eip155:56'];
|
|
243
|
+
|
|
244
|
+
// Filter to only supported EVM networks
|
|
245
|
+
const networksToCheck = blockchains.filter(net => supportedNetworks.includes(net));
|
|
246
|
+
|
|
247
|
+
if (networksToCheck.length === 0) {
|
|
248
|
+
console.log(tag, 'No supported networks for stable coins');
|
|
249
|
+
return;
|
|
250
|
+
}
|
|
251
|
+
|
|
252
|
+
console.log(tag, `Checking stable coins on ${networksToCheck.length} networks`);
|
|
253
|
+
|
|
254
|
+
// Fetch stable coins for each network
|
|
255
|
+
for (const networkId of networksToCheck) {
|
|
256
|
+
try {
|
|
257
|
+
const response = await pioneer.GetStableCoins({ networkId, address: primaryAddress });
|
|
258
|
+
const stableCoins = response?.data?.tokens || [];
|
|
259
|
+
|
|
260
|
+
console.log(tag, `Found ${stableCoins.length} stable coins on ${networkId}`);
|
|
261
|
+
|
|
262
|
+
// Process each stable coin
|
|
263
|
+
for (const token of stableCoins) {
|
|
264
|
+
// Convert to ChartBalance format
|
|
265
|
+
const chartBalance = processPortfolioToken(token, primaryAddress, context, blockchains);
|
|
266
|
+
|
|
267
|
+
// Add if not already in balances (avoid duplicates)
|
|
268
|
+
if (chartBalance && !checkDuplicateBalance(balances, chartBalance.caip, chartBalance.pubkey)) {
|
|
269
|
+
balances.push(chartBalance);
|
|
270
|
+
console.log(tag, `Added stable coin: ${chartBalance.symbol} = ${chartBalance.balance}`);
|
|
271
|
+
}
|
|
272
|
+
}
|
|
273
|
+
} catch (error: any) {
|
|
274
|
+
console.error(tag, `Error fetching stable coins for ${networkId}:`, error.message);
|
|
275
|
+
// Continue with other networks even if one fails
|
|
276
|
+
}
|
|
277
|
+
}
|
|
278
|
+
|
|
279
|
+
console.log(tag, `Stable coin redundancy complete. Total balances: ${balances.length}`);
|
|
199
280
|
}
|
|
@@ -0,0 +1,162 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Stable Coins Configuration
|
|
3
|
+
*
|
|
4
|
+
* Hardcoded list of stable coin and high-priority token addresses across chains.
|
|
5
|
+
* This ensures we ALWAYS fetch balances for these tokens, even if the API fails.
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
export interface TokenConfig {
|
|
9
|
+
symbol: string;
|
|
10
|
+
name: string;
|
|
11
|
+
address: string;
|
|
12
|
+
networkId: string;
|
|
13
|
+
caip: string;
|
|
14
|
+
decimals: number;
|
|
15
|
+
icon?: string;
|
|
16
|
+
coingeckoId?: string;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* Ethereum Mainnet Tokens (eip155:1)
|
|
21
|
+
*/
|
|
22
|
+
export const ETHEREUM_STABLE_COINS: TokenConfig[] = [
|
|
23
|
+
// USDC - Circle USD Coin
|
|
24
|
+
{
|
|
25
|
+
symbol: 'USDC',
|
|
26
|
+
name: 'USD Coin',
|
|
27
|
+
address: '0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48',
|
|
28
|
+
networkId: 'eip155:1',
|
|
29
|
+
caip: 'eip155:1/erc20:0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48',
|
|
30
|
+
decimals: 6,
|
|
31
|
+
coingeckoId: 'usd-coin',
|
|
32
|
+
},
|
|
33
|
+
|
|
34
|
+
// USDT - Tether USD
|
|
35
|
+
{
|
|
36
|
+
symbol: 'USDT',
|
|
37
|
+
name: 'Tether USD',
|
|
38
|
+
address: '0xdAC17F958D2ee523a2206206994597C13D831ec7',
|
|
39
|
+
networkId: 'eip155:1',
|
|
40
|
+
caip: 'eip155:1/erc20:0xdAC17F958D2ee523a2206206994597C13D831ec7',
|
|
41
|
+
decimals: 6,
|
|
42
|
+
coingeckoId: 'tether',
|
|
43
|
+
},
|
|
44
|
+
|
|
45
|
+
// DAI - Dai Stablecoin
|
|
46
|
+
{
|
|
47
|
+
symbol: 'DAI',
|
|
48
|
+
name: 'Dai Stablecoin',
|
|
49
|
+
address: '0x6B175474E89094C44Da98b954EedeAC495271d0F',
|
|
50
|
+
networkId: 'eip155:1',
|
|
51
|
+
caip: 'eip155:1/erc20:0x6B175474E89094C44Da98b954EedeAC495271d0F',
|
|
52
|
+
decimals: 18,
|
|
53
|
+
coingeckoId: 'dai',
|
|
54
|
+
},
|
|
55
|
+
];
|
|
56
|
+
|
|
57
|
+
/**
|
|
58
|
+
* Polygon (MATIC) Tokens (eip155:137)
|
|
59
|
+
*/
|
|
60
|
+
export const POLYGON_STABLE_COINS: TokenConfig[] = [
|
|
61
|
+
// USDC on Polygon
|
|
62
|
+
{
|
|
63
|
+
symbol: 'USDC',
|
|
64
|
+
name: 'USD Coin (Polygon)',
|
|
65
|
+
address: '0x2791Bca1f2de4661ED88A30C99A7a9449Aa84174',
|
|
66
|
+
networkId: 'eip155:137',
|
|
67
|
+
caip: 'eip155:137/erc20:0x2791Bca1f2de4661ED88A30C99A7a9449Aa84174',
|
|
68
|
+
decimals: 6,
|
|
69
|
+
coingeckoId: 'usd-coin',
|
|
70
|
+
},
|
|
71
|
+
|
|
72
|
+
// USDT on Polygon
|
|
73
|
+
{
|
|
74
|
+
symbol: 'USDT',
|
|
75
|
+
name: 'Tether USD (Polygon)',
|
|
76
|
+
address: '0xc2132D05D31c914a87C6611C10748AEb04B58e8F',
|
|
77
|
+
networkId: 'eip155:137',
|
|
78
|
+
caip: 'eip155:137/erc20:0xc2132D05D31c914a87C6611C10748AEb04B58e8F',
|
|
79
|
+
decimals: 6,
|
|
80
|
+
coingeckoId: 'tether',
|
|
81
|
+
},
|
|
82
|
+
];
|
|
83
|
+
|
|
84
|
+
/**
|
|
85
|
+
* Base Tokens (eip155:8453)
|
|
86
|
+
*/
|
|
87
|
+
export const BASE_STABLE_COINS: TokenConfig[] = [
|
|
88
|
+
// USDC on Base
|
|
89
|
+
{
|
|
90
|
+
symbol: 'USDC',
|
|
91
|
+
name: 'USD Coin (Base)',
|
|
92
|
+
address: '0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913',
|
|
93
|
+
networkId: 'eip155:8453',
|
|
94
|
+
caip: 'eip155:8453/erc20:0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913',
|
|
95
|
+
decimals: 6,
|
|
96
|
+
coingeckoId: 'usd-coin',
|
|
97
|
+
},
|
|
98
|
+
];
|
|
99
|
+
|
|
100
|
+
/**
|
|
101
|
+
* BSC (BNB Smart Chain) Tokens (eip155:56)
|
|
102
|
+
*/
|
|
103
|
+
export const BSC_STABLE_COINS: TokenConfig[] = [
|
|
104
|
+
// USDT on BSC
|
|
105
|
+
{
|
|
106
|
+
symbol: 'USDT',
|
|
107
|
+
name: 'Tether USD (BSC)',
|
|
108
|
+
address: '0x55d398326f99059fF775485246999027B3197955',
|
|
109
|
+
networkId: 'eip155:56',
|
|
110
|
+
caip: 'eip155:56/erc20:0x55d398326f99059fF775485246999027B3197955',
|
|
111
|
+
decimals: 18,
|
|
112
|
+
coingeckoId: 'tether',
|
|
113
|
+
},
|
|
114
|
+
|
|
115
|
+
// USDC on BSC
|
|
116
|
+
{
|
|
117
|
+
symbol: 'USDC',
|
|
118
|
+
name: 'USD Coin (BSC)',
|
|
119
|
+
address: '0x8AC76a51cc950d9822D68b83fE1Ad97B32Cd580d',
|
|
120
|
+
networkId: 'eip155:56',
|
|
121
|
+
caip: 'eip155:56/erc20:0x8AC76a51cc950d9822D68b83fE1Ad97B32Cd580d',
|
|
122
|
+
decimals: 18,
|
|
123
|
+
coingeckoId: 'usd-coin',
|
|
124
|
+
},
|
|
125
|
+
];
|
|
126
|
+
|
|
127
|
+
/**
|
|
128
|
+
* All stable coins aggregated by network
|
|
129
|
+
*/
|
|
130
|
+
export const STABLE_COINS_BY_NETWORK: Record<string, TokenConfig[]> = {
|
|
131
|
+
'eip155:1': ETHEREUM_STABLE_COINS,
|
|
132
|
+
'eip155:137': POLYGON_STABLE_COINS,
|
|
133
|
+
'eip155:8453': BASE_STABLE_COINS,
|
|
134
|
+
'eip155:56': BSC_STABLE_COINS,
|
|
135
|
+
};
|
|
136
|
+
|
|
137
|
+
/**
|
|
138
|
+
* Get all stable coins for a specific network
|
|
139
|
+
*/
|
|
140
|
+
export function getStableCoinsForNetwork(networkId: string): TokenConfig[] {
|
|
141
|
+
return STABLE_COINS_BY_NETWORK[networkId] || [];
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
/**
|
|
145
|
+
* Get all stable coins across all networks
|
|
146
|
+
*/
|
|
147
|
+
export function getAllStableCoins(): TokenConfig[] {
|
|
148
|
+
return [
|
|
149
|
+
...ETHEREUM_STABLE_COINS,
|
|
150
|
+
...POLYGON_STABLE_COINS,
|
|
151
|
+
...BASE_STABLE_COINS,
|
|
152
|
+
...BSC_STABLE_COINS,
|
|
153
|
+
];
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
/**
|
|
157
|
+
* Check if a token address is a known stable coin
|
|
158
|
+
*/
|
|
159
|
+
export function isKnownStableCoin(networkId: string, address: string): boolean {
|
|
160
|
+
const coins = getStableCoinsForNetwork(networkId);
|
|
161
|
+
return coins.some(coin => coin.address.toLowerCase() === address.toLowerCase());
|
|
162
|
+
}
|