@clonegod/ttd-sol-common 1.0.115 → 1.0.117

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.
@@ -51,5 +51,5 @@ export declare class RpcClient {
51
51
  sendSmartTransactionWithTipMixed(solana_trade_runtime: SolanaTradeRuntimeType, instructions: TransactionInstruction[], signers: Signer[], lookupTables?: AddressLookupTableAccount[], tipAmount?: number, region?: JitoRegion, feePayer?: Signer, lastValidBlockHeightOffset?: number): Promise<string>;
52
52
  sendJitoTransaction(serializedTransaction: string, jitoApiUrl: string): Promise<string>;
53
53
  get_last_blockhash_slot(connections: Connection[]): Promise<RpcResponseAndContext<BlockhashWithExpiryBlockHeight>>;
54
- check_bundle_result(bundle_id: string, timeoutMs?: number): Promise<void>;
54
+ try_get_bundle_failed_result(txid: string, bundle_id: string, timeoutMs?: number): Promise<void>;
55
55
  }
@@ -19,6 +19,7 @@ const axios_1 = __importDefault(require("axios"));
19
19
  const types_1 = require("./types");
20
20
  const get_signature_1 = require("../send_tx/get_signature");
21
21
  const dist_1 = require("@clonegod/ttd-common/dist");
22
+ const common_1 = require("../common");
22
23
  const jito_1 = require("../jito");
