@clonegod/ttd-core 3.1.111 → 3.1.113

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.
@@ -908,7 +908,7 @@ class ArbCache {
908
908
  console.log(`=================================================================================`);
909
909
  console.log(`| TRADE GROUP RUNTIME |`);
910
910
  console.log(`=================================================================================`);
911
- console.dir(_trade_runtime, { depth: 4 });
911
+ console.dir(_trade_runtime, { depth: process.env.LOG_DEPTH ? Number(process.env.LOG_DEPTH) : null });
912
912
  (0, index_1.log_trace)(`create_trade_runtime, end`);
913
913
  return trade_runtime;
914
914
  });
package/dist/index.d.ts CHANGED
@@ -18,7 +18,7 @@ export * from './chains';
18
18
  export * from './log_bus';
19
19
  export * from './ws';
20
20
  export * from './util';
21
- export type { StandardTokenConfigType, StandardTokenInfoType, StandardPoolConfigType, StandardDexPoolConfigType, StandardPoolInfoType, StandardPairType, TradeServiceConfigType, TradeGroupType, TradePairType, TradePairDexPoolsType, TradeSettingsType, RpcInfoType, TradeStrategyType, TradeCommandLineArgs, TradeRuntimeType, TradeProcessInstanceType, TokenPriceWithAmountType, QuoteResultType, PriceMessageType, QuoteSourceType, UniqueOrderbookIdType, PriceType, QuoteTimeInfoType, OrderbookPriceType, Ladder, OrderMessageType, OrderSubmitResultType, OrderSubmitResponseType, StandardSwapDetailType, TokenBalChangeType, TokenBalanceChangeType, TradeResponseType, TradeResultType, TradeResultBalanceChangeType, TradeExecutionInfoType, TradeTimeFlowType, TradeBroadcastType, TradeGasFeeType, ServerInfoType, SendTxLogType, WalletInfoType, WalletTokenBalanceInfoType, RedisConfigChangeEventMessageType, RedisOrderEventMessageType, RedisQuoteEventMessageType, PreTradeEventType, ProviderComparisonType, ProviderArrivalType, OnTradeType, OnTradePriceType, OnTradeDepthType, OnTradeExecutionType, OnTradeResultType, AnalyzeDepthLevelType, AnalyzeTierLevelType, AnalyzeTokenAmountType, PostTradeType, AnalyzeQuoteSnapshotType, AnalyzePoolEventType, AnalyzeEventSummaryType, AnalyzeSameBlockType, } from '../types';
21
+ export type { StandardTokenConfigType, StandardTokenInfoType, StandardPoolConfigType, StandardDexPoolConfigType, StandardPoolInfoType, PoolTokenTaxType, PoolTokenTaxRowType, StandardPairType, TradeServiceConfigType, TradeGroupType, TradePairType, TradePairDexPoolsType, TradeSettingsType, RpcInfoType, TradeStrategyType, TradeCommandLineArgs, TradeRuntimeType, TradeProcessInstanceType, TokenPriceWithAmountType, QuoteResultType, PriceMessageType, QuoteSourceType, UniqueOrderbookIdType, PriceType, QuoteTimeInfoType, OrderbookPriceType, Ladder, OrderMessageType, OrderSubmitResultType, OrderSubmitResponseType, StandardSwapDetailType, TokenBalChangeType, TokenBalanceChangeType, TradeResponseType, TradeResultType, TradeResultBalanceChangeType, TradeExecutionInfoType, TradeTimeFlowType, TradeBroadcastType, TradeGasFeeType, ServerInfoType, SendTxLogType, WalletInfoType, WalletTokenBalanceInfoType, RedisConfigChangeEventMessageType, RedisOrderEventMessageType, RedisQuoteEventMessageType, PreTradeEventType, ProviderComparisonType, ProviderArrivalType, OnTradeType, OnTradePriceType, OnTradeDepthType, OnTradeExecutionType, OnTradeResultType, AnalyzeDepthLevelType, AnalyzeTierLevelType, AnalyzeTokenAmountType, PostTradeType, AnalyzeQuoteSnapshotType, AnalyzePoolEventType, AnalyzeEventSummaryType, AnalyzeSameBlockType, } from '../types';
22
22
  export declare const FAILED = "FAILED";
23
23
  export declare const SUCCESS = "SUCCESS";
24
24
  export declare const NOT_FOUND = "NOT_FOUND";
@@ -19,6 +19,7 @@ const core_env_1 = require("../appconfig/core_env");
19
19
  const index_1 = require("../index");
20
20
  const service_ports_1 = require("../constants/service_ports");
21
21
  const is_not_arb_token_1 = require("../token/is_not_arb_token");
