@clonegod/ttd-core 2.0.63 → 2.0.64
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.d.ts
CHANGED
|
@@ -34,7 +34,8 @@ export declare enum CHAIN_ID {
|
|
|
34
34
|
OPTIMISM = "OPTIMISM",
|
|
35
35
|
LINEA = "LINEA",
|
|
36
36
|
TRON = "TRON",
|
|
37
|
-
SONIC = "SONIC"
|
|
37
|
+
SONIC = "SONIC",
|
|
38
|
+
XLAYER = "XLAYER"
|
|
38
39
|
}
|
|
39
40
|
export declare enum DEX_ID {
|
|
40
41
|
SUNSWAP_AMM = "SUNSWAP-AMM",
|
|
@@ -60,7 +61,10 @@ export declare enum DEX_ID {
|
|
|
60
61
|
LFJ_V1 = "LFJ-V1",
|
|
61
62
|
LFJ_V2 = "LFJ-V2",
|
|
62
63
|
BLACKHOLE_V2 = "BLACKHOLE-V2",
|
|
63
|
-
BLACKHOLE_V3 = "BLACKHOLE-V3"
|
|
64
|
+
BLACKHOLE_V3 = "BLACKHOLE-V3",
|
|
65
|
+
POTATO_AMM = "POTATO-AMM",
|
|
66
|
+
DYOR_AMM = "DYOR-AMM",
|
|
67
|
+
DYOR_CLMM = "DYOR-CLMM"
|
|
64
68
|
}
|
|
65
69
|
export declare enum GROUP_ID {
|
|
66
70
|
TRON_DEV1 = "TRON-DEV1",
|
package/dist/index.js
CHANGED
|
@@ -118,6 +118,7 @@ var CHAIN_ID;
|
|
|
118
118
|
CHAIN_ID["LINEA"] = "LINEA";
|
|
119
119
|
CHAIN_ID["TRON"] = "TRON";
|
|
120
120
|
CHAIN_ID["SONIC"] = "SONIC";
|
|
121
|
+
CHAIN_ID["XLAYER"] = "XLAYER";
|
|
121
122
|
})(CHAIN_ID || (exports.CHAIN_ID = CHAIN_ID = {}));
|
|
122
123
|
var DEX_ID;
|
|
123
124
|
(function (DEX_ID) {
|
|
@@ -145,6 +146,9 @@ var DEX_ID;
|
|
|
145
146
|
DEX_ID["LFJ_V2"] = "LFJ-V2";
|
|
146
147
|
DEX_ID["BLACKHOLE_V2"] = "BLACKHOLE-V2";
|
|
147
148
|
DEX_ID["BLACKHOLE_V3"] = "BLACKHOLE-V3";
|
|
149
|
+
DEX_ID["POTATO_AMM"] = "POTATO-AMM";
|
|
150
|
+
DEX_ID["DYOR_AMM"] = "DYOR-AMM";
|
|
151
|
+
DEX_ID["DYOR_CLMM"] = "DYOR-CLMM";
|
|
148
152
|
})(DEX_ID || (exports.DEX_ID = DEX_ID = {}));
|
|
149
153
|
var GROUP_ID;
|
|
150
154
|
(function (GROUP_ID) {
|
|
@@ -0,0 +1,104 @@
|
|
|
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_xlayer_token_price_info = get_xlayer_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_xlayer_token_price_info(addresses) {
|
|
19
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
20
|
+
addresses = addresses.map(addr => addr.toLowerCase());
|
|
21
|
+
(0, index_1.log_info)(`get_xlayer_token_price_info`, addresses);
|
|
22
|
+
const result = new Map();
|
|
23
|
+
const PRICE_CHANNELS = [
|
|
24
|
+
{
|
|
25
|
+
name: 'CachedPrice',
|
|
26
|
+
fetchFn: price_cache_1.fetchPriceFromCache,
|
|
27
|
+
batchSize: 100,
|
|
28
|
+
batchDelay: 1000,
|
|
29
|
+
},
|
|
30
|
+
{
|
|
31
|
+
name: 'DefiLlama',
|
|
32
|
+
fetchFn: (address_list) => (0, defi_llama_1.fetchPriceFromDefiLlama)(index_1.CHAIN_ID.XLAYER, address_list),
|
|
33
|
+
batchSize: 10,
|
|
34
|
+
batchDelay: 2000,
|
|
35
|
+
},
|
|
36
|
+
{
|
|
37
|
+
name: 'GeckoTerminal',
|
|
38
|
+
fetchFn: (address_list) => (0, gecko_terminal_1.fetchPriceFromGeckoTerminal)('x-layer', address_list),
|
|
39
|
+
batchSize: 10,
|
|
40
|
+
batchDelay: 2000,
|
|
41
|
+
},
|
|
42
|
+
];
|
|
43
|
+
try {
|
|
44
|
+
for (const channel of PRICE_CHANNELS) {
|
|
45
|
+
if (addresses.length === 0)
|
|
46
|
+
break;
|
|
47
|
+
(0, index_1.log_debug)(`[get_token_price_info] Processing ${addresses.length} tokens using ${channel.name}`);
|
|
48
|
+
const batches = (0, index_1.chunkArray)(addresses, channel.batchSize);
|
|
49
|
+
(0, index_1.log_debug)(`[get_token_price_info] Split into ${batches.length} batches of size ${channel.batchSize}`);
|
|
50
|
+
let remainingAddresses = [...addresses];
|
|
51
|
+
for (let i = 0; i < batches.length; i++) {
|
|
52
|
+
const batch = batches[i];
|
|
53
|
+
if (batch.length === 0)
|
|
54
|
+
continue;
|
|
55
|
+
(0, index_1.log_debug)(`[get_token_price_info] Processing batch ${i + 1}/${batches.length} (${batch.length} tokens) with ${channel.name}`);
|
|
56
|
+
try {
|
|
57
|
+
const channelResult = yield channel.fetchFn(batch);
|
|
58
|
+
for (const [address, priceInfo] of channelResult.entries()) {
|
|
59
|
+
result.set(address, priceInfo);
|
|
60
|
+
remainingAddresses = remainingAddresses.filter(addr => addr !== address);
|
|
61
|
+
if (channel.name !== 'CachedPrice') {
|
|
62
|
+
(0, price_cache_1.cache_new_market_price)(address, priceInfo.price, channel.name);
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
(0, index_1.log_debug)(`[get_token_price_info] ${channel.name} found prices for ${channelResult.size}/${batch.length} tokens in batch ${i + 1}`);
|
|
66
|
+
}
|
|
67
|
+
catch (error) {
|
|
68
|
+
(0, index_1.log_warn)(`[get_token_price_info] Error processing batch ${i + 1} with ${channel.name}: ${error instanceof Error ? error.message : String(error)}`);
|
|
69
|
+
}
|
|
70
|
+
if (i < batches.length - 1) {
|
|
71
|
+
yield (0, index_1.sleep)(channel.batchDelay);
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
addresses = [...remainingAddresses];
|
|
75
|
+
if (addresses.length === 0) {
|
|
76
|
+
(0, index_1.log_debug)(`[get_token_price_info] All token prices retrieved using ${channel.name}`);
|
|
77
|
+
break;
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
if (result.size === 0) {
|
|
81
|
+
throw new Error(`Unable to get price information for any token: ${addresses.join(', ')}`);
|
|
82
|
+
}
|
|
83
|
+
if (addresses.length > 0) {
|
|
84
|
+
(0, index_1.log_warn)(`[get_token_price_info] Failed to get prices for ${addresses.length} tokens after trying all channels: ${addresses.join(', ')}`);
|
|
85
|
+
}
|
|
86
|
+
(0, index_1.log_debug)(`[get_token_price_info] Completed price fetching for ${result.size} tokens`);
|
|
87
|
+
return result;
|
|
88
|
+
}
|
|
89
|
+
catch (error) {
|
|
90
|
+
throw new Error(`Failed to get token price information: ${error instanceof Error ? error.message : String(error)}`);
|
|
91
|
+
}
|
|
92
|
+
});
|
|
93
|
+
}
|
|
94
|
+
if (require.main === module) {
|
|
95
|
+
(() => __awaiter(void 0, void 0, void 0, function* () {
|
|
96
|
+
let addresses = [
|
|
97
|
+
"0xe538905cf8410324e03A5A23C1c177a474D59b2b".toLowerCase(),
|
|
98
|
+
"0x1E4a5963aBFD975d8c9021ce480b42188849D41d".toLowerCase(),
|
|
99
|
+
"0x74b7F16337b8972027F6196A17a631aC6dE26d22".toLowerCase(),
|
|
100
|
+
"0x0cc24c51BF89c00c5afFBfCf5E856C25ecBdb48e".toLowerCase(),
|
|
101
|
+
];
|
|
102
|
+
console.log(yield get_xlayer_token_price_info(addresses));
|
|
103
|
+
}))();
|
|
104
|
+
}
|
|
@@ -19,3 +19,4 @@ __exportStar(require("./get_eth_token_price"), exports);
|
|
|
19
19
|
__exportStar(require("./get_solana_token_price"), exports);
|
|
20
20
|
__exportStar(require("./get_tron_token_price"), exports);
|
|
21
21
|
__exportStar(require("./get_sui_token_price"), exports);
|
|
22
|
+
__exportStar(require("./get_xlayer_token_price"), exports);
|