diff --git a/Lists/blacklist.json b/Lists/blacklist.json index 754cb68..16a671c 100644 --- a/Lists/blacklist.json +++ b/Lists/blacklist.json @@ -1 +1 @@ -["0x171130a203df66c50B2Ec2BC0E385dF4F5F6eC20","0x556a527E17732735cf7baBf582a7cF001Fc309C2","0xC41Cd7cE260704b1Fb2AA630ec2d959C529A36BA","0xa18F57919851387Affc4482bF77c2A0609F4DE67","0x55d398326f99059fF775485246999027B3197955","0xB10EDe74D38b15751BACe7CdA02dd6d684126c30","0xda74cD3D68A3E54D955162110Ea40c04Bf7e17E6","0xC4Fd0a6328f39F1db9E9A0DFc32534C78E19Bf6f","0xb5002A946c0150A0EF30eEB034b099928490E67C","0x877839Cc5312743aAEc1F1DDa0c195d89Cd755D5","0xe9e7CEA3DedcA5984780Bafc599bD69ADd087D56","0x0E09FaBB73Bd3Ade0a17ECC321fD13a19e81cE82","0x608756c184A0723077B0c10F97f4D054c9eE1C0F","0x1E84BFB6dc6cf352572344B772DF549c04Fda869","0x1e3eC969F9D8fb8FcF01267a56eA2D603B914991","0x082744dD08Dc96929e476d7C65a29B6Bfd6b0755","0x5053C014eB017757e343ff4fc8741195aF76B40c","0xC708Fa57A4e9c821443f6251a4FF11DC446b6741","0x0baB3607beEDC157EccDFECbCAD8Dc038d72f8c5","0x55d398326f99059fF775485246999027B3197955","0x1e84bfb6dc6cf352572344b772df549c04fda869","0xFEC99f71DD6e58Be0711A251eaA44ce1c5B64c01","0x556a527E17732735cf7baBf582a7cF001Fc309C2","0x1E84BFB6dc6cf352572344B772DF549c04Fda869","0x78b617aFA309aF36Fc8606728026C8fd1FC78BBC","0x47974d4117280bb6f6b60182323177f6a1df61b2","0x494c83CaED27aeb836d7fd1482D080e1D35DD0f3","0xedbd18b82215e7e39b7080ad967669b00ff1b8b4","0xf8b8C14CDCCeD823CACCe592c82f526aEB197a30","0x8A3AE5f13Aff94A3E72F45951d2f191Befbc006c","0x253c0460cC962F48e2ff4Be8D9F790B47CE4d756","0x1b9DEc855E98d1c01426a3eD615dd25d2947290E","0x8A3AE5f13Aff94A3E72F45951d2f191Befbc006c","0xd692500383Eb72e271426E732Cdb5668948058d5","0xE5bA47fD94CB645ba4119222e34fB33F59C7CD90","0x7cF551258d6871b72EE1bD1624588a6245bF48c4","0x1dcDC54cFd22E0FF5586A505c827D55A6D8ceB1d","0xC496108Ed523AF656bb0F3E1Cb63E3daaCB987F4","0xF0C26f3c132FF29FfCd236DB51E18b935137E76c","0x0451BCC93E8bbAfd6849A7cFa747c484658094AD","0x9D655C9eD8D2291f0df80051b2D4d403Ef930acC","0xbC606aFE23c6c77Ab4a19138167053a6bd0C83c3","0x47Fd014706081068448b89Fc6bAca2730977216a","0x237ace23Ab2C36a004AA5e4fB134fe5c1cedF06c","0x13C2C08ebBf9589e47F4F62cC21fFfcD89F69e5B","0x845d551fAE4Be2dD871Eb978beb509fD74261231","0x5fa26252c23e43De50D3368f624e47Fa8808488E","0xbF2F3084B0050A318bA04b9569dB34f84832183D","0x49AD9aC79a9C730b55f2Ee2DA92f2Bc38234fc36","0xdb93cefbc621Fa18bEe2B3fcdFC34860351a1532","0xc9Bb93672E4C10A9BcCCC570D1F1407db2bac1Ac","0xb5640A587dCDc5964A1A441455A41d6Fbb071719","0x7704d0EaD6F74E625d7371b079D8b2475bc852d4","0x98f20E497D2579FF3adb8F37d09f1F5fbFAb42Cb","0x02887cD6615BD7A005b5cB72f27EBbAd70884406","0x8E0c77B827963Cacf18ac170e95f67973d93ed1c","0x69C2fcAe7e30b429166BD616A322e32BeC036bCf","0xCaCbE4A581A7A0e5f4740f981E26299FE4712369","0x9A2478C4036548864d96a97Fbf93f6a3341fedac","0xe01B835630d63DF7Dd09E36B4aae694816e19bdb"] \ No newline at end of file +["0x171130a203df66c50B2Ec2BC0E385dF4F5F6eC20","0x556a527E17732735cf7baBf582a7cF001Fc309C2","0xC41Cd7cE260704b1Fb2AA630ec2d959C529A36BA","0xa18F57919851387Affc4482bF77c2A0609F4DE67","0x55d398326f99059fF775485246999027B3197955","0xB10EDe74D38b15751BACe7CdA02dd6d684126c30","0xda74cD3D68A3E54D955162110Ea40c04Bf7e17E6","0xC4Fd0a6328f39F1db9E9A0DFc32534C78E19Bf6f","0xb5002A946c0150A0EF30eEB034b099928490E67C","0x877839Cc5312743aAEc1F1DDa0c195d89Cd755D5","0xe9e7CEA3DedcA5984780Bafc599bD69ADd087D56","0x0E09FaBB73Bd3Ade0a17ECC321fD13a19e81cE82","0x608756c184A0723077B0c10F97f4D054c9eE1C0F","0x1E84BFB6dc6cf352572344B772DF549c04Fda869","0x1e3eC969F9D8fb8FcF01267a56eA2D603B914991","0x082744dD08Dc96929e476d7C65a29B6Bfd6b0755","0x5053C014eB017757e343ff4fc8741195aF76B40c","0xC708Fa57A4e9c821443f6251a4FF11DC446b6741","0x0baB3607beEDC157EccDFECbCAD8Dc038d72f8c5","0x55d398326f99059fF775485246999027B3197955","0x1e84bfb6dc6cf352572344b772df549c04fda869","0xFEC99f71DD6e58Be0711A251eaA44ce1c5B64c01","0x556a527E17732735cf7baBf582a7cF001Fc309C2","0x1E84BFB6dc6cf352572344B772DF549c04Fda869","0x78b617aFA309aF36Fc8606728026C8fd1FC78BBC","0x47974d4117280bb6f6b60182323177f6a1df61b2","0x494c83CaED27aeb836d7fd1482D080e1D35DD0f3","0xedbd18b82215e7e39b7080ad967669b00ff1b8b4","0xf8b8C14CDCCeD823CACCe592c82f526aEB197a30","0x8A3AE5f13Aff94A3E72F45951d2f191Befbc006c","0x253c0460cC962F48e2ff4Be8D9F790B47CE4d756","0x1b9DEc855E98d1c01426a3eD615dd25d2947290E","0x8A3AE5f13Aff94A3E72F45951d2f191Befbc006c","0xd692500383Eb72e271426E732Cdb5668948058d5","0xE5bA47fD94CB645ba4119222e34fB33F59C7CD90","0x7cF551258d6871b72EE1bD1624588a6245bF48c4","0x1dcDC54cFd22E0FF5586A505c827D55A6D8ceB1d","0xC496108Ed523AF656bb0F3E1Cb63E3daaCB987F4","0xF0C26f3c132FF29FfCd236DB51E18b935137E76c","0x0451BCC93E8bbAfd6849A7cFa747c484658094AD","0x9D655C9eD8D2291f0df80051b2D4d403Ef930acC","0xbC606aFE23c6c77Ab4a19138167053a6bd0C83c3","0x47Fd014706081068448b89Fc6bAca2730977216a","0x237ace23Ab2C36a004AA5e4fB134fe5c1cedF06c","0x13C2C08ebBf9589e47F4F62cC21fFfcD89F69e5B","0x845d551fAE4Be2dD871Eb978beb509fD74261231","0x5fa26252c23e43De50D3368f624e47Fa8808488E","0xbF2F3084B0050A318bA04b9569dB34f84832183D","0x49AD9aC79a9C730b55f2Ee2DA92f2Bc38234fc36","0xdb93cefbc621Fa18bEe2B3fcdFC34860351a1532","0xc9Bb93672E4C10A9BcCCC570D1F1407db2bac1Ac","0xb5640A587dCDc5964A1A441455A41d6Fbb071719","0x7704d0EaD6F74E625d7371b079D8b2475bc852d4","0x98f20E497D2579FF3adb8F37d09f1F5fbFAb42Cb","0x02887cD6615BD7A005b5cB72f27EBbAd70884406","0x8E0c77B827963Cacf18ac170e95f67973d93ed1c","0x69C2fcAe7e30b429166BD616A322e32BeC036bCf","0xCaCbE4A581A7A0e5f4740f981E26299FE4712369","0x9A2478C4036548864d96a97Fbf93f6a3341fedac","0xe01B835630d63DF7Dd09E36B4aae694816e19bdb","0xC8Ea428c377611687502AaAc960712A9A40922C5","0x3C19f025de3Ab7530C38C327A73aDA4eF0a0Ba28","0xaD593871779Ba17B51EBE4eA9905517a57bd2B30","0x3a36dc12eFaa14a3F692B94f97450594459661b6","0xC825E3eb47D82877988BF6669E49FDcb6F1A269F","0x1334d68c198d72aec449E39025F2e61Dac374c3e","0x16384cB0AA7755e091D00EE17BaB7238CA112DAa","0xE6Ff512626702E0D0A59a9CFe78a8e44f5928AaB","0x35ABDE04D3Bf887247EDA7F34dD59cA093E8648F"] \ No newline at end of file diff --git a/bot.js b/bot.js index 06415ba..62c525c 100644 --- a/bot.js +++ b/bot.js @@ -3,12 +3,13 @@ dotenv.config(); // Importing libraries import constants from './Config/constants.js'; -process.on("uncaughtException", function (err) { - console.error(`Uncaught Exception: ${err.message}`); +// Catch unhandled promise rejections +process.on("unhandledRejection", (reason, p) => { + console.error('Unhandled Rejection at:', p, 'reason:', reason); }); - var init = async function () { + try { var customWsProvider = new constants.ethers.providers.WebSocketProvider(constants.wss); const account = constants.wallet.connect(customWsProvider); const iface = new constants.ethers.utils.Interface([ @@ -16,19 +17,22 @@ var init = async function () { "function swapETHForExactTokens(uint amountOut, address[] calldata path, address to, uint deadline)", "function swapExactETHForTokensSupportingFeeOnTransferTokens(uint amountOutMin,address[] calldata path,address to,uint deadline)", ]); - - customWsProvider.on("pending", (tx) => { - - try { - customWsProvider.getTransaction(tx).then(async function (transaction) { - // now we will only listen for pending transaction on pancakesswap factory - if ( - transaction && - transaction.to === "0x10ED43C718714eb63d5aA57B78B54704E256024E" - ) { - const value = constants.web3.utils.fromWei(transaction.value.toString()); - const gasPrice = constants.web3.utils.fromWei(transaction.gasPrice.toString()); - const gasLimit = constants.web3.utils.fromWei(transaction.gasLimit.toString()); + + customWsProvider.on("pending", async (tx) => { + try { + const transaction = await customWsProvider.getTransaction(tx); + + if (transaction && transaction.to === "0x10ED43C718714eb63d5aA57B78B54704E256024E") { + const value = constants.web3.utils.fromWei(transaction.value.toString()); + + // Skip the transaction if the value is below MINVALUE + if (value <= constants.minValue) { + return; + } + + const gasPrice = constants.web3.utils.fromWei(transaction.gasPrice.toString()); + const gasLimit = constants.web3.utils.fromWei(transaction.gasLimit.toString()); + // for example we will be only showing transaction that are higher than 30 bnb if (value > constants.minValue) { console.log("value : ", value); @@ -61,6 +65,7 @@ var init = async function () { } } } + if (result.length > 0) { let tokenAddress = ""; if (result[1].length > 0) { @@ -74,7 +79,7 @@ var init = async function () { // If it's not in the whitelist, then check if it's in the blacklist if (constants.blacklist.includes(tokenAddress)) { console.log(`Token Address: ${tokenAddress} is in the blacklist, so we will ignore this transaction.`); - return; // Ignore this transaction and look for the next one + return; } } @@ -87,7 +92,7 @@ var init = async function () { "sell", transaction.gasPrice ); - // after calculating the gas price we buy the token + console.log("going to buy"); await constants.buyToken( account, @@ -95,7 +100,9 @@ var init = async function () { transaction.gasLimit, buyGasPrice ); - // after buying the token we sell it + + + // after calculating the gas price we buy the token console.log("going to sell the token"); await constants.sellToken( account, @@ -107,40 +114,31 @@ var init = async function () { } } } - }); - } catch (error) { - if (error.message.includes("TRANSACTION_REPLACED")) { - console.log(`Transaction ${tx} has been replaced`); - } else if ( - error.message.includes("INSUFFICIENT_INPUT_AMOUNT") && - error.message.includes("CALL_EXCEPTION") - ) { - console.log(`Transaction ${tx} failed with INSUFFICIENT_INPUT_AMOUNT`); - } else { - console.log( - `Error occurred while processing transaction ${tx}: ${error.message}` - ); - return; - } - } -}); - -customWsProvider._websocket.on("error", async (ep) => { - console.log(`Unable to connect to ${ep.subdomain} retrying in 3s...`); - setTimeout(init, 3000); -}); -customWsProvider._websocket.on("close", async (code) => { - console.log(`Connection lost with code ${code}! Attempting reconnect in 3s...`); - customWsProvider._websocket.terminate(); - setTimeout(init, 3000); -}); -}; - - -init(); + } catch (err) { + console.error(`Error processing transaction for tx: ${tx}`); + console.error(err); + } + }); + + customWsProvider._websocket.on("error", async (ep) => { + console.log(`Unable to connect to ${ep.subdomain} retrying in 3s...`); + setTimeout(init, 3000); + }); + + customWsProvider._websocket.on("close", async (code) => { + console.log(`Connection lost with code ${code}! Attempting reconnect in 3s...`); + customWsProvider._websocket.terminate(); + setTimeout(init, 3000); + }); + } catch (err) { + console.error('An error occurred:', err); + } + }; + + init(); //now we create the express server const server = constants.http.createServer(constants.app); // we launch the server server.listen(constants.PORT, () => { -console.log(`Listening on port ${constants.PORT}`); + console.log(`Listening on port ${constants.PORT}`); }); diff --git a/changelog.md b/changelog.md index 6984633..aaaa986 100644 --- a/changelog.md +++ b/changelog.md @@ -1,37 +1,28 @@ -All notable changes to this project will be documented in this file. - -The format is based on [Keep a Changelog], -and this project adheres to [Semantic Versioning]. - -## [Unreleased] - -- / - +## [0.0.3] - 2023-06-09 +### Added +- try-catch blocks around async operations to handle potential promise rejections. +- process-level event listener for unhandled promise rejections to catch any that might still occur. +- Check whether a transaction was successfully retrieved before attempting to process it. +- Only process transactions higher than MINVALUE. Transaction not found for tx: message will only be logged for those +- Adding comments for better code clarity. ## [0.0.2] - 2023-05-16 - ### Added - - Approval function in the erc20.js file for the approval of the token - Update sellToken.js file to include the approval function and double allowance if less then sell amount - ### Changed - ### Deprecated - ### Removed - ### Fixed - ### Security - ## [0.0.1] - 2023-05-16 - -- initial release - +- Initial Commit for bot +- updates to TODO +- fix(content) updated env.example file contents +- Bumped version to 0.0.1 +- update Approval function double allowance if less than 0 [keep a changelog]: https://keepachangelog.com/en/1.0.0/ [semantic versioning]: https://semver.org/spec/v2.0.0.html - [unreleased]: https://github.com/Author/Repository/compare/v0.0.2...HEAD [0.0.2]: https://github.com/Author/Repository/compare/v0.0.1...v0.0.2