@clonegod/ttd-sol-common 2.0.46 → 2.0.48
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/index.d.ts +1 -0
- package/dist/trade/index.js +1 -0
- package/dist/trade/send/jito.js +2 -2
- package/dist/trade/sol_gas_cache.d.ts +3 -0
- package/dist/trade/sol_gas_cache.js +15 -0
- package/dist/trade/tx_result_parse.js +10 -2
- package/package.json +1 -1
- package/src/trade/index.ts +3 -1
- package/src/trade/send/jito.ts +9 -2
- package/src/trade/sol_gas_cache.ts +22 -0
- package/src/trade/tx_result_parse.ts +9 -2
package/dist/trade/index.d.ts
CHANGED
package/dist/trade/index.js
CHANGED
|
@@ -20,3 +20,4 @@ __exportStar(require("../config/SolanaTradeAppConfig"), exports);
|
|
|
20
20
|
__exportStar(require("./tx_builder"), exports);
|
|
21
21
|
__exportStar(require("./send"), exports);
|
|
22
22
|
__exportStar(require("./jito_tip_wallets"), exports);
|
|
23
|
+
__exportStar(require("./sol_gas_cache"), exports);
|
package/dist/trade/send/jito.js
CHANGED
|
@@ -85,7 +85,7 @@ const sendBundleWithJito = async (mainTxBase64, tipTxBase64) => {
|
|
|
85
85
|
id: 1,
|
|
86
86
|
method: 'sendBundle',
|
|
87
87
|
params: [
|
|
88
|
-
[
|
|
88
|
+
[mainTxBase64, tipTxBase64],
|
|
89
89
|
{
|
|
90
90
|
"encoding": "base64"
|
|
91
91
|
}
|
|
@@ -116,7 +116,7 @@ const sendBundleWithJitoMultiIps = async (mainTxHash, mainTxBase64, tipTxBase64)
|
|
|
116
116
|
trace_id: '',
|
|
117
117
|
txid: mainTxHash,
|
|
118
118
|
encoding: 'base64',
|
|
119
|
-
encoded_tx: [
|
|
119
|
+
encoded_tx: [mainTxBase64, tipTxBase64].join(','),
|
|
120
120
|
max_retry: 3
|
|
121
121
|
};
|
|
122
122
|
Promise.all(urls.map(async (url) => {
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.get_sol_gas_fee = exports.set_sol_gas_fee = void 0;
|
|
4
|
+
var tx_gas_map = new Map();
|
|
5
|
+
const set_sol_gas_fee = (txid, sol_gas_fee) => {
|
|
6
|
+
tx_gas_map.set(txid, sol_gas_fee);
|
|
7
|
+
};
|
|
8
|
+
exports.set_sol_gas_fee = set_sol_gas_fee;
|
|
9
|
+
const get_sol_gas_fee = (txid) => {
|
|
10
|
+
if (tx_gas_map.has(txid)) {
|
|
11
|
+
return tx_gas_map.get(txid);
|
|
12
|
+
}
|
|
13
|
+
return null;
|
|
14
|
+
};
|
|
15
|
+
exports.get_sol_gas_fee = get_sol_gas_fee;
|
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.parse_tx_failed_error_code = exports.TransactionResultParser = void 0;
|
|
4
4
|
const dist_1 = require("@clonegod/ttd-core/dist");
|
|
5
|
+
const sol_gas_cache_1 = require("./sol_gas_cache");
|
|
5
6
|
class TransactionResultParser {
|
|
6
7
|
constructor(env_args, wallet_pubkey, event_emitter) {
|
|
7
8
|
this.env_args = env_args;
|
|
@@ -43,8 +44,15 @@ class TransactionResultParser {
|
|
|
43
44
|
const base_fee = 5000;
|
|
44
45
|
let priority_fee = 0;
|
|
45
46
|
let total_fee = 0;
|
|
46
|
-
|
|
47
|
-
|
|
47
|
+
let sol_gas_fee = (0, sol_gas_cache_1.get_sol_gas_fee)(txid);
|
|
48
|
+
if (sol_gas_fee) {
|
|
49
|
+
priority_fee = sol_gas_fee.priority_fee;
|
|
50
|
+
total_fee = base_fee + priority_fee;
|
|
51
|
+
}
|
|
52
|
+
else {
|
|
53
|
+
total_fee = preBalances[0] - postBalances[0];
|
|
54
|
+
priority_fee = Math.abs(total_fee - base_fee);
|
|
55
|
+
}
|
|
48
56
|
let gas_fee = {
|
|
49
57
|
base_fee,
|
|
50
58
|
priority_fee,
|
package/package.json
CHANGED
package/src/trade/index.ts
CHANGED
package/src/trade/send/jito.ts
CHANGED
|
@@ -54,12 +54,17 @@ export const sendBundleWithJito = async (mainTxBase64: string, tipTxBase64: stri
|
|
|
54
54
|
// 使用共享的 axios 实例,复用连接池
|
|
55
55
|
const client = getHttpClient(url)
|
|
56
56
|
|
|
57
|
+
// Bundle 顺序: [mainTx, tipTx]
|
|
58
|
+
// 根据 Jito Sandwich Mitigation 规则 (https://docs.jito.wtf/lowlatencytxnsend/#sandwich-mitigation):
|
|
59
|
+
// - 如果主交易包含 jitodontfront 账户,它必须在 bundle 的第一个位置(索引 0)
|
|
60
|
+
// - 允许的模式: [tx_with_dont_front, tip]
|
|
61
|
+
// - 不允许的模式: [tip, tx_with_dont_front]
|
|
57
62
|
const requestData = {
|
|
58
63
|
jsonrpc: '2.0',
|
|
59
64
|
id: 1,
|
|
60
65
|
method: 'sendBundle',
|
|
61
66
|
params: [
|
|
62
|
-
[
|
|
67
|
+
[mainTxBase64, tipTxBase64],
|
|
63
68
|
{
|
|
64
69
|
"encoding": "base64"
|
|
65
70
|
}
|
|
@@ -96,11 +101,13 @@ export const sendBundleWithJitoMultiIps = async (mainTxHash: string, mainTxBase6
|
|
|
96
101
|
let ips = (process.env.JITO_SEND_BUNDLE_SERVER_IPS || '127.0.0.1').split(',')
|
|
97
102
|
let urls = ips.map(ip => `http://${ip}:10001/solana/send_tx`)
|
|
98
103
|
|
|
104
|
+
// Bundle 顺序: [mainTx, tipTx]
|
|
105
|
+
// 与 sendBundleWithJito 保持一致,符合 Jito Sandwich Mitigation 规则
|
|
99
106
|
const body = {
|
|
100
107
|
trace_id: '',
|
|
101
108
|
txid: mainTxHash,
|
|
102
109
|
encoding: 'base64', // base64
|
|
103
|
-
encoded_tx: [
|
|
110
|
+
encoded_tx: [mainTxBase64, tipTxBase64].join(','), // bundle: mainTx, tipTx
|
|
104
111
|
max_retry: 3
|
|
105
112
|
}
|
|
106
113
|
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { TradeGasFeeType } from "@clonegod/ttd-core"
|
|
2
|
+
|
|
3
|
+
var tx_gas_map:Map<string, TradeGasFeeType> = new Map()
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* 将发送交易的gas费用缓存到内存中,用于后续的交易结果解析
|
|
7
|
+
*
|
|
8
|
+
* @param txid
|
|
9
|
+
* @param sol_gas_fee
|
|
10
|
+
*/
|
|
11
|
+
export const set_sol_gas_fee = (txid: string, sol_gas_fee: TradeGasFeeType) => {
|
|
12
|
+
tx_gas_map.set(txid, sol_gas_fee)
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export const get_sol_gas_fee = (txid: string) : TradeGasFeeType => {
|
|
16
|
+
if(tx_gas_map.has(txid)) {
|
|
17
|
+
return tx_gas_map.get(txid)
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
return null
|
|
21
|
+
}
|
|
22
|
+
|
|
@@ -3,6 +3,7 @@ import { StandardPoolInfoType, StandardSwapDetailType, TradeGasFeeType } from '@
|
|
|
3
3
|
import { DEX_ID, log_info, TradeErrorCodeType } from '@clonegod/ttd-core/dist';
|
|
4
4
|
import { ParsedTransactionWithMeta, PublicKey, TokenBalance } from '@solana/web3.js';
|
|
5
5
|
import { EventEmitter } from 'events';
|
|
6
|
+
import { get_sol_gas_fee } from './sol_gas_cache';
|
|
6
7
|
|
|
7
8
|
export class TransactionResultParser {
|
|
8
9
|
|
|
@@ -68,8 +69,14 @@ export class TransactionResultParser {
|
|
|
68
69
|
let priority_fee = 0
|
|
69
70
|
let total_fee = 0
|
|
70
71
|
|
|
71
|
-
|
|
72
|
-
|
|
72
|
+
let sol_gas_fee = get_sol_gas_fee(txid)
|
|
73
|
+
if(sol_gas_fee) {
|
|
74
|
+
priority_fee = sol_gas_fee.priority_fee // priority fee + jito tip fee
|
|
75
|
+
total_fee = base_fee + priority_fee
|
|
76
|
+
} else {
|
|
77
|
+
total_fee = preBalances[0] - postBalances[0]
|
|
78
|
+
priority_fee = Math.abs(total_fee - base_fee)
|
|
79
|
+
}
|
|
73
80
|
|
|
74
81
|
|
|
75
82
|
let gas_fee: TradeGasFeeType = {
|