@clonegod/ttd-sol-common 1.0.116 → 1.0.118
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
|
-
|
|
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.
|
|
583
|
+
this.try_get_bundle_failed_result(txid, bundleId);
|
|
583
584
|
(0, dist_1.log_info)(`sendJitoBundle finish`, {
|
|
584
585
|
jitoApiUrl,
|
|
585
586
|
txid,
|
|
@@ -609,7 +610,7 @@ class RpcClient {
|
|
|
609
610
|
}
|
|
610
611
|
yield new Promise((resolve) => setTimeout(resolve, interval));
|
|
611
612
|
}
|
|
612
|
-
let err = new Error('Bundle failed to confirm within the timeout period');
|
|
613
|
+
let err = new Error('Bundle failed to confirm within the timeout period:' + timeout + 'ms');
|
|
613
614
|
(0, dist_1.log_error)(`Bundle failed to confirm, txid=${txid}`, err);
|
|
614
615
|
throw err;
|
|
615
616
|
}), 0);
|
|
@@ -712,7 +713,7 @@ class RpcClient {
|
|
|
712
713
|
});
|
|
713
714
|
const currentBlockHeight = yield solana_trade_runtime.connection.getBlockHeight();
|
|
714
715
|
const lastValidBlockHeight = Math.min(blockhash.lastValidBlockHeight, currentBlockHeight + lastValidBlockHeightOffset);
|
|
715
|
-
const timeout =
|
|
716
|
+
const timeout = 10000;
|
|
716
717
|
const interval = 5000;
|
|
717
718
|
const startTime = Date.now();
|
|
718
719
|
while (Date.now() - startTime < timeout ||
|
|
@@ -735,7 +736,7 @@ class RpcClient {
|
|
|
735
736
|
}
|
|
736
737
|
yield new Promise((resolve) => setTimeout(resolve, interval));
|
|
737
738
|
}
|
|
738
|
-
let err = new Error('Bundle failed to confirm within the timeout period');
|
|
739
|
+
let err = new Error('Bundle failed to confirm within the timeout period:' + timeout + 'ms');
|
|
739
740
|
(0, dist_1.log_error)(`Bundle failed to confirm, txid=${txid}`, err);
|
|
740
741
|
throw err;
|
|
741
742
|
}), 0);
|
|
@@ -797,19 +798,49 @@ class RpcClient {
|
|
|
797
798
|
return last_blockhash_slot;
|
|
798
799
|
});
|
|
799
800
|
}
|
|
800
|
-
|
|
801
|
-
return __awaiter(this, arguments, void 0, function* (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');
|
|
802
805
|
let start = Date.now();
|
|
803
806
|
while (Date.now() - start < timeoutMs) {
|
|
804
807
|
try {
|
|
805
|
-
let
|
|
806
|
-
|
|
807
|
-
|
|
808
|
+
let err_result = yield (yield fetch(url)).json();
|
|
809
|
+
if (err_result && err_result.length > 0) {
|
|
810
|
+
(0, dist_1.log_warn)('get_bundle_error, res=', { url, txid, check_interval, timeoutMs, err_result });
|
|
811
|
+
let appConfig = global.appConfig;
|
|
812
|
+
let mock_failed_tx = {
|
|
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(err_result),
|
|
824
|
+
logMessages: [],
|
|
825
|
+
preBalances: [0],
|
|
826
|
+
postBalances: [0]
|
|
827
|
+
}
|
|
828
|
+
}
|
|
829
|
+
}
|
|
830
|
+
}
|
|
831
|
+
};
|
|
832
|
+
appConfig.emit(common_1.LOCAL_EVENT_NAME.EVENT_WALLET_TRANSACTION + '#' + txid, JSON.stringify(mock_failed_tx));
|
|
833
|
+
break;
|
|
834
|
+
}
|
|
835
|
+
else {
|
|
836
|
+
(0, dist_1.log_debug)('get_bundle_error, res=', { url, check_interval, rs: err_result });
|
|
837
|
+
}
|
|
808
838
|
}
|
|
809
839
|
catch (err) {
|
|
810
840
|
console.error('get_bundle_error, error!', err);
|
|
841
|
+
break;
|
|
811
842
|
}
|
|
812
|
-
yield new Promise(resolve => setTimeout(resolve,
|
|
843
|
+
yield new Promise(resolve => setTimeout(resolve, check_interval));
|
|
813
844
|
}
|
|
814
845
|
});
|
|
815
846
|
}
|
|
@@ -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
|
-
|
|
63
|
-
|
|
64
|
-
|
|
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) {
|
|
@@ -71,11 +71,9 @@ class TransactionResultChecker {
|
|
|
71
71
|
else {
|
|
72
72
|
this.event_emitter.emit(dist_1.TRANSACTION_STATE_FAILED, trade_result);
|
|
73
73
|
}
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
console.log('---------------------------------------------------->');
|
|
78
|
-
}, 0);
|
|
74
|
+
console.log('<----------------------------------------------------');
|
|
75
|
+
console.dir(trade_result, { depth: 8 });
|
|
76
|
+
console.log('---------------------------------------------------->');
|
|
79
77
|
}
|
|
80
78
|
catch (err) {
|
|
81
79
|
(0, dist_1.log_error)('parse geyser stream message error!', err);
|
|
@@ -114,11 +112,11 @@ class TransactionResultChecker {
|
|
|
114
112
|
this.event_emitter.emit(dist_1.TRANSACTION_STATE_FAILED, trade_result);
|
|
115
113
|
}
|
|
116
114
|
}
|
|
117
|
-
|
|
115
|
+
if (dist_1.LOG.debug) {
|
|
118
116
|
console.log('<====================================================');
|
|
119
117
|
console.dir(trade_result, { depth: 8 });
|
|
120
118
|
console.log('====================================================>');
|
|
121
|
-
}
|
|
119
|
+
}
|
|
122
120
|
}
|
|
123
121
|
else {
|
|
124
122
|
clearInterval(intervalId);
|