@clonegod/ttd-sol-common 2.0.44 → 2.0.45
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 -2
- package/dist/trade/send/helius.js +2 -2
- package/dist/trade/send/jito.d.ts +2 -3
- package/dist/trade/send/jito.js +5 -6
- package/dist/trade/send/send_tx.d.ts +2 -1
- package/dist/trade/send/send_tx.js +20 -3
- package/package.json +1 -1
- package/src/trade/send/helius.ts +2 -3
- package/src/trade/send/jito.ts +5 -7
- package/src/trade/send/send_tx.ts +24 -4
|
@@ -1,3 +1,2 @@
|
|
|
1
|
-
import { Transaction } from "@solana/web3.js";
|
|
2
1
|
export declare const HELIUS_TIP_ACCOUNTS: string[];
|
|
3
|
-
export declare const sendTxWithHelius: (
|
|
2
|
+
export declare const sendTxWithHelius: (signedTransactionBase64: string, swqos_only: boolean) => Promise<string>;
|
|
@@ -14,7 +14,7 @@ exports.HELIUS_TIP_ACCOUNTS = [
|
|
|
14
14
|
"4vieeGHPYPG2MmyPRcYjdiDmmhN3ww7hsFNap8pVN3Ey",
|
|
15
15
|
"4TQLFNWK8AovT1gFvda5jfw2oJeRMKEmw7aH6MGBJ3or"
|
|
16
16
|
];
|
|
17
|
-
const sendTxWithHelius = async (
|
|
17
|
+
const sendTxWithHelius = async (signedTransactionBase64, swqos_only) => {
|
|
18
18
|
let url = process.env.HELIUS_SEND_TX_URL || 'http://tyo-sender.helius-rpc.com/fast';
|
|
19
19
|
if (swqos_only) {
|
|
20
20
|
url = url + "?swqos_only=true";
|
|
@@ -25,7 +25,7 @@ const sendTxWithHelius = async (signedTransaction, swqos_only) => {
|
|
|
25
25
|
id: Date.now().toString(),
|
|
26
26
|
method: 'sendTransaction',
|
|
27
27
|
params: [
|
|
28
|
-
|
|
28
|
+
signedTransactionBase64,
|
|
29
29
|
{
|
|
30
30
|
encoding: 'base64',
|
|
31
31
|
skipPreflight: true,
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { Transaction } from "@solana/web3.js";
|
|
2
1
|
export declare const JITO_TIP_ACCOUNTS: string[];
|
|
3
2
|
export declare class JitoUtils {
|
|
4
3
|
static jitoTipAccounts: string[];
|
|
@@ -6,5 +5,5 @@ export declare class JitoUtils {
|
|
|
6
5
|
static fetchJitoTipAccounts(): Promise<string[]>;
|
|
7
6
|
}
|
|
8
7
|
export declare const getJitoTipAccount: () => string;
|
|
9
|
-
export declare const sendBundleWithJito: (
|
|
10
|
-
export declare const sendBundleWithJitoMultiIps: (
|
|
8
|
+
export declare const sendBundleWithJito: (mainTxBase64: string, tipTxBase64: string) => Promise<string>;
|
|
9
|
+
export declare const sendBundleWithJitoMultiIps: (mainTxHash: string, mainTxBase64: string, tipTxBase64: string) => Promise<string>;
|
package/dist/trade/send/jito.js
CHANGED
|
@@ -36,7 +36,6 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
36
36
|
exports.sendBundleWithJitoMultiIps = exports.sendBundleWithJito = exports.getJitoTipAccount = exports.JitoUtils = exports.JITO_TIP_ACCOUNTS = void 0;
|
|
37
37
|
const dist_1 = require("@clonegod/ttd-core/dist");
|
|
38
38
|
const axios_1 = __importStar(require("axios"));
|
|
39
|
-
const common_1 = require("../../common");
|
|
40
39
|
const http_client_1 = require("./http_client");
|
|
41
40
|
exports.JITO_TIP_ACCOUNTS = [
|
|
42
41
|
"DfXygSm4jCyNCybVYYK6DwvWqjKee8pbDmJGcLWNDXjh",
|
|
@@ -77,7 +76,7 @@ const getJitoTipAccount = () => {
|
|
|
77
76
|
};
|
|
78
77
|
exports.getJitoTipAccount = getJitoTipAccount;
|
|
79
78
|
JitoUtils.init();
|
|
80
|
-
const sendBundleWithJito = async (
|
|
79
|
+
const sendBundleWithJito = async (mainTxBase64, tipTxBase64) => {
|
|
81
80
|
var _a, _b;
|
|
82
81
|
let url = process.env.JITO_SEND_BUNDLE_URL || 'https://tokyo.mainnet.block-engine.jito.wtf/api/v1/bundles';
|
|
83
82
|
const client = (0, http_client_1.getHttpClient)(url);
|
|
@@ -86,7 +85,7 @@ const sendBundleWithJito = async (mainTx, tipTx) => {
|
|
|
86
85
|
id: 1,
|
|
87
86
|
method: 'sendBundle',
|
|
88
87
|
params: [
|
|
89
|
-
[
|
|
88
|
+
[tipTxBase64, mainTxBase64],
|
|
90
89
|
{
|
|
91
90
|
"encoding": "base64"
|
|
92
91
|
}
|
|
@@ -110,14 +109,14 @@ const sendBundleWithJito = async (mainTx, tipTx) => {
|
|
|
110
109
|
}
|
|
111
110
|
};
|
|
112
111
|
exports.sendBundleWithJito = sendBundleWithJito;
|
|
113
|
-
const sendBundleWithJitoMultiIps = async (
|
|
112
|
+
const sendBundleWithJitoMultiIps = async (mainTxHash, mainTxBase64, tipTxBase64) => {
|
|
114
113
|
let ips = (process.env.JITO_SEND_BUNDLE_SERVER_IPS || '127.0.0.1').split(',');
|
|
115
114
|
let urls = ips.map(ip => `http://${ip}:10001/solana/send_tx`);
|
|
116
115
|
const body = {
|
|
117
116
|
trace_id: '',
|
|
118
|
-
txid:
|
|
117
|
+
txid: mainTxHash,
|
|
119
118
|
encoding: 'base64',
|
|
120
|
-
encoded_tx: [
|
|
119
|
+
encoded_tx: [tipTxBase64, mainTxBase64].join(','),
|
|
121
120
|
max_retry: 3
|
|
122
121
|
};
|
|
123
122
|
Promise.all(urls.map(async (url) => {
|
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
import { Transaction } from '@solana/web3.js';
|
|
1
|
+
import { Transaction, VersionedTransaction } from '@solana/web3.js';
|
|
2
2
|
export declare class TransactionSender {
|
|
3
3
|
constructor();
|
|
4
4
|
sendTransaction(singedTransaction: Transaction, swqos_only: boolean): Promise<string>;
|
|
5
5
|
sendBundle(mainTx: Transaction, tipTx: Transaction, use_multi_ips?: boolean): Promise<string>;
|
|
6
6
|
}
|
|
7
|
+
export declare function serializeTransactionBase64(tx: Transaction | VersionedTransaction): string;
|
|
@@ -1,21 +1,38 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.TransactionSender = void 0;
|
|
4
|
+
exports.serializeTransactionBase64 = serializeTransactionBase64;
|
|
5
|
+
const web3_js_1 = require("@solana/web3.js");
|
|
4
6
|
const helius_1 = require("./helius");
|
|
5
7
|
const jito_1 = require("./jito");
|
|
8
|
+
const common_1 = require("../../common");
|
|
6
9
|
class TransactionSender {
|
|
7
10
|
constructor() {
|
|
8
11
|
}
|
|
9
12
|
async sendTransaction(singedTransaction, swqos_only) {
|
|
10
|
-
|
|
13
|
+
const mainTxBase64 = serializeTransactionBase64(singedTransaction);
|
|
14
|
+
return await (0, helius_1.sendTxWithHelius)(mainTxBase64, swqos_only);
|
|
11
15
|
}
|
|
12
16
|
async sendBundle(mainTx, tipTx, use_multi_ips = false) {
|
|
17
|
+
const mainTxBase64 = serializeTransactionBase64(mainTx);
|
|
18
|
+
const tipTxBase64 = serializeTransactionBase64(tipTx);
|
|
13
19
|
if (use_multi_ips) {
|
|
14
|
-
|
|
20
|
+
const mainTxHash = (0, common_1.getSignature)(mainTx);
|
|
21
|
+
return await (0, jito_1.sendBundleWithJitoMultiIps)(mainTxHash, mainTxBase64, tipTxBase64);
|
|
15
22
|
}
|
|
16
23
|
else {
|
|
17
|
-
return await (0, jito_1.sendBundleWithJito)(
|
|
24
|
+
return await (0, jito_1.sendBundleWithJito)(mainTxBase64, tipTxBase64);
|
|
18
25
|
}
|
|
19
26
|
}
|
|
20
27
|
}
|
|
21
28
|
exports.TransactionSender = TransactionSender;
|
|
29
|
+
function serializeTransactionBase64(tx) {
|
|
30
|
+
let buffer;
|
|
31
|
+
if (tx instanceof web3_js_1.VersionedTransaction) {
|
|
32
|
+
buffer = Buffer.from(tx.serialize());
|
|
33
|
+
}
|
|
34
|
+
else {
|
|
35
|
+
buffer = Buffer.from(tx.serialize({ verifySignatures: false }));
|
|
36
|
+
}
|
|
37
|
+
return buffer.toString('base64');
|
|
38
|
+
}
|
package/package.json
CHANGED
package/src/trade/send/helius.ts
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { Transaction } from "@solana/web3.js"
|
|
2
1
|
import { getHttpClient } from "./http_client"
|
|
3
2
|
|
|
4
3
|
export const HELIUS_TIP_ACCOUNTS = [
|
|
@@ -17,7 +16,7 @@ export const HELIUS_TIP_ACCOUNTS = [
|
|
|
17
16
|
/**
|
|
18
17
|
* Jito + SWQOS
|
|
19
18
|
*/
|
|
20
|
-
export const sendTxWithHelius = async (
|
|
19
|
+
export const sendTxWithHelius = async (signedTransactionBase64: string, swqos_only: boolean): Promise<string> => {
|
|
21
20
|
let url = process.env.HELIUS_SEND_TX_URL || 'http://tyo-sender.helius-rpc.com/fast'
|
|
22
21
|
|
|
23
22
|
if (swqos_only) {
|
|
@@ -31,7 +30,7 @@ export const sendTxWithHelius = async (signedTransaction: Transaction, swqos_onl
|
|
|
31
30
|
id: Date.now().toString(),
|
|
32
31
|
method: 'sendTransaction',
|
|
33
32
|
params: [
|
|
34
|
-
|
|
33
|
+
signedTransactionBase64,
|
|
35
34
|
{
|
|
36
35
|
encoding: 'base64',
|
|
37
36
|
skipPreflight: true, // Required for Sender
|
package/src/trade/send/jito.ts
CHANGED
|
@@ -1,7 +1,5 @@
|
|
|
1
1
|
import { log_warn } from "@clonegod/ttd-core/dist";
|
|
2
|
-
import { Transaction } from "@solana/web3.js";
|
|
3
2
|
import axios, { AxiosError } from "axios";
|
|
4
|
-
import { getSignature } from "../../common";
|
|
5
3
|
import { getHttpClient } from "./http_client";
|
|
6
4
|
|
|
7
5
|
export const JITO_TIP_ACCOUNTS = [
|
|
@@ -50,7 +48,7 @@ JitoUtils.init()
|
|
|
50
48
|
|
|
51
49
|
// -----------------------------------------------------------
|
|
52
50
|
|
|
53
|
-
export const sendBundleWithJito = async (
|
|
51
|
+
export const sendBundleWithJito = async (mainTxBase64: string, tipTxBase64: string): Promise<string> => {
|
|
54
52
|
let url = process.env.JITO_SEND_BUNDLE_URL || 'https://tokyo.mainnet.block-engine.jito.wtf/api/v1/bundles'
|
|
55
53
|
|
|
56
54
|
// 使用共享的 axios 实例,复用连接池
|
|
@@ -61,7 +59,7 @@ export const sendBundleWithJito = async (mainTx: Transaction, tipTx: Transaction
|
|
|
61
59
|
id: 1,
|
|
62
60
|
method: 'sendBundle',
|
|
63
61
|
params: [
|
|
64
|
-
[
|
|
62
|
+
[tipTxBase64, mainTxBase64],
|
|
65
63
|
{
|
|
66
64
|
"encoding": "base64"
|
|
67
65
|
}
|
|
@@ -94,15 +92,15 @@ export const sendBundleWithJito = async (mainTx: Transaction, tipTx: Transaction
|
|
|
94
92
|
}
|
|
95
93
|
|
|
96
94
|
|
|
97
|
-
export const sendBundleWithJitoMultiIps = async (
|
|
95
|
+
export const sendBundleWithJitoMultiIps = async (mainTxHash: string, mainTxBase64: string, tipTxBase64: string): Promise<string> => {
|
|
98
96
|
let ips = (process.env.JITO_SEND_BUNDLE_SERVER_IPS || '127.0.0.1').split(',')
|
|
99
97
|
let urls = ips.map(ip => `http://${ip}:10001/solana/send_tx`)
|
|
100
98
|
|
|
101
99
|
const body = {
|
|
102
100
|
trace_id: '',
|
|
103
|
-
txid:
|
|
101
|
+
txid: mainTxHash,
|
|
104
102
|
encoding: 'base64', // base64
|
|
105
|
-
encoded_tx: [
|
|
103
|
+
encoded_tx: [tipTxBase64, mainTxBase64].join(','), // main tx
|
|
106
104
|
max_retry: 3
|
|
107
105
|
}
|
|
108
106
|
|
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
import { Transaction } from '@solana/web3.js';
|
|
1
|
+
import { Transaction, VersionedTransaction } from '@solana/web3.js';
|
|
2
2
|
import { sendTxWithHelius } from './helius';
|
|
3
3
|
import { sendBundleWithJito, sendBundleWithJitoMultiIps } from './jito';
|
|
4
|
+
import { getSignature } from '../../common';
|
|
4
5
|
|
|
5
6
|
|
|
6
7
|
/**
|
|
@@ -12,16 +13,35 @@ export class TransactionSender {
|
|
|
12
13
|
}
|
|
13
14
|
|
|
14
15
|
async sendTransaction(singedTransaction: Transaction, swqos_only:boolean): Promise<string> {
|
|
15
|
-
|
|
16
|
+
const mainTxBase64 = serializeTransactionBase64(singedTransaction)
|
|
17
|
+
return await sendTxWithHelius(mainTxBase64, swqos_only)
|
|
16
18
|
}
|
|
17
19
|
|
|
18
20
|
async sendBundle(mainTx: Transaction, tipTx:Transaction, use_multi_ips: boolean=false): Promise<string> {
|
|
21
|
+
const mainTxBase64 = serializeTransactionBase64(mainTx)
|
|
22
|
+
const tipTxBase64 = serializeTransactionBase64(tipTx)
|
|
19
23
|
if(use_multi_ips) {
|
|
20
|
-
|
|
24
|
+
const mainTxHash = getSignature(mainTx)
|
|
25
|
+
return await sendBundleWithJitoMultiIps(mainTxHash, mainTxBase64, tipTxBase64)
|
|
21
26
|
} else {
|
|
22
|
-
return await sendBundleWithJito(
|
|
27
|
+
return await sendBundleWithJito(mainTxBase64, tipTxBase64)
|
|
23
28
|
}
|
|
24
29
|
}
|
|
25
30
|
|
|
26
31
|
}
|
|
27
32
|
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* 序列化交易为 base64 字符串
|
|
36
|
+
*/
|
|
37
|
+
export function serializeTransactionBase64(tx: Transaction | VersionedTransaction): string {
|
|
38
|
+
let buffer:Buffer
|
|
39
|
+
if (tx instanceof VersionedTransaction) {
|
|
40
|
+
buffer = Buffer.from(tx.serialize())
|
|
41
|
+
} else {
|
|
42
|
+
// Transaction.serialize() 参数是可选的,但默认会验证签名
|
|
43
|
+
// 传入 { verifySignatures: false } 可以跳过验证,因为我们已经在发送前签名了
|
|
44
|
+
buffer = Buffer.from(tx.serialize({ verifySignatures: false }))
|
|
45
|
+
}
|
|
46
|
+
return buffer.toString('base64')
|
|
47
|
+
}
|