@pioneer-platform/markets 8.11.3 → 8.11.10
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/.turbo/turbo-build.log +1 -2
- package/CHANGELOG.md +13 -0
- package/lib/index.js +52 -31
- package/package.json +3 -2
- package/test-results.log +5073 -0
- package/lib/index.js.map +0 -145
package/.turbo/turbo-build.log
CHANGED
|
@@ -1,2 +1 @@
|
|
|
1
|
-
|
|
2
|
-
[0m[2m[35m$[0m [2m[1mtsc -p .[0m
|
|
1
|
+
$ tsc -p .
|
package/CHANGELOG.md
CHANGED
package/lib/index.js
CHANGED
|
@@ -56,13 +56,15 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
56
56
|
var TAG = " | market-module | ";
|
|
57
57
|
// @ts-ignore
|
|
58
58
|
var pioneer_discovery_1 = require("@pioneer-platform/pioneer-discovery");
|
|
59
|
+
var caip_1 = require("@shapeshiftoss/caip");
|
|
59
60
|
var axiosLib = require('axios');
|
|
60
61
|
var Axios = axiosLib.default || axiosLib;
|
|
61
62
|
var https = require('https');
|
|
62
63
|
var axios = Axios.create({
|
|
63
64
|
httpsAgent: new https.Agent({
|
|
64
65
|
rejectUnauthorized: false
|
|
65
|
-
})
|
|
66
|
+
}),
|
|
67
|
+
timeout: 5000 // 5 second timeout for all requests (prevents hanging indefinitely)
|
|
66
68
|
});
|
|
67
69
|
var axiosRetry = require('axios-retry');
|
|
68
70
|
axiosRetry(axios, {
|
|
@@ -108,8 +110,8 @@ module.exports = {
|
|
|
108
110
|
//if(!COINGECKO_API_KEY) throw Error("api key required! set env COINGECKO_API_KEY")
|
|
109
111
|
},
|
|
110
112
|
// NEW: CAIP-first individual asset price lookup
|
|
111
|
-
getAssetPriceByCaip: function (caip) {
|
|
112
|
-
return get_asset_price_by_caip(caip);
|
|
113
|
+
getAssetPriceByCaip: function (caip, returnSource) {
|
|
114
|
+
return get_asset_price_by_caip(caip, returnSource);
|
|
113
115
|
},
|
|
114
116
|
// Legacy bulk fetch functions
|
|
115
117
|
getAssetsCoinCap: function () {
|
|
@@ -621,32 +623,42 @@ var get_assets_coingecko = function (limit, skip) {
|
|
|
621
623
|
* @returns Object with identifiers for each API
|
|
622
624
|
*/
|
|
623
625
|
var caip_to_identifiers = function (caip) {
|
|
626
|
+
var _a;
|
|
624
627
|
var tag = TAG + ' | caip_to_identifiers | ';
|
|
625
|
-
// Get asset data
|
|
628
|
+
// Get asset data for symbol
|
|
626
629
|
var asset = pioneer_discovery_1.assetData[caip] || pioneer_discovery_1.assetData[caip.toUpperCase()] || pioneer_discovery_1.assetData[caip.toLowerCase()];
|
|
630
|
+
var symbol = ((_a = asset === null || asset === void 0 ? void 0 : asset.symbol) === null || _a === void 0 ? void 0 : _a.toUpperCase()) || '';
|
|
631
|
+
// PRIORITY 1: Check our generated CoinGecko mapping (most accurate)
|
|
632
|
+
// @ts-ignore
|
|
633
|
+
var mappedCoingeckoId = pioneer_discovery_1.coingeckoMapping[caip];
|
|
634
|
+
if (mappedCoingeckoId) {
|
|
635
|
+
return {
|
|
636
|
+
symbol: symbol,
|
|
637
|
+
coingeckoId: mappedCoingeckoId,
|
|
638
|
+
cmcSymbol: symbol,
|
|
639
|
+
coincapSymbol: symbol.toLowerCase()
|
|
640
|
+
};
|
|
641
|
+
}
|
|
642
|
+
// PRIORITY 2: Try ShapeShift CAIP adapter (for coins we might have missed)
|
|
643
|
+
var shapeshiftCoingeckoId = caip_1.adapters.assetIdToCoingecko(caip);
|
|
644
|
+
if (shapeshiftCoingeckoId) {
|
|
645
|
+
return {
|
|
646
|
+
symbol: symbol,
|
|
647
|
+
coingeckoId: shapeshiftCoingeckoId,
|
|
648
|
+
cmcSymbol: symbol,
|
|
649
|
+
coincapSymbol: symbol.toLowerCase()
|
|
650
|
+
};
|
|
651
|
+
}
|
|
652
|
+
// PRIORITY 3: Fallback to asset data
|
|
627
653
|
if (!asset || !asset.symbol) {
|
|
628
654
|
log.debug(tag, "No asset mapping found for CAIP: ".concat(caip));
|
|
629
655
|
return null;
|
|
630
656
|
}
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
// For now, use symbol-based mapping with known exceptions
|
|
634
|
-
var coinGeckoIdMap = {
|
|
635
|
-
'BTC': 'bitcoin',
|
|
636
|
-
'ETH': 'ethereum',
|
|
637
|
-
'ATOM': 'cosmos',
|
|
638
|
-
'OSMO': 'osmosis',
|
|
639
|
-
'RUNE': 'thorchain',
|
|
640
|
-
'CACAO': 'cacao', // MayaChain
|
|
641
|
-
'MAYA': 'maya-protocol',
|
|
642
|
-
'XRP': 'ripple',
|
|
643
|
-
'LTC': 'litecoin',
|
|
644
|
-
'DOGE': 'dogecoin',
|
|
645
|
-
'BCH': 'bitcoin-cash'
|
|
646
|
-
};
|
|
657
|
+
// PRIORITY 4: Last resort - use symbol as coingecko ID (least accurate, but better than nothing)
|
|
658
|
+
log.debug(tag, "Using symbol fallback for CAIP: ".concat(caip, " (symbol: ").concat(symbol, ")"));
|
|
647
659
|
return {
|
|
648
660
|
symbol: symbol,
|
|
649
|
-
coingeckoId:
|
|
661
|
+
coingeckoId: symbol.toLowerCase(),
|
|
650
662
|
cmcSymbol: symbol,
|
|
651
663
|
coincapSymbol: symbol.toLowerCase()
|
|
652
664
|
};
|
|
@@ -830,10 +842,12 @@ var get_price_from_mayascan = function () {
|
|
|
830
842
|
/**
|
|
831
843
|
* Main function: Get asset price by CAIP
|
|
832
844
|
* Tries all APIs in order: CoinGecko → CoinMarketCap → CoinCap
|
|
845
|
+
* Returns: { price: number, source: string } or backwards compatible number
|
|
833
846
|
*/
|
|
834
|
-
var get_asset_price_by_caip = function (
|
|
835
|
-
return __awaiter(this,
|
|
847
|
+
var get_asset_price_by_caip = function (caip_2) {
|
|
848
|
+
return __awaiter(this, arguments, void 0, function (caip, returnSource) {
|
|
836
849
|
var tag, mayaPrice, identifiers, price;
|
|
850
|
+
if (returnSource === void 0) { returnSource = false; }
|
|
837
851
|
return __generator(this, function (_a) {
|
|
838
852
|
switch (_a.label) {
|
|
839
853
|
case 0:
|
|
@@ -845,7 +859,7 @@ var get_asset_price_by_caip = function (caip) {
|
|
|
845
859
|
case 1:
|
|
846
860
|
mayaPrice = _a.sent();
|
|
847
861
|
if (mayaPrice > 0) {
|
|
848
|
-
return [2 /*return*/, mayaPrice];
|
|
862
|
+
return [2 /*return*/, returnSource ? { price: mayaPrice, source: 'mayascan' } : mayaPrice];
|
|
849
863
|
}
|
|
850
864
|
log.warn(tag, '❌ Failed to get MAYA price from MayaScan, trying standard APIs');
|
|
851
865
|
_a.label = 2;
|
|
@@ -853,31 +867,38 @@ var get_asset_price_by_caip = function (caip) {
|
|
|
853
867
|
identifiers = caip_to_identifiers(caip);
|
|
854
868
|
if (!identifiers) {
|
|
855
869
|
log.warn(tag, "No identifier mapping found for CAIP: ".concat(caip));
|
|
856
|
-
return [2 /*return*/, 0];
|
|
870
|
+
return [2 /*return*/, returnSource ? { price: 0, source: 'none' } : 0];
|
|
857
871
|
}
|
|
858
872
|
log.debug(tag, "Identifiers for ".concat(caip, ":"), identifiers);
|
|
873
|
+
// Try CoinGecko first (free, no API key needed, most comprehensive)
|
|
874
|
+
console.log("\uD83E\uDD8E Trying CoinGecko for: ".concat(identifiers.coingeckoId));
|
|
859
875
|
return [4 /*yield*/, get_price_from_coingecko(identifiers.coingeckoId)];
|
|
860
876
|
case 3:
|
|
861
877
|
price = _a.sent();
|
|
878
|
+
console.log("\uD83E\uDD8E CoinGecko returned price: $".concat(price));
|
|
862
879
|
if (price > 0) {
|
|
863
|
-
return [2 /*return*/, price];
|
|
880
|
+
return [2 /*return*/, returnSource ? { price: price, source: 'coingecko' } : price];
|
|
864
881
|
}
|
|
882
|
+
// Try CoinMarketCap second (requires API key, very comprehensive)
|
|
883
|
+
console.log("\uD83D\uDCCA CoinGecko failed (price=$0), trying CoinMarketCap for: ".concat(identifiers.cmcSymbol));
|
|
865
884
|
return [4 /*yield*/, get_price_from_coinmarketcap(identifiers.cmcSymbol)];
|
|
866
885
|
case 4:
|
|
867
|
-
// Try CoinMarketCap second (requires API key, very comprehensive)
|
|
868
886
|
price = _a.sent();
|
|
887
|
+
console.log("\uD83D\uDCCA CoinMarketCap returned price: $".concat(price));
|
|
869
888
|
if (price > 0) {
|
|
870
|
-
return [2 /*return*/, price];
|
|
889
|
+
return [2 /*return*/, returnSource ? { price: price, source: 'coinmarketcap' } : price];
|
|
871
890
|
}
|
|
891
|
+
// Try CoinCap last (requires API key, currently rate limited)
|
|
892
|
+
console.log("\uD83D\uDCB0 CoinMarketCap failed (price=$0), trying CoinCap for: ".concat(identifiers.coincapSymbol));
|
|
872
893
|
return [4 /*yield*/, get_price_from_coincap(identifiers.coincapSymbol)];
|
|
873
894
|
case 5:
|
|
874
|
-
// Try CoinCap last (requires API key, currently rate limited)
|
|
875
895
|
price = _a.sent();
|
|
896
|
+
console.log("\uD83D\uDCB0 CoinCap returned price: $".concat(price));
|
|
876
897
|
if (price > 0) {
|
|
877
|
-
return [2 /*return*/, price];
|
|
898
|
+
return [2 /*return*/, returnSource ? { price: price, source: 'coincap' } : price];
|
|
878
899
|
}
|
|
879
900
|
log.warn(tag, "\u274C No price found from any API for: ".concat(caip));
|
|
880
|
-
return [2 /*return*/, 0];
|
|
901
|
+
return [2 /*return*/, returnSource ? { price: 0, source: 'none' } : 0];
|
|
881
902
|
}
|
|
882
903
|
});
|
|
883
904
|
});
|
package/package.json
CHANGED
|
@@ -1,15 +1,16 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@pioneer-platform/markets",
|
|
3
|
-
"version": "8.11.
|
|
3
|
+
"version": "8.11.10",
|
|
4
4
|
"main": "./lib/index.js",
|
|
5
5
|
"types": "./lib/index.d.ts",
|
|
6
6
|
"dependencies": {
|
|
7
7
|
"@pioneer-platform/default-redis": "^8.11.0",
|
|
8
8
|
"@pioneer-platform/loggerdog": "^8.11.0",
|
|
9
9
|
"@pioneer-platform/pioneer-coins": "^9.11.0",
|
|
10
|
-
"@pioneer-platform/pioneer-discovery": "^
|
|
10
|
+
"@pioneer-platform/pioneer-discovery": "^8.11.4",
|
|
11
11
|
"@pioneer-platform/pioneer-types": "^8.11.0",
|
|
12
12
|
"@pioneer-platform/pro-token": "^0.8.0",
|
|
13
|
+
"@shapeshiftoss/caip": "^9.0.0-alpha.0",
|
|
13
14
|
"axios": "^1.6.0",
|
|
14
15
|
"axios-retry": "^3.2.0",
|
|
15
16
|
"dotenv": "^8.2.0"
|