Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Output value from getAmountsIn > swapExactTokensForTokens in arbitrage price difference opportunity #136

Open
Samboy76 opened this issue Oct 9, 2022 · 1 comment

Comments

@Samboy76
Copy link

Samboy76 commented Oct 9, 2022

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

@Samboy76 Samboy76 changed the title Arbitrage profit through combination of getAmountsIn and getAmountsOut functions Determine arbitrage profit based on price differences and reserve amounts between two selected DEXs Oct 9, 2022
@Samboy76 Samboy76 changed the title Determine arbitrage profit based on price differences and reserve amounts between two selected DEXs Determine flashloan token amount to yield a profit based on price differences and reserve amounts in two selected DEXs Oct 9, 2022
@Samboy76 Samboy76 changed the title Determine flashloan token amount to yield a profit based on price differences and reserve amounts in two selected DEXs Output value from getAmountsIn > getAmountsIn in arbitrage price difference opportunity Oct 30, 2022
@Samboy76 Samboy76 changed the title Output value from getAmountsIn > getAmountsIn in arbitrage price difference opportunity Output value from getAmountsIn > swapExactTokensForTokens in arbitrage price difference opportunity Dec 5, 2022
@MattCorte
Copy link

i have the same problem, did you fixed?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants