@clonegod/ttd-sol-common 1.0.170 → 1.0.171

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.
@@ -1,5 +1,6 @@
1
1
  import { FormattedTokenPrice } from "./types";
2
2
  export declare const get_token_price_info: (mints: string[]) => Promise<Map<string, FormattedTokenPrice>>;
3
3
  export declare const get_token_price_info_from_raydium: (mints: string[]) => Promise<Map<string, FormattedTokenPrice>>;
4
- export declare const get_token_price_info_from_jupiter: (mints: string[]) => Promise<Map<string, FormattedTokenPrice>>;
4
+ export declare const get_token_price_info_from_jupiter_v2: (mints: string[]) => Promise<Map<string, FormattedTokenPrice>>;
5
+ export declare const get_token_price_info_from_jupiter_v1: (mints: string[]) => Promise<Map<string, FormattedTokenPrice>>;
5
6
  export declare const get_token_price_info_from_coingecko: (mints: string[]) => Promise<Map<string, FormattedTokenPrice>>;
@@ -12,14 +12,14 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
12
12
  return (mod && mod.__esModule) ? mod : { "default": mod };
13
13
  };
14
14
  Object.defineProperty(exports, "__esModule", { value: true });
15
- exports.get_token_price_info_from_coingecko = exports.get_token_price_info_from_jupiter = exports.get_token_price_info_from_raydium = exports.get_token_price_info = void 0;
15
+ exports.get_token_price_info_from_coingecko = exports.get_token_price_info_from_jupiter_v1 = exports.get_token_price_info_from_jupiter_v2 = exports.get_token_price_info_from_raydium = exports.get_token_price_info = void 0;
16
16
  const dist_1 = require("@clonegod/ttd-common/dist");
17
17
  const axios_1 = __importDefault(require("axios"));
