Skip to content

Commit 3f3b5ed

Browse files
committed
handle no routes found
1 parent 77a8ff6 commit 3f3b5ed

File tree

2 files changed

+23
-0
lines changed

2 files changed

+23
-0
lines changed

src/bot.js

+5
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ const {
1010
toDecimal,
1111
toNumber,
1212
updateIterationsPerMin,
13+
checkRoutesResponse,
1314
} = require("./utils");
1415

1516
const { handleExit, logExit } = require("./exit");
@@ -52,6 +53,8 @@ const pingpongStrategy = async (jupiter, tokenA, tokenB) => {
5253
forceFetch: true,
5354
});
5455

56+
checkRoutesResponse(routes);
57+
5558
// count available routes
5659
cache.availableRoutes[cache.sideBuy ? "buy" : "sell"] =
5760
routes.routesInfos.length;
@@ -230,6 +233,8 @@ const arbitrageStrategy = async (jupiter, tokenA) => {
230233
forceFetch: true,
231234
});
232235

236+
checkRoutesResponse(routes);
237+
233238
// count available routes
234239
cache.availableRoutes[cache.sideBuy ? "buy" : "sell"] =
235240
routes.routesInfos.length;

src/utils.js

+18
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
const fs = require("fs");
22
const ora = require("ora-classic");
3+
const { logExit } = require("./exit");
34

45
const calculateProfit = (oldVal, newVal) => ((newVal - oldVal) / oldVal) * 100;
56

@@ -52,6 +53,22 @@ const storeItInTempAsJSON = (filename, data) => {
5253
fs.writeFileSync(`./temp/${filename}.json`, JSON.stringify(data, null, 2));
5354
};
5455

56+
const checkRoutesResponse = (routes) => {
57+
if (Object.hasOwn(routes, "routesInfos")) {
58+
if (routes.routesInfos.length === 0) {
59+
logExit(1, {
60+
message: "No routes found or something is wrong with RPC / Jupiter! ",
61+
});
62+
process.exit(1);
63+
}
64+
} else {
65+
logExit(1, {
66+
message: "Something is wrong with RPC / Jupiter! ",
67+
});
68+
process.exit(1);
69+
}
70+
};
71+
5572
module.exports = {
5673
calculateProfit,
5774
toDecimal,
@@ -60,4 +77,5 @@ module.exports = {
6077
loadConfigFile,
6178
updateIterationsPerMin,
6279
storeItInTempAsJSON,
80+
checkRoutesResponse,
6381
};

0 commit comments

Comments
 (0)