@clonegod/ttd-sol-common 2.0.18 → 2.0.19

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.
@@ -1,3 +1,3 @@
1
1
  import { Transaction } from "@solana/web3.js";
2
2
  export declare const HELIUS_TIP_ACCOUNTS: string[];
3
- export declare const sendTxWithHelius: (signedTransaction: Transaction, tip_helius: boolean) => Promise<string>;
3
+ export declare const sendTxWithHelius: (signedTransaction: Transaction, swqos_only: boolean) => Promise<string>;
@@ -17,9 +17,9 @@ exports.HELIUS_TIP_ACCOUNTS = [
17
17
  "4vieeGHPYPG2MmyPRcYjdiDmmhN3ww7hsFNap8pVN3Ey",
18
18
  "4TQLFNWK8AovT1gFvda5jfw2oJeRMKEmw7aH6MGBJ3or"
19
19
  ];
20
- const sendTxWithHelius = async (signedTransaction, tip_helius) => {
20
+ const sendTxWithHelius = async (signedTransaction, swqos_only) => {
21
21
  let url = process.env.HELIUS_SEND_TX_URL || 'http://tyo-sender.helius-rpc.com/fast';
22
- if (!tip_helius) {
22
+ if (!swqos_only) {
23
23
  url = url + "?swqos_only=true";
24
24
  }
25
25
  const response = await axios_1.default.post(url, {
@@ -1,6 +1,6 @@
1
1
  import { Transaction } from '@solana/web3.js';
2
2
  export declare class TransactionSender {
3
3
  constructor();
4
- sendTransaction(singedTransactions: Transaction[], tip_helius: boolean): Promise<string>;
4
+ sendTransaction(singedTransactions: Transaction[], swqos_only: boolean): Promise<string>;
5
5
  sendBundle(signedTransactions: Transaction[]): Promise<string>;
6
6
  }
@@ -6,9 +6,9 @@ const jito_1 = require("./jito");
6
6
  class TransactionSender {
7
7
  constructor() {
8
8
  }
9
- async sendTransaction(singedTransactions, tip_helius) {
9
+ async sendTransaction(singedTransactions, swqos_only) {
10
10
  if (singedTransactions.length === 1) {
11
- return await (0, helius_1.sendTxWithHelius)(singedTransactions[0], tip_helius);
11
+ return await (0, helius_1.sendTxWithHelius)(singedTransactions[0], swqos_only);
12
12
  }
13
13
  else {
14
14
  return await this.sendBundle(singedTransactions);
@@ -12,7 +12,6 @@ export declare class SolTransactionBuilder {
12
12
  private handleBlockUpdateEvent;
13
13
  private getPreInstructions;
14
14
  private getPostInstructions;
15
- buildTransactionForSwap(context: TradeContext, swapInstructions: TransactionInstruction[], tip_helius: boolean): Transaction;
16
- private getHeliusTipInstruction;
15
+ buildTransactionForSwap(context: TradeContext, swapInstructions: TransactionInstruction[]): Transaction;
17
16
  buildTransactionForTipJito(context: TradeContext, tipPayer?: Keypair): Transaction;
18
17
  }
@@ -37,7 +37,7 @@ class SolTransactionBuilder {
37
37
  getPostInstructions(context) {
38
38
  return [];
39
39
  }
40
- buildTransactionForSwap(context, swapInstructions, tip_helius) {
40
+ buildTransactionForSwap(context, swapInstructions) {
41
41
  const max_block_offset = context.trade_runtime.settings.strategy.max_block_offset;
42
42
  const swapTx = new web3_js_1.Transaction();
43
43
  const preInstructions = this.getPreInstructions(context);
@@ -46,20 +46,21 @@ class SolTransactionBuilder {
46
46
  swapTx.recentBlockhash = this.recentBlockhash;
47
47
  swapTx.lastValidBlockHeight = this.recentBlockheight + max_block_offset;
48
48
  swapTx.feePayer = this.keypair.publicKey;
49
- if (tip_helius) {
50
- let jitoTipInstruction = this.getHeliusTipInstruction(context);
51
- swapTx.instructions.push(jitoTipInstruction);
49
+ let tip_lamports = context.trade_runtime.settings.strategy.sol_tip_fee;
50
+ if (tip_lamports < 5000) {
51
+ tip_lamports = 5000;
52
52
  }
53
- swapTx.sign(this.keypair);
54
- return swapTx;
55
- }
56
- getHeliusTipInstruction(context) {
57
- let tip_lamports = Math.min(context.trade_runtime.settings.strategy.sol_tip_fee, 0.0002 * web3_js_1.LAMPORTS_PER_SOL);
58
- return web3_js_1.SystemProgram.transfer({
53
+ if (tip_lamports > 300000) {
54
+ tip_lamports = 300000;
55
+ }
56
+ let tip_instruction = web3_js_1.SystemProgram.transfer({
59
57
  fromPubkey: this.keypair.publicKey,
60
58
  toPubkey: new web3_js_1.PublicKey(helius_1.HELIUS_TIP_ACCOUNTS[Math.floor(Math.random() * helius_1.HELIUS_TIP_ACCOUNTS.length)]),
61
59
  lamports: tip_lamports,
62
60
  });
61
+ swapTx.instructions.push(tip_instruction);
62
+ swapTx.sign(this.keypair);
63
+ return swapTx;
63
64
  }
64
65
  buildTransactionForTipJito(context, tipPayer = undefined) {
65
66
  const max_block_offset = context.trade_runtime.settings.strategy.max_block_offset;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@clonegod/ttd-sol-common",
3
- "version": "2.0.18",
3
+ "version": "2.0.19",
4
4
  "description": "",
5
5
  "main": "dist/index.js",
6
6
  "types": "types/index.d.ts",
@@ -17,10 +17,10 @@ export const HELIUS_TIP_ACCOUNTS = [
17
17
  /**
18
18
  * Jito + SWQOS
19
19
  */
20
- export const sendTxWithHelius = async (signedTransaction: Transaction, tip_helius: boolean): Promise<string> => {
20
+ export const sendTxWithHelius = async (signedTransaction: Transaction, swqos_only: boolean): Promise<string> => {
21
21
  let url = process.env.HELIUS_SEND_TX_URL || 'http://tyo-sender.helius-rpc.com/fast'
22
-
23
- if (!tip_helius) {
22
+
23
+ if (!swqos_only) {
24
24
  url = url + "?swqos_only=true"
25
25
  }
26
26
  const response = await axios.post<{ result: string }>(url, {
@@ -11,9 +11,9 @@ export class TransactionSender {
11
11
  constructor() {
12
12
  }
13
13
 
14
- async sendTransaction(singedTransactions: Transaction[], tip_helius:boolean): Promise<string> {
14
+ async sendTransaction(singedTransactions: Transaction[], swqos_only:boolean): Promise<string> {
15
15
  if(singedTransactions.length === 1) {
16
- return await sendTxWithHelius(singedTransactions[0], tip_helius)
16
+ return await sendTxWithHelius(singedTransactions[0], swqos_only)
17
17
  } else {
18
18
  return await this.sendBundle(singedTransactions)
19
19
  }
@@ -63,7 +63,13 @@ export class SolTransactionBuilder {
63
63
  }
64
64
 
65
65
 
66
- buildTransactionForSwap(context: TradeContext, swapInstructions: TransactionInstruction[], tip_helius:boolean): Transaction {
66
+ /**
67
+ * 构建 Swap 交易指令
68
+ * @param context
69
+ * @param swapInstructions
70
+ * @returns
71
+ */
72
+ buildTransactionForSwap(context: TradeContext, swapInstructions: TransactionInstruction[]): Transaction {
67
73
  const max_block_offset = context.trade_runtime.settings.strategy.max_block_offset
68
74
  // console.log(`buildTransactionForSwap, max_block_offset: ${max_block_offset}`)
69
75
 
@@ -77,25 +83,28 @@ export class SolTransactionBuilder {
77
83
  swapTx.lastValidBlockHeight = this.recentBlockheight + max_block_offset
78
84
  swapTx.feePayer = this.keypair.publicKey
79
85
 
80
- if(tip_helius) {
81
- let jitoTipInstruction = this.getHeliusTipInstruction(context)
82
- swapTx.instructions.push(jitoTipInstruction)
86
+ // Helius Sender 要求:
87
+ // 1、swqos_only: 至少 5000 lamports 小费
88
+ // -> transaction must send a tip of at least 5000 lamports to one of the following Helius wallets: [xxx, ...]
89
+ // 2、swqos + jito: 至少 0.0002 SOL 小费 -> lamports = 0.0002 * LAMPORTS_PER_SOL
90
+ // -> Requires minimum 0.0002 SOL tip.
91
+ let tip_lamports = context.trade_runtime.settings.strategy.sol_tip_fee
92
+ if(tip_lamports < 5000) {
93
+ tip_lamports = 5000
83
94
  }
84
-
85
- swapTx.sign(this.keypair)
86
-
87
- return swapTx
88
- }
89
-
90
- private getHeliusTipInstruction(context: TradeContext): TransactionInstruction {
91
- // Requires minimum 0.0002 SOL tip. (Helius)
92
- // transaction must send a tip of at least 5000 lamports to one of the following Helius wallets: [xxx, ...]
93
- let tip_lamports = Math.min(context.trade_runtime.settings.strategy.sol_tip_fee, 0.0002 * LAMPORTS_PER_SOL)
94
- return SystemProgram.transfer({
95
+ if(tip_lamports > 300000) {
96
+ tip_lamports = 300000
97
+ }
98
+ let tip_instruction = SystemProgram.transfer({
95
99
  fromPubkey: this.keypair.publicKey,
96
100
  toPubkey: new PublicKey(HELIUS_TIP_ACCOUNTS[Math.floor(Math.random() * HELIUS_TIP_ACCOUNTS.length)]),
97
101
  lamports: tip_lamports,
98
102
  })
103
+ swapTx.instructions.push(tip_instruction)
104
+
105
+ swapTx.sign(this.keypair)
106
+
107
+ return swapTx
99
108
  }
100
109
 
101
110