@clonegod/ttd-core 3.1.23 → 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 = new EnvArgs_1.EnvArgs();
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;
@@ -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
- let config_pool_url = `${ccBase}/pools`;
28
- for (let [dex_id, pool_list] of sol_pools_cache) {
29
- let batch_pools = (0, index_1.chunkArray)(pool_list, 10);
30
- for (let one_pool_list of batch_pools) {
31
- let valid_pool_list = [];
32
- for (let pool of one_pool_list) {
33
- let is_contains_unkown_symbol = !valid_tokens_map.has(pool.tokenA.symbol) || !valid_tokens_map.has(pool.tokenB.symbol);
34
- if (is_contains_unkown_symbol || (0, is_not_arb_token_1.is_not_arb_token)(pool.pool_name)) {
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
- let body = [
72
- {
73
- dex_id: dex_id,
74
- pool_list: valid_pool_list
75
- }
76
- ];
77
- const res = (yield axios_1.default.post(config_pool_url, body, {
78
- headers: { 'Content-Type': 'application/json' }
79
- })).data;
80
- (0, index_1.log_trace)('cache_pool_config, res', res);
81
- yield (0, index_1.sleep)(200);
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
- let config_token_url = `${ccBase}/tokens`;
26
- let count = 0;
27
- let batch_symbols = (0, index_1.chunkArray)(Array.from(valid_tokens_map.keys()), 20);
28
- for (let one_batch of batch_symbols) {
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 body = valid_tokens;
58
- const res = (yield axios_1.default.post(config_token_url, body, {
59
- headers: { 'Content-Type': 'application/json' }
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: ${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', {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@clonegod/ttd-core",
3
- "version": "3.1.23",
3
+ "version": "3.1.24",
4
4
  "description": "Common types and utilities for trading systems - use `npm run push` to publish",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",