@clonegod/ttd-sol-common 1.0.90 → 1.0.92
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,101 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
12
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
|
+
};
|
|
14
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
+
exports.subscribe_wallet_transaction_txid = void 0;
|
|
16
|
+
const dist_1 = require("@clonegod/ttd-common/dist");
|
|
17
|
+
const ws_1 = __importDefault(require("ws"));
|
|
18
|
+
const constants_1 = require("../common/constants");
|
|
19
|
+
const subscribe_wallet_transaction_txid = (geyser_ws_url, signature, eventEmitter) => __awaiter(void 0, void 0, void 0, function* () {
|
|
20
|
+
if ((0, dist_1.isEmpty)(geyser_ws_url)) {
|
|
21
|
+
(0, dist_1.log_warn)(`geyser_ws_url is empty, cann't subscribe`);
|
|
22
|
+
return;
|
|
23
|
+
}
|
|
24
|
+
if ((0, dist_1.isEmpty)(signature)) {
|
|
25
|
+
(0, dist_1.log_warn)(`signature is empty, nothing to subscribe`);
|
|
26
|
+
return;
|
|
27
|
+
}
|
|
28
|
+
var ws_client = new ws_1.default(geyser_ws_url);
|
|
29
|
+
function subscribe_transaction_by_txid() {
|
|
30
|
+
(0, dist_1.log_info)(`subscribe_transaction_by_txid`, signature);
|
|
31
|
+
const request = {
|
|
32
|
+
jsonrpc: '2.0',
|
|
33
|
+
id: 420,
|
|
34
|
+
method: 'transactionSubscribe',
|
|
35
|
+
params: [
|
|
36
|
+
{
|
|
37
|
+
signature: signature,
|
|
38
|
+
},
|
|
39
|
+
{
|
|
40
|
+
commitment: constants_1.COMMITMENT_LEVEL.PROCESSED,
|
|
41
|
+
encoding: 'base64',
|
|
42
|
+
transactionDetails: 'full',
|
|
43
|
+
showRewards: true,
|
|
44
|
+
maxSupportedTransactionVersion: 0,
|
|
45
|
+
},
|
|
46
|
+
],
|
|
47
|
+
};
|
|
48
|
+
ws_client.send(JSON.stringify(request));
|
|
49
|
+
}
|
|
50
|
+
function startPing(ws) {
|
|
51
|
+
setInterval(() => {
|
|
52
|
+
if (ws.readyState === ws_1.default.OPEN) {
|
|
53
|
+
ws.ping();
|
|
54
|
+
(0, dist_1.log_debug)('Ping helius ws server');
|
|
55
|
+
}
|
|
56
|
+
}, 30000);
|
|
57
|
+
}
|
|
58
|
+
ws_client.on('open', function open() {
|
|
59
|
+
(0, dist_1.log_info)(`WebSocket is open`);
|
|
60
|
+
subscribe_transaction_by_txid();
|
|
61
|
+
});
|
|
62
|
+
ws_client.on('message', function incoming(data) {
|
|
63
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
64
|
+
const messageStr = data.toString('utf8');
|
|
65
|
+
(0, dist_1.log_debug)('[helius-subscribe-tx] Received:', messageStr);
|
|
66
|
+
try {
|
|
67
|
+
if (messageStr == '{}' || messageStr.includes('INTERNAL_ERROR')) {
|
|
68
|
+
console.error('[helius-subscribe-tx] receive bad message, something wrong! reconnect ...');
|
|
69
|
+
subscribe_transaction_by_txid();
|
|
70
|
+
return;
|
|
71
|
+
}
|
|
72
|
+
const messageObj = JSON.parse(messageStr);
|
|
73
|
+
const { method } = messageObj;
|
|
74
|
+
if (method === 'transactionNotification') {
|
|
75
|
+
if (messageObj.params.error) {
|
|
76
|
+
throw new Error(messageObj.params.error);
|
|
77
|
+
}
|
|
78
|
+
const result = messageObj.params.result;
|
|
79
|
+
const txid = result.signature;
|
|
80
|
+
const eventName = constants_1.LOCAL_EVENT_NAME.EVENT_WALLET_TRANSACTION + '#' + txid;
|
|
81
|
+
eventEmitter.emit(eventName, messageStr);
|
|
82
|
+
ws_client.close();
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
catch (e) {
|
|
86
|
+
(0, dist_1.log_error)('[helius-subscribe-tx] Failed to parse JSON:', e);
|
|
87
|
+
ws_client.close();
|
|
88
|
+
}
|
|
89
|
+
});
|
|
90
|
+
});
|
|
91
|
+
ws_client.on('error', function error(err) {
|
|
92
|
+
(0, dist_1.log_error)(`WebSocket error:`, err);
|
|
93
|
+
ws_client.close();
|
|
94
|
+
});
|
|
95
|
+
ws_client.on('close', function close() {
|
|
96
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
97
|
+
(0, dist_1.log_warn)(`Socket is closed.`);
|
|
98
|
+
});
|
|
99
|
+
});
|
|
100
|
+
});
|
|
101
|
+
exports.subscribe_wallet_transaction_txid = subscribe_wallet_transaction_txid;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { SendOptions, Signer, TransactionInstruction } from "@solana/web3.js";
|
|
1
|
+
import { AddressLookupTableAccount, SendOptions, Signer, TransactionInstruction } from "@solana/web3.js";
|
|
2
2
|
import { SolanaTradeRuntimeType } from '../../types';
|
|
3
3
|
import { Helius } from "../helius_sdk_v1.4.0";
|
|
4
4
|
export declare class HeliusClient {
|
|
@@ -8,7 +8,7 @@ export declare class HeliusClient {
|
|
|
8
8
|
helius_mainnet: Helius;
|
|
9
9
|
helius_staked: Helius;
|
|
10
10
|
constructor(signers: Signer[]);
|
|
11
|
-
send_transaction(solana_trade_runtime: SolanaTradeRuntimeType, instructions: TransactionInstruction[]): Promise<string>;
|
|
11
|
+
send_transaction(solana_trade_runtime: SolanaTradeRuntimeType, instructions: TransactionInstruction[], addressLookupTableAccounts?: AddressLookupTableAccount[]): Promise<string>;
|
|
12
12
|
private send_smart_transaction;
|
|
13
13
|
private send_transaction_by_jito;
|
|
14
14
|
private send_transaction_mixed;
|
|
@@ -27,19 +27,19 @@ class HeliusClient {
|
|
|
27
27
|
this.helius_mainnet = new helius_sdk_v1_4_0_1.Helius('', this.cluster, 'helius-sdk', helius_mainnet_endpoint);
|
|
28
28
|
this.helius_staked = new helius_sdk_v1_4_0_1.Helius('', this.cluster, 'helius-sdk', helius_staked_endpoint);
|
|
29
29
|
}
|
|
30
|
-
send_transaction(
|
|
31
|
-
return __awaiter(this,
|
|
30
|
+
send_transaction(solana_trade_runtime_1, instructions_1) {
|
|
31
|
+
return __awaiter(this, arguments, void 0, function* (solana_trade_runtime, instructions, addressLookupTableAccounts = []) {
|
|
32
32
|
let txid = '';
|
|
33
33
|
let { broadcast_type, speed } = solana_trade_runtime.settings.strategy;
|
|
34
34
|
let use_staked_endpint = speed === 'turbo' || speed === 'ultra';
|
|
35
35
|
if (broadcast_type === 'rpc') {
|
|
36
|
-
txid = yield this.send_smart_transaction(solana_trade_runtime, instructions, use_staked_endpint);
|
|
36
|
+
txid = yield this.send_smart_transaction(solana_trade_runtime, instructions, use_staked_endpint, addressLookupTableAccounts);
|
|
37
37
|
}
|
|
38
38
|
else if (broadcast_type === 'jito') {
|
|
39
|
-
txid = yield this.send_transaction_by_jito(solana_trade_runtime, instructions);
|
|
39
|
+
txid = yield this.send_transaction_by_jito(solana_trade_runtime, instructions, addressLookupTableAccounts);
|
|
40
40
|
}
|
|
41
41
|
else if (broadcast_type === 'mixed') {
|
|
42
|
-
txid = yield this.send_transaction_mixed(solana_trade_runtime, instructions, use_staked_endpint);
|
|
42
|
+
txid = yield this.send_transaction_mixed(solana_trade_runtime, instructions, use_staked_endpint, addressLookupTableAccounts);
|
|
43
43
|
}
|
|
44
44
|
else {
|
|
45
45
|
throw new Error(`Not support broadcast_type: ${broadcast_type}`);
|
|
@@ -47,12 +47,12 @@ class HeliusClient {
|
|
|
47
47
|
return txid;
|
|
48
48
|
});
|
|
49
49
|
}
|
|
50
|
-
send_smart_transaction(
|
|
51
|
-
return __awaiter(this,
|
|
50
|
+
send_smart_transaction(solana_trade_runtime_1, instructions_1, use_staked_endpint_1) {
|
|
51
|
+
return __awaiter(this, arguments, void 0, function* (solana_trade_runtime, instructions, use_staked_endpint, addressLookupTableAccounts = []) {
|
|
52
52
|
(0, dist_1.log_info)(`send_smart_transaction, start`);
|
|
53
53
|
let start_time = Date.now();
|
|
54
54
|
let rpc = use_staked_endpint ? this.helius_staked.rpc : this.helius_mainnet.rpc;
|
|
55
|
-
let txid = yield rpc.sendSmartTransaction(solana_trade_runtime, instructions, this.signers,
|
|
55
|
+
let txid = yield rpc.sendSmartTransaction(solana_trade_runtime, instructions, this.signers, addressLookupTableAccounts, this.sendOptions);
|
|
56
56
|
(0, dist_1.log_info)(`send_smart_transaction, end`, {
|
|
57
57
|
txid,
|
|
58
58
|
use_staked_endpint,
|
|
@@ -61,14 +61,14 @@ class HeliusClient {
|
|
|
61
61
|
return txid;
|
|
62
62
|
});
|
|
63
63
|
}
|
|
64
|
-
send_transaction_by_jito(
|
|
65
|
-
return __awaiter(this,
|
|
64
|
+
send_transaction_by_jito(solana_trade_runtime_1, instructions_1) {
|
|
65
|
+
return __awaiter(this, arguments, void 0, function* (solana_trade_runtime, instructions, addressLookupTableAccounts = []) {
|
|
66
66
|
(0, dist_1.log_info)(`send_transaction_by_jito, start`);
|
|
67
67
|
let start_time = Date.now();
|
|
68
68
|
let tipAmount = solana_trade_runtime.tip_amount;
|
|
69
69
|
let jito_region = (0, strategy_util_1.get_jito_region)();
|
|
70
70
|
let rpc = this.helius_mainnet.rpc;
|
|
71
|
-
let txid = yield rpc.sendSmartTransactionWithTip(solana_trade_runtime, instructions, this.signers,
|
|
71
|
+
let txid = yield rpc.sendSmartTransactionWithTip(solana_trade_runtime, instructions, this.signers, addressLookupTableAccounts, tipAmount, jito_region);
|
|
72
72
|
(0, dist_1.log_info)(`send_transaction_by_jito, end`, {
|
|
73
73
|
tipAmount,
|
|
74
74
|
jito_region,
|
|
@@ -78,14 +78,14 @@ class HeliusClient {
|
|
|
78
78
|
return txid;
|
|
79
79
|
});
|
|
80
80
|
}
|
|
81
|
-
send_transaction_mixed(
|
|
82
|
-
return __awaiter(this,
|
|
81
|
+
send_transaction_mixed(solana_trade_runtime_1, instructions_1, use_staked_endpint_1) {
|
|
82
|
+
return __awaiter(this, arguments, void 0, function* (solana_trade_runtime, instructions, use_staked_endpint, addressLookupTableAccounts = []) {
|
|
83
83
|
(0, dist_1.log_info)(`send_transaction_mixed, start`);
|
|
84
84
|
let start_time = Date.now();
|
|
85
85
|
let tipAmount = solana_trade_runtime.tip_amount;
|
|
86
86
|
let jito_region = (0, strategy_util_1.get_jito_region)();
|
|
87
87
|
let rpc = use_staked_endpint ? this.helius_staked.rpc : this.helius_mainnet.rpc;
|
|
88
|
-
let txid = yield rpc.sendSmartTransactionWithTipMixed(solana_trade_runtime, instructions, this.signers,
|
|
88
|
+
let txid = yield rpc.sendSmartTransactionWithTipMixed(solana_trade_runtime, instructions, this.signers, addressLookupTableAccounts, tipAmount, jito_region);
|
|
89
89
|
(0, dist_1.log_info)(`send_transaction_mixed, end`, {
|
|
90
90
|
tipAmount,
|
|
91
91
|
jito_region,
|