@clonegod/ttd-sol-common 1.1.0 → 1.1.2

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,11 +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>;
48
- send_jup_ag_tx_by_jito(solana_trade_runtime: SolanaTradeRuntimeType, transaction: VersionedTransaction, tipAmount?: number, region?: JitoRegion): 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>;
49
51
  getNftEditions(params: DAS.GetNftEditionsRequest): Promise<DAS.GetNftEditionsResponse>;
50
52
  getTokenAccounts(params: DAS.GetTokenAccountsRequest): Promise<DAS.GetTokenAccountsResponse>;
51
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) {
@@ -616,16 +629,19 @@ class RpcClient {
616
629
  serializedTipTx
617
630
  ].join(',');
618
631
  }
632
+ const max_retry = Number(process.env.JITO_MAX_RETRIES || '10');
619
633
  const send_result = yield (0, dist_1.postJSON)(send_tx_jito_url, {
620
634
  encoding,
621
635
  encoded_tx,
622
636
  txid,
623
637
  trace_id: '',
624
- group_id
638
+ group_id,
639
+ max_retry
625
640
  });
626
641
  (0, dist_1.log_info)(`sendJitoBundle (mul_ips)`, {
627
642
  txid,
628
643
  jito_use_separate_tx,
644
+ max_retry,
629
645
  send_result
630
646
  });
631
647
  return;
@@ -641,8 +657,8 @@ class RpcClient {
641
657
  return txid;
642
658
  });
643
659
  }
644
- send_jup_ag_tx_by_jito(solana_trade_runtime_1, transaction_1) {
645
- return __awaiter(this, arguments, void 0, function* (solana_trade_runtime, transaction, tipAmount = 1000, region = 'Default') {
660
+ send_jup_ag_tx_by_jito(solana_trade_runtime_1, transaction_1, signers_1) {
661
+ return __awaiter(this, arguments, void 0, function* (solana_trade_runtime, transaction, signers, tipAmount = 1000, region = 'Default') {
646
662
  let txid = (0, get_signature_1.getSignature)(transaction);
647
663
  setTimeout(() => __awaiter(this, void 0, void 0, function* () {
648
664
  let block_offset = solana_trade_runtime.settings.strategy.block_offset;
@@ -657,33 +673,41 @@ class RpcClient {
657
673
  let jitoApiUrl = `${types_1.JITO_API_URLS[jito_region]}/api/v1/bundles`;
658
674
  const send_tx_jito_url = process.env.SEND_TX_JITO_URL || '';
659
675
  const send_tx_jito_stratgy = process.env.SEND_TX_JITO_STRATEGY || '';
676
+ let serializedTipTx = '';
660
677
  if (!(0, dist_1.isEmpty)(send_tx_jito_url) && send_tx_jito_stratgy === 'mul_ips') {
661
678
  let { jito_use_separate_tx } = solana_trade_runtime;
662
679
  let group_id = solana_trade_runtime.group.id;
663
680
  let recent_blockhash = blockhash;
664
681
  let encoded_tx = serializedMainTx;
665
682
  if (jito_use_separate_tx) {
666
- let 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;
667
- encoded_tx = [
668
- serializedMainTx,
669
- serializedTipTx
670
- ].join(',');
683
+ 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;
684
+ }
685
+ else {
686
+ serializedTipTx = yield this.getSerializedTipTransaction(signers, tipAmount, blockhash, encoding);
671
687
  }
688
+ encoded_tx = [
689
+ serializedTipTx,
690
+ serializedMainTx
691
+ ].join(',');
692
+ const max_retry = Number(process.env.JITO_MAX_RETRIES || '0');
672
693
  const send_result = yield (0, dist_1.postJSON)(send_tx_jito_url, {
673
694
  encoding,
674
695
  encoded_tx,
675
696
  txid,
676
697
  trace_id: '',
677
- group_id
698
+ group_id,
699
+ max_retry
678
700
  });
679
701
  (0, dist_1.log_info)(`sendJitoBundle (mul_ips)`, {
680
702
  txid,
681
703
  jito_use_separate_tx,
704
+ max_retry,
682
705
  send_result
683
706
  });
684
707
  return;
685
708
  }
686
- let bundleId = yield this.sendJitoBundle([serializedMainTx], encoding, jitoApiUrl);
709
+ serializedTipTx = yield this.getSerializedTipTransaction(signers, tipAmount, blockhash, encoding);
710
+ let bundleId = yield this.sendJitoBundle([serializedMainTx, serializedTipTx], encoding, jitoApiUrl);
687
711
  (0, dist_1.log_info)(`sendJitoBundle`, {
688
712
  txid,
689
713
  jitoApiUrl,
@@ -694,6 +718,13 @@ class RpcClient {
694
718
  return txid;
695
719
  });
696
720
  }
721
+ getSerializedTipTransaction(signers_1, tipAmount_1, blockhash_1) {
722
+ return __awaiter(this, arguments, void 0, function* (signers, tipAmount, blockhash, encoding = 'base64') {
723
+ const randomTipAccount = types_1.JITO_TIP_ACCOUNTS[Math.floor(Math.random() * types_1.JITO_TIP_ACCOUNTS.length)];
724
+ let tipTransaction = this.getTipTransaction(signers, randomTipAccount, tipAmount, blockhash);
725
+ return tipTransaction.serialize({ verifySignatures: false }).toString(encoding);
726
+ });
727
+ }
697
728
  getNftEditions(params) {
698
729
  return __awaiter(this, void 0, void 0, function* () {
699
730
  try {
@@ -55,7 +55,7 @@ class HeliusClient {
55
55
  let { tip_amount: jito_tip_fee, priority_fee } = solana_trade_runtime;
56
56
  let jito_region = (0, strategy_util_1.get_jito_region)();
57
57
  let rpc = this.helius_mainnet.rpc;
58
- let txid = yield rpc.send_jup_ag_tx_by_jito(solana_trade_runtime, transaction, jito_tip_fee, jito_region);
58
+ let txid = yield rpc.send_jup_ag_tx_by_jito(solana_trade_runtime, transaction, this.signers, jito_tip_fee, jito_region);
59
59
  (0, sol_gas_cache_1.set_sol_gas_fee)(txid, { priority_fee, jito_tip_fee });
60
60
  (0, dist_1.log_info)(`send_transaction_jup_ag_with_jito, end`, {
61
61
  jito_tip_fee,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@clonegod/ttd-sol-common",
3
- "version": "1.1.0",
3
+ "version": "1.1.2",
4
4
  "description": "",
5
5
  "main": "dist/index.js",
6
6
  "types": "types/index.d.ts",