Hello,
For a given pair in a flashloan arbitrage operation, taking the example of uniswap and sushiswap as the selected DEX´s for executing an arbitrage opportunity, and for 1INCH/WETH token pair, sushiswap WETH price is cheaper than uniswap (despite having larger reserve volumes in comparison).
The problem lies when I execute the following two lines of code in my uniswapV2call
method:
uint amountToRepay = UniswapV2Library.getAmountsIn(factory, _amount, path)[0];
uint amountReceived = router.swapExactTokensForTokens(
_amount,
amountToRepay,
path,
msg.sender,
(block.timestamp + 300))[1];
and it returns amountToRepay > amountReceived when I was expecting the result to be other way round owing to spotted price difference opportunity under arbitrage operation.
Output console.log (from my back-end smart contract)
getAmountsIn() results.......
path[0] 0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2
path[1] 0x111111111117dc0aa78b770fa6a738034120c302
amountBorrowed 2497817866881194385864
amountToRepay 964334905750628563
getAmountsOut() results.......
path[0] 0x111111111117dc0aa78b770fa6a738034120c302
path[1] 0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2
amountReceived 950114205093874394
Output error message
Error: VM Exception while processing transaction: reverted with reason string 'UniswapV2Router: INSUFFICIENT_OUTPUT_AMOUNT'
at . (0x7a250d5630b4cf539739df2c5dacb4c659f2488d)
at FlashloanerArbitrage.uniswapV2Call (contracts/FlashloanerArbitrage.sol:261)
at . (0x86f518368e0d49d5916e2bd9eb162e9952b7b04d)
at FlashloanerArbitrage.startSwap (contracts/FlashloanerArbitrage.sol:180)
at processTicksAndRejections (node:internal/process/task_queues:96:5)
at EthModule._estimateGasAction (C:\Samuel\Blockchain\Flashloan-arbitrage-bot-uniswapV2_hardhat\node_modules\hardhat\src\internal\hardhat-network\provider\modules\eth.ts:429:7)
at HardhatNetworkProvider._sendWithLogging (C:\Samuel\Blockchain\Flashloan-arbitrage-bot-uniswapV2_hardhat\node_modules\hardhat\src\internal\hardhat-network\provider\provider.ts:139:22)
at HardhatNetworkProvider.request (C:\Samuel\Blockchain\Flashloan-arbitrage-bot-uniswapV2_hardhat\node_modules\hardhat\src\internal\hardhat-network\provider\provider.ts:116:18)
at JsonRpcHandler._handleRequest (C:\Samuel\Blockchain\Flashloan-arbitrage-bot-uniswapV2_hardhat\node_modules\hardhat\src\internal\hardhat-network\jsonrpc\handler.ts:188:20)
at JsonRpcHandler._handleSingleRequest (C:\Samuel\Blockchain\Flashloan-arbitrage-bot-uniswapV2_hardhat\node_modules\hardhat\src\internal\hardhat-network\jsonrpc\handler.ts:167:17)
at Server.JsonRpcHandler.handleHttp (C:\Samuel\Blockchain\Flashloan-arbitrage-bot-uniswapV2_hardhat\node_modules\hardhat\src\internal\hardhat-network\jsonrpc\handler.ts:52:21)
Where am I going wrong here as this issue has been troubling me for several weeks now.
I have tried implementing other_ pricing oracle methods but it comes back to this very same issue.
Any help or suggestions would be greatly appreciated.
Thank you
Top comments (0)