@clonegod/ttd-sol-common 2.0.25 → 2.0.27

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.
@@ -0,0 +1,2 @@
1
+ import { Transaction, VersionedTransaction } from '@solana/web3.js';
2
+ export declare function getSignature(transaction: Transaction | VersionedTransaction): string;
@@ -0,0 +1,15 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.getSignature = getSignature;
7
+ const bs58_1 = __importDefault(require("bs58"));
8
+ function getSignature(transaction) {
9
+ const signature = 'signature' in transaction ? transaction.signature : transaction.signatures[0];
10
+ if (!signature) {
11
+ throw new Error('Missing transaction signature, the transaction was not signed by the fee payer');
12
+ }
13
+ let txid = bs58_1.default.encode(signature);
14
+ return txid;
15
+ }
@@ -1,3 +1,4 @@
1
1
  export * from './constants';
2
2
  export * from './get_wallet_token_account';
3
3
  export * from './subscribe_account_update';
4
+ export * from './get_signature';
@@ -17,3 +17,4 @@ Object.defineProperty(exports, "__esModule", { value: true });
17
17
  __exportStar(require("./constants"), exports);
18
18
  __exportStar(require("./get_wallet_token_account"), exports);
19
19
  __exportStar(require("./subscribe_account_update"), exports);
20
+ __exportStar(require("./get_signature"), exports);
@@ -1,10 +1,42 @@
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
36
  exports.sendBundleWithJitoMultiIps = exports.sendBundleWithJito = exports.getJitoTipAccount = exports.JitoUtils = exports.JITO_TIP_ACCOUNTS = void 0;
7
- const axios_1 = __importDefault(require("axios"));
37
+ const dist_1 = require("@clonegod/ttd-core/dist");
38
+ const axios_1 = __importStar(require("axios"));
39
+ const common_1 = require("../../common");
8
40
  const http_client_1 = require("./http_client");
