@clonegod/ttd-sol-common 1.0.103 → 1.0.105
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.
|
@@ -8,43 +8,47 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
8
8
|
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
9
|
});
|
|
10
10
|
};
|
|
11
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
12
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
|
+
};
|
|
11
14
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
+
exports.subscribe_jito_tips = void 0;
|
|
12
16
|
exports.get_latest_jito_tip = get_latest_jito_tip;
|
|
13
17
|
const dist_1 = require("@clonegod/ttd-common/dist");
|
|
14
18
|
const web3_js_1 = require("@solana/web3.js");
|
|
15
|
-
|
|
19
|
+
const ws_1 = __importDefault(require("ws"));
|
|
20
|
+
var jito_tip_floor;
|
|
16
21
|
const jito_tip_stats_url = process.env.JITO_TIP_FEE_STATS_URL || 'https://bundles.jito.wtf/api/v1/bundles/tip_floor';
|
|
17
|
-
const JITO_TIP_DEFAULT = 0.
|
|
18
|
-
const JITO_TIP_MIN = 0.
|
|
19
|
-
const JITO_TIP_MAX = 0.
|
|
22
|
+
const JITO_TIP_DEFAULT = 0.00018;
|
|
23
|
+
const JITO_TIP_MIN = 0.00008;
|
|
24
|
+
const JITO_TIP_MAX = 0.0008;
|
|
20
25
|
function get_jito_tip_floor() {
|
|
21
26
|
return __awaiter(this, void 0, void 0, function* () {
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
27
|
+
try {
|
|
28
|
+
let res = yield (yield fetch(jito_tip_stats_url)).json();
|
|
29
|
+
(0, dist_1.log_info)(`get_jito_tip_floor,res=`, res);
|
|
30
|
+
return res[0];
|
|
31
|
+
}
|
|
32
|
+
catch (err) {
|
|
33
|
+
(0, dist_1.log_error)('get_jito_tip_floor error!', err);
|
|
34
|
+
}
|
|
25
35
|
});
|
|
26
36
|
}
|
|
27
|
-
function refresh_jito_tip_floor() {
|
|
28
|
-
setInterval(() => __awaiter(this, void 0, void 0, function* () {
|
|
29
|
-
jito_tip_pct = yield get_jito_tip_floor();
|
|
30
|
-
}), 1 * 60 * 1000);
|
|
31
|
-
}
|
|
32
|
-
refresh_jito_tip_floor();
|
|
33
37
|
function get_latest_jito_tip(speed, fee_max_cap) {
|
|
34
38
|
return __awaiter(this, void 0, void 0, function* () {
|
|
35
39
|
let tip_sol = JITO_TIP_DEFAULT;
|
|
36
|
-
if (!
|
|
37
|
-
|
|
40
|
+
if (!jito_tip_floor) {
|
|
41
|
+
jito_tip_floor = yield get_jito_tip_floor();
|
|
38
42
|
}
|
|
39
|
-
if (
|
|
43
|
+
if (jito_tip_floor) {
|
|
40
44
|
if (speed === 'fast') {
|
|
41
|
-
tip_sol =
|
|
45
|
+
tip_sol = jito_tip_floor['landed_tips_50th_percentile'];
|
|
42
46
|
}
|
|
43
47
|
if (speed === 'turbo') {
|
|
44
|
-
tip_sol =
|
|
48
|
+
tip_sol = jito_tip_floor['landed_tips_75th_percentile'];
|
|
45
49
|
}
|
|
46
50
|
if (speed === 'ultra') {
|
|
47
|
-
tip_sol =
|
|
51
|
+
tip_sol = jito_tip_floor['landed_tips_95th_percentile'];
|
|
48
52
|
}
|
|
49
53
|
}
|
|
50
54
|
if (tip_sol < JITO_TIP_MIN) {
|
|
@@ -60,3 +64,50 @@ function get_latest_jito_tip(speed, fee_max_cap) {
|
|
|
60
64
|
return tip_lamports;
|
|
61
65
|
});
|
|
62
66
|
}
|
|
67
|
+
const jito_tip_ws_url = 'ws://bundles-api-rest.jito.wtf/api/v1/bundles/tip_stream';
|
|
68
|
+
const subscribe_jito_tips = () => __awaiter(void 0, void 0, void 0, function* () {
|
|
69
|
+
if (process.env.SUB_JITO_TIPS !== 'true') {
|
|
70
|
+
(0, dist_1.log_info)(`subscribe_jito_tips, process.env.SUB_JITO_TIPS=${process.env.SUB_JITO_TIPS}, skip!`);
|
|
71
|
+
return;
|
|
72
|
+
}
|
|
73
|
+
(0, dist_1.log_info)(`subscribe_jito_tips`, jito_tip_ws_url);
|
|
74
|
+
var ws_client = new ws_1.default(jito_tip_ws_url);
|
|
75
|
+
function startPing(ws) {
|
|
76
|
+
setInterval(() => {
|
|
77
|
+
if (ws.readyState === ws_1.default.OPEN) {
|
|
78
|
+
ws.ping();
|
|
79
|
+
(0, dist_1.log_debug)('Ping ws server');
|
|
80
|
+
}
|
|
81
|
+
}, 30000);
|
|
82
|
+
}
|
|
83
|
+
ws_client.on('open', function open() {
|
|
84
|
+
(0, dist_1.log_info)(`WebSocket is open`);
|
|
85
|
+
startPing(ws_client);
|
|
86
|
+
});
|
|
87
|
+
ws_client.on('message', function incoming(data) {
|
|
88
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
89
|
+
const messageStr = data.toString('utf8');
|
|
90
|
+
(0, dist_1.log_debug)('[subscribe_jito_tips] Received:', messageStr);
|
|
91
|
+
try {
|
|
92
|
+
jito_tip_floor = JSON.parse(messageStr)[0];
|
|
93
|
+
}
|
|
94
|
+
catch (e) {
|
|
95
|
+
(0, dist_1.log_error)('[subscribe_jito_tips] Failed to parse JSON:', e);
|
|
96
|
+
ws_client.close();
|
|
97
|
+
}
|
|
98
|
+
});
|
|
99
|
+
});
|
|
100
|
+
ws_client.on('error', function error(err) {
|
|
101
|
+
(0, dist_1.log_error)(`WebSocket error:`, err);
|
|
102
|
+
ws_client.close();
|
|
103
|
+
});
|
|
104
|
+
ws_client.on('close', function close() {
|
|
105
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
106
|
+
(0, dist_1.log_warn)(`Socket is closed. Reconnect will be attempted in few seconds`);
|
|
107
|
+
yield (0, dist_1.sleep)(3000);
|
|
108
|
+
(0, exports.subscribe_jito_tips)();
|
|
109
|
+
});
|
|
110
|
+
});
|
|
111
|
+
});
|
|
112
|
+
exports.subscribe_jito_tips = subscribe_jito_tips;
|
|
113
|
+
(0, exports.subscribe_jito_tips)();
|