@clonegod/ttd-core 3.1.102 → 3.1.105
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/dist/index.js
CHANGED
|
@@ -235,13 +235,17 @@ const format_token_symbol = (symbol) => {
|
|
|
235
235
|
return /^[A-Z0-9]+$/.test(cleaned) ? cleaned : '';
|
|
236
236
|
};
|
|
237
237
|
exports.format_token_symbol = format_token_symbol;
|
|
238
|
+
const PAIR_SYMBOL_ALIAS = {
|
|
239
|
+
USDC: 'USDT', USD1: 'USDT', USDG: 'USDT',
|
|
240
|
+
WTRX: 'TRX', WSOL: 'SOL', WBTC: 'BTC',
|
|
241
|
+
WETH: 'ETH', WBNB: 'BNB', WOKB: 'OKB',
|
|
242
|
+
};
|
|
238
243
|
const format_pair_symbol = (symbol) => {
|
|
244
|
+
var _a;
|
|
239
245
|
if (!symbol)
|
|
240
246
|
return symbol;
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
.replace('WTRX', 'TRX').replace('WSOL', 'SOL').replace('WBTC', 'BTC')
|
|
244
|
-
.replace('WETH', 'ETH').replace('WBNB', 'BNB').replace('WOKB', 'OKB');
|
|
247
|
+
const s = (0, exports.format_token_symbol)(symbol);
|
|
248
|
+
return (_a = PAIR_SYMBOL_ALIAS[s]) !== null && _a !== void 0 ? _a : s;
|
|
245
249
|
};
|
|
246
250
|
exports.format_pair_symbol = format_pair_symbol;
|
|
247
251
|
const format_unique_orderbook_id = (chain_id, dex_id, pool_id, fee_rate) => {
|
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.get_ton_token_price_info = get_ton_token_price_info;
|
|
13
|
+
require('dotenv').config();
|
|
14
|
+
const index_1 = require("../../index");
|
|
15
|
+
const defi_llama_1 = require("./defi_llama");
|
|
16
|
+
const gecko_terminal_1 = require("./gecko_terminal");
|
|
17
|
+
const price_cache_1 = require("./price_cache");
|
|
18
|
+
function get_ton_token_price_info(addresses, opts) {
|
|
19
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
20
|
+
var _a;
|
|
21
|
+
(0, index_1.log_info)(`get_ton_token_price_info`, addresses);
|
|
22
|
+
const source = (_a = opts === null || opts === void 0 ? void 0 : opts.source) !== null && _a !== void 0 ? _a : 'cache_only';
|
|
23
|
+
const result = new Map();
|
|
24
|
+
const cachedChannel = {
|
|
25
|
+
name: 'CachedPrice',
|
|
26
|
+
fetchFn: price_cache_1.fetchPriceFromCache,
|
|
27
|
+
batchSize: 100,
|
|
28
|
+
batchDelay: 1000,
|
|
29
|
+
};
|
|
30
|
+
const externalChannels = [
|
|
31
|
+
{
|
|
32
|
+
name: 'DefiLlama',
|
|
33
|
+
fetchFn: (address_list) => (0, defi_llama_1.fetchPriceFromDefiLlama)(index_1.CHAIN_ID.TON, address_list),
|
|
34
|
+
batchSize: 10,
|
|
35
|
+
batchDelay: 2000,
|
|
36
|
+
},
|
|
37
|
+
{
|
|
38
|
+
name: 'GeckoTerminal',
|
|
39
|
+
fetchFn: (address_list) => (0, gecko_terminal_1.fetchPriceFromGeckoTerminal)('ton', address_list),
|
|
40
|
+
batchSize: 30,
|
|
41
|
+
batchDelay: 1500,
|
|
42
|
+
},
|
|
43
|
+
];
|
|
44
|
+
const PRICE_CHANNELS = source === 'cache_only' ? [cachedChannel] :
|
|
45
|
+
source === 'cache_first' ? [cachedChannel, ...externalChannels] :
|
|
46
|
+
[...externalChannels];
|
|
47
|
+
const externalHits = [];
|
|
48
|
+
let worklist = [...addresses];
|
|
49
|
+
try {
|
|
50
|
+
for (const channel of PRICE_CHANNELS) {
|
|
51
|
+
if (worklist.length === 0)
|
|
52
|
+
break;
|
|
53
|
+
(0, index_1.log_debug)(`[get_ton_token_price_info] Processing ${worklist.length} tokens using ${channel.name}`);
|
|
54
|
+
const batches = (0, index_1.chunkArray)(worklist, channel.batchSize);
|
|
55
|
+
let remainingAddresses = [...worklist];
|
|
56
|
+
for (let i = 0; i < batches.length; i++) {
|
|
57
|
+
const batch = batches[i];
|
|
58
|
+
if (batch.length === 0)
|
|
59
|
+
continue;
|
|
60
|
+
try {
|
|
61
|
+
const channelResult = yield channel.fetchFn(batch);
|
|
62
|
+
for (const [address, priceInfo] of channelResult.entries()) {
|
|
63
|
+
result.set(address, priceInfo);
|
|
64
|
+
remainingAddresses = remainingAddresses.filter(addr => addr !== address);
|
|
65
|
+
if (channel.name !== 'CachedPrice') {
|
|
66
|
+
externalHits.push({ address, price: priceInfo.price, source: channel.name });
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
catch (error) {
|
|
71
|
+
(0, index_1.log_warn)(`[get_ton_token_price_info] Error processing batch ${i + 1} with ${channel.name}: ${error instanceof Error ? error.message : String(error)}`);
|
|
72
|
+
}
|
|
73
|
+
if (i < batches.length - 1) {
|
|
74
|
+
yield (0, index_1.sleep)(channel.batchDelay);
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
worklist = [...remainingAddresses];
|
|
78
|
+
if (worklist.length === 0)
|
|
79
|
+
break;
|
|
80
|
+
}
|
|
81
|
+
if (externalHits.length > 0) {
|
|
82
|
+
yield (0, price_cache_1.cache_new_market_price_batch)(externalHits);
|
|
83
|
+
}
|
|
84
|
+
if (source === 'cache_only' && worklist.length > 0) {
|
|
85
|
+
(0, price_cache_1.warnPriceCacheMiss)(worklist);
|
|
86
|
+
}
|
|
87
|
+
if (source === 'force_fetch' && result.size === 0) {
|
|
88
|
+
throw new Error(`Unable to get price information for any token: ${addresses.join(', ')}`);
|
|
89
|
+
}
|
|
90
|
+
if (source !== 'cache_only' && worklist.length > 0) {
|
|
91
|
+
(0, index_1.log_warn)(`[get_ton_token_price_info] Failed to get prices for ${worklist.length} tokens after trying all channels: ${worklist.join(', ')}`);
|
|
92
|
+
}
|
|
93
|
+
return result;
|
|
94
|
+
}
|
|
95
|
+
catch (error) {
|
|
96
|
+
if (source === 'force_fetch') {
|
|
97
|
+
throw new Error(`Failed to get token price information: ${error instanceof Error ? error.message : String(error)}`);
|
|
98
|
+
}
|
|
99
|
+
return result;
|
|
100
|
+
}
|
|
101
|
+
});
|
|
102
|
+
}
|
|
@@ -4,6 +4,7 @@ export * from './get_eth_token_price';
|
|
|
4
4
|
export * from './get_solana_token_price';
|
|
5
5
|
export * from './get_tron_token_price';
|
|
6
6
|
export * from './get_sui_token_price';
|
|
7
|
+
export * from './get_ton_token_price';
|
|
7
8
|
export * from './get_xlayer_token_price';
|
|
8
9
|
export * from './price_cache';
|
|
9
10
|
export * from './token_price_syncer';
|
|
@@ -20,6 +20,7 @@ __exportStar(require("./get_eth_token_price"), exports);
|
|
|
20
20
|
__exportStar(require("./get_solana_token_price"), exports);
|
|
21
21
|
__exportStar(require("./get_tron_token_price"), exports);
|
|
22
22
|
__exportStar(require("./get_sui_token_price"), exports);
|
|
23
|
+
__exportStar(require("./get_ton_token_price"), exports);
|
|
23
24
|
__exportStar(require("./get_xlayer_token_price"), exports);
|
|
24
25
|
__exportStar(require("./price_cache"), exports);
|
|
25
26
|
__exportStar(require("./token_price_syncer"), exports);
|