@clonegod/ttd-bsc-common 3.0.26 → 3.0.28

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.
package/dist/index.d.ts CHANGED
@@ -6,3 +6,4 @@ export * from './types';
6
6
  export * from './utils';
7
7
  export * from './redis';
8
8
  export * from './ws';
9
+ export * from './send-tx';
package/dist/index.js CHANGED
@@ -22,3 +22,4 @@ __exportStar(require("./types"), exports);
22
22
  __exportStar(require("./utils"), exports);
23
23
  __exportStar(require("./redis"), exports);
24
24
  __exportStar(require("./ws"), exports);
25
+ __exportStar(require("./send-tx"), exports);
@@ -0,0 +1,5 @@
1
+ export declare enum BSC_EOA_ADDRESS {
2
+ BLOCKRAZOR = "0x1266C6bE60392A8Ff346E8d5ECCd3E69dD9c5F20",
3
+ _48CLUB = "0x4848489f0b2BEdd788c696e2D79b6b69D7484848",
4
+ BLXR = "0x74c5F8C6ffe41AD4789602BDB9a48E6Cad623520"
5
+ }
@@ -0,0 +1,9 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.BSC_EOA_ADDRESS = void 0;
4
+ var BSC_EOA_ADDRESS;
5
+ (function (BSC_EOA_ADDRESS) {
6
+ BSC_EOA_ADDRESS["BLOCKRAZOR"] = "0x1266C6bE60392A8Ff346E8d5ECCd3E69dD9c5F20";
7
+ BSC_EOA_ADDRESS["_48CLUB"] = "0x4848489f0b2BEdd788c696e2D79b6b69D7484848";
8
+ BSC_EOA_ADDRESS["BLXR"] = "0x74c5F8C6ffe41AD4789602BDB9a48E6Cad623520";
9
+ })(BSC_EOA_ADDRESS || (exports.BSC_EOA_ADDRESS = BSC_EOA_ADDRESS = {}));
@@ -0,0 +1,2 @@
1
+ export * from './types';
2
+ export * from './constants';
@@ -0,0 +1,18 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ __exportStar(require("./types"), exports);
18
+ __exportStar(require("./constants"), exports);
@@ -0,0 +1,3 @@
1
+ export interface ITransactionSender {
2
+ sendTransaction(signedMainTx: string, eoa_tip_transaction: (eoa_address: string) => Promise<string>, order_trace_id: string, pair?: string, only_bundle?: boolean): Promise<string[]>;
3
+ }
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -2,7 +2,7 @@ import { AbastrcatTrade, AppConfig, TradeContext } from '@clonegod/ttd-core';
2
2
  import { ethers } from "ethers";
3
3
  import { EvmChainConfig } from "../types";
4
4
  import { CallerManager } from "./caller_manager";
5
- import { TransactionSender } from "@clonegod/ttd-bsc-send-tx";
5
+ import { ITransactionSender } from "../send-tx";
6
6
  import { SimpleRedisClient } from "../redis";
