@clonegod/ttd-core 2.0.62 → 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/cache/arb_cache.d.ts +1 -1
- package/dist/cache/arb_cache.js +2 -2
- package/dist/index.d.ts +6 -2
- package/dist/index.js +4 -0
- package/dist/token/price/get_xlayer_token_price.d.ts +2 -0
- package/dist/token/price/get_xlayer_token_price.js +104 -0
- package/dist/token/price/index.d.ts +1 -0
- package/dist/token/price/index.js +1 -0
- package/package.json +1 -1
|
@@ -76,5 +76,5 @@ export declare class ArbCache {
|
|
|
76
76
|
get_trade_dex_pool_list(dex_id_list: string[], trade_runtime: TradeRuntimeType): Promise<StandardPoolInfoType[]>;
|
|
77
77
|
get_group_trade_pair_info(chain_id: CHAIN_ID, group_id: string, pair: string): Promise<Map<string, StandardPairType>>;
|
|
78
78
|
get_all_trade_tokens(force_refresh?: boolean): Promise<StandardTokenInfoType[]>;
|
|
79
|
-
get_all_trade_pools(group_id?: string): Promise<StandardPoolInfoType[]>;
|
|
79
|
+
get_all_trade_pools(group_id?: string, force_refresh?: boolean): Promise<StandardPoolInfoType[]>;
|
|
80
80
|
}
|
package/dist/cache/arb_cache.js
CHANGED
|
@@ -978,12 +978,12 @@ class ArbCache {
|
|
|
978
978
|
});
|
|
979
979
|
}
|
|
980
980
|
get_all_trade_pools() {
|
|
981
|
-
return __awaiter(this, arguments, void 0, function* (group_id = '') {
|
|
981
|
+
return __awaiter(this, arguments, void 0, function* (group_id = '', force_refresh = true) {
|
|
982
982
|
let pools = [];
|
|
983
983
|
let group_id_list = yield this.get_trade_group_id_list();
|
|
984
984
|
group_id_list = group_id_list.filter(gid => (0, index_1.isEmpty)(group_id) || gid === group_id);
|
|
985
985
|
for (let group_id of group_id_list) {
|
|
986
|
-
let trade_group_conifg = yield this.get_trade_service_by_group_id(group_id);
|
|
986
|
+
let trade_group_conifg = yield this.get_trade_service_by_group_id(group_id, force_refresh);
|
|
987
987
|
let { pair_list } = trade_group_conifg;
|
|
988
988
|
let trade_group_pool_id_list = [];
|
|
989
989
|
for (let trade_pair of pair_list) {
|
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);
|