@pioneer-platform/markets 8.3.11 → 8.3.13
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.js +120 -17
- package/package.json +13 -11
package/lib/index.js
CHANGED
|
@@ -25,8 +25,8 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
25
25
|
});
|
|
26
26
|
};
|
|
27
27
|
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
28
|
-
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
29
|
-
return g =
|
|
28
|
+
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);
|
|
29
|
+
return g.next = verb(0), g["throw"] = verb(1), g["return"] = verb(2), typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
30
30
|
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
31
31
|
function step(op) {
|
|
32
32
|
if (f) throw new TypeError("Generator is already executing.");
|
|
@@ -66,8 +66,6 @@ var axios = Axios.create({
|
|
|
66
66
|
})
|
|
67
67
|
});
|
|
68
68
|
var axiosRetry = require('axios-retry');
|
|
69
|
-
var _a = require('ethers'), ethers = _a.ethers, BigNumber = _a.BigNumber;
|
|
70
|
-
var _b = require('@uniswap/sdk'), Token = _b.Token, Fetcher = _b.Fetcher, WETH = _b.WETH, Route = _b.Route, Trade = _b.Trade, TradeType = _b.TradeType, TokenAmount = _b.TokenAmount;
|
|
71
69
|
axiosRetry(axios, {
|
|
72
70
|
retries: 5, // number of retries
|
|
73
71
|
retryDelay: function (retryCount) {
|
|
@@ -82,8 +80,8 @@ axiosRetry(axios, {
|
|
|
82
80
|
});
|
|
83
81
|
var ProToken = require("@pioneer-platform/pro-token");
|
|
84
82
|
var log = require('@pioneer-platform/loggerdog')();
|
|
85
|
-
var
|
|
86
|
-
var
|
|
83
|
+
var _a = require("@pioneer-platform/pioneer-coins"), getExplorerAddressUrl = _a.getExplorerAddressUrl, needsMemoByNetwork = _a.needsMemoByNetwork, COIN_MAP_LONG = _a.COIN_MAP_LONG;
|
|
84
|
+
var _b = require('@pioneer-platform/default-redis'), subscriber = _b.subscriber, publisher = _b.publisher, redis = _b.redis, redisQueue = _b.redisQueue;
|
|
87
85
|
var URL_COINCAP = "https://api.coincap.io/v2/";
|
|
88
86
|
var URL_COINGECKO = "https://api.coingecko.com/api/v3/";
|
|
89
87
|
var COINGECKO_API_KEY = process.env['COINGECKO_API_KEY'];
|
|
@@ -120,7 +118,7 @@ module.exports = {
|
|
|
120
118
|
};
|
|
121
119
|
var update_cache = function () {
|
|
122
120
|
return __awaiter(this, void 0, void 0, function () {
|
|
123
|
-
var tag, entries, url, result, allCoinsArray, _loop_1, i, limit, totalAssets, totalPages, page, url_1, result_1, allCoinsArray_2, _loop_2, _i, allCoinsArray_1, coin, e_1;
|
|
121
|
+
var tag, entries, url, result, allCoinsArray, populatedCaips_1, _loop_1, i, limit, totalAssets, totalPages, page, url_1, result_1, allCoinsArray_2, _loop_2, _i, allCoinsArray_1, coin, missingCaips, e_1;
|
|
124
122
|
return __generator(this, function (_a) {
|
|
125
123
|
switch (_a.label) {
|
|
126
124
|
case 0:
|
|
@@ -130,22 +128,29 @@ var update_cache = function () {
|
|
|
130
128
|
_a.trys.push([1, 16, , 17]);
|
|
131
129
|
entries = Object.entries(pioneer_discovery_1.assetData).map(function (_a) {
|
|
132
130
|
var caip = _a[0], asset = _a[1];
|
|
133
|
-
|
|
131
|
+
if (typeof asset === 'object' && asset !== null) {
|
|
132
|
+
return __assign(__assign({}, asset), { caip: caip });
|
|
133
|
+
}
|
|
134
|
+
else {
|
|
135
|
+
throw new Error("Invalid asset type for CAIP ".concat(caip));
|
|
136
|
+
}
|
|
134
137
|
});
|
|
138
|
+
log.debug(tag, "entries: ", entries);
|
|
139
|
+
log.info(tag, "entries: ", entries[0]);
|
|
140
|
+
log.info(tag, "entries: ", entries.length);
|
|
135
141
|
url = URL_COINCAP + 'assets?limit=2000';
|
|
136
142
|
log.debug(tag, "url: ", url);
|
|
137
143
|
return [4 /*yield*/, axios({
|
|
138
144
|
url: url,
|
|
139
145
|
method: 'GET'
|
|
140
|
-
})
|
|
141
|
-
//parse into keys array off ticker
|
|
142
|
-
];
|
|
146
|
+
})];
|
|
143
147
|
case 2:
|
|
144
148
|
result = _a.sent();
|
|
145
149
|
allCoinsArray = result.data.data;
|
|
146
150
|
log.debug(tag, "allCoinsArray: ", allCoinsArray.length);
|
|
151
|
+
populatedCaips_1 = new Set();
|
|
147
152
|
_loop_1 = function (i) {
|
|
148
|
-
var entry, assetsMatchSymbol, j, asset, key
|
|
153
|
+
var entry, assetsMatchSymbol, j, asset, key;
|
|
149
154
|
return __generator(this, function (_b) {
|
|
150
155
|
switch (_b.label) {
|
|
151
156
|
case 0:
|
|
@@ -159,8 +164,9 @@ var update_cache = function () {
|
|
|
159
164
|
key = "coincap:" + asset.caip;
|
|
160
165
|
return [4 /*yield*/, redis.setex(key, 3600, JSON.stringify(entry))];
|
|
161
166
|
case 2:
|
|
162
|
-
|
|
163
|
-
log.
|
|
167
|
+
_b.sent();
|
|
168
|
+
log.info(tag, "saved: " + key + " result: ", result);
|
|
169
|
+
populatedCaips_1.add(asset.caip);
|
|
164
170
|
_b.label = 3;
|
|
165
171
|
case 3:
|
|
166
172
|
j++;
|
|
@@ -210,7 +216,8 @@ var update_cache = function () {
|
|
|
210
216
|
return [4 /*yield*/, redis.setex(key, 3600, JSON.stringify(coin))];
|
|
211
217
|
case 2:
|
|
212
218
|
_d.sent();
|
|
213
|
-
log.
|
|
219
|
+
log.info(tag, "Saved ".concat(coin.symbol, " under ").concat(key));
|
|
220
|
+
populatedCaips_1.add(matchingAsset.caip);
|
|
214
221
|
_d.label = 3;
|
|
215
222
|
case 3:
|
|
216
223
|
_c++;
|
|
@@ -241,7 +248,10 @@ var update_cache = function () {
|
|
|
241
248
|
case 14:
|
|
242
249
|
page++;
|
|
243
250
|
return [3 /*break*/, 7];
|
|
244
|
-
case 15:
|
|
251
|
+
case 15:
|
|
252
|
+
missingCaips = entries.filter(function (asset) { return !populatedCaips_1.has(asset.caip); }).map(function (asset) { return asset.caip; });
|
|
253
|
+
log.info(tag, "Missing CAIPs: ", missingCaips);
|
|
254
|
+
return [2 /*return*/, missingCaips];
|
|
245
255
|
case 16:
|
|
246
256
|
e_1 = _a.sent();
|
|
247
257
|
log.error(e_1);
|
|
@@ -251,6 +261,99 @@ var update_cache = function () {
|
|
|
251
261
|
});
|
|
252
262
|
});
|
|
253
263
|
};
|
|
264
|
+
// const update_cache = async function() {
|
|
265
|
+
// let tag = TAG + ' | update_cache | '
|
|
266
|
+
// try{
|
|
267
|
+
// // log.info(tag,"assetData: ",assetData)
|
|
268
|
+
// // let entries = Object.values(assetData)
|
|
269
|
+
// // @ts-ignore
|
|
270
|
+
// let entries = Object.entries(assetData).map(([caip, asset]) => ({...asset, caip}));
|
|
271
|
+
//
|
|
272
|
+
// log.debug(tag,"entries: ",entries)
|
|
273
|
+
// log.info(tag,"entries: ",entries[0])
|
|
274
|
+
// log.info(tag,"entries: ",entries.length)
|
|
275
|
+
//
|
|
276
|
+
//
|
|
277
|
+
// let url = URL_COINCAP + 'assets?limit=2000'
|
|
278
|
+
// log.debug(tag,"url: ",url)
|
|
279
|
+
// let result = await axios({
|
|
280
|
+
// url: url,
|
|
281
|
+
// method: 'GET'
|
|
282
|
+
// })
|
|
283
|
+
//
|
|
284
|
+
// //parse into keys array off ticker
|
|
285
|
+
// let allCoinsArray = result.data.data
|
|
286
|
+
// log.debug(tag,"allCoinsArray: ",allCoinsArray.length)
|
|
287
|
+
//
|
|
288
|
+
// // let marketInfoCoinGecko = await get_assets_coingecko()
|
|
289
|
+
// for(let i = 0; i < allCoinsArray.length; i++){
|
|
290
|
+
// let entry = allCoinsArray[i]
|
|
291
|
+
// // log.debug(tag,"entry: ",entry)
|
|
292
|
+
//
|
|
293
|
+
// //hits by symbol
|
|
294
|
+
// // @ts-ignore
|
|
295
|
+
// let assetsMatchSymbol = entries.filter(asset => asset.symbol === entry.symbol);
|
|
296
|
+
// //for now ignore this stuffs
|
|
297
|
+
// // if(assetsMatchSymbol.length > 1){ // @ts-ignore
|
|
298
|
+
// // console.log(assetsMatchSymbol[0].symbol+ " assetsMatchSymbol: ",assetsMatchSymbol.length)
|
|
299
|
+
// // console.log("0: ",assetsMatchSymbol[0])
|
|
300
|
+
// // console.log("1: ",assetsMatchSymbol[1])
|
|
301
|
+
// // }
|
|
302
|
+
//
|
|
303
|
+
// for(let j = 0; j < assetsMatchSymbol.length; j++){
|
|
304
|
+
// let asset = assetsMatchSymbol[j]
|
|
305
|
+
// // log.debug(tag,"asset: ",asset)
|
|
306
|
+
// // @ts-ignore
|
|
307
|
+
// let key = "coincap:"+asset.caip
|
|
308
|
+
// // log.debug(tag,"key: ",key)
|
|
309
|
+
// //save cache by caip with 1hour cache
|
|
310
|
+
// let result = await redis.setex(key, 3600, JSON.stringify(entry))
|
|
311
|
+
// log.debug(tag,"saved: "+key+" result: ",result)
|
|
312
|
+
// }
|
|
313
|
+
// }
|
|
314
|
+
//
|
|
315
|
+
// // Handling pagination for CoinGecko
|
|
316
|
+
// const limit = 250; // assets per request
|
|
317
|
+
// const totalAssets = 2000; // total assets to fetch
|
|
318
|
+
// const totalPages = Math.ceil(totalAssets / limit); // calculate total pages needed
|
|
319
|
+
//
|
|
320
|
+
// for (let page = 1; page <= totalPages; page++) {
|
|
321
|
+
// let url = `${URL_COINGECKO}coins/markets?vs_currency=usd&order=market_cap_desc&per_page=${limit}&page=${page}&sparkline=false`;
|
|
322
|
+
// log.debug(tag, "Fetching URL: ", url);
|
|
323
|
+
//
|
|
324
|
+
// let result = await axios.get(url);
|
|
325
|
+
// let allCoinsArray = result.data;
|
|
326
|
+
// log.debug(tag, `Fetched ${allCoinsArray.length} coins for page ${page}`);
|
|
327
|
+
// // log.debug(tag,"allCoinsArray: ",allCoinsArray)
|
|
328
|
+
// // Process each coin
|
|
329
|
+
// for (let coin of allCoinsArray) {
|
|
330
|
+
// // log.debug(tag,"coin: ",coin)
|
|
331
|
+
// let matchingAssets = entries.filter(asset => asset.symbol === coin.symbol.toUpperCase());
|
|
332
|
+
// for (let matchingAsset of matchingAssets) {
|
|
333
|
+
// let key = `coingecko:${matchingAsset.caip}`;
|
|
334
|
+
// await redis.setex(key, 3600, JSON.stringify(coin));
|
|
335
|
+
// log.debug(tag, `Saved ${coin.symbol} under ${key}`);
|
|
336
|
+
// }
|
|
337
|
+
// }
|
|
338
|
+
//
|
|
339
|
+
// // Wait 10 seconds before the next page request if it's not the last page
|
|
340
|
+
// if (page < totalPages) {
|
|
341
|
+
// log.debug(tag, `Waiting 10 seconds before next query...`);
|
|
342
|
+
// await new Promise(resolve => setTimeout(resolve, 30000));
|
|
343
|
+
// }
|
|
344
|
+
// }
|
|
345
|
+
//
|
|
346
|
+
//
|
|
347
|
+
// //mayachain info
|
|
348
|
+
// // const response = await axios.get('https://www.mayascan.org/api/cacao/price?days=1');
|
|
349
|
+
// // const latestCandle = response.data.candles.pop(); // Assuming you want the latest price
|
|
350
|
+
// // let cacaoPrice = latestCandle.close; // Using the close price as the current price
|
|
351
|
+
//
|
|
352
|
+
//
|
|
353
|
+
// }catch(e){
|
|
354
|
+
// log.error(e)
|
|
355
|
+
// }
|
|
356
|
+
// }
|
|
254
357
|
var build_balances = function (marketInfoCoinCap, marketInfoCoinGecko, pubkeys) {
|
|
255
358
|
return __awaiter(this, void 0, void 0, function () {
|
|
256
359
|
var tag, valuesUsd, totalValueUsd, outputBalances, unknownTokens, unPricedTokens, i, entry, proUsdRate, coincap, coingecko, priceUsd, balance, valueUsd, e_2;
|
|
@@ -473,9 +576,9 @@ var get_prices_in_quote = function (assets, quote) {
|
|
|
473
576
|
});
|
|
474
577
|
};
|
|
475
578
|
var get_price = function (asset) {
|
|
476
|
-
var _a, _b, _c, _d;
|
|
477
579
|
return __awaiter(this, void 0, void 0, function () {
|
|
478
580
|
var tag, data, currency, marketData, e_6;
|
|
581
|
+
var _a, _b, _c, _d;
|
|
479
582
|
return __generator(this, function (_e) {
|
|
480
583
|
switch (_e.label) {
|
|
481
584
|
case 0:
|
package/package.json
CHANGED
|
@@ -1,35 +1,37 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@pioneer-platform/markets",
|
|
3
|
-
"version": "8.3.
|
|
3
|
+
"version": "8.3.13",
|
|
4
4
|
"main": "./lib/index.js",
|
|
5
5
|
"types": "./lib/index.d.ts",
|
|
6
6
|
"dependencies": {
|
|
7
|
+
"@pioneer-platform/default-redis": "^8.3.1",
|
|
7
8
|
"@pioneer-platform/loggerdog": "^8.3.1",
|
|
8
|
-
"@pioneer-platform/pioneer-
|
|
9
|
+
"@pioneer-platform/pioneer-coins": "^9.2.26",
|
|
10
|
+
"@pioneer-platform/pioneer-discovery": "^0.0.14",
|
|
9
11
|
"@pioneer-platform/pioneer-types": "^8.3.1",
|
|
10
12
|
"@pioneer-platform/pro-token": "^0.0.3",
|
|
11
|
-
"axios": "^1.
|
|
13
|
+
"axios": "^1.6.0",
|
|
12
14
|
"axios-retry": "^3.2.0",
|
|
13
15
|
"dotenv": "^8.2.0"
|
|
14
16
|
},
|
|
15
17
|
"scripts": {
|
|
16
|
-
"npm": "
|
|
17
|
-
"test": "
|
|
18
|
+
"npm": "pnpm i",
|
|
19
|
+
"test": "pnpm run build && node __tests__/test-module.js",
|
|
18
20
|
"build": "tsc -p .",
|
|
19
|
-
"build:watch": "
|
|
20
|
-
"prepublish": "
|
|
21
|
-
"refresh": "rm -rf ./node_modules ./package-lock.json &&
|
|
21
|
+
"build:watch": "pnpm run build && onchange 'src/**/*.ts' -- pnpm run build",
|
|
22
|
+
"prepublish": "pnpm run build",
|
|
23
|
+
"refresh": "rm -rf ./node_modules ./package-lock.json && pnpm install"
|
|
22
24
|
},
|
|
23
25
|
"devDependencies": {
|
|
24
26
|
"@types/jest": "^25.2.3",
|
|
25
|
-
"@types/node": "^
|
|
27
|
+
"@types/node": "^18.16.0",
|
|
26
28
|
"@types/source-map-support": "^0.5.3",
|
|
27
29
|
"jest": "^26.4.2",
|
|
28
30
|
"onchange": "^7.0.2",
|
|
29
31
|
"serve": "^11.3.2",
|
|
30
32
|
"source-map-support": "^0.5.19",
|
|
31
33
|
"ts-jest": "^29.0.5",
|
|
32
|
-
"typescript": "^5.0.
|
|
34
|
+
"typescript": "^5.0.4"
|
|
33
35
|
},
|
|
34
36
|
"gitHead": "aeae28273014ab69b42f22abec159c6693a56c40"
|
|
35
|
-
}
|
|
37
|
+
}
|