Hello James and thank you for this great job 🙏 it was a good complete example to enter the solidity world, I'm testing the bot on a watch mode (without triggering trades) and I just want to share with you some points: to solve the gas problem I've recalculated the correct routes as I will test it on usdt only, to do this I've created a new script that builds all possible routes then test each one by applying the function estimateDualDexTrade if it doesn't catch an error I parse the good route in temp file then copy the result to configuration. I will try to init a score property on each route and always select the first one, if the route gives an arbitrage opportunity I'll increase the score by 1 else I'll decrease it by 1 then sort the routes by the score property, when you've talked about scaling I think It's hard to say as you have tested the result on different conditions.
Sounds like a good idea to score different routes and check more profitable routes more frequently. To scale it I think you would probably want to run your own node and monitor the mempool for incoming trades
Excellent presentation, everything is told in an accessible and understandable way. The tutorial was useful to me for using the bot. Thank you very much.
I am glad to find your channel, so grateful for the free code which helps me a lot with my solidity skills, please update more content like this. Thanks again.
Awesome james nice concise explanation of the code and what it does in the scheme of things no fluff -perfect in its simplicity and showing more than some who leave you stranded with how and where to get hash numbers and where to put them in a tidy orderly manner. Thanks
Yeah so many people have run it now too, it might be harder to find profitable trades. Definitely won't make a fortune but a good introduction to arbitrage and systems trading I hope.
I tried the code in remix, I always use estimate dual trade function to estimate the profit before I will execute the trade and it works, but if I put a higher amount I will be getting “no arbitrage available" error message, if I use small amount it will work, what could be the course?
Thanks for this great tutorial; I learned a lot. It felt great to see "# weth: 52bps" pop up on the log for the 1st time. In the video you mentioned that the dualDexTrade function isn't very gas efficient; would you explain why it's not, or how I could make it more gas efficient?
It was written for a network with zero gas fees at the time. In production you would likely want to monitor the mempool and trade against incoming transactions
Honestly this video has been extremely helpful and I love the way you have kept it interactive. However I have a question; pls with the current transaction fees on aurora and and other expenses. Do you still think this code will be profitable. That is excluding the competition? I need to know it really does help. Thanks
You can just set a minimum profit variable to cover the transaction fee. In practice though a lot of people have forked this code so probably any network other than Aurora would be a better place to run it
Had the same issue and took me a good while to fix it. It was pretty simple for me. Cant read address of undefined means your [owner] isn't hooked up properly. For me I had stupidly changed the .env file name manually and accidentally left .txt on the end meaning the hardhat config file couldn't find the correct file. I removed that .txt and hey presto, I'm onto my next bug ha! Hope this helps
@@charlie.scot. and @James Bachini Hey guys, I've come across this same issue, and I've saved my file correctly as .env But I'm still getting the same error message when I try to run the deploy.js script Do you have any other suggestions with regards to getting the [owner] hooked up properly as you say in your message above? Would appreciate some guidance in getting over this obstacle, thank you!
I don't think it would be profitable for this use case as the fees for the loan would eat into profits and there wasn't much liquidity to scale it anyway. Flash loan > more volume > more slippage > lower margins > plus flashloan fees Some example code here if you still want to give it a try www.quicknode.com/guides/defi/how-to-make-a-flash-loan-using-aave
What are the benefits of doing route search and dual Dex swap from the arb contract address compare to doing it directly from your personal contract address?
Such a nice video, can I change the network to other evm like bsc, arbitrum or base, inside the config file and deploy it... 2. Does the bot determine direction in the two dex, if the price is lower than the other one it will determine which dex it will buy first?
Thanks, the bot is performing trades using mostly the funds inside the base assets, not the tokens; it will perform trades between those assets, right? The more base assets, the more trades it can perform
@@Johnson-d8n depends on the network. If you were doing something on eth mainnet you'd probably want to use the flashbots fast rpc URL. Having said that it wouldn't be anywhere near competitive on eth mainnet
Thanks for this helpful tutorial, My question is what if we put some large amount like $20k or $70k in base assets, it will be profitable or slippage will destroy the benefits?
slippage will destroy it because the pools aren't liquid enough. There's code on github to work out optimal sizing for each transaction I believe as it will vary.
Thank you very much for the great content, please how can I change the dex? I should change the router address of the preferred dex I want right? Or is there any additional steps
If it's based on uni v2 then yes just change the contract address. If it's something else then it might have a different swap function so you'll need to dig into their docs to see how it works programmatically
Thanks for your response, like how much would be the minimum for trade, because the bot has been watching for opportunity yet it did want to execute trade, I also changed tokens and dexes, it didn't work, any advice on this?
@@rolandonwa2369hard to say without much info to go on. You should be able to do tiny $0.01 trades. There is no minimum as such. Maybe try adjusting the profit requirement setting. Also if it's running on a chain or dex with low trading volume it won't find many trades as prices aren't moving much
Flash loans would create more slippage and fees so less profits. Not enough trading volume and liquidity on Aurora to make it viable. You are capped by how much capital you can push through without moving price any way so flash loans would only add more capital and fees which wouldn't work.
Hi James, first of all, thank you so much for the content. It helps a LOT for a newbie like me. I have a query here. Is there a benefit of doing all the "scans" of opportunity through smart contract ("estimateDualDexTrade") vs. interacting with the individual DEX's routers directly (calling router's getAmountsOut from Node JS)? Thanks again!! Looking forward to more of your contents!
There is in that you could potentially trade the same block and it would speed up execution and make it more competitive. On public RPC nodes you'll hit a lot of rate limits doing this so worth running your own version of geth.
Fascinating content. Have you tried integrating the use of Flash Loans into these bots? I understand these are used quite often in these arbitrage transactions.
There's wasn't enough trading volume on Aurora to make it worth a flashloan. You'd be paying a fee on the loan and higher slippage on the dex so would cut into margins. On something like Eth mainnet where millions are traded daily there's a lot more room for volume but then it becomes more competitive too.
I'm not really into programming a lot, I only know few things here and there. Can you please explain how to execute the code you provided? Like what language, program, or system you used?
Hello, first thank's for this great tutorial, i would like to add another blockchain but i don't see how to get the "routes" can you help me for this part ?
Think there some info in the blog post linked in the description. It was a while ago but seem to remember brute forcing the routes using different combos of token addresses
Hi ! Awesome video. I'm getting errors with the solidity compiler, don't exactly know how to change that. Then also, I'm trying to do the "cd Dex-Arbitrage", but it doesn't find the route to the folder. And last question, how can I use this code in a testnet ? Thank you in advance
Should be able to use it on a testnet but bare in mind there's not much trading volume so it won't find many trades. Check token and router addresses if you are getting errors
If I want to do stuff like this and get into MEV bots, should I learn JS before Solidity? I know Python and I know some C, C++, so I'm thinking I'd be better off not being lazy and learning JS before Solidity...
You could actually just use python and solidity or even python and vyper. Use python for the controller script and then solidity or vyper for the contract. JavaScript is useful to learn anyway as it's used a lot in testing (hardhat) and for connecting up web3 frameworks. But it's not essential for this type of thing. Bit of a wishy washy answer. Maybe start with CryptoZombies to get a feel for how it all works together and see where you end up and what bits interest you.
@@JamesBachini Ok, thanks for the advice! I'll start with Crypto Zombies since it always looked interesting anyways, just didn't know whether it had value or not as a hobby programmer.
Great piece James, to begin with, I'm a newbie in programming, but I've been wondering 🤔 is it possible to create a crypto token that never falls by removing/burning sold supplies instantly from the total supply? And is it possible to create a token contract that would auto run an arbitrage contract on its own to generate yields. Will really appreciate a kind and complete answer please 😁!
It's not possible to create a token that never falls unfortunately. Safemoon did something similar to what you are talking about where transaction fees went to liquidity pools to boost price but it was still highly volatile. With regards to a token contract with an underlying arbitrage strategy in theory this would be possible but in practice it's difficult for it to be competitive. Not sure if the incentives are there too. I.e. if someone has a profitable arb strategy why would they want to share the profits with token holders rather than just running it themselves. I think we will see more tokens in the future that have yield farming type strategies backing up the collateral which makes more sense to me as execution is less time critical.
It's pretty old now and was only minimally profitable when aurora first launched in the middle of a bull market. The code has been forked hundreds of times since then so I'd assume it's pretty saturated. You might find a few dollar trades but it certainly won't make you rich overnight. Beware of any code that promises you will get rich quick
Go through the list of ethereum dexes on DeFillama, anything based on Uni v2 should work. Can normally Google "nameOfDex router etherscan" and it'll come up with the address and source code which you can check to see if the function names for swaps are the same
It's quite complex to calculate the optimal sizing. You would need to get the pool sizes at a given state and then figure out a formula to calculate slippage and how that affects profits. There's some more info about calculating slippage for v3 pools here: x3finance.medium.com/how-to-calculate-swap-slippage-of-uniswap-v3-d433ed6d74b0
This is awesome thank you very much I am running it on ftm just to get a feel for how a bot run before i deploy my own but I am curious about how i can add more routes to the json because i added more dexes to the bot? I saw a reply you had saying that that function is in trade.js but is commented out but i am not seeing it. I would like to add it as a separate script that i can run and have write to the uniqueRoutes.json. Also i believe there is an error in the read me instruction because it says to run the bot you just use the deploy script again? I found that not to be the case also the slashes in the .\scripts\deploy.js were backwards for me because i am running on linux, I believe that could be good to specify in the readme
Hi Duncan, thanks for that I'll get the readme updated. To find the routes I just grabbed token addresses and tried every combination of them against popular base assets like usdt/usdc/ftm on every router. If there wasn't a pool for that combo then an error would be thrown and you can catch it and move on to the next. If there was a pool you wouldn't get an error and can write out thpse tokens and router addresses to a goodRoutes.json file
Thanks for the tutorial! quick question, what do you mean by "no transaction fee on Aurora"? I followed your tutorial and located some arb on the Aurora Dexes. But when I try to manual swap then, I got charged by a small fee ETH (enough to wipe out the arb profits)?
When I made the video there were no transaction or gas fees on Aurora. They later introduced them a month or so ago unfortunately. There's some info about it on their twitter account
Is this a scam, cause people on twitter PM about this ? I'll watch the video, and watch more videos, etc. I hate scammers, so if anyone has any way to show me a government website, or something that helps me find answers to these concerns.
Don't buy trading systems from 3rd parties. If someone has something that makes money there is no reason to sell it. Write your own code, learn and continue to be sceptical
Not sure why always got Error: call revert exception (method="estimateDualDexTrade(address,address,address,address,uint256)", errorArgs=null, errorName=null, errorSignature=null, reason=null, code=CALL_EXCEPTION, version=abi/5.5.0) when running trade.js is it realted to the version?
Thanks so much for the bot and video, so great to see the layout, I just have no real idea as to what’s going on exactly. How did you put together the list of all those different routes? Just taking a chance here but if you can pls can you make an in-depth video on this bot for the brand new coders like myself, would be excellent but thanks regardless great video
So the routes are just Token in > Dex > token out You can find dexes by looking on defillama. You can find router address for the Dex by doing a transaction and checking which contract you interacted with in a block explorer. And tokens can be found via the dexes analytics sites or by analysing transactions on the router
@@JamesBachini Hey thanks for the quick reply, I should've specified but the routes I was thinking about is the routes in the config files. At first I was confused as to how you made it to begin with, but reading the code now I see it first gets made under "const lookForDualTrade" and then info is appended to txt file in data folder. Now I'm trying to figure out from, for example ./data/fantomRouteLog.txt ... how does that info get copied to ./config/fantom.json .. how did you get the routes from the fantomRouteLog.txt to fantom.json file ... do you do it manually?
@@22-Zar yeah I think I just used vscode to add the formatting You can search for something like a newline and then hit alt enter and it'll highlight all and you can add the '],[' bits. I can't remember exactly but expect I did it something like that. A better alternative would just be to format it correctly in the script and use JSON.stringify before writing out to the file.
@@JamesBachini thanks James, I'm very new to coding but I've taken time to read the code as best I can and your video does explain it very well, so no real need for that "in-depth video" this is really great ... last question, if I want to use the BSC network can I just create a file like the aurora.json file in config folder, basically copy that but with BSC info and then run the controller to get the list of routes - then copy those routes to the config .json file again under "routes": [ ] and then run off that? Now I just want to figure out how can I use flash loans instead of my personal funds
@@22-Zar yes copy it but change the router addresses to the contract addresses for Pancakeswap and/or other bsc exchanges. The token addresses will be different too. Bscscan is the equivalent of etherscan and useful for this
I don't think so because of the scaling issue. Flash loans are great when you need a lot of capital but here it would just cause more slippage and you'd have to pay the loan fee. The liquidity pools that I was trading on just weren't big enough to justify it. On ethereum mainnet trading into large liquidity pools there might be a case for it but then you are looking at MEV and flashbots. Uni v2 forks generally have a flash swap feature/function at 0.3% which is interesting for certain situations and fun to play with.
Hey. Great tutorial. I got this error on hardhat console: > arb = await IArb.attach(arbContract); Uncaught ReferenceError: arbContract is not defined at REPL10:1:48 I put the arbContract in the .env file. Pls help. Tks u.
There's a function in the trade.js file which just brute forces them using the token list and router addresses. I logged any that didn't pop an error to a JSON file and then used that. Think it's called data/goodRoutes.json in the repo. The logging line is commented out I believe in trade.js
@@JamesBachini Definitely agree, you can find positive trades but i havent been able to beat the transaction fee. I tried it on 5 dexes, pancake, cafe, bakery, cheese and ape. With the 100 tokens with the largest market caps.
i try the aurora one but got gas estimation fail, so tridexes need to amend your code I assume? also how will this work with some other dexes fork like balancer or solidly? thanks
Gas estimation error just means the tx is failing so check your config file and router/token addresses. Other dexes you will need to change the functions you are calling for swaps because they all work slightly differently
@@cheesebeef890114 sure here is a video about Uniswap v3 flashloans with links to tutorial and code in the description ru-vid.com/video/%D0%B2%D0%B8%D0%B4%D0%B5%D0%BE-rte5Rk-XQ24.html
@@Divine_Patrick01 follow the users, if there are degens clicking buttons there will be opportunity for arbitrage. More users and trading volume the bigger the opportunity to find trades
Pls james i need your help. I have tried to deploy the contract using the deploy script in the repo and i have put my private key in dotenv but then it keeps showing me this; * Invalid account: #0 for network: aurora - Expected string, received undefined * Invalid account: #0 for network: fantom - Expected string, received undefined. PLS what could be the problem? Any help would be greatly appreciated😭
Sounds strange. What network are you trying to deploy it on? Maybe double check the .env file, did you put a alchemy API key in there? Also check hardhat.config.js and remove any networks you don't need. Add --network aurora or whatever chain you are deploying on using the key from hardhat.config.js
Yes you will need to update some of the contract addresses and perhaps swap functions for any dexes which aren't based on Uniswap V2 but BSC is EVM so it's compatible
There's a link to a full tutorial in the video or if you search dex arbitrage it should come up. You basically need to find the router address of the Dex using a block explorer. Check the function name matches etc.
Hi James, thank you for this wonderful tutorial. I have a question here: is it necessary to send some FTM to the fantom arbitrage contract (or ETH to the aurora arbitrage contract, since aurora now requires transaction fees)for gas fee? But I always failed to send FTM to the contract. Is it because the contract doesn't have a fallback() or receive() function?
No you only need the base asset that you are trading in the contract. You'll need some FTM in the wallet address in the .env file This fires off the transactions and pays the gas fee.
@@JamesBachini thanks for answering my question! I have another question: I put 500 wftm in the contract and run the trade script, but got "wftm: 0bps" all the time. Is it because 500wftm is too much that causing big slippage?
@@traceurlou2118 I wouldn't have thought so. Fantom is pretty competitive. I found every time I found a good trade the network RPC would go down for 30 seconds like someone ddos'ing it to take out competition. Probably need to run a private node to avoid that. You have the routes set up across a few dexes I assume? Maybe look at gas prices other bots are using to make sure you are competitive.
@@JamesBachini make sense. What is `minBasisPointsPerTrade` in the config file? You mentioned that in the video, but I still don't get it. Why aurora's minBasisPointsPerTrade is 0 while fantom is 50?
The bot isn't going to be profitable or at least isn't going to make a significant amount of money. Set up a fresh test wallet to use and put the private key from that into the .env file
Really helpful video, but im still a novice and i have a question that how can i set baseasset’s input amount for each trade ? Is this random or have any function for this ? Tks James
Trade size is just set as the contracts balance of that token but you could set it manually here: github.com/jamesbachini/DEX-Arbitrage/blob/a1f23b3e3fe6d64350befef98713af5efbd2ff3f/scripts/trade.js#L52
@@JamesBachini hey James, great video and thank you for sharing this code! Can you recommend any resources that would help us make this change to this code? I can see it's line 52 in the link you have shared above in this thread But I'm not sure how to code this yet, would appreciate if you can point me in the direction of where I can find that info to implement it myself Thank you
Hi James, I found many arbitrage bots in some ecosystems. I am trying to find a way to get pair's information without a hardcode, like Uniswap Subgraph. Do u have any idea about this? thank you
You could pass the pair in via a contract function. Finding the pairs, you could maybe look at the contract events if you want to trade newly setup liquidity pools or something like that
InstaArb.sol was just an experiment to take much of the computation into a contract. Didn't work well but might have potential if you were running an internal node.
Such a nice video, please can you give me a suggestion on what I will with this error message, after I changed the chains, also I have funds in those assets. It will load the assets and start displaying this error message Error: cannot estimate gas; transaction may fail or may require manual gas limit reason: 'cannot estimate gas; transaction may fail or may require manual gas limit', code: 'UNPREDICTABLE_GAS_LIMIT' error: ProviderError: execution reverted Please any advice to handle this issue
@@JamesBachini thanks for your response, do you mean if I redeploy the contract it will resolve the issue? Because I recently deployed the contract on a polygon, also when I was using the aurora network it was not showing me the error message
@@williamj2063 some of the tokens and routers might have different addresses on different chains. So you'll need to update the config files accordingly with the correct token addresses and dexes you want to trade on
@@JamesBachini all the tokens are correct with the chains I'm using and dexs, I always make sure I'm in the chain inside dex screener then select the tokens based on that dex and chain
i finally deployed the contract using fantom. i configured it to include three routers and token addresses but when i run it, i get ; 'cannot estimate gas; transaction may fail or may require manual gas limit', code: 'UNPREDICTABLE_GAS_LIMIT', error: ProviderError: execution reverted
@@JamesBachini I got this error when I try to call a function from the IERC20 interface for exemple : call to IERC20.totalSupply errored: Internal JSON-RPC error. { "code": -32000, "message": "execution reverted" } The fact that I don't understand is, this error doesn't appear when I interact with the contract in the Aurora Blockchain (the only differences is the Blockchain where I deploy the contract) Can you tell me how to use it without non Uniswap clones ? (sorry it's a lot of questions)
@@akrfinance8379 you would need to change the function names that carry out the trades. Different dexes may use different functions and parameters so if you are dealing with something unusual you will need to customise the script for it
@@JamesBachini For me the rooter address it's the only parameter I have to change to trade on a different dexes (the addresses token too). Why do I have to change function names ? And what functions are you talking about ? I adapt of course the script but I keep the functions, I only adapt the addresses. Thank you
@@akrfinance8379 the code uses uniswap v2 and its various clones which all use the same functions/code to do swaps. If you are using Uni v3 or another dex which isn't a fork of Uniswap v2 then you'll need to adapt it to suit that code.
Hi James, I've been looking for some time for an arbitrage bot allowing me to invest in it even with low relative profitability despite everything... I'm not a developer and I'm therefore looking to rely on a basic bot with which I can be confident, do you think it could be wise for me to deploy this bot that you present to us in this video, without having to modify it given the fact that I would be truly unable to do so, I looking to earn a small passive income using cryptocurrency arbitrage. Thank you for your video, your advice and your kindness... thank you very much
Hi, no the bot is really provided as a learning tool rather than something that will make consistent and reliable profits. The truth is no one will publish or sell a MeV or arbitrage trading bot that makes consistent profits. Something like yield farming would be a better option in my opinion. Be really careful not to fall for scams with people selling trading bots.
Hi, James. I'm trying to adapt your contract for mainnet(uniswpv2, sushi), experimenting with golang instead of nodejs though. So the question is I'm stuck at `Fail with error 'TransferHelper: TRANSFER_FROM_FAILED'` no clue how to solve it, because I clearly see approve() call at the start of swap() function. Any suggestions would be highly appreciated. And thank you for the content of course.
It does sound like a token isn't approved or there isn't enough balance. Are you storing the tokens on the contract address? And approving them from the address where they are?
@@JamesBachini Sorry, but since you're quite involved in conversation I'd like to ask one more question.. What's the granularity of arbitrage contract/bot? I mean we only see new token prices after block update? Is it possible to go to sub block values?
@@Idontreallycareatall Yeah at the highest level people are modifying geth to monitor the mempool for incoming transactions and then executing arbs via flashbots to close any price discrepancies in the same block.
@@JamesBachini would you be willing to shed more light on what that means? If it's not too much of a bother. I'm pretty new to the web3 space so I'm not quite familiar with those terms yet.
@@olayinkaadebisi7907 same code will work on avalanche. However tokens will often have different addresses on each chain. Also different chains have different DeXs (decentralized exchanges)
First of all, thank you for such an informative video. It’s really valuable for me. I deployed and tried the contract at Aurora. Then it worked exactly how you showed us here. After all I tried to deploy same contract to BSC testnet with particular changes like routes, tokens, swap addresses, dotenv, file names etc… I mean I just changed Auorora things with BSC testnet things. I successfully deployed it on BSC testnet and also mainnet too(with necessarry changes again). The issue I confronted is that when I started to trade.js, I’m getting an error code: ‘UNPREDICTABLE_GAS_LIMIT’ reason: cannot estimate gas: transaction may fail or may require manual gas limit. I have been reserching for complete 18 hours and I couldn’t solve the issue. And I’m really tired :( What could i miss? My wallets have necessary tokens. Routers and token addresses are all of them are correct. If you have a solution of it, could you please share? Thanks and sorry for long question.
I think in the code there's a commented out line to set the gas limit manually on the transaction. Check bscscan and see what other bots are paying in terms of gas and set it to that.
@@JamesBachini I tried to de-commrate but it obviously gives me syntax error, how should you insert it? Const TX = Await Arb.Connect (Owner) .Dualdextrade (Router1, Router2, Basetoken, Token2, Amount); {Gasprice: 1000000000003, Gaslimit: 500000};
1)Contrarily to what deploy.js tells you, DO NOT ADD a line for arbContract in .env (set it only in configuration>fantom.json or aurora.json) otherwise some scripts will crash! 2)Just use deploy.js > fund.js > trade.js > recover.js (I've ignored instadeploy.js and instatrade.js which may be redundant with deploy.js > fund.js > trade.js )
@@bertyguilbo8536 absolutely correct. The insta...js scripts were just experiments I left in for anyone interested. deploy.js > fund.js > trade.js > recover.js are the only ones needed
@@mattis46 the wallet that you use to sign transactions is stored in the .env file. You need some funds in here to pay gas fees. This is normally the native token for that blockchain. i.e. BnB for BSC, ETH for Ethereum, Aurora also introduced transaction fees since I made the video which are payable in Eth
@@JamesBachini Thanks for your reply. I do have ETH in the Metamask Wallet (Aurora Network), but I do get this error anyways. Shall I add the ETH to the base assets in aurora.json file?
Hey James, I don't understand how to find out Routes I have Assets and Dex Router Addresses but have not clue how to find these Routes Addresses Could you please give me a hint?
Yeah just brute force them so try every asset pair on every router. Any routes that don't exist will revert with an error. Log the ones that do exist to a file and use that to loop through in future.
@@equaliserTV just try to look for profitable swaps by looping through an array of token address for each Dex. Many will fail because there isnt a liquidity pool for that pair setup. To save wasting time and RPC bandwidth remove those and continue on with the ones where there are pools and you are finding trades
@@equaliserTV to be fair this is a bit hacky and probably not the most elegant way of doing it. But say you want to find all the routes for trading across Dex1 to Dex2 so you start with base assets i.e. Eth usdt usdc. Then you try to swap them for any token you can find on Dex1 then you try to swap back to the base asset on Dex2 and see if it's profitable. You can make it more complex and find various routes i.e. baseAsset to token1 to token2 to baseAsset. The more complex the route the more variations you have to test to see if token1 and token2 are trading on the dexes. So looping through the token addresses and router addresses and logging what works will give you a more condensed list of potentially profitable routes to query regularly.
Hello james, thanks for the indepth tutorial. However, i am stuck as I am trying to use the arb bot on different chains. Do I have to create the aurora.json file myself and create the routes manually or am I doing something wrong when executing the code. I was under the assumption that once I changed the tokenList.json and execute the code, the aurora.json file would get repopulated with the correct new tokens and routes. correct me if i am wrong. Esentially my question is how did you create the aurora.json file and the routes written below it.
No the router addresses for the Dex's and token contract addresses will all change between networks. You'll need to find out what they are for your specific chain and create a new file
@@JamesBachini I understand that the token addresses for a different chain will be different, as well as the router addresses. However, is there a script already in the repo that creates the routes from looking at tokenList.json or do I have to write it basically. That's my question. Thanks again for this tutorial
@@jarvadetoro7004 you have to write it. There's a function to build out the routes by brute forcing the token/router combinations but you probably wouldn't want to use that on a chain with gas fees
@@JamesBachini I have managed to do all the changes as outlined and fund the contract with the base assets, however when i run the trade.js I am getting the following error : TypeError: Cannot read property 'balance' of undefined at lookForDualTrade (C:\Users\DELL\Documents\arb_bot\DEX-Arbitrage\scripts\trade.js:52:50) Some help would be appreciated
@@jarvadetoro7004 sounds like an issue with one of the token contract addresses for the base assets. Try double checking them and your contract balance in a block explorer.
Learning to code unfortunately. I think it would be hard to make a living from arbitrage trading without knowing how to code up trading bots etc. If you want to work in DeFi then solidity is the programming language of choice, for quants its python and for everything else its Javascript. If you have no preference I'd recommend learning Javascript first because it's used everywhere
Hi James, I'm running the "deploy.js" script and I keep getting the error message: "TypeError: Cannot read property 'address' of undefined" I've read through all of the comments below to try to find the answer but I can't seem to get over this particular hurdle Can you make any reccomendations of where I should be looking, in which file and which lines I should be looking at? Thank you
@@JamesBachini hey James, I managed to resolve this issue :) I had not "cd"'d into the "DEX-Arbitrage" folder But when I did and made edits to those json files it all worked out I'm now able to deposit/withdraw and will begin testing with a real balance soon I do however now sometimes find this error: "replacement fee too low" and "replacement transaction underpriced" (even when there appears to be no pending transactions on either my wallet or contract on polygonscan..) I'm going to keep trying more tomorrow If you've encountered this "fee too low" error before and could recommend the right direction for me to explore to resolve it that would be very helpful Thank you!
@@eharrison it sounds like there's a transaction still in pending because of a low gas fee and the miners not picking it up. Then you are trying to overwrite it with another transaction with the same nonce (perhaps after restarting the programme) and that's too low too. Try upping the gas fee to a competitive amount and you should be good to go.
@@JamesBachini yeh I found a couple other sources/articles that said the same thing So I managed to pull the $1 ish of test WETH out of the contract by going to Remix and manually altering the Gas fee in metamask I'm wondering however, for using "fund.js" to add some base assets to run the Bot for a bit longer to more routes Do you know of any fixes, if the "fee too low" eeors show up again, even whilst there are no current transactions pending either by my wallet or the contract? That's where I'm struggling to understand where this particular "fee too low" error is coming from (when there doesn't appear to be an existing transaction to replace) Thank you for your responses bro, I appreciate it!
@@JamesBachini Also wondering if there is a way for me to alter the gas fees, for the script functions like "Fund.js" - "Recover.js" and "Trade.js" Is there anywhere in the code where we can make some changes to the gas fees, in case of running into these errors again in future?
@@JamesBachini Just trying to learn Solidity in general. I’m not coming from any type of coding background. I’m watching tutorials that say “if I watch this I’ll be a solidity coding master in 4 hours!” and after 3 days straight watching tutorials I’m left scratching my head lol. But I will keep trying.
@@dannyellis971 have you tried cryptozombies? That's a great tutorial/game to get up to speed. It's going to be a lot to take in if you've never coded before. If you hit a particular bug or problem don't forget you can normally Google an error code and figure it out from the stackoverflow post as someone will have been there before too.
I gave up after 2 days and just ended up paying a dev to code me one and to teach me how to deploy it all. It’s working great now and is very profitable
Hi James, is there anywhere in the code we can alter the Gas price? I'm trying on Polygon and I keep coming across the error "fee too low" and "replacement transaction underpriced" I've played around with it a bit and managed to withdraw from the contract using remix/metamask and manually increasing the gas fees in MM But I often come across this "underpriced" error when trying to deposit into the contract (so I can't even test it with real $ atm lol!) Is it possible that this error will be less likely to happen when the networks gas fees come down (as they are significantly higher than usual as I'm typing this) Let me know if there is anywhere in the code that I can play withthe gas fee amount when you get a chance please Thank you again for providing this code for us to test/modify and learn from! Great learning experience making changes to this thing :)
Example of setting a manual gas price on line 80 github.com/jamesbachini/DEX-Arbitrage/blob/a1f23b3e3fe6d64350befef98713af5efbd2ff3f/scripts/trade.js#L80
@@eharrison is there any line number or reference for this error: "TypeError: Cannot read property 'balance' of undefined" it sounds like the contract isn't defined or it's trying to check the balance of something that hasn't been created in the code yet. That could be having knock on effects so I'd start with trying to find out what is going wrong here
@@JamesBachini it also says "at lookForDualTrade" Lines 59 and 75 Line 59 is: let tradeSize = balances[targetRoute.token1].balance; And then line 75 is: await lookForDualTrade(); I'm guessing that I need to make changes so that "balance" can be read properly I'm not quite sure what "Cannot read property 'balance' of undefined" means yet I'm not sure what is undefined, or how to define it lol!
@@JamesBachini When you say the contract isn't defined, is there an additional process I need to do to define the contract? Should I verify the on Polygonscan using the bytecode (which I've not done yet)?
i'm very new to this so I was wondering I keep getting * Invalid account: #0 for network: aurora - Expected string, received undefined. Do you know what this means? Also is it an aurora wallet I need to connect or can I use me metamask as I want to use it with a test network?
You can use any address, it doesn't need to be your metamask wallet. There's a handy little too/repol in my GitHub called ethers-vanity-address which I use to make test wallets. Put the wallet credentials in a .env file and put some funds on there. Aurora you don't need anything to pay transaction fees but most other networks you do. Even testnets you need some free testnet play tokens from a faucet. You'll also need some of the base asset that you want to trade to send to the contract. There's a couple of scripts to help with this called scripts/fund.js and scripts/recover.js Check it all works with tiny amounts including recover.js so you can get any funds back out of the contract when finished.
Just to be clear and from what I understand, I need to transfer funds to a main wallet the baseAsset tokens (will just be using usdt) (does the wallet need to be on the aurora mainnet or will having funds in Binance Smart Chain be ok? if not how do I get funds into the aurora mainnet) and then deploy.js to get the contract key that goes into arbContract. Then, use fund.js to transfer funds from the wallet to arbcontract and then trade.js, then recover.js to get the funds back from the contract?
@@mitchhammy3612 the wallet needs to be on the same network you plan on running the bot. There was someone who left a comment about running it on Binance smart chain. I'd suggest setting up a separate wallet either in metamask or somewhere else and try it first with like less than $1 in USDT so you can make sure you can recover funds and everything works. You'll need to add the bsc network details to hardhat.config.js If you want to run it on Aurora you can bridge assets across from Binance smart chain to the aurora network using a tool like multichain or synapse
How did you get scammed? I don't think it can be from the bot in this video as the code is all open source and I wrote it myself. If you purchased a 3rd party bot then that was something else as all the code here is free and on GitHub. If someone promises you riches for $19.99/month it's probably a scam. Arbitrage is hard and you need to code your own solutions and tools to be competitive.
@@JamesBachini this video was presented as elementary with other info. I put some money into my wallet, and joined project through wallet's browser. Details on pm if you are interested.
This bot not a scam ...just make sure u have basic coding understanding to begin with. Don't use third party coded bot .instead use the original from GitHub repository and scale the bot urself.
So Uniswap v3 has some licensing issues to stop people copying it. All the clones like Pancakeswap, Trisolaris, Sushi etc. Are based in v2. It's possible to set this up with v3 as well you just need to change the function and parameters. Example code here for ve swaps github.com/JohnRSim/0xtr.ee-Contracts/blob/main/contracts/SwapExample.sol Contract addresses in the code are for the polygon Mumbai testnet
Awesome Tutorial James!. However I have a question. I used the bot as it is, on the Fantom network and as you said, results were not good. So I simply changed one of the router addresses to the router address of another Fantom dex. I also replaced the router dex address on the listed routes in fantom.json file. Here is where I have hit a roadblock. I get the following error "reason: 'cannot estimate gas; transaction may fail or may require manual gas limit', code: 'UNPREDICTABLE_GAS_LIMIT'". I have manually put the gas limit in the hardhat.config file with no success, passed the gas price into the function in trade.js like so: const tx = await arb.connect(owner).dualDexTrade(router1, router2, baseToken, token2, amount, { gasPrice: 50000000000, gasLimit: 500000 }); yet same error. I have tinkered with this, using various gas prices well above what I see on the Fantom block explorer to no avail. But anytime I roll back changes and bring back the original script as you made it with spiritswap and spookyswap it works. Can you solve this with a simple example using another dex, maybe jetswap? Thanks in advance!
The gas price error message just means the transaction is expected to fail. It will likely be because of one of the router addresses is incorrect or not compatible with Uniswap be type DEX functions. Check the address is not all lowercase as that can cause a checksum error.
@@JamesBachini So I double checked, replaced the router addresses with the dual case contract address. I used SpiritSwap with router address : 0x16327E3FbDaCA3bcF7E38F5Af2599D2DDc33aE52 as against Wigoswap with contract address: 0x5023882f4D1EC10544FCB2066abE9C1645E95AA0 . Wigoswap has verified contract on ftmscan . Its still the same error.
@@JamesBachini Its is. Its stated as a uniswap fork on defilama. Anyway I tried it this time on Bsc between pancakeswap and bakeryswap with the same error. Surely bakeryswap is a uniswap v2 fork. maybe the full error log will be helpful. here it is: Error: cannot estimate gas; transaction may fail or may require manual gas limit (error={"name":"ProviderError","code":-32000,"_isProviderError":true}, method="call", transaction={"from":"0x5d78Eec03d7bBCcfF78bFf012CccfA423343B2fF","to":"0xDD9e3DEb5eD590fBb5E710731AA5D2e7d0f244b2","data":"0x068e7ca1000000000000000000000000cde540d7eafe93ac5fe6233bee57e1270d3e330f00000000000000000000000010ed43c718714eb63d5aa57b78b54704e256024e000000000000000000000000bb4cdb9cbd36b01bd1cbaebf2de08d9173bc095c0000000000000000000000001fa4a73a3f0133f0025378af00236f3abdee5d6300000000000000000000000000000000000000000000000000f8b0a10e470000","accessList":null}, code=UNPREDICTABLE_GAS_LIMIT, version=providers/5.5.2) at Logger.makeError (C:\Users\myasu\DEX-Arbitrage ode_modules\@ethersproject\logger\src.ts\index.ts:225:28) at Logger.throwError (C:\Users\myasu\DEX-Arbitrage ode_modules\@ethersproject\logger\src.ts\index.ts:237:20) at checkError (C:\Users\myasu\DEX-Arbitrage ode_modules\@ethersproject\providers\src.ts\json-rpc-provider.ts:80:16) at EthersProviderWrapper. (C:\Users\myasu\DEX-Arbitrage ode_modules\@ethersproject\providers\src.ts\json-rpc-provider.ts:562:20) at step (C:\Users\myasu\DEX-Arbitrage ode_modules\@ethersproject\providers\lib\json-rpc-provider.js:48:23) at Object.throw (C:\Users\myasu\DEX-Arbitrage ode_modules\@ethersproject\providers\lib\json-rpc-provider.js:29:53) at rejected (C:\Users\myasu\DEX-Arbitrage ode_modules\@ethersproject\providers\lib\json-rpc-provider.js:21:65) at runMicrotasks () at processTicksAndRejections (node:internal/process/task_queues:96:5) { reason: 'cannot estimate gas; transaction may fail or may require manual gas limit', code: 'UNPREDICTABLE_GAS_LIMIT', error: ProviderError: execution reverted at HttpProvider.request (C:\Users\myasu\DEX-Arbitrage ode_modules\hardhat\src\internal\core\providers\http.ts:49:19) at LocalAccountsProvider.request (C:\Users\myasu\DEX-Arbitrage ode_modules\hardhat\src\internal\core\providers\accounts.ts:187:34) at runMicrotasks () at processTicksAndRejections (node:internal/process/task_queues:96:5) at EthersProviderWrapper.send (C:\Users\myasu\DEX-Arbitrage ode_modules\@nomiclabs\hardhat-ethers\src\internal\ethers-provider-wrapper.ts:13:20), method: 'call', transaction: { from: '0x5d78Eec03d7bBCcfF78bFf012CccfA423343B2fF', to: '0xDD9e3DEb5eD590fBb5E710731AA5D2e7d0f244b2', data: '0x068e7ca1000000000000000000000000cde540d7eafe93ac5fe6233bee57e1270d3e330f00000000000000000000000010ed43c718714eb63d5aa57b78b54704e256024e000000000000000000000000bb4cdb9cbd36b01bd1cbaebf2de08d9173bc095c0000000000000000000000001fa4a73a3f0133f0025378af00236f3abdee5d6300000000000000000000000000000000000000000000000000f8b0a10e470000', accessList: null } }
@@softassets7370 I think it's just showing that the transaction will fail. Not much else to go off. Likely an issue with a token or router address as that is all that's really changed
Hi i, thank you for sharing this, i tried it all of the router and token addresses are correct but i am getting a 'cannot estimate gas: transaction may fail or may require manual gas limit' code: unpredictable gas_limit. Tried to looked at the comments and included decommented it out and included at the end of the function (..gasPrice ,gasLimit) but i had yo change the syntax from gasLimit : 1000000001 to gasLimit =1000000 same with the gas price as i am getting a "unexpected token :" . Method: estimateGas
Hey double check the contract and router addresses including checksums. If you look at the GitHub closed issues there are 3-4 threads from people with similar problems. I think the error message is a bit misleading but it basically means the transaction will fail. The other thing is it won't work as standard with Uniswap v3 only v2 and the million v2 clones out there.
@@JamesBachini I figured out how to save and edit. I noticed there is a lot of WETH9 in the code. If i am using this on another EVM that doesnt have ETH/WETH for gas but instead another coin do I need to edit all those WETH9 to whatever the gas coin is on that network?
@@harrisonfang Uniswap always uses weth rather than the native Eth. So on Polygon for example they use wMatic rather than mastic. There is a list in the Uniswap docs I think of all the correct addresses
@@JamesBachini Right. My question is for my case I am trying to test this on the SMR evm network which uses SMR for gas fees. In my case would I need to edit your code and replace everything that says WETH9 with SMR?