@clonegod/ttd-sol-common 2.0.24 → 2.0.26

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.
@@ -6,5 +6,5 @@ export declare class JitoUtils {
6
6
  static fetchJitoTipAccounts(): Promise<string[]>;
7
7
  }
8
8
  export declare const getJitoTipAccount: () => string;
9
- export declare const sendBundleWithJito: (signedTransactions: Transaction[]) => Promise<string>;
10
- export declare const sendBundleWithJitoByMultiIps: (signedTransactions: Transaction[]) => Promise<string>;
9
+ export declare const sendBundleWithJito: (mainTx: Transaction, tipTx: Transaction) => Promise<string>;
10
+ export declare const sendBundleWithJitoMultiIps: (mainTx: Transaction, tipTx: Transaction) => Promise<string>;
@@ -1,10 +1,41 @@
1
1
  "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || (function () {
19
+ var ownKeys = function(o) {
20
+ ownKeys = Object.getOwnPropertyNames || function (o) {
21
+ var ar = [];
22
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
+ return ar;
24
+ };
25
+ return ownKeys(o);
26
+ };
27
+ return function (mod) {
28
+ if (mod && mod.__esModule) return mod;
29
+ var result = {};
30
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
+ __setModuleDefault(result, mod);
32
+ return result;
33
+ };
34
+ })();
5
35
  Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.sendBundleWithJitoByMultiIps = exports.sendBundleWithJito = exports.getJitoTipAccount = exports.JitoUtils = exports.JITO_TIP_ACCOUNTS = void 0;
7
- const axios_1 = __importDefault(require("axios"));
36
+ exports.sendBundleWithJitoMultiIps = exports.sendBundleWithJito = exports.getJitoTipAccount = exports.JitoUtils = exports.JITO_TIP_ACCOUNTS = void 0;
37
+ const axios_1 = __importStar(require("axios"));
38
+ const dist_1 = require("@clonegod/ttd-core/dist");
8
39
  const http_client_1 = require("./http_client");
