@clonegod/ttd-core 3.1.22 → 3.1.24
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.
|
@@ -15,13 +15,11 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
15
15
|
exports.AppConfig = void 0;
|
|
16
16
|
const events_1 = __importDefault(require("events"));
|
|
17
17
|
const __1 = require("..");
|
|
18
|
-
const EnvArgs_1 = require("./EnvArgs");
|
|
19
18
|
const core_env_1 = require("./core_env");
|
|
20
19
|
class AppConfig extends events_1.default {
|
|
21
20
|
constructor() {
|
|
22
21
|
super();
|
|
23
|
-
this.env_args =
|
|
24
|
-
(0, core_env_1.setCoreEnv)(this.env_args);
|
|
22
|
+
this.env_args = (0, core_env_1.getCoreEnv)();
|
|
25
23
|
let { chain_id, app_name, dex_id } = this.env_args;
|
|
26
24
|
this.app_full_name = `${chain_id}_${dex_id}_${app_name}`;
|
|
27
25
|
global.app_config = this;
|
|
@@ -5,7 +5,6 @@ const __1 = require("..");
|
|
|
5
5
|
const env_loader_1 = require("./env_loader");
|
|
6
6
|
class EnvArgs {
|
|
7
7
|
constructor(chain_id, dex_id) {
|
|
8
|
-
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q;
|
|
9
8
|
const overrides = {};
|
|
10
9
|
if (chain_id)
|
|
11
10
|
overrides.chain_id = chain_id;
|
|
@@ -13,54 +12,10 @@ class EnvArgs {
|
|
|
13
12
|
overrides.dex_id = dex_id;
|
|
14
13
|
const cfg = (0, env_loader_1.loadEnvConfig)(overrides);
|
|
15
14
|
this._cfg = cfg;
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
this.chain_id = (cfg.chain_id || '').toUpperCase();
|
|
19
|
-
this.dex_id = (cfg.dex_id || '').toUpperCase();
|
|
20
|
-
if ((0, __1.isEmpty)(this.chain_id)) {
|
|
15
|
+
const cid = (cfg.chain_id || '').toUpperCase();
|
|
16
|
+
if ((0, __1.isEmpty)(cid)) {
|
|
21
17
|
throw new Error(`environment: CHAIN_ID is empty!!!`);
|
|
22
18
|
}
|
|
23
|
-
this.log_level = (_a = cfg.log_level) !== null && _a !== void 0 ? _a : '';
|
|
24
|
-
this.log_depth = cfg.log_depth;
|
|
25
|
-
this.server_id = (_b = cfg.server_id) !== null && _b !== void 0 ? _b : '';
|
|
26
|
-
this.redis_host = cfg.redis_host;
|
|
27
|
-
this.redis_port = String(cfg.redis_port);
|
|
28
|
-
this.config_center_host = cfg.config_center_host;
|
|
29
|
-
this.enable_init_cache = (_c = cfg.enable_init_cache) !== null && _c !== void 0 ? _c : '';
|
|
30
|
-
this.trade_analyze_url = cfg.trade_analyze_url;
|
|
31
|
-
this.trade_analyze_host = (_d = cfg.trade_analyze_host) !== null && _d !== void 0 ? _d : '';
|
|
32
|
-
this.rpc_endpoint = cfg.rpc_endpoint;
|
|
33
|
-
this.ws_endpoint = cfg.ws_endpoint;
|
|
34
|
-
this.grpc_endpoint = cfg.grpc_endpoint;
|
|
35
|
-
this.grpc_token = cfg.grpc_token;
|
|
36
|
-
this.auto_quote_enable = cfg.auto_quote_enable;
|
|
37
|
-
this.auto_quote_interval_mills = cfg.auto_quote_interval_mills;
|
|
38
|
-
this.quote_pair = cfg.quote_pair;
|
|
39
|
-
this.quote_amount_usd = cfg.quote_amount_usd;
|
|
40
|
-
this.quote_pool_address = cfg.quote_pool_address;
|
|
41
|
-
this.quote_pool_name = cfg.quote_pool_name;
|
|
42
|
-
this.quote_pool_fee_rate = cfg.quote_pool_fee_rate;
|
|
43
|
-
this.tick_cache_force_full_refresh_interval = cfg.tick_cache_force_full_refresh_interval;
|
|
44
|
-
this.depth_cex_bps = cfg.depth_cex_bps;
|
|
45
|
-
this.group_id = (_e = cfg.group_id) !== null && _e !== void 0 ? _e : '';
|
|
46
|
-
this.trade_group_id = cfg.trade_group_id;
|
|
47
|
-
this.trade_pair = cfg.trade_pair;
|
|
48
|
-
this.trade_log_report_cex_url = (_f = cfg.trade_log_report_cex_url) !== null && _f !== void 0 ? _f : '';
|
|
49
|
-
this.trade_log_report_cex_data_type = (_g = cfg.trade_log_report_cex_data_type) !== null && _g !== void 0 ? _g : '';
|
|
50
|
-
this.token_price_cache_seconds = cfg.token_price_cache_seconds;
|
|
51
|
-
this.token_market_price_url = (_h = cfg.token_market_price_url) !== null && _h !== void 0 ? _h : '';
|
|
52
|
-
this.wallet_dir = cfg.wallet_dir;
|
|
53
|
-
this.encryption_key = (_j = cfg.encryption_key) !== null && _j !== void 0 ? _j : '';
|
|
54
|
-
this.providers_file_path = cfg.providers_file_path;
|
|
55
|
-
this.fixed_symbol_address_file = (_k = cfg.fixed_symbol_address_file) !== null && _k !== void 0 ? _k : '';
|
|
56
|
-
this.zh_pinyin_map_file = (_l = cfg.zh_pinyin_map_file) !== null && _l !== void 0 ? _l : '';
|
|
57
|
-
this.alert_analyze_host = (_m = cfg.alert_analyze_host) !== null && _m !== void 0 ? _m : '';
|
|
58
|
-
this.alert_flush_size = cfg.alert_flush_size;
|
|
59
|
-
this.alert_flush_ms = cfg.alert_flush_ms;
|
|
60
|
-
this.alert_dedup_window_ms = cfg.alert_dedup_window_ms;
|
|
61
|
-
this.namespace = (_o = cfg.namespace) !== null && _o !== void 0 ? _o : '';
|
|
62
|
-
this.server_ip_list = (_p = cfg.server_ip_list) !== null && _p !== void 0 ? _p : '';
|
|
63
|
-
this.ip_exclude_prefix = (_q = cfg.ip_exclude_prefix) !== null && _q !== void 0 ? _q : '';
|
|
64
19
|
}
|
|
65
20
|
print(moduleName) {
|
|
66
21
|
(0, env_loader_1.printEnvConfig)(moduleName || this.app_name || 'EnvArgs', this);
|
|
@@ -24,63 +24,55 @@ const cache_pool_config = (chain_id, valid_tokens_map, sol_pools_cache) => __awa
|
|
|
24
24
|
let skip_pool_list = [];
|
|
25
25
|
const genv = (0, core_env_1.getCoreEnv)();
|
|
26
26
|
const ccBase = `http://${(genv.config_center_host || '127.0.0.1').trim()}:${service_ports_1.SERVICE_PORT.CONFIG_CENTER_HTTP}/${chain_id}/config`;
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
skip_pool_list.push(pool);
|
|
36
|
-
continue;
|
|
37
|
-
}
|
|
38
|
-
let std_pool = {
|
|
39
|
-
program_id: pool.program_id,
|
|
40
|
-
authority: pool.authority,
|
|
41
|
-
subscribe_type: 'grpc',
|
|
42
|
-
pair: pool.pair,
|
|
43
|
-
dex_id: dex_id,
|
|
44
|
-
pool_name: pool.pool_name,
|
|
45
|
-
pool_address: pool.pool_address,
|
|
46
|
-
pool_address_hex: '',
|
|
47
|
-
tokenA: null,
|
|
48
|
-
tokenB: null,
|
|
49
|
-
vaultA: pool.vaultA,
|
|
50
|
-
vaultB: pool.vaultB,
|
|
51
|
-
subscribe_vault_change: pool.subscribe_vault_change,
|
|
52
|
-
router_id: null,
|
|
53
|
-
fee_rate: pool.fee_rate_bps,
|
|
54
|
-
quote_token: pool.quote_token,
|
|
55
|
-
quote_amount_usd: genv.quote_amount_usd,
|
|
56
|
-
quote_price_decimals: 18,
|
|
57
|
-
is_reverse_token: null,
|
|
58
|
-
cu_limit: get_cu_limit(dex_id),
|
|
59
|
-
tvl: pool.tvl,
|
|
60
|
-
vol_24h: pool.vol_24h,
|
|
61
|
-
update_time: (0, index_1.getCurDateTime)(),
|
|
62
|
-
is_trade_native_token: pool.is_trade_native_token,
|
|
63
|
-
enable: true,
|
|
64
|
-
};
|
|
65
|
-
valid_pool_list.push(std_pool);
|
|
66
|
-
count = count + 1;
|
|
67
|
-
}
|
|
68
|
-
if (valid_pool_list.length === 0) {
|
|
27
|
+
const config_pool_url = `${ccBase}/pools`;
|
|
28
|
+
const body = [];
|
|
29
|
+
for (const [dex_id, pool_list] of sol_pools_cache) {
|
|
30
|
+
const valid_pool_list = [];
|
|
31
|
+
for (const pool of pool_list) {
|
|
32
|
+
const is_contains_unkown_symbol = !valid_tokens_map.has(pool.tokenA.symbol) || !valid_tokens_map.has(pool.tokenB.symbol);
|
|
33
|
+
if (is_contains_unkown_symbol || (0, is_not_arb_token_1.is_not_arb_token)(pool.pool_name)) {
|
|
34
|
+
skip_pool_list.push(pool);
|
|
69
35
|
continue;
|
|
70
36
|
}
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
37
|
+
valid_pool_list.push({
|
|
38
|
+
program_id: pool.program_id,
|
|
39
|
+
authority: pool.authority,
|
|
40
|
+
subscribe_type: 'grpc',
|
|
41
|
+
pair: pool.pair,
|
|
42
|
+
dex_id,
|
|
43
|
+
pool_name: pool.pool_name,
|
|
44
|
+
pool_address: pool.pool_address,
|
|
45
|
+
pool_address_hex: '',
|
|
46
|
+
tokenA: null,
|
|
47
|
+
tokenB: null,
|
|
48
|
+
vaultA: pool.vaultA,
|
|
49
|
+
vaultB: pool.vaultB,
|
|
50
|
+
subscribe_vault_change: pool.subscribe_vault_change,
|
|
51
|
+
router_id: null,
|
|
52
|
+
fee_rate: pool.fee_rate_bps,
|
|
53
|
+
quote_token: pool.quote_token,
|
|
54
|
+
quote_amount_usd: genv.quote_amount_usd,
|
|
55
|
+
quote_price_decimals: 18,
|
|
56
|
+
is_reverse_token: null,
|
|
57
|
+
cu_limit: get_cu_limit(dex_id),
|
|
58
|
+
tvl: pool.tvl,
|
|
59
|
+
vol_24h: pool.vol_24h,
|
|
60
|
+
update_time: (0, index_1.getCurDateTime)(),
|
|
61
|
+
is_trade_native_token: pool.is_trade_native_token,
|
|
62
|
+
enable: true,
|
|
63
|
+
});
|
|
64
|
+
count = count + 1;
|
|
65
|
+
}
|
|
66
|
+
if (valid_pool_list.length > 0) {
|
|
67
|
+
body.push({ dex_id, pool_list: valid_pool_list });
|
|
82
68
|
}
|
|
83
69
|
}
|
|
70
|
+
if (body.length > 0) {
|
|
71
|
+
const res = (yield axios_1.default.post(config_pool_url, body, {
|
|
72
|
+
headers: { 'Content-Type': 'application/json' },
|
|
73
|
+
})).data;
|
|
74
|
+
(0, index_1.log_trace)('cache_pool_config, res', res);
|
|
75
|
+
}
|
|
84
76
|
(0, index_1.log_info)(`cache_pool_config finished! sync pool count:${count}, skip: ${skip_pool_list.length}`);
|
|
85
77
|
skip_pool_list.sort((a, b) => a.pair.localeCompare(b.pair));
|
|
86
78
|
(0, index_1.writeFile)(`dist/${chain_id.toLowerCase()}_skip_pool_list.json`, JSON.stringify({
|
|
@@ -22,46 +22,35 @@ const cache_token_config = (chain_id, valid_tokens_map) => __awaiter(void 0, voi
|
|
|
22
22
|
(0, index_1.log_info)(`cache_token_config start`);
|
|
23
23
|
const genv = (0, core_env_1.getCoreEnv)();
|
|
24
24
|
const ccBase = `http://${(genv.config_center_host || '127.0.0.1').trim()}:${service_ports_1.SERVICE_PORT.CONFIG_CENTER_HTTP}/${chain_id}/config`;
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
let valid_tokens = [];
|
|
30
|
-
for (let key of one_batch) {
|
|
31
|
-
let value = valid_tokens_map.get(key);
|
|
32
|
-
if (!value || value.length !== 1) {
|
|
33
|
-
continue;
|
|
34
|
-
}
|
|
35
|
-
let token = value[0];
|
|
36
|
-
let std_token = {
|
|
37
|
-
symbol: token.symbol,
|
|
38
|
-
address: token.address,
|
|
39
|
-
address_hex: '',
|
|
40
|
-
decimals: token.decimals,
|
|
41
|
-
name: token.name,
|
|
42
|
-
is_token2022: token.is_token_2022,
|
|
43
|
-
market_price: token.price,
|
|
44
|
-
update_time: (0, index_1.getCurDateTime)(),
|
|
45
|
-
alias: (0, index_1.get_token_symbol_alias)(token.address),
|
|
46
|
-
enable: true
|
|
47
|
-
};
|
|
48
|
-
if ((0, is_not_arb_token_1.is_not_arb_token)(std_token.symbol)) {
|
|
49
|
-
continue;
|
|
50
|
-
}
|
|
51
|
-
valid_tokens.push(std_token);
|
|
52
|
-
count += 1;
|
|
53
|
-
}
|
|
54
|
-
if (valid_tokens.length === 0) {
|
|
25
|
+
const config_token_url = `${ccBase}/tokens`;
|
|
26
|
+
const valid_tokens = [];
|
|
27
|
+
for (const [, value] of valid_tokens_map) {
|
|
28
|
+
if (!value || value.length !== 1)
|
|
55
29
|
continue;
|
|
56
|
-
|
|
57
|
-
const
|
|
58
|
-
|
|
59
|
-
|
|
30
|
+
const token = value[0];
|
|
31
|
+
const std_token = {
|
|
32
|
+
symbol: token.symbol,
|
|
33
|
+
address: token.address,
|
|
34
|
+
address_hex: '',
|
|
35
|
+
decimals: token.decimals,
|
|
36
|
+
name: token.name,
|
|
37
|
+
is_token2022: token.is_token_2022,
|
|
38
|
+
market_price: token.price,
|
|
39
|
+
update_time: (0, index_1.getCurDateTime)(),
|
|
40
|
+
alias: (0, index_1.get_token_symbol_alias)(token.address),
|
|
41
|
+
enable: true,
|
|
42
|
+
};
|
|
43
|
+
if ((0, is_not_arb_token_1.is_not_arb_token)(std_token.symbol))
|
|
44
|
+
continue;
|
|
45
|
+
valid_tokens.push(std_token);
|
|
46
|
+
}
|
|
47
|
+
if (valid_tokens.length > 0) {
|
|
48
|
+
const res = (yield axios_1.default.post(config_token_url, valid_tokens, {
|
|
49
|
+
headers: { 'Content-Type': 'application/json' },
|
|
60
50
|
})).data;
|
|
61
51
|
(0, index_1.log_trace)('cache_token_config, res', res);
|
|
62
|
-
yield (0, index_1.sleep)(200);
|
|
63
52
|
}
|
|
64
|
-
(0, index_1.log_info)(`cache_token_config finish! sync token count: ${
|
|
53
|
+
(0, index_1.log_info)(`cache_token_config finish! sync token count: ${valid_tokens.length}`);
|
|
65
54
|
let notify_config_change_url = `${ccBase}/change?type=token`;
|
|
66
55
|
let res = (yield axios_1.default.get(notify_config_change_url)).data;
|
|
67
56
|
(0, index_1.log_info)('fetch tokens end, notify config change', {
|