9
41
  exports.JITO_TIP_ACCOUNTS = [
10
42
  "DfXygSm4jCyNCybVYYK6DwvWqjKee8pbDmJGcLWNDXjh",
@@ -46,9 +78,10 @@ const getJitoTipAccount = () => {
46
78
  exports.getJitoTipAccount = getJitoTipAccount;
47
79
  JitoUtils.init();
48
80
  const sendBundleWithJito = async (mainTx, tipTx) => {
81
+ var _a, _b, _c, _d, _e, _f;
49
82
  let url = process.env.JITO_SEND_BUNDLE_URL || 'https://tokyo.mainnet.block-engine.jito.wtf/api/v1/bundles';
50
83
  const client = (0, http_client_1.getHttpClient)(url);
51
- const response = await client.post(url, {
84
+ const requestData = {
52
85
  jsonrpc: '2.0',
53
86
  id: 1,
54
87
  method: 'sendBundle',
@@ -58,8 +91,24 @@ const sendBundleWithJito = async (mainTx, tipTx) => {
58
91
  "encoding": "base64"
59
92
  }
60
93
  ]
61
- });
62
- return response.data.result;
94
+ };
95
+ try {
96
+ const response = await client.post(url, requestData);
97
+ return response.data.result;
98
+ }
99
+ catch (error) {
100
+ if (error instanceof axios_1.AxiosError) {
101
+ const method = ((_b = (_a = error.config) === null || _a === void 0 ? void 0 : _a.method) === null || _b === void 0 ? void 0 : _b.toUpperCase()) || '';
102
+ const errorUrl = ((_c = error.config) === null || _c === void 0 ? void 0 : _c.url) || url;
103
+ const errorData = (_d = error.config) === null || _d === void 0 ? void 0 : _d.data;
104
+ const status = (_e = error.response) === null || _e === void 0 ? void 0 : _e.status;
105
+ const statusText = (_f = error.response) === null || _f === void 0 ? void 0 : _f.statusText;
106
+ (0, dist_1.log_warn)(`[sendBundleWithJito] Request failed - method: ${method}, url: ${errorUrl}, status: ${status}, statusText: ${statusText}, data: ${errorData}`);
107
+ }
108
+ else {
109
+ (0, dist_1.log_warn)(`[sendBundleWithJito] Unexpected error: ${url} - ${error.message}`);
110
+ }
111
+ }
63
112
  };
64
113
  exports.sendBundleWithJito = sendBundleWithJito;
65
114
  const sendBundleWithJitoMultiIps = async (mainTx, tipTx) => {
@@ -67,7 +116,7 @@ const sendBundleWithJitoMultiIps = async (mainTx, tipTx) => {
67
116
  let urls = ips.map(ip => `http://${ip}:10429/solana/send_tx`);
68
117
  const body = {
69
118
  trace_id: '',
70
- txid: Buffer.from(mainTx.serialize()).toString('base64'),
119
+ txid: (0, common_1.getSignature)(mainTx),
71
120
  encoding: 'base64',
72
121
  encoded_tx: [tipTx, mainTx].map(tx => Buffer.from(tx.serialize()).toString('base64')).join(','),
73
122
  max_retry: 3
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@clonegod/ttd-sol-common",
3
- "version": "2.0.25",
3
+ "version": "2.0.27",
4
4
  "description": "",
5
5
  "main": "dist/index.js",
6
6
  "types": "types/index.d.ts",
@@ -0,0 +1,12 @@
1
+ import bs58 from 'bs58'
2
+ import { Transaction, VersionedTransaction } from '@solana/web3.js'
3
+
4
+ export function getSignature(transaction: Transaction | VersionedTransaction): string {
5
+ const signature = 'signature' in transaction ? transaction.signature : transaction.signatures[0]
6
+ if (!signature) {
7
+ throw new Error('Missing transaction signature, the transaction was not signed by the fee payer')
8
+ }
9
+ let txid = bs58.encode(signature)
10
+
11
+ return txid
12
+ }
@@ -1,3 +1,4 @@
1
1
  export * from './constants'
2
2
  export * from './get_wallet_token_account'
3
3
  export * from './subscribe_account_update'
4
+ export * from './get_signature'
@@ -1,5 +1,7 @@
1
+ import { log_warn } from "@clonegod/ttd-core/dist";
1
2
  import { Transaction } from "@solana/web3.js";
2
- import axios from "axios";
3
+ import axios, { AxiosError } from "axios";
4
+ import { getSignature } from "../../common";
3
5
  import { getHttpClient } from "./http_client";
4
6
 
5
7
  export const JITO_TIP_ACCOUNTS = [
@@ -53,7 +55,8 @@ export const sendBundleWithJito = async (mainTx: Transaction, tipTx: Transaction
53
55
 
54
56
  // 使用共享的 axios 实例,复用连接池
55
57
  const client = getHttpClient(url)
56
- const response = await client.post<{ result: string }>(url, {
58
+
59
+ const requestData = {
57
60
  jsonrpc: '2.0',
58
61
  id: 1,
59
62
  method: 'sendBundle',
@@ -63,16 +66,31 @@ export const sendBundleWithJito = async (mainTx: Transaction, tipTx: Transaction
63
66
  "encoding": "base64"
64
67
  }
65
68
  ]
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;
69
+ };
70
+
71
+ try {
72
+ const response = await client.post<{ result: string }>(url, requestData)
73
+ // {
74
+ // jsonrpc: '2.0',
75
+ // result: 'e62062b4af6963bb0f67fea429f97e4f4fee59851a4ef65154b9f49b5995b5be', // bundle id
76
+ // id: 1
77
+ // }
78
+ // console.dir(response.data, { depth: null })
79
+ return response.data.result;
80
+ } catch (error) {
81
+ if(error instanceof AxiosError) {
82
+ // 提取关键错误信息
83
+ const method = error.config?.method?.toUpperCase() || '';
84
+ const errorUrl = error.config?.url || url;
85
+ const errorData = error.config?.data;
86
+ const status = error.response?.status;
87
+ const statusText = error.response?.statusText;
88
+
89
+ log_warn(`[sendBundleWithJito] Request failed - method: ${method}, url: ${errorUrl}, status: ${status}, statusText: ${statusText}, data: ${errorData}`);
90
+ } else {
91
+ log_warn(`[sendBundleWithJito] Unexpected error: ${url} - ${error.message}`);
92
+ }
93
+ }
76
94
  }
77
95
 
78
96
 
@@ -82,7 +100,7 @@ export const sendBundleWithJitoMultiIps = async (mainTx: Transaction, tipTx: Tra
82
100
 
83
101
  const body = {
84
102
  trace_id: '',
85
- txid: Buffer.from(mainTx.serialize()).toString('base64'),
103
+ txid: getSignature(mainTx),
86
104
  encoding: 'base64', // base64
87
105
  encoded_tx: [tipTx, mainTx].map(tx => Buffer.from(tx.serialize()).toString('base64')).join(','), // main tx
88
106
  max_retry: 3