@clonegod/ttd-sol-common 1.0.76 → 1.0.77
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.
|
@@ -46,4 +46,6 @@ export declare class RpcClient {
|
|
|
46
46
|
getNftEditions(params: DAS.GetNftEditionsRequest): Promise<DAS.GetNftEditionsResponse>;
|
|
47
47
|
getTokenAccounts(params: DAS.GetTokenAccountsRequest): Promise<DAS.GetTokenAccountsResponse>;
|
|
48
48
|
sendTransaction(transaction: Transaction | VersionedTransaction, options?: HeliusSendOptions): Promise<TransactionSignature>;
|
|
49
|
+
sendSmartTransactionWithTipMixed(solana_trade_runtime: SolanaTradeRuntimeType, instructions: TransactionInstruction[], signers: Signer[], lookupTables?: AddressLookupTableAccount[], tipAmount?: number, region?: JitoRegion, feePayer?: Signer, lastValidBlockHeightOffset?: number): Promise<string>;
|
|
50
|
+
sendJitoTransaction(serializedTransaction: string, jitoApiUrl: string): Promise<string>;
|
|
49
51
|
}
|
|
@@ -418,6 +418,9 @@ class RpcClient {
|
|
|
418
418
|
if (solana_trade_runtime.settings.strategy.broadcast_type === 'jito') {
|
|
419
419
|
priorityFeeEstimate = 1;
|
|
420
420
|
}
|
|
421
|
+
if (solana_trade_runtime.settings.strategy.broadcast_type === 'mixed') {
|
|
422
|
+
priorityFeeEstimate = Math.ceil(priorityFeeEstimate * 0.7);
|
|
423
|
+
}
|
|
421
424
|
const computeBudgetIx = web3_js_1.ComputeBudgetProgram.setComputeUnitPrice({
|
|
422
425
|
microLamports: priorityFeeEstimate,
|
|
423
426
|
});
|
|
@@ -676,12 +679,88 @@ class RpcClient {
|
|
|
676
679
|
if (response.data.error) {
|
|
677
680
|
throw new Error(`RPC error: ${JSON.stringify(response.data.error)}`);
|
|
678
681
|
}
|
|
679
|
-
|
|
682
|
+
let txid = response.data.result;
|
|
683
|
+
(0, dist_1.log_info)(`sendTransaction`, {
|
|
684
|
+
url,
|
|
685
|
+
txid
|
|
686
|
+
});
|
|
687
|
+
return txid;
|
|
680
688
|
}
|
|
681
689
|
catch (error) {
|
|
682
690
|
throw new Error(`Error sending transaction: ${error}`);
|
|
683
691
|
}
|
|
684
692
|
});
|
|
685
693
|
}
|
|
694
|
+
sendSmartTransactionWithTipMixed(solana_trade_runtime_1, instructions_1, signers_1) {
|
|
695
|
+
return __awaiter(this, arguments, void 0, function* (solana_trade_runtime, instructions, signers, lookupTables = [], tipAmount = 1000, region = 'Default', feePayer, lastValidBlockHeightOffset = 150) {
|
|
696
|
+
if (lastValidBlockHeightOffset < 0)
|
|
697
|
+
throw new Error('lastValidBlockHeightOffset must be a positive integer');
|
|
698
|
+
if (!signers.length) {
|
|
699
|
+
throw new Error('The transaction must have at least one signer');
|
|
700
|
+
}
|
|
701
|
+
const { transaction, blockhash } = yield this.createSmartTransactionWithTip(solana_trade_runtime, instructions, signers, lookupTables, tipAmount, feePayer);
|
|
702
|
+
let txid = (0, get_signature_1.getSignature)(transaction);
|
|
703
|
+
setTimeout(() => __awaiter(this, void 0, void 0, function* () {
|
|
704
|
+
const serializedTransaction = bs58_1.default.encode(transaction.serialize());
|
|
705
|
+
let jitoApiUrl = `${types_1.JITO_API_URLS[region]}/api/v1/transactions`;
|
|
706
|
+
if (solana_trade_runtime.jito_plugin_url) {
|
|
707
|
+
jitoApiUrl = solana_trade_runtime.jito_plugin_url;
|
|
708
|
+
}
|
|
709
|
+
(0, dist_1.log_info)('sendSmartTransactionWithTipMixed, start');
|
|
710
|
+
this.sendTransaction(transaction);
|
|
711
|
+
const bundleId = yield this.sendJitoTransaction(serializedTransaction, jitoApiUrl);
|
|
712
|
+
(0, dist_1.log_info)(`sendJitoTransaction`, {
|
|
713
|
+
txid,
|
|
714
|
+
bundleId
|
|
715
|
+
});
|
|
716
|
+
const currentBlockHeight = yield solana_trade_runtime.connection.getBlockHeight();
|
|
717
|
+
const lastValidBlockHeight = Math.min(blockhash.lastValidBlockHeight, currentBlockHeight + lastValidBlockHeightOffset);
|
|
718
|
+
const timeout = 60000;
|
|
719
|
+
const interval = 5000;
|
|
720
|
+
const startTime = Date.now();
|
|
721
|
+
while (Date.now() - startTime < timeout ||
|
|
722
|
+
(yield this.connection.getBlockHeight()) <= lastValidBlockHeight) {
|
|
723
|
+
const bundleStatuses = yield this.getBundleStatuses([bundleId], jitoApiUrl);
|
|
724
|
+
(0, dist_1.log_info)(`getBundleStatuses`, {
|
|
725
|
+
txid,
|
|
726
|
+
bundleId,
|
|
727
|
+
jitoApiUrl,
|
|
728
|
+
bundleStatuses
|
|
729
|
+
});
|
|
730
|
+
if (bundleStatuses &&
|
|
731
|
+
bundleStatuses.value &&
|
|
732
|
+
bundleStatuses.value.length > 0 &&
|
|
733
|
+
bundleStatuses.value[0]) {
|
|
734
|
+
const status = bundleStatuses.value[0].confirmation_status;
|
|
735
|
+
if (status === 'confirmed') {
|
|
736
|
+
return bundleStatuses.value[0].transactions[0];
|
|
737
|
+
}
|
|
738
|
+
}
|
|
739
|
+
yield new Promise((resolve) => setTimeout(resolve, interval));
|
|
740
|
+
}
|
|
741
|
+
let err = new Error('Bundle failed to confirm within the timeout period');
|
|
742
|
+
(0, dist_1.log_error)(`Bundle failed to confirm, txid=${txid}`, err);
|
|
743
|
+
throw err;
|
|
744
|
+
}), 0);
|
|
745
|
+
return txid;
|
|
746
|
+
});
|
|
747
|
+
}
|
|
748
|
+
sendJitoTransaction(serializedTransaction, jitoApiUrl) {
|
|
749
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
750
|
+
const response = yield axios_1.default.post(jitoApiUrl, {
|
|
751
|
+
jsonrpc: '2.0',
|
|
752
|
+
id: 1,
|
|
753
|
+
method: 'sendTransaction',
|
|
754
|
+
params: [serializedTransaction],
|
|
755
|
+
}, {
|
|
756
|
+
headers: { 'Content-Type': 'application/json' },
|
|
757
|
+
});
|
|
758
|
+
if (response.data.error) {
|
|
759
|
+
throw new Error(`Error sending bundles: ${JSON.stringify(response.data.error, null, 2)}`);
|
|
760
|
+
}
|
|
761
|
+
console.log(response.headers);
|
|
762
|
+
return response.headers['x-bundle-id'];
|
|
763
|
+
});
|
|
764
|
+
}
|
|
686
765
|
}
|
|
687
766
|
exports.RpcClient = RpcClient;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { SendOptions, Signer, TransactionInstruction } from "@solana/web3.js";
|
|
2
|
-
import { Helius } from "../helius_sdk_v1.4.0";
|
|
3
2
|
import { SolanaTradeRuntimeType } from '../../types';
|
|
3
|
+
import { Helius } from "../helius_sdk_v1.4.0";
|
|
4
4
|
export declare class HeliusClient {
|
|
5
5
|
signers: Signer[];
|
|
6
6
|
sendOptions: SendOptions;
|
|
@@ -11,4 +11,5 @@ export declare class HeliusClient {
|
|
|
11
11
|
send_transaction(solana_trade_runtime: SolanaTradeRuntimeType, instructions: TransactionInstruction[]): Promise<string>;
|
|
12
12
|
private send_smart_transaction;
|
|
13
13
|
private send_transaction_by_jito;
|
|
14
|
+
private send_transaction_mixed;
|
|
14
15
|
}
|
|
@@ -31,13 +31,16 @@ class HeliusClient {
|
|
|
31
31
|
return __awaiter(this, void 0, void 0, function* () {
|
|
32
32
|
let txid = '';
|
|
33
33
|
let { broadcast_type, speed } = solana_trade_runtime.settings.strategy;
|
|
34
|
+
let use_staked_endpint = speed === 'turbo' || speed === 'ultra';
|
|
34
35
|
if (broadcast_type === 'rpc') {
|
|
35
|
-
let use_staked_endpint = speed === 'turbo' || speed === 'ultra';
|
|
36
36
|
txid = yield this.send_smart_transaction(solana_trade_runtime, instructions, use_staked_endpint);
|
|
37
37
|
}
|
|
38
38
|
else if (broadcast_type === 'jito') {
|
|
39
39
|
txid = yield this.send_transaction_by_jito(solana_trade_runtime, instructions);
|
|
40
40
|
}
|
|
41
|
+
else if (broadcast_type === 'mixed') {
|
|
42
|
+
txid = yield this.send_transaction_mixed(solana_trade_runtime, instructions, use_staked_endpint);
|
|
43
|
+
}
|
|
41
44
|
else {
|
|
42
45
|
throw new Error(`Not support broadcast_type: ${broadcast_type}`);
|
|
43
46
|
}
|
|
@@ -75,5 +78,22 @@ class HeliusClient {
|
|
|
75
78
|
return txid;
|
|
76
79
|
});
|
|
77
80
|
}
|
|
81
|
+
send_transaction_mixed(solana_trade_runtime, instructions, use_staked_endpint) {
|
|
82
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
83
|
+
(0, dist_1.log_info)(`send_transaction_mixed, start`);
|
|
84
|
+
let start_time = Date.now();
|
|
85
|
+
let tipAmount = Math.ceil(solana_trade_runtime.priority_fee * 0.3);
|
|
86
|
+
let jito_region = (0, strategy_util_1.get_jito_region)();
|
|
87
|
+
let rpc = use_staked_endpint ? this.helius_staked.rpc : this.helius_mainnet.rpc;
|
|
88
|
+
let txid = yield rpc.sendSmartTransactionWithTip(solana_trade_runtime, instructions, this.signers, [], tipAmount, jito_region);
|
|
89
|
+
(0, dist_1.log_info)(`send_transaction_mixed, end`, {
|
|
90
|
+
tipAmount,
|
|
91
|
+
jito_region,
|
|
92
|
+
txid,
|
|
93
|
+
take_time: Date.now() - start_time
|
|
94
|
+
});
|
|
95
|
+
return txid;
|
|
96
|
+
});
|
|
97
|
+
}
|
|
78
98
|
}
|
|
79
99
|
exports.HeliusClient = HeliusClient;
|