@clonegod/ttd-core 3.1.57 → 3.1.59

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.
@@ -24,7 +24,6 @@ export declare const ALERT_TYPES: {
24
24
  readonly QUOTE_POOL_INIT_FAILED: AlertTypeDef;
25
25
  readonly QUOTE_V2_STALL: AlertTypeDef;
26
26
  readonly QUOTE_VERIFY_HIGH_DRIFT: AlertTypeDef;
27
- readonly QUOTE_HOOK_FEE_CHANGE: AlertTypeDef;
28
27
  readonly TRADE_NONCE_DESYNC: AlertTypeDef;
29
28
  readonly TRADE_CALLER_LOW_BALANCE: AlertTypeDef;
30
29
  readonly TRADE_TX_PENDING_TOO_LONG: AlertTypeDef;
@@ -138,7 +138,6 @@ exports.ALERT_TYPES = {
138
138
  QUOTE_POOL_INIT_FAILED: def('quote.pool_init_failed', 'critical', { display: '池子初始化失败', ttl_ms: 0, enable: true }),
139
139
  QUOTE_V2_STALL: def('quote.v2_stall', 'warn', { display: 'V2 事件流停摆(降级 V1)', ttl_ms: 60000, enable: true, auto_resolve_on_recheck: true }),
140
140
  QUOTE_VERIFY_HIGH_DRIFT: def('quote.verify_high_drift', 'warn', { display: '报价反校验偏差超阈值', ttl_ms: 300000, enable: true }),
141
- QUOTE_HOOK_FEE_CHANGE: def('quote.hook_fee_change', 'info', { display: 'Hook 动态 fee 变化', ttl_ms: 0, enable: true, kind: 'event' }),
142
141
  TRADE_NONCE_DESYNC: def('trade.nonce_desync', 'critical', { display: 'Nonce 不同步', ttl_ms: 30000, enable: true, auto_resolve_on_recheck: true }),
143
142
  TRADE_CALLER_LOW_BALANCE: def('trade.caller_low_balance', 'warn', { display: 'Caller 余额不足', ttl_ms: 300000, enable: true }),
144
143
  TRADE_TX_PENDING_TOO_LONG: def('trade.tx_pending_too_long', 'warn', { display: '交易长时间未上链', ttl_ms: 60000, enable: true }),
@@ -28,10 +28,12 @@ export interface OrderbookTier {
28
28
  pct: number;
29
29
  price: number;
30
30
  amount: number;
31
+ usdValue: number;
31
32
  }
32
33
  export interface OrderbookEntry {
33
34
  price: number;
34
35
  amount: number;
36
+ usdValue: number;
35
37
  tiers: OrderbookTier[];
36
38
  }
37
39
  export declare function toOrderbookEntry(q: QuoteEntry): OrderbookEntry;
@@ -7,7 +7,8 @@ function toOrderbookEntry(q) {
7
7
  return {
8
8
  price: q.price,
9
9
  amount: q.amount,
10
- tiers: q.tiers.map(t => ({ pct: t.pct, price: t.price, amount: t.amount })),
10
+ usdValue: q.amount_in_usd,
11
+ tiers: q.tiers.map(t => ({ pct: t.pct, price: t.price, amount: t.amount, usdValue: t.amount_in_usd })),
11
12
  };
12
13
  }
13
14
  const PCT_LEVEL_DEFAULT = [0.1, 0.2, 0.3, 0.5, 1.0];
@@ -21,13 +21,13 @@ function on_quote_response(opts) {
21
21
  price_time: priceTime,
22
22
  total_quote_time: priceTime - streamTime
23
23
  };
24
- (0, to_price_message_1.to_price_message)(appConfig, quoteAmountUsd, 0, quoteAskPrice, quoteBidPrice, poolInfo, time, String(blockNumber), source, depth)
24
+ (0, to_price_message_1.to_price_message)(appConfig, quoteAmountUsd, 0, quoteAskPrice, quoteBidPrice, poolInfo, time, blockNumber, source, depth)
25
25
  .then((price_msg) => {
26
26
  if (pushPriceMessage) {
27
27
  (0, publish_quote_price_1.publish_quote_price)(appConfig, price_msg);
28
28
  }
29
29
  (0, log_quote_price_1.log_quote_price)(String(blockNumber), price_msg, txid);
30
- (0, analyze_1.report_data_to_analyze)('PriceMessageType', Object.assign(Object.assign({}, price_msg), { quote_source: { slot: String(blockNumber), block: null, txid } }));
30
+ (0, analyze_1.report_data_to_analyze)('PriceMessageType', Object.assign(Object.assign({}, price_msg), { quote_source: { block_number: blockNumber, txid } }));
31
31
  if (depth) {
32
32
  (0, analyze_1.report_data_to_analyze)('DepthLevels', {
33
33
  price_id: price_msg.price_id,
@@ -2,5 +2,5 @@ import { StandardPoolInfoType, QuoteTimeInfoType, PriceMessageType } from '../..
2
2
  import { AppConfig } from '../appconfig';
3
3
  import { QuoteDepthOutput } from './depth_tier';
4
4
  export declare const get_quote_token_decimals: (pool_info: StandardPoolInfoType) => number;
5
- export declare function to_price_message(appConfig: AppConfig, quote_amount_usd: number, tx_price: number, quote_ask_price: number, quote_bid_price: number, pool_info: StandardPoolInfoType, time: QuoteTimeInfoType, slot: string | undefined, source: string, depth?: QuoteDepthOutput): Promise<PriceMessageType>;
5
+ export declare function to_price_message(appConfig: AppConfig, quote_amount_usd: number, tx_price: number, quote_ask_price: number, quote_bid_price: number, pool_info: StandardPoolInfoType, time: QuoteTimeInfoType, blockNumber: number, source: string, depth?: QuoteDepthOutput): Promise<PriceMessageType>;
6
6
  export declare function normalize_pair_name(priceMessage: PriceMessageType): void;
@@ -26,7 +26,7 @@ const get_quote_token_decimals = (pool_info) => {
26
26
  return decimals;
27
27
  };
28
28
  exports.get_quote_token_decimals = get_quote_token_decimals;
29
- function to_price_message(appConfig, quote_amount_usd, tx_price, quote_ask_price, quote_bid_price, pool_info, time, slot, source, depth) {
29
+ function to_price_message(appConfig, quote_amount_usd, tx_price, quote_ask_price, quote_bid_price, pool_info, time, blockNumber, source, depth) {
30
30
  return __awaiter(this, void 0, void 0, function* () {
31
31
  let { pool_address, tokenA, tokenB } = pool_info;
32
32
  let { dex_id, pool_name, fee_rate, is_reverse_token } = yield appConfig.arb_cache.get_one_pool_info(pool_address);
@@ -40,8 +40,8 @@ function to_price_message(appConfig, quote_amount_usd, tx_price, quote_ask_price
40
40
  let mid_price;
41
41
  let fee_rate_bps;
42
42
  if (depth) {
43
- ask = depth.ask;
44
- bid = depth.bid;
43
+ ask = quote_ask_price > 0 ? Object.assign(Object.assign({}, depth.ask), { price: quote_ask_price.toFixed(12) }) : depth.ask;
44
+ bid = quote_bid_price > 0 ? Object.assign(Object.assign({}, depth.bid), { price: quote_bid_price.toFixed(12) }) : depth.bid;
45
45
  mid_price = depth.mid_price;
46
46
  fee_rate_bps = depth.fee_rate_bps;
47
47
  }
@@ -84,8 +84,7 @@ function to_price_message(appConfig, quote_amount_usd, tx_price, quote_ask_price
84
84
  ask,
85
85
  bid,
86
86
  time,
87
- slot: slot !== null && slot !== void 0 ? slot : '',
88
- blockNumber: slot ? parseInt(slot, 10) || undefined : undefined,
87
+ blockNumber: blockNumber > 0 ? blockNumber : undefined,
89
88
  source: source !== null && source !== void 0 ? source : '',
90
89
  };
91
90
  normalize_pair_name(price_message);
@@ -51,7 +51,7 @@ class AbstractTransactionResultCheck {
51
51
  }
52
52
  map_swap_result_to_tx_result(swap_result) {
53
53
  var _a;
54
- let { success, error_code, wallet, block_number, block_time: order_block_time, txid, tx_price, tokenA, tokenB, gas_fee } = swap_result;
54
+ let { success, error_code, wallet, block_number, tx_index, block_time: order_block_time, txid, tx_price, tokenA, tokenB, gas_fee } = swap_result;
55
55
  if (this.context.ui_tip_amount) {
56
56
  gas_fee.priority_fee = this.context.ui_tip_amount;
57
57
  gas_fee.total_fee = gas_fee.base_fee + gas_fee.priority_fee;
@@ -81,6 +81,7 @@ class AbstractTransactionResultCheck {
81
81
  total_order_time,
82
82
  };
83
83
  time.order_block_number = block_number || 0;
84
+ time.order_tx_index = tx_index || 0;
84
85
  const _marks = (_a = this.context) === null || _a === void 0 ? void 0 : _a._execution_marks;
85
86
  if (_marks) {
86
87
  ;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@clonegod/ttd-core",
3
- "version": "3.1.57",
3
+ "version": "3.1.59",
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
@@ -285,15 +285,15 @@ export interface PriceMessageType {
285
285
  /** 买方报价:同上,两种形态共存 */
286
286
  bid: QuoteEntry | PriceType
287
287
  time: QuoteTimeInfoType // quote 耗时数据
288
- slot: string // 询价生成的价格,所对应的slot (account, vaultA, vaultB)
289
- blockNumber?: number // 报价基于的区块号
288
+ /** 报价基于的区块号;0 / 缺失表示无 block 信息(如 PriceFeed 路径) */
289
+ blockNumber: number
290
290
  quote_source?: QuoteSourceType // 触发本次询价的事件源信息
291
291
  source?: string // 报价来源:rpc:v1, QuickNode:v2, YYWS:v3
292
292
  }
293
293
 
294
294
  export interface QuoteSourceType {
295
- slot: string
296
- block: string
295
+ /** 触发本次询价的事件所在 block;0 表示无 block 信息 */
296
+ block_number: number
297
297
  txid: string
298
298
  }
299
299
 
@@ -349,15 +349,11 @@ export interface Ladder {
349
349
  /** 默认主档(0.2%)目标价;字符串以保持 wire 兼容性 */
350
350
  price: string
351
351
  /** 默认主档(0.2%)可成交 base token 数量 */
352
- amount: string
352
+ qty: string
353
+ /** 默认主档(0.2%)该档位 USD 估值 */
354
+ usd_value: string
353
355
  /** 多档完整数据(按 pct 升序:0.1, 0.2, 0.3, 0.5, 1.0) */
354
- tiers: { pct: number; price: string; amount: string }[]
355
-
356
- // 询价生成的价格,所对应的slot (account, vaultA, vaultB)
357
- slot: string
358
-
359
- // 区块号
360
- blockNumber?: string
356
+ tiers: { pct: number; price: string; qty: string; usd_value: string }[]
361
357
 
362
358
  // 价格来源: "rpc:v1" | "{provider_id}:v2" | "{provider_id}:v3"
363
359
  source?: string
@@ -428,6 +424,8 @@ export interface StandardSwapDetailType {
428
424
  txid: string,
429
425
  block_time: number
430
426
  block_number: number
427
+ /** 交易在区块内的位置(从 receipt.transactionIndex 读);解析失败则 0 */
428
+ tx_index: number
431
429
 
432
430
  pool_address: string
433
431
  tokenA: TokenBalanceChangeType
@@ -940,7 +938,6 @@ export interface AnalyzeTierLevelType {
940
938
  amount_in_usd: number
941
939
  fee: number
942
940
  fee_usd: number
943
- cumulative_usd: number
944
941
  tick_move?: string
945
942
  }
946
943
 
@@ -1026,6 +1023,8 @@ export interface AnalyzeQuoteSnapshotType {
1026
1023
  bid: string
1027
1024
  block_number: number
1028
1025
  source_txid: string
1026
+ /** 报价来源标签: 'rpc:v1' | '{provider}:v2' | '{provider}:v3' */
1027
+ source?: string
1029
1028
  stream_recv_time: number
1030
1029
  price_ready_time: number
1031
1030
  }