@clonegod/ttd-core 3.1.84 → 3.1.87

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.
@@ -1,2 +1,3 @@
1
1
  import { CHAIN_ID, DEX_ID, FormattedPoolInfo, FormattedTokenInfo } from "../index";
2
2
  export declare const cache_pool_config: (chain_id: CHAIN_ID, tokens_map: Map<string, FormattedTokenInfo>, pools_map: Map<DEX_ID, FormattedPoolInfo[]>) => Promise<void>;
3
+ export declare function assert_cache_pool_fields(pools_map: Map<DEX_ID, FormattedPoolInfo[]>): void;
@@ -13,6 +13,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
13
13
  };
14
14
  Object.defineProperty(exports, "__esModule", { value: true });
15
15
  exports.cache_pool_config = void 0;
16
+ exports.assert_cache_pool_fields = assert_cache_pool_fields;
16
17
  const axios_1 = __importDefault(require("axios"));
17
18
  const core_env_1 = require("../appconfig/core_env");
18
19
  const index_1 = require("../index");
@@ -36,7 +37,7 @@ const cache_pool_config = (chain_id, tokens_map, pools_map) => __awaiter(void 0,
36
37
  continue;
37
38
  }
38
39
  valid_pool_list.push({
39
- _id: (pool.pool_address || '').toLowerCase(),
40
+ _id: pool._id,
40
41
  program_id: pool.program_id,
41
42
  authority: pool.authority,
42
43
  subscribe_type: 'grpc',
@@ -113,3 +114,13 @@ function get_cu_limit(dex_id) {
113
114
  }
114
115
  return cu_limit;
115
116
  }
117
+ function assert_cache_pool_fields(pools_map) {
118
+ var _a, _b;
119
+ for (const [dex_id, pools] of pools_map) {
120
+ for (const p of pools) {
121
+ if (!(p === null || p === void 0 ? void 0 : p._id) || !p.pool_address || !p.pair || !((_a = p.tokenA) === null || _a === void 0 ? void 0 : _a._id) || !((_b = p.tokenB) === null || _b === void 0 ? void 0 : _b._id)) {
122
+ throw new Error(`assert_cache_pool_fields: pool 字段不全(须含 _id/pool_address/pair/tokenA._id/tokenB._id): dex=${dex_id} name=${p === null || p === void 0 ? void 0 : p.pool_name} addr=${p === null || p === void 0 ? void 0 : p.pool_address}`);
123
+ }
124
+ }
125
+ }
126
+ }
@@ -1,2 +1,3 @@
1
1
  import { CHAIN_ID, FormattedTokenInfo } from "../index";
2
2
  export declare const cache_token_config: (chain_id: CHAIN_ID, tokens_map: Map<string, FormattedTokenInfo>) => Promise<void>;
3
+ export declare function assert_cache_token_fields(tokens_map: Map<string, FormattedTokenInfo>): void;
@@ -13,6 +13,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
13
13
  };
14
14
  Object.defineProperty(exports, "__esModule", { value: true });
15
15
  exports.cache_token_config = void 0;
16
+ exports.assert_cache_token_fields = assert_cache_token_fields;
16
17
  const axios_1 = __importDefault(require("axios"));
17
18
  const core_env_1 = require("../appconfig/core_env");
18
19
  const index_1 = require("../index");
@@ -30,7 +31,7 @@ const cache_token_config = (chain_id, tokens_map) => __awaiter(void 0, void 0, v
30
31
  if ((0, is_not_arb_token_1.is_not_arb_token)(token.symbol))
31
32
  continue;
32
33
  valid_tokens.push({
33
- _id: (token.address || '').toLowerCase(),
34
+ _id: token._id,
34
35
  symbol: token.symbol,
35
36
  raw_symbol: token.raw_symbol,
36
37
  address: token.address,
@@ -58,3 +59,10 @@ const cache_token_config = (chain_id, tokens_map) => __awaiter(void 0, void 0, v
58
59
  });
59
60
  });
60
61
  exports.cache_token_config = cache_token_config;
62
+ function assert_cache_token_fields(tokens_map) {
63
+ for (const t of tokens_map.values()) {
64
+ if (!(t === null || t === void 0 ? void 0 : t._id) || !t.symbol || !t.address) {
65
+ throw new Error(`assert_cache_token_fields: token 字段不全(须含 _id/symbol/address): ${JSON.stringify({ _id: t === null || t === void 0 ? void 0 : t._id, symbol: t === null || t === void 0 ? void 0 : t.symbol, address: t === null || t === void 0 ? void 0 : t.address })}`);
66
+ }
67
+ }
68
+ }
@@ -23,9 +23,8 @@ const fetchPriceFromCache = (token_address_list) => __awaiter(void 0, void 0, vo
23
23
  (0, __1.log_warn)('global_app_config is not set, skip get token price from cache');
24
24
  return result;
25
25
  }
26
- const map = global_app_config.arb_cache.token_address_map;
27
26
  for (const address of token_address_list) {
28
- const token = map.get(address.toLowerCase());
27
+ const token = global_app_config.arb_cache.getTokenByAddress(address);
29
28
  if (token === null || token === void 0 ? void 0 : token.market_price) {
30
29
  result.set(address, {
31
30
  address: token.address,
@@ -51,14 +50,13 @@ function cache_new_market_price_batch(hits) {
51
50
  (0, __1.log_warn)('global_app_config is not set, skip cache_new_market_price_batch');
52
51
  return;
53
52
  }
54
- const map = global_app_config.arb_cache.token_address_map;
55
53
  const updated = [];
56
54
  for (const { address, price, source } of hits) {
57
55
  if (!price || Number(price) <= 0) {
58
56
  (0, __1.log_warn)(`skip cache invalid market_price from ${source}`, { address, price });
59
57
  continue;
60
58
  }
61
- const tokenInfo = map.get(address.toLowerCase());
59
+ const tokenInfo = global_app_config.arb_cache.getTokenByAddress(address);
62
60
  if (!tokenInfo) {
63
61
  (0, __1.log_warn)(`tokenInfo not found in arb_cache.token_address_map: address=${address}`);
64
62
  continue;
@@ -90,10 +88,9 @@ function warnPriceCacheMiss(missed_addresses) {
90
88
  return;
91
89
  }
92
90
  const now = Date.now();
93
- const map = cfg.arb_cache.token_address_map;
94
91
  const to_warn = [];
95
92
  for (const addr of missed_addresses) {
96
- const known = map.has(addr.toLowerCase());
93
+ const known = cfg.arb_cache.getTokenByAddress(addr) !== undefined;
97
94
  if (!known)
98
95
  continue;
99
96
  const last = (_a = _priceMissLastWarnAt.get(addr)) !== null && _a !== void 0 ? _a : 0;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@clonegod/ttd-core",
3
- "version": "3.1.84",
3
+ "version": "3.1.87",
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",