@clonegod/ttd-sol-common 2.0.35 → 2.0.38
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/common/subscribe_account_update.js +2 -1
- package/dist/trade/SolanaTradeAppConfig.js +14 -1
- package/dist/trade/send/jito.js +2 -2
- package/dist/trade/tx_result_check.js +6 -7
- package/package.json +1 -1
- package/src/common/subscribe_account_update.ts +2 -1
- package/src/trade/SolanaTradeAppConfig.ts +23 -3
- package/src/trade/send/jito.ts +2 -2
- package/src/trade/tx_result_check.ts +7 -8
|
@@ -3,7 +3,8 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.subscribe_pool_account_update = subscribe_pool_account_update;
|
|
4
4
|
const dist_1 = require("@clonegod/ttd-core/dist");
|
|
5
5
|
function subscribe_pool_account_update(dex_id, pool_list, callback) {
|
|
6
|
-
const
|
|
6
|
+
const port = process.env.STREAM_WS_QUOTE_PORT || 10000;
|
|
7
|
+
const ws_url = `ws://127.0.0.1:${port}`;
|
|
7
8
|
const ws_client = new dist_1.WebSocketClient(ws_url);
|
|
8
9
|
ws_client.onOpen(() => {
|
|
9
10
|
pool_list.forEach(({ pool_name, pool_address }, _) => {
|
|
@@ -5,9 +5,22 @@ const dist_1 = require("@clonegod/ttd-core/dist");
|
|
|
5
5
|
class SolanaTradeAppConfig extends dist_1.AbstractTradeAppConfig {
|
|
6
6
|
constructor() {
|
|
7
7
|
super();
|
|
8
|
+
this.subscribe_wallet_raw_txn_event();
|
|
8
9
|
}
|
|
9
10
|
subscribe_wallet_raw_txn_event() {
|
|
10
|
-
|
|
11
|
+
const transactionHandler = async (messageStr) => {
|
|
12
|
+
let messageObj = messageStr;
|
|
13
|
+
if (typeof messageStr === 'string') {
|
|
14
|
+
messageObj = JSON.parse(messageStr);
|
|
15
|
+
}
|
|
16
|
+
const tx_id = messageObj.transaction.signature;
|
|
17
|
+
(0, dist_1.log_info)(`Received transaction result via WebSocket: ${tx_id}`);
|
|
18
|
+
this.emit(dist_1.LOCAL_EVENT_NAME.EVENT_WALLET_TRANSACTION + '#' + tx_id, messageObj);
|
|
19
|
+
};
|
|
20
|
+
const ws_port = process.env.STREAM_WS_TRADE_PORT || 10002;
|
|
21
|
+
const ws = new dist_1.WebSocketClient(`ws://localhost:${ws_port}`);
|
|
22
|
+
ws.onMessage(transactionHandler);
|
|
23
|
+
ws.connect();
|
|
11
24
|
}
|
|
12
25
|
}
|
|
13
26
|
exports.SolanaTradeAppConfig = SolanaTradeAppConfig;
|
package/dist/trade/send/jito.js
CHANGED
|
@@ -111,8 +111,8 @@ const sendBundleWithJito = async (mainTx, tipTx) => {
|
|
|
111
111
|
};
|
|
112
112
|
exports.sendBundleWithJito = sendBundleWithJito;
|
|
113
113
|
const sendBundleWithJitoMultiIps = async (mainTx, tipTx) => {
|
|
114
|
-
let ips = (process.env.
|
|
115
|
-
let urls = ips.map(ip => `http://${ip}:
|
|
114
|
+
let ips = (process.env.JITO_SEND_BUNDLE_SERVER_IPS || '127.0.0.1').split(',');
|
|
115
|
+
let urls = ips.map(ip => `http://${ip}:10001/solana/send_tx`);
|
|
116
116
|
const body = {
|
|
117
117
|
trace_id: '',
|
|
118
118
|
txid: (0, common_1.getSignature)(mainTx),
|
|
@@ -35,13 +35,12 @@ class TransactionResultChecker extends dist_1.AbstractTransactionResultCheck {
|
|
|
35
35
|
this.on_subscibe_transaction();
|
|
36
36
|
}
|
|
37
37
|
on_subscibe_transaction() {
|
|
38
|
-
this.event_emitter.once(dist_1.LOCAL_EVENT_NAME.EVENT_WALLET_TRANSACTION + '#' + this.txid, (
|
|
38
|
+
this.event_emitter.once(dist_1.LOCAL_EVENT_NAME.EVENT_WALLET_TRANSACTION + '#' + this.txid, (message) => {
|
|
39
39
|
try {
|
|
40
40
|
this.trade_result_already_processed = true;
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
messageObj = JSON.parse(messageStr);
|
|
41
|
+
let messageObj = message;
|
|
42
|
+
if (typeof message === 'string') {
|
|
43
|
+
messageObj = JSON.parse(message);
|
|
45
44
|
}
|
|
46
45
|
const result = messageObj.params.result;
|
|
47
46
|
const _txid = result.signature;
|
|
@@ -75,8 +74,8 @@ class TransactionResultChecker extends dist_1.AbstractTransactionResultCheck {
|
|
|
75
74
|
}
|
|
76
75
|
async check_tx_result_interval() {
|
|
77
76
|
const check_start_time = Date.now();
|
|
78
|
-
const check_interval = parseInt(process.env.CHECK_TX_RESULT_INTERVAL_MILLS || '
|
|
79
|
-
const check_timeout = parseInt(process.env.CHECK_TX_RESULT_TIMEOUT_MILLS || '
|
|
77
|
+
const check_interval = parseInt(process.env.CHECK_TX_RESULT_INTERVAL_MILLS || '1000');
|
|
78
|
+
const check_timeout = parseInt(process.env.CHECK_TX_RESULT_TIMEOUT_MILLS || '6000');
|
|
80
79
|
(0, dist_1.log_info)(`check transaction start: check_interval=${check_interval}, check_timeout=${check_timeout}`);
|
|
81
80
|
if (check_interval >= check_timeout) {
|
|
82
81
|
(0, dist_1.log_warn)(`check_interval=${check_interval} >= check_timeout=${check_timeout}, check_tx_result_interval failed!`);
|
package/package.json
CHANGED
|
@@ -8,7 +8,8 @@ import { SolanaPoolAccountUpdateEventData } from "../types";
|
|
|
8
8
|
* - 交易使用:交易中需要池子的最新状态
|
|
9
9
|
*/
|
|
10
10
|
export function subscribe_pool_account_update(dex_id: DEX_ID, pool_list: StandardPoolInfoType[], callback: (eventData: SolanaPoolAccountUpdateEventData) => void) {
|
|
11
|
-
const
|
|
11
|
+
const port = process.env.STREAM_WS_QUOTE_PORT || 10000;
|
|
12
|
+
const ws_url = `ws://127.0.0.1:${port}`;
|
|
12
13
|
const ws_client = new WebSocketClient(ws_url)
|
|
13
14
|
ws_client.onOpen(() => {
|
|
14
15
|
pool_list.forEach(({ pool_name, pool_address }, _) => {
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { AbstractTradeAppConfig } from "@clonegod/ttd-core/dist";
|
|
1
|
+
import { AbstractTradeAppConfig, log_info, log_error, WebSocketClient, LOCAL_EVENT_NAME } from "@clonegod/ttd-core/dist";
|
|
2
2
|
import { Connection, Keypair } from "@solana/web3.js";
|
|
3
3
|
|
|
4
4
|
export class SolanaTradeAppConfig extends AbstractTradeAppConfig {
|
|
@@ -9,13 +9,33 @@ export class SolanaTradeAppConfig extends AbstractTradeAppConfig {
|
|
|
9
9
|
|
|
10
10
|
constructor() {
|
|
11
11
|
super();
|
|
12
|
+
this.subscribe_wallet_raw_txn_event();
|
|
12
13
|
}
|
|
13
14
|
|
|
14
15
|
|
|
15
16
|
// 订阅 Wallet 在链上发生的tx data
|
|
16
17
|
subscribe_wallet_raw_txn_event(): void {
|
|
17
|
-
//
|
|
18
|
-
|
|
18
|
+
// 定义处理函数,便于后续移除
|
|
19
|
+
const transactionHandler = async (messageStr: any) => {
|
|
20
|
+
let messageObj = messageStr
|
|
21
|
+
if(typeof messageStr === 'string') {
|
|
22
|
+
messageObj = JSON.parse(messageStr)
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
// console.dir(messge, { depth: null });
|
|
26
|
+
const tx_id = messageObj.transaction.signature;
|
|
27
|
+
log_info(`Received transaction result via WebSocket: ${tx_id}`);
|
|
28
|
+
|
|
29
|
+
this.emit(LOCAL_EVENT_NAME.EVENT_WALLET_TRANSACTION + '#' + tx_id, messageObj);
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
const ws_port = process.env.STREAM_WS_TRADE_PORT || 10002;
|
|
33
|
+
const ws = new WebSocketClient(`ws://localhost:${ws_port}`)
|
|
34
|
+
ws.onMessage(transactionHandler);
|
|
35
|
+
ws.connect();
|
|
36
|
+
|
|
37
|
+
// 不断开连接
|
|
38
|
+
// setTimeout(() => { ws.disconnect(); }, 6000);
|
|
19
39
|
}
|
|
20
40
|
|
|
21
41
|
|
package/src/trade/send/jito.ts
CHANGED
|
@@ -95,8 +95,8 @@ export const sendBundleWithJito = async (mainTx: Transaction, tipTx: Transaction
|
|
|
95
95
|
|
|
96
96
|
|
|
97
97
|
export const sendBundleWithJitoMultiIps = async (mainTx: Transaction, tipTx: Transaction): Promise<string> => {
|
|
98
|
-
let ips = (process.env.
|
|
99
|
-
let urls = ips.map(ip => `http://${ip}:
|
|
98
|
+
let ips = (process.env.JITO_SEND_BUNDLE_SERVER_IPS || '127.0.0.1').split(',')
|
|
99
|
+
let urls = ips.map(ip => `http://${ip}:10001/solana/send_tx`)
|
|
100
100
|
|
|
101
101
|
const body = {
|
|
102
102
|
trace_id: '',
|
|
@@ -76,17 +76,16 @@ export class TransactionResultChecker extends AbstractTransactionResultCheck {
|
|
|
76
76
|
}
|
|
77
77
|
|
|
78
78
|
/**
|
|
79
|
-
* 从第三方服务(
|
|
79
|
+
* 从第三方服务(stream ws)订阅Transaction结果
|
|
80
80
|
*/
|
|
81
81
|
on_subscibe_transaction() {
|
|
82
|
-
this.event_emitter.once(LOCAL_EVENT_NAME.EVENT_WALLET_TRANSACTION + '#' + this.txid, (
|
|
82
|
+
this.event_emitter.once(LOCAL_EVENT_NAME.EVENT_WALLET_TRANSACTION + '#' + this.txid, (message: any) => {
|
|
83
83
|
try {
|
|
84
84
|
this.trade_result_already_processed = true
|
|
85
|
-
log_debug('on events: EVENT_WALLET_TRANSACTION', messageStr)
|
|
86
85
|
|
|
87
|
-
let messageObj =
|
|
88
|
-
if(typeof
|
|
89
|
-
messageObj = JSON.parse(
|
|
86
|
+
let messageObj = message
|
|
87
|
+
if(typeof message === 'string') {
|
|
88
|
+
messageObj = JSON.parse(message)
|
|
90
89
|
}
|
|
91
90
|
|
|
92
91
|
const result = messageObj.params.result
|
|
@@ -130,8 +129,8 @@ export class TransactionResultChecker extends AbstractTransactionResultCheck {
|
|
|
130
129
|
*/
|
|
131
130
|
async check_tx_result_interval() {
|
|
132
131
|
const check_start_time = Date.now()
|
|
133
|
-
const check_interval = parseInt(process.env.CHECK_TX_RESULT_INTERVAL_MILLS || '
|
|
134
|
-
const check_timeout = parseInt(process.env.CHECK_TX_RESULT_TIMEOUT_MILLS || '
|
|
132
|
+
const check_interval = parseInt(process.env.CHECK_TX_RESULT_INTERVAL_MILLS || '1000')
|
|
133
|
+
const check_timeout = parseInt(process.env.CHECK_TX_RESULT_TIMEOUT_MILLS || '6000')
|
|
135
134
|
|
|
136
135
|
log_info(`check transaction start: check_interval=${check_interval}, check_timeout=${check_timeout}`)
|
|
137
136
|
|