23
24
  class RpcClient {
24
25
  constructor(connection, id) {
@@ -579,7 +580,7 @@ class RpcClient {
579
580
  let jitoApiUrl = `${types_1.JITO_API_URLS[region]}/api/v1/bundles`;
580
581
  this.sendJitoTransaction(serializedTransaction, `${types_1.JITO_API_URLS['Default']}/api/v1/transactions?bundleOnly=true`);
581
582
  const bundleId = yield this.sendJitoBundle([serializedTransaction], jitoApiUrl);
582
- this.check_bundle_result(bundleId);
583
+ this.try_get_bundle_failed_result(txid, bundleId);
583
584
  (0, dist_1.log_info)(`sendJitoBundle finish`, {
584
585
  jitoApiUrl,
585
586
  txid,
@@ -588,10 +589,9 @@ class RpcClient {
588
589
  const currentBlockHeight = yield solana_trade_runtime.connection.getBlockHeight();
589
590
  const lastValidBlockHeight = Math.min(blockhash.lastValidBlockHeight, currentBlockHeight + lastValidBlockHeightOffset);
590
591
  const timeout = 10000;
591
- const interval = 5000;
592
+ const interval = 2000;
592
593
  const startTime = Date.now();
593
- while (Date.now() - startTime < timeout ||
594
- (yield this.connection.getBlockHeight()) <= lastValidBlockHeight) {
594
+ while (Date.now() - startTime < timeout) {
595
595
  const bundleStatuses = yield this.getBundleStatuses([bundleId], jitoApiUrl);
596
596
  (0, dist_1.log_info)(`getBundleStatuses`, {
597
597
  txid,
@@ -798,20 +798,47 @@ class RpcClient {
798
798
  return last_blockhash_slot;
799
799
  });
800
800
  }
801
- check_bundle_result(bundle_id_1) {
802
- return __awaiter(this, arguments, void 0, function* (bundle_id, timeoutMs = 3000) {
803
- this.jitoClient.confirmInflightBundle(bundle_id, timeoutMs);
801
+ try_get_bundle_failed_result(txid_1, bundle_id_1) {
802
+ return __awaiter(this, arguments, void 0, function* (txid, bundle_id, timeoutMs = 90000) {
803
+ let url = `https://bundles.jito.wtf/api/v1/bundles/get_bundle_error/${bundle_id}`;
804
+ let check_interval = parseInt(process.env.CHECK_BUNDLE_ERROR_INTERVAL_MILLS || '7000');
804
805
  let start = Date.now();
805
806
  while (Date.now() - start < timeoutMs) {
806
807
  try {
807
- let rs = yield fetch(`https://bundles.jito.wtf/api/v1/bundles/get_bundle_error/${bundle_id}`);
808
- let jsonObj = yield rs.json();
809
- console.log('get_bundle_error, res=', jsonObj);
808
+ let rs = yield (yield fetch(url)).json();
809
+ if (rs && rs.length > 0) {
810
+ (0, dist_1.log_warn)('get_bundle_error, res=', { url, txid, check_interval, timeoutMs, rs });
811
+ let appConfig = global.appConfig;
812
+ let mock_tx_obj = {
813
+ params: {
814
+ result: {
815
+ signature: txid,
816
+ slot: -1,
817
+ transaction: {
818
+ transaction: {
819
+ signatures: [txid]
820
+ },
821
+ version: 0,
822
+ meta: {
823
+ err: JSON.stringify(rs),
824
+ logMessages: []
825
+ }
826
+ }
827
+ }
828
+ }
829
+ };
830
+ appConfig.emit(common_1.LOCAL_EVENT_NAME.EVENT_WALLET_TRANSACTION + '#' + txid, JSON.stringify(mock_tx_obj));
831
+ break;
832
+ }
833
+ else {
834
+ (0, dist_1.log_debug)('get_bundle_error, res=', { url, check_interval, rs });
835
+ }
810
836
  }
811
837
  catch (err) {
812
838
  console.error('get_bundle_error, error!', err);
839
+ break;
813
840
  }
814
- yield new Promise(resolve => setTimeout(resolve, 500));
841
+ yield new Promise(resolve => setTimeout(resolve, check_interval));
815
842
  }
816
843
  });
817
844
  }
@@ -59,11 +59,9 @@ const try_lock_order_msg = (appConfig, order_msg) => __awaiter(void 0, void 0, v
59
59
  exports.try_lock_order_msg = try_lock_order_msg;
60
60
  const handle_order_message = (appConfig, trade, message) => __awaiter(void 0, void 0, void 0, function* () {
61
61
  (0, dist_1.new_line)(3);
62
- setTimeout(() => {
63
- console.log(`=================================================================================`);
64
- console.log(`| NEW ORDER MESSAGE |`);
65
- console.log(`=================================================================================`);
66
- }, 0);
62
+ console.log(`=================================================================================`);
63
+ console.log(`| NEW ORDER MESSAGE |`);
64
+ console.log(`=================================================================================`);
67
65
  (0, dist_1.log_info)(`handle_order_message, on message: `, message);
68
66
  let order_event_message = JSON.parse(message);
69
67
  if (dist_1.LOG.debug) {
@@ -73,12 +71,14 @@ const handle_order_message = (appConfig, trade, message) => __awaiter(void 0, vo
73
71
  let { price_msg, id_parts } = yield check_parse_order_msg(appConfig, order_msg);
74
72
  let { order_trace_id } = order_msg;
75
73
  let { chain_id, dex_id, pool_id, fee_rate } = id_parts;
76
- let lock_order = yield (0, exports.try_lock_order_msg)(appConfig, order_msg);
77
- if (!lock_order) {
78
- (0, dist_1.log_warn)(`try lock order failed!`, {
79
- chain_id, group_id, order_trace_id
80
- });
81
- return;
74
+ if (process.env.ENABLE_MULTIPLE_PROCESS === 'true') {
75
+ let lock_order = yield (0, exports.try_lock_order_msg)(appConfig, order_msg);
76
+ if (!lock_order) {
77
+ (0, dist_1.log_warn)(`try lock order failed!`, {
78
+ chain_id, group_id, order_trace_id
79
+ });
80
+ return;
81
+ }
82
82
  }
83
83
  let context;
84
84
  let txid = '';
@@ -87,7 +87,7 @@ class TransactionResultChecker {
87
87
  return __awaiter(this, void 0, void 0, function* () {
88
88
  const check_start_time = Date.now();
89
89
  const check_interval = parseInt(process.env.CHECK_TX_RESULT_INTERVAL_MILLS || '1000');
90
- const check_timeout = parseInt(process.env.CHECK_TX_RESULT_TIMEOUT_MILLS || '30000');
90
+ const check_timeout = parseInt(process.env.CHECK_TX_RESULT_TIMEOUT_MILLS || '6000');
91
91
  const intervalId = setInterval(() => __awaiter(this, void 0, void 0, function* () {
92
92
  this.check_count += 1;
93
93
  (0, dist_1.log_info)(`check transaction start: seq=[${this.check_count}], txhash= ${this.txid}, trace_id=${this.trace_id}`);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@clonegod/ttd-sol-common",
3
- "version": "1.0.115",
3
+ "version": "1.0.117",
4
4
  "description": "",
5
5
  "main": "dist/index.js",
6
6
  "types": "types/index.d.ts",