9
40
  exports.JITO_TIP_ACCOUNTS = [
10
41
  "DfXygSm4jCyNCybVYYK6DwvWqjKee8pbDmJGcLWNDXjh",
@@ -45,31 +76,48 @@ const getJitoTipAccount = () => {
45
76
  };
46
77
  exports.getJitoTipAccount = getJitoTipAccount;
47
78
  JitoUtils.init();
48
- const sendBundleWithJito = async (signedTransactions) => {
79
+ const sendBundleWithJito = async (mainTx, tipTx) => {
80
+ var _a, _b, _c, _d, _e, _f;
49
81
  let url = process.env.JITO_SEND_BUNDLE_URL || 'https://tokyo.mainnet.block-engine.jito.wtf/api/v1/bundles';
50
82
  const client = (0, http_client_1.getHttpClient)(url);
51
- const response = await client.post(url, {
83
+ const requestData = {
52
84
  jsonrpc: '2.0',
53
85
  id: 1,
54
86
  method: 'sendBundle',
55
87
  params: [
56
- signedTransactions.map(tx => Buffer.from(tx.serialize()).toString('base64')),
88
+ [tipTx, mainTx].map(tx => Buffer.from(tx.serialize()).toString('base64')),
57
89
  {
58
90
  "encoding": "base64"
59
91
  }
60
92
  ]
61
- });
62
- return response.data.result;
93
+ };
94
+ try {
95
+ const response = await client.post(url, requestData);
96
+ return response.data.result;
97
+ }
98
+ catch (error) {
99
+ if (error instanceof axios_1.AxiosError) {
100
+ const method = ((_b = (_a = error.config) === null || _a === void 0 ? void 0 : _a.method) === null || _b === void 0 ? void 0 : _b.toUpperCase()) || '';
101
+ const errorUrl = ((_c = error.config) === null || _c === void 0 ? void 0 : _c.url) || url;
102
+ const errorData = (_d = error.config) === null || _d === void 0 ? void 0 : _d.data;
103
+ const status = (_e = error.response) === null || _e === void 0 ? void 0 : _e.status;
104
+ const statusText = (_f = error.response) === null || _f === void 0 ? void 0 : _f.statusText;
105
+ (0, dist_1.log_warn)(`[sendBundleWithJito] Request failed - method: ${method}, url: ${errorUrl}, status: ${status}, statusText: ${statusText}, data: ${errorData}`);
106
+ }
107
+ else {
108
+ (0, dist_1.log_warn)(`[sendBundleWithJito] Unexpected error: ${url} - ${error.message}`);
109
+ }
110
+ }
63
111
  };
64
112
  exports.sendBundleWithJito = sendBundleWithJito;
65
- const sendBundleWithJitoByMultiIps = async (signedTransactions) => {
113
+ const sendBundleWithJitoMultiIps = async (mainTx, tipTx) => {
66
114
  let ips = (process.env.JITO_SEND_BUNDLE_PROXY_SERVERS || '127.0.0.1').split(',');
67
- let urls = ips.map(ip => `http://${ip}:18888/solana/send_tx`);
115
+ let urls = ips.map(ip => `http://${ip}:10429/solana/send_tx`);
68
116
  const body = {
69
117
  trace_id: '',
70
- txid: Buffer.from(signedTransactions[0].serialize()).toString('base64'),
118
+ txid: Buffer.from(mainTx.serialize()).toString('base64'),
71
119
  encoding: 'base64',
72
- encoded_tx: signedTransactions.map(tx => Buffer.from(tx.serialize()).toString('base64')).join(','),
120
+ encoded_tx: [tipTx, mainTx].map(tx => Buffer.from(tx.serialize()).toString('base64')).join(','),
73
121
  max_retry: 3
74
122
  };
75
123
  Promise.all(urls.map(async (url) => {
@@ -84,4 +132,4 @@ const sendBundleWithJitoByMultiIps = async (signedTransactions) => {
84
132
  }));
85
133
  return 'success';
86
134
  };
87
- exports.sendBundleWithJitoByMultiIps = sendBundleWithJitoByMultiIps;
135
+ exports.sendBundleWithJitoMultiIps = sendBundleWithJitoMultiIps;
@@ -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[], swqos_only: boolean): Promise<string>;
5
- sendBundle(signedTransactions: Transaction[]): Promise<string>;
4
+ sendTransaction(singedTransaction: Transaction, swqos_only: boolean): Promise<string>;
5
+ sendBundle(mainTx: Transaction, tipTx: Transaction, use_multi_ips?: boolean): Promise<string>;
6
6
  }
@@ -6,16 +6,16 @@ const jito_1 = require("./jito");
6
6
  class TransactionSender {
7
7
  constructor() {
8
8
  }
9
- async sendTransaction(singedTransactions, swqos_only) {
10
- if (singedTransactions.length === 1) {
11
- return await (0, helius_1.sendTxWithHelius)(singedTransactions[0], swqos_only);
9
+ async sendTransaction(singedTransaction, swqos_only) {
10
+ return await (0, helius_1.sendTxWithHelius)(singedTransaction, swqos_only);
11
+ }
12
+ async sendBundle(mainTx, tipTx, use_multi_ips = false) {
13
+ if (use_multi_ips) {
14
+ return await (0, jito_1.sendBundleWithJitoMultiIps)(mainTx, tipTx);
12
15
  }
13
16
  else {
14
- return await this.sendBundle(singedTransactions);
17
+ return await (0, jito_1.sendBundleWithJito)(mainTx, tipTx);
15
18
  }
16
19
  }
17
- async sendBundle(signedTransactions) {
18
- return await (0, jito_1.sendBundleWithJito)(signedTransactions);
19
- }
20
20
  }
21
21
  exports.TransactionSender = TransactionSender;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@clonegod/ttd-sol-common",
3
- "version": "2.0.24",
3
+ "version": "2.0.26",
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.5",
16
+ "@clonegod/ttd-core": "2.1.6",
17
17
  "@solana/web3.js": "1.91.6",
18
18
  "rpc-websockets": "7.10.0",
19
19
  "axios": "^1.2.3",
@@ -1,5 +1,6 @@
1
1
  import { Transaction } from "@solana/web3.js";
2
- import axios from "axios";
2
+ import axios, { AxiosError } from "axios";
3
+ import { log_error, log_warn } from "@clonegod/ttd-core/dist";
3
4
  import { getHttpClient } from "./http_client";
4
5
 
5
6
  export const JITO_TIP_ACCOUNTS = [
@@ -48,43 +49,59 @@ JitoUtils.init()
48
49
 
49
50
  // -----------------------------------------------------------
50
51
 
51
- export const sendBundleWithJito = async (signedTransactions: Transaction[]): Promise<string> => {
52
+ export const sendBundleWithJito = async (mainTx: Transaction, tipTx: Transaction): Promise<string> => {
52
53
  let url = process.env.JITO_SEND_BUNDLE_URL || 'https://tokyo.mainnet.block-engine.jito.wtf/api/v1/bundles'
53
54
 
54
55
  // 使用共享的 axios 实例,复用连接池
55
56
  const client = getHttpClient(url)
56
- const response = await client.post<{ result: string }>(url, {
57
+
58
+ const requestData = {
57
59
  jsonrpc: '2.0',
58
60
  id: 1,
59
61
  method: 'sendBundle',
60
62
  params: [
61
- signedTransactions.map(tx => Buffer.from(tx.serialize()).toString('base64')),
63
+ [tipTx, mainTx].map(tx => Buffer.from(tx.serialize()).toString('base64')),
62
64
  {
63
65
  "encoding": "base64"
64
66
  }
65
67
  ]
66
- })
67
-
68
- // {
69
- // jsonrpc: '2.0',
70
- // result: 'e62062b4af6963bb0f67fea429f97e4f4fee59851a4ef65154b9f49b5995b5be', // bundle id
71
- // id: 1
72
- // }
73
- // console.dir(response.data, { depth: null })
74
-
75
- return response.data.result;
68
+ };
69
+
70
+ try {
71
+ const response = await client.post<{ result: string }>(url, requestData)
72
+ // {
73
+ // jsonrpc: '2.0',
74
+ // result: 'e62062b4af6963bb0f67fea429f97e4f4fee59851a4ef65154b9f49b5995b5be', // bundle id
75
+ // id: 1
76
+ // }
77
+ // console.dir(response.data, { depth: null })
78
+ return response.data.result;
79
+ } catch (error) {
80
+ if(error instanceof AxiosError) {
81
+ // 提取关键错误信息
82
+ const method = error.config?.method?.toUpperCase() || '';
83
+ const errorUrl = error.config?.url || url;
84
+ const errorData = error.config?.data;
85
+ const status = error.response?.status;
86
+ const statusText = error.response?.statusText;
87
+
88
+ log_warn(`[sendBundleWithJito] Request failed - method: ${method}, url: ${errorUrl}, status: ${status}, statusText: ${statusText}, data: ${errorData}`);
89
+ } else {
90
+ log_warn(`[sendBundleWithJito] Unexpected error: ${url} - ${error.message}`);
91
+ }
92
+ }
76
93
  }
77
94
 
78
95
 
79
- export const sendBundleWithJitoByMultiIps = async (signedTransactions: Transaction[]): Promise<string> => {
96
+ export const sendBundleWithJitoMultiIps = async (mainTx: Transaction, tipTx: Transaction): Promise<string> => {
80
97
  let ips = (process.env.JITO_SEND_BUNDLE_PROXY_SERVERS || '127.0.0.1').split(',')
81
- let urls = ips.map(ip => `http://${ip}:18888/solana/send_tx`)
98
+ let urls = ips.map(ip => `http://${ip}:10429/solana/send_tx`)
82
99
 
83
100
  const body = {
84
101
  trace_id: '',
85
- txid: Buffer.from(signedTransactions[0].serialize()).toString('base64'),
102
+ txid: Buffer.from(mainTx.serialize()).toString('base64'),
86
103
  encoding: 'base64', // base64
87
- encoded_tx: signedTransactions.map(tx => Buffer.from(tx.serialize()).toString('base64')).join(','), // main tx
104
+ encoded_tx: [tipTx, mainTx].map(tx => Buffer.from(tx.serialize()).toString('base64')).join(','), // main tx
88
105
  max_retry: 3
89
106
  }
90
107
 
@@ -1,6 +1,6 @@
1
1
  import { Transaction } from '@solana/web3.js';
2
2
  import { sendTxWithHelius } from './helius';
3
- import { sendBundleWithJito } from './jito';
3
+ import { sendBundleWithJito, sendBundleWithJitoMultiIps } from './jito';
4
4
 
5
5
 
6
6
  /**
@@ -11,16 +11,16 @@ export class TransactionSender {
11
11
  constructor() {
12
12
  }
13
13
 
14
- async sendTransaction(singedTransactions: Transaction[], swqos_only:boolean): Promise<string> {
15
- if(singedTransactions.length === 1) {
16
- return await sendTxWithHelius(singedTransactions[0], swqos_only)
17
- } else {
18
- return await this.sendBundle(singedTransactions)
19
- }
14
+ async sendTransaction(singedTransaction: Transaction, swqos_only:boolean): Promise<string> {
15
+ return await sendTxWithHelius(singedTransaction, swqos_only)
20
16
  }
21
17
 
22
- async sendBundle(signedTransactions: Transaction[]): Promise<string> {
23
- return await sendBundleWithJito(signedTransactions)
18
+ async sendBundle(mainTx: Transaction, tipTx:Transaction, use_multi_ips: boolean=false): Promise<string> {
19
+ if(use_multi_ips) {
20
+ return await sendBundleWithJitoMultiIps(mainTx, tipTx)
21
+ } else {
22
+ return await sendBundleWithJito(mainTx, tipTx)
23
+ }
24
24
  }
25
25
 
26
26
  }