@clonegod/ttd-core 3.1.26 → 3.1.27

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.
@@ -34,6 +34,32 @@ export declare class ArbCache {
34
34
  publish_token_change_event(): Promise<void>;
35
35
  cache_pool_list(): Promise<void>;
36
36
  private scan_duplicate_address;
37
+ resolve_duplicate_address(authoritative_mappings: Array<{
38
+ address: string;
39
+ symbol: string;
40
+ }>): Promise<{
41
+ cleaned_tokens: Array<{
42
+ address: string;
43
+ dropped_symbols: string[];
44
+ kept_symbol: string;
45
+ }>;
46
+ cleaned_pools: Array<{
47
+ pool_address: string;
48
+ pool_name: string;
49
+ dex_id: string;
50
+ }>;
51
+ skipped_trading_pools: Array<{
52
+ pool_address: string;
53
+ pool_name: string;
54
+ dex_id: string;
55
+ reason: string;
56
+ }>;
57
+ not_found: Array<{
58
+ address: string;
59
+ symbol: string;
60
+ reason: string;
61
+ }>;
62
+ }>;
37
63
  set_pool_token_info(pool: StandardPoolInfoType, token_info_list: StandardTokenInfoType[]): boolean;
38
64
  set_pool_extra(pool: StandardPoolInfoType): void;
39
65
  update_pool_list(input_dex_pool_list: StandardDexPoolConfigType[]): Promise<void>;
@@ -315,6 +315,85 @@ class ArbCache {
315
315
  });
316
316
  (0, index_1.log_warn)(`[token-duplicate] 发现 ${conflicts.length} 个 address 被多 symbol 引用(垃圾数据,需人工清理 token-list.json + pool-list.json + Redis):\n${lines.join('\n')}`);
317
317
  }
318
+ resolve_duplicate_address(authoritative_mappings) {
319
+ return __awaiter(this, void 0, void 0, function* () {
320
+ const token_list = yield this.get_token_list();
321
+ const by_addr = new Map();
322
+ for (const t of token_list) {
323
+ const addr = (t.address || '').toLowerCase();
324
+ if (!addr)
325
+ continue;
326
+ if (!by_addr.has(addr))
327
+ by_addr.set(addr, []);
328
+ by_addr.get(addr).push(t);
329
+ }
330
+ const tokens_to_disable = [];
331
+ const cleaned_tokens = [];
332
+ const not_found = [];
333
+ for (const { address, symbol } of authoritative_mappings) {
334
+ const addr = (address || '').toLowerCase();
335
+ const tokens = by_addr.get(addr) || [];
336
+ if (tokens.length === 0) {
337
+ not_found.push({ address: addr, symbol, reason: `address 在 token-list 中未找到` });
338
+ continue;
339
+ }
340
+ const canonical = tokens.find(t => t.symbol === symbol);
341
+ if (!canonical) {
342
+ not_found.push({ address: addr, symbol, reason: `symbol=${symbol} 在 address ${addr} 的条目中未找到(token-list 里 symbols=[${tokens.map(t => t.symbol).join(',')}])` });
343
+ continue;
344
+ }
345
+ const dropped = tokens.filter(t => t.symbol !== symbol);
346
+ if (dropped.length === 0)
347
+ continue;
348
+ for (const t of dropped) {
349
+ tokens_to_disable.push(Object.assign(Object.assign({}, t), { enable: false }));
350
+ }
351
+ cleaned_tokens.push({
352
+ address: addr,
353
+ dropped_symbols: dropped.map(t => t.symbol),
354
+ kept_symbol: symbol,
355
+ });
356
+ }
357
+ const dropped_symbols = new Set(tokens_to_disable.map(t => t.symbol));
358
+ const cleaned_pools = [];
359
+ const skipped_trading_pools = [];
360
+ if (dropped_symbols.size > 0) {
361
+ const pool_list = yield this.get_pool_list();
362
+ const trade_pool_set = new Set((yield this.get_all_trade_pools()).map(p => p.pool_address));
363
+ const pools_to_disable_by_dex = new Map();
364
+ for (const p of pool_list) {
365
+ const [t0, t1] = (p.pool_name || '').split('/');
366
+ if (!dropped_symbols.has(t0) && !dropped_symbols.has(t1))
367
+ continue;
368
+ if (trade_pool_set.has(p.pool_address)) {
369
+ skipped_trading_pools.push({
370
+ pool_address: p.pool_address,
371
+ pool_name: p.pool_name,
372
+ dex_id: p.dex_id,
373
+ reason: 'pool in trading config (protected)',
374
+ });
375
+ continue;
376
+ }
377
+ if (!pools_to_disable_by_dex.has(p.dex_id))
378
+ pools_to_disable_by_dex.set(p.dex_id, []);
379
+ pools_to_disable_by_dex.get(p.dex_id).push(Object.assign(Object.assign({}, p), { enable: false }));
380
+ cleaned_pools.push({ pool_address: p.pool_address, pool_name: p.pool_name, dex_id: p.dex_id });
381
+ }
382
+ if (pools_to_disable_by_dex.size > 0) {
383
+ const dex_pool_list = [];
384
+ for (const [dex_id, pools] of pools_to_disable_by_dex) {
385
+ dex_pool_list.push({ dex_id: dex_id, pool_list: pools });
386
+ }
387
+ yield this.update_pool_list(dex_pool_list);
388
+ }
389
+ }
390
+ if (tokens_to_disable.length > 0) {
391
+ yield this.update_token_list(tokens_to_disable);
392
+ }
393
+ (0, index_1.log_warn)(`[resolve-duplicate] 完成: disabled ${tokens_to_disable.length} 个 symbol, 删 ${cleaned_pools.length} 个 pool, 跳过交易中 pool ${skipped_trading_pools.length} 个, 映射 not_found ${not_found.length} 个`);
394
+ return { cleaned_tokens, cleaned_pools, skipped_trading_pools, not_found };
395
+ });
396
+ }
318
397
  set_pool_token_info(pool, token_info_list) {
319
398
  if (index_1.LOG.debug) {
320
399
  (0, index_1.log_trace)(`set_pool_token_info`);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@clonegod/ttd-core",
3
- "version": "3.1.26",
3
+ "version": "3.1.27",
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",
package/types/index.d.ts CHANGED
@@ -600,6 +600,12 @@ export declare class ArbCache {
600
600
  publish_token_change_event(): Promise<void>;
601
601
  cache_pool_list(): Promise<void>;
602
602
  set_pool_token_info(pool: StandardPoolInfoType, token_info_list: StandardTokenInfoType[]): boolean;
603
+ resolve_duplicate_address(authoritative_mappings: Array<{ address: string; symbol: string }>): Promise<{
604
+ cleaned_tokens: Array<{ address: string; dropped_symbols: string[]; kept_symbol: string }>;
605
+ cleaned_pools: Array<{ pool_address: string; pool_name: string; dex_id: string }>;
606
+ skipped_trading_pools: Array<{ pool_address: string; pool_name: string; dex_id: string; reason: string }>;
607
+ not_found: Array<{ address: string; symbol: string; reason: string }>;
608
+ }>;
603
609
  set_pool_extra(pool: StandardPoolInfoType): void;
604
610
  update_pool_list(input_dex_pool_list: StandardDexPoolConfigType[]): Promise<void>;
605
611
  get_pool_list_by_pair(pair: string): Promise<StandardPoolInfoType[]>;