7
7
  export interface TradeConfig {
8
8
  vaultAddress: string;
@@ -17,7 +17,7 @@ export declare abstract class AbstractDexTrade extends AbastrcatTrade {
17
17
  protected appConfig: AppConfig;
18
18
  protected callerManager: CallerManager;
19
19
  protected provider: any;
20
- protected transactionSender: TransactionSender;
20
+ protected transactionSender: ITransactionSender;
21
21
  protected chainConfig: EvmChainConfig;
22
22
  protected redisClient: SimpleRedisClient;
23
23
  protected tradeConfig: TradeConfig;
@@ -26,7 +26,7 @@ export declare abstract class AbstractDexTrade extends AbastrcatTrade {
26
26
  constructor(appConfig: AppConfig);
27
27
  protected abstract initConfigs(): void;
28
28
  abstract encodeTradeData(context: TradeContext): TradeCalldata;
29
- init(): Promise<void>;
29
+ init(transactionSender?: ITransactionSender): Promise<void>;
30
30
  execute(context: TradeContext): Promise<string>;
31
31
  protected getGasPriceGwei(context: TradeContext): string;
32
32
  protected getBuilderTipAmoutGwei(context: TradeContext): string;
@@ -16,7 +16,8 @@ exports.AbstractDexTrade = void 0;
16
16
  exports.buildTradeConfig = buildTradeConfig;
17
17
  const ttd_core_1 = require("@clonegod/ttd-core");
18
18
  const caller_manager_1 = require("./caller_manager");
19
- const ttd_bsc_send_tx_1 = require("@clonegod/ttd-bsc-send-tx");
19
+ const send_tx_1 = require("../send-tx");
20
+ const base_tx_result_checker_1 = require("./check/base_tx_result_checker");
20
21
  const redis_1 = require("../redis");
21
22
  const trade_direction_1 = require("../utils/trade_direction");
22
23
  const ethers_compat_1 = require("../utils/ethers_compat");
@@ -52,10 +53,12 @@ class AbstractDexTrade extends ttd_core_1.AbastrcatTrade {
52
53
  this.redisClient = new redis_1.SimpleRedisClient(`${this.chainNameLower}:tx`);
53
54
  this.vaultInterface = new ethers_compat_1.ethersCompat.Interface(VAULT_ABI);
54
55
  }
55
- init() {
56
+ init(transactionSender) {
56
57
  return __awaiter(this, void 0, void 0, function* () {
57
58
  this.provider = new ethers_compat_1.ethersCompat.JsonRpcProvider(this.chainConfig.rpcEndpoint);
58
- this.transactionSender = new ttd_bsc_send_tx_1.TransactionSender(this.appConfig);
59
+ if (transactionSender) {
60
+ this.transactionSender = transactionSender;
61
+ }
59
62
  const defaultCallerId = `${this.chainNameLower.toUpperCase()}-CALLER`;
60
63
  const callerGroupIds = (process.env.CALLER_GROUP_IDS || defaultCallerId).trim().split(',').filter(Boolean);
61
64
  this.callerManager = new caller_manager_1.CallerManager({
@@ -112,7 +115,6 @@ class AbstractDexTrade extends ttd_core_1.AbastrcatTrade {
112
115
  const transfer_amount_gwei = this.getBuilderTipAmoutGwei(context);
113
116
  context.ui_tip_amount = new decimal_js_1.default(transfer_amount_gwei).div(Math.pow(10, 9)).toNumber();
114
117
  const mainTx = {
115
- type: 0,
116
118
  to: this.tradeConfig.vaultAddress,
117
119
  data: vaultCalldata,
118
120
  gasLimit: this.chainConfig.gasOptions.gasLimit,
@@ -122,9 +124,9 @@ class AbstractDexTrade extends ttd_core_1.AbastrcatTrade {
122
124
  value: 0,
123
125
  };
124
126
  const builderAddresses = [
125
- ttd_bsc_send_tx_1.BSC_EOA_ADDRESS.BLOCKRAZOR,
126
- ttd_bsc_send_tx_1.BSC_EOA_ADDRESS._48CLUB,
127
- ttd_bsc_send_tx_1.BSC_EOA_ADDRESS.BLXR,
127
+ send_tx_1.BSC_EOA_ADDRESS.BLOCKRAZOR,
128
+ send_tx_1.BSC_EOA_ADDRESS._48CLUB,
129
+ send_tx_1.BSC_EOA_ADDRESS.BLXR,
128
130
  ];
129
131
  const [rawMainTx, ...rawTips] = yield Promise.all([
130
132
  caller.signTransaction(mainTx),
@@ -146,6 +148,10 @@ class AbstractDexTrade extends ttd_core_1.AbastrcatTrade {
146
148
  pair, direction: isBuy ? 'BUY' : 'SELL',
147
149
  txid, attempt: i, caller: caller.address
148
150
  }, order_trace_id);
151
+ try {
152
+ base_tx_result_checker_1.TradeResultSubscriber.getInstance().sendNonceWatch(caller.address, txid);
153
+ }
154
+ catch (_b) { }
149
155
  return txid;
150
156
  }
151
157
  catch (error) {
@@ -197,8 +203,6 @@ class AbstractDexTrade extends ttd_core_1.AbastrcatTrade {
197
203
  const real_transfer_amount_gwei = Math.min(Number(transfer_amount_gwei), this.chainConfig.gasOptions.maxTipAmountGwei).toString();
198
204
  const real_gas_price_gwei = Math.min(Number(gas_price_gwei), this.chainConfig.gasOptions.maxGasPriceGwei).toString();
199
205
  const tx_data = {
200
- type: 0,
201
- from: wallet.address,
202
206
  to,
203
207
  value: ethers_compat_1.ethersCompat.parseUnits(real_transfer_amount_gwei, 'gwei'),
204
208
  gasLimit: 21000,
@@ -1,6 +1,17 @@
1
1
  import { EnvArgs } from '@clonegod/ttd-core';
2
2
  import { AbstractTransactionResultCheck } from "@clonegod/ttd-core/dist/trade";
3
3
  import { EventEmitter } from 'events';
4
+ export declare class TradeResultSubscriber {
5
+ private static instance;
6
+ private ws;
7
+ private connected;
8
+ private listeners;
9
+ static getInstance(): TradeResultSubscriber;
10
+ listen(txHash: string, callback: (receipt: any) => void, timeoutMs?: number): void;
11
+ remove(txHash: string): void;
12
+ sendNonceWatch(caller: string, txHash: string): void;
13
+ private ensureConnected;
14
+ }
4
15
  export declare abstract class BaseTxResultChecker extends AbstractTransactionResultCheck {
5
16
  protected provider: any;
6
17
  constructor(env_args: EnvArgs, event_emitter: EventEmitter);
@@ -9,7 +9,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
9
9
  });
10
10
  };
11
11
  Object.defineProperty(exports, "__esModule", { value: true });
12
- exports.BaseTxResultChecker = void 0;
12
+ exports.BaseTxResultChecker = exports.TradeResultSubscriber = void 0;
13
13
  const ttd_core_1 = require("@clonegod/ttd-core");
14
14
  const trade_1 = require("@clonegod/ttd-core/dist/trade");
15
15
  const ethers_compat_1 = require("../../utils/ethers_compat");
@@ -36,6 +36,12 @@ class TradeResultSubscriber {
36
36
  remove(txHash) {
37
37
  this.listeners.delete(txHash.toLowerCase());
38
38
  }
39
+ sendNonceWatch(caller, txHash) {
40
+ this.ensureConnected();
41
+ if (this.ws && this.connected) {
42
+ this.ws.send(JSON.stringify({ type: 'nonceWatch', caller, txHash }));
43
+ }
44
+ }
39
45
  ensureConnected() {
40
46
  if (this.ws && this.connected)
41
47
  return;
@@ -69,6 +75,7 @@ class TradeResultSubscriber {
69
75
  this.ws.connect();
70
76
  }
71
77
  }
78
+ exports.TradeResultSubscriber = TradeResultSubscriber;
72
79
  TradeResultSubscriber.instance = null;
73
80
  class BaseTxResultChecker extends trade_1.AbstractTransactionResultCheck {
74
81
  constructor(env_args, event_emitter) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@clonegod/ttd-bsc-common",
3
- "version": "3.0.26",
3
+ "version": "3.0.28",
4
4
  "description": "BSC common library",
5
5
  "license": "UNLICENSED",
6
6
  "main": "dist/index.js",
@@ -15,7 +15,7 @@
15
15
  },
16
16
  "dependencies": {
17
17
  "@clonegod/ttd-core": "3.0.8",
18
- "@clonegod/ttd-bsc-send-tx": "1.0.1",
18
+ "@clonegod/ttd-bsc-send-tx": "2.0.3",
19
19
  "axios": "^1.12.0",
20
20
  "dotenv": "^16.4.7",
21
21
  "ethers": "^5.8.0"