@clonegod/ttd-sol-common 2.0.47 → 2.0.49
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/send_tx.d.ts +3 -3
- package/dist/trade/send/send_tx.js +12 -5
- 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/send_tx.ts +22 -6
- 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);
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { Transaction, VersionedTransaction } from '@solana/web3.js';
|
|
2
|
+
import { TradeContext } from '@clonegod/ttd-core/dist';
|
|
2
3
|
export declare class TransactionSender {
|
|
3
4
|
constructor();
|
|
4
|
-
sendTransaction(
|
|
5
|
-
sendBundle(mainTx: Transaction | VersionedTransaction, tipTx: Transaction | VersionedTransaction, use_multi_ips?: boolean): Promise<string>;
|
|
5
|
+
sendTransaction(context: TradeContext, mainTx: Transaction | VersionedTransaction, swqos_only?: boolean): Promise<string>;
|
|
6
|
+
sendBundle(context: TradeContext, mainTx: Transaction | VersionedTransaction, tipTx: Transaction | VersionedTransaction, use_multi_ips?: boolean): Promise<string>;
|
|
6
7
|
}
|
|
7
|
-
export declare function serializeTransactionBase64(tx: Transaction | VersionedTransaction): string;
|
|
@@ -1,23 +1,26 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.TransactionSender = void 0;
|
|
4
|
-
exports.serializeTransactionBase64 = serializeTransactionBase64;
|
|
5
4
|
const web3_js_1 = require("@solana/web3.js");
|
|
6
5
|
const helius_1 = require("./helius");
|
|
7
6
|
const jito_1 = require("./jito");
|
|
8
7
|
const common_1 = require("../../common");
|
|
8
|
+
const sol_gas_cache_1 = require("../sol_gas_cache");
|
|
9
9
|
class TransactionSender {
|
|
10
10
|
constructor() {
|
|
11
11
|
}
|
|
12
|
-
async sendTransaction(
|
|
13
|
-
const
|
|
12
|
+
async sendTransaction(context, mainTx, swqos_only = true) {
|
|
13
|
+
const mainTxHash = (0, common_1.getSignature)(mainTx);
|
|
14
|
+
set_transaciton_gas_cost(mainTxHash, context);
|
|
15
|
+
const singedTxBase64 = serializeTransactionBase64(mainTx);
|
|
14
16
|
return await (0, helius_1.sendTxWithHelius)(singedTxBase64, swqos_only);
|
|
15
17
|
}
|
|
16
|
-
async sendBundle(mainTx, tipTx, use_multi_ips = false) {
|
|
18
|
+
async sendBundle(context, mainTx, tipTx, use_multi_ips = false) {
|
|
19
|
+
const mainTxHash = (0, common_1.getSignature)(mainTx);
|
|
20
|
+
set_transaciton_gas_cost(mainTxHash, context);
|
|
17
21
|
const mainTxBase64 = serializeTransactionBase64(mainTx);
|
|
18
22
|
const tipTxBase64 = serializeTransactionBase64(tipTx);
|
|
19
23
|
if (use_multi_ips) {
|
|
20
|
-
const mainTxHash = (0, common_1.getSignature)(mainTx);
|
|
21
24
|
return await (0, jito_1.sendBundleWithJitoMultiIps)(mainTxHash, mainTxBase64, tipTxBase64);
|
|
22
25
|
}
|
|
23
26
|
else {
|
|
@@ -36,3 +39,7 @@ function serializeTransactionBase64(tx) {
|
|
|
36
39
|
}
|
|
37
40
|
return buffer.toString('base64');
|
|
38
41
|
}
|
|
42
|
+
function set_transaciton_gas_cost(txid, context) {
|
|
43
|
+
const { sol_priority_fee, sol_tip_fee } = context.trade_runtime.settings.strategy;
|
|
44
|
+
(0, sol_gas_cache_1.set_sol_gas_fee)(txid, { base_fee: 5000, priority_fee: sol_priority_fee + sol_tip_fee, total_fee: 5000 + sol_priority_fee + sol_tip_fee });
|
|
45
|
+
}
|
|
@@ -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
|
@@ -2,6 +2,8 @@ import { Transaction, VersionedTransaction } from '@solana/web3.js';
|
|
|
2
2
|
import { sendTxWithHelius } from './helius';
|
|
3
3
|
import { sendBundleWithJito, sendBundleWithJitoMultiIps } from './jito';
|
|
4
4
|
import { getSignature } from '../../common';
|
|
5
|
+
import { TradeContext } from '@clonegod/ttd-core/dist';
|
|
6
|
+
import { set_sol_gas_fee } from '../sol_gas_cache';
|
|
5
7
|
|
|
6
8
|
|
|
7
9
|
/**
|
|
@@ -17,12 +19,15 @@ export class TransactionSender {
|
|
|
17
19
|
* - swqos_only=true, 需给 helius 发送至少5000lamports的通道使用费
|
|
18
20
|
* - swqos_only=false, 需给helius 发送至少0.0002SOL的小费,会同时向jito发送交易
|
|
19
21
|
*
|
|
20
|
-
* @param
|
|
22
|
+
* @param mainTx 签名后的交易
|
|
21
23
|
* @param swqos_only true:swqos ;false: swqos + jito
|
|
22
24
|
* @returns txhash
|
|
23
25
|
*/
|
|
24
|
-
async sendTransaction(
|
|
25
|
-
const
|
|
26
|
+
async sendTransaction(context:TradeContext, mainTx: Transaction | VersionedTransaction, swqos_only:boolean=true): Promise<string> {
|
|
27
|
+
const mainTxHash = getSignature(mainTx)
|
|
28
|
+
set_transaciton_gas_cost(mainTxHash, context)
|
|
29
|
+
|
|
30
|
+
const singedTxBase64 = serializeTransactionBase64(mainTx)
|
|
26
31
|
return await sendTxWithHelius(singedTxBase64, swqos_only)
|
|
27
32
|
}
|
|
28
33
|
|
|
@@ -36,11 +41,14 @@ export class TransactionSender {
|
|
|
36
41
|
* @param use_multi_ips true:多节点;false: 单节点
|
|
37
42
|
* @returns bundleId
|
|
38
43
|
*/
|
|
39
|
-
async sendBundle(mainTx: Transaction | VersionedTransaction, tipTx: Transaction | VersionedTransaction, use_multi_ips: boolean=false): Promise<string> {
|
|
44
|
+
async sendBundle(context:TradeContext, mainTx: Transaction | VersionedTransaction, tipTx: Transaction | VersionedTransaction, use_multi_ips: boolean=false): Promise<string> {
|
|
45
|
+
const mainTxHash = getSignature(mainTx)
|
|
46
|
+
set_transaciton_gas_cost(mainTxHash, context)
|
|
47
|
+
|
|
40
48
|
const mainTxBase64 = serializeTransactionBase64(mainTx)
|
|
41
49
|
const tipTxBase64 = serializeTransactionBase64(tipTx)
|
|
50
|
+
|
|
42
51
|
if(use_multi_ips) {
|
|
43
|
-
const mainTxHash = getSignature(mainTx)
|
|
44
52
|
return await sendBundleWithJitoMultiIps(mainTxHash, mainTxBase64, tipTxBase64)
|
|
45
53
|
} else {
|
|
46
54
|
return await sendBundleWithJito(mainTxBase64, tipTxBase64)
|
|
@@ -53,7 +61,7 @@ export class TransactionSender {
|
|
|
53
61
|
/**
|
|
54
62
|
* 序列化交易为 base64 字符串
|
|
55
63
|
*/
|
|
56
|
-
|
|
64
|
+
function serializeTransactionBase64(tx: Transaction | VersionedTransaction): string {
|
|
57
65
|
let buffer:Buffer
|
|
58
66
|
if (tx instanceof VersionedTransaction) {
|
|
59
67
|
buffer = Buffer.from(tx.serialize())
|
|
@@ -64,3 +72,11 @@ export function serializeTransactionBase64(tx: Transaction | VersionedTransactio
|
|
|
64
72
|
}
|
|
65
73
|
return buffer.toString('base64')
|
|
66
74
|
}
|
|
75
|
+
|
|
76
|
+
|
|
77
|
+
// 缓存交易的gas支出
|
|
78
|
+
function set_transaciton_gas_cost(txid:string, context:TradeContext) {
|
|
79
|
+
const {sol_priority_fee, sol_tip_fee} = context.trade_runtime.settings.strategy
|
|
80
|
+
set_sol_gas_fee(txid, {base_fee: 5000, priority_fee: sol_priority_fee + sol_tip_fee, total_fee: 5000 + sol_priority_fee + sol_tip_fee})
|
|
81
|
+
}
|
|
82
|
+
|
|
@@ -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 = {
|