@clonegod/ttd-sol-common 1.0.110 → 1.0.112

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.
@@ -26,6 +26,7 @@ class AppConfig extends events_1.EventEmitter {
26
26
  this.env_args = new env_args_1.EnvArgs();
27
27
  let { chain_id, app_name } = this.env_args;
28
28
  this.app_full_name = app_name;
29
+ global.appConfig = this;
29
30
  }
30
31
  init() {
31
32
  return __awaiter(this, void 0, void 0, function* () {
@@ -22,9 +22,9 @@ function log_quote_price(event_source, price_message, tx_hash) {
22
22
  time.price_time - time.stream_time,
23
23
  time.price_time - time.block_time,
24
24
  ];
25
- setTimeout(() => {
25
+ if (event_source || tx_hash) {
26
26
  console.log(`> [${event_source}] - ${tx_hash}`);
27
- console.log(price_time_str, ' - ', unique_orderbook_id, ' - ', String(price_id).padEnd(32), ' - ', pool_name.padEnd(12), ' - ', pair.padEnd(12), ' - ', String(quote_amount_usd).padEnd(4), ' - ', String(ask.price).padEnd(8), ' - ', String(bid.price).padEnd(8), ' - ', `${times.join(',')} ms`, '\n');
28
- }, 0);
27
+ }
28
+ console.log(price_time_str, ' - ', unique_orderbook_id, ' - ', String(price_id).padEnd(32), ' - ', pool_name.padEnd(12), ' - ', pair.padEnd(12), ' - ', String(quote_amount_usd).padEnd(4), ' - ', String(ask.price).padEnd(8), ' - ', String(bid.price).padEnd(8), ' - ', `${times.join(',')} ms`, '\n');
29
29
  });
30
30
  }
@@ -1,2 +1 @@
1
1
  export declare function get_latest_jito_tip(speed: string, fee_max_cap: number): Promise<number>;
2
- export declare const subscribe_jito_tips: () => Promise<void>;
@@ -8,25 +8,38 @@ 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
- };
14
11
  Object.defineProperty(exports, "__esModule", { value: true });
15
- exports.subscribe_jito_tips = void 0;
16
12
  exports.get_latest_jito_tip = get_latest_jito_tip;
17
13
  const dist_1 = require("@clonegod/ttd-common/dist");
18
14
  const web3_js_1 = require("@solana/web3.js");
19
- const ws_1 = __importDefault(require("ws"));
20
- var jito_tip_floor;
21
15
  const jito_tip_stats_url = process.env.JITO_TIP_FEE_STATS_URL || 'https://bundles.jito.wtf/api/v1/bundles/tip_floor';
22
16
  const JITO_TIP_DEFAULT = 0.00018;
23
17
  const JITO_TIP_MIN = 0.00008;
24
18
  const JITO_TIP_MAX = 0.001;
