olegmitrakhovich / Defi-Arb-Bot

arbitrage bot, looks for prices differences on uniswap and kyber. Uses flashloan to make a trade between 2 exchanges. #eattheblocks course
295 stars 92 forks source link

Transactions reverted "Fail with error 'Not enough funds to repay dydx loan!" #4

Open olegmitrakhovich opened 4 years ago

olegmitrakhovich commented 4 years ago

So far the bot was able to find some ARB opportunities, but all 3 transactions were reverted: https://etherscan.io/address/0x92E52890cfA407D9713A6cFcd7FB6F8d50B99FB2

The error I am getting is "Fail with error 'Not enough funds to repay dydx loan!", no idea why this is happening? My theory is that the prices that the bot is finding are wrong, therefore the calculation of profit for that transaction is wrong. I tried switching to another service like QuickNode instead of Infura, but the result is the same. Any ideas are welcome :)

olegmitrakhovich commented 4 years ago

New block received. Block # 10769902 Kyber -> Uniswap. Dai input / output: 20000 / 20226.65515378271518166 Uniswap -> Kyber. Dai input / output: 20000 / 19864.450886301560153009 <------------------Using Gas Price:-----------------------> <BN: 4614ff8200> Arb opportunity found Kyber -> Uniswap! Expected profit: 55.41484450071518166 Dai New block received. Block # 10769903 Kyber -> Uniswap. Dai input / output: 20000 / 20002.773397261110680253 Uniswap -> Kyber. Dai input / output: 20000 / 19864.36329089209059149 <------------------Using Gas Price:-----------------------> <BN: 4614ff8200> Kyber -> Uniswap. Dai input / output: 20000 / 20002.773397261110680253 Uniswap -> Kyber. Dai input / output: 20000 / 19864.36329089209059149 <------------------Using Gas Price:-----------------------> <BN: 4614ff8200> New block received. Block # 10769904 New block received. Block # 10769905 New block received. Block # 10769906 (node:30758) UnhandledPromiseRejectionWarning: Error: Transaction has been reverted by the EVM: { "blockHash": "0x5ab8fd72d3c70c8592a81de9b42b6c1056f72393b8119b95d6e7f5cbe5e28ee4", "blockNumber": 10769905, "contractAddress": null, "cumulativeGasUsed": 7898434, "from": "0x91df1a2da70f5a9085773ea483aa46f7c13a728f", "gasUsed": 1217128, "logs": [], "logsBloom": "0x000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000$ "status": false, "to": "0x92e52890cfa407d9713a6cfcd7fb6f8d50b99fb2", "transactionHash": "0x92fd033de7fd2807f594a812cb96746c05b62732331e208e67cf2bae8cb0d990", "transactionIndex": 74 } at Object.TransactionError (/root/Defi-Arb-Bot/node_modules/web3-core-helpers/src/errors.js:96:21) at Object.TransactionRevertedWithoutReasonError (/root/Defi-Arb-Bot/node_modules/web3-core-helpers/src/errors.js:108:21) at /root/Defi-Arb-Bot/node_modules/web3-core-method/src/index.js:482:48 at at process._tickCallback (internal/process/next_tick.js:188:7) (node:30758) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or $ Kyber -> Uniswap. Dai input / output: 20000 / 19943.426926241242587365

olegmitrakhovich commented 4 years ago

https://bloxy.info/tx/0x92fd033de7fd2807f594a812cb96746c05b62732331e208e67cf2bae8cb0d990

olegmitrakhovich commented 4 years ago

transaction

cnspot commented 4 years ago

it mean uniswap sell price<buy price ,so money be come lesser?

olegmitrakhovich commented 4 years ago

the prices that I am getting are just wrong and there was no ARB in actuality. @cnspot

cnspot commented 3 years ago

this bug had fixed now? the bug of geting wrong prices

StrawberryFlavor commented 3 years ago

Maybe it would be better not to use dydx loan, just arbitrage on uniswap, the trading pair can be as follows: WETH--> token, token --> DAI, DAI-WETH, this is just an example. This can avoid the extra transaction cost of loan and only use the existing balance

olegmitrakhovich commented 3 years ago

hmmm good idea...pull request? @StrawberryFlavor

krishanb4 commented 3 years ago

I think in your wallet must have dydx interest pay amount before getting loan

olegmitrakhovich commented 3 years ago

sorry, what do you mean? @krishanb4

krishanb4 commented 3 years ago

if you use DAI(example) your wallet must have dydx fee(DAI) before start arbi. Because if your profit cannot pay dydx loan fee you have to pay it from your wallet DAI balance.