@clonegod/ttd-core 3.1.95 → 3.1.97
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.
|
@@ -15,16 +15,22 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
15
15
|
exports.get_eth_token_price_info = get_eth_token_price_info;
|
|
16
16
|
require('dotenv').config();
|
|
17
17
|
const axios_1 = __importDefault(require("axios"));
|
|
18
|
-
const chains_1 = require("../../chains");
|
|
19
18
|
const index_1 = require("../../index");
|
|
20
19
|
const defi_llama_1 = require("./defi_llama");
|
|
21
20
|
const gecko_terminal_1 = require("./gecko_terminal");
|
|
22
21
|
const price_cache_1 = require("./price_cache");
|
|
23
22
|
function get_eth_token_price_info(evm_chain_info, addresses, opts) {
|
|
24
23
|
return __awaiter(this, void 0, void 0, function* () {
|
|
25
|
-
var _a;
|
|
24
|
+
var _a, _b;
|
|
26
25
|
const source = (_a = opts === null || opts === void 0 ? void 0 : opts.source) !== null && _a !== void 0 ? _a : 'cache_only';
|
|
27
26
|
addresses = addresses.map(addr => addr.toLowerCase());
|
|
27
|
+
const ZERO_ADDR = '0x0000000000000000000000000000000000000000';
|
|
28
|
+
const wrappedNativeAddr = (_b = evm_chain_info.weth_addr) === null || _b === void 0 ? void 0 : _b.toLowerCase();
|
|
29
|
+
const wantsNative = !!wrappedNativeAddr && addresses.includes(ZERO_ADDR);
|
|
30
|
+
if (wantsNative) {
|
|
31
|
+
addresses = addresses.map(a => a === ZERO_ADDR ? wrappedNativeAddr : a);
|
|
32
|
+
addresses = Array.from(new Set(addresses));
|
|
33
|
+
}
|
|
28
34
|
const result = new Map();
|
|
29
35
|
const cachedChannel = {
|
|
30
36
|
name: 'CachedPrice',
|
|
@@ -104,6 +110,11 @@ function get_eth_token_price_info(evm_chain_info, addresses, opts) {
|
|
|
104
110
|
if (source !== 'cache_only' && addresses.length > 0) {
|
|
105
111
|
(0, index_1.log_warn)(`[get_token_price_info] Failed to get prices for ${addresses.length} tokens after trying all channels: ${addresses.join(', ')}`);
|
|
106
112
|
}
|
|
113
|
+
if (wantsNative) {
|
|
114
|
+
const wrappedInfo = result.get(wrappedNativeAddr);
|
|
115
|
+
if (wrappedInfo)
|
|
116
|
+
result.set(ZERO_ADDR, wrappedInfo);
|
|
117
|
+
}
|
|
107
118
|
(0, index_1.log_debug)(`[get_token_price_info] Completed price fetching for ${result.size} tokens`);
|
|
108
119
|
return result;
|
|
109
120
|
}
|
|
@@ -178,15 +189,4 @@ function fetchPriceFromUniSwap(chain_name, addresses) {
|
|
|
178
189
|
});
|
|
179
190
|
}
|
|
180
191
|
if (require.main === module) {
|
|
181
|
-
(() => __awaiter(void 0, void 0, void 0, function* () {
|
|
182
|
-
let evm_chain_info = chains_1.EvmChainConfig.ROBINHOOD;
|
|
183
|
-
let addresses = [
|
|
184
|
-
"0x0bd7d308f8e1639fab988df18a8011f41eacad73",
|
|
185
|
-
"0x5fc5360d0400a0fd4f2af552add042d716f1d168".toLowerCase(),
|
|
186
|
-
"0x020bfc650a365f8bb26819deaabf3e21291018b4".toLowerCase(),
|
|
187
|
-
];
|
|
188
|
-
console.log(yield get_eth_token_price_info(evm_chain_info, addresses));
|
|
189
|
-
console.log(yield fetchPriceFromUniSwap(evm_chain_info.chain_full_name, addresses));
|
|
190
|
-
console.log(yield (0, gecko_terminal_1.fetchPriceFromGeckoTerminal)(evm_chain_info.chain_short_name, addresses));
|
|
191
|
-
}))();
|
|
192
192
|
}
|