@clonegod/ttd-sol-common 1.0.117 → 1.0.119
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.
|
@@ -49,7 +49,8 @@ export declare class RpcClient {
|
|
|
49
49
|
getTokenAccounts(params: DAS.GetTokenAccountsRequest): Promise<DAS.GetTokenAccountsResponse>;
|
|
50
50
|
sendTransaction(transaction: Transaction | VersionedTransaction, options?: HeliusSendOptions): Promise<TransactionSignature>;
|
|
51
51
|
sendSmartTransactionWithTipMixed(solana_trade_runtime: SolanaTradeRuntimeType, instructions: TransactionInstruction[], signers: Signer[], lookupTables?: AddressLookupTableAccount[], tipAmount?: number, region?: JitoRegion, feePayer?: Signer, lastValidBlockHeightOffset?: number): Promise<string>;
|
|
52
|
-
sendJitoTransaction(serializedTransaction: string, jitoApiUrl: string): Promise<string>;
|
|
52
|
+
sendJitoTransaction(serializedTransaction: string, jitoApiUrl: string, encoding?: 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
|
+
send_tx_to_all_jito_region(serializedTransaction: string, encoding: string): Promise<string>;
|
|
55
56
|
}
|
|
@@ -485,7 +485,7 @@ class RpcClient {
|
|
|
485
485
|
let error;
|
|
486
486
|
do {
|
|
487
487
|
try {
|
|
488
|
-
const signature = yield this.connection.sendRawTransaction(transaction.serialize(), Object.assign({ maxRetries: 3, preflightCommitment: 'confirmed', skipPreflight: sendOptions.skipPreflight, minContextSlot }, sendOptions));
|
|
488
|
+
const signature = yield this.connection.sendRawTransaction(transaction.serialize({ verifySignatures: false }), Object.assign({ maxRetries: 3, preflightCommitment: 'confirmed', skipPreflight: sendOptions.skipPreflight, minContextSlot }, sendOptions));
|
|
489
489
|
const abortSignal = AbortSignal.timeout(15000);
|
|
490
490
|
yield this.connection.confirmTransaction({
|
|
491
491
|
abortSignal,
|
|
@@ -576,10 +576,10 @@ class RpcClient {
|
|
|
576
576
|
const { transaction, blockhash } = yield this.createSmartTransactionWithTip(solana_trade_runtime, instructions, signers, lookupTables, tipAmount, feePayer);
|
|
577
577
|
let txid = (0, get_signature_1.getSignature)(transaction);
|
|
578
578
|
setTimeout(() => __awaiter(this, void 0, void 0, function* () {
|
|
579
|
-
const
|
|
579
|
+
const encoding = 'base64';
|
|
580
|
+
const serializedTransaction = transaction.serialize({ verifySignatures: false }).toString(encoding);
|
|
580
581
|
let jitoApiUrl = `${types_1.JITO_API_URLS[region]}/api/v1/bundles`;
|
|
581
|
-
this.
|
|
582
|
-
const bundleId = yield this.sendJitoBundle([serializedTransaction], jitoApiUrl);
|
|
582
|
+
const bundleId = yield this.send_tx_to_all_jito_region(serializedTransaction, encoding);
|
|
583
583
|
this.try_get_bundle_failed_result(txid, bundleId);
|
|
584
584
|
(0, dist_1.log_info)(`sendJitoBundle finish`, {
|
|
585
585
|
jitoApiUrl,
|
|
@@ -593,7 +593,7 @@ class RpcClient {
|
|
|
593
593
|
const startTime = Date.now();
|
|
594
594
|
while (Date.now() - startTime < timeout) {
|
|
595
595
|
const bundleStatuses = yield this.getBundleStatuses([bundleId], jitoApiUrl);
|
|
596
|
-
(0, dist_1.
|
|
596
|
+
(0, dist_1.log_debug)(`getBundleStatuses success`, {
|
|
597
597
|
txid,
|
|
598
598
|
bundleId,
|
|
599
599
|
jitoApiUrl,
|
|
@@ -610,7 +610,7 @@ class RpcClient {
|
|
|
610
610
|
}
|
|
611
611
|
yield new Promise((resolve) => setTimeout(resolve, interval));
|
|
612
612
|
}
|
|
613
|
-
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');
|
|
614
614
|
(0, dist_1.log_error)(`Bundle failed to confirm, txid=${txid}`, err);
|
|
615
615
|
throw err;
|
|
616
616
|
}), 0);
|
|
@@ -664,7 +664,7 @@ class RpcClient {
|
|
|
664
664
|
rawTransaction = Buffer.from(transaction.serialize()).toString('base64');
|
|
665
665
|
}
|
|
666
666
|
else {
|
|
667
|
-
rawTransaction = transaction.serialize().toString('base64');
|
|
667
|
+
rawTransaction = transaction.serialize({ verifySignatures: false }).toString('base64');
|
|
668
668
|
}
|
|
669
669
|
try {
|
|
670
670
|
const url = `${this.connection.rpcEndpoint}`;
|
|
@@ -701,7 +701,7 @@ class RpcClient {
|
|
|
701
701
|
const { transaction, blockhash } = yield this.createSmartTransactionWithTip(solana_trade_runtime, instructions, signers, lookupTables, tipAmount, feePayer);
|
|
702
702
|
let txid = (0, get_signature_1.getSignature)(transaction);
|
|
703
703
|
setTimeout(() => __awaiter(this, void 0, void 0, function* () {
|
|
704
|
-
const serializedTransaction = bs58_1.default.encode(transaction.serialize());
|
|
704
|
+
const serializedTransaction = bs58_1.default.encode(transaction.serialize({ verifySignatures: false }));
|
|
705
705
|
let jitoApiUrl = `${types_1.JITO_API_URLS[region]}/api/v1/bundles`;
|
|
706
706
|
(0, dist_1.log_info)('sendSmartTransactionWithTipMixed, start');
|
|
707
707
|
this.sendTransaction(transaction);
|
|
@@ -713,7 +713,7 @@ class RpcClient {
|
|
|
713
713
|
});
|
|
714
714
|
const currentBlockHeight = yield solana_trade_runtime.connection.getBlockHeight();
|
|
715
715
|
const lastValidBlockHeight = Math.min(blockhash.lastValidBlockHeight, currentBlockHeight + lastValidBlockHeightOffset);
|
|
716
|
-
const timeout =
|
|
716
|
+
const timeout = 10000;
|
|
717
717
|
const interval = 5000;
|
|
718
718
|
const startTime = Date.now();
|
|
719
719
|
while (Date.now() - startTime < timeout ||
|
|
@@ -736,23 +736,31 @@ class RpcClient {
|
|
|
736
736
|
}
|
|
737
737
|
yield new Promise((resolve) => setTimeout(resolve, interval));
|
|
738
738
|
}
|
|
739
|
-
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');
|
|
740
740
|
(0, dist_1.log_error)(`Bundle failed to confirm, txid=${txid}`, err);
|
|
741
741
|
throw err;
|
|
742
742
|
}), 0);
|
|
743
743
|
return txid;
|
|
744
744
|
});
|
|
745
745
|
}
|
|
746
|
-
sendJitoTransaction(
|
|
747
|
-
return __awaiter(this,
|
|
748
|
-
|
|
749
|
-
|
|
750
|
-
|
|
746
|
+
sendJitoTransaction(serializedTransaction_1, jitoApiUrl_1) {
|
|
747
|
+
return __awaiter(this, arguments, void 0, function* (serializedTransaction, jitoApiUrl, encoding = 'base64') {
|
|
748
|
+
let start = Date.now();
|
|
749
|
+
let params;
|
|
750
|
+
if (encoding === 'base64') {
|
|
751
|
+
params = [serializedTransaction, { encoding }];
|
|
752
|
+
}
|
|
753
|
+
else if (encoding === 'bs58') {
|
|
754
|
+
params = [serializedTransaction];
|
|
755
|
+
}
|
|
756
|
+
else {
|
|
757
|
+
throw new Error('Invalid type of encoding:' + encoding);
|
|
758
|
+
}
|
|
751
759
|
const response = yield axios_1.default.post(jitoApiUrl, {
|
|
752
760
|
jsonrpc: '2.0',
|
|
753
761
|
id: 1,
|
|
754
762
|
method: 'sendTransaction',
|
|
755
|
-
params
|
|
763
|
+
params,
|
|
756
764
|
}, {
|
|
757
765
|
headers: { 'Content-Type': 'application/json' },
|
|
758
766
|
});
|
|
@@ -762,7 +770,9 @@ class RpcClient {
|
|
|
762
770
|
let bundleId = response.headers['x-bundle-id'];
|
|
763
771
|
(0, dist_1.log_info)('sendJitoTransaction finish', {
|
|
764
772
|
jitoApiUrl,
|
|
765
|
-
|
|
773
|
+
encoding,
|
|
774
|
+
bundleId,
|
|
775
|
+
take: (Date.now() - start) + 'ms'
|
|
766
776
|
});
|
|
767
777
|
return bundleId;
|
|
768
778
|
});
|
|
@@ -805,11 +815,11 @@ class RpcClient {
|
|
|
805
815
|
let start = Date.now();
|
|
806
816
|
while (Date.now() - start < timeoutMs) {
|
|
807
817
|
try {
|
|
808
|
-
let
|
|
809
|
-
if (
|
|
810
|
-
(0, dist_1.log_warn)('get_bundle_error, res=', { url, txid, check_interval, timeoutMs,
|
|
818
|
+
let err_result = yield (yield fetch(url)).json();
|
|
819
|
+
if (err_result && err_result.length > 0) {
|
|
820
|
+
(0, dist_1.log_warn)('get_bundle_error, res=', { url, txid, check_interval, timeoutMs, err_result });
|
|
811
821
|
let appConfig = global.appConfig;
|
|
812
|
-
let
|
|
822
|
+
let mock_failed_tx = {
|
|
813
823
|
params: {
|
|
814
824
|
result: {
|
|
815
825
|
signature: txid,
|
|
@@ -820,18 +830,20 @@ class RpcClient {
|
|
|
820
830
|
},
|
|
821
831
|
version: 0,
|
|
822
832
|
meta: {
|
|
823
|
-
err: JSON.stringify(
|
|
824
|
-
logMessages: []
|
|
833
|
+
err: JSON.stringify(err_result),
|
|
834
|
+
logMessages: [],
|
|
835
|
+
preBalances: [0],
|
|
836
|
+
postBalances: [0]
|
|
825
837
|
}
|
|
826
838
|
}
|
|
827
839
|
}
|
|
828
840
|
}
|
|
829
841
|
};
|
|
830
|
-
appConfig.emit(common_1.LOCAL_EVENT_NAME.EVENT_WALLET_TRANSACTION + '#' + txid, JSON.stringify(
|
|
842
|
+
appConfig.emit(common_1.LOCAL_EVENT_NAME.EVENT_WALLET_TRANSACTION + '#' + txid, JSON.stringify(mock_failed_tx));
|
|
831
843
|
break;
|
|
832
844
|
}
|
|
833
845
|
else {
|
|
834
|
-
(0, dist_1.log_debug)('get_bundle_error, res=', { url, check_interval, rs });
|
|
846
|
+
(0, dist_1.log_debug)('get_bundle_error, res=', { url, check_interval, rs: err_result });
|
|
835
847
|
}
|
|
836
848
|
}
|
|
837
849
|
catch (err) {
|
|
@@ -842,5 +854,19 @@ class RpcClient {
|
|
|
842
854
|
}
|
|
843
855
|
});
|
|
844
856
|
}
|
|
857
|
+
send_tx_to_all_jito_region(serializedTransaction, encoding) {
|
|
858
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
859
|
+
let jito_block_engine_urls = [
|
|
860
|
+
`${types_1.JITO_API_URLS['Default']}/api/v1/transactions?bundleOnly=true`,
|
|
861
|
+
`${types_1.JITO_API_URLS['NY']}/api/v1/transactions?bundleOnly=true`,
|
|
862
|
+
`${types_1.JITO_API_URLS['Amsterdam']}/api/v1/transactions?bundleOnly=true`,
|
|
863
|
+
`${types_1.JITO_API_URLS['Frankfurt']}/api/v1/transactions?bundleOnly=true`,
|
|
864
|
+
`${types_1.JITO_API_URLS['Tokyo']}/api/v1/transactions?bundleOnly=true`,
|
|
865
|
+
`${types_1.JITO_API_URLS['Slc']}/api/v1/transactions?bundleOnly=true`,
|
|
866
|
+
];
|
|
867
|
+
let bundle_id = yield Promise.race(jito_block_engine_urls.map(address => this.sendJitoTransaction(serializedTransaction, address, encoding)));
|
|
868
|
+
return bundle_id;
|
|
869
|
+
});
|
|
870
|
+
}
|
|
845
871
|
}
|
|
846
872
|
exports.RpcClient = RpcClient;
|
|
@@ -602,4 +602,5 @@ exports.JITO_API_URLS = {
|
|
|
602
602
|
Amsterdam: 'https://amsterdam.mainnet.block-engine.jito.wtf',
|
|
603
603
|
Frankfurt: 'https://frankfurt.mainnet.block-engine.jito.wtf',
|
|
604
604
|
Tokyo: 'https://tokyo.mainnet.block-engine.jito.wtf',
|
|
605
|
+
Slc: 'https://slc.mainnet.block-engine.jito.wtf'
|
|
605
606
|
};
|
|
@@ -293,7 +293,7 @@ export interface GetPriorityFeeEstimateResponse {
|
|
|
293
293
|
priorityFeeEstimate?: number;
|
|
294
294
|
priorityFeeLevels?: MicroLamportPriorityFeeLevels;
|
|
295
295
|
}
|
|
296
|
-
export type JitoRegion = 'Default' | 'NY' | 'Amsterdam' | 'Frankfurt' | 'Tokyo';
|
|
296
|
+
export type JitoRegion = 'Default' | 'NY' | 'Amsterdam' | 'Frankfurt' | 'Tokyo' | 'Slc';
|
|
297
297
|
export type PollTransactionOptions = {
|
|
298
298
|
confirmationStatuses?: TransactionConfirmationStatus[];
|
|
299
299
|
timeout?: number;
|
|
@@ -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);
|