@clonegod/ttd-bsc-common 3.1.5 → 3.1.11

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.
@@ -1,12 +1,15 @@
1
1
  import { EnvArgs } from '@clonegod/ttd-core';
2
2
  export declare class BscEnvArgs extends EnvArgs {
3
- large_trade_threshold_usd: number;
4
3
  gas_price_gwei: number;
5
4
  gas_limit: number;
6
5
  tip_amount_gwei: number;
7
6
  tx_status_check_interval_mills: number;
8
7
  tx_cancel_timeout_ms: number;
9
8
  tx_cancel_gas_boost_factor: number;
9
+ send_tx_blockrazor_bundle: boolean;
10
+ send_tx_48club_bundle: boolean;
11
+ send_tx_48club_bundle_ws: boolean;
12
+ send_tx_blox_bundle_ws: boolean;
10
13
  constructor();
11
14
  print(moduleName?: string): void;
12
15
  }
@@ -3,34 +3,52 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.BscEnvArgs = void 0;
4
4
  const ttd_core_1 = require("@clonegod/ttd-core");
5
5
  const BSC_KEYS = [
6
- 'large_trade_threshold_usd',
7
6
  'gas_price_gwei',
8
7
  'gas_limit',
9
8
  'tip_amount_gwei',
10
9
  'tx_status_check_interval_mills',
11
10
  'tx_cancel_timeout_ms',
12
11
  'tx_cancel_gas_boost_factor',
12
+ 'send_tx_blockrazor_bundle',
13
+ 'send_tx_48club_bundle',
14
+ 'send_tx_48club_bundle_ws',
15
+ 'send_tx_blox_bundle_ws',
13
16
  ];
14
17
  (0, ttd_core_1.registerEnvVars)({
15
- large_trade_threshold_usd: { env: 'LARGE_TRADE_THRESHOLD_USD', type: 'number', default: 500, desc: '大额交易识别阈值(USD)' },
16
18
  gas_price_gwei: { env: 'GAS_PRICE_GWEI', type: 'number', default: 1, desc: '交易 gas 价格(Gwei)' },
17
19
  gas_limit: { env: 'GAS_LIMIT', type: 'number', default: 300000, desc: '交易 gas 上限' },
18
20
  tip_amount_gwei: { env: 'EOA_TIP_AMOUNT_GWEI', type: 'number', default: 10000, desc: 'Builder tip(Gwei)' },
19
21
  tx_status_check_interval_mills: { env: 'TX_STATUS_CHECK_INTERVAL_MILLS', type: 'number', default: 3000, desc: '交易状态检查间隔(ms)' },
20
22
  tx_cancel_timeout_ms: { env: 'TX_CANCEL_TIMEOUT_MS', type: 'number', default: 15000, desc: '交易取消超时(ms)' },
21
23
  tx_cancel_gas_boost_factor: { env: 'TX_CANCEL_GAS_PRICE_BOOST_FACTOR', type: 'number', default: 1.5, desc: '取消交易 gas 提升倍数' },
24
+ send_tx_blockrazor_bundle: { env: 'SEND_TX_BLOCKRAZOR_BUNDLE', type: 'boolean', default: false, desc: 'BlockRazor Bundle 开关' },
25
+ send_tx_48club_bundle: { env: 'SEND_TX_48CLUB_BUNDLE', type: 'boolean', default: false, desc: '48Club Bundle HTTP 开关' },
26
+ send_tx_48club_bundle_ws: { env: 'SEND_TX_48CLUB_BUNDLE_WS', type: 'boolean', default: false, desc: '48Club Bundle WS 开关' },
27
+ send_tx_blox_bundle_ws: { env: 'SEND_TX_BLOX_BUNDLE_WS', type: 'boolean', default: false, desc: 'BloxRoute Bundle WS 开关' },
28
+ stream_quote_ws_host: { env: 'STREAM_QUOTE_WS_HOST', type: 'string', default: '127.0.0.1', desc: 'stream-quote WS 地址' },
29
+ min_quote_interval_ms: { env: 'MIN_QUOTE_INTERVAL_MS', type: 'number', default: 10000, desc: '最小询价间隔(ms)' },
30
+ skip_price_feed_yynode: { env: 'SKIP_PRICE_FEED_YYNODE', type: 'boolean', default: false, desc: '跳过 YYNode PriceFeed' },
31
+ push_price_feed: { env: 'PUSH_PRICE_FEED', type: 'boolean', default: false, desc: 'PriceFeed 推送开关' },
32
+ need_block_time_info: { env: 'NEED_BLOCK_TIME_INFO', type: 'boolean', default: false, desc: '区块时间信息开关' },
33
+ tick_cache_neighboring_words: { env: 'TICK_CACHE_NEIGHBORING_WORDS', type: 'number', default: 2, desc: 'tick 预加载 words 数' },
34
+ tick_cache_ttl: { env: 'TICK_CACHE_TTL', type: 'number', default: 30000, desc: 'tick 缓存 TTL(ms)' },
35
+ tick_cache_min_update_interval: { env: 'TICK_CACHE_MIN_UPDATE_INTERVAL', type: 'number', default: 3000, desc: 'tick 最小刷新间隔(ms)' },
36
+ tick_cache_force_full_refresh: { env: 'TICK_CACHE_FORCE_FULL_REFRESH_INTERVAL', type: 'number', default: 60000, desc: 'tick 全量刷新间隔(ms)' },
22
37
  });
