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