22
+ const pool_token_taxes_1 = require("./pool_token_taxes");
22
23
  const cache_pool_config = (chain_id, tokens_map, pools_map) => __awaiter(void 0, void 0, void 0, function* () {
23
24
  (0, index_1.log_info)(`cache_pool_config start`);
24
25
  let count = 0;
@@ -26,6 +27,19 @@ const cache_pool_config = (chain_id, tokens_map, pools_map) => __awaiter(void 0,
26
27
  const genv = (0, core_env_1.getCoreEnv)();
27
28
  const ccBase = `http://${(genv.config_center_host || '127.0.0.1').trim()}:${service_ports_1.SERVICE_PORT.CONFIG_CENTER_HTTP}/${chain_id}/config`;
28
29
  const config_pool_url = `${ccBase}/pools`;
30
+ const taxByPool = new Map();
31
+ for (const row of (0, pool_token_taxes_1.get_pool_token_taxes)()) {
32
+ const key = row.pool_address.toLowerCase();
33
+ if (!taxByPool.has(key))
34
+ taxByPool.set(key, []);
35
+ taxByPool.get(key).push({
36
+ token_address: row.token_address.toLowerCase(),
37
+ buy_tax_bps: row.buy_tax_bps,
38
+ sell_tax_bps: row.sell_tax_bps,
39
+ note: row.note,
40
+ });
41
+ }
42
+ const stamped_tax_pools = [];
29
43
  const body = [];
30
44
  for (const [dex_id, pool_list] of pools_map) {
31
45
  const valid_pool_list = [];
@@ -36,6 +50,9 @@ const cache_pool_config = (chain_id, tokens_map, pools_map) => __awaiter(void 0,
36
50
  skip_pool_list.push(pool);
37
51
  continue;
38
52
  }
53
+ const token_taxes = taxByPool.get(pool.pool_address.toLowerCase());
54
+ if (token_taxes)
55
+ stamped_tax_pools.push(`${pool.pool_name}(${pool.pool_address})`);
39
56
  valid_pool_list.push({
40
57
  _id: pool._id,
41
58
  program_id: pool.program_id,
@@ -61,6 +78,7 @@ const cache_pool_config = (chain_id, tokens_map, pools_map) => __awaiter(void 0,
61
78
  vol_24h: pool.vol_24h,
62
79
  update_time: (0, index_1.getCurDateTime)(),
63
80
  is_trade_native_token: pool.is_trade_native_token,
81
+ token_taxes,
64
82
  enable: true,
65
83
  });
66
84
  count = count + 1;
@@ -75,6 +93,9 @@ const cache_pool_config = (chain_id, tokens_map, pools_map) => __awaiter(void 0,
75
93
  })).data;
76
94
  (0, index_1.log_trace)('cache_pool_config, res', res);
77
95
  }
96
+ if (taxByPool.size > 0) {
97
+ (0, index_1.log_info)(`cache_pool_config token_taxes: 配置 ${taxByPool.size} 个池子, 本轮盖章 ${stamped_tax_pools.length} 个: ${stamped_tax_pools.join(', ')}`);
98
+ }
78
99
  (0, index_1.log_info)(`cache_pool_config finished! sync pool count:${count}, skip: ${skip_pool_list.length}`);
79
100
  skip_pool_list.sort((a, b) => a.pair.localeCompare(b.pair));
80
101
  (0, index_1.writeFile)(`dist/${chain_id.toLowerCase()}_skip_pool_list.json`, JSON.stringify({
@@ -1,3 +1,4 @@
1
1
  export * from './types';
2
2
  export * from './pool_util';
3
3
  export * from './cache_pool_config';
4
+ export * from './pool_token_taxes';
@@ -17,3 +17,4 @@ Object.defineProperty(exports, "__esModule", { value: true });
17
17
  __exportStar(require("./types"), exports);
18
18
  __exportStar(require("./pool_util"), exports);
19
19
  __exportStar(require("./cache_pool_config"), exports);
20
+ __exportStar(require("./pool_token_taxes"), exports);
@@ -0,0 +1,3 @@
1
+ import { PoolTokenTaxRowType } from '../../types';
2
+ export declare const get_pool_token_taxes: () => PoolTokenTaxRowType[];
3
+ export declare function assertPoolTokenTaxRows(data: any, source: string): void;
@@ -0,0 +1,52 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.get_pool_token_taxes = void 0;
7
+ exports.assertPoolTokenTaxRows = assertPoolTokenTaxRows;
8
+ const os_1 = __importDefault(require("os"));
9
+ const path_1 = __importDefault(require("path"));
10
+ const fs_1 = __importDefault(require("fs"));
11
+ const core_env_1 = require("../appconfig/core_env");
12
+ const index_1 = require("../index");
13
+ let _first_load_logged = false;
14
+ function getPoolTokenTaxesFilePath(chainId) {
15
+ return path_1.default.join(os_1.default.homedir(), 'data', 'onchain_data', chainId.toLowerCase(), 'pool_token_taxes.json');
16
+ }
17
+ const get_pool_token_taxes = () => {
18
+ const coreEnv = (0, core_env_1.getCoreEnv)();
19
+ const chain_id = coreEnv.chain_id;
20
+ if (!chain_id) {
21
+ return [];
22
+ }
23
+ const filepath = getPoolTokenTaxesFilePath(chain_id);
24
+ if (!fs_1.default.existsSync(filepath)) {
25
+ return [];
26
+ }
27
+ const data = JSON.parse(fs_1.default.readFileSync(filepath, 'utf-8'));
28
+ assertPoolTokenTaxRows(data, filepath);
29
+ if (!_first_load_logged) {
30
+ _first_load_logged = true;
31
+ (0, index_1.log_info)(`[pool_token_taxes] loaded ${data.length} entries from ${filepath}`);
32
+ }
33
+ return data;
34
+ };
35
+ exports.get_pool_token_taxes = get_pool_token_taxes;
36
+ function assertPoolTokenTaxRows(data, source) {
37
+ if (!Array.isArray(data)) {
38
+ throw new Error(`[pool_token_taxes] ${source}: 必须是 JSON 数组`);
39
+ }
40
+ const bad = [];
41
+ for (const row of data) {
42
+ const okAddr = (v) => typeof v === 'string' && v.trim().length > 0;
43
+ const okBps = (v) => Number.isInteger(v) && v >= 0 && v <= 9999;
44
+ if (!okAddr(row === null || row === void 0 ? void 0 : row.pool_address) || !okAddr(row === null || row === void 0 ? void 0 : row.token_address) || !okBps(row === null || row === void 0 ? void 0 : row.buy_tax_bps) || !okBps(row === null || row === void 0 ? void 0 : row.sell_tax_bps)) {
45
+ bad.push(JSON.stringify(row));
46
+ }
47
+ }
48
+ if (bad.length > 0) {
49
+ throw new Error(`[pool_token_taxes] ${source}: ${bad.length} 行非法(要求 pool_address/token_address 非空、` +
50
+ `buy_tax_bps/sell_tax_bps 为 0~9999 整数): ${bad.slice(0, 5).join('; ')}`);
51
+ }
52
+ }
@@ -149,6 +149,9 @@ class AbstractTransactionResultCheck {
149
149
  execution: trade_extra_info,
150
150
  c_id
151
151
  };
152
+ const analyzeExtra = swap_result.analyze_extra;
153
+ if (analyzeExtra && typeof analyzeExtra === 'object')
154
+ Object.assign(trade_result, analyzeExtra);
152
155
  (0, analyze_1.report_data_to_analyze)('TradeResultType', trade_result);
153
156
  return trade_result;
154
157
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@clonegod/ttd-core",
3
- "version": "3.1.111",
3
+ "version": "3.1.113",
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
@@ -47,6 +47,25 @@ export interface StandardDexPoolConfigType {
47
47
  pool_list: StandardPoolInfoType[]
48
48
  }
49
49
 
50
+ /**
51
+ * 池子维度 token 转账税(fee-on-transfer,如 flap.sh 税币 MarsCoin)。
52
+ * 税挂池子维度而非 token 维度:同一 token 可能只在部分池收税
53
+ * (MARS 只在 V2 主池收 3%,V3 池免税)。
54
+ * buy_tax_bps = 池子转出该 token 时按转账金额收(用户买入实收打折)
55
+ * sell_tax_bps = 该 token 转入池子时收(池子实收打折)
56
+ */
57
+ export interface PoolTokenTaxType {
58
+ token_address: string
59
+ buy_tax_bps: number
60
+ sell_tax_bps: number
61
+ note?: string
62
+ }
63
+
64
+ /** pool_token_taxes.json 文件行:税配置表(UI 维护),market-data 同步时按 pool_address 盖章进 poolInfo */
65
+ export interface PoolTokenTaxRowType extends PoolTokenTaxType {
66
+ pool_address: string
67
+ }
68
+
50
69
  export interface StandardPoolInfoType {
51
70
  /**
52
71
  * 内部对比/Map key 专用:pool_address.toLowerCase()
@@ -78,6 +97,8 @@ export interface StandardPoolInfoType {
78
97
  vol_24h?: string|number
79
98
  update_time?: string
80
99
  is_trade_native_token?: boolean // POOL 是否交易的链原生代币(BNB)
100
+ /** token 转账税(fee-on-transfer);无税池子不带该字段。来源:pool_token_taxes.json(UI 配置),market-data 同步时盖章 */
101
+ token_taxes?: PoolTokenTaxType[]
81
102
  }
82
103
 
83
104