@clonegod/ttd-core 3.1.37 → 3.1.39
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.
- package/dist/appconfig/EnvArgs.d.ts +0 -1
- package/dist/appconfig/env_registry.js +0 -1
- package/dist/index.d.ts +3 -5
- package/dist/index.js +18 -19
- package/dist/market_price/estimate_token_amount.js +1 -1
- package/dist/quote/to_price_message.js +2 -2
- package/dist/util/httputil.js +3 -5
- package/package.json +1 -1
|
@@ -31,7 +31,6 @@ export declare class EnvArgs {
|
|
|
31
31
|
trade_log_report_cex_url: string;
|
|
32
32
|
trade_log_report_cex_data_type: string;
|
|
33
33
|
token_price_refresh_interval_seconds: number;
|
|
34
|
-
token_market_price_url: string;
|
|
35
34
|
wallet_dir: string;
|
|
36
35
|
encryption_key: string;
|
|
37
36
|
providers_file_path: string;
|
|
@@ -44,7 +44,6 @@ registerEnvVars({
|
|
|
44
44
|
trade_analyze_url: { env: 'TRADE_ANALYZE_URL', type: 'string', default: '', desc: 'analyze HTTP 基址(旧 EnvArgs;未配则 analyze 上报走默认拼接)' },
|
|
45
45
|
providers_file_path: { env: 'PROVIDERS_FILE_PATH', type: 'string', default: '', desc: 'stream-quote providers.json 绝对路径;留空则仅写 Redis' },
|
|
46
46
|
token_price_refresh_interval_seconds: { env: 'TOKEN_PRICE_REFRESH_INTERVAL_SECONDS', type: 'number', default: 600, desc: 'TokenPriceSyncer 刷价周期(s):market-data 通过 force_fetch 拉外部价(DefiLlama→Gecko→...)并直接批量写入 Redis + 发 TOKEN_CONFIG_CHANGE 事件的频率' },
|
|
47
|
-
token_market_price_url: { env: 'TOKEN_MARKET_PRICE_URL', type: 'string', default: '', desc: '【使用方: ttd-core estimate_token_amount】config-center 市价估算 HTTP 基址;为空则跳过远程回退' },
|
|
48
47
|
fixed_symbol_address_file: { env: 'FIXED_SYMBOL_ADDRESS_FILE', type: 'string', default: '', desc: '固定 symbol/address 映射文件路径(覆盖默认按 CHAIN_ID 推断的路径)' },
|
|
49
48
|
zh_pinyin_map_file: { env: 'ZH_PINYIN_MAP_FILE', type: 'string', default: '', desc: '中文拼音映射文件路径(覆盖默认路径)' },
|
|
50
49
|
server_ip_list: { env: 'SERVER_IP_LIST', type: 'string', default: '', desc: '服务器可用 IP 列表(逗号分隔);配置后优先使用;为空则从网卡探测并结合 IP_EXCLUDE_PREFIX 过滤' },
|
package/dist/index.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import BN from 'bn.js';
|
|
2
2
|
import Decimal from 'decimal.js';
|
|
3
3
|
import fs from "fs";
|
|
4
|
-
import {
|
|
4
|
+
import { StandardPoolInfoType, StandardTokenInfoType, TokenPriceWithAmountType, TradeResponseType, UniqueOrderbookIdType, WalletInfoType } from '../types';
|
|
5
5
|
import * as redis from './redis';
|
|
6
6
|
import * as cache from './cache';
|
|
7
7
|
export * from './analyze';
|
|
@@ -9,7 +9,6 @@ export * from './appconfig';
|
|
|
9
9
|
export * from './redis';
|
|
10
10
|
export * from './cache';
|
|
11
11
|
export * from './constants';
|
|
12
|
-
export * from './market_price';
|
|
13
12
|
export * from './pool';
|
|
14
13
|
export * from './quote';
|
|
15
14
|
export * from './token';
|
|
@@ -117,7 +116,6 @@ export declare enum OnChainDataSubscribeType {
|
|
|
117
116
|
export declare enum CACHE_KEY_TYPE {
|
|
118
117
|
CONFIG_TOKEN_LIST = "c:token",
|
|
119
118
|
CONFIG_POOL_LIST = "c:pool",
|
|
120
|
-
CONFIG_PAIR_LIST = "c:pair",
|
|
121
119
|
CONFIG_TRADE_SERVICE = "c:trade",
|
|
122
120
|
QUOTE_PRICE = "q:price",
|
|
123
121
|
ORDER_MESSAGE = "o:msg",
|
|
@@ -130,7 +128,8 @@ export declare enum LOCAL_EVENT_NAME {
|
|
|
130
128
|
EVENT_WALLET_TRANSACTION = "EVENT_WALLET_TRANSACTION",
|
|
131
129
|
EVENT_WALLET_TRANSACTION_NEW_TXID = "EVENT_WALLET_TRANSACTION_NEW_TXID"
|
|
132
130
|
}
|
|
133
|
-
export declare const
|
|
131
|
+
export declare const clean_token_symbol: (symbol: string) => string;
|
|
132
|
+
export declare const format_pair_symbol: (symbol: string) => string;
|
|
134
133
|
export declare const format_unique_orderbook_id: (chain_id: CHAIN_ID, dex_id: DEX_ID, pool_id: string, fee_rate: number) => string;
|
|
135
134
|
export declare const parse_unique_orderbook_id: (unique_orderbook_id: string) => UniqueOrderbookIdType;
|
|
136
135
|
export declare const format_unique_order_msg_id: (group_id: string, price_id: string, order_trace_id: string) => string;
|
|
@@ -262,7 +261,6 @@ export declare const failed: (err: Error, error_code?: string, code?: number) =>
|
|
|
262
261
|
msg: string;
|
|
263
262
|
error_code: string;
|
|
264
263
|
};
|
|
265
|
-
export declare const estimate_amount_in_token: (arb_cache: ArbCache, token: StandardTokenInfoType, amount_in_usd: number, query_token_market_price_url?: string) => Promise<string>;
|
|
266
264
|
export declare const calc_amount_in_token: (amount_in_usd: number, market_price: string, token_info: StandardTokenInfoType) => TokenPriceWithAmountType;
|
|
267
265
|
export declare const get_input_out_token: (poolInfo: StandardPoolInfoType, aToB: boolean) => {
|
|
268
266
|
inputToken: StandardTokenInfoType;
|
package/dist/index.js
CHANGED
|
@@ -48,8 +48,8 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
48
48
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
49
49
|
};
|
|
50
50
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
51
|
-
exports.
|
|
52
|
-
exports.inspect_arb_local_cache = exports.save_trade_execution_logs = exports.get_input_out_token_fix = exports.get_input_out_token = exports.calc_amount_in_token = exports.
|
|
51
|
+
exports.DATE_TIME_FORMAT_DEFAULT = exports.to_json_str = exports.DecimalUtil = exports.generateRandomNumber = exports.LOG = exports._active_log_level = exports.LOG_LEVEL = exports.REDIS_EVENT_TYPE_TRADE_INSTANCE_CHANGE = exports.REDIS_EVENT_TYPE_ORDER = exports.REDIS_EVENT_TYPE_QUOTE = exports.REDIS_EVENT_TYPE_CONFIG_CHANGE = exports.REDIS_EVENT_CHANNEL = exports.get_new_block_channel_name = exports.get_tx_result_channel_name = exports.get_wallet_raw_tx_channel_name = exports.get_order_channel_name = exports.get_quote_channel_name = exports.get_config_channel_name = exports.get_cache_key = exports.getArbEventSubscriber = exports.getArbEventPublisher = exports.getArbCache = exports.getLoadingCache = exports.getRedisClient = exports.format_order_lock_key = exports.format_unique_order_msg_id = exports.parse_unique_orderbook_id = exports.format_unique_orderbook_id = exports.format_pair_symbol = exports.clean_token_symbol = exports.LOCAL_EVENT_NAME = exports.CACHE_KEY_TYPE = exports.OnChainDataSubscribeType = exports.TradeErrorCodeType = exports.SystemErrorCodeType = exports.TRADE_TYPE = exports.GROUP_ID = exports.DEX_ID = exports.CHAIN_ID = exports.STREAMING_TRANSACTION_CONFIRMED = exports.TRANSACTION_STATE_FAILED = exports.TRANSACTION_STATE_SUCCESS = exports.TRANSACTION_STATE_PROCESSING = exports.QUOTE_AMOUNT_USD_MAX = exports.QUOTE_AMOUNT_USD_MIN = exports.REGEX_HEX_PREFIX = exports.PROCESSING = exports.NOT_FOUND = exports.SUCCESS = exports.FAILED = void 0;
|
|
52
|
+
exports.inspect_arb_local_cache = exports.save_trade_execution_logs = exports.get_input_out_token_fix = exports.get_input_out_token = exports.calc_amount_in_token = exports.failed = exports.success = exports.home_dir = exports.postJSON = exports.deep_merge_object = exports.isArray = exports.isTrue = exports.deep_clone = exports.uuid = exports.DATE_TIME_FORMAT_NO_WHITESPACE = void 0;
|
|
53
53
|
exports._caller = _caller;
|
|
54
54
|
exports.log_trace = log_trace;
|
|
55
55
|
exports.log_debug = log_debug;
|
|
@@ -86,14 +86,12 @@ const os_1 = __importDefault(require("os"));
|
|
|
86
86
|
const path_1 = __importDefault(require("path"));
|
|
87
87
|
const redis = __importStar(require("./redis"));
|
|
88
88
|
const cache = __importStar(require("./cache"));
|
|
89
|
-
const market_price_1 = require("./market_price");
|
|
90
89
|
const crypto_1 = require("./util/crypto");
|
|
91
90
|
__exportStar(require("./analyze"), exports);
|
|
92
91
|
__exportStar(require("./appconfig"), exports);
|
|
93
92
|
__exportStar(require("./redis"), exports);
|
|
94
93
|
__exportStar(require("./cache"), exports);
|
|
95
94
|
__exportStar(require("./constants"), exports);
|
|
96
|
-
__exportStar(require("./market_price"), exports);
|
|
97
95
|
__exportStar(require("./pool"), exports);
|
|
98
96
|
__exportStar(require("./quote"), exports);
|
|
99
97
|
__exportStar(require("./token"), exports);
|
|
@@ -209,7 +207,6 @@ var CACHE_KEY_TYPE;
|
|
|
209
207
|
(function (CACHE_KEY_TYPE) {
|
|
210
208
|
CACHE_KEY_TYPE["CONFIG_TOKEN_LIST"] = "c:token";
|
|
211
209
|
CACHE_KEY_TYPE["CONFIG_POOL_LIST"] = "c:pool";
|
|
212
|
-
CACHE_KEY_TYPE["CONFIG_PAIR_LIST"] = "c:pair";
|
|
213
210
|
CACHE_KEY_TYPE["CONFIG_TRADE_SERVICE"] = "c:trade";
|
|
214
211
|
CACHE_KEY_TYPE["QUOTE_PRICE"] = "q:price";
|
|
215
212
|
CACHE_KEY_TYPE["ORDER_MESSAGE"] = "o:msg";
|
|
@@ -223,18 +220,24 @@ var LOCAL_EVENT_NAME;
|
|
|
223
220
|
LOCAL_EVENT_NAME["EVENT_WALLET_TRANSACTION"] = "EVENT_WALLET_TRANSACTION";
|
|
224
221
|
LOCAL_EVENT_NAME["EVENT_WALLET_TRANSACTION_NEW_TXID"] = "EVENT_WALLET_TRANSACTION_NEW_TXID";
|
|
225
222
|
})(LOCAL_EVENT_NAME || (exports.LOCAL_EVENT_NAME = LOCAL_EVENT_NAME = {}));
|
|
226
|
-
const
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
.replace(
|
|
231
|
-
.replace(
|
|
232
|
-
.replace('WETH', 'ETH')
|
|
233
|
-
.replace('WBNB', 'BNB')
|
|
234
|
-
.replace('WOKB', 'OKB')
|
|
223
|
+
const clean_token_symbol = (symbol) => {
|
|
224
|
+
if (!symbol)
|
|
225
|
+
return symbol;
|
|
226
|
+
return symbol
|
|
227
|
+
.replace(/\$/g, '')
|
|
228
|
+
.replace(/\s+/g, '')
|
|
235
229
|
.toUpperCase();
|
|
236
230
|
};
|
|
237
|
-
exports.
|
|
231
|
+
exports.clean_token_symbol = clean_token_symbol;
|
|
232
|
+
const format_pair_symbol = (symbol) => {
|
|
233
|
+
if (!symbol)
|
|
234
|
+
return symbol;
|
|
235
|
+
return (0, exports.clean_token_symbol)(symbol)
|
|
236
|
+
.replace('USDC', 'USDT').replace('USD1', 'USDT')
|
|
237
|
+
.replace('WTRX', 'TRX').replace('WSOL', 'SOL').replace('WBTC', 'BTC')
|
|
238
|
+
.replace('WETH', 'ETH').replace('WBNB', 'BNB').replace('WOKB', 'OKB');
|
|
239
|
+
};
|
|
240
|
+
exports.format_pair_symbol = format_pair_symbol;
|
|
238
241
|
const format_unique_orderbook_id = (chain_id, dex_id, pool_id, fee_rate) => {
|
|
239
242
|
return `${chain_id}_${dex_id}_${pool_id}_${fee_rate}`;
|
|
240
243
|
};
|
|
@@ -776,10 +779,6 @@ const failed = (err, error_code = 'SYSTEM_ERROR', code = 500) => {
|
|
|
776
779
|
};
|
|
777
780
|
};
|
|
778
781
|
exports.failed = failed;
|
|
779
|
-
const estimate_amount_in_token = (arb_cache_1, token_1, amount_in_usd_1, ...args_1) => __awaiter(void 0, [arb_cache_1, token_1, amount_in_usd_1, ...args_1], void 0, function* (arb_cache, token, amount_in_usd, query_token_market_price_url = '') {
|
|
780
|
-
return yield market_price_1.EstimateAmountInToken.estimate_amount_in_token(arb_cache, token, amount_in_usd, query_token_market_price_url);
|
|
781
|
-
});
|
|
782
|
-
exports.estimate_amount_in_token = estimate_amount_in_token;
|
|
783
782
|
const calc_amount_in_token = (amount_in_usd, market_price, token_info) => {
|
|
784
783
|
if (isEmpty(market_price) || Number(market_price) === 0) {
|
|
785
784
|
throw new Error(`calc_token_amount_out error! invalid argument! market_price=${market_price}`);
|
|
@@ -43,7 +43,7 @@ class EstimateAmountInToken {
|
|
|
43
43
|
if (index_1.LOG.debug) {
|
|
44
44
|
(0, index_1.log_debug)('estimate_amount_in_token, start');
|
|
45
45
|
}
|
|
46
|
-
let symbol = (0, index_1.
|
|
46
|
+
let symbol = (0, index_1.clean_token_symbol)(token.symbol);
|
|
47
47
|
let amountInToken;
|
|
48
48
|
let token_info;
|
|
49
49
|
try {
|
|
@@ -112,7 +112,7 @@ function normalize_pair_name(priceMessage) {
|
|
|
112
112
|
pool_name = pool_name.split('/')[1] + '/' + pool_name.split('/')[0];
|
|
113
113
|
}
|
|
114
114
|
const dex_pair_names = pool_name.split('/');
|
|
115
|
-
let cex_base_token = (0, __1.
|
|
116
|
-
let cex_qutoe_token = (0, __1.
|
|
115
|
+
let cex_base_token = (0, __1.format_pair_symbol)(dex_pair_names[0]);
|
|
116
|
+
let cex_qutoe_token = (0, __1.format_pair_symbol)(dex_pair_names[1]);
|
|
117
117
|
priceMessage.pair = cex_base_token.toUpperCase() + '/' + cex_qutoe_token.toUpperCase();
|
|
118
118
|
}
|
package/dist/util/httputil.js
CHANGED
|
@@ -103,15 +103,13 @@ function createAxiosInstance() {
|
|
|
103
103
|
return config;
|
|
104
104
|
});
|
|
105
105
|
instance.interceptors.response.use((response) => response, (error) => {
|
|
106
|
-
var _a;
|
|
106
|
+
var _a, _b;
|
|
107
107
|
const simplifiedError = simplifyAxiosError(error);
|
|
108
108
|
const url = ((_a = error.config) === null || _a === void 0 ? void 0 : _a.url) || 'unknown url';
|
|
109
|
-
console.
|
|
109
|
+
console.warn(`[HttpUtil] ${url} → ${simplifiedError}`);
|
|
110
110
|
const simplifiedAxiosError = new Error(simplifiedError);
|
|
111
111
|
simplifiedAxiosError.isAxiosError = true;
|
|
112
|
-
simplifiedAxiosError.
|
|
113
|
-
simplifiedAxiosError.response = error.response;
|
|
114
|
-
simplifiedAxiosError.request = error.request;
|
|
112
|
+
simplifiedAxiosError.status = (_b = error.response) === null || _b === void 0 ? void 0 : _b.status;
|
|
115
113
|
return Promise.reject(simplifiedAxiosError);
|
|
116
114
|
});
|
|
117
115
|
return instance;
|