@clonegod/ttd-sol-common 2.0.36 → 2.0.39

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.
@@ -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 ws_url = process.env.SUBSCIBE_MULTIPLE_PROVIDERS_WS_URL || 'ws://127.0.0.1:10000';
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 }, _) => {
@@ -12,7 +13,7 @@ function subscribe_pool_account_update(dex_id, pool_list, callback) {
12
13
  });
13
14
  ws_client.onMessage(((eventData) => {
14
15
  if (!eventData.data) {
15
- (0, dist_1.log_warn)(`[SolanaTradeAppConfig] subscribe_pool_events_from_multiple_providers: no data`, eventData);
16
+ (0, dist_1.log_warn)(`subscribe_pool_account_update: no data`, eventData);
16
17
  }
17
18
  else {
18
19
  callback(eventData);
@@ -0,0 +1,8 @@
1
+ import { AbstractTradeAppConfig } from "@clonegod/ttd-core/dist";
2
+ import { Connection, Keypair } from "@solana/web3.js";
3
+ export declare class SolanaTradeAppConfig extends AbstractTradeAppConfig {
4
+ connection: Connection;
5
+ keypair: Keypair;
6
+ constructor();
7
+ subscribe_wallet_raw_txn_event(): void;
8
+ }
@@ -0,0 +1,26 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.SolanaTradeAppConfig = void 0;
4
+ const dist_1 = require("@clonegod/ttd-core/dist");
5
+ class SolanaTradeAppConfig extends dist_1.AbstractTradeAppConfig {
6
+ constructor() {
7
+ super();
8
+ this.subscribe_wallet_raw_txn_event();
9
+ }
10
+ subscribe_wallet_raw_txn_event() {
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();
24
+ }
25
+ }
26
+ exports.SolanaTradeAppConfig = SolanaTradeAppConfig;
@@ -0,0 +1 @@
1
+ export * from './SolanaTradeAppConfig';
@@ -0,0 +1,17 @@
1
+ "use strict";
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 __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ __exportStar(require("./SolanaTradeAppConfig"), exports);
@@ -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
- return;
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;
@@ -1,6 +1,6 @@
1
1
  export * from './tx_result_check';
2
2
  export * from './tx_result_parse';
3
- export * from './SolanaTradeAppConfig';
3
+ export * from '../config/SolanaTradeAppConfig';
4
4
  export * from './tx_builder';
5
5
  export * from './send';
6
6
  export * from './jito_tip_wallets';
@@ -16,7 +16,7 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
16
16
  Object.defineProperty(exports, "__esModule", { value: true });
17
17
  __exportStar(require("./tx_result_check"), exports);
18
18
  __exportStar(require("./tx_result_parse"), exports);
19
- __exportStar(require("./SolanaTradeAppConfig"), exports);
19
+ __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);
@@ -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.JITO_SEND_BUNDLE_PROXY_SERVERS || '127.0.0.1').split(',');
115
- let urls = ips.map(ip => `http://${ip}:10429/solana/send_tx`);
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),
@@ -1,6 +1,6 @@
1
1
  import { TradeContext } from "@clonegod/ttd-core/dist";
2
2
  import { Connection, Keypair, Transaction, TransactionInstruction } from "@solana/web3.js";
3
- import { SolanaTradeAppConfig } from "./SolanaTradeAppConfig";
3
+ import { SolanaTradeAppConfig } from "../config/SolanaTradeAppConfig";
4
4
  import { JitoTipWalletManager } from "./jito_tip_wallets";
5
5
  export declare class SolTransactionBuilder {
6
6
  appConfig: SolanaTradeAppConfig;
@@ -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, (messageStr) => {
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
- (0, dist_1.log_debug)('on events: EVENT_WALLET_TRANSACTION', messageStr);
42
- let messageObj = messageStr;
43
- if (typeof messageStr === 'string') {
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 || '3000');
79
- const check_timeout = parseInt(process.env.CHECK_TX_RESULT_TIMEOUT_MILLS || '10000');
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
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@clonegod/ttd-sol-common",
3
- "version": "2.0.36",
3
+ "version": "2.0.39",
4
4
  "description": "",
5
5
  "main": "dist/index.js",
6
6
  "types": "types/index.d.ts",
@@ -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 ws_url = process.env.SUBSCIBE_MULTIPLE_PROVIDERS_WS_URL || 'ws://127.0.0.1:10000';
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 }, _) => {
@@ -17,7 +18,7 @@ export function subscribe_pool_account_update(dex_id: DEX_ID, pool_list: Standar
17
18
  })
18
19
  ws_client.onMessage(((eventData: SolanaPoolAccountUpdateEventData): void => {
19
20
  if (!eventData.data) {
20
- log_warn(`[SolanaTradeAppConfig] subscribe_pool_events_from_multiple_providers: no data`, eventData);
21
+ log_warn(`subscribe_pool_account_update: no data`, eventData);
21
22
  } else {
22
23
  callback(eventData);
23
24
  }
@@ -0,0 +1,45 @@
1
+ import { AbstractTradeAppConfig, LOCAL_EVENT_NAME, log_info, WebSocketClient } from "@clonegod/ttd-core/dist";
2
+ import { Connection, Keypair } from "@solana/web3.js";
3
+
4
+ export class SolanaTradeAppConfig extends AbstractTradeAppConfig {
5
+
6
+ // 子类需要设置的属性
7
+ public connection: Connection;
8
+ public keypair: Keypair;
9
+
10
+ constructor() {
11
+ super();
12
+ this.subscribe_wallet_raw_txn_event();
13
+ }
14
+
15
+
16
+ // 订阅 Wallet 在链上发生的tx data
17
+ subscribe_wallet_raw_txn_event(): void {
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);
39
+ }
40
+
41
+
42
+
43
+ }
44
+
45
+
@@ -0,0 +1,2 @@
1
+ export * from './SolanaTradeAppConfig';
2
+
@@ -1,6 +1,6 @@
1
1
  export * from './tx_result_check'
2
2
  export * from './tx_result_parse'
3
- export * from './SolanaTradeAppConfig'
3
+ export * from '../config/SolanaTradeAppConfig'
4
4
  export * from './tx_builder'
5
5
  export * from './send'
6
6
  export * from './jito_tip_wallets'
@@ -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.JITO_SEND_BUNDLE_PROXY_SERVERS || '127.0.0.1').split(',')
99
- let urls = ips.map(ip => `http://${ip}:10429/solana/send_tx`)
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: '',
@@ -2,7 +2,7 @@ import { CHAIN_ID, TradeContext } from "@clonegod/ttd-core/dist";
2
2
  import { ComputeBudgetProgram, Connection, Keypair, LAMPORTS_PER_SOL, PublicKey, SystemProgram, Transaction, TransactionInstruction } from "@solana/web3.js";
3
3
  import { LAMPORTS_PER_MICRO_LAMPORTS } from "../common";
4
4
  import { SolanaBlockMetaUpdateEvent } from "../types";
5
- import { SolanaTradeAppConfig } from "./SolanaTradeAppConfig";
5
+ import { SolanaTradeAppConfig } from "../config/SolanaTradeAppConfig";
6
6
  import { HELIUS_TIP_ACCOUNTS } from "./send/helius";
7
7
  import { getJitoTipAccount } from "./send/jito";
8
8
  import { JitoTipWalletManager } from "./jito_tip_wallets";
@@ -76,17 +76,16 @@ export class TransactionResultChecker extends AbstractTransactionResultCheck {
76
76
  }
77
77
 
78
78
  /**
79
- * 从第三方服务(helius geyser ws)订阅Transaction结果
79
+ * 从第三方服务(stream ws)订阅Transaction结果
80
80
  */
81
81
  on_subscibe_transaction() {
82
- this.event_emitter.once(LOCAL_EVENT_NAME.EVENT_WALLET_TRANSACTION + '#' + this.txid, (messageStr) => {
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 = messageStr
88
- if(typeof messageStr === 'string') {
89
- messageObj = JSON.parse(messageStr)
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 || '3000')
134
- const check_timeout = parseInt(process.env.CHECK_TX_RESULT_TIMEOUT_MILLS || '10000')
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
 
@@ -1,25 +0,0 @@
1
- import { AbstractTradeAppConfig } from "@clonegod/ttd-core/dist";
2
- import { Connection, Keypair } from "@solana/web3.js";
3
-
4
- export class SolanaTradeAppConfig extends AbstractTradeAppConfig {
5
-
6
- // 子类需要设置的属性
7
- public connection: Connection;
8
- public keypair: Keypair;
9
-
10
- constructor() {
11
- super();
12
- }
13
-
14
-
15
- // 订阅 Wallet 在链上发生的tx data
16
- subscribe_wallet_raw_txn_event(): void {
17
- // not used
18
- return;
19
- }
20
-
21
-
22
-
23
- }
24
-
25
-