23
38
  class BscEnvArgs extends ttd_core_1.EnvArgs {
24
39
  constructor() {
25
40
  super();
26
41
  const cfg = (0, ttd_core_1.loadEnvConfig)(BSC_KEYS);
27
- this.large_trade_threshold_usd = cfg.large_trade_threshold_usd;
28
42
  this.gas_price_gwei = cfg.gas_price_gwei;
29
43
  this.gas_limit = cfg.gas_limit;
30
44
  this.tip_amount_gwei = cfg.tip_amount_gwei;
31
45
  this.tx_status_check_interval_mills = cfg.tx_status_check_interval_mills;
32
46
  this.tx_cancel_timeout_ms = cfg.tx_cancel_timeout_ms;
33
47
  this.tx_cancel_gas_boost_factor = cfg.tx_cancel_gas_boost_factor;
48
+ this.send_tx_blockrazor_bundle = cfg.send_tx_blockrazor_bundle;
49
+ this.send_tx_48club_bundle = cfg.send_tx_48club_bundle;
50
+ this.send_tx_48club_bundle_ws = cfg.send_tx_48club_bundle_ws;
51
+ this.send_tx_blox_bundle_ws = cfg.send_tx_blox_bundle_ws;
34
52
  }
35
53
  print(moduleName) {
36
54
  super.print(moduleName);
package/dist/index.d.ts CHANGED
@@ -4,6 +4,5 @@ export * from './quote';
4
4
  export * from './trade';
5
5
  export * from './types';
6
6
  export * from './utils';
7
- export * from './redis';
8
7
  export * from './ws';
9
8
  export * from './send-tx';
package/dist/index.js CHANGED
@@ -20,6 +20,5 @@ __exportStar(require("./quote"), exports);
20
20
  __exportStar(require("./trade"), exports);
21
21
  __exportStar(require("./types"), exports);
22
22
  __exportStar(require("./utils"), exports);
23
- __exportStar(require("./redis"), exports);
24
23
  __exportStar(require("./ws"), exports);
25
24
  __exportStar(require("./send-tx"), exports);
@@ -3,7 +3,7 @@ import { ethers } from "ethers";
3
3
  import { EvmChainConfig } from "../types";
4
4
  import { CallerManager } from "./caller_manager";
5
5
  import { ITransactionSender } from "../send-tx";
6
- import { SimpleRedisClient } from "../redis";
6
+ import { RedisClient } from "@clonegod/ttd-core";
7
7
  export interface TradeConfig {
8
8
  vaultAddress: string;
9
9
  executorIds: Record<string, string>;
@@ -19,7 +19,7 @@ export declare abstract class AbstractDexTrade extends AbastrcatTrade {
19
19
  protected provider: any;
20
20
  protected transactionSender: ITransactionSender;
21
21
  protected chainConfig: EvmChainConfig;
22
- protected redisClient: SimpleRedisClient;
22
+ protected redisClient: RedisClient;
23
23
  protected tradeConfig: TradeConfig;
24
24
  protected vaultInterface: any;
25
25
  protected chainNameLower: string;
@@ -45,7 +45,7 @@ const path = __importStar(require("path"));
45
45
  const caller_manager_1 = require("./caller_manager");
46
46
  const send_tx_1 = require("../send-tx");
47
47
  const base_tx_result_checker_1 = require("./check/base_tx_result_checker");
48
- const redis_1 = require("../redis");
48
+ const ttd_core_2 = require("@clonegod/ttd-core");
49
49
  const trade_direction_1 = require("../utils/trade_direction");
50
50
  const ethers_compat_1 = require("../utils/ethers_compat");
51
51
  const fast_signer_1 = require("../utils/fast_signer");
@@ -79,7 +79,7 @@ class AbstractDexTrade extends ttd_core_1.AbastrcatTrade {
79
79
  this.appConfig = appConfig;
80
80
  this.initConfigs();
81
81
  this.chainNameLower = this.appConfig.env_args.chain_id.toLowerCase();
82
- this.redisClient = new redis_1.SimpleRedisClient(`${this.chainNameLower}:tx`);
82
+ this.redisClient = new ttd_core_2.RedisClient(`${this.chainNameLower}:tx`);
83
83
  this.vaultInterface = new ethers_compat_1.ethersCompat.Interface(VAULT_ABI);
84
84
  }
85
85
  async init(transactionSender) {
@@ -156,11 +156,14 @@ class AbstractDexTrade extends ttd_core_1.AbastrcatTrade {
156
156
  chainId: this.chainConfig.chainId,
157
157
  value: 0,
158
158
  };
159
- const builderAddresses = [
160
- send_tx_1.BSC_EOA_ADDRESS.BLOCKRAZOR,
161
- send_tx_1.BSC_EOA_ADDRESS._48CLUB,
162
- send_tx_1.BSC_EOA_ADDRESS.BLXR,
163
- ];
159
+ const env = this.appConfig.env_args;
160
+ const builderAddresses = [];
161
+ if (env.send_tx_blockrazor_bundle)
162
+ builderAddresses.push(send_tx_1.BSC_EOA_ADDRESS.BLOCKRAZOR);
163
+ if (env.send_tx_48club_bundle || env.send_tx_48club_bundle_ws)
164
+ builderAddresses.push(send_tx_1.BSC_EOA_ADDRESS._48CLUB);
165
+ if (env.send_tx_blox_bundle_ws)
166
+ builderAddresses.push(send_tx_1.BSC_EOA_ADDRESS.BLXR);
164
167
  const [rawMainTx, ...rawTips] = await Promise.all([
165
168
  caller.signTransaction(mainTx),
166
169
  ...builderAddresses.map(addr => this.buildTipTransferTx(addr, transfer_amount_gwei, realGasPriceGwei, tipNonce, caller)),
@@ -4,7 +4,7 @@ exports.CallerManager = void 0;
4
4
  const dist_1 = require("@clonegod/ttd-core/dist");
5
5
  const logger = (0, dist_1.createLogger)(__filename);
6
6
  const ethers_1 = require("ethers");
7
- const redis_1 = require("../redis");
7
+ const ttd_core_1 = require("@clonegod/ttd-core");
8
8
  const CALLER_NONCE_KEY = 'caller:nonce';
9
9
  const CALLER_LAST_USED_KEY = 'caller:last_used';
10
10
  const VAULT_CALLERS_KEY = 'vault:callers';
@@ -12,13 +12,13 @@ class CallerManager {
12
12
  constructor(config) {
13
13
  this.callers = [];
14
14
  this.config = config;
15
- this.redis = new redis_1.SimpleRedisClient(`${config.chainName}:caller`);
15
+ this.redis = new ttd_core_1.RedisClient(`${config.chainName}:caller`);
16
16
  }
17
17
  async init() {
18
18
  const walletInfos = (0, dist_1.load_wallet_multi)(this.config.callerGroupIds, false);
19
19
  const allWallets = walletInfos.map(info => new ethers_1.ethers.Wallet(info.private_key, this.config.provider));
20
20
  const vaultCallersKey = `${this.config.chainName}:${VAULT_CALLERS_KEY}`;
21
- const rawJson = await this.redis.hgetvalue(vaultCallersKey, this.config.groupId);
21
+ const rawJson = await this.redis.hget(vaultCallersKey, this.config.groupId);
22
22
  let allowedAddresses = [];
23
23
  if (rawJson) {
24
24
  try {
@@ -96,13 +96,13 @@ class CallerManager {
96
96
  }
97
97
  }
98
98
  callerAddr = addresses[selectedIdx];
99
- await this.redis.hsetValue(lastUsedKey, callerAddr, String(Date.now()), 24 * 60 * 60);
99
+ await this.redis.hset(lastUsedKey, callerAddr, String(Date.now()), 24 * 60 * 60);
100
100
  }
101
101
  finally {
102
102
  this.redis.releaseLock(lockKey, lockValue).catch(() => { });
103
103
  }
104
104
  const nonceKey = this.getNonceRedisKey();
105
- const nonceStr = await this.redis.hgetvalue(nonceKey, callerAddr);
105
+ const nonceStr = await this.redis.hget(nonceKey, callerAddr);
106
106
  if (nonceStr === null || nonceStr === undefined) {
107
107
  throw new Error(`Caller ${callerAddr} nonce not found in Redis, stream-trade may not be running`);
108
108
  }
@@ -140,7 +140,7 @@ class CallerManager {
140
140
  }
141
141
  async getNonce(address) {
142
142
  const nonceKey = this.getNonceRedisKey();
143
- const val = await this.redis.hgetvalue(nonceKey, address.toLowerCase());
143
+ const val = await this.redis.hget(nonceKey, address.toLowerCase());
144
144
  if (val !== null && val !== undefined) {
145
145
  return parseInt(val, 10);
146
146
  }
@@ -148,7 +148,7 @@ class CallerManager {
148
148
  }
149
149
  async setNonce(address, nonce) {
150
150
  const nonceKey = this.getNonceRedisKey();
151
- await this.redis.hsetValue(nonceKey, address.toLowerCase(), String(nonce), 24 * 60 * 60);
151
+ await this.redis.hset(nonceKey, address.toLowerCase(), String(nonce), 24 * 60 * 60);
152
152
  }
153
153
  }
154
154
  exports.CallerManager = CallerManager;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@clonegod/ttd-bsc-common",
3
- "version": "3.1.5",
3
+ "version": "3.1.11",
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.6",
17
+ "@clonegod/ttd-core": "^3.1.11",
18
18
  "axios": "^1.12.0",
19
19
  "dotenv": "^16.4.7",
20
20
  "ethers": "^5.8.0",