@clonegod/ttd-bsc-common 3.1.4 → 3.1.5

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.
@@ -8,4 +8,5 @@ export declare class BscEnvArgs extends EnvArgs {
8
8
  tx_cancel_timeout_ms: number;
9
9
  tx_cancel_gas_boost_factor: number;
10
10
  constructor();
11
+ print(moduleName?: string): void;
11
12
  }
@@ -2,18 +2,38 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.BscEnvArgs = void 0;
4
4
  const ttd_core_1 = require("@clonegod/ttd-core");
5
- const decimal_js_1 = require("decimal.js");
5
+ const BSC_KEYS = [
6
+ 'large_trade_threshold_usd',
7
+ 'gas_price_gwei',
8
+ 'gas_limit',
9
+ 'tip_amount_gwei',
10
+ 'tx_status_check_interval_mills',
11
+ 'tx_cancel_timeout_ms',
12
+ 'tx_cancel_gas_boost_factor',
13
+ ];
14
+ (0, ttd_core_1.registerEnvVars)({
15
+ large_trade_threshold_usd: { env: 'LARGE_TRADE_THRESHOLD_USD', type: 'number', default: 500, desc: '大额交易识别阈值(USD)' },
16
+ gas_price_gwei: { env: 'GAS_PRICE_GWEI', type: 'number', default: 1, desc: '交易 gas 价格(Gwei)' },
17
+ gas_limit: { env: 'GAS_LIMIT', type: 'number', default: 300000, desc: '交易 gas 上限' },
18
+ tip_amount_gwei: { env: 'EOA_TIP_AMOUNT_GWEI', type: 'number', default: 10000, desc: 'Builder tip(Gwei)' },
19
+ tx_status_check_interval_mills: { env: 'TX_STATUS_CHECK_INTERVAL_MILLS', type: 'number', default: 3000, desc: '交易状态检查间隔(ms)' },
20
+ tx_cancel_timeout_ms: { env: 'TX_CANCEL_TIMEOUT_MS', type: 'number', default: 15000, desc: '交易取消超时(ms)' },
21
+ tx_cancel_gas_boost_factor: { env: 'TX_CANCEL_GAS_PRICE_BOOST_FACTOR', type: 'number', default: 1.5, desc: '取消交易 gas 提升倍数' },
22
+ });
6
23
  class BscEnvArgs extends ttd_core_1.EnvArgs {
7
24
  constructor() {
8
25
  super();
9
- this.large_trade_threshold_usd = parseInt(process.env.LARGE_TRADE_THRESHOLD_USD || '500');
10
- this.gas_price_gwei = new decimal_js_1.Decimal(process.env.GAS_PRICE_GWEI || '1').toNumber();
11
- this.gas_limit = parseInt(process.env.GAS_LIMIT || '300000');
12
- this.tip_amount_gwei = parseInt(process.env.EOA_TIP_AMOUNT_GWEI || '10000');
13
- this.tx_status_check_interval_mills = parseInt(process.env.TX_STATUS_CHECK_INTERVAL_MILLS || '3000');
14
- this.tx_cancel_timeout_ms = parseInt(process.env.TX_CANCEL_TIMEOUT_MS || '15000');
15
- this.tx_cancel_gas_boost_factor = new decimal_js_1.Decimal(process.env.TX_CANCEL_GAS_PRICE_BOOST_FACTOR || '1.5').toNumber();
16
- this.print();
26
+ const cfg = (0, ttd_core_1.loadEnvConfig)(BSC_KEYS);
27
+ this.large_trade_threshold_usd = cfg.large_trade_threshold_usd;
28
+ this.gas_price_gwei = cfg.gas_price_gwei;
29
+ this.gas_limit = cfg.gas_limit;
30
+ this.tip_amount_gwei = cfg.tip_amount_gwei;
31
+ this.tx_status_check_interval_mills = cfg.tx_status_check_interval_mills;
32
+ this.tx_cancel_timeout_ms = cfg.tx_cancel_timeout_ms;
33
+ this.tx_cancel_gas_boost_factor = cfg.tx_cancel_gas_boost_factor;
34
+ }
35
+ print(moduleName) {
36
+ super.print(moduleName);
17
37
  }
18
38
  }
19
39
  exports.BscEnvArgs = BscEnvArgs;
@@ -2,6 +2,7 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.QuotePriceVerify = void 0;
4
4
  const trade_direction_1 = require("../../utils/trade_direction");
5
+ const ttd_core_1 = require("@clonegod/ttd-core");
5
6
  class QuotePriceVerify {
6
7
  constructor() {
7
8
  this.quoteCache = new Map();
@@ -138,7 +139,31 @@ class QuotePriceVerify {
138
139
  const swapTag = `swap[blk:${swapBlk}${swapTx}]`;
139
140
  const priceLabel = isBuy ? 'ask' : 'bid';
140
141
  const msg = ` ↳ [Verify] ${side} ${usdStr} (${tradeFlow}) ${quoteTag} ${priceLabel}=${refPrice.toFixed(12)} vs ${swapTag} exec=${execPriceNum.toFixed(12)} diff=${diffBps > 0 ? '+' : ''}${diffBps.toFixed(1)}bps ${status}${rangeTag}`;
141
- console.log(msg);
142
+ (0, ttd_core_1.log_info)(msg);
143
+ try {
144
+ (0, ttd_core_1.report_trade_analyze_data)('QuoteVerify', {
145
+ pool_address: poolAddress,
146
+ pool_name: poolName,
147
+ price_id: cached.priceId,
148
+ quote_block: cached.blockNumber,
149
+ swap_block: swapBlockNumber,
150
+ tx_hash: txHash || '',
151
+ side,
152
+ ref_price: refPrice,
153
+ exec_price: execPriceNum,
154
+ diff_bps: parseFloat(diffBps.toFixed(1)),
155
+ swap_usd: parseFloat(swapUsd.toFixed(0)),
156
+ in_range: inRange,
157
+ input_amount: inputAmountUi,
158
+ output_amount: outputAmountUi,
159
+ input_symbol: isBuy ? quoteToken.symbol : baseToken.symbol,
160
+ output_symbol: isBuy ? baseToken.symbol : quoteToken.symbol,
161
+ status,
162
+ time: Date.now(),
163
+ });
164
+ }
165
+ catch (_) {
166
+ }
142
167
  }
143
168
  }
144
169
  exports.QuotePriceVerify = QuotePriceVerify;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@clonegod/ttd-bsc-common",
3
- "version": "3.1.4",
3
+ "version": "3.1.5",
4
4
  "description": "BSC common library",
5
5
  "license": "UNLICENSED",
6
6
  "main": "dist/index.js",
@@ -14,7 +14,7 @@
14
14
  "push": "npm run build && npm publish"
15
15
  },
16
16
  "dependencies": {
17
- "@clonegod/ttd-core": "3.1.4",
17
+ "@clonegod/ttd-core": "^3.1.6",
18
18
  "axios": "^1.12.0",
19
19
  "dotenv": "^16.4.7",
20
20
  "ethers": "^5.8.0",