2

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
);
6
  • 1
    Will upvote for visibility, I have similar problems with dydx flash loans too although for a different use. Also, do you maybe have some resources to trade kyber? I've tried looking into it but seems like one of the most complicated exchanges to understand, how do they calculate amountOut? Thanks mate
    – Hiperfly
    Commented Jun 15, 2021 at 19:44
  • Can you share the exception with more details and what method throws an exception, the contract code on GitHub causes this exception can give us a better understanding of the bug, I suggest you remove and call approve methods or that methods no need to run with the main method in another method. this helps you with better debugging. Commented Jun 16, 2021 at 11:13
  • It throw error on second step of arbitrage(Kyber step).The error is 'rate < min rate'. Commented Jun 16, 2021 at 11:17
  • Where did you get you flashloan program? Im trying to build something similiar. But I am so new I am struggling. Commented Jul 10, 2021 at 19:30
  • A bit rage is a good way to spell it, but actually it is ar bit rage Commented Jul 10, 2021 at 22:55

1 Answer 1

2

i am trying to make a flash loan too. i saw some codes on how to buy on kyber and sell on uniswap

https://github.com/jklepatch/eattheblocks/tree/master/profitable-flashloans/24-buy-kyber-sell-uniswap you can check it out.. you can email me so we talk more about it forsonfranklin @gmail

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.