@clonegod/ttd-core 2.0.9 → 2.0.11
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/app_config/app_config.d.ts +0 -1
- package/dist/app_config/app_config.js +0 -5
- package/dist/app_config/app_trade_config.js +1 -0
- package/dist/app_config/env_args.d.ts +1 -1
- package/dist/app_config/env_args.js +1 -2
- package/dist/cache/arb_cache.js +4 -0
- package/dist/token/price/cached_price.js +8 -3
- package/package.json +1 -1
|
@@ -8,7 +8,6 @@ export declare class AppConfig extends EventEmitter {
|
|
|
8
8
|
arb_cache: ArbCache;
|
|
9
9
|
arb_event_subscriber: ArbEventSubscriber;
|
|
10
10
|
trade_runtime: TradeRuntimeType;
|
|
11
|
-
query_token_market_price_url: string;
|
|
12
11
|
constructor();
|
|
13
12
|
init(): Promise<void>;
|
|
14
13
|
subscribe_config_change(): Promise<void>;
|
|
@@ -28,15 +28,10 @@ class AppConfig extends events_1.default {
|
|
|
28
28
|
return __awaiter(this, void 0, void 0, function* () {
|
|
29
29
|
this.arb_cache = (0, __1.getArbCache)(this.env_args);
|
|
30
30
|
yield this.arb_cache.init();
|
|
31
|
-
this.arb_cache.listen_trade_result(this);
|
|
32
31
|
let common_service_config = yield this.arb_cache.get_common_service();
|
|
33
32
|
if ((0, __1.isEmpty)(common_service_config)) {
|
|
34
33
|
throw new Error(`get_common_service from cache failed! read from cache=${(0, __1.to_json_str)(common_service_config)}`);
|
|
35
34
|
}
|
|
36
|
-
let { config_center } = common_service_config;
|
|
37
|
-
this.query_token_market_price_url = this.env_args.token_market_price_url
|
|
38
|
-
.replace('${config_center_http_port}', config_center.http_port + '')
|
|
39
|
-
.replace('${chain_id}', this.env_args.chain_id);
|
|
40
35
|
});
|
|
41
36
|
}
|
|
42
37
|
subscribe_config_change() {
|
|
@@ -12,7 +12,6 @@ class EnvArgs {
|
|
|
12
12
|
}
|
|
13
13
|
this.dex_id = dex_id || ((_b = process.env.DEX_ID) === null || _b === void 0 ? void 0 : _b.toUpperCase());
|
|
14
14
|
if ((0, __1.isEmpty)(this.dex_id)) {
|
|
15
|
-
throw new Error(`Invalid config: DEX_ID=${process.env.DEX_ID}!!!`);
|
|
16
15
|
}
|
|
17
16
|
this.app_base_dir = process.env.APP_BASE_DIR || '';
|
|
18
17
|
this.redis_host = process.env.REDIS_HOST;
|
|
@@ -34,7 +33,7 @@ class EnvArgs {
|
|
|
34
33
|
this.trade_pool_address = process.env.TRADE_POOL_ADDRESS;
|
|
35
34
|
this.trade_pool_name = process.env.TRADE_POOL_NAME;
|
|
36
35
|
this.trade_pool_fee_rate = parseInt(process.env.TRADE_POOL_FEE_RATE || '0');
|
|
37
|
-
this.
|
|
36
|
+
this.token_price_cache_seconds = parseInt(process.env.TOKEN_PRICE_CACHE_SECONDS || '600');
|
|
38
37
|
(0, __1.log_info)('EnvArgs init finish', this);
|
|
39
38
|
}
|
|
40
39
|
}
|
package/dist/cache/arb_cache.js
CHANGED
|
@@ -39,6 +39,10 @@ class ArbCache {
|
|
|
39
39
|
]);
|
|
40
40
|
this.redis_event_publisher = (0, index_1.getArbEventPublisher)(this);
|
|
41
41
|
(0, index_1.mkdirSync)(path_1.default.join('config', this.chain_id, 'bak').toLowerCase(), true);
|
|
42
|
+
yield Promise.all([
|
|
43
|
+
this.get_token_list_no_cache(),
|
|
44
|
+
this.get_pool_list_no_cache()
|
|
45
|
+
]);
|
|
42
46
|
if (((_a = process.env.APP_NAME) === null || _a === void 0 ? void 0 : _a.toLowerCase()) === 'config-center') {
|
|
43
47
|
yield this.init_configs();
|
|
44
48
|
}
|
|
@@ -20,6 +20,9 @@ const check_token_price_timeout = (token_info, token_price_timeout_seconds) => {
|
|
|
20
20
|
let diff_seconds = Math.floor((Date.now() - (0, __1.parseDateTimeStrToMills)(last_update_time)) / 1000);
|
|
21
21
|
return diff_seconds > token_price_timeout_seconds;
|
|
22
22
|
};
|
|
23
|
+
const get_diff_seconds = (last_update_time, now) => {
|
|
24
|
+
return Math.floor((now - (0, __1.parseDateTimeStrToMills)(last_update_time)) / 1000);
|
|
25
|
+
};
|
|
23
26
|
const fetchPriceFromCache = (token_address_list) => __awaiter(void 0, void 0, void 0, function* () {
|
|
24
27
|
let result = new Map();
|
|
25
28
|
let global_app_config;
|
|
@@ -40,13 +43,13 @@ const fetchPriceFromCache = (token_address_list) => __awaiter(void 0, void 0, vo
|
|
|
40
43
|
not_found_token_list.push(token_info);
|
|
41
44
|
}
|
|
42
45
|
else {
|
|
43
|
-
let diff_seconds =
|
|
46
|
+
let diff_seconds = get_diff_seconds(token_info.update_time, Date.now());
|
|
44
47
|
result.set(token_info.address, {
|
|
45
48
|
address: token_info.address,
|
|
46
49
|
price: token_info.market_price,
|
|
47
50
|
update_time: token_info.update_time,
|
|
48
51
|
});
|
|
49
|
-
(0, __1.log_info)(`get token price from cache success: ${token_info.symbol} ${token_info.address}, price=${token_info.market_price} (${diff_seconds}s ago)`);
|
|
52
|
+
(0, __1.log_info)(`get token price from cache(token_info) success: ${token_info.symbol} ${token_info.address}, price=${token_info.market_price} (${diff_seconds}s ago)`);
|
|
50
53
|
}
|
|
51
54
|
}
|
|
52
55
|
catch (err) {
|
|
@@ -63,6 +66,8 @@ const fetchPriceFromCache = (token_address_list) => __awaiter(void 0, void 0, vo
|
|
|
63
66
|
price: price_info.market_price,
|
|
64
67
|
update_time: price_info.update_time,
|
|
65
68
|
});
|
|
69
|
+
let diff_seconds = get_diff_seconds(price_info.update_time, Date.now());
|
|
70
|
+
(0, __1.log_info)(`get token price from cache(market_price) success: ${token_info.symbol} ${token_info.address}, price=${price_info.market_price} (${diff_seconds}s ago)`);
|
|
66
71
|
}
|
|
67
72
|
return result;
|
|
68
73
|
});
|
|
@@ -77,7 +82,7 @@ function cache_new_market_price(token_address, market_price, market_source) {
|
|
|
77
82
|
(0, __1.log_warn)('global_app_config is not set, skip get token price from cache');
|
|
78
83
|
return;
|
|
79
84
|
}
|
|
80
|
-
let ttl = global_app_config.env_args.
|
|
85
|
+
let ttl = global_app_config.env_args.token_price_cache_seconds;
|
|
81
86
|
let tokenInfo = global_app_config.arb_cache.token_address_map.get(token_address);
|
|
82
87
|
if (!tokenInfo) {
|
|
83
88
|
tokenInfo = (yield global_app_config.arb_cache.get_token_list_no_cache()).find(e => e.address === token_address);
|