@clonegod/ttd-bsc-common 3.0.18 → 3.0.20

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.
@@ -16,12 +16,12 @@ export interface TradeCalldata {
16
16
  export declare abstract class AbstractDexTrade extends AbastrcatTrade {
17
17
  protected appConfig: AppConfig;
18
18
  protected callerManager: CallerManager;
19
- protected provider: ethers.providers.JsonRpcProvider;
19
+ protected provider: any;
20
20
  protected transactionSender: TransactionSender;
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, _f;
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
+ JsonRpcProvider: ((_b = ethers_1.ethers.providers) === null || _b === void 0 ? void 0 : _b.JsonRpcProvider) || ethers_1.ethers.JsonRpcProvider,
28
+ id: ((_c = ethers_1.ethers.utils) === null || _c === void 0 ? void 0 : _c.id) || ethers_1.ethers.id,
29
+ formatUnits: ((_d = ethers_1.ethers.utils) === null || _d === void 0 ? void 0 : _d.formatUnits) || ethers_1.ethers.formatUnits,
30
+ parseUnits: ((_e = ethers_1.ethers.utils) === null || _e === void 0 ? void 0 : _e.parseUnits) || ethers_1.ethers.parseUnits,
31
+ keccak256: ((_f = ethers_1.ethers.utils) === null || _f === void 0 ? void 0 : _f.keccak256) || ethers_1.ethers.keccak256,
32
+ };
24
33
  function buildTradeConfig() {
25
- var _a, _b;
26
34
  const vaultGroupId = process.env.TRADE_GROUP_ID || process.env.VAULT_GROUP_ID;
27
35
  if (!vaultGroupId) {
28
36
  throw new Error('环境变量 TRADE_GROUP_ID 未配置');
@@ -36,8 +44,8 @@ function buildTradeConfig() {
36
44
  return {
37
45
  vaultAddress: vaultWallet.public_key,
38
46
  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),
47
+ pancake: ethersCompat.id(pancakeIdName),
48
+ uniswap: ethersCompat.id(uniswapIdName),
41
49
  },
42
50
  };
43
51
  }
@@ -51,11 +59,11 @@ class AbstractDexTrade extends ttd_core_1.AbastrcatTrade {
51
59
  this.initConfigs();
52
60
  this.chainNameLower = this.appConfig.env_args.chain_id.toLowerCase();
53
61
  this.redisClient = new redis_1.SimpleRedisClient(`${this.chainNameLower}:tx`);
54
- this.vaultInterface = new ethers_1.ethers.utils.Interface(VAULT_ABI);
62
+ this.vaultInterface = new ethersCompat.Interface(VAULT_ABI);
55
63
  }
56
64
  init() {
57
65
  return __awaiter(this, void 0, void 0, function* () {
58
- this.provider = new ethers_1.ethers.providers.JsonRpcProvider(this.chainConfig.rpcEndpoint);
66
+ this.provider = new ethersCompat.JsonRpcProvider(this.chainConfig.rpcEndpoint);
59
67
  this.transactionSender = new ttd_bsc_send_tx_1.TransactionSender(this.appConfig);
60
68
  const defaultCallerId = `${this.chainNameLower.toUpperCase()}-CALLER`;
61
69
  const callerGroupIds = (process.env.CALLER_GROUP_IDS || defaultCallerId).trim().split(',').filter(Boolean);
@@ -82,7 +90,7 @@ class AbstractDexTrade extends ttd_core_1.AbastrcatTrade {
82
90
  pair,
83
91
  direction: isBuy ? 'BUY' : 'SELL',
84
92
  input: `${amount} ${inputToken.symbol}`,
85
- outputMin: `${ethers_1.ethers.utils.formatUnits(amountOutMin, outputToken.decimals)} ${outputToken.symbol}`,
93
+ outputMin: `${ethersCompat.formatUnits(amountOutMin, outputToken.decimals)} ${outputToken.symbol}`,
86
94
  slippage: `${slippage_bps / 100}%`,
87
95
  });
88
96
  let maxAttempts = Math.min(Math.max(parseInt(process.env.NONCE_LOCK_MAX_RETRIES || '3'), 1), 3);
@@ -116,7 +124,7 @@ class AbstractDexTrade extends ttd_core_1.AbastrcatTrade {
116
124
  to: this.tradeConfig.vaultAddress,
117
125
  data: vaultCalldata,
118
126
  gasLimit: this.chainConfig.gasOptions.gasLimit,
119
- gasPrice: ethers_1.ethers.utils.parseUnits(realGasPriceGwei, 'gwei'),
127
+ gasPrice: ethersCompat.parseUnits(realGasPriceGwei, 'gwei'),
120
128
  nonce,
121
129
  chainId: this.chainConfig.chainId,
122
130
  value: 0,
@@ -130,7 +138,7 @@ class AbstractDexTrade extends ttd_core_1.AbastrcatTrade {
130
138
  caller.signTransaction(mainTx),
131
139
  ...builderAddresses.map(addr => this.buildTipTransferTx(addr, transfer_amount_gwei, realGasPriceGwei, tipNonce, caller)),
132
140
  ]);
133
- txid = ethers_1.ethers.utils.keccak256(signedMainTx);
141
+ txid = ethersCompat.keccak256(signedMainTx);
134
142
  const tipTxMap = new Map();
135
143
  builderAddresses.forEach((addr, idx) => tipTxMap.set(addr, signedTips[idx]));
136
144
  (0, ttd_core_1.log_info)(`交易已签名`, { txid, nonce, caller: caller.address, gasPriceGwei: realGasPriceGwei }, order_trace_id);
@@ -196,9 +204,9 @@ class AbstractDexTrade extends ttd_core_1.AbastrcatTrade {
196
204
  const tx_data = {
197
205
  from: wallet.address,
198
206
  to,
199
- value: ethers_1.ethers.utils.parseUnits(real_transfer_amount_gwei, 'gwei'),
207
+ value: ethersCompat.parseUnits(real_transfer_amount_gwei, 'gwei'),
200
208
  gasLimit: 42000,
201
- gasPrice: ethers_1.ethers.utils.parseUnits(real_gas_price_gwei, 'gwei'),
209
+ gasPrice: ethersCompat.parseUnits(real_gas_price_gwei, 'gwei'),
202
210
  nonce,
203
211
  chainId: this.chainConfig.chainId
204
212
  };
@@ -206,7 +214,7 @@ class AbstractDexTrade extends ttd_core_1.AbastrcatTrade {
206
214
  (0, ttd_core_1.log_info)(`构建 tip 转账交易`, {
207
215
  to, nonce,
208
216
  tipGwei: real_transfer_amount_gwei,
209
- txhash: ethers_1.ethers.utils.keccak256(signedTx)
217
+ txhash: ethersCompat.keccak256(signedTx)
210
218
  });
211
219
  return signedTx;
212
220
  });
@@ -230,7 +238,7 @@ class AbstractDexTrade extends ttd_core_1.AbastrcatTrade {
230
238
  expectedOut = inputAmount.mul(price);
231
239
  }
232
240
  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);
241
+ return ethersCompat.parseUnits(minOutput.toFixed(outputToken.decimals), outputToken.decimals);
234
242
  }
235
243
  extractNonceFromErrorMsg(errorMessage) {
236
244
  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.20",
4
4
  "description": "BSC common library",
5
5
  "license": "UNLICENSED",
6
6
  "main": "dist/index.js",