I have a smart contract that get flashLoan
from dydx
and arbitrage between Kyber
and Uniswap
. I have another javascript
code that wait for a good opportunity between this tow dexes.
If there is an arbitrage opportunity ,I will call flash loan method with ether js
and arbitrage.
My smart contract was working on kovan
network but it doesn't work on mainnet
.
It always throw error of minimum rate on the second dex
.
This code is for buy uniswap and sell kyber
:
uint256 deadline = block.timestamp + 15;
address[] memory path = new address[](2);
path[0] = address(WETH);
path[1] = midToken;
WETH.approve(address(uniswap), loanAmount);
uniswap.swapExactTokensForTokens(loanAmount, midTokenMinAmount, path, address(this), deadline);
uint256 midTokenBalance = IERC20(midToken).balanceOf(address(this));
IERC20(midToken).approve(address(kyber), midTokenBalance);
kyber.swapTokenToToken(
IERC20(midToken),
midTokenBalance,
IERC20(WETH),
loanAmount
);