@clonegod/ttd-sol-common 2.0.18 → 2.0.20
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.
- package/dist/trade/send/helius.d.ts +1 -1
- package/dist/trade/send/helius.js +2 -2
- package/dist/trade/send/send_tx.d.ts +1 -1
- package/dist/trade/send/send_tx.js +2 -2
- package/dist/trade/tx_builder.d.ts +1 -2
- package/dist/trade/tx_builder.js +11 -10
- package/package.json +2 -2
- package/src/trade/send/helius.ts +3 -3
- package/src/trade/send/send_tx.ts +2 -2
- package/src/trade/tx_builder.ts +24 -15
|
@@ -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,
|
|
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,
|
|
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 (!
|
|
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[],
|
|
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,
|
|
9
|
+
async sendTransaction(singedTransactions, swqos_only) {
|
|
10
10
|
if (singedTransactions.length === 1) {
|
|
11
|
-
return await (0, helius_1.sendTxWithHelius)(singedTransactions[0],
|
|
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[]
|
|
16
|
-
private getHeliusTipInstruction;
|
|
15
|
+
buildTransactionForSwap(context: TradeContext, swapInstructions: TransactionInstruction[]): Transaction;
|
|
17
16
|
buildTransactionForTipJito(context: TradeContext, tipPayer?: Keypair): Transaction;
|
|
18
17
|
}
|
package/dist/trade/tx_builder.js
CHANGED
|
@@ -37,7 +37,7 @@ class SolTransactionBuilder {
|
|
|
37
37
|
getPostInstructions(context) {
|
|
38
38
|
return [];
|
|
39
39
|
}
|
|
40
|
-
buildTransactionForSwap(context, swapInstructions
|
|
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
|
-
|
|
50
|
-
|
|
51
|
-
|
|
49
|
+
let tip_lamports = context.trade_runtime.settings.strategy.sol_tip_fee;
|
|
50
|
+
if (tip_lamports < 5000) {
|
|
51
|
+
tip_lamports = 5000;
|
|
52
52
|
}
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
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.
|
|
3
|
+
"version": "2.0.20",
|
|
4
4
|
"description": "",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "types/index.d.ts",
|
|
@@ -13,7 +13,7 @@
|
|
|
13
13
|
"push": "npm run build && npm publish"
|
|
14
14
|
},
|
|
15
15
|
"dependencies": {
|
|
16
|
-
"@clonegod/ttd-core": "2.1.
|
|
16
|
+
"@clonegod/ttd-core": "2.1.5",
|
|
17
17
|
"@solana/web3.js": "1.91.6",
|
|
18
18
|
"rpc-websockets": "7.10.0",
|
|
19
19
|
"axios": "^1.2.3",
|
package/src/trade/send/helius.ts
CHANGED
|
@@ -17,10 +17,10 @@ export const HELIUS_TIP_ACCOUNTS = [
|
|
|
17
17
|
/**
|
|
18
18
|
* Jito + SWQOS
|
|
19
19
|
*/
|
|
20
|
-
export const sendTxWithHelius = async (signedTransaction: Transaction,
|
|
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 (!
|
|
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[],
|
|
14
|
+
async sendTransaction(singedTransactions: Transaction[], swqos_only:boolean): Promise<string> {
|
|
15
15
|
if(singedTransactions.length === 1) {
|
|
16
|
-
return await sendTxWithHelius(singedTransactions[0],
|
|
16
|
+
return await sendTxWithHelius(singedTransactions[0], swqos_only)
|
|
17
17
|
} else {
|
|
18
18
|
return await this.sendBundle(singedTransactions)
|
|
19
19
|
}
|
package/src/trade/tx_builder.ts
CHANGED
|
@@ -63,7 +63,13 @@ export class SolTransactionBuilder {
|
|
|
63
63
|
}
|
|
64
64
|
|
|
65
65
|
|
|
66
|
-
|
|
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
|
-
|
|
81
|
-
|
|
82
|
-
|
|
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
|
-
|
|
86
|
-
|
|
87
|
-
|
|
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
|
|