@clonegod/ttd-bsc-common 3.0.17 → 3.0.19

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.
@@ -21,7 +21,7 @@ export declare abstract class AbstractDexTrade extends AbastrcatTrade {
21
21
  protected chainConfig: EvmChainConfig;
22
22
  protected redisClient: SimpleRedisClient;
23
23
  protected tradeConfig: TradeConfig;
24
- protected vaultInterface: ethers.utils.Interface;
24
+ protected vaultInterface: any;
25
25
  protected chainNameLower: string;
26
26
  constructor(appConfig: AppConfig);
27
27
  protected abstract initConfigs(): void;
@@ -11,6 +11,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
11
11
  var __importDefault = (this && this.__importDefault) || function (mod) {
12
12
  return (mod && mod.__esModule) ? mod : { "default": mod };
13
13
  };
14
+ var _a, _b, _c, _d, _e;
14
15
  Object.defineProperty(exports, "__esModule", { value: true });
15
16
  exports.AbstractDexTrade = void 0;
16
17
  exports.buildTradeConfig = buildTradeConfig;
@@ -21,8 +22,15 @@ const ttd_bsc_send_tx_1 = require("@clonegod/ttd-bsc-send-tx");
21
22
  const redis_1 = require("../redis");
22
23
  const trade_direction_1 = require("../utils/trade_direction");
23
24
  const decimal_js_1 = __importDefault(require("decimal.js"));
25
+ const ethersCompat = {
26
+ Interface: ((_a = ethers_1.ethers.utils) === null || _a === void 0 ? void 0 : _a.Interface) || ethers_1.ethers.Interface,
27
+ id: ((_b = ethers_1.ethers.utils) === null || _b === void 0 ? void 0 : _b.id) || ethers_1.ethers.id,
28
+ formatUnits: ((_c = ethers_1.ethers.utils) === null || _c === void 0 ? void 0 : _c.formatUnits) || ethers_1.ethers.formatUnits,
29
+ parseUnits: ((_d = ethers_1.ethers.utils) === null || _d === void 0 ? void 0 : _d.parseUnits) || ethers_1.ethers.parseUnits,
30
+ keccak256: ((_e = ethers_1.ethers.utils) === null || _e === void 0 ? void 0 : _e.keccak256) || ethers_1.ethers.keccak256,
31
+ };
24
32
  function buildTradeConfig() {
25
- const vaultGroupId = process.env.TRADE_GROUP_ID;
33
+ const vaultGroupId = process.env.TRADE_GROUP_ID || process.env.VAULT_GROUP_ID;
26
34
  if (!vaultGroupId) {
27
35
  throw new Error('环境变量 TRADE_GROUP_ID 未配置');
28
36
  }
@@ -35,8 +43,8 @@ function buildTradeConfig() {
35
43
  return {
36
44
  vaultAddress: vaultWallet.public_key,
37
45
  executorIds: {
38
- pancake: ethers_1.ethers.utils.id(pancakeIdName),
39
- uniswap: ethers_1.ethers.utils.id(uniswapIdName),
46
+ pancake: ethersCompat.id(pancakeIdName),
47
+ uniswap: ethersCompat.id(uniswapIdName),
40
48
  },
41
49
  };
42
50
  }
@@ -50,7 +58,7 @@ class AbstractDexTrade extends ttd_core_1.AbastrcatTrade {
50
58
  this.initConfigs();
51
59
  this.chainNameLower = this.appConfig.env_args.chain_id.toLowerCase();
52
60
  this.redisClient = new redis_1.SimpleRedisClient(`${this.chainNameLower}:tx`);
53
- this.vaultInterface = new ethers_1.ethers.utils.Interface(VAULT_ABI);
61
+ this.vaultInterface = new ethersCompat.Interface(VAULT_ABI);
54
62
  }
55
63
  init() {
56
64
  return __awaiter(this, void 0, void 0, function* () {
@@ -81,7 +89,7 @@ class AbstractDexTrade extends ttd_core_1.AbastrcatTrade {
81
89
  pair,
82
90
  direction: isBuy ? 'BUY' : 'SELL',
83
91
  input: `${amount} ${inputToken.symbol}`,
84
- outputMin: `${ethers_1.ethers.utils.formatUnits(amountOutMin, outputToken.decimals)} ${outputToken.symbol}`,
92
+ outputMin: `${ethersCompat.formatUnits(amountOutMin, outputToken.decimals)} ${outputToken.symbol}`,
85
93
  slippage: `${slippage_bps / 100}%`,
86
94
  });
87
95
  let maxAttempts = Math.min(Math.max(parseInt(process.env.NONCE_LOCK_MAX_RETRIES || '3'), 1), 3);
@@ -115,7 +123,7 @@ class AbstractDexTrade extends ttd_core_1.AbastrcatTrade {
115
123
  to: this.tradeConfig.vaultAddress,
116
124
  data: vaultCalldata,
117
125
  gasLimit: this.chainConfig.gasOptions.gasLimit,
118
- gasPrice: ethers_1.ethers.utils.parseUnits(realGasPriceGwei, 'gwei'),
126
+ gasPrice: ethersCompat.parseUnits(realGasPriceGwei, 'gwei'),
119
127
  nonce,
120
128
  chainId: this.chainConfig.chainId,
121
129
  value: 0,
@@ -129,7 +137,7 @@ class AbstractDexTrade extends ttd_core_1.AbastrcatTrade {
129
137
  caller.signTransaction(mainTx),
130
138
  ...builderAddresses.map(addr => this.buildTipTransferTx(addr, transfer_amount_gwei, realGasPriceGwei, tipNonce, caller)),
131
139
  ]);
132
- txid = ethers_1.ethers.utils.keccak256(signedMainTx);
140
+ txid = ethersCompat.keccak256(signedMainTx);
133
141
  const tipTxMap = new Map();
134
142
  builderAddresses.forEach((addr, idx) => tipTxMap.set(addr, signedTips[idx]));
135
143
  (0, ttd_core_1.log_info)(`交易已签名`, { txid, nonce, caller: caller.address, gasPriceGwei: realGasPriceGwei }, order_trace_id);
@@ -195,9 +203,9 @@ class AbstractDexTrade extends ttd_core_1.AbastrcatTrade {
195
203
  const tx_data = {
196
204
  from: wallet.address,
197
205
  to,
198
- value: ethers_1.ethers.utils.parseUnits(real_transfer_amount_gwei, 'gwei'),
206
+ value: ethersCompat.parseUnits(real_transfer_amount_gwei, 'gwei'),
199
207
  gasLimit: 42000,
200
- gasPrice: ethers_1.ethers.utils.parseUnits(real_gas_price_gwei, 'gwei'),
208
+ gasPrice: ethersCompat.parseUnits(real_gas_price_gwei, 'gwei'),
201
209
  nonce,
202
210
  chainId: this.chainConfig.chainId
203
211
  };
@@ -205,7 +213,7 @@ class AbstractDexTrade extends ttd_core_1.AbastrcatTrade {
205
213
  (0, ttd_core_1.log_info)(`构建 tip 转账交易`, {
206
214
  to, nonce,
207
215
  tipGwei: real_transfer_amount_gwei,
208
- txhash: ethers_1.ethers.utils.keccak256(signedTx)
216
+ txhash: ethersCompat.keccak256(signedTx)
209
217
  });
210
218
  return signedTx;
211
219
  });
@@ -229,7 +237,7 @@ class AbstractDexTrade extends ttd_core_1.AbastrcatTrade {
229
237
  expectedOut = inputAmount.mul(price);
230
238
  }
231
239
  const minOutput = expectedOut.mul(new decimal_js_1.default(1).sub(new decimal_js_1.default(slippage)));
232
- return ethers_1.ethers.utils.parseUnits(minOutput.toFixed(outputToken.decimals), outputToken.decimals);
240
+ return ethersCompat.parseUnits(minOutput.toFixed(outputToken.decimals), outputToken.decimals);
233
241
  }
234
242
  extractNonceFromErrorMsg(errorMessage) {
235
243
  try {
@@ -44,7 +44,7 @@ class TradeResultSubscriber {
44
44
  this.ws = new ttd_core_1.WebSocketClient(wsUrl);
45
45
  this.ws.onOpen(() => {
46
46
  this.connected = true;
47
- const groupIds = (process.env.TRADE_GROUP_ID || '').split(',').map(s => s.trim()).filter(Boolean);
47
+ const groupIds = (process.env.TRADE_GROUP_ID || process.env.VAULT_GROUP_ID || '').split(',').map(s => s.trim()).filter(Boolean);
48
48
  for (const gid of groupIds) {
49
49
  const w = (0, ttd_core_1.load_wallet)(gid, true);
50
50
  if (w.public_key) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@clonegod/ttd-bsc-common",
3
- "version": "3.0.17",
3
+ "version": "3.0.19",
4
4
  "description": "BSC common library",
5
5
  "license": "UNLICENSED",
6
6
  "main": "dist/index.js",