@clonegod/ttd-sol-common 2.0.26 → 2.0.28

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);
@@ -34,8 +34,9 @@ var __importStar = (this && this.__importStar) || (function () {
34
34
  })();
35
35
  Object.defineProperty(exports, "__esModule", { value: true });
36
36
  exports.sendBundleWithJitoMultiIps = exports.sendBundleWithJito = exports.getJitoTipAccount = exports.JitoUtils = exports.JITO_TIP_ACCOUNTS = void 0;
37
- const axios_1 = __importStar(require("axios"));
38
37
  const dist_1 = require("@clonegod/ttd-core/dist");
38
+ const axios_1 = __importStar(require("axios"));
39
+ const common_1 = require("../../common");
39
40
  const http_client_1 = require("./http_client");
40
41
  exports.JITO_TIP_ACCOUNTS = [
41
42
  "DfXygSm4jCyNCybVYYK6DwvWqjKee8pbDmJGcLWNDXjh",
@@ -77,7 +78,7 @@ const getJitoTipAccount = () => {
77
78
  exports.getJitoTipAccount = getJitoTipAccount;
78
79
  JitoUtils.init();
79
80
  const sendBundleWithJito = async (mainTx, tipTx) => {
80
- var _a, _b, _c, _d, _e, _f;
81
+ var _a, _b;
81
82
  let url = process.env.JITO_SEND_BUNDLE_URL || 'https://tokyo.mainnet.block-engine.jito.wtf/api/v1/bundles';
82
83
  const client = (0, http_client_1.getHttpClient)(url);
83
84
  const requestData = {
@@ -97,12 +98,9 @@ const sendBundleWithJito = async (mainTx, tipTx) => {
97
98
  }
98
99
  catch (error) {
99
100
  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}`);
101
+ const status = (_a = error.response) === null || _a === void 0 ? void 0 : _a.status;
102
+ const statusText = (_b = error.response) === null || _b === void 0 ? void 0 : _b.statusText;
103
+ (0, dist_1.log_warn)(`[sendBundleWithJito] Request failed: ${status} - ${statusText}`);
106
104
  }
107
105
  else {
108
106
  (0, dist_1.log_warn)(`[sendBundleWithJito] Unexpected error: ${url} - ${error.message}`);
@@ -115,7 +113,7 @@ const sendBundleWithJitoMultiIps = async (mainTx, tipTx) => {
115
113
  let urls = ips.map(ip => `http://${ip}:10429/solana/send_tx`);
116
114
  const body = {
117
115
  trace_id: '',
118
- txid: Buffer.from(mainTx.serialize()).toString('base64'),
116
+ txid: (0, common_1.getSignature)(mainTx),
119
117
  encoding: 'base64',
120
118
  encoded_tx: [tipTx, mainTx].map(tx => Buffer.from(tx.serialize()).toString('base64')).join(','),
121
119
  max_retry: 3
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@clonegod/ttd-sol-common",
3
- "version": "2.0.26",
3
+ "version": "2.0.28",
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,6 +1,7 @@
1
+ import { log_warn } from "@clonegod/ttd-core/dist";
1
2
  import { Transaction } from "@solana/web3.js";
2
3
  import axios, { AxiosError } from "axios";
3
- import { log_error, log_warn } from "@clonegod/ttd-core/dist";
4
+ import { getSignature } from "../../common";
4
5
  import { getHttpClient } from "./http_client";
5
6
 
6
7
  export const JITO_TIP_ACCOUNTS = [
@@ -79,13 +80,10 @@ export const sendBundleWithJito = async (mainTx: Transaction, tipTx: Transaction
79
80
  } catch (error) {
80
81
  if(error instanceof AxiosError) {
81
82
  // 提取关键错误信息
82
- const method = error.config?.method?.toUpperCase() || '';
83
- const errorUrl = error.config?.url || url;
84
- const errorData = error.config?.data;
85
83
  const status = error.response?.status;
86
84
  const statusText = error.response?.statusText;
87
85
 
88
- log_warn(`[sendBundleWithJito] Request failed - method: ${method}, url: ${errorUrl}, status: ${status}, statusText: ${statusText}, data: ${errorData}`);
86
+ log_warn(`[sendBundleWithJito] Request failed: ${status} - ${statusText}`);
89
87
  } else {
90
88
  log_warn(`[sendBundleWithJito] Unexpected error: ${url} - ${error.message}`);
91
89
  }
@@ -99,7 +97,7 @@ export const sendBundleWithJitoMultiIps = async (mainTx: Transaction, tipTx: Tra
99
97
 
100
98
  const body = {
101
99
  trace_id: '',
102
- txid: Buffer.from(mainTx.serialize()).toString('base64'),
100
+ txid: getSignature(mainTx),
103
101
  encoding: 'base64', // base64
104
102
  encoded_tx: [tipTx, mainTx].map(tx => Buffer.from(tx.serialize()).toString('base64')).join(','), // main tx
105
103
  max_retry: 3