@clonegod/ttd-core 3.1.17 → 3.1.19
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/alert/reporter.js +12 -6
- package/dist/analyze/index.d.ts +5 -3
- package/dist/analyze/index.js +81 -19
- package/dist/analyze/ws_client.d.ts +15 -0
- package/dist/analyze/ws_client.js +88 -0
- package/dist/app_config/AppConfig.js +2 -4
- package/dist/app_config/EnvArgs.d.ts +22 -0
- package/dist/app_config/EnvArgs.js +45 -38
- package/dist/app_config/core_env.d.ts +3 -0
- package/dist/app_config/core_env.js +14 -0
- package/dist/app_config/env_loader.d.ts +3 -3
- package/dist/app_config/env_loader.js +8 -17
- package/dist/app_config/env_registry.js +25 -20
- package/dist/app_config/index.d.ts +1 -0
- package/dist/app_config/index.js +1 -0
- package/dist/cache/arb_cache.d.ts +1 -4
- package/dist/cache/arb_cache.js +10 -70
- package/dist/cache/arb_event_sub.js +2 -1
- package/dist/constants/service_ports.d.ts +0 -1
- package/dist/constants/service_ports.js +0 -1
- package/dist/index.d.ts +2 -4
- package/dist/index.js +17 -28
- package/dist/market_price/estimate_token_amount.js +14 -14
- package/dist/pool/cache_pool_config.js +7 -3
- package/dist/quote/on_quote_response.d.ts +0 -1
- package/dist/quote/on_quote_response.js +3 -16
- package/dist/quote/to_price_message.js +2 -1
- package/dist/redis/redis_client.d.ts +1 -0
- package/dist/redis/redis_client.js +8 -3
- package/dist/redis/redis_connection.js +4 -2
- package/dist/token/cache_token_config.js +6 -2
- package/dist/token/fixed_symbol_address.js +4 -3
- package/dist/token/price/get_bsc_token_price.js +1 -1
- package/dist/token/price/get_eth_token_price.d.ts +1 -1
- package/dist/token/price/get_eth_token_price.js +1 -1
- package/dist/token/price/get_solana_token_price.js +3 -3
- package/dist/token/zh_pinyin_map.js +4 -3
- package/dist/trade/abstract_tx_check.js +1 -1
- package/dist/trade/handle_order_message.js +1 -1
- package/dist/util/crypto.js +2 -2
- package/dist/util/ip_util.js +9 -3
- package/dist/ws/ws_client.js +14 -14
- package/package.json +1 -1
- package/types/index.d.ts +0 -40
- package/dist/cache/redis_client.d.ts +0 -3
- package/dist/cache/redis_client.js +0 -45
- package/dist/cache/redis_cmd.d.ts +0 -328
- package/dist/cache/redis_cmd.js +0 -285
- package/dist/chains/evm_gas_options.d.ts +0 -9
- package/dist/chains/evm_gas_options.js +0 -2
- package/dist/util/config_center_http.d.ts +0 -1
- package/dist/util/config_center_http.js +0 -14
- package/dist/ws/ws_client_example.d.ts +0 -5
- package/dist/ws/ws_client_example.js +0 -69
|
@@ -16,9 +16,9 @@ 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
18
|
const index_1 = require("../../index");
|
|
19
|
+
const defi_llama_1 = require("./defi_llama");
|
|
19
20
|
const gecko_terminal_1 = require("./gecko_terminal");
|
|
20
21
|
const price_cache_1 = require("./price_cache");
|
|
21
|
-
const defi_llama_1 = require("./defi_llama");
|
|
22
22
|
function get_eth_token_price_info(evm_chain_info, addresses) {
|
|
23
23
|
return __awaiter(this, void 0, void 0, function* () {
|
|
24
24
|
addresses = addresses.map(addr => addr.toLowerCase());
|
|
@@ -13,7 +13,6 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
13
13
|
};
|
|
14
14
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
15
|
exports.get_solana_token_price_info = get_solana_token_price_info;
|
|
16
|
-
require('dotenv').config();
|
|
17
16
|
const axios_1 = __importDefault(require("axios"));
|
|
18
17
|
const index_1 = require("../../index");
|
|
19
18
|
const gecko_terminal_1 = require("./gecko_terminal");
|
|
@@ -107,7 +106,8 @@ function fetchPriceFromJupiter(addresses) {
|
|
|
107
106
|
const timeout = 6000;
|
|
108
107
|
const maxRetries = 1;
|
|
109
108
|
const retrysleepMs = 1000;
|
|
110
|
-
const
|
|
109
|
+
const jupBase = process.env.JUPITER_PRICE_API || 'https://api.jup.ag/price/v3';
|
|
110
|
+
const url = jupBase + `?ids=${addresses.join(',')}`;
|
|
111
111
|
(0, index_1.log_debug)(`[fetchPriceFromJupiter] Requesting Jupiter API for ${addresses.length} tokens`);
|
|
112
112
|
let attempt = 0;
|
|
113
113
|
while (attempt <= maxRetries) {
|
|
@@ -115,7 +115,7 @@ function fetchPriceFromJupiter(addresses) {
|
|
|
115
115
|
attempt++;
|
|
116
116
|
const response = yield axios_1.default.get(url, {
|
|
117
117
|
headers: {
|
|
118
|
-
'x-api-key': process.env.JUPITER_API_KEY
|
|
118
|
+
'x-api-key': process.env.JUPITER_API_KEY || ''
|
|
119
119
|
},
|
|
120
120
|
timeout,
|
|
121
121
|
});
|
|
@@ -5,17 +5,18 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
exports.get_zh_pinyin_map = void 0;
|
|
7
7
|
exports.replace_zh_symbols = replace_zh_symbols;
|
|
8
|
-
require('dotenv').config();
|
|
9
8
|
const os_1 = __importDefault(require("os"));
|
|
9
|
+
const core_env_1 = require("../app_config/core_env");
|
|
10
10
|
const path_1 = __importDefault(require("path"));
|
|
11
11
|
const index_1 = require("../index");
|
|
12
12
|
let _first_load_logged = false;
|
|
13
13
|
const get_zh_pinyin_map = () => {
|
|
14
|
-
const
|
|
14
|
+
const coreEnv = (0, core_env_1.getCoreEnv)();
|
|
15
|
+
const chain_id = coreEnv.chain_id;
|
|
15
16
|
if (!chain_id) {
|
|
16
17
|
return [];
|
|
17
18
|
}
|
|
18
|
-
const filepath =
|
|
19
|
+
const filepath = coreEnv.zh_pinyin_map_file ||
|
|
19
20
|
path_1.default.join(os_1.default.homedir(), 'data', 'onchain_data', chain_id.toLowerCase(), 'zh_pinyin_map.json');
|
|
20
21
|
let list = [];
|
|
21
22
|
try {
|
|
@@ -148,7 +148,7 @@ class AbstractTransactionResultCheck {
|
|
|
148
148
|
execution: trade_extra_info,
|
|
149
149
|
c_id
|
|
150
150
|
};
|
|
151
|
-
(0, analyze_1.
|
|
151
|
+
(0, analyze_1.report_data_to_analyze)('TradeResultType', trade_result);
|
|
152
152
|
return trade_result;
|
|
153
153
|
}
|
|
154
154
|
}
|
|
@@ -115,7 +115,7 @@ const handle_order_message = (trade_appconfig, trade_instance, tx_result_checker
|
|
|
115
115
|
.catch(err => {
|
|
116
116
|
logger.warn('cache order submit result, error!', { order_msg, order_submit_result, err });
|
|
117
117
|
});
|
|
118
|
-
(0, analyze_1.
|
|
118
|
+
(0, analyze_1.report_data_to_analyze)('OrderMessageType', order_msg_with_result);
|
|
119
119
|
}
|
|
120
120
|
});
|
|
121
121
|
exports.handle_order_message = handle_order_message;
|
package/dist/util/crypto.js
CHANGED
|
@@ -5,10 +5,10 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
exports.encrypt = encrypt;
|
|
7
7
|
exports.decrypt = decrypt;
|
|
8
|
-
require('dotenv').config();
|
|
9
8
|
const crypto_1 = __importDefault(require("crypto"));
|
|
9
|
+
const core_env_1 = require("../app_config/core_env");
|
|
10
10
|
function getEncryptionKey() {
|
|
11
|
-
const envKey =
|
|
11
|
+
const envKey = (0, core_env_1.getCoreEnv)().encryption_key;
|
|
12
12
|
if (envKey && envKey.length >= 32) {
|
|
13
13
|
return envKey.substring(0, 32);
|
|
14
14
|
}
|
package/dist/util/ip_util.js
CHANGED
|
@@ -38,11 +38,14 @@ exports.getNextIP = getNextIP;
|
|
|
38
38
|
exports.getCurrentIpList = getCurrentIpList;
|
|
39
39
|
require('dotenv').config();
|
|
40
40
|
const os = __importStar(require("os"));
|
|
41
|
+
const core_env_1 = require("../app_config/core_env");
|
|
41
42
|
let IP_LIST = getServerIpList();
|
|
42
43
|
let ip_counter = 0;
|
|
43
44
|
function getProxyIpFromEnv() {
|
|
44
|
-
|
|
45
|
-
|
|
45
|
+
const coreEnv = (0, core_env_1.getCoreEnv)();
|
|
46
|
+
const raw = coreEnv.server_ip_list || '';
|
|
47
|
+
if (raw) {
|
|
48
|
+
const ipList = String(raw).split(',')
|
|
46
49
|
.map(ip => ip.trim())
|
|
47
50
|
.filter(ip => ip.length > 0);
|
|
48
51
|
if (ipList.length > 0) {
|
|
@@ -52,7 +55,10 @@ function getProxyIpFromEnv() {
|
|
|
52
55
|
return [];
|
|
53
56
|
}
|
|
54
57
|
function getProxyIpFromLocal() {
|
|
55
|
-
|
|
58
|
+
var _a;
|
|
59
|
+
const coreEnv = (0, core_env_1.getCoreEnv)();
|
|
60
|
+
const prefixRaw = (_a = coreEnv.ip_exclude_prefix) !== null && _a !== void 0 ? _a : '192.168';
|
|
61
|
+
const exclude_ip_prefix_arr = String(prefixRaw || '192.168').split(',').map(p => p.trim());
|
|
56
62
|
const ips = [];
|
|
57
63
|
const interfaces = os.networkInterfaces();
|
|
58
64
|
for (const devName in interfaces) {
|
package/dist/ws/ws_client.js
CHANGED
|
@@ -13,7 +13,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
13
13
|
};
|
|
14
14
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
15
|
exports.WebSocketClient = void 0;
|
|
16
|
-
const
|
|
16
|
+
const __1 = require("..");
|
|
17
17
|
const ws_1 = __importDefault(require("ws"));
|
|
18
18
|
class WebSocketClient {
|
|
19
19
|
constructor(url, options = {}) {
|
|
@@ -26,11 +26,11 @@ class WebSocketClient {
|
|
|
26
26
|
this.options = Object.assign({ reconnectInterval: 3000, rejectUnauthorized: false, keepAlive: false, keepAliveInterval: 30000 }, options);
|
|
27
27
|
}
|
|
28
28
|
connect() {
|
|
29
|
-
(0,
|
|
29
|
+
(0, __1.log_info)(`Connecting to ${this.url}`);
|
|
30
30
|
try {
|
|
31
31
|
this.ws = new ws_1.default(this.url, { headers: this.options.headers });
|
|
32
32
|
this.ws.on('open', () => {
|
|
33
|
-
(0,
|
|
33
|
+
(0, __1.log_info)('ws connected');
|
|
34
34
|
this.isReconnecting = false;
|
|
35
35
|
this.startKeepAlive();
|
|
36
36
|
if (this.onOpenCallback)
|
|
@@ -43,20 +43,20 @@ class WebSocketClient {
|
|
|
43
43
|
this.onMessageCallback(data);
|
|
44
44
|
}
|
|
45
45
|
catch (err) {
|
|
46
|
-
(0,
|
|
46
|
+
(0, __1.log_error)('Invalid message format:', err);
|
|
47
47
|
}
|
|
48
48
|
});
|
|
49
49
|
this.ws.on('close', (code, reason) => {
|
|
50
|
-
(0,
|
|
50
|
+
(0, __1.log_warn)(`ws disconnected: ${code} - ${reason.toString()}`);
|
|
51
51
|
this.reconnect();
|
|
52
52
|
});
|
|
53
53
|
this.ws.on('error', (err) => {
|
|
54
|
-
(0,
|
|
54
|
+
(0, __1.log_error)('ws error:', err);
|
|
55
55
|
this.reconnect();
|
|
56
56
|
});
|
|
57
57
|
}
|
|
58
58
|
catch (error) {
|
|
59
|
-
(0,
|
|
59
|
+
(0, __1.log_error)('Failed to create WebSocket:', error);
|
|
60
60
|
this.reconnect();
|
|
61
61
|
}
|
|
62
62
|
}
|
|
@@ -66,8 +66,8 @@ class WebSocketClient {
|
|
|
66
66
|
return;
|
|
67
67
|
}
|
|
68
68
|
this.isReconnecting = true;
|
|
69
|
-
(0,
|
|
70
|
-
yield (0,
|
|
69
|
+
(0, __1.log_info)(`Reconnecting in ${this.options.reconnectInterval}ms`);
|
|
70
|
+
yield (0, __1.sleep)(this.options.reconnectInterval);
|
|
71
71
|
this.forceCleanup();
|
|
72
72
|
this.connect();
|
|
73
73
|
});
|
|
@@ -84,7 +84,7 @@ class WebSocketClient {
|
|
|
84
84
|
return true;
|
|
85
85
|
}
|
|
86
86
|
else {
|
|
87
|
-
(0,
|
|
87
|
+
(0, __1.log_warn)('ws is not connected, you need connect first, then send message');
|
|
88
88
|
return false;
|
|
89
89
|
}
|
|
90
90
|
}
|
|
@@ -99,7 +99,7 @@ class WebSocketClient {
|
|
|
99
99
|
}
|
|
100
100
|
}
|
|
101
101
|
catch (error) {
|
|
102
|
-
(0,
|
|
102
|
+
(0, __1.log_warn)(`Error closing WebSocket: ${error.message}`);
|
|
103
103
|
}
|
|
104
104
|
this.ws = null;
|
|
105
105
|
}
|
|
@@ -113,11 +113,11 @@ class WebSocketClient {
|
|
|
113
113
|
}
|
|
114
114
|
this.stopKeepAlive();
|
|
115
115
|
const interval = this.options.keepAliveInterval || 30000;
|
|
116
|
-
(0,
|
|
116
|
+
(0, __1.log_info)(`Starting keepAlive with interval: ${interval}ms`);
|
|
117
117
|
this.keepAliveTimer = setInterval(() => {
|
|
118
118
|
if (this.ws && this.ws.readyState === ws_1.default.OPEN) {
|
|
119
119
|
this.ws.ping();
|
|
120
|
-
(0,
|
|
120
|
+
(0, __1.log_info)('KeepAlive ping sent');
|
|
121
121
|
}
|
|
122
122
|
}, interval);
|
|
123
123
|
}
|
|
@@ -125,7 +125,7 @@ class WebSocketClient {
|
|
|
125
125
|
if (this.keepAliveTimer) {
|
|
126
126
|
clearInterval(this.keepAliveTimer);
|
|
127
127
|
this.keepAliveTimer = null;
|
|
128
|
-
(0,
|
|
128
|
+
(0, __1.log_info)('KeepAlive stopped');
|
|
129
129
|
}
|
|
130
130
|
}
|
|
131
131
|
forceCleanup() {
|
package/package.json
CHANGED
package/types/index.d.ts
CHANGED
|
@@ -1,40 +1,3 @@
|
|
|
1
|
-
/*********************************************************************
|
|
2
|
-
* CONFIG - COMMON SERVICE CONFIG TYPE *
|
|
3
|
-
* *******************************************************************/
|
|
4
|
-
export interface CommonServiceType {
|
|
5
|
-
config_center: ConfigCenterServiceType
|
|
6
|
-
quote: QuoteServiceType[]
|
|
7
|
-
orderbook: OrderbookServiceType
|
|
8
|
-
trade_proxy: TradeProxyServiceType
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
// Service
|
|
12
|
-
export interface ConfigCenterServiceType {
|
|
13
|
-
http_port: number
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
// Service
|
|
17
|
-
export interface QuoteServiceType {
|
|
18
|
-
dex_id: string
|
|
19
|
-
http_port: number
|
|
20
|
-
ws_port: number
|
|
21
|
-
enable: boolean
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
// Service
|
|
25
|
-
export interface OrderbookServiceType {
|
|
26
|
-
http_port: number
|
|
27
|
-
ws_port: number
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
// Service
|
|
31
|
-
export interface TradeProxyServiceType {
|
|
32
|
-
http_port: number
|
|
33
|
-
ws_port: number
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
1
|
/*********************************************************************
|
|
39
2
|
* CONFIG - TOKEN CONFIG TYPE *
|
|
40
3
|
* *******************************************************************/
|
|
@@ -624,7 +587,6 @@ export declare class ArbCache {
|
|
|
624
587
|
init(): Promise<void>;
|
|
625
588
|
init_configs(): Promise<void>;
|
|
626
589
|
get_config_filepath(suffix: string): string;
|
|
627
|
-
get_bak_config_filepath(suffix: string): string;
|
|
628
590
|
refresh_local_cache_token_list(token_list: StandardTokenInfoType[]): void;
|
|
629
591
|
refresh_local_cache_pool_list(pool_list: StandardPoolInfoType[]): void;
|
|
630
592
|
refresh_local_cache_group_map(trade_config: TradeServiceConfigType): void;
|
|
@@ -645,8 +607,6 @@ export declare class ArbCache {
|
|
|
645
607
|
publish_pool_change_event(): Promise<void>;
|
|
646
608
|
get_one_pair(input_pair: string): Promise<StandardPairType>;
|
|
647
609
|
get_pair_list(input_pair?: string): Promise<StandardPairType[]>;
|
|
648
|
-
cache_common_service(): Promise<void>;
|
|
649
|
-
get_common_service(): Promise<CommonServiceType>;
|
|
650
610
|
cache_trade_group(update_group_id?: string): Promise<void>;
|
|
651
611
|
update_trade_group(input_trade_config: TradeServiceConfigType): Promise<void>;
|
|
652
612
|
get_trade_group_id_list(): Promise<string[]>;
|
|
@@ -1,45 +0,0 @@
|
|
|
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.getRedisClient = getRedisClient;
|
|
13
|
-
const redis_1 = require("redis");
|
|
14
|
-
let redisClient = null;
|
|
15
|
-
let connectPromise = null;
|
|
16
|
-
function createConnection() {
|
|
17
|
-
const host = process.env.REDIS_HOST || '127.0.0.1';
|
|
18
|
-
const port = process.env.REDIS_PORT || '6379';
|
|
19
|
-
const url = `redis://${host}:${port}`;
|
|
20
|
-
console.log(`[Redis] connecting to ${url}`);
|
|
21
|
-
const client = (0, redis_1.createClient)({ url });
|
|
22
|
-
client.on('error', (err) => console.error(`[Redis] error: ${err.message}`));
|
|
23
|
-
client.on('reconnecting', () => console.info('[Redis] reconnecting...'));
|
|
24
|
-
client.on('ready', () => console.info('[Redis] ready'));
|
|
25
|
-
return client.connect().then(() => {
|
|
26
|
-
redisClient = client;
|
|
27
|
-
console.info(`[Redis] connected to ${url}`);
|
|
28
|
-
return client;
|
|
29
|
-
}).catch((err) => {
|
|
30
|
-
redisClient = null;
|
|
31
|
-
connectPromise = null;
|
|
32
|
-
console.error(`[Redis] connect failed: ${err.message}`);
|
|
33
|
-
throw err;
|
|
34
|
-
});
|
|
35
|
-
}
|
|
36
|
-
function getRedisClient() {
|
|
37
|
-
return __awaiter(this, arguments, void 0, function* (module_name = '') {
|
|
38
|
-
if (redisClient)
|
|
39
|
-
return redisClient;
|
|
40
|
-
if (connectPromise)
|
|
41
|
-
return connectPromise;
|
|
42
|
-
connectPromise = createConnection();
|
|
43
|
-
return connectPromise;
|
|
44
|
-
});
|
|
45
|
-
}
|