19
+ function get_jito_tip_floor_from_cache() {
20
+ return __awaiter(this, void 0, void 0, function* () {
21
+ let tip_floor = null;
22
+ try {
23
+ let appConfig = global.appConfig;
24
+ let { key, value } = yield appConfig.arb_cache.loading_cache.get(dist_1.CHAIN_ID.SOLANA, 'jito', 'tip', true);
25
+ if (value) {
26
+ tip_floor = JSON.parse(value);
27
+ }
28
+ }
29
+ catch (err) {
30
+ (0, dist_1.log_error)('get_jito_tip_floor_from_cache error!', err);
31
+ }
32
+ if (tip_floor && tip_floor["landed_tips_75th_percentile"] > 0) {
33
+ return tip_floor;
34
+ }
35
+ return null;
36
+ });
37
+ }
25
38
  function get_jito_tip_floor() {
26
39
  return __awaiter(this, void 0, void 0, function* () {
27
40
  try {
28
41
  let res = yield (yield fetch(jito_tip_stats_url)).json();
29
- (0, dist_1.log_info)(`get_jito_tip_floor,res=`, res);
42
+ (0, dist_1.log_debug)(`get_jito_tip_floor, res=`, res);
30
43
  return res[0];
31
44
  }
32
45
  catch (err) {
@@ -37,6 +50,7 @@ function get_jito_tip_floor() {
37
50
  function get_latest_jito_tip(speed, fee_max_cap) {
38
51
  return __awaiter(this, void 0, void 0, function* () {
39
52
  let tip_sol = JITO_TIP_DEFAULT;
53
+ let jito_tip_floor = yield get_jito_tip_floor_from_cache();
40
54
  if (!jito_tip_floor) {
41
55
  jito_tip_floor = yield get_jito_tip_floor();
42
56
  }
@@ -69,49 +83,3 @@ function get_latest_jito_tip(speed, fee_max_cap) {
69
83
  return tip_lamports;
70
84
  });
71
85
  }
72
- const jito_tip_ws_url = 'ws://bundles-api-rest.jito.wtf/api/v1/bundles/tip_stream';
73
- const subscribe_jito_tips = () => __awaiter(void 0, void 0, void 0, function* () {
74
- if (process.env.SUB_JITO_TIPS !== 'true') {
75
- (0, dist_1.log_info)(`subscribe_jito_tips, process.env.SUB_JITO_TIPS=${process.env.SUB_JITO_TIPS}, skip!`);
76
- return;
77
- }
78
- (0, dist_1.log_info)(`subscribe_jito_tips`, jito_tip_ws_url);
79
- var ws_client = new ws_1.default(jito_tip_ws_url);
80
- function startPing(ws) {
81
- setInterval(() => {
82
- if (ws.readyState === ws_1.default.OPEN) {
83
- ws.ping();
84
- (0, dist_1.log_debug)('Ping ws server');
85
- }
86
- }, 30000);
87
- }
88
- ws_client.on('open', function open() {
89
- (0, dist_1.log_info)(`WebSocket is open`);
90
- startPing(ws_client);
91
- });
92
- ws_client.on('message', function incoming(data) {
93
- return __awaiter(this, void 0, void 0, function* () {
94
- const messageStr = data.toString('utf8');
95
- (0, dist_1.log_debug)('[subscribe_jito_tips] Received:', messageStr);
96
- try {
97
- jito_tip_floor = JSON.parse(messageStr)[0];
98
- }
99
- catch (e) {
100
- (0, dist_1.log_error)('[subscribe_jito_tips] Failed to parse JSON:', e);
101
- ws_client.close();
102
- }
103
- });
104
- });
105
- ws_client.on('error', function error(err) {
106
- (0, dist_1.log_error)(`WebSocket error:`, err);
107
- ws_client.close();
108
- });
109
- ws_client.on('close', function close() {
110
- return __awaiter(this, void 0, void 0, function* () {
111
- (0, dist_1.log_warn)(`Socket is closed. Reconnect will be attempted in few seconds`);
112
- yield (0, dist_1.sleep)(3000);
113
- (0, exports.subscribe_jito_tips)();
114
- });
115
- });
116
- });
117
- exports.subscribe_jito_tips = subscribe_jito_tips;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@clonegod/ttd-sol-common",
3
- "version": "1.0.110",
3
+ "version": "1.0.112",
4
4
  "description": "",
5
5
  "main": "dist/index.js",
6
6
  "types": "types/index.d.ts",
@@ -13,7 +13,7 @@
13
13
  "push": "npm run build && npm publish"
14
14
  },
15
15
  "dependencies": {
16
- "@clonegod/ttd-common": "^1.0.160",
16
+ "@clonegod/ttd-common": "^1.0.162",
17
17
  "@irys/sdk": "^0.2.10",
18
18
  "@metaplex-foundation/mpl-token-metadata": "^2.5.2",
19
19
  "@solana/web3.js": "1.91.6",