@clonegod/ttd-sol-common 1.0.194 → 1.1.1

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.
@@ -41,10 +41,13 @@ export declare class RpcClient {
41
41
  lastValidBlockHeightOffset?: number;
42
42
  }): Promise<TransactionSignature>;
43
43
  addTipInstruction(instructions: TransactionInstruction[], feePayer: PublicKey, tipAccount: string, tipAmount: number): void;
44
+ getTipTransaction(singers: Signer[], tipAccount: string, tipAmount: number, blockhash: string): Transaction;
44
45
  createSmartTransactionWithTip(solana_trade_runtime: SolanaTradeRuntimeType, instructions: TransactionInstruction[], signers: Signer[], lookupTables?: AddressLookupTableAccount[], tipAmount?: number, feePayer?: Signer): Promise<SmartTransactionContext>;
45
46
  sendJitoBundle(serializedTransactions: string[], encoding: string, jitoApiUrl: string): Promise<string>;
46
47
  getBundleStatuses(bundleIds: string[], jitoApiUrl: string): Promise<any>;
47
48
  sendSmartTransactionWithTip(solana_trade_runtime: SolanaTradeRuntimeType, instructions: TransactionInstruction[], signers: Signer[], lookupTables?: AddressLookupTableAccount[], tipAmount?: number, region?: JitoRegion, feePayer?: Signer, lastValidBlockHeightOffset?: number): Promise<string>;
49
+ send_jup_ag_tx_by_jito(solana_trade_runtime: SolanaTradeRuntimeType, transaction: VersionedTransaction, signers: Signer[], tipAmount?: number, region?: JitoRegion): Promise<string>;
50
+ getSerializedTipTransaction(signers: Signer[], tipAmount: number, blockhash: string, encoding?: BufferEncoding): Promise<string>;
48
51
  getNftEditions(params: DAS.GetNftEditionsRequest): Promise<DAS.GetNftEditionsResponse>;
49
52
  getTokenAccounts(params: DAS.GetTokenAccountsRequest): Promise<DAS.GetTokenAccountsResponse>;
50
53
  sendTransaction(transaction: Transaction | VersionedTransaction, options?: HeliusSendOptions): Promise<TransactionSignature>;
@@ -531,6 +531,19 @@ class RpcClient {
531
531
  });
532
532
  instructions.push(tipInstruction);
533
533
  }
