@clonegod/ttd-core 2.0.82 → 2.0.84
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.
|
@@ -8,16 +8,13 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
8
8
|
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
9
|
});
|
|
10
10
|
};
|
|
11
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
12
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
|
-
};
|
|
14
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
12
|
exports.get_bsc_token_price_info = get_bsc_token_price_info;
|
|
16
13
|
require('dotenv').config();
|
|
17
|
-
const axios_1 = __importDefault(require("axios"));
|
|
18
14
|
const index_1 = require("../../index");
|
|
19
15
|
const gecko_terminal_1 = require("./gecko_terminal");
|
|
20
16
|
const price_cache_1 = require("./price_cache");
|
|
17
|
+
const defi_llama_1 = require("./defi_llama");
|
|
21
18
|
function get_bsc_token_price_info(addresses) {
|
|
22
19
|
return __awaiter(this, void 0, void 0, function* () {
|
|
23
20
|
addresses = addresses.map(addr => addr.toLowerCase());
|
|
@@ -30,8 +27,8 @@ function get_bsc_token_price_info(addresses) {
|
|
|
30
27
|
batchDelay: 1000,
|
|
31
28
|
},
|
|
32
29
|
{
|
|
33
|
-
name: '
|
|
34
|
-
fetchFn:
|
|
30
|
+
name: 'DefiLlama',
|
|
31
|
+
fetchFn: (address_list) => (0, defi_llama_1.fetchPriceFromDefiLlama)(index_1.CHAIN_ID.BSC, address_list),
|
|
35
32
|
batchSize: 10,
|
|
36
33
|
batchDelay: 1000,
|
|
37
34
|
},
|
|
@@ -39,14 +36,14 @@ function get_bsc_token_price_info(addresses) {
|
|
|
39
36
|
name: 'GeckoTerminal',
|
|
40
37
|
fetchFn: (address_list) => (0, gecko_terminal_1.fetchPriceFromGeckoTerminal)(index_1.CHAIN_ID.BSC, address_list),
|
|
41
38
|
batchSize: 10,
|
|
42
|
-
batchDelay:
|
|
39
|
+
batchDelay: 1000,
|
|
43
40
|
},
|
|
44
41
|
];
|
|
45
42
|
try {
|
|
46
43
|
for (const channel of PRICE_CHANNELS) {
|
|
47
44
|
if (addresses.length === 0)
|
|
48
45
|
break;
|
|
49
|
-
(0, index_1.
|
|
46
|
+
(0, index_1.log_info)(`[get_token_price_info] Processing ${addresses.length} tokens using ${channel.name}`);
|
|
50
47
|
const batches = (0, index_1.chunkArray)(addresses, channel.batchSize);
|
|
51
48
|
(0, index_1.log_debug)(`[get_token_price_info] Split into ${batches.length} batches of size ${channel.batchSize}`);
|
|
52
49
|
let remainingAddresses = [...addresses];
|
|
@@ -92,52 +89,6 @@ function get_bsc_token_price_info(addresses) {
|
|
|
92
89
|
}
|
|
93
90
|
});
|
|
94
91
|
}
|
|
95
|
-
function fetchPriceFromPancakeSwap(addresses) {
|
|
96
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
97
|
-
const result = new Map();
|
|
98
|
-
const currentTime = (0, index_1.getCurDateTime)();
|
|
99
|
-
const timeout = 10000;
|
|
100
|
-
const maxRetries = 2;
|
|
101
|
-
const retrysleepMs = 500;
|
|
102
|
-
const addressString = addresses.map(addr => `56:${addr}`).join('%2C');
|
|
103
|
-
const url = `https://wallet-api.pancakeswap.com/v1/prices/list/${addressString}`;
|
|
104
|
-
(0, index_1.log_debug)(`[fetchPriceFromPancakeSwap] Requesting PancakeSwap API for ${addresses.length} tokens`);
|
|
105
|
-
let retryCount = 0;
|
|
106
|
-
while (retryCount <= maxRetries) {
|
|
107
|
-
try {
|
|
108
|
-
const response = yield axios_1.default.get(url, { timeout });
|
|
109
|
-
if (response.data) {
|
|
110
|
-
for (const address of addresses) {
|
|
111
|
-
const key = `56:${address}`;
|
|
112
|
-
if (response.data[key] !== undefined) {
|
|
113
|
-
result.set(address, {
|
|
114
|
-
symbol: '',
|
|
115
|
-
address: address,
|
|
116
|
-
price: response.data[key].toString(),
|
|
117
|
-
update_time: currentTime
|
|
118
|
-
});
|
|
119
|
-
}
|
|
120
|
-
}
|
|
121
|
-
(0, index_1.log_debug)(`[fetchPriceFromPancakeSwap] Retrieved prices for ${result.size}/${addresses.length} tokens`);
|
|
122
|
-
}
|
|
123
|
-
else {
|
|
124
|
-
(0, index_1.log_debug)(`[fetchPriceFromPancakeSwap] Invalid response from PancakeSwap for ${addresses.length} tokens`);
|
|
125
|
-
}
|
|
126
|
-
break;
|
|
127
|
-
}
|
|
128
|
-
catch (error) {
|
|
129
|
-
retryCount++;
|
|
130
|
-
(0, index_1.log_warn)(`[fetchPriceFromPancakeSwap] Request failed (attempt ${retryCount}/${maxRetries}): ${error instanceof Error ? error.message : String(error)}`);
|
|
131
|
-
if (retryCount <= maxRetries) {
|
|
132
|
-
const currentRetrysleep = retrysleepMs * retryCount;
|
|
133
|
-
(0, index_1.log_debug)(`[fetchPriceFromPancakeSwap] Retrying in ${currentRetrysleep}ms...`);
|
|
134
|
-
yield (0, index_1.sleep)(currentRetrysleep);
|
|
135
|
-
}
|
|
136
|
-
}
|
|
137
|
-
}
|
|
138
|
-
return result;
|
|
139
|
-
});
|
|
140
|
-
}
|
|
141
92
|
if (require.main === module) {
|
|
142
93
|
(() => __awaiter(void 0, void 0, void 0, function* () {
|
|
143
94
|
(() => __awaiter(void 0, void 0, void 0, function* () {
|
|
@@ -145,8 +96,8 @@ if (require.main === module) {
|
|
|
145
96
|
"0xbb4cdb9cbd36b01bd1cbaebf2de08d9173bc095c",
|
|
146
97
|
"0x55d398326f99059ff775485246999027b3197955",
|
|
147
98
|
"0x0e09fabb73bd3ade0a17ecc321fd13a19e81ce82",
|
|
99
|
+
"0x8263CD1601FE73C066bf49cc09841f35348e3be0",
|
|
148
100
|
];
|
|
149
|
-
console.log(yield get_bsc_token_price_info(addresses));
|
|
150
101
|
}))();
|
|
151
102
|
}))();
|
|
152
103
|
}
|