18
18
  const get_token_price_info = (mints) => __awaiter(void 0, void 0, void 0, function* () {
19
19
  let price_map = yield (0, exports.get_token_price_info_from_raydium)(mints);
20
20
  let not_found_arr = mints.filter(address => !price_map.has(address));
21
21
  if (not_found_arr.length > 0) {
22
- let _price_map = yield (0, exports.get_token_price_info_from_jupiter)(not_found_arr);
22
+ let _price_map = yield (0, exports.get_token_price_info_from_jupiter_v2)(not_found_arr);
23
23
  for (let [key, value] of _price_map) {
24
24
  if (value) {
25
25
  price_map.set(key, value);
@@ -31,7 +31,7 @@ const get_token_price_info = (mints) => __awaiter(void 0, void 0, void 0, functi
31
31
  }
32
32
  not_found_arr = mints.filter(address => !price_map.has(address));
33
33
  if (not_found_arr.length > 0) {
34
- let _price_map = yield (0, exports.get_token_price_info_from_coingecko)(not_found_arr);
34
+ let _price_map = yield (0, exports.get_token_price_info_from_jupiter_v1)(not_found_arr);
35
35
  for (let [key, value] of _price_map) {
36
36
  if (value) {
37
37
  price_map.set(key, value);
@@ -75,14 +75,14 @@ const get_token_price_info_from_raydium = (mints) => __awaiter(void 0, void 0, v
75
75
  return price_map;
76
76
  });
77
77
  exports.get_token_price_info_from_raydium = get_token_price_info_from_raydium;
78
- const get_token_price_info_from_jupiter = (mints) => __awaiter(void 0, void 0, void 0, function* () {
78
+ const get_token_price_info_from_jupiter_v2 = (mints) => __awaiter(void 0, void 0, void 0, function* () {
79
79
  let price_map = new Map();
80
80
  let ids_list = (0, dist_1.chunkArray)(mints, 10);
81
81
  for (let ids of ids_list) {
82
82
  try {
83
83
  let url = `https://api.jup.ag/price/v2?ids=${ids.join(',')}`;
84
84
  const res = (yield axios_1.default.get(url)).data;
85
- (0, dist_1.log_debug)(`get_token_price_info_from_jupiter, res=`, res);
85
+ (0, dist_1.log_debug)(`get_token_price_info_from_jupiter_v2, res=`, res);
86
86
  let failed_mints = [];
87
87
  for (let address of ids) {
88
88
  let price_obj = res.data[address];
@@ -100,17 +100,53 @@ const get_token_price_info_from_jupiter = (mints) => __awaiter(void 0, void 0, v
100
100
  }
101
101
  let failed_count = failed_mints.length;
102
102
  if (failed_mints.length > 0) {
103
- (0, dist_1.log_warn)(`get_token_price_info_from_jupiter failed! failed_count=${failed_count}, failed_mints: `, failed_mints);
103
+ (0, dist_1.log_warn)(`get_token_price_info_from_jupiter_v2 failed! failed_count=${failed_count}, failed_mints: `, failed_mints);
104
104
  }
105
105
  }
106
106
  catch (err) {
107
- (0, dist_1.log_error)(`get_token_price_info_from_jupiter error!`, err);
107
+ (0, dist_1.log_error)(`get_token_price_info_from_jupiter_v2 error!`, err);
108
108
  }
109
109
  yield (0, dist_1.sleep)(1000);
110
110
  }
111
111
  return price_map;
112
112
  });
113
- exports.get_token_price_info_from_jupiter = get_token_price_info_from_jupiter;
113
+ exports.get_token_price_info_from_jupiter_v2 = get_token_price_info_from_jupiter_v2;
114
+ const get_token_price_info_from_jupiter_v1 = (mints) => __awaiter(void 0, void 0, void 0, function* () {
115
+ let price_map = new Map();
116
+ let ids_list = (0, dist_1.chunkArray)(mints, 10);
117
+ for (let ids of ids_list) {
118
+ try {
119
+ let url = `https://fe-api.jup.ag/api/v1/prices?list_address=${ids.join(',')}`;
120
+ const res = (yield axios_1.default.get(url)).data;
121
+ (0, dist_1.log_debug)(`get_token_price_info_from_jupiter_v1, res=`, res);
122
+ let failed_mints = [];
123
+ for (let address of ids) {
124
+ let price_obj = res.prices;
125
+ if (!price_obj || !price_obj[address]) {
126
+ failed_mints.push(address);
127
+ continue;
128
+ }
129
+ let price = price_obj[address];
130
+ price_map.set(address, {
131
+ symbol: '',
132
+ address,
133
+ price,
134
+ update_time: (0, dist_1.getCurDateTime)()
135
+ });
136
+ }
137
+ let failed_count = failed_mints.length;
138
+ if (failed_mints.length > 0) {
139
+ (0, dist_1.log_warn)(`get_token_price_info_from_jupiter_v1 failed! failed_count=${failed_count}, failed_mints: `, failed_mints);
140
+ }
141
+ }
142
+ catch (err) {
143
+ (0, dist_1.log_error)(`get_token_price_info_from_jupiter_v1 error!`, err);
144
+ }
145
+ yield (0, dist_1.sleep)(1000);
146
+ }
147
+ return price_map;
148
+ });
149
+ exports.get_token_price_info_from_jupiter_v1 = get_token_price_info_from_jupiter_v1;
114
150
  const get_token_price_info_from_coingecko = (mints) => __awaiter(void 0, void 0, void 0, function* () {
115
151
  let network_id = 'solana';
116
152
  let price_map = new Map();
@@ -141,7 +177,7 @@ const get_token_price_info_from_coingecko = (mints) => __awaiter(void 0, void 0,
141
177
  }
142
178
  }
143
179
  catch (err) {
144
- (0, dist_1.log_error)(`get_token_price_info_from_coingecko error!`, err);
180
+ (0, dist_1.log_error)(`get_token_price_info_from_coingecko error!`, new Error(err.message));
145
181
  }
146
182
  yield (0, dist_1.sleep)(1000);
147
183
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@clonegod/ttd-sol-common",
3
- "version": "1.0.170",
3
+ "version": "1.0.171",
4
4
  "description": "",
5
5
  "main": "dist/index.js",
6
6
  "types": "types/index.d.ts",