534
+ getTipTransaction(singers, tipAccount, tipAmount, blockhash) {
535
+ const feePayer = singers[0];
536
+ const tipInstruction = web3_js_1.SystemProgram.transfer({
537
+ fromPubkey: feePayer.publicKey,
538
+ toPubkey: new web3_js_1.PublicKey(tipAccount),
539
+ lamports: tipAmount,
540
+ });
541
+ const transaction = new web3_js_1.Transaction().add(tipInstruction);
542
+ transaction.recentBlockhash = blockhash;
543
+ transaction.feePayer = feePayer.publicKey;
544
+ transaction.sign(feePayer);
545
+ return transaction;
546
+ }
534
547
  createSmartTransactionWithTip(solana_trade_runtime_1, instructions_1, signers_1) {
535
548
  return __awaiter(this, arguments, void 0, function* (solana_trade_runtime, instructions, signers, lookupTables = [], tipAmount = 1000, feePayer) {
536
549
  if (!signers.length) {
@@ -641,6 +654,71 @@ class RpcClient {
641
654
  return txid;
642
655
  });
643
656
  }
657
+ send_jup_ag_tx_by_jito(solana_trade_runtime_1, transaction_1, signers_1) {
658
+ return __awaiter(this, arguments, void 0, function* (solana_trade_runtime, transaction, signers, tipAmount = 1000, region = 'Default') {
659
+ let txid = (0, get_signature_1.getSignature)(transaction);
660
+ setTimeout(() => __awaiter(this, void 0, void 0, function* () {
661
+ let block_offset = solana_trade_runtime.settings.strategy.block_offset;
662
+ if (isNaN(block_offset) || block_offset < 0) {
663
+ throw new Error('block_offset must be a positive integer');
664
+ }
665
+ let blockhash_by_slot_offset = yield this.getBlockhashBySlotOffset(block_offset);
666
+ let blockhash = blockhash_by_slot_offset.value.blockhash;
667
+ const encoding = 'base64';
668
+ const serializedMainTx = Buffer.from(transaction.serialize()).toString(encoding);
669
+ let jito_region = process.env.JITO_REGION || region;
670
+ let jitoApiUrl = `${types_1.JITO_API_URLS[jito_region]}/api/v1/bundles`;
671
+ const send_tx_jito_url = process.env.SEND_TX_JITO_URL || '';
672
+ const send_tx_jito_stratgy = process.env.SEND_TX_JITO_STRATEGY || '';
673
+ let serializedTipTx = '';
674
+ if (!(0, dist_1.isEmpty)(send_tx_jito_url) && send_tx_jito_stratgy === 'mul_ips') {
675
+ let { jito_use_separate_tx } = solana_trade_runtime;
676
+ let group_id = solana_trade_runtime.group.id;
677
+ let recent_blockhash = blockhash;
678
+ let encoded_tx = serializedMainTx;
679
+ if (jito_use_separate_tx) {
680
+ serializedTipTx = (yield axios_1.default.get(`${process.env.JITO_CREATE_TIP_TX_URL}?group_id=${group_id}&blockhash=${recent_blockhash}&encoding=${encoding}&tip_amount=${tipAmount}`)).data.data;
681
+ }
682
+ else {
683
+ serializedTipTx = yield this.getSerializedTipTransaction(signers, tipAmount, blockhash, encoding);
684
+ }
685
+ encoded_tx = [
686
+ serializedTipTx,
687
+ serializedMainTx
688
+ ].join(',');
689
+ const send_result = yield (0, dist_1.postJSON)(send_tx_jito_url, {
690
+ encoding,
691
+ encoded_tx,
692
+ txid,
693
+ trace_id: '',
694
+ group_id
695
+ });
696
+ (0, dist_1.log_info)(`sendJitoBundle (mul_ips)`, {
697
+ txid,
698
+ jito_use_separate_tx,
699
+ send_result
700
+ });
701
+ return;
702
+ }
703
+ serializedTipTx = yield this.getSerializedTipTransaction(signers, tipAmount, blockhash, encoding);
704
+ let bundleId = yield this.sendJitoBundle([serializedMainTx, serializedTipTx], encoding, jitoApiUrl);
705
+ (0, dist_1.log_info)(`sendJitoBundle`, {
706
+ txid,
707
+ jitoApiUrl,
708
+ encoding,
709
+ bundleId
710
+ });
711
+ }), 0);
712
+ return txid;
713
+ });
714
+ }
715
+ getSerializedTipTransaction(signers_1, tipAmount_1, blockhash_1) {
716
+ return __awaiter(this, arguments, void 0, function* (signers, tipAmount, blockhash, encoding = 'base64') {
717
+ const randomTipAccount = types_1.JITO_TIP_ACCOUNTS[Math.floor(Math.random() * types_1.JITO_TIP_ACCOUNTS.length)];
718
+ let tipTransaction = this.getTipTransaction(signers, randomTipAccount, tipAmount, blockhash);
719
+ return tipTransaction.serialize({ verifySignatures: false }).toString(encoding);
720
+ });
721
+ }
644
722
  getNftEditions(params) {
645
723
  return __awaiter(this, void 0, void 0, function* () {
646
724
  try {
@@ -1,4 +1,4 @@
1
- import { AddressLookupTableAccount, SendOptions, Signer, TransactionInstruction } from "@solana/web3.js";
1
+ import { AddressLookupTableAccount, SendOptions, Signer, TransactionInstruction, VersionedTransaction } from "@solana/web3.js";
2
2
  import { SolanaTradeRuntimeType } from '../../types';
3
3
  import { Helius } from "../helius_sdk_v1.4.0";
4
4
  export declare class HeliusClient {
@@ -9,6 +9,7 @@ export declare class HeliusClient {
9
9
  helius_staked: Helius;
10
10
  constructor(signers: Signer[]);
11
11
  send_transaction(solana_trade_runtime: SolanaTradeRuntimeType, instructions: TransactionInstruction[], addressLookupTableAccounts?: AddressLookupTableAccount[]): Promise<string>;
12
+ send_transaction_jup_ag_with_jito(solana_trade_runtime: SolanaTradeRuntimeType, transaction: VersionedTransaction): Promise<string>;
12
13
  private send_smart_transaction;
13
14
  private send_transaction_by_jito;
14
15
  private send_transaction_mixed;
@@ -48,6 +48,24 @@ class HeliusClient {
48
48
  return txid;
49
49
  });
50
50
  }
51
+ send_transaction_jup_ag_with_jito(solana_trade_runtime, transaction) {
52
+ return __awaiter(this, void 0, void 0, function* () {
53
+ (0, dist_1.log_info)(`send_transaction_jup_ag_with_jito, start`);
54
+ let start_time = Date.now();
55
+ let { tip_amount: jito_tip_fee, priority_fee } = solana_trade_runtime;
56
+ let jito_region = (0, strategy_util_1.get_jito_region)();
57
+ let rpc = this.helius_mainnet.rpc;
58
+ let txid = yield rpc.send_jup_ag_tx_by_jito(solana_trade_runtime, transaction, this.signers, jito_tip_fee, jito_region);
59
+ (0, sol_gas_cache_1.set_sol_gas_fee)(txid, { priority_fee, jito_tip_fee });
60
+ (0, dist_1.log_info)(`send_transaction_jup_ag_with_jito, end`, {
61
+ jito_tip_fee,
62
+ jito_region,
63
+ txid,
64
+ take_time: Date.now() - start_time
65
+ });
66
+ return txid;
67
+ });
68
+ }
51
69
  send_smart_transaction(solana_trade_runtime_1, instructions_1, use_staked_endpint_1) {
52
70
  return __awaiter(this, arguments, void 0, function* (solana_trade_runtime, instructions, use_staked_endpint, addressLookupTableAccounts = []) {
53
71
  (0, dist_1.log_info)(`send_smart_transaction, start`);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@clonegod/ttd-sol-common",
3
- "version": "1.0.194",
3
+ "version": "1.1.1",
4
4
  "description": "",
5
5
  "main": "dist/index.js",
6
6
  "types": "types/index.d.ts",